MIME classes with docs (not yet added to the makefiles)
[wxWidgets.git] / include / wx / mimetype.h
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
12 #ifndef _MIMETYPE_H
13 #define _MIMETYPE_H
14
15 // fwd decls
16 class wxIcon;
17 class wxFileTypeImpl;
18 class wxMimeTypesManagerImpl;
19
20 // the things we really need
21 #include "wx/string.h"
22
23 // This class holds information about a given "file type". File type is the
24 // same as MIME type under Unix, but under Windows it corresponds more to an
25 // extension than to MIME type (in fact, several extensions may correspond to a
26 // file type). This object may be created in many different ways and depending
27 // on how it was created some fields may be unknown so the return value of all
28 // the accessors *must* be checked!
29 class wxFileType
30 {
31 friend wxMimeTypesManagerImpl; // it has access to m_impl
32
33 public:
34 // An object of this class must be passed to Get{Open|Print}Command. The
35 // default implementation is trivial and doesn't know anything at all about
36 // parameters, only filename and MIME type are used (so it's probably ok for
37 // Windows where %{param} is not used anyhow)
38 class MessageParameters
39 {
40 public:
41 // ctors
42 MessageParameters() { }
43 MessageParameters(const wxString& filename, const wxString& mimetype)
44 : m_filename(filename), m_mimetype(mimetype) { }
45
46 // accessors (called by GetOpenCommand)
47 // filename
48 const wxString& GetFileName() const { return m_filename; }
49 // mime type
50 const wxString& GetMimeType() const { return m_mimetype; }
51
52 // override this function in derived class
53 virtual wxString GetParamValue(const wxString& paramName) const
54 { return ""; }
55
56 // virtual dtor as in any base class
57 virtual ~MessageParameters() { }
58
59 protected:
60 wxString m_filename, m_mimetype;
61 };
62
63 // accessors: all of them return true if the corresponding information
64 // could be retrieved/found, false otherwise (and in this case all [out]
65 // parameters are unchanged)
66 // return the MIME type for this file type
67 bool GetMimeType(wxString *mimeType) const;
68 // fill passed in array with all extensions associated with this file
69 // type
70 bool GetExtensions(wxArrayString& extensions);
71 // get the icon corresponding to this file type
72 bool GetIcon(wxIcon *icon) const;
73 // get a brief file type description ("*.txt" => "text document")
74 bool GetDescription(wxString *desc) const;
75
76 // get the command to be used to open/print the given file.
77 // get the command to execute the file of given type
78 bool GetOpenCommand(wxString *openCmd,
79 const MessageParameters& params) const;
80 // get the command to print the file of given type
81 bool GetPrintCommand(wxString *printCmd,
82 const MessageParameters& params) const;
83
84 // operations
85 // expand a string in the format of GetOpenCommand (which may contain
86 // '%s' and '%t' format specificators for the file name and mime type
87 // and %{param} constructions).
88 static wxString ExpandCommand(const wxString& command,
89 const MessageParameters& params);
90
91 // dtor (not virtual, shouldn't be derived from)
92 ~wxFileType();
93
94 private:
95 // default ctor is private because the user code never creates us
96 wxFileType();
97
98 // no copy ctor/assignment operator
99 wxFileType(const wxFileType&);
100 wxFileType& operator=(const wxFileType&);
101
102 wxFileTypeImpl *m_impl;
103 };
104
105 // This class accesses the information about all known MIME types and allows
106 // the application to retrieve information (including how to handle data of
107 // given type) about them.
108 //
109 // NB: currently it doesn't support modifying MIME database (read-only access).
110 class wxMimeTypesManager
111 {
112 public:
113 // ctor
114 wxMimeTypesManager();
115
116 // Database lookup: all functions return a pointer to wxFileType object
117 // whose methods may be used to query it for the information you're
118 // interested in. If the return value is !NULL, caller is responsible for
119 // deleting it.
120 // get file type from file extension
121 wxFileType *GetFileTypeFromExtension(const wxString& ext);
122 // get file type from MIME type (in format <category>/<format>)
123 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
124
125 // other operations
126 // read in additional file (the standard ones are read automatically)
127 // in mailcap format (see mimetype.cpp for description)
128 void ReadMailcap(const wxString& filename);
129 // read in additional file in mime.types format
130 void ReadMimeTypes(const wxString& filename);
131
132 // dtor (not virtual, shouldn't be derived from)
133 ~wxMimeTypesManager();
134
135 private:
136 // no copy ctor/assignment operator
137 wxMimeTypesManager(const wxMimeTypesManager&);
138 wxMimeTypesManager& operator=(const wxMimeTypesManager&);
139
140 wxMimeTypesManagerImpl *m_impl;
141 };
142
143 #endif //_MIMETYPE_H
144
145 /* vi: set cin tw=80 ts=4 sw=4: */