Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | |
| 31 | #include "edscontactbackend.h" |
| 32 | |
| 33 | #include <person.h> |
| 34 | #include <personmodel.h> |
| 35 | #include <contactmethod.h> |
| 36 | #include <collectioneditor.h> |
| 37 | #include <memory> |
| 38 | |
| 39 | static void |
| 40 | client_cb(G_GNUC_UNUSED ESource *source, GAsyncResult *result, G_GNUC_UNUSED gpointer user_data) |
| 41 | { |
| 42 | GError *error = NULL; |
| 43 | EClient *client = e_book_client_connect_finish(result, &error); |
| 44 | if (!client) { |
| 45 | g_warning("%s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 46 | g_clear_error(&error); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 47 | } else { |
| 48 | /* got a client for this addressbook, add as backend */ |
| 49 | PersonModel::instance()->addCollection<EdsContactBackend, EClient *>( |
| 50 | client, LoadOptions::FORCE_ENABLED); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static void |
| 55 | registry_cb(G_GNUC_UNUSED GObject *source, GAsyncResult *result, GCancellable *cancellable) |
| 56 | { |
| 57 | GError *error = NULL; |
| 58 | ESourceRegistry *registry = e_source_registry_new_finish(result, &error); |
| 59 | if(!registry) { |
| 60 | g_critical("Unable to create EDS registry: %s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 61 | g_clear_error(&error); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 62 | return; |
| 63 | } else { |
| 64 | GList *list = e_source_registry_list_enabled(registry, E_SOURCE_EXTENSION_ADDRESS_BOOK); |
| 65 | |
| 66 | for (GList *l = list ; l; l = l->next) { |
| 67 | ESource *source = E_SOURCE(l->data); |
| 68 | /* try to connect to each source ansynch */ |
Stepan Salenikovich | b53e9c0 | 2015-04-14 17:41:10 -0400 | [diff] [blame] | 69 | #if EDS_CHECK_VERSION(3,16,0) |
Edric Milaret | 66c50a3 | 2015-05-06 10:38:42 -0400 | [diff] [blame] | 70 | e_book_client_connect(source, |
| 71 | EdsContactBackend::WAIT_FOR_CONNECTED_SECONDS, |
| 72 | cancellable, |
| 73 | (GAsyncReadyCallback)client_cb, |
| 74 | NULL); |
| 75 | #else |
| 76 | e_book_client_connect(source, cancellable, (GAsyncReadyCallback)client_cb, NULL); |
Stepan Salenikovich | b53e9c0 | 2015-04-14 17:41:10 -0400 | [diff] [blame] | 77 | #endif |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | g_list_free_full(list, g_object_unref); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void load_eds_sources(GCancellable *cancellable) |
| 85 | { |
| 86 | /* load the registery asynchronously, and then each source asynch as well |
| 87 | * pass the cancellable as a param so that the loading of each source can |
| 88 | * also be cancelled |
| 89 | */ |
| 90 | e_source_registry_new(cancellable, (GAsyncReadyCallback)registry_cb, cancellable); |
| 91 | } |
| 92 | |
| 93 | class EdsContactEditor : public CollectionEditor<Person> |
| 94 | { |
| 95 | public: |
| 96 | EdsContactEditor(CollectionMediator<Person>* m, EdsContactBackend* parent); |
| 97 | ~EdsContactEditor(); |
| 98 | virtual bool save ( const Person* item ) override; |
| 99 | virtual bool remove ( const Person* item ) override; |
| 100 | virtual bool edit ( Person* item ) override; |
| 101 | virtual bool addNew ( const Person* item ) override; |
| 102 | virtual bool addExisting( const Person* item ) override; |
| 103 | |
| 104 | private: |
| 105 | virtual QVector<Person*> items() const override; |
| 106 | |
| 107 | QVector<Person*> items_; |
| 108 | EdsContactBackend* collection_; |
| 109 | }; |
| 110 | |
| 111 | EdsContactEditor::EdsContactEditor(CollectionMediator<Person>* m, EdsContactBackend* parent) : |
| 112 | CollectionEditor<Person>(m),collection_(parent) |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | EdsContactEditor::~EdsContactEditor() |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | bool EdsContactEditor::save(const Person* item) |
| 121 | { |
| 122 | Q_UNUSED(item) |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool EdsContactEditor::remove(const Person* item) |
| 127 | { |
Stepan Salenikovich | bb35859 | 2015-07-10 14:45:50 -0400 | [diff] [blame^] | 128 | mediator()->removeItem(item); |
| 129 | return true; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | bool EdsContactEditor::edit( Person* item) |
| 133 | { |
| 134 | Q_UNUSED(item) |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | bool EdsContactEditor::addNew(const Person* item) |
| 139 | { |
| 140 | Q_UNUSED(item) |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | bool EdsContactEditor::addExisting(const Person* item) |
| 145 | { |
| 146 | items_ << const_cast<Person*>(item); |
| 147 | mediator()->addItem(item); |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | QVector<Person*> EdsContactEditor::items() const |
| 152 | { |
| 153 | return items_; |
| 154 | } |
| 155 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 156 | static void free_client_view(EBookClientView *client_view) { |
| 157 | g_return_if_fail(client_view); |
| 158 | GError *error = NULL; |
| 159 | e_book_client_view_stop(client_view, &error); |
| 160 | if (error) { |
| 161 | g_warning("error stopping EBookClientView: %s", error->message); |
| 162 | g_clear_error(&error); |
| 163 | } |
| 164 | g_object_unref(client_view); |
| 165 | } |
| 166 | |
| 167 | static void |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 168 | free_object_list(GSList *list) |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 169 | { |
| 170 | g_slist_free_full(list, g_object_unref); |
| 171 | }; |
| 172 | |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 173 | static void |
| 174 | free_string_list(GSList *list) |
| 175 | { |
| 176 | g_slist_free_full(list, g_free); |
| 177 | }; |
| 178 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 179 | EdsContactBackend::EdsContactBackend(CollectionMediator<Person>* mediator, EClient *client, CollectionInterface* parent) |
| 180 | : CollectionInterface(new EdsContactEditor(mediator,this), parent) |
| 181 | , mediator_(mediator) |
| 182 | , client_(client, g_object_unref) |
| 183 | , cancellable_(g_cancellable_new(), g_object_unref) |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 184 | , client_view_(nullptr, &free_client_view) |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 185 | { |
| 186 | } |
| 187 | |
| 188 | EdsContactBackend::~EdsContactBackend() |
| 189 | { |
| 190 | /* cancel any cancellable operations */ |
| 191 | g_cancellable_cancel(cancellable_.get()); |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 192 | |
| 193 | /* cancel contact loading timeout source, if its not finished */ |
| 194 | if (add_contacts_source_id != 0) |
| 195 | g_source_remove(add_contacts_source_id); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | QString EdsContactBackend::name() const |
| 199 | { |
| 200 | return QObject::tr("Evolution-data-server backend"); |
| 201 | } |
| 202 | |
| 203 | QString EdsContactBackend::category() const |
| 204 | { |
| 205 | return QObject::tr("Contacts"); |
| 206 | } |
| 207 | |
| 208 | bool EdsContactBackend::isEnabled() const |
| 209 | { |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | static void |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 214 | contacts_added(G_GNUC_UNUSED EBookClientView *client_view, const GSList *objects, EdsContactBackend *self) |
| 215 | { |
| 216 | std::unique_ptr<GSList,void(*)(GSList *)> contacts( |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 217 | g_slist_copy_deep((GSList *)objects, (GCopyFunc)g_object_ref, NULL ), &free_object_list); |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 218 | self->addContacts(std::move(contacts)); |
| 219 | } |
| 220 | |
| 221 | static void |
Stepan Salenikovich | eccd310 | 2015-06-26 15:49:34 -0400 | [diff] [blame] | 222 | contacts_modified(EBookClientView *client_view, const GSList *objects, EdsContactBackend *self) |
| 223 | { |
| 224 | /* The parseContact function will check if the contacts we're "adding" have |
| 225 | * the same URI as any existing ones and if so will update those instead */ |
| 226 | contacts_added(client_view, objects, self); |
| 227 | } |
| 228 | |
| 229 | static void |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 230 | contacts_removed(G_GNUC_UNUSED EBookClientView *client_view, const GSList *uids, EdsContactBackend *self) |
| 231 | { |
| 232 | std::unique_ptr<GSList,void(*)(GSList *)> contact_uids( |
| 233 | g_slist_copy_deep((GSList *)uids, (GCopyFunc)g_strdup, NULL ), &free_string_list); |
| 234 | self->removeContacts(std::move(contact_uids)); |
| 235 | } |
| 236 | |
| 237 | static void |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 238 | client_view_cb(EBookClient *client, GAsyncResult *result, EdsContactBackend *self) |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 239 | { |
| 240 | g_return_if_fail(E_IS_BOOK_CLIENT(client)); |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 241 | EBookClientView *client_view = NULL; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 242 | GError *error = NULL; |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 243 | if(!e_book_client_get_view_finish(client, result, &client_view, &error)) { |
| 244 | g_critical("Unable to get client view: %s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 245 | g_clear_error(&error); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 246 | return; |
| 247 | } else { |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 248 | /* we want the EBookClientView to have the same life cycle as the backend */ |
| 249 | std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view_ptr( |
| 250 | client_view, &free_client_view); |
| 251 | self->addClientView(std::move(client_view_ptr)); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 255 | void EdsContactBackend::parseContact(EContact *contact) |
| 256 | { |
| 257 | /* Check if the photo is in-line or a URI, in the case that it is a URI, |
| 258 | * try to make it inline so that the lrc vcard parser is able to get the |
| 259 | * photo. Note that this will only work on local URIs |
| 260 | */ |
| 261 | EContactPhoto *photo = (EContactPhoto *)e_contact_get(contact, E_CONTACT_PHOTO); |
| 262 | if (photo) { |
| 263 | if (photo->type == E_CONTACT_PHOTO_TYPE_URI) { |
| 264 | GError *error = NULL; |
| 265 | if (!e_contact_inline_local_photos(contact, &error)) { |
| 266 | g_warning("could not inline photo from vcard URI: %s", error->message); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 267 | g_clear_error(&error); |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
| 271 | e_contact_photo_free(photo); |
| 272 | |
| 273 | EVCard *vcard = E_VCARD(contact); |
| 274 | gchar *vcard_str = e_vcard_to_string(vcard, EVC_FORMAT_VCARD_30); |
| 275 | Person *p = new Person(vcard_str, Person::Encoding::vCard, this); |
| 276 | g_free(vcard_str); |
Stepan Salenikovich | eccd310 | 2015-06-26 15:49:34 -0400 | [diff] [blame] | 277 | |
| 278 | /* check if this person already exists */ |
| 279 | Person *existing = PersonModel::instance()->getPersonByUid(p->uid()); |
| 280 | if (existing) { |
| 281 | /* update existing person */ |
| 282 | existing->setContactMethods ( p->phoneNumbers() ); |
| 283 | existing->setNickName ( p->nickName() ); |
| 284 | existing->setFirstName ( p->firstName() ); |
| 285 | existing->setFamilyName ( p->secondName() ); |
| 286 | existing->setFormattedName ( p->formattedName() ); |
| 287 | existing->setOrganization ( p->organization() ); |
| 288 | existing->setPreferredEmail ( p->preferredEmail() ); |
| 289 | existing->setGroup ( p->group() ); |
| 290 | existing->setDepartment ( p->department() ); |
| 291 | existing->setPhoto ( p->photo() ); |
| 292 | |
| 293 | delete p; |
| 294 | } else { |
| 295 | editor<Person>()->addExisting(p); |
| 296 | } |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | typedef struct AddContactsData_ |
| 300 | { |
| 301 | EdsContactBackend* backend; |
| 302 | GSList *next; |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 303 | std::unique_ptr<GSList, void(*)(GSList *)> contacts; |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 304 | } AddContactsData; |
| 305 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 306 | void |
| 307 | free_add_contacts_data(AddContactsData *data) |
| 308 | { |
| 309 | g_return_if_fail(data && data->contacts); |
| 310 | data->contacts.reset(); |
| 311 | g_free(data); |
| 312 | } |
| 313 | |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 314 | static gboolean |
| 315 | add_contacts(AddContactsData *data) |
| 316 | { |
| 317 | for (int i = 0; i < data->backend->CONTACT_ADD_LIMIT && data->next; i++) { |
| 318 | data->backend->parseContact(E_CONTACT(data->next->data)); |
| 319 | data->next = data->next->next; |
| 320 | } |
| 321 | |
| 322 | if (!data->next) { |
| 323 | data->backend->lastContactAdded(); |
| 324 | return G_SOURCE_REMOVE; |
| 325 | } |
| 326 | |
| 327 | return G_SOURCE_CONTINUE; |
| 328 | } |
| 329 | |
| 330 | void EdsContactBackend::lastContactAdded() |
| 331 | { |
| 332 | /* Sets the source id to 0 to make sure we don't try to remove this source |
| 333 | * after it has already finished */ |
| 334 | add_contacts_source_id = 0; |
| 335 | } |
| 336 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 337 | void EdsContactBackend::addClientView(std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view) |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 338 | { |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 339 | client_view_ = std::move(client_view); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 340 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 341 | /* connect signals for adding, removing, and modifying contacts */ |
| 342 | g_signal_connect(client_view_.get(), "objects-added", G_CALLBACK(contacts_added), this); |
Stepan Salenikovich | eccd310 | 2015-06-26 15:49:34 -0400 | [diff] [blame] | 343 | g_signal_connect(client_view_.get(), "objects-modified", G_CALLBACK(contacts_modified), this); |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 344 | g_signal_connect(client_view_.get(), "objects-removed", G_CALLBACK(contacts_removed), this); |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 345 | |
| 346 | /* start processing the signals */ |
| 347 | GError *error = NULL; |
| 348 | e_book_client_view_start(client_view_.get(), &error); |
| 349 | if (error) { |
| 350 | g_critical("Unable to get start client view: %s", error->message); |
| 351 | g_clear_error(&error); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | void EdsContactBackend::addContacts(std::unique_ptr<GSList, void(*)(GSList *)> contacts) |
| 356 | { |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 357 | /* add CONTACT_ADD_LIMIT # of contacts every CONTACT_ADD_INTERVAL miliseconds */ |
| 358 | AddContactsData *data = g_new0(AddContactsData, 1); |
| 359 | data->backend = this; |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 360 | data->contacts = std::move(contacts); |
| 361 | data->next = data->contacts.get(); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 362 | |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 363 | g_timeout_add_full(G_PRIORITY_DEFAULT, |
| 364 | CONTACT_ADD_INTERVAL, |
| 365 | (GSourceFunc)add_contacts, |
| 366 | data, |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 367 | (GDestroyNotify)free_add_contacts_data); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 368 | } |
| 369 | |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 370 | void EdsContactBackend::removeContacts(std::unique_ptr<GSList, void(*)(GSList *)> contact_uids) |
| 371 | { |
| 372 | GSList *next = contact_uids.get(); |
| 373 | while(next) { |
| 374 | gchar *uid = (gchar *)next->data; |
| 375 | if (uid) { |
| 376 | Person *p = PersonModel::instance()->getPersonByUid(uid); |
| 377 | if (p) { |
| 378 | g_debug("removing: %s", p->formattedName().toUtf8().constData()); |
| 379 | deactivate(p); |
Stepan Salenikovich | bb35859 | 2015-07-10 14:45:50 -0400 | [diff] [blame^] | 380 | editor<Person>()->remove(p); |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 381 | } else { |
| 382 | g_warning("person with given UID doesn't exist: %s", uid); |
| 383 | } |
| 384 | } else { |
| 385 | g_warning("null UID in list"); |
| 386 | } |
| 387 | next = g_slist_next(next); |
| 388 | } |
| 389 | } |
| 390 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 391 | bool EdsContactBackend::load() |
| 392 | { |
| 393 | /** |
| 394 | * load the contacts by querying for them, |
| 395 | * we want the contact to have some kind of name |
| 396 | */ |
| 397 | EBookQuery *queries[4]; |
| 398 | int idx = 0; |
| 399 | queries[idx++] = e_book_query_field_exists(E_CONTACT_NAME_OR_ORG); |
| 400 | queries[idx++] = e_book_query_field_exists(E_CONTACT_GIVEN_NAME); |
| 401 | queries[idx++] = e_book_query_field_exists(E_CONTACT_FAMILY_NAME); |
| 402 | queries[idx++] = e_book_query_field_exists(E_CONTACT_NICKNAME); |
| 403 | |
| 404 | EBookQuery *name_query = e_book_query_or(idx, queries, TRUE); |
| 405 | gchar *query_str = e_book_query_to_string(name_query); |
| 406 | e_book_query_unref(name_query); |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 407 | |
| 408 | /* test */ |
| 409 | e_book_client_get_view(E_BOOK_CLIENT(client_.get()), |
| 410 | query_str, |
| 411 | cancellable_.get(), |
| 412 | (GAsyncReadyCallback)client_view_cb, |
| 413 | this); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 414 | g_free(query_str); |
| 415 | |
| 416 | return true; |
| 417 | } |
| 418 | |
| 419 | bool EdsContactBackend::reload() |
| 420 | { |
| 421 | return false; |
| 422 | } |
| 423 | |
Stepan Salenikovich | 4e40993 | 2015-04-24 12:12:39 -0400 | [diff] [blame] | 424 | FlagPack<CollectionInterface::SupportedFeatures> EdsContactBackend::supportedFeatures() const |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 425 | { |
Stepan Salenikovich | 4e40993 | 2015-04-24 12:12:39 -0400 | [diff] [blame] | 426 | return (CollectionInterface::SupportedFeatures::NONE | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 427 | CollectionInterface::SupportedFeatures::LOAD); |
| 428 | } |
| 429 | |
| 430 | bool EdsContactBackend::clear() |
| 431 | { |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | QByteArray EdsContactBackend::id() const |
| 436 | { |
| 437 | return "edscb"; |
| 438 | } |