]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/mimetype.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / unix / mimetype.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/mimetype.h
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 23.09.98
7 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence (part of wxExtra library)
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _MIMETYPE_IMPL_H
12 #define _MIMETYPE_IMPL_H
13
14 #include "wx/mimetype.h"
15
16 #if wxUSE_MIMETYPE
17
18 class wxMimeTypeCommands;
19
20 WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray);
21
22 // this is the real wxMimeTypesManager for Unix
23 class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
24 {
25 public:
26 // ctor and dtor
27 wxMimeTypesManagerImpl();
28 virtual ~wxMimeTypesManagerImpl();
29
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);
33
34 // and delete the data here
35 void ClearData();
36
37 // implement containing class functions
38 wxFileType *GetFileTypeFromExtension(const wxString& ext);
39 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
40
41 size_t EnumAllFileTypes(wxArrayString& mimetypes);
42
43 void AddFallback(const wxFileTypeInfo& filetype);
44
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);
54
55 // add a new record to the user .mailcap/.mime.types files
56 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
57 // remove association
58 bool Unassociate(wxFileType *ft);
59
60 // accessors
61 // get the string containing space separated extensions for the given
62 // file type
63 wxString GetExtension(size_t index) { return m_aExtensions[index]; }
64
65 protected:
66 void InitIfNeeded();
67
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
72
73 // verb=command pairs for this file type
74 wxMimeCommandsArray m_aEntries;
75
76 // are we initialized?
77 bool m_initialized;
78
79 wxString GetCommand(const wxString &verb, size_t nIndex) const;
80
81 // Read XDG *.desktop file
82 void LoadXDGApp(const wxString& filename);
83 // Scan XDG directory
84 void LoadXDGAppsFilesFromDir(const wxString& dirname);
85
86 // Load XDG globs files
87 void LoadXDGGlobs(const wxString& filename);
88
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);
101
102 // give it access to m_aXXX variables
103 friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl;
104 };
105
106 class WXDLLIMPEXP_BASE wxFileTypeImpl
107 {
108 public:
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
115
116 void Init(wxMimeTypesManagerImpl *manager, size_t index)
117 { m_manager = manager; m_index.Add(index); }
118
119 // accessors
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;
125
126 bool GetDescription(wxString *desc) const
127 { *desc = m_manager->m_aDescriptions[m_index[0]]; return true; }
128
129 bool GetOpenCommand(wxString *openCmd,
130 const wxFileType::MessageParameters& params) const
131 {
132 *openCmd = GetExpandedCommand(wxT("open"), params);
133 return (! openCmd -> IsEmpty() );
134 }
135
136 bool GetPrintCommand(wxString *printCmd,
137 const wxFileType::MessageParameters& params) const
138 {
139 *printCmd = GetExpandedCommand(wxT("print"), params);
140 return (! printCmd -> IsEmpty() );
141 }
142
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;
146
147
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)
151 {
152 return m_manager->Unassociate(ft);
153 }
154
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);
159
160 private:
161 wxString
162 GetExpandedCommand(const wxString & verb,
163 const wxFileType::MessageParameters& params) const;
164
165 wxMimeTypesManagerImpl *m_manager;
166 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
167 };
168
169 #endif // wxUSE_MIMETYPE
170
171 #endif // _MIMETYPE_IMPL_H
172
173