]>
Commit | Line | Data |
---|---|---|
7dc3cc31 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/mac/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> | |
371a5b4e | 9 | // Licence: wxWindows licence (part of wxExtra library) |
7dc3cc31 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _MIMETYPE_IMPL_H | |
13 | #define _MIMETYPE_IMPL_H | |
14 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
4b6ed6bc GD |
16 | #pragma interface "mimetype.h" |
17 | #endif | |
7dc3cc31 VS |
18 | |
19 | #include "wx/defs.h" | |
20 | #include "wx/mimetype.h" | |
21 | ||
22 | ||
7dc3cc31 VS |
23 | class wxMimeTypesManagerImpl |
24 | { | |
25 | public : | |
26 | wxMimeTypesManagerImpl() { } | |
f11bdd03 | 27 | #ifdef __DARWIN__ |
4b6ed6bc GD |
28 | ~wxMimeTypesManagerImpl() { } |
29 | #endif | |
30 | ||
f040060e GD |
31 | // load all data into memory - done when it is needed for the first time |
32 | void Initialize(int mailcapStyles = wxMAILCAP_STANDARD, | |
33 | const wxString& extraDir = wxEmptyString); | |
34 | ||
35 | // and delete the data here | |
36 | void ClearData(); | |
37 | ||
7dc3cc31 VS |
38 | // implement containing class functions |
39 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
03e11df5 | 40 | wxFileType *GetOrAllocateFileTypeFromExtension(const wxString& ext) ; |
7dc3cc31 VS |
41 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); |
42 | ||
43 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
44 | ||
45 | // this are NOPs under MacOS | |
af49c4b8 GD |
46 | bool ReadMailcap(const wxString& WXUNUSED(filename), bool WXUNUSED(fallback) = TRUE) { return TRUE; } |
47 | bool ReadMimeTypes(const wxString& WXUNUSED(filename)) { return TRUE; } | |
7dc3cc31 VS |
48 | |
49 | void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); } | |
50 | ||
03e11df5 GD |
51 | // create a new filetype association |
52 | wxFileType *Associate(const wxFileTypeInfo& ftInfo); | |
f040060e GD |
53 | // remove association |
54 | bool Unassociate(wxFileType *ft); | |
03e11df5 GD |
55 | |
56 | // create a new filetype with the given name and extension | |
57 | wxFileType *CreateFileType(const wxString& filetype, const wxString& ext); | |
58 | ||
7dc3cc31 VS |
59 | private: |
60 | wxArrayFileTypeInfo m_fallbacks; | |
61 | }; | |
62 | ||
63 | class wxFileTypeImpl | |
64 | { | |
65 | public: | |
f040060e GD |
66 | // initialization functions |
67 | // this is used to construct a list of mimetypes which match; | |
68 | // if built with GetFileTypeFromMimetype index 0 has the exact match and | |
69 | // index 1 the type / * match | |
70 | // if built with GetFileTypeFromExtension, index 0 has the mimetype for | |
71 | // the first extension found, index 1 for the second and so on | |
72 | ||
73 | void Init(wxMimeTypesManagerImpl *manager, size_t index) | |
e40298d5 | 74 | { m_manager = manager; m_index.Add(index); } |
f040060e | 75 | |
7dc3cc31 VS |
76 | // initialize us with our file type name |
77 | void SetFileType(const wxString& strFileType) | |
78 | { m_strFileType = strFileType; } | |
79 | void SetExt(const wxString& ext) | |
80 | { m_ext = ext; } | |
81 | ||
82 | // implement accessor functions | |
83 | bool GetExtensions(wxArrayString& extensions); | |
84 | bool GetMimeType(wxString *mimeType) const; | |
4d2976ad | 85 | bool GetMimeTypes(wxArrayString& mimeTypes) const; |
f040060e | 86 | bool GetIcon(wxIcon *icon, wxString *sCommand = NULL, int *iIndex = NULL) const; |
7dc3cc31 VS |
87 | bool GetDescription(wxString *desc) const; |
88 | bool GetOpenCommand(wxString *openCmd, | |
89 | const wxFileType::MessageParameters&) const | |
90 | { return GetCommand(openCmd, "open"); } | |
91 | bool GetPrintCommand(wxString *printCmd, | |
92 | const wxFileType::MessageParameters&) const | |
93 | { return GetCommand(printCmd, "print"); } | |
94 | ||
03e11df5 GD |
95 | size_t GetAllCommands(wxArrayString * verbs, wxArrayString * commands, |
96 | const wxFileType::MessageParameters& params) const; | |
97 | ||
f040060e GD |
98 | // remove the record for this file type |
99 | // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead | |
100 | bool Unassociate(wxFileType *ft) | |
e40298d5 JS |
101 | { |
102 | return m_manager->Unassociate(ft); | |
103 | } | |
104 | ||
f040060e GD |
105 | // set an arbitrary command, ask confirmation if it already exists and |
106 | // overwriteprompt is TRUE | |
107 | bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); | |
108 | bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0); | |
109 | ||
110 | private: | |
7dc3cc31 VS |
111 | // helper function |
112 | bool GetCommand(wxString *command, const char *verb) const; | |
f040060e GD |
113 | |
114 | wxMimeTypesManagerImpl *m_manager; | |
115 | wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays | |
7dc3cc31 VS |
116 | wxString m_strFileType, m_ext; |
117 | }; | |
118 | ||
7dc3cc31 VS |
119 | #endif |
120 | //_MIMETYPE_H | |
121 | ||
122 | /* vi: set cin tw=80 ts=4 sw=4: */ |