1 /////////////////////////////////////////////////////////////////////////////
2 // Name: unix/mimetype.h
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _MIMETYPE_IMPL_H
13 #define _MIMETYPE_IMPL_H
17 #pragma interface "mimetype.h"
20 #include "wx/mimetype.h"
22 #if (wxUSE_FILE && wxUSE_TEXTFILE)
25 class wxMimeTypeIconHandler
;
27 WX_DEFINE_ARRAY(wxMimeTypeIconHandler
*, ArrayIconHandlers
);
28 WX_DEFINE_ARRAY(MailCapEntry
*, ArrayTypeEntries
);
30 // this is the real wxMimeTypesManager for Unix
31 class WXDLLEXPORT wxMimeTypesManagerImpl
33 friend class WXDLLEXPORT wxFileTypeImpl
; // give it access to m_aXXX variables
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 ~wxMimeTypesManagerImpl();
42 // implement containing class functions
43 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
44 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
46 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
48 bool ReadMailcap(const wxString
& filename
, bool fallback
= FALSE
);
49 bool ReadMimeTypes(const wxString
& filename
);
51 void AddFallback(const wxFileTypeInfo
& filetype
);
53 // add information about the given mimetype
54 void AddMimeTypeInfo(const wxString
& mimetype
,
55 const wxString
& extensions
,
56 const wxString
& description
);
57 void AddMailcapInfo(const wxString
& strType
,
58 const wxString
& strOpenCmd
,
59 const wxString
& strPrintCmd
,
60 const wxString
& strTest
,
61 const wxString
& strDesc
);
64 // get the string containing space separated extensions for the given
66 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
68 // get the array of icon handlers
69 static ArrayIconHandlers
& GetIconHandlers();
72 wxArrayString m_aTypes
, // MIME types
73 m_aDescriptions
, // descriptions (just some text)
74 m_aExtensions
; // space separated list of extensions
75 ArrayTypeEntries m_aEntries
; // commands and tests for this file type
77 // head of the linked list of the icon handlers
78 static ArrayIconHandlers ms_iconHandlers
;
83 class WXDLLEXPORT wxFileTypeImpl
86 // initialization functions
87 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
88 { m_manager
= manager
; m_index
.Add(index
); }
91 bool GetExtensions(wxArrayString
& extensions
);
92 bool GetMimeType(wxString
*mimeType
) const
93 { *mimeType
= m_manager
->m_aTypes
[m_index
[0]]; return TRUE
; }
94 bool GetMimeTypes(wxArrayString
& mimeTypes
) const;
95 bool GetIcon(wxIcon
*icon
) const;
96 bool GetDescription(wxString
*desc
) const
97 { *desc
= m_manager
->m_aDescriptions
[m_index
[0]]; return TRUE
; }
99 bool GetOpenCommand(wxString
*openCmd
,
100 const wxFileType::MessageParameters
& params
) const
102 return GetExpandedCommand(openCmd
, params
, TRUE
);
105 bool GetPrintCommand(wxString
*printCmd
,
106 const wxFileType::MessageParameters
& params
) const
108 return GetExpandedCommand(printCmd
, params
, FALSE
);
112 // get the entry which passes the test (may return NULL)
113 MailCapEntry
*GetEntry(const wxFileType::MessageParameters
& params
) const;
115 // choose the correct entry to use and expand the command
116 bool GetExpandedCommand(wxString
*expandedCmd
,
117 const wxFileType::MessageParameters
& params
,
120 wxMimeTypesManagerImpl
*m_manager
;
121 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays