Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frameworks
KIconThemes
Commits
13181b03
Commit
13181b03
authored
Nov 25, 2021
by
Janet Blackquill
🌈
Committed by
Nicolas Fella
Dec 03, 2021
Browse files
KIconLoader: prefer icons from current theme before falling back to other themes
BUG: 445804
parent
59cce6d4
Pipeline
#104770
passed with stage
in 47 seconds
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
autotests/kiconloader_unittest.cpp
View file @
13181b03
...
...
@@ -112,6 +112,12 @@ private Q_SLOTS:
QVERIFY
(
QFile
::
copy
(
QStringLiteral
(
":/test-22x22.png"
),
testIconsDir
.
filePath
(
QStringLiteral
(
"breeze/22x22/mimetypes/unknown.png"
))));
QVERIFY
(
QFile
::
copy
(
QStringLiteral
(
":/coloredsvgicon.svg"
),
testIconsDir
.
filePath
(
QStringLiteral
(
"breeze/22x22/apps/coloredsvgicon.svg"
))));
// prepare some icons for our actions test
// when querying breeze for 'one-two', we expect
// 'one' from breeze instead of oxygen's 'one-two'.
QVERIFY
(
QFile
::
copy
(
QStringLiteral
(
":/test-22x22.png"
),
testIconsDir
.
filePath
(
QStringLiteral
(
"oxygen/22x22/actions/one-two.png"
))));
QVERIFY
(
QFile
::
copy
(
QStringLiteral
(
":/test-22x22.png"
),
testIconsDir
.
filePath
(
QStringLiteral
(
"breeze/22x22/actions/one.png"
))));
QVERIFY
(
QFile
::
setPermissions
(
breezeThemeFile
,
QFileDevice
::
ReadOwner
|
QFileDevice
::
WriteOwner
));
KConfig
configFile
(
breezeThemeFile
);
KConfigGroup
iconThemeGroup
=
configFile
.
group
(
"Icon Theme"
);
...
...
@@ -332,6 +338,25 @@ private Q_SLOTS:
QVERIFY
(
QFile
::
exists
(
unknownPath
));
}
void
testCorrectFallback
()
{
// we want to prefer icons from the same theme
// so if we have something like:
/*
oxygen:
one-two
breeze:
one
*/
// and we ask for 'one-two', we expect to see 'one' from breeze instead
// of 'one-two' from oxygen.
QString
path
;
KIconLoader
::
global
()
->
loadIcon
(
QStringLiteral
(
"one-two"
),
KIconLoader
::
Desktop
,
24
,
KIconLoader
::
DefaultState
,
QStringList
(),
&
path
);
QVERIFY
(
path
.
contains
(
"breeze/22x22/actions"
));
}
void
testPathStore
()
{
QString
path
;
...
...
src/kiconloader.cpp
View file @
13181b03
...
...
@@ -1021,12 +1021,7 @@ QString KIconLoaderPrivate::findMatchingIcon(const QString &name, int size, qrea
{
const_cast
<
KIconLoaderPrivate
*>
(
this
)
->
initIconThemes
();
// Do two passes through themeNodes.
//
// The first pass looks for an exact match in each themeNode one after the other.
// If one is found and it is an app icon then return that icon.
//
// In the next pass (assuming the first pass failed), it looks for
// This looks for the exact match and its
// generic fallbacks in each themeNode one after the other.
// In theory we should only do this for mimetype icons, not for app icons,
...
...
@@ -1036,22 +1031,17 @@ QString KIconLoaderPrivate::findMatchingIcon(const QString &name, int size, qrea
// Once everyone uses that to look up mimetype icons, we can kill the fallback code
// from this method.
for
(
KIconThemeNode
*
themeNode
:
std
::
as_const
(
links
))
{
const
QString
path
=
themeNode
->
theme
->
iconPathByName
(
name
,
size
,
KIconLoader
::
MatchBest
,
scale
);
if
(
!
path
.
isEmpty
())
{
return
path
;
}
}
if
(
name
.
endsWith
(
QLatin1String
(
"-x-generic"
)))
{
return
QString
();
// no further fallback
}
bool
genericFallback
=
false
;
bool
genericFallback
=
name
.
endsWith
(
QLatin1String
(
"-x-generic"
));;
QString
path
;
for
(
KIconThemeNode
*
themeNode
:
std
::
as_const
(
links
))
{
QString
currentName
=
name
;
while
(
!
currentName
.
isEmpty
())
{
path
=
themeNode
->
theme
->
iconPathByName
(
currentName
,
size
,
KIconLoader
::
MatchBest
,
scale
);
if
(
!
path
.
isEmpty
())
{
return
path
;
}
if
(
genericFallback
)
{
// we already tested the base name
break
;
...
...
@@ -1088,16 +1078,6 @@ QString KIconLoaderPrivate::findMatchingIcon(const QString &name, int size, qrea
break
;
}
}
if
(
currentName
.
isEmpty
())
{
break
;
}
// qCDebug(KICONTHEMES) << "Looking up" << currentName;
path
=
themeNode
->
theme
->
iconPathByName
(
currentName
,
size
,
KIconLoader
::
MatchBest
,
scale
);
if
(
!
path
.
isEmpty
())
{
return
path
;
}
}
}
...
...
David Redondo
🏎
@davidre
mentioned in merge request
!63 (closed)
·
May 03, 2022
mentioned in merge request
!63 (closed)
mentioned in merge request !63
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment