[PATCH] libtaskmanager: show Comment for launcher icons when appropriate
authorNate Graham <nate@kde.org>
Thu, 22 May 2025 15:06:52 +0000 (09:06 -0600)
committerAurélien COUDERC <coucouf@debian.org>
Mon, 21 Jul 2025 16:21:10 +0000 (18:21 +0200)
Right now, launcher icons get a caption equal to the app's GenericName,
if one is set in the metadata. If not, it gets no caption.

This differs from what Kicker and Kickoff Manager do: a more complex
behavior to show the Comment if the app has no GenericName or if its
GenericName is equal to its Name. Let's replicate the same logic here.

BUG: 504431
FIXED-IN: 6.4.0

(cherry picked from commit ae39f3219d6fc849fe8de0d1c165a572598082fe)

Co-authored-by: Nate Graham <nate@kde.org>
Gbp-Pq: Name upstream_45784326_libtaskmanager-show-Comment-for-launcher-icons-when-appropriate.patch

libtaskmanager/tasktools.cpp

index 873d9eac31745197fcbccf40129e7777e6402aad..e46d96382b50b3c9f1a207af5c4a7bf9e8e7424c 100644 (file)
 
 using namespace Qt::StringLiterals;
 
+static const QString appropriateCaption(const KService::Ptr &service)
+{
+    if (!service) {
+        return {};
+    }
+
+    const QString genericName = service->genericName();
+    if (!genericName.isEmpty() && genericName != service->name()) {
+        return genericName;
+    }
+
+    return service->comment();
+}
+
 namespace TaskManager
 {
 AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon)
@@ -65,7 +79,7 @@ AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon)
 
         if (service && url.path() == service->menuId()) {
             data.name = service->name();
-            data.genericName = service->genericName();
+            data.genericName = appropriateCaption(service);
             data.id = service->storageId();
 
             if (data.icon.isNull()) {
@@ -89,7 +103,7 @@ AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon)
 
             if (service && QUrl::fromLocalFile(service->entryPath()) == url) {
                 data.name = service->name();
-                data.genericName = service->genericName();
+                data.genericName = appropriateCaption(service);
                 data.id = service->storageId();
 
                 if (data.icon.isNull()) {
@@ -99,7 +113,7 @@ AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon)
                 KDesktopFile f(url.toLocalFile());
                 if (f.tryExec()) {
                     data.name = f.readName();
-                    data.genericName = f.readGenericName();
+                    data.genericName = appropriateCaption(KService::serviceByDesktopPath(url.toLocalFile()));
                     data.id = QUrl::fromLocalFile(f.fileName()).fileName();
 
                     if (data.icon.isNull()) {
@@ -144,7 +158,7 @@ AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon)
             const QString &desktopFile = service->entryPath();
 
             data.name = service->name();
-            data.genericName = service->genericName();
+            data.genericName = appropriateCaption(service);
             data.id = service->storageId();
 
             if (data.icon.isNull()) {