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>
27 #include "indicator.h"
29 #include "indicator_gui.h"
35 #define APP_CONTROL_OPERATION_POPUP_SEARCH "http://samsung.com/appcontrol/operation/search"
37 #define DEFAULT_DIR ICONDIR
38 #define DIR_PREFIX "Theme_%02d_"
39 #define LABEL_STRING "<color=#%02x%02x%02x%02x>%s</color>"
42 char *util_set_label_text_color(const char *txt)
44 Eina_Strbuf *temp_buf = NULL;
45 Eina_Bool buf_result = EINA_FALSE;
48 retif(txt == NULL, NULL, "Invalid parameter!");
50 temp_buf = eina_strbuf_new();
51 buf_result = eina_strbuf_append_printf(temp_buf,
52 LABEL_STRING, FONT_COLOR, txt);
54 if (buf_result == EINA_FALSE)
55 DBG("Failed to make label string!");
57 ret_str = eina_strbuf_string_steal(temp_buf);
59 eina_strbuf_free(temp_buf);
63 const char *util_get_icon_dir(void)
65 return util_get_res_file_path(DEFAULT_DIR);
70 void util_signal_emit(void* data, const char *emission, const char *source)
72 struct appdata *ad = NULL;
73 Evas_Object *edje = NULL;
77 ad = (struct appdata *)data;
79 char *filter1 = "indicator.connection.updown";
80 char *filter2 = "indicator.wifi.updown";
81 if (strncmp(filter1, emission, strlen(filter1)) != 0
82 && strncmp(filter2, emission, strlen(filter2)) != 0) {
83 SECURE_DBG("emission %s",emission);
86 edje = elm_layout_edje_get(ad->win.layout);
88 edje_object_signal_emit(edje, emission, source);
93 void util_part_text_emit(void* data, const char *part, const char *text)
95 struct appdata *ad = (struct appdata *)data;
96 retif(data == NULL, , "Invalid parameter!");
99 retif(ad->win.layout == NULL, , "Invalid parameter!");
100 edje = elm_layout_edje_get(ad->win.layout);
101 edje_object_part_text_set(edje, part, text);
106 void util_signal_emit_by_win(void* data, const char *emission, const char *source)
108 win_info *win = NULL;
109 Evas_Object *edje = NULL;
113 win = (win_info*)data;
114 ret_if(!win->layout);
116 _D("emission %s", emission);
118 edje = elm_layout_edje_get(win->layout);
119 edje_object_signal_emit(edje, emission, source);
124 void util_part_text_emit_by_win(void* data, const char *part, const char *text)
126 win_info *win = (win_info*)data;
127 retif(data == NULL, , "Invalid parameter!");
130 retif(win->layout == NULL, , "Invalid parameter!");
131 edje = elm_layout_edje_get(win->layout);
132 edje_object_part_text_set(edje, part, text);
137 void util_battery_percentage_part_content_set(void* data, const char *part, const char *img_path)
139 struct appdata *ad = (struct appdata *)data;
140 retif(data == NULL, , "Invalid parameter!");
141 Evas_Object *icon = NULL;
144 retif(ad->win.layout == NULL, , "Invalid parameter!");
146 icon = elm_image_add(ad->win.layout);
147 retif(!icon, , "Cannot create elm icon object!");
149 if (strncmp(img_path, "/", 1) != 0)
151 snprintf(path, sizeof(path), "%s/%s", util_get_icon_dir(), img_path);
155 strncpy(path, img_path, sizeof(path)-1);
158 if (!ecore_file_exists(path))
160 ERR("icon file does not exist!!: %s",path);
163 elm_image_file_set(icon, path, NULL);
164 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
165 elm_object_part_content_set(ad->win.layout, part, icon);
170 void util_send_status_message_start(void* data,double duration)
173 win_info* win = (win_info*)data;
174 retif(data == NULL, , "Invalid parameter!");
175 struct appdata *ad = win->data;
176 Indicator_Data_Animation msg = {0,};
178 msg.xwin = ad->active_indi_win;
179 msg.duration = duration;
181 DBG("status start %x, %f",ad->active_indi_win,duration);
182 ee_port = ecore_evas_ecore_evas_get(evas_object_evas_get(win->win));
183 ecore_evas_msg_send(ee_port, MSG_DOMAIN_CONTROL_INDICATOR, MSG_ID_INDICATOR_ANI_START, &(msg), sizeof(Indicator_Data_Animation));
189 void util_launch_search(void* data)
191 int lock_state = VCONFKEY_IDLE_UNLOCK;
193 app_control_h service;
194 int ret = APP_CONTROL_ERROR_NONE;
196 lock_ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state);
198 /* In Lock Screen, home button don't have to do */
199 if (lock_ret == 0 && lock_state == VCONFKEY_IDLE_LOCK) {
203 if (util_check_system_status() == FAIL) {
204 DBG("util_check_system_status failed");
208 app_control_create(&service);
209 app_control_set_operation(service, APP_CONTROL_OPERATION_MAIN);
210 app_control_set_app_id(service, SEARCH_PKG_NAME);
212 ret = app_control_send_launch_request(service, NULL, NULL);
214 if(ret != APP_CONTROL_ERROR_NONE) {
215 ERR("Cannot launch app");
218 app_control_destroy(service);
223 int util_check_system_status(void)
227 ret = vconf_get_int(VCONFKEY_PWLOCK_STATE, &value);
229 (value == VCONFKEY_PWLOCK_BOOTING_LOCK ||
230 value == VCONFKEY_PWLOCK_RUNNING_LOCK))
238 #ifdef _SUPPORT_SCREEN_READER
239 Evas_Object *util_access_object_register(Evas_Object *object, Evas_Object *layout)
241 if ((object == NULL) || (layout == NULL)) {
242 ERR("Access object doesn't exist!!! %x %x",object,layout);
246 return elm_access_object_register(object, layout);
251 void util_access_object_unregister(Evas_Object *object)
253 if (object == NULL) {
254 ERR("Access object doesn't exist!!! %x",object);
258 elm_access_object_unregister(object);
263 void util_access_object_info_set(Evas_Object *object, int info_type, char *info_text)
265 if ((object == NULL) || (info_text == NULL)) {
266 ERR("Access info set fails %x, %x!!!",object,info_text);
270 elm_access_info_set(object, info_type, (const char *)info_text);
275 void util_access_object_activate_cb_set(Evas_Object *object, Elm_Access_Activate_Cb activate_cb, void *cb_data)
277 if ((object == NULL) || (activate_cb == NULL)) {
278 ERR("Access activated cb set fails %x %x!!!",object,activate_cb);
282 elm_access_activate_cb_set(object, activate_cb, cb_data);
287 void util_access_object_info_cb_set(Evas_Object *object, int type, Elm_Access_Info_Cb info_cb, void *cb_data)
289 if ((object == NULL) || (info_cb == NULL)) {
290 ERR("Access info cb set fails %x %x!!!",object,info_cb);
294 elm_access_info_cb_set(object, type, info_cb, cb_data);
299 void util_icon_access_register(icon_s *icon)
308 if(icon->tts_enable == EINA_TRUE && icon->ao==NULL)
310 Evas_Object *to = NULL;
312 to = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(icon->img_obj.obj), "elm.rect.icon.access");
313 icon->ao = util_access_object_register(to, icon->img_obj.obj);
315 if(icon->access_cb!=NULL)
317 util_access_object_info_cb_set(icon->ao,ELM_ACCESS_INFO,icon->access_cb,icon->ad);
324 void util_icon_access_unregister(icon_s *icon)
332 if(icon->tts_enable == EINA_TRUE&&icon->ao!=NULL)
334 util_access_object_unregister(icon->ao);
338 #endif /* _SUPPORT_SCREEN_READER */
342 static char* _get_timezone_from_vconf(void)
344 char *szTimezone = NULL;
345 szTimezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
346 if(szTimezone == NULL)
348 ERR("Cannot get time zone.");
349 return strdup("N/A");
357 char* util_get_timezone_str(void)
359 enum { BUFFERSIZE = 1024 };
360 char buf[BUFFERSIZE];
361 ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
369 ERR("NO TIMEZONEINFO");
370 return _get_timezone_from_vconf();
372 return (char*)strdup(buf+20); // Asia/Seoul
377 Eina_Bool util_win_prop_angle_get(Ecore_X_Window win, int *req)
379 Eina_Bool res = EINA_FALSE;
382 int angle[2] = {-1, -1};
383 unsigned char* prop_data = NULL;
384 ret = ecore_x_window_prop_property_get(win, ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE, ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
386 if (prop_data) free(prop_data);
390 if (ret && prop_data) {
391 memcpy (&angle, prop_data, sizeof (int)*count);
392 if (count == 2) res = EINA_TRUE;
395 if (prop_data) free(prop_data);
396 *req = angle[0]; //current angle
398 if (angle[0] == -1 && angle[1] == -1) res = EINA_FALSE;
406 int util_get_block_width(void* data, const char* part)
408 Evas_Object * eo = NULL;
411 retif(data == NULL,-1, "Invalid parameter!");
412 retif(part == NULL,-1, "Invalid parameter!");
414 win_info* win = (win_info*)data;
416 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
418 evas_object_geometry_get(eo, NULL, NULL, &geo_dx, &geo_dy);
425 int util_get_string_width(void* data, const char* part)
427 Evas_Object * eo = NULL;
430 retif(data == NULL,-1, "Invalid parameter!");
431 retif(part == NULL,-1, "Invalid parameter!");
433 win_info* win = (win_info*)data;
435 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
437 evas_object_textblock_size_formatted_get(eo, &text_dx, &text_dy);
444 int util_is_orf(void)
451 int util_check_noti_ani(const char* path)
454 if (!strcmp(path,"reserved://indicator/ani/downloading")
455 || !strcmp(path,"reserved://indicator/ani/uploading")) {
463 void util_start_noti_ani(void* data)
465 icon_s *icon = (icon_s *)data;
466 retif(data == NULL, , "Invalid parameter!");
468 if(util_check_noti_ani(icon->img_obj.data))
470 DBG("%s",icon->name);
471 if(!strcmp(icon->img_obj.data,"reserved://indicator/ani/downloading"))
473 icon_ani_set(icon,ICON_ANI_DOWNLOADING);
477 icon_ani_set(icon,ICON_ANI_UPLOADING);
484 void util_stop_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 Evas_Object *img_edje;
492 img_edje = elm_layout_edje_get(icon->img_obj.obj);
493 DBG("%s",icon->name);
494 if(!strcmp(icon->img_obj.data,"reserved://indicator/ani/downloading"))
496 edje_object_signal_emit(img_edje, "indicator.ani.downloading.stop","elm.swallow.icon");
500 edje_object_signal_emit(img_edje, "indicator.ani.uploading.stop","elm.swallow.icon");
507 void util_char_replace(char *text, char s, char t)
509 retif(text == NULL, , "invalid argument");
511 int i = 0, text_len = 0;
513 text_len = strlen(text);
515 for (i = 0; i < text_len; i++) {
516 if (*(text + i) == s) {
524 static bool _is_empty_str(const char *str)
526 if (NULL == str || '\0' == str[0])
533 char *util_safe_str(const char *str, const char *strSearch)
535 if (_is_empty_str(str))
538 return strstr(str, strSearch);
543 int util_dynamic_state_get(void)
546 //vconf_get_bool(VCONFKEY_SETAPPL_DYNAMIC_STATUS_BAR, &val);
552 Ecore_File_Monitor* util_file_monitor_add(const char* file_path, Ecore_File_Monitor_Cb callback_func, void *ad)
554 SECURE_DBG("File path : %s", file_path);
555 Ecore_File_Monitor* pFileMonitor = NULL;
556 pFileMonitor = ecore_file_monitor_add(file_path, callback_func, ad);
557 if(pFileMonitor == NULL) SECURE_DBG("ecore_file_monitor_add return NULL !!");
564 void util_file_monitor_remove(Ecore_File_Monitor* pFileMonitor)
566 if(pFileMonitor == NULL) return;
568 ecore_file_monitor_del(pFileMonitor);
572 const char *util_get_file_path(enum app_subdir dir, const char *relative)
574 static char buf[PATH_MAX];
579 prefix = app_get_data_path();
582 prefix = app_get_cache_path();
584 case APP_DIR_RESOURCE:
585 prefix = app_get_resource_path();
587 case APP_DIR_SHARED_DATA:
588 prefix = app_get_shared_data_path();
590 case APP_DIR_SHARED_RESOURCE:
591 prefix = app_get_shared_resource_path();
593 case APP_DIR_SHARED_TRUSTED:
594 prefix = app_get_shared_trusted_path();
596 case APP_DIR_EXTERNAL_DATA:
597 prefix = app_get_external_data_path();
599 case APP_DIR_EXTERNAL_CACHE:
600 prefix = app_get_external_cache_path();
602 case APP_DIR_EXTERNAL_SHARED_DATA:
603 prefix = app_get_external_shared_data_path();
606 LOGE("Not handled directory type.");
609 size_t res = eina_file_path_join(buf, sizeof(buf), prefix, relative);
611 if (res > sizeof(buf)) {
612 LOGE("Path exceeded PATH_MAX");