/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel IRC Team *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#ifndef HAVE_KDE
+
+#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
#include "iconloader.h"
+#include "quassel.h"
+#include "util.h"
IconLoader IconLoader::_iconLoader;
int IconLoader::_groupSize[] = { 48, 22, 22, 16, 32, 22 }; // default sizes taken from Oxygen
IconLoader *IconLoader::global() {
+ // Workaround: the static _iconLoader might be initialized before the resources it needs
+ // This way, first call to global() will init it by setting the theme
+ if(_iconLoader.theme().isEmpty())
+ _iconLoader.setTheme("oxygen");
return &_iconLoader;
}
IconLoader::IconLoader(QObject *parent) : QObject(parent) {
- setTheme("oxygen");
+ // setTheme("oxygen");
}
IconLoader::~IconLoader() {
// check which dirs could contain themed icons
_themedIconDirNames.clear();
_plainIconDirNames.clear();
- QString path;
- QStringList dataDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':');
- // System theme in $data/icons/$theme
- foreach(QString dir, dataDirNames) {
- path = QString("%1/icons/%2").arg(dir, theme);
+ // 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);
+ }
+#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);
+ _themedIconDirNames << path;
}
- // Resource for system theme :/icons/$theme
- path = QString(":/icons/%2");
- if(QFile::exists(path))
- _themedIconDirNames.append(path);
-
- // Own icons in $data/apps/quassel/icons/hicolor and :/icons/hicolor
- // Also, plain icon dirs $data/apps/quassel/pics and :/pics
- dataDirNames.append(":");
- foreach(QString dir, dataDirNames) {
- path = QString("%1/apps/quassel/icons/hicolor");
+ foreach(const QString &dir, iconDirNames) {
+ QString path = dir + "hicolor/";
if(QFile::exists(path))
- _themedIconDirNames.append(path);
- path = QString("%1/apps/quassel/pics");
+ _themedIconDirNames << 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.append(path);
+ _plainIconDirNames << path;
}
+ // And of course, our resource path
+ if(QFile::exists(":/pics"))
+ _plainIconDirNames << ":/pics";
+
}
// TODO: optionally implement cache (speed/memory tradeoff?)
if(QFile::exists(path)) return path;
}
+ qWarning() << "Icon not found:" << name << size;
return QString();
}
+
+// Convenience constructors
+
+QPixmap DesktopIcon(const QString& name, int force_size) {
+ IconLoader *loader = IconLoader::global();
+ return loader->loadIcon(name, IconLoader::Desktop, force_size);
+}
+
+QPixmap BarIcon(const QString& name, int force_size) {
+ IconLoader *loader = IconLoader::global();
+ return loader->loadIcon(name, IconLoader::Toolbar, force_size);
+}
+
+QPixmap MainBarIcon(const QString& name, int force_size) {
+ IconLoader *loader = IconLoader::global();
+ return loader->loadIcon(name, IconLoader::MainToolbar, force_size);
+}
+
+QPixmap SmallIcon(const QString& name, int force_size) {
+ IconLoader *loader = IconLoader::global();
+ return loader->loadIcon(name, IconLoader::Small, force_size);
+}
+
+#endif