Merge lp:~3v1n0/appmenu-qt5/icons-user-cache-on-snap into lp:appmenu-qt5

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 48
Merged at revision: 46
Proposed branch: lp:~3v1n0/appmenu-qt5/icons-user-cache-on-snap
Merge into: lp:appmenu-qt5
Prerequisite: lp:~3v1n0/appmenu-qt5/x11-usertime-on-activate
Diff against target: 138 lines (+50/-13)
4 files modified
src/appmenuplatformmenubar.cpp (+14/-3)
src/appmenuplatformsystemtrayicon.cpp (+1/-1)
src/iconcache.cpp (+34/-7)
src/iconcache.h (+1/-2)
To merge this branch: bzr merge lp:~3v1n0/appmenu-qt5/icons-user-cache-on-snap
Reviewer Review Type Date Requested Status
Lukáš Tinkl (community) Approve
Review via email: mp+311067@code.launchpad.net

Commit message

IconCache: get the proper theme path based on the fact we're using a themed icon or not

If an app uses QIcon::fromTheme then we only have the icon name of it,
and thus we need to return a valid icon theme path. Now, it's not possible
to return the whole list of dirs, so we just fallback to the home icons
older, so that users might in case add icons there.

In $SNAP world, when using desktop-launcher ~/.local/share/icons also
contains all the themes in from /usr/share/icons and potentially more
(depending on the wrapper used for launching) so, we can be quite flexible
with it.

Also when running in a snap, save icons in $XDG_CACHE_HOME or in the user
cache, but still in an indicator readable location

Description of the change

To post a comment you must log in.
48. By Marco Trevisan (Treviño)

IconCache: try to get $XDG_DATA_HOME as base icon folders

Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

LGTM, works fine

review: Approve
49. By Marco Trevisan (Treviño)

Merging with lp:~3v1n0/appmenu-qt5/avoid-x11-calls-in-other-envs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/appmenuplatformmenubar.cpp'
2--- src/appmenuplatformmenubar.cpp 2014-12-13 15:38:51 +0000
3+++ src/appmenuplatformmenubar.cpp 2016-11-24 02:19:42 +0000
4@@ -35,6 +35,7 @@
5 #include <QDebug>
6 #include <QList>
7 #include <QVariant>
8+#include <QX11Info>
9
10 #undef signals // Needed to make sure we can include gtk.h
11 #include <gtk/gtk.h>
12@@ -229,6 +230,10 @@
13 /* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */
14 static QString gtkSetting(const gchar *propertyName)
15 {
16+ if (!QX11Info::isPlatformX11()) {
17+ return QString();
18+ }
19+
20 GtkSettings *settings = gtk_settings_get_default();
21 gchararray value;
22 g_object_get(settings, propertyName, &value, NULL);
23@@ -261,13 +266,19 @@
24 GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()
25 : QGnomeTheme()
26 {
27- int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
28- gtk_init(0, 0);
29- XSetErrorHandler(oldErrorHandler);
30+ if (QX11Info::isPlatformX11()) {
31+ int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
32+ gtk_init(0, 0);
33+ XSetErrorHandler(oldErrorHandler);
34+ }
35 }
36
37 QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const
38 {
39+ if (!QX11Info::isPlatformX11()) {
40+ return QVariant(QVariant::String);
41+ }
42+
43 switch (hint) {
44 case QPlatformTheme::SystemIconThemeName:
45 return QVariant(gtkSetting("gtk-icon-theme-name"));
46
47=== modified file 'src/appmenuplatformsystemtrayicon.cpp'
48--- src/appmenuplatformsystemtrayicon.cpp 2016-11-24 02:19:42 +0000
49+++ src/appmenuplatformsystemtrayicon.cpp 2016-11-24 02:19:42 +0000
50@@ -181,7 +181,7 @@
51
52 QString AppMenuPlatformSystemTrayIcon::iconThemePath() const
53 {
54- return iconCache.themePath();
55+ return iconCache.themePath(m_icon);
56 }
57
58 QString AppMenuPlatformSystemTrayIcon::iconName() const
59
60=== modified file 'src/iconcache.cpp'
61--- src/iconcache.cpp 2014-12-13 15:38:51 +0000
62+++ src/iconcache.cpp 2016-11-24 02:19:42 +0000
63@@ -29,8 +29,7 @@
64
65 IconCache::IconCache(QObject *parent):
66 QObject(parent),
67- m_temporaryDir(Q_NULLPTR),
68- m_initialized(false)
69+ m_temporaryDir(Q_NULLPTR)
70 {
71 }
72
73@@ -41,13 +40,41 @@
74 }
75 }
76
77-QString IconCache::themePath()
78+QString IconCache::themePath(const QIcon &icon)
79 {
80- if (!m_initialized) {
81- QString path = QDir::tempPath() + QStringLiteral("/iconcache-XXXXXX");
82+ if (!m_temporaryDir) {
83+ QString dir;
84+
85+ if (!getenv("SNAP")) {
86+ dir = QDir::tempPath();
87+ } else {
88+ // Try to get the .cache from $XDG_CACHE_HOME, if it's not set,
89+ // it has to be in ~/.cache as per XDG standard
90+ dir = QString::fromUtf8(getenv("XDG_CACHE_HOME"));
91+ if (dir.isEmpty()) {
92+ dir = QDir::cleanPath(QDir::homePath() + QStringLiteral("/.cache"));
93+ }
94+
95+ QDir d(dir);
96+ if (!d.exists()) {
97+ d.mkpath(".");
98+ }
99+ }
100+
101+ QString path = dir + QStringLiteral("/qt-tray-iconcache-XXXXXX");
102 m_temporaryDir = new QTemporaryDir(path);
103- m_initialized = true;
104- }
105+ }
106+
107+ if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) {
108+ QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME"));
109+
110+ if (dataHome.isEmpty()) {
111+ dataHome = QDir::homePath() + "/.local/share";
112+ }
113+
114+ return QDir::cleanPath(dataHome + "/icons");
115+ }
116+
117 return m_temporaryDir->path();
118 }
119
120
121=== modified file 'src/iconcache.h'
122--- src/iconcache.h 2014-12-13 15:38:51 +0000
123+++ src/iconcache.h 2016-11-24 02:19:42 +0000
124@@ -39,13 +39,12 @@
125
126 static const int MaxIconCount;
127
128- QString themePath();
129+ QString themePath(const QIcon &icon = QIcon());
130 QString nameForIcon(const QIcon &icon);
131
132 private:
133 QTemporaryDir *m_temporaryDir;
134 mutable QList<qint64> m_cacheKeys;
135- bool m_initialized;
136
137 void cacheIcon(qint64 key, const QIcon &);
138 void trimCache();

Subscribers

People subscribed via source and target branches