Merge lp:~unity-api-team/unity-scope-click/remove_accents_from_search into lp:unity-scope-click

Proposed by Antti Kaijanmäki
Status: Merged
Approved by: dobey
Approved revision: 422
Merged at revision: 422
Proposed branch: lp:~unity-api-team/unity-scope-click/remove_accents_from_search
Merge into: lp:unity-scope-click
Diff against target: 140 lines (+80/-13)
3 files modified
libclickscope/click/interface.cpp (+38/-13)
libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop (+13/-0)
libclickscope/tests/test_interface.cpp (+29/-0)
To merge this branch: bzr merge lp:~unity-api-team/unity-scope-click/remove_accents_from_search
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
dobey (community) Approve
Review via email: mp+286799@code.launchpad.net

Commit message

libclickscope/click/interface.cpp: remove accents and use QString::compare() to find matches

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
420. By Antti Kaijanmäki

Add test.

421. By Antti Kaijanmäki

Accended -> Accented

422. By Antti Kaijanmäki

add second test

Revision history for this message
dobey (dobey) wrote :

Looks ok.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/interface.cpp'
2--- libclickscope/click/interface.cpp 2016-01-04 20:56:17 +0000
3+++ libclickscope/click/interface.cpp 2016-03-03 14:30:59 +0000
4@@ -31,6 +31,7 @@
5 #include <QDir>
6 #include <QProcess>
7 #include <QStandardPaths>
8+#include <QString>
9 #include <QTimer>
10
11 #include <cstdio>
12@@ -56,6 +57,34 @@
13
14 #include <click/click-i18n.h>
15
16+namespace {
17+
18+/* Thanks to
19+ * - http://stackoverflow.com/a/14031349
20+ * - http://stackoverflow.com/questions/12278448/removing-accents-from-a-qstring
21+ */
22+QString unaccent(const QString &str)
23+{
24+ QString tmp = str.normalized(QString::NormalizationForm_KD,
25+ QChar::currentUnicodeVersion());
26+ QString ret;
27+ for (int i = 0, j = tmp.length();
28+ i < j;
29+ i++) {
30+
31+ // strip diacritic marks
32+ if (tmp.at(i).category() != QChar::Mark_NonSpacing &&
33+ tmp.at(i).category() != QChar::Mark_SpacingCombining &&
34+ tmp.at(i).category() != QChar::Mark_Enclosing) {
35+ ret.append(tmp.at(i));
36+ }
37+ }
38+
39+ return ret;
40+}
41+
42+}
43+
44 namespace click {
45
46 const std::unordered_set<std::string>& nonClickDesktopFiles()
47@@ -343,26 +372,22 @@
48 if (search_query.empty()) {
49 result.push_back(app);
50 } else {
51- std::string lquery = search_query;
52- std::transform(lquery.begin(), lquery.end(),
53- lquery.begin(), ::tolower);
54+ QString lquery = ::unaccent(QString::fromStdString(search_query));
55+
56 // Check keywords for the search query as well.
57- for (auto keyword: app.keywords) {
58- std::transform(keyword.begin(), keyword.end(),
59- keyword.begin(), ::tolower);
60- if (!keyword.empty()
61- && keyword.find(lquery) != std::string::npos) {
62+ for (auto kwd: app.keywords) {
63+ QString keyword = ::unaccent(QString::fromStdString(kwd));
64+ if (!keyword.isEmpty()
65+ && keyword.contains(lquery, Qt::CaseInsensitive)) {
66 result.push_back(app);
67 return;
68 }
69 }
70
71- std::string search_title = app.title;
72- std::transform(search_title.begin(), search_title.end(),
73- search_title.begin(), ::tolower);
74+ QString search_title = ::unaccent(QString::fromStdString(app.title));
75 // check the app title for the search query.
76- if (!search_title.empty()
77- && search_title.find(lquery) != std::string::npos) {
78+ if (!search_title.isEmpty()
79+ && search_title.contains(lquery, Qt::CaseInsensitive)) {
80 result.push_back(app);
81 }
82 }
83
84=== added file 'libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop'
85--- libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop 1970-01-01 00:00:00 +0000
86+++ libclickscope/tests/applications/user/com.ubuntu.accented_accented_0.5.29.desktop 2016-03-03 14:30:59 +0000
87@@ -0,0 +1,13 @@
88+[Desktop Entry]
89+Version=1.0
90+Type=Application
91+Terminal=false
92+Exec=aa-exec-click -p com.ubuntu.accented_accented_0.5.29 -- qmlscene ./ubuntu-accented-app.qml -I ./plugins
93+Icon=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.accented/./accented64.png
94+Name=Cámara
95+X-Ubuntu-Touch=true
96+X-Ubuntu-StageHint=SideStage
97+
98+Path=/usr/share/click/preinstalled/.click/users/@all/com.ubuntu.accented
99+X-Ubuntu-Old-Icon=./accented64.png
100+X-Ubuntu-Application-ID=com.ubuntu.accented_accented_0.5.29
101
102=== modified file 'libclickscope/tests/test_interface.cpp'
103--- libclickscope/tests/test_interface.cpp 2016-01-04 20:56:17 +0000
104+++ libclickscope/tests/test_interface.cpp 2016-03-03 14:30:59 +0000
105@@ -365,6 +365,35 @@
106 EXPECT_EQ(1, results.size());
107 }
108
109+TEST(ClickInterface, testFindAppAccented)
110+{
111+ QSharedPointer<click::KeyFileLocator> keyFileLocator(
112+ new click::KeyFileLocator(
113+ testing::systemApplicationsDirectoryForTesting(),
114+ testing::userApplicationsDirectoryForTesting()));
115+
116+ click::Interface iface(keyFileLocator);
117+
118+ auto results = iface.find_installed_apps("Cámara");
119+
120+ EXPECT_EQ(1, results.size());
121+}
122+
123+TEST(ClickInterface, testFindAppAccented2)
124+{
125+ QSharedPointer<click::KeyFileLocator> keyFileLocator(
126+ new click::KeyFileLocator(
127+ testing::systemApplicationsDirectoryForTesting(),
128+ testing::userApplicationsDirectoryForTesting()));
129+
130+ click::Interface iface(keyFileLocator);
131+
132+ auto results = iface.find_installed_apps("Camara");
133+
134+ EXPECT_EQ(1, results.size());
135+}
136+
137+
138 TEST(ClickInterface, testIsIconIdentifier)
139 {
140 EXPECT_TRUE(Interface::is_icon_identifier("contacts-app"));

Subscribers

People subscribed via source and target branches

to all changes: