https://bugs.kde.org/show_bug.cgi?id=502128

            Bug ID: 502128
           Summary: iconSourceUrl algorithm is overcomplicated and does
                    not account for a simple case when the icon is
                    correctly exported and properly specified in the
                    exported desktop file
    Classification: Applications
           Product: systemsettings
           Version: 6.3.3
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: kcm_flatpak
          Assignee: plasma-b...@kde.org
          Reporter: m...@ratijas.tk
                CC: joshiesuha...@gmail.com
  Target Milestone: ---

SUMMARY

Flatpak KCM can not find a bunch of icons for the apps, in particular: Telegram
Desktop, LocalSend, LibreOffice, Kdenlive and Shotcut. The
`FlatpakHelper::iconSourceUrl` algorithm[1] goes an extra mile only to fail to
locate the proper icons which were specified in the exported desktop entries
the whole time!

Take a look at **LocalSend** for example:

```
$ cd
/var/lib/flatpak/app/org.localsend.localsend_app/x86_64/stable/306064fe957c0bc287c6353de49295eb5302335bcecd527f08e8a73f249e454a

$ tree export
export
├── bin
│   └── org.localsend.localsend_app
└── share
    ├── applications
    │   └── org.localsend.localsend_app.desktop
    ├── icons
    │   └── hicolor
    │       ├── 32x32
    │       │   └── apps
    │       │       └── org.localsend.localsend_app-tray.png
    │       └── 512x512
    │           └── apps
    │               └── org.localsend.localsend_app.png
    └── metainfo
        └── org.localsend.localsend_app.metainfo.xml

$ cat export/share/applications/org.localsend.localsend_app.desktop

[Desktop Entry]
[...]
Name=LocalSend
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=localsend
--file-forwarding org.localsend.localsend_app @@u %U @@
Icon=org.localsend.localsend_app
X-Flatpak=org.localsend.localsend_app
```

the algorithm has no idea about "512x512" directory, it just take some random
`nextDir = dir.entryList().at(0);` which on my machine consistently ends up
being "32x32" — the one which contains tray icon instead of the app icon.

Let's take **Shotcut** for example. Things are even funnier there: for some
reason it provides exported *scalable* icons of Glaxnimate:

```
files/share/icons
└── hicolor
    ├── 128x128
    │   └── apps
    │       └── org.shotcut.Shotcut.png
    ├── 512x512
    │   └── apps
    │       ├── glaxnimate.png
    │       └── org.mattbas.Glaxnimate.png
    ├── 64x64
    │   └── apps
    │       └── org.shotcut.Shotcut.png
    └── scalable
        └── apps
            ├── glaxnimate.svg
            └── org.mattbas.Glaxnimate.svg
```

So the algorithm falls for `if (dir.exists(QStringLiteral("scalable")))`
despite the Shotcut icon not being there.


**Telegram** exports Icon=org.telegram.desktop, but provides a symbolic version
with a "-symbolic" suffix which hides it from the algorithm while masking other
directories than "hicolor/symbolic".

**Kdenlive** provides its scalable icon with *.svgz extension which the
algorithm doesn't account for.

And finally, **LibreOffice** isn't exactly a single app: it is a bundle of
apps, with a central .desktop launcher named simply
org.libreoffice.LibreOffice.desktop; however its Icon= is not as simple — it
has a suffix which algorithm has no idea about:
"org.libreoffice.LibreOffice.startcenter.png".

STEPS TO REPRODUCE
1. Install some flatpak apps, including the aforementioned ones.
2. Add some debug logs to the iconSourceUrl function.
3. Open Flatpak KCM

OBSERVED RESULT
Some apps are missing their icons, replaced with a generic one instead.

EXPECTED RESULT
Reuse the wheel instead of reinventing it.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.6-arch1-1 (64-bit)
Graphics Platform: X11


ADDITIONAL INFORMATION

[1] The `FlatpakHelper::iconSourceUrl` algorithm:

```
QUrl iconSourceUrl(const QString &displayName, const QString &flatpakName,
const QString &appBaseDirectory)
{
    QString dirPath = appBaseDirectory +
QStringLiteral("/files/share/icons/hicolor/");
    QDir dir(dirPath);
    dir.setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);

    QString nextDir;
    if (dir.exists(QStringLiteral("scalable"))) {
        nextDir = QStringLiteral("scalable");
    } else if (dir.exists(QStringLiteral("symbolic"))) {
        nextDir = QStringLiteral("symbolic");
    } else if (!dir.isEmpty()) {
        nextDir = dir.entryList().at(0);
    } else {
        return QUrl();
    }
    dir.cd(nextDir + QStringLiteral("/apps"));

    QString file = flatpakName + QStringLiteral(".png");
    if (!dir.exists(file)) {
        file = flatpakName + QStringLiteral(".svg");
        if (!dir.exists(file)) {
            file = displayName.toLower() + QStringLiteral(".png");
            if (!dir.exists(file)) {
                file = displayName.toLower() + QStringLiteral(".svg");
                if (!dir.exists(file)) {
                    return QUrl();
                }
            }
        }
    }
    return QUrl::fromLocalFile(dir.absoluteFilePath(file));
}
```

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to