Changed contact provider files location to more appropriate, changed their namespaces. 37/62537/2
authorSergei Kobec <s.kobec@samsung.com>
Wed, 16 Mar 2016 12:19:57 +0000 (14:19 +0200)
committerSergei Kobec <s.kobec@samsung.com>
Wed, 16 Mar 2016 12:19:57 +0000 (14:19 +0200)
Change-Id: I1d77768e83aa7681ad0d2172b50d3bc3441887e2
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
20 files changed:
lib-common/inc/Contacts/ContactData.h [deleted file]
lib-common/inc/Contacts/DbChangeObserver.h [deleted file]
lib-common/inc/Contacts/Model/ContactData.h [new file with mode: 0644]
lib-common/inc/Contacts/Model/ContactDataProvider.h [moved from lib-common/inc/Contacts/ContactDataProvider.h with 50% similarity]
lib-common/inc/Contacts/Model/ContactRecordData.h [new file with mode: 0644]
lib-common/inc/Contacts/Model/ContactRecordProvider.h [moved from lib-contact/inc/Contacts/List/Model/ContactRecordProvider.h with 55% similarity]
lib-common/inc/Contacts/Model/DbChangeObserver.h [new file with mode: 0644]
lib-common/src/Contacts/Model/ContactData.cpp [moved from lib-common/src/Contacts/ContactData.cpp with 94% similarity]
lib-common/src/Contacts/Model/ContactDataProvider.cpp [moved from lib-common/src/Contacts/ContactDataProvider.cpp with 92% similarity]
lib-common/src/Contacts/Model/ContactRecordData.cpp [moved from lib-contact/src/Contacts/List/Model/ContactRecordData.cpp with 97% similarity]
lib-common/src/Contacts/Model/ContactRecordProvider.cpp [moved from lib-contact/src/Contacts/List/Model/ContactRecordProvider.cpp with 94% similarity]
lib-common/src/Contacts/Model/DbChangeObserver.cpp [moved from lib-common/src/Contacts/DbChangeObserver.cpp with 98% similarity]
lib-contact/inc/Contacts/List/ListView.h
lib-contact/inc/Contacts/List/Model/ContactRecordData.h [deleted file]
lib-contact/inc/Contacts/List/Model/Person.h
lib-contact/inc/Contacts/List/Model/PersonProvider.h
lib-contact/inc/Contacts/List/Model/VcardProvider.h
lib-contact/src/Contacts/List/ListView.cpp
lib-contact/src/Contacts/List/Model/PersonProvider.cpp
lib-contact/src/Contacts/List/Model/VcardProvider.cpp

