From fb86c5a47060b11a7fa6ee4d93ff51f052b904aa Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 16 May 2023 22:01:03 +0300 Subject: [PATCH] QGuiApplication: Remove .desktop suffix in setDesktopFileName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The desktop file name should not contain ".desktop" suffix, but some applications still specify it anyway because of the ambiguity in the documentation that was fixed in 0c5135a9dfa6140d23d86b001c3054891c22dcb9. This change makes setDesktopFileName remove ".desktop" suffix so desktopFileName always returns a desktop file name with correct format and its users don't need to chop ".desktop". Pick-to: 6.5 Change-Id: If5abccaf3bf976449cada8891fff887870e45b5f Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qguiapplication.cpp | 10 ++++++++++ .../gui/kernel/qguiapplication/tst_qguiapplication.cpp | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3ee1c54826..fe40e05536 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -792,6 +793,15 @@ void QGuiApplication::setDesktopFileName(const QString &name) if (!QGuiApplicationPrivate::desktopFileName) QGuiApplicationPrivate::desktopFileName = new QString; *QGuiApplicationPrivate::desktopFileName = name; + if (name.endsWith(QLatin1String(".desktop"))) { // ### Qt 7: remove + const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name); + if (!filePath.isEmpty()) { + qWarning("QGuiApplication::setDesktopFileName: the specified desktop file name " + "ends with .desktop. For compatibility reasons, the .desktop suffix will " + "be removed. Please specify a desktop file name without .desktop suffix"); + (*QGuiApplicationPrivate::desktopFileName).chop(8); + } + } } QString QGuiApplication::desktopFileName() diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 5a206d8177..8542ce300f 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -122,8 +122,8 @@ void tst_QGuiApplication::desktopFileName() QCOMPARE(QGuiApplication::desktopFileName(), QString()); - QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop"); - QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop")); + QGuiApplication::setDesktopFileName("io.qt.QGuiApplication"); + QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication")); QGuiApplication::setDesktopFileName(QString()); QCOMPARE(QGuiApplication::desktopFileName(), QString());