From 1acee6822c086a55d513c87e533e969abeb05762 Mon Sep 17 00:00:00 2001 From: Nataliia Sydorchuk Date: Tue, 22 Mar 2016 10:01:40 +0200 Subject: [PATCH] TizenRefApp-5910 Implement use of "contacts_vcard_parse_to_contact_foreach " func in the Vcard Provider Change-Id: I70b4c45c204f3334f607af503e70cd14bcf0b115 Signed-off-by: Nataliia Sydorchuk --- .../inc/Contacts/List/Model/VcardProvider.h | 3 -- .../src/Contacts/List/Model/VcardProvider.cpp | 44 ++++++---------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/lib-contact/inc/Contacts/List/Model/VcardProvider.h b/lib-contact/inc/Contacts/List/Model/VcardProvider.h index 60af307..83e0556 100644 --- a/lib-contact/inc/Contacts/List/Model/VcardProvider.h +++ b/lib-contact/inc/Contacts/List/Model/VcardProvider.h @@ -49,9 +49,6 @@ namespace Contacts virtual const Contacts::Model::ContactDataList &getContactDataList() override; private: - contacts_list_h getListFromVcard(const char *path); - - private: Contacts::Model::ContactDataList m_ContactsList; }; } diff --git a/lib-contact/src/Contacts/List/Model/VcardProvider.cpp b/lib-contact/src/Contacts/List/Model/VcardProvider.cpp index b636dbb..9bb86e5 100644 --- a/lib-contact/src/Contacts/List/Model/VcardProvider.cpp +++ b/lib-contact/src/Contacts/List/Model/VcardProvider.cpp @@ -17,7 +17,6 @@ #include "Contacts/Model/ContactRecordData.h" #include "Contacts/List/Model/VcardProvider.h" -#include "Contacts/Utils.h" #include "Utils/Logger.h" using namespace Contacts; @@ -26,16 +25,20 @@ using namespace Contacts::List::Model; VcardProvider::VcardProvider(const char *path) { - contacts_list_h list = getListFromVcard(path); - contacts_record_h record = nullptr; + int err = contacts_vcard_parse_to_contact_foreach(path, [](contacts_record_h record, void *data)->bool { + RETVM_IF(!record || !data, true, "invalid data"); + ContactDataList *list = (ContactDataList *)data; - CONTACTS_LIST_FOREACH(list, record) { ContactRecordData *contact = new ContactRecordData(ContactData::TypeContact); - contact->updateContactRecord(record); - m_ContactsList.push_back(contact); - } - - contacts_list_destroy(list, false); + contacts_record_h recordClone; + contacts_record_clone(record, &recordClone); + contact->updateContactRecord(recordClone); + list->push_back(contact); + + // Return true to continue to scan next contact, according to contacts_vcard_parse_cb specification. + return true; + }, &m_ContactsList); + WARN_IF_ERR(err, "contacts_vcard_parse_to_contact_foreach() failed."); } VcardProvider::~VcardProvider() @@ -49,26 +52,3 @@ const ContactDataList &VcardProvider::getContactDataList() { return m_ContactsList; } - -contacts_list_h VcardProvider::getListFromVcard(const char *path) -{ - contacts_list_h list = nullptr; - - FILE *file = fopen(path, "r"); - RETVM_IF(!file, nullptr, "fopen() failed"); - fseek(file, 0, SEEK_END); - long size = ftell(file); - rewind(file); - - char *stream = new char[size]; - if (stream) { - fread(stream, 1, size, file); - - int err = contacts_vcard_parse_to_contacts(stream, &list); - WARN_IF_ERR(err, "contacts_vcard_parse_to_contacts() failed."); - delete[] stream; - } - - fclose(file); - return list; -} -- 2.7.4