+// 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() );