SVN_SILENT made messages (.desktop file)
[trojita.git] / src / Gui / IconLoader.h
blobf534e22ab852ca578336d9661d151645d9a04235
1 /* Copyright (C) 2006 - 2012 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef TROJITA_GUI_ICONLOADER_H
24 #define TROJITA_GUI_ICONLOADER_H
26 #include <QIcon>
28 namespace Gui
31 /** @short Wrapper around the QIcon::fromTheme with sane fallback
33 * The issue with the QIcon::fromTheme is that it does not realy work on non-X11
34 * platforms, unless you ship your own theme index and specify your theme name.
35 * In Trojitá, we do not really want to hardcode anything, because the
36 * preference is to use whatever is available from the current theme, but *also*
37 * provide an icon as a fallback. And that is exactly why this function is here.
39 * It is implemented inline in order to prevent a dependency from the Imap lib
40 * into the Gui lib.
41 * */
42 inline QIcon loadIcon(const QString &name)
44 // A QIcon(QString) constructor creates non-null QIcons, even though the resulting icon will
45 // not ever return a valid and usable pixmap. This means that we have to actually look at the
46 // icon's pixmap to find out what to return.
47 // If we do not do that, the GUI shows empty pixmaps instead of a text fallback, which is
48 // clearly suboptimal.
49 QIcon res = QIcon::fromTheme(name, QIcon(QString::fromUtf8(":/icons/%1").arg(name)));
50 if (res.pixmap(QSize(16, 16)).isNull()) {
51 return QIcon();
52 } else {
53 return res;
59 #endif // TROJITA_GUI_ICONLOADER_H