diff --git a/lib-common/inc/Contacts/ContactData.h b/lib-common/inc/Contacts/ContactData.h
deleted file mode 100644 (file)
index 4013596..0000000
+++ /dev/null
@@ -1,162 +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_CONTACT_DATA_H
-#define CONTACTS_CONTACT_DATA_H
-
-#include <memory>
-#include <tizen.h>
-#include <list>
-
-namespace Contacts
-{
-       class ContactData;
-
-       typedef std::unique_ptr<ContactData> ContactDataPtr;
-       typedef std::list<ContactData *> ContactDataList;
-
-       class EXPORT_API ContactData
-       {
-       public:
-               /**
-                * @brief Determine object type
-                */
-               enum Type
-               {
-                       TypeSpeeddial,  /**< Speeddial number */
-                       TypeLog,        /**< Log number */
-                       TypePerson,     /**< Person */
-                       TypeContact     /**< Contact */
-               };
-
-               /**
-                * @brief Determine object fields
-                */
-               enum Field
-               {
-                       FieldFirst,
-                       FieldName = FieldFirst, /**< Name */
-                       FieldNumber,            /**< Number */
-                       FieldImage,             /**< Image path */
-                       FieldMax                /**< Sentinel value */
-               };
-
-               /**
-                * @brief Represents ContactData changes on update event
-                */
-               enum ChangedInfo
-               {
-                       ChangedNone     = 0,                /**< Nothing was changed */
-                       ChangedName     = 1 << FieldName,   /**< Name has changed */
-                       ChangedNumber   = 1 << FieldNumber, /**< Number has changed */
-                       ChangedImage    = 1 << FieldImage   /**< Image path has changed */
-               };
-
-               /**
-                * @brief Change callback
-                * @param[in] Changed info
-                */
-               typedef std::function<void(int)> UpdateCallback;
-
-               /**
-                * @brief Delete callback
-                */
-               typedef std::function<void()> DeleteCallback;
-
-               /**
-                * @brief Create ContactData object
-                * @param[in]   type    ContactData type
-                */
-               ContactData(Type type);
-               ContactData(const ContactData &that) = delete;
-               virtual ~ContactData() { }
-
-               ContactData &operator=(const ContactData &that) = delete;
-
-               /**
-                * @return ID
-                */
-               virtual int getId() const = 0;
-
-               /**
-                * @return Name
-                */
-               virtual const char *getName() const = 0;
-
-               /**
-                * @return Number
-                */
-               virtual const char *getNumber() const = 0;
-
-               /**
-                * @return Image path
-                */
-               virtual const char *getImagePath() const = 0;
-
-               /**
-                * @return ContactData type
-                */
-               Type getType() const;
-
-               /**
-                * @brief Determine if object searchable string contains @a str
-                * @return true if it contains, false if not
-                */
-               virtual bool compare(const char *str) = 0;
-
-               /**
-                * @brief Set update callback
-                * @param[in]   callback    Update callback
-                */
-               void setUpdateCallback(UpdateCallback callback);
-
-               /**
-                * @brief Unset update callback
-                */
-               void unsetUpdateCallback();
-
-               /**
-                * @brief Set delete callback
-                * @param[in]   callback    Delete callback
-                */
-               void setDeleteCallback(DeleteCallback callback);
-
-               /**
-                * @brief Unset delete callback
-                */
-               void unsetDeleteCallback();
-
-       protected:
-               /**
-                * @brief ContactData updated callback
-                * @param[in]   changes     Changed info
-                */
-               void onUpdated(int changes);
-
-               /**
-                * @brief ContactData deleted callback
-                */
-               void onDeleted();
-
-       private:
-               Type m_Type;
-               UpdateCallback m_OnUpdated;
-               DeleteCallback m_OnDeleted;
-       };
-}
-
-#endif /* CONTACTS_CONTACT_DATA_H */
diff --git a/lib-common/inc/Contacts/DbChangeObserver.h b/lib-common/inc/Contacts/DbChangeObserver.h
deleted file mode 100644 (file)
index 149324b..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2015 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_LIST_MODEL_DB_CHANGE_OBSERVER_H
-#define CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H
-
-#include <contacts.h>
-#include <functional>
-#include <list>
-#include <tizen.h>
-#include <unordered_map>
-
-namespace Contacts
-{
-       /**
-        * @brief Observe changes in contacts DB table
-        */
-       class EXPORT_API DbChangeObserver
-       {
-       public:
-               /**
-                * @brief Represents what DB table is observed by this object
-                */
-               enum Table
-               {
-                       TableFirst,
-                       TableContact = TableFirst,
-                       TableMax
-               };
-
-               /**
-                * @brief Callback function prototype
-                * @param[in]   id          Contact DB record ID
-                * @param[in]   changeType  Inserted/Updated/Deleted change type
-                */
-               typedef std::function<void(int id, contacts_changed_e changeType)> Callback;
-
-       private:
-               typedef std::list<Callback> RecordCbs;
-
-       public:
-               /**
-                * @brief Callback handle
-                * @remark Used to remove callback
-                */
-               typedef RecordCbs::const_iterator CallbackHandle;
-
-               /**
-                * @brief Get observer instance
-                * @param[in]   table     DB table view
-                * @return observer object on success or nullptr if wrong parameter passed
-                */
-               static DbChangeObserver *getInstance(Table table = TableContact);
-
-               ~DbChangeObserver();
-
-               DbChangeObserver(const DbChangeObserver &that) = delete;
-               DbChangeObserver &operator=(const DbChangeObserver &that) = delete;
-
-               /**
-                * @brief Add callback
-                * @param[in]   callback    DB change callback
-                * @return Callback handle
-                */
-               CallbackHandle addCallback(Callback callback);
-
-               /**
-                * @brief Remove callback
-                * @param[in]   handle      Handle to delete callback
-                */
-               void removeCallback(CallbackHandle handle);
-
-               /**
-                * @brief Add callback
-                * @param[in]   id          Record ID
-                * @param[in]   callback    DB change callback
-                * @return Callback handle
-                */
-               CallbackHandle addCallback(int id, Callback callback);
-
-               /**
-                * @brief Remove callback
-                * @param[in]   id          Record ID
-                * @param[in]   handle      Callback handle
-                */
-               void removeCallback(int id, CallbackHandle handle);
-
-       private:
-               typedef RecordCbs                          Callbacks;
-               typedef std::unordered_map<int, RecordCbs> ChangeCallbacks;
-
-               DbChangeObserver(Table table);
-               DbChangeObserver(DbChangeObserver &&that) = default;
-
-               void subscribe();
-               void unsubscribe();
-
-               CallbackHandle addCallback(RecordCbs &recordCbs, Callback callback);
-
-               void onChanged(const char *viewUri);
-               void notifyContactChanges();
-               void notify(int id, contacts_changed_e changeType);
-
-               static DbChangeObserver m_Observers[TableMax];
-
-               Callbacks m_Callbacks;
-               ChangeCallbacks m_ChangeCallbacks;
-
-               Table m_Table;
-               int m_DbVersion;
-               bool m_IsSubscribed;
-       };
-}
-
-#endif /* CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H */
diff --git a/lib-common/inc/Contacts/Model/ContactData.h b/lib-common/inc/Contacts/Model/ContactData.h
new file mode 100644 (file)
index 0000000..4d80513
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * 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_CONTACT_DATA_H
+#define CONTACTS_CONTACT_DATA_H
+
+#include <memory>
+#include <tizen.h>
+#include <list>
+
+namespace Contacts
+{
+       namespace Model
+       {
+               class ContactData;
+
+               typedef std::unique_ptr<ContactData> ContactDataPtr;
+               typedef std::list<ContactData *> ContactDataList;
+
+               class EXPORT_API ContactData
+               {
+               public:
+                       /**
+                        * @brief Determine object type
+                        */
+                       enum Type
+                       {
+                               TypeSpeeddial,  /**< Speeddial number */
+                               TypeLog,        /**< Log number */
+                               TypePerson,     /**< Person */
+                               TypeContact     /**< Contact */
+                       };
+
+                       /**
+                        * @brief Determine object fields
+                        */
+                       enum Field
+                       {
+                               FieldFirst,
+                               FieldName = FieldFirst, /**< Name */
+                               FieldNumber,            /**< Number */
+                               FieldImage,             /**< Image path */
+                               FieldMax                /**< Sentinel value */
+                       };
+
+                       /**
+                        * @brief Represents ContactData changes on update event
+                        */
+                       enum ChangedInfo
+                       {
+                               ChangedNone     = 0,                /**< Nothing was changed */
+                               ChangedName     = 1 << FieldName,   /**< Name has changed */
+                               ChangedNumber   = 1 << FieldNumber, /**< Number has changed */
+                               ChangedImage    = 1 << FieldImage   /**< Image path has changed */
+                       };
+
+                       /**
+                        * @brief Change callback
+                        * @param[in] Changed info
+                        */
+                       typedef std::function<void(int)> UpdateCallback;
+
+                       /**
+                        * @brief Delete callback
+                        */
+                       typedef std::function<void()> DeleteCallback;
+
+                       /**
+                        * @brief Create ContactData object
+                        * @param[in]   type    ContactData type
+                        */
+                       ContactData(Type type);
+                       ContactData(const ContactData &that) = delete;
+                       virtual ~ContactData() { }
+
+                       ContactData &operator=(const ContactData &that) = delete;
+
+                       /**
+                        * @return ID
+                        */
+                       virtual int getId() const = 0;
+
+                       /**
+                        * @return Name
+                        */
+                       virtual const char *getName() const = 0;
+
+                       /**
+                        * @return Number
+                        */
+                       virtual const char *getNumber() const = 0;
+
+                       /**
+                        * @return Image path
+                        */
+                       virtual const char *getImagePath() const = 0;
+
+                       /**
+                        * @return ContactData type
+                        */
+                       Type getType() const;
+
+                       /**
+                        * @brief Determine if object searchable string contains @a str
+                        * @return true if it contains, false if not
+                        */
+                       virtual bool compare(const char *str) = 0;
+
+                       /**
+                        * @brief Set update callback
+                        * @param[in]   callback    Update callback
+                        */
+                       void setUpdateCallback(UpdateCallback callback);
+
+                       /**
+                        * @brief Unset update callback
+                        */
+                       void unsetUpdateCallback();
+
+                       /**
+                        * @brief Set delete callback
+                        * @param[in]   callback    Delete callback
+                        */
+                       void setDeleteCallback(DeleteCallback callback);
+
+                       /**
+                        * @brief Unset delete callback
+                        */
+                       void unsetDeleteCallback();
+
+               protected:
+                       /**
+                        * @brief ContactData updated callback
+                        * @param[in]   changes     Changed info
+                        */
+                       void onUpdated(int changes);
+
+                       /**
+                        * @brief ContactData deleted callback
+                        */
+                       void onDeleted();
+
+               private:
+                       Type m_Type;
+                       UpdateCallback m_OnUpdated;
+                       DeleteCallback m_OnDeleted;
+               };
+       }
+}
+
+#endif /* CONTACTS_CONTACT_DATA_H */
 #ifndef CONTACTS_CONTACT_DATA_PROVIDER_H
 #define CONTACTS_CONTACT_DATA_PROVIDER_H
 
