]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/unix/mimetype.h
Fix warnings about signed/unsigned comparisons inside wxMax() and friends.
[wxWidgets.git] / include / wx / unix / mimetype.h
... / ...
CommitLineData
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// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows licence (part of wxExtra library)
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _MIMETYPE_IMPL_H
13#define _MIMETYPE_IMPL_H
14
15#include "wx/mimetype.h"
16
17#if wxUSE_MIMETYPE
18
19class wxMimeTypeCommands;
20
21WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray);
22
23// this is the real wxMimeTypesManager for Unix
24class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
25{
26public:
27 // ctor and dtor
28 wxMimeTypesManagerImpl();
29 virtual ~wxMimeTypesManagerImpl();
30
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);
34
35 // and delete the data here
36 void ClearData();
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 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
56 // add a new record to the user .mailcap/.mime.types files
57 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
58 // remove association
59 bool Unassociate(wxFileType *ft);
60
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
66protected:
67 void InitIfNeeded();
68
69 wxArrayString m_aTypes, // MIME types
70 m_aDescriptions, // descriptions (just some text)
71 m_aExtensions, // space separated list of extensions
72 m_aIcons; // Icon filenames
73
74 // verb=command pairs for this file type
75 wxMimeCommandsArray m_aEntries;
76
77 // are we initialized?
78 bool m_initialized;
79
80 wxString GetCommand(const wxString &verb, size_t nIndex) const;
81
82 // Read XDG *.desktop file
83 void LoadXDGApp(const wxString& filename);
84 // Scan XDG directory
85 void LoadXDGAppsFilesFromDir(const wxString& dirname);
86
87 // Load XDG globs files
88 void LoadXDGGlobs(const wxString& filename);
89
90 // functions used to do associations
91 virtual int AddToMimeData(const wxString& strType,
92 const wxString& strIcon,
93 wxMimeTypeCommands *entry,
94 const wxArrayString& strExtensions,
95 const wxString& strDesc,
96 bool replaceExisting = true);
97 virtual bool DoAssociation(const wxString& strType,
98 const wxString& strIcon,
99 wxMimeTypeCommands *entry,
100 const wxArrayString& strExtensions,
101 const wxString& strDesc);
102
103 // give it access to m_aXXX variables
104 friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl;
105};
106
107class WXDLLIMPEXP_BASE wxFileTypeImpl
108{
109public:
110 // initialization functions
111 // this is used to construct a list of mimetypes which match;
112 // if built with GetFileTypeFromMimetype index 0 has the exact match and
113 // index 1 the type / * match
114 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
115 // the first extension found, index 1 for the second and so on
116
117 void Init(wxMimeTypesManagerImpl *manager, size_t index)
118 { m_manager = manager; m_index.Add(index); }
119
120 // accessors
121 bool GetExtensions(wxArrayString& extensions);
122 bool GetMimeType(wxString *mimeType) const
123 { *mimeType = m_manager->m_aTypes[m_index[0]]; return true; }
124 bool GetMimeTypes(wxArrayString& mimeTypes) const;
125 bool GetIcon(wxIconLocation *iconLoc) const;
126
127 bool GetDescription(wxString *desc) const
128 { *desc = m_manager->m_aDescriptions[m_index[0]]; return true; }
129
130 bool GetOpenCommand(wxString *openCmd,
131 const wxFileType::MessageParameters& params) const
132 {
133 *openCmd = GetExpandedCommand(wxT("open"), params);
134 return (! openCmd -> IsEmpty() );
135 }
136
137 bool GetPrintCommand(wxString *printCmd,
138 const wxFileType::MessageParameters& params) const
139 {
140 *printCmd = GetExpandedCommand(wxT("print"), params);
141 return (! printCmd -> IsEmpty() );
142 }
143
144 // return the number of commands defined for this file type, 0 if none
145 size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands,
146 const wxFileType::MessageParameters& params) const;
147
148
149 // remove the record for this file type
150 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
151 bool Unassociate(wxFileType *ft)
152 {
153 return m_manager->Unassociate(ft);
154 }
155
156 // set an arbitrary command, ask confirmation if it already exists and
157 // overwriteprompt is TRUE
158 bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = true);
159 bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
160
161private:
162 wxString
163 GetExpandedCommand(const wxString & verb,
164 const wxFileType::MessageParameters& params) const;
165
166 wxMimeTypesManagerImpl *m_manager;
167 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
168};
169
170#endif // wxUSE_MIMETYPE
171
172#endif // _MIMETYPE_IMPL_H
173
174