]>
Commit | Line | Data |
---|---|---|
7dc3cc31 | 1 | ///////////////////////////////////////////////////////////////////////////// |
678ebfcd | 2 | // Name: wx/unix/mimetype.h |
7dc3cc31 VS |
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> | |
65571936 | 9 | // Licence: wxWindows licence (part of wxExtra library) |
7dc3cc31 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _MIMETYPE_IMPL_H | |
13 | #define _MIMETYPE_IMPL_H | |
14 | ||
7dc3cc31 VS |
15 | #include "wx/mimetype.h" |
16 | ||
0d2c74c6 | 17 | #if wxUSE_MIMETYPE |
7dc3cc31 | 18 | |
678ebfcd | 19 | class wxMimeTypeCommands; |
7dc3cc31 | 20 | |
0d2c74c6 | 21 | WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray); |
7dc3cc31 VS |
22 | |
23 | // this is the real wxMimeTypesManager for Unix | |
09902c51 | 24 | class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl |
7dc3cc31 | 25 | { |
7dc3cc31 | 26 | public: |
a6c65e88 | 27 | // ctor and dtor |
7dc3cc31 | 28 | wxMimeTypesManagerImpl(); |
2b850ae1 | 29 | virtual ~wxMimeTypesManagerImpl(); |
a6c65e88 VZ |
30 | |
31 | // load all data into memory - done when it is needed for the first time | |
805f26b3 | 32 | void Initialize(int mailcapStyles = wxMAILCAP_ALL, |
2b813b73 VZ |
33 | const wxString& extraDir = wxEmptyString); |
34 | ||
35 | // and delete the data here | |
36 | void ClearData(); | |
7dc3cc31 VS |
37 | |
38 | // implement containing class functions | |
39 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
40 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); | |
41 | ||
42 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
43 | ||
7dc3cc31 VS |
44 | void AddFallback(const wxFileTypeInfo& filetype); |
45 | ||
46 | // add information about the given mimetype | |
47 | void AddMimeTypeInfo(const wxString& mimetype, | |
48 | const wxString& extensions, | |
49 | const wxString& description); | |
50 | void AddMailcapInfo(const wxString& strType, | |
51 | const wxString& strOpenCmd, | |
52 | const wxString& strPrintCmd, | |
53 | const wxString& strTest, | |
54 | const wxString& strDesc); | |
55 | ||
a6c65e88 VZ |
56 | // add a new record to the user .mailcap/.mime.types files |
57 | wxFileType *Associate(const wxFileTypeInfo& ftInfo); | |
2b813b73 VZ |
58 | // remove association |
59 | bool Unassociate(wxFileType *ft); | |
a6c65e88 | 60 | |
7dc3cc31 VS |
61 | // accessors |
62 | // get the string containing space separated extensions for the given | |
63 | // file type | |
64 | wxString GetExtension(size_t index) { return m_aExtensions[index]; } | |
65 | ||
2b850ae1 | 66 | protected: |
6d718495 | 67 | void InitIfNeeded(); |
a6c65e88 | 68 | |
7dc3cc31 VS |
69 | wxArrayString m_aTypes, // MIME types |
70 | m_aDescriptions, // descriptions (just some text) | |
2b813b73 VZ |
71 | m_aExtensions, // space separated list of extensions |
72 | m_aIcons; // Icon filenames | |
73 | ||
74 | // verb=command pairs for this file type | |
678ebfcd | 75 | wxMimeCommandsArray m_aEntries; |
7dc3cc31 | 76 | |
a6c65e88 VZ |
77 | // are we initialized? |
78 | bool m_initialized; | |
79 | ||
2b813b73 VZ |
80 | wxString GetCommand(const wxString &verb, size_t nIndex) const; |
81 | ||
31383ebc RR |
82 | void LoadKDEApp(const wxString& filename); |
83 | void LoadKDEAppsFilesFromDir(const wxString& dirname); | |
2b813b73 VZ |
84 | |
85 | // write KDE | |
86 | bool WriteKDEMimeFile(int index, bool delete_index); | |
87 | bool CheckKDEDirsExist(const wxString & sOK, const wxString& sTest); | |
88 | ||
2b813b73 | 89 | // functions used to do associations |
2b850ae1 | 90 | virtual int AddToMimeData(const wxString& strType, |
2b813b73 | 91 | const wxString& strIcon, |
678ebfcd | 92 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
93 | const wxArrayString& strExtensions, |
94 | const wxString& strDesc, | |
95 | bool replaceExisting = TRUE); | |
2b850ae1 | 96 | virtual bool DoAssociation(const wxString& strType, |
2b813b73 | 97 | const wxString& strIcon, |
678ebfcd | 98 | wxMimeTypeCommands *entry, |
2b813b73 VZ |
99 | const wxArrayString& strExtensions, |
100 | const wxString& strDesc); | |
101 | ||
2b850ae1 | 102 | virtual bool WriteMimeInfo(int nIndex, bool delete_mime ); |
a6c65e88 VZ |
103 | |
104 | // give it access to m_aXXX variables | |
4f7d425f | 105 | friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl; |
7dc3cc31 VS |
106 | }; |
107 | ||
09902c51 | 108 | class WXDLLIMPEXP_BASE wxFileTypeImpl |
7dc3cc31 VS |
109 | { |
110 | public: | |
111 | // initialization functions | |
2b813b73 VZ |
112 | // this is used to construct a list of mimetypes which match; |
113 | // if built with GetFileTypeFromMimetype index 0 has the exact match and | |
114 | // index 1 the type / * match | |
115 | // if built with GetFileTypeFromExtension, index 0 has the mimetype for | |
116 | // the first extension found, index 1 for the second and so on | |
117 | ||
7dc3cc31 | 118 | void Init(wxMimeTypesManagerImpl *manager, size_t index) |
4d2976ad | 119 | { m_manager = manager; m_index.Add(index); } |
7dc3cc31 VS |
120 | |
121 | // accessors | |
122 | bool GetExtensions(wxArrayString& extensions); | |
123 | bool GetMimeType(wxString *mimeType) const | |
4d2976ad VS |
124 | { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } |
125 | bool GetMimeTypes(wxArrayString& mimeTypes) const; | |
da0766ab | 126 | bool GetIcon(wxIconLocation *iconLoc) const; |
2b813b73 | 127 | |
7dc3cc31 | 128 | bool GetDescription(wxString *desc) const |
4d2976ad | 129 | { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } |
7dc3cc31 VS |
130 | |
131 | bool GetOpenCommand(wxString *openCmd, | |
132 | const wxFileType::MessageParameters& params) const | |
133 | { | |
2b813b73 VZ |
134 | *openCmd = GetExpandedCommand(wxT("open"), params); |
135 | return (! openCmd -> IsEmpty() ); | |
7dc3cc31 VS |
136 | } |
137 | ||
138 | bool GetPrintCommand(wxString *printCmd, | |
139 | const wxFileType::MessageParameters& params) const | |
140 | { | |
2b813b73 VZ |
141 | *printCmd = GetExpandedCommand(wxT("print"), params); |
142 | return (! printCmd -> IsEmpty() ); | |
7dc3cc31 VS |
143 | } |
144 | ||
2b813b73 VZ |
145 | // return the number of commands defined for this file type, 0 if none |
146 | size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, | |
147 | const wxFileType::MessageParameters& params) const; | |
148 | ||
149 | ||
a6c65e88 | 150 | // remove the record for this file type |
2b813b73 VZ |
151 | // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead |
152 | bool Unassociate(wxFileType *ft) | |
153 | { | |
154 | return m_manager->Unassociate(ft); | |
155 | } | |
a6c65e88 | 156 | |
2b813b73 VZ |
157 | // set an arbitrary command, ask confirmation if it already exists and |
158 | // overwriteprompt is TRUE | |
159 | bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); | |
160 | bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); | |
7dc3cc31 | 161 | |
2b813b73 VZ |
162 | private: |
163 | wxString | |
164 | GetExpandedCommand(const wxString & verb, | |
165 | const wxFileType::MessageParameters& params) const; | |
7dc3cc31 VS |
166 | |
167 | wxMimeTypesManagerImpl *m_manager; | |
4d2976ad | 168 | wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays |
7dc3cc31 VS |
169 | }; |
170 | ||
0d2c74c6 VZ |
171 | #endif // wxUSE_MIMETYPE |
172 | ||
173 | #endif // _MIMETYPE_IMPL_H | |
7dc3cc31 | 174 | |
7dc3cc31 | 175 |