+ if ( nIndex == wxNOT_FOUND )
+ {
+ comment = wxT("Comment=");
+ nIndex = file.pIndexOf(comment);
+ }
+
+ if ( nIndex != wxNOT_FOUND )
+ mime_desc = file.GetCmd(nIndex);
+ //else: no description
+
+ // next find the extensions
+ wxString mime_extension;
+
+ nIndex = file.pIndexOf(wxT("Patterns="));
+ if ( nIndex != wxNOT_FOUND )
+ {
+ wxString exts = file.GetCmd(nIndex);
+
+ wxStringTokenizer tokenizer(exts, wxT(";"));
+ while ( tokenizer.HasMoreTokens() )
+ {
+ wxString e = tokenizer.GetNextToken();
+
+ // don't support too difficult patterns
+ if ( e.Left(2) != wxT("*.") )
+ continue;
+
+ if ( !mime_extension.empty() )
+ {
+ // separate from the previous ext
+ mime_extension << wxT(' ');
+ }
+
+ mime_extension << e.Mid(2);
+ }
+ }
+
+ sExts.Add(mime_extension);
+
+ // ok, now we can take care of icon:
+
+ nIndex = file.pIndexOf(wxT("Icon="));
+ if ( nIndex != wxNOT_FOUND )
+ {
+ strIcon = file.GetCmd(nIndex);
+
+ wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str());
+
+ // it could be the real path, but more often a short name
+ if (!wxFileExists(strIcon))
+ {
+ // icon is just the short name
+ if ( !strIcon.empty() )
+ {
+ // we must check if the file exists because it may be stored
+ // in many locations, at least ~/.kde and $KDEDIR
+ size_t nDir, nDirs = icondirs.GetCount();
+ for ( nDir = 0; nDir < nDirs; nDir++ )
+ {
+ wxFileName fnameIcon( strIcon );
+ wxFileName fname( icondirs[nDir], fnameIcon.GetName() );
+ fname.SetExt( wxT("png") );
+ if (fname.FileExists())
+ {
+ strIcon = fname.GetFullPath();
+ wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str());
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // now look for lines which know about the application
+ // exec= or DefaultApp=
+
+ nIndex = file.pIndexOf(wxT("DefaultApp"));
+
+ if ( nIndex == wxNOT_FOUND )
+ {
+ // no entry try exec
+ nIndex = file.pIndexOf(wxT("Exec"));
+ }
+
+ if ( nIndex != wxNOT_FOUND )
+ {
+ // we expect %f; others including %F and %U and %u are possible
+ wxString sTmp = file.GetCmd(nIndex);
+ if (0 == sTmp.Replace( wxT("%f"), wxT("%s") ))
+ sTmp += wxT(" %s");
+ entry->AddOrReplaceVerb(wxString(wxT("open")), sTmp );
+ }
+
+ AddToMimeData(mimetype, strIcon, entry, sExts, mime_desc);
+}
+
+void wxMimeTypesManagerImpl::LoadKDELinksForMimeType(const wxString& dirbase,
+ const wxString& subdir,
+ const wxArrayString& icondirs)
+{
+ wxString dirname = dirbase;
+ dirname += subdir;
+ wxDir dir(dirname);
+ if ( !dir.IsOpened() )
+ return;
+
+ wxLogTrace(TRACE_MIME, wxT("--- Loading from KDE directory %s ---"),
+ dirname.c_str());
+
+ dirname += wxT('/');
+
+ wxString filename;
+ bool cont = dir.GetFirst(&filename, wxT("*.kdelnk"), wxDIR_FILES);
+ while ( cont )
+ {
+ LoadKDELinksForMimeSubtype(dirname, subdir, filename, icondirs);
+
+ cont = dir.GetNext(&filename);
+ }
+
+ // new standard for Gnome and KDE
+ cont = dir.GetFirst(&filename, wxT("*.desktop"), wxDIR_FILES);
+ while ( cont )
+ {
+ LoadKDELinksForMimeSubtype(dirname, subdir, filename, icondirs);
+
+ cont = dir.GetNext(&filename);
+ }
+}
+
+void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString& dirbase,
+ const wxArrayString& icondirs)
+{
+ wxASSERT_MSG( !dirbase.empty() && !wxEndsWithPathSeparator(dirbase),
+ wxT("base directory shouldn't end with a slash") );
+
+ wxString dirname = dirbase;
+ dirname << wxT("/mimelnk");
+
+ if ( !wxDir::Exists(dirname) )
+ return;
+
+ wxDir dir(dirname);