1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/mimetype.h
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence (part of wxExtra library)
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _MIMETYPE_IMPL_H
12 #define _MIMETYPE_IMPL_H
14 #include "wx/mimetype.h"
18 class wxMimeTypeCommands
;
20 WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands
*, wxMimeCommandsArray
);
22 // this is the real wxMimeTypesManager for Unix
23 class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
27 wxMimeTypesManagerImpl();
28 virtual ~wxMimeTypesManagerImpl();
30 // load all data into memory - done when it is needed for the first time
31 void Initialize(int mailcapStyles
= wxMAILCAP_ALL
,
32 const wxString
& extraDir
= wxEmptyString
);
34 // and delete the data here
37 // implement containing class functions
38 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
39 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
41 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
43 void AddFallback(const wxFileTypeInfo
& filetype
);
45 // add information about the given mimetype
46 void AddMimeTypeInfo(const wxString
& mimetype
,
47 const wxString
& extensions
,
48 const wxString
& description
);
49 void AddMailcapInfo(const wxString
& strType
,
50 const wxString
& strOpenCmd
,
51 const wxString
& strPrintCmd
,
52 const wxString
& strTest
,
53 const wxString
& strDesc
);
55 // add a new record to the user .mailcap/.mime.types files
56 wxFileType
*Associate(const wxFileTypeInfo
& ftInfo
);
58 bool Unassociate(wxFileType
*ft
);
61 // get the string containing space separated extensions for the given
63 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
68 wxArrayString m_aTypes
, // MIME types
69 m_aDescriptions
, // descriptions (just some text)
70 m_aExtensions
, // space separated list of extensions
71 m_aIcons
; // Icon filenames
73 // verb=command pairs for this file type
74 wxMimeCommandsArray m_aEntries
;
76 // are we initialized?
79 wxString
GetCommand(const wxString
&verb
, size_t nIndex
) const;
81 // Read XDG *.desktop file
82 void LoadXDGApp(const wxString
& filename
);
84 void LoadXDGAppsFilesFromDir(const wxString
& dirname
);
86 // Load XDG globs files
87 void LoadXDGGlobs(const wxString
& filename
);
89 // functions used to do associations
90 virtual int AddToMimeData(const wxString
& strType
,
91 const wxString
& strIcon
,
92 wxMimeTypeCommands
*entry
,
93 const wxArrayString
& strExtensions
,
94 const wxString
& strDesc
,
95 bool replaceExisting
= true);
96 virtual bool DoAssociation(const wxString
& strType
,
97 const wxString
& strIcon
,
98 wxMimeTypeCommands
*entry
,
99 const wxArrayString
& strExtensions
,
100 const wxString
& strDesc
);
102 // give it access to m_aXXX variables
103 friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl
;
106 class WXDLLIMPEXP_BASE wxFileTypeImpl
109 // initialization functions
110 // this is used to construct a list of mimetypes which match;
111 // if built with GetFileTypeFromMimetype index 0 has the exact match and
112 // index 1 the type / * match
113 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
114 // the first extension found, index 1 for the second and so on
116 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
117 { m_manager
= manager
; m_index
.Add(index
); }
120 bool GetExtensions(wxArrayString
& extensions
);
121 bool GetMimeType(wxString
*mimeType
) const
122 { *mimeType
= m_manager
->m_aTypes
[m_index
[0]]; return true; }
123 bool GetMimeTypes(wxArrayString
& mimeTypes
) const;
124 bool GetIcon(wxIconLocation
*iconLoc
) const;
126 bool GetDescription(wxString
*desc
) const
127 { *desc
= m_manager
->m_aDescriptions
[m_index
[0]]; return true; }
129 bool GetOpenCommand(wxString
*openCmd
,
130 const wxFileType::MessageParameters
& params
) const
132 *openCmd
= GetExpandedCommand(wxT("open"), params
);
133 return (! openCmd
-> IsEmpty() );
136 bool GetPrintCommand(wxString
*printCmd
,
137 const wxFileType::MessageParameters
& params
) const
139 *printCmd
= GetExpandedCommand(wxT("print"), params
);
140 return (! printCmd
-> IsEmpty() );
143 // return the number of commands defined for this file type, 0 if none
144 size_t GetAllCommands(wxArrayString
*verbs
, wxArrayString
*commands
,
145 const wxFileType::MessageParameters
& params
) const;
148 // remove the record for this file type
149 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
150 bool Unassociate(wxFileType
*ft
)
152 return m_manager
->Unassociate(ft
);
155 // set an arbitrary command, ask confirmation if it already exists and
156 // overwriteprompt is TRUE
157 bool SetCommand(const wxString
& cmd
, const wxString
& verb
, bool overwriteprompt
= true);
158 bool SetDefaultIcon(const wxString
& strIcon
= wxEmptyString
, int index
= 0);
162 GetExpandedCommand(const wxString
& verb
,
163 const wxFileType::MessageParameters
& params
) const;
165 wxMimeTypesManagerImpl
*m_manager
;
166 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays
169 #endif // wxUSE_MIMETYPE
171 #endif // _MIMETYPE_IMPL_H