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>
This commit is contained in:
Marco Trevisan (Treviño) 2017-01-13 17:17:14 +01:00 committed by Shawn Rutledge
parent c876bb1f13
commit e1c93cc74b

View File

@ -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");