]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/mimetype.h
Applied patch [ 679397 ] remove GPL code from motif build
[wxWidgets.git] / include / wx / unix / mimetype.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "mimetype.h"
17 #endif
18
19 #include "wx/mimetype.h"
20
21 #if (wxUSE_FILE && wxUSE_TEXTFILE)
22
23 class wxMimeTypeCommands;
24
25 WX_DEFINE_ARRAY(wxMimeTypeCommands *, wxMimeCommandsArray);
26
27 // this is the real wxMimeTypesManager for Unix
28 class WXDLLEXPORT wxMimeTypesManagerImpl
29 {
30 public:
31 // ctor and dtor
32 wxMimeTypesManagerImpl();
33 ~wxMimeTypesManagerImpl();
34
35 // load all data into memory - done when it is needed for the first time
36 void Initialize(int mailcapStyles = wxMAILCAP_ALL,
37 const wxString& extraDir = wxEmptyString);
38
39 // and delete the data here
40 void ClearData();
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
63 // add a new record to the user .mailcap/.mime.types files
64 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
65 // remove association
66 bool Unassociate(wxFileType *ft);
67
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
73 private:
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
83 wxArrayString m_aTypes, // MIME types
84 m_aDescriptions, // descriptions (just some text)
85 m_aExtensions, // space separated list of extensions
86 m_aIcons; // Icon filenames
87
88 // verb=command pairs for this file type
89 wxMimeCommandsArray m_aEntries;
90
91 // are we initialized?
92 bool m_initialized;
93
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 const wxArrayString& dirs);
103 void LoadGnomeMimeTypesFromMimeFile(const wxString& filename);
104 void LoadGnomeMimeFilesFromDir(const wxString& dirbase,
105 const wxArrayString& dirs);
106 void GetGnomeMimeInfo(const wxString& sExtraDir);
107
108 // write gnome files
109 bool CheckGnomeDirsExist();
110 bool WriteGnomeKeyFile(int index, bool delete_index);
111 bool WriteGnomeMimeFile(int index, bool delete_index);
112
113 // read KDE
114 void LoadKDELinksForMimeSubtype(const wxString& dirbase,
115 const wxString& subdir,
116 const wxString& filename,
117 const wxArrayString& icondirs);
118 void LoadKDELinksForMimeType(const wxString& dirbase,
119 const wxString& subdir,
120 const wxArrayString& icondirs);
121 void LoadKDELinkFilesFromDir(const wxString& dirbase,
122 const wxArrayString& icondirs);
123 void GetKDEMimeInfo(const wxString& sExtraDir);
124
125 // write KDE
126 bool WriteKDEMimeFile(int index, bool delete_index);
127 bool CheckKDEDirsExist(const wxString & sOK, const wxString& sTest);
128
129 //read write Netscape and MetaMail formats
130 void GetMimeInfo (const wxString& sExtraDir);
131 bool WriteToMailCap (int index, bool delete_index);
132 bool WriteToMimeTypes (int index, bool delete_index);
133 bool WriteToNSMimeTypes (int index, bool delete_index);
134
135 // ReadMailcap() helper
136 bool ProcessOtherMailcapField(struct MailcapLineData& data,
137 const wxString& curField);
138
139 // functions used to do associations
140
141 int AddToMimeData(const wxString& strType,
142 const wxString& strIcon,
143 wxMimeTypeCommands *entry,
144 const wxArrayString& strExtensions,
145 const wxString& strDesc,
146 bool replaceExisting = TRUE);
147
148 bool DoAssociation(const wxString& strType,
149 const wxString& strIcon,
150 wxMimeTypeCommands *entry,
151 const wxArrayString& strExtensions,
152 const wxString& strDesc);
153
154 bool WriteMimeInfo(int nIndex, bool delete_mime );
155
156 // give it access to m_aXXX variables
157 friend class WXDLLEXPORT wxFileTypeImpl;
158 };
159
160
161
162 class WXDLLEXPORT wxFileTypeImpl
163 {
164 public:
165 // initialization functions
166 // this is used to construct a list of mimetypes which match;
167 // if built with GetFileTypeFromMimetype index 0 has the exact match and
168 // index 1 the type / * match
169 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
170 // the first extension found, index 1 for the second and so on
171
172 void Init(wxMimeTypesManagerImpl *manager, size_t index)
173 { m_manager = manager; m_index.Add(index); }
174
175 // accessors
176 bool GetExtensions(wxArrayString& extensions);
177 bool GetMimeType(wxString *mimeType) const
178 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
179 bool GetMimeTypes(wxArrayString& mimeTypes) const;
180 bool GetIcon(wxIcon *icon, wxString *iconFile = NULL,
181 int *iconIndex = NULL) const;
182
183 bool GetDescription(wxString *desc) const
184 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
185
186 bool GetOpenCommand(wxString *openCmd,
187 const wxFileType::MessageParameters& params) const
188 {
189 *openCmd = GetExpandedCommand(wxT("open"), params);
190 return (! openCmd -> IsEmpty() );
191 }
192
193 bool GetPrintCommand(wxString *printCmd,
194 const wxFileType::MessageParameters& params) const
195 {
196 *printCmd = GetExpandedCommand(wxT("print"), params);
197 return (! printCmd -> IsEmpty() );
198 }
199
200 // return the number of commands defined for this file type, 0 if none
201 size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands,
202 const wxFileType::MessageParameters& params) const;
203
204
205 // remove the record for this file type
206 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
207 bool Unassociate(wxFileType *ft)
208 {
209 return m_manager->Unassociate(ft);
210 }
211
212 // set an arbitrary command, ask confirmation if it already exists and
213 // overwriteprompt is TRUE
214 bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE);
215 bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
216
217 private:
218 wxString
219 GetExpandedCommand(const wxString & verb,
220 const wxFileType::MessageParameters& params) const;
221
222 wxMimeTypesManagerImpl *m_manager;
223 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
224 };
225
226 #endif
227 // wxUSE_FILE
228
229 #endif
230 //_MIMETYPE_IMPL_H
231