-#include "Contacts/ContactData.h"
+#include "Contacts/Model/ContactData.h"
 
 #include <functional>
 #include <tizen.h>
 
 namespace Contacts
 {
-       class EXPORT_API ContactDataProvider
+       namespace Model
        {
-       public:
-               /**
-                * @brief Insert callback
-                * @param[in] Contact data
-                */
-               typedef std::function<void(ContactData &)> InsertCallback;
+               class EXPORT_API ContactDataProvider
+               {
+               public:
+                       /**
+                        * @brief Insert callback
+                        * @param[in] Contact data
+                        */
+                       typedef std::function<void(ContactData &)> InsertCallback;
 
-               virtual ~ContactDataProvider() { }
+                       virtual ~ContactDataProvider() { }
 
-               /**
-                * @return Contact data list
-                */
-               virtual const ContactDataList &getContactDataList() = 0;
+                       /**
+                        * @return Contact data list
+                        */
+                       virtual const ContactDataList &getContactDataList() = 0;
 
-               /**
-                * @brief Set insert callback
-                * @param[in]   callback    Create callback
-                */
-               void setInsertCallback(InsertCallback callback);
+                       /**
+                        * @brief Set insert callback
+                        * @param[in]   callback    Create callback
+                        */
+                       void setInsertCallback(InsertCallback callback);
 
-               /**
-                * @brief Unset insert callback
-                */
-               void unsetInsertCallback();
+                       /**
+                        * @brief Unset insert callback
+                        */
+                       void unsetInsertCallback();
 
-       protected:
-               /**
-                * @brief ContactData inserted callback
-                * @param[in]   contactData     Contact data
-                */
-               void onInserted(ContactData &contactData);
+               protected:
+                       /**
+                        * @brief ContactData inserted callback
+                        * @param[in]   contactData     Contact data
+                        */
+                       void onInserted(ContactData &contactData);
 
-       private:
-               InsertCallback m_OnInserted;
-       };
+               private:
+                       InsertCallback m_OnInserted;
+               };
+       }
 }
 
 #endif /* CONTACTS_CONTACT_DATA_PROVIDER_H */
