]>
Commit | Line | Data |
---|---|---|
7dc3cc31 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: unix/mimetype.h | |
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> | |
9 | // Licence: wxWindows license (part of wxExtra library) | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _MIMETYPE_IMPL_H | |
13 | #define _MIMETYPE_IMPL_H | |
14 | ||
7dc3cc31 VS |
15 | #ifdef __GNUG__ |
16 | #pragma interface "mimetype.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/mimetype.h" | |
20 | ||
21 | #if (wxUSE_FILE && wxUSE_TEXTFILE) | |
22 | ||
2b813b73 | 23 | class wxMimeArrayString; |
7dc3cc31 | 24 | |
2b813b73 | 25 | WX_DEFINE_ARRAY(wxMimeArrayString *, wxArrayTypeEntries); |
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 | |
a06c1b9b | 36 | void Initialize(int mailcapStyles = wxMAILCAP_STANDARD, |
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: |
a6c65e88 VZ |
74 | void InitIfNeeded() |
75 | { | |
76 | if ( !m_initialized ) { | |
77 | // set the flag first to prevent recursion | |
78 | m_initialized = TRUE; | |
79 | Initialize(); | |
80 | } | |
81 | } | |
82 | ||
7dc3cc31 VS |
83 | wxArrayString m_aTypes, // MIME types |
84 | m_aDescriptions, // descriptions (just some text) | |
2b813b73 VZ |
85 | m_aExtensions, // space separated list of extensions |
86 | m_aIcons; // Icon filenames | |
87 | ||
88 | // verb=command pairs for this file type | |
89 | wxArrayTypeEntries m_aEntries; | |
7dc3cc31 | 90 | |
a6c65e88 VZ |
91 | // are we initialized? |
92 | bool m_initialized; | |
93 | ||
2b813b73 VZ |
94 | // keep track of the files we had already loaded (this is a bitwise OR of |
95 | // wxMailcapStyle values) | |
96 | int m_mailcapStylesInited; | |
97 | ||
98 | wxString GetCommand(const wxString &verb, size_t nIndex) const; | |
99 | ||
100 | // read Gnome files | |
101 | void LoadGnomeDataFromKeyFile(const wxString& filename); | |
102 | void LoadGnomeMimeTypesFromMimeFile(const wxString& filename); | |
103 | void LoadGnomeMimeFilesFromDir(const wxString& dirbase); | |
104 | void GetGnomeMimeInfo(const wxString& sExtraDir); | |
105 | ||
106 | // write gnome files | |
107 | bool CheckGnomeDirsExist(); | |
108 | bool WriteGnomeKeyFile(int index, bool delete_index); | |
109 | bool WriteGnomeMimeFile(int index, bool delete_index); | |
110 | ||
111 | // read KDE | |
112 | void LoadKDELinksForMimeSubtype(const wxString& dirbase, | |
113 | const wxString& subdir, | |
114 | const wxString& filename, | |
115 | const wxArrayString& icondirs); | |
116 | void LoadKDELinksForMimeType(const wxString& dirbase, | |
117 | const wxString& subdir, | |
118 | const wxArrayString& icondirs); | |
119 | void LoadKDELinkFilesFromDir(const wxString& dirbase, | |
120 | const wxArrayString& icondirs); | |
121 | void GetKDEMimeInfo(const wxString& sExtraDir); | |
122 | ||
123 | // write KDE | |
124 | bool WriteKDEMimeFile(int index, bool delete_index); | |
125 | bool CheckKDEDirsExist(const wxString & sOK, const wxString& sTest); | |
126 | ||
127 | //read write Netscape and MetaMail formats | |
128 | void GetMimeInfo (const wxString& sExtraDir); | |
129 | bool WriteToMailCap (int index, bool delete_index); | |
130 | bool WriteToMimeTypes (int index, bool delete_index); | |
131 | bool WriteToNSMimeTypes (int index, bool delete_index); | |
132 | ||
133 | // functions used to do associations | |
134 | ||
135 | int AddToMimeData(const wxString& strType, | |
136 | const wxString& strIcon, | |
137 | wxMimeArrayString *entry, | |
138 | const wxArrayString& strExtensions, | |
139 | const wxString& strDesc, | |
140 | bool replaceExisting = TRUE); | |
141 | ||
142 | bool DoAssociation(const wxString& strType, | |
143 | const wxString& strIcon, | |
144 | wxMimeArrayString *entry, | |
145 | const wxArrayString& strExtensions, | |
146 | const wxString& strDesc); | |
147 | ||
148 | bool WriteMimeInfo(int nIndex, bool delete_mime ); | |
a6c65e88 VZ |
149 | |
150 | // give it access to m_aXXX variables | |
151 | friend class WXDLLEXPORT wxFileTypeImpl; | |
7dc3cc31 VS |
152 | }; |
153 | ||
4d2976ad VS |
154 | |
155 | ||
7dc3cc31 VS |
156 | class WXDLLEXPORT wxFileTypeImpl |
157 | { | |
158 | public: | |
159 | // initialization functions | |
2b813b73 VZ |
160 | // this is used to construct a list of mimetypes which match; |
161 | // if built with GetFileTypeFromMimetype index 0 has the exact match and | |
162 | // index 1 the type / * match | |
163 | // if built with GetFileTypeFromExtension, index 0 has the mimetype for | |
164 | // the first extension found, index 1 for the second and so on | |
165 | ||
7dc3cc31 | 166 | void Init(wxMimeTypesManagerImpl *manager, size_t index) |
4d2976ad | 167 | { m_manager = manager; m_index.Add(index); } |
7dc3cc31 VS |
168 | |
169 | // accessors | |
170 | bool GetExtensions(wxArrayString& extensions); | |
171 | bool GetMimeType(wxString *mimeType) const | |
4d2976ad VS |
172 | { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } |
173 | bool GetMimeTypes(wxArrayString& mimeTypes) const; | |
2b813b73 VZ |
174 | bool GetIcon(wxIcon *icon, wxString *iconFile = NULL, |
175 | int *iconIndex = NULL) const; | |
176 | ||
7dc3cc31 | 177 | bool GetDescription(wxString *desc) const |
4d2976ad | 178 | { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } |
7dc3cc31 VS |
179 | |
180 | bool GetOpenCommand(wxString *openCmd, | |
181 | const wxFileType::MessageParameters& params) const | |
182 | { | |
2b813b73 VZ |
183 | *openCmd = GetExpandedCommand(wxT("open"), params); |
184 | return (! openCmd -> IsEmpty() ); | |
7dc3cc31 VS |
185 | } |
186 | ||
187 | bool GetPrintCommand(wxString *printCmd, | |
188 | const wxFileType::MessageParameters& params) const | |
189 | { | |
2b813b73 VZ |
190 | *printCmd = GetExpandedCommand(wxT("print"), params); |
191 | return (! printCmd -> IsEmpty() ); | |
7dc3cc31 VS |
192 | } |
193 | ||
2b813b73 VZ |
194 | // return the number of commands defined for this file type, 0 if none |
195 | size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, | |
196 | const wxFileType::MessageParameters& params) const; | |
197 | ||
198 | ||
a6c65e88 | 199 | // remove the record for this file type |
2b813b73 VZ |
200 | // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead |
201 | bool Unassociate(wxFileType *ft) | |
202 | { | |
203 | return m_manager->Unassociate(ft); | |
204 | } | |
a6c65e88 | 205 | |
2b813b73 VZ |
206 | // set an arbitrary command, ask confirmation if it already exists and |
207 | // overwriteprompt is TRUE | |
208 | bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); | |
209 | bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); | |
7dc3cc31 | 210 | |
2b813b73 VZ |
211 | private: |
212 | wxString | |
213 | GetExpandedCommand(const wxString & verb, | |
214 | const wxFileType::MessageParameters& params) const; | |
7dc3cc31 VS |
215 | |
216 | wxMimeTypesManagerImpl *m_manager; | |
4d2976ad | 217 | wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays |
7dc3cc31 VS |
218 | }; |
219 | ||
7dc3cc31 VS |
220 | #endif |
221 | // wxUSE_FILE | |
222 | ||
223 | #endif | |
224 | //_MIMETYPE_IMPL_H | |
225 |