Refactored Contact model to store field adapters in ContactArray and ContactObject. 52/57252/3
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 18 Jan 2016 16:10:40 +0000 (18:10 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 18 Jan 2016 16:10:40 +0000 (18:10 +0200)
Replaced field pointers with references wherever possible.

Change-Id: I6c732068c67915c98ecf3510bbfcad1da37fdbf1
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
32 files changed:
lib-contact/inc/Contacts/Input/ContactCompoundObjectControl.h
lib-contact/inc/Contacts/Input/ContactDateFieldControl.h
lib-contact/inc/Contacts/Input/ContactFieldItem.h
lib-contact/inc/Contacts/Input/ContactFieldSubItem.h
lib-contact/inc/Contacts/Input/ContactImageFieldControl.h
lib-contact/inc/Contacts/Input/ContactObjectTypeControl.h
lib-contact/inc/Contacts/Input/ContactTextFieldControl.h
lib-contact/inc/Contacts/Input/ContactTypedFieldItem.h
lib-contact/inc/Contacts/Input/InputView.h
lib-contact/inc/Contacts/Model/Contact.h
lib-contact/inc/Contacts/Model/ContactArray.h
lib-contact/inc/Contacts/Model/ContactFactory.h
lib-contact/inc/Contacts/Model/ContactField.h
lib-contact/inc/Contacts/Model/ContactIterator.h
lib-contact/inc/Contacts/Model/ContactObject.h
lib-contact/inc/Contacts/Model/ContactTypedObject.h
lib-contact/src/Contacts/Input/ContactCompoundFieldItem.cpp
lib-contact/src/Contacts/Input/ContactCompoundObjectControl.cpp
lib-contact/src/Contacts/Input/ContactDateFieldControl.cpp
lib-contact/src/Contacts/Input/ContactFieldItem.cpp
lib-contact/src/Contacts/Input/ContactFieldSubItem.cpp
lib-contact/src/Contacts/Input/ContactImageFieldControl.cpp
lib-contact/src/Contacts/Input/ContactImageFieldItem.cpp
lib-contact/src/Contacts/Input/ContactObjectTypeControl.cpp
lib-contact/src/Contacts/Input/ContactTextFieldControl.cpp
lib-contact/src/Contacts/Input/ContactTypedFieldItem.cpp
lib-contact/src/Contacts/Input/InputView.cpp
lib-contact/src/Contacts/Model/Contact.cpp
lib-contact/src/Contacts/Model/ContactArray.cpp
lib-contact/src/Contacts/Model/ContactFactory.cpp
lib-contact/src/Contacts/Model/ContactObject.cpp
lib-contact/src/Contacts/Model/ContactTypedObject.cpp

index 0e28e8d85e7c4355f12f1c6c9444090133fc2034..08b5620ad65433ddcccd8d574c92a606ea9a86a4 100644 (file)
@@ -39,13 +39,13 @@ namespace Contacts
                         * @brief Create control
                         * @param[in]   object  Contact compound object
                         */
-                       ContactCompoundObjectControl(Model::ContactCompoundObject *object);
+                       ContactCompoundObjectControl(Model::ContactCompoundObject &object);
 
                private:
                        virtual void onCreated() override;
                        void onUnfocused(Evas_Object *entry, void *eventInfo);
 
-                       Model::ContactCompoundObject *m_Object;
+                       Model::ContactCompoundObject &m_Object;
                };
        }
 }
index 4c58fc62ae5515bc8f5fb7f634469525a18e9980..13d0b05db37fa37dad1461e1e619faec67a473b2 100644 (file)
@@ -39,7 +39,7 @@ namespace Contacts
                         * @brief Create control
                         * @param[in]   field   Contact date field to edit
                         */
-                       ContactDateFieldControl(Model::ContactDateField *field);
+                       ContactDateFieldControl(Model::ContactDateField &field);
 
                private:
                        virtual Evas_Object *onCreate(Evas_Object *parent) override;
@@ -48,7 +48,7 @@ namespace Contacts
                        void setButtonDate(tm date);
                        void onButtonPressed(Evas_Object *button, void *eventInfo);
 
-                       Model::ContactDateField *m_Field;
+                       Model::ContactDateField &m_Field;
                        Evas_Object *m_Button;
                };
        }
index 85842dea48c43be26e4fbfa565036efa0931f276..3a0b5b23dfb148b914a7961b7fc48fdb62624e1c 100644 (file)
  *
  */
 
-#ifndef CONTACTS_INPUT_CONTACT_OBJECT_ITEM_H
-#define CONTACTS_INPUT_CONTACT_OBJECT_ITEM_H
+#ifndef CONTACTS_INPUT_CONTACT_FIELD_ITEM_H
+#define CONTACTS_INPUT_CONTACT_FIELD_ITEM_H
 
-#include "Contacts/Model/ContactField.h"
 #include "Contacts/Input/ContactFieldSubItem.h"
 #include "Ui/GenlistGroupItem.h"
 #include <functional>
@@ -47,13 +46,13 @@ namespace Contacts
                         * @param[in]   Genlist item to be removed
                         * @param[in]   Field to be removed
                         */
-                       typedef std::function<void(ContactFieldItem *, Model::ContactFieldPtr)> RemoveCallback;
+                       typedef std::function<void(ContactFieldItem *)> RemoveCallback;
 
                        /**
                         * @brief Create genlist item representing ContactObject.
                         * @param[in]   object      Contact field of TypeObject type
                         */
-                       ContactFieldItem(Model::ContactFieldPtr object);
+                       ContactFieldItem(Model::ContactObject &object);
 
                        /**
                         * @brief Set remove field callback.
@@ -92,10 +91,10 @@ namespace Contacts
                private:
                        void onRemovePressed(Evas_Object *button, void *eventInfo);
 
-                       Model::ContactFieldPtr m_Object;
+                       Model::ContactObject &m_Object;
                        RemoveCallback m_OnRemove;
                };
        }
 }
 
-#endif /* CONTACTS_INPUT_CONTACT_OBJECT_ITEM_H */
+#endif /* CONTACTS_INPUT_CONTACT_FIELD_ITEM_H */
index ac7e3bdbafb6f09c31c10ef46ee87b115e618666..9f127cd095d7798d3f18323b50146160a86c2940 100644 (file)
  *
  */
 
