View: Add pin view for locking favorited channel 26/47226/2
authorHyojung Jo <hj903.jo@samsung.com>
Tue, 1 Sep 2015 07:00:36 +0000 (16:00 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Wed, 2 Sep 2015 00:56:40 +0000 (09:56 +0900)
Change-Id: I3ca541eee93b9edb1159503d72e7b61c7c71c813
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
20 files changed:
CMakeLists.txt
include/datamgr.h
include/define.h
include/grid.h
include/view.h
packaging/org.tizen.favorite.spec
src/data/app.c
src/data/channel.c
src/data/media.c
src/data/web.c
src/grid/grid_apps.c
src/grid/grid_gallery.c
src/grid/grid_movie.c
src/grid/grid_music.c
src/grid/grid_tv.c
src/grid/grid_webs.c
src/main.c
src/view/view_action_menu.c
src/view/view_base.c
src/view/view_pin.c [new file with mode: 0644]

index 1bef08a..4300f1b 100644 (file)
@@ -27,6 +27,7 @@ pkg_check_modules(PKGS REQUIRED
                glib-2.0
                capi-web-bookmark
                tv-service
+               ui-gadget-1
                )
 
 IF(NOT DEFINED PACKAGE_NAME)
@@ -66,6 +67,7 @@ SET(SRCS
        src/common/utils.c
        src/view/view_base.c
        src/view/view_action_menu.c
+       src/view/view_pin.c
        src/grid/grid_tv.c
        src/grid/grid_movie.c
        src/grid/grid_gallery.c
index ead6b10..c83e92f 100644 (file)
@@ -35,8 +35,9 @@ struct datamgr {
        void (*free_favorites)(Eina_List *list);
        int (*get_count)(enum item_type type);
        char *(*get_data)(void *data, enum data_type type);
-       bool (*action)(Elm_Object_Item *it, enum action_type type);
+       bool (*action)(Elm_Object_Item *it, enum action_type type, void *data);
        bool (*data_updated)(void *data1, void *data2);
+       bool (*data_locked)(Elm_Object_Item *it, bool *locked);
 };
 
 struct datamgr *get_channel_datamgr(void);
index 1a5eadf..1a411b9 100644 (file)
 /* View ID */
 #define VIEW_BASE "VIEW_BASE"
 #define VIEW_ACTION_MENU "VIEW_ACTION_MENU"
+#define VIEW_PIN "VIEW_PIN"
+
+/* Grid ID */
+#define GRID_TV "TV"
+#define GRID_MOVIE "Movie"
+#define GRID_GALLERY "Gallery"
+#define GRID_MUSIC "Music"
+#define GRID_APP "Apps"
+#define GRID_WEB "Web"
 
 /* Group */
 #define GRP_VIEW_BASE "grp.view.base"
 #define STR_BROWSER "Web Browser"
 #define STR_LIVETV "Live TV"
 #define STR_REMOVE_FAVORITE "Removed from your favorite."
+#define STR_SUCCESS "success"
+#define STR_FAIL "fail"
+#define STR_LOCKED "Content is locked."
+#define STR_UNLOCKED "Content is unlocked."
 
 /* Font */
 #define FONT_TIZENSANS_REGULAR "TizenSans"
index 924d89c..6bf4b74 100644 (file)
@@ -30,8 +30,10 @@ struct grid_data {
 
        Eina_List *(*create_item_list)(void);
        void (*destroy_item_list)(Eina_List *list);
-       bool (*item_action)(Elm_Object_Item *it, enum action_type type);
+       bool (*item_action)(Elm_Object_Item *it,
+                       enum action_type type, void *data);
        bool (*item_updated)(void *pre_data, void *new_data);
+       bool (*item_locked)(Elm_Object_Item *it, bool *locked);
 };
 
 struct grid_data *get_tv_grid_data(void);
index 159fd2e..af49323 100644 (file)
@@ -19,6 +19,7 @@
 
 view_class *view_base_get_vclass(void);
 view_class *view_action_menu_get_vclass(void);
+view_class *view_pin_get_vclass(void);
 
 enum update_type {
        UPDATE_DATA = 0,
index 63df129..fd682bb 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires: pkgconfig(capi-content-media-content)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(capi-web-bookmark)
 BuildRequires: pkgconfig(tv-service)
+BuildRequires: pkgconfig(ui-gadget-1)
 
 %define _appdir /usr/apps/%{name}
 %define _bindir %{_appdir}/bin
index d73a69c..6601d40 100644 (file)
@@ -154,7 +154,7 @@ static void _free_favorites(Eina_List *list)
        }
 }
 
-static bool _action(Elm_Object_Item *it, enum action_type type)
+static bool _action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct app_data *adata;
        int r;
index b18b6d0..9697cbc 100644 (file)
@@ -174,7 +174,43 @@ static bool _unset_favorite(struct channel_data *cdata)
        return true;
 }
 
