+ 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)
+{
+ wxFileName dirname(dirbase, wxEmptyString);
+ dirname.AppendDir(subdir);
+
+ // Don't complain if we don't have permissions to read - it confuses users
+ wxLogNull logNull;
+
+ wxDir dir(dirname.GetPath());
+ if(! dir.IsOpened())
+ return;
+
+ wxLogTrace(TRACE_MIME, wxT("--- Loading from KDE directory %s ---"),
+ dirname.GetPath().c_str());
+
+ wxString filename;
+ bool cont = dir.GetFirst(&filename, wxT("*.kdelnk"), wxDIR_FILES);
+ while(cont) {
+ LoadKDELinksForMimeSubtype(dirname.GetPath(), 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.GetPath(), subdir,
+ filename, icondirs);
+ cont = dir.GetNext(&filename);
+ }
+}
+
+void wxMimeTypesManagerImpl::LoadKDELinkFilesFromDir(const wxString& dirname,
+ const wxArrayString& icondirs)
+{
+ // Don't complain if we don't have permissions to read - it confuses users
+ wxLogNull logNull;
+
+ if(! wxDir::Exists(dirname))
+ return;
+
+ wxDir dir(dirname);
+ if ( !dir.IsOpened() )
+ return;
+
+ wxString subdir;
+ bool cont = dir.GetFirst(&subdir, wxEmptyString, wxDIR_DIRS);
+ while ( cont )
+ {
+ LoadKDELinksForMimeType(dirname, subdir, icondirs);
+
+ cont = dir.GetNext(&subdir);
+ }
+}
+
+// Read a KDE .desktop file of type 'Application'
+void wxMimeTypesManagerImpl::LoadKDEApp(const wxString& filename)
+{
+ wxLogTrace(TRACE_MIME, wxT("loading KDE file %s"), filename.c_str());
+
+ wxMimeTextFile file;
+ if ( !file.Open(filename) )
+ return;
+
+ // Here, only type 'Application' should be considered.
+ int nIndex = file.pIndexOf( wxT("Type=") );
+ if (nIndex != wxNOT_FOUND &&
+ file.GetCmd(nIndex).Lower() != wxT("application"))
+ return;
+
+ // The hidden entry specifies a file to be ignored.
+ nIndex = file.pIndexOf( wxT("Hidden=") );
+ if (nIndex != wxNOT_FOUND && file.GetCmd(nIndex).Lower() == wxT("true"))
+ return;
+
+ // Semicolon separated list of mime types handled by the application.
+ nIndex = file.pIndexOf( wxT("MimeType=") );
+ if (nIndex == wxNOT_FOUND)
+ return;
+ wxString mimetypes = file.GetCmd (nIndex);
+
+ // Name of the application
+ wxString nameapp;
+ nIndex = wxNOT_FOUND;
+#if wxUSE_INTL // try "Name[locale name]" first
+ wxLocale *locale = wxGetLocale();
+ if ( locale )
+ nIndex = file.pIndexOf(_T("Name[")+locale->GetName()+_T("]="));
+#endif // wxUSE_INTL
+ if(nIndex == wxNOT_FOUND)
+ nIndex = file.pIndexOf( wxT("Name=") );
+ if(nIndex != wxNOT_FOUND)
+ nameapp = file.GetCmd(nIndex);
+
+ // Icon of the application.
+ wxString nameicon, namemini;
+ nIndex = wxNOT_FOUND;
+#if wxUSE_INTL // try "Icon[locale name]" first
+ if ( locale )
+ nIndex = file.pIndexOf(_T("Icon[")+locale->GetName()+_T("]="));
+#endif // wxUSE_INTL
+ if(nIndex == wxNOT_FOUND)
+ nIndex = file.pIndexOf( wxT("Icon=") );
+ if(nIndex != wxNOT_FOUND) {
+ nameicon = wxString(wxT("--icon ")) + file.GetCmd(nIndex);
+ namemini = wxString(wxT("--miniicon ")) + file.GetCmd(nIndex);
+ }
+
+ // Replace some of the field code in the 'Exec' entry.
+ // TODO: deal with %d, %D, %n, %N, %k and %v (but last one is deprecated)
+ nIndex = file.pIndexOf( wxT("Exec=") );
+ if (nIndex == wxNOT_FOUND)
+ return;
+ wxString sCmd = file.GetCmd(nIndex);
+ // we expect %f; others including %F and %U and %u are possible
+ sCmd.Replace(wxT("%F"), wxT("%f"));
+ sCmd.Replace(wxT("%U"), wxT("%f"));
+ sCmd.Replace(wxT("%u"), wxT("%f"));
+ if (0 == sCmd.Replace ( wxT("%f"), wxT("%s") ))
+ sCmd = sCmd + wxT(" %s");
+ sCmd.Replace(wxT("%c"), nameapp);
+ sCmd.Replace(wxT("%i"), nameicon);
+ sCmd.Replace(wxT("%m"), namemini);
+
+ wxStringTokenizer tokenizer(mimetypes, _T(";"));
+ while(tokenizer.HasMoreTokens()) {
+ wxString mimetype = tokenizer.GetNextToken().Lower();
+ nIndex = m_aTypes.Index(mimetype);
+ if(nIndex != wxNOT_FOUND) { // is this a known MIME type?
+ wxMimeTypeCommands* entry = m_aEntries[nIndex];
+ entry->AddOrReplaceVerb(wxT("open"), sCmd);
+ }