-#ifndef CONTACTS_INPUT_CONTACT_FIELD_ITEM_H
-#define CONTACTS_INPUT_CONTACT_FIELD_ITEM_H
+#ifndef CONTACTS_INPUT_CONTACT_FIELD_SUB_ITEM_H
+#define CONTACTS_INPUT_CONTACT_FIELD_SUB_ITEM_H
 
-#include "Contacts/Model/ContactField.h"
 #include "Ui/GenlistItem.h"
 
 namespace Contacts
 {
+       namespace Model
+       {
+               class ContactField;
+       }
+
        namespace Input
        {
                /**
@@ -35,7 +39,7 @@ namespace Contacts
                         * @brief Create field genlist item.
                         * @param[in]   field   Contact field of TypeText or TypeDate type
                         */
-                       ContactFieldSubItem(Model::ContactFieldPtr field);
+                       ContactFieldSubItem(Model::ContactField &field);
 
                        /**
                         * @return ContactField associated with the item.
@@ -78,10 +82,10 @@ namespace Contacts
                        void onEntryFocused(Evas_Object *entry, void *eventInfo);
                        void onEntryActivated(Evas_Object *entry, void *eventInfo);
 
-                       Model::ContactFieldPtr m_Field;
+                       Model::ContactField &m_Field;
                        Ui::GenlistItem *m_NextFocusItem;
                };
        }
 }
 
-#endif /* CONTACTS_INPUT_CONTACT_FIELD_ITEM_H */
+#endif /* CONTACTS_INPUT_CONTACT_FIELD_SUB_ITEM_H */
index 19be449e900441698f2829508843ae7c0ac9f9e2..293b51fadb9c84a7a1dc1c8d168b47a34cc2e3ab 100644 (file)
@@ -40,7 +40,7 @@ namespace Contacts
                         * @brief Create control
                         * @param[in]   field   Contact image path field
                         */
-                       ContactImageFieldControl(Model::ContactTextField *field);
+                       ContactImageFieldControl(Model::ContactTextField &field);
 
                private:
                        virtual void onCreated() override;
@@ -50,7 +50,7 @@ namespace Contacts
                                        app_control_result_e result);
                        void onImagePressed(Evas_Object *image, void *eventInfo);
 
-                       Model::ContactTextField *m_Field;
+                       Model::ContactTextField &m_Field;
                        App::AppControl m_AppControl;
                };
        }
index af9f7ae9851f1bbf4e2e8ab83405828f14cd29ed..0a827b5abf09433e983feb4279e6986c1bbbbeca 100644 (file)
@@ -43,15 +43,15 @@ namespace Contacts
                         * @param[in]   typeField   Object's "type" field
                         * @param[in]   labelField  Object's custom type label field
                         */
-                       ContactObjectTypeControl(Model::ContactEnumField *typeField,
-                                       Model::ContactTextField *labelField);
+                       ContactObjectTypeControl(Model::ContactEnumField &typeField,
+                                       Model::ContactTextField &labelField);
 
                private:
                        virtual void onCreated() override;
                        bool onSelected(int value);
 
-                       Model::ContactEnumField *m_TypeField;
-                       Model::ContactTextField *m_LabelField;
+                       Model::ContactEnumField &m_TypeField;
+                       Model::ContactTextField &m_LabelField;
                };
        }
 }
index 41d21be9c7e929620f6fdb4a55c61c0e72d8bc2a..3d7bfee2c0a2dc01191d7441fc055d494829378d 100644 (file)
@@ -39,13 +39,13 @@ namespace Contacts
                         * @brief Create control
                         * @param[in]   field   Contact text field to edit
                         */
-                       ContactTextFieldControl(Model::ContactTextField *field);
+                       ContactTextFieldControl(Model::ContactTextField &field);
 
                private:
                        virtual void onCreated() override;
                        void onUnfocused(Evas_Object *entry, void *eventInfo);
 
-                       Model::ContactTextField *m_Field;
+                       Model::ContactTextField &m_Field;
                };
        }
 }
index 9e55c1abfa2569cfe2d066cd5220954a489a92c9..54b7dece5865f21cfa856050b01582e3d2418c93 100644 (file)
@@ -15,8 +15,8 @@
  *
  */
 
-#ifndef CONTACTS_INPUT_CONTACT_TYPED_OBJECT_ITEM_H
-#define CONTACTS_INPUT_CONTACT_TYPED_OBJECT_ITEM_H
+#ifndef CONTACTS_INPUT_CONTACT_TYPED_FIELD_ITEM_H
+#define CONTACTS_INPUT_CONTACT_TYPED_FIELD_ITEM_H
 
 #include "Contacts/Input/ContactFieldItem.h"
 
@@ -25,6 +25,8 @@ namespace Contacts
        namespace Model
        {
                class ContactTypedObject;
+               class ContactEnumField;
+               class ContactTextField;
        }
 
        namespace Input
@@ -37,9 +39,9 @@ namespace Contacts
                {
                public:
                        /**
-                        * @see ContactObjectItem::ContactObjectItem()
+                        * @see ContactFieldItem::ContactFieldItem()
                         */
-                       ContactTypedFieldItem(Model::ContactFieldPtr object);
+                       ContactTypedFieldItem(Model::ContactObject &object);
 
                protected:
                        /**
@@ -57,10 +59,11 @@ namespace Contacts
                         */
                        virtual Eina_Bool getState(Evas_Object *parent, const char *part) override;
 
-                       Model::ContactFieldPtr m_TypeField;
-                       Model::ContactFieldPtr m_LabelField;
+               private:
+                       Model::ContactEnumField &m_TypeField;
+                       Model::ContactTextField &m_LabelField;
                };
        }
 }
 
-#endif /* CONTACTS_INPUT_CONTACT_TYPED_OBJECT_ITEM_H */
+#endif /* CONTACTS_INPUT_CONTACT_TYPED_FIELD_ITEM_H */
index b2711e4305c8c09207795806b8798d3ac6e534c2..becb3e3432e85c8527691b0bdd27c6f16b5b5079 100644 (file)
@@ -61,17 +61,17 @@ namespace Contacts
                        virtual void onCreated() override;
                        virtual void onPageAttached() override;
 