-static bool _action(Elm_Object_Item *it, enum action_type type)
+static bool _update_lock(struct channel_data *cdata, void *data)
+{
+       TvServiceChannel channel;
+       char *pincode;
+       int r;
+
+       if (!data)
+               return false;
+
+       pincode = data;
+
+       r = tv_service_channel_info_create();
+       if (r != TVS_ERROR_OK) {
+               _ERR("Tv Service channel info create failed.");
+               return false;
+       }
+
+       r = tv_service_get_channel(cdata->id, &channel);
+       if (r != TVS_ERROR_OK) {
+               tv_service_channel_info_destroy();
+               return false;
+       }
+
+       if (channel.locked)
+               r = tv_service_unlock_channel(cdata->id, pincode);
+       else
+               r = tv_service_lock_channel(cdata->id, pincode);
+
+       tv_service_channel_info_destroy();
+
+       if (r < 0)
+               return false;
+
+       return true;
+}
+
+static bool _action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct channel_data *cdata;
        char str[SIZE_STR];
@@ -208,7 +244,11 @@ static bool _action(Elm_Object_Item *it, enum action_type type)
                break;
 
        case ACTION_UPDATE_LOCK:
-               /* It will implemented later. */
+               if (!_update_lock(cdata, data)) {
+                       _ERR("Update lock status failed.");
+                       return false;
+               }
+
                break;
 
        default:
@@ -232,6 +272,40 @@ static bool _data_updated(void *data1, void *data2)
        return true;
 }
 
+static bool _data_locked(Elm_Object_Item *it, bool *locked)
+{
+       struct channel_data *cdata;
+       TvServiceChannel channel;
+       int r;
+
+       if (!it) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       cdata = elm_object_item_data_get(it);
+       if (!cdata)
+               return false;
+
+       r = tv_service_channel_info_create();
+       if (r != TVS_ERROR_OK) {
+               _ERR("Tv Service channel info create failed.");
+               return false;
+       }
+
+       r = tv_service_get_channel(cdata->id, &channel);
+       if (r != TVS_ERROR_OK) {
+               tv_service_channel_info_destroy();
+               return false;
+       }
+
+       *locked = channel.locked;
+
+       tv_service_channel_info_destroy();
+
+       return true;
+}
+
 static struct datamgr _dmgr = {
        .get_data = _get_data,
        .get_count = NULL,
@@ -239,6 +313,7 @@ static struct datamgr _dmgr = {
        .free_favorites = _free_favorites,
        .action = _action,
        .data_updated = _data_updated,
+       .data_locked = _data_locked,
 };
 
 struct datamgr *get_channel_datamgr(void)
index 0cb365f..a4335da 100644 (file)
@@ -224,7 +224,7 @@ static void _free_favorites(Eina_List *list)
        }
 }
 
-static bool _action(Elm_Object_Item *it, enum action_type type)
+static bool _action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        app_media *am;
        app_media_info *minfo;
index e58437e..da1733f 100644 (file)
@@ -125,7 +125,7 @@ static void _free_favorites(Eina_List *list)
        }
 }
 
-static bool _action(Elm_Object_Item *it, enum action_type type)
+static bool _action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        /* It will be implemented later. */
 
index a7be106..8cc220d 100644 (file)
@@ -23,7 +23,6 @@
 #include "define.h"
 #include "grid.h"
 
-#define STR_APPS "Apps"
 #define STYLE_APPS "style.apps"
 #define ITEM_APPS_X (212 + 26)
 #define ITEM_APPS_Y (294 + 26)
@@ -154,7 +153,7 @@ static void _destroy_item_list(Eina_List *list)
        dmgr->free_favorites(list);
 }
 
