glib-2.0
capi-web-bookmark
tv-service
+ ui-gadget-1
)
IF(NOT DEFINED PACKAGE_NAME)
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
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);
/* 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"
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);
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,
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
}
}
-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;
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];
break;
case ACTION_UPDATE_LOCK:
- /* It will implemented later. */
+ if (!_update_lock(cdata, data)) {
+ _ERR("Update lock status failed.");
+ return false;
+ }
+
break;
default:
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,
.free_favorites = _free_favorites,
.action = _action,
.data_updated = _data_updated,
+ .data_locked = _data_locked,
};
struct datamgr *get_channel_datamgr(void)
}
}
-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;
}
}
-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. */
#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)
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;
if (!dmgr || !dmgr->action)
return false;
- if (!dmgr->action(it, type)) {
+ if (!dmgr->action(it, type, data)) {
_ERR("The item action failed.");
return false;
}
}
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,
#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)
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;
if (!dmgr || !dmgr->action)
return false;
- if (!dmgr->action(it, type)) {
+ if (!dmgr->action(it, type, data)) {
_ERR("The item action failed.");
return false;
}
}
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,
#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)
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;
if (!dmgr || !dmgr->action)
return false;
- if (!dmgr->action(it, type)) {
+ if (!dmgr->action(it, type, data)) {
_ERR("The item action failed.");
return false;
}
}
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,
#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)
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;
if (!dmgr || !dmgr->action)
return false;
- if (!dmgr->action(it, type)) {
+ if (!dmgr->action(it, type, data)) {
_ERR("The item action failed.");
return false;
}
}
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,
#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)
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;
if (!dmgr || !dmgr->action)
return false;
- if (!dmgr->action(it, type)) {
+ if (!dmgr->action(it, type, data)) {
_ERR("The item action failed.");
return false;
}
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,
.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)
#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)
}
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,
#include <app.h>
#include <Elementary.h>
#include <viewmgr.h>
+#include <ui-gadget.h>
#include <app_debug.h>
#include "define.h"
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);
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;
viewmgr_remove_view(VIEW_BASE);
viewmgr_remove_view(VIEW_ACTION_MENU);
+ viewmgr_remove_view(VIEW_PIN);
viewmgr_destroy();
}
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
}
};
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;
}
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;
break;
case BTN_LOCK:
- /* It is not supported yet. */
+ _lock_selected(priv->gdata);
break;
default:
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;
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;
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;
}
}
_draw_livetv_area(priv);
- _draw_action_area(priv);
return base;
}
}
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)
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);
}
--- /dev/null
+/* 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;
+}