-                       ContactFieldItem *createFieldItem(Model::ContactFieldPtr field);
+                       ContactFieldItem *createFieldItem(Model::ContactObject &field);
                        Ui::GenlistItem *getNextFieldItem(Model::ContactFieldId fieldId);
 
-                       Model::ContactFieldPtr addField(Model::ContactFieldId fieldId);
-                       void removeField(Model::ContactFieldPtr field);
+                       Model::ContactObject &addField(Model::ContactFieldId fieldId);
+                       void removeField(Model::ContactObject &field);
 
-                       ContactFieldItem *addFieldItem(Model::ContactFieldPtr field);
-                       void removeFieldItem(ContactFieldItem *item, Model::ContactFieldId fieldId);
+                       ContactFieldItem *addFieldItem(Model::ContactObject &field);
+                       void removeFieldItem(ContactFieldItem *item);
 
                        void onAddField(Model::ContactFieldId fieldId);
-                       void onRemoveField(ContactFieldItem *item, Model::ContactFieldPtr field);
+                       void onRemoveField(ContactFieldItem *item);
 
                        void onDonePressed(Evas_Object *button, void *eventInfo);
                        void onCancelPressed(Evas_Object *button, void *eventInfo);
index d5cb9097d96e64623dcc38eb28e44b8e874fab89..1a5d5dee2ebf488f4662e862848607fcb5855904 100644 (file)
@@ -38,7 +38,6 @@ namespace Contacts
                        Contact(const Contact &that) = delete;
                        virtual ~Contact() override;
 
-
                        /**
                         * @brief Initialize contact object.
                         * @param[in]   id      Database record ID or 0 to create new contact
index 2123b3d1a64a99070a956fc82ba70e2696fe7765..cbf66f06bcfff601f55b7845668e1daa57e34f50 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  *
  */
+
 #ifndef CONTACTS_MODEL_CONTACT_ARRAY_H
 #define CONTACTS_MODEL_CONTACT_ARRAY_H
 
@@ -34,6 +35,11 @@ namespace Contacts
                public:
                        using ContactField::ContactField;
 
+                       /**
+                        * @see ContactField::initialize()
+                        */
+                       virtual void initialize() override;
+
                        /**
                         * @see ContactField::isEmpty()
                         */
@@ -54,22 +60,24 @@ namespace Contacts
                         * @param[in]   index   Child field index
                         * @return Child field.
                         */
-                       ContactFieldPtr getField(unsigned index) const;
+                       ContactField *getField(unsigned index) const;
 
                        /**
                         * @brief Add new child field.
                         * @return New child field.
                         */
-                       ContactFieldPtr addField();
+                       ContactField &addField();
 
                        /**
                         * @brief Remove child field and destroy the object.
                         * @param[in]   childField  Child field.
                         */
-                       void removeField(ContactFieldPtr field);
+                       void removeField(ContactField &field);
 
                private:
                        const ContactArrayMetadata &getArrayMetadata() const;
+
+                       ContactFields m_Fields;
                };
        }
 }
index a551c087ea95758d0868f4dd80e5338e23280651..e0f245b18369dc5de4a08dd3f48b09257d9b560c 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  *
  */
+
 #ifndef CONTACTS_MODEL_CONTACT_FIELD_FACTORY_H
 #define CONTACTS_MODEL_CONTACT_FIELD_FACTORY_H
 
index ec87a584ce864709e41515016a57a7874fe1b7d8..9a93539a0f3ac5309e23e8650c122d58f3840278 100644 (file)
  * limitations under the License.
  *
  */
+
 #ifndef CONTACTS_MODEL_CONTACT_FIELD_H
 #define CONTACTS_MODEL_CONTACT_FIELD_H
 
 #include <contacts.h>
 #include <memory>
+#include <vector>
 
 #include "Contacts/Model/ContactFields.h"
 #include "Contacts/Model/ContactTypes.h"
@@ -47,15 +49,21 @@ namespace Contacts
                        virtual ~ContactField() { }
 
                        /**
-                        * @return Whether field has no value.
+                        * @brief Initialize the adapter.
+                        * @remark This method should be called before using the object
                         */
-                       virtual bool isEmpty() const { return false; }
+                       virtual void initialize() { }
 
                        /**
                         * @brief Reset field values to default.
                         */
                        virtual void reset() { }
 
+                       /**
+                        * @return Whether field has no value.
+                        */
+                       virtual bool isEmpty() const { return false; }
+
                        /**
                         * @brief Cast field to derived type.
                         */
@@ -125,6 +133,7 @@ namespace Contacts
                };
 
                typedef std::unique_ptr<ContactField> ContactFieldPtr;
+               typedef std::vector<ContactFieldPtr> ContactFields;
        }
 }
 
index 04054dff52efc41105f2e932de53fd634b11e920..941d2dc77bbdc7362da8f286420b8439cb66e037 100644 (file)
@@ -33,7 +33,7 @@ namespace Contacts
                 */
                template <typename FieldContainer>
                class ContactIterator :
-                       public std::iterator<std::input_iterator_tag, ContactFieldPtr>
+                       public std::iterator<std::input_iterator_tag, ContactField>
                {
                public:
                        /**
@@ -52,7 +52,7 @@ namespace Contacts
                        /**
                         * @brief Get field pointed by iterator.
                         */
-                       ContactFieldPtr operator*() const { return m_Container.getField(m_Index); }
+                       ContactField &operator*() const { return *m_Container.getField(m_Index); }
 
                        /**
                         * @brief Compare iterators for inequality.
index fc18d438da6717e12ef106b3f43e0ab27356d994..bc3b3adc739a23ac29befe1d2c2a9b3f8be76650 100644 (file)
@@ -36,6 +36,11 @@ namespace Contacts
                public:
                        using ContactField::ContactField;
 
+                       /**
+                        * @see ContactField::initialize()
+                        */
+                       virtual void initialize() override;
+
                        /**
                         * @see ContactField::isEmpty()
                         */
@@ -61,17 +66,20 @@ namespace Contacts
                         * @param[in]   index   Child field index
                         * @return Child field.
                         */
-                       ContactFieldPtr getField(unsigned index) const;
+                       ContactField *getField(unsigned index) const;
 
                        /**
                         * @brief Get child field by id.
                         * @param[in]   id      Child field id
                         * @return Child field.
                         */
-                       ContactFieldPtr getFieldById(unsigned id) const;
+                       ContactField *getFieldById(unsigned id) const;
 
                protected:
                        const ContactObjectMetadata &getObjectMetadata() const;
+
+               private:
+                       ContactFields m_Fields;
                };
        }
 }
