summaryrefslogtreecommitdiff
path: root/src/view_channelnumber.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/view_channelnumber.c')
-rw-r--r--src/view_channelnumber.c437
1 files changed, 0 insertions, 437 deletions
diff --git a/src/view_channelnumber.c b/src/view_channelnumber.c
deleted file mode 100644
index 9e395ac..0000000
--- a/src/view_channelnumber.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
- * 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 <inputmgr.h>
-#include <app_debug.h>
-
-#include "define.h"
-#include "util.h"
-#include "tv.h"
-#include "view.h"
-
-#define HIDE_DUR 3.0
-#define BUF_MAX 128
-#define INPUT_MAX 4
-#define NUMBER_MAX 2
-
-struct _priv {
- Evas_Object *base;
- Evas_Object *list;
- Ecore_Timer *hide_timer;
-
- int major;
- int minor;
- char number[INPUT_MAX+1];
-};
-
-static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
- Evas_Event_Key_Down *ev)
-{
- if (!strcmp(ev->keyname, KEY_BACK) ||
- !strcmp(ev->keyname, KEY_ESC))
- viewmgr_hide_view(VIEW_CHANNELNUMBER);
-}
-
-static input_handler key_handler = {
- .key_down = _key_down_cb,
-};
-
-static void _stop_hide_timer(struct _priv *priv)
-{
- if (priv->hide_timer) {
- ecore_timer_del(priv->hide_timer);
- priv->hide_timer = NULL;
- }
-}
-
-static Eina_Bool _done_input(void *data)
-{
- struct _priv *priv;
- int r;
-
- if (!data)
- return ECORE_CALLBACK_CANCEL;
-
- priv = data;
-
- r = tv_channel_direct_tune(priv->major, priv->minor);
- if (r < 0)
- _ERR("invalid channel");
-
- viewmgr_hide_view(VIEW_CHANNELNUMBER);
-
- return ECORE_CALLBACK_CANCEL;
-}
-
-static void _start_hide_timer(struct _priv *priv)
-{
- if (priv->hide_timer)
- ecore_timer_reset(priv->hide_timer);
- else
- priv->hide_timer = ecore_timer_add(HIDE_DUR, _done_input, priv);
-}
-
-static void _tune_channel(void *data)
-{
- int service_id;
- int r;
-
- if (!data) {
- _ERR("failed to get data");
- return;
- }
-
- service_id = (int) data;
- if (service_id < 0) {
- _ERR("failed to get service id");
- return;
- }
-
- r = tv_channel_tune_with_service_id(service_id);
- if (r < 0)
- _ERR("failed to tune with service id");
-
- viewmgr_hide_view(VIEW_CHANNELNUMBER);
-}
-
-static void _channel_key_down_cb(int id, void *data, Evas *e, Evas_Object *obj,
- Evas_Event_Key_Down *ev)
-{
- if (!strcmp(ev->keyname, KEY_ENTER)) {
- ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
-
- _tune_channel(data);
- }
-}
-
-static void _channel_mouse_down_cb(int id, void *data, Evas *e,
- Evas_Object *obj, Evas_Event_Mouse_Down *ev)
-{
- _tune_channel(data);
-}
-
-static void _channel_focused_cb(int id, void *data,
- Evas_Object *obj, Elm_Object_Item *it)
-{
- viewmgr_update_view(VIEW_CHANNELNUMBER,
- UPDATE_TYPE_TIMER, 0);
-}
-
-static input_handler channel_handler = {
- .key_down = _channel_key_down_cb,
- .mouse_down = _channel_mouse_down_cb,
- .focused = _channel_focused_cb,
-};
-
-static void _update_channel_list(struct _priv *priv)
-{
- Evas_Object *ly, *first;
- Eina_List *channel_list, *l;
- const struct tv_channel_info *channel_info;
- char buf[BUF_MAX];
-
- channel_list = tv_channel_search_by_number(priv->major, priv->minor);
-
- elm_box_clear(priv->list);
-
- if (!channel_list) {
- evas_object_hide(priv->list);
- return;
- }
-
- evas_object_show(priv->list);
-
- first = NULL;
- ly = NULL;
- EINA_LIST_FOREACH(channel_list, l, channel_info) {
- ly = util_add_layout(priv->list, GRP_CHANNELNUMBER_LIST_ITEM);
- if (!ly) {
- _ERR("failed to create layout");
- return;
- }
-
- elm_object_focus_allow_set(ly, EINA_TRUE);
-
- if (channel_info->channel_minor > 0 &&
- channel_info->channel_minor < MINOR_MAX)
- snprintf(buf, sizeof(buf), "%lu-%lu %s",
- channel_info->channel_major,
- channel_info->channel_minor,
- channel_info->channel_name);
- else
- snprintf(buf, sizeof(buf), "%lu %s",
- channel_info->channel_major,
- channel_info->channel_name);
-
- elm_object_text_set(ly, buf);
-
- inputmgr_add_callback(ly, 0, &channel_handler,
- (void *) channel_info->service_id);
-
- elm_box_pack_end(priv->list, ly);
-
- if (!first) {
- first = ly;
- elm_object_focus_set(ly, EINA_TRUE);
- elm_object_signal_emit(ly, SIGNAL_FIRST, "");
- }
- }
-
- if (first && ly) {
- elm_object_focus_next_object_set(first, ly, ELM_FOCUS_UP);
- elm_object_focus_next_object_set(ly, first, ELM_FOCUS_DOWN);
- elm_object_signal_emit(ly, SIGNAL_LAST, "");
- }
-
- if (channel_list)
- tv_channel_del_list(channel_list);
-}
-
-static void _update_number_info(struct _priv *priv)
-{
- char buf[BUF_MAX] = "\0";
-
- if (strlen(priv->number) > NUMBER_MAX) {
- strncpy(buf, priv->number, NUMBER_MAX);
- strncat(buf, "-", 1);
- strncat(buf, priv->number + NUMBER_MAX, NUMBER_MAX);
- elm_object_part_text_set(priv->base,
- PART_CHANNELNUMBER_NUMBER, buf);
- } else {
- elm_object_part_text_set(priv->base,
- PART_CHANNELNUMBER_NUMBER, priv->number);
- }
-
- _update_channel_list(priv);
-}
-
-static int _get_number(const char *keyname)
-{
- static const char * const keys[] = {
- KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
- KEY_5, KEY_6, KEY_7, KEY_8, KEY_9
- };
-
- int i;
-
- if (!keyname) {
- _ERR("failed to get keyname");
- return -1;
- }
-
- for (i = 0; i < sizeof(keys) / sizeof(*keys); i++) {
- if (!strcmp(keyname, keys[i]))
- return i;
- }
-
- return -1;
-}
-
-static void _number_reset(struct _priv *priv)
-{
- memset(priv->number, '\0', sizeof(char) * INPUT_MAX + 1);
- priv->major = 0;
- priv->minor = 0;
-
- elm_box_clear(priv->list);
-}
-
-static void _number_tuning(struct _priv *priv, const char *keyname)
-{
- char buf[BUF_MAX] = "\0";
-
- if (!keyname) {
- _ERR("failed to get keyname");
- return;
- }
-
- strncat(priv->number, keyname, 1);
- strncpy(buf, priv->number, INPUT_MAX);
-
- priv->minor = atoi(buf + NUMBER_MAX);
- buf[NUMBER_MAX] = '\0';
- priv->major = atoi(buf);
-
- _update_number_info(priv);
-
- if (strlen(priv->number) >= INPUT_MAX)
- _done_input(priv);
-}
-
-static Evas_Object *_create(Evas_Object *win, void *data)
-{
- struct _priv *priv;
- Evas_Object *scroll = NULL;
-
- if (!win) {
- _ERR("failed to get win object");
- return NULL;
- }
-
- priv = calloc(1, sizeof(*priv));
- if (!priv) {
- _ERR("failed to allocate priv");
- return NULL;
- }
-
- priv->base = elm_layout_add(win);
- if (!priv->base) {
- _ERR("failed to create base object");
- goto error;
- }
- elm_layout_file_set(priv->base, EDJEFILE, GRP_VIEW_CHANNELNUMBER);
-
- evas_object_size_hint_weight_set(priv->base,
- EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(win, priv->base);
- elm_object_focus_allow_set(priv->base, EINA_TRUE);
-
- scroll = util_add_scroller(priv->base, PART_CHANNELNUMBER_LIST);
- if (!scroll) {
- _ERR("failed to create scroll");
- goto error;
- }
-
- priv->list = util_add_box(scroll, false);
- if (!priv->list) {
- _ERR("failed to create box");
- goto error;
- }
- elm_box_align_set(priv->list, 0.5, 0.0);
-
- viewmgr_set_view_data(VIEW_CHANNELNUMBER, priv);
-
- inputmgr_add_callback(priv->base, 0, &key_handler, priv);
-
- return priv->base;
-
-error:
- _ERR("failed to create view");
-
- if (priv->list)
- evas_object_del(priv->list);
- if (scroll)
- evas_object_del(scroll);
- if (priv->base)
- evas_object_del(priv->base);
-
- free(priv);
-
- return NULL;
-}
-
-static void _show(void *view_data)
-{
- struct _priv *priv;
-
- if (!view_data) {
- _ERR("failed to get view data");
- return;
- }
-
- priv = view_data;
-
- _start_hide_timer(priv);
-
- evas_object_show(priv->base);
-
- viewmgr_hide_view(VIEW_CHANNELINFO);
- elm_object_focus_set(priv->base, EINA_TRUE);
-}
-
-static void _hide(void *view_data)
-{
- struct _priv *priv;
-
- if (!view_data) {
- _ERR("failed to get view data");
- return;
- }
-
- priv = view_data;
-
- _stop_hide_timer(priv);
- _number_reset(priv);
-
- evas_object_hide(priv->base);
-}
-
-static void _destroy(void *view_data)
-{
- struct _priv *priv;
-
- if (!view_data) {
- _ERR("failed to get view data");
- return;
- }
-
- priv = view_data;
-
- evas_object_del(priv->base);
-
- free(priv);
-}
-
-static void _update(void *view_data, int type, void *data)
-{
- struct _priv *priv;
-
- if (!view_data) {
- _ERR("failed to get view data");
- return;
- }
-
- priv = view_data;
-
- if (type == UPDATE_TYPE_TIMER) {
- _start_hide_timer(priv);
- } else if (type == UPDATE_TYPE_INPUT_KEY_DOWN) {
- Evas_Event_Key_Down *ev = data;
-
- if (!ev) {
- _ERR("failed to get ev");
- return;
- }
-
- viewmgr_show_view(VIEW_CHANNELNUMBER);
-
- if (_get_number(ev->keyname) != -1)
- _number_tuning(priv, ev->keyname);
- } else if (type == UPDATE_TYPE_INPUT_KEY_UP) {
- Evas_Event_Key_Up *ev = data;
-
- if (!ev) {
- _ERR("failed to get ev");
- return;
- }
- }
-}
-
-static view_class vclass = {
- .view_id = VIEW_CHANNELNUMBER,
- .create = _create,
- .show = _show,
- .hide = _hide,
- .destroy = _destroy,
- .update = _update
-};
-
-view_class *view_channelnumber_get_vclass(void)
-{
- return &vclass;
-}