TizenRefApp-6322 Implement Ringtone functionality 55/74755/2
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 15 Jun 2016 11:13:51 +0000 (14:13 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Fri, 17 Jun 2016 07:24:52 +0000 (00:24 -0700)
Change-Id: I8eec80caeea793061eddf8643649bb1117dfc78c
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
12 files changed:
lib-contacts/inc/Contacts/Input/ContactFieldSubItem.h
lib-contacts/inc/Contacts/Input/ContactRingtoneFieldItem.h [new file with mode: 0644]
lib-contacts/inc/Contacts/Model/ContactFields.h
lib-contacts/inc/Contacts/Model/ContactTypes.h
lib-contacts/src/Contacts/Common/Strings.cpp
lib-contacts/src/Contacts/Details/DetailsView.cpp
lib-contacts/src/Contacts/Input/ContactFieldItem.cpp
lib-contacts/src/Contacts/Input/ContactFieldSubItem.cpp
lib-contacts/src/Contacts/Input/ContactRingtoneFieldItem.cpp [new file with mode: 0644]
lib-contacts/src/Contacts/Input/InputView.cpp
lib-contacts/src/Contacts/Model/ContactFieldMetadata.cpp
lib-contacts/src/Contacts/Model/ContactObject.cpp

index 17dddca..8bdcd45 100644 (file)
@@ -83,6 +83,11 @@ namespace Contacts
                        virtual Eina_Bool getState(Evas_Object *parent, const char *part) override;
 
                        /**
+                        * @see GenlistItem::onInserted()
+                        */
+                       virtual void onInserted() override;
+
+                       /**
                         * @see GenlistItem::onFocused()
                         */
                        virtual void onFocused() override;
diff --git a/lib-contacts/inc/Contacts/Input/ContactRingtoneFieldItem.h b/lib-contacts/inc/Contacts/Input/ContactRingtoneFieldItem.h
new file mode 100644 (file)
index 0000000..8b4c5fd
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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_INPUT_CONTACT_RINGTONE_FIELD_ITEM_H
+#define CONTACTS_INPUT_CONTACT_RINGTONE_FIELD_ITEM_H
+
+#include "Contacts/Input/ContactFieldItem.h"
+#include "App/AppControl.h"
+
+namespace Contacts
+{
+       namespace Input
+       {
+               /**
+                * @brief Genlist item representing FieldRingtone field.
+                */
+               class ContactRingtoneFieldItem : public ContactFieldItem
+               {
+               public:
+                       using ContactFieldItem::ContactFieldItem;
+
+                       /**
+                        * @see GenlistItem::isFocusable()
+                        */
+                       virtual bool isFocusable() const override;
+
+               private:
+                       virtual Elm_Genlist_Item_Class *getItemClass() const override;
+                       virtual char *getText(Evas_Object *parent, const char *part) override;
+                       virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
+
+                       virtual void onInserted() override;
+                       virtual void onSelected() override;
+                       virtual void onFocused() override;
+
+                       char *getRingtonePath() const;
+                       void pickRingtone();
+                       void onPickResult(app_control_h request, app_control_h reply,
+                                       app_control_result_e result);
+
+                       App::AppControl m_AppControl;
+               };
+       }
+}
+
+#endif /* CONTACTS_INPUT_CONTACT_RINGTONE_FIELD_ITEM_H */
index 924b8b2..06cbf52 100644 (file)
@@ -43,6 +43,7 @@ namespace Contacts
                        FieldNote,
                        FieldNickname,
                        FieldRelationship,
+                       FieldRingtone,
                        FieldEnd
                };
 
index c606a42..ce6690f 100644 (file)
@@ -64,7 +64,8 @@ namespace Contacts
                        ObjectTypeMessenger,
                        ObjectTypeNickname,
                        ObjectTypeCompany,
-                       ObjectTypePhoneticName
+                       ObjectTypePhoneticName,
+                       ObjectTypeRingtone
                };
 
                /**
index 574aa64..da960a5 100644 (file)
@@ -38,7 +38,8 @@ namespace
                /* [FieldEvent]        = */ "IDS_PB_MBODY_EVENT",
                /* [FieldNote]         = */ "IDS_PB_BUTTON_NOTES",
                /* [FieldNickname]     = */ "IDS_PB_BODY_NICKNAME_ABB",
