/* * 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 #include #include #include #include #include "define.h" #include "util/util.h" #define STR_GRID_CONTENT "grid_content" #define VIDEO_COPYRIGHT "Unknown" /* * NOTE: Workaround * we assumed that if video content have the copyright then it's a movie. */ bool util_check_movie_type(const char *str) { if (!str) return false; return strcmp(str, VIDEO_COPYRIGHT); } bool util_launch_request(const char *appid, const char *key, const char *value) { 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 false; } 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 false; } if (key && value) { r = app_control_add_extra_data(app_ctrl, key, value); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to add extra data"); app_control_destroy(app_ctrl); return false; } } r = app_control_set_app_id(app_ctrl, appid); if (r != APP_CONTROL_ERROR_NONE) { _ERR("failed to set app control app id"); app_control_destroy(app_ctrl); return false; } 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 false; } app_control_destroy(app_ctrl); return true; } Evas_Object *util_add_button(Evas_Object *base, const char *style, const char *text) { Evas_Object *btn; if (!base) return NULL; btn = elm_button_add(base); if (!btn) { _ERR("failed to create button object"); return NULL; } if (style) elm_object_style_set(btn, style); if (text) elm_object_text_set(btn, text); return btn; } Evas_Object *util_add_box(Evas_Object *base, Eina_Bool horizontal) { Evas_Object *box; if (!base) return NULL; box = elm_box_add(base); if (!box) { _ERR("failed to create box object"); return NULL; } evas_object_size_hint_align_set(box, 0.0, EVAS_HINT_FILL); evas_object_size_hint_weight_set(box, 0.0, EVAS_HINT_EXPAND); elm_box_horizontal_set(box, horizontal); return box; } Evas_Object *util_add_gengrid(Evas_Object *base, int item_size_x, int item_size_y, Eina_Bool horizontal) { Evas_Object *grid; if (!base) return NULL; grid = elm_gengrid_add(base); if (!grid) { _ERR("failed to create gengrid object"); return NULL; } evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS); elm_gengrid_multi_select_set(grid, EINA_FALSE); elm_gengrid_horizontal_set(grid, horizontal); elm_gengrid_align_set(grid, 0.0, 0.0); elm_gengrid_item_size_set(grid, ELM_SCALE_SIZE(item_size_x), ELM_SCALE_SIZE(item_size_y)); elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); return grid; } Evas_Object *util_add_genlist(Evas_Object *base) { Evas_Object *list; list = elm_genlist_add(base); if (!list) { _ERR("failed to adding genlist"); return NULL; } evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_genlist_homogeneous_set(list, EINA_TRUE); elm_genlist_select_mode_set(list, ELM_OBJECT_SELECT_MODE_ALWAYS); elm_genlist_multi_select_set(list, EINA_FALSE); elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); return list; } Evas_Object *util_add_image(Evas_Object *base, const char *file) { Evas_Object *image; if (!base) return NULL; image = elm_image_add(base); if (!image) { _ERR("failed to create image object"); return NULL; } if (file) { elm_image_file_set(image, file, NULL); elm_image_aspect_fixed_set(image, EINA_FALSE); } return image; } static void _notify_timeout(void *data, Evas_Object *obj, void *ei) { if (!obj) return; evas_object_del(obj); } Evas_Object *util_add_notify(Evas_Object *base, const char *notify_style, const char *label_style, const char *text, double time) { Evas_Object *notify, *label; if (!base) return NULL; notify = elm_notify_add(base); if (!notify) { _ERR("failed to create notify object"); return NULL; } if (notify_style) elm_object_style_set(notify, notify_style); evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_notify_align_set(notify, 0.0, 1.0); elm_notify_timeout_set(notify, time); evas_object_smart_callback_add(notify, SIG_TIMEOUT, _notify_timeout, NULL); label = elm_label_add(notify); if (!label) { _ERR("failed to create label object"); evas_object_del(notify); return NULL; } if (label_style) elm_object_style_set(label, label_style); elm_object_content_set(notify, label); if (text) elm_object_text_set(label, text); evas_object_show(notify); return notify; } Evas_Object *util_add_scroller(Evas_Object *base) { Evas_Object *scr; if (!base) return NULL; scr = elm_scroller_add(base); if (!scr) { _ERR("failed to create scroller object"); return NULL; } elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); return scr; } Evas_Object *util_add_table(Evas_Object *base, int padding_x, int padding_y) { Evas_Object *table; if (!base) return NULL; table = elm_table_add(base); if (!table) { _ERR("failed to create table object"); return NULL; } elm_table_padding_set(table, padding_x, padding_y); return table; } void util_time_string(char *str, int size, unsigned int ms, bool full) { int sec; int h, m, s; sec = ms / 1000; h = sec / 3600; m = (sec % 3600) / 60; s = sec % 60; if (full) { snprintf(str, size, "%02d:%02d:%02d", h, m, s); } else { if (h) snprintf(str, size, "%d:%02d:%02d", h, m, s); else snprintf(str, size, "%d:%02d", m, s); } } void util_up_string(char *str) { while (*str) { *str = toupper(*str); str++; } } int util_get_media_index(Eina_List *list, void *data) { Eina_List *l; int index; void *obj; index = 0; EINA_LIST_FOREACH(list, l, obj) { if (data == obj) return index; index++; } return -1; } int util_get_media_index_from_id(Eina_List *list, const char *id) { Eina_List *l; app_media *am; app_media_info *info; int index; index = 0; EINA_LIST_FOREACH(list, l, am) { info = app_media_get_info(am); if (!info) continue; if (!strcmp(id, info->media_id)) return index; index++; } return -1; } app_media *util_find_media_info(Eina_List *list, const char *id) { Eina_List *l; app_media *am; app_media_info *info; EINA_LIST_FOREACH(list, l, am) { info = app_media_get_info(am); if (!info) continue; if (!strcmp(info->media_id, id)) return am; } return NULL; } void util_add_to_recent(Eina_List *list, int index) { app_media *am; app_media_info *mi; am = eina_list_nth(list, index); if (!am) { _ERR("failed to get app_media"); return; } mi = app_media_get_info(am); if (!mi) { _ERR("failed to getting media info"); return; } app_contents_recent_add(CONTENTS_MEDIA, mi->media_id); app_media_update(am); } void util_create_thumbnail(Evas_Object *grid, app_media *am, void (*completed_cb)(media_content_error_e, const char *, void *)) { Eina_List *list; Elm_Object_Item *it; int index; int r; list = evas_object_data_get(grid, STR_GRID_CONTENT); index = util_get_media_index(list, am); it = elm_gengrid_first_item_get(grid); while (index--) it = elm_gengrid_item_next_get(it); r = media_info_create_thumbnail(app_media_get_media_handle(am), completed_cb, it); if (r != MEDIA_CONTENT_ERROR_NONE) _ERR("failed to create thumbnail"); }