Merge lp:~renatofilho/address-book-app/fix-1367906 into lp:address-book-app

Proposed by Renato Araujo Oliveira Filho
Status: Superseded
Proposed branch: lp:~renatofilho/address-book-app/fix-1367906
Merge into: lp:address-book-app
Diff against target: 254 lines (+177/-10)
6 files modified
src/imports/Ubuntu/Contacts/ContactListModel.qml (+22/-10)
src/imports/Ubuntu/Contacts/contacts.cpp (+16/-0)
src/imports/Ubuntu/Contacts/contacts.h (+1/-0)
tests/data/tst_ContactListModel_data.vcf (+30/-0)
tests/qml/CMakeLists.txt (+2/-0)
tests/qml/tst_ContactListModel.qml (+106/-0)
To merge this branch: bzr merge lp:~renatofilho/address-book-app/fix-1367906
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+244787@code.launchpad.net

This proposal has been superseded by a proposal from 2014-12-15.

Commit message

Implemented search for unaccented contact names.

To post a comment you must log in.
351. By Renato Araujo Oliveira Filho

Fixed contact filter when using contact manager != "galera"

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/imports/Ubuntu/Contacts/ContactListModel.qml'
2--- src/imports/Ubuntu/Contacts/ContactListModel.qml 2014-12-08 20:00:47 +0000
3+++ src/imports/Ubuntu/Contacts/ContactListModel.qml 2014-12-15 19:48:22 +0000
4@@ -16,6 +16,7 @@
5
6 import QtQuick 2.2
7 import QtContacts 5.0
8+import Ubuntu.Contacts 0.1
9
10 ContactModel {
11 id: root
12@@ -66,19 +67,30 @@
13 id: contactTermFilter
14
15 property string value: ""
16-
17- DetailFilter {
18- detail: ContactDetail.DisplayLabel
19- field: DisplayLabel.Label
20- value: contactTermFilter.value
21- matchFlags: DetailFilter.MatchContains
22- }
23-
24- DetailFilter {
25+ property var phoneNumberFilter: DetailFilter {
26 detail: ContactDetail.PhoneNumber
27 field: PhoneNumber.Number
28 value: contactTermFilter.value
29- matchFlags: DetailFilter.MatchPhoneNumber | DetailFilter.MatchContains
30+ matchFlags: (DetailFilter.MatchPhoneNumber | DetailFilter.MatchContains)
31+ }
32+
33+ filters: [
34+ DetailFilter {
35+ detail: ContactDetail.ExtendedDetail
36+ field: root.manager === "galera" ? ExtendedDetail.Data : ContactDetail.DisplayLabel
37+ value: root.manager === "galera" ? Contacts.normalized(contactTermFilter.value) : contactTermFilter.value
38+ matchFlags: DetailFilter.MatchContains
39+ }
40+ ]
41+
42+ onValueChanged: {
43+ var containsLetter = /^[a-zA-Z]/.test(value)
44+
45+ if (containsLetter && (filters.length > 1)) {
46+ filters = [filters[0]]
47+ } else if (!containsLetter) {
48+ filters = [filters[0], phoneNumberFilter]
49+ }
50 }
51 },
52 IntersectionFilter {
53
54=== modified file 'src/imports/Ubuntu/Contacts/contacts.cpp'
55--- src/imports/Ubuntu/Contacts/contacts.cpp 2014-07-05 22:00:02 +0000
56+++ src/imports/Ubuntu/Contacts/contacts.cpp 2014-12-15 19:48:22 +0000
57@@ -39,3 +39,19 @@
58
59 return initials;
60 }
61+
62+QString UbuntuContacts::normalized(const QString &value)
63+{
64+ QString s2 = value.normalized(QString::NormalizationForm_D);
65+ QString out;
66+
67+ for (int i=0, j=s2.length(); i<j; i++)
68+ {
69+ // strip diacritic marks
70+ if (s2.at(i).category() != QChar::Mark_NonSpacing &&
71+ s2.at(i).category() != QChar::Mark_SpacingCombining) {
72+ out.append(s2.at(i));
73+ }
74+ }
75+ return out;
76+}
77
78=== modified file 'src/imports/Ubuntu/Contacts/contacts.h'
79--- src/imports/Ubuntu/Contacts/contacts.h 2014-07-05 22:00:02 +0000
80+++ src/imports/Ubuntu/Contacts/contacts.h 2014-12-15 19:48:22 +0000
81@@ -28,6 +28,7 @@
82 UbuntuContacts(QObject *parent = 0);
83
84 Q_INVOKABLE QString contactInitialsFromString(const QString &value);
85+ Q_INVOKABLE QString normalized(const QString &value);
86 };
87
88 #endif //_UBUNTU_CONTACTS_H_
89
90=== added file 'tests/data/tst_ContactListModel_data.vcf'
91--- tests/data/tst_ContactListModel_data.vcf 1970-01-01 00:00:00 +0000
92+++ tests/data/tst_ContactListModel_data.vcf 2014-12-15 19:48:22 +0000
93@@ -0,0 +1,30 @@
94+BEGIN:VCARD
95+VERSION:3.0
96+UID:47bbbfcab7c9b8ef0e7375074d22ff54905174bd
97+X-QTPROJECT-EXTENDED-DETAIL:CLIENTPIDMAP;[\n "1"\n]\n
98+N:First;Last;;;
99+FN:First Last
100+X-QTPROJECT-FAVORITE:false;0
101+TEL:123456
102+CATEGORIES:F
103+END:VCARD
104+BEGIN:VCARD
105+VERSION:3.0
106+UID:e5bb57fc852541dfc9ad29d583a36f1c353b65ed
107+X-QTPROJECT-EXTENDED-DETAIL:CLIENTPIDMAP;[\n "1"\n]\n
108+N:Fulano;de;tal6;;
109+FN:Fulano de Tal6
110+X-QTPROJECT-FAVORITE:false;0
111+TEL:123678
112+CATEGORIES:F
113+END:VCARD
114+BEGIN:VCARD
115+VERSION:3.0
116+UID:0d753ce1005dde92f69e4ddb62222240691693a0
117+X-QTPROJECT-EXTENDED-DETAIL:CLIENTPIDMAP;[\n "1"\n]\n
118+N:Fulano;da;Silva1;;;
119+FN:Fulano da Silva1
120+X-QTPROJECT-FAVORITE:false;0
121+TEL:555666
122+CATEGORIES:F
123+END:VCARD
124
125=== modified file 'tests/qml/CMakeLists.txt'
126--- tests/qml/CMakeLists.txt 2014-11-10 20:14:36 +0000
127+++ tests/qml/CMakeLists.txt 2014-12-15 19:48:22 +0000
128@@ -22,6 +22,7 @@
129
130 if(QMLTESTRUNNER_BIN AND XVFB_RUN_BIN)
131 declare_qml_test("contact_list" tst_ContactList.qml)
132+ declare_qml_test("Contact_list_model" tst_ContactListModel.qml)
133 declare_qml_test("contact_editor" tst_ContactEditor.qml)
134 declare_qml_test("contact_avatar" tst_ContactAvatar.qml)
135 declare_qml_test("list_with_actions" tst_ListWithActions.qml)
136@@ -40,6 +41,7 @@
137 tst_ContactEditor.qml
138 tst_ContactAvatar.qml
139 tst_ContactList.qml
140+ tst_ContactListModel.qml
141 tst_ListWithActions.qml
142 tst_ContactPreviewPage.qml
143 tst_VCardParser.qml
144
145=== added file 'tests/qml/tst_ContactListModel.qml'
146--- tests/qml/tst_ContactListModel.qml 1970-01-01 00:00:00 +0000
147+++ tests/qml/tst_ContactListModel.qml 2014-12-15 19:48:22 +0000
148@@ -0,0 +1,106 @@
149+/*
150+ * Copyright (C) 2014 Canonical, Ltd.
151+ *
152+ * This program is free software; you can redistribute it and/or modify
153+ * it under the terms of the GNU General Public License as published by
154+ * the Free Software Foundation; version 3.
155+ *
156+ * This program is distributed in the hope that it will be useful,
157+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
158+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159+ * GNU General Public License for more details.
160+ *
161+ * You should have received a copy of the GNU General Public License
162+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
163+ */
164+
165+import QtQuick 2.2
166+import QtTest 1.0
167+import Ubuntu.Components 1.1
168+import Ubuntu.Test 0.1
169+import Ubuntu.Contacts 0.1
170+
171+Item {
172+ id: root
173+
174+ property var application
175+ property var contactListModelObj
176+
177+ width: units.gu(40)
178+ height: units.gu(80)
179+
180+ Component {
181+ id: contactListModelCmp
182+
183+ ContactListModel {
184+ id: contactListModel
185+
186+ property int contactCount: contacts ? contacts.length : 0
187+
188+ manager: "memory"
189+ Component.onCompleted: importContacts(Qt.resolvedUrl("../data/tst_ContactListModel_data.vcf"))
190+ }
191+ }
192+
193+ UbuntuTestCase {
194+ id: contactListModelTestCase
195+ name: 'contactListModelTestCase'
196+
197+ when: windowShown
198+
199+ function init()
200+ {
201+ root.contactListModelObj = contactListModelCmp.createObject(root)
202+ //waitForRendering(root.contactListModelObj)
203+ }
204+
205+ function cleanup()
206+ {
207+ root.contactListModelObj.destroy()
208+ }
209+
210+ function test_contactImport()
211+ {
212+ tryCompare(root.contactListModelObj, "contactCount", 3)
213+ }
214+
215+ function test_searchByPhoneNumber()
216+ {
217+ root.contactListModelObj.filterTerm = "555"
218+ tryCompare(root.contactListModelObj, "contactCount", 1)
219+
220+ root.contactListModelObj.filterTerm = "5"
221+ tryCompare(root.contactListModelObj, "contactCount", 2)
222+
223+ root.contactListModelObj.filterTerm = "6"
224+ tryCompare(root.contactListModelObj, "contactCount", 3)
225+ }
226+
227+ function test_searchByContactName()
228+ {
229+ root.contactListModelObj.filterTerm = "First"
230+ tryCompare(root.contactListModelObj, "contactCount", 1)
231+
232+ root.contactListModelObj.filterTerm = "Fulano"
233+ tryCompare(root.contactListModelObj, "contactCount", 2)
234+
235+ root.contactListModelObj.filterTerm = "F"
236+ tryCompare(root.contactListModelObj, "contactCount", 3)
237+
238+ root.contactListModelObj.filterTerm = "tal6"
239+ tryCompare(root.contactListModelObj, "contactCount", 1)
240+ }
241+
242+ function test_searchByNameAndNumber()
243+ {
244+ root.contactListModelObj.filterTerm = "First"
245+ tryCompare(root.contactListModelObj, "contactCount", 1)
246+
247+ root.contactListModelObj.filterTerm = "555"
248+ tryCompare(root.contactListModelObj, "contactCount", 1)
249+
250+ root.contactListModelObj.filterTerm = "1"
251+ tryCompare(root.contactListModelObj, "contactCount", 3)
252+ }
253+ }
254+}

Subscribers

People subscribed via source and target branches