]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/mimetype.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
18 class wxMimeTypesManagerImpl
;
24 // the things we really need
25 #include "wx/string.h"
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!
35 friend wxMimeTypesManagerImpl
; // it has access to m_impl
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
46 MessageParameters() { }
47 MessageParameters(const wxString
& filename
, const wxString
& mimetype
)
48 : m_filename(filename
), m_mimetype(mimetype
) { }
50 // accessors (called by GetOpenCommand)
52 const wxString
& GetFileName() const { return m_filename
; }
54 const wxString
& GetMimeType() const { return m_mimetype
; }
56 // override this function in derived class
57 virtual wxString
GetParamValue(const wxString
& WXUNUSED(paramName
)) const
60 // virtual dtor as in any base class
61 virtual ~MessageParameters() { }
64 wxString m_filename
, m_mimetype
;
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
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;
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;
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
);
95 // dtor (not virtual, shouldn't be derived from)
99 // default ctor is private because the user code never creates us
102 // no copy ctor/assignment operator
103 wxFileType(const wxFileType
&);
104 wxFileType
& operator=(const wxFileType
&);
106 wxFileTypeImpl
*m_impl
;
109 // This class accesses the information about all known MIME types and allows
110 // the application to retrieve information (including how to handle data of
111 // given type) about them.
113 // NB: currently it doesn't support modifying MIME database (read-only access).
114 class wxMimeTypesManager
117 // static helper functions
118 // -----------------------
120 // check if the given MIME type is the same as the other one: the second
121 // argument may contain wildcards ('*'), but not the first. If the
122 // types are equal or if the mimeType matches wildcard the function
123 // returns TRUE, otherwise it returns FALSE
124 static bool IsOfType(const wxString
& mimeType
, const wxString
& wildcard
);
127 wxMimeTypesManager();
129 // Database lookup: all functions return a pointer to wxFileType object
130 // whose methods may be used to query it for the information you're
131 // interested in. If the return value is !NULL, caller is responsible for
133 // get file type from file extension
134 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
135 // get file type from MIME type (in format <category>/<format>)
136 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
138 // other operations: return TRUE if there were no errors or FALSE if there
139 // were some unreckognized entries (the good entries are always read anyhow)
140 // read in additional file (the standard ones are read automatically)
141 // in mailcap format (see mimetype.cpp for description)
143 // 'fallback' parameter may be set to TRUE to avoid overriding the
144 // settings from other, previously parsed, files by this one: normally,
145 // the files read most recently would override the older files, but with
146 // fallback == TRUE this won't happen
147 bool ReadMailcap(const wxString
& filename
, bool fallback
= FALSE
);
148 // read in additional file in mime.types format
149 bool ReadMimeTypes(const wxString
& filename
);
151 // dtor (not virtual, shouldn't be derived from)
152 ~wxMimeTypesManager();
155 // no copy ctor/assignment operator
156 wxMimeTypesManager(const wxMimeTypesManager
&);
157 wxMimeTypesManager
& operator=(const wxMimeTypesManager
&);
159 wxMimeTypesManagerImpl
*m_impl
;
168 /* vi: set cin tw=80 ts=4 sw=4: */