summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2017-01-13 17:17:14 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-06 14:15:31 +0000
commite1c93cc74b43d8c49208b38dde824298590ac788 (patch)
tree20f173e78309c8385f7943c56af71c80dafa0215
parentc876bb1f1333e47722e202b0916415e771137071 (diff)
QDBusTrayIcon: try use runtime or cache for icons
It's better to save icons in $XDG_RUNTIME_DIR or $XDG_CACHE_HOME paths than in $TMPDIR as these places are readable from the desktop environment when an app is ran confined in a sandbox (as in snap packages) Change-Id: I1a3e4c5714f8ea51034d18fb87cead87ed21d6be Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
-rw-r--r--src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
index b55ace357a..9baf94726d 100644
--- a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
+++ b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
@@ -65,9 +65,32 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(qLcTray, "qt.qpa.tray")
+static QString iconTempPath()
+{
+ QString tempPath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
+ if (!tempPath.isEmpty())
+ return tempPath;
+
+ tempPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+
+ if (!tempPath.isEmpty()) {
+ QDir tempDir(tempPath);
+ if (tempDir.exists())
+ return tempPath;
+
+ if (tempDir.mkpath(QStringLiteral("."))) {
+ const QFile::Permissions permissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;
+ if (QFile(tempPath).setPermissions(permissions))
+ return tempPath;
+ }
+ }
+
+ return QDir::tempPath();
+}
+
static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2");
static const QString KDEWatcherService = QStringLiteral("org.kde.StatusNotifierWatcher");
-static const QString TempFileTemplate = QDir::tempPath() + QLatin1String("/qt-trayicon-XXXXXX.png");
+static const QString TempFileTemplate = iconTempPath() + QLatin1String("/qt-trayicon-XXXXXX.png");
static const QString XdgNotificationService = QStringLiteral("org.freedesktop.Notifications");
static const QString XdgNotificationPath = QStringLiteral("/org/freedesktop/Notifications");
static const QString DefaultAction = QStringLiteral("default");