TizenRefApp-6415 Search Result isn't Updated after Editing Contact 82/79182/3
authorSergei Kobec <s.kobec@samsung.com>
Mon, 11 Jul 2016 10:38:20 +0000 (13:38 +0300)
committerSergei Kobec <s.kobec@samsung.com>
Tue, 12 Jul 2016 10:24:55 +0000 (13:24 +0300)
Implementation: Added getters to Person, that needed for search functionality

Change-Id: I16ff62c50ece1371a9111b23dc148c2cd1021085
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
lib-common/inc/Contacts/Model/ContactNumberData.h [deleted file]
lib-common/src/Contacts/Model/ContactNumberData.cpp [deleted file]
lib-contacts/inc/Contacts/List/Model/Person.h
lib-contacts/src/Contacts/List/Model/Person.cpp
lib-contacts/src/Contacts/List/Model/PersonSearchData.cpp

diff --git a/lib-common/inc/Contacts/Model/ContactNumberData.h b/lib-common/inc/Contacts/Model/ContactNumberData.h
deleted file mode 100644 (file)
index 0fb73ab..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef CONTACTS_MODEL_CONTACT_NUMBER_DATA_H
-#define CONTACTS_MODEL_CONTACT_NUMBER_DATA_H
-
-#include "Contacts/Model/ContactData.h"
-#include <contacts.h>
-
-namespace Contacts
-{
-       namespace Model
-       {
-               class EXPORT_API ContactNumberData : public ContactData
-               {
-               public:
-                       /**
-                        * @brief Create Number object
-                        * @param[in]   contact         Contact object
-                        * @param[in]   numberRecord    _contacts_number record
-                        */
-                       ContactNumberData(ContactData &contact, contacts_record_h numberRecord);
-                       virtual ~ContactNumberData() override;
-
-                       /**
-                        * @see ContactData::getId()
-                        */
-                       virtual int getId() const override;
-
-                       /**
-                        * @see ContactData::getName()
-                        */
-                       virtual const char *getName() const override;
-
-                       /**
-                        * @see ContactData::getNumber()
-                        */
-                       virtual const char *getNumber() const override;
-
-                       /**
-                        * @see ContactData::getImagePath()
-                        */
-                       virtual const char *getImagePath() const override;
-
-                       //Todo: Implement support update and delete logic
-
-               private:
-                       ContactData &m_ContactData;
-                       contacts_record_h m_NumberRecord;
-               };
-       }
-}
-
-#endif /* CONTACTS_MODEL_CONTACT_NUMBER_DATA_H */
diff --git a/lib-common/src/Contacts/Model/ContactNumberData.cpp b/lib-common/src/Contacts/Model/ContactNumberData.cpp
deleted file mode 100644 (file)
index 949be46..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "Contacts/Model/ContactNumberData.h"
-#include "Common/Database/RecordUtils.h"
-
-using namespace Common::Database;
-using namespace Contacts::Model;
-using namespace Utils;
-
-ContactNumberData::ContactNumberData(ContactData &contact, contacts_record_h numberRecord)
-       : ContactData(TypeContactNumber),
-         m_ContactData(contact), m_NumberRecord(numberRecord)
-{
-}
-
-ContactNumberData::~ContactNumberData()
-{
-       contacts_record_destroy(m_NumberRecord, true);
-}
-
-int ContactNumberData::getId() const
-{
-       return m_ContactData.getId();
-}
-
-const char *ContactNumberData::getName() const
-{
-       return m_ContactData.getName();
-}
-
-const char *ContactNumberData::getNumber() const
-{
-       return getRecordStr(m_NumberRecord, _contacts_number.number);
-}
-
-const char *ContactNumberData::getImagePath() const
-{
-       return m_ContactData.getImagePath();
-}
index 778b13b..05647d2 100644 (file)
@@ -19,6 +19,7 @@
 #define CONTACTS_LIST_MODEL_PERSON_H
 
 #include "Contacts/Model/ContactData.h"
+#include "Common/Database/ChildRecordIterator.h"
 #include "Utils/UniString.h"
 
 #include <contacts.h>
