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.
22 #include <app_preference.h>
29 #include "indicator_gui.h"
33 #define PRIVATE_DATA_KEY_ICON_B_ANI "p_i_ba"
35 #define ON_TIMER_ICON_ANIMATION_FRAME_TIME 0.3
36 #define UPLOAD_ICON_ANIMATION_SIGNAL "indicator.ani.uploading.%d"
37 #define DOWNLOAD_ICON_ANIMATION_SIGNAL "indicator.ani.downloading.%d"
39 static unsigned int update_icon_flag = 1; // For battery problem
41 static void _reset_on_timer_icon_animation(icon_s *icon)
45 if (icon->p_animation_timer) {
46 ecore_timer_del(icon->p_animation_timer);
47 icon->p_animation_timer = NULL;
49 icon->animation_in_progress = EINA_FALSE;
50 icon->last_animation_timestamp = ecore_time_unix_get();
51 icon->signal_to_emit_prefix[0] = '\0';
52 icon->animation_state = UD_ICON_ANI_STATE_0;
57 static Eina_Bool _animate_on_timer_cb(void *data)
61 retv_if(!data, ECORE_CALLBACK_CANCEL);
63 icon = (icon_s *)data;
65 if (icon->animation_in_progress == EINA_FALSE) {
66 icon->p_animation_timer = NULL;
67 return ECORE_CALLBACK_CANCEL;
70 if ((ecore_time_unix_get() - icon->last_animation_timestamp) < ON_TIMER_ICON_ANIMATION_FRAME_TIME) {
71 return ECORE_CALLBACK_RENEW;
74 Evas_Object *img_edje = elm_layout_edje_get(icon->img_obj.obj);
75 retv_if(!img_edje, ECORE_CALLBACK_CANCEL);
77 char signal_to_emit[SIGNAL_SIZE] = {'\0',};
79 snprintf(signal_to_emit, SIGNAL_SIZE, icon->signal_to_emit_prefix, icon->animation_state);
81 edje_object_signal_emit(img_edje, signal_to_emit,"prog");
83 if (icon->animation_state == UD_ICON_ANI_STATE_MAX) {
84 icon->animation_state = UD_ICON_ANI_STATE_0;
86 icon->animation_state++;
88 icon->last_animation_timestamp = ecore_time_unix_get();
90 return ECORE_CALLBACK_RENEW;
95 static const char *_icon_ani_type_set_send_signal(icon_s *icon, Icon_Ani_Type type)
99 const char *BLINK_SIGNAL = "icon,state,blink";
100 const char *ROATATE_SIGNAL = "icon,state,rotate";
101 const char *METRONOME_SIGNAL = "icon,state,metronome";
102 const char *DEFAULT = "icon,state,default";
103 const char *send_signal = DEFAULT;
107 send_signal = BLINK_SIGNAL;
109 case ICON_ANI_ROTATE:
110 send_signal = ROATATE_SIGNAL;
112 case ICON_ANI_METRONOME:
113 send_signal = METRONOME_SIGNAL;
115 case ICON_ANI_DOWNLOADING:
116 case ICON_ANI_UPLOADING:
117 /* If this icon is already animated during download/upload we don't have to set timer again */
118 if (icon->animation_in_progress == EINA_FALSE) {
119 _reset_on_timer_icon_animation(icon);
120 send_signal = "dummy.signal";
122 if (type == ICON_ANI_DOWNLOADING) {
123 strncpy(icon->signal_to_emit_prefix, DOWNLOAD_ICON_ANIMATION_SIGNAL, sizeof(DOWNLOAD_ICON_ANIMATION_SIGNAL));
126 if (type == ICON_ANI_UPLOADING) {
127 strncpy(icon->signal_to_emit_prefix, UPLOAD_ICON_ANIMATION_SIGNAL,sizeof(UPLOAD_ICON_ANIMATION_SIGNAL));
129 icon->animation_in_progress = EINA_TRUE;
130 icon->p_animation_timer = ecore_timer_add(ON_TIMER_ICON_ANIMATION_FRAME_TIME,_animate_on_timer_cb, icon);
142 void icon_ani_set(icon_s *icon, Icon_Ani_Type type)
144 Evas_Object *img_edje = NULL;
145 const char *send_signal = NULL;
151 if (!icon->obj_exist) return;
153 send_signal = _icon_ani_type_set_send_signal(icon, type);
154 ret_if(!send_signal);
156 switch (icon->type) {
157 case INDICATOR_IMG_ICON:
158 img_edje = elm_layout_edje_get(icon->img_obj.obj);
159 edje_object_signal_emit(img_edje, send_signal,"elm.swallow.icon");
161 case INDICATOR_TXT_ICON:
163 case INDICATOR_TXT_WITH_IMG_ICON:
165 case INDICATOR_DIGIT_ICON:
166 img_edje = elm_layout_edje_get(icon->img_obj.obj);
167 edje_object_signal_emit(img_edje, send_signal,"elm.swallow.icon");
176 static void _fixed_icon_layout_file_set(icon_s *icon, Evas_Object *ly)
181 if(icon->type == INDICATOR_DIGIT_ICON && icon->digit_area == DIGIT_DOZENS) {
182 elm_layout_file_set(ly, util_get_res_file_path(ICON_THEME_FILE), "elm/indicator/icon/dozen_digit");
184 elm_layout_file_set(ly, util_get_res_file_path(ICON_THEME_FILE), "elm/indicator/icon/base");
190 static void _noti_ani_icon_layout_file_set(int noti_is_ani, Evas_Object *ly)
195 evas_object_data_set(ly, PRIVATE_DATA_KEY_ICON_B_ANI, (void *) 1);
196 elm_layout_file_set(ly, util_get_res_file_path(ICON_NONFIXED_THEME_ANI_FILE), "elm/indicator/icon/base");
198 elm_layout_file_set(ly, util_get_res_file_path(ICON_NONFIXED_THEME_FILE), "elm/indicator/icon/base");
204 static Evas_Object *_img_icon_add(win_info *win, icon_s *icon)
207 Evas_Object *evas_icon;
209 const char *imgpath = NULL;
214 retv_if(!icon, NULL);
216 imgpath = (char *) icon->img_obj.data;
218 _reset_on_timer_icon_animation(icon);
220 if (icon->img_obj.width <= 0) {
221 icon->img_obj.width = DEFAULT_ICON_WIDTH;
224 if (icon->img_obj.height <= 0) {
225 icon->img_obj.height = DEFAULT_ICON_HEIGHT;
228 memset(path, 0x00, sizeof(path));
230 ly = elm_layout_add(win->layout);
233 if (icon->area == INDICATOR_ICON_AREA_FIXED) {
234 _fixed_icon_layout_file_set(icon, ly);
236 noti_is_ani = util_check_noti_ani(imgpath);
237 _noti_ani_icon_layout_file_set(noti_is_ani, ly);
240 evas_icon = elm_image_add(ly);
241 retv_if(!evas_icon, NULL);
243 b_ani = (int) evas_object_data_get(ly, PRIVATE_DATA_KEY_ICON_B_ANI);
246 if (strncmp(imgpath, "/", 1) != 0) {
247 snprintf(path, sizeof(path), "%s/%s", util_get_icon_dir(), imgpath);
249 strncpy(path, imgpath, sizeof(path)-1);
252 if (!ecore_file_exists(path)) {
253 _E("icon file does not exist : %s", path);
255 elm_image_file_set(evas_icon, path, NULL);
258 evas_object_size_hint_min_set(evas_icon, ELM_SCALE_SIZE(icon->img_obj.width), ELM_SCALE_SIZE(icon->img_obj.height));
259 elm_object_part_content_set(ly, "elm.swallow.icon", evas_icon);
261 evas_object_data_set(ly, DATA_KEY_IMG_ICON, evas_icon);
262 evas_object_size_hint_min_set(ly, ELM_SCALE_SIZE(icon->img_obj.width), ELM_SCALE_SIZE(icon->img_obj.height));
263 evas_object_hide(ly);
270 char *icon_label_set(const char *buf, char *font_name, char *font_style, int font_size, void *data)
272 Eina_Strbuf *temp_buf = NULL;
273 char *ret_str = NULL;
274 char *label_font = ICON_FONT_NAME;
275 char *label_font_style = ICON_FONT_STYLE;
276 int label_font_size = ICON_FONT_SIZE;
277 Eina_Bool buf_result = EINA_FALSE;
279 retvm_if(data == NULL || buf == NULL, NULL, "Invalid parameter!");
281 temp_buf = eina_strbuf_new();
282 if (font_name != NULL)
283 label_font = font_name;
284 if (font_style != NULL)
285 label_font_style = font_style;
287 label_font_size = font_size;
289 buf_result = eina_strbuf_append_printf(temp_buf, CUSTOM_LABEL_STRING,
290 label_font, label_font_style,
291 label_font_size, buf);
293 if (buf_result != EINA_FALSE)
294 ret_str = eina_strbuf_string_steal(temp_buf);
296 eina_strbuf_free(temp_buf);
303 Eina_Bool icon_add(win_info *win, icon_s *icon)
305 retv_if(!icon, EINA_FALSE);
307 switch (icon->type) {
308 case INDICATOR_TXT_ICON:
310 case INDICATOR_IMG_ICON:
311 icon->img_obj.obj = _img_icon_add(win, icon);
313 case INDICATOR_TXT_WITH_IMG_ICON:
315 case INDICATOR_DIGIT_ICON:
316 icon->img_obj.obj = _img_icon_add(win, icon);
319 _E("Icon type check error!");
322 icon->obj_exist = EINA_TRUE;
329 Eina_Bool icon_del(icon_s *icon)
331 Evas_Object *icon_obj;
332 retvm_if(icon == NULL, EINA_FALSE, "Invalid parameter!");
334 _reset_on_timer_icon_animation(icon);
336 if (icon->obj_exist != EINA_FALSE) {
337 if (icon->img_obj.obj) {
339 evas_object_data_get(icon->img_obj.obj, DATA_KEY_IMG_ICON);
340 evas_object_del(icon_obj);
341 evas_object_del(icon->img_obj.obj);
342 icon->img_obj.obj = NULL;
350 /******************************************************************************
352 * Static functions : util functions - check priority
354 *****************************************************************************/
356 static int _show_others_in_same_priority(icon_s *icon)
358 icon_s *wish_add_icon;
359 int area = icon->area;
360 retvm_if(icon == NULL, FAIL, "Invalid parameter!");
362 wish_add_icon = list_try_to_find_icon_to_show(icon->area, icon->priority);
363 if (wish_add_icon == NULL)
368 if (box_exist_icon(wish_add_icon))
370 /* Already shown icon */
374 if(area ==INDICATOR_ICON_AREA_NOTI)
376 box_pack_append(wish_add_icon);
380 box_pack(wish_add_icon);
388 static int _hide_others_in_view_list(icon_s *icon)
390 icon_s *wish_remove_icon = NULL;
391 retvm_if(icon == NULL, FAIL, "Invalid parameter!");
393 if (INDICATOR_ICON_AREA_SYSTEM == icon->area || INDICATOR_ICON_AREA_NOTI == icon->area || INDICATOR_ICON_AREA_MINICTRL == icon->area)
397 /* In Case of Nonfixed icon, remove same or
398 * lower priority icon. Check count of non-fixed view list
401 ret = box_is_enable_to_insert_in_non_fixed_list(icon);
402 icon->wish_to_show = EINA_TRUE;
406 case CAN_ADD_WITH_DEL_NOTI:
407 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_NOTI,0);
408 box_unpack(wish_remove_icon);
410 retvm_if(wish_remove_icon == NULL, FAIL, "Unexpected Error : CAN_ADD_WITH_DEL_NOTI");
412 case CAN_ADD_WITH_DEL_SYSTEM:
413 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_SYSTEM,0);
415 box_unpack(wish_remove_icon);
416 retvm_if(wish_remove_icon == NULL, FAIL, "Unexpected Error : CAN_ADD_WITH_DEL_SYSTEM");
418 case CAN_ADD_WITH_DEL_MINICTRL:
419 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_MINICTRL,0);
421 box_unpack(wish_remove_icon);
422 retvm_if(wish_remove_icon == NULL, FAIL, "Unexpected Error : CAN_ADD_WITH_DEL_MINICTRL");
424 case CAN_ADD_WITHOUT_DEL:
432 else if (INDICATOR_ICON_AREA_FIXED == icon->area)
434 /* In Case of fixed icon, remove same priority icon */
435 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_FIXED,icon->priority);
437 /* First icon in the priority */
438 if (wish_remove_icon == NULL)
443 /* Already shown icon */
444 if (wish_remove_icon == icon)
449 icon->wish_to_show = EINA_TRUE;
452 /* Wish_remove_icon is always_top icon */
453 if (wish_remove_icon->always_top)
458 /* Other Icon of Same Priority should remove in view list */
459 box_unpack(wish_remove_icon);
467 /******************************************************************************
469 * Util Functions : external
471 *****************************************************************************/
474 int icon_width_set(icon_s *icon)
481 static int _icon_update(icon_s *icon)
483 struct appdata *ad = NULL;
487 retvm_if(icon == NULL || icon->ad == NULL, FAIL, "Invalid parameter!");
490 memset(buf, 0x00, sizeof(buf));
492 if (icon->type == INDICATOR_IMG_ICON || icon->type == INDICATOR_TXT_WITH_IMG_ICON || icon->type == INDICATOR_DIGIT_ICON) {
493 if (icon->area== INDICATOR_ICON_AREA_FIXED) {
494 if(icon->type == INDICATOR_DIGIT_ICON && icon->digit_area == DIGIT_DOZENS) {
495 elm_layout_file_set(icon->img_obj.obj, util_get_res_file_path(ICON_THEME_FILE), "elm/indicator/icon/dozen_digit");
497 elm_layout_file_set(icon->img_obj.obj, util_get_res_file_path(ICON_THEME_FILE), "elm/indicator/icon/base");
500 if(util_check_noti_ani(icon->img_obj.data)) {
501 elm_layout_file_set(icon->img_obj.obj, util_get_res_file_path(ICON_NONFIXED_THEME_ANI_FILE), "elm/indicator/icon/base");
503 elm_layout_file_set(icon->img_obj.obj, util_get_res_file_path(ICON_NONFIXED_THEME_FILE), "elm/indicator/icon/base");
507 img_eo = evas_object_data_get(icon->img_obj.obj, DATA_KEY_IMG_ICON);
509 util_start_noti_ani(icon);
511 /* Check absolute path */
512 retvm_if(icon->img_obj.data == NULL, FAIL,"Invalid parameter!");
514 if (strncmp(icon->img_obj.data, "/", 1) != 0) {
515 snprintf(buf, sizeof(buf), "%s/%s", util_get_icon_dir(),icon->img_obj.data);
516 elm_image_file_set(img_eo, buf, NULL);
518 retvm_if(icon->img_obj.data[0] == '\0', FAIL,"Invalid parameter!");
519 elm_image_file_set(img_eo, icon->img_obj.data, NULL);
522 if (icon->img_obj.width >= 0 && icon->img_obj.height>=0) {
523 evas_object_size_hint_min_set(img_eo,
524 ELM_SCALE_SIZE(icon->img_obj.width),
525 ELM_SCALE_SIZE(icon->img_obj.height));
527 evas_object_size_hint_min_set(img_eo, ELM_SCALE_SIZE(DEFAULT_ICON_WIDTH), ELM_SCALE_SIZE(DEFAULT_ICON_HEIGHT));
531 if (icon->area == INDICATOR_ICON_AREA_SYSTEM) {
534 if(ad->opacity_mode == INDICATOR_OPACITY_TRANSPARENT && bDisplay == 1) {
535 util_send_status_message_start(ad,2.5);
544 void icon_show(icon_s *icon)
546 struct appdata *ad = NULL;
551 ad = (struct appdata *)icon->ad;
553 if (icon->obj_exist != EINA_FALSE) {
554 if (icon->priority == INDICATOR_PRIORITY_NOTI_2) {
557 box_update_display(&(ad->win));
563 if (_hide_others_in_view_list(icon) == FAIL) {
569 box_update_display(&(ad->win));
572 void icon_hide(icon_s *icon)
576 retm_if(icon == NULL, "Invalid parameter!");
577 struct appdata *ad = (struct appdata *)icon->ad;
579 icon->wish_to_show = EINA_FALSE;
581 if (icon->exist_in_view == EINA_TRUE) {
582 ret = box_unpack(icon);
585 _E("Failed to unpack!");
587 _show_others_in_same_priority(icon);
589 box_update_display(&(ad->win));
596 void icon_event_count_set(int count, void *data)
598 static int _cnt = -1;
601 retm_if(data == NULL, "Cannot get layout!");
604 memset(buf, 0x00, sizeof(buf));
606 snprintf(buf, sizeof(buf), "%d", count);
607 util_signal_emit(data,"badge,show,1","elm.image.badge");
609 util_signal_emit(data,"badge,hide,1","elm.image.badge");
612 util_part_text_emit(data,"elm.text.badge", buf);
619 unsigned int icon_get_update_flag(void)
621 return update_icon_flag;
626 void icon_set_update_flag(unsigned int val)
628 _D("SET UPDATE FLAG %d",val);
629 update_icon_flag = val;
634 void icon_reset_list(void)
636 int system_cnt = box_get_count(SYSTEM_LIST);
638 if (system_cnt > box_get_enabled_system_count()) {
639 while(system_cnt > box_get_enabled_system_count()) {
640 icon_s *wish_remove_icon = NULL;
641 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_SYSTEM, 0);
643 if (wish_remove_icon == NULL) {
647 box_unpack(wish_remove_icon);
648 system_cnt = box_get_count(SYSTEM_LIST);
651 while (system_cnt < box_get_enabled_system_count()) {
652 icon_s *wish_add_icon = NULL;
653 wish_add_icon = list_try_to_find_icon_to_show(INDICATOR_ICON_AREA_SYSTEM, 0);
654 if (wish_add_icon == NULL) {
658 if (box_exist_icon(wish_add_icon)) {
662 box_pack_append(wish_add_icon);
663 system_cnt = box_get_count(SYSTEM_LIST);
664 if(system_cnt == box_get_enabled_system_count()) {
670 int minictrl_cnt = box_get_count(MINICTRL_LIST);
672 if (minictrl_cnt > box_get_minictrl_list()) {
673 _D("11 minictrl_cnt : %d // box_get_minictrl_list : %d", minictrl_cnt, box_get_minictrl_list());
674 while (minictrl_cnt > box_get_minictrl_list()) {
675 _D("22 minictrl_cnt : %d // box_get_minictrl_list : %d", minictrl_cnt, box_get_minictrl_list());
676 icon_s *wish_remove_icon = NULL;
677 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_MINICTRL,0);
679 if (wish_remove_icon == NULL) {
680 _D("icon_reset_list NULL!");
684 box_unpack(wish_remove_icon);
685 minictrl_cnt = box_get_count(MINICTRL_LIST);
688 while (minictrl_cnt < box_get_minictrl_list()) {
689 icon_s *wish_add_icon = NULL;
690 wish_add_icon = list_try_to_find_icon_to_show(INDICATOR_ICON_AREA_MINICTRL, 0);
691 if (wish_add_icon == NULL) {
695 if (box_exist_icon(wish_add_icon)) {
699 box_pack_append(wish_add_icon);
700 minictrl_cnt = box_get_count(MINICTRL_LIST);
701 if(minictrl_cnt==box_get_minictrl_list()) {
707 int noti_cnt = box_get_count(NOTI_LIST);
709 if (noti_cnt > box_get_enabled_noti_count()) {
710 while (noti_cnt > box_get_enabled_noti_count()) {
711 icon_s *wish_remove_icon = NULL;
712 wish_remove_icon = list_try_to_find_icon_to_remove(INDICATOR_ICON_AREA_NOTI, 0);
714 if (wish_remove_icon == NULL) {
718 box_unpack(wish_remove_icon);
719 noti_cnt = box_get_count(NOTI_LIST);
722 while (noti_cnt < box_get_enabled_noti_count()) {
723 icon_s *wish_add_icon = NULL;
724 wish_add_icon = list_try_to_find_icon_to_show(INDICATOR_ICON_AREA_NOTI, 0);
725 if (wish_add_icon == NULL) {
729 if (box_exist_icon(wish_add_icon)) {
733 box_pack_append(wish_add_icon);
734 noti_cnt = box_get_count(NOTI_LIST);
735 if(noti_cnt==box_get_enabled_noti_count()) {
744 static void _show_hide_more_noti(win_info* win, bool show)
746 int err = preference_set_boolean(INDICATOR_MORE_NOTI, show);
747 retm_if(err != PREFERENCE_ERROR_NONE, "preference_set_boolean failed: %s", get_error_message(err));
750 void icon_handle_more_notify_icon(win_info* win)
752 retm_if(win == NULL, "Invalid parameter!");
753 _D("icon_handle_more_notify_icon called !!");
754 /* int system_cnt = box_get_count(SYSTEM_LIST);
755 int minictrl_cnt = box_get_count(MINICTRL_LIST);
756 int noti_cnt = list_get_noti_count();
758 _D("System count : %d, Minictrl count : %d, Notification count : %d", system_cnt, minictrl_cnt, noti_cnt);
759 if(win->type == INDICATOR_WIN_PORT)
761 _D("PORT :: %d", (system_cnt + minictrl_cnt + noti_cnt));
762 if((system_cnt + minictrl_cnt + noti_cnt) > MAX_NOTI_ICONS_PORT)
764 _show_hide_more_noti(win, true);
765 _D("PORT :: handle_more_notify_show");
769 _show_hide_more_noti(win, false);
770 _D("PORT :: handle_more_notify_hide");
777 void* icon_util_make(void* input)
779 icon_s *icon = (icon_s *)input;
781 retvm_if(input == NULL, NULL, "Invalid parameter!");
784 obj = calloc(1, sizeof(icon_s));
787 memset(obj, 0, sizeof(icon_s));
788 memcpy(obj,input,sizeof(icon_s));
789 obj->name = strdup(icon->name);