]>
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 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
371a5b4e | 9 | // Licence: wxWindows licence (part of wxExtra library) |
7dc3cc31 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _MIMETYPE_IMPL_H | |
13 | #define _MIMETYPE_IMPL_H | |
14 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
7dc3cc31 VS |
16 | #pragma interface "mimetype.h" |
17 | #endif | |
18 | ||
19 | #include "wx/mimetype.h" | |
20 | ||
21 | #if (wxUSE_FILE && wxUSE_TEXTFILE) | |
22 | ||
678ebfcd | 23 | class wxMimeTypeCommands; |
7dc3cc31 | 24 | |
678ebfcd | 25 | WX_DEFINE_ARRAY(wxMimeTypeCommands *, wxMimeCommandsArray); |
7dc3cc31 VS |
26 | |
27 | // this is the real wxMimeTypesManager for Unix | |
28 | class WXDLLEXPORT wxMimeTypesManagerImpl | |
29 | { | |
7dc3cc31 | 30 | public: |
a6c65e88 | 31 | // ctor and dtor |
7dc3cc31 | 32 | wxMimeTypesManagerImpl(); |
cf471cab | 33 | ~wxMimeTypesManagerImpl(); |
a6c65e88 VZ |
34 | |
35 | // load all data into memory - done when it is needed for the first time | |
805f26b3 | 36 | void Initialize(int mailcapStyles = wxMAILCAP_ALL, |
2b813b73 VZ |
37 | const wxString& extraDir = wxEmptyString); |
38 | ||
39 | // and delete the data here | |
40 | void ClearData(); | |
7dc3cc31 VS |
41 | |
42 | // implement containing class functions | |
43 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
44 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); | |
45 | ||
46 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
47 | ||
48 | bool ReadMailcap(const wxString& filename, bool fallback = FALSE); | |
49 | bool ReadMimeTypes(const wxString& filename); | |
50 | ||
51 | void AddFallback(const wxFileTypeInfo& filetype); | |
52 | ||
53 | // add information about the given mimetype | |
54 | void AddMimeTypeInfo(const wxString& mimetype, | |
55 | const wxString& extensions, | |
56 | const wxString& description); | |
57 | void AddMailcapInfo(const wxString& strType, | |
58 | const wxString& strOpenCmd, | |
59 | const wxString& strPrintCmd, | |
60 | const wxString& strTest, | |
61 | const wxString& strDesc); | |
62 | ||
a6c65e88 VZ |
63 | // add a new record to the user .mailcap/.mime.types files |
64 | wxFileType *Associate(const wxFileTypeInfo& ftInfo); | |
2b813b73 VZ |
65 | // remove association |
66 | bool Unassociate(wxFileType *ft); | |
a6c65e88 | 67 | |
7dc3cc31 VS |
68 | // accessors |
69 | // get the string containing space separated extensions for the given | |
70 | // file type | |
71 | wxString GetExtension(size_t index) { return m_aExtensions[index]; } | |
72 | ||
7dc3cc31 | 73 | private: |
6d718495 | 74 | void InitIfNeeded(); |
a6c65e88 | 75 | |
7dc3cc31 VS |
76 | wxArrayString m_aTypes, // MIME types |
77 | m_aDescriptions, // descriptions (just some text) | |
2b813b73 VZ |
78 | m_aExtensions, // space separated list of extensions |
79 | m_aIcons; // Icon filenames | |
80 | ||
81 | // verb=command pairs for this file type | |
678ebfcd | 82 | wxMimeCommandsArray m_aEntries; |
7dc3cc31 | 83 | |
a6c65e88 VZ |
84 | // are we initialized? |
85 | bool m_initialized; | |
86 | ||
2b813b73 VZ |
87 | // keep track of the files we had already loaded (this is a bitwise OR of |
88 | // wxMailcapStyle values) | |
89 | int m_mailcapStylesInited; | |
90 | ||
91 | wxString GetCommand(const wxString &verb, size_t nIndex) const; | |
92 | ||
93 | // read Gnome files | |
805f26b3 VS |
94 | void LoadGnomeDataFromKeyFile(const wxString& filename, |
95 | const wxArrayString& dirs); | |
2b813b73 | 96 | void LoadGnomeMimeTypesFromMimeFile(const wxString& filename); |
805f26b3 VS |
97 | void LoadGnomeMimeFilesFromDir(const wxString& dirbase, |
98 | const wxArrayString& dirs); | |
2b813b73 VZ |
99 | void GetGnomeMimeInfo(const wxString& sExtraDir); |
100 | ||
101 | // write gnome files | |
102 | bool CheckGnomeDirsExist(); | |
103 | bool WriteGnomeKeyFile(int index, bool delete_index); | |
104 | bool WriteGnomeMimeFile(int index, bool delete_index); | |
105 | ||
106 | // read KDE | |
107 | void LoadKDELinksForMimeSubtype(const wxString& dirbase, | |
108 | const wxString& subdir, | |
109 | const wxString& filename, | |
110 | const wxArrayString& icondirs); | |
111 | void LoadKDELinksForMimeType(const wxString& dirbase, | |
112 | const wxString& subdir, | |
113 | const wxArrayString& icondirs); | |
114 | void LoadKDELinkFilesFromDir(const wxString& dirbase, | |
115 | const wxArrayString& icondirs); | |
116 | void GetKDEMimeInfo(const wxString& sExtraDir); | |
117 | ||
118 | // write KDE | |
119 | bool WriteKDEMimeFile(int index, bool delete_index); | |
120 | bool CheckKDEDirsExist(const wxString & sOK, const wxString& sTest); | |
121 | ||
122 | //read write Netscape and MetaMail formats | |
123 | void GetMimeInfo (const wxString& sExtraDir); | |
124 | bool WriteToMailCap (int index, bool delete_index); | |
125 | bool WriteToMimeTypes (int index, bool delete_index); | |
126 | bool WriteToNSMimeTypes (int index, bool delete_index); | |
127 | ||
678ebfcd VZ |
128 | // ReadMailcap() helper |
129 | bool ProcessOtherMailcapField(struct MailcapLineData& data, | |
130 | const wxString& curField); | |
131 | ||
2b813b73 VZ |
132 | // functions used to do associations |
133 | ||
134 | int AddToMimeData(const wxString& strType, | |
135 | const wxString& strIcon, | |
678ebfcd | 136 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
137 | const wxArrayString& strExtensions, |
138 | const wxString& strDesc, | |
139 | bool replaceExisting = TRUE); | |
140 | ||
141 | bool DoAssociation(const wxString& strType, | |
142 | const wxString& strIcon, | |
678ebfcd | 143 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
144 | const wxArrayString& strExtensions, |
145 | const wxString& strDesc); | |
146 | ||
147 | bool WriteMimeInfo(int nIndex, bool delete_mime ); | |
a6c65e88 VZ |
148 | |
149 | // give it access to m_aXXX variables | |
150 | friend class WXDLLEXPORT wxFileTypeImpl; | |
7dc3cc31 VS |
151 | }; |
152 | ||
4d2976ad VS |
153 | |
154 | ||
7dc3cc31 VS |
155 | class WXDLLEXPORT wxFileTypeImpl |
156 | { | |
157 | public: | |
158 | // initialization functions | |
2b813b73 VZ |
159 | // this is used to construct a list of mimetypes which match; |
160 | // if built with GetFileTypeFromMimetype index 0 has the exact match and | |
161 | // index 1 the type / * match | |
162 | // if built with GetFileTypeFromExtension, index 0 has the mimetype for | |
163 | // the first extension found, index 1 for the second and so on | |
164 | ||
7dc3cc31 | 165 | void Init(wxMimeTypesManagerImpl *manager, size_t index) |
4d2976ad | 166 | { m_manager = manager; m_index.Add(index); } |
7dc3cc31 VS |
167 | |
168 | // accessors | |
169 | bool GetExtensions(wxArrayString& extensions); | |
170 | bool GetMimeType(wxString *mimeType) const | |
4d2976ad VS |
171 | { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } |
172 | bool GetMimeTypes(wxArrayString& mimeTypes) const; | |
da0766ab | 173 | bool GetIcon(wxIconLocation *iconLoc) const; |
2b813b73 | 174 | |
7dc3cc31 | 175 | bool GetDescription(wxString *desc) const |
4d2976ad | 176 | { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } |
7dc3cc31 VS |
177 | |
178 | bool GetOpenCommand(wxString *openCmd, | |
179 | const wxFileType::MessageParameters& params) const | |
180 | { | |
2b813b73 VZ |
181 | *openCmd = GetExpandedCommand(wxT("open"), params); |
182 | return (! openCmd -> IsEmpty() ); | |
7dc3cc31 VS |
183 | } |
184 | ||
185 | bool GetPrintCommand(wxString *printCmd, | |
186 | const wxFileType::MessageParameters& params) const | |
187 | { | |
2b813b73 VZ |
188 | *printCmd = GetExpandedCommand(wxT("print"), params); |
189 | return (! printCmd -> IsEmpty() ); | |
7dc3cc31 VS |
190 | } |
191 | ||
2b813b73 VZ |
192 | // return the number of commands defined for this file type, 0 if none |
193 | size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, | |
194 | const wxFileType::MessageParameters& params) const; | |
195 | ||
196 | ||
a6c65e88 | 197 | // remove the record for this file type |
2b813b73 VZ |
198 | // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead |
199 | bool Unassociate(wxFileType *ft) | |
200 | { | |
201 | return m_manager->Unassociate(ft); | |
202 | } | |
a6c65e88 | 203 | |
2b813b73 VZ |
204 | // set an arbitrary command, ask confirmation if it already exists and |
205 | // overwriteprompt is TRUE | |
206 | bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); | |
207 | bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); | |
7dc3cc31 | 208 | |
2b813b73 VZ |
209 | private: |
210 | wxString | |
211 | GetExpandedCommand(const wxString & verb, | |
212 | const wxFileType::MessageParameters& params) const; | |
7dc3cc31 VS |
213 | |
214 | wxMimeTypesManagerImpl *m_manager; | |
4d2976ad | 215 | wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays |
7dc3cc31 VS |
216 | }; |
217 | ||
7dc3cc31 VS |
218 | #endif |
219 | // wxUSE_FILE | |
220 | ||
221 | #endif | |
222 | //_MIMETYPE_IMPL_H | |
223 |