1 /////////////////////////////////////////////////////////////////////////////
2 // Name: unix/mimetype.cpp
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 licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 // known bugs; there may be others!! chris elliott, biol75@york.ac.uk 27 Mar 01
14 // 1) .mailcap and .mimetypes can be either in a netscape or metamail format
15 // and entries may get confused during writing (I've tried to fix this; please let me know
16 // any files that fail)
17 // 2) KDE and Gnome do not yet fully support international read/write
18 // 3) Gnome key lines like open.latex."LaTeX this file"=latex %f will have odd results
19 // 4) writing to files comments out the existing data; I hope this avoids losing
20 // any data which we could not read, and data which we did not store like test=
21 // 5) results from reading files with multiple entries (especially matches with type/* )
22 // may (or may not) work for getXXX commands
23 // 6) Loading the png icons in Gnome doesn't work for me...
24 // 7) In Gnome, if keys.mime exists but keys.users does not, there is
25 // an error message in debug mode, but the file is still written OK
26 // 8) Deleting entries is only allowed from the user file; sytem wide entries
27 // will be preserved during unassociate
28 // 9) KDE does not yet handle multiple actions; Netscape mode never will
30 // TODO: this file is a mess, we need to split it and review everything (VZ)
32 // for compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
43 #if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE
46 #include "wx/string.h"
52 #include "wx/dynarray.h"
53 #include "wx/confbase.h"
56 #include "wx/textfile.h"
59 #include "wx/tokenzr.h"
60 #include "wx/iconloc.h"
61 #include "wx/filename.h"
63 #include "wx/unix/mimetype.h"
66 #include "wx/gtk/gnome/gvfs.h"
68 // other standard headers
72 /* silence warnings for comparing unsigned int's <0 */
73 # pragma message disable unscomzer
76 // this class extends wxTextFile
79 class wxMimeTextFile
: public wxTextFile
83 wxMimeTextFile () : wxTextFile () {};
84 wxMimeTextFile(const wxString
& strFile
) : wxTextFile(strFile
) {};
86 int pIndexOf(const wxString
& sSearch
, bool bIncludeComments
= false, int iStart
= 0)
89 int nResult
= wxNOT_FOUND
;
90 if (i
>= GetLineCount())
93 wxString sTest
= sSearch
;
99 while ( i
< GetLineCount() )
103 if (sLine
.Contains(sTest
))
111 while ( (i
< GetLineCount()) )
115 if ( ! sLine
.StartsWith(wxT("#")))
117 if (sLine
.Contains(sTest
))
128 bool CommentLine(int nIndex
)
132 if (nIndex
>= (int)GetLineCount() )
135 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
139 bool CommentLine(const wxString
& sTest
)
141 int nIndex
= pIndexOf(sTest
);
144 if (nIndex
>= (int)GetLineCount() )
147 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
151 wxString
GetVerb(size_t i
)
153 if (i
> GetLineCount() )
154 return wxEmptyString
;
156 wxString sTmp
= GetLine(i
).BeforeFirst(wxT('='));
160 wxString
GetCmd(size_t i
)
162 if (i
> GetLineCount() )
163 return wxEmptyString
;
165 wxString sTmp
= GetLine(i
).AfterFirst(wxT('='));
170 // in case we're compiling in non-GUI mode
171 class WXDLLEXPORT wxIcon
;
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 // MIME code tracing mask
178 #define TRACE_MIME wxT("mime")
180 // give trace messages about the results of mailcap tests
181 #define TRACE_MIME_TEST wxT("mimetest")
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 // there are some fields which we don't understand but for which we don't give
188 // warnings as we know that they're not important - this function is used to
190 static bool IsKnownUnimportantField(const wxString
& field
);
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
197 // This class uses both mailcap and mime.types to gather information about file
200 // The information about mailcap file was extracted from metamail(1) sources
201 // and documentation and subsequently revised when I found the RFC 1524
204 // Format of mailcap file: spaces are ignored, each line is either a comment
205 // (starts with '#') or a line of the form <field1>;<field2>;...;<fieldN>.
206 // A backslash can be used to quote semicolons and newlines (and, in fact,
207 // anything else including itself).
209 // The first field is always the MIME type in the form of type/subtype (see RFC
210 // 822) where subtype may be '*' meaning "any". Following metamail, we accept
211 // "type" which means the same as "type/*", although I'm not sure whether this
214 // The second field is always the command to run. It is subject to
215 // parameter/filename expansion described below.
217 // All the following fields are optional and may not be present at all. If
218 // they're present they may appear in any order, although each of them should
219 // appear only once. The optional fields are the following:
220 // * notes=xxx is an uninterpreted string which is silently ignored
221 // * test=xxx is the command to be used to determine whether this mailcap line
222 // applies to our data or not. The RHS of this field goes through the
223 // parameter/filename expansion (as the 2nd field) and the resulting string
224 // is executed. The line applies only if the command succeeds, i.e. returns 0
226 // * print=xxx is the command to be used to print (and not view) the data of
227 // this type (parameter/filename expansion is done here too)
228 // * edit=xxx is the command to open/edit the data of this type
229 // * needsterminal means that a new interactive console must be created for
231 // * copiousoutput means that the viewer doesn't interact with the user but
232 // produces (possibly) a lof of lines of output on stdout (i.e. "cat" is a
233 // good example), thus it might be a good idea to use some kind of paging
235 // * textualnewlines means not to perform CR/LF translation (not honored)
236 // * compose and composetyped fields are used to determine the program to be
237 // called to create a new message pert in the specified format (unused).
239 // Parameter/filename expansion:
240 // * %s is replaced with the (full) file name
241 // * %t is replaced with MIME type/subtype of the entry
242 // * for multipart type only %n is replaced with the nnumber of parts and %F is
243 // replaced by an array of (content-type, temporary file name) pairs for all
244 // message parts (TODO)
245 // * %{parameter} is replaced with the value of parameter taken from
246 // Content-type header line of the message.
249 // There are 2 possible formats for mime.types file, one entry per line (used
250 // for global mime.types and called Mosaic format) and "expanded" format where
251 // an entry takes multiple lines (used for users mime.types and called
254 // For both formats spaces are ignored and lines starting with a '#' are
255 // comments. Each record has one of two following forms:
256 // a) for "brief" format:
257 // <mime type> <space separated list of extensions>
258 // b) for "expanded" format:
259 // type=<mime type> BACKSLASH
260 // desc="<description>" BACKSLASH
261 // exts="<comma separated list of extensions>"
263 // (where BACKSLASH is a literal '\\' which we can't put here because cpp
266 // We try to autodetect the format of mime.types: if a non-comment line starts
267 // with "type=" we assume the second format, otherwise the first one.
269 // there may be more than one entry for one and the same mime type, to
270 // choose the right one we have to run the command specified in the test
271 // field on our data.
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
277 // GNOME stores the info we're interested in in several locations:
278 // 1. xxx.keys files under /usr/share/mime-info
279 // 2. xxx.keys files under ~/.gnome/mime-info
281 // Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
282 // just before the field name.
285 void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString
& filename
,
286 const wxArrayString
& dirs
)
288 wxTextFile
textfile(filename
);
289 #if defined(__WXGTK20__) && wxUSE_UNICODE
290 if ( !textfile
.Open(wxConvUTF8
) )
292 if ( !textfile
.Open() )
296 wxLogTrace(TRACE_MIME
, wxT("--- Opened Gnome file %s ---"),
299 wxArrayString
search_dirs( dirs
);
301 // values for the entry being parsed
302 wxString curMimeType
, curIconFile
;
303 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
305 wxArrayString strExtensions
;
309 size_t nLineCount
= textfile
.GetLineCount();
311 while ( nLine
< nLineCount
)
313 pc
= textfile
[nLine
].c_str();
314 if ( *pc
!= wxT('#') )
317 wxLogTrace(TRACE_MIME
, wxT("--- Reading from Gnome file %s '%s' ---"),
318 filename
.c_str(), pc
);
320 // trim trailing space and tab
321 while ((*pc
== wxT(' ')) || (*pc
== wxT('\t')))
325 int equal_pos
= sTmp
.Find( wxT('=') );
328 wxString left_of_equal
= sTmp
.Left( equal_pos
);
329 const wxChar
*right_of_equal
= pc
;
330 right_of_equal
+= equal_pos
+1;
332 if (left_of_equal
== wxT("icon_filename"))
335 curIconFile
= right_of_equal
;
337 wxFileName
newFile( curIconFile
);
338 if (newFile
.IsRelative() || newFile
.FileExists())
340 size_t nDirs
= search_dirs
.GetCount();
342 for (size_t nDir
= 0; nDir
< nDirs
; nDir
++)
344 newFile
.SetPath( search_dirs
[nDir
] );
345 newFile
.AppendDir( wxT("pixmaps") );
346 newFile
.AppendDir( wxT("document-icons") );
347 newFile
.SetExt( wxT("png") );
348 if (newFile
.FileExists())
350 curIconFile
= newFile
.GetFullPath();
351 // reorder search_dirs for speedup (fewer
352 // calls to FileExist() required)
355 wxString tmp
= search_dirs
[nDir
];
356 search_dirs
.RemoveAt( nDir
);
357 search_dirs
.Insert( tmp
, 0 );
364 else if (left_of_equal
== wxT("open"))
366 sTmp
= right_of_equal
;
367 sTmp
.Replace( wxT("%f"), wxT("%s") );
368 sTmp
.Prepend( wxT("open=") );
371 else if (left_of_equal
== wxT("view"))
373 sTmp
= right_of_equal
;
374 sTmp
.Replace( wxT("%f"), wxT("%s") );
375 sTmp
.Prepend( wxT("view=") );
378 else if (left_of_equal
== wxT("print"))
380 sTmp
= right_of_equal
;
381 sTmp
.Replace( wxT("%f"), wxT("%s") );
382 sTmp
.Prepend( wxT("print=") );
385 else if (left_of_equal
== wxT("description"))
387 strDesc
= right_of_equal
;
389 else if (left_of_equal
== wxT("short_list_application_ids_for_novice_user_level"))
391 sTmp
= right_of_equal
;
392 if (sTmp
.Contains( wxT(",") ))
393 sTmp
= sTmp
.BeforeFirst( wxT(',') );
394 sTmp
.Prepend( wxT("open=") );
395 sTmp
.Append( wxT(" %s") );
399 } // emd of has an equals sign
402 // not a comment and not an equals sign
403 if (sTmp
.Contains(wxT('/')))
405 // this is the start of the new mimetype
406 // overwrite any existing data
407 if (! curMimeType
.empty())
409 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
411 // now get ready for next bit
412 entry
= new wxMimeTypeCommands
;
415 curMimeType
= sTmp
.BeforeFirst(wxT(':'));
418 } // end of not a comment
420 // ignore blank lines
422 } // end of while, save any data
424 if ( curMimeType
.empty() )
427 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
430 void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString
& filename
)
432 wxTextFile
textfile(filename
);
433 if ( !textfile
.Open() )
436 wxLogTrace(TRACE_MIME
,
437 wxT("--- Opened Gnome file %s ---"),
440 // values for the entry being parsed
441 wxString curMimeType
, curExtList
;
444 size_t nLineCount
= textfile
.GetLineCount();
445 for ( size_t nLine
= 0; /* nothing */; nLine
++ )
447 if ( nLine
< nLineCount
)
449 pc
= textfile
[nLine
].c_str();
450 if ( *pc
== wxT('#') )
458 // so that we will fall into the "if" below
465 if ( !curMimeType
.empty() && !curExtList
.empty() )
467 wxLogTrace(TRACE_MIME
,
468 wxT("--- At end of Gnome file finding mimetype %s ---"),
469 curMimeType
.c_str());
471 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
476 // the end: this can only happen if nLine == nLineCount
485 // what do we have here?
486 if ( *pc
== wxT('\t') )
488 // this is a field=value ling
489 pc
++; // skip leading TAB
491 static const int lenField
= 5; // strlen("ext: ")
492 if ( wxStrncmp(pc
, wxT("ext: "), lenField
) == 0 )
494 // skip it and take everything left until the end of line
495 curExtList
= pc
+ lenField
;
497 //else: some other field, we don't care
501 // this is the start of the new section
502 wxLogTrace(TRACE_MIME
,
503 wxT("--- In Gnome file finding mimetype %s ---"),
504 curMimeType
.c_str());
506 if (! curMimeType
.empty())
507 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
511 while ( *pc
!= wxT(':') && *pc
!= wxT('\0') )
513 curMimeType
+= *pc
++;
520 void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
521 const wxString
& dirbase
, const wxArrayString
& dirs
)
523 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
524 wxT("base directory shouldn't end with a slash") );
526 wxString dirname
= dirbase
;
527 dirname
<< wxT("/mime-info");
529 if ( !wxDir::Exists(dirname
) )
533 if ( !dir
.IsOpened() )
536 // we will concatenate it with filename to get the full path below
542 cont
= dir
.GetFirst(&filename
, wxT("*.mime"), wxDIR_FILES
);
545 LoadGnomeMimeTypesFromMimeFile(dirname
+ filename
);
547 cont
= dir
.GetNext(&filename
);
550 cont
= dir
.GetFirst(&filename
, wxT("*.keys"), wxDIR_FILES
);
553 LoadGnomeDataFromKeyFile(dirname
+ filename
, dirs
);
555 cont
= dir
.GetNext(&filename
);
558 // FIXME: Hack alert: We scan all icons and deduce the
559 // mime-type from the file name.
561 dirname
<< wxT("/pixmaps/document-icons");
563 // these are always empty in this file
564 wxArrayString strExtensions
;
567 if ( !wxDir::Exists(dirname
) )
569 // Just test for default GPE dir also
570 dirname
= wxT("/usr/share/gpe/pixmaps/default/filemanager/document-icons");
572 if ( !wxDir::Exists(dirname
) )
576 wxDir
dir2( dirname
);
578 cont
= dir2
.GetFirst(&filename
, wxT("gnome-*.png"), wxDIR_FILES
);
581 wxString mimeType
= filename
;
582 mimeType
.Remove( 0, 6 ); // remove "gnome-"
583 mimeType
.Remove( mimeType
.Len() - 4, 4 ); // remove ".png"
584 int pos
= mimeType
.Find( wxT("-") );
585 if (pos
!= wxNOT_FOUND
)
587 mimeType
.SetChar( pos
, wxT('/') );
588 wxString iconFile
= dirname
;
589 iconFile
<< wxT("/");
590 iconFile
<< filename
;
591 AddToMimeData( mimeType
, iconFile
, NULL
, strExtensions
, strDesc
, true );
594 cont
= dir2
.GetNext(&filename
);
598 void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString
& sExtraDir
)
602 wxString gnomedir
= wxGetenv( wxT("GNOMEDIR") );
603 if (!gnomedir
.empty())
605 gnomedir
<< wxT("/share");
606 dirs
.Add( gnomedir
);
609 dirs
.Add(wxT("/usr/share"));
610 dirs
.Add(wxT("/usr/local/share"));
612 gnomedir
= wxGetHomeDir();
613 gnomedir
<< wxT("/.gnome");
614 dirs
.Add( gnomedir
);
616 if (!sExtraDir
.empty())
617 dirs
.Add( sExtraDir
);
619 size_t nDirs
= dirs
.GetCount();
620 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
622 LoadGnomeMimeFilesFromDir(dirs
[nDir
], dirs
);
626 // ----------------------------------------------------------------------------
628 // ----------------------------------------------------------------------------
631 // KDE stores the icon info in its .kdelnk files. The file for mimetype/subtype
632 // may be found in either of the following locations
634 // 1. $KDEDIR/share/mimelnk/mimetype/subtype.kdelnk
635 // 2. ~/.kde/share/mimelnk/mimetype/subtype.kdelnk
637 // The format of a .kdelnk file is almost the same as the one used by
638 // wxFileConfig, i.e. there are groups, comments and entries. The icon is the
639 // value for the entry "Type"
641 // kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD
642 // for now write to .kdelnk but should eventually do .desktop instead (in preference??)
644 bool wxMimeTypesManagerImpl::CheckKDEDirsExist( const wxString
&sOK
, const wxString
&sTest
)
648 return wxDir::Exists(sOK
);
652 wxString sStart
= sOK
+ wxT("/") + sTest
.BeforeFirst(wxT('/'));
653 if (!wxDir::Exists(sStart
))
655 wxString sEnd
= sTest
.AfterFirst(wxT('/'));
656 return CheckKDEDirsExist(sStart
, sEnd
);
660 bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index
, bool delete_index
)
662 wxMimeTextFile appoutfile
, mimeoutfile
;
663 wxString sHome
= wxGetHomeDir();
664 wxString sTmp
= wxT(".kde/share/mimelnk/");
665 wxString sMime
= m_aTypes
[index
];
666 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.BeforeFirst(wxT('/')) );
667 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
+ wxT(".kdelnk");
670 bool bMimeExists
= mimeoutfile
.Open(sTmp
);
673 bTemp
= mimeoutfile
.Create(sTmp
);
674 // some unknown error eg out of disk space
679 sTmp
= wxT(".kde/share/applnk/");
680 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.AfterFirst(wxT('/')) );
681 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
.AfterFirst(wxT('/')) + wxT(".kdelnk");
684 bAppExists
= appoutfile
.Open(sTmp
);
687 bTemp
= appoutfile
.Create(sTmp
);
688 // some unknown error eg out of disk space
693 // fixed data; write if new file
696 mimeoutfile
.AddLine(wxT("#KDE Config File"));
697 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
698 mimeoutfile
.AddLine(wxT("Version=1.0"));
699 mimeoutfile
.AddLine(wxT("Type=MimeType"));
700 mimeoutfile
.AddLine(wxT("MimeType=") + sMime
);
705 mimeoutfile
.AddLine(wxT("#KDE Config File"));
706 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
707 appoutfile
.AddLine(wxT("Version=1.0"));
708 appoutfile
.AddLine(wxT("Type=Application"));
709 appoutfile
.AddLine(wxT("MimeType=") + sMime
+ wxT(';'));
714 mimeoutfile
.CommentLine(wxT("Comment="));
716 mimeoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
717 appoutfile
.CommentLine(wxT("Name="));
719 appoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
721 sTmp
= m_aIcons
[index
];
722 // we can either give the full path, or the shortfilename if its in
723 // one of the directories we search
724 mimeoutfile
.CommentLine(wxT("Icon=") );
726 mimeoutfile
.AddLine(wxT("Icon=") + sTmp
);
727 appoutfile
.CommentLine(wxT("Icon=") );
729 appoutfile
.AddLine(wxT("Icon=") + sTmp
);
731 sTmp
= wxT(" ") + m_aExtensions
[index
];
733 wxStringTokenizer
tokenizer(sTmp
, wxT(" "));
734 sTmp
= wxT("Patterns=");
735 mimeoutfile
.CommentLine(sTmp
);
736 while ( tokenizer
.HasMoreTokens() )
738 // holds an extension; need to change it to *.ext;
739 wxString e
= wxT("*.") + tokenizer
.GetNextToken() + wxT(";");
744 mimeoutfile
.AddLine(sTmp
);
746 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
747 // if we don't find open just have an empty string ... FIX this
748 sTmp
= entries
->GetCommandForVerb(wxT("open"));
749 sTmp
.Replace( wxT("%s"), wxT("%f") );
751 mimeoutfile
.CommentLine(wxT("DefaultApp=") );
753 mimeoutfile
.AddLine(wxT("DefaultApp=") + sTmp
);
755 sTmp
.Replace( wxT("%f"), wxT("") );
756 appoutfile
.CommentLine(wxT("Exec="));
758 appoutfile
.AddLine(wxT("Exec=") + sTmp
);
760 if (entries
->GetCount() > 1)
762 //other actions as well as open
766 if (mimeoutfile
.Write())
769 if (appoutfile
.Write())
776 void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString
& dirbase
,
777 const wxString
& subdir
,
778 const wxString
& filename
,
779 const wxArrayString
& icondirs
)
782 if ( !file
.Open(dirbase
+ filename
) )
785 wxLogTrace(TRACE_MIME
, wxT("loading KDE file %s"),
786 (dirbase
+ filename
).c_str());
788 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
790 wxString mimetype
, mime_desc
, strIcon
;
792 int nIndex
= file
.pIndexOf( wxT("MimeType=") );
793 if (nIndex
== wxNOT_FOUND
)
795 // construct mimetype from the directory name and the basename of the
796 // file (it always has .kdelnk extension)
797 mimetype
<< subdir
<< wxT('/') << filename
.BeforeLast( wxT('.') );
800 mimetype
= file
.GetCmd(nIndex
);
802 // first find the description string: it is the value in either "Comment="
803 // line or "Comment[<locale_name>]=" one
804 nIndex
= wxNOT_FOUND
;
809 wxLocale
*locale
= wxGetLocale();
812 // try "Comment[locale name]" first
813 comment
<< wxT("Comment[") + locale
->GetName() + wxT("]=");
814 nIndex
= file
.pIndexOf(comment
);
818 if ( nIndex
== wxNOT_FOUND
)
820 comment
= wxT("Comment=");
821 nIndex
= file
.pIndexOf(comment
);
824 if ( nIndex
!= wxNOT_FOUND
)
825 mime_desc
= file
.GetCmd(nIndex
);
826 //else: no description
828 // next find the extensions
829 wxString mime_extension
;
831 nIndex
= file
.pIndexOf(wxT("Patterns="));
832 if ( nIndex
!= wxNOT_FOUND
)
834 wxString exts
= file
.GetCmd(nIndex
);
836 wxStringTokenizer
tokenizer(exts
, wxT(";"));
837 while ( tokenizer
.HasMoreTokens() )
839 wxString e
= tokenizer
.GetNextToken();
841 // don't support too difficult patterns
842 if ( e
.Left(2) != wxT("*.") )
845 if ( !mime_extension
.empty() )
847 // separate from the previous ext
848 mime_extension
<< wxT(' ');
851 mime_extension
<< e
.Mid(2);
855 sExts
.Add(mime_extension
);
857 // ok, now we can take care of icon:
859 nIndex
= file
.pIndexOf(wxT("Icon="));
860 if ( nIndex
!= wxNOT_FOUND
)
862 strIcon
= file
.GetCmd(nIndex
);
864 wxLogTrace(TRACE_MIME
, wxT(" icon %s"), strIcon
.c_str());
866 // it could be the real path, but more often a short name
867 if (!wxFileExists(strIcon
))
869 // icon is just the short name
870 if ( !strIcon
.empty() )
872 // we must check if the file exists because it may be stored
873 // in many locations, at least ~/.kde and $KDEDIR
874 size_t nDir
, nDirs
= icondirs
.GetCount();
875 for ( nDir
= 0; nDir
< nDirs
; nDir
++ )
877 wxFileName
fnameIcon( strIcon
);
878 wxFileName
fname( icondirs
[nDir
], fnameIcon
.GetName() );
879 fname
.SetExt( wxT("png") );
880 if (fname
.FileExists())
882 strIcon
= fname
.GetFullPath();
883 wxLogTrace(TRACE_MIME
, wxT(" iconfile %s"), strIcon
.c_str());
891 // now look for lines which know about the application
892 // exec= or DefaultApp=
894 nIndex
= file
.pIndexOf(wxT("DefaultApp"));
896 if ( nIndex
== wxNOT_FOUND
)
899 nIndex
= file
.pIndexOf(wxT("Exec"));
902 if ( nIndex
!= wxNOT_FOUND
)
904 // we expect %f; others including %F and %U and %u are possible
905 wxString sTmp
= file
.GetCmd(nIndex
);
906 if (0 == sTmp
.Replace( wxT("%f"), wxT("%s") ))
907 sTmp
= sTmp
+ wxT(" %s");
908 entry
->AddOrReplaceVerb(wxString(wxT("open")), sTmp
);
911 AddToMimeData(mimetype
, strIcon
, entry
, sExts
, mime_desc
);
914 void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString
& dirbase
,
915 const wxString
& subdir
,
916 const wxArrayString
& icondirs
)
918 wxString dirname
= dirbase
;
921 if ( !dir
.IsOpened() )
924 wxLogTrace(TRACE_MIME
, wxT("--- Loading from KDE directory %s ---"),
930 bool cont
= dir
.GetFirst(&filename
, wxT("*.kdelnk"), wxDIR_FILES
);
933 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
935 cont
= dir
.GetNext(&filename
);
938 // new standard for Gnome and KDE
939 cont
= dir
.GetFirst(&filename
, wxT("*.desktop"), wxDIR_FILES
);
942 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
944 cont
= dir
.GetNext(&filename
);
948 void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString
& dirbase
,
949 const wxArrayString
& icondirs
)
951 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
952 wxT("base directory shouldn't end with a slash") );
954 wxString dirname
= dirbase
;
955 dirname
<< wxT("/mimelnk");
957 if ( !wxDir::Exists(dirname
) )
961 if ( !dir
.IsOpened() )
964 // we will concatenate it with dir name to get the full path below
968 bool cont
= dir
.GetFirst(&subdir
, wxEmptyString
, wxDIR_DIRS
);
971 LoadKDELinksForMimeType(dirname
, subdir
, icondirs
);
973 cont
= dir
.GetNext(&subdir
);
977 void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString
& sExtraDir
)
980 wxArrayString icondirs
;
982 // FIXME: This code is heavily broken. There are three bugs in it:
983 // 1) it uses only KDEDIR, which is deprecated, instead of using
984 // list of paths from KDEDIRS and using KDEDIR only if KDEDIRS
986 // 2) it doesn't look into ~/.kde/share/config/kdeglobals where
987 // user's settings are stored and thus *ignores* user's settings
988 // instead of respecting them
989 // 3) it "tries to guess KDEDIR" and "tries a few likely theme
990 // names", both of which is completely arbitrary; instead, the
991 // code should give up if KDEDIR(S) is not set and/or the icon
992 // theme cannot be determined, because it means that the user is
993 // not using KDE (and thus is not interested in KDE icons anyway)
995 // the variable $KDEDIR is set when KDE is running
996 wxString kdedir
= wxGetenv( wxT("KDEDIR") );
1000 // $(KDEDIR)/share/config/kdeglobals holds info
1001 // the current icons theme
1002 wxFileName
configFile( kdedir
, wxEmptyString
);
1003 configFile
.AppendDir( wxT("share") );
1004 configFile
.AppendDir( wxT("config") );
1005 configFile
.SetName( wxT("kdeglobals") );
1008 if (configFile
.FileExists() && config
.Open(configFile
.GetFullPath()))
1010 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1011 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1012 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1013 configFile
.AppendDir( wxT("icons") );
1016 wxString
theme(wxT("default.kde"));
1017 size_t cnt
= config
.GetLineCount();
1018 for (size_t i
= 0; i
< cnt
; i
++)
1020 if (config
[i
].StartsWith(wxT("Theme="), &theme
/*rest*/))
1024 configFile
.AppendDir(theme
);
1028 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1029 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1031 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1032 configFile
.AppendDir( wxT("icons") );
1034 // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
1035 configFile
.AppendDir( wxT("default.kde") );
1038 configFile
.SetName( wxEmptyString
);
1039 configFile
.AppendDir( wxT("32x32") );
1040 configFile
.AppendDir( wxT("mimetypes") );
1042 // Just try a few likely icons theme names
1044 int pos
= configFile
.GetDirCount() - 3;
1046 if (!wxDir::Exists(configFile
.GetPath()))
1048 configFile
.RemoveDir( pos
);
1049 configFile
.InsertDir( pos
, wxT("default.kde") );
1052 if (!wxDir::Exists(configFile
.GetPath()))
1054 configFile
.RemoveDir( pos
);
1055 configFile
.InsertDir( pos
, wxT("default") );
1058 if (!wxDir::Exists(configFile
.GetPath()))
1060 configFile
.RemoveDir( pos
);
1061 configFile
.InsertDir( pos
, wxT("crystalsvg") );
1064 if (!wxDir::Exists(configFile
.GetPath()))
1066 configFile
.RemoveDir( pos
);
1067 configFile
.InsertDir( pos
, wxT("crystal") );
1070 if (wxDir::Exists(configFile
.GetPath()))
1071 icondirs
.Add( configFile
.GetFullPath() );
1074 // settings in ~/.kde have maximal priority
1075 dirs
.Add(wxGetHomeDir() + wxT("/.kde/share"));
1076 icondirs
.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
1080 dirs
.Add( wxString(kdedir
) + wxT("/share") );
1081 icondirs
.Add( wxString(kdedir
) + wxT("/share/icons/") );
1085 // try to guess KDEDIR
1086 dirs
.Add(wxT("/usr/share"));
1087 dirs
.Add(wxT("/opt/kde/share"));
1088 icondirs
.Add(wxT("/usr/share/icons/"));
1089 icondirs
.Add(wxT("/usr/X11R6/share/icons/")); // Debian/Corel linux
1090 icondirs
.Add(wxT("/opt/kde/share/icons/"));
1093 if (!sExtraDir
.empty())
1094 dirs
.Add(sExtraDir
);
1095 icondirs
.Add(sExtraDir
+ wxT("/icons"));
1097 size_t nDirs
= dirs
.GetCount();
1098 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1100 LoadKDELinkFilesFromDir(dirs
[nDir
], icondirs
);
1104 // ----------------------------------------------------------------------------
1105 // wxFileTypeImpl (Unix)
1106 // ----------------------------------------------------------------------------
1108 wxString
wxFileTypeImpl::GetExpandedCommand(const wxString
& verb
, const wxFileType::MessageParameters
& params
) const
1112 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1114 sTmp
= m_manager
->GetCommand( verb
, m_index
[i
] );
1118 return wxFileType::ExpandCommand(sTmp
, params
);
1121 bool wxFileTypeImpl::GetIcon(wxIconLocation
*iconLoc
) const
1125 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1127 sTmp
= m_manager
->m_aIcons
[m_index
[i
]];
1136 iconLoc
->SetFileName(sTmp
);
1142 bool wxFileTypeImpl::GetMimeTypes(wxArrayString
& mimeTypes
) const
1145 for (size_t i
= 0; i
< m_index
.GetCount(); i
++)
1146 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
1151 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
1152 wxArrayString
*commands
,
1153 const wxFileType::MessageParameters
& params
) const
1155 wxString vrb
, cmd
, sTmp
;
1157 wxMimeTypeCommands
* sPairs
;
1159 // verbs and commands have been cleared already in mimecmn.cpp...
1160 // if we find no entries in the exact match, try the inexact match
1161 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
1163 // list of verb = command pairs for this mimetype
1164 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
1166 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
1168 vrb
= sPairs
->GetVerb(i
);
1169 // some gnome entries have "." inside
1170 vrb
= vrb
.AfterLast(wxT('.'));
1171 cmd
= sPairs
->GetCmd(i
);
1174 cmd
= wxFileType::ExpandCommand(cmd
, params
);
1176 if ( vrb
.IsSameAs(wxT("open")))
1179 verbs
->Insert(vrb
, 0u);
1181 commands
->Insert(cmd
, 0u);
1197 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
1199 wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
1202 // one extension in the space or comma-delimited list
1204 for ( const wxChar
*p
= strExtensions
; /* nothing */; p
++ )
1206 if ( *p
== wxT(' ') || *p
== wxT(',') || *p
== wxT('\0') )
1208 if ( !strExt
.empty() )
1210 extensions
.Add(strExt
);
1213 //else: repeated spaces
1214 // (shouldn't happen, but it's not that important if it does happen)
1216 if ( *p
== wxT('\0') )
1219 else if ( *p
== wxT('.') )
1221 // remove the dot from extension (but only if it's the first char)
1222 if ( !strExt
.empty() )
1226 //else: no, don't append it
1237 // set an arbitrary command:
1238 // could adjust the code to ask confirmation if it already exists and
1239 // overwriteprompt is true, but this is currently ignored as *Associate* has
1240 // no overwrite prompt
1242 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
1243 const wxString
& verb
,
1244 bool WXUNUSED(overwriteprompt
))
1246 wxArrayString strExtensions
;
1247 wxString strDesc
, strIcon
;
1249 wxArrayString strTypes
;
1250 GetMimeTypes(strTypes
);
1251 if ( strTypes
.IsEmpty() )
1254 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1255 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
1258 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1260 if (!m_manager
->DoAssociation(strTypes
[i
], strIcon
, entry
, strExtensions
, strDesc
))
1267 // ignore index on the grouds that we only have one icon in a Unix file
1268 bool wxFileTypeImpl::SetDefaultIcon(const wxString
& strIcon
, int WXUNUSED(index
))
1270 if (strIcon
.empty())
1273 wxArrayString strExtensions
;
1276 wxArrayString strTypes
;
1277 GetMimeTypes(strTypes
);
1278 if ( strTypes
.IsEmpty() )
1281 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1283 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1285 if ( !m_manager
->DoAssociation
1301 // ----------------------------------------------------------------------------
1302 // wxMimeTypesManagerImpl (Unix)
1303 // ----------------------------------------------------------------------------
1305 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
1307 m_initialized
= false;
1308 m_mailcapStylesInited
= 0;
1311 void wxMimeTypesManagerImpl::InitIfNeeded()
1313 if ( !m_initialized
)
1315 // set the flag first to prevent recursion
1316 m_initialized
= true;
1318 wxString wm
= wxGetenv( wxT("WINDOWMANAGER") );
1320 if (wm
.Find( wxT("kde") ) != wxNOT_FOUND
)
1321 Initialize( wxMAILCAP_KDE
);
1322 else if (wm
.Find( wxT("gnome") ) != wxNOT_FOUND
)
1323 Initialize( wxMAILCAP_GNOME
);
1329 // read system and user mailcaps and other files
1330 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
1331 const wxString
& sExtraDir
)
1333 // read mimecap amd mime.types
1334 if ( (mailcapStyles
& wxMAILCAP_NETSCAPE
) ||
1335 (mailcapStyles
& wxMAILCAP_STANDARD
) )
1336 GetMimeInfo(sExtraDir
);
1338 // read GNOME tables
1339 if (mailcapStyles
& wxMAILCAP_GNOME
)
1340 GetGnomeMimeInfo(sExtraDir
);
1343 if (mailcapStyles
& wxMAILCAP_KDE
)
1344 GetKDEMimeInfo(sExtraDir
);
1346 m_mailcapStylesInited
|= mailcapStyles
;
1349 // clear data so you can read another group of WM files
1350 void wxMimeTypesManagerImpl::ClearData()
1354 m_aExtensions
.Clear();
1355 m_aDescriptions
.Clear();
1357 WX_CLEAR_ARRAY(m_aEntries
);
1360 m_mailcapStylesInited
= 0;
1363 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
1368 void wxMimeTypesManagerImpl::GetMimeInfo(const wxString
& sExtraDir
)
1370 // read this for netscape or Metamail formats
1372 // directories where we look for mailcap and mime.types by default
1373 // used by netscape and pine and other mailers, using 2 different formats!
1375 // (taken from metamail(1) sources)
1377 // although RFC 1524 specifies the search path of
1378 // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
1379 // places - OTOH, the RFC also says that this path can be changed with
1380 // MAILCAPS environment variable (containing the colon separated full
1381 // filenames to try) which is not done yet (TODO?)
1383 wxString strHome
= wxGetenv(wxT("HOME"));
1386 dirs
.Add( strHome
+ wxT("/.") );
1387 dirs
.Add( wxT("/etc/") );
1388 dirs
.Add( wxT("/usr/etc/") );
1389 dirs
.Add( wxT("/usr/local/etc/") );
1390 dirs
.Add( wxT("/etc/mail/") );
1391 dirs
.Add( wxT("/usr/public/lib/") );
1392 if (!sExtraDir
.empty())
1393 dirs
.Add( sExtraDir
+ wxT("/") );
1395 size_t nDirs
= dirs
.GetCount();
1396 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1398 wxString file
= dirs
[nDir
] + wxT("mailcap");
1399 if ( wxFile::Exists(file
) )
1404 file
= dirs
[nDir
] + wxT("mime.types");
1405 if ( wxFile::Exists(file
) )
1407 ReadMimeTypes(file
);
1412 bool wxMimeTypesManagerImpl::WriteToMimeTypes(int index
, bool delete_index
)
1414 // check we have the right manager
1415 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1419 wxString strHome
= wxGetenv(wxT("HOME"));
1421 // and now the users mailcap
1422 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1424 wxMimeTextFile file
;
1425 if ( wxFile::Exists(strUserMailcap
) )
1427 bTemp
= file
.Open(strUserMailcap
);
1434 bTemp
= file
.Create(strUserMailcap
);
1440 // test for netscape's header and return false if its found
1441 nIndex
= file
.pIndexOf(wxT("#--Netscape"));
1442 if (nIndex
!= wxNOT_FOUND
)
1444 wxASSERT_MSG(false,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed"));
1448 // write it in alternative format
1449 // get rid of unwanted entries
1450 wxString strType
= m_aTypes
[index
];
1451 nIndex
= file
.pIndexOf(strType
);
1453 // get rid of all the unwanted entries...
1454 if (nIndex
!= wxNOT_FOUND
)
1455 file
.CommentLine(nIndex
);
1459 // add the new entries in
1460 wxString sTmp
= strType
.Append( wxT(' '), 40 - strType
.Len() );
1461 sTmp
= sTmp
+ m_aExtensions
[index
];
1465 bTemp
= file
.Write();
1472 bool wxMimeTypesManagerImpl::WriteToNSMimeTypes(int index
, bool delete_index
)
1474 //check we have the right managers
1475 if (! ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) )
1479 wxString strHome
= wxGetenv(wxT("HOME"));
1481 // and now the users mailcap
1482 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1484 wxMimeTextFile file
;
1485 if ( wxFile::Exists(strUserMailcap
) )
1487 bTemp
= file
.Open(strUserMailcap
);
1494 bTemp
= file
.Create(strUserMailcap
);
1499 // write it in the format that Netscape uses
1501 // test for netscape's header and insert if required...
1502 // this is a comment so use true
1503 nIndex
= file
.pIndexOf(wxT("#--Netscape"), true);
1504 if (nIndex
== wxNOT_FOUND
)
1506 // either empty file or metamail format
1507 // at present we can't cope with mixed formats, so exit to preseve
1508 // metamail entreies
1509 if (file
.GetLineCount() > 0)
1511 wxASSERT_MSG(false, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
1515 file
.InsertLine(wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
1519 wxString strType
= wxT("type=") + m_aTypes
[index
];
1520 nIndex
= file
.pIndexOf(strType
);
1522 // get rid of all the unwanted entries...
1523 if (nIndex
!= wxNOT_FOUND
)
1525 wxString sOld
= file
[nIndex
];
1526 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1528 file
.CommentLine(nIndex
);
1529 sOld
= file
[nIndex
];
1531 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex
, sOld
.c_str());
1536 if (nIndex
< (int) file
.GetLineCount())
1537 file
.CommentLine(nIndex
);
1540 nIndex
= (int) file
.GetLineCount();
1542 wxString sTmp
= strType
+ wxT(" \\");
1544 file
.InsertLine(sTmp
, nIndex
);
1546 if ( ! m_aDescriptions
.Item(index
).empty() )
1548 sTmp
= wxT("desc=\"") + m_aDescriptions
[index
]+ wxT("\" \\"); //.trim ??
1552 file
.InsertLine(sTmp
, nIndex
);
1556 wxString sExts
= m_aExtensions
.Item(index
);
1557 sTmp
= wxT("exts=\"") + sExts
.Trim(false).Trim() + wxT("\"");
1561 file
.InsertLine(sTmp
, nIndex
);
1564 bTemp
= file
.Write();
1571 bool wxMimeTypesManagerImpl::WriteToMailCap(int index
, bool delete_index
)
1573 //check we have the right managers
1574 if ( !( ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) ||
1575 ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) ) )
1579 wxString strHome
= wxGetenv(wxT("HOME"));
1581 // and now the users mailcap
1582 wxString strUserMailcap
= strHome
+ wxT("/.mailcap");
1584 wxMimeTextFile file
;
1585 if ( wxFile::Exists(strUserMailcap
) )
1587 bTemp
= file
.Open(strUserMailcap
);
1594 bTemp
= file
.Create(strUserMailcap
);
1599 // now got a file we can write to ....
1600 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
1602 wxString sCmd
= entries
->GetCommandForVerb(wxT("open"), &iOpen
);
1605 sTmp
= m_aTypes
[index
];
1607 int nIndex
= file
.pIndexOf(sTmp
);
1609 // get rid of all the unwanted entries...
1610 if (nIndex
== wxNOT_FOUND
)
1612 nIndex
= (int) file
.GetLineCount();
1616 sOld
= file
[nIndex
];
1617 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mailcap line '%d' ---"), nIndex
);
1619 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1621 file
.CommentLine(nIndex
);
1622 if (nIndex
< (int) file
.GetLineCount())
1623 sOld
= sOld
+ file
[nIndex
];
1627 file
.GetLineCount()) file
.CommentLine(nIndex
);
1630 sTmp
= sTmp
+ wxT(";") + sCmd
; //includes wxT(" %s ");
1632 // write it in the format that Netscape uses (default)
1633 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1636 file
.InsertLine(sTmp
, nIndex
);
1641 // write extended format
1643 // TODO - FIX this code:
1645 // sOld holds all the entries, but our data store only has some
1646 // eg test= is not stored
1648 // so far we have written the mimetype and command out
1649 wxStringTokenizer
sT(sOld
, wxT(";\\"));
1650 if (sT
.CountTokens() > 2)
1652 // first one mimetype; second one command, rest unknown...
1654 s
= sT
.GetNextToken();
1655 s
= sT
.GetNextToken();
1658 s
= sT
.GetNextToken();
1659 while ( ! s
.empty() )
1661 bool bKnownToken
= false;
1662 if (s
.Contains(wxT("description=")))
1664 if (s
.Contains(wxT("x11-bitmap=")))
1668 for (i
=0; i
< entries
->GetCount(); i
++)
1670 if (s
.Contains(entries
->GetVerb(i
)))
1676 sTmp
= sTmp
+ wxT("; \\");
1677 file
.InsertLine(sTmp
, nIndex
);
1681 s
= sT
.GetNextToken();
1685 if (! m_aDescriptions
[index
].empty() )
1687 sTmp
= sTmp
+ wxT("; \\");
1688 file
.InsertLine(sTmp
, nIndex
);
1690 sTmp
= wxT(" description=\"") + m_aDescriptions
[index
] + wxT("\"");
1693 if (! m_aIcons
[index
].empty() )
1695 sTmp
= sTmp
+ wxT("; \\");
1696 file
.InsertLine(sTmp
, nIndex
);
1698 sTmp
= wxT(" x11-bitmap=\"") + m_aIcons
[index
] + wxT("\"");
1701 if ( entries
->GetCount() > 1 )
1704 for (i
=0; i
< entries
->GetCount(); i
++)
1707 sTmp
= sTmp
+ wxT("; \\");
1708 file
.InsertLine(sTmp
, nIndex
);
1710 sTmp
= wxT(" ") + entries
->GetVerbCmd(i
);
1714 file
.InsertLine(sTmp
, nIndex
);
1718 bTemp
= file
.Write();
1725 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
1729 wxString strType
= ftInfo
.GetMimeType();
1730 wxString strDesc
= ftInfo
.GetDescription();
1731 wxString strIcon
= ftInfo
.GetIconFile();
1733 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1735 if ( ! ftInfo
.GetOpenCommand().empty())
1736 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
1737 if ( ! ftInfo
.GetPrintCommand().empty())
1738 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
1740 // now find where these extensions are in the data store and remove them
1741 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
1742 wxString sExt
, sExtStore
;
1744 for (i
=0; i
< sA_Exts
.GetCount(); i
++)
1746 sExt
= sA_Exts
.Item(i
);
1748 // clean up to just a space before and after
1749 sExt
.Trim().Trim(false);
1750 sExt
= wxT(' ') + sExt
+ wxT(' ');
1751 for (nIndex
= 0; nIndex
< m_aExtensions
.GetCount(); nIndex
++)
1753 sExtStore
= m_aExtensions
.Item(nIndex
);
1754 if (sExtStore
.Replace(sExt
, wxT(" ") ) > 0)
1755 m_aExtensions
.Item(nIndex
) = sExtStore
;
1759 if ( !DoAssociation(strType
, strIcon
, entry
, sA_Exts
, strDesc
) )
1762 return GetFileTypeFromMimeType(strType
);
1765 bool wxMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
1766 const wxString
& strIcon
,
1767 wxMimeTypeCommands
*entry
,
1768 const wxArrayString
& strExtensions
,
1769 const wxString
& strDesc
)
1771 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
1773 if ( nIndex
== wxNOT_FOUND
)
1776 return WriteMimeInfo(nIndex
, false);
1779 bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex
, bool delete_mime
)
1783 if ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
)
1785 // write in metamail format;
1786 if (WriteToMimeTypes(nIndex
, delete_mime
) )
1787 if ( WriteToMailCap(nIndex
, delete_mime
) )
1791 if ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
)
1793 // write in netsacpe format;
1794 if (WriteToNSMimeTypes(nIndex
, delete_mime
) )
1795 if ( WriteToMailCap(nIndex
, delete_mime
) )
1799 // Don't write GNOME files here as this is not
1800 // allowed and simply doesn't work
1802 if (m_mailcapStylesInited
& wxMAILCAP_KDE
)
1804 // write in KDE format;
1805 if (WriteKDEMimeFile(nIndex
, delete_mime
) )
1812 int wxMimeTypesManagerImpl::AddToMimeData(const wxString
& strType
,
1813 const wxString
& strIcon
,
1814 wxMimeTypeCommands
*entry
,
1815 const wxArrayString
& strExtensions
,
1816 const wxString
& strDesc
,
1817 bool replaceExisting
)
1821 // ensure mimetype is always lower case
1822 wxString mimeType
= strType
.Lower();
1824 // is this a known MIME type?
1825 int nIndex
= m_aTypes
.Index(mimeType
);
1826 if ( nIndex
== wxNOT_FOUND
)
1829 m_aTypes
.Add(mimeType
);
1830 m_aIcons
.Add(strIcon
);
1831 m_aEntries
.Add(entry
? entry
: new wxMimeTypeCommands
);
1833 // change nIndex so we can use it below to add the extensions
1834 m_aExtensions
.Add(wxEmptyString
);
1835 nIndex
= m_aExtensions
.size() - 1;
1837 m_aDescriptions
.Add(strDesc
);
1839 else // yes, we already have it
1841 if ( replaceExisting
)
1843 // if new description change it
1844 if ( !strDesc
.empty())
1845 m_aDescriptions
[nIndex
] = strDesc
;
1847 // if new icon change it
1848 if ( !strIcon
.empty())
1849 m_aIcons
[nIndex
] = strIcon
;
1853 delete m_aEntries
[nIndex
];
1854 m_aEntries
[nIndex
] = entry
;
1857 else // add data we don't already have ...
1859 // if new description add only if none
1860 if ( m_aDescriptions
[nIndex
].empty() )
1861 m_aDescriptions
[nIndex
] = strDesc
;
1863 // if new icon and no existing icon
1864 if ( m_aIcons
[nIndex
].empty() )
1865 m_aIcons
[nIndex
] = strIcon
;
1867 // add any new entries...
1870 wxMimeTypeCommands
*entryOld
= m_aEntries
[nIndex
];
1872 size_t count
= entry
->GetCount();
1873 for ( size_t i
= 0; i
< count
; i
++ )
1875 const wxString
& verb
= entry
->GetVerb(i
);
1876 if ( !entryOld
->HasVerb(verb
) )
1878 entryOld
->AddOrReplaceVerb(verb
, entry
->GetCmd(i
));
1882 // as we don't store it anywhere, it won't be deleted later as
1883 // usual -- do it immediately instead
1889 // always add the extensions to this mimetype
1890 wxString
& exts
= m_aExtensions
[nIndex
];
1892 // add all extensions we don't have yet
1893 size_t count
= strExtensions
.GetCount();
1894 for ( size_t i
= 0; i
< count
; i
++ )
1896 wxString ext
= strExtensions
[i
] + wxT(' ');
1898 if ( exts
.Find(ext
) == wxNOT_FOUND
)
1904 // check data integrity
1905 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
1906 m_aTypes
.Count() == m_aExtensions
.Count() &&
1907 m_aTypes
.Count() == m_aIcons
.Count() &&
1908 m_aTypes
.Count() == m_aDescriptions
.Count() );
1913 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
1920 size_t count
= m_aExtensions
.GetCount();
1921 for ( size_t n
= 0; n
< count
; n
++ )
1923 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
1925 while ( tk
.HasMoreTokens() )
1927 // consider extensions as not being case-sensitive
1928 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
1931 wxFileType
*fileType
= new wxFileType
;
1932 fileType
->m_impl
->Init(this, n
);
1942 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
1946 wxFileType
* fileType
= NULL
;
1947 // mime types are not case-sensitive
1948 wxString
mimetype(mimeType
);
1949 mimetype
.MakeLower();
1951 // first look for an exact match
1952 int index
= m_aTypes
.Index(mimetype
);
1953 if ( index
!= wxNOT_FOUND
)
1955 fileType
= new wxFileType
;
1956 fileType
->m_impl
->Init(this, index
);
1959 // then try to find "text/*" as match for "text/plain" (for example)
1960 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
1961 // the whole string - ok.
1963 index
= wxNOT_FOUND
;
1964 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
1966 size_t nCount
= m_aTypes
.Count();
1967 for ( size_t n
= 0; n
< nCount
; n
++ )
1969 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
1970 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
1977 if ( index
!= wxNOT_FOUND
)
1979 // don't throw away fileType that was already found
1981 fileType
= new wxFileType
;
1982 fileType
->m_impl
->Init(this, index
);
1988 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
1990 wxString command
, testcmd
, sV
, sTmp
;
1991 sV
= verb
+ wxT("=");
1993 // list of verb = command pairs for this mimetype
1994 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
1997 for ( i
= 0; i
< sPairs
->GetCount (); i
++ )
1999 sTmp
= sPairs
->GetVerbCmd (i
);
2000 if ( sTmp
.Contains(sV
) )
2001 command
= sTmp
.AfterFirst(wxT('='));
2007 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
2011 wxString extensions
;
2012 const wxArrayString
& exts
= filetype
.GetExtensions();
2013 size_t nExts
= exts
.GetCount();
2014 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
2017 extensions
+= wxT(' ');
2019 extensions
+= exts
[nExt
];
2022 AddMimeTypeInfo(filetype
.GetMimeType(),
2024 filetype
.GetDescription());
2026 AddMailcapInfo(filetype
.GetMimeType(),
2027 filetype
.GetOpenCommand(),
2028 filetype
.GetPrintCommand(),
2030 filetype
.GetDescription());
2033 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
2034 const wxString
& strExtensions
,
2035 const wxString
& strDesc
)
2037 // reading mailcap may find image/* , while
2038 // reading mime.types finds image/gif and no match is made
2039 // this means all the get functions don't work fix this
2041 wxString sTmp
= strExtensions
;
2043 wxArrayString sExts
;
2044 sTmp
.Trim().Trim(false);
2046 while (!sTmp
.empty())
2048 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
2049 sTmp
= sTmp
.BeforeLast(wxT(' '));
2052 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
2055 void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString
& strType
,
2056 const wxString
& strOpenCmd
,
2057 const wxString
& strPrintCmd
,
2058 const wxString
& strTest
,
2059 const wxString
& strDesc
)
2063 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands
;
2064 entry
->Add(wxT("open=") + strOpenCmd
);
2065 entry
->Add(wxT("print=") + strPrintCmd
);
2066 entry
->Add(wxT("test=") + strTest
);
2069 wxArrayString strExtensions
;
2071 AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
2074 bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString
& strFileName
)
2076 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mime.types file '%s' ---"),
2077 strFileName
.c_str());
2079 wxTextFile
file(strFileName
);
2080 #if defined(__WXGTK20__) && wxUSE_UNICODE
2081 if ( !file
.Open(wxConvUTF8
) )
2087 // the information we extract
2088 wxString strMimeType
, strDesc
, strExtensions
;
2090 size_t nLineCount
= file
.GetLineCount();
2091 const wxChar
*pc
= NULL
;
2092 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2096 // now we're at the start of the line
2097 pc
= file
[nLine
].c_str();
2101 // we didn't finish with the previous line yet
2106 while ( wxIsspace(*pc
) )
2109 // comment or blank line?
2110 if ( *pc
== wxT('#') || !*pc
)
2112 // skip the whole line
2117 // detect file format
2118 const wxChar
*pEqualSign
= wxStrchr(pc
, wxT('='));
2119 if ( pEqualSign
== NULL
)
2124 // first field is mime type
2125 for ( strMimeType
.Empty(); !wxIsspace(*pc
) && *pc
!= wxT('\0'); pc
++ )
2131 while ( wxIsspace(*pc
) )
2134 // take all the rest of the string
2137 // no description...
2145 // the string on the left of '=' is the field name
2146 wxString
strLHS(pc
, pEqualSign
- pc
);
2149 for ( pc
= pEqualSign
+ 1; wxIsspace(*pc
); pc
++ )
2153 if ( *pc
== wxT('"') )
2155 // the string is quoted and ends at the matching quote
2156 pEnd
= wxStrchr(++pc
, wxT('"'));
2159 wxLogWarning(wxT("Mime.types file %s, line %lu: unterminated quoted string."),
2160 strFileName
.c_str(), nLine
+ 1L);
2165 // unquoted string ends at the first space or at the end of
2167 for ( pEnd
= pc
; *pEnd
&& !wxIsspace(*pEnd
); pEnd
++ )
2171 // now we have the RHS (field value)
2172 wxString
strRHS(pc
, pEnd
- pc
);
2174 // check what follows this entry
2175 if ( *pEnd
== wxT('"') )
2181 for ( pc
= pEnd
; wxIsspace(*pc
); pc
++ )
2184 // if there is something left, it may be either a '\\' to continue
2185 // the line or the next field of the same entry
2186 bool entryEnded
= *pc
== wxT('\0');
2187 bool nextFieldOnSameLine
= false;
2190 nextFieldOnSameLine
= ((*pc
!= wxT('\\')) || (pc
[1] != wxT('\0')));
2193 // now see what we got
2194 if ( strLHS
== wxT("type") )
2196 strMimeType
= strRHS
;
2198 else if ( strLHS
.StartsWith(wxT("desc")) )
2202 else if ( strLHS
== wxT("exts") )
2204 strExtensions
= strRHS
;
2206 else if ( strLHS
== wxT("icon") )
2208 // this one is simply ignored: it usually refers to Netscape
2209 // built in icons which are useless for us anyhow
2211 else if ( !strLHS
.StartsWith(wxT("x-")) )
2213 // we suppose that all fields starting with "X-" are
2214 // unregistered extensions according to the standard practice,
2215 // but it may be worth telling the user about other junk in
2216 // his mime.types file
2217 wxLogWarning(wxT("Unknown field in file %s, line %lu: '%s'."),
2218 strFileName
.c_str(), nLine
+ 1L, strLHS
.c_str());
2223 if ( !nextFieldOnSameLine
)
2225 //else: don't reset it
2227 // as we don't reset strMimeType, the next field in this entry
2228 // will be interpreted correctly.
2234 // depending on the format (Mosaic or Netscape) either space or comma
2235 // is used to separate the extensions
2236 strExtensions
.Replace(wxT(","), wxT(" "));
2238 // also deal with the leading dot
2239 if ( !strExtensions
.empty() && strExtensions
[0u] == wxT('.') )
2241 strExtensions
.erase(0, 1);
2244 wxLogTrace(TRACE_MIME
, wxT("mime.types: '%s' => '%s' (%s)"),
2245 strExtensions
.c_str(),
2246 strMimeType
.c_str(),
2249 AddMimeTypeInfo(strMimeType
, strExtensions
, strDesc
);
2251 // finished with this line
2258 // ----------------------------------------------------------------------------
2259 // UNIX mailcap files parsing
2260 // ----------------------------------------------------------------------------
2262 // the data for a single MIME type
2263 struct MailcapLineData
2272 wxArrayString verbs
,
2280 MailcapLineData() { testfailed
= needsterminal
= copiousoutput
= false; }
2283 // process a non-standard (i.e. not the first or second one) mailcap field
2285 wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData
& data
,
2286 const wxString
& curField
)
2288 if ( curField
.empty() )
2294 // is this something of the form foo=bar?
2295 const wxChar
*pEq
= wxStrchr(curField
, wxT('='));
2298 // split "LHS = RHS" in 2
2299 wxString lhs
= curField
.BeforeFirst(wxT('=')),
2300 rhs
= curField
.AfterFirst(wxT('='));
2302 lhs
.Trim(true); // from right
2303 rhs
.Trim(false); // from left
2305 // it might be quoted
2306 if ( !rhs
.empty() && rhs
[0u] == wxT('"') && rhs
.Last() == wxT('"') )
2308 rhs
= rhs
.Mid(1, rhs
.length() - 2);
2311 // is it a command verb or something else?
2312 if ( lhs
== wxT("test") )
2314 if ( wxSystem(rhs
) == 0 )
2317 wxLogTrace(TRACE_MIME_TEST
,
2318 wxT("Test '%s' for mime type '%s' succeeded."),
2319 rhs
.c_str(), data
.type
.c_str());
2323 wxLogTrace(TRACE_MIME_TEST
,
2324 wxT("Test '%s' for mime type '%s' failed, skipping."),
2325 rhs
.c_str(), data
.type
.c_str());
2327 data
.testfailed
= true;
2330 else if ( lhs
== wxT("desc") )
2334 else if ( lhs
== wxT("x11-bitmap") )
2338 else if ( lhs
== wxT("notes") )
2342 else // not a (recognized) special case, must be a verb (e.g. "print")
2344 data
.verbs
.Add(lhs
);
2345 data
.commands
.Add(rhs
);
2348 else // '=' not found
2350 // so it must be a simple flag
2351 if ( curField
== wxT("needsterminal") )
2353 data
.needsterminal
= true;
2355 else if ( curField
== wxT("copiousoutput"))
2357 // copiousoutput impies that the viewer is a console program
2358 data
.needsterminal
=
2359 data
.copiousoutput
= true;
2361 else if ( !IsKnownUnimportantField(curField
) )
2370 bool wxMimeTypesManagerImpl::ReadMailcap(const wxString
& strFileName
,
2373 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mailcap file '%s' ---"),
2374 strFileName
.c_str());
2376 wxTextFile
file(strFileName
);
2377 #if defined(__WXGTK20__) && wxUSE_UNICODE
2378 if ( !file
.Open(wxConvUTF8
) )
2384 // indices of MIME types (in m_aTypes) we already found in this file
2386 // (see the comments near the end of function for the reason we need this)
2387 wxArrayInt aIndicesSeenHere
;
2389 // accumulator for the current field
2391 curField
.reserve(1024);
2393 size_t nLineCount
= file
.GetLineCount();
2394 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2396 // now we're at the start of the line
2397 const wxChar
*pc
= file
[nLine
].c_str();
2400 while ( wxIsspace(*pc
) )
2403 // comment or empty string?
2404 if ( *pc
== wxT('#') || *pc
== wxT('\0') )
2410 // what field are we currently in? The first 2 are fixed and there may
2411 // be an arbitrary number of other fields parsed by
2412 // ProcessOtherMailcapField()
2414 // the first field is the MIME type
2421 currentToken
= Field_Type
;
2423 // the flags and field values on the current line
2424 MailcapLineData data
;
2432 // interpret the next character literally (notice that
2433 // backslash can be used for line continuation)
2434 if ( *++pc
== wxT('\0') )
2436 // fetch the next line if there is one
2437 if ( nLine
== nLineCount
- 1 )
2439 // something is wrong, bail out
2442 wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."),
2443 strFileName
.c_str(),
2448 // pass to the beginning of the next line
2449 pc
= file
[++nLine
].c_str();
2451 // skip pc++ at the end of the loop
2457 // just a normal character
2463 cont
= false; // end of line reached, exit the loop
2465 // fall through to still process this field
2468 // trim whitespaces from both sides
2469 curField
.Trim(true).Trim(false);
2471 switch ( currentToken
)
2474 data
.type
= curField
.Lower();
2475 if ( data
.type
.empty() )
2477 // I don't think that this is a valid mailcap
2478 // entry, but try to interpret it somehow
2479 data
.type
= wxT('*');
2482 if ( data
.type
.Find(wxT('/')) == wxNOT_FOUND
)
2484 // we interpret "type" as "type/*"
2485 data
.type
+= wxT("/*");
2488 currentToken
= Field_OpenCmd
;
2492 data
.cmdOpen
= curField
;
2494 currentToken
= Field_Other
;
2498 if ( !ProcessOtherMailcapField(data
, curField
) )
2500 // don't flood the user with error messages if
2501 // we don't understand something in his
2502 // mailcap, but give them in debug mode because
2503 // this might be useful for the programmer
2506 wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."),
2507 strFileName
.c_str(),
2513 else if ( data
.testfailed
)
2515 // skip this entry entirely
2519 // it already has this value
2520 //currentToken = Field_Other;
2524 wxFAIL_MSG(wxT("unknown field type in mailcap"));
2527 // next token starts immediately after ';'
2535 // continue in the same line
2539 // we read the entire entry, check what have we got
2540 // ------------------------------------------------
2542 // check that we really read something reasonable
2543 if ( currentToken
< Field_Other
)
2545 wxLogWarning(wxT("Mailcap file %s, line %lu: incomplete entry ignored."),
2546 strFileName
.c_str(), nLine
+ 1L);
2551 // if the test command failed, it's as if the entry were not there at all
2552 if ( data
.testfailed
)
2557 // support for flags:
2558 // 1. create an xterm for 'needsterminal'
2559 // 2. append "| $PAGER" for 'copiousoutput'
2561 // Note that the RFC says that having both needsterminal and
2562 // copiousoutput is probably a mistake, so it seems that running
2563 // programs with copiousoutput inside an xterm as it is done now
2564 // is a bad idea (FIXME)
2565 if ( data
.copiousoutput
)
2567 const wxChar
*p
= wxGetenv(wxT("PAGER"));
2568 data
.cmdOpen
<< wxT(" | ") << (p
? p
: wxT("more"));
2571 if ( data
.needsterminal
)
2573 data
.cmdOpen
= wxString::Format(wxT("xterm -e sh -c '%s'"),
2574 data
.cmdOpen
.c_str());
2577 if ( !data
.cmdOpen
.empty() )
2579 data
.verbs
.Insert(wxT("open"), 0);
2580 data
.commands
.Insert(data
.cmdOpen
, 0);
2583 // we have to decide whether the new entry should replace any entries
2584 // for the same MIME type we had previously found or not
2587 // the fall back entries have the lowest priority, by definition
2594 // have we seen this one before?
2595 int nIndex
= m_aTypes
.Index(data
.type
);
2597 // and if we have, was it in this file? if not, we should
2598 // overwrite the previously seen one
2599 overwrite
= nIndex
== wxNOT_FOUND
||
2600 aIndicesSeenHere
.Index(nIndex
) == wxNOT_FOUND
;
2603 wxLogTrace(TRACE_MIME
, wxT("mailcap %s: %s [%s]"),
2604 data
.type
.c_str(), data
.cmdOpen
.c_str(),
2605 overwrite
? wxT("replace") : wxT("add"));
2607 int n
= AddToMimeData
2611 new wxMimeTypeCommands(data
.verbs
, data
.commands
),
2612 wxArrayString() /* extensions */,
2619 aIndicesSeenHere
.Add(n
);
2626 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
2633 size_t count
= m_aTypes
.GetCount();
2634 for ( size_t n
= 0; n
< count
; n
++ )
2636 // don't return template types from here (i.e. anything containg '*')
2638 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
2640 mimetypes
.Add(type
);
2644 return mimetypes
.GetCount();
2647 // ----------------------------------------------------------------------------
2648 // writing to MIME type files
2649 // ----------------------------------------------------------------------------
2651 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
2653 wxArrayString sMimeTypes
;
2654 ft
->GetMimeTypes(sMimeTypes
);
2658 for (i
= 0; i
< sMimeTypes
.GetCount(); i
++)
2660 sMime
= sMimeTypes
.Item(i
);
2661 int nIndex
= m_aTypes
.Index(sMime
);
2662 if ( nIndex
== wxNOT_FOUND
)
2664 // error if we get here ??
2669 WriteMimeInfo(nIndex
, true);
2670 m_aTypes
.RemoveAt(nIndex
);
2671 m_aEntries
.RemoveAt(nIndex
);
2672 m_aExtensions
.RemoveAt(nIndex
);
2673 m_aDescriptions
.RemoveAt(nIndex
);
2674 m_aIcons
.RemoveAt(nIndex
);
2677 // check data integrity
2678 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
2679 m_aTypes
.Count() == m_aExtensions
.Count() &&
2680 m_aTypes
.Count() == m_aIcons
.Count() &&
2681 m_aTypes
.Count() == m_aDescriptions
.Count() );
2686 // ----------------------------------------------------------------------------
2687 // private functions
2688 // ----------------------------------------------------------------------------
2690 static bool IsKnownUnimportantField(const wxString
& fieldAll
)
2692 static const wxChar
*knownFields
[] =
2694 wxT("x-mozilla-flags"),
2695 wxT("nametemplate"),
2696 wxT("textualnewlines"),
2699 wxString field
= fieldAll
.BeforeFirst(wxT('='));
2700 for ( size_t n
= 0; n
< WXSIZEOF(knownFields
); n
++ )
2702 if ( field
.CmpNoCase(knownFields
[n
]) == 0 )
2710 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE