Merge lp:~renatofilho/telephony-service/fix-1585634 into lp:telephony-service

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 1197
Merged at revision: 1197
Proposed branch: lp:~renatofilho/telephony-service/fix-1585634
Merge into: lp:telephony-service
Diff against target: 124 lines (+35/-9)
3 files modified
libtelephonyservice/contactutils.cpp (+17/-9)
libtelephonyservice/greetercontacts.cpp (+10/-0)
tests/libtelephonyservice/GreeterContactsTest.cpp (+8/-0)
To merge this branch: bzr merge lp:~renatofilho/telephony-service/fix-1585634
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+296224@code.launchpad.net

Commit message

Contact name now checks for QContactDisplayLabel to display full name when possible.

To post a comment you must log in.
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libtelephonyservice/contactutils.cpp'
2--- libtelephonyservice/contactutils.cpp 2015-11-18 12:33:16 +0000
3+++ libtelephonyservice/contactutils.cpp 2016-06-01 15:34:09 +0000
4@@ -21,6 +21,7 @@
5
6 #include "contactutils.h"
7 #include <QContactName>
8+#include <QContactDisplayLabel>
9
10 QTCONTACTS_USE_NAMESPACE
11
12@@ -41,18 +42,25 @@
13 // to use more than just first and last names.
14 QString formatContactName(const QContact &contact)
15 {
16+ // try contact display label
17+ QContactDisplayLabel displayLabel = contact.detail<QContactDisplayLabel>();
18+ if (!displayLabel.isEmpty() && !displayLabel.label().isEmpty()) {
19+ return displayLabel.label();
20+ }
21+
22+ // if empty fallback to contact name
23 QContactName name = contact.detail<QContactName>();
24-
25 QString formattedName = name.firstName();
26
27- // now check if we need an extra space to separate the first and last names
28- if (!formattedName.isEmpty() && !name.lastName().isEmpty()) {
29- formattedName.append(" ");
30- }
31-
32- formattedName.append(name.lastName());
33-
34- return formattedName;
35+ if (!name.middleName().isEmpty()) {
36+ formattedName += " " + name.middleName();
37+ }
38+
39+ if (!name.lastName().isEmpty()) {
40+ formattedName += " " + name.lastName();
41+ }
42+
43+ return formattedName.trimmed();
44 }
45
46 }
47
48=== modified file 'libtelephonyservice/greetercontacts.cpp'
49--- libtelephonyservice/greetercontacts.cpp 2016-03-18 22:14:21 +0000
50+++ libtelephonyservice/greetercontacts.cpp 2016-06-01 15:34:09 +0000
51@@ -26,6 +26,7 @@
52 #include <QContactInvalidFilter>
53 #include <QContactManagerEngine>
54 #include <QContactName>
55+#include <QContactDisplayLabel>
56 #include <QContactPhoneNumber>
57 #include <QDBusInterface>
58 #include <QDBusMetaType>
59@@ -508,8 +509,12 @@
60 QContactAvatar avatarDetail = contact.detail<QContactAvatar>();
61 map.insert("Image", avatarDetail.imageUrl().toLocalFile());
62
63+ QContactDisplayLabel displayLabel = contact.detail<QContactDisplayLabel>();
64+ map.insert("DisplayLabel", displayLabel.label());
65+
66 QContactName nameDetail = contact.detail<QContactName>();
67 map.insert("FirstName", nameDetail.firstName());
68+ map.insert("MiddleName", nameDetail.middleName());
69 map.insert("LastName", nameDetail.lastName());
70
71 QContactPhoneNumber numberDetail = contact.detail<QContactPhoneNumber>();
72@@ -528,8 +533,13 @@
73
74 // We only use FirstName and LastName right now in ContactUtils::formatContactName().
75 // If/When we use more, we should save more detail values here.
76+ QContactDisplayLabel displayLabel;
77+ displayLabel.setValue(QContactDisplayLabel::FieldLabel, map.value("DisplayLabel"));
78+ contact.saveDetail(&displayLabel);
79+
80 QContactName nameDetail;
81 nameDetail.setValue(QContactName::FieldFirstName, map.value("FirstName"));
82+ nameDetail.setValue(QContactName::FieldMiddleName, map.value("MiddleName"));
83 nameDetail.setValue(QContactName::FieldLastName, map.value("LastName"));
84 contact.saveDetail(&nameDetail);
85
86
87=== modified file 'tests/libtelephonyservice/GreeterContactsTest.cpp'
88--- tests/libtelephonyservice/GreeterContactsTest.cpp 2015-08-14 18:27:11 +0000
89+++ tests/libtelephonyservice/GreeterContactsTest.cpp 2016-06-01 15:34:09 +0000
90@@ -22,6 +22,7 @@
91 #include <QContact>
92 #include <QContactAvatar>
93 #include <QContactName>
94+#include <QContactDisplayLabel>
95 #include <QContactPhoneNumber>
96 #include <QDBusInterface>
97 #include <QDBusPendingCallWatcher>
98@@ -218,9 +219,11 @@
99 QVariantMap GreeterContactsTest::makeTestMap()
100 {
101 QVariantMap map;
102+ map.insert("DisplayLabel", QVariant(""));
103 map.insert("FirstName", QVariant("First"));
104 map.insert("Image", QVariant(CMAKE_SOURCE_DIR "/icons/hicolor/48x48/apps/telephony-service-call.png"));
105 map.insert("LastName", QVariant("Last"));
106+ map.insert("MiddleName", QVariant("Middle"));
107 map.insert("PhoneNumber", QVariant("555"));
108 return map;
109 }
110@@ -240,9 +243,14 @@
111 avatarDetail.setValue(QContactAvatar::FieldImageUrl, QUrl::fromLocalFile(imagePath));
112 contact.saveDetail(&avatarDetail);
113
114+ QContactDisplayLabel label;
115+ label.setLabel("");
116+ contact.saveDetail(&label);
117+
118 QContactName nameDetail;
119 nameDetail.setValue(QContactName::FieldFirstName, "First");
120 nameDetail.setValue(QContactName::FieldLastName, "Last");
121+ nameDetail.setValue(QContactName::FieldMiddleName, "Middle");
122 contact.saveDetail(&nameDetail);
123
124 QContactPhoneNumber numberDetail;

Subscribers

People subscribed via source and target branches