index 7859ae3323173c63066d90c1712e55ea42354286..5f69baccea65905786f061166123ddba785fe1c4 100644 (file)
@@ -37,6 +37,11 @@ namespace Contacts
                public:
                        using ContactObject::ContactObject;
 
+                       /**
+                        * @see ContactField::initialize()
+                        */
+                       virtual void initialize() override;
+
                        /**
                         * @see ContactField::reset()
                         */
@@ -45,15 +50,18 @@ namespace Contacts
                        /**
                         * @return Field that represents object's type.
                         */
-                       ContactFieldPtr getTypeField() const;
+                       ContactEnumField &getTypeField() const;
 
                        /**
                         * @return Field that stores object's custom type label.
                         */
-                       ContactFieldPtr getLabelField() const;
+                       ContactTextField &getLabelField() const;
 
                private:
                        const ContactTypedObjectMetadata &getTypedObjectMetadata() const;
+
+                       ContactFieldPtr m_TypeField;
+                       ContactFieldPtr m_LabelField;
                };
        }
 }
index ecbce667b27c292802e3c22a0f45da20427eed5e..a7776063fb94cef3bd44f4e59d6b1ae6fe2574ce 100644 (file)
@@ -57,7 +57,7 @@ void ContactCompoundFieldItem::onContracted()
 
 Evas_Object *ContactCompoundFieldItem::createCompoundControl(Evas_Object *parent)
 {
-       auto control = new ContactCompoundObjectControl(&getObject().cast<ContactCompoundObject>());
+       auto control = new ContactCompoundObjectControl(getObject().cast<ContactCompoundObject>());
        control->create(parent);
 
        enableEntryReturnButton(control->getEntry());
index 7a086a7f030b7fb1555aaea84b8cb0719ee89bed..a1f91a6f9df3c347cd7c6e6b36de090cf955f99e 100644 (file)
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactCompoundObjectControl::ContactCompoundObjectControl(ContactCompoundObject *object)
+ContactCompoundObjectControl::ContactCompoundObjectControl(ContactCompoundObject &object)
        : m_Object(object)
 {
 }
 
 void ContactCompoundObjectControl::onCreated()
 {
-       setGuideText(Common::getContactFieldName(ContactFieldId(m_Object->getId())));
+       setGuideText(Common::getContactFieldName(ContactFieldId(m_Object.getId())));
 
        Evas_Object *entry = getEntry();
        elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_WORD);
        evas_object_smart_callback_add(entry, "unfocused",
                        makeCallback(&ContactCompoundObjectControl::onUnfocused), this);
 
-       char *text = elm_entry_utf8_to_markup(m_Object->getValue().c_str());
+       char *text = elm_entry_utf8_to_markup(m_Object.getValue().c_str());
        elm_entry_entry_set(entry, text);
        free(text);
 }
@@ -45,6 +45,6 @@ void ContactCompoundObjectControl::onCreated()
 void ContactCompoundObjectControl::onUnfocused(Evas_Object *entry, void *eventInfo)
 {
        char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(getEntry()));
-       m_Object->setValue(text);
+       m_Object.setValue(text);
        free(text);
 }
index b12a8d09ab8f9d302964848f381b3bf10775257b..9c063248d38f3bc5160c3976bdab76749d1767e1 100644 (file)
@@ -28,7 +28,7 @@
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactDateFieldControl::ContactDateFieldControl(Model::ContactDateField *field)
+ContactDateFieldControl::ContactDateFieldControl(Model::ContactDateField &field)
        : m_Field(field), m_Button(nullptr)
 {
 }
@@ -52,7 +52,7 @@ Evas_Object *ContactDateFieldControl::onCreate(Evas_Object *parent)
 
 void ContactDateFieldControl::onCreated()
 {
-       setButtonDate(m_Field->getValue());
+       setButtonDate(m_Field.getValue());
 }
 
 void ContactDateFieldControl::setButtonDate(tm date)
