add user delete button and delete popup 33/43333/1
authorSoohye Shin <soohye.shin@samsung.com>
Wed, 8 Jul 2015 06:40:55 +0000 (15:40 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Wed, 8 Jul 2015 06:40:55 +0000 (15:40 +0900)
Change-Id: I61d747a8ea2bbd793216e149cfae2d82566c332c
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
include/defs.h
src/view/view_user_edit.c

index c1fc975..34cf03c 100644 (file)
@@ -71,7 +71,7 @@
 #define PART_USER_EDIT_CONTENTS_PIN "part.user.edit.contents.pin"
 #define PART_USER_EDIT_CONTENTS_ACCOUNT "part.user.edit.contents.account"
 #define PART_USER_EDIT_CONTENTS_LOCK "part.user.edit.contents.lock"
-#define PART_USER_EDIT_CONTETNS_DELETE "part.user.edit.contents.delete"
+#define PART_USER_EDIT_CONTENTS_DELETE "part.user.edit.contents.delete"
 #define PART_USER_EDIT_PHOTO "part.user.edit.photo"
 #define PART_USER_EDIT_PHOTO_FOCUS "part.user.edit.photo.focus"
 #define PART_USER_EDIT_ENTRY "part.user.edit.entry"
@@ -93,6 +93,9 @@
 #define PART_PHOTO_VIEWER "part.photo.viewer"
 #define PART_PHOTO_VIEWER_CANCEL "part.photo.viewer.cancel"
 #define PART_PHOTO_VIEWER_DONE "part.photo.viewer.done"
+#define PART_TITLE_TEXT "title,text"
+#define PART_POPUP_BUTTON_1 "button1"
+#define PART_POPUP_BUTTON_2 "button2"
 
 #define SIG_SHOW_NAVIGATION "sig.show.navigation"
 #define SIG_HIDE_NAVIGATION "sig.hide.navigation"
index c72a3d9..d488200 100644 (file)
 #define MESSAGE_BTN_CANCEL "Cancel"
 #define MESSAGE_ADD_USER "Add user"
 #define MESSAGE_EDIT_USER "Edit user"
+#define MESSAGE_DELETE_USER "Delete user"
+#define MESSAGE_DELETE_CONTENTS "If you delete this user, their data will also be deleted."
+#define MESSAGE_DELETE "Delete"
+#define MESSAGE_CANCEL "Cancel"
+
 #define MESSAGE_ENTRY_NAME "User Name"
 #define MESSAGE_ENTRY_ACCOUNT "sample@tizen.com"
 #define MESSAGE_ENTRY_PIN "Pin code"
@@ -39,6 +44,7 @@
 
 #define CTXPOPUP_X 294
 #define CTXPOPUP_Y 310
+#define MAX_BUF 128
 
 struct _icon_info {
        const char *file;
@@ -61,6 +67,8 @@ struct _priv {
        Evas_Object *done;
        Evas_Object *cancel;
        Evas_Object *ctxpopup;
+       Evas_Object *del;
+       Evas_Object *popup;
 
        struct datamgr *dm;
 };
@@ -485,6 +493,129 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        return base;
 }
 
+static void _delete_user_key_down(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       priv = data;
+
+       if (!strcmp(ev->keyname, KEY_ENTER) ||
+                       !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+               evas_object_del(priv->popup);
+               priv->popup = NULL;
+               /* TODO: datamgr_select_item for deleting user */
+       } else if (!strcmp(ev->keyname, KEY_BACK) ||
+                       !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+               evas_object_del(priv->popup);
+               priv->popup = NULL;
+       }
+}
+
+static input_handler delete_user_handler = {
+       .key_down = _delete_user_key_down
+};
+
+static void _cancel_user_key_down(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       priv = data;
+
+       if (!strcmp(ev->keyname, KEY_ENTER) ||
+                       !strcmp(ev->keyname, KEY_ENTER_REMOTE) ||
+                       !strcmp(ev->keyname, KEY_BACK) ||
+                       !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+               evas_object_del(priv->popup);
+               priv->popup = NULL;
+       }
+}
+
+static input_handler cancel_user_handler = {
+       .key_down = _cancel_user_key_down
+};
+
+static void _add_delete_popup(struct _priv *priv)
+{
+       Evas_Object *popup, *delete_btn, *cancel_btn;
+       char buf[MAX_BUF];
+
+       popup = elm_popup_add(priv->base);
+       if (!popup) {
+               _ERR("failed to add popup");
+               return;
+       }
+       elm_object_part_text_set(popup, PART_TITLE_TEXT, MESSAGE_DELETE_USER);
+       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+       evas_object_show(popup);
+       priv->popup = popup;
+
+       /* TODO: put the user name */
+       snprintf(buf, sizeof(buf), "%s %s?<br> %s", MESSAGE_DELETE,
+                       "", MESSAGE_DELETE_CONTENTS);
+       elm_object_text_set(popup, buf);
+
+       delete_btn = utils_add_button(popup, MESSAGE_DELETE,
+                       PART_POPUP_BUTTON_1);
+       if (!delete_btn) {
+               _ERR("failed to add delete btn");
+               evas_object_del(popup);
+               return;
+       }
+       inputmgr_add_callback(delete_btn, 0, &delete_user_handler, priv);
+
+       cancel_btn = utils_add_button(popup, MESSAGE_CANCEL,
+                       PART_POPUP_BUTTON_2);
+       if (!cancel_btn) {
+               _ERR("failed to add cancel btn");
+               evas_object_del(popup);
+               return;
+       }
+       inputmgr_add_callback(cancel_btn, 0, &cancel_user_handler, priv);
+       elm_object_focus_set(cancel_btn, EINA_TRUE);
+}
+
+static void _del_key_down(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       if (!strcmp(ev->keyname, KEY_ENTER) ||
+                       !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+               _add_delete_popup(data);
+       }
+}
+
+static input_handler del_handler = {
+       .focused = _focused,
+       .unfocused = _unfocused,
+       .key_down = _del_key_down
+};
+
+static void _load_del_btn(struct _priv *priv)
+{
+       Evas_Object *btn;
+
+       btn = utils_add_layout(priv->ly, GRP_USER_EDIT_DELETE, true,
+                       PART_USER_EDIT_CONTENTS_DELETE);
+       if (!btn) {
+               _ERR("failed toa add delete button");
+               return;
+       }
+       inputmgr_add_callback(btn, 0, &del_handler, priv);
+
+       priv->del = btn;
+}
+
 static void _show(void *data)
 {
        struct _priv *priv;
@@ -501,6 +632,7 @@ static void _show(void *data)
                        MESSAGE_ADD_USER);
        _load_user_icon(priv, IMAGE_USER_CURRENT_DEFAULT,
                        IMAGE_USER_CURRENT_DEFAULT_FOCUS);
+       _load_del_btn(priv);
 }
 
 static void _hide(void *data)
@@ -513,6 +645,11 @@ static void _hide(void *data)
        }
 
        priv = data;
+       if (priv->del) {
+               inputmgr_remove_callback(priv->del, &del_handler);
+               evas_object_del(priv->del);
+               priv->del = NULL;
+       }
 
        evas_object_hide(priv->base);
 }