]>
Commit | Line | Data |
---|---|---|
7dc3cc31 | 1 | ///////////////////////////////////////////////////////////////////////////// |
678ebfcd | 2 | // Name: wx/unix/mimetype.h |
7dc3cc31 VS |
3 | // Purpose: classes and functions to manage MIME types |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 23.09.98 | |
7dc3cc31 | 7 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> |
65571936 | 8 | // Licence: wxWindows licence (part of wxExtra library) |
7dc3cc31 VS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _MIMETYPE_IMPL_H | |
12 | #define _MIMETYPE_IMPL_H | |
13 | ||
7dc3cc31 VS |
14 | #include "wx/mimetype.h" |
15 | ||
0d2c74c6 | 16 | #if wxUSE_MIMETYPE |
7dc3cc31 | 17 | |
678ebfcd | 18 | class wxMimeTypeCommands; |
7dc3cc31 | 19 | |
0d2c74c6 | 20 | WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray); |
7dc3cc31 VS |
21 | |
22 | // this is the real wxMimeTypesManager for Unix | |
09902c51 | 23 | class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl |
7dc3cc31 | 24 | { |
7dc3cc31 | 25 | public: |
a6c65e88 | 26 | // ctor and dtor |
7dc3cc31 | 27 | wxMimeTypesManagerImpl(); |
2b850ae1 | 28 | virtual ~wxMimeTypesManagerImpl(); |
a6c65e88 VZ |
29 | |
30 | // load all data into memory - done when it is needed for the first time | |
805f26b3 | 31 | void Initialize(int mailcapStyles = wxMAILCAP_ALL, |
2b813b73 VZ |
32 | const wxString& extraDir = wxEmptyString); |
33 | ||
34 | // and delete the data here | |
35 | void ClearData(); | |
7dc3cc31 VS |
36 | |
37 | // implement containing class functions | |
38 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
39 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); | |
40 | ||
41 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
42 | ||
7dc3cc31 VS |
43 | void AddFallback(const wxFileTypeInfo& filetype); |
44 | ||
45 | // add information about the given mimetype | |
46 | void AddMimeTypeInfo(const wxString& mimetype, | |
47 | const wxString& extensions, | |
48 | const wxString& description); | |
49 | void AddMailcapInfo(const wxString& strType, | |
50 | const wxString& strOpenCmd, | |
51 | const wxString& strPrintCmd, | |
52 | const wxString& strTest, | |
53 | const wxString& strDesc); | |
54 | ||
a6c65e88 VZ |
55 | // add a new record to the user .mailcap/.mime.types files |
56 | wxFileType *Associate(const wxFileTypeInfo& ftInfo); | |
2b813b73 VZ |
57 | // remove association |
58 | bool Unassociate(wxFileType *ft); | |
a6c65e88 | 59 | |
7dc3cc31 VS |
60 | // accessors |
61 | // get the string containing space separated extensions for the given | |
62 | // file type | |
63 | wxString GetExtension(size_t index) { return m_aExtensions[index]; } | |
64 | ||
2b850ae1 | 65 | protected: |
6d718495 | 66 | void InitIfNeeded(); |
a6c65e88 | 67 | |
7dc3cc31 VS |
68 | wxArrayString m_aTypes, // MIME types |
69 | m_aDescriptions, // descriptions (just some text) | |
2b813b73 VZ |
70 | m_aExtensions, // space separated list of extensions |
71 | m_aIcons; // Icon filenames | |
72 | ||
73 | // verb=command pairs for this file type | |
678ebfcd | 74 | wxMimeCommandsArray m_aEntries; |
7dc3cc31 | 75 | |
a6c65e88 VZ |
76 | // are we initialized? |
77 | bool m_initialized; | |
78 | ||
2b813b73 VZ |
79 | wxString GetCommand(const wxString &verb, size_t nIndex) const; |
80 | ||
03647350 | 81 | // Read XDG *.desktop file |
d39e2bbc RR |
82 | void LoadXDGApp(const wxString& filename); |
83 | // Scan XDG directory | |
84 | void LoadXDGAppsFilesFromDir(const wxString& dirname); | |
2b813b73 | 85 | |
05f616ef RR |
86 | // Load XDG globs files |
87 | void LoadXDGGlobs(const wxString& filename); | |
88 | ||
2b813b73 | 89 | // functions used to do associations |
2b850ae1 | 90 | virtual int AddToMimeData(const wxString& strType, |
2b813b73 | 91 | const wxString& strIcon, |
678ebfcd | 92 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
93 | const wxArrayString& strExtensions, |
94 | const wxString& strDesc, | |
8e6efd1f | 95 | bool replaceExisting = true); |
2b850ae1 | 96 | virtual bool DoAssociation(const wxString& strType, |
2b813b73 | 97 | const wxString& strIcon, |
678ebfcd | 98 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
99 | const wxArrayString& strExtensions, |
100 | const wxString& strDesc); | |
101 | ||
a6c65e88 | 102 | // give it access to m_aXXX variables |
4f7d425f | 103 | friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl; |
7dc3cc31 VS |
104 | }; |
105 | ||
09902c51 | 106 | class WXDLLIMPEXP_BASE wxFileTypeImpl |
7dc3cc31 VS |
107 | { |
108 | public: | |
109 | // initialization functions | |
2b813b73 VZ |
110 | // this is used to construct a list of mimetypes which match; |
111 | // if built with GetFileTypeFromMimetype index 0 has the exact match and | |
112 | // index 1 the type / * match | |
113 | // if built with GetFileTypeFromExtension, index 0 has the mimetype for | |
114 | // the first extension found, index 1 for the second and so on | |
115 | ||
7dc3cc31 | 116 | void Init(wxMimeTypesManagerImpl *manager, size_t index) |
4d2976ad | 117 | { m_manager = manager; m_index.Add(index); } |
7dc3cc31 VS |
118 | |
119 | // accessors | |
120 | bool GetExtensions(wxArrayString& extensions); | |
121 | bool GetMimeType(wxString *mimeType) const | |
8e6efd1f | 122 | { *mimeType = m_manager->m_aTypes[m_index[0]]; return true; } |
4d2976ad | 123 | bool GetMimeTypes(wxArrayString& mimeTypes) const; |
da0766ab | 124 | bool GetIcon(wxIconLocation *iconLoc) const; |
2b813b73 | 125 | |
7dc3cc31 | 126 | bool GetDescription(wxString *desc) const |
8e6efd1f | 127 | { *desc = m_manager->m_aDescriptions[m_index[0]]; return true; } |
7dc3cc31 VS |
128 | |
129 | bool GetOpenCommand(wxString *openCmd, | |
130 | const wxFileType::MessageParameters& params) const | |
131 | { | |
2b813b73 VZ |
132 | *openCmd = GetExpandedCommand(wxT("open"), params); |
133 | return (! openCmd -> IsEmpty() ); | |
7dc3cc31 VS |
134 | } |
135 | ||
136 | bool GetPrintCommand(wxString *printCmd, | |
137 | const wxFileType::MessageParameters& params) const | |
138 | { | |
2b813b73 VZ |
139 | *printCmd = GetExpandedCommand(wxT("print"), params); |
140 | return (! printCmd -> IsEmpty() ); | |
7dc3cc31 VS |
141 | } |
142 | ||
2b813b73 VZ |
143 | // return the number of commands defined for this file type, 0 if none |
144 | size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, | |
145 | const wxFileType::MessageParameters& params) const; | |
146 | ||
147 | ||
a6c65e88 | 148 | // remove the record for this file type |
2b813b73 VZ |
149 | // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead |
150 | bool Unassociate(wxFileType *ft) | |
151 | { | |
152 | return m_manager->Unassociate(ft); | |
153 | } | |
a6c65e88 | 154 | |
2b813b73 VZ |
155 | // set an arbitrary command, ask confirmation if it already exists and |
156 | // overwriteprompt is TRUE | |
8e6efd1f | 157 | bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = true); |
2b813b73 | 158 | bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); |
7dc3cc31 | 159 | |
2b813b73 VZ |
160 | private: |
161 | wxString | |
162 | GetExpandedCommand(const wxString & verb, | |
163 | const wxFileType::MessageParameters& params) const; | |
7dc3cc31 VS |
164 | |
165 | wxMimeTypesManagerImpl *m_manager; | |
4d2976ad | 166 | wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays |
7dc3cc31 VS |
167 | }; |
168 | ||
0d2c74c6 VZ |
169 | #endif // wxUSE_MIMETYPE |
170 | ||
171 | #endif // _MIMETYPE_IMPL_H | |
7dc3cc31 | 172 | |
7dc3cc31 | 173 |