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
35 wxMimeTypesManagerImpl();
36 ~wxMimeTypesManagerImpl();
38 // load all data into memory - done when it is needed for the first time
41 // implement containing class functions
42 wxFileType
*GetFileTypeFromExtension(const wxString
& ext
);
43 wxFileType
*GetFileTypeFromMimeType(const wxString
& mimeType
);
45 size_t EnumAllFileTypes(wxArrayString
& mimetypes
);
47 bool ReadMailcap(const wxString
& filename
, bool fallback
= FALSE
);
48 bool ReadMimeTypes(const wxString
& filename
);
50 void AddFallback(const wxFileTypeInfo
& filetype
);
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
);
62 // add a new record to the user .mailcap/.mime.types files
63 wxFileType
*Associate(const wxFileTypeInfo
& ftInfo
);
66 // get the string containing space separated extensions for the given
68 wxString
GetExtension(size_t index
) { return m_aExtensions
[index
]; }
70 // get the array of icon handlers
71 static ArrayIconHandlers
& GetIconHandlers();
76 if ( !m_initialized
) {
77 // set the flag first to prevent recursion
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
88 // are we initialized?
91 // head of the linked list of the icon handlers
92 static ArrayIconHandlers ms_iconHandlers
;
94 // give it access to m_aXXX variables
95 friend class WXDLLEXPORT wxFileTypeImpl
;
100 class WXDLLEXPORT wxFileTypeImpl
103 // initialization functions
104 void Init(wxMimeTypesManagerImpl
*manager
, size_t index
)
105 { m_manager
= manager
; m_index
.Add(index
); }
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
; }
116 bool GetOpenCommand(wxString
*openCmd
,
117 const wxFileType::MessageParameters
& params
) const
119 return GetExpandedCommand(openCmd
, params
, TRUE
);
122 bool GetPrintCommand(wxString
*printCmd
,
123 const wxFileType::MessageParameters
& params
) const
125 return GetExpandedCommand(printCmd
, params
, FALSE
);
128 // remove the record for this file type
132 // get the entry which passes the test (may return NULL)
133 MailCapEntry
*GetEntry(const wxFileType::MessageParameters
& params
) const;
135 // choose the correct entry to use and expand the command
136 bool GetExpandedCommand(wxString
*expandedCmd
,
137 const wxFileType::MessageParameters
& params
,
140 wxMimeTypesManagerImpl
*m_manager
;
141 wxArrayInt m_index
; // in the wxMimeTypesManagerImpl arrays