-static bool _item_action(Elm_Object_Item *it, enum action_type type)
+static bool _item_action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct datamgr *dmgr;
 
@@ -167,7 +166,7 @@ static bool _item_action(Elm_Object_Item *it, enum action_type type)
        if (!dmgr || !dmgr->action)
                return false;
 
-       if (!dmgr->action(it, type)) {
+       if (!dmgr->action(it, type, data)) {
                _ERR("The item action failed.");
                return false;
        }
@@ -187,7 +186,7 @@ static bool _item_updated(void *pre_data, void *new_data)
 }
 
 static struct grid_data _gdata = {
-       .id = STR_APPS,
+       .id = GRID_APP,
        .item_size_x = ITEM_APPS_X,
        .item_size_y = ITEM_APPS_Y,
        .gclass = &_gclass,
index be85c2c..d648caa 100644 (file)
@@ -23,7 +23,6 @@
 #include "define.h"
 #include "grid.h"
 
-#define STR_GALLERY "Gallery"
 #define STYLE_GALLERY "style.gallery"
 #define ITEM_GALLERY_X (200 + 6)
 #define ITEM_GALLERY_Y (200 + 6)
@@ -133,7 +132,7 @@ static void _destroy_item_list(Eina_List *list)
        dmgr->free_favorites(list);
 }
 
-static bool _item_action(Elm_Object_Item *it, enum action_type type)
+static bool _item_action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct datamgr *dmgr;
 
@@ -146,7 +145,7 @@ static bool _item_action(Elm_Object_Item *it, enum action_type type)
        if (!dmgr || !dmgr->action)
                return false;
 
-       if (!dmgr->action(it, type)) {
+       if (!dmgr->action(it, type, data)) {
                _ERR("The item action failed.");
                return false;
        }
@@ -166,7 +165,7 @@ static bool _item_updated(void *pre_data, void *new_data)
 }
 
 static struct grid_data _gdata = {
-       .id = STR_GALLERY,
+       .id = GRID_GALLERY,
        .item_size_x = ITEM_GALLERY_X,
        .item_size_y = ITEM_GALLERY_Y,
        .gclass = &_gclass,
index 5ac0356..c90ffe6 100644 (file)
@@ -22,7 +22,6 @@
 #include "define.h"
 #include "grid.h"
 
-#define STR_MOVIE "Movie"
 #define STYLE_MOVIE "style.movie"
 #define ITEM_MOVIE_X (378 + 26)
 #define ITEM_MOVIE_Y (294 + 26)
@@ -157,7 +156,7 @@ static void _destroy_item_list(Eina_List *list)
        dmgr->free_favorites(list);
 }
 
-static bool _item_action(Elm_Object_Item *it, enum action_type type)
+static bool _item_action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct datamgr *dmgr;
 
@@ -170,7 +169,7 @@ static bool _item_action(Elm_Object_Item *it, enum action_type type)
        if (!dmgr || !dmgr->action)
                return false;
 
-       if (!dmgr->action(it, type)) {
+       if (!dmgr->action(it, type, data)) {
                _ERR("The item action failed.");
                return false;
        }
@@ -190,7 +189,7 @@ static bool _item_updated(void *pre_data, void *new_data)
 }
 
 static struct grid_data _gdata = {
-       .id = STR_MOVIE,
+       .id = GRID_MOVIE,
        .item_size_x = ITEM_MOVIE_X,
        .item_size_y = ITEM_MOVIE_Y,
        .gclass = &_gclass,
index e6090c6..3a2aae4 100644 (file)
@@ -23,7 +23,6 @@
 #include "define.h"
 #include "grid.h"
 
-#define STR_MUSIC "Music"
 #define STYLE_MUSIC "style.music"
 #define ITEM_MUSIC_X (488 + 26)
 #define ITEM_MUSIC_Y (134 + 26)
@@ -131,7 +130,7 @@ static void _destroy_item_list(Eina_List *list)
        dmgr->free_favorites(list);
 }
 
-static bool _item_action(Elm_Object_Item *it, enum action_type type)
+static bool _item_action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct datamgr *dmgr;
 
