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
42 #include "wx/string.h"
48 #include "wx/dynarray.h"
49 #include "wx/confbase.h"
52 #include "wx/textfile.h"
55 #include "wx/tokenzr.h"
56 #include "wx/iconloc.h"
57 #include "wx/filename.h"
59 #include "wx/unix/mimetype.h"
62 #include "wx/gtk/gnome/gvfs.h"
64 // other standard headers
67 // this class extends wxTextFile
70 class wxMimeTextFile
: public wxTextFile
74 wxMimeTextFile () : wxTextFile () {};
75 wxMimeTextFile(const wxString
& strFile
) : wxTextFile(strFile
) {};
77 int pIndexOf(const wxString
& sSearch
, bool bIncludeComments
= false, int iStart
= 0)
80 int nResult
= wxNOT_FOUND
;
81 if (i
>= GetLineCount())
84 wxString sTest
= sSearch
;
90 while ( i
< GetLineCount() )
94 if (sLine
.Contains(sTest
))
102 while ( (i
< GetLineCount()) )
106 if ( ! sLine
.StartsWith(wxT("#")))
108 if (sLine
.Contains(sTest
))
119 bool CommentLine(int nIndex
)
123 if (nIndex
>= (int)GetLineCount() )
126 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
130 bool CommentLine(const wxString
& sTest
)
132 int nIndex
= pIndexOf(sTest
);
135 if (nIndex
>= (int)GetLineCount() )
138 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
142 wxString
GetVerb(size_t i
)
144 if (i
> GetLineCount() )
145 return wxEmptyString
;
147 wxString sTmp
= GetLine(i
).BeforeFirst(wxT('='));
151 wxString
GetCmd(size_t i
)
153 if (i
> GetLineCount() )
154 return wxEmptyString
;
156 wxString sTmp
= GetLine(i
).AfterFirst(wxT('='));
161 // in case we're compiling in non-GUI mode
162 class WXDLLEXPORT wxIcon
;
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 // MIME code tracing mask
169 #define TRACE_MIME wxT("mime")
171 // give trace messages about the results of mailcap tests
172 #define TRACE_MIME_TEST wxT("mimetest")
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 // there are some fields which we don't understand but for which we don't give
179 // warnings as we know that they're not important - this function is used to
181 static bool IsKnownUnimportantField(const wxString
& field
);
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
188 // This class uses both mailcap and mime.types to gather information about file
191 // The information about mailcap file was extracted from metamail(1) sources
192 // and documentation and subsequently revised when I found the RFC 1524
195 // Format of mailcap file: spaces are ignored, each line is either a comment
196 // (starts with '#') or a line of the form <field1>;<field2>;...;<fieldN>.
197 // A backslash can be used to quote semicolons and newlines (and, in fact,
198 // anything else including itself).
200 // The first field is always the MIME type in the form of type/subtype (see RFC
201 // 822) where subtype may be '*' meaning "any". Following metamail, we accept
202 // "type" which means the same as "type/*", although I'm not sure whether this
205 // The second field is always the command to run. It is subject to
206 // parameter/filename expansion described below.
208 // All the following fields are optional and may not be present at all. If
209 // they're present they may appear in any order, although each of them should
210 // appear only once. The optional fields are the following:
211 // * notes=xxx is an uninterpreted string which is silently ignored
212 // * test=xxx is the command to be used to determine whether this mailcap line
213 // applies to our data or not. The RHS of this field goes through the
214 // parameter/filename expansion (as the 2nd field) and the resulting string
215 // is executed. The line applies only if the command succeeds, i.e. returns 0
217 // * print=xxx is the command to be used to print (and not view) the data of
218 // this type (parameter/filename expansion is done here too)
219 // * edit=xxx is the command to open/edit the data of this type
220 // * needsterminal means that a new interactive console must be created for
222 // * copiousoutput means that the viewer doesn't interact with the user but
223 // produces (possibly) a lof of lines of output on stdout (i.e. "cat" is a
224 // good example), thus it might be a good idea to use some kind of paging
226 // * textualnewlines means not to perform CR/LF translation (not honored)
227 // * compose and composetyped fields are used to determine the program to be
228 // called to create a new message pert in the specified format (unused).
230 // Parameter/filename expansion:
231 // * %s is replaced with the (full) file name
232 // * %t is replaced with MIME type/subtype of the entry
233 // * for multipart type only %n is replaced with the nnumber of parts and %F is
234 // replaced by an array of (content-type, temporary file name) pairs for all
235 // message parts (TODO)
236 // * %{parameter} is replaced with the value of parameter taken from
237 // Content-type header line of the message.
240 // There are 2 possible formats for mime.types file, one entry per line (used
241 // for global mime.types and called Mosaic format) and "expanded" format where
242 // an entry takes multiple lines (used for users mime.types and called
245 // For both formats spaces are ignored and lines starting with a '#' are
246 // comments. Each record has one of two following forms:
247 // a) for "brief" format:
248 // <mime type> <space separated list of extensions>
249 // b) for "expanded" format:
250 // type=<mime type> BACKSLASH
251 // desc="<description>" BACKSLASH
252 // exts="<comma separated list of extensions>"
254 // (where BACKSLASH is a literal '\\' which we can't put here because cpp
257 // We try to autodetect the format of mime.types: if a non-comment line starts
258 // with "type=" we assume the second format, otherwise the first one.
260 // there may be more than one entry for one and the same mime type, to
261 // choose the right one we have to run the command specified in the test
262 // field on our data.
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 // GNOME stores the info we're interested in in several locations:
269 // 1. xxx.keys files under /usr/share/mime-info
270 // 2. xxx.keys files under ~/.gnome/mime-info
272 // Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
273 // just before the field name.
276 void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString
& filename
,
277 const wxArrayString
& dirs
)
279 wxTextFile
textfile(filename
);
280 #if defined(__WXGTK20__) && wxUSE_UNICODE
281 if ( !textfile
.Open(wxConvUTF8
) )
283 if ( !textfile
.Open() )
287 wxLogTrace(TRACE_MIME
, wxT("--- Opened Gnome file %s ---"),
290 wxArrayString
search_dirs( dirs
);
292 // values for the entry being parsed
293 wxString curMimeType
, curIconFile
;
294 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
296 wxArrayString strExtensions
;
300 size_t nLineCount
= textfile
.GetLineCount();
302 while ( nLine
< nLineCount
)
304 pc
= textfile
[nLine
].c_str();
305 if ( *pc
!= wxT('#') )
308 wxLogTrace(TRACE_MIME
, wxT("--- Reading from Gnome file %s '%s' ---"),
309 filename
.c_str(), pc
);
311 // trim trailing space and tab
312 while ((*pc
== wxT(' ')) || (*pc
== wxT('\t')))
316 int equal_pos
= sTmp
.Find( wxT('=') );
319 wxString left_of_equal
= sTmp
.Left( equal_pos
);
320 const wxChar
*right_of_equal
= pc
;
321 right_of_equal
+= equal_pos
+1;
323 if (left_of_equal
== wxT("icon_filename"))
326 curIconFile
= right_of_equal
;
328 wxFileName
newFile( curIconFile
);
329 if (newFile
.IsRelative() || newFile
.FileExists())
331 size_t nDirs
= search_dirs
.GetCount();
333 for (size_t nDir
= 0; nDir
< nDirs
; nDir
++)
335 newFile
.SetPath( search_dirs
[nDir
] );
336 newFile
.AppendDir( wxT("pixmaps") );
337 newFile
.AppendDir( wxT("document-icons") );
338 newFile
.SetExt( wxT("png") );
339 if (newFile
.FileExists())
341 curIconFile
= newFile
.GetFullPath();
342 // reorder search_dirs for speedup (fewer
343 // calls to FileExist() required)
346 wxString tmp
= search_dirs
[nDir
];
347 search_dirs
.RemoveAt( nDir
);
348 search_dirs
.Insert( tmp
, 0 );
355 else if (left_of_equal
== wxT("open"))
357 sTmp
= right_of_equal
;
358 sTmp
.Replace( wxT("%f"), wxT("%s") );
359 sTmp
.Prepend( wxT("open=") );
362 else if (left_of_equal
== wxT("view"))
364 sTmp
= right_of_equal
;
365 sTmp
.Replace( wxT("%f"), wxT("%s") );
366 sTmp
.Prepend( wxT("view=") );
369 else if (left_of_equal
== wxT("print"))
371 sTmp
= right_of_equal
;
372 sTmp
.Replace( wxT("%f"), wxT("%s") );
373 sTmp
.Prepend( wxT("print=") );
376 else if (left_of_equal
== wxT("description"))
378 strDesc
= right_of_equal
;
380 else if (left_of_equal
== wxT("short_list_application_ids_for_novice_user_level"))
382 sTmp
= right_of_equal
;
383 if (sTmp
.Contains( wxT(",") ))
384 sTmp
= sTmp
.BeforeFirst( wxT(',') );
385 sTmp
.Prepend( wxT("open=") );
386 sTmp
.Append( wxT(" %s") );
390 } // emd of has an equals sign
393 // not a comment and not an equals sign
394 if (sTmp
.Contains(wxT('/')))
396 // this is the start of the new mimetype
397 // overwrite any existing data
398 if (! curMimeType
.empty())
400 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
402 // now get ready for next bit
403 entry
= new wxMimeTypeCommands
;
406 curMimeType
= sTmp
.BeforeFirst(wxT(':'));
409 } // end of not a comment
411 // ignore blank lines
413 } // end of while, save any data
415 if ( curMimeType
.empty() )
418 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
421 void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString
& filename
)
423 wxTextFile
textfile(filename
);
424 if ( !textfile
.Open() )
427 wxLogTrace(TRACE_MIME
,
428 wxT("--- Opened Gnome file %s ---"),
431 // values for the entry being parsed
432 wxString curMimeType
, curExtList
;
435 size_t nLineCount
= textfile
.GetLineCount();
436 for ( size_t nLine
= 0; /* nothing */; nLine
++ )
438 if ( nLine
< nLineCount
)
440 pc
= textfile
[nLine
].c_str();
441 if ( *pc
== wxT('#') )
449 // so that we will fall into the "if" below
456 if ( !curMimeType
.empty() && !curExtList
.empty() )
458 wxLogTrace(TRACE_MIME
,
459 wxT("--- At end of Gnome file finding mimetype %s ---"),
460 curMimeType
.c_str());
462 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
467 // the end: this can only happen if nLine == nLineCount
476 // what do we have here?
477 if ( *pc
== wxT('\t') )
479 // this is a field=value ling
480 pc
++; // skip leading TAB
482 static const int lenField
= 5; // strlen("ext: ")
483 if ( wxStrncmp(pc
, wxT("ext: "), lenField
) == 0 )
485 // skip it and take everything left until the end of line
486 curExtList
= pc
+ lenField
;
488 //else: some other field, we don't care
492 // this is the start of the new section
493 wxLogTrace(TRACE_MIME
,
494 wxT("--- In Gnome file finding mimetype %s ---"),
495 curMimeType
.c_str());
497 if (! curMimeType
.empty())
498 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
502 while ( *pc
!= wxT(':') && *pc
!= wxT('\0') )
504 curMimeType
+= *pc
++;
511 void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
512 const wxString
& dirbase
, const wxArrayString
& dirs
)
514 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
515 wxT("base directory shouldn't end with a slash") );
517 wxString dirname
= dirbase
;
518 dirname
<< wxT("/mime-info");
520 if ( !wxDir::Exists(dirname
) )
524 if ( !dir
.IsOpened() )
527 // we will concatenate it with filename to get the full path below
533 cont
= dir
.GetFirst(&filename
, wxT("*.mime"), wxDIR_FILES
);
536 LoadGnomeMimeTypesFromMimeFile(dirname
+ filename
);
538 cont
= dir
.GetNext(&filename
);
541 cont
= dir
.GetFirst(&filename
, wxT("*.keys"), wxDIR_FILES
);
544 LoadGnomeDataFromKeyFile(dirname
+ filename
, dirs
);
546 cont
= dir
.GetNext(&filename
);
549 // FIXME: Hack alert: We scan all icons and deduce the
550 // mime-type from the file name.
552 dirname
<< wxT("/pixmaps/document-icons");
554 // these are always empty in this file
555 wxArrayString strExtensions
;
558 if ( !wxDir::Exists(dirname
) )
560 // Just test for default GPE dir also
561 dirname
= wxT("/usr/share/gpe/pixmaps/default/filemanager/document-icons");
563 if ( !wxDir::Exists(dirname
) )
567 wxDir
dir2( dirname
);
569 cont
= dir2
.GetFirst(&filename
, wxT("gnome-*.png"), wxDIR_FILES
);
572 wxString mimeType
= filename
;
573 mimeType
.Remove( 0, 6 ); // remove "gnome-"
574 mimeType
.Remove( mimeType
.Len() - 4, 4 ); // remove ".png"
575 int pos
= mimeType
.Find( wxT("-") );
576 if (pos
!= wxNOT_FOUND
)
578 mimeType
.SetChar( pos
, wxT('/') );
579 wxString iconFile
= dirname
;
580 iconFile
<< wxT("/");
581 iconFile
<< filename
;
582 AddToMimeData( mimeType
, iconFile
, NULL
, strExtensions
, strDesc
, true );
585 cont
= dir2
.GetNext(&filename
);
589 void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString
& sExtraDir
)
593 wxString gnomedir
= wxGetenv( wxT("GNOMEDIR") );
594 if (!gnomedir
.empty())
596 gnomedir
<< wxT("/share");
597 dirs
.Add( gnomedir
);
600 dirs
.Add(wxT("/usr/share"));
601 dirs
.Add(wxT("/usr/local/share"));
603 gnomedir
= wxGetHomeDir();
604 gnomedir
<< wxT("/.gnome");
605 dirs
.Add( gnomedir
);
607 if (!sExtraDir
.empty())
608 dirs
.Add( sExtraDir
);
610 size_t nDirs
= dirs
.GetCount();
611 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
613 LoadGnomeMimeFilesFromDir(dirs
[nDir
], dirs
);
617 // ----------------------------------------------------------------------------
619 // ----------------------------------------------------------------------------
622 // KDE stores the icon info in its .kdelnk files. The file for mimetype/subtype
623 // may be found in either of the following locations
625 // 1. $KDEDIR/share/mimelnk/mimetype/subtype.kdelnk
626 // 2. ~/.kde/share/mimelnk/mimetype/subtype.kdelnk
628 // The format of a .kdelnk file is almost the same as the one used by
629 // wxFileConfig, i.e. there are groups, comments and entries. The icon is the
630 // value for the entry "Type"
632 // kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD
633 // for now write to .kdelnk but should eventually do .desktop instead (in preference??)
635 bool wxMimeTypesManagerImpl::CheckKDEDirsExist( const wxString
&sOK
, const wxString
&sTest
)
639 return wxDir::Exists(sOK
);
643 wxString sStart
= sOK
+ wxT("/") + sTest
.BeforeFirst(wxT('/'));
644 if (!wxDir::Exists(sStart
))
646 wxString sEnd
= sTest
.AfterFirst(wxT('/'));
647 return CheckKDEDirsExist(sStart
, sEnd
);
651 bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index
, bool delete_index
)
653 wxMimeTextFile appoutfile
, mimeoutfile
;
654 wxString sHome
= wxGetHomeDir();
655 wxString sTmp
= wxT(".kde/share/mimelnk/");
656 wxString sMime
= m_aTypes
[index
];
657 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.BeforeFirst(wxT('/')) );
658 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
+ wxT(".kdelnk");
661 bool bMimeExists
= mimeoutfile
.Open(sTmp
);
664 bTemp
= mimeoutfile
.Create(sTmp
);
665 // some unknown error eg out of disk space
670 sTmp
= wxT(".kde/share/applnk/");
671 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.AfterFirst(wxT('/')) );
672 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
.AfterFirst(wxT('/')) + wxT(".kdelnk");
675 bAppExists
= appoutfile
.Open(sTmp
);
678 bTemp
= appoutfile
.Create(sTmp
);
679 // some unknown error eg out of disk space
684 // fixed data; write if new file
687 mimeoutfile
.AddLine(wxT("#KDE Config File"));
688 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
689 mimeoutfile
.AddLine(wxT("Version=1.0"));
690 mimeoutfile
.AddLine(wxT("Type=MimeType"));
691 mimeoutfile
.AddLine(wxT("MimeType=") + sMime
);
696 mimeoutfile
.AddLine(wxT("#KDE Config File"));
697 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
698 appoutfile
.AddLine(wxT("Version=1.0"));
699 appoutfile
.AddLine(wxT("Type=Application"));
700 appoutfile
.AddLine(wxT("MimeType=") + sMime
+ wxT(';'));
705 mimeoutfile
.CommentLine(wxT("Comment="));
707 mimeoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
708 appoutfile
.CommentLine(wxT("Name="));
710 appoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
712 sTmp
= m_aIcons
[index
];
713 // we can either give the full path, or the shortfilename if its in
714 // one of the directories we search
715 mimeoutfile
.CommentLine(wxT("Icon=") );
717 mimeoutfile
.AddLine(wxT("Icon=") + sTmp
);
718 appoutfile
.CommentLine(wxT("Icon=") );
720 appoutfile
.AddLine(wxT("Icon=") + sTmp
);
722 sTmp
= wxT(" ") + m_aExtensions
[index
];
724 wxStringTokenizer
tokenizer(sTmp
, wxT(" "));
725 sTmp
= wxT("Patterns=");
726 mimeoutfile
.CommentLine(sTmp
);
727 while ( tokenizer
.HasMoreTokens() )
729 // holds an extension; need to change it to *.ext;
730 wxString e
= wxT("*.") + tokenizer
.GetNextToken() + wxT(";");
735 mimeoutfile
.AddLine(sTmp
);
737 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
738 // if we don't find open just have an empty string ... FIX this
739 sTmp
= entries
->GetCommandForVerb(wxT("open"));
740 sTmp
.Replace( wxT("%s"), wxT("%f") );
742 mimeoutfile
.CommentLine(wxT("DefaultApp=") );
744 mimeoutfile
.AddLine(wxT("DefaultApp=") + sTmp
);
746 sTmp
.Replace( wxT("%f"), wxT("") );
747 appoutfile
.CommentLine(wxT("Exec="));
749 appoutfile
.AddLine(wxT("Exec=") + sTmp
);
751 if (entries
->GetCount() > 1)
753 //other actions as well as open
757 if (mimeoutfile
.Write())
760 if (appoutfile
.Write())
767 void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString
& dirbase
,
768 const wxString
& subdir
,
769 const wxString
& filename
,
770 const wxArrayString
& icondirs
)
773 if ( !file
.Open(dirbase
+ filename
) )
776 wxLogTrace(TRACE_MIME
, wxT("loading KDE file %s"),
777 (dirbase
+ filename
).c_str());
779 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
781 wxString mimetype
, mime_desc
, strIcon
;
783 int nIndex
= file
.pIndexOf( wxT("MimeType=") );
784 if (nIndex
== wxNOT_FOUND
)
786 // construct mimetype from the directory name and the basename of the
787 // file (it always has .kdelnk extension)
788 mimetype
<< subdir
<< wxT('/') << filename
.BeforeLast( wxT('.') );
791 mimetype
= file
.GetCmd(nIndex
);
793 // first find the description string: it is the value in either "Comment="
794 // line or "Comment[<locale_name>]=" one
795 nIndex
= wxNOT_FOUND
;
800 wxLocale
*locale
= wxGetLocale();
803 // try "Comment[locale name]" first
804 comment
<< wxT("Comment[") + locale
->GetName() + wxT("]=");
805 nIndex
= file
.pIndexOf(comment
);
809 if ( nIndex
== wxNOT_FOUND
)
811 comment
= wxT("Comment=");
812 nIndex
= file
.pIndexOf(comment
);
815 if ( nIndex
!= wxNOT_FOUND
)
816 mime_desc
= file
.GetCmd(nIndex
);
817 //else: no description
819 // next find the extensions
820 wxString mime_extension
;
822 nIndex
= file
.pIndexOf(wxT("Patterns="));
823 if ( nIndex
!= wxNOT_FOUND
)
825 wxString exts
= file
.GetCmd(nIndex
);
827 wxStringTokenizer
tokenizer(exts
, wxT(";"));
828 while ( tokenizer
.HasMoreTokens() )
830 wxString e
= tokenizer
.GetNextToken();
832 // don't support too difficult patterns
833 if ( e
.Left(2) != wxT("*.") )
836 if ( !mime_extension
.empty() )
838 // separate from the previous ext
839 mime_extension
<< wxT(' ');
842 mime_extension
<< e
.Mid(2);
846 sExts
.Add(mime_extension
);
848 // ok, now we can take care of icon:
850 nIndex
= file
.pIndexOf(wxT("Icon="));
851 if ( nIndex
!= wxNOT_FOUND
)
853 strIcon
= file
.GetCmd(nIndex
);
855 wxLogTrace(TRACE_MIME
, wxT(" icon %s"), strIcon
.c_str());
857 // it could be the real path, but more often a short name
858 if (!wxFileExists(strIcon
))
860 // icon is just the short name
861 if ( !strIcon
.empty() )
863 // we must check if the file exists because it may be stored
864 // in many locations, at least ~/.kde and $KDEDIR
865 size_t nDir
, nDirs
= icondirs
.GetCount();
866 for ( nDir
= 0; nDir
< nDirs
; nDir
++ )
868 wxFileName
fnameIcon( strIcon
);
869 wxFileName
fname( icondirs
[nDir
], fnameIcon
.GetName() );
870 fname
.SetExt( wxT("png") );
871 if (fname
.FileExists())
873 strIcon
= fname
.GetFullPath();
874 wxLogTrace(TRACE_MIME
, wxT(" iconfile %s"), strIcon
.c_str());
882 // now look for lines which know about the application
883 // exec= or DefaultApp=
885 nIndex
= file
.pIndexOf(wxT("DefaultApp"));
887 if ( nIndex
== wxNOT_FOUND
)
890 nIndex
= file
.pIndexOf(wxT("Exec"));
893 if ( nIndex
!= wxNOT_FOUND
)
895 // we expect %f; others including %F and %U and %u are possible
896 wxString sTmp
= file
.GetCmd(nIndex
);
897 if (0 == sTmp
.Replace( wxT("%f"), wxT("%s") ))
898 sTmp
= sTmp
+ wxT(" %s");
899 entry
->AddOrReplaceVerb(wxString(wxT("open")), sTmp
);
902 AddToMimeData(mimetype
, strIcon
, entry
, sExts
, mime_desc
);
905 void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString
& dirbase
,
906 const wxString
& subdir
,
907 const wxArrayString
& icondirs
)
909 wxString dirname
= dirbase
;
912 if ( !dir
.IsOpened() )
915 wxLogTrace(TRACE_MIME
, wxT("--- Loading from KDE directory %s ---"),
921 bool cont
= dir
.GetFirst(&filename
, wxT("*.kdelnk"), wxDIR_FILES
);
924 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
926 cont
= dir
.GetNext(&filename
);
929 // new standard for Gnome and KDE
930 cont
= dir
.GetFirst(&filename
, wxT("*.desktop"), wxDIR_FILES
);
933 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
935 cont
= dir
.GetNext(&filename
);
939 void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString
& dirbase
,
940 const wxArrayString
& icondirs
)
942 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
943 wxT("base directory shouldn't end with a slash") );
945 wxString dirname
= dirbase
;
946 dirname
<< wxT("/mimelnk");
948 if ( !wxDir::Exists(dirname
) )
952 if ( !dir
.IsOpened() )
955 // we will concatenate it with dir name to get the full path below
959 bool cont
= dir
.GetFirst(&subdir
, wxEmptyString
, wxDIR_DIRS
);
962 LoadKDELinksForMimeType(dirname
, subdir
, icondirs
);
964 cont
= dir
.GetNext(&subdir
);
968 void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString
& sExtraDir
)
971 wxArrayString icondirs
;
973 // FIXME: This code is heavily broken. There are three bugs in it:
974 // 1) it uses only KDEDIR, which is deprecated, instead of using
975 // list of paths from KDEDIRS and using KDEDIR only if KDEDIRS
977 // 2) it doesn't look into ~/.kde/share/config/kdeglobals where
978 // user's settings are stored and thus *ignores* user's settings
979 // instead of respecting them
980 // 3) it "tries to guess KDEDIR" and "tries a few likely theme
981 // names", both of which is completely arbitrary; instead, the
982 // code should give up if KDEDIR(S) is not set and/or the icon
983 // theme cannot be determined, because it means that the user is
984 // not using KDE (and thus is not interested in KDE icons anyway)
986 // the variable $KDEDIR is set when KDE is running
987 wxString kdedir
= wxGetenv( wxT("KDEDIR") );
991 // $(KDEDIR)/share/config/kdeglobals holds info
992 // the current icons theme
993 wxFileName
configFile( kdedir
, wxEmptyString
);
994 configFile
.AppendDir( wxT("share") );
995 configFile
.AppendDir( wxT("config") );
996 configFile
.SetName( wxT("kdeglobals") );
999 if (configFile
.FileExists() && config
.Open(configFile
.GetFullPath()))
1001 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1002 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1003 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1004 configFile
.AppendDir( wxT("icons") );
1007 wxString
theme(wxT("default.kde"));
1008 size_t cnt
= config
.GetLineCount();
1009 for (size_t i
= 0; i
< cnt
; i
++)
1011 if (config
[i
].StartsWith(wxT("Theme="), &theme
/*rest*/))
1015 configFile
.AppendDir(theme
);
1019 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1020 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1022 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1023 configFile
.AppendDir( wxT("icons") );
1025 // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
1026 configFile
.AppendDir( wxT("default.kde") );
1029 configFile
.SetName( wxEmptyString
);
1030 configFile
.AppendDir( wxT("32x32") );
1031 configFile
.AppendDir( wxT("mimetypes") );
1033 // Just try a few likely icons theme names
1035 int pos
= configFile
.GetDirCount() - 3;
1037 if (!wxDir::Exists(configFile
.GetPath()))
1039 configFile
.RemoveDir( pos
);
1040 configFile
.InsertDir( pos
, wxT("default.kde") );
1043 if (!wxDir::Exists(configFile
.GetPath()))
1045 configFile
.RemoveDir( pos
);
1046 configFile
.InsertDir( pos
, wxT("default") );
1049 if (!wxDir::Exists(configFile
.GetPath()))
1051 configFile
.RemoveDir( pos
);
1052 configFile
.InsertDir( pos
, wxT("crystalsvg") );
1055 if (!wxDir::Exists(configFile
.GetPath()))
1057 configFile
.RemoveDir( pos
);
1058 configFile
.InsertDir( pos
, wxT("crystal") );
1061 if (wxDir::Exists(configFile
.GetPath()))
1062 icondirs
.Add( configFile
.GetFullPath() );
1065 // settings in ~/.kde have maximal priority
1066 dirs
.Add(wxGetHomeDir() + wxT("/.kde/share"));
1067 icondirs
.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
1071 dirs
.Add( wxString(kdedir
) + wxT("/share") );
1072 icondirs
.Add( wxString(kdedir
) + wxT("/share/icons/") );
1076 // try to guess KDEDIR
1077 dirs
.Add(wxT("/usr/share"));
1078 dirs
.Add(wxT("/opt/kde/share"));
1079 icondirs
.Add(wxT("/usr/share/icons/"));
1080 icondirs
.Add(wxT("/usr/X11R6/share/icons/")); // Debian/Corel linux
1081 icondirs
.Add(wxT("/opt/kde/share/icons/"));
1084 if (!sExtraDir
.empty())
1085 dirs
.Add(sExtraDir
);
1086 icondirs
.Add(sExtraDir
+ wxT("/icons"));
1088 size_t nDirs
= dirs
.GetCount();
1089 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1091 LoadKDELinkFilesFromDir(dirs
[nDir
], icondirs
);
1095 // ----------------------------------------------------------------------------
1096 // wxFileTypeImpl (Unix)
1097 // ----------------------------------------------------------------------------
1099 wxString
wxFileTypeImpl::GetExpandedCommand(const wxString
& verb
, const wxFileType::MessageParameters
& params
) const
1103 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1105 sTmp
= m_manager
->GetCommand( verb
, m_index
[i
] );
1109 return wxFileType::ExpandCommand(sTmp
, params
);
1112 bool wxFileTypeImpl::GetIcon(wxIconLocation
*iconLoc
) const
1116 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1118 sTmp
= m_manager
->m_aIcons
[m_index
[i
]];
1127 iconLoc
->SetFileName(sTmp
);
1133 bool wxFileTypeImpl::GetMimeTypes(wxArrayString
& mimeTypes
) const
1136 for (size_t i
= 0; i
< m_index
.GetCount(); i
++)
1137 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
1142 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
1143 wxArrayString
*commands
,
1144 const wxFileType::MessageParameters
& params
) const
1146 wxString vrb
, cmd
, sTmp
;
1148 wxMimeTypeCommands
* sPairs
;
1150 // verbs and commands have been cleared already in mimecmn.cpp...
1151 // if we find no entries in the exact match, try the inexact match
1152 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
1154 // list of verb = command pairs for this mimetype
1155 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
1157 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
1159 vrb
= sPairs
->GetVerb(i
);
1160 // some gnome entries have "." inside
1161 vrb
= vrb
.AfterLast(wxT('.'));
1162 cmd
= sPairs
->GetCmd(i
);
1165 cmd
= wxFileType::ExpandCommand(cmd
, params
);
1167 if ( vrb
.IsSameAs(wxT("open")))
1170 verbs
->Insert(vrb
, 0u);
1172 commands
->Insert(cmd
, 0u);
1188 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
1190 wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
1193 // one extension in the space or comma-delimited list
1195 for ( const wxChar
*p
= strExtensions
; /* nothing */; p
++ )
1197 if ( *p
== wxT(' ') || *p
== wxT(',') || *p
== wxT('\0') )
1199 if ( !strExt
.empty() )
1201 extensions
.Add(strExt
);
1204 //else: repeated spaces
1205 // (shouldn't happen, but it's not that important if it does happen)
1207 if ( *p
== wxT('\0') )
1210 else if ( *p
== wxT('.') )
1212 // remove the dot from extension (but only if it's the first char)
1213 if ( !strExt
.empty() )
1217 //else: no, don't append it
1228 // set an arbitrary command:
1229 // could adjust the code to ask confirmation if it already exists and
1230 // overwriteprompt is true, but this is currently ignored as *Associate* has
1231 // no overwrite prompt
1233 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
1234 const wxString
& verb
,
1235 bool WXUNUSED(overwriteprompt
))
1237 wxArrayString strExtensions
;
1238 wxString strDesc
, strIcon
;
1240 wxArrayString strTypes
;
1241 GetMimeTypes(strTypes
);
1242 if ( strTypes
.IsEmpty() )
1245 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1246 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
1249 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1251 if (!m_manager
->DoAssociation(strTypes
[i
], strIcon
, entry
, strExtensions
, strDesc
))
1258 // ignore index on the grouds that we only have one icon in a Unix file
1259 bool wxFileTypeImpl::SetDefaultIcon(const wxString
& strIcon
, int WXUNUSED(index
))
1261 if (strIcon
.empty())
1264 wxArrayString strExtensions
;
1267 wxArrayString strTypes
;
1268 GetMimeTypes(strTypes
);
1269 if ( strTypes
.IsEmpty() )
1272 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1274 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1276 if ( !m_manager
->DoAssociation
1292 // ----------------------------------------------------------------------------
1293 // wxMimeTypesManagerImpl (Unix)
1294 // ----------------------------------------------------------------------------
1296 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
1298 m_initialized
= false;
1299 m_mailcapStylesInited
= 0;
1302 void wxMimeTypesManagerImpl::InitIfNeeded()
1304 if ( !m_initialized
)
1306 // set the flag first to prevent recursion
1307 m_initialized
= true;
1309 wxString wm
= wxGetenv( wxT("WINDOWMANAGER") );
1311 if (wm
.Find( wxT("kde") ) != wxNOT_FOUND
)
1312 Initialize( wxMAILCAP_KDE
);
1313 else if (wm
.Find( wxT("gnome") ) != wxNOT_FOUND
)
1314 Initialize( wxMAILCAP_GNOME
);
1320 // read system and user mailcaps and other files
1321 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
1322 const wxString
& sExtraDir
)
1324 // read mimecap amd mime.types
1325 if ( (mailcapStyles
& wxMAILCAP_NETSCAPE
) ||
1326 (mailcapStyles
& wxMAILCAP_STANDARD
) )
1327 GetMimeInfo(sExtraDir
);
1329 // read GNOME tables
1330 if (mailcapStyles
& wxMAILCAP_GNOME
)
1331 GetGnomeMimeInfo(sExtraDir
);
1334 if (mailcapStyles
& wxMAILCAP_KDE
)
1335 GetKDEMimeInfo(sExtraDir
);
1337 m_mailcapStylesInited
|= mailcapStyles
;
1340 // clear data so you can read another group of WM files
1341 void wxMimeTypesManagerImpl::ClearData()
1345 m_aExtensions
.Clear();
1346 m_aDescriptions
.Clear();
1348 WX_CLEAR_ARRAY(m_aEntries
);
1351 m_mailcapStylesInited
= 0;
1354 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
1359 void wxMimeTypesManagerImpl::GetMimeInfo(const wxString
& sExtraDir
)
1361 // read this for netscape or Metamail formats
1363 // directories where we look for mailcap and mime.types by default
1364 // used by netscape and pine and other mailers, using 2 different formats!
1366 // (taken from metamail(1) sources)
1368 // although RFC 1524 specifies the search path of
1369 // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
1370 // places - OTOH, the RFC also says that this path can be changed with
1371 // MAILCAPS environment variable (containing the colon separated full
1372 // filenames to try) which is not done yet (TODO?)
1374 wxString strHome
= wxGetenv(wxT("HOME"));
1377 dirs
.Add( strHome
+ wxT("/.") );
1378 dirs
.Add( wxT("/etc/") );
1379 dirs
.Add( wxT("/usr/etc/") );
1380 dirs
.Add( wxT("/usr/local/etc/") );
1381 dirs
.Add( wxT("/etc/mail/") );
1382 dirs
.Add( wxT("/usr/public/lib/") );
1383 if (!sExtraDir
.empty())
1384 dirs
.Add( sExtraDir
+ wxT("/") );
1386 size_t nDirs
= dirs
.GetCount();
1387 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1389 wxString file
= dirs
[nDir
] + wxT("mailcap");
1390 if ( wxFile::Exists(file
) )
1395 file
= dirs
[nDir
] + wxT("mime.types");
1396 if ( wxFile::Exists(file
) )
1398 ReadMimeTypes(file
);
1403 bool wxMimeTypesManagerImpl::WriteToMimeTypes(int index
, bool delete_index
)
1405 // check we have the right manager
1406 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1410 wxString strHome
= wxGetenv(wxT("HOME"));
1412 // and now the users mailcap
1413 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1415 wxMimeTextFile file
;
1416 if ( wxFile::Exists(strUserMailcap
) )
1418 bTemp
= file
.Open(strUserMailcap
);
1425 bTemp
= file
.Create(strUserMailcap
);
1431 // test for netscape's header and return false if its found
1432 nIndex
= file
.pIndexOf(wxT("#--Netscape"));
1433 if (nIndex
!= wxNOT_FOUND
)
1435 wxASSERT_MSG(false,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed"));
1439 // write it in alternative format
1440 // get rid of unwanted entries
1441 wxString strType
= m_aTypes
[index
];
1442 nIndex
= file
.pIndexOf(strType
);
1444 // get rid of all the unwanted entries...
1445 if (nIndex
!= wxNOT_FOUND
)
1446 file
.CommentLine(nIndex
);
1450 // add the new entries in
1451 wxString sTmp
= strType
.Append( wxT(' '), 40 - strType
.Len() );
1452 sTmp
= sTmp
+ m_aExtensions
[index
];
1456 bTemp
= file
.Write();
1463 bool wxMimeTypesManagerImpl::WriteToNSMimeTypes(int index
, bool delete_index
)
1465 //check we have the right managers
1466 if (! ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) )
1470 wxString strHome
= wxGetenv(wxT("HOME"));
1472 // and now the users mailcap
1473 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1475 wxMimeTextFile file
;
1476 if ( wxFile::Exists(strUserMailcap
) )
1478 bTemp
= file
.Open(strUserMailcap
);
1485 bTemp
= file
.Create(strUserMailcap
);
1490 // write it in the format that Netscape uses
1492 // test for netscape's header and insert if required...
1493 // this is a comment so use true
1494 nIndex
= file
.pIndexOf(wxT("#--Netscape"), true);
1495 if (nIndex
== wxNOT_FOUND
)
1497 // either empty file or metamail format
1498 // at present we can't cope with mixed formats, so exit to preseve
1499 // metamail entreies
1500 if (file
.GetLineCount() > 0)
1502 wxASSERT_MSG(false, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
1506 file
.InsertLine(wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
1510 wxString strType
= wxT("type=") + m_aTypes
[index
];
1511 nIndex
= file
.pIndexOf(strType
);
1513 // get rid of all the unwanted entries...
1514 if (nIndex
!= wxNOT_FOUND
)
1516 wxString sOld
= file
[nIndex
];
1517 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1519 file
.CommentLine(nIndex
);
1520 sOld
= file
[nIndex
];
1522 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex
, sOld
.c_str());
1527 if (nIndex
< (int) file
.GetLineCount())
1528 file
.CommentLine(nIndex
);
1531 nIndex
= (int) file
.GetLineCount();
1533 wxString sTmp
= strType
+ wxT(" \\");
1535 file
.InsertLine(sTmp
, nIndex
);
1537 if ( ! m_aDescriptions
.Item(index
).empty() )
1539 sTmp
= wxT("desc=\"") + m_aDescriptions
[index
]+ wxT("\" \\"); //.trim ??
1543 file
.InsertLine(sTmp
, nIndex
);
1547 wxString sExts
= m_aExtensions
.Item(index
);
1548 sTmp
= wxT("exts=\"") + sExts
.Trim(false).Trim() + wxT("\"");
1552 file
.InsertLine(sTmp
, nIndex
);
1555 bTemp
= file
.Write();
1562 bool wxMimeTypesManagerImpl::WriteToMailCap(int index
, bool delete_index
)
1564 //check we have the right managers
1565 if ( !( ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) ||
1566 ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) ) )
1570 wxString strHome
= wxGetenv(wxT("HOME"));
1572 // and now the users mailcap
1573 wxString strUserMailcap
= strHome
+ wxT("/.mailcap");
1575 wxMimeTextFile file
;
1576 if ( wxFile::Exists(strUserMailcap
) )
1578 bTemp
= file
.Open(strUserMailcap
);
1585 bTemp
= file
.Create(strUserMailcap
);
1590 // now got a file we can write to ....
1591 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
1593 wxString sCmd
= entries
->GetCommandForVerb(wxT("open"), &iOpen
);
1596 sTmp
= m_aTypes
[index
];
1598 int nIndex
= file
.pIndexOf(sTmp
);
1600 // get rid of all the unwanted entries...
1601 if (nIndex
== wxNOT_FOUND
)
1603 nIndex
= (int) file
.GetLineCount();
1607 sOld
= file
[nIndex
];
1608 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mailcap line '%d' ---"), nIndex
);
1610 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1612 file
.CommentLine(nIndex
);
1613 if (nIndex
< (int) file
.GetLineCount())
1614 sOld
= sOld
+ file
[nIndex
];
1618 file
.GetLineCount()) file
.CommentLine(nIndex
);
1621 sTmp
= sTmp
+ wxT(";") + sCmd
; //includes wxT(" %s ");
1623 // write it in the format that Netscape uses (default)
1624 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1627 file
.InsertLine(sTmp
, nIndex
);
1632 // write extended format
1634 // TODO - FIX this code:
1636 // sOld holds all the entries, but our data store only has some
1637 // eg test= is not stored
1639 // so far we have written the mimetype and command out
1640 wxStringTokenizer
sT(sOld
, wxT(";\\"));
1641 if (sT
.CountTokens() > 2)
1643 // first one mimetype; second one command, rest unknown...
1645 s
= sT
.GetNextToken();
1646 s
= sT
.GetNextToken();
1649 s
= sT
.GetNextToken();
1650 while ( ! s
.empty() )
1652 bool bKnownToken
= false;
1653 if (s
.Contains(wxT("description=")))
1655 if (s
.Contains(wxT("x11-bitmap=")))
1659 for (i
=0; i
< entries
->GetCount(); i
++)
1661 if (s
.Contains(entries
->GetVerb(i
)))
1667 sTmp
= sTmp
+ wxT("; \\");
1668 file
.InsertLine(sTmp
, nIndex
);
1672 s
= sT
.GetNextToken();
1676 if (! m_aDescriptions
[index
].empty() )
1678 sTmp
= sTmp
+ wxT("; \\");
1679 file
.InsertLine(sTmp
, nIndex
);
1681 sTmp
= wxT(" description=\"") + m_aDescriptions
[index
] + wxT("\"");
1684 if (! m_aIcons
[index
].empty() )
1686 sTmp
= sTmp
+ wxT("; \\");
1687 file
.InsertLine(sTmp
, nIndex
);
1689 sTmp
= wxT(" x11-bitmap=\"") + m_aIcons
[index
] + wxT("\"");
1692 if ( entries
->GetCount() > 1 )
1695 for (i
=0; i
< entries
->GetCount(); i
++)
1698 sTmp
= sTmp
+ wxT("; \\");
1699 file
.InsertLine(sTmp
, nIndex
);
1701 sTmp
= wxT(" ") + entries
->GetVerbCmd(i
);
1705 file
.InsertLine(sTmp
, nIndex
);
1709 bTemp
= file
.Write();
1716 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
1720 wxString strType
= ftInfo
.GetMimeType();
1721 wxString strDesc
= ftInfo
.GetDescription();
1722 wxString strIcon
= ftInfo
.GetIconFile();
1724 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1726 if ( ! ftInfo
.GetOpenCommand().empty())
1727 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
1728 if ( ! ftInfo
.GetPrintCommand().empty())
1729 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
1731 // now find where these extensions are in the data store and remove them
1732 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
1733 wxString sExt
, sExtStore
;
1735 for (i
=0; i
< sA_Exts
.GetCount(); i
++)
1737 sExt
= sA_Exts
.Item(i
);
1739 // clean up to just a space before and after
1740 sExt
.Trim().Trim(false);
1741 sExt
= wxT(' ') + sExt
+ wxT(' ');
1742 for (nIndex
= 0; nIndex
< m_aExtensions
.GetCount(); nIndex
++)
1744 sExtStore
= m_aExtensions
.Item(nIndex
);
1745 if (sExtStore
.Replace(sExt
, wxT(" ") ) > 0)
1746 m_aExtensions
.Item(nIndex
) = sExtStore
;
1750 if ( !DoAssociation(strType
, strIcon
, entry
, sA_Exts
, strDesc
) )
1753 return GetFileTypeFromMimeType(strType
);
1756 bool wxMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
1757 const wxString
& strIcon
,
1758 wxMimeTypeCommands
*entry
,
1759 const wxArrayString
& strExtensions
,
1760 const wxString
& strDesc
)
1762 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
1764 if ( nIndex
== wxNOT_FOUND
)
1767 return WriteMimeInfo(nIndex
, false);
1770 bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex
, bool delete_mime
)
1774 if ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
)
1776 // write in metamail format;
1777 if (WriteToMimeTypes(nIndex
, delete_mime
) )
1778 if ( WriteToMailCap(nIndex
, delete_mime
) )
1782 if ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
)
1784 // write in netsacpe format;
1785 if (WriteToNSMimeTypes(nIndex
, delete_mime
) )
1786 if ( WriteToMailCap(nIndex
, delete_mime
) )
1790 // Don't write GNOME files here as this is not
1791 // allowed and simply doesn't work
1793 if (m_mailcapStylesInited
& wxMAILCAP_KDE
)
1795 // write in KDE format;
1796 if (WriteKDEMimeFile(nIndex
, delete_mime
) )
1803 int wxMimeTypesManagerImpl::AddToMimeData(const wxString
& strType
,
1804 const wxString
& strIcon
,
1805 wxMimeTypeCommands
*entry
,
1806 const wxArrayString
& strExtensions
,
1807 const wxString
& strDesc
,
1808 bool replaceExisting
)
1812 // ensure mimetype is always lower case
1813 wxString mimeType
= strType
.Lower();
1815 // is this a known MIME type?
1816 int nIndex
= m_aTypes
.Index(mimeType
);
1817 if ( nIndex
== wxNOT_FOUND
)
1820 m_aTypes
.Add(mimeType
);
1821 m_aIcons
.Add(strIcon
);
1822 m_aEntries
.Add(entry
? entry
: new wxMimeTypeCommands
);
1824 // change nIndex so we can use it below to add the extensions
1825 m_aExtensions
.Add(wxEmptyString
);
1826 nIndex
= m_aExtensions
.size() - 1;
1828 m_aDescriptions
.Add(strDesc
);
1830 else // yes, we already have it
1832 if ( replaceExisting
)
1834 // if new description change it
1835 if ( !strDesc
.empty())
1836 m_aDescriptions
[nIndex
] = strDesc
;
1838 // if new icon change it
1839 if ( !strIcon
.empty())
1840 m_aIcons
[nIndex
] = strIcon
;
1844 delete m_aEntries
[nIndex
];
1845 m_aEntries
[nIndex
] = entry
;
1848 else // add data we don't already have ...
1850 // if new description add only if none
1851 if ( m_aDescriptions
[nIndex
].empty() )
1852 m_aDescriptions
[nIndex
] = strDesc
;
1854 // if new icon and no existing icon
1855 if ( m_aIcons
[nIndex
].empty() )
1856 m_aIcons
[nIndex
] = strIcon
;
1858 // add any new entries...
1861 wxMimeTypeCommands
*entryOld
= m_aEntries
[nIndex
];
1863 size_t count
= entry
->GetCount();
1864 for ( size_t i
= 0; i
< count
; i
++ )
1866 const wxString
& verb
= entry
->GetVerb(i
);
1867 if ( !entryOld
->HasVerb(verb
) )
1869 entryOld
->AddOrReplaceVerb(verb
, entry
->GetCmd(i
));
1873 // as we don't store it anywhere, it won't be deleted later as
1874 // usual -- do it immediately instead
1880 // always add the extensions to this mimetype
1881 wxString
& exts
= m_aExtensions
[nIndex
];
1883 // add all extensions we don't have yet
1884 size_t count
= strExtensions
.GetCount();
1885 for ( size_t i
= 0; i
< count
; i
++ )
1887 wxString ext
= strExtensions
[i
] + wxT(' ');
1889 if ( exts
.Find(ext
) == wxNOT_FOUND
)
1895 // check data integrity
1896 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
1897 m_aTypes
.Count() == m_aExtensions
.Count() &&
1898 m_aTypes
.Count() == m_aIcons
.Count() &&
1899 m_aTypes
.Count() == m_aDescriptions
.Count() );
1904 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
1911 size_t count
= m_aExtensions
.GetCount();
1912 for ( size_t n
= 0; n
< count
; n
++ )
1914 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
1916 while ( tk
.HasMoreTokens() )
1918 // consider extensions as not being case-sensitive
1919 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
1922 wxFileType
*fileType
= new wxFileType
;
1923 fileType
->m_impl
->Init(this, n
);
1933 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
1937 wxFileType
* fileType
= NULL
;
1938 // mime types are not case-sensitive
1939 wxString
mimetype(mimeType
);
1940 mimetype
.MakeLower();
1942 // first look for an exact match
1943 int index
= m_aTypes
.Index(mimetype
);
1944 if ( index
!= wxNOT_FOUND
)
1946 fileType
= new wxFileType
;
1947 fileType
->m_impl
->Init(this, index
);
1950 // then try to find "text/*" as match for "text/plain" (for example)
1951 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
1952 // the whole string - ok.
1954 index
= wxNOT_FOUND
;
1955 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
1957 size_t nCount
= m_aTypes
.Count();
1958 for ( size_t n
= 0; n
< nCount
; n
++ )
1960 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
1961 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
1968 if ( index
!= wxNOT_FOUND
)
1970 // don't throw away fileType that was already found
1972 fileType
= new wxFileType
;
1973 fileType
->m_impl
->Init(this, index
);
1979 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
1981 wxString command
, testcmd
, sV
, sTmp
;
1982 sV
= verb
+ wxT("=");
1984 // list of verb = command pairs for this mimetype
1985 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
1988 for ( i
= 0; i
< sPairs
->GetCount (); i
++ )
1990 sTmp
= sPairs
->GetVerbCmd (i
);
1991 if ( sTmp
.Contains(sV
) )
1992 command
= sTmp
.AfterFirst(wxT('='));
1998 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
2002 wxString extensions
;
2003 const wxArrayString
& exts
= filetype
.GetExtensions();
2004 size_t nExts
= exts
.GetCount();
2005 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
2008 extensions
+= wxT(' ');
2010 extensions
+= exts
[nExt
];
2013 AddMimeTypeInfo(filetype
.GetMimeType(),
2015 filetype
.GetDescription());
2017 AddMailcapInfo(filetype
.GetMimeType(),
2018 filetype
.GetOpenCommand(),
2019 filetype
.GetPrintCommand(),
2021 filetype
.GetDescription());
2024 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
2025 const wxString
& strExtensions
,
2026 const wxString
& strDesc
)
2028 // reading mailcap may find image/* , while
2029 // reading mime.types finds image/gif and no match is made
2030 // this means all the get functions don't work fix this
2032 wxString sTmp
= strExtensions
;
2034 wxArrayString sExts
;
2035 sTmp
.Trim().Trim(false);
2037 while (!sTmp
.empty())
2039 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
2040 sTmp
= sTmp
.BeforeLast(wxT(' '));
2043 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
2046 void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString
& strType
,
2047 const wxString
& strOpenCmd
,
2048 const wxString
& strPrintCmd
,
2049 const wxString
& strTest
,
2050 const wxString
& strDesc
)
2054 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands
;
2055 entry
->Add(wxT("open=") + strOpenCmd
);
2056 entry
->Add(wxT("print=") + strPrintCmd
);
2057 entry
->Add(wxT("test=") + strTest
);
2060 wxArrayString strExtensions
;
2062 AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
2065 bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString
& strFileName
)
2067 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mime.types file '%s' ---"),
2068 strFileName
.c_str());
2070 wxTextFile
file(strFileName
);
2071 #if defined(__WXGTK20__) && wxUSE_UNICODE
2072 if ( !file
.Open(wxConvUTF8
) )
2078 // the information we extract
2079 wxString strMimeType
, strDesc
, strExtensions
;
2081 size_t nLineCount
= file
.GetLineCount();
2082 const wxChar
*pc
= NULL
;
2083 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2087 // now we're at the start of the line
2088 pc
= file
[nLine
].c_str();
2092 // we didn't finish with the previous line yet
2097 while ( wxIsspace(*pc
) )
2100 // comment or blank line?
2101 if ( *pc
== wxT('#') || !*pc
)
2103 // skip the whole line
2108 // detect file format
2109 const wxChar
*pEqualSign
= wxStrchr(pc
, wxT('='));
2110 if ( pEqualSign
== NULL
)
2115 // first field is mime type
2116 for ( strMimeType
.Empty(); !wxIsspace(*pc
) && *pc
!= wxT('\0'); pc
++ )
2122 while ( wxIsspace(*pc
) )
2125 // take all the rest of the string
2128 // no description...
2136 // the string on the left of '=' is the field name
2137 wxString
strLHS(pc
, pEqualSign
- pc
);
2140 for ( pc
= pEqualSign
+ 1; wxIsspace(*pc
); pc
++ )
2144 if ( *pc
== wxT('"') )
2146 // the string is quoted and ends at the matching quote
2147 pEnd
= wxStrchr(++pc
, wxT('"'));
2150 wxLogWarning(wxT("Mime.types file %s, line %lu: unterminated quoted string."),
2151 strFileName
.c_str(), nLine
+ 1L);
2156 // unquoted string ends at the first space or at the end of
2158 for ( pEnd
= pc
; *pEnd
&& !wxIsspace(*pEnd
); pEnd
++ )
2162 // now we have the RHS (field value)
2163 wxString
strRHS(pc
, pEnd
- pc
);
2165 // check what follows this entry
2166 if ( *pEnd
== wxT('"') )
2172 for ( pc
= pEnd
; wxIsspace(*pc
); pc
++ )
2175 // if there is something left, it may be either a '\\' to continue
2176 // the line or the next field of the same entry
2177 bool entryEnded
= *pc
== wxT('\0');
2178 bool nextFieldOnSameLine
= false;
2181 nextFieldOnSameLine
= ((*pc
!= wxT('\\')) || (pc
[1] != wxT('\0')));
2184 // now see what we got
2185 if ( strLHS
== wxT("type") )
2187 strMimeType
= strRHS
;
2189 else if ( strLHS
.StartsWith(wxT("desc")) )
2193 else if ( strLHS
== wxT("exts") )
2195 strExtensions
= strRHS
;
2197 else if ( strLHS
== wxT("icon") )
2199 // this one is simply ignored: it usually refers to Netscape
2200 // built in icons which are useless for us anyhow
2202 else if ( !strLHS
.StartsWith(wxT("x-")) )
2204 // we suppose that all fields starting with "X-" are
2205 // unregistered extensions according to the standard practice,
2206 // but it may be worth telling the user about other junk in
2207 // his mime.types file
2208 wxLogWarning(wxT("Unknown field in file %s, line %lu: '%s'."),
2209 strFileName
.c_str(), nLine
+ 1L, strLHS
.c_str());
2214 if ( !nextFieldOnSameLine
)
2216 //else: don't reset it
2218 // as we don't reset strMimeType, the next field in this entry
2219 // will be interpreted correctly.
2225 // depending on the format (Mosaic or Netscape) either space or comma
2226 // is used to separate the extensions
2227 strExtensions
.Replace(wxT(","), wxT(" "));
2229 // also deal with the leading dot
2230 if ( !strExtensions
.empty() && strExtensions
[0u] == wxT('.') )
2232 strExtensions
.erase(0, 1);
2235 wxLogTrace(TRACE_MIME
, wxT("mime.types: '%s' => '%s' (%s)"),
2236 strExtensions
.c_str(),
2237 strMimeType
.c_str(),
2240 AddMimeTypeInfo(strMimeType
, strExtensions
, strDesc
);
2242 // finished with this line
2249 // ----------------------------------------------------------------------------
2250 // UNIX mailcap files parsing
2251 // ----------------------------------------------------------------------------
2253 // the data for a single MIME type
2254 struct MailcapLineData
2263 wxArrayString verbs
,
2271 MailcapLineData() { testfailed
= needsterminal
= copiousoutput
= false; }
2274 // process a non-standard (i.e. not the first or second one) mailcap field
2276 wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData
& data
,
2277 const wxString
& curField
)
2279 if ( curField
.empty() )
2285 // is this something of the form foo=bar?
2286 const wxChar
*pEq
= wxStrchr(curField
, wxT('='));
2289 // split "LHS = RHS" in 2
2290 wxString lhs
= curField
.BeforeFirst(wxT('=')),
2291 rhs
= curField
.AfterFirst(wxT('='));
2293 lhs
.Trim(true); // from right
2294 rhs
.Trim(false); // from left
2296 // it might be quoted
2297 if ( !rhs
.empty() && rhs
[0u] == wxT('"') && rhs
.Last() == wxT('"') )
2299 rhs
= rhs
.Mid(1, rhs
.length() - 2);
2302 // is it a command verb or something else?
2303 if ( lhs
== wxT("test") )
2305 if ( wxSystem(rhs
) == 0 )
2308 wxLogTrace(TRACE_MIME_TEST
,
2309 wxT("Test '%s' for mime type '%s' succeeded."),
2310 rhs
.c_str(), data
.type
.c_str());
2314 wxLogTrace(TRACE_MIME_TEST
,
2315 wxT("Test '%s' for mime type '%s' failed, skipping."),
2316 rhs
.c_str(), data
.type
.c_str());
2318 data
.testfailed
= true;
2321 else if ( lhs
== wxT("desc") )
2325 else if ( lhs
== wxT("x11-bitmap") )
2329 else if ( lhs
== wxT("notes") )
2333 else // not a (recognized) special case, must be a verb (e.g. "print")
2335 data
.verbs
.Add(lhs
);
2336 data
.commands
.Add(rhs
);
2339 else // '=' not found
2341 // so it must be a simple flag
2342 if ( curField
== wxT("needsterminal") )
2344 data
.needsterminal
= true;
2346 else if ( curField
== wxT("copiousoutput"))
2348 // copiousoutput impies that the viewer is a console program
2349 data
.needsterminal
=
2350 data
.copiousoutput
= true;
2352 else if ( !IsKnownUnimportantField(curField
) )
2361 bool wxMimeTypesManagerImpl::ReadMailcap(const wxString
& strFileName
,
2364 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mailcap file '%s' ---"),
2365 strFileName
.c_str());
2367 wxTextFile
file(strFileName
);
2368 #if defined(__WXGTK20__) && wxUSE_UNICODE
2369 if ( !file
.Open(wxConvUTF8
) )
2375 // indices of MIME types (in m_aTypes) we already found in this file
2377 // (see the comments near the end of function for the reason we need this)
2378 wxArrayInt aIndicesSeenHere
;
2380 // accumulator for the current field
2382 curField
.reserve(1024);
2384 size_t nLineCount
= file
.GetLineCount();
2385 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2387 // now we're at the start of the line
2388 const wxChar
*pc
= file
[nLine
].c_str();
2391 while ( wxIsspace(*pc
) )
2394 // comment or empty string?
2395 if ( *pc
== wxT('#') || *pc
== wxT('\0') )
2401 // what field are we currently in? The first 2 are fixed and there may
2402 // be an arbitrary number of other fields parsed by
2403 // ProcessOtherMailcapField()
2405 // the first field is the MIME type
2412 currentToken
= Field_Type
;
2414 // the flags and field values on the current line
2415 MailcapLineData data
;
2423 // interpret the next character literally (notice that
2424 // backslash can be used for line continuation)
2425 if ( *++pc
== wxT('\0') )
2427 // fetch the next line if there is one
2428 if ( nLine
== nLineCount
- 1 )
2430 // something is wrong, bail out
2433 wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."),
2434 strFileName
.c_str(),
2439 // pass to the beginning of the next line
2440 pc
= file
[++nLine
].c_str();
2442 // skip pc++ at the end of the loop
2448 // just a normal character
2454 cont
= false; // end of line reached, exit the loop
2456 // fall through to still process this field
2459 // trim whitespaces from both sides
2460 curField
.Trim(true).Trim(false);
2462 switch ( currentToken
)
2465 data
.type
= curField
.Lower();
2466 if ( data
.type
.empty() )
2468 // I don't think that this is a valid mailcap
2469 // entry, but try to interpret it somehow
2470 data
.type
= wxT('*');
2473 if ( data
.type
.Find(wxT('/')) == wxNOT_FOUND
)
2475 // we interpret "type" as "type/*"
2476 data
.type
+= wxT("/*");
2479 currentToken
= Field_OpenCmd
;
2483 data
.cmdOpen
= curField
;
2485 currentToken
= Field_Other
;
2489 if ( !ProcessOtherMailcapField(data
, curField
) )
2491 // don't flood the user with error messages if
2492 // we don't understand something in his
2493 // mailcap, but give them in debug mode because
2494 // this might be useful for the programmer
2497 wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."),
2498 strFileName
.c_str(),
2504 else if ( data
.testfailed
)
2506 // skip this entry entirely
2510 // it already has this value
2511 //currentToken = Field_Other;
2515 wxFAIL_MSG(wxT("unknown field type in mailcap"));
2518 // next token starts immediately after ';'
2526 // continue in the same line
2530 // we read the entire entry, check what have we got
2531 // ------------------------------------------------
2533 // check that we really read something reasonable
2534 if ( currentToken
< Field_Other
)
2536 wxLogWarning(wxT("Mailcap file %s, line %lu: incomplete entry ignored."),
2537 strFileName
.c_str(), nLine
+ 1L);
2542 // if the test command failed, it's as if the entry were not there at all
2543 if ( data
.testfailed
)
2548 // support for flags:
2549 // 1. create an xterm for 'needsterminal'
2550 // 2. append "| $PAGER" for 'copiousoutput'
2552 // Note that the RFC says that having both needsterminal and
2553 // copiousoutput is probably a mistake, so it seems that running
2554 // programs with copiousoutput inside an xterm as it is done now
2555 // is a bad idea (FIXME)
2556 if ( data
.copiousoutput
)
2558 const wxChar
*p
= wxGetenv(wxT("PAGER"));
2559 data
.cmdOpen
<< wxT(" | ") << (p
? p
: wxT("more"));
2562 if ( data
.needsterminal
)
2564 data
.cmdOpen
= wxString::Format(wxT("xterm -e sh -c '%s'"),
2565 data
.cmdOpen
.c_str());
2568 if ( !data
.cmdOpen
.empty() )
2570 data
.verbs
.Insert(wxT("open"), 0);
2571 data
.commands
.Insert(data
.cmdOpen
, 0);
2574 // we have to decide whether the new entry should replace any entries
2575 // for the same MIME type we had previously found or not
2578 // the fall back entries have the lowest priority, by definition
2585 // have we seen this one before?
2586 int nIndex
= m_aTypes
.Index(data
.type
);
2588 // and if we have, was it in this file? if not, we should
2589 // overwrite the previously seen one
2590 overwrite
= nIndex
== wxNOT_FOUND
||
2591 aIndicesSeenHere
.Index(nIndex
) == wxNOT_FOUND
;
2594 wxLogTrace(TRACE_MIME
, wxT("mailcap %s: %s [%s]"),
2595 data
.type
.c_str(), data
.cmdOpen
.c_str(),
2596 overwrite
? wxT("replace") : wxT("add"));
2598 int n
= AddToMimeData
2602 new wxMimeTypeCommands(data
.verbs
, data
.commands
),
2603 wxArrayString() /* extensions */,
2610 aIndicesSeenHere
.Add(n
);
2617 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
2624 size_t count
= m_aTypes
.GetCount();
2625 for ( size_t n
= 0; n
< count
; n
++ )
2627 // don't return template types from here (i.e. anything containg '*')
2629 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
2631 mimetypes
.Add(type
);
2635 return mimetypes
.GetCount();
2638 // ----------------------------------------------------------------------------
2639 // writing to MIME type files
2640 // ----------------------------------------------------------------------------
2642 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
2644 wxArrayString sMimeTypes
;
2645 ft
->GetMimeTypes(sMimeTypes
);
2649 for (i
= 0; i
< sMimeTypes
.GetCount(); i
++)
2651 sMime
= sMimeTypes
.Item(i
);
2652 int nIndex
= m_aTypes
.Index(sMime
);
2653 if ( nIndex
== wxNOT_FOUND
)
2655 // error if we get here ??
2660 WriteMimeInfo(nIndex
, true);
2661 m_aTypes
.RemoveAt(nIndex
);
2662 m_aEntries
.RemoveAt(nIndex
);
2663 m_aExtensions
.RemoveAt(nIndex
);
2664 m_aDescriptions
.RemoveAt(nIndex
);
2665 m_aIcons
.RemoveAt(nIndex
);
2668 // check data integrity
2669 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
2670 m_aTypes
.Count() == m_aExtensions
.Count() &&
2671 m_aTypes
.Count() == m_aIcons
.Count() &&
2672 m_aTypes
.Count() == m_aDescriptions
.Count() );
2677 // ----------------------------------------------------------------------------
2678 // private functions
2679 // ----------------------------------------------------------------------------
2681 static bool IsKnownUnimportantField(const wxString
& fieldAll
)
2683 static const wxChar
*knownFields
[] =
2685 wxT("x-mozilla-flags"),
2686 wxT("nametemplate"),
2687 wxT("textualnewlines"),
2690 wxString field
= fieldAll
.BeforeFirst(wxT('='));
2691 for ( size_t n
= 0; n
< WXSIZEOF(knownFields
); n
++ )
2693 if ( field
.CmpNoCase(knownFields
[n
]) == 0 )
2701 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE