]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mimetype.h
compile bug fix
[wxWidgets.git] / include / wx / mimetype.h
CommitLineData
b13d92d1
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/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
ce4169a4
RR
12#ifndef _MIMETYPE_H
13#define _MIMETYPE_H
b13d92d1 14
ecf23aa6
VS
15#ifdef __GNUG__
16#pragma interface "mimetypebase.h"
17#endif
18
19
b13d92d1
VZ
20// fwd decls
21class wxIcon;
22class wxFileTypeImpl;
23class wxMimeTypesManagerImpl;
24
ce4169a4
RR
25#include "wx/defs.h"
26
27#if wxUSE_FILE
28
b13d92d1
VZ
29// the things we really need
30#include "wx/string.h"
ecf23aa6 31#include "wx/dynarray.h"
b13d92d1 32
66806a0b
VS
33class wxMimeTypeCmnModule;
34
b13d92d1
VZ
35// This class holds information about a given "file type". File type is the
36// same as MIME type under Unix, but under Windows it corresponds more to an
37// extension than to MIME type (in fact, several extensions may correspond to a
38// file type). This object may be created in many different ways and depending
39// on how it was created some fields may be unknown so the return value of all
40// the accessors *must* be checked!
9f04ccb1 41class WXDLLEXPORT wxFileType
b13d92d1 42{
d5a07b9e 43friend class WXDLLEXPORT wxMimeTypesManagerImpl; // it has access to m_impl
b13d92d1
VZ
44
45public:
46 // An object of this class must be passed to Get{Open|Print}Command. The
47 // default implementation is trivial and doesn't know anything at all about
48 // parameters, only filename and MIME type are used (so it's probably ok for
49 // Windows where %{param} is not used anyhow)
50 class MessageParameters
51 {
52 public:
53 // ctors
54 MessageParameters() { }
55 MessageParameters(const wxString& filename, const wxString& mimetype)
56 : m_filename(filename), m_mimetype(mimetype) { }
57
58 // accessors (called by GetOpenCommand)
59 // filename
60 const wxString& GetFileName() const { return m_filename; }
61 // mime type
62 const wxString& GetMimeType() const { return m_mimetype; }
63
64 // override this function in derived class
c330a2cf 65 virtual wxString GetParamValue(const wxString& WXUNUSED(paramName)) const
b13d92d1
VZ
66 { return ""; }
67
68 // virtual dtor as in any base class
69 virtual ~MessageParameters() { }
70
71 protected:
72 wxString m_filename, m_mimetype;
73 };
74
75 // accessors: all of them return true if the corresponding information
76 // could be retrieved/found, false otherwise (and in this case all [out]
77 // parameters are unchanged)
78 // return the MIME type for this file type
79 bool GetMimeType(wxString *mimeType) const;
4d2976ad 80 bool GetMimeTypes(wxArrayString& mimeTypes) const;
b13d92d1
VZ
81 // fill passed in array with all extensions associated with this file
82 // type
83 bool GetExtensions(wxArrayString& extensions);
84 // get the icon corresponding to this file type
85 bool GetIcon(wxIcon *icon) const;
86 // get a brief file type description ("*.txt" => "text document")
87 bool GetDescription(wxString *desc) const;
88
89 // get the command to be used to open/print the given file.
90 // get the command to execute the file of given type
91 bool GetOpenCommand(wxString *openCmd,
92 const MessageParameters& params) const;
93 // get the command to print the file of given type
94 bool GetPrintCommand(wxString *printCmd,
95 const MessageParameters& params) const;
96
97 // operations
98 // expand a string in the format of GetOpenCommand (which may contain
99 // '%s' and '%t' format specificators for the file name and mime type
100 // and %{param} constructions).
101 static wxString ExpandCommand(const wxString& command,
102 const MessageParameters& params);
103
104 // dtor (not virtual, shouldn't be derived from)
105 ~wxFileType();
106
107private:
108 // default ctor is private because the user code never creates us
109 wxFileType();
110
111 // no copy ctor/assignment operator
112 wxFileType(const wxFileType&);
113 wxFileType& operator=(const wxFileType&);
114
115 wxFileTypeImpl *m_impl;
116};
117
71f21f46
VZ
118// This class is only used wuth wxMimeTypesManager::AddFallbacks() and is meant
119// just as the container for the wxFileType data.
120class WXDLLEXPORT wxFileTypeInfo
121{
122public:
123 // ctors
124 // a normal item
125 wxFileTypeInfo(const char *mimeType,
126 const char *openCmd,
127 const char *printCmd,
128 const char *desc,
129 // the other parameters form a NULL terminated list of
130 // extensions
131 ...);
8e124873 132
71f21f46
VZ
133 // invalid item - use this to terminate the array passed to
134 // wxMimeTypesManager::AddFallbacks
135 wxFileTypeInfo() { }
136
137 bool IsValid() const { return !m_mimeType.IsEmpty(); }
138
8e124873
VZ
139 // accessors
140 // get the MIME type
141 const wxString& GetMimeType() const { return m_mimeType; }
142 // get the open command
143 const wxString& GetOpenCommand() const { return m_openCmd; }
144 // get the print command
145 const wxString& GetPrintCommand() const { return m_printCmd; }
146 // get the description
147 const wxString& GetDescription() const { return m_desc; }
148 // get the array of all extensions
149 const wxArrayString& GetExtensions() const { return m_exts; }
150
71f21f46
VZ
151private:
152 wxString m_mimeType, // the MIME type in "type/subtype" form
153 m_openCmd, // command to use for opening the file (%s allowed)
154 m_printCmd, // command to use for printing the file (%s allowed)
155 m_desc; // a free form description of this file type
156
157 wxArrayString m_exts; // the extensions which are mapped on this filetype
158};
159
ecf23aa6
VS
160WX_DECLARE_EXPORTED_OBJARRAY(wxFileTypeInfo, wxArrayFileTypeInfo);
161
162
b13d92d1
VZ
163// This class accesses the information about all known MIME types and allows
164// the application to retrieve information (including how to handle data of
165// given type) about them.
166//
167// NB: currently it doesn't support modifying MIME database (read-only access).
9f04ccb1 168class WXDLLEXPORT wxMimeTypesManager
b13d92d1
VZ
169{
170public:
da61ab31
VZ
171 // static helper functions
172 // -----------------------
173
174 // check if the given MIME type is the same as the other one: the second
175 // argument may contain wildcards ('*'), but not the first. If the
176 // types are equal or if the mimeType matches wildcard the function
177 // returns TRUE, otherwise it returns FALSE
178 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
179
b13d92d1
VZ
180 // ctor
181 wxMimeTypesManager();
182
183 // Database lookup: all functions return a pointer to wxFileType object
184 // whose methods may be used to query it for the information you're
185 // interested in. If the return value is !NULL, caller is responsible for
186 // deleting it.
187 // get file type from file extension
188 wxFileType *GetFileTypeFromExtension(const wxString& ext);
189 // get file type from MIME type (in format <category>/<format>)
190 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
191
cc385968
VZ
192 // other operations: return TRUE if there were no errors or FALSE if there
193 // were some unreckognized entries (the good entries are always read anyhow)
b13d92d1
VZ
194 // read in additional file (the standard ones are read automatically)
195 // in mailcap format (see mimetype.cpp for description)
cc385968
VZ
196 //
197 // 'fallback' parameter may be set to TRUE to avoid overriding the
198 // settings from other, previously parsed, files by this one: normally,
199 // the files read most recently would override the older files, but with
200 // fallback == TRUE this won't happen
201 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
b13d92d1 202 // read in additional file in mime.types format
cc385968 203 bool ReadMimeTypes(const wxString& filename);
b13d92d1 204
696e1ea0 205 // enumerate all known MIME types
1b986aef
VZ
206 //
207 // returns the number of retrieved file types
696e1ea0 208 size_t EnumAllFileTypes(wxArrayString& mimetypes);
1b986aef 209
71f21f46
VZ
210 // these functions can be used to provide default values for some of the
211 // MIME types inside the program itself (you may also use
212 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
213 // achieve the same goal, but this requires having this info in a file).
214 //
215 // It isn't possible (currently) to provide fallback icons using this
216 // function.
217 //
218 // The filetypes array should be terminated by a NULL entry
8e124873 219 void AddFallbacks(const wxFileTypeInfo *filetypes);
71f21f46 220
b13d92d1
VZ
221 // dtor (not virtual, shouldn't be derived from)
222 ~wxMimeTypesManager();
223
224private:
225 // no copy ctor/assignment operator
226 wxMimeTypesManager(const wxMimeTypesManager&);
227 wxMimeTypesManager& operator=(const wxMimeTypesManager&);
228
229 wxMimeTypesManagerImpl *m_impl;
ecf23aa6
VS
230
231 // if m_impl is NULL, create one
232 void EnsureImpl();
66806a0b
VS
233
234 friend class wxMimeTypeCmnModule;
b13d92d1
VZ
235};
236
ecf23aa6
VS
237
238// ----------------------------------------------------------------------------
239// global variables
240// ----------------------------------------------------------------------------
241
242// the default mime manager for wxWindows programs
243WXDLLEXPORT_DATA(extern wxMimeTypesManager *) wxTheMimeTypesManager;
244
ce4169a4
RR
245#endif
246 // wxUSE_FILE
247
9f04ccb1 248#endif
ce4169a4 249 //_MIMETYPE_H
b13d92d1
VZ
250
251/* vi: set cin tw=80 ts=4 sw=4: */