Merge lp:~aacid/ubuntu-ui-toolkit/improveIconSearching into lp:ubuntu-ui-toolkit/staging

Proposed by Albert Astals Cid
Status: Merged
Approved by: Tim Peeters
Approved revision: 1901
Merged at revision: 1905
Proposed branch: lp:~aacid/ubuntu-ui-toolkit/improveIconSearching
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 161 lines (+73/-8)
6 files modified
src/Ubuntu/Components/plugin/unitythemeiconprovider.cpp (+24/-5)
tests/unit_x11/tst_iconprovider/icons/hicolor/index.theme (+10/-0)
tests/unit_x11/tst_iconprovider/icons/mockTheme/index.theme (+1/-0)
tests/unit_x11/tst_iconprovider/icons/mockTheme2/index.theme (+3/-0)
tests/unit_x11/tst_iconprovider/icons/mockTheme3/index.theme (+10/-0)
tests/unit_x11/tst_iconprovider/tst_iconprovider.cpp (+25/-3)
To merge this branch: bzr merge lp:~aacid/ubuntu-ui-toolkit/improveIconSearching
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Approve
Tim Peeters Approve
Review via email: mp+289204@code.launchpad.net

Commit message

Improve icon file searching

Leave searching in hicolor to the end
Do not search on icon themes we've already searched

Description of the change

hicolor is the last theme, don't search it before others, for example without this patch the "search" icon is searched at suru, Humanity, Adwaita, hicolor and finally ubuntu-mobile where it is found. If hicolor had a search icon we would be incorrectly returning it.

Also themes can have parents that are recursive, i.e. suru has Humanity and ubuntu-mobile as parents and ubuntu-mobile also has Humanity as parent, so when we get to ubuntu-mobile it doesn't make sense searching Humanity again.

To post a comment you must log in.
1900. By Albert Astals Cid

Add note explaining why hicolor is searched last

Revision history for this message
Tim Peeters (tpeeters) wrote :

Can we add a test to tst_iconprovider.cpp that checks the new behavior?

review: Needs Fixing
1901. By Albert Astals Cid

Tests that hicolor is last in search

Revision history for this message
Albert Astals Cid (aacid) wrote :

> Can we add a test to tst_iconprovider.cpp that checks the new behavior?

Added.

Revision history for this message
Tim Peeters (tpeeters) wrote :