@@ -144,7 +143,7 @@ static bool _item_action(Elm_Object_Item *it, enum action_type type)
        if (!dmgr || !dmgr->action)
                return false;
 
-       if (!dmgr->action(it, type)) {
+       if (!dmgr->action(it, type, data)) {
                _ERR("The item action failed.");
                return false;
        }
@@ -164,7 +163,7 @@ static bool _item_updated(void *pre_data, void *new_data)
 }
 
 static struct grid_data _gdata = {
-       .id = STR_MUSIC,
+       .id = GRID_MUSIC,
        .item_size_x = ITEM_MUSIC_X,
        .item_size_y = ITEM_MUSIC_Y,
        .gclass = &_gclass,
index 8ad32b4..a791221 100644 (file)
@@ -23,7 +23,6 @@
 #include "grid.h"
 #include "datamgr.h"
 
-#define STR_TV "TV"
 #define STYLE_TV "style.tv"
 #define ITEM_TV_X (378 + 26)
 #define ITEM_TV_Y (294 + 26)
@@ -154,7 +153,7 @@ static void _destroy_item_list(Eina_List *list)
        dmgr->free_favorites(list);
 }
 
-static bool _item_action(Elm_Object_Item *it, enum action_type type)
+static bool _item_action(Elm_Object_Item *it, enum action_type type, void *data)
 {
        struct datamgr *dmgr;
 
@@ -167,7 +166,7 @@ static bool _item_action(Elm_Object_Item *it, enum action_type type)
        if (!dmgr || !dmgr->action)
                return false;
 
-       if (!dmgr->action(it, type)) {
+       if (!dmgr->action(it, type, data)) {
                _ERR("The item action failed.");
                return false;
        }
@@ -186,8 +185,29 @@ static bool _item_updated(void *pre_data, void *new_data)
        return dmgr->data_updated(pre_data, new_data);
 }
 
+static bool _item_locked(Elm_Object_Item *it, bool *locked)
+{
+       struct datamgr *dmgr;
+
+       if (!it) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       dmgr = get_channel_datamgr();
+       if (!dmgr || !dmgr->data_locked)
+               return false;
+
+       if (!dmgr->data_locked(it, locked)) {
+               _ERR("Get lock status failed.");
+               return false;
+       }
+
+       return true;
+}
+
 static struct grid_data _gdata = {
-       .id = STR_TV,
+       .id = GRID_TV,
        .item_size_x = ITEM_TV_X,
        .item_size_y = ITEM_TV_Y,
        .gclass = &_gclass,
@@ -195,6 +215,7 @@ static struct grid_data _gdata = {
        .destroy_item_list = _destroy_item_list,
        .item_action = _item_action,
        .item_updated = _item_updated,
+       .item_locked = _item_locked,
 };
 
 struct grid_data *get_tv_grid_data(void)
index ee42d6b..1414742 100644 (file)
@@ -22,7 +22,6 @@
 #include "define.h"
 #include "grid.h"
 
-#define STR_WEBS "Web"
 #define STYLE_WEBS "style.webs"
 #define ITEM_WEBS_X (378 + 26)
 #define ITEM_WEBS_Y (294 + 26)
@@ -148,7 +147,7 @@ static void _destroy_item_list(Eina_List *list)
 }
 
 static struct grid_data _gdata = {
-       .id = STR_WEBS,
+       .id = GRID_WEB,
        .item_size_x = ITEM_WEBS_X,
        .item_size_y = ITEM_WEBS_Y,
        .gclass = &_gclass,
index 2f75d0e..6fd76e9 100644 (file)
@@ -17,6 +17,7 @@
 #include <app.h>
 #include <Elementary.h>
 #include <viewmgr.h>
+#include <ui-gadget.h>
 #include <app_debug.h>
 
 #include "define.h"
@@ -49,6 +50,12 @@ static bool _create(void *data)
                return false;
        }
 
+       if (ug_init_efl(win, UG_OPT_INDICATOR_ENABLE) < 0) {
+               _ERR("Fail to init ug");
+               evas_object_del(win);
+               return false;
+       }
+
        if (!viewmgr_create(win)) {
                _ERR("Create viewmgr failed.");
                evas_object_del(win);
@@ -69,6 +76,13 @@ static bool _create(void *data)
                return false;
        }
 
+       if (!viewmgr_add_view(view_pin_get_vclass(), NULL)) {
+               _ERR("Add view faild.");
+               viewmgr_destroy();
+               evas_object_del(win);
+               return false;
+       }
+
        ad->win = win;
 
        return true;
@@ -91,6 +105,7 @@ static void _terminate(void *data)
 
        viewmgr_remove_view(VIEW_BASE);
        viewmgr_remove_view(VIEW_ACTION_MENU);
+       viewmgr_remove_view(VIEW_PIN);
        viewmgr_destroy();
 }
 
