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