]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mimetype.h | |
e54c96f1 | 3 | // Purpose: interface of wxMimeTypesManager |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxMimeTypesManager | |
7c913512 | 11 | |
23324ae1 FM |
12 | This class allows the application to retrieve the information about all known |
13 | MIME types from a system-specific location and the filename extensions to the | |
14 | MIME types and vice versa. After initialization the functions | |
f369c7c2 | 15 | GetFileTypeFromMimeType() and GetFileTypeFromExtension() |
23324ae1 FM |
16 | may be called: they will return a wxFileType object which |
17 | may be further queried for file description, icon and other attributes. | |
7c913512 | 18 | |
f369c7c2 RR |
19 | Under Windows, the MIME type information is queried from registry. Under |
20 | Linux and Unix, it is queried from the XDG data directories. | |
21 | ||
22 | Currently, wxMimeTypesManager is limited to reading MIME type information. | |
7c913512 | 23 | |
f369c7c2 RR |
24 | The application should not construct its own manaer: it should use the |
25 | object pointer ::wxTheMimeTypesManger. | |
7c913512 | 26 | |
23324ae1 FM |
27 | @library{wxbase} |
28 | @category{misc} | |
7c913512 | 29 | |
e54c96f1 | 30 | @see wxFileType |
23324ae1 | 31 | */ |
7c913512 | 32 | class wxMimeTypesManager |
23324ae1 FM |
33 | { |
34 | public: | |
35 | /** | |
f369c7c2 | 36 | Constructor puts the object in the "working" state. |
23324ae1 FM |
37 | */ |
38 | wxMimeTypesManager(); | |
39 | ||
40 | /** | |
41 | Destructor is not virtual, so this class should not be derived from. | |
42 | */ | |
43 | ~wxMimeTypesManager(); | |
44 | ||
45 | /** | |
46 | This function may be used to provide hard-wired fallbacks for the MIME types | |
47 | and extensions that might not be present in the system MIME database. | |
23324ae1 FM |
48 | Please see the typetest sample for an example of using it. |
49 | */ | |
4cc4bfaf | 50 | void AddFallbacks(const wxFileTypeInfo* fallbacks); |
23324ae1 | 51 | |
23324ae1 FM |
52 | /** |
53 | Gather information about the files with given extension and return the | |
f369c7c2 RR |
54 | corresponding wxFileType object or @NULL if the extension is unknown. |
55 | ||
4cc4bfaf | 56 | The @a extension parameter may have, or not, the leading dot, if it has it, |
23324ae1 FM |
57 | it is stripped automatically. It must not however be empty. |
58 | */ | |
59 | wxFileType* GetFileTypeFromExtension(const wxString& extension); | |
60 | ||
61 | /** | |
62 | Gather information about the files with given MIME type and return the | |
f369c7c2 | 63 | corresponding wxFileType object or @NULL if the MIME type is unknown. |
23324ae1 FM |
64 | */ |
65 | wxFileType* GetFileTypeFromMimeType(const wxString& mimeType); | |
66 | ||
23324ae1 FM |
67 | |
68 | /** | |
4cc4bfaf FM |
69 | This function returns @true if either the given @a mimeType is exactly the |
70 | same as @a wildcard or if it has the same category and the subtype of | |
71 | @a wildcard is '*'. Note that the '*' wildcard is not allowed in | |
72 | @a mimeType itself. | |
23324ae1 FM |
73 | The comparison don by this function is case insensitive so it is not |
74 | necessary to convert the strings to the same case before calling it. | |
75 | */ | |
f369c7c2 | 76 | static bool IsOfType(const wxString& mimeType, const wxString& wildcard); |
23324ae1 | 77 | |
23324ae1 FM |
78 | }; |
79 | ||
80 | ||
f369c7c2 RR |
81 | /** |
82 | The global wxMimeTypesManager instance. | |
83 | */ | |
84 | wxMimeTypesManager* wxTheMimeTypesManager; | |
85 | ||
e54c96f1 | 86 | |
23324ae1 FM |
87 | /** |
88 | @class wxFileType | |
7c913512 | 89 | |
23324ae1 FM |
90 | This class holds information about a given @e file type. File type is the same |
91 | as | |
92 | MIME type under Unix, but under Windows it corresponds more to an extension than | |
93 | to MIME type (in fact, several extensions may correspond to a file type). This | |
94 | object may be created in several different ways: the program might know the file | |
95 | extension and wish to find out the corresponding MIME type or, conversely, it | |
96 | might want to find the right extension for the file to which it writes the | |
97 | contents of given MIME type. Depending on how it was created some fields may be | |
98 | unknown so the return value of all the accessors @b must be checked: @false | |
99 | will be returned if the corresponding information couldn't be found. | |
7c913512 | 100 | |
23324ae1 | 101 | The objects of this class are never created by the application code but are |
7c913512 | 102 | returned by wxMimeTypesManager::GetFileTypeFromMimeType and |
23324ae1 FM |
103 | wxMimeTypesManager::GetFileTypeFromExtension methods. |
104 | But it is your responsibility to delete the returned pointer when you're done | |
105 | with it! | |
7c913512 | 106 | |
23324ae1 FM |
107 | A brief reminder about what the MIME types are (see the RFC 1341 for more |
108 | information): basically, it is just a pair category/type (for example, | |
109 | "text/plain") where the category is a basic indication of what a file is. | |
110 | Examples of categories are "application", "image", "text", "binary", and | |
111 | type is a precise definition of the document format: "plain" in the example | |
112 | above means just ASCII text without any formatting, while "text/html" is the | |
113 | HTML document source. | |
7c913512 | 114 | |
23324ae1 FM |
115 | A MIME type may have one or more associated extensions: "text/plain" will |
116 | typically correspond to the extension ".txt", but may as well be associated with | |
117 | ".ini" or ".conf". | |
7c913512 | 118 | |
23324ae1 FM |
119 | @library{wxbase} |
120 | @category{FIXME} | |
7c913512 | 121 | |
e54c96f1 | 122 | @see wxMimeTypesManager |
23324ae1 | 123 | */ |
7c913512 | 124 | class wxFileType |
23324ae1 FM |
125 | { |
126 | public: | |
127 | /** | |
128 | The default constructor is private because you should never create objects of | |
129 | this type: they are only returned by wxMimeTypesManager methods. | |
130 | */ | |
131 | wxFileType(); | |
132 | ||
133 | /** | |
134 | The destructor of this class is not virtual, so it should not be derived from. | |
135 | */ | |
136 | ~wxFileType(); | |
137 | ||
138 | /** | |
139 | This function is primarily intended for GetOpenCommand and GetPrintCommand | |
140 | usage but may be also used by the application directly if, for example, you want | |
141 | to use some non-default command to open the file. | |
23324ae1 | 142 | The function replaces all occurrences of |
3c4f71cc | 143 | |
23324ae1 | 144 | format specification |
3c4f71cc | 145 | |
23324ae1 | 146 | with |
3c4f71cc | 147 | |
23324ae1 | 148 | %s |
3c4f71cc | 149 | |
23324ae1 | 150 | the full file name |
3c4f71cc | 151 | |
23324ae1 | 152 | %t |
3c4f71cc | 153 | |
23324ae1 | 154 | the MIME type |
3c4f71cc | 155 | |
23324ae1 | 156 | %{param} |
3c4f71cc | 157 | |
23324ae1 | 158 | the value of the parameter @e param |
3c4f71cc | 159 | |
23324ae1 | 160 | using the MessageParameters object you pass to it. |
23324ae1 FM |
161 | If there is no '%s' in the command string (and the string is not empty), it is |
162 | assumed that the command reads the data on stdin and so the effect is the same | |
163 | as " %s" were appended to the string. | |
23324ae1 FM |
164 | Unlike all other functions of this class, there is no error return for this |
165 | function. | |
166 | */ | |
167 | static wxString ExpandCommand(const wxString& command, | |
168 | MessageParameters& params); | |
169 | ||
170 | /** | |
4cc4bfaf | 171 | If the function returns @true, the string pointed to by @a desc is filled |
23324ae1 FM |
172 | with a brief description for this file type: for example, "text document" for |
173 | the "text/plain" MIME type. | |
174 | */ | |
175 | bool GetDescription(wxString* desc); | |
176 | ||
177 | /** | |
4cc4bfaf | 178 | If the function returns @true, the array @a extensions is filled |
23324ae1 FM |
179 | with all extensions associated with this file type: for example, it may |
180 | contain the following two elements for the MIME type "text/html" (notice the | |
181 | absence of the leading dot): "html" and "htm". | |
23324ae1 FM |
182 | @b Windows: This function is currently not implemented: there is no |
183 | (efficient) way to retrieve associated extensions from the given MIME type on | |
184 | this platform, so it will only return @true if the wxFileType object was | |
185 | created | |
7c913512 | 186 | by wxMimeTypesManager::GetFileTypeFromExtension |
23324ae1 FM |
187 | function in the first place. |
188 | */ | |
189 | bool GetExtensions(wxArrayString& extensions); | |
190 | ||
191 | /** | |
192 | If the function returns @true, the @c iconLoc is filled with the | |
193 | location of the icon for this MIME type. A wxIcon may be | |
4cc4bfaf | 194 | created from @a iconLoc later. |
23324ae1 FM |
195 | @b Windows: The function returns the icon shown by Explorer for the files of |
196 | the specified type. | |
23324ae1 | 197 | @b Mac: This function is not implemented and always returns @false. |
23324ae1 FM |
198 | @b Unix: MIME manager gathers information about icons from GNOME |
199 | and KDE settings and thus GetIcon's success depends on availability | |
200 | of these desktop environments. | |
201 | */ | |
4cc4bfaf | 202 | bool GetIcon(wxIconLocation* iconLoc); |
23324ae1 FM |
203 | |
204 | /** | |
4cc4bfaf | 205 | If the function returns @true, the string pointed to by @a mimeType is filled |
23324ae1 FM |
206 | with full MIME type specification for this file type: for example, "text/plain". |
207 | */ | |
208 | bool GetMimeType(wxString* mimeType); | |
209 | ||
210 | /** | |
211 | Same as GetMimeType() but returns array of MIME | |
212 | types. This array will contain only one item in most cases but sometimes, | |
213 | notably under Unix with KDE, may contain more MIME types. This happens when | |
214 | one file extension is mapped to different MIME types by KDE, mailcap and | |
215 | mime.types. | |
216 | */ | |
217 | bool GetMimeType(wxArrayString& mimeTypes); | |
218 | ||
219 | //@{ | |
220 | /** | |
221 | With the first version of this method, if the @true is returned, the | |
4cc4bfaf | 222 | string pointed to by @a command is filled with the command which must be |
e54c96f1 | 223 | executed (see wxExecute()) in order to open the file of the |
23324ae1 | 224 | given type. In this case, the name of the file as well as any other parameters |
7c913512 | 225 | is retrieved from MessageParameters() |
23324ae1 | 226 | class. |
23324ae1 FM |
227 | In the second case, only the filename is specified and the command to be used |
228 | to open this kind of file is returned directly. An empty string is returned to | |
229 | indicate that an error occurred (typically meaning that there is no standard way | |
230 | to open this kind of files). | |
231 | */ | |
232 | bool GetOpenCommand(wxString* command, | |
233 | MessageParameters& params); | |
7c913512 | 234 | wxString GetOpenCommand(const wxString& filename); |
23324ae1 FM |
235 | //@} |
236 | ||
237 | /** | |
4cc4bfaf | 238 | If the function returns @true, the string pointed to by @a command is filled |
e54c96f1 | 239 | with the command which must be executed (see wxExecute()) in |
23324ae1 FM |
240 | order to print the file of the given type. The name of the file is |
241 | retrieved from MessageParameters() class. | |
242 | */ | |
243 | bool GetPrintCommand(wxString* command, | |
244 | MessageParameters& params); | |
245 | ||
246 | /** | |
247 | One of the most common usages of MIME is to encode an e-mail message. The MIME | |
248 | type of the encoded message is an example of a @e message parameter. These | |
249 | parameters are found in the message headers ("Content-XXX"). At the very least, | |
250 | they must specify the MIME type and the version of MIME used, but almost always | |
251 | they provide additional information about the message such as the original file | |
252 | name or the charset (for the text documents). | |
23324ae1 FM |
253 | These parameters may be useful to the program used to open, edit, view or print |
254 | the message, so, for example, an e-mail client program will have to pass them to | |
255 | this program. Because wxFileType itself can not know about these parameters, | |
256 | it uses MessageParameters class to query them. The default implementation only | |
257 | requires the caller to provide the file name (always used by the program to be | |
258 | called - it must know which file to open) and the MIME type and supposes that | |
259 | there are no other parameters. If you wish to supply additional parameters, you | |
260 | must derive your own class from MessageParameters and override GetParamValue() | |
261 | function, for example: | |
3c4f71cc | 262 | |
23324ae1 FM |
263 | Now you only need to create an object of this class and pass it to, for example, |
264 | GetOpenCommand() like this: | |
3c4f71cc | 265 | |
23324ae1 FM |
266 | @b Windows: As only the file name is used by the program associated with the |
267 | given extension anyhow (but no other message parameters), there is no need to | |
268 | ever derive from MessageParameters class for a Windows-only program. | |
269 | */ | |
270 | }; | |
e54c96f1 | 271 |