1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
39 #if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE
41 #include "wx/unix/mimetype.h"
44 #include "wx/dynarray.h"
45 #include "wx/string.h"
52 #include "wx/confbase.h"
55 #include "wx/textfile.h"
57 #include "wx/tokenzr.h"
58 #include "wx/iconloc.h"
59 #include "wx/filename.h"
63 #include "wx/gtk/gnome/gvfs.h"
66 // other standard headers
69 // this class extends wxTextFile
72 class wxMimeTextFile
: public wxTextFile
76 wxMimeTextFile () : wxTextFile () {};
77 wxMimeTextFile(const wxString
& strFile
) : wxTextFile(strFile
) {};
79 int pIndexOf(const wxString
& sSearch
, bool bIncludeComments
= false, int iStart
= 0)
82 int nResult
= wxNOT_FOUND
;
83 if (i
>= GetLineCount())
86 wxString sTest
= sSearch
;
92 while ( i
< GetLineCount() )
96 if (sLine
.Contains(sTest
))
104 while ( (i
< GetLineCount()) )
108 if ( ! sLine
.StartsWith(wxT("#")))
110 if (sLine
.Contains(sTest
))
121 bool CommentLine(int nIndex
)
125 if (nIndex
>= (int)GetLineCount() )
128 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
132 bool CommentLine(const wxString
& sTest
)
134 int nIndex
= pIndexOf(sTest
);
137 if (nIndex
>= (int)GetLineCount() )
140 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
144 wxString
GetVerb(size_t i
)
146 if (i
> GetLineCount() )
147 return wxEmptyString
;
149 wxString sTmp
= GetLine(i
).BeforeFirst(wxT('='));
153 wxString
GetCmd(size_t i
)
155 if (i
> GetLineCount() )
156 return wxEmptyString
;
158 wxString sTmp
= GetLine(i
).AfterFirst(wxT('='));
163 // in case we're compiling in non-GUI mode
164 class WXDLLEXPORT wxIcon
;
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 // MIME code tracing mask
171 #define TRACE_MIME wxT("mime")
173 // give trace messages about the results of mailcap tests
174 #define TRACE_MIME_TEST wxT("mimetest")
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 // there are some fields which we don't understand but for which we don't give
181 // warnings as we know that they're not important - this function is used to
183 static bool IsKnownUnimportantField(const wxString
& field
);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
190 // This class uses both mailcap and mime.types to gather information about file
193 // The information about mailcap file was extracted from metamail(1) sources
194 // and documentation and subsequently revised when I found the RFC 1524
197 // Format of mailcap file: spaces are ignored, each line is either a comment
198 // (starts with '#') or a line of the form <field1>;<field2>;...;<fieldN>.
199 // A backslash can be used to quote semicolons and newlines (and, in fact,
200 // anything else including itself).
202 // The first field is always the MIME type in the form of type/subtype (see RFC
203 // 822) where subtype may be '*' meaning "any". Following metamail, we accept
204 // "type" which means the same as "type/*", although I'm not sure whether this
207 // The second field is always the command to run. It is subject to
208 // parameter/filename expansion described below.
210 // All the following fields are optional and may not be present at all. If
211 // they're present they may appear in any order, although each of them should
212 // appear only once. The optional fields are the following:
213 // * notes=xxx is an uninterpreted string which is silently ignored
214 // * test=xxx is the command to be used to determine whether this mailcap line
215 // applies to our data or not. The RHS of this field goes through the
216 // parameter/filename expansion (as the 2nd field) and the resulting string
217 // is executed. The line applies only if the command succeeds, i.e. returns 0
219 // * print=xxx is the command to be used to print (and not view) the data of
220 // this type (parameter/filename expansion is done here too)
221 // * edit=xxx is the command to open/edit the data of this type
222 // * needsterminal means that a new interactive console must be created for
224 // * copiousoutput means that the viewer doesn't interact with the user but
225 // produces (possibly) a lof of lines of output on stdout (i.e. "cat" is a
226 // good example), thus it might be a good idea to use some kind of paging
228 // * textualnewlines means not to perform CR/LF translation (not honored)
229 // * compose and composetyped fields are used to determine the program to be
230 // called to create a new message pert in the specified format (unused).
232 // Parameter/filename expansion:
233 // * %s is replaced with the (full) file name
234 // * %t is replaced with MIME type/subtype of the entry
235 // * for multipart type only %n is replaced with the nnumber of parts and %F is
236 // replaced by an array of (content-type, temporary file name) pairs for all
237 // message parts (TODO)
238 // * %{parameter} is replaced with the value of parameter taken from
239 // Content-type header line of the message.
242 // There are 2 possible formats for mime.types file, one entry per line (used
243 // for global mime.types and called Mosaic format) and "expanded" format where
244 // an entry takes multiple lines (used for users mime.types and called
247 // For both formats spaces are ignored and lines starting with a '#' are
248 // comments. Each record has one of two following forms:
249 // a) for "brief" format:
250 // <mime type> <space separated list of extensions>
251 // b) for "expanded" format:
252 // type=<mime type> BACKSLASH
253 // desc="<description>" BACKSLASH
254 // exts="<comma separated list of extensions>"
256 // (where BACKSLASH is a literal '\\' which we can't put here because cpp
259 // We try to autodetect the format of mime.types: if a non-comment line starts
260 // with "type=" we assume the second format, otherwise the first one.
262 // there may be more than one entry for one and the same mime type, to
263 // choose the right one we have to run the command specified in the test
264 // field on our data.
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
270 // GNOME stores the info we're interested in in several locations:
271 // 1. xxx.keys files under /usr/share/mime-info
272 // 2. xxx.keys files under ~/.gnome/mime-info
274 // Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
275 // just before the field name.
278 void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString
& filename
,
279 const wxArrayString
& dirs
)
281 wxTextFile
textfile(filename
);
282 #if defined(__WXGTK20__) && wxUSE_UNICODE
283 if ( !textfile
.Open(wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL
)) )
285 if ( !textfile
.Open() )
289 wxLogTrace(TRACE_MIME
, wxT("--- Opened Gnome file %s ---"),
292 wxArrayString
search_dirs( dirs
);
294 // values for the entry being parsed
295 wxString curMimeType
, curIconFile
;
296 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
298 wxArrayString strExtensions
;
302 size_t nLineCount
= textfile
.GetLineCount();
304 while ( nLine
< nLineCount
)
306 pc
= textfile
[nLine
].c_str();
307 if ( *pc
!= wxT('#') )
310 wxLogTrace(TRACE_MIME
, wxT("--- Reading from Gnome file %s '%s' ---"),
311 filename
.c_str(), pc
);
313 // trim trailing space and tab
314 while ((*pc
== wxT(' ')) || (*pc
== wxT('\t')))
318 int equal_pos
= sTmp
.Find( wxT('=') );
321 wxString left_of_equal
= sTmp
.Left( equal_pos
);
322 const wxChar
*right_of_equal
= pc
;
323 right_of_equal
+= equal_pos
+1;
325 if (left_of_equal
== wxT("icon_filename"))
328 curIconFile
= right_of_equal
;
330 wxFileName
newFile( curIconFile
);
331 if (newFile
.IsRelative() || newFile
.FileExists())
333 size_t nDirs
= search_dirs
.GetCount();
335 for (size_t nDir
= 0; nDir
< nDirs
; nDir
++)
337 newFile
.SetPath( search_dirs
[nDir
] );
338 newFile
.AppendDir( wxT("pixmaps") );
339 newFile
.AppendDir( wxT("document-icons") );
340 newFile
.SetExt( wxT("png") );
341 if (newFile
.FileExists())
343 curIconFile
= newFile
.GetFullPath();
344 // reorder search_dirs for speedup (fewer
345 // calls to FileExist() required)
348 wxString tmp
= search_dirs
[nDir
];
349 search_dirs
.RemoveAt( nDir
);
350 search_dirs
.Insert( tmp
, 0 );
357 else if (left_of_equal
== wxT("open"))
359 sTmp
= right_of_equal
;
360 sTmp
.Replace( wxT("%f"), wxT("%s") );
361 sTmp
.Prepend( wxT("open=") );
364 else if (left_of_equal
== wxT("view"))
366 sTmp
= right_of_equal
;
367 sTmp
.Replace( wxT("%f"), wxT("%s") );
368 sTmp
.Prepend( wxT("view=") );
371 else if (left_of_equal
== wxT("print"))
373 sTmp
= right_of_equal
;
374 sTmp
.Replace( wxT("%f"), wxT("%s") );
375 sTmp
.Prepend( wxT("print=") );
378 else if (left_of_equal
== wxT("description"))
380 strDesc
= right_of_equal
;
382 else if (left_of_equal
== wxT("short_list_application_ids_for_novice_user_level"))
384 sTmp
= right_of_equal
;
385 if (sTmp
.Contains( wxT(",") ))
386 sTmp
= sTmp
.BeforeFirst( wxT(',') );
387 sTmp
.Prepend( wxT("open=") );
388 sTmp
.Append( wxT(" %s") );
392 } // emd of has an equals sign
395 // not a comment and not an equals sign
396 if (sTmp
.Contains(wxT('/')))
398 // this is the start of the new mimetype
399 // overwrite any existing data
400 if (! curMimeType
.empty())
402 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
404 // now get ready for next bit
405 entry
= new wxMimeTypeCommands
;
408 curMimeType
= sTmp
.BeforeFirst(wxT(':'));
411 } // end of not a comment
413 // ignore blank lines
415 } // end of while, save any data
417 if ( curMimeType
.empty() )
420 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
423 void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString
& filename
)
425 wxTextFile
textfile(filename
);
426 if ( !textfile
.Open() )
429 wxLogTrace(TRACE_MIME
,
430 wxT("--- Opened Gnome file %s ---"),
433 // values for the entry being parsed
434 wxString curMimeType
, curExtList
;
437 size_t nLineCount
= textfile
.GetLineCount();
438 for ( size_t nLine
= 0; /* nothing */; nLine
++ )
440 if ( nLine
< nLineCount
)
442 pc
= textfile
[nLine
].c_str();
443 if ( *pc
== wxT('#') )
451 // so that we will fall into the "if" below
458 if ( !curMimeType
.empty() && !curExtList
.empty() )
460 wxLogTrace(TRACE_MIME
,
461 wxT("--- At end of Gnome file finding mimetype %s ---"),
462 curMimeType
.c_str());
464 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
469 // the end: this can only happen if nLine == nLineCount
478 // what do we have here?
479 if ( *pc
== wxT('\t') )
481 // this is a field=value ling
482 pc
++; // skip leading TAB
484 static const int lenField
= 5; // strlen("ext: ")
485 if ( wxStrncmp(pc
, wxT("ext: "), lenField
) == 0 )
487 // skip it and take everything left until the end of line
488 curExtList
= pc
+ lenField
;
490 //else: some other field, we don't care
494 // this is the start of the new section
495 wxLogTrace(TRACE_MIME
,
496 wxT("--- In Gnome file finding mimetype %s ---"),
497 curMimeType
.c_str());
499 if (! curMimeType
.empty())
500 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
504 while ( *pc
!= wxT(':') && *pc
!= wxT('\0') )
506 curMimeType
+= *pc
++;
513 void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
514 const wxString
& dirbase
, const wxArrayString
& dirs
)
516 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
517 wxT("base directory shouldn't end with a slash") );
519 wxString dirname
= dirbase
;
520 dirname
<< wxT("/mime-info");
522 if ( !wxDir::Exists(dirname
) )
526 if ( !dir
.IsOpened() )
529 // we will concatenate it with filename to get the full path below
535 cont
= dir
.GetFirst(&filename
, wxT("*.mime"), wxDIR_FILES
);
538 LoadGnomeMimeTypesFromMimeFile(dirname
+ filename
);
540 cont
= dir
.GetNext(&filename
);
543 cont
= dir
.GetFirst(&filename
, wxT("*.keys"), wxDIR_FILES
);
546 LoadGnomeDataFromKeyFile(dirname
+ filename
, dirs
);
548 cont
= dir
.GetNext(&filename
);
551 // FIXME: Hack alert: We scan all icons and deduce the
552 // mime-type from the file name.
554 dirname
<< wxT("/pixmaps/document-icons");
556 // these are always empty in this file
557 wxArrayString strExtensions
;
560 if ( !wxDir::Exists(dirname
) )
562 // Just test for default GPE dir also
563 dirname
= wxT("/usr/share/gpe/pixmaps/default/filemanager/document-icons");
565 if ( !wxDir::Exists(dirname
) )
569 wxDir
dir2( dirname
);
571 cont
= dir2
.GetFirst(&filename
, wxT("gnome-*.png"), wxDIR_FILES
);
574 wxString mimeType
= filename
;
575 mimeType
.Remove( 0, 6 ); // remove "gnome-"
576 mimeType
.Remove( mimeType
.Len() - 4, 4 ); // remove ".png"
577 int pos
= mimeType
.Find( wxT("-") );
578 if (pos
!= wxNOT_FOUND
)
580 mimeType
.SetChar( pos
, wxT('/') );
581 wxString iconFile
= dirname
;
582 iconFile
<< wxT("/");
583 iconFile
<< filename
;
584 AddToMimeData( mimeType
, iconFile
, NULL
, strExtensions
, strDesc
, true );
587 cont
= dir2
.GetNext(&filename
);
591 void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString
& sExtraDir
)
595 wxString gnomedir
= wxGetenv( wxT("GNOMEDIR") );
596 if (!gnomedir
.empty())
598 gnomedir
<< wxT("/share");
599 dirs
.Add( gnomedir
);
602 dirs
.Add(wxT("/usr/share"));
603 dirs
.Add(wxT("/usr/local/share"));
605 gnomedir
= wxGetHomeDir();
606 gnomedir
<< wxT("/.gnome");
607 dirs
.Add( gnomedir
);
609 if (!sExtraDir
.empty())
610 dirs
.Add( sExtraDir
);
612 size_t nDirs
= dirs
.GetCount();
613 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
615 LoadGnomeMimeFilesFromDir(dirs
[nDir
], dirs
);
619 // ----------------------------------------------------------------------------
621 // ----------------------------------------------------------------------------
624 // KDE stores the icon info in its .kdelnk files. The file for mimetype/subtype
625 // may be found in either of the following locations
627 // 1. $KDEDIR/share/mimelnk/mimetype/subtype.kdelnk
628 // 2. ~/.kde/share/mimelnk/mimetype/subtype.kdelnk
630 // The format of a .kdelnk file is almost the same as the one used by
631 // wxFileConfig, i.e. there are groups, comments and entries. The icon is the
632 // value for the entry "Type"
634 // kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD
635 // for now write to .kdelnk but should eventually do .desktop instead (in preference??)
637 bool wxMimeTypesManagerImpl::CheckKDEDirsExist( const wxString
&sOK
, const wxString
&sTest
)
641 return wxDir::Exists(sOK
);
645 wxString sStart
= sOK
+ wxT("/") + sTest
.BeforeFirst(wxT('/'));
646 if (!wxDir::Exists(sStart
))
648 wxString sEnd
= sTest
.AfterFirst(wxT('/'));
649 return CheckKDEDirsExist(sStart
, sEnd
);
653 bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index
, bool delete_index
)
655 wxMimeTextFile appoutfile
, mimeoutfile
;
656 wxString sHome
= wxGetHomeDir();
657 wxString sTmp
= wxT(".kde/share/mimelnk/");
658 wxString sMime
= m_aTypes
[index
];
659 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.BeforeFirst(wxT('/')) );
660 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
+ wxT(".kdelnk");
663 bool bMimeExists
= mimeoutfile
.Open(sTmp
);
666 bTemp
= mimeoutfile
.Create(sTmp
);
667 // some unknown error eg out of disk space
672 sTmp
= wxT(".kde/share/applnk/");
673 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.AfterFirst(wxT('/')) );
674 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
.AfterFirst(wxT('/')) + wxT(".kdelnk");
677 bAppExists
= appoutfile
.Open(sTmp
);
680 bTemp
= appoutfile
.Create(sTmp
);
681 // some unknown error eg out of disk space
686 // fixed data; write if new file
689 mimeoutfile
.AddLine(wxT("#KDE Config File"));
690 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
691 mimeoutfile
.AddLine(wxT("Version=1.0"));
692 mimeoutfile
.AddLine(wxT("Type=MimeType"));
693 mimeoutfile
.AddLine(wxT("MimeType=") + sMime
);
698 mimeoutfile
.AddLine(wxT("#KDE Config File"));
699 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
700 appoutfile
.AddLine(wxT("Version=1.0"));
701 appoutfile
.AddLine(wxT("Type=Application"));
702 appoutfile
.AddLine(wxT("MimeType=") + sMime
+ wxT(';'));
707 mimeoutfile
.CommentLine(wxT("Comment="));
709 mimeoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
710 appoutfile
.CommentLine(wxT("Name="));
712 appoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
714 sTmp
= m_aIcons
[index
];
715 // we can either give the full path, or the shortfilename if its in
716 // one of the directories we search
717 mimeoutfile
.CommentLine(wxT("Icon=") );
719 mimeoutfile
.AddLine(wxT("Icon=") + sTmp
);
720 appoutfile
.CommentLine(wxT("Icon=") );
722 appoutfile
.AddLine(wxT("Icon=") + sTmp
);
724 sTmp
= wxT(" ") + m_aExtensions
[index
];
726 wxStringTokenizer
tokenizer(sTmp
, wxT(" "));
727 sTmp
= wxT("Patterns=");
728 mimeoutfile
.CommentLine(sTmp
);
729 while ( tokenizer
.HasMoreTokens() )
731 // holds an extension; need to change it to *.ext;
732 wxString e
= wxT("*.") + tokenizer
.GetNextToken() + wxT(";");
737 mimeoutfile
.AddLine(sTmp
);
739 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
740 // if we don't find open just have an empty string ... FIX this
741 sTmp
= entries
->GetCommandForVerb(wxT("open"));
742 sTmp
.Replace( wxT("%s"), wxT("%f") );
744 mimeoutfile
.CommentLine(wxT("DefaultApp=") );
746 mimeoutfile
.AddLine(wxT("DefaultApp=") + sTmp
);
748 sTmp
.Replace( wxT("%f"), wxT("") );
749 appoutfile
.CommentLine(wxT("Exec="));
751 appoutfile
.AddLine(wxT("Exec=") + sTmp
);
753 if (entries
->GetCount() > 1)
755 //other actions as well as open
759 if (mimeoutfile
.Write())
762 if (appoutfile
.Write())
769 void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString
& dirbase
,
770 const wxString
& subdir
,
771 const wxString
& filename
,
772 const wxArrayString
& icondirs
)
775 if ( !file
.Open(dirbase
+ filename
) )
778 wxLogTrace(TRACE_MIME
, wxT("loading KDE file %s"),
779 (dirbase
+ filename
).c_str());
781 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
783 wxString mimetype
, mime_desc
, strIcon
;
785 int nIndex
= file
.pIndexOf( wxT("MimeType=") );
786 if (nIndex
== wxNOT_FOUND
)
788 // construct mimetype from the directory name and the basename of the
789 // file (it always has .kdelnk extension)
790 mimetype
<< subdir
<< wxT('/') << filename
.BeforeLast( wxT('.') );
793 mimetype
= file
.GetCmd(nIndex
);
795 // first find the description string: it is the value in either "Comment="
796 // line or "Comment[<locale_name>]=" one
797 nIndex
= wxNOT_FOUND
;
802 wxLocale
*locale
= wxGetLocale();
805 // try "Comment[locale name]" first
806 comment
<< wxT("Comment[") + locale
->GetName() + wxT("]=");
807 nIndex
= file
.pIndexOf(comment
);
811 if ( nIndex
== wxNOT_FOUND
)
813 comment
= wxT("Comment=");
814 nIndex
= file
.pIndexOf(comment
);
817 if ( nIndex
!= wxNOT_FOUND
)
818 mime_desc
= file
.GetCmd(nIndex
);
819 //else: no description
821 // next find the extensions
822 wxString mime_extension
;
824 nIndex
= file
.pIndexOf(wxT("Patterns="));
825 if ( nIndex
!= wxNOT_FOUND
)
827 wxString exts
= file
.GetCmd(nIndex
);
829 wxStringTokenizer
tokenizer(exts
, wxT(";"));
830 while ( tokenizer
.HasMoreTokens() )
832 wxString e
= tokenizer
.GetNextToken();
834 // don't support too difficult patterns
835 if ( e
.Left(2) != wxT("*.") )
838 if ( !mime_extension
.empty() )
840 // separate from the previous ext
841 mime_extension
<< wxT(' ');
844 mime_extension
<< e
.Mid(2);
848 sExts
.Add(mime_extension
);
850 // ok, now we can take care of icon:
852 nIndex
= file
.pIndexOf(wxT("Icon="));
853 if ( nIndex
!= wxNOT_FOUND
)
855 strIcon
= file
.GetCmd(nIndex
);
857 wxLogTrace(TRACE_MIME
, wxT(" icon %s"), strIcon
.c_str());
859 // it could be the real path, but more often a short name
860 if (!wxFileExists(strIcon
))
862 // icon is just the short name
863 if ( !strIcon
.empty() )
865 // we must check if the file exists because it may be stored
866 // in many locations, at least ~/.kde and $KDEDIR
867 size_t nDir
, nDirs
= icondirs
.GetCount();
868 for ( nDir
= 0; nDir
< nDirs
; nDir
++ )
870 wxFileName
fnameIcon( strIcon
);
871 wxFileName
fname( icondirs
[nDir
], fnameIcon
.GetName() );
872 fname
.SetExt( wxT("png") );
873 if (fname
.FileExists())
875 strIcon
= fname
.GetFullPath();
876 wxLogTrace(TRACE_MIME
, wxT(" iconfile %s"), strIcon
.c_str());
884 // now look for lines which know about the application
885 // exec= or DefaultApp=
887 nIndex
= file
.pIndexOf(wxT("DefaultApp"));
889 if ( nIndex
== wxNOT_FOUND
)
892 nIndex
= file
.pIndexOf(wxT("Exec"));
895 if ( nIndex
!= wxNOT_FOUND
)
897 // we expect %f; others including %F and %U and %u are possible
898 wxString sTmp
= file
.GetCmd(nIndex
);
899 if (0 == sTmp
.Replace( wxT("%f"), wxT("%s") ))
900 sTmp
= sTmp
+ wxT(" %s");
901 entry
->AddOrReplaceVerb(wxString(wxT("open")), sTmp
);
904 AddToMimeData(mimetype
, strIcon
, entry
, sExts
, mime_desc
);
907 void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString
& dirbase
,
908 const wxString
& subdir
,
909 const wxArrayString
& icondirs
)
911 wxString dirname
= dirbase
;
914 if ( !dir
.IsOpened() )
917 wxLogTrace(TRACE_MIME
, wxT("--- Loading from KDE directory %s ---"),
923 bool cont
= dir
.GetFirst(&filename
, wxT("*.kdelnk"), wxDIR_FILES
);
926 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
928 cont
= dir
.GetNext(&filename
);
931 // new standard for Gnome and KDE
932 cont
= dir
.GetFirst(&filename
, wxT("*.desktop"), wxDIR_FILES
);
935 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
937 cont
= dir
.GetNext(&filename
);
941 void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString
& dirbase
,
942 const wxArrayString
& icondirs
)
944 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
945 wxT("base directory shouldn't end with a slash") );
947 wxString dirname
= dirbase
;
948 dirname
<< wxT("/mimelnk");
950 if ( !wxDir::Exists(dirname
) )
954 if ( !dir
.IsOpened() )
957 // we will concatenate it with dir name to get the full path below
961 bool cont
= dir
.GetFirst(&subdir
, wxEmptyString
, wxDIR_DIRS
);
964 LoadKDELinksForMimeType(dirname
, subdir
, icondirs
);
966 cont
= dir
.GetNext(&subdir
);
970 void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString
& sExtraDir
)
973 wxArrayString icondirs
;
975 // FIXME: This code is heavily broken. There are three bugs in it:
976 // 1) it uses only KDEDIR, which is deprecated, instead of using
977 // list of paths from KDEDIRS and using KDEDIR only if KDEDIRS
979 // 2) it doesn't look into ~/.kde/share/config/kdeglobals where
980 // user's settings are stored and thus *ignores* user's settings
981 // instead of respecting them
982 // 3) it "tries to guess KDEDIR" and "tries a few likely theme
983 // names", both of which is completely arbitrary; instead, the
984 // code should give up if KDEDIR(S) is not set and/or the icon
985 // theme cannot be determined, because it means that the user is
986 // not using KDE (and thus is not interested in KDE icons anyway)
988 // the variable $KDEDIR is set when KDE is running
989 wxString kdedir
= wxGetenv( wxT("KDEDIR") );
993 // $(KDEDIR)/share/config/kdeglobals holds info
994 // the current icons theme
995 wxFileName
configFile( kdedir
, wxEmptyString
);
996 configFile
.AppendDir( wxT("share") );
997 configFile
.AppendDir( wxT("config") );
998 configFile
.SetName( wxT("kdeglobals") );
1001 if (configFile
.FileExists() && config
.Open(configFile
.GetFullPath()))
1003 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1004 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1005 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1006 configFile
.AppendDir( wxT("icons") );
1009 wxString
theme(wxT("default.kde"));
1010 size_t cnt
= config
.GetLineCount();
1011 for (size_t i
= 0; i
< cnt
; i
++)
1013 if (config
[i
].StartsWith(wxT("Theme="), &theme
/*rest*/))
1017 configFile
.AppendDir(theme
);
1021 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1022 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1024 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1025 configFile
.AppendDir( wxT("icons") );
1027 // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
1028 configFile
.AppendDir( wxT("default.kde") );
1031 configFile
.SetName( wxEmptyString
);
1032 configFile
.AppendDir( wxT("32x32") );
1033 configFile
.AppendDir( wxT("mimetypes") );
1035 // Just try a few likely icons theme names
1037 int pos
= configFile
.GetDirCount() - 3;
1039 if (!wxDir::Exists(configFile
.GetPath()))
1041 configFile
.RemoveDir( pos
);
1042 configFile
.InsertDir( pos
, wxT("default.kde") );
1045 if (!wxDir::Exists(configFile
.GetPath()))
1047 configFile
.RemoveDir( pos
);
1048 configFile
.InsertDir( pos
, wxT("default") );
1051 if (!wxDir::Exists(configFile
.GetPath()))
1053 configFile
.RemoveDir( pos
);
1054 configFile
.InsertDir( pos
, wxT("crystalsvg") );
1057 if (!wxDir::Exists(configFile
.GetPath()))
1059 configFile
.RemoveDir( pos
);
1060 configFile
.InsertDir( pos
, wxT("crystal") );
1063 if (wxDir::Exists(configFile
.GetPath()))
1064 icondirs
.Add( configFile
.GetFullPath() );
1067 // settings in ~/.kde have maximal priority
1068 dirs
.Add(wxGetHomeDir() + wxT("/.kde/share"));
1069 icondirs
.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
1073 dirs
.Add( wxString(kdedir
) + wxT("/share") );
1074 icondirs
.Add( wxString(kdedir
) + wxT("/share/icons/") );
1078 // try to guess KDEDIR
1079 dirs
.Add(wxT("/usr/share"));
1080 dirs
.Add(wxT("/opt/kde/share"));
1081 icondirs
.Add(wxT("/usr/share/icons/"));
1082 icondirs
.Add(wxT("/usr/X11R6/share/icons/")); // Debian/Corel linux
1083 icondirs
.Add(wxT("/opt/kde/share/icons/"));
1086 if (!sExtraDir
.empty())
1087 dirs
.Add(sExtraDir
);
1088 icondirs
.Add(sExtraDir
+ wxT("/icons"));
1090 size_t nDirs
= dirs
.GetCount();
1091 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1093 LoadKDELinkFilesFromDir(dirs
[nDir
], icondirs
);
1097 // ----------------------------------------------------------------------------
1098 // wxFileTypeImpl (Unix)
1099 // ----------------------------------------------------------------------------
1101 wxString
wxFileTypeImpl::GetExpandedCommand(const wxString
& verb
, const wxFileType::MessageParameters
& params
) const
1105 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1107 sTmp
= m_manager
->GetCommand( verb
, m_index
[i
] );
1111 return wxFileType::ExpandCommand(sTmp
, params
);
1114 bool wxFileTypeImpl::GetIcon(wxIconLocation
*iconLoc
) const
1118 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1120 sTmp
= m_manager
->m_aIcons
[m_index
[i
]];
1129 iconLoc
->SetFileName(sTmp
);
1135 bool wxFileTypeImpl::GetMimeTypes(wxArrayString
& mimeTypes
) const
1138 for (size_t i
= 0; i
< m_index
.GetCount(); i
++)
1139 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
1144 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
1145 wxArrayString
*commands
,
1146 const wxFileType::MessageParameters
& params
) const
1148 wxString vrb
, cmd
, sTmp
;
1150 wxMimeTypeCommands
* sPairs
;
1152 // verbs and commands have been cleared already in mimecmn.cpp...
1153 // if we find no entries in the exact match, try the inexact match
1154 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
1156 // list of verb = command pairs for this mimetype
1157 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
1159 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
1161 vrb
= sPairs
->GetVerb(i
);
1162 // some gnome entries have "." inside
1163 vrb
= vrb
.AfterLast(wxT('.'));
1164 cmd
= sPairs
->GetCmd(i
);
1167 cmd
= wxFileType::ExpandCommand(cmd
, params
);
1169 if ( vrb
.IsSameAs(wxT("open")))
1172 verbs
->Insert(vrb
, 0u);
1174 commands
->Insert(cmd
, 0u);
1190 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
1192 wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
1195 // one extension in the space or comma-delimited list
1197 for ( const wxChar
*p
= strExtensions
; /* nothing */; p
++ )
1199 if ( *p
== wxT(' ') || *p
== wxT(',') || *p
== wxT('\0') )
1201 if ( !strExt
.empty() )
1203 extensions
.Add(strExt
);
1206 //else: repeated spaces
1207 // (shouldn't happen, but it's not that important if it does happen)
1209 if ( *p
== wxT('\0') )
1212 else if ( *p
== wxT('.') )
1214 // remove the dot from extension (but only if it's the first char)
1215 if ( !strExt
.empty() )
1219 //else: no, don't append it
1230 // set an arbitrary command:
1231 // could adjust the code to ask confirmation if it already exists and
1232 // overwriteprompt is true, but this is currently ignored as *Associate* has
1233 // no overwrite prompt
1235 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
1236 const wxString
& verb
,
1237 bool WXUNUSED(overwriteprompt
))
1239 wxArrayString strExtensions
;
1240 wxString strDesc
, strIcon
;
1242 wxArrayString strTypes
;
1243 GetMimeTypes(strTypes
);
1244 if ( strTypes
.IsEmpty() )
1247 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1248 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
1251 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1253 if (!m_manager
->DoAssociation(strTypes
[i
], strIcon
, entry
, strExtensions
, strDesc
))
1260 // ignore index on the grouds that we only have one icon in a Unix file
1261 bool wxFileTypeImpl::SetDefaultIcon(const wxString
& strIcon
, int WXUNUSED(index
))
1263 if (strIcon
.empty())
1266 wxArrayString strExtensions
;
1269 wxArrayString strTypes
;
1270 GetMimeTypes(strTypes
);
1271 if ( strTypes
.IsEmpty() )
1274 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1276 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1278 if ( !m_manager
->DoAssociation
1294 // ----------------------------------------------------------------------------
1295 // wxMimeTypesManagerImpl (Unix)
1296 // ----------------------------------------------------------------------------
1298 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
1300 m_initialized
= false;
1301 m_mailcapStylesInited
= 0;
1304 void wxMimeTypesManagerImpl::InitIfNeeded()
1306 if ( !m_initialized
)
1308 // set the flag first to prevent recursion
1309 m_initialized
= true;
1311 wxString wm
= wxGetenv( wxT("WINDOWMANAGER") );
1313 if (wm
.Find( wxT("kde") ) != wxNOT_FOUND
)
1314 Initialize( wxMAILCAP_KDE
);
1315 else if (wm
.Find( wxT("gnome") ) != wxNOT_FOUND
)
1316 Initialize( wxMAILCAP_GNOME
);
1322 // read system and user mailcaps and other files
1323 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
1324 const wxString
& sExtraDir
)
1326 // read mimecap amd mime.types
1327 if ( (mailcapStyles
& wxMAILCAP_NETSCAPE
) ||
1328 (mailcapStyles
& wxMAILCAP_STANDARD
) )
1329 GetMimeInfo(sExtraDir
);
1331 // read GNOME tables
1332 if (mailcapStyles
& wxMAILCAP_GNOME
)
1333 GetGnomeMimeInfo(sExtraDir
);
1336 if (mailcapStyles
& wxMAILCAP_KDE
)
1337 GetKDEMimeInfo(sExtraDir
);
1339 m_mailcapStylesInited
|= mailcapStyles
;
1342 // clear data so you can read another group of WM files
1343 void wxMimeTypesManagerImpl::ClearData()
1347 m_aExtensions
.Clear();
1348 m_aDescriptions
.Clear();
1350 WX_CLEAR_ARRAY(m_aEntries
);
1353 m_mailcapStylesInited
= 0;
1356 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
1361 void wxMimeTypesManagerImpl::GetMimeInfo(const wxString
& sExtraDir
)
1363 // read this for netscape or Metamail formats
1365 // directories where we look for mailcap and mime.types by default
1366 // used by netscape and pine and other mailers, using 2 different formats!
1368 // (taken from metamail(1) sources)
1370 // although RFC 1524 specifies the search path of
1371 // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
1372 // places - OTOH, the RFC also says that this path can be changed with
1373 // MAILCAPS environment variable (containing the colon separated full
1374 // filenames to try) which is not done yet (TODO?)
1376 wxString strHome
= wxGetenv(wxT("HOME"));
1379 dirs
.Add( strHome
+ wxT("/.") );
1380 dirs
.Add( wxT("/etc/") );
1381 dirs
.Add( wxT("/usr/etc/") );
1382 dirs
.Add( wxT("/usr/local/etc/") );
1383 dirs
.Add( wxT("/etc/mail/") );
1384 dirs
.Add( wxT("/usr/public/lib/") );
1385 if (!sExtraDir
.empty())
1386 dirs
.Add( sExtraDir
+ wxT("/") );
1388 size_t nDirs
= dirs
.GetCount();
1389 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1391 wxString file
= dirs
[nDir
] + wxT("mailcap");
1392 if ( wxFile::Exists(file
) )
1397 file
= dirs
[nDir
] + wxT("mime.types");
1398 if ( wxFile::Exists(file
) )
1400 ReadMimeTypes(file
);
1405 bool wxMimeTypesManagerImpl::WriteToMimeTypes(int index
, bool delete_index
)
1407 // check we have the right manager
1408 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1412 wxString strHome
= wxGetenv(wxT("HOME"));
1414 // and now the users mailcap
1415 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1417 wxMimeTextFile file
;
1418 if ( wxFile::Exists(strUserMailcap
) )
1420 bTemp
= file
.Open(strUserMailcap
);
1427 bTemp
= file
.Create(strUserMailcap
);
1433 // test for netscape's header and return false if its found
1434 nIndex
= file
.pIndexOf(wxT("#--Netscape"));
1435 if (nIndex
!= wxNOT_FOUND
)
1437 wxFAIL_MSG(wxT("Error in .mime.types\nTrying to mix Netscape and Metamail formats\nFile not modified"));
1441 // write it in alternative format
1442 // get rid of unwanted entries
1443 wxString strType
= m_aTypes
[index
];
1444 nIndex
= file
.pIndexOf(strType
);
1446 // get rid of all the unwanted entries...
1447 if (nIndex
!= wxNOT_FOUND
)
1448 file
.CommentLine(nIndex
);
1452 // add the new entries in
1453 wxString sTmp
= strType
.Append( wxT(' '), 40 - strType
.Len() );
1454 sTmp
= sTmp
+ m_aExtensions
[index
];
1458 bTemp
= file
.Write();
1465 bool wxMimeTypesManagerImpl::WriteToNSMimeTypes(int index
, bool delete_index
)
1467 //check we have the right managers
1468 if (! ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) )
1472 wxString strHome
= wxGetenv(wxT("HOME"));
1474 // and now the users mailcap
1475 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1477 wxMimeTextFile file
;
1478 if ( wxFile::Exists(strUserMailcap
) )
1480 bTemp
= file
.Open(strUserMailcap
);
1487 bTemp
= file
.Create(strUserMailcap
);
1492 // write it in the format that Netscape uses
1494 // test for netscape's header and insert if required...
1495 // this is a comment so use true
1496 nIndex
= file
.pIndexOf(wxT("#--Netscape"), true);
1497 if (nIndex
== wxNOT_FOUND
)
1499 // either empty file or metamail format
1500 // at present we can't cope with mixed formats, so exit to preseve
1501 // metamail entreies
1502 if (file
.GetLineCount() > 0)
1504 wxFAIL_MSG(wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
1508 file
.InsertLine(wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
1512 wxString strType
= wxT("type=") + m_aTypes
[index
];
1513 nIndex
= file
.pIndexOf(strType
);
1515 // get rid of all the unwanted entries...
1516 if (nIndex
!= wxNOT_FOUND
)
1518 wxString sOld
= file
[nIndex
];
1519 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1521 file
.CommentLine(nIndex
);
1522 sOld
= file
[nIndex
];
1524 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex
, sOld
.c_str());
1529 if (nIndex
< (int) file
.GetLineCount())
1530 file
.CommentLine(nIndex
);
1533 nIndex
= (int) file
.GetLineCount();
1535 wxString sTmp
= strType
+ wxT(" \\");
1537 file
.InsertLine(sTmp
, nIndex
);
1539 if ( ! m_aDescriptions
.Item(index
).empty() )
1541 sTmp
= wxT("desc=\"") + m_aDescriptions
[index
]+ wxT("\" \\"); //.trim ??
1545 file
.InsertLine(sTmp
, nIndex
);
1549 wxString sExts
= m_aExtensions
.Item(index
);
1550 sTmp
= wxT("exts=\"") + sExts
.Trim(false).Trim() + wxT("\"");
1554 file
.InsertLine(sTmp
, nIndex
);
1557 bTemp
= file
.Write();
1564 bool wxMimeTypesManagerImpl::WriteToMailCap(int index
, bool delete_index
)
1566 //check we have the right managers
1567 if ( !( ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) ||
1568 ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) ) )
1572 wxString strHome
= wxGetenv(wxT("HOME"));
1574 // and now the users mailcap
1575 wxString strUserMailcap
= strHome
+ wxT("/.mailcap");
1577 wxMimeTextFile file
;
1578 if ( wxFile::Exists(strUserMailcap
) )
1580 bTemp
= file
.Open(strUserMailcap
);
1587 bTemp
= file
.Create(strUserMailcap
);
1592 // now got a file we can write to ....
1593 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
1595 wxString sCmd
= entries
->GetCommandForVerb(wxT("open"), &iOpen
);
1598 sTmp
= m_aTypes
[index
];
1600 int nIndex
= file
.pIndexOf(sTmp
);
1602 // get rid of all the unwanted entries...
1603 if (nIndex
== wxNOT_FOUND
)
1605 nIndex
= (int) file
.GetLineCount();
1609 sOld
= file
[nIndex
];
1610 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mailcap line '%d' ---"), nIndex
);
1612 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1614 file
.CommentLine(nIndex
);
1615 if (nIndex
< (int) file
.GetLineCount())
1616 sOld
= sOld
+ file
[nIndex
];
1620 file
.GetLineCount()) file
.CommentLine(nIndex
);
1623 sTmp
= sTmp
+ wxT(";") + sCmd
; //includes wxT(" %s ");
1625 // write it in the format that Netscape uses (default)
1626 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1629 file
.InsertLine(sTmp
, nIndex
);
1634 // write extended format
1636 // TODO - FIX this code:
1638 // sOld holds all the entries, but our data store only has some
1639 // eg test= is not stored
1641 // so far we have written the mimetype and command out
1642 wxStringTokenizer
sT(sOld
, wxT(";\\"));
1643 if (sT
.CountTokens() > 2)
1645 // first one mimetype; second one command, rest unknown...
1647 s
= sT
.GetNextToken();
1648 s
= sT
.GetNextToken();
1651 s
= sT
.GetNextToken();
1652 while ( ! s
.empty() )
1654 bool bKnownToken
= false;
1655 if (s
.Contains(wxT("description=")))
1657 if (s
.Contains(wxT("x11-bitmap=")))
1661 for (i
=0; i
< entries
->GetCount(); i
++)
1663 if (s
.Contains(entries
->GetVerb(i
)))
1669 sTmp
= sTmp
+ wxT("; \\");
1670 file
.InsertLine(sTmp
, nIndex
);
1674 s
= sT
.GetNextToken();
1678 if (! m_aDescriptions
[index
].empty() )
1680 sTmp
= sTmp
+ wxT("; \\");
1681 file
.InsertLine(sTmp
, nIndex
);
1683 sTmp
= wxT(" description=\"") + m_aDescriptions
[index
] + wxT("\"");
1686 if (! m_aIcons
[index
].empty() )
1688 sTmp
= sTmp
+ wxT("; \\");
1689 file
.InsertLine(sTmp
, nIndex
);
1691 sTmp
= wxT(" x11-bitmap=\"") + m_aIcons
[index
] + wxT("\"");
1694 if ( entries
->GetCount() > 1 )
1697 for (i
=0; i
< entries
->GetCount(); i
++)
1700 sTmp
= sTmp
+ wxT("; \\");
1701 file
.InsertLine(sTmp
, nIndex
);
1703 sTmp
= wxT(" ") + entries
->GetVerbCmd(i
);
1707 file
.InsertLine(sTmp
, nIndex
);
1711 bTemp
= file
.Write();
1718 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
1722 wxString strType
= ftInfo
.GetMimeType();
1723 wxString strDesc
= ftInfo
.GetDescription();
1724 wxString strIcon
= ftInfo
.GetIconFile();
1726 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1728 if ( ! ftInfo
.GetOpenCommand().empty())
1729 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
1730 if ( ! ftInfo
.GetPrintCommand().empty())
1731 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
1733 // now find where these extensions are in the data store and remove them
1734 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
1735 wxString sExt
, sExtStore
;
1737 for (i
=0; i
< sA_Exts
.GetCount(); i
++)
1739 sExt
= sA_Exts
.Item(i
);
1741 // clean up to just a space before and after
1742 sExt
.Trim().Trim(false);
1743 sExt
= wxT(' ') + sExt
+ wxT(' ');
1744 for (nIndex
= 0; nIndex
< m_aExtensions
.GetCount(); nIndex
++)
1746 sExtStore
= m_aExtensions
.Item(nIndex
);
1747 if (sExtStore
.Replace(sExt
, wxT(" ") ) > 0)
1748 m_aExtensions
.Item(nIndex
) = sExtStore
;
1752 if ( !DoAssociation(strType
, strIcon
, entry
, sA_Exts
, strDesc
) )
1755 return GetFileTypeFromMimeType(strType
);
1758 bool wxMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
1759 const wxString
& strIcon
,
1760 wxMimeTypeCommands
*entry
,
1761 const wxArrayString
& strExtensions
,
1762 const wxString
& strDesc
)
1764 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
1766 if ( nIndex
== wxNOT_FOUND
)
1769 return WriteMimeInfo(nIndex
, false);
1772 bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex
, bool delete_mime
)
1776 if ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
)
1778 // write in metamail format;
1779 if (WriteToMimeTypes(nIndex
, delete_mime
) )
1780 if ( WriteToMailCap(nIndex
, delete_mime
) )
1784 if ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
)
1786 // write in netsacpe format;
1787 if (WriteToNSMimeTypes(nIndex
, delete_mime
) )
1788 if ( WriteToMailCap(nIndex
, delete_mime
) )
1792 // Don't write GNOME files here as this is not
1793 // allowed and simply doesn't work
1795 if (m_mailcapStylesInited
& wxMAILCAP_KDE
)
1797 // write in KDE format;
1798 if (WriteKDEMimeFile(nIndex
, delete_mime
) )
1805 int wxMimeTypesManagerImpl::AddToMimeData(const wxString
& strType
,
1806 const wxString
& strIcon
,
1807 wxMimeTypeCommands
*entry
,
1808 const wxArrayString
& strExtensions
,
1809 const wxString
& strDesc
,
1810 bool replaceExisting
)
1814 // ensure mimetype is always lower case
1815 wxString mimeType
= strType
.Lower();
1817 // is this a known MIME type?
1818 int nIndex
= m_aTypes
.Index(mimeType
);
1819 if ( nIndex
== wxNOT_FOUND
)
1822 m_aTypes
.Add(mimeType
);
1823 m_aIcons
.Add(strIcon
);
1824 m_aEntries
.Add(entry
? entry
: new wxMimeTypeCommands
);
1826 // change nIndex so we can use it below to add the extensions
1827 m_aExtensions
.Add(wxEmptyString
);
1828 nIndex
= m_aExtensions
.size() - 1;
1830 m_aDescriptions
.Add(strDesc
);
1832 else // yes, we already have it
1834 if ( replaceExisting
)
1836 // if new description change it
1837 if ( !strDesc
.empty())
1838 m_aDescriptions
[nIndex
] = strDesc
;
1840 // if new icon change it
1841 if ( !strIcon
.empty())
1842 m_aIcons
[nIndex
] = strIcon
;
1846 delete m_aEntries
[nIndex
];
1847 m_aEntries
[nIndex
] = entry
;
1850 else // add data we don't already have ...
1852 // if new description add only if none
1853 if ( m_aDescriptions
[nIndex
].empty() )
1854 m_aDescriptions
[nIndex
] = strDesc
;
1856 // if new icon and no existing icon
1857 if ( m_aIcons
[nIndex
].empty() )
1858 m_aIcons
[nIndex
] = strIcon
;
1860 // add any new entries...
1863 wxMimeTypeCommands
*entryOld
= m_aEntries
[nIndex
];
1865 size_t count
= entry
->GetCount();
1866 for ( size_t i
= 0; i
< count
; i
++ )
1868 const wxString
& verb
= entry
->GetVerb(i
);
1869 if ( !entryOld
->HasVerb(verb
) )
1871 entryOld
->AddOrReplaceVerb(verb
, entry
->GetCmd(i
));
1875 // as we don't store it anywhere, it won't be deleted later as
1876 // usual -- do it immediately instead
1882 // always add the extensions to this mimetype
1883 wxString
& exts
= m_aExtensions
[nIndex
];
1885 // add all extensions we don't have yet
1886 size_t count
= strExtensions
.GetCount();
1887 for ( size_t i
= 0; i
< count
; i
++ )
1889 wxString ext
= strExtensions
[i
] + wxT(' ');
1891 if ( exts
.Find(ext
) == wxNOT_FOUND
)
1897 // check data integrity
1898 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
1899 m_aTypes
.Count() == m_aExtensions
.Count() &&
1900 m_aTypes
.Count() == m_aIcons
.Count() &&
1901 m_aTypes
.Count() == m_aDescriptions
.Count() );
1906 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
1913 size_t count
= m_aExtensions
.GetCount();
1914 for ( size_t n
= 0; n
< count
; n
++ )
1916 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
1918 while ( tk
.HasMoreTokens() )
1920 // consider extensions as not being case-sensitive
1921 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
1924 wxFileType
*fileType
= new wxFileType
;
1925 fileType
->m_impl
->Init(this, n
);
1935 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
1939 wxFileType
* fileType
= NULL
;
1940 // mime types are not case-sensitive
1941 wxString
mimetype(mimeType
);
1942 mimetype
.MakeLower();
1944 // first look for an exact match
1945 int index
= m_aTypes
.Index(mimetype
);
1946 if ( index
!= wxNOT_FOUND
)
1948 fileType
= new wxFileType
;
1949 fileType
->m_impl
->Init(this, index
);
1952 // then try to find "text/*" as match for "text/plain" (for example)
1953 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
1954 // the whole string - ok.
1956 index
= wxNOT_FOUND
;
1957 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
1959 size_t nCount
= m_aTypes
.Count();
1960 for ( size_t n
= 0; n
< nCount
; n
++ )
1962 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
1963 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
1970 if ( index
!= wxNOT_FOUND
)
1972 // don't throw away fileType that was already found
1974 fileType
= new wxFileType
;
1975 fileType
->m_impl
->Init(this, index
);
1981 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
1983 wxString command
, testcmd
, sV
, sTmp
;
1984 sV
= verb
+ wxT("=");
1986 // list of verb = command pairs for this mimetype
1987 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
1990 for ( i
= 0; i
< sPairs
->GetCount (); i
++ )
1992 sTmp
= sPairs
->GetVerbCmd (i
);
1993 if ( sTmp
.Contains(sV
) )
1994 command
= sTmp
.AfterFirst(wxT('='));
2000 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
2004 wxString extensions
;
2005 const wxArrayString
& exts
= filetype
.GetExtensions();
2006 size_t nExts
= exts
.GetCount();
2007 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
2010 extensions
+= wxT(' ');
2012 extensions
+= exts
[nExt
];
2015 AddMimeTypeInfo(filetype
.GetMimeType(),
2017 filetype
.GetDescription());
2019 AddMailcapInfo(filetype
.GetMimeType(),
2020 filetype
.GetOpenCommand(),
2021 filetype
.GetPrintCommand(),
2023 filetype
.GetDescription());
2026 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
2027 const wxString
& strExtensions
,
2028 const wxString
& strDesc
)
2030 // reading mailcap may find image/* , while
2031 // reading mime.types finds image/gif and no match is made
2032 // this means all the get functions don't work fix this
2034 wxString sTmp
= strExtensions
;
2036 wxArrayString sExts
;
2037 sTmp
.Trim().Trim(false);
2039 while (!sTmp
.empty())
2041 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
2042 sTmp
= sTmp
.BeforeLast(wxT(' '));
2045 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
2048 void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString
& strType
,
2049 const wxString
& strOpenCmd
,
2050 const wxString
& strPrintCmd
,
2051 const wxString
& strTest
,
2052 const wxString
& strDesc
)
2056 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands
;
2057 entry
->Add(wxT("open=") + strOpenCmd
);
2058 entry
->Add(wxT("print=") + strPrintCmd
);
2059 entry
->Add(wxT("test=") + strTest
);
2062 wxArrayString strExtensions
;
2064 AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
2067 bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString
& strFileName
)
2069 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mime.types file '%s' ---"),
2070 strFileName
.c_str());
2072 wxTextFile
file(strFileName
);
2073 #if defined(__WXGTK20__) && wxUSE_UNICODE
2074 if ( !file
.Open(wxConvUTF8
) )
2080 // the information we extract
2081 wxString strMimeType
, strDesc
, strExtensions
;
2083 size_t nLineCount
= file
.GetLineCount();
2084 const wxChar
*pc
= NULL
;
2085 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2089 // now we're at the start of the line
2090 pc
= file
[nLine
].c_str();
2094 // we didn't finish with the previous line yet
2099 while ( wxIsspace(*pc
) )
2102 // comment or blank line?
2103 if ( *pc
== wxT('#') || !*pc
)
2105 // skip the whole line
2110 // detect file format
2111 const wxChar
*pEqualSign
= wxStrchr(pc
, wxT('='));
2112 if ( pEqualSign
== NULL
)
2117 // first field is mime type
2118 for ( strMimeType
.Empty(); !wxIsspace(*pc
) && *pc
!= wxT('\0'); pc
++ )
2124 while ( wxIsspace(*pc
) )
2127 // take all the rest of the string
2130 // no description...
2138 // the string on the left of '=' is the field name
2139 wxString
strLHS(pc
, pEqualSign
- pc
);
2142 for ( pc
= pEqualSign
+ 1; wxIsspace(*pc
); pc
++ )
2146 if ( *pc
== wxT('"') )
2148 // the string is quoted and ends at the matching quote
2149 pEnd
= wxStrchr(++pc
, wxT('"'));
2152 wxLogWarning(wxT("Mime.types file %s, line %lu: unterminated quoted string."),
2153 strFileName
.c_str(), nLine
+ 1L);
2158 // unquoted string ends at the first space or at the end of
2160 for ( pEnd
= pc
; *pEnd
&& !wxIsspace(*pEnd
); pEnd
++ )
2164 // now we have the RHS (field value)
2165 wxString
strRHS(pc
, pEnd
- pc
);
2167 // check what follows this entry
2168 if ( *pEnd
== wxT('"') )
2174 for ( pc
= pEnd
; wxIsspace(*pc
); pc
++ )
2177 // if there is something left, it may be either a '\\' to continue
2178 // the line or the next field of the same entry
2179 bool entryEnded
= *pc
== wxT('\0');
2180 bool nextFieldOnSameLine
= false;
2183 nextFieldOnSameLine
= ((*pc
!= wxT('\\')) || (pc
[1] != wxT('\0')));
2186 // now see what we got
2187 if ( strLHS
== wxT("type") )
2189 strMimeType
= strRHS
;
2191 else if ( strLHS
.StartsWith(wxT("desc")) )
2195 else if ( strLHS
== wxT("exts") )
2197 strExtensions
= strRHS
;
2199 else if ( strLHS
== wxT("icon") )
2201 // this one is simply ignored: it usually refers to Netscape
2202 // built in icons which are useless for us anyhow
2204 else if ( !strLHS
.StartsWith(wxT("x-")) )
2206 // we suppose that all fields starting with "X-" are
2207 // unregistered extensions according to the standard practice,
2208 // but it may be worth telling the user about other junk in
2209 // his mime.types file
2210 wxLogWarning(wxT("Unknown field in file %s, line %lu: '%s'."),
2211 strFileName
.c_str(), nLine
+ 1L, strLHS
.c_str());
2216 if ( !nextFieldOnSameLine
)
2218 //else: don't reset it
2220 // as we don't reset strMimeType, the next field in this entry
2221 // will be interpreted correctly.
2227 // depending on the format (Mosaic or Netscape) either space or comma
2228 // is used to separate the extensions
2229 strExtensions
.Replace(wxT(","), wxT(" "));
2231 // also deal with the leading dot
2232 if ( !strExtensions
.empty() && strExtensions
[0u] == wxT('.') )
2234 strExtensions
.erase(0, 1);
2237 wxLogTrace(TRACE_MIME
, wxT("mime.types: '%s' => '%s' (%s)"),
2238 strExtensions
.c_str(),
2239 strMimeType
.c_str(),
2242 AddMimeTypeInfo(strMimeType
, strExtensions
, strDesc
);
2244 // finished with this line
2251 // ----------------------------------------------------------------------------
2252 // UNIX mailcap files parsing
2253 // ----------------------------------------------------------------------------
2255 // the data for a single MIME type
2256 struct MailcapLineData
2265 wxArrayString verbs
,
2273 MailcapLineData() { testfailed
= needsterminal
= copiousoutput
= false; }
2276 // process a non-standard (i.e. not the first or second one) mailcap field
2278 wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData
& data
,
2279 const wxString
& curField
)
2281 if ( curField
.empty() )
2287 // is this something of the form foo=bar?
2288 const wxChar
*pEq
= wxStrchr(curField
, wxT('='));
2291 // split "LHS = RHS" in 2
2292 wxString lhs
= curField
.BeforeFirst(wxT('=')),
2293 rhs
= curField
.AfterFirst(wxT('='));
2295 lhs
.Trim(true); // from right
2296 rhs
.Trim(false); // from left
2298 // it might be quoted
2299 if ( !rhs
.empty() && rhs
[0u] == wxT('"') && rhs
.Last() == wxT('"') )
2301 rhs
= rhs
.Mid(1, rhs
.length() - 2);
2304 // is it a command verb or something else?
2305 if ( lhs
== wxT("test") )
2307 if ( wxSystem(rhs
) == 0 )
2310 wxLogTrace(TRACE_MIME_TEST
,
2311 wxT("Test '%s' for mime type '%s' succeeded."),
2312 rhs
.c_str(), data
.type
.c_str());
2316 wxLogTrace(TRACE_MIME_TEST
,
2317 wxT("Test '%s' for mime type '%s' failed, skipping."),
2318 rhs
.c_str(), data
.type
.c_str());
2320 data
.testfailed
= true;
2323 else if ( lhs
== wxT("desc") )
2327 else if ( lhs
== wxT("x11-bitmap") )
2331 else if ( lhs
== wxT("notes") )
2335 else // not a (recognized) special case, must be a verb (e.g. "print")
2337 data
.verbs
.Add(lhs
);
2338 data
.commands
.Add(rhs
);
2341 else // '=' not found
2343 // so it must be a simple flag
2344 if ( curField
== wxT("needsterminal") )
2346 data
.needsterminal
= true;
2348 else if ( curField
== wxT("copiousoutput"))
2350 // copiousoutput impies that the viewer is a console program
2351 data
.needsterminal
=
2352 data
.copiousoutput
= true;
2354 else if ( !IsKnownUnimportantField(curField
) )
2363 bool wxMimeTypesManagerImpl::ReadMailcap(const wxString
& strFileName
,
2366 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mailcap file '%s' ---"),
2367 strFileName
.c_str());
2369 wxTextFile
file(strFileName
);
2370 #if defined(__WXGTK20__) && wxUSE_UNICODE
2371 if ( !file
.Open(wxConvUTF8
) )
2377 // indices of MIME types (in m_aTypes) we already found in this file
2379 // (see the comments near the end of function for the reason we need this)
2380 wxArrayInt aIndicesSeenHere
;
2382 // accumulator for the current field
2384 curField
.reserve(1024);
2386 size_t nLineCount
= file
.GetLineCount();
2387 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2389 // now we're at the start of the line
2390 const wxChar
*pc
= file
[nLine
].c_str();
2393 while ( wxIsspace(*pc
) )
2396 // comment or empty string?
2397 if ( *pc
== wxT('#') || *pc
== wxT('\0') )
2403 // what field are we currently in? The first 2 are fixed and there may
2404 // be an arbitrary number of other fields parsed by
2405 // ProcessOtherMailcapField()
2407 // the first field is the MIME type
2414 currentToken
= Field_Type
;
2416 // the flags and field values on the current line
2417 MailcapLineData data
;
2425 // interpret the next character literally (notice that
2426 // backslash can be used for line continuation)
2427 if ( *++pc
== wxT('\0') )
2429 // fetch the next line if there is one
2430 if ( nLine
== nLineCount
- 1 )
2432 // something is wrong, bail out
2435 wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."),
2436 strFileName
.c_str(),
2441 // pass to the beginning of the next line
2442 pc
= file
[++nLine
].c_str();
2444 // skip pc++ at the end of the loop
2450 // just a normal character
2456 cont
= false; // end of line reached, exit the loop
2458 // fall through to still process this field
2461 // trim whitespaces from both sides
2462 curField
.Trim(true).Trim(false);
2464 switch ( currentToken
)
2467 data
.type
= curField
.Lower();
2468 if ( data
.type
.empty() )
2470 // I don't think that this is a valid mailcap
2471 // entry, but try to interpret it somehow
2472 data
.type
= wxT('*');
2475 if ( data
.type
.Find(wxT('/')) == wxNOT_FOUND
)
2477 // we interpret "type" as "type/*"
2478 data
.type
+= wxT("/*");
2481 currentToken
= Field_OpenCmd
;
2485 data
.cmdOpen
= curField
;
2487 currentToken
= Field_Other
;
2491 if ( !ProcessOtherMailcapField(data
, curField
) )
2493 // don't flood the user with error messages if
2494 // we don't understand something in his
2495 // mailcap, but give them in debug mode because
2496 // this might be useful for the programmer
2499 wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."),
2500 strFileName
.c_str(),
2506 else if ( data
.testfailed
)
2508 // skip this entry entirely
2512 // it already has this value
2513 //currentToken = Field_Other;
2517 wxFAIL_MSG(wxT("unknown field type in mailcap"));
2520 // next token starts immediately after ';'
2528 // continue in the same line
2532 // we read the entire entry, check what have we got
2533 // ------------------------------------------------
2535 // check that we really read something reasonable
2536 if ( currentToken
< Field_Other
)
2538 wxLogWarning(wxT("Mailcap file %s, line %lu: incomplete entry ignored."),
2539 strFileName
.c_str(), nLine
+ 1L);
2544 // if the test command failed, it's as if the entry were not there at all
2545 if ( data
.testfailed
)
2550 // support for flags:
2551 // 1. create an xterm for 'needsterminal'
2552 // 2. append "| $PAGER" for 'copiousoutput'
2554 // Note that the RFC says that having both needsterminal and
2555 // copiousoutput is probably a mistake, so it seems that running
2556 // programs with copiousoutput inside an xterm as it is done now
2557 // is a bad idea (FIXME)
2558 if ( data
.copiousoutput
)
2560 const wxChar
*p
= wxGetenv(wxT("PAGER"));
2561 data
.cmdOpen
<< wxT(" | ") << (p
? p
: wxT("more"));
2564 if ( data
.needsterminal
)
2566 data
.cmdOpen
= wxString::Format(wxT("xterm -e sh -c '%s'"),
2567 data
.cmdOpen
.c_str());
2570 if ( !data
.cmdOpen
.empty() )
2572 data
.verbs
.Insert(wxT("open"), 0);
2573 data
.commands
.Insert(data
.cmdOpen
, 0);
2576 // we have to decide whether the new entry should replace any entries
2577 // for the same MIME type we had previously found or not
2580 // the fall back entries have the lowest priority, by definition
2587 // have we seen this one before?
2588 int nIndex
= m_aTypes
.Index(data
.type
);
2590 // and if we have, was it in this file? if not, we should
2591 // overwrite the previously seen one
2592 overwrite
= nIndex
== wxNOT_FOUND
||
2593 aIndicesSeenHere
.Index(nIndex
) == wxNOT_FOUND
;
2596 wxLogTrace(TRACE_MIME
, wxT("mailcap %s: %s [%s]"),
2597 data
.type
.c_str(), data
.cmdOpen
.c_str(),
2598 overwrite
? wxT("replace") : wxT("add"));
2600 int n
= AddToMimeData
2604 new wxMimeTypeCommands(data
.verbs
, data
.commands
),
2605 wxArrayString() /* extensions */,
2612 aIndicesSeenHere
.Add(n
);
2619 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
2626 size_t count
= m_aTypes
.GetCount();
2627 for ( size_t n
= 0; n
< count
; n
++ )
2629 // don't return template types from here (i.e. anything containg '*')
2631 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
2633 mimetypes
.Add(type
);
2637 return mimetypes
.GetCount();
2640 // ----------------------------------------------------------------------------
2641 // writing to MIME type files
2642 // ----------------------------------------------------------------------------
2644 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
2648 wxArrayString sMimeTypes
;
2649 ft
->GetMimeTypes(sMimeTypes
);
2653 for (i
= 0; i
< sMimeTypes
.GetCount(); i
++)
2655 sMime
= sMimeTypes
.Item(i
);
2656 int nIndex
= m_aTypes
.Index(sMime
);
2657 if ( nIndex
== wxNOT_FOUND
)
2659 // error if we get here ??
2664 WriteMimeInfo(nIndex
, true);
2665 m_aTypes
.RemoveAt(nIndex
);
2666 m_aEntries
.RemoveAt(nIndex
);
2667 m_aExtensions
.RemoveAt(nIndex
);
2668 m_aDescriptions
.RemoveAt(nIndex
);
2669 m_aIcons
.RemoveAt(nIndex
);
2672 // check data integrity
2673 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
2674 m_aTypes
.Count() == m_aExtensions
.Count() &&
2675 m_aTypes
.Count() == m_aIcons
.Count() &&
2676 m_aTypes
.Count() == m_aDescriptions
.Count() );
2681 // ----------------------------------------------------------------------------
2682 // private functions
2683 // ----------------------------------------------------------------------------
2685 static bool IsKnownUnimportantField(const wxString
& fieldAll
)
2687 static const wxChar
*knownFields
[] =
2689 wxT("x-mozilla-flags"),
2690 wxT("nametemplate"),
2691 wxT("textualnewlines"),
2694 wxString field
= fieldAll
.BeforeFirst(wxT('='));
2695 for ( size_t n
= 0; n
< WXSIZEOF(knownFields
); n
++ )
2697 if ( field
.CmpNoCase(knownFields
[n
]) == 0 )
2705 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE