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