index 81cafdd..9b20ebb 100644 (file)
@@ -44,21 +44,18 @@ struct _action_info {
        int id;
        const char *title;
        const char *style;
-       Eina_Bool disable;
 };
 
 static struct _action_info action_info[] = {
        {
                .id = BTN_FAVORITE,
                .title = STR_FAVORITE,
-               .style = STYLE_ACTION_MENU_FAV_BTN,
-               .disable = EINA_FALSE
+               .style = STYLE_ACTION_MENU_FAV_BTN
        },
        {
                .id = BTN_LOCK,
                .title = STR_LOCK,
-               .style = STYLE_ACTION_MENU_LOCK_BTN,
-               .disable = EINA_TRUE
+               .style = STYLE_ACTION_MENU_LOCK_BTN
        }
 };
 
@@ -86,7 +83,8 @@ static void _livetv_selected(void)
 
 static void _favorite_selected(struct grid_data *gdata)
 {
-       if (!gdata->item_action(gdata->focused_item, ACTION_UPDATE_FAVORITE)) {
+       if (!gdata->item_action(gdata->focused_item,
+                               ACTION_UPDATE_FAVORITE, NULL)) {
                _ERR("Unfavorite failed.");
                return;
        }
@@ -96,6 +94,15 @@ static void _favorite_selected(struct grid_data *gdata)
        viewmgr_hide_view(VIEW_ACTION_MENU);
 }
 
+static void _lock_selected(struct grid_data *gdata)
+{
+       if (!gdata->item_action || !gdata->item_locked)
+               return;
+
+       viewmgr_update_view(VIEW_PIN, UPDATE_DATA, gdata);
+       viewmgr_show_view(VIEW_PIN);
+}
+
 static void _clicked_cb(int id, void *data, Evas_Object *obj)
 {
        struct _priv *priv;
@@ -117,7 +124,7 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
                break;
 
        case BTN_LOCK:
-               /* It is not supported yet. */
+               _lock_selected(priv->gdata);
                break;
 
        default:
@@ -157,15 +164,67 @@ static bool _draw_livetv_area(struct _priv *priv)
 
        inputmgr_add_callback(btn, BTN_LIVETV, &_btn_input_handler, priv);
 
-       elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_UP);
-       elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_LEFT);
-       elm_object_focus_next_object_set(btn, btn, ELM_FOCUS_RIGHT);
-
        priv->live_btn = btn;
 
        return true;
 }
 
