void wxMimeTypesManagerImpl::LoadXDGAppsFilesFromDir(const wxString& dirname) { // 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 filename; // Look into .desktop files bool cont = dir.GetFirst(&filename, wxT("*.desktop"), wxDIR_FILES); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (cont) { wxFileName p(dirname, filename); LoadXDGApp( p.GetFullPath() ); cont = dir.GetNext(&filename); } // Recurse into subdirs, which on KDE may hold most of the .desktop files cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (cont) { wxFileName p(dirname, wxEmptyString); p.AppendDir(filename); LoadXDGAppsFilesFromDir( p.GetPath() ); cont = dir.GetNext(&filename); } }
void wxMimeTypesManagerImpl::LoadXDGAppsFilesFromDir(const wxString& dirname) { // 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 filename; // Look into .desktop files bool cont = dir.GetFirst(&filename, wxT("*.desktop"), wxDIR_FILES); while (cont) { wxFileName p(dirname, filename); LoadXDGApp( p.GetFullPath() ); cont = dir.GetNext(&filename); } #if 0 // RR: I'm not sure this makes any sense. On my system we'll just // scan the YAST2 and other useless directories // Look recursively into subdirs cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); while (cont) { wxFileName p(dirname, wxEmptyString); p.AppendDir(filename); LoadXDGAppsFilesFromDir( p.GetPath() ); cont = dir.GetNext(&filename); } #endif }
// read system and user mailcaps and other files void wxMimeTypesManagerImpl::Initialize(int mailcapStyles, const wxString& sExtraDir) { #ifdef __VMS // XDG tables are never installed on OpenVMS return; #else // Read MIME type - extension associations LoadXDGGlobs( "/usr/share/mime/globs" ); LoadXDGGlobs( "/usr/local/share/mime/globs" ); // Load desktop files for XDG, and then override them with the 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. { wxString xdgDataHome = wxGetenv("XDG_DATA_HOME"); if ( xdgDataHome.empty() ) xdgDataHome = wxGetHomeDir() + "/.local/share"; wxString xdgDataDirs = wxGetenv("XDG_DATA_DIRS"); if ( xdgDataDirs.empty() ) { xdgDataDirs = "/usr/local/share:/usr/share"; if (mailcapStyles & wxMAILCAP_GNOME) xdgDataDirs += ":/usr/share/gnome:/opt/gnome/share"; if (mailcapStyles & wxMAILCAP_KDE) xdgDataDirs += ":/usr/share/kde3:/opt/kde3/share"; } if ( !sExtraDir.empty() ) { xdgDataDirs += ':'; xdgDataDirs += sExtraDir; } wxArrayString dirs; wxStringTokenizer tokenizer(xdgDataDirs, ":"); 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]; if (f.Last() != '/') f += '/'; f += "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]; if (dirStr.Last() != '/') dirStr += '/'; dirStr += "applications"; LoadXDGAppsFilesFromDir(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.GetLine(i).Find(wxT("=")) != wxNOT_FOUND) { 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]; if (desktopPath.Last() != '/') desktopPath += '/'; desktopPath += "applications/"; desktopPath += desktopFile; if (wxFileExists(desktopPath)) LoadXDGApp(desktopPath); } } } } } } } } #endif }