X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Ficon.cpp;h=9a6a52887b6a66f3404fac7bee9f812bc4525450;hp=19e9f88fd35f22823386cce8dfd53251dc260932;hb=c27d5bfbe80bfeb583a25404f4ccee4b70b010e0;hpb=4a5065255e652dd0c301bac0db41b7afb777ef49 diff --git a/src/uisupport/icon.cpp b/src/uisupport/icon.cpp index 19e9f88f..9a6a5288 100644 --- a/src/uisupport/icon.cpp +++ b/src/uisupport/icon.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,34 +18,70 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef HAVE_KDE - #include "icon.h" -#include "iconloader.h" -Icon::Icon() : QIcon() -{ -} +#include + +#include + +namespace icon { +namespace { -Icon::Icon(const QString &name) : QIcon() +void printWarning(const QString &iconName, const QString &extra = {}) { - addPixmap(IconLoader::global()->loadIcon(name, IconLoader::Desktop)); + static std::set warnedAbout; + if (warnedAbout.insert(iconName).second) { + qWarning() << "Missing icon:" << iconName << qPrintable(extra); + } +} + } -Icon::Icon(const QIcon ©) : QIcon(copy) +QIcon get(const QString &iconName, const QString &fallbackPath) { + return get(std::vector{iconName}, fallbackPath); } -Icon &Icon::operator=(const Icon &other) +QIcon get(const std::vector &iconNames, const QString &fallbackPath) { - if (this != &other) { - QIcon::operator=(other); + for (auto &&iconName : iconNames) { + // Exact match + if (QIcon::hasThemeIcon(iconName)) { + return QIcon::fromTheme(iconName); + } } - return *this; -} + for (auto &&iconName : iconNames) { + // Try to get something from the theme anyway (i.e. a more generic fallback) + QIcon fallback = QIcon::fromTheme(iconName); + if (!fallback.availableSizes().isEmpty()) { + printWarning(iconName, QString{"(using fallback: \"%1\")"}.arg(fallback.name())); + return fallback; + } + } + + // Build error string + QStringList requested; + for (auto &&iconName : iconNames) { + requested << iconName; + } + QString missing = "{" + requested.join(", ") + "}"; + + // Nothing from the theme, so try to load from path if given + if (!fallbackPath.isEmpty()) { + QIcon fallback{fallbackPath}; + if (!fallback.availableSizes().isEmpty()) { + printWarning(missing, QString{"(using fallback: \"%1\")"}.arg(fallbackPath)); + return fallback; + } + } + + // Meh. + printWarning(missing); + return {}; +} -#endif +}