diff options
author | jinwoo.shin <jw0227.shin@samsung.com> | 2015-08-20 14:01:26 +0900 |
---|---|---|
committer | jinwoo.shin <jw0227.shin@samsung.com> | 2015-08-20 15:50:13 +0900 |
commit | bdd9c587914eb6136336436dc0c5b045dddb240e (patch) | |
tree | b12a40316f3926371c7e6214c22bba430ec3f444 | |
parent | 51b037c604d70eebc5cd85a71e25b86fdeef0f52 (diff) | |
download | air_livetv-bdd9c587914eb6136336436dc0c5b045dddb240e.tar.gz air_livetv-bdd9c587914eb6136336436dc0c5b045dddb240e.tar.bz2 air_livetv-bdd9c587914eb6136336436dc0c5b045dddb240e.zip |
Add button action and status update
Change-Id: I4ceffae9439782f51535548c9624db8959a1a39f
Signed-off-by: jinwoo.shin <jw0227.shin@samsung.com>
-rw-r--r-- | include/define.h | 2 | ||||
-rw-r--r-- | include/view.h | 1 | ||||
-rw-r--r-- | src/view_action_menu.c | 166 |
3 files changed, 142 insertions, 27 deletions
diff --git a/include/define.h b/include/define.h index d521b65..b967015 100644 --- a/include/define.h +++ b/include/define.h @@ -43,6 +43,8 @@ #define SIGNAL_LAST "elm,state,last" #define SIGNAL_LOCKED "elm,state,locked" #define SIGNAL_FAVORITE "elm,state,favorite" +#define SIGNAL_TOGGLE "elm,state,toggle" +#define SIGNAL_UNTOGGLE "elm,state,untoggle" #define FONT_REGULAR "TizenSans" #define FONT_LIGHT "TizenSans:style=Light" diff --git a/include/view.h b/include/view.h index bc299cb..2ad1f15 100644 --- a/include/view.h +++ b/include/view.h @@ -25,6 +25,7 @@ enum _update_type { UPDATE_TYPE_INPUT_KEY_UP, UPDATE_TYPE_NOCHANNEL, UPDATE_TYPE_NOSIGNAL, + UPDATE_TYPE_CHANNELINFO, }; enum _update_op { diff --git a/src/view_action_menu.c b/src/view_action_menu.c index a332c91..6e167de 100644 --- a/src/view_action_menu.c +++ b/src/view_action_menu.c @@ -40,13 +40,20 @@ enum _button_id { BUTTON_LOCK, }; +enum _button_state { + STATE_INVALID = -1, + STATE_UNTOGGLE, + STATE_TOGGLE, + STATE_DISABLED, +}; + struct _priv { Evas_Object *base; Evas_Object *channel_info; Evas_Object *menu_btn[BUTTON_MAX]; }; -struct _button_state { +struct _button_data { const char *text; const char *normal; const char *focused; @@ -54,45 +61,96 @@ struct _button_state { const char *disabled; }; +static void _fav_clicked(void) +{ + const struct tv_channel_info *channel_info; + int r; + + channel_info = tv_channel_get_info(); + if (!channel_info) { + _ERR("failed to get channel info"); + return; + } + + r = tv_channel_set_favorite(channel_info->service_id, + !channel_info->favorite); + if (r < 0) + _ERR("failed to set favorite"); + + viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_TYPE_CHANNELINFO, NULL); + + tv_channel_del_info(channel_info); +} + +static int _fav_state(void) +{ + const struct tv_channel_info *channel_info; + int r; + + channel_info = tv_channel_get_info(); + if (!channel_info) { + _ERR("failed to get channel info"); + return STATE_INVALID; + } + + r = channel_info->favorite ? STATE_TOGGLE : STATE_UNTOGGLE; + + tv_channel_del_info(channel_info); + + return r; +} + +static int _lock_state(void) +{ + return STATE_DISABLED; +} + struct _button { int id; - struct _button_state state[2]; + struct _button_data data[2]; + + void (*clicked)(void); + int (*state)(void); }; static struct _button buttons[] = { { .id = BUTTON_FAV, - .state[UNTOGGLE] = { + .data[UNTOGGLE] = { .text = STR_BUTTON_FAVORITE, .normal = IMAGE_FAV_NOR, .focused = IMAGE_FAV_FOC, .selected = IMAGE_FAV_SEL, .disabled = IMAGE_FAV_DIS }, - .state[TOGGLE] = { + .data[TOGGLE] = { .text = STR_BUTTON_FAVORITE, .normal = IMAGE_FAV_NOR, .focused = IMAGE_FAV_FOC, .selected = IMAGE_FAV_SEL, .disabled = IMAGE_FAV_DIS - } + }, + .clicked = _fav_clicked, + .state = _fav_state }, { .id = BUTTON_LOCK, - .state[UNTOGGLE] = { + .data[UNTOGGLE] = { .text = STR_BUTTON_LOCK, .normal = IMAGE_LOCK_NOR, .focused = IMAGE_LOCK_FOC, .selected = IMAGE_LOCK_SEL, .disabled = IMAGE_LOCK_DIS }, - .state[TOGGLE] = { + .data[TOGGLE] = { .text = STR_BUTTON_UNLOCK, .normal = IMAGE_UNLOCK_NOR, .focused = IMAGE_UNLOCK_FOC, .selected = IMAGE_UNLOCK_SEL, .disabled = IMAGE_UNLOCK_DIS - } + }, + .clicked = NULL, + .state = _lock_state }, { .id = BUTTON_INVALID @@ -111,15 +169,49 @@ static input_handler key_handler = { .key_down = _key_down_cb, }; -static void _button_click(int id) +static void _update_button_state(Evas_Object *obj, struct _button *button) { - switch (id) { - case BUTTON_LIVETV: - viewmgr_hide_view(VIEW_ACTION_MENU); + int state; + + if (!obj || !button->state) { + _ERR("failed to get button state"); + return; + } + + state = button->state(); + + switch (state) { + case STATE_UNTOGGLE: + elm_object_signal_emit(obj, SIGNAL_UNTOGGLE, SOURCE_ELM); + break; + case STATE_TOGGLE: + elm_object_signal_emit(obj, SIGNAL_TOGGLE, SOURCE_ELM); + break; + case STATE_DISABLED: + elm_object_disabled_set(obj, EINA_TRUE); + break; + case STATE_INVALID: break; } } +static void _button_clicked(Evas_Object *obj, int id, void *data) +{ + struct _button *button; + + if (!data) { + _ERR("failed to get data"); + return; + } + + button = data; + + if (button->clicked) + button->clicked(); + + _update_button_state(obj, button); +} + static void _button_key_up_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Up *ev) { @@ -127,13 +219,13 @@ static void _button_key_up_cb(int id, void *data, Evas *e, Evas_Object *obj, strcmp(ev->keyname, KEY_ENTER_REMOTE)) return; - _button_click(id); + _button_clicked(obj, id, data); } static void _button_mouse_up_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Up *ev) { - _button_click(id); + _button_clicked(obj, id, data); } static void _button_mouse_move_cb(int id, void *data, Evas *e, Evas_Object *obj, @@ -217,7 +309,7 @@ static bool _draw_menu_area(struct _priv *priv) i = 0; while (buttons[i].id != BUTTON_INVALID && i < BUTTON_MAX) { btn = util_add_button(priv->base, NULL, - buttons[i].state[UNTOGGLE].text, + buttons[i].data[UNTOGGLE].text, STYLE_ACTION_MENU_BTN); if (!btn) { _ERR("Add button failed."); @@ -225,26 +317,28 @@ static bool _draw_menu_area(struct _priv *priv) return false; } - util_add_icon(btn, buttons[i].state[UNTOGGLE].normal, + util_add_icon(btn, buttons[i].data[UNTOGGLE].normal, PART_ICON); - util_add_icon(btn, buttons[i].state[UNTOGGLE].focused, + util_add_icon(btn, buttons[i].data[UNTOGGLE].focused, PART_ICON_FOCUSED); - util_add_icon(btn, buttons[i].state[UNTOGGLE].selected, + util_add_icon(btn, buttons[i].data[UNTOGGLE].selected, PART_ICON_SELECTED); - util_add_icon(btn, buttons[i].state[UNTOGGLE].disabled, + util_add_icon(btn, buttons[i].data[UNTOGGLE].disabled, PART_ICON_DISABLED); elm_object_part_text_set(btn, PART_TEXT_1, - buttons[i].state[TOGGLE].text); - util_add_icon(btn, buttons[i].state[TOGGLE].normal, + buttons[i].data[TOGGLE].text); + util_add_icon(btn, buttons[i].data[TOGGLE].normal, PART_ICON_1); - util_add_icon(btn, buttons[i].state[TOGGLE].focused, + util_add_icon(btn, buttons[i].data[TOGGLE].focused, PART_ICON_1_FOCUSED); - util_add_icon(btn, buttons[i].state[TOGGLE].selected, + util_add_icon(btn, buttons[i].data[TOGGLE].selected, PART_ICON_1_SELECTED); - util_add_icon(btn, buttons[i].state[TOGGLE].disabled, + util_add_icon(btn, buttons[i].data[TOGGLE].disabled, PART_ICON_1_DISABLED); inputmgr_add_callback(btn, buttons[i].id, - &button_handler, priv); + &button_handler, &buttons[i]); + + _update_button_state(btn, &buttons[i]); col = i % ITEMS_IN_ROW; row = i / ITEMS_IN_ROW; @@ -408,7 +502,18 @@ static void _destroy(void *data) static void _update(void *view_data, int type, void *data) { - if (type == UPDATE_TYPE_INPUT_KEY_DOWN) { + struct _priv *priv; + + if (!view_data) { + _ERR("failed to get view data"); + return; + } + + priv = view_data; + + switch (type) { + case UPDATE_TYPE_INPUT_KEY_DOWN: + { Evas_Event_Key_Down *ev = data; if (!ev) { @@ -416,7 +521,14 @@ static void _update(void *view_data, int type, void *data) return; } - viewmgr_show_view(VIEW_ACTION_MENU); + if (!strcmp(ev->keyname, KEY_MENU) || + !strcmp(ev->keyname, KEY_MENU_REMOTE)) + viewmgr_show_view(VIEW_ACTION_MENU); + break; + } + case UPDATE_TYPE_CHANNELINFO: + _update_channel_info(priv); + break; } } |