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();
40 // implement containing class functions
41 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
42 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
44 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
46 bool ReadMailcap(const wxString
& filename
, bool fallback
= FALSE
);
47 bool ReadMimeTypes(const wxString
& filename
);
49 void AddFallback(const wxFileTypeInfo
& filetype
);
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
);
62 // get the string containing space separated extensions for the given
64 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
66 // get the array of icon handlers
67 static ArrayIconHandlers
& GetIconHandlers();
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
75 // head of the linked list of the icon handlers
76 static ArrayIconHandlers ms_iconHandlers
;
81 class WXDLLEXPORT wxFileTypeImpl
84 // initialization functions
85 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
86 { m_manager
= manager
; m_index
.Add(index
); }
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
; }
97 bool GetOpenCommand(wxString
*openCmd
,
98 const wxFileType::MessageParameters
& params
) const
100 return GetExpandedCommand(openCmd
, params
, TRUE
);
103 bool GetPrintCommand(wxString
*printCmd
,
104 const wxFileType::MessageParameters
& params
) const
106 return GetExpandedCommand(printCmd
, params
, FALSE
);
110 // get the entry which passes the test (may return NULL)
111 MailCapEntry
*GetEntry(const wxFileType::MessageParameters
& params
) const;
113 // choose the correct entry to use and expand the command
114 bool GetExpandedCommand(wxString
*expandedCmd
,
115 const wxFileType::MessageParameters
& params
,
118 wxMimeTypesManagerImpl
*m_manager
;
119 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays