Merge lp:~renatofilho/address-book-service/irc-accounts into lp:address-book-service
- irc-accounts
- Merge into trunk
Status: | Approved |
---|---|
Approved by: | Tiago Salem Herrmann |
Approved revision: | 236 |
Proposed branch: | lp:~renatofilho/address-book-service/irc-accounts |
Merge into: | lp:address-book-service |
Diff against target: |
786 lines (+444/-33) 12 files modified
CMakeLists.txt (+1/-1) common/vcard-parser.cpp (+61/-11) common/vcard-parser.h (+2/-0) lib/detail-context-parser.cpp (+6/-3) lib/gee-utils.cpp (+10/-4) lib/gee-utils.h (+1/-1) lib/qindividual.cpp (+68/-9) lib/qindividual.h (+3/-4) lib/update-contact-request.cpp (+28/-0) tests/unittest/CMakeLists.txt (+1/-0) tests/unittest/contact-accounts-test.cpp (+182/-0) tests/unittest/vcardparser-test.cpp (+81/-0) |
To merge this branch: | bzr merge lp:~renatofilho/address-book-service/irc-accounts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tiago Salem Herrmann (community) | Approve | ||
system-apps-ci-bot | continuous-integration | Approve | |
Review via email: mp+317836@code.launchpad.net |
Commit message
Implement support for saving IRC accounts.
Description of the change
- 233. By Renato Araujo Oliveira Filho
-
Added missing file.
- 234. By Renato Araujo Oliveira Filho
-
Implement support for PROVIDERS save on IRC accounts.
- 235. By Renato Araujo Oliveira Filho
-
Implement support for PROVIDER on online accounts.
TODO: Folks EDS does not support it.
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
Tiago Salem Herrmann (tiagosh) wrote : | # |
just one remark.
looks good otherwise.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
> just one remark.
> looks good otherwise.
Fixed
- 236. By Renato Araujo Oliveira Filho
-
Removed duplicated check.
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:236
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Tiago Salem Herrmann (tiagosh) wrote : | # |
looks good. thanks.
Unmerged revisions
- 236. By Renato Araujo Oliveira Filho
-
Removed duplicated check.
- 235. By Renato Araujo Oliveira Filho
-
Implement support for PROVIDER on online accounts.
TODO: Folks EDS does not support it.
- 234. By Renato Araujo Oliveira Filho
-
Implement support for PROVIDERS save on IRC accounts.
- 233. By Renato Araujo Oliveira Filho
-
Added missing file.
- 232. By Renato Araujo Oliveira Filho
-
Fixed contact creation with IRC field.
- 231. By Renato Araujo Oliveira Filho
-
Implement support for saving IRC accounts.
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2015-09-23 12:36:13 +0000 | |||
3 | +++ CMakeLists.txt 2017-03-22 11:39:22 +0000 | |||
4 | @@ -40,7 +40,7 @@ | |||
5 | 40 | else() | 40 | else() |
6 | 41 | set(EVOLUTION_API_3_17 "1") | 41 | set(EVOLUTION_API_3_17 "1") |
7 | 42 | set(EVOLUTION_ADDRESSBOOK_SERVICE_NAME "org.gnome.evolution.dataserver.AddressBook9") | 42 | set(EVOLUTION_ADDRESSBOOK_SERVICE_NAME "org.gnome.evolution.dataserver.AddressBook9") |
9 | 43 | set(EVOLUTION_SOURCE_SERVICE_NAME "org.gnome.evolution.dataserver.Sources4") | 43 | set(EVOLUTION_SOURCE_SERVICE_NAME "org.gnome.evolution.dataserver.Sources5") |
10 | 44 | endif() | 44 | endif() |
11 | 45 | 45 | ||
12 | 46 | set(CMAKE_INCLUDE_CURRENT_DIR ON) | 46 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
13 | 47 | 47 | ||
14 | === modified file 'common/vcard-parser.cpp' | |||
15 | --- common/vcard-parser.cpp 2015-11-03 23:54:53 +0000 | |||
16 | +++ common/vcard-parser.cpp 2017-03-22 11:39:22 +0000 | |||
17 | @@ -34,6 +34,20 @@ | |||
18 | 34 | using namespace QtVersit; | 34 | using namespace QtVersit; |
19 | 35 | using namespace QtContacts; | 35 | using namespace QtContacts; |
20 | 36 | 36 | ||
21 | 37 | namespace galera | ||
22 | 38 | { | ||
23 | 39 | |||
24 | 40 | const QString VCardParser::PidMapFieldName = QStringLiteral("CLIENTPIDMAP"); | ||
25 | 41 | const QString VCardParser::PidFieldName = QStringLiteral("PID"); | ||
26 | 42 | const QString VCardParser::PrefParamName = QStringLiteral("PREF"); | ||
27 | 43 | const QString VCardParser::IrremovableFieldName = QStringLiteral("IRREMOVABLE"); | ||
28 | 44 | const QString VCardParser::ReadOnlyFieldName = QStringLiteral("READ-ONLY"); | ||
29 | 45 | const QString VCardParser::TagFieldName = QStringLiteral("TAG"); | ||
30 | 46 | const QString VCardParser::IrcFieldName = QStringLiteral("X-IRC"); | ||
31 | 47 | const QString VCardParser::OnlineAccountProviderParamName = QStringLiteral("PROVIDER"); | ||
32 | 48 | |||
33 | 49 | } | ||
34 | 50 | |||
35 | 37 | namespace | 51 | namespace |
36 | 38 | { | 52 | { |
37 | 39 | class ContactExporterDetailHandler : public QVersitContactExporterDetailHandlerV2 | 53 | class ContactExporterDetailHandler : public QVersitContactExporterDetailHandlerV2 |
38 | @@ -67,10 +81,25 @@ | |||
39 | 67 | } | 81 | } |
40 | 68 | 82 | ||
41 | 69 | if (detail.type() == QContactDetail::TypeExtendedDetail) { | 83 | if (detail.type() == QContactDetail::TypeExtendedDetail) { |
46 | 70 | QVersitProperty prop; | 84 | // Do not translate X-IRC extended details |
47 | 71 | prop.setName(detail.value(QContactExtendedDetail::FieldName).toString()); | 85 | if (detail.value(QContactExtendedDetail::FieldName).toString() != galera::VCardParser::IrcFieldName) { |
48 | 72 | prop.setValue(detail.value(QContactExtendedDetail::FieldData).toString()); | 86 | QVersitProperty prop; |
49 | 73 | *toBeAdded << prop; | 87 | prop.setName(detail.value(QContactExtendedDetail::FieldName).toString()); |
50 | 88 | prop.setValue(detail.value(QContactExtendedDetail::FieldData).toString()); | ||
51 | 89 | *toBeAdded << prop; | ||
52 | 90 | } | ||
53 | 91 | } | ||
54 | 92 | |||
55 | 93 | // export IRC online account (This is not exported by QtVersit) | ||
56 | 94 | if (detail.type() == QContactDetail::TypeOnlineAccount) { | ||
57 | 95 | QContactOnlineAccount acc = static_cast<QContactOnlineAccount>(detail); | ||
58 | 96 | if (acc.protocol() == QContactOnlineAccount::ProtocolIrc) { | ||
59 | 97 | QVersitProperty prop; | ||
60 | 98 | prop.setName(galera::VCardParser::IrcFieldName); | ||
61 | 99 | prop.setValue(acc.accountUri()); | ||
62 | 100 | // provider will be added by later accout parse | ||
63 | 101 | *toBeAdded << prop; | ||
64 | 102 | } | ||
65 | 74 | } | 103 | } |
66 | 75 | 104 | ||
67 | 76 | if (toBeAdded->size() == 0) { | 105 | if (toBeAdded->size() == 0) { |
68 | @@ -122,6 +151,15 @@ | |||
69 | 122 | } | 151 | } |
70 | 123 | break; | 152 | break; |
71 | 124 | } | 153 | } |
72 | 154 | case QContactDetail::TypeOnlineAccount: | ||
73 | 155 | { | ||
74 | 156 | QContactOnlineAccount account = static_cast<QContactOnlineAccount>(detail); | ||
75 | 157 | QVersitProperty &prop = toBeAdded->last(); | ||
76 | 158 | QMultiHash<QString, QString> params = prop.parameters(); | ||
77 | 159 | params.insert(galera::VCardParser::OnlineAccountProviderParamName, account.serviceProvider()); | ||
78 | 160 | prop.setParameters(params); | ||
79 | 161 | break; | ||
80 | 162 | } | ||
81 | 125 | default: | 163 | default: |
82 | 126 | break; | 164 | break; |
83 | 127 | } | 165 | } |
84 | @@ -170,9 +208,19 @@ | |||
85 | 170 | } | 208 | } |
86 | 171 | 209 | ||
87 | 172 | if (!*alreadyProcessed && (property.name().startsWith("X-"))) { | 210 | if (!*alreadyProcessed && (property.name().startsWith("X-"))) { |
88 | 211 | // IRC FIELDS | ||
89 | 212 | if (property.name() == galera::VCardParser::IrcFieldName) { | ||
90 | 213 | QContactOnlineAccount acc; | ||
91 | 214 | acc.setProtocol(QContactOnlineAccount::ProtocolIrc); | ||
92 | 215 | acc.setAccountUri(property.value()); | ||
93 | 216 | acc.setServiceProvider(property.parameters().value(galera::VCardParser::OnlineAccountProviderParamName)); | ||
94 | 217 | *updatedDetails << acc; | ||
95 | 218 | } | ||
96 | 173 | QContactExtendedDetail xDet; | 219 | QContactExtendedDetail xDet; |
97 | 174 | xDet.setName(property.name()); | 220 | xDet.setName(property.name()); |
98 | 175 | xDet.setData(property.value<QString>()); | 221 | xDet.setData(property.value<QString>()); |
99 | 222 | xDet.setValue(QContactExtendedDetail::FieldData + 1, property.parameters().value(galera::VCardParser::OnlineAccountProviderParamName)); | ||
100 | 223 | |||
101 | 176 | *updatedDetails << xDet; | 224 | *updatedDetails << xDet; |
102 | 177 | *alreadyProcessed = true; | 225 | *alreadyProcessed = true; |
103 | 178 | } | 226 | } |
104 | @@ -181,6 +229,7 @@ | |||
105 | 181 | return; | 229 | return; |
106 | 182 | } | 230 | } |
107 | 183 | 231 | ||
108 | 232 | |||
109 | 184 | QString pid = property.parameters().value(galera::VCardParser::PidFieldName); | 233 | QString pid = property.parameters().value(galera::VCardParser::PidFieldName); |
110 | 185 | if (!pid.isEmpty()) { | 234 | if (!pid.isEmpty()) { |
111 | 186 | QContactDetail &det = updatedDetails->last(); | 235 | QContactDetail &det = updatedDetails->last(); |
112 | @@ -230,6 +279,14 @@ | |||
113 | 230 | } | 279 | } |
114 | 231 | break; | 280 | break; |
115 | 232 | } | 281 | } |
116 | 282 | case QContactDetail::TypeOnlineAccount: | ||
117 | 283 | { | ||
118 | 284 | // Fill provider for online accounts | ||
119 | 285 | QString provider = property.parameters().value(galera::VCardParser::OnlineAccountProviderParamName); | ||
120 | 286 | if (!provider.isEmpty()) | ||
121 | 287 | det.setValue(QContactOnlineAccount::FieldServiceProvider, provider); | ||
122 | 288 | break; | ||
123 | 289 | } | ||
124 | 233 | default: | 290 | default: |
125 | 234 | break; | 291 | break; |
126 | 235 | } | 292 | } |
127 | @@ -270,13 +327,6 @@ | |||
128 | 270 | namespace galera | 327 | namespace galera |
129 | 271 | { | 328 | { |
130 | 272 | 329 | ||
131 | 273 | const QString VCardParser::PidMapFieldName = QStringLiteral("CLIENTPIDMAP"); | ||
132 | 274 | const QString VCardParser::PidFieldName = QStringLiteral("PID"); | ||
133 | 275 | const QString VCardParser::PrefParamName = QStringLiteral("PREF"); | ||
134 | 276 | const QString VCardParser::IrremovableFieldName = QStringLiteral("IRREMOVABLE"); | ||
135 | 277 | const QString VCardParser::ReadOnlyFieldName = QStringLiteral("READ-ONLY"); | ||
136 | 278 | const QString VCardParser::TagFieldName = QStringLiteral("TAG"); | ||
137 | 279 | |||
138 | 280 | static QMap<QtContacts::QContactDetail::DetailType, QString> prefferedActions() | 330 | static QMap<QtContacts::QContactDetail::DetailType, QString> prefferedActions() |
139 | 281 | { | 331 | { |
140 | 282 | QMap<QtContacts::QContactDetail::DetailType, QString> values; | 332 | QMap<QtContacts::QContactDetail::DetailType, QString> values; |
141 | 283 | 333 | ||
142 | === modified file 'common/vcard-parser.h' | |||
143 | --- common/vcard-parser.h 2015-10-28 14:28:11 +0000 | |||
144 | +++ common/vcard-parser.h 2017-03-22 11:39:22 +0000 | |||
145 | @@ -57,6 +57,8 @@ | |||
146 | 57 | static const QString IrremovableFieldName; | 57 | static const QString IrremovableFieldName; |
147 | 58 | static const QString ReadOnlyFieldName; | 58 | static const QString ReadOnlyFieldName; |
148 | 59 | static const QString TagFieldName; | 59 | static const QString TagFieldName; |
149 | 60 | static const QString IrcFieldName; | ||
150 | 61 | static const QString OnlineAccountProviderParamName; | ||
151 | 60 | static const QMap<QtContacts::QContactDetail::DetailType, QString> PreferredActionNames; | 62 | static const QMap<QtContacts::QContactDetail::DetailType, QString> PreferredActionNames; |
152 | 61 | 63 | ||
153 | 62 | static QtContacts::QContact vcardToContact(const QString &vcard); | 64 | static QtContacts::QContact vcardToContact(const QString &vcard); |
154 | 63 | 65 | ||
155 | === modified file 'lib/detail-context-parser.cpp' | |||
156 | --- lib/detail-context-parser.cpp 2016-09-20 13:25:21 +0000 | |||
157 | +++ lib/detail-context-parser.cpp 2017-03-22 11:39:22 +0000 | |||
158 | @@ -218,10 +218,13 @@ | |||
159 | 218 | 218 | ||
160 | 219 | while (gee_iterator_next (siter)) { | 219 | while (gee_iterator_next (siter)) { |
161 | 220 | char *parameter = (char*) gee_iterator_get(siter); | 220 | char *parameter = (char*) gee_iterator_get(siter); |
163 | 221 | if (QString::fromUtf8(parameter).toUpper() == VCardParser::PrefParamName) { | 221 | const QString parameterName = QString::fromUtf8(parameter).toUpper(); |
164 | 222 | if (parameterName == VCardParser::PrefParamName) { | ||
165 | 222 | params << "pref"; | 223 | params << "pref"; |
166 | 223 | continue; | 224 | continue; |
168 | 224 | } else if (QString::fromUtf8(parameter) != "type") { | 225 | } else if (parameterName == VCardParser::OnlineAccountProviderParamName) { |
169 | 226 | |||
170 | 227 | } else if (parameterName != "TYPE") { | ||
171 | 225 | if (!whiteList.contains(QString::fromUtf8(parameter))) { | 228 | if (!whiteList.contains(QString::fromUtf8(parameter))) { |
172 | 226 | qDebug() << "not supported field details" << parameter; | 229 | qDebug() << "not supported field details" << parameter; |
173 | 227 | // FIXME: check what to do with other parameters | 230 | // FIXME: check what to do with other parameters |
174 | @@ -389,7 +392,7 @@ | |||
175 | 389 | Q_FOREACH(const QString ¶m, parameters) { | 392 | Q_FOREACH(const QString ¶m, parameters) { |
176 | 390 | if (map.contains(param.toLower())) { | 393 | if (map.contains(param.toLower())) { |
177 | 391 | values << map[param.toLower()]; | 394 | values << map[param.toLower()]; |
179 | 392 | } else { | 395 | } else { |
180 | 393 | qWarning() << "invalid IM subtype" << param; | 396 | qWarning() << "invalid IM subtype" << param; |
181 | 394 | } | 397 | } |
182 | 395 | } | 398 | } |
183 | 396 | 399 | ||
184 | === modified file 'lib/gee-utils.cpp' | |||
185 | --- lib/gee-utils.cpp 2013-10-30 19:07:49 +0000 | |||
186 | +++ lib/gee-utils.cpp 2017-03-22 11:39:22 +0000 | |||
187 | @@ -19,6 +19,7 @@ | |||
188 | 19 | #include "gee-utils.h" | 19 | #include "gee-utils.h" |
189 | 20 | 20 | ||
190 | 21 | #include <QDebug> | 21 | #include <QDebug> |
191 | 22 | #include <QPair> | ||
192 | 22 | 23 | ||
193 | 23 | GValue* GeeUtils::gValueSliceNew(GType type) | 24 | GValue* GeeUtils::gValueSliceNew(GType type) |
194 | 24 | { | 25 | { |
195 | @@ -39,7 +40,7 @@ | |||
196 | 39 | g_hash_table_insert(details, (gpointer) folks_persona_store_detail_key(key), value); | 40 | g_hash_table_insert(details, (gpointer) folks_persona_store_detail_key(key), value); |
197 | 40 | } | 41 | } |
198 | 41 | 42 | ||
200 | 42 | GValue* GeeUtils::asvSetStrNew(QMultiMap<QString, QString> providerUidMap) | 43 | GValue* GeeUtils::asvSetStrNew(QMultiMap<QString, QPair<QString, QString> > providerUidMap) |
201 | 43 | { | 44 | { |
202 | 44 | GeeMultiMap *hashSet = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); | 45 | GeeMultiMap *hashSet = GEE_MULTI_MAP_AFD_NEW(FOLKS_TYPE_IM_FIELD_DETAILS); |
203 | 45 | GValue *retval = gValueSliceNew (G_TYPE_OBJECT); | 46 | GValue *retval = gValueSliceNew (G_TYPE_OBJECT); |
204 | @@ -47,11 +48,16 @@ | |||
205 | 47 | 48 | ||
206 | 48 | QList<QString> keys = providerUidMap.keys(); | 49 | QList<QString> keys = providerUidMap.keys(); |
207 | 49 | Q_FOREACH(const QString& key, keys) { | 50 | Q_FOREACH(const QString& key, keys) { |
210 | 50 | QList<QString> values = providerUidMap.values(key); | 51 | Q_FOREACH(const auto &value, providerUidMap.values(key)) { |
209 | 51 | Q_FOREACH(const QString& value, values) { | ||
211 | 52 | FolksImFieldDetails *imfd; | 52 | FolksImFieldDetails *imfd; |
212 | 53 | const QString &accountUri = value.first; | ||
213 | 54 | const QString &accountProvider = value.second; | ||
214 | 53 | 55 | ||
216 | 54 | imfd = folks_im_field_details_new (value.toUtf8().data(), NULL); | 56 | imfd = folks_im_field_details_new (accountUri.toUtf8().data(), NULL); |
217 | 57 | if (!accountProvider.isEmpty()) { | ||
218 | 58 | folks_abstract_field_details_add_parameter(FOLKS_ABSTRACT_FIELD_DETAILS(imfd), | ||
219 | 59 | "PROVIDER", accountProvider.toUtf8().data()); | ||
220 | 60 | } | ||
221 | 55 | 61 | ||
222 | 56 | gee_multi_map_set(hashSet, | 62 | gee_multi_map_set(hashSet, |
223 | 57 | key.toUtf8().data(), | 63 | key.toUtf8().data(), |
224 | 58 | 64 | ||
225 | === modified file 'lib/gee-utils.h' | |||
226 | --- lib/gee-utils.h 2013-10-30 19:07:49 +0000 | |||
227 | +++ lib/gee-utils.h 2017-03-22 11:39:22 +0000 | |||
228 | @@ -84,7 +84,7 @@ | |||
229 | 84 | static GValue* gValueSliceNew(GType type); | 84 | static GValue* gValueSliceNew(GType type); |
230 | 85 | static void gValueSliceFree(GValue *value); | 85 | static void gValueSliceFree(GValue *value); |
231 | 86 | static void personaDetailsInsert(GHashTable *details, FolksPersonaDetail key, gpointer value); | 86 | static void personaDetailsInsert(GHashTable *details, FolksPersonaDetail key, gpointer value); |
233 | 87 | static GValue* asvSetStrNew(QMultiMap<QString, QString> providerUidMap); | 87 | static GValue* asvSetStrNew(QMultiMap<QString, QPair<QString, QString> > providerUidMap); |
234 | 88 | }; // class | 88 | }; // class |
235 | 89 | 89 | ||
236 | 90 | #endif | 90 | #endif |
237 | 91 | 91 | ||
238 | === modified file 'lib/qindividual.cpp' | |||
239 | --- lib/qindividual.cpp 2016-05-04 17:56:15 +0000 | |||
240 | +++ lib/qindividual.cpp 2017-03-22 11:39:22 +0000 | |||
241 | @@ -28,6 +28,7 @@ | |||
242 | 28 | #include <libebook/libebook.h> | 28 | #include <libebook/libebook.h> |
243 | 29 | 29 | ||
244 | 30 | #include <QtCore/QMutexLocker> | 30 | #include <QtCore/QMutexLocker> |
245 | 31 | #include <QtCore/QPair> | ||
246 | 31 | 32 | ||
247 | 32 | #include <QtVersit/QVersitDocument> | 33 | #include <QtVersit/QVersitDocument> |
248 | 33 | #include <QtVersit/QVersitProperty> | 34 | #include <QtVersit/QVersitProperty> |
249 | @@ -64,6 +65,7 @@ | |||
250 | 64 | #define X_GROUP_ID "X-GROUP-ID" | 65 | #define X_GROUP_ID "X-GROUP-ID" |
251 | 65 | #define X_DELETED_AT "X-DELETED-AT" | 66 | #define X_DELETED_AT "X-DELETED-AT" |
252 | 66 | #define X_AVATAR_REV "X-AVATAR-REV" | 67 | #define X_AVATAR_REV "X-AVATAR-REV" |
253 | 68 | #define X_IRC_ACCOUNT "X-IRC" | ||
254 | 67 | 69 | ||
255 | 68 | namespace | 70 | namespace |
256 | 69 | { | 71 | { |
257 | @@ -100,12 +102,16 @@ | |||
258 | 100 | } else if(g_type == FOLKS_TYPE_WEB_SERVICE_FIELD_DETAILS) { | 102 | } else if(g_type == FOLKS_TYPE_WEB_SERVICE_FIELD_DETAILS) { |
259 | 101 | fieldDetails = FOLKS_ABSTRACT_FIELD_DETAILS ( | 103 | fieldDetails = FOLKS_ABSTRACT_FIELD_DETAILS ( |
260 | 102 | folks_web_service_field_details_new(v_string, NULL)); | 104 | folks_web_service_field_details_new(v_string, NULL)); |
261 | 105 | } else if(g_type == FOLKS_TYPE_EXTENDED_FIELD_DETAILS) { | ||
262 | 106 | fieldDetails = FOLKS_ABSTRACT_FIELD_DETAILS ( | ||
263 | 107 | folks_extended_field_details_new(v_string, NULL)); | ||
264 | 103 | } | 108 | } |
265 | 104 | 109 | ||
266 | 105 | if (fieldDetails == NULL) { | 110 | if (fieldDetails == NULL) { |
267 | 106 | qWarning() << "Invalid fieldDetails type" << g_type; | 111 | qWarning() << "Invalid fieldDetails type" << g_type; |
268 | 107 | } else { | 112 | } else { |
269 | 108 | galera::DetailContextParser::parseContext(fieldDetails, detail, ispreferred); | 113 | galera::DetailContextParser::parseContext(fieldDetails, detail, ispreferred); |
270 | 114 | |||
271 | 109 | gee_collection_add(collection, fieldDetails); | 115 | gee_collection_add(collection, fieldDetails); |
272 | 110 | 116 | ||
273 | 111 | g_object_unref(fieldDetails); | 117 | g_object_unref(fieldDetails); |
274 | @@ -151,6 +157,7 @@ | |||
275 | 151 | { | 157 | { |
276 | 152 | bool QIndividual::m_autoLink = false; | 158 | bool QIndividual::m_autoLink = false; |
277 | 153 | QStringList QIndividual::m_supportedExtendedDetails; | 159 | QStringList QIndividual::m_supportedExtendedDetails; |
278 | 160 | QList<QContactOnlineAccount::Protocol> QIndividual::m_protocolBlackList; | ||
279 | 154 | 161 | ||
280 | 155 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) | 162 | QIndividual::QIndividual(FolksIndividual *individual, FolksIndividualAggregator *aggregator) |
281 | 156 | : m_individual(0), | 163 | : m_individual(0), |
282 | @@ -164,7 +171,8 @@ | |||
283 | 164 | << X_REMOTE_ID | 171 | << X_REMOTE_ID |
284 | 165 | << X_GOOGLE_ETAG | 172 | << X_GOOGLE_ETAG |
285 | 166 | << X_GROUP_ID | 173 | << X_GROUP_ID |
287 | 167 | << X_AVATAR_REV; | 174 | << X_AVATAR_REV |
288 | 175 | << X_IRC_ACCOUNT; | ||
289 | 168 | } | 176 | } |
290 | 169 | setIndividual(individual); | 177 | setIndividual(individual); |
291 | 170 | } | 178 | } |
292 | @@ -689,6 +697,20 @@ | |||
293 | 689 | int protocolId = DetailContextParser::accountProtocolFromString(qStringFromGChar(key)); | 697 | int protocolId = DetailContextParser::accountProtocolFromString(qStringFromGChar(key)); |
294 | 690 | account.setProtocol(static_cast<QContactOnlineAccount::Protocol>(protocolId)); | 698 | account.setProtocol(static_cast<QContactOnlineAccount::Protocol>(protocolId)); |
295 | 691 | 699 | ||
296 | 700 | // provider | ||
297 | 701 | GeeCollection *providers = folks_abstract_field_details_get_parameter_values(fd, "PROVIDER"); | ||
298 | 702 | if (providers) { | ||
299 | 703 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE (providers)); | ||
300 | 704 | if (iter) { | ||
301 | 705 | char *provider = (char*) gee_iterator_get(iter); | ||
302 | 706 | if (strlen(provider) > 0) { | ||
303 | 707 | account.setServiceProvider(QString::fromUtf8(provider)); | ||
304 | 708 | } | ||
305 | 709 | g_free(provider); | ||
306 | 710 | g_object_unref(iter); | ||
307 | 711 | } | ||
308 | 712 | } | ||
309 | 713 | |||
310 | 692 | bool isPref = false; | 714 | bool isPref = false; |
311 | 693 | DetailContextParser::parseParameters(account, fd, &isPref); | 715 | DetailContextParser::parseParameters(account, fd, &isPref); |
312 | 694 | account.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); | 716 | account.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); |
313 | @@ -765,12 +787,24 @@ | |||
314 | 765 | EVCardAttribute *attr = e_vcard_get_attribute(E_VCARD(c), xDetName.toUtf8().constData()); | 787 | EVCardAttribute *attr = e_vcard_get_attribute(E_VCARD(c), xDetName.toUtf8().constData()); |
315 | 766 | if (attr) { | 788 | if (attr) { |
316 | 767 | GString *attrValue = e_vcard_attribute_get_value_decoded(attr); | 789 | GString *attrValue = e_vcard_attribute_get_value_decoded(attr); |
323 | 768 | QContactExtendedDetail xDet; | 790 | |
324 | 769 | xDet.setName(xDetName); | 791 | if (xDetName == X_IRC_ACCOUNT) { |
325 | 770 | xDet.setData(QString::fromUtf8(attrValue->str)); | 792 | QContactOnlineAccount acc; |
326 | 771 | xDet.setDetailUri(QString("%1.1").arg(index)); | 793 | acc.setProtocol(QContactOnlineAccount::ProtocolIrc); |
327 | 772 | g_string_free(attrValue, true); | 794 | acc.setAccountUri(QString::fromUtf8(attrValue->str)); |
328 | 773 | result << xDet; | 795 | GList *param = e_vcard_attribute_get_param(attr, "PROVIDER"); |
329 | 796 | if (param) | ||
330 | 797 | acc.setServiceProvider(QString::fromUtf8(static_cast<gchar*>(param->data))); | ||
331 | 798 | |||
332 | 799 | result << acc; | ||
333 | 800 | } else { | ||
334 | 801 | QContactExtendedDetail xDet; | ||
335 | 802 | xDet.setName(xDetName); | ||
336 | 803 | xDet.setData(QString::fromUtf8(attrValue->str)); | ||
337 | 804 | xDet.setDetailUri(QString("%1.1").arg(index)); | ||
338 | 805 | g_string_free(attrValue, true); | ||
339 | 806 | result << xDet; | ||
340 | 807 | } | ||
341 | 774 | } | 808 | } |
342 | 775 | } | 809 | } |
343 | 776 | 810 | ||
344 | @@ -1559,11 +1593,20 @@ | |||
345 | 1559 | return details; | 1593 | return details; |
346 | 1560 | } | 1594 | } |
347 | 1561 | 1595 | ||
349 | 1562 | QMultiMap<QString, QString> providerUidMap; | 1596 | if (m_protocolBlackList.isEmpty()) { |
350 | 1597 | m_protocolBlackList << QContactOnlineAccount::ProtocolIrc; | ||
351 | 1598 | } | ||
352 | 1599 | |||
353 | 1600 | QMultiMap<QString, QPair<QString,QString> > providerUidMap; | ||
354 | 1563 | Q_FOREACH(const QContactDetail &detail, cDetails) { | 1601 | Q_FOREACH(const QContactDetail &detail, cDetails) { |
355 | 1564 | QContactOnlineAccount account = static_cast<QContactOnlineAccount>(detail); | 1602 | QContactOnlineAccount account = static_cast<QContactOnlineAccount>(detail); |
356 | 1603 | if (m_protocolBlackList.contains(account.protocol())) { | ||
357 | 1604 | continue; | ||
358 | 1605 | } | ||
359 | 1606 | |||
360 | 1565 | if (!account.isEmpty()) { | 1607 | if (!account.isEmpty()) { |
362 | 1566 | providerUidMap.insert(DetailContextParser::accountProtocolName(account.protocol()), account.accountUri()); | 1608 | providerUidMap.insert(DetailContextParser::accountProtocolName(account.protocol()), |
363 | 1609 | qMakePair(account.accountUri(), account.serviceProvider())); | ||
364 | 1567 | } | 1610 | } |
365 | 1568 | } | 1611 | } |
366 | 1569 | 1612 | ||
367 | @@ -1789,6 +1832,17 @@ | |||
368 | 1789 | } | 1832 | } |
369 | 1790 | 1833 | ||
370 | 1791 | attr = e_vcard_attribute_new("", xd.name().toUtf8().constData()); | 1834 | attr = e_vcard_attribute_new("", xd.name().toUtf8().constData()); |
371 | 1835 | |||
372 | 1836 | // Special cases | ||
373 | 1837 | if (xd.name() == X_IRC_ACCOUNT) { | ||
374 | 1838 | // IRC - save provider | ||
375 | 1839 | QString provider = xd.value(QContactExtendedDetail::FieldData + 1).toString(); | ||
376 | 1840 | if (!provider.isEmpty()) { | ||
377 | 1841 | EVCardAttributeParam * param = e_vcard_attribute_param_new("PROVIDER"); | ||
378 | 1842 | e_vcard_attribute_add_param_with_value(attr, param, provider.toUtf8().constData()); | ||
379 | 1843 | } | ||
380 | 1844 | } | ||
381 | 1845 | |||
382 | 1792 | e_vcard_add_attribute_with_value(E_VCARD(c), | 1846 | e_vcard_add_attribute_with_value(E_VCARD(c), |
383 | 1793 | attr, | 1847 | attr, |
384 | 1794 | xd.data().toString().toUtf8().constData()); | 1848 | xd.data().toString().toUtf8().constData()); |
385 | @@ -1824,6 +1878,11 @@ | |||
386 | 1824 | return m_autoLink; | 1878 | return m_autoLink; |
387 | 1825 | } | 1879 | } |
388 | 1826 | 1880 | ||
389 | 1881 | QList<QContactOnlineAccount::Protocol> QIndividual::protocolBlackList() | ||
390 | 1882 | { | ||
391 | 1883 | return m_protocolBlackList; | ||
392 | 1884 | } | ||
393 | 1885 | |||
394 | 1827 | FolksPersona* QIndividual::primaryPersona() | 1886 | FolksPersona* QIndividual::primaryPersona() |
395 | 1828 | { | 1887 | { |
396 | 1829 | if (m_personas.size() > 0) { | 1888 | if (m_personas.size() > 0) { |
397 | 1830 | 1889 | ||
398 | === modified file 'lib/qindividual.h' | |||
399 | --- lib/qindividual.h 2015-09-04 15:01:52 +0000 | |||
400 | +++ lib/qindividual.h 2017-03-22 11:39:22 +0000 | |||
401 | @@ -29,6 +29,7 @@ | |||
402 | 29 | 29 | ||
403 | 30 | #include <QtContacts/QContact> | 30 | #include <QtContacts/QContact> |
404 | 31 | #include <QtContacts/QContactDetail> | 31 | #include <QtContacts/QContactDetail> |
405 | 32 | #include <QtContacts/QContactOnlineAccount> | ||
406 | 32 | 33 | ||
407 | 33 | #include <folks/folks.h> | 34 | #include <folks/folks.h> |
408 | 34 | 35 | ||
409 | @@ -70,6 +71,7 @@ | |||
410 | 70 | // enable or disable auto-link | 71 | // enable or disable auto-link |
411 | 71 | static void enableAutoLink(bool flag); | 72 | static void enableAutoLink(bool flag); |
412 | 72 | static bool autoLinkEnabled(); | 73 | static bool autoLinkEnabled(); |
413 | 74 | static QList<QtContacts::QContactOnlineAccount::Protocol> protocolBlackList(); | ||
414 | 73 | 75 | ||
415 | 74 | private: | 76 | private: |
416 | 75 | FolksIndividual *m_individual; | 77 | FolksIndividual *m_individual; |
417 | @@ -86,6 +88,7 @@ | |||
418 | 86 | bool m_visible; | 88 | bool m_visible; |
419 | 87 | static bool m_autoLink; | 89 | static bool m_autoLink; |
420 | 88 | static QStringList m_supportedExtendedDetails; | 90 | static QStringList m_supportedExtendedDetails; |
421 | 91 | static QList<QtContacts::QContactOnlineAccount::Protocol> m_protocolBlackList; | ||
422 | 89 | 92 | ||
423 | 90 | QIndividual(); | 93 | QIndividual(); |
424 | 91 | QIndividual(const QIndividual &); | 94 | QIndividual(const QIndividual &); |
425 | @@ -144,10 +147,6 @@ | |||
426 | 144 | 147 | ||
427 | 145 | static void avatarCacheStoreDone(GObject *source, GAsyncResult *result, gpointer data); | 148 | static void avatarCacheStoreDone(GObject *source, GAsyncResult *result, gpointer data); |
428 | 146 | 149 | ||
429 | 147 | // create | ||
430 | 148 | void createPersonaFromDetails(QList<QtContacts::QContactDetail> detail, ParseDetailsFunc parseFunc, void *data) const; | ||
431 | 149 | static void createPersonaForDetailDone(GObject *detail, GAsyncResult *result, gpointer userdata); | ||
432 | 150 | |||
433 | 151 | // translate details | 150 | // translate details |
434 | 152 | static GHashTable *parseFullNameDetails (GHashTable *details, | 151 | static GHashTable *parseFullNameDetails (GHashTable *details, |
435 | 153 | const QList<QtContacts::QContactDetail> &cDetails, | 152 | const QList<QtContacts::QContactDetail> &cDetails, |
436 | 154 | 153 | ||
437 | === modified file 'lib/update-contact-request.cpp' | |||
438 | --- lib/update-contact-request.cpp 2015-09-24 17:47:49 +0000 | |||
439 | +++ lib/update-contact-request.cpp 2017-03-22 11:39:22 +0000 | |||
440 | @@ -229,6 +229,7 @@ | |||
441 | 229 | return detailsFromPersona(m_originalContact, type, persona, false, pref); | 229 | return detailsFromPersona(m_originalContact, type, persona, false, pref); |
442 | 230 | } | 230 | } |
443 | 231 | 231 | ||
444 | 232 | |||
445 | 232 | QList<QtContacts::QContactDetail> UpdateContactRequest::detailsFromPersona(QtContacts::QContactDetail::DetailType type, | 233 | QList<QtContacts::QContactDetail> UpdateContactRequest::detailsFromPersona(QtContacts::QContactDetail::DetailType type, |
446 | 233 | int persona, | 234 | int persona, |
447 | 234 | QtContacts::QContactDetail *pref) const | 235 | QtContacts::QContactDetail *pref) const |
448 | @@ -570,6 +571,27 @@ | |||
449 | 570 | m_currentPersonaIndex, | 571 | m_currentPersonaIndex, |
450 | 571 | &prefDetail); | 572 | &prefDetail); |
451 | 572 | 573 | ||
452 | 574 | // remove blacklisted protocols to avoid try to save it | ||
453 | 575 | QList<QtContacts::QContactDetail>::iterator i = originalDetails.begin(); | ||
454 | 576 | while (i != originalDetails.end()) | ||
455 | 577 | { | ||
456 | 578 | if (QIndividual::protocolBlackList().contains(static_cast<QtContacts::QContactOnlineAccount>(*i).protocol())) { | ||
457 | 579 | originalDetails.erase(i++); | ||
458 | 580 | } else { | ||
459 | 581 | ++i; | ||
460 | 582 | } | ||
461 | 583 | } | ||
462 | 584 | |||
463 | 585 | i = newDetails.begin(); | ||
464 | 586 | while (i != newDetails.end()) | ||
465 | 587 | { | ||
466 | 588 | if (QIndividual::protocolBlackList().contains(static_cast<QtContacts::QContactOnlineAccount>(*i).protocol())) { | ||
467 | 589 | newDetails.erase(i++); | ||
468 | 590 | } else { | ||
469 | 591 | ++i; | ||
470 | 592 | } | ||
471 | 593 | } | ||
472 | 594 | |||
473 | 573 | if (m_currentPersona && | 595 | if (m_currentPersona && |
474 | 574 | FOLKS_IS_IM_DETAILS(m_currentPersona) && | 596 | FOLKS_IS_IM_DETAILS(m_currentPersona) && |
475 | 575 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { | 597 | !isEqual(originalDetails, originalPref, newDetails, prefDetail)) { |
476 | @@ -585,6 +607,10 @@ | |||
477 | 585 | field = folks_im_field_details_new(accountUri.constData(), NULL); | 607 | field = folks_im_field_details_new(accountUri.constData(), NULL); |
478 | 586 | DetailContextParser::parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(field), account, account == prefDetail); | 608 | DetailContextParser::parseContext(FOLKS_ABSTRACT_FIELD_DETAILS(field), account, account == prefDetail); |
479 | 587 | 609 | ||
480 | 610 | if (!account.serviceProvider().isEmpty()) { | ||
481 | 611 | folks_abstract_field_details_add_parameter(FOLKS_ABSTRACT_FIELD_DETAILS(field), | ||
482 | 612 | "PROVIDER", account.serviceProvider().toUtf8().data()); | ||
483 | 613 | } | ||
484 | 588 | QString protocolName(DetailContextParser::accountProtocolName(account.protocol())); | 614 | QString protocolName(DetailContextParser::accountProtocolName(account.protocol())); |
485 | 589 | QByteArray protocolNameUtf8 = protocolName.toUtf8(); | 615 | QByteArray protocolNameUtf8 = protocolName.toUtf8(); |
486 | 590 | gee_multi_map_set(imMap, protocolNameUtf8.constData(), field); | 616 | gee_multi_map_set(imMap, protocolNameUtf8.constData(), field); |
487 | @@ -769,6 +795,8 @@ | |||
488 | 769 | { | 795 | { |
489 | 770 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeExtendedDetail, m_currentPersonaIndex, 0); | 796 | QList<QContactDetail> originalDetails = originalDetailsFromPersona(QContactDetail::TypeExtendedDetail, m_currentPersonaIndex, 0); |
490 | 771 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeExtendedDetail, m_currentPersonaIndex, 0); | 797 | QList<QContactDetail> newDetails = detailsFromPersona(QContactDetail::TypeExtendedDetail, m_currentPersonaIndex, 0); |
491 | 798 | |||
492 | 799 | |||
493 | 772 | if (m_currentPersona && | 800 | if (m_currentPersona && |
494 | 773 | !isEqual(originalDetails, newDetails)) { | 801 | !isEqual(originalDetails, newDetails)) { |
495 | 774 | qDebug() << "Extended details diff"; | 802 | qDebug() << "Extended details diff"; |
496 | 775 | 803 | ||
497 | === modified file 'tests/unittest/CMakeLists.txt' | |||
498 | --- tests/unittest/CMakeLists.txt 2015-09-29 14:15:42 +0000 | |||
499 | +++ tests/unittest/CMakeLists.txt 2017-03-22 11:39:22 +0000 | |||
500 | @@ -116,6 +116,7 @@ | |||
501 | 116 | declare_eds_test(contact-collection-test) | 116 | declare_eds_test(contact-collection-test) |
502 | 117 | declare_eds_test(contact-timestamp-test) | 117 | declare_eds_test(contact-timestamp-test) |
503 | 118 | declare_eds_test(contact-avatar-test) | 118 | declare_eds_test(contact-avatar-test) |
504 | 119 | declare_eds_test(contact-accounts-test) | ||
505 | 119 | elseif() | 120 | elseif() |
506 | 120 | message(STATUS "DBus test runner not found. Some tests will be disabled") | 121 | message(STATUS "DBus test runner not found. Some tests will be disabled") |
507 | 121 | endif() | 122 | endif() |
508 | 122 | 123 | ||
509 | === added file 'tests/unittest/contact-accounts-test.cpp' | |||
510 | --- tests/unittest/contact-accounts-test.cpp 1970-01-01 00:00:00 +0000 | |||
511 | +++ tests/unittest/contact-accounts-test.cpp 2017-03-22 11:39:22 +0000 | |||
512 | @@ -0,0 +1,182 @@ | |||
513 | 1 | /* | ||
514 | 2 | * Copyright 2013 Canonical Ltd. | ||
515 | 3 | * | ||
516 | 4 | * This file is part of contact-service-app. | ||
517 | 5 | * | ||
518 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
519 | 7 | * it under the terms of the GNU General Public License as published by | ||
520 | 8 | * the Free Software Foundation; version 3. | ||
521 | 9 | * | ||
522 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
523 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
524 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
525 | 13 | * GNU General Public License for more details. | ||
526 | 14 | * | ||
527 | 15 | * You should have received a copy of the GNU General Public License | ||
528 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
529 | 17 | */ | ||
530 | 18 | |||
531 | 19 | #include <QObject> | ||
532 | 20 | #include <QtTest> | ||
533 | 21 | #include <QDebug> | ||
534 | 22 | #include <QtContacts> | ||
535 | 23 | |||
536 | 24 | #include "config.h" | ||
537 | 25 | #include "common/vcard-parser.h" | ||
538 | 26 | #include "base-eds-test.h" | ||
539 | 27 | |||
540 | 28 | using namespace QtContacts; | ||
541 | 29 | |||
542 | 30 | class ContactAccountTest : public QObject, public BaseEDSTest | ||
543 | 31 | { | ||
544 | 32 | Q_OBJECT | ||
545 | 33 | private: | ||
546 | 34 | |||
547 | 35 | |||
548 | 36 | private Q_SLOTS: | ||
549 | 37 | void initTestCase() | ||
550 | 38 | { | ||
551 | 39 | BaseEDSTest::initTestCaseImpl(); | ||
552 | 40 | } | ||
553 | 41 | |||
554 | 42 | void cleanupTestCase() | ||
555 | 43 | { | ||
556 | 44 | BaseEDSTest::cleanupTestCaseImpl(); | ||
557 | 45 | } | ||
558 | 46 | |||
559 | 47 | void init() | ||
560 | 48 | { | ||
561 | 49 | BaseEDSTest::initImpl(); | ||
562 | 50 | } | ||
563 | 51 | |||
564 | 52 | void cleanup() | ||
565 | 53 | { | ||
566 | 54 | QList<QContactId> contacts = m_manager->contactIds(); | ||
567 | 55 | m_manager->removeContacts(contacts); | ||
568 | 56 | BaseEDSTest::cleanupImpl(); | ||
569 | 57 | } | ||
570 | 58 | |||
571 | 59 | void testCreateIrcAccount() | ||
572 | 60 | { | ||
573 | 61 | QContact contact = galera::VCardParser::vcardToContact(QString("BEGIN:VCARD\r\n" | ||
574 | 62 | "VERSION:3.0\r\n" | ||
575 | 63 | "X-REMOTE-ID:1dd7d51a1518626a\r\n" | ||
576 | 64 | "N:;Fulano;;;\r\n" | ||
577 | 65 | "EMAIL:fulano@gmail.com\r\n" | ||
578 | 66 | "TEL:123456\r\n" | ||
579 | 67 | "X-IRC;PROVIDER=irc.freenode.net:myIRC\r\n" | ||
580 | 68 | "CLIENTPIDMAP:56183a5b-5da7-49fe-8cf6-9bfd3633bf6d\r\n" | ||
581 | 69 | "END:VCARD\r\n")); | ||
582 | 70 | |||
583 | 71 | QCOMPARE(contact.details<QContactOnlineAccount>().size(), 1); | ||
584 | 72 | |||
585 | 73 | // create a contact | ||
586 | 74 | QSignalSpy spyContactAdded(m_manager, SIGNAL(contactsAdded(QList<QContactId>))); | ||
587 | 75 | bool result = m_manager->saveContact(&contact); | ||
588 | 76 | QCOMPARE(contact.details<QContactOnlineAccount>().size(), 1); | ||
589 | 77 | QCOMPARE(result, true); | ||
590 | 78 | QTRY_COMPARE(spyContactAdded.count(), 1); | ||
591 | 79 | |||
592 | 80 | // query contacts; | ||
593 | 81 | QContactFilter filter; | ||
594 | 82 | QList<QContact> contacts = m_manager->contacts(filter); | ||
595 | 83 | QCOMPARE(contacts.size(), 1); | ||
596 | 84 | |||
597 | 85 | QList<QContactOnlineAccount> accs = contacts[0].details<QContactOnlineAccount>(); | ||
598 | 86 | QCOMPARE(accs.size(), 1); | ||
599 | 87 | |||
600 | 88 | QContactOnlineAccount acc = accs[0]; | ||
601 | 89 | QCOMPARE(acc.protocol(), QContactOnlineAccount::ProtocolIrc); | ||
602 | 90 | QCOMPARE(acc.accountUri(), QStringLiteral("myIRC")); | ||
603 | 91 | QCOMPARE(acc.serviceProvider(), QStringLiteral("irc.freenode.net")); | ||
604 | 92 | } | ||
605 | 93 | |||
606 | 94 | //TODO: implement support for provider in well-know accounts | ||
607 | 95 | /* | ||
608 | 96 | void testCreateSkypeAccount() | ||
609 | 97 | { | ||
610 | 98 | QContact contact = galera::VCardParser::vcardToContact(QString("BEGIN:VCARD\r\n" | ||
611 | 99 | "VERSION:3.0\r\n" | ||
612 | 100 | "X-REMOTE-ID:1dd7d51a1518626a\r\n" | ||
613 | 101 | "N:;Fulano;;;\r\n" | ||
614 | 102 | "EMAIL:fulano@gmail.com\r\n" | ||
615 | 103 | "TEL:123456\r\n" | ||
616 | 104 | "X-SKYPE;PROVIDER=skype.net:mySkype\r\n" | ||
617 | 105 | "CLIENTPIDMAP:56183a5b-5da7-49fe-8cf6-9bfd3633bf6d\r\n" | ||
618 | 106 | "END:VCARD\r\n")); | ||
619 | 107 | |||
620 | 108 | QCOMPARE(contact.details<QContactOnlineAccount>().size(), 1); | ||
621 | 109 | |||
622 | 110 | // create a contact | ||
623 | 111 | QSignalSpy spyContactAdded(m_manager, SIGNAL(contactsAdded(QList<QContactId>))); | ||
624 | 112 | bool result = m_manager->saveContact(&contact); | ||
625 | 113 | QCOMPARE(contact.details<QContactOnlineAccount>().size(), 1); | ||
626 | 114 | QCOMPARE(result, true); | ||
627 | 115 | QTRY_COMPARE(spyContactAdded.count(), 1); | ||
628 | 116 | |||
629 | 117 | // query contacts; | ||
630 | 118 | QContactFilter filter; | ||
631 | 119 | QList<QContact> contacts = m_manager->contacts(filter); | ||
632 | 120 | QCOMPARE(contacts.size(), 1); | ||
633 | 121 | |||
634 | 122 | QList<QContactOnlineAccount> accs = contacts[0].details<QContactOnlineAccount>(); | ||
635 | 123 | QCOMPARE(accs.size(), 1); | ||
636 | 124 | |||
637 | 125 | QContactOnlineAccount acc = accs[0]; | ||
638 | 126 | QCOMPARE(acc.protocol(), QContactOnlineAccount::ProtocolSkype); | ||
639 | 127 | QCOMPARE(acc.accountUri(), QStringLiteral("mySkype")); | ||
640 | 128 | QCOMPARE(acc.serviceProvider(), QStringLiteral("skype.net")); | ||
641 | 129 | } | ||
642 | 130 | */ | ||
643 | 131 | |||
644 | 132 | void testModifyIrcAccount() | ||
645 | 133 | { | ||
646 | 134 | QContact contact = galera::VCardParser::vcardToContact(QString("BEGIN:VCARD\r\n" | ||
647 | 135 | "VERSION:3.0\r\n" | ||
648 | 136 | "X-REMOTE-ID:1dd7d51a1518626a\r\n" | ||
649 | 137 | "N:;Fulano;;;\r\n" | ||
650 | 138 | "EMAIL:fulano@gmail.com\r\n" | ||
651 | 139 | "TEL:123456\r\n" | ||
652 | 140 | "X-IRC;PROVIDER=irc.freenode.net:myIRC\r\n" | ||
653 | 141 | "CLIENTPIDMAP:56183a5b-5da7-49fe-8cf6-9bfd3633bf6d\r\n" | ||
654 | 142 | "END:VCARD\r\n")); | ||
655 | 143 | |||
656 | 144 | QCOMPARE(contact.details<QContactOnlineAccount>().size(), 1); | ||
657 | 145 | |||
658 | 146 | // create a contact | ||
659 | 147 | QSignalSpy spyContactAdded(m_manager, SIGNAL(contactsAdded(QList<QContactId>))); | ||
660 | 148 | bool result = m_manager->saveContact(&contact); | ||
661 | 149 | QCOMPARE(result, true); | ||
662 | 150 | QTRY_COMPARE(spyContactAdded.count(), 1); | ||
663 | 151 | |||
664 | 152 | // query contacts; | ||
665 | 153 | QContactFilter filter; | ||
666 | 154 | QList<QContact> contacts = m_manager->contacts(filter); | ||
667 | 155 | QCOMPARE(contacts.size(), 1); | ||
668 | 156 | |||
669 | 157 | contact = contacts[0]; | ||
670 | 158 | QList<QContactOnlineAccount> accs = contact.details<QContactOnlineAccount>(); | ||
671 | 159 | QCOMPARE(accs.size(), 1); | ||
672 | 160 | |||
673 | 161 | QContactOnlineAccount acc = accs[0]; | ||
674 | 162 | acc.setAccountUri(QStringLiteral("otherIRC")); | ||
675 | 163 | contact.saveDetail(&acc); | ||
676 | 164 | |||
677 | 165 | QSignalSpy spyContactChanged(m_manager, SIGNAL(contactsChanged(QList<QContactId>))); | ||
678 | 166 | result = m_manager->saveContact(&contact); | ||
679 | 167 | QCOMPARE(result, true); | ||
680 | 168 | QTRY_COMPARE(spyContactChanged.count(), 1); | ||
681 | 169 | |||
682 | 170 | accs = contact.details<QContactOnlineAccount>(); | ||
683 | 171 | QCOMPARE(accs.size(), 1); | ||
684 | 172 | |||
685 | 173 | acc = accs[0]; | ||
686 | 174 | QCOMPARE(acc.protocol(), QContactOnlineAccount::ProtocolIrc); | ||
687 | 175 | QCOMPARE(acc.accountUri(), QStringLiteral("otherIRC")); | ||
688 | 176 | QCOMPARE(acc.serviceProvider(), QStringLiteral("irc.freenode.net")); | ||
689 | 177 | } | ||
690 | 178 | }; | ||
691 | 179 | |||
692 | 180 | QTEST_MAIN(ContactAccountTest) | ||
693 | 181 | |||
694 | 182 | #include "contact-accounts-test.moc" | ||
695 | 0 | 183 | ||
696 | === modified file 'tests/unittest/vcardparser-test.cpp' | |||
697 | --- tests/unittest/vcardparser-test.cpp 2015-09-29 14:15:42 +0000 | |||
698 | +++ tests/unittest/vcardparser-test.cpp 2017-03-22 11:39:22 +0000 | |||
699 | @@ -425,6 +425,87 @@ | |||
700 | 425 | QString vcard = VCardParser::contactToVcard(c); | 425 | QString vcard = VCardParser::contactToVcard(c); |
701 | 426 | QVERIFY(vcard.contains("UID:11")); | 426 | QVERIFY(vcard.contains("UID:11")); |
702 | 427 | } | 427 | } |
703 | 428 | |||
704 | 429 | /* | ||
705 | 430 | * Test parse a vcard with irc | ||
706 | 431 | */ | ||
707 | 432 | void testVCardWithIrc() | ||
708 | 433 | { | ||
709 | 434 | QString vcard = QStringLiteral("BEGIN:VCARD\r\n" | ||
710 | 435 | "VERSION:3.0\r\n" | ||
711 | 436 | "N:Sauro;Dino;da Silva;;\r\n" | ||
712 | 437 | "X-IRC;PROVIDER=irc.freenode.net:myIRC\r\n" | ||
713 | 438 | "REV:2015-04-14T21:56:56Z(2300)\r\n" | ||
714 | 439 | "END:VCARD\r\n"); | ||
715 | 440 | QContact contact = VCardParser::vcardToContact(vcard); | ||
716 | 441 | QList<QContactOnlineAccount> accs = contact.details<QContactOnlineAccount>(); | ||
717 | 442 | QCOMPARE(accs.size(), 1); | ||
718 | 443 | |||
719 | 444 | QContactOnlineAccount acc = accs.at(0); | ||
720 | 445 | QCOMPARE(acc.protocol(), QContactOnlineAccount::ProtocolIrc); | ||
721 | 446 | QCOMPARE(acc.accountUri(), QStringLiteral("myIRC")); | ||
722 | 447 | QCOMPARE(acc.serviceProvider(), QStringLiteral("irc.freenode.net")); | ||
723 | 448 | |||
724 | 449 | QList<QContactExtendedDetail> exs = contact.details<QContactExtendedDetail>(); | ||
725 | 450 | QCOMPARE(exs.size(), 1); | ||
726 | 451 | |||
727 | 452 | QContactExtendedDetail ex = exs.at(0); | ||
728 | 453 | QCOMPARE(ex.name(), QStringLiteral("X-IRC")); | ||
729 | 454 | QCOMPARE(ex.data().toString(), QStringLiteral("myIRC")); | ||
730 | 455 | QCOMPARE(ex.value(QContactExtendedDetail::FieldData+1).toString(), QStringLiteral("irc.freenode.net")); | ||
731 | 456 | } | ||
732 | 457 | |||
733 | 458 | void testContactWithIrc() | ||
734 | 459 | { | ||
735 | 460 | QContact c = m_contacts[0]; | ||
736 | 461 | |||
737 | 462 | QContactOnlineAccount acc; | ||
738 | 463 | acc.setProtocol(QContactOnlineAccount::ProtocolIrc); | ||
739 | 464 | acc.setAccountUri(QStringLiteral("myIRC")); | ||
740 | 465 | acc.setServiceProvider(QStringLiteral("irc.freenode.net")); | ||
741 | 466 | c.saveDetail(&acc); | ||
742 | 467 | |||
743 | 468 | QString vcard = VCardParser::contactToVcard(c); | ||
744 | 469 | QVERIFY(vcard.contains("X-IRC;PROVIDER=irc.freenode.net:myIRC")); | ||
745 | 470 | } | ||
746 | 471 | |||
747 | 472 | /* | ||
748 | 473 | * Test parse a vcard with an online account | ||
749 | 474 | */ | ||
750 | 475 | void testVCardWithSkype() | ||
751 | 476 | { | ||
752 | 477 | QString vcard = QStringLiteral("BEGIN:VCARD\r\n" | ||
753 | 478 | "VERSION:3.0\r\n" | ||
754 | 479 | "N:Sauro;Dino;da Silva;;\r\n" | ||
755 | 480 | "X-SKYPE;PROVIDER=microsoft.com:mySkype\r\n" | ||
756 | 481 | "REV:2015-04-14T21:56:56Z(2300)\r\n" | ||
757 | 482 | "END:VCARD\r\n"); | ||
758 | 483 | QContact contact = VCardParser::vcardToContact(vcard); | ||
759 | 484 | QList<QContactOnlineAccount> accs = contact.details<QContactOnlineAccount>(); | ||
760 | 485 | QCOMPARE(accs.size(), 1); | ||
761 | 486 | |||
762 | 487 | QContactOnlineAccount acc = accs.at(0); | ||
763 | 488 | QCOMPARE(acc.protocol(), QContactOnlineAccount::ProtocolSkype); | ||
764 | 489 | QCOMPARE(acc.accountUri(), QStringLiteral("mySkype")); | ||
765 | 490 | QCOMPARE(acc.serviceProvider(), QStringLiteral("microsoft.com")); | ||
766 | 491 | |||
767 | 492 | QList<QContactExtendedDetail> exs = contact.details<QContactExtendedDetail>(); | ||
768 | 493 | QCOMPARE(exs.size(), 0); | ||
769 | 494 | } | ||
770 | 495 | |||
771 | 496 | void testContactWithSkype() | ||
772 | 497 | { | ||
773 | 498 | QContact c = m_contacts[0]; | ||
774 | 499 | |||
775 | 500 | QContactOnlineAccount acc; | ||
776 | 501 | acc.setProtocol(QContactOnlineAccount::ProtocolSkype); | ||
777 | 502 | acc.setAccountUri(QStringLiteral("mySkype")); | ||
778 | 503 | acc.setServiceProvider(QStringLiteral("microsoft.com")); | ||
779 | 504 | c.saveDetail(&acc); | ||
780 | 505 | |||
781 | 506 | QString vcard = VCardParser::contactToVcard(c); | ||
782 | 507 | QVERIFY(vcard.contains("X-SKYPE;PROVIDER=microsoft.com:mySkype")); | ||
783 | 508 | } | ||
784 | 428 | }; | 509 | }; |
785 | 429 | 510 | ||
786 | 430 | QTEST_MAIN(VCardParseTest) | 511 | QTEST_MAIN(VCardParseTest) |
FAILED: Continuous integration, rev:235 /jenkins. canonical. com/system- apps/job/ lp-address- book-service- ci/1/
https:/
Executed test runs:
Click here to trigger a rebuild: /jenkins. canonical. com/system- apps/job/ lp-address- book-service- ci/1/rebuild
https:/