[Kicker/App Entry] Try QIcon with path if no theme icon is found
AbandonedPublic

Authored by broulik on Mar 19 2017, 10:25 PM.

Details

Reviewers
hein
Group Reviewers
Plasma
Summary

Applications can specify an absolute file path for an icon which won't work with QIcon::fromTheme.
If a theme icon isn't find, first try to load it using an absolute path before falling back to an unknown icon.

BUG: 365131

Test Plan

5.9 branch?

Diff Detail

Repository
R119 Plasma Desktop
Lint
Lint Skipped
Unit
Unit Tests Skipped
broulik created this revision.Mar 19 2017, 10:25 PM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 19 2017, 10:25 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript

What's super weird about this one is that QIcon::fromTheme internally actually does

if (QDir::isAbsolutePath(name)) {
    return QIcon(name);
}

yet only with this patch I get an icon for .svg icons with an absolute path I configured. Maybe icon.availableSizes() is empty for svg images and thus the previously used fallback argument of fromTheme is always chosen.

hein edited edge metadata.Mar 20 2017, 11:14 AM

Please add a comment, and I wonder if the absolutePath check should maybe be in the code?

Note this patch breaks fallback loading in the case where an absolute path for an SVG or pixmap is set.
It's possibly still worth it?

I think your analysis is right, and QIcon::fromTheme(name, fallback) also checks availableSizes because it can't rely on all engines implementing the new isNull virtual.

KIconLoader does, but even Qt's own ones QSvgIconEngine and QPixmapIconEngine don't currently.

applets/kicker/plugin/appentry.cpp
107–109

This should be just:

icon = QIcon::fromTheme(m_service->icon();
if (icon.isNull()) {
icon = QIcon::fromTheme("unknown")
}

you don't need that bit in the middle.

ngraham added a subscriber: ngraham.Sep 4 2017, 1:50 PM
rkflx added subscribers: smartins, rkflx.EditedOct 31 2017, 10:48 PM

I keep stumbling upon this issue on bugzilla and wonder what we can do here?


Bugzillas (lxr will probably find even more cases):
https://bugs.kde.org/show_bug.cgi?id=371835
https://bugs.kde.org/show_bug.cgi?id=381442
https://bugs.kde.org/show_bug.cgi?id=315983
https://bugs.kde.org/show_bug.cgi?id=368951
https://bugs.kde.org/show_bug.cgi?id=365131

KIconLoader does, but even Qt's own ones QSvgIconEngine and QPixmapIconEngine don't currently.

I did fix QPixmapIcon and QSvgIconEngine,

This should mean we can change QIcon::fromTheme to check isNull() which will then implicitly solve this.

Yeah, putting workarounds everywhere isn't so appealing. My preference would be for a Qt fix, otherwise we'll be playing whack-a-mole here forever.

broulik abandoned this revision.Nov 15 2017, 10:29 PM