@@ -64,9 +64,9 @@ void ContactDateFieldControl::setButtonDate(tm date)
 
 void ContactDateFieldControl::onButtonPressed(Evas_Object *button, void *eventInfo)
 {
-       Ui::DatePopup *popup = new Ui::DatePopup(m_Field->getValue());
+       Ui::DatePopup *popup = new Ui::DatePopup(m_Field.getValue());
        popup->setResultCallback([this](const tm &date) {
-               m_Field->setValue(date);
+               m_Field.setValue(date);
                setButtonDate(date);
        });
        popup->create(getEvasObject());
index f39116277e4d492bbf564b05f3be053412accb21..18e5194ac035f4a51d26f13539fc5cf7358bfd71 100644 (file)
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactFieldItem::ContactFieldItem(ContactFieldPtr object)
-       : ContactFieldSubItem(object->cast<ContactObject>().getField(0)),
-         m_Object(std::move(object))
+ContactFieldItem::ContactFieldItem(ContactObject &object)
+       : ContactFieldSubItem(*object.getField(0)),
+         m_Object(object)
 {
        unsigned firstFieldId = getField().getId();
        for (auto &&field : getObject()) {
-               if (field->getId() != firstFieldId) {
-                       insertSubItem(new ContactFieldSubItem(std::move(field)));
+               if (field.getId() != firstFieldId) {
+                       insertSubItem(new ContactFieldSubItem(field));
                }
        }
 }
@@ -45,7 +45,7 @@ void ContactFieldItem::setRemoveCallback(RemoveCallback callback)
 
 ContactObject &ContactFieldItem::getObject() const
 {
-       return m_Object->cast<ContactObject>();
+       return m_Object;
 }
 
 Elm_Genlist_Item_Class *ContactFieldItem::getItemClass() const
@@ -76,7 +76,6 @@ void ContactFieldItem::onInserted()
 void ContactFieldItem::onRemovePressed(Evas_Object *button, void *eventInfo)
 {
        if (m_OnRemove) {
-               m_OnRemove(this, std::move(m_Object));
+               m_OnRemove(this);
        }
-       delete this;
 }
index 006e3e7d2b1e397bc10e1516755b2ae77c5e924e..8f8151c0ceefa6eb9b027f3d61a5525b406b581a 100644 (file)
@@ -19,6 +19,7 @@
 #include "Contacts/Input/ContactFieldItem.h"
 #include "Contacts/Input/ContactDateFieldControl.h"
 #include "Contacts/Input/ContactTextFieldControl.h"
+#include "Contacts/Model/ContactField.h"
 #include "Utils/Callback.h"
 
 #include "InputItemLayout.h"
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactFieldSubItem::ContactFieldSubItem(ContactFieldPtr field)
-       : m_Field(std::move(field)), m_NextFocusItem(nullptr)
+ContactFieldSubItem::ContactFieldSubItem(ContactField &field)
+       : m_Field(field), m_NextFocusItem(nullptr)
 {
 }
 
 ContactField &ContactFieldSubItem::getField() const
 {
-       return *m_Field;
+       return m_Field;
 }
 
 bool ContactFieldSubItem::isFocusable() const
 {
-       return m_Field->getType() == TypeText;
+       return m_Field.getType() == TypeText;
 }
 
 Elm_Genlist_Item_Class *ContactFieldSubItem::getItemClass() const
@@ -49,11 +50,11 @@ Elm_Genlist_Item_Class *ContactFieldSubItem::getItemClass() const
 
 Evas_Object *ContactFieldSubItem::getContent(Evas_Object *parent, const char *part)
 {
-       if (m_Field && strcmp(part, PART_MIDDLE) == 0) {
-               switch (m_Field->getType()) {
+       if (strcmp(part, PART_MIDDLE) == 0) {
+               switch (m_Field.getType()) {
                        case TypeText:
                        {
-                               auto control = new ContactTextFieldControl(&m_Field->cast<ContactTextField>());
+                               auto control = new ContactTextFieldControl(m_Field.cast<ContactTextField>());
                                control->create(parent);
 
                                enableEntryReturnButton(control->getEntry());
@@ -61,7 +62,7 @@ Evas_Object *ContactFieldSubItem::getContent(Evas_Object *parent, const char *pa
                        }
                        case TypeDate:
                        {
-                               auto control = new ContactDateFieldControl(&m_Field->cast<ContactDateField>());
+                               auto control = new ContactDateFieldControl(m_Field.cast<ContactDateField>());
                                return control->create(parent);
                        }
                        default:
@@ -84,7 +85,7 @@ void ContactFieldSubItem::onFocused()
        Ui::Control *control = Ui::Control::getControl(content);
 
        if (control) {
-               if (m_Field->getType() == TypeText) {
+               if (m_Field.getType() == TypeText) {
                        Evas_Object *entry = static_cast<Ui::Editfield *>(control)->getEntry();
                        elm_object_focus_set(entry, EINA_TRUE);
                }
index 735c602a2fe3491db66d87709ab1d6a0492f4131..fbb365484a0af75f2b30480b50f44a8ba2c5507e 100644 (file)
@@ -26,7 +26,7 @@
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactImageFieldControl::ContactImageFieldControl(ContactTextField *field)
+ContactImageFieldControl::ContactImageFieldControl(ContactTextField &field)
        : Thumbnail(Thumbnail::SizeLarge), m_Field(field)
 {
 }
@@ -41,13 +41,13 @@ void ContactImageFieldControl::onCreated()
 
 void ContactImageFieldControl::updateImage()
 {
-       setImagePath(m_Field->getValue());
+       setImagePath(m_Field.getValue());
 }
 
 void ContactImageFieldControl::onImageResult(app_control_h request, app_control_h reply,
                app_control_result_e result)
 {
-       m_Field->setValue(App::getSingleExtraData(reply, APP_CONTROL_DATA_SELECTED).c_str());
+       m_Field.setValue(App::getSingleExtraData(reply, APP_CONTROL_DATA_SELECTED).c_str());
        updateImage();
 }
 
@@ -65,9 +65,9 @@ void ContactImageFieldControl::onImagePressed(Evas_Object *image, void *eventInf
                m_AppControl.launch(makeCallbackWithLastParam(&ContactImageFieldControl::onImageResult), this);
        });
 
-       if (!m_Field->isEmpty()) {
+       if (!m_Field.isEmpty()) {
                popup->addItem("IDS_PB_OPT_REMOVE", [this] {
-                       m_Field->reset();
+                       m_Field.reset();
                        updateImage();
                });
        }
index a75da2ce926db437ebcff1417ac6614ff86c204d..abfe8b6a5fab1772605ec9f889a7cce6152c536d 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "Contacts/Input/ContactImageFieldItem.h"
 #include "Contacts/Input/ContactImageFieldControl.h"
+#include "Contacts/Model/ContactField.h"
 #include "InputItemLayout.h"
 
 using namespace Contacts::Input;
@@ -30,6 +31,6 @@ Elm_Genlist_Item_Class *ContactImageFieldItem::getItemClass() const
 
 Evas_Object *ContactImageFieldItem::getContent(Evas_Object *parent, const char *part)
 {
-       auto control = new ContactImageFieldControl(&getField().cast<ContactTextField>());
+       auto control = new ContactImageFieldControl(getField().cast<ContactTextField>());
        return control->create(parent);
 }
index 228449e434d7ac022093a92766e6455616feb233..4ae68fadc08f6e726d7bb8b632c3190eb754cfc6 100644 (file)
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactObjectTypeControl::ContactObjectTypeControl(ContactEnumField *typeField,
-               ContactTextField *labelField)
+ContactObjectTypeControl::ContactObjectTypeControl(ContactEnumField &typeField,
+               ContactTextField &labelField)
        : m_TypeField(typeField), m_LabelField(labelField)
 {
 }
 
 void ContactObjectTypeControl::onCreated()
 {
-       int currentValue = m_TypeField->getValue();
+       int currentValue = m_TypeField.getValue();
 
-       auto names = Common::getContactEnumValueNames(ContactEnumType(m_TypeField->getSubType()));
-       auto values = m_TypeField->getValues();
+       auto names = Common::getContactEnumValueNames(ContactEnumType(m_TypeField.getSubType()));
+       auto values = m_TypeField.getValues();
        RETM_IF(names.count() != values.count(), "names.count() != values.count()");
 
        for (size_t i = 0; i < values.count(); ++i) {
@@ -47,8 +47,8 @@ void ContactObjectTypeControl::onCreated()
                }
        }
 
-       if (m_TypeField->hasCustomValue()) {
-               setText(m_LabelField->getValue());
+       if (m_TypeField.hasCustomValue()) {
+               setText(m_LabelField.getValue());
        }
 
        setSelectedCallback(std::bind(&ContactObjectTypeControl::onSelected, this,
@@ -57,22 +57,22 @@ void ContactObjectTypeControl::onCreated()
 
 bool ContactObjectTypeControl::onSelected(int value)
 {
-       if (value == m_TypeField->getCustomValue()) {
+       if (value == m_TypeField.getCustomValue()) {
                auto popup = new ContactObjectCustomTypePopup();
                popup->setResultCallback([this, value](const char *label) {
-                       m_TypeField->setValue(value);
-                       m_LabelField->setValue(label);
+                       m_TypeField.setValue(value);
+                       m_LabelField.setValue(label);
                        setText(label);
                });
 
                popup->create(getEvasObject());
                return false;
        } else {
-               if (m_TypeField->hasCustomValue()) {
-                       m_LabelField->reset();
+               if (m_TypeField.hasCustomValue()) {
+                       m_LabelField.reset();
                }
 
-               m_TypeField->setValue(value);
+               m_TypeField.setValue(value);
                return true;
        }
 }
index 2c98f20a8ff5e7ced41ed206fab4a26efc157989..52e3a2f4b7e8e3f675cd95b2d3f4bdf9fb173db8 100644 (file)
@@ -33,21 +33,21 @@ namespace
        };
 }
 
-ContactTextFieldControl::ContactTextFieldControl(Model::ContactTextField *field)
+ContactTextFieldControl::ContactTextFieldControl(Model::ContactTextField &field)
        : m_Field(field)
 {
 }
 
 void ContactTextFieldControl::onCreated()
 {
-       setGuideText(Common::getContactChildFieldName(m_Field->getId()));
+       setGuideText(Common::getContactChildFieldName(m_Field.getId()));
 
        Evas_Object *entry = getEntry();
-       elm_entry_input_panel_layout_set(entry, Utils::at(inputLayout, m_Field->getSubType()));
+       elm_entry_input_panel_layout_set(entry, Utils::at(inputLayout, m_Field.getSubType()));
        evas_object_smart_callback_add(entry, "unfocused",
                        makeCallback(&ContactTextFieldControl::onUnfocused), this);
 
-       char *text = elm_entry_utf8_to_markup(m_Field->getValue());
+       char *text = elm_entry_utf8_to_markup(m_Field.getValue());
        elm_entry_entry_set(entry, text);
        free(text);
 }
@@ -55,6 +55,6 @@ void ContactTextFieldControl::onCreated()
 void ContactTextFieldControl::onUnfocused(Evas_Object *entry, void *eventInfo)
 {
        char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(getEntry()));
-       m_Field->setValue(text);
+       m_Field.setValue(text);
        free(text);
 }
index 7e299e9818dfd22d75efaed40fe19132960de4c3..f9733d279698072e972d707cc25e505c54b6620a 100644 (file)
 using namespace Contacts::Input;
 using namespace Contacts::Model;
 
-ContactTypedFieldItem::ContactTypedFieldItem(Model::ContactFieldPtr object)
-       : ContactFieldItem(std::move(object))
+ContactTypedFieldItem::ContactTypedFieldItem(Model::ContactObject &object)
+       : ContactFieldItem(object),
+         m_TypeField(getTypedObject().getTypeField()),
+         m_LabelField(getTypedObject().getLabelField())
 {
-       m_TypeField = getTypedObject().getTypeField();
-       m_LabelField = getTypedObject().getLabelField();
 }
 
 const ContactTypedObject &ContactTypedFieldItem::getTypedObject() const
@@ -39,9 +39,7 @@ const ContactTypedObject &ContactTypedFieldItem::getTypedObject() const
 Evas_Object *ContactTypedFieldItem::getContent(Evas_Object *parent, const char *part)
 {
        if (strcmp(part, PART_LEFT) == 0) {
-               Ui::Control *control = new ContactObjectTypeControl(
-                               &m_TypeField->cast<ContactEnumField>(),
-                               &m_LabelField->cast<ContactTextField>());
+               Ui::Control *control = new ContactObjectTypeControl(m_TypeField, m_LabelField);
                return control->create(parent);
        } else {
                return ContactFieldItem::getContent(parent, part);
index dd6bb3a7f185d1870ad21bd7164b32ca17f37a22..f0574a73136903a75e50278652eb74d6eeba580a 100644 (file)
@@ -72,16 +72,16 @@ void InputView::onCreated()
        }
 
        for (auto &&field : m_Contact) {
-               switch (field->getType()) {
+               switch (field.getType()) {
                        case TypeArray:
-                               for (auto &&element : field->cast<ContactArray>()) {
-                                       addFieldItem(std::move(element));
+                               for (auto &&element : field.cast<ContactArray>()) {
+                                       addFieldItem(element.cast<ContactObject>());
                                }
                                break;
                        case TypeObject:
-                               if (!m_Items[field->getId()] && !field->isEmpty()) {
-                                       m_AddFieldsItem->setAddFieldState(ContactFieldId(field->getId()), false);
-                                       addFieldItem(std::move(field));
+                               if (!m_Items[field.getId()] && !field.isEmpty()) {
+                                       m_AddFieldsItem->setAddFieldState(ContactFieldId(field.getId()), false);
+                                       addFieldItem(field.cast<ContactObject>());
                                }
                                break;
                        default:
@@ -110,22 +110,22 @@ void InputView::onPageAttached()
        page->setContent("title_left_btn", cancelButton);
 }
 
-ContactFieldItem *InputView::createFieldItem(ContactFieldPtr field)
+ContactFieldItem *InputView::createFieldItem(ContactObject &field)
 {
        ContactFieldItem *item = nullptr;
-       if (field->getId() == FieldImage) {
-               item = new ContactImageFieldItem(std::move(field));
-       } else if (field->getId() == FieldRelationship) {
-               item = new ContactRelationshipFieldItem(std::move(field));
-       } else if (field->getSubType() & ObjectTyped) {
-               item = new ContactTypedFieldItem(std::move(field));
-       } else if (field->getSubType() & ObjectCompound) {
-               item = new ContactCompoundFieldItem(std::move(field));
+       if (field.getId() == FieldImage) {
+               item = new ContactImageFieldItem(field);
+       } else if (field.getId() == FieldRelationship) {
+               item = new ContactRelationshipFieldItem(field);
+       } else if (field.getSubType() & ObjectTyped) {
+               item = new ContactTypedFieldItem(field);
+       } else if (field.getSubType() & ObjectCompound) {
+               item = new ContactCompoundFieldItem(field);
        } else {
-               item = new ContactFieldItem(std::move(field));
+               item = new ContactFieldItem(field);
        }
 
-       item->setRemoveCallback(std::bind(&InputView::onRemoveField, this, _1, _2));
+       item->setRemoveCallback(std::bind(&InputView::onRemoveField, this, _1));
 
        return item;
 }
@@ -141,34 +141,34 @@ Ui::GenlistItem *InputView::getNextFieldItem(ContactFieldId fieldId)
        return m_AddFieldsItem;
 }
 
-ContactFieldPtr InputView::addField(ContactFieldId fieldId)
+ContactObject &InputView::addField(ContactFieldId fieldId)
 {
-       ContactFieldPtr parentField = m_Contact.getFieldById(fieldId);
-       if (parentField->getType() == TypeArray) {
-               return parentField->cast<ContactArray>().addField();
+       ContactField &parentField = *m_Contact.getFieldById(fieldId);
+       if (parentField.getType() == TypeArray) {
+               return parentField.cast<ContactArray>().addField().cast<ContactObject>();
        } else {
                m_AddFieldsItem->setAddFieldState(fieldId, false);
-               return parentField;
+               return parentField.cast<ContactObject>();
        }
 }
 
-void InputView::removeField(ContactFieldPtr field)
+void InputView::removeField(ContactObject &field)
 {
-       ContactFieldId fieldId = ContactFieldId(field->getId());
-       ContactFieldPtr parentField = m_Contact.getFieldById(fieldId);
-       if (parentField->getType() == TypeArray) {
-               parentField->cast<ContactArray>().removeField(std::move(field));
+       ContactFieldId fieldId = ContactFieldId(field.getId());
+       ContactField &parentField = *m_Contact.getFieldById(fieldId);
+       if (parentField.getType() == TypeArray) {
+               parentField.cast<ContactArray>().removeField(field);
        } else {
                m_AddFieldsItem->setAddFieldState(fieldId, true);
-               field->reset();
+               field.reset();
        }
 }
 
-ContactFieldItem *InputView::addFieldItem(Model::ContactFieldPtr field)
+ContactFieldItem *InputView::addFieldItem(Model::ContactObject &field)
 {
-       ContactFieldId fieldId = ContactFieldId(field->getId());
+       ContactFieldId fieldId = ContactFieldId(field.getId());
 
-       ContactFieldItem *item = createFieldItem(std::move(field));
+       ContactFieldItem *item = createFieldItem(field);
        m_Genlist->insert(item, nullptr, getNextFieldItem(fieldId));
 
        if (!m_Items[fieldId]) {
@@ -178,8 +178,10 @@ ContactFieldItem *InputView::addFieldItem(Model::ContactFieldPtr field)
        return item;
 }
 
-void InputView::removeFieldItem(ContactFieldItem *item, ContactFieldId fieldId)
+void InputView::removeFieldItem(ContactFieldItem *item)
 {
+       ContactFieldId fieldId = ContactFieldId(item->getObject().getId());
+
        if (item == m_Items[fieldId]) {
                ContactFieldItem *nextItem = static_cast<ContactFieldItem *>(item->getNextGroupItem());
                if (nextItem && nextItem->getObject().getId() == fieldId) {
@@ -188,6 +190,8 @@ void InputView::removeFieldItem(ContactFieldItem *item, ContactFieldId fieldId)
                        m_Items[fieldId] = nullptr;
                }
        }
+
+       delete item;
 }
 
 void InputView::onAddField(ContactFieldId fieldId)
@@ -196,10 +200,11 @@ void InputView::onAddField(ContactFieldId fieldId)
        item->focus(ELM_GENLIST_ITEM_SCROLLTO_TOP);
 }
 
-void InputView::onRemoveField(ContactFieldItem *item, ContactFieldPtr field)
+void InputView::onRemoveField(ContactFieldItem *item)
 {
-       removeFieldItem(item, ContactFieldId(field->getId()));
-       removeField(std::move(field));
+       ContactObject &field = item->getObject();
+       removeFieldItem(item);
+       removeField(field);
 }
 
 void InputView::onDonePressed(Evas_Object *button, void *eventInfo)
index f5e4622edc86d7a18cced5c264cd535ee15edccd..67ecc7f9c11bdfc2d2a5e3a35b7f524722a0877c 100644 (file)
@@ -44,6 +44,8 @@ int Contact::initialize(int recordId)
        }
 
        setRecord(record);
+       ContactObject::initialize();
+
        return err;
 }
 
index bd401fac09a4076ec65f77d168fc35be98b9c47d..4e13875e61e3fc4240f173e224e3a0251dbdee86 100644 (file)
 #include "Contacts/Model/ContactFactory.h"
 #include "Contacts/Model/ContactFieldMetadata.h"
 
+#include <algorithm>
+
 using namespace Contacts::Model;
 
+void ContactArray::initialize()
+{
+       int count = 0;
+       contacts_record_get_child_record_count(getRecord(), getPropertyId(), &count);
+
+       for (int i = 0; i < count; ++i) {
+               contacts_record_h record = nullptr;
+               contacts_record_get_child_record_at_p(getRecord(), getPropertyId(), i, &record);
+               m_Fields.push_back(ContactFactory::createField(record, getArrayMetadata().element));
+       }
+}
+
 bool ContactArray::isEmpty() const
 {
        bool isEmpty = true;
        for (auto &&field : *this) {
-               if (!field->isEmpty()) {
+               if (!field.isEmpty()) {
                        isEmpty = false;
                        break;
                }
@@ -41,23 +55,19 @@ ContactArrayIterator ContactArray::begin() const
 
 ContactArrayIterator ContactArray::end() const
 {
-       int count = 0;
-       contacts_record_get_child_record_count(getRecord(), getPropertyId(), &count);
-       return ContactArrayIterator(*this, count);
+       return ContactArrayIterator(*this, m_Fields.size());
 }
 
-ContactFieldPtr ContactArray::getField(unsigned index) const
+ContactField *ContactArray::getField(unsigned index) const
 {
-       contacts_record_h record = nullptr;
-       contacts_record_get_child_record_at_p(getRecord(), getPropertyId(), index, &record);
-       if (record) {
-               return ContactFactory::createField(record, getArrayMetadata().element);
+       if (index < m_Fields.size()) {
+               return m_Fields[index].get();
        }
 
        return nullptr;
 }
 
-ContactFieldPtr ContactArray::addField()
+ContactField &ContactArray::addField()
 {
        const ContactFieldMetadata *elementMetadata = &getArrayMetadata().element;
        const char *uri = ((const ContactObjectMetadata *) elementMetadata->typeMetadata)->uri;
@@ -68,13 +78,21 @@ ContactFieldPtr ContactArray::addField()
 
        ContactFieldPtr field = ContactFactory::createField(record, getArrayMetadata().element);
        field->reset();
-       return field;
+
+       m_Fields.push_back(std::move(field));
+       return *m_Fields.back().get();
 }
 
-void ContactArray::removeField(ContactFieldPtr field)
+void ContactArray::removeField(ContactField &field)
 {
-       contacts_record_remove_child_record(getRecord(), getPropertyId(), field->getRecord());
-       contacts_record_destroy(field->getRecord(), true);
+       auto comp = [&field](ContactFieldPtr &ptr) {
+               return ptr.get() == &field;
+       };
+
+       m_Fields.erase(std::remove_if(m_Fields.begin(), m_Fields.end(), comp), m_Fields.end());
+
+       contacts_record_remove_child_record(getRecord(), getPropertyId(), field.getRecord());
+       contacts_record_destroy(field.getRecord(), true);
 }
 
 const ContactArrayMetadata &ContactArray::getArrayMetadata() const
index 957fd2b74f8e075ad26b98fad0850fd5290c14e4..1fe4be146de1aa4703924e0107cbe0bc38e60868 100644 (file)
@@ -65,6 +65,10 @@ ContactFieldPtr ContactFactory::createField(contacts_record_h record,
                        break;
        }
 
+       if (field) {
+               field->initialize();
+       }
+
        return ContactFieldPtr(field);
 }
 
index 833d4dd2289e6d38b744e5f0eecb96b8678a4ee8..0fd6606148fc337127ec513f7e0e56dcd00ad765 100644 (file)
 
 using namespace Contacts::Model;
 
+void ContactObject::initialize()
+{
+       for (auto &&field : getObjectMetadata().fields) {
+               m_Fields.push_back(ContactFactory::createField(getRecord(), field));
+       }
+}
+
 bool ContactObject::isEmpty() const
 {
        bool isEmpty = true;
        for (auto &&field : *this) {
-               if (!field->isEmpty()) {
+               if (!field.isEmpty()) {
                        isEmpty = false;
                        break;
                }
@@ -37,7 +44,7 @@ bool ContactObject::isEmpty() const
 void ContactObject::reset()
 {
        for (auto &&field : *this) {
-               field->reset();
+               field.reset();
        }
 }
 
@@ -48,25 +55,23 @@ ContactObjectIterator ContactObject::begin() const
 
 ContactObjectIterator ContactObject::end() const
 {
-       return ContactObjectIterator(*this, getObjectMetadata().fields.count());
+       return ContactObjectIterator(*this, m_Fields.size());
 }
 
-ContactFieldPtr ContactObject::getField(unsigned index) const
+ContactField *ContactObject::getField(unsigned index) const
 {
-       const ContactObjectMetadata &metadata = getObjectMetadata();
-       const ContactFieldMetadata *field = metadata.fields.begin() + index;
-       if (field < metadata.fields.end()) {
-               return ContactFactory::createField(getRecord(), *field);
+       if (index < m_Fields.size()) {
+               return m_Fields[index].get();
        }
 
        return nullptr;
 }
 
-ContactFieldPtr ContactObject::getFieldById(unsigned id) const
+ContactField *ContactObject::getFieldById(unsigned id) const
 {
-       for (auto &&field : getObjectMetadata().fields) {
-               if (field.id == id) {
-                       return ContactFactory::createField(getRecord(), field);
+       for (auto &&field : m_Fields) {
+               if (field->getId() == id) {
+                       return field.get();
                }
        }
 
index db34d59ce0b748048680d58b648b19b3819aa6f7..8c3eb33a92a2015a0a01a1813acec2b2d678f777 100644 (file)
 
 using namespace Contacts::Model;
 
+void ContactTypedObject::initialize()
+{
+       ContactObject::initialize();
+       m_TypeField = ContactFactory::createField(getRecord(), getTypedObjectMetadata().typeField);
+       m_LabelField = ContactFactory::createField(getRecord(), getTypedObjectMetadata().labelField);
+}
+
 void ContactTypedObject::reset()
 {
-       getTypeField()->reset();
-       getLabelField()->reset();
        ContactObject::reset();
+       m_TypeField->reset();
+       m_LabelField->reset();
 }
 
-ContactFieldPtr ContactTypedObject::getTypeField() const
+ContactEnumField &ContactTypedObject::getTypeField() const
 {
-       return ContactFactory::createField(getRecord(), getTypedObjectMetadata().typeField);
+       return m_TypeField->cast<ContactEnumField>();
 }
 
-ContactFieldPtr ContactTypedObject::getLabelField() const
+ContactTextField &ContactTypedObject::getLabelField() const
 {
-       return ContactFactory::createField(getRecord(), getTypedObjectMetadata().labelField);
+       return m_LabelField->cast<ContactTextField>();
 }
 
 const ContactTypedObjectMetadata &ContactTypedObject::getTypedObjectMetadata() const