-
- // accessors
- const wxString& GetOpenCmd() const { return m_openCmd; }
- const wxString& GetPrintCmd() const { return m_printCmd; }
- const wxString& GetTestCmd() const { return m_testCmd; }
-
- MailCapEntry *GetNext() const { return m_next; }
-
- // operations
- // prepend this element to the list
- void Prepend(MailCapEntry *next) { m_next = next; }
- // insert into the list at given position
- void Insert(MailCapEntry *next, size_t pos)
- {
- // FIXME slooow...
- MailCapEntry *cur;
- size_t n = 0;
- for ( cur = next; cur != NULL; cur = cur->m_next, n++ ) {
- if ( n == pos )
- break;
- }
-
- wxASSERT_MSG( n == pos, wxT("invalid position in MailCapEntry::Insert") );
-
- m_next = cur->m_next;
- cur->m_next = this;
- }
- // append this element to the list
- void Append(MailCapEntry *next)
- {
- wxCHECK_RET( next != NULL, wxT("Append()ing to what?") );
-
- // FIXME slooow...
- MailCapEntry *cur;
- for ( cur = next; cur->m_next != NULL; cur = cur->m_next )
- ;
-
- cur->m_next = this;
-
- wxASSERT_MSG( !m_next, wxT("Append()ing element already in the list?") );
- }
-
-private:
- wxString m_openCmd, // command to use to open/view the file
- m_printCmd, // print
- m_testCmd; // only apply this entry if test yields
- // true (i.e. the command returns 0)
-
- MailCapEntry *m_next; // in the linked list
-};
-
-
-// the base class which may be used to find an icon for the MIME type
-class wxMimeTypeIconHandler
-{
-public:
- virtual bool GetIcon(const wxString& mimetype, wxIcon *icon) = 0;
-
- // this function fills manager with MIME types information gathered
- // (as side effect) when searching for icons. This may be particularly
- // useful if mime.types is incomplete (e.g. RedHat distributions).
- virtual void GetMimeInfoRecords(wxMimeTypesManagerImpl *manager) = 0;
-};
-
-
-// the icon handler which uses GNOME MIME database
-class wxGNOMEIconHandler : public wxMimeTypeIconHandler
-{
-public:
- virtual bool GetIcon(const wxString& mimetype, wxIcon *icon);
- virtual void GetMimeInfoRecords(wxMimeTypesManagerImpl *manager);
-
-private:
- void Init();
- void LoadIconsFromKeyFile(const wxString& filename);
- void LoadKeyFilesFromDir(const wxString& dirbase);
-
- void LoadMimeTypesFromMimeFile(const wxString& filename, wxMimeTypesManagerImpl *manager);
- void LoadMimeFilesFromDir(const wxString& dirbase, wxMimeTypesManagerImpl *manager);
-
- static bool m_inited;
-
- static wxSortedArrayString ms_mimetypes;
- static wxArrayString ms_icons;
-};
-
-// the icon handler which uses KDE MIME database
-class wxKDEIconHandler : public wxMimeTypeIconHandler
-{
-public:
- virtual bool GetIcon(const wxString& mimetype, wxIcon *icon);
- virtual void GetMimeInfoRecords(wxMimeTypesManagerImpl *manager);
-
-private:
- void LoadLinksForMimeSubtype(const wxString& dirbase,
- const wxString& subdir,
- const wxString& filename,
- const wxArrayString& icondirs);
- void LoadLinksForMimeType(const wxString& dirbase,
- const wxString& subdir,
- const wxArrayString& icondirs);
- void LoadLinkFilesFromDir(const wxString& dirbase,
- const wxArrayString& icondirs);
- void Init();
-
- static bool m_inited;
-
- static wxSortedArrayString ms_mimetypes;
- static wxArrayString ms_icons;
-
- static wxArrayString ms_infoTypes;
- static wxArrayString ms_infoDescriptions;
- static wxArrayString ms_infoExtensions;
-};
-
-
-
-// ----------------------------------------------------------------------------
-// various statics
-// ----------------------------------------------------------------------------
-
-static wxGNOMEIconHandler gs_iconHandlerGNOME;
-static wxKDEIconHandler gs_iconHandlerKDE;
-
-bool wxGNOMEIconHandler::m_inited = FALSE;
-wxSortedArrayString wxGNOMEIconHandler::ms_mimetypes;
-wxArrayString wxGNOMEIconHandler::ms_icons;
-
-bool wxKDEIconHandler::m_inited = FALSE;
-wxSortedArrayString wxKDEIconHandler::ms_mimetypes;
-wxArrayString wxKDEIconHandler::ms_icons;
-
-wxArrayString wxKDEIconHandler::ms_infoTypes;
-wxArrayString wxKDEIconHandler::ms_infoDescriptions;
-wxArrayString wxKDEIconHandler::ms_infoExtensions;
-
-
-ArrayIconHandlers wxMimeTypesManagerImpl::ms_iconHandlers;
-
-// ----------------------------------------------------------------------------
-// wxGNOMEIconHandler
-// ----------------------------------------------------------------------------
-
-// GNOME stores the info we're interested in in several locations:
-// 1. xxx.keys files under /usr/share/mime-info
-// 2. xxx.keys files under ~/.gnome/mime-info
-//
-// The format of xxx.keys file is the following:
-//
-// mimetype/subtype:
-// field=value
-//
-// with blank lines separating the entries and indented lines starting with
-// TABs. We're interested in the field icon-filename whose value is the path
-// containing the icon.
-//
-// Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
-// just before the field name.
-
-void wxGNOMEIconHandler::LoadIconsFromKeyFile(const wxString& filename)
-{
- wxTextFile textfile(filename);
- if ( !textfile.Open() )
- return;
-
- // values for the entry being parsed
- wxString curMimeType, curIconFile;
-
- const wxChar *pc;
- size_t nLineCount = textfile.GetLineCount();
- for ( size_t nLine = 0; ; nLine++ )
- {
- if ( nLine < nLineCount )
- {
- pc = textfile[nLine].c_str();
- if ( *pc == _T('#') )
- {
- // skip comments
- continue;
- }
- }
- else
- {
- // so that we will fall into the "if" below
- pc = NULL;
- }
-
- if ( !pc || !*pc )
- {
- // end of the entry
- if ( !!curMimeType && !!curIconFile )
- {
- // do we already know this mimetype?
- int i = ms_mimetypes.Index(curMimeType);
- if ( i == wxNOT_FOUND )
- {
- // add a new entry
- size_t n = ms_mimetypes.Add(curMimeType);
- ms_icons.Insert(curIconFile, n);
- }
- else
- {
- // replace the existing one (this means that the directories
- // should be searched in order of increased priority!)
- ms_icons[(size_t)i] = curIconFile;
- }
- }
-
- if ( !pc )
- {
- // the end - this can only happen if nLine == nLineCount
- break;
- }
-
- curIconFile.Empty();
-
- continue;
- }
-
- // what do we have here?
- if ( *pc == _T('\t') )
- {
- // this is a field=value ling
- pc++; // skip leading TAB
-
- // skip optional "[lang]"
- if ( *pc == _T('[') )
- {
- while ( *pc )
- {
- if ( *pc++ == _T(']') )
- break;
- }
- }
-
- static const int lenField = 13; // strlen("icon-filename")
- if ( wxStrncmp(pc, _T("icon-filename"), lenField) == 0 )
- {
- // skip '=' which follows and take everything left until the end
- // of line
- curIconFile = pc + lenField + 1;
- }
- //else: some other field, we don't care
- }
- else
- {
- // this is the start of the new section
- curMimeType.Empty();
-
- while ( *pc != _T(':') && *pc != _T('\0') )
- {
- curMimeType += *pc++;
- }
- }
- }
-}
-
-void wxGNOMEIconHandler::LoadKeyFilesFromDir(const wxString& dirbase)
-{
- wxASSERT_MSG( !!dirbase && !wxEndsWithPathSeparator(dirbase),
- _T("base directory shouldn't end with a slash") );
-
- wxString dirname = dirbase;
- dirname << _T("/mime-info");
-
- if ( !wxDir::Exists(dirname) )
- return;
-
- wxDir dir(dirname);
- if ( !dir.IsOpened() )
- return;
-
- // we will concatenate it with filename to get the full path below
- dirname += _T('/');
-
- wxString filename;
- bool cont = dir.GetFirst(&filename, _T("*.keys"), wxDIR_FILES);
- while ( cont )