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 const 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") ))
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 nCount
= config
.GetLineCount();
1011 for (size_t i
= 0; i
< nCount
; 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 size_t nCount
= m_index
.GetCount();
1139 for (size_t i
= 0; i
< nCount
; i
++)
1140 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
1145 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
1146 wxArrayString
*commands
,
1147 const wxFileType::MessageParameters
& params
) const
1149 wxString vrb
, cmd
, sTmp
;
1151 wxMimeTypeCommands
* sPairs
;
1153 // verbs and commands have been cleared already in mimecmn.cpp...
1154 // if we find no entries in the exact match, try the inexact match
1155 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
1157 // list of verb = command pairs for this mimetype
1158 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
1160 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
1162 vrb
= sPairs
->GetVerb(i
);
1163 // some gnome entries have "." inside
1164 vrb
= vrb
.AfterLast(wxT('.'));
1165 cmd
= sPairs
->GetCmd(i
);
1168 cmd
= wxFileType::ExpandCommand(cmd
, params
);
1170 if ( vrb
.IsSameAs(wxT("open")))
1173 verbs
->Insert(vrb
, 0u);
1175 commands
->Insert(cmd
, 0u);
1191 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
1193 wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
1196 // one extension in the space or comma-delimited list
1198 for ( const wxChar
*p
= strExtensions
; /* nothing */; p
++ )
1200 if ( *p
== wxT(' ') || *p
== wxT(',') || *p
== wxT('\0') )
1202 if ( !strExt
.empty() )
1204 extensions
.Add(strExt
);
1207 //else: repeated spaces
1208 // (shouldn't happen, but it's not that important if it does happen)
1210 if ( *p
== wxT('\0') )
1213 else if ( *p
== wxT('.') )
1215 // remove the dot from extension (but only if it's the first char)
1216 if ( !strExt
.empty() )
1220 //else: no, don't append it
1231 // set an arbitrary command:
1232 // could adjust the code to ask confirmation if it already exists and
1233 // overwriteprompt is true, but this is currently ignored as *Associate* has
1234 // no overwrite prompt
1236 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
1237 const wxString
& verb
,
1238 bool WXUNUSED(overwriteprompt
))
1240 wxArrayString strExtensions
;
1241 wxString strDesc
, strIcon
;
1243 wxArrayString strTypes
;
1244 GetMimeTypes(strTypes
);
1245 if ( strTypes
.IsEmpty() )
1248 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1249 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
1252 size_t nCount
= strTypes
.GetCount();
1253 for ( size_t i
= 0; i
< nCount
; i
++ )
1255 if (!m_manager
->DoAssociation(strTypes
[i
], strIcon
, entry
, strExtensions
, strDesc
))
1262 // ignore index on the grounds that we only have one icon in a Unix file
1263 bool wxFileTypeImpl::SetDefaultIcon(const wxString
& strIcon
, int WXUNUSED(index
))
1265 if (strIcon
.empty())
1268 wxArrayString strExtensions
;
1271 wxArrayString strTypes
;
1272 GetMimeTypes(strTypes
);
1273 if ( strTypes
.IsEmpty() )
1276 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1278 size_t nCount
= strTypes
.GetCount();
1279 for ( size_t i
= 0; i
< nCount
; i
++ )
1281 if ( !m_manager
->DoAssociation
1297 // ----------------------------------------------------------------------------
1298 // wxMimeTypesManagerImpl (Unix)
1299 // ----------------------------------------------------------------------------
1301 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
1303 m_initialized
= false;
1304 m_mailcapStylesInited
= 0;
1307 void wxMimeTypesManagerImpl::InitIfNeeded()
1309 if ( !m_initialized
)
1311 // set the flag first to prevent recursion
1312 m_initialized
= true;
1314 const wxString
&wm
= wxGetenv( wxT("WINDOWMANAGER") );
1316 if (wm
.Find( wxT("kde") ) != wxNOT_FOUND
)
1317 Initialize( wxMAILCAP_KDE
);
1318 else if (wm
.Find( wxT("gnome") ) != wxNOT_FOUND
)
1319 Initialize( wxMAILCAP_GNOME
);
1325 // read system and user mailcaps and other files
1326 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
1327 const wxString
& sExtraDir
)
1329 // read mimecap amd mime.types
1330 if ( (mailcapStyles
& wxMAILCAP_NETSCAPE
) ||
1331 (mailcapStyles
& wxMAILCAP_STANDARD
) )
1332 GetMimeInfo(sExtraDir
);
1334 // read GNOME tables
1335 if (mailcapStyles
& wxMAILCAP_GNOME
)
1336 GetGnomeMimeInfo(sExtraDir
);
1339 if (mailcapStyles
& wxMAILCAP_KDE
)
1340 GetKDEMimeInfo(sExtraDir
);
1342 m_mailcapStylesInited
|= mailcapStyles
;
1345 // clear data so you can read another group of WM files
1346 void wxMimeTypesManagerImpl::ClearData()
1350 m_aExtensions
.Clear();
1351 m_aDescriptions
.Clear();
1353 WX_CLEAR_ARRAY(m_aEntries
);
1356 m_mailcapStylesInited
= 0;
1359 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
1364 void wxMimeTypesManagerImpl::GetMimeInfo(const wxString
& sExtraDir
)
1366 // read this for netscape or Metamail formats
1368 // directories where we look for mailcap and mime.types by default
1369 // used by netscape and pine and other mailers, using 2 different formats!
1371 // (taken from metamail(1) sources)
1373 // although RFC 1524 specifies the search path of
1374 // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
1375 // places - OTOH, the RFC also says that this path can be changed with
1376 // MAILCAPS environment variable (containing the colon separated full
1377 // filenames to try) which is not done yet (TODO?)
1379 wxString strHome
= wxGetenv(wxT("HOME"));
1382 dirs
.Add( strHome
+ wxT("/.") );
1383 dirs
.Add( wxT("/etc/") );
1384 dirs
.Add( wxT("/usr/etc/") );
1385 dirs
.Add( wxT("/usr/local/etc/") );
1386 dirs
.Add( wxT("/etc/mail/") );
1387 dirs
.Add( wxT("/usr/public/lib/") );
1388 if (!sExtraDir
.empty())
1389 dirs
.Add( sExtraDir
+ wxT("/") );
1392 size_t nDirs
= dirs
.GetCount();
1393 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1396 file
+= wxT("mailcap");
1397 if ( wxFile::Exists(file
) )
1403 file
+= wxT("mime.types");
1404 if ( wxFile::Exists(file
) )
1405 ReadMimeTypes(file
);
1409 bool wxMimeTypesManagerImpl::WriteToMimeTypes(int index
, bool delete_index
)
1411 // check we have the right manager
1412 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1416 wxString strHome
= wxGetenv(wxT("HOME"));
1418 // and now the users mailcap
1419 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1421 wxMimeTextFile file
;
1422 if ( wxFile::Exists(strUserMailcap
) )
1424 bTemp
= file
.Open(strUserMailcap
);
1431 bTemp
= file
.Create(strUserMailcap
);
1437 // test for netscape's header and return false if its found
1438 nIndex
= file
.pIndexOf(wxT("#--Netscape"));
1439 if (nIndex
!= wxNOT_FOUND
)
1441 wxFAIL_MSG(wxT("Error in .mime.types\nTrying to mix Netscape and Metamail formats\nFile not modified"));
1445 // write it in alternative format
1446 // get rid of unwanted entries
1447 wxString strType
= m_aTypes
[index
];
1448 nIndex
= file
.pIndexOf(strType
);
1450 // get rid of all the unwanted entries...
1451 if (nIndex
!= wxNOT_FOUND
)
1452 file
.CommentLine(nIndex
);
1456 // add the new entries in
1457 wxString sTmp
= strType
.Append( wxT(' '), 40 - strType
.Len() );
1458 sTmp
+= m_aExtensions
[index
];
1462 bTemp
= file
.Write();
1469 bool wxMimeTypesManagerImpl::WriteToNSMimeTypes(int index
, bool delete_index
)
1471 //check we have the right managers
1472 if (! ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) )
1476 wxString strHome
= wxGetenv(wxT("HOME"));
1478 // and now the users mailcap
1479 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1481 wxMimeTextFile file
;
1482 if ( wxFile::Exists(strUserMailcap
) )
1484 bTemp
= file
.Open(strUserMailcap
);
1491 bTemp
= file
.Create(strUserMailcap
);
1496 // write it in the format that Netscape uses
1498 // test for netscape's header and insert if required...
1499 // this is a comment so use true
1500 nIndex
= file
.pIndexOf(wxT("#--Netscape"), true);
1501 if (nIndex
== wxNOT_FOUND
)
1503 // either empty file or metamail format
1504 // at present we can't cope with mixed formats, so exit to preseve
1505 // metamail entreies
1506 if (file
.GetLineCount() > 0)
1508 wxFAIL_MSG(wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
1512 file
.InsertLine(wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
1516 wxString strType
= wxT("type=") + m_aTypes
[index
];
1517 nIndex
= file
.pIndexOf(strType
);
1519 // get rid of all the unwanted entries...
1520 if (nIndex
!= wxNOT_FOUND
)
1522 wxString sOld
= file
[nIndex
];
1523 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1525 file
.CommentLine(nIndex
);
1526 sOld
= file
[nIndex
];
1528 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex
, sOld
.c_str());
1533 if (nIndex
< (int) file
.GetLineCount())
1534 file
.CommentLine(nIndex
);
1537 nIndex
= (int) file
.GetLineCount();
1539 wxString sTmp
= strType
+ wxT(" \\");
1541 file
.InsertLine(sTmp
, nIndex
);
1543 if ( ! m_aDescriptions
.Item(index
).empty() )
1545 sTmp
= wxT("desc=\"") + m_aDescriptions
[index
]+ wxT("\" \\"); //.trim ??
1549 file
.InsertLine(sTmp
, nIndex
);
1553 wxString sExts
= m_aExtensions
.Item(index
);
1554 sTmp
= wxT("exts=\"") + sExts
.Trim(false).Trim() + wxT("\"");
1558 file
.InsertLine(sTmp
, nIndex
);
1561 bTemp
= file
.Write();
1568 bool wxMimeTypesManagerImpl::WriteToMailCap(int index
, bool delete_index
)
1570 //check we have the right managers
1571 if ( !( ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) ||
1572 ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) ) )
1576 wxString strHome
= wxGetenv(wxT("HOME"));
1578 // and now the users mailcap
1579 wxString strUserMailcap
= strHome
+ wxT("/.mailcap");
1581 wxMimeTextFile file
;
1582 if ( wxFile::Exists(strUserMailcap
) )
1584 bTemp
= file
.Open(strUserMailcap
);
1591 bTemp
= file
.Create(strUserMailcap
);
1596 // now got a file we can write to ....
1597 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
1599 wxString sCmd
= entries
->GetCommandForVerb(wxT("open"), &iOpen
);
1602 sTmp
= m_aTypes
[index
];
1604 int nIndex
= file
.pIndexOf(sTmp
);
1606 // get rid of all the unwanted entries...
1607 if (nIndex
== wxNOT_FOUND
)
1609 nIndex
= (int) file
.GetLineCount();
1613 sOld
= file
[nIndex
];
1614 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mailcap line '%d' ---"), nIndex
);
1616 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1618 file
.CommentLine(nIndex
);
1619 if (nIndex
< (int) file
.GetLineCount())
1620 sOld
= sOld
+ file
[nIndex
];
1624 file
.GetLineCount()) file
.CommentLine(nIndex
);
1627 sTmp
+= wxT(";") + sCmd
; //includes wxT(" %s ");
1629 // write it in the format that Netscape uses (default)
1630 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1633 file
.InsertLine(sTmp
, nIndex
);
1638 // write extended format
1640 // TODO - FIX this code:
1642 // sOld holds all the entries, but our data store only has some
1643 // eg test= is not stored
1645 // so far we have written the mimetype and command out
1646 wxStringTokenizer
sT(sOld
, wxT(";\\"));
1647 if (sT
.CountTokens() > 2)
1649 // first one mimetype; second one command, rest unknown...
1651 s
= sT
.GetNextToken();
1652 s
= sT
.GetNextToken();
1655 s
= sT
.GetNextToken();
1656 while ( ! s
.empty() )
1658 bool bKnownToken
= false;
1659 if (s
.Contains(wxT("description=")))
1661 if (s
.Contains(wxT("x11-bitmap=")))
1665 size_t nCount
= entries
->GetCount();
1666 for (i
=0; i
< nCount
; i
++)
1668 if (s
.Contains(entries
->GetVerb(i
)))
1674 sTmp
+= wxT("; \\");
1675 file
.InsertLine(sTmp
, nIndex
);
1679 s
= sT
.GetNextToken();
1683 if (! m_aDescriptions
[index
].empty() )
1685 sTmp
+= wxT("; \\");
1686 file
.InsertLine(sTmp
, nIndex
);
1688 sTmp
= wxT(" description=\"") + m_aDescriptions
[index
] + wxT("\"");
1691 if (! m_aIcons
[index
].empty() )
1693 sTmp
+= wxT("; \\");
1694 file
.InsertLine(sTmp
, nIndex
);
1696 sTmp
= wxT(" x11-bitmap=\"") + m_aIcons
[index
] + wxT("\"");
1699 if ( entries
->GetCount() > 1 )
1702 for (i
=0; i
< entries
->GetCount(); i
++)
1705 sTmp
+= wxT("; \\");
1706 file
.InsertLine(sTmp
, nIndex
);
1708 sTmp
= wxT(" ") + entries
->GetVerbCmd(i
);
1712 file
.InsertLine(sTmp
, nIndex
);
1716 bTemp
= file
.Write();
1723 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
1727 wxString strType
= ftInfo
.GetMimeType();
1728 wxString strDesc
= ftInfo
.GetDescription();
1729 wxString strIcon
= ftInfo
.GetIconFile();
1731 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1733 if ( ! ftInfo
.GetOpenCommand().empty())
1734 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
1735 if ( ! ftInfo
.GetPrintCommand().empty())
1736 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
1738 // now find where these extensions are in the data store and remove them
1739 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
1740 wxString sExt
, sExtStore
;
1742 size_t nExtCount
= sA_Exts
.GetCount();
1743 for (i
=0; i
< nExtCount
; i
++)
1745 sExt
= sA_Exts
.Item(i
);
1747 // clean up to just a space before and after
1748 sExt
.Trim().Trim(false);
1749 sExt
= wxT(' ') + sExt
+ wxT(' ');
1750 size_t nCount
= m_aExtensions
.GetCount();
1751 for (nIndex
= 0; nIndex
< nCount
; 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
1894 size_t count
= strExtensions
.GetCount();
1895 for ( size_t i
= 0; i
< count
; i
++ )
1897 ext
= strExtensions
[i
];
1900 if ( exts
.Find(ext
) == wxNOT_FOUND
)
1906 // check data integrity
1907 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
1908 m_aTypes
.Count() == m_aExtensions
.Count() &&
1909 m_aTypes
.Count() == m_aIcons
.Count() &&
1910 m_aTypes
.Count() == m_aDescriptions
.Count() );
1915 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
1922 size_t count
= m_aExtensions
.GetCount();
1923 for ( size_t n
= 0; n
< count
; n
++ )
1925 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
1927 while ( tk
.HasMoreTokens() )
1929 // consider extensions as not being case-sensitive
1930 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
1933 wxFileType
*fileType
= new wxFileType
;
1934 fileType
->m_impl
->Init(this, n
);
1944 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
1948 wxFileType
* fileType
= NULL
;
1949 // mime types are not case-sensitive
1950 wxString
mimetype(mimeType
);
1951 mimetype
.MakeLower();
1953 // first look for an exact match
1954 int index
= m_aTypes
.Index(mimetype
);
1955 if ( index
!= wxNOT_FOUND
)
1957 fileType
= new wxFileType
;
1958 fileType
->m_impl
->Init(this, index
);
1961 // then try to find "text/*" as match for "text/plain" (for example)
1962 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
1963 // the whole string - ok.
1965 index
= wxNOT_FOUND
;
1966 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
1968 size_t nCount
= m_aTypes
.Count();
1969 for ( size_t n
= 0; n
< nCount
; n
++ )
1971 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
1972 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
1979 if ( index
!= wxNOT_FOUND
)
1981 // don't throw away fileType that was already found
1983 fileType
= new wxFileType
;
1984 fileType
->m_impl
->Init(this, index
);
1990 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
1992 wxString command
, testcmd
, sV
, sTmp
;
1993 sV
= verb
+ wxT("=");
1995 // list of verb = command pairs for this mimetype
1996 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
1999 size_t nCount
= sPairs
->GetCount();
2000 for ( i
= 0; i
< nCount
; i
++ )
2002 sTmp
= sPairs
->GetVerbCmd (i
);
2003 if ( sTmp
.Contains(sV
) )
2004 command
= sTmp
.AfterFirst(wxT('='));
2010 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
2014 wxString extensions
;
2015 const wxArrayString
& exts
= filetype
.GetExtensions();
2016 size_t nExts
= exts
.GetCount();
2017 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
2020 extensions
+= wxT(' ');
2022 extensions
+= exts
[nExt
];
2025 AddMimeTypeInfo(filetype
.GetMimeType(),
2027 filetype
.GetDescription());
2029 AddMailcapInfo(filetype
.GetMimeType(),
2030 filetype
.GetOpenCommand(),
2031 filetype
.GetPrintCommand(),
2033 filetype
.GetDescription());
2036 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
2037 const wxString
& strExtensions
,
2038 const wxString
& strDesc
)
2040 // reading mailcap may find image/* , while
2041 // reading mime.types finds image/gif and no match is made
2042 // this means all the get functions don't work fix this
2044 wxString sTmp
= strExtensions
;
2046 wxArrayString sExts
;
2047 sTmp
.Trim().Trim(false);
2049 while (!sTmp
.empty())
2051 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
2052 sTmp
= sTmp
.BeforeLast(wxT(' '));
2055 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
2058 void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString
& strType
,
2059 const wxString
& strOpenCmd
,
2060 const wxString
& strPrintCmd
,
2061 const wxString
& strTest
,
2062 const wxString
& strDesc
)
2066 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands
;
2067 entry
->Add(wxT("open=") + strOpenCmd
);
2068 entry
->Add(wxT("print=") + strPrintCmd
);
2069 entry
->Add(wxT("test=") + strTest
);
2072 wxArrayString strExtensions
;
2074 AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
2077 bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString
& strFileName
)
2079 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mime.types file '%s' ---"),
2080 strFileName
.c_str());
2082 wxTextFile
file(strFileName
);
2083 #if defined(__WXGTK20__) && wxUSE_UNICODE
2084 if ( !file
.Open(wxConvUTF8
) )
2090 // the information we extract
2091 wxString strMimeType
, strDesc
, strExtensions
;
2093 size_t nLineCount
= file
.GetLineCount();
2094 const wxChar
*pc
= NULL
;
2095 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2099 // now we're at the start of the line
2100 pc
= file
[nLine
].c_str();
2104 // we didn't finish with the previous line yet
2109 while ( wxIsspace(*pc
) )
2112 // comment or blank line?
2113 if ( *pc
== wxT('#') || !*pc
)
2115 // skip the whole line
2120 // detect file format
2121 const wxChar
*pEqualSign
= wxStrchr(pc
, wxT('='));
2122 if ( pEqualSign
== NULL
)
2127 // first field is mime type
2128 for ( strMimeType
.Empty(); !wxIsspace(*pc
) && *pc
!= wxT('\0'); pc
++ )
2134 while ( wxIsspace(*pc
) )
2137 // take all the rest of the string
2140 // no description...
2148 // the string on the left of '=' is the field name
2149 wxString
strLHS(pc
, pEqualSign
- pc
);
2152 for ( pc
= pEqualSign
+ 1; wxIsspace(*pc
); pc
++ )
2156 if ( *pc
== wxT('"') )
2158 // the string is quoted and ends at the matching quote
2159 pEnd
= wxStrchr(++pc
, wxT('"'));
2162 wxLogWarning(wxT("Mime.types file %s, line %lu: unterminated quoted string."),
2163 strFileName
.c_str(), nLine
+ 1L);
2168 // unquoted string ends at the first space or at the end of
2170 for ( pEnd
= pc
; *pEnd
&& !wxIsspace(*pEnd
); pEnd
++ )
2174 // now we have the RHS (field value)
2175 wxString
strRHS(pc
, pEnd
- pc
);
2177 // check what follows this entry
2178 if ( *pEnd
== wxT('"') )
2184 for ( pc
= pEnd
; wxIsspace(*pc
); pc
++ )
2187 // if there is something left, it may be either a '\\' to continue
2188 // the line or the next field of the same entry
2189 bool entryEnded
= *pc
== wxT('\0');
2190 bool nextFieldOnSameLine
= false;
2193 nextFieldOnSameLine
= ((*pc
!= wxT('\\')) || (pc
[1] != wxT('\0')));
2196 // now see what we got
2197 if ( strLHS
== wxT("type") )
2199 strMimeType
= strRHS
;
2201 else if ( strLHS
.StartsWith(wxT("desc")) )
2205 else if ( strLHS
== wxT("exts") )
2207 strExtensions
= strRHS
;
2209 else if ( strLHS
== wxT("icon") )
2211 // this one is simply ignored: it usually refers to Netscape
2212 // built in icons which are useless for us anyhow
2214 else if ( !strLHS
.StartsWith(wxT("x-")) )
2216 // we suppose that all fields starting with "X-" are
2217 // unregistered extensions according to the standard practice,
2218 // but it may be worth telling the user about other junk in
2219 // his mime.types file
2220 wxLogWarning(wxT("Unknown field in file %s, line %lu: '%s'."),
2221 strFileName
.c_str(), nLine
+ 1L, strLHS
.c_str());
2226 if ( !nextFieldOnSameLine
)
2228 //else: don't reset it
2230 // as we don't reset strMimeType, the next field in this entry
2231 // will be interpreted correctly.
2237 // depending on the format (Mosaic or Netscape) either space or comma
2238 // is used to separate the extensions
2239 strExtensions
.Replace(wxT(","), wxT(" "));
2241 // also deal with the leading dot
2242 if ( !strExtensions
.empty() && strExtensions
[0u] == wxT('.') )
2244 strExtensions
.erase(0, 1);
2247 wxLogTrace(TRACE_MIME
, wxT("mime.types: '%s' => '%s' (%s)"),
2248 strExtensions
.c_str(),
2249 strMimeType
.c_str(),
2252 AddMimeTypeInfo(strMimeType
, strExtensions
, strDesc
);
2254 // finished with this line
2261 // ----------------------------------------------------------------------------
2262 // UNIX mailcap files parsing
2263 // ----------------------------------------------------------------------------
2265 // the data for a single MIME type
2266 struct MailcapLineData
2275 wxArrayString verbs
,
2283 MailcapLineData() { testfailed
= needsterminal
= copiousoutput
= false; }
2286 // process a non-standard (i.e. not the first or second one) mailcap field
2288 wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData
& data
,
2289 const wxString
& curField
)
2291 if ( curField
.empty() )
2297 // is this something of the form foo=bar?
2298 const wxChar
*pEq
= wxStrchr(curField
, wxT('='));
2301 // split "LHS = RHS" in 2
2302 wxString lhs
= curField
.BeforeFirst(wxT('=')),
2303 rhs
= curField
.AfterFirst(wxT('='));
2305 lhs
.Trim(true); // from right
2306 rhs
.Trim(false); // from left
2308 // it might be quoted
2309 if ( !rhs
.empty() && rhs
[0u] == wxT('"') && rhs
.Last() == wxT('"') )
2311 rhs
= rhs
.Mid(1, rhs
.length() - 2);
2314 // is it a command verb or something else?
2315 if ( lhs
== wxT("test") )
2317 if ( wxSystem(rhs
) == 0 )
2320 wxLogTrace(TRACE_MIME_TEST
,
2321 wxT("Test '%s' for mime type '%s' succeeded."),
2322 rhs
.c_str(), data
.type
.c_str());
2326 wxLogTrace(TRACE_MIME_TEST
,
2327 wxT("Test '%s' for mime type '%s' failed, skipping."),
2328 rhs
.c_str(), data
.type
.c_str());
2330 data
.testfailed
= true;
2333 else if ( lhs
== wxT("desc") )
2337 else if ( lhs
== wxT("x11-bitmap") )
2341 else if ( lhs
== wxT("notes") )
2345 else // not a (recognized) special case, must be a verb (e.g. "print")
2347 data
.verbs
.Add(lhs
);
2348 data
.commands
.Add(rhs
);
2351 else // '=' not found
2353 // so it must be a simple flag
2354 if ( curField
== wxT("needsterminal") )
2356 data
.needsterminal
= true;
2358 else if ( curField
== wxT("copiousoutput"))
2360 // copiousoutput impies that the viewer is a console program
2361 data
.needsterminal
=
2362 data
.copiousoutput
= true;
2364 else if ( !IsKnownUnimportantField(curField
) )
2373 bool wxMimeTypesManagerImpl::ReadMailcap(const wxString
& strFileName
,
2376 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mailcap file '%s' ---"),
2377 strFileName
.c_str());
2379 wxTextFile
file(strFileName
);
2380 #if defined(__WXGTK20__) && wxUSE_UNICODE
2381 if ( !file
.Open(wxConvUTF8
) )
2387 // indices of MIME types (in m_aTypes) we already found in this file
2389 // (see the comments near the end of function for the reason we need this)
2390 wxArrayInt aIndicesSeenHere
;
2392 // accumulator for the current field
2394 curField
.reserve(1024);
2396 const wxChar
*pPagerEnv
= wxGetenv(wxT("PAGER"));
2398 const wxArrayString empty_extensions_list
;
2400 size_t nLineCount
= file
.GetLineCount();
2401 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2403 // now we're at the start of the line
2404 const wxChar
*pc
= file
[nLine
].c_str();
2407 while ( wxIsspace(*pc
) )
2410 // comment or empty string?
2411 if ( *pc
== wxT('#') || *pc
== wxT('\0') )
2417 // what field are we currently in? The first 2 are fixed and there may
2418 // be an arbitrary number of other fields parsed by
2419 // ProcessOtherMailcapField()
2421 // the first field is the MIME type
2428 currentToken
= Field_Type
;
2430 // the flags and field values on the current line
2431 MailcapLineData data
;
2439 // interpret the next character literally (notice that
2440 // backslash can be used for line continuation)
2441 if ( *++pc
== wxT('\0') )
2443 // fetch the next line if there is one
2444 if ( nLine
== nLineCount
- 1 )
2446 // something is wrong, bail out
2449 wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."),
2450 strFileName
.c_str(),
2455 // pass to the beginning of the next line
2456 pc
= file
[++nLine
].c_str();
2458 // skip pc++ at the end of the loop
2464 // just a normal character
2470 cont
= false; // end of line reached, exit the loop
2472 // fall through to still process this field
2475 // trim whitespaces from both sides
2476 curField
.Trim(true).Trim(false);
2478 switch ( currentToken
)
2481 data
.type
= curField
.Lower();
2482 if ( data
.type
.empty() )
2484 // I don't think that this is a valid mailcap
2485 // entry, but try to interpret it somehow
2486 data
.type
= wxT('*');
2489 if ( data
.type
.Find(wxT('/')) == wxNOT_FOUND
)
2491 // we interpret "type" as "type/*"
2492 data
.type
+= wxT("/*");
2495 currentToken
= Field_OpenCmd
;
2499 data
.cmdOpen
= curField
;
2501 currentToken
= Field_Other
;
2505 if ( !ProcessOtherMailcapField(data
, curField
) )
2507 // don't flood the user with error messages if
2508 // we don't understand something in his
2509 // mailcap, but give them in debug mode because
2510 // this might be useful for the programmer
2513 wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."),
2514 strFileName
.c_str(),
2520 else if ( data
.testfailed
)
2522 // skip this entry entirely
2526 // it already has this value
2527 //currentToken = Field_Other;
2531 wxFAIL_MSG(wxT("unknown field type in mailcap"));
2534 // next token starts immediately after ';'
2542 // continue in the same line
2546 // we read the entire entry, check what have we got
2547 // ------------------------------------------------
2549 // check that we really read something reasonable
2550 if ( currentToken
< Field_Other
)
2552 wxLogWarning(wxT("Mailcap file %s, line %lu: incomplete entry ignored."),
2553 strFileName
.c_str(), nLine
+ 1L);
2558 // if the test command failed, it's as if the entry were not there at all
2559 if ( data
.testfailed
)
2564 // support for flags:
2565 // 1. create an xterm for 'needsterminal'
2566 // 2. append "| $PAGER" for 'copiousoutput'
2568 // Note that the RFC says that having both needsterminal and
2569 // copiousoutput is probably a mistake, so it seems that running
2570 // programs with copiousoutput inside an xterm as it is done now
2571 // is a bad idea (FIXME)
2572 if ( data
.copiousoutput
)
2574 data
.cmdOpen
<< wxT(" | ") << (pPagerEnv
? pPagerEnv
: wxT("more"));
2577 if ( data
.needsterminal
)
2579 data
.cmdOpen
.Printf(wxT("xterm -e sh -c '%s'"),
2580 data
.cmdOpen
.c_str());
2583 if ( !data
.cmdOpen
.empty() )
2585 data
.verbs
.Insert(wxT("open"), 0);
2586 data
.commands
.Insert(data
.cmdOpen
, 0);
2589 // we have to decide whether the new entry should replace any entries
2590 // for the same MIME type we had previously found or not
2593 // the fall back entries have the lowest priority, by definition
2600 // have we seen this one before?
2601 int nIndex
= m_aTypes
.Index(data
.type
);
2603 // and if we have, was it in this file? if not, we should
2604 // overwrite the previously seen one
2605 overwrite
= nIndex
== wxNOT_FOUND
||
2606 aIndicesSeenHere
.Index(nIndex
) == wxNOT_FOUND
;
2609 wxLogTrace(TRACE_MIME
, wxT("mailcap %s: %s [%s]"),
2610 data
.type
.c_str(), data
.cmdOpen
.c_str(),
2611 overwrite
? wxT("replace") : wxT("add"));
2613 int n
= AddToMimeData
2617 new wxMimeTypeCommands(data
.verbs
, data
.commands
),
2618 empty_extensions_list
,
2625 aIndicesSeenHere
.Add(n
);
2632 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
2638 size_t count
= m_aTypes
.GetCount();
2639 for ( size_t n
= 0; n
< count
; n
++ )
2641 // don't return template types from here (i.e. anything containg '*')
2642 const wxString
&type
= m_aTypes
[n
];
2643 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
2645 mimetypes
.Add(type
);
2649 return mimetypes
.GetCount();
2652 // ----------------------------------------------------------------------------
2653 // writing to MIME type files
2654 // ----------------------------------------------------------------------------
2656 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
2660 wxArrayString sMimeTypes
;
2661 ft
->GetMimeTypes(sMimeTypes
);
2664 size_t nCount
= sMimeTypes
.GetCount();
2665 for (i
= 0; i
< nCount
; i
++)
2667 const wxString
&sMime
= sMimeTypes
.Item(i
);
2668 int nIndex
= m_aTypes
.Index(sMime
);
2669 if ( nIndex
== wxNOT_FOUND
)
2671 // error if we get here ??
2676 WriteMimeInfo(nIndex
, true);
2677 m_aTypes
.RemoveAt(nIndex
);
2678 m_aEntries
.RemoveAt(nIndex
);
2679 m_aExtensions
.RemoveAt(nIndex
);
2680 m_aDescriptions
.RemoveAt(nIndex
);
2681 m_aIcons
.RemoveAt(nIndex
);
2684 // check data integrity
2685 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
2686 m_aTypes
.Count() == m_aExtensions
.Count() &&
2687 m_aTypes
.Count() == m_aIcons
.Count() &&
2688 m_aTypes
.Count() == m_aDescriptions
.Count() );
2693 // ----------------------------------------------------------------------------
2694 // private functions
2695 // ----------------------------------------------------------------------------
2697 static bool IsKnownUnimportantField(const wxString
& fieldAll
)
2699 static const wxChar
* const knownFields
[] =
2701 wxT("x-mozilla-flags"),
2702 wxT("nametemplate"),
2703 wxT("textualnewlines"),
2706 wxString field
= fieldAll
.BeforeFirst(wxT('='));
2707 for ( size_t n
= 0; n
< WXSIZEOF(knownFields
); n
++ )
2709 if ( field
.CmpNoCase(knownFields
[n
]) == 0 )
2717 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE