1 /////////////////////////////////////////////////////////////////////////////
2 // Name: unix/mimetype.cpp
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
12 // known bugs; there may be others!! chris elliott, biol75@york.ac.uk 27 Mar 01
14 // 1) .mailcap and .mimetypes can be either in a netscape or metamail format
15 // and entries may get confused during writing (I've tried to fix this; please let me know
16 // any files that fail)
17 // 2) KDE and Gnome do not yet fully support international read/write
18 // 3) Gnome key lines like open.latex."LaTeX this file"=latex %f will have odd results
19 // 4) writing to files comments out the existing data; I hope this avoids losing
20 // any data which we could not read, and data which we did not store like test=
21 // 5) results from reading files with multiple entries (especially matches with type/* )
22 // may (or may not) work for getXXX commands
23 // 6) Loading the png icons in Gnome doesn't work for me...
24 // 7) In Gnome, if keys.mime exists but keys.users does not, there is
25 // an error message in debug mode, but the file is still written OK
26 // 8) Deleting entries is only allowed from the user file; sytem wide entries
27 // will be preserved during unassociate
28 // 9) KDE does not yet handle multiple actions; Netscape mode never will
30 // TODO: this file is a mess, we need to split it and review everything (VZ)
32 // for compilers that support precompilation, includes "wx.h".
33 #include "wx/wxprec.h"
43 #if wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE
46 #include "wx/string.h"
52 #include "wx/dynarray.h"
53 #include "wx/confbase.h"
56 #include "wx/textfile.h"
59 #include "wx/tokenzr.h"
60 #include "wx/iconloc.h"
61 #include "wx/filename.h"
63 #include "wx/unix/mimetype.h"
66 #include "wx/gtk/gnome/gvfs.h"
68 // other standard headers
71 // this class extends wxTextFile
74 class wxMimeTextFile
: public wxTextFile
78 wxMimeTextFile () : wxTextFile () {};
79 wxMimeTextFile(const wxString
& strFile
) : wxTextFile(strFile
) {};
81 int pIndexOf(const wxString
& sSearch
, bool bIncludeComments
= false, int iStart
= 0)
84 int nResult
= wxNOT_FOUND
;
85 if (i
>= GetLineCount())
88 wxString sTest
= sSearch
;
94 while ( i
< GetLineCount() )
98 if (sLine
.Contains(sTest
))
106 while ( (i
< GetLineCount()) )
110 if ( ! sLine
.StartsWith(wxT("#")))
112 if (sLine
.Contains(sTest
))
123 bool CommentLine(int nIndex
)
127 if (nIndex
>= (int)GetLineCount() )
130 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
134 bool CommentLine(const wxString
& sTest
)
136 int nIndex
= pIndexOf(sTest
);
139 if (nIndex
>= (int)GetLineCount() )
142 GetLine(nIndex
) = GetLine(nIndex
).Prepend(wxT("#"));
146 wxString
GetVerb(size_t i
)
148 if (i
> GetLineCount() )
149 return wxEmptyString
;
151 wxString sTmp
= GetLine(i
).BeforeFirst(wxT('='));
155 wxString
GetCmd(size_t i
)
157 if (i
> GetLineCount() )
158 return wxEmptyString
;
160 wxString sTmp
= GetLine(i
).AfterFirst(wxT('='));
165 // in case we're compiling in non-GUI mode
166 class WXDLLEXPORT wxIcon
;
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 // MIME code tracing mask
173 #define TRACE_MIME wxT("mime")
175 // give trace messages about the results of mailcap tests
176 #define TRACE_MIME_TEST wxT("mimetest")
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 // there are some fields which we don't understand but for which we don't give
183 // warnings as we know that they're not important - this function is used to
185 static bool IsKnownUnimportantField(const wxString
& field
);
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
192 // This class uses both mailcap and mime.types to gather information about file
195 // The information about mailcap file was extracted from metamail(1) sources
196 // and documentation and subsequently revised when I found the RFC 1524
199 // Format of mailcap file: spaces are ignored, each line is either a comment
200 // (starts with '#') or a line of the form <field1>;<field2>;...;<fieldN>.
201 // A backslash can be used to quote semicolons and newlines (and, in fact,
202 // anything else including itself).
204 // The first field is always the MIME type in the form of type/subtype (see RFC
205 // 822) where subtype may be '*' meaning "any". Following metamail, we accept
206 // "type" which means the same as "type/*", although I'm not sure whether this
209 // The second field is always the command to run. It is subject to
210 // parameter/filename expansion described below.
212 // All the following fields are optional and may not be present at all. If
213 // they're present they may appear in any order, although each of them should
214 // appear only once. The optional fields are the following:
215 // * notes=xxx is an uninterpreted string which is silently ignored
216 // * test=xxx is the command to be used to determine whether this mailcap line
217 // applies to our data or not. The RHS of this field goes through the
218 // parameter/filename expansion (as the 2nd field) and the resulting string
219 // is executed. The line applies only if the command succeeds, i.e. returns 0
221 // * print=xxx is the command to be used to print (and not view) the data of
222 // this type (parameter/filename expansion is done here too)
223 // * edit=xxx is the command to open/edit the data of this type
224 // * needsterminal means that a new interactive console must be created for
226 // * copiousoutput means that the viewer doesn't interact with the user but
227 // produces (possibly) a lof of lines of output on stdout (i.e. "cat" is a
228 // good example), thus it might be a good idea to use some kind of paging
230 // * textualnewlines means not to perform CR/LF translation (not honored)
231 // * compose and composetyped fields are used to determine the program to be
232 // called to create a new message pert in the specified format (unused).
234 // Parameter/filename expansion:
235 // * %s is replaced with the (full) file name
236 // * %t is replaced with MIME type/subtype of the entry
237 // * for multipart type only %n is replaced with the nnumber of parts and %F is
238 // replaced by an array of (content-type, temporary file name) pairs for all
239 // message parts (TODO)
240 // * %{parameter} is replaced with the value of parameter taken from
241 // Content-type header line of the message.
244 // There are 2 possible formats for mime.types file, one entry per line (used
245 // for global mime.types and called Mosaic format) and "expanded" format where
246 // an entry takes multiple lines (used for users mime.types and called
249 // For both formats spaces are ignored and lines starting with a '#' are
250 // comments. Each record has one of two following forms:
251 // a) for "brief" format:
252 // <mime type> <space separated list of extensions>
253 // b) for "expanded" format:
254 // type=<mime type> BACKSLASH
255 // desc="<description>" BACKSLASH
256 // exts="<comma separated list of extensions>"
258 // (where BACKSLASH is a literal '\\' which we can't put here because cpp
261 // We try to autodetect the format of mime.types: if a non-comment line starts
262 // with "type=" we assume the second format, otherwise the first one.
264 // there may be more than one entry for one and the same mime type, to
265 // choose the right one we have to run the command specified in the test
266 // field on our data.
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 // GNOME stores the info we're interested in in several locations:
273 // 1. xxx.keys files under /usr/share/mime-info
274 // 2. xxx.keys files under ~/.gnome/mime-info
276 // Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
277 // just before the field name.
280 void wxMimeTypesManagerImpl::LoadGnomeDataFromKeyFile(const wxString
& filename
,
281 const wxArrayString
& dirs
)
283 wxTextFile
textfile(filename
);
284 #if defined(__WXGTK20__) && wxUSE_UNICODE
285 if ( !textfile
.Open(wxConvUTF8
) )
287 if ( !textfile
.Open() )
291 wxLogTrace(TRACE_MIME
, wxT("--- Opened Gnome file %s ---"),
294 wxArrayString
search_dirs( dirs
);
296 // values for the entry being parsed
297 wxString curMimeType
, curIconFile
;
298 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
300 wxArrayString strExtensions
;
304 size_t nLineCount
= textfile
.GetLineCount();
306 while ( nLine
< nLineCount
)
308 pc
= textfile
[nLine
].c_str();
309 if ( *pc
!= wxT('#') )
312 wxLogTrace(TRACE_MIME
, wxT("--- Reading from Gnome file %s '%s' ---"),
313 filename
.c_str(), pc
);
315 // trim trailing space and tab
316 while ((*pc
== wxT(' ')) || (*pc
== wxT('\t')))
320 int equal_pos
= sTmp
.Find( wxT('=') );
323 wxString left_of_equal
= sTmp
.Left( equal_pos
);
324 const wxChar
*right_of_equal
= pc
;
325 right_of_equal
+= equal_pos
+1;
327 if (left_of_equal
== wxT("icon_filename"))
330 curIconFile
= right_of_equal
;
332 wxFileName
newFile( curIconFile
);
333 if (newFile
.IsRelative() || newFile
.FileExists())
335 size_t nDirs
= search_dirs
.GetCount();
337 for (size_t nDir
= 0; nDir
< nDirs
; nDir
++)
339 newFile
.SetPath( search_dirs
[nDir
] );
340 newFile
.AppendDir( wxT("pixmaps") );
341 newFile
.AppendDir( wxT("document-icons") );
342 newFile
.SetExt( wxT("png") );
343 if (newFile
.FileExists())
345 curIconFile
= newFile
.GetFullPath();
346 // reorder search_dirs for speedup (fewer
347 // calls to FileExist() required)
350 wxString tmp
= search_dirs
[nDir
];
351 search_dirs
.RemoveAt( nDir
);
352 search_dirs
.Insert( tmp
, 0 );
359 else if (left_of_equal
== wxT("open"))
361 sTmp
= right_of_equal
;
362 sTmp
.Replace( wxT("%f"), wxT("%s") );
363 sTmp
.Prepend( wxT("open=") );
366 else if (left_of_equal
== wxT("view"))
368 sTmp
= right_of_equal
;
369 sTmp
.Replace( wxT("%f"), wxT("%s") );
370 sTmp
.Prepend( wxT("view=") );
373 else if (left_of_equal
== wxT("print"))
375 sTmp
= right_of_equal
;
376 sTmp
.Replace( wxT("%f"), wxT("%s") );
377 sTmp
.Prepend( wxT("print=") );
380 else if (left_of_equal
== wxT("description"))
382 strDesc
= right_of_equal
;
384 else if (left_of_equal
== wxT("short_list_application_ids_for_novice_user_level"))
386 sTmp
= right_of_equal
;
387 if (sTmp
.Contains( wxT(",") ))
388 sTmp
= sTmp
.BeforeFirst( wxT(',') );
389 sTmp
.Prepend( wxT("open=") );
390 sTmp
.Append( wxT(" %s") );
394 } // emd of has an equals sign
397 // not a comment and not an equals sign
398 if (sTmp
.Contains(wxT('/')))
400 // this is the start of the new mimetype
401 // overwrite any existing data
402 if (! curMimeType
.empty())
404 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
406 // now get ready for next bit
407 entry
= new wxMimeTypeCommands
;
410 curMimeType
= sTmp
.BeforeFirst(wxT(':'));
413 } // end of not a comment
415 // ignore blank lines
417 } // end of while, save any data
419 if ( curMimeType
.empty() )
422 AddToMimeData( curMimeType
, curIconFile
, entry
, strExtensions
, strDesc
);
425 void wxMimeTypesManagerImpl::LoadGnomeMimeTypesFromMimeFile(const wxString
& filename
)
427 wxTextFile
textfile(filename
);
428 if ( !textfile
.Open() )
431 wxLogTrace(TRACE_MIME
,
432 wxT("--- Opened Gnome file %s ---"),
435 // values for the entry being parsed
436 wxString curMimeType
, curExtList
;
439 size_t nLineCount
= textfile
.GetLineCount();
440 for ( size_t nLine
= 0; /* nothing */; nLine
++ )
442 if ( nLine
< nLineCount
)
444 pc
= textfile
[nLine
].c_str();
445 if ( *pc
== wxT('#') )
453 // so that we will fall into the "if" below
460 if ( !curMimeType
.empty() && !curExtList
.empty() )
462 wxLogTrace(TRACE_MIME
,
463 wxT("--- At end of Gnome file finding mimetype %s ---"),
464 curMimeType
.c_str());
466 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
471 // the end: this can only happen if nLine == nLineCount
480 // what do we have here?
481 if ( *pc
== wxT('\t') )
483 // this is a field=value ling
484 pc
++; // skip leading TAB
486 static const int lenField
= 5; // strlen("ext: ")
487 if ( wxStrncmp(pc
, wxT("ext: "), lenField
) == 0 )
489 // skip it and take everything left until the end of line
490 curExtList
= pc
+ lenField
;
492 //else: some other field, we don't care
496 // this is the start of the new section
497 wxLogTrace(TRACE_MIME
,
498 wxT("--- In Gnome file finding mimetype %s ---"),
499 curMimeType
.c_str());
501 if (! curMimeType
.empty())
502 AddMimeTypeInfo(curMimeType
, curExtList
, wxEmptyString
);
506 while ( *pc
!= wxT(':') && *pc
!= wxT('\0') )
508 curMimeType
+= *pc
++;
515 void wxMimeTypesManagerImpl::LoadGnomeMimeFilesFromDir(
516 const wxString
& dirbase
, const wxArrayString
& dirs
)
518 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
519 wxT("base directory shouldn't end with a slash") );
521 wxString dirname
= dirbase
;
522 dirname
<< wxT("/mime-info");
524 if ( !wxDir::Exists(dirname
) )
528 if ( !dir
.IsOpened() )
531 // we will concatenate it with filename to get the full path below
537 cont
= dir
.GetFirst(&filename
, wxT("*.mime"), wxDIR_FILES
);
540 LoadGnomeMimeTypesFromMimeFile(dirname
+ filename
);
542 cont
= dir
.GetNext(&filename
);
545 cont
= dir
.GetFirst(&filename
, wxT("*.keys"), wxDIR_FILES
);
548 LoadGnomeDataFromKeyFile(dirname
+ filename
, dirs
);
550 cont
= dir
.GetNext(&filename
);
553 // FIXME: Hack alert: We scan all icons and deduce the
554 // mime-type from the file name.
556 dirname
<< wxT("/pixmaps/document-icons");
558 // these are always empty in this file
559 wxArrayString strExtensions
;
562 if ( !wxDir::Exists(dirname
) )
564 // Just test for default GPE dir also
565 dirname
= wxT("/usr/share/gpe/pixmaps/default/filemanager/document-icons");
567 if ( !wxDir::Exists(dirname
) )
571 wxDir
dir2( dirname
);
573 cont
= dir2
.GetFirst(&filename
, wxT("gnome-*.png"), wxDIR_FILES
);
576 wxString mimeType
= filename
;
577 mimeType
.Remove( 0, 6 ); // remove "gnome-"
578 mimeType
.Remove( mimeType
.Len() - 4, 4 ); // remove ".png"
579 int pos
= mimeType
.Find( wxT("-") );
580 if (pos
!= wxNOT_FOUND
)
582 mimeType
.SetChar( pos
, wxT('/') );
583 wxString iconFile
= dirname
;
584 iconFile
<< wxT("/");
585 iconFile
<< filename
;
586 AddToMimeData( mimeType
, iconFile
, NULL
, strExtensions
, strDesc
, true );
589 cont
= dir2
.GetNext(&filename
);
593 void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString
& sExtraDir
)
597 wxString gnomedir
= wxGetenv( wxT("GNOMEDIR") );
598 if (!gnomedir
.empty())
600 gnomedir
<< wxT("/share");
601 dirs
.Add( gnomedir
);
604 dirs
.Add(wxT("/usr/share"));
605 dirs
.Add(wxT("/usr/local/share"));
607 gnomedir
= wxGetHomeDir();
608 gnomedir
<< wxT("/.gnome");
609 dirs
.Add( gnomedir
);
611 if (!sExtraDir
.empty())
612 dirs
.Add( sExtraDir
);
614 size_t nDirs
= dirs
.GetCount();
615 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
617 LoadGnomeMimeFilesFromDir(dirs
[nDir
], dirs
);
621 // ----------------------------------------------------------------------------
623 // ----------------------------------------------------------------------------
626 // KDE stores the icon info in its .kdelnk files. The file for mimetype/subtype
627 // may be found in either of the following locations
629 // 1. $KDEDIR/share/mimelnk/mimetype/subtype.kdelnk
630 // 2. ~/.kde/share/mimelnk/mimetype/subtype.kdelnk
632 // The format of a .kdelnk file is almost the same as the one used by
633 // wxFileConfig, i.e. there are groups, comments and entries. The icon is the
634 // value for the entry "Type"
636 // kde writing; see http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/kdelibs/kio/DESKTOP_ENTRY_STANDARD
637 // for now write to .kdelnk but should eventually do .desktop instead (in preference??)
639 bool wxMimeTypesManagerImpl::CheckKDEDirsExist( const wxString
&sOK
, const wxString
&sTest
)
643 return wxDir::Exists(sOK
);
647 wxString sStart
= sOK
+ wxT("/") + sTest
.BeforeFirst(wxT('/'));
648 if (!wxDir::Exists(sStart
))
650 wxString sEnd
= sTest
.AfterFirst(wxT('/'));
651 return CheckKDEDirsExist(sStart
, sEnd
);
655 bool wxMimeTypesManagerImpl::WriteKDEMimeFile(int index
, bool delete_index
)
657 wxMimeTextFile appoutfile
, mimeoutfile
;
658 wxString sHome
= wxGetHomeDir();
659 wxString sTmp
= wxT(".kde/share/mimelnk/");
660 wxString sMime
= m_aTypes
[index
];
661 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.BeforeFirst(wxT('/')) );
662 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
+ wxT(".kdelnk");
665 bool bMimeExists
= mimeoutfile
.Open(sTmp
);
668 bTemp
= mimeoutfile
.Create(sTmp
);
669 // some unknown error eg out of disk space
674 sTmp
= wxT(".kde/share/applnk/");
675 CheckKDEDirsExist(sHome
, sTmp
+ sMime
.AfterFirst(wxT('/')) );
676 sTmp
= sHome
+ wxT('/') + sTmp
+ sMime
.AfterFirst(wxT('/')) + wxT(".kdelnk");
679 bAppExists
= appoutfile
.Open(sTmp
);
682 bTemp
= appoutfile
.Create(sTmp
);
683 // some unknown error eg out of disk space
688 // fixed data; write if new file
691 mimeoutfile
.AddLine(wxT("#KDE Config File"));
692 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
693 mimeoutfile
.AddLine(wxT("Version=1.0"));
694 mimeoutfile
.AddLine(wxT("Type=MimeType"));
695 mimeoutfile
.AddLine(wxT("MimeType=") + sMime
);
700 mimeoutfile
.AddLine(wxT("#KDE Config File"));
701 mimeoutfile
.AddLine(wxT("[KDE Desktop Entry]"));
702 appoutfile
.AddLine(wxT("Version=1.0"));
703 appoutfile
.AddLine(wxT("Type=Application"));
704 appoutfile
.AddLine(wxT("MimeType=") + sMime
+ wxT(';'));
709 mimeoutfile
.CommentLine(wxT("Comment="));
711 mimeoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
712 appoutfile
.CommentLine(wxT("Name="));
714 appoutfile
.AddLine(wxT("Comment=") + m_aDescriptions
[index
]);
716 sTmp
= m_aIcons
[index
];
717 // we can either give the full path, or the shortfilename if its in
718 // one of the directories we search
719 mimeoutfile
.CommentLine(wxT("Icon=") );
721 mimeoutfile
.AddLine(wxT("Icon=") + sTmp
);
722 appoutfile
.CommentLine(wxT("Icon=") );
724 appoutfile
.AddLine(wxT("Icon=") + sTmp
);
726 sTmp
= wxT(" ") + m_aExtensions
[index
];
728 wxStringTokenizer
tokenizer(sTmp
, wxT(" "));
729 sTmp
= wxT("Patterns=");
730 mimeoutfile
.CommentLine(sTmp
);
731 while ( tokenizer
.HasMoreTokens() )
733 // holds an extension; need to change it to *.ext;
734 wxString e
= wxT("*.") + tokenizer
.GetNextToken() + wxT(";");
739 mimeoutfile
.AddLine(sTmp
);
741 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
742 // if we don't find open just have an empty string ... FIX this
743 sTmp
= entries
->GetCommandForVerb(wxT("open"));
744 sTmp
.Replace( wxT("%s"), wxT("%f") );
746 mimeoutfile
.CommentLine(wxT("DefaultApp=") );
748 mimeoutfile
.AddLine(wxT("DefaultApp=") + sTmp
);
750 sTmp
.Replace( wxT("%f"), wxT("") );
751 appoutfile
.CommentLine(wxT("Exec="));
753 appoutfile
.AddLine(wxT("Exec=") + sTmp
);
755 if (entries
->GetCount() > 1)
757 //other actions as well as open
761 if (mimeoutfile
.Write())
764 if (appoutfile
.Write())
771 void wxMimeTypesManagerImpl::LoadKDELinksForMimeSubtype(const wxString
& dirbase
,
772 const wxString
& subdir
,
773 const wxString
& filename
,
774 const wxArrayString
& icondirs
)
777 if ( !file
.Open(dirbase
+ filename
) )
780 wxLogTrace(TRACE_MIME
, wxT("loading KDE file %s"),
781 (dirbase
+ filename
).c_str());
783 wxMimeTypeCommands
* entry
= new wxMimeTypeCommands
;
785 wxString mimetype
, mime_desc
, strIcon
;
787 int nIndex
= file
.pIndexOf( wxT("MimeType=") );
788 if (nIndex
== wxNOT_FOUND
)
790 // construct mimetype from the directory name and the basename of the
791 // file (it always has .kdelnk extension)
792 mimetype
<< subdir
<< wxT('/') << filename
.BeforeLast( wxT('.') );
795 mimetype
= file
.GetCmd(nIndex
);
797 // first find the description string: it is the value in either "Comment="
798 // line or "Comment[<locale_name>]=" one
799 nIndex
= wxNOT_FOUND
;
804 wxLocale
*locale
= wxGetLocale();
807 // try "Comment[locale name]" first
808 comment
<< wxT("Comment[") + locale
->GetName() + wxT("]=");
809 nIndex
= file
.pIndexOf(comment
);
813 if ( nIndex
== wxNOT_FOUND
)
815 comment
= wxT("Comment=");
816 nIndex
= file
.pIndexOf(comment
);
819 if ( nIndex
!= wxNOT_FOUND
)
820 mime_desc
= file
.GetCmd(nIndex
);
821 //else: no description
823 // next find the extensions
824 wxString mime_extension
;
826 nIndex
= file
.pIndexOf(wxT("Patterns="));
827 if ( nIndex
!= wxNOT_FOUND
)
829 wxString exts
= file
.GetCmd(nIndex
);
831 wxStringTokenizer
tokenizer(exts
, wxT(";"));
832 while ( tokenizer
.HasMoreTokens() )
834 wxString e
= tokenizer
.GetNextToken();
836 // don't support too difficult patterns
837 if ( e
.Left(2) != wxT("*.") )
840 if ( !mime_extension
.empty() )
842 // separate from the previous ext
843 mime_extension
<< wxT(' ');
846 mime_extension
<< e
.Mid(2);
850 sExts
.Add(mime_extension
);
852 // ok, now we can take care of icon:
854 nIndex
= file
.pIndexOf(wxT("Icon="));
855 if ( nIndex
!= wxNOT_FOUND
)
857 strIcon
= file
.GetCmd(nIndex
);
859 wxLogTrace(TRACE_MIME
, wxT(" icon %s"), strIcon
.c_str());
861 // it could be the real path, but more often a short name
862 if (!wxFileExists(strIcon
))
864 // icon is just the short name
865 if ( !strIcon
.empty() )
867 // we must check if the file exists because it may be stored
868 // in many locations, at least ~/.kde and $KDEDIR
869 size_t nDir
, nDirs
= icondirs
.GetCount();
870 for ( nDir
= 0; nDir
< nDirs
; nDir
++ )
872 wxFileName
fnameIcon( strIcon
);
873 wxFileName
fname( icondirs
[nDir
], fnameIcon
.GetName() );
874 fname
.SetExt( wxT("png") );
875 if (fname
.FileExists())
877 strIcon
= fname
.GetFullPath();
878 wxLogTrace(TRACE_MIME
, wxT(" iconfile %s"), strIcon
.c_str());
886 // now look for lines which know about the application
887 // exec= or DefaultApp=
889 nIndex
= file
.pIndexOf(wxT("DefaultApp"));
891 if ( nIndex
== wxNOT_FOUND
)
894 nIndex
= file
.pIndexOf(wxT("Exec"));
897 if ( nIndex
!= wxNOT_FOUND
)
899 // we expect %f; others including %F and %U and %u are possible
900 wxString sTmp
= file
.GetCmd(nIndex
);
901 if (0 == sTmp
.Replace( wxT("%f"), wxT("%s") ))
902 sTmp
= sTmp
+ wxT(" %s");
903 entry
->AddOrReplaceVerb(wxString(wxT("open")), sTmp
);
906 AddToMimeData(mimetype
, strIcon
, entry
, sExts
, mime_desc
);
909 void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString
& dirbase
,
910 const wxString
& subdir
,
911 const wxArrayString
& icondirs
)
913 wxString dirname
= dirbase
;
916 if ( !dir
.IsOpened() )
919 wxLogTrace(TRACE_MIME
, wxT("--- Loading from KDE directory %s ---"),
925 bool cont
= dir
.GetFirst(&filename
, wxT("*.kdelnk"), wxDIR_FILES
);
928 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
930 cont
= dir
.GetNext(&filename
);
933 // new standard for Gnome and KDE
934 cont
= dir
.GetFirst(&filename
, wxT("*.desktop"), wxDIR_FILES
);
937 LoadKDELinksForMimeSubtype(dirname
, subdir
, filename
, icondirs
);
939 cont
= dir
.GetNext(&filename
);
943 void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString
& dirbase
,
944 const wxArrayString
& icondirs
)
946 wxASSERT_MSG( !dirbase
.empty() && !wxEndsWithPathSeparator(dirbase
),
947 wxT("base directory shouldn't end with a slash") );
949 wxString dirname
= dirbase
;
950 dirname
<< wxT("/mimelnk");
952 if ( !wxDir::Exists(dirname
) )
956 if ( !dir
.IsOpened() )
959 // we will concatenate it with dir name to get the full path below
963 bool cont
= dir
.GetFirst(&subdir
, wxEmptyString
, wxDIR_DIRS
);
966 LoadKDELinksForMimeType(dirname
, subdir
, icondirs
);
968 cont
= dir
.GetNext(&subdir
);
972 void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString
& sExtraDir
)
975 wxArrayString icondirs
;
977 // FIXME: This code is heavily broken. There are three bugs in it:
978 // 1) it uses only KDEDIR, which is deprecated, instead of using
979 // list of paths from KDEDIRS and using KDEDIR only if KDEDIRS
981 // 2) it doesn't look into ~/.kde/share/config/kdeglobals where
982 // user's settings are stored and thus *ignores* user's settings
983 // instead of respecting them
984 // 3) it "tries to guess KDEDIR" and "tries a few likely theme
985 // names", both of which is completely arbitrary; instead, the
986 // code should give up if KDEDIR(S) is not set and/or the icon
987 // theme cannot be determined, because it means that the user is
988 // not using KDE (and thus is not interested in KDE icons anyway)
990 // the variable $KDEDIR is set when KDE is running
991 wxString kdedir
= wxGetenv( wxT("KDEDIR") );
995 // $(KDEDIR)/share/config/kdeglobals holds info
996 // the current icons theme
997 wxFileName
configFile( kdedir
, wxEmptyString
);
998 configFile
.AppendDir( wxT("share") );
999 configFile
.AppendDir( wxT("config") );
1000 configFile
.SetName( wxT("kdeglobals") );
1003 if (configFile
.FileExists() && config
.Open(configFile
.GetFullPath()))
1005 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1006 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1007 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1008 configFile
.AppendDir( wxT("icons") );
1011 wxString
theme(wxT("default.kde"));
1012 size_t cnt
= config
.GetLineCount();
1013 for (size_t i
= 0; i
< cnt
; i
++)
1015 if (config
[i
].StartsWith(wxT("Theme="), &theme
/*rest*/))
1019 configFile
.AppendDir(theme
);
1023 // $(KDEDIR)/share/config -> $(KDEDIR)/share
1024 configFile
.RemoveDir( configFile
.GetDirCount() - 1 );
1026 // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
1027 configFile
.AppendDir( wxT("icons") );
1029 // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
1030 configFile
.AppendDir( wxT("default.kde") );
1033 configFile
.SetName( wxEmptyString
);
1034 configFile
.AppendDir( wxT("32x32") );
1035 configFile
.AppendDir( wxT("mimetypes") );
1037 // Just try a few likely icons theme names
1039 int pos
= configFile
.GetDirCount() - 3;
1041 if (!wxDir::Exists(configFile
.GetPath()))
1043 configFile
.RemoveDir( pos
);
1044 configFile
.InsertDir( pos
, wxT("default.kde") );
1047 if (!wxDir::Exists(configFile
.GetPath()))
1049 configFile
.RemoveDir( pos
);
1050 configFile
.InsertDir( pos
, wxT("default") );
1053 if (!wxDir::Exists(configFile
.GetPath()))
1055 configFile
.RemoveDir( pos
);
1056 configFile
.InsertDir( pos
, wxT("crystalsvg") );
1059 if (!wxDir::Exists(configFile
.GetPath()))
1061 configFile
.RemoveDir( pos
);
1062 configFile
.InsertDir( pos
, wxT("crystal") );
1065 if (wxDir::Exists(configFile
.GetPath()))
1066 icondirs
.Add( configFile
.GetFullPath() );
1069 // settings in ~/.kde have maximal priority
1070 dirs
.Add(wxGetHomeDir() + wxT("/.kde/share"));
1071 icondirs
.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
1075 dirs
.Add( wxString(kdedir
) + wxT("/share") );
1076 icondirs
.Add( wxString(kdedir
) + wxT("/share/icons/") );
1080 // try to guess KDEDIR
1081 dirs
.Add(wxT("/usr/share"));
1082 dirs
.Add(wxT("/opt/kde/share"));
1083 icondirs
.Add(wxT("/usr/share/icons/"));
1084 icondirs
.Add(wxT("/usr/X11R6/share/icons/")); // Debian/Corel linux
1085 icondirs
.Add(wxT("/opt/kde/share/icons/"));
1088 if (!sExtraDir
.empty())
1089 dirs
.Add(sExtraDir
);
1090 icondirs
.Add(sExtraDir
+ wxT("/icons"));
1092 size_t nDirs
= dirs
.GetCount();
1093 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1095 LoadKDELinkFilesFromDir(dirs
[nDir
], icondirs
);
1099 // ----------------------------------------------------------------------------
1100 // wxFileTypeImpl (Unix)
1101 // ----------------------------------------------------------------------------
1103 wxString
wxFileTypeImpl::GetExpandedCommand(const wxString
& verb
, const wxFileType::MessageParameters
& params
) const
1107 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1109 sTmp
= m_manager
->GetCommand( verb
, m_index
[i
] );
1113 return wxFileType::ExpandCommand(sTmp
, params
);
1116 bool wxFileTypeImpl::GetIcon(wxIconLocation
*iconLoc
) const
1120 while ( (i
< m_index
.GetCount() ) && sTmp
.empty() )
1122 sTmp
= m_manager
->m_aIcons
[m_index
[i
]];
1131 iconLoc
->SetFileName(sTmp
);
1137 bool wxFileTypeImpl::GetMimeTypes(wxArrayString
& mimeTypes
) const
1140 for (size_t i
= 0; i
< m_index
.GetCount(); i
++)
1141 mimeTypes
.Add(m_manager
->m_aTypes
[m_index
[i
]]);
1146 size_t wxFileTypeImpl::GetAllCommands(wxArrayString
*verbs
,
1147 wxArrayString
*commands
,
1148 const wxFileType::MessageParameters
& params
) const
1150 wxString vrb
, cmd
, sTmp
;
1152 wxMimeTypeCommands
* sPairs
;
1154 // verbs and commands have been cleared already in mimecmn.cpp...
1155 // if we find no entries in the exact match, try the inexact match
1156 for (size_t n
= 0; ((count
== 0) && (n
< m_index
.GetCount())); n
++)
1158 // list of verb = command pairs for this mimetype
1159 sPairs
= m_manager
->m_aEntries
[m_index
[n
]];
1161 for ( i
= 0; i
< sPairs
->GetCount(); i
++ )
1163 vrb
= sPairs
->GetVerb(i
);
1164 // some gnome entries have "." inside
1165 vrb
= vrb
.AfterLast(wxT('.'));
1166 cmd
= sPairs
->GetCmd(i
);
1169 cmd
= wxFileType::ExpandCommand(cmd
, params
);
1171 if ( vrb
.IsSameAs(wxT("open")))
1174 verbs
->Insert(vrb
, 0u);
1176 commands
->Insert(cmd
, 0u);
1192 bool wxFileTypeImpl::GetExtensions(wxArrayString
& extensions
)
1194 wxString strExtensions
= m_manager
->GetExtension(m_index
[0]);
1197 // one extension in the space or comma-delimited list
1199 for ( const wxChar
*p
= strExtensions
; /* nothing */; p
++ )
1201 if ( *p
== wxT(' ') || *p
== wxT(',') || *p
== wxT('\0') )
1203 if ( !strExt
.empty() )
1205 extensions
.Add(strExt
);
1208 //else: repeated spaces
1209 // (shouldn't happen, but it's not that important if it does happen)
1211 if ( *p
== wxT('\0') )
1214 else if ( *p
== wxT('.') )
1216 // remove the dot from extension (but only if it's the first char)
1217 if ( !strExt
.empty() )
1221 //else: no, don't append it
1232 // set an arbitrary command:
1233 // could adjust the code to ask confirmation if it already exists and
1234 // overwriteprompt is true, but this is currently ignored as *Associate* has
1235 // no overwrite prompt
1237 wxFileTypeImpl::SetCommand(const wxString
& cmd
,
1238 const wxString
& verb
,
1239 bool WXUNUSED(overwriteprompt
))
1241 wxArrayString strExtensions
;
1242 wxString strDesc
, strIcon
;
1244 wxArrayString strTypes
;
1245 GetMimeTypes(strTypes
);
1246 if ( strTypes
.IsEmpty() )
1249 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1250 entry
->Add(verb
+ wxT("=") + cmd
+ wxT(" %s "));
1253 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1255 if (!m_manager
->DoAssociation(strTypes
[i
], strIcon
, entry
, strExtensions
, strDesc
))
1262 // ignore index on the grouds 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 for ( size_t i
= 0; i
< strTypes
.GetCount(); i
++ )
1280 if ( !m_manager
->DoAssociation
1296 // ----------------------------------------------------------------------------
1297 // wxMimeTypesManagerImpl (Unix)
1298 // ----------------------------------------------------------------------------
1300 wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
1302 m_initialized
= false;
1303 m_mailcapStylesInited
= 0;
1306 void wxMimeTypesManagerImpl::InitIfNeeded()
1308 if ( !m_initialized
)
1310 // set the flag first to prevent recursion
1311 m_initialized
= true;
1313 wxString wm
= wxGetenv( wxT("WINDOWMANAGER") );
1315 if (wm
.Find( wxT("kde") ) != wxNOT_FOUND
)
1316 Initialize( wxMAILCAP_KDE
);
1317 else if (wm
.Find( wxT("gnome") ) != wxNOT_FOUND
)
1318 Initialize( wxMAILCAP_GNOME
);
1324 // read system and user mailcaps and other files
1325 void wxMimeTypesManagerImpl::Initialize(int mailcapStyles
,
1326 const wxString
& sExtraDir
)
1328 // read mimecap amd mime.types
1329 if ( (mailcapStyles
& wxMAILCAP_NETSCAPE
) ||
1330 (mailcapStyles
& wxMAILCAP_STANDARD
) )
1331 GetMimeInfo(sExtraDir
);
1333 // read GNOME tables
1334 if (mailcapStyles
& wxMAILCAP_GNOME
)
1335 GetGnomeMimeInfo(sExtraDir
);
1338 if (mailcapStyles
& wxMAILCAP_KDE
)
1339 GetKDEMimeInfo(sExtraDir
);
1341 m_mailcapStylesInited
|= mailcapStyles
;
1344 // clear data so you can read another group of WM files
1345 void wxMimeTypesManagerImpl::ClearData()
1349 m_aExtensions
.Clear();
1350 m_aDescriptions
.Clear();
1352 WX_CLEAR_ARRAY(m_aEntries
);
1355 m_mailcapStylesInited
= 0;
1358 wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
1363 void wxMimeTypesManagerImpl::GetMimeInfo(const wxString
& sExtraDir
)
1365 // read this for netscape or Metamail formats
1367 // directories where we look for mailcap and mime.types by default
1368 // used by netscape and pine and other mailers, using 2 different formats!
1370 // (taken from metamail(1) sources)
1372 // although RFC 1524 specifies the search path of
1373 // /etc/:/usr/etc:/usr/local/etc only, it doesn't hurt to search in more
1374 // places - OTOH, the RFC also says that this path can be changed with
1375 // MAILCAPS environment variable (containing the colon separated full
1376 // filenames to try) which is not done yet (TODO?)
1378 wxString strHome
= wxGetenv(wxT("HOME"));
1381 dirs
.Add( strHome
+ wxT("/.") );
1382 dirs
.Add( wxT("/etc/") );
1383 dirs
.Add( wxT("/usr/etc/") );
1384 dirs
.Add( wxT("/usr/local/etc/") );
1385 dirs
.Add( wxT("/etc/mail/") );
1386 dirs
.Add( wxT("/usr/public/lib/") );
1387 if (!sExtraDir
.empty())
1388 dirs
.Add( sExtraDir
+ wxT("/") );
1390 size_t nDirs
= dirs
.GetCount();
1391 for ( size_t nDir
= 0; nDir
< nDirs
; nDir
++ )
1393 wxString file
= dirs
[nDir
] + wxT("mailcap");
1394 if ( wxFile::Exists(file
) )
1399 file
= dirs
[nDir
] + wxT("mime.types");
1400 if ( wxFile::Exists(file
) )
1402 ReadMimeTypes(file
);
1407 bool wxMimeTypesManagerImpl::WriteToMimeTypes(int index
, bool delete_index
)
1409 // check we have the right manager
1410 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1414 wxString strHome
= wxGetenv(wxT("HOME"));
1416 // and now the users mailcap
1417 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1419 wxMimeTextFile file
;
1420 if ( wxFile::Exists(strUserMailcap
) )
1422 bTemp
= file
.Open(strUserMailcap
);
1429 bTemp
= file
.Create(strUserMailcap
);
1435 // test for netscape's header and return false if its found
1436 nIndex
= file
.pIndexOf(wxT("#--Netscape"));
1437 if (nIndex
!= wxNOT_FOUND
)
1439 wxASSERT_MSG(false,wxT("Error in .mime.types \nTrying to mix Netscape and Metamail formats\nFile not modiifed"));
1443 // write it in alternative format
1444 // get rid of unwanted entries
1445 wxString strType
= m_aTypes
[index
];
1446 nIndex
= file
.pIndexOf(strType
);
1448 // get rid of all the unwanted entries...
1449 if (nIndex
!= wxNOT_FOUND
)
1450 file
.CommentLine(nIndex
);
1454 // add the new entries in
1455 wxString sTmp
= strType
.Append( wxT(' '), 40 - strType
.Len() );
1456 sTmp
= sTmp
+ m_aExtensions
[index
];
1460 bTemp
= file
.Write();
1467 bool wxMimeTypesManagerImpl::WriteToNSMimeTypes(int index
, bool delete_index
)
1469 //check we have the right managers
1470 if (! ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) )
1474 wxString strHome
= wxGetenv(wxT("HOME"));
1476 // and now the users mailcap
1477 wxString strUserMailcap
= strHome
+ wxT("/.mime.types");
1479 wxMimeTextFile file
;
1480 if ( wxFile::Exists(strUserMailcap
) )
1482 bTemp
= file
.Open(strUserMailcap
);
1489 bTemp
= file
.Create(strUserMailcap
);
1494 // write it in the format that Netscape uses
1496 // test for netscape's header and insert if required...
1497 // this is a comment so use true
1498 nIndex
= file
.pIndexOf(wxT("#--Netscape"), true);
1499 if (nIndex
== wxNOT_FOUND
)
1501 // either empty file or metamail format
1502 // at present we can't cope with mixed formats, so exit to preseve
1503 // metamail entreies
1504 if (file
.GetLineCount() > 0)
1506 wxASSERT_MSG(false, wxT(".mime.types File not in Netscape format\nNo entries written to\n.mime.types or to .mailcap"));
1510 file
.InsertLine(wxT( "#--Netscape Communications Corporation MIME Information" ), 0);
1514 wxString strType
= wxT("type=") + m_aTypes
[index
];
1515 nIndex
= file
.pIndexOf(strType
);
1517 // get rid of all the unwanted entries...
1518 if (nIndex
!= wxNOT_FOUND
)
1520 wxString sOld
= file
[nIndex
];
1521 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1523 file
.CommentLine(nIndex
);
1524 sOld
= file
[nIndex
];
1526 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mime.types line '%d %s' ---"), nIndex
, sOld
.c_str());
1531 if (nIndex
< (int) file
.GetLineCount())
1532 file
.CommentLine(nIndex
);
1535 nIndex
= (int) file
.GetLineCount();
1537 wxString sTmp
= strType
+ wxT(" \\");
1539 file
.InsertLine(sTmp
, nIndex
);
1541 if ( ! m_aDescriptions
.Item(index
).empty() )
1543 sTmp
= wxT("desc=\"") + m_aDescriptions
[index
]+ wxT("\" \\"); //.trim ??
1547 file
.InsertLine(sTmp
, nIndex
);
1551 wxString sExts
= m_aExtensions
.Item(index
);
1552 sTmp
= wxT("exts=\"") + sExts
.Trim(false).Trim() + wxT("\"");
1556 file
.InsertLine(sTmp
, nIndex
);
1559 bTemp
= file
.Write();
1566 bool wxMimeTypesManagerImpl::WriteToMailCap(int index
, bool delete_index
)
1568 //check we have the right managers
1569 if ( !( ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
) ||
1570 ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) ) )
1574 wxString strHome
= wxGetenv(wxT("HOME"));
1576 // and now the users mailcap
1577 wxString strUserMailcap
= strHome
+ wxT("/.mailcap");
1579 wxMimeTextFile file
;
1580 if ( wxFile::Exists(strUserMailcap
) )
1582 bTemp
= file
.Open(strUserMailcap
);
1589 bTemp
= file
.Create(strUserMailcap
);
1594 // now got a file we can write to ....
1595 wxMimeTypeCommands
* entries
= m_aEntries
[index
];
1597 wxString sCmd
= entries
->GetCommandForVerb(wxT("open"), &iOpen
);
1600 sTmp
= m_aTypes
[index
];
1602 int nIndex
= file
.pIndexOf(sTmp
);
1604 // get rid of all the unwanted entries...
1605 if (nIndex
== wxNOT_FOUND
)
1607 nIndex
= (int) file
.GetLineCount();
1611 sOld
= file
[nIndex
];
1612 wxLogTrace(TRACE_MIME
, wxT("--- Deleting from mailcap line '%d' ---"), nIndex
);
1614 while ( (sOld
.Contains(wxT("\\"))) && (nIndex
< (int) file
.GetLineCount()) )
1616 file
.CommentLine(nIndex
);
1617 if (nIndex
< (int) file
.GetLineCount())
1618 sOld
= sOld
+ file
[nIndex
];
1622 file
.GetLineCount()) file
.CommentLine(nIndex
);
1625 sTmp
= sTmp
+ wxT(";") + sCmd
; //includes wxT(" %s ");
1627 // write it in the format that Netscape uses (default)
1628 if (! ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
) )
1631 file
.InsertLine(sTmp
, nIndex
);
1636 // write extended format
1638 // TODO - FIX this code:
1640 // sOld holds all the entries, but our data store only has some
1641 // eg test= is not stored
1643 // so far we have written the mimetype and command out
1644 wxStringTokenizer
sT(sOld
, wxT(";\\"));
1645 if (sT
.CountTokens() > 2)
1647 // first one mimetype; second one command, rest unknown...
1649 s
= sT
.GetNextToken();
1650 s
= sT
.GetNextToken();
1653 s
= sT
.GetNextToken();
1654 while ( ! s
.empty() )
1656 bool bKnownToken
= false;
1657 if (s
.Contains(wxT("description=")))
1659 if (s
.Contains(wxT("x11-bitmap=")))
1663 for (i
=0; i
< entries
->GetCount(); i
++)
1665 if (s
.Contains(entries
->GetVerb(i
)))
1671 sTmp
= sTmp
+ wxT("; \\");
1672 file
.InsertLine(sTmp
, nIndex
);
1676 s
= sT
.GetNextToken();
1680 if (! m_aDescriptions
[index
].empty() )
1682 sTmp
= sTmp
+ wxT("; \\");
1683 file
.InsertLine(sTmp
, nIndex
);
1685 sTmp
= wxT(" description=\"") + m_aDescriptions
[index
] + wxT("\"");
1688 if (! m_aIcons
[index
].empty() )
1690 sTmp
= sTmp
+ wxT("; \\");
1691 file
.InsertLine(sTmp
, nIndex
);
1693 sTmp
= wxT(" x11-bitmap=\"") + m_aIcons
[index
] + wxT("\"");
1696 if ( entries
->GetCount() > 1 )
1699 for (i
=0; i
< entries
->GetCount(); i
++)
1702 sTmp
= sTmp
+ wxT("; \\");
1703 file
.InsertLine(sTmp
, nIndex
);
1705 sTmp
= wxT(" ") + entries
->GetVerbCmd(i
);
1709 file
.InsertLine(sTmp
, nIndex
);
1713 bTemp
= file
.Write();
1720 wxFileType
* wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo
& ftInfo
)
1724 wxString strType
= ftInfo
.GetMimeType();
1725 wxString strDesc
= ftInfo
.GetDescription();
1726 wxString strIcon
= ftInfo
.GetIconFile();
1728 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands();
1730 if ( ! ftInfo
.GetOpenCommand().empty())
1731 entry
->Add(wxT("open=") + ftInfo
.GetOpenCommand() + wxT(" %s "));
1732 if ( ! ftInfo
.GetPrintCommand().empty())
1733 entry
->Add(wxT("print=") + ftInfo
.GetPrintCommand() + wxT(" %s "));
1735 // now find where these extensions are in the data store and remove them
1736 wxArrayString sA_Exts
= ftInfo
.GetExtensions();
1737 wxString sExt
, sExtStore
;
1739 for (i
=0; i
< sA_Exts
.GetCount(); i
++)
1741 sExt
= sA_Exts
.Item(i
);
1743 // clean up to just a space before and after
1744 sExt
.Trim().Trim(false);
1745 sExt
= wxT(' ') + sExt
+ wxT(' ');
1746 for (nIndex
= 0; nIndex
< m_aExtensions
.GetCount(); nIndex
++)
1748 sExtStore
= m_aExtensions
.Item(nIndex
);
1749 if (sExtStore
.Replace(sExt
, wxT(" ") ) > 0)
1750 m_aExtensions
.Item(nIndex
) = sExtStore
;
1754 if ( !DoAssociation(strType
, strIcon
, entry
, sA_Exts
, strDesc
) )
1757 return GetFileTypeFromMimeType(strType
);
1760 bool wxMimeTypesManagerImpl::DoAssociation(const wxString
& strType
,
1761 const wxString
& strIcon
,
1762 wxMimeTypeCommands
*entry
,
1763 const wxArrayString
& strExtensions
,
1764 const wxString
& strDesc
)
1766 int nIndex
= AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
1768 if ( nIndex
== wxNOT_FOUND
)
1771 return WriteMimeInfo(nIndex
, false);
1774 bool wxMimeTypesManagerImpl::WriteMimeInfo(int nIndex
, bool delete_mime
)
1778 if ( m_mailcapStylesInited
& wxMAILCAP_STANDARD
)
1780 // write in metamail format;
1781 if (WriteToMimeTypes(nIndex
, delete_mime
) )
1782 if ( WriteToMailCap(nIndex
, delete_mime
) )
1786 if ( m_mailcapStylesInited
& wxMAILCAP_NETSCAPE
)
1788 // write in netsacpe format;
1789 if (WriteToNSMimeTypes(nIndex
, delete_mime
) )
1790 if ( WriteToMailCap(nIndex
, delete_mime
) )
1794 // Don't write GNOME files here as this is not
1795 // allowed and simply doesn't work
1797 if (m_mailcapStylesInited
& wxMAILCAP_KDE
)
1799 // write in KDE format;
1800 if (WriteKDEMimeFile(nIndex
, delete_mime
) )
1807 int wxMimeTypesManagerImpl::AddToMimeData(const wxString
& strType
,
1808 const wxString
& strIcon
,
1809 wxMimeTypeCommands
*entry
,
1810 const wxArrayString
& strExtensions
,
1811 const wxString
& strDesc
,
1812 bool replaceExisting
)
1816 // ensure mimetype is always lower case
1817 wxString mimeType
= strType
.Lower();
1819 // is this a known MIME type?
1820 int nIndex
= m_aTypes
.Index(mimeType
);
1821 if ( nIndex
== wxNOT_FOUND
)
1824 m_aTypes
.Add(mimeType
);
1825 m_aIcons
.Add(strIcon
);
1826 m_aEntries
.Add(entry
? entry
: new wxMimeTypeCommands
);
1828 // change nIndex so we can use it below to add the extensions
1829 m_aExtensions
.Add(wxEmptyString
);
1830 nIndex
= m_aExtensions
.size() - 1;
1832 m_aDescriptions
.Add(strDesc
);
1834 else // yes, we already have it
1836 if ( replaceExisting
)
1838 // if new description change it
1839 if ( !strDesc
.empty())
1840 m_aDescriptions
[nIndex
] = strDesc
;
1842 // if new icon change it
1843 if ( !strIcon
.empty())
1844 m_aIcons
[nIndex
] = strIcon
;
1848 delete m_aEntries
[nIndex
];
1849 m_aEntries
[nIndex
] = entry
;
1852 else // add data we don't already have ...
1854 // if new description add only if none
1855 if ( m_aDescriptions
[nIndex
].empty() )
1856 m_aDescriptions
[nIndex
] = strDesc
;
1858 // if new icon and no existing icon
1859 if ( m_aIcons
[nIndex
].empty() )
1860 m_aIcons
[nIndex
] = strIcon
;
1862 // add any new entries...
1865 wxMimeTypeCommands
*entryOld
= m_aEntries
[nIndex
];
1867 size_t count
= entry
->GetCount();
1868 for ( size_t i
= 0; i
< count
; i
++ )
1870 const wxString
& verb
= entry
->GetVerb(i
);
1871 if ( !entryOld
->HasVerb(verb
) )
1873 entryOld
->AddOrReplaceVerb(verb
, entry
->GetCmd(i
));
1877 // as we don't store it anywhere, it won't be deleted later as
1878 // usual -- do it immediately instead
1884 // always add the extensions to this mimetype
1885 wxString
& exts
= m_aExtensions
[nIndex
];
1887 // add all extensions we don't have yet
1888 size_t count
= strExtensions
.GetCount();
1889 for ( size_t i
= 0; i
< count
; i
++ )
1891 wxString ext
= strExtensions
[i
] + wxT(' ');
1893 if ( exts
.Find(ext
) == wxNOT_FOUND
)
1899 // check data integrity
1900 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
1901 m_aTypes
.Count() == m_aExtensions
.Count() &&
1902 m_aTypes
.Count() == m_aIcons
.Count() &&
1903 m_aTypes
.Count() == m_aDescriptions
.Count() );
1908 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString
& ext
)
1915 size_t count
= m_aExtensions
.GetCount();
1916 for ( size_t n
= 0; n
< count
; n
++ )
1918 wxStringTokenizer
tk(m_aExtensions
[n
], wxT(' '));
1920 while ( tk
.HasMoreTokens() )
1922 // consider extensions as not being case-sensitive
1923 if ( tk
.GetNextToken().IsSameAs(ext
, false /* no case */) )
1926 wxFileType
*fileType
= new wxFileType
;
1927 fileType
->m_impl
->Init(this, n
);
1937 wxFileType
* wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString
& mimeType
)
1941 wxFileType
* fileType
= NULL
;
1942 // mime types are not case-sensitive
1943 wxString
mimetype(mimeType
);
1944 mimetype
.MakeLower();
1946 // first look for an exact match
1947 int index
= m_aTypes
.Index(mimetype
);
1948 if ( index
!= wxNOT_FOUND
)
1950 fileType
= new wxFileType
;
1951 fileType
->m_impl
->Init(this, index
);
1954 // then try to find "text/*" as match for "text/plain" (for example)
1955 // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
1956 // the whole string - ok.
1958 index
= wxNOT_FOUND
;
1959 wxString strCategory
= mimetype
.BeforeFirst(wxT('/'));
1961 size_t nCount
= m_aTypes
.Count();
1962 for ( size_t n
= 0; n
< nCount
; n
++ )
1964 if ( (m_aTypes
[n
].BeforeFirst(wxT('/')) == strCategory
) &&
1965 m_aTypes
[n
].AfterFirst(wxT('/')) == wxT("*") )
1972 if ( index
!= wxNOT_FOUND
)
1974 // don't throw away fileType that was already found
1976 fileType
= new wxFileType
;
1977 fileType
->m_impl
->Init(this, index
);
1983 wxString
wxMimeTypesManagerImpl::GetCommand(const wxString
& verb
, size_t nIndex
) const
1985 wxString command
, testcmd
, sV
, sTmp
;
1986 sV
= verb
+ wxT("=");
1988 // list of verb = command pairs for this mimetype
1989 wxMimeTypeCommands
* sPairs
= m_aEntries
[nIndex
];
1992 for ( i
= 0; i
< sPairs
->GetCount (); i
++ )
1994 sTmp
= sPairs
->GetVerbCmd (i
);
1995 if ( sTmp
.Contains(sV
) )
1996 command
= sTmp
.AfterFirst(wxT('='));
2002 void wxMimeTypesManagerImpl::AddFallback(const wxFileTypeInfo
& filetype
)
2006 wxString extensions
;
2007 const wxArrayString
& exts
= filetype
.GetExtensions();
2008 size_t nExts
= exts
.GetCount();
2009 for ( size_t nExt
= 0; nExt
< nExts
; nExt
++ )
2012 extensions
+= wxT(' ');
2014 extensions
+= exts
[nExt
];
2017 AddMimeTypeInfo(filetype
.GetMimeType(),
2019 filetype
.GetDescription());
2021 AddMailcapInfo(filetype
.GetMimeType(),
2022 filetype
.GetOpenCommand(),
2023 filetype
.GetPrintCommand(),
2025 filetype
.GetDescription());
2028 void wxMimeTypesManagerImpl::AddMimeTypeInfo(const wxString
& strMimeType
,
2029 const wxString
& strExtensions
,
2030 const wxString
& strDesc
)
2032 // reading mailcap may find image/* , while
2033 // reading mime.types finds image/gif and no match is made
2034 // this means all the get functions don't work fix this
2036 wxString sTmp
= strExtensions
;
2038 wxArrayString sExts
;
2039 sTmp
.Trim().Trim(false);
2041 while (!sTmp
.empty())
2043 sExts
.Add(sTmp
.AfterLast(wxT(' ')));
2044 sTmp
= sTmp
.BeforeLast(wxT(' '));
2047 AddToMimeData(strMimeType
, strIcon
, NULL
, sExts
, strDesc
, true);
2050 void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString
& strType
,
2051 const wxString
& strOpenCmd
,
2052 const wxString
& strPrintCmd
,
2053 const wxString
& strTest
,
2054 const wxString
& strDesc
)
2058 wxMimeTypeCommands
*entry
= new wxMimeTypeCommands
;
2059 entry
->Add(wxT("open=") + strOpenCmd
);
2060 entry
->Add(wxT("print=") + strPrintCmd
);
2061 entry
->Add(wxT("test=") + strTest
);
2064 wxArrayString strExtensions
;
2066 AddToMimeData(strType
, strIcon
, entry
, strExtensions
, strDesc
, true);
2069 bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString
& strFileName
)
2071 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mime.types file '%s' ---"),
2072 strFileName
.c_str());
2074 wxTextFile
file(strFileName
);
2075 #if defined(__WXGTK20__) && wxUSE_UNICODE
2076 if ( !file
.Open(wxConvUTF8
) )
2082 // the information we extract
2083 wxString strMimeType
, strDesc
, strExtensions
;
2085 size_t nLineCount
= file
.GetLineCount();
2086 const wxChar
*pc
= NULL
;
2087 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2091 // now we're at the start of the line
2092 pc
= file
[nLine
].c_str();
2096 // we didn't finish with the previous line yet
2101 while ( wxIsspace(*pc
) )
2104 // comment or blank line?
2105 if ( *pc
== wxT('#') || !*pc
)
2107 // skip the whole line
2112 // detect file format
2113 const wxChar
*pEqualSign
= wxStrchr(pc
, wxT('='));
2114 if ( pEqualSign
== NULL
)
2119 // first field is mime type
2120 for ( strMimeType
.Empty(); !wxIsspace(*pc
) && *pc
!= wxT('\0'); pc
++ )
2126 while ( wxIsspace(*pc
) )
2129 // take all the rest of the string
2132 // no description...
2140 // the string on the left of '=' is the field name
2141 wxString
strLHS(pc
, pEqualSign
- pc
);
2144 for ( pc
= pEqualSign
+ 1; wxIsspace(*pc
); pc
++ )
2148 if ( *pc
== wxT('"') )
2150 // the string is quoted and ends at the matching quote
2151 pEnd
= wxStrchr(++pc
, wxT('"'));
2154 wxLogWarning(wxT("Mime.types file %s, line %lu: unterminated quoted string."),
2155 strFileName
.c_str(), nLine
+ 1L);
2160 // unquoted string ends at the first space or at the end of
2162 for ( pEnd
= pc
; *pEnd
&& !wxIsspace(*pEnd
); pEnd
++ )
2166 // now we have the RHS (field value)
2167 wxString
strRHS(pc
, pEnd
- pc
);
2169 // check what follows this entry
2170 if ( *pEnd
== wxT('"') )
2176 for ( pc
= pEnd
; wxIsspace(*pc
); pc
++ )
2179 // if there is something left, it may be either a '\\' to continue
2180 // the line or the next field of the same entry
2181 bool entryEnded
= *pc
== wxT('\0');
2182 bool nextFieldOnSameLine
= false;
2185 nextFieldOnSameLine
= ((*pc
!= wxT('\\')) || (pc
[1] != wxT('\0')));
2188 // now see what we got
2189 if ( strLHS
== wxT("type") )
2191 strMimeType
= strRHS
;
2193 else if ( strLHS
.StartsWith(wxT("desc")) )
2197 else if ( strLHS
== wxT("exts") )
2199 strExtensions
= strRHS
;
2201 else if ( strLHS
== wxT("icon") )
2203 // this one is simply ignored: it usually refers to Netscape
2204 // built in icons which are useless for us anyhow
2206 else if ( !strLHS
.StartsWith(wxT("x-")) )
2208 // we suppose that all fields starting with "X-" are
2209 // unregistered extensions according to the standard practice,
2210 // but it may be worth telling the user about other junk in
2211 // his mime.types file
2212 wxLogWarning(wxT("Unknown field in file %s, line %lu: '%s'."),
2213 strFileName
.c_str(), nLine
+ 1L, strLHS
.c_str());
2218 if ( !nextFieldOnSameLine
)
2220 //else: don't reset it
2222 // as we don't reset strMimeType, the next field in this entry
2223 // will be interpreted correctly.
2229 // depending on the format (Mosaic or Netscape) either space or comma
2230 // is used to separate the extensions
2231 strExtensions
.Replace(wxT(","), wxT(" "));
2233 // also deal with the leading dot
2234 if ( !strExtensions
.empty() && strExtensions
[0u] == wxT('.') )
2236 strExtensions
.erase(0, 1);
2239 wxLogTrace(TRACE_MIME
, wxT("mime.types: '%s' => '%s' (%s)"),
2240 strExtensions
.c_str(),
2241 strMimeType
.c_str(),
2244 AddMimeTypeInfo(strMimeType
, strExtensions
, strDesc
);
2246 // finished with this line
2253 // ----------------------------------------------------------------------------
2254 // UNIX mailcap files parsing
2255 // ----------------------------------------------------------------------------
2257 // the data for a single MIME type
2258 struct MailcapLineData
2267 wxArrayString verbs
,
2275 MailcapLineData() { testfailed
= needsterminal
= copiousoutput
= false; }
2278 // process a non-standard (i.e. not the first or second one) mailcap field
2280 wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData
& data
,
2281 const wxString
& curField
)
2283 if ( curField
.empty() )
2289 // is this something of the form foo=bar?
2290 const wxChar
*pEq
= wxStrchr(curField
, wxT('='));
2293 // split "LHS = RHS" in 2
2294 wxString lhs
= curField
.BeforeFirst(wxT('=')),
2295 rhs
= curField
.AfterFirst(wxT('='));
2297 lhs
.Trim(true); // from right
2298 rhs
.Trim(false); // from left
2300 // it might be quoted
2301 if ( !rhs
.empty() && rhs
[0u] == wxT('"') && rhs
.Last() == wxT('"') )
2303 rhs
= rhs
.Mid(1, rhs
.length() - 2);
2306 // is it a command verb or something else?
2307 if ( lhs
== wxT("test") )
2309 if ( wxSystem(rhs
) == 0 )
2312 wxLogTrace(TRACE_MIME_TEST
,
2313 wxT("Test '%s' for mime type '%s' succeeded."),
2314 rhs
.c_str(), data
.type
.c_str());
2318 wxLogTrace(TRACE_MIME_TEST
,
2319 wxT("Test '%s' for mime type '%s' failed, skipping."),
2320 rhs
.c_str(), data
.type
.c_str());
2322 data
.testfailed
= true;
2325 else if ( lhs
== wxT("desc") )
2329 else if ( lhs
== wxT("x11-bitmap") )
2333 else if ( lhs
== wxT("notes") )
2337 else // not a (recognized) special case, must be a verb (e.g. "print")
2339 data
.verbs
.Add(lhs
);
2340 data
.commands
.Add(rhs
);
2343 else // '=' not found
2345 // so it must be a simple flag
2346 if ( curField
== wxT("needsterminal") )
2348 data
.needsterminal
= true;
2350 else if ( curField
== wxT("copiousoutput"))
2352 // copiousoutput impies that the viewer is a console program
2353 data
.needsterminal
=
2354 data
.copiousoutput
= true;
2356 else if ( !IsKnownUnimportantField(curField
) )
2365 bool wxMimeTypesManagerImpl::ReadMailcap(const wxString
& strFileName
,
2368 wxLogTrace(TRACE_MIME
, wxT("--- Parsing mailcap file '%s' ---"),
2369 strFileName
.c_str());
2371 wxTextFile
file(strFileName
);
2372 #if defined(__WXGTK20__) && wxUSE_UNICODE
2373 if ( !file
.Open(wxConvUTF8
) )
2379 // indices of MIME types (in m_aTypes) we already found in this file
2381 // (see the comments near the end of function for the reason we need this)
2382 wxArrayInt aIndicesSeenHere
;
2384 // accumulator for the current field
2386 curField
.reserve(1024);
2388 size_t nLineCount
= file
.GetLineCount();
2389 for ( size_t nLine
= 0; nLine
< nLineCount
; nLine
++ )
2391 // now we're at the start of the line
2392 const wxChar
*pc
= file
[nLine
].c_str();
2395 while ( wxIsspace(*pc
) )
2398 // comment or empty string?
2399 if ( *pc
== wxT('#') || *pc
== wxT('\0') )
2405 // what field are we currently in? The first 2 are fixed and there may
2406 // be an arbitrary number of other fields parsed by
2407 // ProcessOtherMailcapField()
2409 // the first field is the MIME type
2416 currentToken
= Field_Type
;
2418 // the flags and field values on the current line
2419 MailcapLineData data
;
2427 // interpret the next character literally (notice that
2428 // backslash can be used for line continuation)
2429 if ( *++pc
== wxT('\0') )
2431 // fetch the next line if there is one
2432 if ( nLine
== nLineCount
- 1 )
2434 // something is wrong, bail out
2437 wxLogDebug(wxT("Mailcap file %s, line %lu: '\\' on the end of the last line ignored."),
2438 strFileName
.c_str(),
2443 // pass to the beginning of the next line
2444 pc
= file
[++nLine
].c_str();
2446 // skip pc++ at the end of the loop
2452 // just a normal character
2458 cont
= false; // end of line reached, exit the loop
2460 // fall through to still process this field
2463 // trim whitespaces from both sides
2464 curField
.Trim(true).Trim(false);
2466 switch ( currentToken
)
2469 data
.type
= curField
.Lower();
2470 if ( data
.type
.empty() )
2472 // I don't think that this is a valid mailcap
2473 // entry, but try to interpret it somehow
2474 data
.type
= wxT('*');
2477 if ( data
.type
.Find(wxT('/')) == wxNOT_FOUND
)
2479 // we interpret "type" as "type/*"
2480 data
.type
+= wxT("/*");
2483 currentToken
= Field_OpenCmd
;
2487 data
.cmdOpen
= curField
;
2489 currentToken
= Field_Other
;
2493 if ( !ProcessOtherMailcapField(data
, curField
) )
2495 // don't flood the user with error messages if
2496 // we don't understand something in his
2497 // mailcap, but give them in debug mode because
2498 // this might be useful for the programmer
2501 wxT("Mailcap file %s, line %lu: unknown field '%s' for the MIME type '%s' ignored."),
2502 strFileName
.c_str(),
2508 else if ( data
.testfailed
)
2510 // skip this entry entirely
2514 // it already has this value
2515 //currentToken = Field_Other;
2519 wxFAIL_MSG(wxT("unknown field type in mailcap"));
2522 // next token starts immediately after ';'
2530 // continue in the same line
2534 // we read the entire entry, check what have we got
2535 // ------------------------------------------------
2537 // check that we really read something reasonable
2538 if ( currentToken
< Field_Other
)
2540 wxLogWarning(wxT("Mailcap file %s, line %lu: incomplete entry ignored."),
2541 strFileName
.c_str(), nLine
+ 1L);
2546 // if the test command failed, it's as if the entry were not there at all
2547 if ( data
.testfailed
)
2552 // support for flags:
2553 // 1. create an xterm for 'needsterminal'
2554 // 2. append "| $PAGER" for 'copiousoutput'
2556 // Note that the RFC says that having both needsterminal and
2557 // copiousoutput is probably a mistake, so it seems that running
2558 // programs with copiousoutput inside an xterm as it is done now
2559 // is a bad idea (FIXME)
2560 if ( data
.copiousoutput
)
2562 const wxChar
*p
= wxGetenv(wxT("PAGER"));
2563 data
.cmdOpen
<< wxT(" | ") << (p
? p
: wxT("more"));
2566 if ( data
.needsterminal
)
2568 data
.cmdOpen
= wxString::Format(wxT("xterm -e sh -c '%s'"),
2569 data
.cmdOpen
.c_str());
2572 if ( !data
.cmdOpen
.empty() )
2574 data
.verbs
.Insert(wxT("open"), 0);
2575 data
.commands
.Insert(data
.cmdOpen
, 0);
2578 // we have to decide whether the new entry should replace any entries
2579 // for the same MIME type we had previously found or not
2582 // the fall back entries have the lowest priority, by definition
2589 // have we seen this one before?
2590 int nIndex
= m_aTypes
.Index(data
.type
);
2592 // and if we have, was it in this file? if not, we should
2593 // overwrite the previously seen one
2594 overwrite
= nIndex
== wxNOT_FOUND
||
2595 aIndicesSeenHere
.Index(nIndex
) == wxNOT_FOUND
;
2598 wxLogTrace(TRACE_MIME
, wxT("mailcap %s: %s [%s]"),
2599 data
.type
.c_str(), data
.cmdOpen
.c_str(),
2600 overwrite
? wxT("replace") : wxT("add"));
2602 int n
= AddToMimeData
2606 new wxMimeTypeCommands(data
.verbs
, data
.commands
),
2607 wxArrayString() /* extensions */,
2614 aIndicesSeenHere
.Add(n
);
2621 size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString
& mimetypes
)
2628 size_t count
= m_aTypes
.GetCount();
2629 for ( size_t n
= 0; n
< count
; n
++ )
2631 // don't return template types from here (i.e. anything containg '*')
2633 if ( type
.Find(wxT('*')) == wxNOT_FOUND
)
2635 mimetypes
.Add(type
);
2639 return mimetypes
.GetCount();
2642 // ----------------------------------------------------------------------------
2643 // writing to MIME type files
2644 // ----------------------------------------------------------------------------
2646 bool wxMimeTypesManagerImpl::Unassociate(wxFileType
*ft
)
2648 wxArrayString sMimeTypes
;
2649 ft
->GetMimeTypes(sMimeTypes
);
2653 for (i
= 0; i
< sMimeTypes
.GetCount(); i
++)
2655 sMime
= sMimeTypes
.Item(i
);
2656 int nIndex
= m_aTypes
.Index(sMime
);
2657 if ( nIndex
== wxNOT_FOUND
)
2659 // error if we get here ??
2664 WriteMimeInfo(nIndex
, true);
2665 m_aTypes
.RemoveAt(nIndex
);
2666 m_aEntries
.RemoveAt(nIndex
);
2667 m_aExtensions
.RemoveAt(nIndex
);
2668 m_aDescriptions
.RemoveAt(nIndex
);
2669 m_aIcons
.RemoveAt(nIndex
);
2672 // check data integrity
2673 wxASSERT( m_aTypes
.Count() == m_aEntries
.Count() &&
2674 m_aTypes
.Count() == m_aExtensions
.Count() &&
2675 m_aTypes
.Count() == m_aIcons
.Count() &&
2676 m_aTypes
.Count() == m_aDescriptions
.Count() );
2681 // ----------------------------------------------------------------------------
2682 // private functions
2683 // ----------------------------------------------------------------------------
2685 static bool IsKnownUnimportantField(const wxString
& fieldAll
)
2687 static const wxChar
*knownFields
[] =
2689 wxT("x-mozilla-flags"),
2690 wxT("nametemplate"),
2691 wxT("textualnewlines"),
2694 wxString field
= fieldAll
.BeforeFirst(wxT('='));
2695 for ( size_t n
= 0; n
< WXSIZEOF(knownFields
); n
++ )
2697 if ( field
.CmpNoCase(knownFields
[n
]) == 0 )
2705 // wxUSE_MIMETYPE && wxUSE_FILE && wxUSE_TEXTFILE