]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_mimetype.i
reSWIGged
[wxWidgets.git] / wxPython / src / _mimetype.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _joystick.i
3 // Purpose: SWIG interface stuff for wxJoystick
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 18-June-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19 %{
20 #include <wx/mimetype.h>
21 %}
22
23 //---------------------------------------------------------------------------
24
25 enum wxMailcapStyle
26 {
27 wxMAILCAP_STANDARD = 1,
28 wxMAILCAP_NETSCAPE = 2,
29 wxMAILCAP_KDE = 4,
30 wxMAILCAP_GNOME = 8,
31
32 wxMAILCAP_ALL = 15
33 };
34
35
36
37
38 // wxFileTypeInfo: static container of information accessed via wxFileType.
39 class wxFileTypeInfo
40 {
41 public:
42 // a normal item
43 wxFileTypeInfo(const wxString& mimeType,
44 const wxString& openCmd,
45 const wxString& printCmd,
46 const wxString& desc);
47
48
49 // the array elements correspond to the parameters of the ctor above in
50 // the same order
51 %Rename(FileTypeInfoSequence,, wxFileTypeInfo(const wxArrayString& sArray));
52
53 // invalid item - use this to terminate the array passed to
54 // wxMimeTypesManager::AddFallbacks
55 %Rename(NullFileTypeInfo,, wxFileTypeInfo());
56
57
58 // test if this object can be used
59 bool IsValid() const;
60
61 // set the icon info
62 void SetIcon(const wxString& iconFile, int iconIndex = 0);
63
64 // set the short desc
65 void SetShortDesc(const wxString& shortDesc);
66
67 // get the MIME type
68 const wxString& GetMimeType() const;
69
70 // get the open command
71 const wxString& GetOpenCommand() const;
72
73 // get the print command
74 const wxString& GetPrintCommand() const;
75
76 // get the short description (only used under Win32 so far)
77 const wxString& GetShortDesc() const;
78
79 // get the long, user visible description
80 const wxString& GetDescription() const;
81
82 // get the array of all extensions
83 const wxArrayString& GetExtensions() const;
84 int GetExtensionsCount() const;
85
86 // get the icon info
87 const wxString& GetIconFile() const;
88 int GetIconIndex() const;
89 };
90
91
92
93 //---------------------------------------------------------------------------
94
95 // wxFileType: gives access to all information about the files of given type.
96 //
97 // This class holds information about a given "file type". File type is the
98 // same as MIME type under Unix, but under Windows it corresponds more to an
99 // extension than to MIME type (in fact, several extensions may correspond to a
100 // file type). This object may be created in many different ways and depending
101 // on how it was created some fields may be unknown so the return value of all
102 // the accessors *must* be checked!
103 class wxFileType
104 {
105 public:
106
107 // // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
108
109 // // An object of this class must be passed to Get{Open|Print}Command. The
110 // // default implementation is trivial and doesn't know anything at all about
111 // // parameters, only filename and MIME type are used (so it's probably ok for
112 // // Windows where %{param} is not used anyhow)
113 // class MessageParameters
114 // {
115 // public:
116 // // ctors
117 // MessageParameters(const wxString& filename=wxPyEmptyString,
118 // const wxString& mimetype=wxPyEmptyString);
119
120 // // accessors (called by GetOpenCommand)
121 // // filename
122 // const wxString& GetFileName() const;
123 // // mime type
124 // const wxString& GetMimeType() const;;
125
126 // // override this function in derived class
127 // virtual wxString GetParamValue(const wxString& name) const;
128
129 // // virtual dtor as in any base class
130 // virtual ~MessageParameters();
131 // };
132
133
134 // ctor from static data
135 wxFileType(const wxFileTypeInfo& ftInfo);
136 ~wxFileType();
137
138
139 // return the MIME type for this file type
140 %extend {
141 PyObject* GetMimeType() {
142 wxString str;
143 if (self->GetMimeType(&str))
144 return wx2PyString(str);
145 else
146 RETURN_NONE();
147 }
148
149 PyObject* GetMimeTypes() {
150 wxArrayString arr;
151 if (self->GetMimeTypes(arr))
152 return wxArrayString2PyList_helper(arr);
153 else
154 RETURN_NONE();
155 }
156 }
157
158
159 // Get all extensions associated with this file type
160 %extend {
161 PyObject* GetExtensions() {
162 wxArrayString arr;
163 if (self->GetExtensions(arr))
164 return wxArrayString2PyList_helper(arr);
165 else
166 RETURN_NONE();
167 }
168 }
169
170
171 %extend {
172 // Get the icon corresponding to this file type
173 %newobject GetIcon;
174 wxIcon* GetIcon() {
175 wxIconLocation loc;
176 if (self->GetIcon(&loc))
177 return new wxIcon(loc);
178 else
179 return NULL;
180 }
181
182 // Get the icon corresponding to this file type, the name of the file
183 // where this icon resides, and its index in this file if applicable.
184 PyObject* GetIconInfo() {
185 wxIconLocation loc;
186 if (self->GetIcon(&loc)) {
187 wxString iconFile = loc.GetFileName();
188 int iconIndex = -1;
189 #ifdef __WXMSW__
190 iconIndex = loc.GetIndex();
191 #endif
192 // Make a tuple and put the values in it
193 wxPyBlock_t blocked = wxPyBeginBlockThreads();
194 PyObject* tuple = PyTuple_New(3);
195 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(loc),
196 wxT("wxIcon"), true));
197 PyTuple_SetItem(tuple, 1, wx2PyString(iconFile));
198 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
199 wxPyEndBlockThreads(blocked);
200 return tuple;
201 }
202 else
203 RETURN_NONE();
204 }
205 }
206
207 %extend {
208 // get a brief file type description ("*.txt" => "text document")
209 PyObject* GetDescription() {
210 wxString str;
211 if (self->GetDescription(&str))
212 return wx2PyString(str);
213 else
214 RETURN_NONE();
215 }
216 }
217
218
219 // get the command to open/execute the file of given type
220 %extend {
221 PyObject* GetOpenCommand(const wxString& filename,
222 const wxString& mimetype=wxPyEmptyString) {
223 wxString str;
224 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
225 return wx2PyString(str);
226 else
227 RETURN_NONE();
228 }
229 }
230
231
232 // get the command to print the file of given type
233 %extend {
234 PyObject* GetPrintCommand(const wxString& filename,
235 const wxString& mimetype=wxPyEmptyString) {
236 wxString str;
237 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
238 return wx2PyString(str);
239 else
240 RETURN_NONE();
241 }
242 }
243
244
245 // Get all commands defined for this file type
246 %extend {
247 PyObject* GetAllCommands(const wxString& filename,
248 const wxString& mimetype=wxPyEmptyString) {
249 wxArrayString verbs;
250 wxArrayString commands;
251 if (self->GetAllCommands(&verbs, &commands,
252 wxFileType::MessageParameters(filename, mimetype))) {
253 wxPyBlock_t blocked = wxPyBeginBlockThreads();
254 PyObject* tuple = PyTuple_New(2);
255 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
256 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
257 wxPyEndBlockThreads(blocked);
258 return tuple;
259 }
260 else
261 RETURN_NONE();
262 }
263 }
264
265
266 // set an arbitrary command, ask confirmation if it already exists and
267 // overwriteprompt is True
268 bool SetCommand(const wxString& cmd, const wxString& verb,
269 bool overwriteprompt = true);
270
271 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
272
273
274 // remove the association for this filetype from the system MIME database:
275 // notice that it will only work if the association is defined in the user
276 // file/registry part, we will never modify the system-wide settings
277 bool Unassociate();
278
279 // operations
280 // expand a string in the format of GetOpenCommand (which may contain
281 // '%s' and '%t' format specificators for the file name and mime type
282 // and %{param} constructions).
283 %extend {
284 static wxString ExpandCommand(const wxString& command,
285 const wxString& filename,
286 const wxString& mimetype=wxPyEmptyString) {
287 return wxFileType::ExpandCommand(command,
288 wxFileType::MessageParameters(filename, mimetype));
289 }
290 }
291
292 };
293
294
295
296 //---------------------------------------------------------------------------
297
298 // See also wxPy_ReinitStockObjects in helpers.cpp
299 wxMimeTypesManager* const wxTheMimeTypesManager;
300
301
302 // wxMimeTypesManager: interface to system MIME database.
303 //
304 // This class accesses the information about all known MIME types and allows
305 // the application to retrieve information (including how to handle data of
306 // given type) about them.
307 class wxMimeTypesManager
308 {
309 public:
310 // static helper functions
311 // -----------------------
312
313 // check if the given MIME type is the same as the other one: the
314 // second argument may contain wildcards ('*'), but not the first. If
315 // the types are equal or if the mimeType matches wildcard the function
316 // returns True, otherwise it returns False
317 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
318
319 // ctor
320 wxMimeTypesManager();
321
322 // loads data from standard files according to the mailcap styles
323 // specified: this is a bitwise OR of wxMailcapStyle values
324 //
325 // use the extraDir parameter if you want to look for files in another
326 // directory
327 void Initialize(int mailcapStyle = wxMAILCAP_ALL,
328 const wxString& extraDir = wxPyEmptyString);
329
330 // and this function clears all the data from the manager
331 void ClearData();
332
333 // Database lookup: all functions return a pointer to wxFileType object
334 // whose methods may be used to query it for the information you're
335 // interested in. If the return value is !NULL, caller is responsible for
336 // deleting it.
337 // get file type from file extension
338 %newobject GetFileTypeFromExtension;
339 wxFileType *GetFileTypeFromExtension(const wxString& ext);
340
341 // get file type from MIME type (in format <category>/<format>)
342 %newobject GetFileTypeFromMimeType;
343 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
344
345 // other operations: return True if there were no errors or False if there
346 // were some unrecognized entries (the good entries are always read anyhow)
347 //
348
349 // read in additional file (the standard ones are read automatically)
350 // in mailcap format (see mimetype.cpp for description)
351 //
352 // 'fallback' parameter may be set to True to avoid overriding the
353 // settings from other, previously parsed, files by this one: normally,
354 // the files read most recently would override the older files, but with
355 // fallback == True this won't happen
356 bool ReadMailcap(const wxString& filename, bool fallback = false);
357
358 // read in additional file in mime.types format
359 bool ReadMimeTypes(const wxString& filename);
360
361 // enumerate all known MIME types
362 %extend {
363 PyObject* EnumAllFileTypes() {
364 wxArrayString arr;
365 self->EnumAllFileTypes(arr);
366 return wxArrayString2PyList_helper(arr);
367 }
368 }
369
370 // these functions can be used to provide default values for some of the
371 // MIME types inside the program itself (you may also use
372 // ReadMailcap(filenameWithDefaultTypes, True /* use as fallback */) to
373 // achieve the same goal, but this requires having this info in a file).
374 //
375 void AddFallback(const wxFileTypeInfo& ft);
376
377
378 // create or remove associations
379
380 // create a new association using the fields of wxFileTypeInfo (at least
381 // the MIME type and the extension should be set)
382 // if the other fields are empty, the existing values should be left alone
383 %newobject Associate;
384 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
385
386 // undo Associate()
387 bool Unassociate(wxFileType *ft) ;
388
389 ~wxMimeTypesManager();
390 };
391
392 //---------------------------------------------------------------------------
393
394 //---------------------------------------------------------------------------
395 //---------------------------------------------------------------------------