Implemented ContactNumberData 63/65863/8
authorSergei Kobec <s.kobec@samsung.com>
Thu, 14 Apr 2016 10:50:35 +0000 (13:50 +0300)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Mon, 18 Apr 2016 10:59:53 +0000 (03:59 -0700)
Change-Id: Idc0614868075fce036633f49fd9f6caf0191896b
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
lib-common/inc/Contacts/Model/ContactNumberData.h [new file with mode: 0644]
lib-common/inc/Contacts/Model/ContactRecordData.h
lib-common/src/Contacts/Model/ContactNumberData.cpp [new file with mode: 0644]
lib-common/src/Contacts/Model/ContactRecordData.cpp
lib-contacts/inc/Contacts/List/Model/Person.h
lib-contacts/src/Contacts/List/Model/Person.cpp

diff --git a/lib-common/inc/Contacts/Model/ContactNumberData.h b/lib-common/inc/Contacts/Model/ContactNumberData.h
new file mode 100644 (file)
index 0000000..c6171bd
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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 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);
+
+                       /**
+                        * @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 */
index 21c93417a8102a6bd06024e6b0b740d12f8e2055..e69f6d081d7c843f2cd67ed2b293ebbbf13fae35 100644 (file)
@@ -19,6 +19,7 @@
 #define CONTACTS_MODEL_CONTACT_RECORD_DATA_H
 
 #include "Contacts/Model/ContactData.h"
+#include "Contacts/Model/ContactNumberData.h"
 #include "Contacts/Model/DbChangeObserver.h"
 #include <contacts.h>
 #include <vector>
@@ -30,6 +31,11 @@ namespace Contacts
                class EXPORT_API ContactRecordData : public ContactData
                {
                public:
+                       /**
+                        * @brief Number objects list
+                        */
+                       typedef std::vector<ContactNumberData *> Numbers;
+
                        /**
                         * @brief Create ContactRecordData object
                         * @param[in]   type    ContactRecordData type
@@ -62,6 +68,11 @@ namespace Contacts
                         */
                        virtual const char *getImagePath() const override;
 
+                       /**
+                        * @return Contact number list
+                        */
+                       virtual const Numbers &getNumbers();
+
                        /**
                         * @return contact record
                         */
@@ -103,6 +114,23 @@ namespace Contacts
                         */
                        void clearChangedHandles();
 
+                       /**
+                        * @brief Fill contact numbers from DB
+                        * @param[in]   record     _contacts_contact record
+                        */
+                       void fillContactNumbers(contacts_record_h record);
+
+                       /**
+                        * @return Contact numbers
+                        */
+                       const Numbers &getContactNumbers() const;
+
+                       /**
+                        * @param[in]   newContact  New contact record
+                        * @return Changes between current and new contacts
+                        */
+                       int getChanges(contacts_record_h newContact);
+
                        /**
                         * @param[in]   record  Contact record
                         * @return Contact ID
@@ -116,18 +144,13 @@ namespace Contacts
                         */
                        static const char *getValue(contacts_record_h record, Field field);
 
-                       /**
-                        * @param[in]   newContact  New contact record
-                        * @return Changes between current and new contacts
-                        */
-                       int getChanges(contacts_record_h newContact);
-
                private:
                        friend class ContactRecordProvider;
 
                        virtual void onUpdate(contacts_record_h record);
 
                        contacts_record_h m_Record;
+                       Numbers m_Numbers;
                        std::vector<DbChangeObserver::CallbackHandle> m_Handles;
                };
        }
diff --git a/lib-common/src/Contacts/Model/ContactNumberData.cpp b/lib-common/src/Contacts/Model/ContactNumberData.cpp
new file mode 100644 (file)
index 0000000..001974e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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 "Contacts/Utils.h"
+
+using namespace Contacts::Model;
+using namespace Utils;
+
+ContactNumberData::ContactNumberData(ContactData &contact, contacts_record_h numberRecord)
+       : ContactData(TypeContactNumber),
+         m_ContactData(contact), m_NumberRecord(numberRecord)
+{
+}
+
+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 ccdb915817cd40e7a8fe21eb36bfb649f061777f..bd0e3247a3f7f6aa145cbb193087a99716fdd256 100644 (file)
@@ -52,6 +52,15 @@ const char *ContactRecordData::getImagePath() const
        return getValue(m_Record, FieldImage);
 }
 
