X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Ficonloader.cpp;h=354e0ee1b1359e8f062a5ba7f003ff4753d69ff3;hp=0fff1e8213c9827ebb0861bb6f1dad00a95189b8;hb=7d686d70a5d7c9972590bc6a11925be2555ada8a;hpb=71d7e1a6931b5edfa3fd15de5ad82bbca25d1426 diff --git a/src/uisupport/iconloader.cpp b/src/uisupport/iconloader.cpp index 0fff1e82..354e0ee1 100644 --- a/src/uisupport/iconloader.cpp +++ b/src/uisupport/iconloader.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * 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 * @@ -18,22 +18,31 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifndef HAVE_KDE + +#include #include #include #include #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() { @@ -46,7 +55,7 @@ void IconLoader::setTheme(const QString &theme) { _themedIconDirNames.clear(); _plainIconDirNames.clear(); QString path; - QStringList dataDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':'); + QStringList dataDirNames = Quassel::dataDirPaths(); // System theme in $data/icons/$theme foreach(QString dir, dataDirNames) { @@ -55,21 +64,29 @@ void IconLoader::setTheme(const QString &theme) { _themedIconDirNames.append(path); } // Resource for system theme :/icons/$theme - path = QString(":/icons/%2"); + path = QString(":/icons/%1").arg(theme); 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(":"); + // Own icons in $data/apps/quassel/icons/hicolor + // Also, plain icon dirs $data/apps/quassel/pics foreach(QString dir, dataDirNames) { - path = QString("%1/apps/quassel/icons/hicolor"); + path = QString("%1/icons/hicolor").arg(dir); if(QFile::exists(path)) _themedIconDirNames.append(path); - path = QString("%1/apps/quassel/pics"); + path = QString("%1/apps/quassel/pics").arg(dir); if(QFile::exists(path)) _plainIconDirNames.append(path); } + + // Same for :/icons/hicolor and :/pics + path = QString(":/icons/hicolor"); + if(QFile::exists(path)) + _themedIconDirNames.append(path); + + path = QString(":/pics"); + if(QFile::exists(path)) + _plainIconDirNames.append(path); } // TODO: optionally implement cache (speed/memory tradeoff?) @@ -108,5 +125,30 @@ QString IconLoader::findIconPath(const QString &name, int size) { 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