+    // FIXME: This code is heavily broken. There are three bugs in it:
+    //        1) it uses only KDEDIR, which is deprecated, instead of using
+    //           list of paths from KDEDIRS and using KDEDIR only if KDEDIRS
+    //           is not set
+    //        2) it doesn't look into ~/.kde/share/config/kdeglobals where
+    //           user's settings are stored and thus *ignores* user's settings
+    //           instead of respecting them
+    //        3) it "tries to guess KDEDIR" and "tries a few likely theme
+    //           names", both of which is completely arbitrary; instead, the
+    //           code should give up if KDEDIR(S) is not set and/or the icon
+    //           theme cannot be determined, because it means that the user is
+    //           not using KDE (and thus is not interested in KDE icons anyway)
+
+    // the variable $KDEDIR is set when KDE is running
+    wxString kdedir = wxGetenv( wxT("KDEDIR") );
+
+    if (!kdedir.empty())
+    {
+        // $(KDEDIR)/share/config/kdeglobals holds info
+        // the current icons theme
+        wxFileName configFile( kdedir, wxEmptyString );
+        configFile.AppendDir( wxT("share") );
+        configFile.AppendDir( wxT("config") );
+        configFile.SetName( wxT("kdeglobals") );
+
+        wxTextFile config;
+        if (configFile.FileExists() && config.Open(configFile.GetFullPath()))
+        {
+            // $(KDEDIR)/share/config -> $(KDEDIR)/share
+            configFile.RemoveDir( configFile.GetDirCount() - 1 );
+            // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
+            configFile.AppendDir( wxT("icons") );
+
+            // Check for entry
+            wxString theme(wxT("default.kde"));
+            size_t cnt = config.GetLineCount();
+            for (size_t i = 0; i < cnt; i++)
+            {
+                if (config[i].StartsWith(wxT("Theme="), &theme/*rest*/))
+                    break;
+            }
+
+            configFile.AppendDir(theme);
+        }
+        else
+        {
+            // $(KDEDIR)/share/config -> $(KDEDIR)/share
+            configFile.RemoveDir( configFile.GetDirCount() - 1 );
+
+            // $(KDEDIR)/share/ -> $(KDEDIR)/share/icons
+            configFile.AppendDir( wxT("icons") );
+
+            // $(KDEDIR)/share/icons -> $(KDEDIR)/share/icons/default.kde
+            configFile.AppendDir( wxT("default.kde") );
+        }
+
+        configFile.SetName( wxEmptyString );
+        configFile.AppendDir( wxT("32x32") );
+        configFile.AppendDir( wxT("mimetypes") );
+
+        // Just try a few likely icons theme names
+
+        int pos = configFile.GetDirCount() - 3;
+
+        if (!wxDir::Exists(configFile.GetPath()))
+        {
+            configFile.RemoveDir( pos );
+            configFile.InsertDir( pos, wxT("default.kde") );
+        }
+
+        if (!wxDir::Exists(configFile.GetPath()))
+        {
+            configFile.RemoveDir( pos );
+            configFile.InsertDir( pos, wxT("default") );
+        }
+
+        if (!wxDir::Exists(configFile.GetPath()))
+        {
+            configFile.RemoveDir( pos );
+            configFile.InsertDir( pos, wxT("crystalsvg") );
+        }
+
+        if (!wxDir::Exists(configFile.GetPath()))
+        {
+            configFile.RemoveDir( pos );
+            configFile.InsertDir( pos, wxT("crystal") );
+        }
+
+        if (wxDir::Exists(configFile.GetPath()))
+            icondirs.Add( configFile.GetFullPath() );
+    }
+