]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/mimetype.h
1. added wxMemoryConfig (private) class
[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{
33friend class WXDLLEXPORT wxFileTypeImpl; // give it access to m_aXXX variables
34
35public:
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
69private:
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
79class WXDLLEXPORT wxFileTypeImpl
80{
81public:
82 // initialization functions
83 void Init(wxMimeTypesManagerImpl *manager, size_t index)
84 { m_manager = manager; m_index = index; }
85
86 // accessors
87 bool GetExtensions(wxArrayString& extensions);
88 bool GetMimeType(wxString *mimeType) const
89 { *mimeType = m_manager->m_aTypes[m_index]; return TRUE; }
90 bool GetIcon(wxIcon *icon) const;
91 bool GetDescription(wxString *desc) const
92 { *desc = m_manager->m_aDescriptions[m_index]; return TRUE; }
93
94 bool GetOpenCommand(wxString *openCmd,
95 const wxFileType::MessageParameters& params) const
96 {
97 return GetExpandedCommand(openCmd, params, TRUE);
98 }
99
100 bool GetPrintCommand(wxString *printCmd,
101 const wxFileType::MessageParameters& params) const
102 {
103 return GetExpandedCommand(printCmd, params, FALSE);
104 }
105
106private:
107 // get the entry which passes the test (may return NULL)
108 MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const;
109
110 // choose the correct entry to use and expand the command
111 bool GetExpandedCommand(wxString *expandedCmd,
112 const wxFileType::MessageParameters& params,
113 bool open) const;
114
115 wxMimeTypesManagerImpl *m_manager;
116 size_t m_index; // in the wxMimeTypesManagerImpl arrays
117};
118
119
120
121#endif
122 // wxUSE_FILE
123
124#endif
125 //_MIMETYPE_IMPL_H
126