diff --git a/lib-common/inc/Contacts/Model/ContactRecordData.h b/lib-common/inc/Contacts/Model/ContactRecordData.h
new file mode 100644 (file)
index 0000000..3f9b0b9
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * 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_LIST_MODEL_CONTACT_RECORD_DATA_H
+#define CONTACTS_LIST_MODEL_CONTACT_RECORD_DATA_H
+
+#include "Contacts/Model/ContactData.h"
+#include "Contacts/Model/DbChangeObserver.h"
+#include <contacts.h>
+
+namespace Contacts
+{
+       namespace Model
+       {
+               class EXPORT_API ContactRecordData : public ContactData
+               {
+               public:
+                       /**
+                        * @brief Create ContactRecordData object
+                        * @param[in]   type    ContactRecordData type
+                        */
+                       ContactRecordData(Type type);
+                       virtual ~ContactRecordData() override;
+
+                       /**
+                        * @brief Update contact record handle
+                        * @param[in]   record  Contact record
+                        */
+                       void updateContactRecord(contacts_record_h record);
+
+                       /**
+                        * @see ContactData::getId()
+                        * @return Contact ID
+                        */
+                       virtual int getId() const override;
+
+                       /**
+                        * @see ContactData::getName()
+                        * @return Contact name
+                        */
+                       virtual const char *getName() const override;
+
+                       /**
+                        * @see ContactData::getNumber()
+                        * @return Contact number
+                        */
+                       virtual const char *getNumber() const override;
+
+                       /**
+                        * @see ContactData::getImagePath()
+                        * @return Contact image path
+                        */
+                       virtual const char *getImagePath() const override;
+
+                       /**
+                        * @see ContactData::compare()
+                        * @detail Compares by name
+                        */
+                       virtual bool compare(const char *str) override;
+
+               protected:
+                       /**
+                        * @return contact record
+                        */
+                       const contacts_record_h getContactRecord() const;
+
+                       /**
+                        * @brief Set changed callback
+                        * @param[in]   callback    Change callback
+                        */
+                       void setChangedCallback(DbChangeObserver::Callback callback);
+
+                       /**
+                        * @brief Unset changed callback
+                        */
+                       void unsetChangedCallback();
+
+                       /**
+                        * @param[in]   record  Contact record
+                        * @return Contact ID
+                        */
+                       static int getContactId(contacts_record_h record);
+
+                       /**
+                        * @param[in]   record  Contact record
+                        * @param[in]   field   Contact field
+                        * @return Contact value Name/Number/ImagePath
+                        */
+                       static const char *getValue(contacts_record_h record, Field field);
+
+                       /**
+                        * @param[in]   oldContact  Old contact record
+                        * @param[in]   newContact  New contact record
+                        * @return Changes between both contacts
+                        */
+                       static int getChanges(contacts_record_h oldContact, contacts_record_h newContact);
+
+               private:
+                       friend class ContactRecordProvider;
+
+                       void onUpdate(contacts_record_h record);
+
+                       contacts_record_h m_Record;
+                       DbChangeObserver::CallbackHandle m_Handle;
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_MODEL_CONTACT_RECORD_DATA_H */
 #ifndef CONTACTS_LIST_MODEL_CONTACT_RECORD_PROVIDER_H
 #define CONTACTS_LIST_MODEL_CONTACT_RECORD_PROVIDER_H
 
-#include "Contacts/ContactDataProvider.h"
-#include "Contacts/DbChangeObserver.h"
+#include "Contacts/Model/ContactDataProvider.h"
+#include "Contacts/Model/DbChangeObserver.h"
 
 namespace Contacts
 {
-       namespace List
+       namespace Model
        {
-               namespace Model
+               class EXPORT_API ContactRecordProvider : public ContactDataProvider
                {
-                       class ContactRecordProvider : public ContactDataProvider
-                       {
-                       public:
-                               ContactRecordProvider();
-                               virtual ~ContactRecordProvider() override;
+               public:
+                       ContactRecordProvider();
+                       virtual ~ContactRecordProvider() override;
 
-                               /**
-                                * @see ContactDataProvider::getContactDataList()
-                                */
-                               virtual const ContactDataList &getContactDataList() override;
+                       /**
+                        * @see ContactDataProvider::getContactDataList()
+                        */
+                       virtual const ContactDataList &getContactDataList() override;
 
-                       private:
-                               void onContactInserted(int id, contacts_changed_e changeType);
-                               void onContactChanged(ContactDataList::iterator contactIt, int id, contacts_changed_e changeType);
+               private:
+                       void onContactInserted(int id, contacts_changed_e changeType);
+                       void onContactChanged(ContactDataList::iterator contactIt, int id, contacts_changed_e changeType);
 
-                               DbChangeObserver::CallbackHandle m_Handle;
-                               ContactDataList m_ContactList;
-                       };
-               }
+                       DbChangeObserver::CallbackHandle m_Handle;
+                       ContactDataList m_ContactList;
+               };
        }
 }
 
diff --git a/lib-common/inc/Contacts/Model/DbChangeObserver.h b/lib-common/inc/Contacts/Model/DbChangeObserver.h
new file mode 100644 (file)
index 0000000..7f92f7f
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2015 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_LIST_MODEL_DB_CHANGE_OBSERVER_H
+#define CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H
+
+#include <contacts.h>
+#include <functional>
+#include <list>
+#include <tizen.h>
+#include <unordered_map>
+
+namespace Contacts
+{
+       namespace Model
+       {
+               /**
+                * @brief Observe changes in contacts DB table
+                */
+               class EXPORT_API DbChangeObserver
+               {
+               public:
+                       /**
+                        * @brief Represents what DB table is observed by this object
+                        */
+                       enum Table
+                       {
+                               TableFirst,
+                               TableContact = TableFirst,
+                               TableMax
+                       };
+
+                       /**
+                        * @brief Callback function prototype
+                        * @param[in]   id          Contact DB record ID
+                        * @param[in]   changeType  Inserted/Updated/Deleted change type
+                        */
+                       typedef std::function<void(int id, contacts_changed_e changeType)> Callback;
+
+               private:
+                       typedef std::list<Callback> RecordCbs;
+
+               public:
+                       /**
+                        * @brief Callback handle
+                        * @remark Used to remove callback
+                        */
+                       typedef RecordCbs::const_iterator CallbackHandle;
+
+                       /**
+                        * @brief Get observer instance
+                        * @param[in]   table     DB table view
+                        * @return observer object on success or nullptr if wrong parameter passed
+                        */
+                       static DbChangeObserver *getInstance(Table table = TableContact);
+
+                       ~DbChangeObserver();
+
+                       DbChangeObserver(const DbChangeObserver &that) = delete;
+                       DbChangeObserver &operator=(const DbChangeObserver &that) = delete;
+
+                       /**
+                        * @brief Add callback
+                        * @param[in]   callback    DB change callback
+                        * @return Callback handle
+                        */
+                       CallbackHandle addCallback(Callback callback);
+
+                       /**
+                        * @brief Remove callback
+                        * @param[in]   handle      Handle to delete callback
+                        */
+                       void removeCallback(CallbackHandle handle);
+
+                       /**
+                        * @brief Add callback
+                        * @param[in]   id          Record ID
+                        * @param[in]   callback    DB change callback
+                        * @return Callback handle
+                        */
+                       CallbackHandle addCallback(int id, Callback callback);
+
+                       /**
+                        * @brief Remove callback
+                        * @param[in]   id          Record ID
+                        * @param[in]   handle      Callback handle
+                        */
+                       void removeCallback(int id, CallbackHandle handle);
+
+               private:
+                       typedef RecordCbs                          Callbacks;
+                       typedef std::unordered_map<int, RecordCbs> ChangeCallbacks;
+
+                       DbChangeObserver(Table table);
+                       DbChangeObserver(DbChangeObserver &&that) = default;
+
+                       void subscribe();
+                       void unsubscribe();
+
+                       CallbackHandle addCallback(RecordCbs &recordCbs, Callback callback);
+
+                       void onChanged(const char *viewUri);
+                       void notifyContactChanges();
+                       void notify(int id, contacts_changed_e changeType);
+
+                       static DbChangeObserver m_Observers[TableMax];
+
+                       Callbacks m_Callbacks;
+                       ChangeCallbacks m_ChangeCallbacks;
+
+                       Table m_Table;
+                       int m_DbVersion;
+                       bool m_IsSubscribed;
+               };
+       }
+}
+
+#endif /* CONTACTS_LIST_MODEL_DB_CHANGE_OBSERVER_H */
similarity index 94%
rename from lib-common/src/Contacts/ContactData.cpp
rename to lib-common/src/Contacts/Model/ContactData.cpp
index 51f7c0d..34ffa63 100644 (file)
@@ -15,9 +15,9 @@
  *
  */
 
-#include "Contacts/ContactData.h"
+#include "Contacts/Model/ContactData.h"
 
-using namespace Contacts;
+using namespace Contacts::Model;
 
 ContactData::ContactData(Type type)
        : m_Type(type)
@@ -15,9 +15,9 @@
  *
  */
 
-#include "Contacts/ContactDataProvider.h"
+#include "Contacts/Model/ContactDataProvider.h"
 
-using namespace Contacts;
+using namespace Contacts::Model;
 
 void ContactDataProvider::setInsertCallback(InsertCallback callback)
 {
  *
  */
 
-#include "Contacts/List/Model/ContactRecordData.h"
+#include "Contacts/Model/ContactRecordData.h"
 #include "Contacts/ContactRecordChildIterator.h"
 #include <cstring>
 
-using namespace Contacts::List::Model;
+using namespace Contacts::Model;
 
 ContactRecordData::ContactRecordData(Type type)
        : ContactData(type), m_Record(nullptr)
  *
  */
 
-#include "Contacts/List/Model/ContactRecordProvider.h"
-#include "Contacts/List/Model/ContactRecordData.h"
+#include "Contacts/Model/ContactRecordProvider.h"
+#include "Contacts/Model/ContactRecordData.h"
 #include "Contacts/Utils.h"
 
 using namespace Contacts;
-using namespace Contacts::List::Model;
+using namespace Contacts::Model;
 using namespace std::placeholders;
 
 ContactRecordProvider::ContactRecordProvider()
  *
  */
 
-#include "Contacts/DbChangeObserver.h"
+#include "Contacts/Model/DbChangeObserver.h"
 #include "Contacts/Utils.h"
 #include "Utils/Callback.h"
 #include "Utils/Range.h"
 
-using namespace Contacts;
+using namespace Contacts::Model;
 
 namespace
 {
index f016f69..ac3a1ff 100644 (file)
@@ -121,7 +121,7 @@ namespace Contacts
                        void onIndexChanged(Evas_Object *index, Elm_Object_Item *indexItem);
                        void onIndexSelected(Evas_Object *index, Elm_Object_Item *indexItem);
 
-                       void onPersonInserted(ContactData &person);
+                       void onPersonInserted(Contacts::Model::ContactData &person);
                        void onPersonUpdated(PersonItem *item, int changes);
                        void onPersonDeleted(PersonItem *item);
 
diff --git a/lib-contact/inc/Contacts/List/Model/ContactRecordData.h b/lib-contact/inc/Contacts/List/Model/ContactRecordData.h
deleted file mode 100644 (file)
index bda7633..0000000
+++ /dev/null
@@ -1,126 +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_LIST_MODEL_CONTACT_RECORD_DATA_H
-#define CONTACTS_LIST_MODEL_CONTACT_RECORD_DATA_H
-
-#include "Contacts/ContactData.h"
-#include "Contacts/DbChangeObserver.h"
-#include <contacts.h>
-
-namespace Contacts
-{
-       namespace List
-       {
-               namespace Model
-               {
-                       class ContactRecordData : public ContactData
-                       {
-                       public:
-                               /**
-                                * @brief Create ContactRecordData object
-                                * @param[in]   type    ContactRecordData type
-                                */
-                               ContactRecordData(Type type);
-                               virtual ~ContactRecordData() override;
-
-                               /**
-                                * @brief Update contact record handle
-                                * @param[in]   record  Contact record
-                                */
-                               void updateContactRecord(contacts_record_h record);
-
-                               /**
-                                * @see ContactData::getId()
-                                * @return Contact ID
-                                */
-                               virtual int getId() const override;
-
-                               /**
-                                * @see ContactData::getName()
-                                * @return Contact name
-                                */
-                               virtual const char *getName() const override;
-
-                               /**
-                                * @see ContactData::getNumber()
-                                * @return Contact number
-                                */
-                               virtual const char *getNumber() const override;
-
-                               /**
-                                * @see ContactData::getImagePath()
-                                * @return Contact image path
-                                */
-                               virtual const char *getImagePath() const override;
-
-                               /**
-                                * @see ContactData::compare()
-                                * @detail Compares by name
-                                */
-                               virtual bool compare(const char *str) override;
-
-                       protected:
-                               /**
-                                * @return contact record
-                                */
-                               const contacts_record_h getContactRecord() const;
-
-                               /**
-                                * @brief Set changed callback
-                                * @param[in]   callback    Change callback
-                                */
-                               void setChangedCallback(DbChangeObserver::Callback callback);
-
-                               /**
-                                * @brief Unset changed callback
-                                */
-                               void unsetChangedCallback();
-
-                               /**
-                                * @param[in]   record  Contact record
-                                * @return Contact ID
-                                */
-                               static int getContactId(contacts_record_h record);
-
-                               /**
-                                * @param[in]   record  Contact record
-                                * @param[in]   field   Contact field
-                                * @return Contact value Name/Number/ImagePath
-                                */
-                               static const char *getValue(contacts_record_h record, Field field);
-
-                               /**
-                                * @param[in]   oldContact  Old contact record
-                                * @param[in]   newContact  New contact record
-                                * @return Changes between both contacts
-                                */
-                               static int getChanges(contacts_record_h oldContact, contacts_record_h newContact);
-
-                       private:
-                               friend class ContactRecordProvider;
-
-                               void onUpdate(contacts_record_h record);
-
-                               contacts_record_h m_Record;
-                               DbChangeObserver::CallbackHandle m_Handle;
-                       };
-               }
-       }
-}
-
-#endif /* CONTACTS_LIST_MODEL_CONTACT_RECORD_DATA_H */
index 11b239e..db7ae60 100644 (file)
@@ -18,8 +18,8 @@
 #ifndef CONTACTS_LIST_MODEL_PERSON_H
 #define CONTACTS_LIST_MODEL_PERSON_H
 
-#include "Contacts/DbChangeObserver.h"
-#include "Contacts/List/Model/ContactRecordData.h"
+#include "Contacts/Model/DbChangeObserver.h"
+#include "Contacts/Model/ContactRecordData.h"
 #include "Utils/UniString.h"
 #include <contacts.h>
 #include <vector>
@@ -38,7 +38,7 @@ namespace Contacts
                        /**
                         * @brief Person object
                         */
-                       class Person : public ContactRecordData
+                       class Person : public Contacts::Model::ContactRecordData
                        {
                        public:
                                /**
@@ -100,7 +100,7 @@ namespace Contacts
                                Utils::UniString m_IndexLetter;
                                mutable Utils::UniString m_SortValue;
 
-                               std::vector<DbChangeObserver::CallbackHandle> m_Handles;
+                               std::vector<Contacts::Model::DbChangeObserver::CallbackHandle> m_Handles;
                        };
                }
        }
index b62f8fa..8e33c3d 100644 (file)
@@ -19,8 +19,8 @@
 #define CONTACTS_LIST_MODEL_PERSON_PROVIDER_H
 
 #include "Contacts/Common/ContactSelectTypes.h"
-#include "Contacts/ContactDataProvider.h"
-#include "Contacts/DbChangeObserver.h"
+#include "Contacts/Model/ContactDataProvider.h"
+#include "Contacts/Model/DbChangeObserver.h"
 
 #include <contacts.h>
 
@@ -35,7 +35,7 @@ namespace Contacts
                        /**
                         * @brief Provides list of person
                         */
-                       class PersonProvider : public ContactDataProvider
+                       class PersonProvider : public Contacts::Model::ContactDataProvider
                        {
                        public:
                                /**
@@ -50,24 +50,24 @@ namespace Contacts
                                 * @brief Get person list
                                 * @return List of contact objects
                                 */
-                               virtual const ContactDataList &getContactDataList() override;
+                               virtual const Contacts::Model::ContactDataList &getContactDataList() override;
 
                        private:
                                contacts_record_h getFilteredRecord(int contactId);
 
                                void insertPerson(contacts_record_h record);
 
-                               void setChangedCallback(ContactDataList::iterator personIt);
-                               void updateChangedCallback(ContactDataList::iterator personIt);
+                               void setChangedCallback(Contacts::Model::ContactDataList::iterator personIt);
+                               void updateChangedCallback(Contacts::Model::ContactDataList::iterator personIt);
                                void unsetChangedCallback(const Person &person);
 
                                void onPersonInserted(int id, contacts_changed_e changeType);
-                               void onPersonChanged(ContactDataList::iterator it, int id, contacts_changed_e changeType);
+                               void onPersonChanged(Contacts::Model::ContactDataList::iterator it, int id, contacts_changed_e changeType);
 
                                int m_FilterType;
 
-                               DbChangeObserver::CallbackHandle m_Handle;
-                               ContactDataList m_PersonList;
+                               Contacts::Model::DbChangeObserver::CallbackHandle m_Handle;
+                               Contacts::Model::ContactDataList m_PersonList;
                        };
                }
        }
index 40ea6e1..60af307 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef CONTACTS_LIST_MODEL_VCARD_PROVIDER_H
 #define CONTACTS_LIST_MODEL_VCARD_PROVIDER_H
 
-#include "Contacts/ContactDataProvider.h"
+#include "Contacts/Model/ContactDataProvider.h"
 
 namespace Contacts
 {
@@ -29,7 +29,7 @@ namespace Contacts
                        /**
                         * @brief Provides list of contacts from vcard
                         */
-                       class VcardProvider : public ContactDataProvider
+                       class VcardProvider : public Contacts::Model::ContactDataProvider
                        {
                        public:
                                /**
@@ -46,13 +46,13 @@ namespace Contacts
                                 * @see ContactDataProvider::getContactDataList()
                                 * @return Contact data list
                                 */
-                               virtual const ContactDataList &getContactDataList() override;
+                               virtual const Contacts::Model::ContactDataList &getContactDataList() override;
 
                        private:
                                contacts_list_h getListFromVcard(const char *path);
 
                        private:
-                               ContactDataList m_ContactsList;
+                               Contacts::Model::ContactDataList m_ContactsList;
                        };
                }
        }
index 4ff63f1..70bf48b 100644 (file)
@@ -32,6 +32,7 @@
 #include "Utils/Callback.h"
 
 using namespace Contacts;
+using namespace Contacts::Model;
 using namespace Contacts::List;
 using namespace Contacts::List::Model;
 using namespace Utils;
index 24bcaf5..d2af283 100644 (file)
@@ -20,6 +20,7 @@
 #include "Contacts/Utils.h"
 
 using namespace Contacts;
+using namespace Contacts::Model;
 using namespace Contacts::List::Model;
 using namespace std::placeholders;
 
index d57870f..b636dbb 100644 (file)
  *
  */
 
-#include "Contacts/List/Model/ContactRecordData.h"
+#include "Contacts/Model/ContactRecordData.h"
 #include "Contacts/List/Model/VcardProvider.h"
 #include "Contacts/Utils.h"
 #include "Utils/Logger.h"
 
 using namespace Contacts;
+using namespace Contacts::Model;
 using namespace Contacts::List::Model;
 
 VcardProvider::VcardProvider(const char *path)