]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/mimetype.h
MIME type manager fixes described earlier on the list:
[wxWidgets.git] / include / wx / unix / mimetype.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 license (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _MIMETYPE_IMPL_H
13 #define _MIMETYPE_IMPL_H
14
15
16 #ifdef __GNUG__
17 #pragma interface "mimetype.h"
18 #endif
19
20 #include "wx/mimetype.h"
21
22 #if (wxUSE_FILE && wxUSE_TEXTFILE)
23
24 class MailCapEntry;
25 class wxMimeTypeIconHandler;
26
27 WX_DEFINE_ARRAY(wxMimeTypeIconHandler *, ArrayIconHandlers);
28 WX_DEFINE_ARRAY(MailCapEntry *, ArrayTypeEntries);
29
30 // this is the real wxMimeTypesManager for Unix
31 class WXDLLEXPORT wxMimeTypesManagerImpl
32 {
33 public:
34 // ctor and dtor
35 wxMimeTypesManagerImpl();
36 ~wxMimeTypesManagerImpl();
37
38 // load all data into memory - done when it is needed for the first time
39 void Initialize();
40
41 // implement containing class functions
42 wxFileType *GetFileTypeFromExtension(const wxString& ext);
43 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
44
45 size_t EnumAllFileTypes(wxArrayString& mimetypes);
46
47 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
48 bool ReadMimeTypes(const wxString& filename);
49
50 void AddFallback(const wxFileTypeInfo& filetype);
51
52 // add information about the given mimetype
53 void AddMimeTypeInfo(const wxString& mimetype,
54 const wxString& extensions,
55 const wxString& description);
56 void AddMailcapInfo(const wxString& strType,
57 const wxString& strOpenCmd,
58 const wxString& strPrintCmd,
59 const wxString& strTest,
60 const wxString& strDesc);
61
62 // add a new record to the user .mailcap/.mime.types files
63 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
64
65 // accessors
66 // get the string containing space separated extensions for the given
67 // file type
68 wxString GetExtension(size_t index) { return m_aExtensions[index]; }
69
70 // get the array of icon handlers
71 static ArrayIconHandlers& GetIconHandlers();
72
73 private:
74 void InitIfNeeded()
75 {
76 if ( !m_initialized ) {
77 // set the flag first to prevent recursion
78 m_initialized = TRUE;
79 Initialize();
80 }
81 }
82
83 wxArrayString m_aTypes, // MIME types
84 m_aDescriptions, // descriptions (just some text)
85 m_aExtensions; // space separated list of extensions
86 ArrayTypeEntries m_aEntries; // commands and tests for this file type
87
88 // are we initialized?
89 bool m_initialized;
90
91 // head of the linked list of the icon handlers
92 static ArrayIconHandlers ms_iconHandlers;
93
94 // give it access to m_aXXX variables
95 friend class WXDLLEXPORT wxFileTypeImpl;
96 };
97
98
99
100 class WXDLLEXPORT wxFileTypeImpl
101 {
102 public:
103 // initialization functions
104 void Init(wxMimeTypesManagerImpl *manager, size_t index)
105 { m_manager = manager; m_index.Add(index); }
106
107 // accessors
108 bool GetExtensions(wxArrayString& extensions);
109 bool GetMimeType(wxString *mimeType) const
110 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
111 bool GetMimeTypes(wxArrayString& mimeTypes) const;
112 bool GetIcon(wxIcon *icon) const;
113 bool GetDescription(wxString *desc) const
114 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
115
116 bool GetOpenCommand(wxString *openCmd,
117 const wxFileType::MessageParameters& params) const
118 {
119 return GetExpandedCommand(openCmd, params, TRUE);
120 }
121
122 bool GetPrintCommand(wxString *printCmd,
123 const wxFileType::MessageParameters& params) const
124 {
125 return GetExpandedCommand(printCmd, params, FALSE);
126 }
127
128 // remove the record for this file type
129 bool Unassociate();
130
131 private:
132 // get the entry which passes the test (may return NULL)
133 MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const;
134
135 // choose the correct entry to use and expand the command
136 bool GetExpandedCommand(wxString *expandedCmd,
137 const wxFileType::MessageParameters& params,
138 bool open) const;
139
140 wxMimeTypesManagerImpl *m_manager;
141 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
142 };
143
144 #endif
145 // wxUSE_FILE
146
147 #endif
148 //_MIMETYPE_IMPL_H
149