@@ -31,11 +32,6 @@ namespace Utils
 
 namespace Contacts
 {
-       namespace Model
-       {
-               class ContactNumberData;
-       }
-
        namespace List
        {
                namespace Model
@@ -46,10 +42,7 @@ namespace Contacts
                        class Person : public Contacts::Model::ContactData
                        {
                        public:
-                               /**
-                                * @brief Number objects list
-                                */
-                               typedef std::vector<Contacts::Model::ContactNumberData *> Numbers;
+                               typedef std::vector<Common::Database::ChildRecordRange> ContactChildRecords;
 
                                /**
                                 * @brief Complete ContactData::Field with person object fields
@@ -110,9 +103,34 @@ namespace Contacts
                                int getContactId() const;
 
                                /**
+                                * @return Nickname
+                                */
+                               const char *getNickname() const;
+
+                               /**
+                                * @return Note
+                                */
+                               const char *getNotes() const;
+
+                               /**
+                                * @return Organization record
+                                */
+                               contacts_record_h getOrganization() const;
+
+                               /**
+                                * @return Person address list
+                                */
+                               const ContactChildRecords getAddresses() const;
+
+                               /**
+                                * @return Person email list
+                                */
+                               const ContactChildRecords getEmails() const;
+
+                               /**
                                 * @return Person number list
                                 */
-                               const Numbers &getNumbers();
+                               const ContactChildRecords getNumbers() const;
 
                                /**
                                 * @return First letter from formatted person name
@@ -145,6 +163,10 @@ namespace Contacts
                        private:
                                friend class PersonProvider;
 
+                               template <typename Pred>
+                               contacts_record_h getContactChildRecord(unsigned propertyId, Pred predicate) const;
+                               const ContactChildRecords getContactChildRecords(unsigned propertyId) const;
+
                                const Utils::UniString &getSortValue() const;
                                void update(contacts_record_h personRecord);
                                int updateName(contacts_record_h record, unsigned sortProperty);
@@ -156,7 +178,6 @@ namespace Contacts
                                Utils::UniString m_IndexLetter;
                                mutable Utils::UniString m_SortValue;
                                unsigned m_SortProperty;
-                               Numbers m_Numbers;
                        };
                }
        }
index 8d66351..5d51ae7 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "Contacts/List/Model/Person.h"
-#include "Contacts/Model/ContactNumberData.h"
 #include "Common/Database/Queries.h"
 #include "Common/Database/RecordUtils.h"
 #include "Common/Database/RecordIterator.h"
@@ -70,7 +69,7 @@ namespace
                return record;
        }
 
-       contacts_record_h getNumberRecord(contacts_record_h contactRecord)
+       contacts_record_h getDefaultNumberRecord(contacts_record_h contactRecord)
        {
                return getChildRecord(contactRecord, _contacts_contact.number,
                        [](contacts_record_h record) {
@@ -89,9 +88,6 @@ Person::Person(contacts_record_h record)
 
 Person::~Person()
 {
-       for (auto &&number : m_Numbers) {
-               delete number;
-       }
        for (auto &&contact : m_ContactRecords) {
                contacts_record_destroy(contact, true);
        }
@@ -110,7 +106,7 @@ const char *Person::getName() const
 
 const char *Person::getNumber() const
 {
-       return getRecordStr(getNumberRecord(m_DefaultContactRecord), _contacts_number.number);
+       return getRecordStr(getDefaultNumberRecord(m_DefaultContactRecord), _contacts_number.number);
 }
 
 const char *Person::getImagePath() const
@@ -128,24 +124,51 @@ int Person::getContactId() const
        return getRecordInt(m_Record, _contacts_person.display_contact_id);
 }
 
-const Person::Numbers &Person::getNumbers()
+const char *Person::getNickname() const
 {
-       unsigned projection[] = {
-               _contacts_contact.number
-       };
-
-       if (m_Numbers.empty()) {
-               contacts_list_h list = getPersonContacts(getId(), projection);
-               for (auto &&contact : makeRange(list)) {
-                       for (auto &&number : makeRange(contact, _contacts_contact.number)) {
-                               m_Numbers.push_back(new ContactNumberData(*this, number));
-                       }
-                       contacts_record_destroy(contact, false);
+       contacts_record_h record  = getContactChildRecord(_contacts_contact.nickname,
+               [](contacts_record_h record) {
+                       return getRecordStr(record, _contacts_nickname.name) != nullptr;
                }
-               contacts_list_destroy(list, false);
-       }
+       );
+
+       return record ? getRecordStr(record, _contacts_nickname.name) : nullptr;
+}
+
+const char *Person::getNotes() const
+{
+       contacts_record_h record  = getContactChildRecord(_contacts_contact.note,
+               [](contacts_record_h record) {
+                       return getRecordStr(record, _contacts_note.note) != nullptr;
+               }
+       );
 
-       return m_Numbers;
+       return record ? getRecordStr(record, _contacts_note.note) : nullptr;
+}
+
+contacts_record_h Person::getOrganization() const
+{
+       return getContactChildRecord(_contacts_contact.company,
+               [](contacts_record_h record) {
+                       return getRecordStr(record, _contacts_company.name) != nullptr
+                               || getRecordStr(record, _contacts_company.job_title) != nullptr;
+               }
+       );
+}
+
+const Person::ContactChildRecords Person::getAddresses() const
+{
+       return getContactChildRecords(_contacts_contact.address);
+}
+
+const Person::ContactChildRecords Person::getEmails() const
+{
+       return getContactChildRecords(_contacts_contact.email);
+}
+
+const Person::ContactChildRecords Person::getNumbers() const
+{
+       return getContactChildRecords(_contacts_contact.number);
 }
 
 const UniString &Person::getIndexLetter() const
@@ -218,6 +241,34 @@ size_t Person::getContactCount() const
        return m_ContactRecords.size();
 }
 
+template <typename Pred>
+contacts_record_h Person::getContactChildRecord(unsigned propertyId, Pred predicate) const
+{
+       contacts_record_h record = getChildRecord(m_DefaultContactRecord, propertyId);
+       if (record && predicate(record)) {
+               return record;
+       }
+
+       for (auto &&contact : m_ContactRecords) {
+               record = getChildRecord(contact, propertyId);
+               if (record && predicate(record)) {
+                       return record;
+               }
+       }
+
+       return nullptr;
+}
+
+const Person::ContactChildRecords Person::getContactChildRecords(unsigned propertyId) const
+{
+       ContactChildRecords records;
+       for (auto &&contact : m_ContactRecords) {
+               records.push_back(makeRange(contact, propertyId));
+       }
+
+       return records;
+}
+
 const UniString &Person::getSortValue() const
 {
        if (m_SortValue.getI18nStr().empty()) {
index 23e137c..da0121b 100644 (file)
 
 #include "Contacts/List/Model/PersonSearchData.h"
 #include "Contacts/List/Model/Person.h"
-#include "Contacts/Model/ContactNumberData.h"
+#include "Common/Database/RecordUtils.h"
 #include <cstring>
 
 using namespace Contacts::Model;
 using namespace Contacts::List::Model;
+using namespace Common::Database;
 
 PersonSearchData::PersonSearchData(Person &person)
        : SearchData(person)
@@ -78,10 +79,15 @@ SearchResultPtr PersonSearchData::compareName(const std::string &str)
 SearchResultPtr PersonSearchData::compareNumber(const std::string &str)
 {
        auto &person = static_cast<Person &>(getContactData());
-       for (auto &&number : person.getNumbers()) {
-               const char *pos = strstr(number->getNumber(), str.c_str());
-               if (pos) {
-                       return SearchResultPtr(new SearchResult(SearchResult::MatchedNumber, number->getNumber(), { pos, str.size() }));
+       for (auto &&numberRange : person.getNumbers()) {
+               for (auto &&numberRecord : numberRange) {
+                       const char *number = getRecordStr(numberRecord, _contacts_number.number);
+                       const char *pos = strstr(number, str.c_str());
+
+                       if (pos) {
+                               return SearchResultPtr(new SearchResult(SearchResult::MatchedNumber, number, { pos, str.size() }));
+                       }
+
                }
        }