Looks good, thanks! Happroving.

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/unitythemeiconprovider.cpp'
2--- src/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2015-02-27 07:55:51 +0000
3+++ src/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2016-03-16 15:03:14 +0000
4@@ -48,8 +48,14 @@
5 // Does a breadth-first search for an icon with any name in @names. Parent
6 // themes are only looked at if the current theme doesn't contain any icon
7 // in @names.
8- QPixmap findBestIcon(const QStringList &names, const QSize &size)
9+ QPixmap findBestIcon(const QStringList &names, const QSize &size, QSet<QString> *alreadySearchedThemes)
10 {
11+ if (alreadySearchedThemes) {
12+ if (alreadySearchedThemes->contains(name))
13+ return QPixmap();
14+ alreadySearchedThemes->insert(name);
15+ }
16+
17 Q_FOREACH(const QString &name, names) {
18 QPixmap pixmap = lookupIcon(name, size);
19 if (!pixmap.isNull())
20@@ -57,7 +63,7 @@
21 }
22
23 Q_FOREACH(IconThemePointer theme, parents) {
24- QPixmap pixmap = theme->findBestIcon(names, size);
25+ QPixmap pixmap = theme->findBestIcon(names, size, alreadySearchedThemes);
26 if (!pixmap.isNull())
27 return pixmap;
28 }
29@@ -100,8 +106,11 @@
30 directories.append(dir);
31 }
32
33- Q_FOREACH(const QString &name, settings.value("Icon Theme/Inherits").toStringList())
34- parents.append(IconTheme::get(name));
35+ Q_FOREACH(const QString &name, settings.value("Icon Theme/Inherits").toStringList()) {
36+ if (name != "hicolor") {
37+ parents.append(IconTheme::get(name));
38+ }
39+ }
40
41 // there can only be one index.theme
42 break;
43@@ -256,7 +265,17 @@
44
45 QPixmap UnityThemeIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
46 {
47- QPixmap pixmap = theme->findBestIcon(id.split(",", QString::SkipEmptyParts), requestedSize);
48+ // The hicolor theme will be searched last as per
49+ // https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
50+ QSet<QString> alreadySearchedThemes;
51+ const QStringList names = id.split(",", QString::SkipEmptyParts);
52+ QPixmap pixmap = theme->findBestIcon(names, requestedSize, &alreadySearchedThemes);
53+
54+ if (pixmap.isNull()) {
55+ IconTheme::IconThemePointer theme = IconTheme::get("hicolor");
56+ return theme->findBestIcon(names, requestedSize, nullptr);
57+ }
58+
59 *size = pixmap.size();
60 return pixmap;
61 }
62
63=== added directory 'tests/unit_x11/tst_iconprovider/icons/hicolor'
64=== added directory 'tests/unit_x11/tst_iconprovider/icons/hicolor/apps'
65=== added directory 'tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512'
66=== added file 'tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp.png'
67Binary files tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp.png 1970-01-01 00:00:00 +0000 and tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp.png 2016-03-16 15:03:14 +0000 differ
68=== added file 'tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp2.png'
69Binary files tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp2.png 1970-01-01 00:00:00 +0000 and tests/unit_x11/tst_iconprovider/icons/hicolor/apps/512/myapp2.png 2016-03-16 15:03:14 +0000 differ
70=== added file 'tests/unit_x11/tst_iconprovider/icons/hicolor/index.theme'
71--- tests/unit_x11/tst_iconprovider/icons/hicolor/index.theme 1970-01-01 00:00:00 +0000
72+++ tests/unit_x11/tst_iconprovider/icons/hicolor/index.theme 2016-03-16 15:03:14 +0000
73@@ -0,0 +1,10 @@
74+[Icon Theme]
75+Name=MockTheme3
76+
77+Directories=apps/512
78+
79+[apps/512]
80+Size=512
81+Context=Applications
82+Type=Fixed
83+
84
85=== modified file 'tests/unit_x11/tst_iconprovider/icons/mockTheme/index.theme'
86--- tests/unit_x11/tst_iconprovider/icons/mockTheme/index.theme 2015-02-18 12:19:02 +0000
87+++ tests/unit_x11/tst_iconprovider/icons/mockTheme/index.theme 2016-03-16 15:03:14 +0000
88@@ -1,5 +1,6 @@
89 [Icon Theme]
90 Name=MockTheme
91+Inherits=mockTheme2,mockTheme3
92
93 Directories=actions/scalable,apps/512
94
95
96=== added directory 'tests/unit_x11/tst_iconprovider/icons/mockTheme2'
97=== added file 'tests/unit_x11/tst_iconprovider/icons/mockTheme2/index.theme'
98--- tests/unit_x11/tst_iconprovider/icons/mockTheme2/index.theme 1970-01-01 00:00:00 +0000
99+++ tests/unit_x11/tst_iconprovider/icons/mockTheme2/index.theme 2016-03-16 15:03:14 +0000
100@@ -0,0 +1,3 @@
101+[Icon Theme]
102+Name=MockTheme2
103+Inherits=hicolor
104
105=== added directory 'tests/unit_x11/tst_iconprovider/icons/mockTheme3'
106=== added directory 'tests/unit_x11/tst_iconprovider/icons/mockTheme3/apps'
107=== added directory 'tests/unit_x11/tst_iconprovider/icons/mockTheme3/apps/512'
108=== added file 'tests/unit_x11/tst_iconprovider/icons/mockTheme3/apps/512/myapp.png'
109Binary files tests/unit_x11/tst_iconprovider/icons/mockTheme3/apps/512/myapp.png 1970-01-01 00:00:00 +0000 and tests/unit_x11/tst_iconprovider/icons/mockTheme3/apps/512/myapp.png 2016-03-16 15:03:14 +0000 differ
110=== added file 'tests/unit_x11/tst_iconprovider/icons/mockTheme3/index.theme'
111--- tests/unit_x11/tst_iconprovider/icons/mockTheme3/index.theme 1970-01-01 00:00:00 +0000
112+++ tests/unit_x11/tst_iconprovider/icons/mockTheme3/index.theme 2016-03-16 15:03:14 +0000
113@@ -0,0 +1,10 @@
114+[Icon Theme]
115+Name=MockTheme3
116+
117+Directories=apps/512
118+
119+[apps/512]
120+Size=512
121+Context=Applications
122+Type=Fixed
123+
124
125=== modified file 'tests/unit_x11/tst_iconprovider/tst_iconprovider.cpp'
126--- tests/unit_x11/tst_iconprovider/tst_iconprovider.cpp 2015-02-27 07:55:51 +0000
127+++ tests/unit_x11/tst_iconprovider/tst_iconprovider.cpp 2016-03-16 15:03:14 +0000
128@@ -65,9 +65,31 @@
129
130 UnityThemeIconProvider provider("mockTheme");
131 QSize returnedSize;
132- const QPixmap p = provider.requestPixmap(icon, &returnedSize, requestSize);
133- QCOMPARE(p.size(), resultSize);
134- QCOMPARE(returnedSize, resultSize);
135+ QPixmap p = provider.requestPixmap(icon, &returnedSize, requestSize);
136+ QCOMPARE(p.size(), resultSize);
137+ QCOMPARE(returnedSize, resultSize);
138+
139+ // Search again to make sure subsequent searches still work
140+ p = provider.requestPixmap(icon, &returnedSize, requestSize);
141+ QCOMPARE(p.size(), resultSize);
142+ QCOMPARE(returnedSize, resultSize);
143+ }
144+
145+ void test_hicolorLast()
146+ {
147+ QSize returnedSize;
148+ UnityThemeIconProvider provider("mockTheme");
149+
150+ // myapp is in MockTheme3 (white) and hicolor (black)
151+ // MockTheme3 one is returned since hicolor is last per spec
152+ QPixmap p = provider.requestPixmap("myapp", &returnedSize, QSize(-1, -1));
153+ QVERIFY(!p.isNull());
154+ QCOMPARE(QColor(p.toImage().pixel(0,0)), QColor(Qt::white));
155+
156+ // myapp2 is only in hicolor (black) so that's the one returned
157+ p = provider.requestPixmap("myapp2", &returnedSize, QSize(-1, -1));
158+ QVERIFY(!p.isNull());
159+ QCOMPARE(QColor(p.toImage().pixel(0,0)), QColor(Qt::black));
160 }
161 };
162

Subscribers

People subscribed via source and target branches