1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/mimetype.h
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _MIMETYPE_IMPL_H
13 #define _MIMETYPE_IMPL_H
15 #include "wx/mimetype.h"
19 class wxMimeTypeCommands
;
21 WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands
*, wxMimeCommandsArray
);
23 // this is the real wxMimeTypesManager for Unix
24 class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
28 wxMimeTypesManagerImpl();
29 virtual ~wxMimeTypesManagerImpl();
31 // load all data into memory - done when it is needed for the first time
32 void Initialize(int mailcapStyles
= wxMAILCAP_ALL
,
33 const wxString
& extraDir
= wxEmptyString
);
35 // and delete the data here
38 // implement containing class functions
39 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
40 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
42 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
44 void AddFallback(const wxFileTypeInfo
& filetype
);
46 // add information about the given mimetype
47 void AddMimeTypeInfo(const wxString
& mimetype
,
48 const wxString
& extensions
,
49 const wxString
& description
);
50 void AddMailcapInfo(const wxString
& strType
,
51 const wxString
& strOpenCmd
,
52 const wxString
& strPrintCmd
,
53 const wxString
& strTest
,
54 const wxString
& strDesc
);
56 // add a new record to the user .mailcap/.mime.types files
57 wxFileType
*Associate(const wxFileTypeInfo
& ftInfo
);
59 bool Unassociate(wxFileType
*ft
);
62 // get the string containing space separated extensions for the given
64 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
69 wxArrayString m_aTypes
, // MIME types
70 m_aDescriptions
, // descriptions (just some text)
71 m_aExtensions
, // space separated list of extensions
72 m_aIcons
; // Icon filenames
74 // verb=command pairs for this file type
75 wxMimeCommandsArray m_aEntries
;
77 // are we initialized?
80 wxString
GetCommand(const wxString
&verb
, size_t nIndex
) const;
82 // Read XDG *.desktop file
83 void LoadXDGApp(const wxString
& filename
);
85 void LoadXDGAppsFilesFromDir(const wxString
& dirname
);
87 // functions used to do associations
88 virtual int AddToMimeData(const wxString
& strType
,
89 const wxString
& strIcon
,
90 wxMimeTypeCommands
*entry
,
91 const wxArrayString
& strExtensions
,
92 const wxString
& strDesc
,
93 bool replaceExisting
= TRUE
);
94 virtual bool DoAssociation(const wxString
& strType
,
95 const wxString
& strIcon
,
96 wxMimeTypeCommands
*entry
,
97 const wxArrayString
& strExtensions
,
98 const wxString
& strDesc
);
100 // give it access to m_aXXX variables
101 friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl
;
104 class WXDLLIMPEXP_BASE wxFileTypeImpl
107 // initialization functions
108 // this is used to construct a list of mimetypes which match;
109 // if built with GetFileTypeFromMimetype index 0 has the exact match and
110 // index 1 the type / * match
111 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
112 // the first extension found, index 1 for the second and so on
114 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
115 { m_manager
= manager
; m_index
.Add(index
); }
118 bool GetExtensions(wxArrayString
& extensions
);
119 bool GetMimeType(wxString
*mimeType
) const
120 { *mimeType
= m_manager
->m_aTypes
[m_index
[0]]; return TRUE
; }
121 bool GetMimeTypes(wxArrayString
& mimeTypes
) const;
122 bool GetIcon(wxIconLocation
*iconLoc
) const;
124 bool GetDescription(wxString
*desc
) const
125 { *desc
= m_manager
->m_aDescriptions
[m_index
[0]]; return TRUE
; }
127 bool GetOpenCommand(wxString
*openCmd
,
128 const wxFileType::MessageParameters
& params
) const
130 *openCmd
= GetExpandedCommand(wxT("open"), params
);
131 return (! openCmd
-> IsEmpty() );
134 bool GetPrintCommand(wxString
*printCmd
,
135 const wxFileType::MessageParameters
& params
) const
137 *printCmd
= GetExpandedCommand(wxT("print"), params
);
138 return (! printCmd
-> IsEmpty() );
141 // return the number of commands defined for this file type, 0 if none
142 size_t GetAllCommands(wxArrayString
*verbs
, wxArrayString
*commands
,
143 const wxFileType::MessageParameters
& params
) const;
146 // remove the record for this file type
147 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
148 bool Unassociate(wxFileType
*ft
)
150 return m_manager
->Unassociate(ft
);
153 // set an arbitrary command, ask confirmation if it already exists and
154 // overwriteprompt is TRUE
155 bool SetCommand(const wxString
& cmd
, const wxString
& verb
, bool overwriteprompt
= TRUE
);
156 bool SetDefaultIcon(const wxString
& strIcon
= wxEmptyString
, int index
= 0);
160 GetExpandedCommand(const wxString
& verb
,
161 const wxFileType::MessageParameters
& params
) const;
163 wxMimeTypesManagerImpl
*m_manager
;
164 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays
167 #endif // wxUSE_MIMETYPE
169 #endif // _MIMETYPE_IMPL_H