1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
31 void printWarning(const QString &iconName, const QString &extra = {})
33 static std::set<QString> warnedAbout;
34 if (warnedAbout.insert(iconName).second) {
35 qWarning() << "Missing icon:" << iconName << qPrintable(extra);
42 QIcon get(const QString &iconName, const QString &fallbackPath)
44 return get(std::vector<QString>{iconName}, fallbackPath);
48 QIcon get(const std::vector<QString> &iconNames, const QString &fallbackPath)
50 for (auto &&iconName : iconNames) {
52 if (QIcon::hasThemeIcon(iconName)) {
53 return QIcon::fromTheme(iconName);
57 for (auto &&iconName : iconNames) {
58 // Try to get something from the theme anyway (i.e. a more generic fallback)
59 QIcon fallback = QIcon::fromTheme(iconName);
60 if (!fallback.availableSizes().isEmpty()) {
61 printWarning(iconName, QString{"(using fallback: \"%1\")"}.arg(fallback.name()));
67 QStringList requested;
68 for (auto &&iconName : iconNames) {
69 requested << iconName;
71 QString missing = "{" + requested.join(", ") + "}";
73 // Nothing from the theme, so try to load from path if given
74 if (!fallbackPath.isEmpty()) {
75 QIcon fallback{fallbackPath};
76 if (!fallback.availableSizes().isEmpty()) {
77 printWarning(missing, QString{"(using fallback: \"%1\")"}.arg(fallbackPath));
83 printWarning(missing);