1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/mimetype.h
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 licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _MIMETYPE_IMPL_H
13 #define _MIMETYPE_IMPL_H
15 #include "wx/mimetype.h"
19 class wxMimeTypeCommands
;
21 WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands
*, wxMimeCommandsArray
);
23 // this is the real wxMimeTypesManager for Unix
24 class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
28 wxMimeTypesManagerImpl();
29 virtual ~wxMimeTypesManagerImpl();
31 // load all data into memory - done when it is needed for the first time
32 void Initialize(int mailcapStyles
= wxMAILCAP_ALL
,
33 const wxString
& extraDir
= wxEmptyString
);
35 // and delete the data here
38 // implement containing class functions
39 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
40 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
42 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
44 bool ReadMailcap(const wxString
& filename
, bool fallback
= FALSE
);
45 bool ReadMimeTypes(const wxString
& filename
);
47 void AddFallback(const wxFileTypeInfo
& filetype
);
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
);
59 // add a new record to the user .mailcap/.mime.types files
60 wxFileType
*Associate(const wxFileTypeInfo
& ftInfo
);
62 bool Unassociate(wxFileType
*ft
);
65 // get the string containing space separated extensions for the given
67 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
72 wxArrayString m_aTypes
, // MIME types
73 m_aDescriptions
, // descriptions (just some text)
74 m_aExtensions
, // space separated list of extensions
75 m_aIcons
; // Icon filenames
77 // verb=command pairs for this file type
78 wxMimeCommandsArray m_aEntries
;
80 // are we initialized?
83 // keep track of the files we had already loaded (this is a bitwise OR of
84 // wxMailcapStyle values)
85 int m_mailcapStylesInited
;
87 wxString
GetCommand(const wxString
&verb
, size_t nIndex
) const;
90 void LoadGnomeDataFromKeyFile(const wxString
& filename
,
91 const wxArrayString
& dirs
);
92 void LoadGnomeMimeTypesFromMimeFile(const wxString
& filename
);
93 void LoadGnomeMimeFilesFromDir(const wxString
& dirbase
,
94 const wxArrayString
& dirs
);
95 void GetGnomeMimeInfo(const wxString
& sExtraDir
);
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
);
107 void LoadKDEApp(const wxString
& filename
);
108 void LoadKDEAppsFilesFromDir(const wxString
& dirname
);
109 void GetKDEMimeInfo(const wxString
& sExtraDir
);
112 bool WriteKDEMimeFile(int index
, bool delete_index
);
113 bool CheckKDEDirsExist(const wxString
& sOK
, const wxString
& sTest
);
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
);
121 // ReadMailcap() helper
122 bool ProcessOtherMailcapField(struct MailcapLineData
& data
,
123 const wxString
& curField
);
125 // functions used to do associations
127 virtual int AddToMimeData(const wxString
& strType
,
128 const wxString
& strIcon
,
129 wxMimeTypeCommands
*entry
,
130 const wxArrayString
& strExtensions
,
131 const wxString
& strDesc
,
132 bool replaceExisting
= TRUE
);
134 virtual bool DoAssociation(const wxString
& strType
,
135 const wxString
& strIcon
,
136 wxMimeTypeCommands
*entry
,
137 const wxArrayString
& strExtensions
,
138 const wxString
& strDesc
);
140 virtual bool WriteMimeInfo(int nIndex
, bool delete_mime
);
142 // give it access to m_aXXX variables
143 friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl
;
146 class WXDLLIMPEXP_BASE wxFileTypeImpl
149 // initialization functions
150 // this is used to construct a list of mimetypes which match;
151 // if built with GetFileTypeFromMimetype index 0 has the exact match and
152 // index 1 the type / * match
153 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
154 // the first extension found, index 1 for the second and so on
156 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
157 { m_manager
= manager
; m_index
.Add(index
); }
160 bool GetExtensions(wxArrayString
& extensions
);
161 bool GetMimeType(wxString
*mimeType
) const
162 { *mimeType
= m_manager
->m_aTypes
[m_index
[0]]; return TRUE
; }
163 bool GetMimeTypes(wxArrayString
& mimeTypes
) const;
164 bool GetIcon(wxIconLocation
*iconLoc
) const;
166 bool GetDescription(wxString
*desc
) const
167 { *desc
= m_manager
->m_aDescriptions
[m_index
[0]]; return TRUE
; }
169 bool GetOpenCommand(wxString
*openCmd
,
170 const wxFileType::MessageParameters
& params
) const
172 *openCmd
= GetExpandedCommand(wxT("open"), params
);
173 return (! openCmd
-> IsEmpty() );
176 bool GetPrintCommand(wxString
*printCmd
,
177 const wxFileType::MessageParameters
& params
) const
179 *printCmd
= GetExpandedCommand(wxT("print"), params
);
180 return (! printCmd
-> IsEmpty() );
183 // return the number of commands defined for this file type, 0 if none
184 size_t GetAllCommands(wxArrayString
*verbs
, wxArrayString
*commands
,
185 const wxFileType::MessageParameters
& params
) const;
188 // remove the record for this file type
189 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
190 bool Unassociate(wxFileType
*ft
)
192 return m_manager
->Unassociate(ft
);
195 // set an arbitrary command, ask confirmation if it already exists and
196 // overwriteprompt is TRUE
197 bool SetCommand(const wxString
& cmd
, const wxString
& verb
, bool overwriteprompt
= TRUE
);
198 bool SetDefaultIcon(const wxString
& strIcon
= wxEmptyString
, int index
= 0);
202 GetExpandedCommand(const wxString
& verb
,
203 const wxFileType::MessageParameters
& params
) const;
205 wxMimeTypesManagerImpl
*m_manager
;
206 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays
209 #endif // wxUSE_MIMETYPE
211 #endif // _MIMETYPE_IMPL_H