-               /* [FieldRelationship] = */ "IDS_PB_OPT_RELATIONSHIP_ABB2"
+               /* [FieldRelationship] = */ "IDS_PB_OPT_RELATIONSHIP_ABB2",
+               /* [FieldRingtone]     = */ "Ringtone",
        };
 
        const char *childFieldNames[] = {
@@ -57,6 +58,7 @@ namespace
                /* [FieldNote]         = */ "IDS_PB_BODY_NOTES",
                /* [FieldNickname]     = */ "IDS_PB_BODY_NICKNAME_ABB",
                /* [FieldRelationship] = */ "IDS_PB_BODY_NAME",
+               /* [FieldRingtone]     = */ "Ringtone",
 
                /* [CompanyFieldName]     = */ "IDS_PB_BODY_COMPANY_ABB",
                /* [CompanyFieldJobTitle] = */ "IDS_PB_BODY_JOB_TITLE_ABB",
index 37cf468..35e377f 100644 (file)
@@ -60,7 +60,8 @@ namespace
                /* [FieldEvent]        = */ true,
                /* [FieldNote]         = */ true,
                /* [FieldNickname]     = */ true,
-               /* [FieldRelationship] = */ true
+               /* [FieldRelationship] = */ true,
+               /* [FieldRingtone]     = */ true
        };
 }
 
index 83d842b..6f5a6ab 100644 (file)
@@ -76,6 +76,7 @@ Evas_Object *ContactFieldItem::getContent(Evas_Object *parent, const char *part)
 
 void ContactFieldItem::onInserted()
 {
+       ContactFieldSubItem::onInserted();
        elm_genlist_item_expanded_set(getObjectItem(), EINA_TRUE);
 }
 
@@ -84,6 +85,7 @@ Evas_Object *ContactFieldItem::createRemoveButton(Evas_Object *parent)
        Evas_Object *button = elm_button_add(parent);
        elm_object_style_set(button, "icon_expand_delete");
        elm_object_focus_allow_set(button, EINA_FALSE);
+       evas_object_propagate_events_set(button, EINA_FALSE);
        evas_object_smart_callback_add(button, "clicked",
                        makeCallback(&ContactFieldItem::onRemovePressed), this);
 
index 6409fab..11c20b6 100644 (file)
@@ -93,6 +93,11 @@ Eina_Bool ContactFieldSubItem::getState(Evas_Object *parent, const char *part)
        return parentItem ? parentItem->getState(parent, part) : EINA_FALSE;
 }
 
