]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/mimetype.h
inline functions with if moved to .cpp
[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 friend class WXDLLEXPORT wxFileTypeImpl; // give it access to m_aXXX variables
34
35 public:
36 // ctor loads all info into memory for quicker access later on
37 // TODO it would be nice to load them all, but parse on demand only...
38 wxMimeTypesManagerImpl();
39
40 // implement containing class functions
41 wxFileType *GetFileTypeFromExtension(const wxString& ext);
42 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
43
44 size_t EnumAllFileTypes(wxArrayString& mimetypes);
45
46 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
47 bool ReadMimeTypes(const wxString& filename);
48
49 void AddFallback(const wxFileTypeInfo& filetype);
50
51 // add information about the given mimetype
52 void AddMimeTypeInfo(const wxString& mimetype,
53 const wxString& extensions,
54 const wxString& description);
55 void AddMailcapInfo(const wxString& strType,
56 const wxString& strOpenCmd,
57 const wxString& strPrintCmd,
58 const wxString& strTest,
59 const wxString& strDesc);
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
66 // get the array of icon handlers
67 static ArrayIconHandlers& GetIconHandlers();
68
69 private:
70 wxArrayString m_aTypes, // MIME types
71 m_aDescriptions, // descriptions (just some text)
72 m_aExtensions; // space separated list of extensions
73 ArrayTypeEntries m_aEntries; // commands and tests for this file type
74
75 // head of the linked list of the icon handlers
76 static ArrayIconHandlers ms_iconHandlers;
77 };
78
79
80
81 class WXDLLEXPORT wxFileTypeImpl
82 {
83 public:
84 // initialization functions
85 void Init(wxMimeTypesManagerImpl *manager, size_t index)
86 { m_manager = manager; m_index.Add(index); }
87
88 // accessors
89 bool GetExtensions(wxArrayString& extensions);
90 bool GetMimeType(wxString *mimeType) const
91 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
92 bool GetMimeTypes(wxArrayString& mimeTypes) const;
93 bool GetIcon(wxIcon *icon) const;
94 bool GetDescription(wxString *desc) const
95 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
96
97 bool GetOpenCommand(wxString *openCmd,
98 const wxFileType::MessageParameters& params) const
99 {
100 return GetExpandedCommand(openCmd, params, TRUE);
101 }
102
103 bool GetPrintCommand(wxString *printCmd,
104 const wxFileType::MessageParameters& params) const
105 {
106 return GetExpandedCommand(printCmd, params, FALSE);
107 }
108
109 private:
110 // get the entry which passes the test (may return NULL)
111 MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const;
112
113 // choose the correct entry to use and expand the command
114 bool GetExpandedCommand(wxString *expandedCmd,
115 const wxFileType::MessageParameters& params,
116 bool open) const;
117
118 wxMimeTypesManagerImpl *m_manager;
119 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
120 };
121
122
123
124 #endif
125 // wxUSE_FILE
126
127 #endif
128 //_MIMETYPE_IMPL_H
129