+static void _set_focus_policy(struct _priv *priv)
+{
+       int i;
+
+       elm_object_focus_next_object_set(priv->live_btn, priv->live_btn,
+                       ELM_FOCUS_UP);
+       elm_object_focus_next_object_set(priv->live_btn, priv->live_btn,
+                       ELM_FOCUS_LEFT);
+       elm_object_focus_next_object_set(priv->live_btn, priv->live_btn,
+                       ELM_FOCUS_RIGHT);
+       elm_object_focus_next_object_set(priv->live_btn, priv->menu_btn[0],
+                       ELM_FOCUS_DOWN);
+
+       if (elm_object_disabled_get(priv->menu_btn[1])) {
+               elm_object_focus_next_object_set(priv->menu_btn[0],
+                               priv->menu_btn[0], ELM_FOCUS_LEFT);
+               elm_object_focus_next_object_set(priv->menu_btn[0],
+                               priv->menu_btn[0], ELM_FOCUS_RIGHT);
+       } else {
+               elm_object_focus_next_object_set(priv->menu_btn[0],
+                               priv->menu_btn[1], ELM_FOCUS_LEFT);
+               elm_object_focus_next_object_set(priv->menu_btn[1],
+                               priv->menu_btn[0], ELM_FOCUS_RIGHT);
+       }
+
+       for (i = 0; i < COUNT_ACTION; i++)
+               elm_object_focus_next_object_set(priv->menu_btn[i],
+                               priv->menu_btn[i], ELM_FOCUS_DOWN);
+}
+
+static void _set_action_state(int idx, Evas_Object *btn, struct _priv *priv)
+{
+       struct grid_data *gdata;
+       bool locked;
+
+       if (!priv->gdata)
+               return;
+
+       gdata = priv->gdata;
+
+       if (action_info[idx].id == BTN_LOCK) {
+               /* Channel can only be locked */
+               if (!strcmp(gdata->id, GRID_TV) && gdata->item_locked) {
+                       gdata->item_locked(gdata->focused_item, &locked);
+
+                       if (locked)
+                               elm_object_signal_emit(btn, SIG_TOGGLE,
+                                               SRC_ACTION_BTN);
+
+                       return;
+               }
+
+               elm_object_disabled_set(btn, EINA_TRUE);
+       }
+}
+
 static bool _draw_action_area(struct _priv *priv)
 {
        Evas_Object *table, *btn;
@@ -190,8 +249,7 @@ static bool _draw_action_area(struct _priv *priv)
                inputmgr_add_callback(btn, action_info[i].id,
                                &_btn_input_handler, priv);
 
-               if (action_info[i].disable)
-                       elm_object_disabled_set(btn, EINA_TRUE);
+               _set_action_state(i, btn, priv);
 
                col = i % SIZE_COL_MAX;
                row = i / SIZE_COL_MAX;
@@ -201,15 +259,7 @@ static bool _draw_action_area(struct _priv *priv)
                priv->menu_btn[i] = btn;
        }
 
-       /* 'Favorite' can only be focused now. */
-       elm_object_focus_next_object_set(priv->menu_btn[0],
-                       priv->menu_btn[0], ELM_FOCUS_LEFT);
-       elm_object_focus_next_object_set(priv->menu_btn[0],
-                       priv->menu_btn[0], ELM_FOCUS_RIGHT);
-       elm_object_focus_next_object_set(priv->menu_btn[0],
-                       priv->menu_btn[0], ELM_FOCUS_DOWN);
-       elm_object_focus_next_object_set(priv->live_btn, priv->menu_btn[0],
-                       ELM_FOCUS_DOWN);
+       _set_focus_policy(priv);
 
        return true;
 }
@@ -248,7 +298,6 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        }
 
        _draw_livetv_area(priv);
-       _draw_action_area(priv);
 
        return base;
 }
@@ -293,8 +342,13 @@ static void _update(void *view_data, int update_type, void *data)
        }
        priv = view_data;
 
-       if (update_type == UPDATE_DATA)
+       if (update_type == UPDATE_DATA) {
+               if (!data)
+                       return;
+
                priv->gdata = data;
+               _draw_action_area(priv);
+       }
 }
 
 static void _destroy(void *data)
index 4fe5bf3..211bda5 100644 (file)
@@ -270,7 +270,7 @@ static void _grid_item_selected_cb(void *data, Elm_Object_Item *it,
        gdata = data;
 
        if (gdata->item_action)
-               gdata->item_action(it, ACTION_LAUNCH);
+               gdata->item_action(it, ACTION_LAUNCH, NULL);
 
        elm_gengrid_item_selected_set(it, EINA_FALSE);
 }