+void ContactFieldSubItem::onInserted()
+{
+       elm_genlist_item_select_mode_set(getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE);
+}
+
 void ContactFieldSubItem::onFocused()
 {
        Ui::Control *control = getFieldControl();
diff --git a/lib-contacts/src/Contacts/Input/ContactRingtoneFieldItem.cpp b/lib-contacts/src/Contacts/Input/ContactRingtoneFieldItem.cpp
new file mode 100644 (file)
index 0000000..a3f4462
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ *
+ */
+
+#include "Contacts/Input/ContactRingtoneFieldItem.h"
+#include "Contacts/Model/ContactObject.h"
+#include "Contacts/Model/ContactTextField.h"
+#include "Contacts/Common/Strings.h"
+
+#include "App/AppControlRequest.h"
+#include "Utils/Callback.h"
+#include "Utils/Logger.h"
+
+#include "InputItemLayout.h"
+
+#include <app_i18n.h>
+#include <system_settings.h>
+
+using namespace Contacts::Input;
+using namespace Contacts::Model;
+
+bool ContactRingtoneFieldItem::isFocusable() const
+{
+       return false;
+}
+
+Elm_Genlist_Item_Class *ContactRingtoneFieldItem::getItemClass() const
+{
+       static Elm_Genlist_Item_Class itc = createItemClass("type2");
+       return &itc;
+}
+
+char *ContactRingtoneFieldItem::getText(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, "elm.text") == 0) {
+               char *value = getRingtonePath();
+               return strcpy(value, basename(value));
+       } else if (strcmp(part, "elm.text.sub") == 0) {
+               const char *name = Common::getContactFieldName(ContactFieldId(getObject().getId()));
+               return Utils::safeDup(_(name));
+       }
+
+       return nullptr;
+}
+
+Evas_Object *ContactRingtoneFieldItem::getContent(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, "elm.swallow.end") == 0) {
+               return ContactFieldItem::getContent(parent, PART_RIGHT);
+       }
+
+       return nullptr;
+}
+
+void ContactRingtoneFieldItem::onInserted()
+{
+       ContactFieldItem::onInserted();
+       elm_genlist_item_select_mode_set(getObjectItem(), ELM_OBJECT_SELECT_MODE_DEFAULT);
+}
+
+void ContactRingtoneFieldItem::onSelected()
+{
+       pickRingtone();
+}
+
+void ContactRingtoneFieldItem::onFocused()
+{
+       pickRingtone();
+}
+
+char *ContactRingtoneFieldItem::getRingtonePath() const
+{
+       char *value = nullptr;
+       const char *fieldValue = getField().cast<ContactTextField>().getValue();
+       if (fieldValue) {
+               value = strdup(fieldValue);
+       } else {
+               char *defaultValue = nullptr;
+               system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &defaultValue);
+               value = defaultValue;
+       }
+
+       return value;
+}
+
+void ContactRingtoneFieldItem::pickRingtone()
+{
+       char *value = getRingtonePath();
+       m_AppControl = App::requestPickRingtone(value);
+       m_AppControl.launch(makeCallbackWithLastParam(&ContactRingtoneFieldItem::onPickResult), this);
+       free(value);
+}
+
+void ContactRingtoneFieldItem::onPickResult(app_control_h request, app_control_h reply,
+               app_control_result_e result)
+{
+       char *path = nullptr;
+       int err = app_control_get_extra_data(reply, "result", &path);
+       WARN_IF_ERR(err, "app_control_get_extra_data() failed.");
+
+       getField().cast<ContactTextField>().setValue(path);
+       free(path);
+}
index 4b0ed81..b41e6b8 100644 (file)
@@ -20,6 +20,7 @@
 #include "Contacts/Input/ContactCompoundFieldItem.h"
 #include "Contacts/Input/ContactImageFieldItem.h"
 #include "Contacts/Input/ContactRelationshipFieldItem.h"
+#include "Contacts/Input/ContactRingtoneFieldItem.h"
 #include "Contacts/Input/ContactTypedFieldItem.h"
 #include "Contacts/Details/DetailsView.h"
 
@@ -60,7 +61,8 @@ namespace
                /* [FieldEvent]        = */ true,
                /* [FieldNote]         = */ true,
                /* [FieldNickname]     = */ true,
-               /* [FieldRelationship] = */ true
+               /* [FieldRelationship] = */ true,
+               /* [FieldRingtone]     = */ true
        };
 }
 
@@ -115,14 +117,13 @@ Evas_Object *InputView::onCreate(Evas_Object *parent)
 
        m_Genlist = new Ui::Genlist();
        m_Genlist->create(parent);
