]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/mimetype.h
no real changes, just some cleanup
[wxWidgets.git] / include / wx / unix / mimetype.h
CommitLineData
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 19class wxMimeTypeCommands;
7dc3cc31 20
0d2c74c6 21WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray);
7dc3cc31
VS
22
23// this is the real wxMimeTypesManager for Unix
24class WXDLLEXPORT wxMimeTypesManagerImpl
25{
7dc3cc31 26public:
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
44 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
45 bool ReadMimeTypes(const wxString& filename);
46
47 void AddFallback(const wxFileTypeInfo& filetype);
48
49 // add information about the given mimetype
50 void AddMimeTypeInfo(const wxString& mimetype,
51 const wxString& extensions,
52 const wxString& description);
53 void AddMailcapInfo(const wxString& strType,
54 const wxString& strOpenCmd,
55 const wxString& strPrintCmd,
56 const wxString& strTest,
57 const wxString& strDesc);
58
a6c65e88
VZ
59 // add a new record to the user .mailcap/.mime.types files
60 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
2b813b73
VZ
61 // remove association
62 bool Unassociate(wxFileType *ft);
a6c65e88 63
7dc3cc31
VS
64 // accessors
65 // get the string containing space separated extensions for the given
66 // file type
67 wxString GetExtension(size_t index) { return m_aExtensions[index]; }
68
2b850ae1 69protected:
6d718495 70 void InitIfNeeded();
a6c65e88 71
7dc3cc31
VS
72 wxArrayString m_aTypes, // MIME types
73 m_aDescriptions, // descriptions (just some text)
2b813b73
VZ
74 m_aExtensions, // space separated list of extensions
75 m_aIcons; // Icon filenames
76
77 // verb=command pairs for this file type
678ebfcd 78 wxMimeCommandsArray m_aEntries;
7dc3cc31 79
a6c65e88
VZ
80 // are we initialized?
81 bool m_initialized;
82
2b813b73
VZ
83 // keep track of the files we had already loaded (this is a bitwise OR of
84 // wxMailcapStyle values)
85 int m_mailcapStylesInited;
86
87 wxString GetCommand(const wxString &verb, size_t nIndex) const;
88
89 // read Gnome files
805f26b3
VS
90 void LoadGnomeDataFromKeyFile(const wxString& filename,
91 const wxArrayString& dirs);
2b813b73 92 void LoadGnomeMimeTypesFromMimeFile(const wxString& filename);
805f26b3
VS
93 void LoadGnomeMimeFilesFromDir(const wxString& dirbase,
94 const wxArrayString& dirs);
2b813b73
VZ
95 void GetGnomeMimeInfo(const wxString& sExtraDir);
96
2b813b73
VZ
97 // read KDE
98 void LoadKDELinksForMimeSubtype(const wxString& dirbase,
99 const wxString& subdir,
100 const wxString& filename,
101 const wxArrayString& icondirs);
102 void LoadKDELinksForMimeType(const wxString& dirbase,
103 const wxString& subdir,
104 const wxArrayString& icondirs);
105 void LoadKDELinkFilesFromDir(const wxString& dirbase,
106 const wxArrayString& icondirs);
31383ebc
RR
107 void LoadKDEApp(const wxString& filename);
108 void LoadKDEAppsFilesFromDir(const wxString& dirname);
2b813b73
VZ
109 void GetKDEMimeInfo(const wxString& sExtraDir);
110
111 // write KDE
112 bool WriteKDEMimeFile(int index, bool delete_index);
113 bool CheckKDEDirsExist(const wxString & sOK, const wxString& sTest);
114
115 //read write Netscape and MetaMail formats
116 void GetMimeInfo (const wxString& sExtraDir);
117 bool WriteToMailCap (int index, bool delete_index);
118 bool WriteToMimeTypes (int index, bool delete_index);
119 bool WriteToNSMimeTypes (int index, bool delete_index);
120
678ebfcd
VZ
121 // ReadMailcap() helper
122 bool ProcessOtherMailcapField(struct MailcapLineData& data,
123 const wxString& curField);
124
2b813b73
VZ
125 // functions used to do associations
126
2b850ae1 127 virtual int AddToMimeData(const wxString& strType,
2b813b73 128 const wxString& strIcon,
678ebfcd 129 wxMimeTypeCommands *entry,
2b813b73
VZ
130 const wxArrayString& strExtensions,
131 const wxString& strDesc,
132 bool replaceExisting = TRUE);
133
2b850ae1 134 virtual bool DoAssociation(const wxString& strType,
2b813b73 135 const wxString& strIcon,
678ebfcd 136 wxMimeTypeCommands *entry,
2b813b73
VZ
137 const wxArrayString& strExtensions,
138 const wxString& strDesc);
139
2b850ae1 140 virtual bool WriteMimeInfo(int nIndex, bool delete_mime );
a6c65e88
VZ
141
142 // give it access to m_aXXX variables
b5dbe15d 143 friend class WXDLLIMPEXP_FWD_CORE wxFileTypeImpl;
7dc3cc31
VS
144};
145
4d2976ad
VS
146
147
7dc3cc31
VS
148class WXDLLEXPORT wxFileTypeImpl
149{
150public:
151 // initialization functions
2b813b73
VZ
152 // this is used to construct a list of mimetypes which match;
153 // if built with GetFileTypeFromMimetype index 0 has the exact match and
154 // index 1 the type / * match
155 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
156 // the first extension found, index 1 for the second and so on
157
7dc3cc31 158 void Init(wxMimeTypesManagerImpl *manager, size_t index)
4d2976ad 159 { m_manager = manager; m_index.Add(index); }
7dc3cc31
VS
160
161 // accessors
162 bool GetExtensions(wxArrayString& extensions);
163 bool GetMimeType(wxString *mimeType) const
4d2976ad
VS
164 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
165 bool GetMimeTypes(wxArrayString& mimeTypes) const;
da0766ab 166 bool GetIcon(wxIconLocation *iconLoc) const;
2b813b73 167
7dc3cc31 168 bool GetDescription(wxString *desc) const
4d2976ad 169 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
7dc3cc31
VS
170
171 bool GetOpenCommand(wxString *openCmd,
172 const wxFileType::MessageParameters& params) const
173 {
2b813b73
VZ
174 *openCmd = GetExpandedCommand(wxT("open"), params);
175 return (! openCmd -> IsEmpty() );
7dc3cc31
VS
176 }
177
178 bool GetPrintCommand(wxString *printCmd,
179 const wxFileType::MessageParameters& params) const
180 {
2b813b73
VZ
181 *printCmd = GetExpandedCommand(wxT("print"), params);
182 return (! printCmd -> IsEmpty() );
7dc3cc31
VS
183 }
184
2b813b73
VZ
185 // return the number of commands defined for this file type, 0 if none
186 size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands,
187 const wxFileType::MessageParameters& params) const;
188
189
a6c65e88 190 // remove the record for this file type
2b813b73
VZ
191 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
192 bool Unassociate(wxFileType *ft)
193 {
194 return m_manager->Unassociate(ft);
195 }
a6c65e88 196
2b813b73
VZ
197 // set an arbitrary command, ask confirmation if it already exists and
198 // overwriteprompt is TRUE
199 bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE);
200 bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
7dc3cc31 201
2b813b73
VZ
202private:
203 wxString
204 GetExpandedCommand(const wxString & verb,
205 const wxFileType::MessageParameters& params) const;
7dc3cc31
VS
206
207 wxMimeTypesManagerImpl *m_manager;
4d2976ad 208 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
7dc3cc31
VS
209};
210
0d2c74c6
VZ
211#endif // wxUSE_MIMETYPE
212
213#endif // _MIMETYPE_IMPL_H
7dc3cc31 214
7dc3cc31 215