View: Add confirmation popup for uninstalling app 28/47128/2
authorHyojung Jo <hj903.jo@samsung.com>
Mon, 31 Aug 2015 05:33:23 +0000 (14:33 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Mon, 31 Aug 2015 06:29:52 +0000 (15:29 +0900)
Change-Id: Id28966f62bdec2a62399d000d8fb8eee8d88808f
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
include/define.h
include/utils.h
src/utils.c
src/view/view_action_menu.c

index b916cd4..21b8854 100644 (file)
@@ -43,6 +43,9 @@
 #define PART_INSIDE_LINE "part.inside.line"
 #define PART_TOP_BTN "part.top.button"
 #define PART_FAVORITE "part.favorite"
+#define PART_BUTTON1 "button1"
+#define PART_BUTTON2 "button2"
+#define PART_POPUP_TITLE "title,text"
 
 /* Style */
 #define STYLE_MENU_BTN "style.menu.button"
 #define STR_REMOVE_FAVORITE "Removed from your favorite."
 #define STR_WGT "wgt"
 #define STR_TPK "tpk"
+#define STR_OK "Ok"
+#define STR_CANCEL "Cancel"
 
 /* Count */
 #define MENU_COUNT 2
index f6bdefd..c71f59c 100644 (file)
@@ -31,6 +31,8 @@ Evas_Object *utils_add_table(Evas_Object *table, const char *part,
 Evas_Object *utils_add_notify(Evas_Object *parent, const char *text,
                const char *noti_style, const char *label_style,
                int timeout);
+Evas_Object *utils_add_popup(Evas_Object *parent, const char *style,
+               const char *popup_title, const char *popup_text);
 bool utils_launch_app(const char *appid);
 bool utils_uninstall_app(const char *pkgid, const char *pkgtype);
 
index 824d720..13aee13 100644 (file)
@@ -232,6 +232,37 @@ Evas_Object *utils_add_notify(Evas_Object *parent, const char *text,
        return notify;
 }
 
+Evas_Object *utils_add_popup(Evas_Object *parent, const char *style,
+               const char *popup_title, const char *popup_text)
+{
+       Evas_Object *popup;
+
+       if (!parent) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       popup = elm_popup_add(parent);
+       if (!popup) {
+               _ERR("elm_popup_add failed.");
+               return NULL;
+       }
+
+       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+       evas_object_show(popup);
+
+       if (style)
+               elm_object_style_set(popup, style);
+
+       if (popup_title)
+               elm_object_part_text_set(popup, PART_POPUP_TITLE, popup_title);
+
+       if (popup_text)
+               elm_object_text_set(popup, popup_text);
+
+       return popup;
+}
+
 bool utils_launch_app(const char *appid)
 {
        app_control_h app_ctrl;
index 677a2dc..6af16a6 100644 (file)
 #include "data/app.h"
 #include "grid.h"
 
-enum action_type {
+enum button_type {
        BTN_LIVETV = 0,
        BTN_FAVORITE,
        BTN_UNINSTALL,
+       BTN_OK,
+       BTN_CANCEL,
 };
 
 struct _priv {
@@ -39,6 +41,7 @@ struct _priv {
        Evas_Object *grid;
        Evas_Object *live_btn;
        Evas_Object *menu[ACTION_MENU_COUNT];
+       Evas_Object *popup;
        struct gridmgr *gmgr;
        Eina_List *fav_list;
        bool uninstallable;
@@ -132,6 +135,83 @@ static void _uninstall_selected(struct _priv *priv)
        viewmgr_hide_view(VIEW_ACTION_MENU);
 }
 
+static void _popup_clicked_cb(int id, void *data, Evas_Object *obj)
+{
+       struct _priv *priv;
+
+       if (!data)
+               return;
+
+       priv = data;
+
+       evas_object_del(priv->popup);
+
+       if (id == BTN_OK)
+               _uninstall_selected(priv);
+}
+
+static void _popup_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
+               Evas_Event_Key_Down *ev)
+{
+       struct _priv *priv;
+
+       if (!ev || !data) {
+               _ERR("Invalid argument.");
+               return;
+       }
+       priv = data;
+
+       if (!strcmp(ev->keyname, KEY_BACK)
+                       || !strcmp(ev->keyname, KEY_BACK_REMOTE))
+               evas_object_del(priv->popup);
+}
+
+static input_handler _popup_input_handler = {
+       .mouse_move = _mouse_move_cb,
+       .clicked = _popup_clicked_cb,
+       .key_down = _popup_key_down_cb
+};
+
+static void _draw_uninstall_popup(struct _priv *priv)
+{
+       Evas_Object *popup, *btn1, *btn2;
+       char str[SIZE_STR];
+       char *name;
+
+       name = get_app_name(priv->adata);
+       if (!name)
+               return;
+
+       snprintf(str, sizeof(str), "%s %s?", STR_UNINSTALL, name);
+
+       popup = utils_add_popup(priv->base, NULL, STR_UNINSTALL, str);
+       if (!popup) {
+               _ERR("Add popup failed.");
+               return;
+       }
+
+       btn1 = utils_add_button(popup, PART_BUTTON1, STR_CANCEL, NULL);
+       if (!btn1) {
+               _ERR("Add button failed.");
+               evas_object_del(popup);
+               return;
+       }
+
+       btn2 = utils_add_button(popup, PART_BUTTON2, STR_OK, NULL);
+       if (!btn2) {
+               _ERR("Add button failed.");
+               evas_object_del(popup);
+               return;
+       }
+
+       elm_object_focus_set(btn1, EINA_TRUE);
+
+       priv->popup = popup;
+
+       inputmgr_add_callback(btn1, BTN_CANCEL, &_popup_input_handler, priv);
+       inputmgr_add_callback(btn2, BTN_OK, &_popup_input_handler, priv);
+}
+
 static void _clicked_cb(int id, void *data, Evas_Object *obj)
 {
        struct _priv *priv;
@@ -151,7 +231,7 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
                break;
 
        case BTN_UNINSTALL:
-               _uninstall_selected(priv);
+               _draw_uninstall_popup(priv);
                break;
 
        default: