2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
19 #include <layoutmgr.h>
21 #include <app_debug.h>
25 #include "view_channelinfo.h"
26 #include "layout_channelinfo.h"
27 #include "layout_channelinfo_list.h"
28 #include "layout_channelinfo_search.h"
32 #define STATUS_BOX_PADDING 10
41 Ecore_Timer *hide_timer;
42 const char *current_layout;
47 static int _get_program_time(char *buf, int buf_len, time_t start_time,
53 if (start_time >= end_time) {
58 localtime_r(&start_time, &tm);
59 r = strftime(buf, buf_len, "%I:%M %P -", &tm);
63 localtime_r(&end_time, &tm);
64 r = strftime(buf + r, buf_len - r, " %I:%M %P", &tm);
71 static Eina_Bool _hide_timer(void *data)
76 return ECORE_CALLBACK_CANCEL;
80 priv->hide_timer = NULL;
82 viewmgr_hide_view(VIEW_CHANNELINFO);
84 return ECORE_CALLBACK_CANCEL;
87 static void _start_hide_timer(struct _priv *priv)
90 ecore_timer_reset(priv->hide_timer);
92 priv->hide_timer = ecore_timer_add(HIDE_DUR, _hide_timer, priv);
95 static void _stop_hide_timer(struct _priv *priv)
97 if (priv->hide_timer) {
98 ecore_timer_del(priv->hide_timer);
99 priv->hide_timer = NULL;
103 static void _add_icon(Evas_Object *box, const char *file)
107 ic = elm_icon_add(box);
109 _ERR("failed to create icon");
113 elm_image_file_set(ic, file, NULL);
114 elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
115 elm_image_no_scale_set(ic, EINA_TRUE);
116 evas_object_show(ic);
118 elm_box_pack_end(box, ic);
121 static void _pack_icon_box(Evas_Object *obj,
122 const struct tv_channel_info *channel_info)
126 box = elm_box_add(obj);
128 _ERR("failed to create box");
131 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
133 elm_box_horizontal_set(box, EINA_TRUE);
134 elm_box_padding_set(box, STATUS_BOX_PADDING, 0);
135 elm_box_align_set(box, 1.0, 0.5);
136 elm_object_part_content_set(obj, PART_CHANNELINFO_STATUS, box);
138 if (channel_info->locked)
139 _add_icon(box, IMG_LOCKED_NOR);
140 if (channel_info->favorite)
141 _add_icon(box, IMG_FAVORITE_NOR);
144 static void _load_channel_text(Evas_Object *obj,
145 const struct tv_channel_info *channel_info)
149 if (channel_info->channel_minor > 0 &&
150 channel_info->channel_minor < MINOR_MAX)
151 snprintf(buf, sizeof(buf), "%lu-%lu %s",
152 channel_info->channel_major,
153 channel_info->channel_minor,
154 channel_info->channel_name);
156 snprintf(buf, sizeof(buf), "%lu %s",
157 channel_info->channel_major,
158 channel_info->channel_name);
160 elm_object_part_text_set(obj,
161 PART_CHANNELINFO_CHANNEL, buf);
163 elm_object_part_text_set(obj,
164 PART_CHANNELINFO_TITLE,
166 elm_object_part_text_set(obj,
167 PART_CHANNELINFO_TIME,
171 static void _load_program_info(Evas_Object *obj,
172 const struct tv_program_info *prog)
177 if (prog->start_time && prog->end_time) {
178 r = _get_program_time(buf, sizeof(buf),
182 elm_object_part_text_set(obj,
183 PART_CHANNELINFO_TIME, buf);
186 if (strlen(prog->prog_title) > 0)
187 elm_object_part_text_set(obj,
188 PART_CHANNELINFO_TITLE, prog->prog_title);
191 static void _tv_program_cb(Eina_List *prog_list, void *data)
194 struct tv_program_info *prog = NULL;
197 _ERR("failed to get data");
203 prog = (struct tv_program_info *) eina_list_nth(prog_list, 0);
205 _load_program_info(obj, prog);
207 _ERR("failed to get tv_program_info");
209 viewmgr_update_view(VIEW_CHANNELINFO,
210 UPDATE_TYPE_TIMER, START_HIDE_TIMER);
213 void draw_channel_info(Evas_Object *obj,
214 const struct tv_channel_info *channel_info)
216 struct tv_program_request *prog_req;
220 if (!obj || !channel_info) {
221 _ERR("Invalid argument");
226 r = tv_get_current_service_id(¤t_service);
228 current_service = -1;
230 viewmgr_update_view(VIEW_CHANNELINFO,
231 UPDATE_TYPE_TIMER, (void *)STOP_HIDE_TIMER);
233 _load_channel_text(obj, channel_info);
234 _pack_icon_box(obj, channel_info);
236 prog_req = calloc(1, sizeof(*prog_req));
237 prog_req->tv_program_cb = _tv_program_cb;
238 prog_req->user_data = obj;
240 if (channel_info->service_id == current_service)
241 r = tv_epg_get_program(channel_info->service_id, prog_req);
243 r = tv_epg_get_cache_program(channel_info->service_id,
247 viewmgr_update_view(VIEW_CHANNELINFO,
248 UPDATE_TYPE_TIMER, START_HIDE_TIMER);
251 static void _hide_current_layout(struct _priv *priv)
253 if (!priv->current_layout)
256 layoutmgr_hide_layout(priv->lmgr, priv->current_layout);
257 priv->current_layout = NULL;
260 static void _set_current_layout(struct _priv *priv, const char *layout_id)
262 if (priv->current_layout && layout_id &&
263 !strcmp(priv->current_layout, layout_id))
266 if (priv->current_layout)
267 layoutmgr_hide_layout(priv->lmgr, priv->current_layout);
269 layoutmgr_show_layout(priv->lmgr, layout_id);
270 priv->current_layout = layout_id;
273 static Evas_Object *_create(Evas_Object *win, void *data)
278 _ERR("failed to get win object");
282 priv = calloc(1, sizeof(*priv));
284 _ERR("failed to allocate priv");
288 priv->base = elm_layout_add(win);
290 _ERR("failed to create base object");
294 elm_layout_file_set(priv->base, EDJEFILE, GRP_VIEW_CHANNELINFO);
296 evas_object_size_hint_weight_set(priv->base,
297 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
298 elm_win_resize_object_add(win, priv->base);
300 priv->lmgr = layoutmgr_create(priv->base);
301 layoutmgr_add_layout(priv->lmgr, layout_channelinfo_get_lclass(), NULL);
302 layoutmgr_add_layout(priv->lmgr,
303 layout_channelinfo_list_get_lclass(), NULL);
304 layoutmgr_add_layout(priv->lmgr,
305 layout_channelinfo_search_get_lclass(), NULL);
307 viewmgr_set_view_data(VIEW_CHANNELINFO, priv);
312 static void _show(void *view_data)
317 _ERR("failed to get view data");
323 evas_object_show(priv->base);
326 static void _hide(void *view_data)
331 _ERR("failed to get view data");
337 _hide_current_layout(priv);
339 evas_object_hide(priv->base);
342 static void _destroy(void *view_data)
347 _ERR("failed to get view data");
353 layoutmgr_remove_layout(priv->lmgr, LAYOUT_CHANNELINFO);
354 layoutmgr_remove_layout(priv->lmgr, LAYOUT_CHANNELINFO_LIST);
355 layoutmgr_remove_layout(priv->lmgr, LAYOUT_CHANNELINFO_SEARCH);
356 layoutmgr_destroy(priv->lmgr);
358 evas_object_del(priv->base);
363 static void _update(void *view_data, int type, void *data)
368 _ERR("failed to get view data");
374 if (type == UPDATE_TYPE_TIMER) {
375 switch ((int) data) {
376 case START_HIDE_TIMER:
377 _start_hide_timer(priv);
379 case STOP_HIDE_TIMER:
380 _stop_hide_timer(priv);
383 } else if (type == UPDATE_TYPE_INPUT_KEY_DOWN) {
384 Evas_Event_Key_Down *ev = data;
387 _ERR("failed to get ev");
391 if (!strcmp(ev->keyname, KEY_ENTER) ||
392 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
393 if (!priv->current_layout)
394 _set_current_layout(priv, LAYOUT_CHANNELINFO);
396 _set_current_layout(priv,
397 LAYOUT_CHANNELINFO_SEARCH);
398 } else if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
399 !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE) ||
400 !strcmp(ev->keyname, KEY_CHANNELDOWN) ||
401 !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
402 _set_current_layout(priv, LAYOUT_CHANNELINFO_LIST);
403 layoutmgr_update_layout(priv->lmgr,
404 LAYOUT_CHANNELINFO_LIST, type, ev);
406 } else if (type == UPDATE_TYPE_INPUT_KEY_UP) {
407 Evas_Event_Key_Up *ev = data;
410 _ERR("failed to get ev");
414 if (!strcmp(ev->keyname, KEY_CHANNELUP) ||
415 !strcmp(ev->keyname, KEY_CHANNELUP_REMOTE) ||
416 !strcmp(ev->keyname, KEY_CHANNELDOWN) ||
417 !strcmp(ev->keyname, KEY_CHANNELDOWN_REMOTE)) {
418 _set_current_layout(priv, LAYOUT_CHANNELINFO_LIST);
419 layoutmgr_update_layout(priv->lmgr,
420 LAYOUT_CHANNELINFO_LIST, type, ev);
425 static view_class vclass = {
426 .view_id = VIEW_CHANNELINFO,
434 view_class *view_channelinfo_get_vclass(void)