/* * Copyright (c) 2010 Samsung Electronics, Inc. * All rights reserved. * * This software is a confidential and proprietary information * of Samsung Electronics, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Samsung Electronics. */ /* * util.c * * Created on: Nov 21, 2013 * Author: min-hoyun */ #include #include #include #include "util.h" #include #define CALLBACK_TIMER 0.5 #define RES_BUF_SIZE 20 typedef struct { back_btn_cb_ptr cb; void *data; Evas_Object *obj; Evas_Object *genlist_obj; char *cur_genlist_name; } back_button_cb_data; static Ecore_Timer *running_timer = NULL; static Eina_List *back_button_cb_stack = NULL; static bool running = false; void back_button_cb_push(back_btn_cb_ptr cb, void *data, Evas_Object *obj, Evas_Object *genlist_obj, char *genlist_name) { back_button_cb_data *cb_data = NULL; cb_data = malloc(sizeof(*cb_data)); if (!cb_data) return; cb_data->cb = cb; cb_data->data = data; cb_data->obj = obj; cb_data->genlist_obj = genlist_obj; if (strlen(genlist_name)) cb_data->cur_genlist_name = strdup(genlist_name); else cb_data->cur_genlist_name = NULL; back_button_cb_stack = eina_list_prepend(back_button_cb_stack, cb_data); DBG("####### back btn push!! %s", (cb_data->cur_genlist_name) ? cb_data->cur_genlist_name : "NO name"); } void clear_back_button_list() { Eina_List *l; Eina_List *n; back_button_cb_data *item = NULL; EINA_LIST_FOREACH_SAFE(back_button_cb_stack, l, n, item) { if (item) { back_button_cb_stack = eina_list_remove(back_button_cb_stack, item); FREE(item->cur_genlist_name); FREE(item); } } back_button_cb_stack = NULL; } void back_button_cb_pop(void) { back_button_cb_data *cb_data = NULL; if (back_button_cb_stack) cb_data = eina_list_data_get(back_button_cb_stack); else { DBG("####### back btn pop cb - NULL!!!!!! EMPTY"); return; } if (!cb_data) { DBG("####### back btn pop cb - cb_data NULL!!!!!! EMPTY"); return; } if (cb_data->genlist_obj) { DBG("####### back btn pop cb - genlist ptr is %p", cb_data->genlist_obj); if (cb_data->cur_genlist_name) DBG("####### back btn pop cb - genlist name is %s", cb_data->cur_genlist_name); eext_rotary_object_event_activated_set(cb_data->genlist_obj, EINA_TRUE); } FREE(cb_data->cur_genlist_name); back_button_cb_stack = eina_list_remove(back_button_cb_stack, cb_data); FREE(cb_data); } void back_button_cb_call(void) { back_button_cb_data *cb_data = NULL; cb_data = eina_list_data_get(back_button_cb_stack); if (cb_data && cb_data->cb) { cb_data->cb(cb_data->data, cb_data->obj, NULL); } else { ERR("No callback data!"); } } void back_key_popup_cb(void *data, Evas_Object *obj, void *event_info) { appdata *ad = (appdata *)data; if (ad && ad->popup) { evas_object_del(ad->popup); ad->popup = NULL; } back_button_cb_pop(); } void back_key_generic_cb(void *data, Evas_Object *obj, void *event_info) { appdata *ad = (appdata *)data; if (ad) { elm_naviframe_item_pop(ad->nf); back_button_cb_pop(); } else { ERR("data ptr is NULL"); } } char *setting_gettext(const char *s) { /* fisrt find in app pg */ if (s == NULL) { return "NULL"; } char *p = dgettext(SETTING_PACKAGE, s); if (!strcmp(s, p)) { /* not found */ /* find in system pkg */ p = dgettext(SYSTEM_PACKAGE, s); } return p; } char *replace(char *str, char *orig, char *repl) { static char buffer[124]; char *ch; int len; if (!(ch = strstr(str, orig))) { return str; } len = ch - str; if (len > 123) len = 123; strncpy(buffer, str, len); buffer[len] = 0; snprintf(buffer + len, 123 - len, "%s%s", repl, ch + strlen(orig)); return buffer; } void setting_popup_back_cb(void *data, Evas_Object *obj, void *event_info) { appdata *ad = (appdata *)data; if (ad == NULL) { return; } if (ad->popup) { evas_object_del(ad->popup); ad->popup = NULL; } } int is_connected_GM() { int enable = 0; vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &enable); return enable; } bool colorstr_to_decimal(char *color, int *R, int *G, int *B) { DBG("_colorstr_to_decimal"); if (color == NULL) return false; char *ptr; long value; value = strtol(color, &ptr, 16); *R = (value >> 16) & 0xFF; *G = (value >> 8) & 0xFF; *B = value & 0xFF; return true; } char *_get_strnum_from_icu(int number) { char *locale_tmp = vconf_get_str(VCONFKEY_REGIONFORMAT); char locale[32] = {0,}; char *p = NULL; int ret = 0; if (locale_tmp && strlen(locale_tmp) < 32) strncpy(locale, locale_tmp, sizeof(locale)-1); if (locale[0] != '\0') { p = strstr(locale, ".UTF-8"); if (p) { *p = 0; } } char *ret_str = NULL; i18n_error_code_e status = I18N_ERROR_NONE; i18n_unumber_format_h num_fmt; i18n_uchar result[RES_BUF_SIZE+1] = { 0, }; char res[RES_BUF_SIZE+1] = { 0, }; int32_t len = (int32_t)(sizeof(result) / sizeof((result)[0])); ret = i18n_unumber_create(I18N_UNUMBER_DEFAULT, NULL, -1, locale, NULL, &num_fmt); if (ret != I18N_ERROR_NONE) { ERR("INVALID_PARAMETER!!"); FREE(locale_tmp); return NULL; } i18n_unumber_format(num_fmt, number, result, len, NULL, &status); i18n_ustring_copy_au_n(res, result, RES_BUF_SIZE); i18n_unumber_destroy(num_fmt); ret_str = strdup(res); FREE(locale_tmp); return ret_str; } bool is_file_exist(char *file_path) { int fd = 0; if (!file_path) { DBG("Setting - file path is wrong!!"); return false; } fd = open(file_path, O_RDONLY); if (fd == -1) { DBG("Setting - file(%s) do not exist!!", file_path); return false; } if (fd) close(fd); DBG("Setting - file exist!!"); return true; } void connect_to_wheel_with_genlist(Evas_Object *genlist, appdata *ad) { Evas_Object *circle_genlist = eext_circle_object_genlist_add(genlist, ad->circle_surface); eext_circle_object_genlist_scroller_policy_set(circle_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE); } void _hw_back_key_cb(void *data, Evas_Object *obj, void *event_info) { back_button_cb_call(); return; } static char * _accessible_title_name_cb(void *data, Evas_Object *obj) { char buf[255]; Evas_Object *layout = data; snprintf(buf, sizeof(buf), "%s, title", elm_object_part_text_get(layout, "elm.text.title")); return strdup(buf); } static char * _accessible_body_name_cb(void *data, Evas_Object *obj) { Evas_Object *layout = data; return strdup(elm_object_part_text_get(layout, "elm.text")); } void _screen_reader_information_set(Evas_Object *obj) { Evas_Object *to, *ao; to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(obj), "elm.text.title"); if (to) { ao = elm_access_object_register(to, obj); elm_atspi_accessible_name_cb_set(ao, _accessible_title_name_cb, obj); elm_atspi_accessible_reading_info_type_set(ao, ELM_ACCESSIBLE_READING_INFO_TYPE_NAME); } to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(obj), "elm.text"); if (to) { ao = elm_access_object_register(to, obj); elm_atspi_accessible_name_cb_set(ao, _accessible_body_name_cb, obj); elm_atspi_accessible_reading_info_type_set(ao, ELM_ACCESSIBLE_READING_INFO_TYPE_NAME); } } static int is_supported(const char *path) { bool res; if (system_info_get_platform_bool(path, &res) != SYSTEM_INFO_ERROR_NONE) { DBG("Fail to get TELEPHONY INFO"); return -1; } return res; } int is_telephony_enable(void) { static bool first = true; static int ret = 0; if (first) { ret = is_supported(SETTING_TELEPHONY_PATH); first = false; DBG("TELEPHONY = %d", ret); } if (ret > 1 || ret < 0) { DBG("Cannot decide telephony type!"); ret = 0; } return ret; } static Eina_Bool _app_ctrl_timer_cb(void *data) { DBG("reset flags"); running = false; running_timer = NULL; return ECORE_CALLBACK_CANCEL; } bool check_to_run_submenu(void *event_info) { if (running) { elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE); return false; } return true; } void set_running(bool val) { running = val; } bool get_running() { return running; } void clear_running_timer() { if (running_timer) { ecore_timer_del(running_timer); running_timer = NULL; } } void launch_extra_app(extra_app_data data) { if (running) { DBG("running timer is working"); return; } app_control_h service; app_control_create(&service); app_control_set_app_id(service, data.app_id); if (data.extra_data_name) app_control_add_extra_data(service, data.extra_data_name, data.extra_value); if (data.set_operation) app_control_set_operation(service, data.set_operation); if (data.launch_group_mode) app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_GROUP); DBG("app_control_send_launch_request() %s", data.app_id); app_control_send_launch_request(service, NULL, NULL); app_control_destroy(service); if (running) { DBG("running timer is working"); return; } running = true; clear_running_timer(); running_timer = ecore_timer_add(CALLBACK_TIMER, (Ecore_Task_Cb)_app_ctrl_timer_cb, NULL); DBG("return"); return; }