4 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <app_common.h>
26 #include <system_settings.h>
29 #include "indicator.h"
31 #include "indicator_gui.h"
37 #define APP_CONTROL_OPERATION_POPUP_SEARCH "http://samsung.com/appcontrol/operation/search"
39 #define DEFAULT_DIR ICONDIR
40 #define DIR_PREFIX "Theme_%02d_"
41 #define LABEL_STRING "<color=#%02x%02x%02x%02x>%s</color>"
44 wifi_connection_state_changed_cb cb;
49 system_settings_key_e key;
50 system_settings_changed_cb cb;
52 } system_settings_handler_t;
55 runtime_info_key_e key;
56 runtime_info_changed_cb cb;
58 } runtime_info_handler_t;
60 static Eina_List *wifi_callbacks;
61 static Eina_List *ss_callbacks;
62 static Eina_List *ri_callbacks;
64 char *util_set_label_text_color(const char *txt)
66 Eina_Strbuf *temp_buf = NULL;
67 Eina_Bool buf_result = EINA_FALSE;
70 retif(txt == NULL, NULL, "Invalid parameter!");
72 temp_buf = eina_strbuf_new();
73 buf_result = eina_strbuf_append_printf(temp_buf,
74 LABEL_STRING, FONT_COLOR, txt);
76 if (buf_result == EINA_FALSE)
77 DBG("Failed to make label string!");
79 ret_str = eina_strbuf_string_steal(temp_buf);
81 eina_strbuf_free(temp_buf);
85 const char *util_get_icon_dir(void)
87 return util_get_res_file_path(DEFAULT_DIR);
92 void util_signal_emit(void* data, const char *emission, const char *source)
94 struct appdata *ad = NULL;
95 Evas_Object *edje = NULL;
99 ad = (struct appdata *)data;
101 char *filter1 = "indicator.connection.updown";
102 char *filter2 = "indicator.wifi.updown";
103 if (strncmp(filter1, emission, strlen(filter1)) != 0
104 && strncmp(filter2, emission, strlen(filter2)) != 0) {
105 SECURE_DBG("emission %s",emission);
108 edje = elm_layout_edje_get(ad->win.layout);
110 edje_object_signal_emit(edje, emission, source);
115 void util_part_text_emit(void* data, const char *part, const char *text)
117 struct appdata *ad = (struct appdata *)data;
118 retif(data == NULL, , "Invalid parameter!");
121 retif(ad->win.layout == NULL, , "Invalid parameter!");
122 edje = elm_layout_edje_get(ad->win.layout);
123 edje_object_part_text_set(edje, part, text);
128 void util_signal_emit_by_win(void* data, const char *emission, const char *source)
130 win_info *win = NULL;
131 Evas_Object *edje = NULL;
135 win = (win_info*)data;
136 ret_if(!win->layout);
138 _D("emission %s", emission);
140 edje = elm_layout_edje_get(win->layout);
141 edje_object_signal_emit(edje, emission, source);
146 void util_part_text_emit_by_win(void* data, const char *part, const char *text)
148 win_info *win = (win_info*)data;
149 retif(data == NULL, , "Invalid parameter!");
152 retif(win->layout == NULL, , "Invalid parameter!");
153 edje = elm_layout_edje_get(win->layout);
154 edje_object_part_text_set(edje, part, text);
159 void util_battery_percentage_part_content_set(void* data, const char *part, const char *img_path)
161 struct appdata *ad = (struct appdata *)data;
162 retif(data == NULL, , "Invalid parameter!");
163 Evas_Object *icon = NULL;
166 retif(ad->win.layout == NULL, , "Invalid parameter!");
168 icon = elm_image_add(ad->win.layout);
169 retif(!icon, , "Cannot create elm icon object!");
171 if (strncmp(img_path, "/", 1) != 0)
173 snprintf(path, sizeof(path), "%s/%s", util_get_icon_dir(), img_path);
177 strncpy(path, img_path, sizeof(path)-1);
180 if (!ecore_file_exists(path))
182 ERR("icon file does not exist!!: %s",path);
185 elm_image_file_set(icon, path, NULL);
186 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
187 elm_object_part_content_set(ad->win.layout, part, icon);
192 void util_send_status_message_start(void* data,double duration)
195 win_info* win = (win_info*)data;
196 retif(data == NULL, , "Invalid parameter!");
197 struct appdata *ad = win->data;
198 Indicator_Data_Animation msg = {0,};
200 msg.xwin = ad->active_indi_win;
201 msg.duration = duration;
203 DBG("status start %x, %f",ad->active_indi_win,duration);
204 ee_port = ecore_evas_ecore_evas_get(evas_object_evas_get(win->win));
205 ecore_evas_msg_send(ee_port, MSG_DOMAIN_CONTROL_INDICATOR, MSG_ID_INDICATOR_ANI_START, &(msg), sizeof(Indicator_Data_Animation));
211 void util_launch_search(void* data)
213 int lock_state = SYSTEM_SETTINGS_LOCK_STATE_UNLOCK;
214 app_control_h service;
216 int ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_LOCK_STATE, &lock_state);
217 retm_if(ret != SYSTEM_SETTINGS_ERROR_NONE, "system_settings_get_value_int failed %s", get_error_message(ret));
219 /* In Lock Screen, home button don't have to do */
220 if (lock_state == SYSTEM_SETTINGS_LOCK_STATE_LOCK) {
224 if (util_check_system_status() == FAIL) {
225 DBG("util_check_system_status failed");
229 app_control_create(&service);
230 app_control_set_operation(service, APP_CONTROL_OPERATION_MAIN);
231 app_control_set_app_id(service, SEARCH_PKG_NAME);
233 ret = app_control_send_launch_request(service, NULL, NULL);
235 if(ret != APP_CONTROL_ERROR_NONE) {
236 ERR("Cannot launch app");
239 app_control_destroy(service);
244 int util_check_system_status(void)
248 ret = vconf_get_int(VCONFKEY_PWLOCK_STATE, &value);
250 (value == VCONFKEY_PWLOCK_BOOTING_LOCK ||
251 value == VCONFKEY_PWLOCK_RUNNING_LOCK))
259 #ifdef _SUPPORT_SCREEN_READER
260 Evas_Object *util_access_object_register(Evas_Object *object, Evas_Object *layout)
262 if ((object == NULL) || (layout == NULL)) {
263 ERR("Access object doesn't exist!!! %x %x",object,layout);
267 return elm_access_object_register(object, layout);
272 void util_access_object_unregister(Evas_Object *object)
274 if (object == NULL) {
275 ERR("Access object doesn't exist!!! %x",object);
279 elm_access_object_unregister(object);
284 void util_access_object_info_set(Evas_Object *object, int info_type, char *info_text)
286 if ((object == NULL) || (info_text == NULL)) {
287 ERR("Access info set fails %x, %x!!!",object,info_text);
291 elm_access_info_set(object, info_type, (const char *)info_text);
296 void util_access_object_activate_cb_set(Evas_Object *object, Elm_Access_Activate_Cb activate_cb, void *cb_data)
298 if ((object == NULL) || (activate_cb == NULL)) {
299 ERR("Access activated cb set fails %x %x!!!",object,activate_cb);
303 elm_access_activate_cb_set(object, activate_cb, cb_data);
308 void util_access_object_info_cb_set(Evas_Object *object, int type, Elm_Access_Info_Cb info_cb, void *cb_data)
310 if ((object == NULL) || (info_cb == NULL)) {
311 ERR("Access info cb set fails %x %x!!!",object,info_cb);
315 elm_access_info_cb_set(object, type, info_cb, cb_data);
320 void util_icon_access_register(icon_s *icon)
329 if(icon->tts_enable == EINA_TRUE && icon->ao==NULL)
331 Evas_Object *to = NULL;
333 to = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(icon->img_obj.obj), "elm.rect.icon.access");
334 icon->ao = util_access_object_register(to, icon->img_obj.obj);
336 if(icon->access_cb!=NULL)
338 util_access_object_info_cb_set(icon->ao,ELM_ACCESS_INFO,icon->access_cb,icon->ad);
345 void util_icon_access_unregister(icon_s *icon)
353 if(icon->tts_enable == EINA_TRUE&&icon->ao!=NULL)
355 util_access_object_unregister(icon->ao);
359 #endif /* _SUPPORT_SCREEN_READER */
363 static char* _get_timezone_from_vconf(void)
365 char *szTimezone = NULL;
366 szTimezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
367 if(szTimezone == NULL)
369 ERR("Cannot get time zone.");
370 return strdup("N/A");
378 char* util_get_timezone_str(void)
380 enum { BUFFERSIZE = 1024 };
381 char buf[BUFFERSIZE];
382 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
390 ERR("NO TIMEZONEINFO");
391 return _get_timezone_from_vconf();
393 return (char*)strdup(buf+20); // Asia/Seoul
398 Eina_Bool util_win_prop_angle_get(Ecore_X_Window win, int *req)
400 Eina_Bool res = EINA_FALSE;
403 int angle[2] = {-1, -1};
404 unsigned char* prop_data = NULL;
405 ret = ecore_x_window_prop_property_get(win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
407 if (prop_data) free(prop_data);
411 if (ret && prop_data) {
412 memcpy (&angle, prop_data, sizeof (int)*count);
413 if (count == 2) res = EINA_TRUE;
416 if (prop_data) free(prop_data);
417 *req = angle[0]; //current angle
419 if (angle[0] == -1 && angle[1] == -1) res = EINA_FALSE;
427 int util_get_block_width(void* data, const char* part)
429 Evas_Object * eo = NULL;
432 retif(data == NULL,-1, "Invalid parameter!");
433 retif(part == NULL,-1, "Invalid parameter!");
435 win_info* win = (win_info*)data;
437 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
439 evas_object_geometry_get(eo, NULL, NULL, &geo_dx, &geo_dy);
446 int util_get_string_width(void* data, const char* part)
448 Evas_Object * eo = NULL;
451 retif(data == NULL,-1, "Invalid parameter!");
452 retif(part == NULL,-1, "Invalid parameter!");
454 win_info* win = (win_info*)data;
456 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
458 evas_object_textblock_size_formatted_get(eo, &text_dx, &text_dy);
465 int util_is_orf(void)
472 int util_check_noti_ani(const char* path)
475 if (!strcmp(path,"reserved://indicator/ani/downloading")
476 || !strcmp(path,"reserved://indicator/ani/uploading")) {
484 void util_start_noti_ani(void* data)
486 icon_s *icon = (icon_s *)data;
487 retif(data == NULL, , "Invalid parameter!");
489 if(util_check_noti_ani(icon->img_obj.data))
491 DBG("%s",icon->name);
492 if(!strcmp(icon->img_obj.data,"reserved://indicator/ani/downloading"))
494 icon_ani_set(icon,ICON_ANI_DOWNLOADING);
498 icon_ani_set(icon,ICON_ANI_UPLOADING);
505 void util_stop_noti_ani(void* data)
507 icon_s *icon = (icon_s *)data;
508 retif(data == NULL, , "Invalid parameter!");
510 if(util_check_noti_ani(icon->img_obj.data))
512 Evas_Object *img_edje;
513 img_edje = elm_layout_edje_get(icon->img_obj.obj);
514 DBG("%s",icon->name);
515 if(!strcmp(icon->img_obj.data,"reserved://indicator/ani/downloading"))
517 edje_object_signal_emit(img_edje, "indicator.ani.downloading.stop","elm.swallow.icon");
521 edje_object_signal_emit(img_edje, "indicator.ani.uploading.stop","elm.swallow.icon");
528 void util_char_replace(char *text, char s, char t)
530 retif(text == NULL, , "invalid argument");
532 int i = 0, text_len = 0;
534 text_len = strlen(text);
536 for (i = 0; i < text_len; i++) {
537 if (*(text + i) == s) {
545 static bool _is_empty_str(const char *str)
547 if (NULL == str || '\0' == str[0])
554 char *util_safe_str(const char *str, const char *strSearch)
556 if (_is_empty_str(str))
559 return strstr(str, strSearch);
564 int util_dynamic_state_get(void)
567 //vconf_get_bool(VCONFKEY_SETAPPL_DYNAMIC_STATUS_BAR, &val);
573 Ecore_File_Monitor* util_file_monitor_add(const char* file_path, Ecore_File_Monitor_Cb callback_func, void *ad)
575 SECURE_DBG("File path : %s", file_path);
576 Ecore_File_Monitor* pFileMonitor = NULL;
577 pFileMonitor = ecore_file_monitor_add(file_path, callback_func, ad);
578 if(pFileMonitor == NULL) SECURE_DBG("ecore_file_monitor_add return NULL !!");
585 void util_file_monitor_remove(Ecore_File_Monitor* pFileMonitor)
587 if(pFileMonitor == NULL) return;
589 ecore_file_monitor_del(pFileMonitor);
593 const char *util_get_file_path(enum app_subdir dir, const char *relative)
595 static char buf[PATH_MAX];
600 prefix = app_get_data_path();
603 prefix = app_get_cache_path();
605 case APP_DIR_RESOURCE:
606 prefix = app_get_resource_path();
608 case APP_DIR_SHARED_DATA:
609 prefix = app_get_shared_data_path();
611 case APP_DIR_SHARED_RESOURCE:
612 prefix = app_get_shared_resource_path();
614 case APP_DIR_SHARED_TRUSTED:
615 prefix = app_get_shared_trusted_path();
617 case APP_DIR_EXTERNAL_DATA:
618 prefix = app_get_external_data_path();
620 case APP_DIR_EXTERNAL_CACHE:
621 prefix = app_get_external_cache_path();
623 case APP_DIR_EXTERNAL_SHARED_DATA:
624 prefix = app_get_external_shared_data_path();
627 LOGE("Not handled directory type.");
630 size_t res = eina_file_path_join(buf, sizeof(buf), prefix, relative);
632 if (res > sizeof(buf)) {
633 LOGE("Path exceeded PATH_MAX");
640 static void _wifi_state_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data)
645 EINA_LIST_FOREACH(wifi_callbacks, l, hdl) {
646 if (hdl->cb) hdl->cb(state, ap, hdl->data);
650 int util_wifi_set_connection_state_changed_cb(wifi_connection_state_changed_cb cb, void *data)
652 wifi_handler_t *hdl = malloc(sizeof(wifi_handler_t));
657 if (!wifi_callbacks) {
658 int err = wifi_set_connection_state_changed_cb(_wifi_state_cb, NULL);
659 if (err != WIFI_ERROR_NONE) {
667 wifi_callbacks = eina_list_append(wifi_callbacks, cb);
672 void util_wifi_unset_connection_state_changed_cb(wifi_connection_state_changed_cb cb)
677 EINA_LIST_FOREACH_SAFE(wifi_callbacks, l, l2, hdl) {
679 wifi_callbacks = eina_list_remove_list(wifi_callbacks, l);
684 wifi_unset_connection_state_changed_cb();
687 static void _system_settings_cb(system_settings_key_e key, void *data)
690 system_settings_handler_t *hdl;
692 EINA_LIST_FOREACH(ss_callbacks, l, hdl) {
693 if (hdl->key == key) {
694 if (hdl->cb) hdl->cb(key, hdl->data);
699 int util_system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb cb, void *data)
701 system_settings_handler_t *handler = malloc(sizeof(system_settings_handler_t));
706 system_settings_unset_changed_cb(key);
707 int err = system_settings_set_changed_cb(key, _system_settings_cb, NULL);
708 if (err != SYSTEM_SETTINGS_ERROR_NONE) {
709 ERR("system_settings_set_changed_cb failed: %s", get_error_message(err));
716 handler->data = data;
718 ss_callbacks = eina_list_append(ss_callbacks, handler);
723 void util_system_settings_unset_changed_cb(system_settings_key_e key, system_settings_changed_cb cb)
726 system_settings_handler_t *hdl;
727 Eina_Bool del_key_cb = EINA_TRUE;
729 EINA_LIST_FOREACH_SAFE(ss_callbacks, l, l2, hdl) {
730 if (hdl->key == key) {
732 ss_callbacks = eina_list_remove_list(ss_callbacks, l);
736 del_key_cb = EINA_FALSE;
741 system_settings_unset_changed_cb(key);
744 static void _runtime_info_cb(runtime_info_key_e key, void *data)
747 runtime_info_handler_t *hdl;
749 EINA_LIST_FOREACH(ri_callbacks, l, hdl) {
750 if (hdl->key == key) {
751 if (hdl->cb) hdl->cb(key, hdl->data);
756 int util_runtime_info_set_changed_cb(runtime_info_key_e key, runtime_info_changed_cb cb, void *data)
758 runtime_info_handler_t *handler = malloc(sizeof(runtime_info_handler_t));
763 runtime_info_unset_changed_cb(key);
764 int err = runtime_info_set_changed_cb(key, _runtime_info_cb, NULL);
765 if (err != RUNTIME_INFO_ERROR_NONE) {
766 ERR("runtime_info_set_changed_cb failed: %s", get_error_message(err));
773 handler->data = data;
775 ri_callbacks = eina_list_append(ri_callbacks, handler);
780 void util_runtime_info_unset_changed_cb(runtime_info_key_e key, runtime_info_changed_cb cb)
783 runtime_info_handler_t *hdl;
784 Eina_Bool del_key_cb = EINA_TRUE;
786 EINA_LIST_FOREACH_SAFE(ri_callbacks, l, l2, hdl) {
787 if (hdl->key == key) {
789 ri_callbacks = eina_list_remove_list(ri_callbacks, l);
793 del_key_cb = EINA_FALSE;
798 runtime_info_unset_changed_cb(key);