#include "tv.h"
#include "view_channelinfo.h"
+enum _order {
+ CHANNEL_NEXT,
+ CHANNEL_PREV
+};
+
struct _priv {
Evas_Object *base;
Evas_Object *layout;
Evas_Object *current_channel;
Evas_Object *next_channel;
+ const struct tv_channel_info *channel_info;
layoutmgr *lmgr;
};
+static int _set_next_channel(struct _priv *priv, int order)
+{
+ const struct tv_channel_info *next, *current, *channel;
+ Eina_List *channel_list, *l;
+
+ if (priv->channel_info)
+ current = priv->channel_info;
+ else {
+ current = tv_channel_get_info();
+ if (!current) {
+ _ERR("failed to get channel info");
+
+ return -1;
+ }
+ }
+
+ channel_list = tv_channel_get_list();
+ if (!channel_list) {
+ _ERR("failed to get channel list");
+ return -1;
+ }
+
+ if (order == CHANNEL_PREV)
+ channel_list = eina_list_reverse(channel_list);
+
+ next = NULL;
+ EINA_LIST_FOREACH(channel_list, l, channel) {
+ if (channel->service_id == current->service_id) {
+ next = eina_list_data_get(eina_list_next(l));
+ break;
+ }
+ }
+
+ if (!next)
+ next = eina_list_data_get(channel_list);
+
+ priv->channel_info = tv_channel_clone_info(next);
+
+ tv_channel_del_info(current);
+ tv_channel_del_list(channel_list);
+
+ return 0;
+}
+
static void _update_channel_info(struct _priv *priv)
{
- const struct tv_channel_info *current_channel;
+ const struct tv_channel_info *prev, *current, *next, *channel;
+ Eina_List *channel_list, *l;
+
+ if (priv->channel_info)
+ current = priv->channel_info;
+ else {
+ current = tv_channel_get_info();
+ if (!current) {
+ _ERR("failed to get channel info");
+
+ return;
+ }
+ }
- current_channel = tv_channel_get_info();
- if (!current_channel) {
- _ERR("failed to get channel info");
+ draw_channel_info(priv->current_channel, current);
+ channel_list = tv_channel_get_list();
+ if (!channel_list) {
+ _ERR("failed to get channel list");
return;
}
- draw_channel_info(priv->current_channel, current_channel);
+ prev = NULL;
+ next = NULL;
+ EINA_LIST_FOREACH(channel_list, l, channel) {
+ if (channel->service_id == current->service_id) {
+ prev = eina_list_data_get(eina_list_prev(l));
+ next = eina_list_data_get(eina_list_next(l));
+ break;
+ }
+ }
+
+ if (!prev) {
+ prev = eina_list_data_get(eina_list_last(channel_list));
+ if (prev == current)
+ prev = NULL;
+ }
+
+ if (!next) {
+ next = eina_list_data_get(channel_list);
+ if (next == current)
+ next = NULL;
+ }
- tv_channel_del_info(current_channel);
+ if (prev)
+ draw_channel_info(priv->prev_channel, prev);
+
+ if (next)
+ draw_channel_info(priv->next_channel, next);
+
+ tv_channel_del_list(channel_list);
}
static bool _create(layoutmgr *lmgr, void *data)
priv = layout_data;
+ if (priv->channel_info)
+ tv_channel_del_info(priv->channel_info);
+
evas_object_del(priv->layout);
free(priv);
}
priv = layout_data;
- _update_channel_info(priv);
-
elm_object_content_set(priv->base, priv->layout);
evas_object_show(priv->layout);
}
elm_object_content_unset(priv->base);
}
-static void _update(void *layout_data, int update_type, void *data)
+static void _update(void *layout_data, int type, void *data)
{
- Evas_Event_Key_Down *ev = data;
struct _priv *priv;
int r;
- if (!layout_data || !ev) {
+ if (!layout_data) {
_ERR("failed to get layout_data and ev");
return;
}
priv = layout_data;
- if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
- !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE)) {
- r = tv_channel_next();
- if (r < 0)
- _ERR("failed to tune next channel");
-
- _update_channel_info(priv);
- } else if (!strcmp(ev->keyname, KEY_CHANNELDOWN) ||
- !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
- r = tv_channel_prev();
- if (r < 0)
- _ERR("failed to tune next channel");
-
- _update_channel_info(priv);
+ if (type == UPDATE_TYPE_INPUT_KEY_DOWN) {
+ Evas_Event_Key_Down *ev = data;
+
+ if (!ev) {
+ _ERR("failed to get ev");
+ return;
+ }
+
+ if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
+ !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE)) {
+ r = _set_next_channel(priv, CHANNEL_NEXT);
+ if (r < 0)
+ _ERR("failed to set next channel");
+ else
+ _update_channel_info(priv);
+ } else if (!strcmp(ev->keyname, KEY_CHANNELDOWN) ||
+ !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
+ r = _set_next_channel(priv, CHANNEL_PREV);
+ if (r < 0)
+ _ERR("failed to set prev channel");
+ else
+ _update_channel_info(priv);
+ }
+ } else if (type == UPDATE_TYPE_INPUT_KEY_UP) {
+ Evas_Event_Key_Up *ev = data;
+
+ if (!ev) {
+ _ERR("failed to get ev");
+ return;
+ }
+
+ if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
+ !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE) ||
+ !strcmp(ev->keyname, KEY_CHANNELDOWN) ||
+ !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
+ if (!priv->channel_info) {
+ _ERR("failed to get channel info");
+ return;
+ }
+
+ r = tv_channel_tune_with_service_id(
+ priv->channel_info->service_id);
+ if (r < 0)
+ _ERR("failed to tune next channel");
+ }
}
}
if (!strcmp(ev->keyname, g_kmap[i].key[j])) {
viewmgr_show_view(g_kmap[i].view);
viewmgr_update_view(g_kmap[i].view,
- UPDATE_TYPE_INPUT, ev);
+ UPDATE_TYPE_INPUT_KEY_DOWN, ev);
+ return;
+ }
+ j++;
+ }
+ }
+}
+
+static void _key_up_cb(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Up *ev)
+{
+ size_t i, j;
+
+ for (i = 0; i < sizeof(g_kmap) / sizeof(*g_kmap); i++) {
+ j = 0;
+ while (g_kmap[i].key[j]) {
+ if (!strcmp(ev->keyname, g_kmap[i].key[j])) {
+ viewmgr_show_view(g_kmap[i].view);
+ viewmgr_update_view(g_kmap[i].view,
+ UPDATE_TYPE_INPUT_KEY_UP, ev);
return;
}
j++;
static input_handler key_handler = {
.key_down = _key_down_cb,
+ .key_up = _key_up_cb,
};
static Evas_Object *_add_win(const char *name)
return false;
}
+ if (!viewmgr_create(win)) {
+ _ERR("failed to initialize viewmgr");
+ evas_object_del(win);
+ return false;
+ }
+
+ viewmgr_add_view(view_channelinfo_get_vclass(), NULL);
+
r = tv_create();
if (r < 0) {
_ERR("Create TV failed");
return false;
}
- if (!viewmgr_create(win)) {
- _ERR("failed to initialize viewmgr");
- evas_object_del(win);
- return false;
- }
-
- viewmgr_add_view(view_channelinfo_get_vclass(), NULL);
-
ad->win = win;
tv_signal_cb_set(_tv_signal_cb, ad);
ad = data;
- tv_destroy();
+ if (ad->win) {
+ tv_destroy();
- inputmgr_remove_callback(ad->win, &key_handler);
+ inputmgr_remove_callback(ad->win, &key_handler);
- viewmgr_remove_view(VIEW_CHANNELINFO);
- viewmgr_destroy();
+ viewmgr_remove_view(VIEW_CHANNELINFO);
+ viewmgr_destroy();
- if (ad->win) {
evas_object_del(ad->win);
ad->win = NULL;
}
static void _update(void *view_data, int type, void *data)
{
struct _priv *priv;
- Evas_Event_Key_Down *ev;
if (!view_data) {
_ERR("failed to get view data");
_stop_hide_timer(priv);
break;
}
- } else if (type == UPDATE_TYPE_INPUT) {
- ev = data;
+ } else if (type == UPDATE_TYPE_INPUT_KEY_DOWN) {
+ Evas_Event_Key_Down *ev = data;
+
if (!ev) {
_ERR("failed to get ev");
return;
!strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
_set_current_layout(priv, LAYOUT_CHANNELINFO_LIST);
layoutmgr_update_layout(priv->lmgr,
- LAYOUT_CHANNELINFO_LIST, 0, ev);
+ LAYOUT_CHANNELINFO_LIST, type, ev);
+ }
+ } else if (type == UPDATE_TYPE_INPUT_KEY_UP) {
+ Evas_Event_Key_Up *ev = data;
+
+ if (!ev) {
+ _ERR("failed to get ev");
+ return;
+ }
+
+ if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
+ !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE) ||
+ !strcmp(ev->keyname, KEY_CHANNELDOWN) ||
+ !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
+ _set_current_layout(priv, LAYOUT_CHANNELINFO_LIST);
+ layoutmgr_update_layout(priv->lmgr,
+ LAYOUT_CHANNELINFO_LIST, type, ev);
}
}
}