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