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
=== modified file 'src/appmenuplatformmenubar.cpp'
--- src/appmenuplatformmenubar.cpp 2014-12-13 15:38:51 +0000
+++ src/appmenuplatformmenubar.cpp 2016-11-24 02:19:42 +0000
@@ -35,6 +35,7 @@
35#include <QDebug>35#include <QDebug>
36#include <QList>36#include <QList>
37#include <QVariant>37#include <QVariant>
38#include <QX11Info>
3839
39#undef signals // Needed to make sure we can include gtk.h40#undef signals // Needed to make sure we can include gtk.h
40#include <gtk/gtk.h>41#include <gtk/gtk.h>
@@ -229,6 +230,10 @@
229/* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */230/* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */
230static QString gtkSetting(const gchar *propertyName)231static QString gtkSetting(const gchar *propertyName)
231{232{
233 if (!QX11Info::isPlatformX11()) {
234 return QString();
235 }
236
232 GtkSettings *settings = gtk_settings_get_default();237 GtkSettings *settings = gtk_settings_get_default();
233 gchararray value;238 gchararray value;
234 g_object_get(settings, propertyName, &value, NULL);239 g_object_get(settings, propertyName, &value, NULL);
@@ -261,13 +266,19 @@
261GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()266GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()
262 : QGnomeTheme()267 : QGnomeTheme()
263{268{
264 int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);269 if (QX11Info::isPlatformX11()) {
265 gtk_init(0, 0);270 int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
266 XSetErrorHandler(oldErrorHandler);271 gtk_init(0, 0);
272 XSetErrorHandler(oldErrorHandler);
273 }
267}274}
268275
269QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const276QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const
270{277{
278 if (!QX11Info::isPlatformX11()) {
279 return QVariant(QVariant::String);
280 }
281
271 switch (hint) {282 switch (hint) {
272 case QPlatformTheme::SystemIconThemeName:283 case QPlatformTheme::SystemIconThemeName:
273 return QVariant(gtkSetting("gtk-icon-theme-name"));284 return QVariant(gtkSetting("gtk-icon-theme-name"));
274285
=== modified file 'src/appmenuplatformsystemtrayicon.cpp'
--- src/appmenuplatformsystemtrayicon.cpp 2016-11-24 02:19:42 +0000
+++ src/appmenuplatformsystemtrayicon.cpp 2016-11-24 02:19:42 +0000
@@ -181,7 +181,7 @@
181181
182QString AppMenuPlatformSystemTrayIcon::iconThemePath() const182QString AppMenuPlatformSystemTrayIcon::iconThemePath() const
183{183{
184 return iconCache.themePath();184 return iconCache.themePath(m_icon);
185}185}
186186
187QString AppMenuPlatformSystemTrayIcon::iconName() const187QString AppMenuPlatformSystemTrayIcon::iconName() const
188188
=== modified file 'src/iconcache.cpp'
--- src/iconcache.cpp 2014-12-13 15:38:51 +0000
+++ src/iconcache.cpp 2016-11-24 02:19:42 +0000
@@ -29,8 +29,7 @@
2929
30IconCache::IconCache(QObject *parent):30IconCache::IconCache(QObject *parent):
31 QObject(parent),31 QObject(parent),
32 m_temporaryDir(Q_NULLPTR),32 m_temporaryDir(Q_NULLPTR)
33 m_initialized(false)
34{33{
35}34}
3635
@@ -41,13 +40,41 @@
41 }40 }
42}41}
4342
44QString IconCache::themePath()43QString IconCache::themePath(const QIcon &icon)
45{44{
46 if (!m_initialized) {45 if (!m_temporaryDir) {
47 QString path = QDir::tempPath() + QStringLiteral("/iconcache-XXXXXX");46 QString dir;
47
48 if (!getenv("SNAP")) {
49 dir = QDir::tempPath();
50 } else {
51 // Try to get the .cache from $XDG_CACHE_HOME, if it's not set,
52 // it has to be in ~/.cache as per XDG standard
53 dir = QString::fromUtf8(getenv("XDG_CACHE_HOME"));
54 if (dir.isEmpty()) {
55 dir = QDir::cleanPath(QDir::homePath() + QStringLiteral("/.cache"));
56 }
57
58 QDir d(dir);
59 if (!d.exists()) {
60 d.mkpath(".");
61 }
62 }
63
64 QString path = dir + QStringLiteral("/qt-tray-iconcache-XXXXXX");
48 m_temporaryDir = new QTemporaryDir(path);65 m_temporaryDir = new QTemporaryDir(path);
49 m_initialized = true;66 }
50 }67
68 if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) {
69 QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME"));
70
71 if (dataHome.isEmpty()) {
72 dataHome = QDir::homePath() + "/.local/share";
73 }
74
75 return QDir::cleanPath(dataHome + "/icons");
76 }
77
51 return m_temporaryDir->path();78 return m_temporaryDir->path();
52}79}
5380
5481
=== modified file 'src/iconcache.h'
--- src/iconcache.h 2014-12-13 15:38:51 +0000
+++ src/iconcache.h 2016-11-24 02:19:42 +0000
@@ -39,13 +39,12 @@
3939
40 static const int MaxIconCount;40 static const int MaxIconCount;
4141
42 QString themePath();42 QString themePath(const QIcon &icon = QIcon());
43 QString nameForIcon(const QIcon &icon);43 QString nameForIcon(const QIcon &icon);
4444
45private:45private:
46 QTemporaryDir *m_temporaryDir;46 QTemporaryDir *m_temporaryDir;
47 mutable QList<qint64> m_cacheKeys;47 mutable QList<qint64> m_cacheKeys;
48 bool m_initialized;
4948
50 void cacheIcon(qint64 key, const QIcon &);49 void cacheIcon(qint64 key, const QIcon &);
51 void trimCache();50 void trimCache();

Subscribers

People subscribed via source and target branches