-       elm_genlist_select_mode_set(m_Genlist->getEvasObject(), ELM_OBJECT_SELECT_MODE_NONE);
 
        m_AddFieldsItem = new AddFieldsItem();
        m_AddFieldsItem->setAddFieldCallback(std::bind(&InputView::onAddField, this, _1));
        m_Genlist->insert(m_AddFieldsItem);
 
        for (unsigned id = FieldBegin; id < FieldEnd; ++id) {
-               if (!isFieldVisible[id]) {
+               if (!isFieldVisible[id] || !m_Contact.getFieldById(id)) {
                        m_AddFieldsItem->setAddFieldState(ContactFieldId(id), false);
                }
        }
@@ -200,6 +201,8 @@ ContactFieldItem *InputView::createFieldItem(ContactObject &field)
                item = new ContactImageFieldItem(field);
        } else if (field.getId() == FieldRelationship) {
                item = new ContactRelationshipFieldItem(field);
+       } else if (field.getId() == FieldRingtone) {
+               item = new ContactRingtoneFieldItem(field);
        } else if (field.getInterfaces() & InterfaceTypedObject) {
                item = new ContactTypedFieldItem(field);
        } else if (field.getInterfaces() & InterfaceCompoundObject) {
index 57f9dcf..c7c5109 100644 (file)
@@ -106,6 +106,15 @@ const ContactObjectMetadata contactImage = {
        _contacts_image._uri, _contacts_image.id, makeRange(contactImageFields)
 };
 
+/****************************** Ringtone Object *******************************/
+const ContactFieldMetadata contactRingtoneFields[] = {
+       { FieldRingtone, _contacts_contact.ringtone_path, false, &contactRegularText }
+};
+const ContactObjectMetadata contactRingtone = {
+       { TypeObject, ObjectTypeRingtone }, InterfaceNone,
+       _contacts_contact._uri, _contacts_contact.id, makeRange(contactRingtoneFields)
+};
+
 /****************************** Number Object *********************************/
 const int contactNumberTypeValues[] = {
        CONTACTS_NUMBER_TYPE_CELL,
@@ -293,21 +302,22 @@ const ContactArrayMetadata contactMsgs = {
 
 /****************************** Contact Object ********************************/
 const ContactFieldMetadata contactFields[] = {
-       { FieldFavorite,     _contacts_contact.is_favorite,  false, &contactBool },
-       { FieldDisplayName,  _contacts_contact.display_name, false, &contactRegularText },
-       { FieldImage,        _contacts_contact.image,        false, UPCAST(&contactImage) },
-       { FieldName,         _contacts_contact.name,         true,  UPCAST(&contactName) },
-       { FieldPhoneticName, _contacts_contact.name,         false, UPCAST(&contactPhName) },
-       { FieldCompany,      _contacts_contact.company,      true,  UPCAST(&contactCompany) },
-       { FieldNumber,       _contacts_contact.number,       true,  UPCAST(&contactNumbers) },
-       { FieldEmail,        _contacts_contact.email,        true,  UPCAST(&contactEmails) },
-       { FieldAddress,      _contacts_contact.address,      false, UPCAST(&contactAddrs) },
-       { FieldUrl,          _contacts_contact.url,          false, UPCAST(&contactUrls) },
-       { FieldMessenger,    _contacts_contact.messenger,    false, UPCAST(&contactMsgs) },
-       { FieldEvent,        _contacts_contact.event,        false, UPCAST(&contactEvents) },
-       { FieldNote,         _contacts_contact.note,         false, UPCAST(&contactNote) },
-       { FieldNickname,     _contacts_contact.nickname,     true,  UPCAST(&contactNick) },
-       { FieldRelationship, _contacts_contact.relationship, false, UPCAST(&contactRels) }
+       { FieldFavorite,     _contacts_contact.is_favorite,     false, &contactBool },
+       { FieldDisplayName,  _contacts_contact.display_name,    false, &contactRegularText },
+       { FieldImage,        _contacts_contact.image,           false, UPCAST(&contactImage) },
+       { FieldName,         _contacts_contact.name,            true,  UPCAST(&contactName) },
+       { FieldPhoneticName, _contacts_contact.name,            false, UPCAST(&contactPhName) },
+       { FieldCompany,      _contacts_contact.company,         true,  UPCAST(&contactCompany) },
+       { FieldNumber,       _contacts_contact.number,          true,  UPCAST(&contactNumbers) },
+       { FieldEmail,        _contacts_contact.email,           true,  UPCAST(&contactEmails) },
+       { FieldAddress,      _contacts_contact.address,         false, UPCAST(&contactAddrs) },
+       { FieldUrl,          _contacts_contact.url,             false, UPCAST(&contactUrls) },
+       { FieldMessenger,    _contacts_contact.messenger,       false, UPCAST(&contactMsgs) },
+       { FieldEvent,        _contacts_contact.event,           false, UPCAST(&contactEvents) },
+       { FieldNote,         _contacts_contact.note,            false, UPCAST(&contactNote) },
+       { FieldNickname,     _contacts_contact.nickname,        true,  UPCAST(&contactNick) },
+       { FieldRelationship, _contacts_contact.relationship,    false, UPCAST(&contactRels) },
+       { FieldRingtone,     _contacts_contact.ringtone_path,   false, UPCAST(&contactRingtone) }
 };
 const ContactObjectMetadata contactObject = {
        { TypeObject, ObjectTypeContact }, InterfaceNone,
index c39d5f3..86024cf 100644 (file)
@@ -82,5 +82,5 @@ contacts_record_h ContactObject::getChildRecord(contacts_record_h record,
                contacts_record_add_child_record(record, metadata.propId, childRecord);
        }
 
-       return childRecord;
+       return childRecord ? childRecord : record;
 }