+
+ return theme;
+}
+
+// Try to find a file "kdeglobals" in one of the directories and read the
+// "Theme" entry there.
+static wxString GetKDETheme(const wxArrayString& basedirs)
+{
+ wxString theme;
+ for(size_t i = 0; i < basedirs.GetCount(); i++) {
+ wxFileName filename(basedirs.Item(i), wxEmptyString);
+ filename.AppendDir( wxT("share") );
+ filename.AppendDir( wxT("config") );
+ filename.SetName( wxT("kdeglobals") );
+ theme = GetKDEThemeInFile(filename);
+ if(! theme.IsEmpty())
+ return theme;
+ }
+ // If $KDEDIRS and $KDEDIR were set, we try nothing more. Otherwise, we
+ // try to get the configuration file with 'kde-config'.
+ if(basedirs.GetCount() > 1)
+ return theme;
+ wxString paths = ReadPathFromKDEConfig(wxT("config"));
+ if(! paths.IsEmpty()) {
+ wxStringTokenizer tokenizer(paths, wxT(":"));
+ while( tokenizer.HasMoreTokens() ) {
+ wxFileName filename(tokenizer.GetNextToken(), wxT("kdeglobals"));
+ theme = GetKDEThemeInFile(filename);
+ if(! theme.IsEmpty())
+ return theme;
+ }
+ }
+ return theme;
+}
+
+// Get list of directories of icons.
+static void GetKDEIconDirs(const wxArrayString& basedirs,
+ wxArrayString& icondirs)
+{
+ wxString theme = GetKDETheme(basedirs);
+ if(theme.IsEmpty())
+ theme = wxT("default.kde");
+
+ for(size_t i = 0; i < basedirs.GetCount(); i++) {
+ wxFileName dirname(basedirs.Item(i), wxEmptyString);
+ dirname.AppendDir( wxT("share") );
+ dirname.AppendDir( wxT("icons") );
+ dirname.AppendDir(theme);
+ dirname.AppendDir( wxT("32x32") );
+ dirname.AppendDir( wxT("mimetypes") );
+ if( wxDir::Exists( dirname.GetPath() ) )
+ icondirs.Add( dirname.GetPath() );
+ }
+
+ // If $KDEDIRS and $KDEDIR were not set, use 'kde-config'
+ if(basedirs.GetCount() > 1)
+ return;
+ wxString paths = ReadPathFromKDEConfig(wxT("icon"));
+ if(! paths.IsEmpty()) {
+ wxStringTokenizer tokenizer(paths, wxT(":"));
+ while( tokenizer.HasMoreTokens() ) {
+ wxFileName dirname(tokenizer.GetNextToken(), wxEmptyString);
+ dirname.AppendDir(theme);
+ dirname.AppendDir( wxT("32x32") );
+ dirname.AppendDir( wxT("mimetypes") );
+ if(icondirs.Index(dirname.GetPath()) == wxNOT_FOUND &&
+ wxDir::Exists( dirname.GetPath() ) )
+ icondirs.Add( dirname.GetPath() );
+ }
+ }
+}
+
+// Get list of directories of mime types.
+static void GetKDEMimeDirs(const wxArrayString& basedirs,
+ wxArrayString& mimedirs)
+{
+ for(size_t i = 0; i < basedirs.GetCount(); i++) {
+ wxFileName dirname(basedirs.Item(i), wxEmptyString);
+ dirname.AppendDir( wxT("share") );
+ dirname.AppendDir( wxT("mimelnk") );
+ if( wxDir::Exists( dirname.GetPath() ) )
+ mimedirs.Add( dirname.GetPath() );
+ }
+
+ // If $KDEDIRS and $KDEDIR were not set, use 'kde-config'
+ if(basedirs.GetCount() > 1)
+ return;
+ wxString paths = ReadPathFromKDEConfig(wxT("mime"));
+ if(! paths.IsEmpty()) {
+ wxStringTokenizer tokenizer(paths, wxT(":"));
+ while( tokenizer.HasMoreTokens() ) {
+ wxFileName p(tokenizer.GetNextToken(), wxEmptyString);
+ wxString dirname = p.GetPath(); // To remove possible trailing '/'
+ if(mimedirs.Index(dirname) == wxNOT_FOUND &&
+ wxDir::Exists(dirname) )
+ mimedirs.Add(dirname);
+ }
+ }
+}
+
+// Get list of directories of application desktop files.
+static void GetKDEAppsDirs(const wxArrayString& basedirs,
+ wxArrayString& appsdirs)
+{
+ for(size_t i = 0; i < basedirs.GetCount(); i++) {
+ wxFileName dirname(basedirs.Item(i), wxEmptyString);
+ dirname.AppendDir( wxT("share") );
+ dirname.AppendDir( wxT("applnk") );
+ if( wxDir::Exists( dirname.GetPath() ) )
+ appsdirs.Add( dirname.GetPath() );
+ }
+
+ // If $KDEDIRS and $KDEDIR were not set, use 'kde-config'
+ if(basedirs.GetCount() > 1)
+ return;
+ wxString paths = ReadPathFromKDEConfig(wxT("apps"));
+ if(! paths.IsEmpty()) {
+ wxStringTokenizer tokenizer(paths, wxT(":"));
+ while( tokenizer.HasMoreTokens() ) {
+ wxFileName p(tokenizer.GetNextToken(), wxEmptyString);
+ wxString dirname = p.GetPath(); // To remove possible trailing '/'
+ if(appsdirs.Index(dirname) == wxNOT_FOUND &&
+ wxDir::Exists(dirname) )
+ appsdirs.Add(dirname);
+ }
+ }
+ paths = ReadPathFromKDEConfig(wxT("xdgdata-apps"));
+ if(! paths.IsEmpty()) {
+ wxStringTokenizer tokenizer(paths, wxT(":"));
+ while( tokenizer.HasMoreTokens() ) {
+ wxFileName p(tokenizer.GetNextToken(), wxEmptyString);
+ wxString dirname = p.GetPath(); // To remove possible trailing '/'
+ if(appsdirs.Index(dirname) == wxNOT_FOUND &&
+ wxDir::Exists(dirname) )
+ appsdirs.Add(dirname);
+ }
+ }
+}
+
+// Fill database with all mime types.
+void wxMimeTypesManagerImpl::GetKDEMimeInfo(const wxString& sExtraDir)
+{
+ wxArrayString basedirs;
+ GetKDEBaseDirs(basedirs);
+
+ wxArrayString icondirs;
+ GetKDEIconDirs(basedirs, icondirs);
+ wxArrayString mimedirs;
+ GetKDEMimeDirs(basedirs, mimedirs);
+ wxArrayString appsdirs;
+ GetKDEAppsDirs(basedirs, appsdirs);
+
+ if(! sExtraDir.IsEmpty()) {
+ icondirs.Add(sExtraDir + wxT("/icons"));
+ mimedirs.Add(sExtraDir + wxT("/mimelnk"));
+ appsdirs.Add(sExtraDir + wxT("/applnk"));
+ }
+
+ // Load mime types
+ size_t nDirs = mimedirs.GetCount(), nDir;
+ for(nDir = 0; nDir < nDirs; nDir++)
+ LoadKDELinkFilesFromDir(mimedirs[nDir], icondirs);
+
+ // Load application files and associate them to corresponding mime types.
+ nDirs = appsdirs.GetCount();
+ for(nDir = 0; nDir < nDirs; nDir++)
+ LoadKDEAppsFilesFromDir(appsdirs[nDir]);