diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index 453f0d1899..ddc40574c0 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -2707,11 +2707,15 @@ void AbstractClient::setDesktopFileName(QByteArray name) QString AbstractClient::iconFromDesktopFile() const { - if (m_desktopFileName.isEmpty()) { + return iconFromDesktopFile(QFile::decodeName(m_desktopFileName)); +} + +QString AbstractClient::iconFromDesktopFile(const QString &desktopFileName) +{ + if (desktopFileName.isEmpty()) { return {}; } - const QString desktopFileName = QString::fromUtf8(m_desktopFileName); QString desktopFilePath; if (QDir::isAbsolutePath(desktopFileName)) { @@ -2726,6 +2730,9 @@ QString AbstractClient::iconFromDesktopFile() const desktopFilePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, desktopFileName + QLatin1String(".desktop")); } + if (desktopFilePath.isEmpty()) { + return {}; + } KDesktopFile df(desktopFilePath); return df.readIcon(); diff --git a/src/abstract_client.h b/src/abstract_client.h index 4e68465a4b..3bd7a4399f 100644 --- a/src/abstract_client.h +++ b/src/abstract_client.h @@ -878,6 +878,13 @@ public: QRect fullscreenGeometryRestore() const; + /** + * Helper function to compute the icon out of an application id defined by @p fileName + * + * @returns an icon name that can be used with QIcon::fromTheme() + */ + static QString iconFromDesktopFile(const QString &fileName); + public Q_SLOTS: virtual void closeWindow() = 0;