/* * Copyright (c) 2014 Samsung Electronics Co., Ltd. * * 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 #include #include #include #include #include "define.h" #include "view.h" #define BUF_MAX 128 #define TOAST_TIMEOUT 5.0 #define STYLE_TOAST "toast" Evas_Object *util_add_layout(Evas_Object *parent, const char *group) { Evas_Object *ly; if (!parent) { _ERR("failed to get parent"); return NULL; } ly = elm_layout_add(parent); if (!ly) { _ERR("failed to create layout"); return NULL; } elm_layout_file_set(ly, EDJEFILE, group); evas_object_show(ly); return ly; } Evas_Object *util_add_box(Evas_Object *parent, bool horizon) { Evas_Object *box; if (!parent) { _ERR("failed to get parent"); return NULL; } box = elm_box_add(parent); if (!box) { _ERR("failed to create box"); return NULL; } evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_object_content_set(parent, box); if (horizon) elm_box_horizontal_set(box, EINA_TRUE); else elm_box_horizontal_set(box, EINA_FALSE); evas_object_show(box); return box; } Evas_Object *util_add_scroller(Evas_Object *parent, const char *part) { Evas_Object *scroll; if (!parent) { _ERR("failed to get parent"); return NULL; } scroll = elm_scroller_add(parent); if (!scroll) { _ERR("failed to create scroll"); return NULL; } evas_object_size_hint_weight_set(scroll, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_scroller_policy_set(scroll, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); elm_object_part_content_set(parent, part, scroll); evas_object_show(scroll); return scroll; } Evas_Object *util_add_icon(Evas_Object *parent, const char *file, const char *part) { Evas_Object *ic; if (!parent) { _ERR("failed to get parent"); return NULL; } ic = elm_icon_add(parent); if (!ic) { _ERR("failed to create icon"); return NULL; } if (file) elm_image_file_set(ic, file, NULL); if (part) elm_object_part_content_set(parent, part, ic); elm_image_resizable_set(ic, EINA_FALSE, EINA_TRUE); evas_object_show(ic); return ic; } Evas_Object *util_add_button(Evas_Object *parent, const char *part, const char *text, const char *style) { Evas_Object *btn; if (!parent) { _ERR("Invalid argument."); return NULL; } btn = elm_button_add(parent); if (!btn) { _ERR("elm_button_add failed."); return NULL; } if (part) elm_object_part_content_set(parent, part, btn); if (text) elm_object_text_set(btn, text); if (style) elm_object_style_set(btn, style); evas_object_show(btn); return btn; } static void _notify_timeout_cb(void *data, Evas_Object *obj, void *ei) { if (!obj) return; evas_object_del(obj); } Evas_Object *util_add_toast(Evas_Object *parent, char *text) { Evas_Object *toast, *content; if (!parent) { _ERR("Invalid argument."); return NULL; } toast = elm_notify_add(parent); if (!toast) { _ERR("elm_popup_add failed"); return NULL; } elm_object_style_set(toast, STYLE_TOAST); elm_notify_align_set(toast, 0.0, 1.0); elm_notify_timeout_set(toast, TOAST_TIMEOUT); evas_object_smart_callback_add(toast, SIGNAL_TIMEOUT, _notify_timeout_cb, NULL); content = elm_label_add(toast); if (!content) { _ERR("elm_label_add failed"); evas_object_del(toast); return NULL; } elm_object_text_set(content, text); elm_object_style_set(content, STYLE_TOAST); elm_object_content_set(toast, content); evas_object_show(content); evas_object_show(toast); return toast; } static int _get_program_time(char *buf, int buf_len, time_t start_time, time_t end_time) { struct tm tm; int r; if (start_time >= end_time) { _ERR("invalid time"); return -1; } localtime_r(&start_time, &tm); r = strftime(buf, buf_len, "%I:%M %P -", &tm); if (r <= 0) return -1; localtime_r(&end_time, &tm); r = strftime(buf + r, buf_len - r, " %I:%M %P", &tm); if (r <= 0) return -1; return 0; } static void _set_icon_box(Evas_Object *obj, const struct tv_channel_info *channel_info) { elm_object_signal_emit(obj, SIGNAL_RESET, SOURCE_PROGRAM); if (channel_info->locked) elm_object_signal_emit(obj, SIGNAL_LOCKED, SOURCE_PROGRAM); if (channel_info->favorite) elm_object_signal_emit(obj, SIGNAL_FAVORITE, SOURCE_PROGRAM); } static void _load_channel_text(Evas_Object *obj, const struct tv_channel_info *channel_info) { char buf[BUF_MAX]; 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_part_text_set(obj, PART_CHANNELINFO_CHANNEL, buf); elm_object_part_text_set(obj, PART_CHANNELINFO_TITLE, STR_NOTITLE); elm_object_part_text_set(obj, PART_CHANNELINFO_TIME, STR_NOTIME); } static void _load_program_info(Evas_Object *obj, const struct tv_program_info *prog) { char buf[BUF_MAX]; int r, service_id; service_id = (int) evas_object_data_get(obj, KEY_SVCID); if (service_id != prog->service_id) return; if (prog->start_time && prog->end_time) { r = _get_program_time(buf, sizeof(buf), prog->start_time, prog->end_time); if (!r) elm_object_part_text_set(obj, PART_CHANNELINFO_TIME, buf); } if (strlen(prog->prog_title) > 0) elm_object_part_text_set(obj, PART_CHANNELINFO_TITLE, prog->prog_title); } static void _tv_program_cb(Eina_List *prog_list, void *data) { int op; Evas_Object *obj; struct tv_program_info *prog = NULL; if (!data) { _ERR("failed to get data"); return; } obj = data; prog = (struct tv_program_info *) eina_list_nth(prog_list, 0); if (prog) _load_program_info(obj, prog); else _ERR("failed to get tv_program_info"); if (viewmgr_get_view_state(VIEW_CHANNELINFO) == VIEW_STATE_VISIBLE) { op = START_HIDE_TIMER; viewmgr_update_view(VIEW_CHANNELINFO, UPDATE_TYPE_TIMER, &op); } } void util_draw_channel_info(Evas_Object *obj, const struct tv_channel_info *channel_info) { struct tv_program_request *prog_req; int r, op; int current_service; if (!obj || !channel_info) { _ERR("Invalid argument"); return; } r = tv_get_current_service_id(¤t_service); if (r < 0) current_service = -1; if (viewmgr_get_view_state(VIEW_CHANNELINFO) == VIEW_STATE_VISIBLE) { op = STOP_HIDE_TIMER; viewmgr_update_view(VIEW_CHANNELINFO, UPDATE_TYPE_TIMER, &op); } _load_channel_text(obj, channel_info); _set_icon_box(obj, channel_info); evas_object_data_set(obj, KEY_SVCID, (void *)channel_info->service_id); prog_req = calloc(1, sizeof(*prog_req)); if (!prog_req) goto err; prog_req->tv_program_cb = _tv_program_cb; prog_req->user_data = obj; r = tv_epg_get_cache_program(channel_info->service_id, prog_req); if (r < 0) free(prog_req); if (channel_info->service_id == current_service) { prog_req = calloc(1, sizeof(*prog_req)); if (!prog_req) goto err; prog_req->tv_program_cb = _tv_program_cb; prog_req->user_data = obj; r = tv_epg_get_program(channel_info->service_id, prog_req); if (r < 0) free(prog_req); } err: if (r < 0 && viewmgr_get_view_state(VIEW_CHANNELINFO) == VIEW_STATE_VISIBLE) { op = START_HIDE_TIMER; viewmgr_update_view(VIEW_CHANNELINFO, UPDATE_TYPE_TIMER, &op); } } void util_launch_home(void) { app_control_h app_ctrl; int r; r = app_control_create(&app_ctrl); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to create app control handle"); return; } r = app_control_set_operation(app_ctrl, APP_CONTROL_OPERATION_DEFAULT); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to set app control operation"); app_control_destroy(app_ctrl); return; } r = app_control_set_app_id(app_ctrl, APP_ID_HOME); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to set app control app id"); app_control_destroy(app_ctrl); return; } r = app_control_send_launch_request(app_ctrl, NULL, NULL); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to send app control launch request"); app_control_destroy(app_ctrl); return; } app_control_destroy(app_ctrl); }