Gnome Mime type fix by scanning for .desktop files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@54353 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1536,6 +1536,85 @@ void wxMimeTypesManagerImpl::Initialize(int mailcapStyles,
|
||||
GetKDEMimeInfo(sExtraDir);
|
||||
#endif
|
||||
|
||||
// Load desktop files for Gnome, and then override them with the Gnome defaults.
|
||||
// We will override them one desktop file at a time, rather
|
||||
// than one mime type at a time, but it should be a reasonable
|
||||
// heuristic.
|
||||
if (mailcapStyles & wxMAILCAP_GNOME)
|
||||
{
|
||||
wxString xdgDataHome = wxGetenv(wxT("XDG_DATA_HOME"));
|
||||
if ( xdgDataHome.empty() )
|
||||
xdgDataHome = wxGetHomeDir() + wxT("/.local/share");
|
||||
wxString xdgDataDirs = wxGetenv(wxT("XDG_DATA_DIRS"));
|
||||
if ( xdgDataDirs.empty() )
|
||||
xdgDataDirs = wxT("/usr/local/share:/usr/share:/usr/share/gnome");
|
||||
wxArrayString dirs;
|
||||
|
||||
wxStringTokenizer tokenizer(xdgDataDirs, wxT(":"));
|
||||
while ( tokenizer.HasMoreTokens() )
|
||||
{
|
||||
wxString p = tokenizer.GetNextToken();
|
||||
dirs.Add(p);
|
||||
}
|
||||
dirs.insert(dirs.begin(), xdgDataHome);
|
||||
|
||||
wxString defaultsList;
|
||||
size_t i;
|
||||
for (i = 0; i < dirs.GetCount(); i++)
|
||||
{
|
||||
wxString f(dirs[i] + wxT("/applications/defaults.list"));
|
||||
if (wxFileExists(f))
|
||||
{
|
||||
defaultsList = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Load application files and associate them to corresponding mime types.
|
||||
size_t nDirs = dirs.GetCount();
|
||||
for (size_t nDir = 0; nDir < nDirs; nDir++)
|
||||
{
|
||||
wxString dirStr(dirs[nDir] + wxT("/applications"));
|
||||
LoadKDEAppsFilesFromDir(dirStr);
|
||||
}
|
||||
|
||||
if (!defaultsList.IsEmpty())
|
||||
{
|
||||
wxArrayString deskTopFilesSeen;
|
||||
|
||||
wxMimeTextFile textfile(defaultsList);
|
||||
if ( textfile.Open() )
|
||||
{
|
||||
int nIndex = textfile.pIndexOf( wxT("[Default Applications]") );
|
||||
if (nIndex != wxNOT_FOUND)
|
||||
{
|
||||
for (i = nIndex+1; i < textfile.GetLineCount(); i++)
|
||||
{
|
||||
if (textfile[i].Find(wxT("=")) != wxNOT_FOUND)
|
||||
{
|
||||
wxString mimeType = textfile.GetVerb(i);
|
||||
wxString desktopFile = textfile.GetCmd(i);
|
||||
|
||||
if (deskTopFilesSeen.Index(desktopFile) == wxNOT_FOUND)
|
||||
{
|
||||
deskTopFilesSeen.Add(desktopFile);
|
||||
size_t j;
|
||||
for (j = 0; j < dirs.GetCount(); j++)
|
||||
{
|
||||
wxString desktopPath(dirs[j] + wxT("/applications/") + desktopFile);
|
||||
if (wxFileExists(desktopPath))
|
||||
{
|
||||
LoadKDEApp(desktopPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_mailcapStylesInited |= mailcapStyles;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user