summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2018-04-11 16:53:56 +0300
committerAlexander Volkov <a.volkov@rusbitech.ru>2018-06-22 10:28:33 +0000
commitd640dbf730b392640d5497a789e95fa7d88f99fb (patch)
tree88c30e50a7ba60c306b26b63450ef08f85c5dd57
parentc4928e99e9e571890ddfc08ff80139a1dba5fb5d (diff)
QDBusTrayIcon: Avoid needless initialization of a global var
TempFileTemplate is initialized each time an application starts. It leads to the call of QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation) which is slow and can even change permissions of the runtime directory. Use a static wrapper function to initialize this variable only when needed. Change-Id: Ib620f9b842c88103c67f8dfab200f4d39c9981ee Reviewed-by: Dmitry Shachnev <mitya57@gmail.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
index 2153924ec8..e81d272d4f 100644
--- a/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
+++ b/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon.cpp
@@ -90,12 +90,17 @@ static QString iconTempPath()
static const QString KDEItemFormat = QStringLiteral("org.kde.StatusNotifierItem-%1-%2");
static const QString KDEWatcherService = QStringLiteral("org.kde.StatusNotifierWatcher");
-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");
static int instanceCount = 0;
+static inline QString tempFileTemplate()
+{
+ static const QString TempFileTemplate = iconTempPath() + QLatin1String("/qt-trayicon-XXXXXX.png");
+ return TempFileTemplate;
+}
+
/*!
\class QDBusTrayIcon
\internal
@@ -206,7 +211,7 @@ QTemporaryFile *QDBusTrayIcon::tempIcon(const QIcon &icon)
if (!necessary)
return nullptr;
qreal dpr = qGuiApp->devicePixelRatio();
- QTemporaryFile *ret = new QTemporaryFile(TempFileTemplate, this);
+ QTemporaryFile *ret = new QTemporaryFile(tempFileTemplate(), this);
ret->open();
icon.pixmap(QSize(22 * dpr, 22 * dpr)).save(ret);
ret->close();