]>
Commit | Line | Data |
---|---|---|
b13d92d1 VZ |
1 | \section{\class{wxMimeTypesManager}}\label{wxmimetypesmanager} |
2 | ||
3 | This class allows the application to retrieve the information about all known | |
4 | MIME types from a system-specific location and the filename extensions to the | |
5 | MIME types and vice versa. After initialization the functions | |
6 | \helpref{wxMimeTypesManager::GetFileTypeFromMimeType}{wxmimetypesmanagergetfiletypefrommimetype} | |
7 | and \helpref{wxMimeTypesManager::GetFileTypeFromExtension}{wxmimetypesmanagergetfiletypefromextension} | |
8 | may be called: they will return a \helpref{wxFileType}{wxfiletype} object which | |
9 | may be further queried for file description, icon and other attributes. | |
10 | ||
11 | {\bf Windows:} MIME type information is stored in the registry and no additional | |
12 | initialization is needed. | |
13 | ||
14 | {\bf Unix:} MIME type information is stored in the files mailcap and mime.types | |
15 | (system-wide) and .mailcap and .mime.types in the current user's home directory: | |
16 | all of these files are searched for and loaded if found by default. However, | |
17 | additional functions | |
cc385968 | 18 | \helpref{wxMimeTypesManager::ReadMailcap}{wxmimetypesmanagerreadmailcap} and |
b13d92d1 VZ |
19 | \helpref{wxMimeTypesManager::ReadMimeTypes}{wxmimetypesmanagerreadmimetypes} are |
20 | provided to load additional files. | |
21 | ||
cdf339c9 VS |
22 | If GNOME or KDE desktop environment is installed, then wxMimeTypesManager |
23 | gathers MIME information from respective files (e.g. .kdelnk files under KDE). | |
24 | ||
b13d92d1 | 25 | NB: Currently, wxMimeTypesManager is limited to reading MIME type information |
43e8916f | 26 | but it will support modifying it as well in future versions. |
b13d92d1 | 27 | |
d2a190fe VS |
28 | \wxheading{Global objects} |
29 | ||
30 | Global instance of wxMimeTypesManager is always available. It is defined | |
31 | as follows: | |
32 | ||
33 | \begin{verbatim} | |
34 | wxMimeTypesManager *wxTheMimeTypesManager; | |
35 | \end{verbatim} | |
36 | ||
37 | It is recommended to use this instance instead of creating your own because | |
08890e27 | 38 | gathering MIME information may take quite a long time on Unix systems. |
d2a190fe | 39 | |
b13d92d1 VZ |
40 | \wxheading{Derived from} |
41 | ||
42 | No base class. | |
43 | ||
954b8ae6 JS |
44 | \wxheading{Include files} |
45 | ||
46 | <wx/mimetype.h> | |
47 | ||
b13d92d1 VZ |
48 | \wxheading{See also} |
49 | ||
50 | \helpref{wxFileType}{wxfiletype} | |
51 | ||
52 | \latexignore{\rtfignore{\wxheading{Function groups}}} | |
53 | ||
dcbd177f | 54 | \membersection{Helper functions}\label{mimehelperfunctions} |
a5a19b83 VZ |
55 | |
56 | All of these functions are static (i.e. don't need a wxMimeTypesManager object | |
57 | to call them) and provide some useful operations for string representations of | |
58 | MIME types. Their usage is recommended instead of directly working with MIME | |
59 | types using wxString functions. | |
60 | ||
61 | \helpref{IsOfType}{wxmimetypesmanagerisoftype} | |
62 | ||
dcbd177f | 63 | \membersection{Constructor and destructor}\label{mimeconstructordestructor} |
b13d92d1 VZ |
64 | |
65 | NB: You won't normally need to use more than one wxMimeTypesManager object in a | |
66 | program. | |
67 | ||
68 | \helpref{wxMimeTypesManager}{wxmimetypesmanagerctor}\\ | |
69 | \helpref{\destruct{wxMimeTypesManager}}{wxmimetypesmanagerdtor} | |
70 | ||
dcbd177f | 71 | \membersection{Query database}\label{mimequerydatabase} |
b13d92d1 | 72 | |
2432b92d JS |
73 | These functions are the heart of this class: they allow to find a \helpref{file type}{wxfiletype} object |
74 | from either file extension or MIME type. | |
b13d92d1 | 75 | If the function is successful, it returns a pointer to the wxFileType object |
2432b92d | 76 | which {\bf must} be deleted by the caller, otherwise NULL will be returned. |
b13d92d1 VZ |
77 | |
78 | \helpref{GetFileTypeFromMimeType}{wxmimetypesmanagergetfiletypefrommimetype}\\ | |
79 | \helpref{GetFileTypeFromExtension}{wxmimetypesmanagergetfiletypefromextension} | |
80 | ||
2432b92d | 81 | \membersection{Initialization functions}\label{wxmimetypesmanagerinit} |
b13d92d1 | 82 | |
2432b92d JS |
83 | {\bf Unix:} These functions may be used to load additional files (except for the |
84 | default ones which are loaded automatically) containing MIME | |
b13d92d1 VZ |
85 | information in either mailcap(5) or mime.types(5) format. |
86 | ||
87 | \helpref{ReadMailcap}{wxmimetypesmanagerreadmailcap}\\ | |
8e124873 VZ |
88 | \helpref{ReadMimeTypes}{wxmimetypesmanagerreadmimetypes}\\ |
89 | \helpref{AddFallbacks}{wxmimetypesmanageraddfallbacks} | |
b13d92d1 VZ |
90 | |
91 | %%%%% MEMBERS HERE %%%%% | |
92 | \helponly{\insertatlevel{2}{ | |
93 | ||
94 | \wxheading{Members} | |
95 | ||
96 | }} | |
97 | ||
98 | \membersection{wxMimeTypesManager::wxMimeTypesManager}\label{wxmimetypesmanagerctor} | |
2432b92d | 99 | |
b13d92d1 VZ |
100 | \func{}{wxMimeTypesManager}{\void} |
101 | ||
102 | Constructor puts the object in the "working" state, no additional initialization | |
103 | are needed - but \helpref{ReadXXX}{wxmimetypesmanagerinit} may be used to load | |
104 | additional mailcap/mime.types files. | |
105 | ||
106 | \membersection{wxMimeTypesManager::\destruct{wxMimeTypesManager}}\label{wxmimetypesmanagerdtor} | |
2432b92d JS |
107 | |
108 | \func{}{\destruct{wxMimeTypesManager}}{\void} | |
b13d92d1 VZ |
109 | |
110 | Destructor is not virtual, so this class should not be derived from. | |
111 | ||
8e124873 VZ |
112 | \membersection{wxMimeTypesManager::AddFallbacks}\label{wxmimetypesmanageraddfallbacks} |
113 | ||
114 | \func{void}{AddFallbacks}{\param{const wxFileTypeInfo *}{fallbacks}} | |
115 | ||
2edb0bde | 116 | This function may be used to provide hard-wired fallbacks for the MIME types |
8e124873 VZ |
117 | and extensions that might not be present in the system MIME database. |
118 | ||
119 | % TODO | |
120 | ||
121 | Please see the typetest sample for an example of using it. | |
122 | ||
b13d92d1 | 123 | \membersection{wxMimeTypesManager::GetFileTypeFromExtension}\label{wxmimetypesmanagergetfiletypefromextension} |
2432b92d JS |
124 | |
125 | \func{wxFileType*}{GetFileTypeFromExtension}{\param{const wxString\&}{ extension}} | |
b13d92d1 VZ |
126 | |
127 | Gather information about the files with given extension and return the | |
128 | corresponding \helpref{wxFileType}{wxfiletype} object or NULL if the extension | |
129 | is unknown. | |
130 | ||
131 | \membersection{wxMimeTypesManager::GetFileTypeFromMimeType}\label{wxmimetypesmanagergetfiletypefrommimetype} | |
2432b92d JS |
132 | |
133 | \func{wxFileType*}{GetFileTypeFromMimeType}{\param{const wxString\&}{ mimeType}} | |
b13d92d1 VZ |
134 | |
135 | Gather information about the files with given MIME type and return the | |
136 | corresponding \helpref{wxFileType}{wxfiletype} object or NULL if the MIME type | |
137 | is unknown. | |
138 | ||
a5a19b83 VZ |
139 | \membersection{wxMimeTypesManager::IsOfType}\label{wxmimetypesmanagerisoftype} |
140 | ||
141 | \func{bool}{IsOfType}{\param{const wxString\&}{ mimeType}, \param{const wxString\&}{ wildcard}} | |
142 | ||
cc81d32f | 143 | This function returns true if either the given {\it mimeType} is exactly the |
a5a19b83 VZ |
144 | same as {\it wildcard} or if it has the same category and the subtype of |
145 | {\it wildcard} is '*'. Note that the '*' wildcard is not allowed in | |
146 | {\it mimeType} itself. | |
147 | ||
2edb0bde | 148 | The comparison don by this function is case insensitive so it is not |
a5a19b83 VZ |
149 | necessary to convert the strings to the same case before calling it. |
150 | ||
b13d92d1 | 151 | \membersection{wxMimeTypesManager::ReadMailcap}\label{wxmimetypesmanagerreadmailcap} |
2432b92d | 152 | |
cc81d32f | 153 | \func{bool}{ReadMailcap}{\param{const wxString\&}{ filename}, \param{bool}{ fallback = false}} |
b13d92d1 VZ |
154 | |
155 | Load additional file containing information about MIME types and associated | |
156 | information in mailcap format. See metamail(1) and mailcap(5) for more | |
157 | information. | |
158 | ||
cc385968 VZ |
159 | {\it fallback} parameter may be used to load additional mailcap files without |
160 | overriding the settings found in the standard files: normally, entries from | |
161 | files loaded with ReadMailcap will override the entries from files loaded | |
162 | previously (and the standard ones are loaded in the very beginning), but this | |
cc81d32f | 163 | will not happen if this parameter is set to true (default is false). |
cc385968 | 164 | |
cc81d32f | 165 | The return value is true if there were no errors in the file or false |
cc385968 VZ |
166 | otherwise. |
167 | ||
b13d92d1 | 168 | \membersection{wxMimeTypesManager::ReadMimeTypes}\label{wxmimetypesmanagerreadmimetypes} |
2432b92d | 169 | |
cc385968 | 170 | \func{bool}{ReadMimeTypes}{\param{const wxString\&}{ filename}} |
b13d92d1 VZ |
171 | |
172 | Load additional file containing information about MIME types and associated | |
173 | information in mime.types file format. See metamail(1) and mailcap(5) for more | |
174 | information. | |
2432b92d | 175 | |
cc81d32f | 176 | The return value is true if there were no errors in the file or false |
cc385968 VZ |
177 | otherwise. |
178 |