]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/mimetype.h
Undo the Test commit
[wxWidgets.git] / include / wx / unix / mimetype.h
CommitLineData
7dc3cc31
VS
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
24class MailCapEntry;
25class wxMimeTypeIconHandler;
26
27WX_DEFINE_ARRAY(wxMimeTypeIconHandler *, ArrayIconHandlers);
28WX_DEFINE_ARRAY(MailCapEntry *, ArrayTypeEntries);
29
30// this is the real wxMimeTypesManager for Unix
31class WXDLLEXPORT wxMimeTypesManagerImpl
32{
7dc3cc31 33public:
a6c65e88 34 // ctor and dtor
7dc3cc31 35 wxMimeTypesManagerImpl();
cf471cab 36 ~wxMimeTypesManagerImpl();
a6c65e88
VZ
37
38 // load all data into memory - done when it is needed for the first time
39 void Initialize();
7dc3cc31
VS
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
a6c65e88
VZ
62 // add a new record to the user .mailcap/.mime.types files
63 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
64
7dc3cc31
VS
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
73private:
a6c65e88
VZ
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
7dc3cc31
VS
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
a6c65e88
VZ
88 // are we initialized?
89 bool m_initialized;
90
7dc3cc31
VS
91 // head of the linked list of the icon handlers
92 static ArrayIconHandlers ms_iconHandlers;
a6c65e88
VZ
93
94 // give it access to m_aXXX variables
95 friend class WXDLLEXPORT wxFileTypeImpl;
7dc3cc31
VS
96};
97
4d2976ad
VS
98
99
7dc3cc31
VS
100class WXDLLEXPORT wxFileTypeImpl
101{
102public:
103 // initialization functions
104 void Init(wxMimeTypesManagerImpl *manager, size_t index)
4d2976ad 105 { m_manager = manager; m_index.Add(index); }
7dc3cc31
VS
106
107 // accessors
108 bool GetExtensions(wxArrayString& extensions);
109 bool GetMimeType(wxString *mimeType) const
4d2976ad
VS
110 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
111 bool GetMimeTypes(wxArrayString& mimeTypes) const;
7dc3cc31
VS
112 bool GetIcon(wxIcon *icon) const;
113 bool GetDescription(wxString *desc) const
4d2976ad 114 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
7dc3cc31
VS
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
a6c65e88
VZ
128 // remove the record for this file type
129 bool Unassociate();
130
7dc3cc31
VS
131private:
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;
4d2976ad 141 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
7dc3cc31
VS
142};
143
7dc3cc31
VS
144#endif
145 // wxUSE_FILE
146
147#endif
148 //_MIMETYPE_IMPL_H
149