+ size_t cnt = config.GetLineCount();
+ for ( size_t i = 0; i < cnt; i++ )
+ {
+ if ( config[i].StartsWith(wxT("Theme="), &theme) )
+ break;
+ }
+ }
+
+ 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.Count(); 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.Count() > 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.Count(); 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.Count() > 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.Count(); 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.Count() > 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.Count(); 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.Count() > 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);
+ }