1 /***************************************************************************
2 * Copyright (C) 2005-2019 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);
41 QIcon get(const QString& iconName, const QString& fallbackPath)
43 return get(std::vector<QString>{iconName}, fallbackPath);
46 QIcon get(const std::vector<QString>& iconNames, const QString& fallbackPath)
48 for (auto&& iconName : iconNames) {
50 if (QIcon::hasThemeIcon(iconName)) {
51 return QIcon::fromTheme(iconName);
55 for (auto&& iconName : iconNames) {
56 // Try to get something from the theme anyway (i.e. a more generic fallback)
57 QIcon fallback = QIcon::fromTheme(iconName);
58 if (!fallback.availableSizes().isEmpty()) {
59 printWarning(iconName, QString{"(using fallback: \"%1\")"}.arg(fallback.name()));
65 QStringList requested;
66 for (auto&& iconName : iconNames) {
67 requested << iconName;
69 QString missing = "{" + requested.join(", ") + "}";
71 // Nothing from the theme, so try to load from path if given
72 if (!fallbackPath.isEmpty()) {
73 QIcon fallback{fallbackPath};
74 if (!fallback.availableSizes().isEmpty()) {
75 printWarning(missing, QString{"(using fallback: \"%1\")"}.arg(fallbackPath));
81 printWarning(missing);