]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/mimetype.h
Removed unnecessary code from utilsunx.cpp
[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();
cf471cab
VS
39 ~wxMimeTypesManagerImpl();
40
7dc3cc31
VS
41
42 // implement containing class functions
43 wxFileType *GetFileTypeFromExtension(const wxString& ext);
44 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
45
46 size_t EnumAllFileTypes(wxArrayString& mimetypes);
47
48 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
49 bool ReadMimeTypes(const wxString& filename);
50
51 void AddFallback(const wxFileTypeInfo& filetype);
52
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);
62
63 // accessors
64 // get the string containing space separated extensions for the given
65 // file type
66 wxString GetExtension(size_t index) { return m_aExtensions[index]; }
67
68 // get the array of icon handlers
69 static ArrayIconHandlers& GetIconHandlers();
70
71private:
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
76
77 // head of the linked list of the icon handlers
78 static ArrayIconHandlers ms_iconHandlers;
79};
80
4d2976ad
VS
81
82
7dc3cc31
VS
83class WXDLLEXPORT wxFileTypeImpl
84{
85public:
86 // initialization functions
87 void Init(wxMimeTypesManagerImpl *manager, size_t index)
4d2976ad 88 { m_manager = manager; m_index.Add(index); }
7dc3cc31
VS
89
90 // accessors
91 bool GetExtensions(wxArrayString& extensions);
92 bool GetMimeType(wxString *mimeType) const
4d2976ad
VS
93 { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; }
94 bool GetMimeTypes(wxArrayString& mimeTypes) const;
7dc3cc31
VS
95 bool GetIcon(wxIcon *icon) const;
96 bool GetDescription(wxString *desc) const
4d2976ad 97 { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; }
7dc3cc31
VS
98
99 bool GetOpenCommand(wxString *openCmd,
100 const wxFileType::MessageParameters& params) const
101 {
102 return GetExpandedCommand(openCmd, params, TRUE);
103 }
104
105 bool GetPrintCommand(wxString *printCmd,
106 const wxFileType::MessageParameters& params) const
107 {
108 return GetExpandedCommand(printCmd, params, FALSE);
109 }
110
111private:
112 // get the entry which passes the test (may return NULL)
113 MailCapEntry *GetEntry(const wxFileType::MessageParameters& params) const;
114
115 // choose the correct entry to use and expand the command
116 bool GetExpandedCommand(wxString *expandedCmd,
117 const wxFileType::MessageParameters& params,
118 bool open) const;
119
120 wxMimeTypesManagerImpl *m_manager;
4d2976ad 121 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
7dc3cc31
VS
122};
123
124
125
126#endif
127 // wxUSE_FILE
128
129#endif
130 //_MIMETYPE_IMPL_H
131