+const ContactRecordData::Numbers &ContactRecordData::getNumbers()
+{
+       if (m_Numbers.empty()) {
+               fillContactNumbers(m_Record);
+       }
+
+       return m_Numbers;
+}
+
 const contacts_record_h ContactRecordData::getContactRecord() const
 {
        return m_Record;
@@ -92,6 +101,37 @@ void ContactRecordData::clearChangedHandles()
        m_Handles.clear();
 }
 
+void ContactRecordData::fillContactNumbers(contacts_record_h record)
+{
+       auto numberRecords = makeRange(record, _contacts_contact.number);
+       for (auto &&numberRecord : numberRecords) {
+               auto number = new ContactNumberData(*this, numberRecord);
+               m_Numbers.push_back(number);
+       }
+}
+
+const ContactRecordData::Numbers &ContactRecordData::getContactNumbers() const
+{
+       return m_Numbers;
+}
+
+int ContactRecordData::getChanges(contacts_record_h newContact)
+{
+       int changes = ChangedNone;
+
+       for (int i = FieldName; i < FieldMax; ++i) {
+               auto fieldId = static_cast<Field>(i);
+               const char *oldValue = getValue(m_Record, fieldId);
+               const char *newValue = getValue(newContact, fieldId);
+
+               if (!Utils::safeCmp(oldValue, newValue)) {
+                       changes |= (1 << fieldId);
+               }
+       }
+
+       return changes;
+}
+
 int ContactRecordData::getContactId(contacts_record_h record)
 {
        int value = 0;
@@ -127,26 +167,12 @@ const char *ContactRecordData::getValue(contacts_record_h record, Field field)
        return value;
 }
 
-int ContactRecordData::getChanges(contacts_record_h newContact)
-{
-       int changes = ChangedNone;
-
-       for (int i = FieldName; i < FieldMax; ++i) {
-               auto fieldId = static_cast<Field>(i);
-               const char *oldValue = getValue(m_Record, fieldId);
-               const char *newValue = getValue(newContact, fieldId);
-
-               if (!Utils::safeCmp(oldValue, newValue)) {
-                       changes |= (1 << fieldId);
-               }
-       }
-
-       return changes;
-}
-
 void ContactRecordData::onUpdate(contacts_record_h record)
 {
        int changes = getChanges(record);
+
+       m_Numbers.clear();//Todo: Here should be ContactNumberData update/delete
+       fillContactNumbers(m_Record);
        updateRecord(record);
 
        onUpdated(changes);
index 1aa2384eddb52f81d8d55668ca1f48c59695e9ef..39f4ee6ea7a88da1af66904d6e0799939af8d95c 100644 (file)
@@ -78,10 +78,15 @@ namespace Contacts
                                virtual int getId() const override;
 
                                /**
-                                * @see Update record from the database
+                                * @brief Update record from the database
                                 */
                                void updateDbRecord();
 
+                               /**
+                                * @see ContactRecordData::getNumbers()
+                                */
+                               virtual const Numbers &getNumbers() override;
+
                                /**
                                 * @return Displayed by default contact ID
                                 */
index 7ea23649a82f1ef9136168727b6e25bba3798be7..5be27d64074f055ea88a29f57d50398de763a17b 100644 (file)
  */
 
 #include "Contacts/List/Model/Person.h"
+#include "Contacts/RecordListIterator.h"
 #include "Contacts/Utils.h"
 #include "Utils/String.h"
 
 #include <cstring>
 
+using namespace Contacts;
 using namespace Contacts::Model;
 using namespace Contacts::List::Model;
 using namespace Utils;
@@ -90,6 +92,25 @@ void Person::updateDbRecord()
        onUpdate(record);
 }
 
+const Person::Numbers &Person::getNumbers()
+{
+       unsigned projection[] = {
+               _contacts_contact.number
+       };
+
+       if (getContactNumbers().empty()) {
+               contacts_list_h list = getContacts(m_PersonRecord, projection);
+               auto contacts = makeRange(list);
+               for (auto &&contact : contacts) {
+                       fillContactNumbers(contact);
+               }
+
+               contacts_list_destroy(list, false);
+       }
+
+       return getContactNumbers();
+}
+
 int Person::getDisplayContactId() const
 {
        int id = 0;