diff --git a/src/view/view_pin.c b/src/view/view_pin.c
new file mode 100644 (file)
index 0000000..7a86e4e
--- /dev/null
@@ -0,0 +1,222 @@
+/* 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 <Elementary.h>
+#include <viewmgr.h>
+#include <ui-gadget.h>
+#include <app_define.h>
+#include <app_debug.h>
+
+#include "grid.h"
+#include "view.h"
+#include "define.h"
+
+struct _priv {
+       Evas_Object *win;
+       ui_gadget_h ug;
+       struct grid_data *gdata;
+};
+
+static void _send_message(struct _priv *priv, const char *result)
+{
+       service_h service;
+       int r;
+
+       r = service_create(&service);
+       if (r != SERVICE_ERROR_NONE) {
+               _ERR("Fail to create service");
+               return;
+       }
+
+       r = service_add_extra_data(service, PARAM_PIN, result);
+       if (r != SERVICE_ERROR_NONE) {
+               _ERR("Fail to add data");
+               service_destroy(service);
+               return;
+       }
+
+       ug_send_message(priv->ug, service);
+       service_destroy(service);
+}
+
+static void _pincode_checked(struct _priv *priv, char *pincode)
+{
+       bool locked;
+
+       if (!priv->gdata->item_action(priv->gdata->focused_item,
+                               ACTION_UPDATE_LOCK, pincode)) {
+               _ERR("Update lock failed.");
+               _send_message(priv, STR_FAIL);
+               return;
+       }
+
+       if (!priv->gdata->item_locked(priv->gdata->focused_item, &locked)) {
+               _ERR("Get lock status failed.");
+               goto end;
+       }
+
+       if (locked)
+               viewmgr_update_view(VIEW_BASE, UPDATE_SHOW_TOAST, STR_LOCKED);
+       else
+               viewmgr_update_view(VIEW_BASE, UPDATE_SHOW_TOAST, STR_UNLOCKED);
+
+end:
+       viewmgr_hide_view(VIEW_PIN);
+       viewmgr_hide_view(VIEW_ACTION_MENU);
+}
+
+static void _ug_result_cb(ui_gadget_h ug, service_h result, void *priv)
+{
+       char *pincode;
+       int r;
+
+       if (!priv) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       r = service_get_extra_data(result, PARAM_PIN, &pincode);
+       if (r != SERVICE_ERROR_NONE || !pincode) {
+               _ERR("Fail to get data");
+               return;
+       }
+
+       _pincode_checked(priv, pincode);
+
+       free(pincode);
+}
+
+static void _ug_destroy_cb(ui_gadget_h ug, void *priv)
+{
+       viewmgr_hide_view(VIEW_PIN);
+}
+
+static ui_gadget_h _load_pin_ug(struct _priv *priv)
+{
+       ui_gadget_h ug;
+       struct ug_cbs cbs = {0,};
+
+       cbs.result_cb = _ug_result_cb;
+       cbs.destroy_cb = _ug_destroy_cb;
+       cbs.priv = priv;
+
+       ug = ug_create(NULL, UG_ID_PIN, UG_MODE_FRAMEVIEW, NULL, &cbs);
+
+       return ug;
+}
+
+static Evas_Object *_create(Evas_Object *win, void *data)
+{
+       struct _priv *priv;
+
+       if (!win) {
+               _ERR("Get window object failed.");
+               return NULL;
+       }
+
+       priv = calloc(1, sizeof(*priv));
+       if (!priv) {
+               _ERR("Calloc failed.");
+               return NULL;
+       }
+
+       priv->win = win;
+
+       if (!viewmgr_set_view_data(VIEW_PIN, priv)) {
+               _ERR("Set view data failed.");
+               free(priv);
+               return NULL;
+       }
+
+       return win;
+}
+
+static void _show(void *data)
+{
+       struct _priv *priv;
+       ui_gadget_h ug;
+
+       if (!data) {
+               _ERR("Get data failed.");
+               return;
+       }
+       priv = data;
+
+       ug = _load_pin_ug(priv);
+       if (!ug) {
+               _ERR("Create pin ug failed.");
+               return;
+       }
+
+       priv->ug = ug;
+}
+
+static void _hide(void *data)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Get data failed.");
+               return;
+       }
+       priv = data;
+
+       if (priv->ug)
+               ug_destroy(priv->ug);
+}
+
+static void _update(void *view_data, int update_type, void *data)
+{
+       struct _priv *priv;
+
+       if (!view_data) {
+               _ERR("Get data failed.");
+               return;
+       }
+       priv = view_data;
+
+       if (update_type == UPDATE_DATA)
+               priv->gdata = data;
+}
+
+static void _destroy(void *data)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Get data failed.");
+               return;
+       }
+       priv = data;
+
+       if (priv->ug)
+               ug_destroy(priv->ug);
+
+       free(priv);
+}
+
+static view_class _vclass = {
+       .view_id = VIEW_PIN,
+       .create = _create,
+       .show = _show,
+       .hide = _hide,
+       .update = _update,
+       .destroy = _destroy,
+};
+
+view_class *view_pin_get_vclass(void)
+{
+       return &_vclass;
+}