From 61ad604ad41607be97efea5a18cd4d9fb7ddca73 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Thu, 13 Aug 2015 16:37:07 +0200 Subject: Add QGuiApplication::setDesktopFileName() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This property might be set by applications whose desktop entry file name cannot be determined by heuristics already in place. It is particularly useful for QtWayland as it can be used to determine the app_id simply by stripping the ".desktop" suffix from this property. Without a correct app_id, Wayland compositors won't be able to e.g. show the application icon on task managers. This property is also very interesting for X11 as there are various desktop environments trying to map windows to launchers. It will be possible to export desktopFileName as a xproperty, making such mapping less error prone. Change-Id: I0fef23f28f383639e625379ab46e36aecb338ac4 Reviewed-by: Martin Gräßlin Reviewed-by: Thiago Macieira Reviewed-by: David Faure --- src/gui/kernel/qguiapplication.cpp | 31 ++++++++++++++++++++++ src/gui/kernel/qguiapplication.h | 4 +++ src/gui/kernel/qguiapplication_p.h | 1 + .../kernel/qguiapplication/tst_qguiapplication.cpp | 16 +++++++++++ 4 files changed, 52 insertions(+) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 5e2a5b86a4..898f14f8cb 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -143,6 +143,7 @@ QIcon *QGuiApplicationPrivate::app_icon = 0; QString *QGuiApplicationPrivate::platform_name = 0; QString *QGuiApplicationPrivate::displayName = 0; +QString *QGuiApplicationPrivate::desktopFileName = 0; QPalette *QGuiApplicationPrivate::app_pal = 0; // default application palette @@ -604,6 +605,8 @@ QGuiApplication::~QGuiApplication() QGuiApplicationPrivate::platform_name = 0; delete QGuiApplicationPrivate::displayName; QGuiApplicationPrivate::displayName = 0; + delete QGuiApplicationPrivate::desktopFileName; + QGuiApplicationPrivate::desktopFileName = 0; } QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags) @@ -644,6 +647,34 @@ QString QGuiApplication::applicationDisplayName() return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName(); } +/*! + \property QGuiApplication::desktopFileName + \brief the base name of the desktop entry for this application + \since 5.7 + + This is the file name, without the full path, of the desktop entry + that represents this application according to the freedesktop desktop + entry specification. + + This property gives a precise indication of what desktop entry represents + the application and it is needed by the windowing system to retrieve + such information without resorting to imprecise heuristics. + + The latest version of the freedesktop desktop entry specification can be obtained + \l{http://standards.freedesktop.org/desktop-entry-spec/latest/}{here}. +*/ +void QGuiApplication::setDesktopFileName(const QString &name) +{ + if (!QGuiApplicationPrivate::desktopFileName) + QGuiApplicationPrivate::desktopFileName = new QString; + *QGuiApplicationPrivate::desktopFileName = name; +} + +QString QGuiApplication::desktopFileName() +{ + return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString(); +} + /*! Returns the most recently shown modal window. If no modal windows are visible, this function returns zero. diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index c89268d8d4..6eb26e8b06 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -67,6 +67,7 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication Q_OBJECT Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon) Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName) + Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) Q_PROPERTY(QString platformName READ platformName STORED false) Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed) @@ -82,6 +83,9 @@ public: static void setApplicationDisplayName(const QString &name); static QString applicationDisplayName(); + static void setDesktopFileName(const QString &name); + static QString desktopFileName(); + static QWindowList allWindows(); static QWindowList topLevelWindows(); static QWindow *topLevelAt(const QPoint &pos); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0559442049..6dc8735f86 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -183,6 +183,7 @@ public: static QIcon *app_icon; static QString *platform_name; static QString *displayName; + static QString *desktopFileName; QWindowList modalWindowList; static void showModalWindow(QWindow *window); diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 2ddfdad7e4..5cade82b6b 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -62,6 +62,7 @@ class tst_QGuiApplication: public tst_QCoreApplication private slots: void cleanup(); void displayName(); + void desktopFileName(); void firstWindowTitle(); void windowIcon(); void focusObject(); @@ -101,6 +102,21 @@ void tst_QGuiApplication::displayName() QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application")); } +void tst_QGuiApplication::desktopFileName() +{ + int argc = 1; + char *argv[] = { const_cast("tst_qguiapplication") }; + QGuiApplication app(argc, argv); + + QCOMPARE(QGuiApplication::desktopFileName(), QString()); + + QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop"); + QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop")); + + QGuiApplication::setDesktopFileName(QString()); + QCOMPARE(QGuiApplication::desktopFileName(), QString()); +} + void tst_QGuiApplication::firstWindowTitle() { int argc = 3; -- cgit v1.2.3