Provide a fallback in case XDG_DATA_DIRS is not set
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 27 Sep 2008 11:39:56 +0000 (13:39 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 27 Sep 2008 11:39:56 +0000 (13:39 +0200)
This works only on UNIX. On other platforms, you probably should build-in the
icons anyway, or tell me if there are (standard locations for) icon themes at all...

CMakeLists.txt
src/uisupport/iconloader.cpp

index e28d90f..8462db8 100644 (file)
@@ -20,7 +20,6 @@ cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
 
 if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
-   cmake_policy(SET CMP0005 NEW)
 endif(COMMAND cmake_policy)
 
 # Use our own (well, and KDE's) version of some modules
@@ -61,8 +60,6 @@ set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps)
 set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons)
 set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications)
 
-add_definitions(-DPREFIX=${CMAKE_INSTALL_PREFIX})
-
 # Enable various flags on gcc
 if(CMAKE_COMPILER_IS_GNUCXX)
   # Let's just hope that all gccs support these options and skip the tests...
index 688d0b1..d5dbade 100644 (file)
@@ -18,6 +18,7 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <QCoreApplication>
 #include <QDebug>
 #include <QDir>
 #include <QFile>
@@ -50,7 +51,19 @@ void IconLoader::setTheme(const QString &theme) {
   _themedIconDirNames.clear();
   _plainIconDirNames.clear();
   QString path;
-  QStringList dataDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':');
+  QStringList dataDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':', QString::SkipEmptyParts);
+
+// Provide a fallback
+# ifdef Q_OS_UNIX
+    if(dataDirNames.isEmpty()) dataDirNames.append("/usr/share");
+    // on UNIX, we always check our install prefix
+    QString appDir = QCoreApplication::applicationDirPath();
+    int binpos = appDir.lastIndexOf("/bin");
+    if(binpos >= 0) {
+      appDir.replace(binpos, 4, "/share");
+      if(!dataDirNames.contains(appDir)) dataDirNames.append(appDir);
+    }
+# endif
 
   // System theme in $data/icons/$theme
   foreach(QString dir, dataDirNames) {