From 4261ffff050064aebc8b4d0566886c3ef7352cfa Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 25 Jan 2009 02:00:39 +0100 Subject: [PATCH] Improve data and icon file handling Add some more locations that data files are being searched in, and reorder the icon search order to prefer system themes over our own files. Ah, and fix some bugs that would exclude some dirs that really should be included. This hopefully provides sane handling of external files now. --- src/common/quassel.cpp | 34 ++++++++--------- src/uisupport/iconloader.cpp | 72 +++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp index d9e180e7..5444979e 100644 --- a/src/common/quassel.cpp +++ b/src/common/quassel.cpp @@ -284,32 +284,32 @@ QStringList Quassel::findDataDirPaths() const { dataDirNames[i].append("/apps/quassel/"); } else { // Provide a fallback - // FIXME fix this for win and mac! #ifdef Q_OS_WIN32 - dataDirNames << qgetenv("APPDATA") + QCoreApplication::organizationDomain() + dataDirNames << qgetenv("APPDATA") + QCoreApplication::organizationDomain() + "/share/apps/quassel/" + << qgetenv("APPDATA") + QCoreApplication::organizationDomain() << QCoreApplication::applicationDirPath(); + } #elif defined Q_WS_MAC dataDirNames << QDir::homePath() + "/Library/Application Support/Quassel/" << QCoreApplication::applicationDirPath(); + } #else - if(dataDirNames.isEmpty()) - dataDirNames.append("/usr/share/apps/quassel/"); - // 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"); - appDir.append("/apps/quassel/"); - if(!dataDirNames.contains(appDir)) - dataDirNames.append(appDir); - } -#endif + dataDirNames.append("/usr/share/apps/quassel/"); + } + // 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"); + appDir.append("/apps/quassel/"); + if(!dataDirNames.contains(appDir)) + dataDirNames.append(appDir); } +#endif // add resource path and workdir just in case - dataDirNames << ":/data/" - << QCoreApplication::applicationDirPath() + "/data/" - << QCoreApplication::applicationDirPath(); + dataDirNames << QCoreApplication::applicationDirPath() + "/data/" + << ":/data/"; // append trailing '/' and check for existence QStringList::Iterator iter = dataDirNames.begin(); diff --git a/src/uisupport/iconloader.cpp b/src/uisupport/iconloader.cpp index 354e0ee1..1c3d6e77 100644 --- a/src/uisupport/iconloader.cpp +++ b/src/uisupport/iconloader.cpp @@ -54,39 +54,59 @@ void IconLoader::setTheme(const QString &theme) { // check which dirs could contain themed icons _themedIconDirNames.clear(); _plainIconDirNames.clear(); - QString path; - QStringList dataDirNames = Quassel::dataDirPaths(); - // System theme in $data/icons/$theme - foreach(QString dir, dataDirNames) { - path = QString("%1/icons/%2").arg(dir, theme); - if(QFile::exists(path)) - _themedIconDirNames.append(path); + // First, look for a system theme + // This is supposed to only work on Unix, though other platforms might set $XDG_DATA_DIRS if they please. + QStringList iconDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':', QString::SkipEmptyParts); + if(!iconDirNames.isEmpty()) { + for(int i = 0; i < iconDirNames.count(); i++) + iconDirNames[i].append(QString("/icons/")); + } +#ifdef Q_OS_UNIX + else { + // Provide a fallback + iconDirNames << "/usr/share/icons/"; + } + // Add our prefix too + QString appDir = QCoreApplication::applicationDirPath(); + int binpos = appDir.lastIndexOf("/bin"); + if(binpos >= 0) { + appDir.replace(binpos, 4, "/share"); + appDir.append("/icons/"); + if(!iconDirNames.contains(appDir)) + iconDirNames.append(appDir); } - // Resource for system theme :/icons/$theme - path = QString(":/icons/%1").arg(theme); - if(QFile::exists(path)) - _themedIconDirNames.append(path); - - // Own icons in $data/apps/quassel/icons/hicolor - // Also, plain icon dirs $data/apps/quassel/pics - foreach(QString dir, dataDirNames) { - path = QString("%1/icons/hicolor").arg(dir); +#endif + + // Now look for an icons/ subdir in our data paths + foreach(const QString &dir, Quassel::dataDirPaths()) + iconDirNames << dir + "icons/"; + + // Add our resource path too + iconDirNames << ":/icons/"; + + // Ready do add theme names + foreach(const QString &dir, iconDirNames) { + QString path = dir + theme + '/'; if(QFile::exists(path)) - _themedIconDirNames.append(path); - path = QString("%1/apps/quassel/pics").arg(dir); + _themedIconDirNames << path; + } + foreach(const QString &dir, iconDirNames) { + QString path = dir + "hicolor/"; if(QFile::exists(path)) - _plainIconDirNames.append(path); + _themedIconDirNames << path; } - // Same for :/icons/hicolor and :/pics - path = QString(":/icons/hicolor"); - if(QFile::exists(path)) - _themedIconDirNames.append(path); + // We ship some plain (non-themed) icons in $data/pics + foreach(const QString &dir, Quassel::dataDirPaths()) { + QString path = dir + "pics/"; + if(QFile::exists(path)) + _plainIconDirNames << path; + } + // And of course, our resource path + if(QFile::exists(":/pics")) + _plainIconDirNames << ":/pics"; - path = QString(":/pics"); - if(QFile::exists(path)) - _plainIconDirNames.append(path); } // TODO: optionally implement cache (speed/memory tradeoff?) -- 2.20.1