used boolean defines from stdbool.h
[apps/core/preloaded/indicator-win.git] / src / box.c
1 /*
2  *  Indicator
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 //#include <Ecore_X.h>
21 #include <Eina.h>
22 #include <vconf.h>
23
24 #include "common.h"
25 #include "box.h"
26 #include "icon.h"
27 #include "list.h"
28 #include "main.h"
29 #include "indicator_gui.h"
30 #include "util.h"
31 #include "plmn.h"
32 #include "message.h"
33 #include "log.h"
34
35 #define FIXED_BOX_PART_NAME             "elm.swallow.fixed"
36 #define SYSTEM_BOX_PART_NAME    "elm.swallow.system"
37 #define MINICTRL_BOX_PART_NAME  "elm.swallow.minictrl"
38 #define NOTI_BOX_PART_NAME      "elm.swallow.noti"
39 #define DIGIT_BOX_PART_NAME "percentage.digit.box"
40
41 #define CORRECTION 10
42 #define MORE_NOTI "more_notify"
43
44 Eina_List *_view_fixed_list;
45 Eina_List *_view_system_list;
46 Eina_List *_view_minictrl_list;
47 Eina_List *_view_noti_list;
48 Eina_List *_view_alarm_list;
49
50 /* FIXME */
51 #if 0
52 win_info *_win;
53 #endif
54 static int icon_show_state = 0;
55 int previous_noti_count = 0;
56
57
58
59 static Evas_Object *_box_add(Evas_Object * parent)
60 {
61         Evas_Object *obj = NULL;
62
63         retv_if(!parent, NULL);
64
65         obj = elm_box_add(parent);
66         retv_if(!obj, NULL);
67         evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68         evas_object_size_hint_fill_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
69
70         /* Align to left-top */
71         elm_box_horizontal_set(obj, EINA_TRUE);
72         evas_object_show(obj);
73
74         return obj;
75 }
76
77
78 #if 0
79 static void _update_window(win_info *win)
80 {
81         int root_w, root_h;
82         Ecore_X_Window xwin, root;
83
84         retif(win == NULL, , "Invalid parameter!");
85
86         xwin = elm_win_xwindow_get(win->win);
87         if (!xwin) return;
88         root = ecore_x_window_root_get(xwin);
89         if (!root) return;
90         ecore_x_window_size_get(root, &root_w, &root_h);
91
92         if (win->angle == 0 || win->angle == 180) win->w = root_w;
93         else win->w = root_h;
94
95         switch (win->angle) {
96         case 0:
97                 ecore_x_window_shape_input_rectangle_set(xwin, root_w - win->w, 0, win->w, win->h);
98                 break;
99         case 90:
100                 ecore_x_window_shape_input_rectangle_set(xwin, 0, 0, win->h, win->w);
101                 break;
102         case 180:
103                 ecore_x_window_shape_input_rectangle_set(xwin, 0, 0, win->w, win->h);
104                 break;
105         case 270:
106                 ecore_x_window_shape_input_rectangle_set(xwin, 0, root_h - win->w, win->h, win->w);
107                 break;
108         default:
109                 break;
110         }
111 }
112 #endif
113
114 #if 0
115 void box_delete_noti_icon_all(win_info *win)
116 {
117         icon_s *icon;
118         Eina_List *l;
119
120         elm_box_unpack_all(win->_noti_box);
121
122         EINA_LIST_FOREACH(_view_noti_list, l, icon) {
123                 if (icon->obj_exist == EINA_TRUE) {
124                         if (icon_del(icon) == EINA_TRUE) {
125                                 icon->obj_exist = EINA_FALSE;
126                         }
127                 }
128         }
129 }
130 #endif
131
132
133 static void _fixed_box_pack_icon(win_info *win, icon_s *icon)
134 {
135         ret_if(!win);
136         ret_if(!icon);
137
138         switch (icon->type) {
139                 case INDICATOR_IMG_ICON:
140                         evas_object_show(icon->img_obj.obj);
141                         elm_box_pack_start(win->_fixed_box[icon->priority], icon->img_obj.obj);
142                         break;
143                 case INDICATOR_TXT_ICON:
144                         break;
145                 case INDICATOR_TXT_WITH_IMG_ICON:
146                         break;
147                 case INDICATOR_DIGIT_ICON:
148                         switch(icon->digit_area) {
149                                 case DIGIT_UNITY:
150                                         evas_object_show(icon->img_obj.obj);
151                                         elm_box_pack_end(win->_digit_box, icon->img_obj.obj);
152                                         break;
153                                 case DIGIT_DOZENS:
154                                         evas_object_show(icon->img_obj.obj);
155                                         elm_box_pack_end(win->_digit_box, icon->img_obj.obj);
156                                         break;
157                                 case DIGIT_DOZENS_UNITY:
158                                         evas_object_show(icon->img_obj.obj);
159                                         elm_box_pack_end(win->_digit_box, icon->img_obj.obj);
160                                         break;
161                                 case DIGIT_HUNDREDS:
162                                         evas_object_show(icon->img_obj.obj);
163                                         elm_box_pack_end(win->_digit_box, icon->img_obj.obj);
164                                         break;
165                                 default:
166                                         _E("default");
167                                         break;
168                         }
169                         break;
170                 default:
171                         _E("default");
172                         break;
173         }
174 #ifdef _SUPPORT_SCREEN_READER
175         util_icon_access_register(icon);
176 #endif
177 }
178
179
180
181 static void _box_pack_icon(icon_s *icon, Evas_Object *box)
182 {
183         ret_if(!icon);
184         ret_if(!box);
185
186         switch (icon->type) {
187         case INDICATOR_IMG_ICON:
188                 evas_object_show(icon->img_obj.obj);
189                 elm_box_pack_end(box, icon->img_obj.obj);
190                 break;
191         case INDICATOR_TXT_ICON:
192                 break;
193         case INDICATOR_TXT_WITH_IMG_ICON:
194                 break;
195         case INDICATOR_DIGIT_ICON:
196                 evas_object_show(icon->img_obj.obj);
197                 elm_box_pack_end(box, icon->img_obj.obj);
198                 break;
199         default:
200                 _E("default");
201                 break;
202         }
203 #ifdef _support_screen_reader
204         util_icon_access_register(icon);
205 #endif
206         if (icon->area == INDICATOR_ICON_AREA_NOTI || icon->area == INDICATOR_ICON_AREA_ALARM) {
207                 util_start_noti_ani(icon);
208         }
209 }
210
211
212
213 static void _create_img_obj(icon_s *icon)
214 {
215         Evas_Object *img_eo = NULL;
216
217         ret_if(!icon);
218
219         img_eo = evas_object_data_get(icon->img_obj.obj, DATA_KEY_IMG_ICON);
220         evas_object_size_hint_min_set(img_eo, ELM_SCALE_SIZE(icon->img_obj.width), ELM_SCALE_SIZE(icon->img_obj.height));
221         box_handle_animated_gif(icon);
222 }
223
224
225
226 static void _update_icon(win_info *win, Eina_List *list)
227 {
228         icon_s *icon;
229         Eina_List *l;
230
231         ret_if(!win);
232         ret_if(!list);
233
234         EINA_LIST_FOREACH(list, l, icon) {
235                 if (icon->obj_exist == EINA_FALSE) {
236                         icon_add(win, icon);
237                 }
238
239                 if (icon->obj_exist == EINA_TRUE) {
240                         if (icon->area == INDICATOR_ICON_AREA_FIXED
241                         && icon->priority <= INDICATOR_PRIORITY_FIXED_MAX) {
242                                 _create_img_obj(icon);
243                                 _fixed_box_pack_icon(win, icon);
244                         }
245                         if (icon->area == INDICATOR_ICON_AREA_SYSTEM
246                         && icon->priority >= INDICATOR_PRIORITY_SYSTEM_MIN
247                         && icon->priority <= INDICATOR_PRIORITY_SYSTEM_MAX) {
248                                 _create_img_obj(icon);
249                                 _box_pack_icon(icon, win->_non_fixed_box);
250                         }
251                         if (icon->area == INDICATOR_ICON_AREA_MINICTRL
252                         && icon->priority >= INDICATOR_PRIORITY_MINICTRL_MIN
253                         && icon->priority <= INDICATOR_PRIORITY_MINICTRL_MAX) {
254                                 _create_img_obj(icon);
255                                 _box_pack_icon(icon, win->_minictrl_box);
256                         }
257                         if (icon->area == INDICATOR_ICON_AREA_NOTI) {
258                                 _create_img_obj(icon);
259                                 _box_pack_icon(icon, win->_noti_box);
260                         }
261                         if (icon->area == INDICATOR_ICON_AREA_ALARM) {
262                                 _create_img_obj(icon);
263                                 _box_pack_icon(icon, win->_alarm_box);
264                         }
265                 }
266         }
267 }
268
269
270
271 extern unsigned int box_get_count(Box_List list)
272 {
273         int count = 0;
274
275         switch (list) {
276         case FIXED_LIST:
277                 count = eina_list_count(_view_fixed_list);
278                 break;
279         case SYSTEM_LIST:
280                 count = eina_list_count(_view_system_list);
281                 break;
282         case MINICTRL_LIST:
283                 count = eina_list_count(_view_minictrl_list);
284                 break;
285         case NOTI_LIST:
286                 count = eina_list_count(_view_noti_list);
287                 break;
288         default:
289                 _D("List dose not exist");
290                 break;
291         }
292
293         return count;
294 }
295
296
297
298 static void _update_display(win_info *win)
299 {
300         int i = 0;
301
302         ret_if(!win);
303
304         if (box_get_count(SYSTEM_LIST)) {
305                 util_signal_emit(win->data, "indicator.system.show", "indicator.prog");
306         } else {
307                 util_signal_emit(win->data, "indicator.system.hide", "indicator.prog");
308         }
309
310         if (box_get_count(MINICTRL_LIST)) {
311                 util_signal_emit(win->data, "indicator.minictrl.show", "indicator.prog");
312         } else {
313                 util_signal_emit(win->data, "indicator.minictrl.hide", "indicator.prog");
314         }
315
316         if (box_get_count(NOTI_LIST)) {
317                 util_signal_emit(win->data, "indicator.noti.show", "indicator.prog");
318         } else {
319                 util_signal_emit(win->data, "indicator.noti.hide", "indicator.prog");
320         }
321
322
323         if (message_ani_playing_check() == 1) {
324                 return;
325         }
326
327         for (i = 0; i < FIXED_COUNT; ++i) {
328                 elm_box_unpack_all(win->_fixed_box[i]);
329         }
330
331         elm_box_unpack_all(win->_non_fixed_box);
332         elm_box_unpack_all(win->_minictrl_box);
333         elm_box_unpack_all(win->_noti_box);
334         elm_box_unpack_all(win->_alarm_box);
335         elm_box_unpack_all(win->_digit_box);
336
337         _update_icon(win, _view_fixed_list);
338         _update_icon(win, _view_system_list);
339         _update_icon(win, _view_minictrl_list);
340         _update_icon(win, _view_noti_list);
341         _update_icon(win, _view_alarm_list);
342
343 #if 0
344         if (win) _update_window(win);
345 #endif
346 }
347
348
349
350 extern void box_update_display(win_info *win)
351 {
352         ret_if(!win);
353
354 #if 0
355         _update_window(win);
356 #endif
357         icon_reset_list();
358         _update_display(win);
359         icon_handle_more_notify_icon(win);
360 }
361
362
363
364 extern int box_pack(icon_s *icon)
365 {
366         struct appdata *ad = NULL;
367         int noti_count = 0;
368
369         retv_if(!icon, 0);
370
371         ad = (struct appdata*)icon->ad;
372
373         if (box_exist_icon(icon)) return OK;
374
375         if (INDICATOR_ICON_AREA_FIXED == icon->area) {
376                 icon->exist_in_view = EINA_TRUE;
377                 _view_fixed_list = eina_list_append(_view_fixed_list, icon);
378         } else if(INDICATOR_ICON_AREA_SYSTEM == icon->area) {
379                 icon_s *data;
380                 Eina_List *l = NULL;
381
382                 EINA_LIST_FOREACH(_view_system_list, l, data) {
383                         if (data->priority <= icon->priority) {
384                                 icon->exist_in_view = EINA_TRUE;
385                                 _view_system_list = eina_list_append_relative_list(_view_system_list, icon, l);
386                                 DBG("System (eina_list_append_relative_list) %s",icon->name);
387                                 goto __CATCH;
388                         }
389                 }
390
391                 /* if finding condition is failed, append it at tail */
392                 icon->exist_in_view = EINA_TRUE;
393                 _view_system_list = eina_list_prepend(_view_system_list, icon);
394                 DBG("System prepend (Priority low) : %s",icon->name);
395         } else if(INDICATOR_ICON_AREA_MINICTRL == icon->area) {
396                 INFO("Pack to MINICTRL list : %s", icon->name);
397                 icon_s *data;
398                 Eina_List *l;
399
400                 EINA_LIST_FOREACH(_view_minictrl_list, l, data) {
401                         if (data->priority <= icon->priority) {
402                                 icon->exist_in_view = EINA_TRUE;
403                                 _view_minictrl_list = eina_list_append_relative_list(_view_minictrl_list, icon, l);
404                                 goto __CATCH;
405                         }
406                 }
407
408                 /* if finding condition is failed, append it at tail */
409                 icon->exist_in_view = EINA_TRUE;
410                 _view_minictrl_list = eina_list_append(_view_minictrl_list, icon);
411         } else if(INDICATOR_ICON_AREA_NOTI == icon->area) {
412                 if(strncmp(icon->name, MORE_NOTI, strlen(MORE_NOTI))==0)
413                 {
414                         icon->exist_in_view = EINA_TRUE;
415                         _view_noti_list = eina_list_prepend(_view_noti_list, icon);
416                         goto __CATCH;
417                 }
418
419                 /* if finding condition is failed, append it at tail */
420                 icon->exist_in_view = EINA_TRUE;
421                 _view_noti_list = eina_list_append(_view_noti_list, icon);
422         } else {
423                 icon->exist_in_view = EINA_TRUE;
424                 _view_alarm_list = eina_list_append(_view_alarm_list, icon);
425         }
426
427 __CATCH:
428         previous_noti_count = noti_count;
429         if (icon->area == INDICATOR_ICON_AREA_NOTI
430                         || icon->area == INDICATOR_ICON_AREA_SYSTEM
431                         || icon->area == INDICATOR_ICON_AREA_MINICTRL) {
432                 int bDisplay = 0;
433                 bDisplay = 1;
434
435                 if (ad->opacity_mode == INDICATOR_OPACITY_TRANSPARENT
436                                 && bDisplay == 1) {
437                         util_send_status_message_start(ad,2.5);
438                 }
439         }
440
441         return OK;
442 }
443
444
445
446 extern int box_pack_append(icon_s *icon)
447 {
448         Eina_List *l;
449         icon_s *data;
450
451         retv_if(!icon, 0);
452
453         if (box_exist_icon(icon)) return OK;
454
455         switch (icon->area) {
456         case INDICATOR_ICON_AREA_FIXED:
457                 icon->exist_in_view = EINA_TRUE;
458                 _view_fixed_list = eina_list_append(_view_fixed_list, icon);
459                 break;
460         case INDICATOR_ICON_AREA_SYSTEM:
461                 icon->exist_in_view = EINA_TRUE;
462                 _view_system_list = eina_list_append(_view_system_list, icon);
463                 break;
464         case INDICATOR_ICON_AREA_MINICTRL:
465                 icon->exist_in_view = EINA_TRUE;
466                 _view_minictrl_list = eina_list_append(_view_minictrl_list, icon);
467                 break;
468         case INDICATOR_ICON_AREA_NOTI:
469                 EINA_LIST_FOREACH(_view_noti_list, l, data) {
470                         if (strncmp(data->name, MORE_NOTI, strlen(MORE_NOTI)) == 0) {
471                                 icon->exist_in_view = EINA_TRUE;
472                                 _view_noti_list = eina_list_append_relative_list(_view_noti_list, icon, l);
473                                 return OK;
474                         }
475                 }
476                 icon->exist_in_view = EINA_TRUE;
477                 _view_noti_list = eina_list_append(_view_noti_list, icon);
478                 break;
479         default:
480                 _D("Icon area does not exists");
481                 break;
482         }
483
484         return OK;
485 }
486
487
488
489 int box_unpack(icon_s *icon)
490 {
491         retv_if(!icon, 0);
492
493         SECURE_DBG("[box_unpack] %s!",icon->name);
494         switch (icon->area) {
495         case INDICATOR_ICON_AREA_FIXED:
496                 icon->exist_in_view = EINA_FALSE;
497                 _view_fixed_list = eina_list_remove(_view_fixed_list, icon);
498                 break;
499         case INDICATOR_ICON_AREA_SYSTEM:
500                 icon->exist_in_view = EINA_FALSE;
501                 _view_system_list = eina_list_remove(_view_system_list, icon);
502                 break;
503         case INDICATOR_ICON_AREA_MINICTRL:
504                 icon->exist_in_view = EINA_FALSE;
505                 _view_minictrl_list = eina_list_remove(_view_minictrl_list, icon);
506                 break;
507         case INDICATOR_ICON_AREA_NOTI:
508                 icon->exist_in_view = EINA_FALSE;
509                 _view_noti_list = eina_list_remove(_view_noti_list, icon);
510                 break;
511         case INDICATOR_ICON_AREA_ALARM:
512                 icon->exist_in_view = EINA_FALSE;
513                 _view_alarm_list = eina_list_remove(_view_alarm_list, icon);
514                 break;
515         default:
516                 _D("icon area dose not exists");
517                 break;
518         }
519
520 #if 0
521         int noti_count = 0;
522
523         noti_count = box_get_count(NOTI_LIST);
524         if (noti_count > 0) {
525                 util_signal_emit(_win->data, "indicator.noti.show", "indicator.prog");
526         } else {
527                 DBG("Need to stop blink animation and hide icon");
528                 util_signal_emit_by_win(_win->data,"indicator.noti.hide", "indicator.prog");
529         }
530 #endif
531 #ifdef _SUPPORT_SCREEN_READER
532         util_icon_access_unregister(icon);
533 #endif
534
535         if (icon->obj_exist == EINA_TRUE) {
536                 if (icon_del(icon) == EINA_TRUE) {
537                         icon->obj_exist = EINA_FALSE;
538                 }
539         }
540
541         return OK;
542 }
543
544
545
546 extern void box_init(win_info *win)
547 {
548         char *str_text = NULL;
549         int i = 0;
550
551         ret_if(!win);
552
553         /* Make Fixed Box Object */
554         for (i = 0; i < FIXED_COUNT; ++i) {
555                 if (win->_fixed_box[i] == NULL) {
556                         win->_fixed_box[i] = _box_add(win->layout);
557                         ret_if(!(win->_fixed_box[i]));
558
559                         Eina_Strbuf *temp_str = eina_strbuf_new();
560                         eina_strbuf_append_printf(temp_str, "%s%d", FIXED_BOX_PART_NAME, i);
561                         str_text = eina_strbuf_string_steal(temp_str);
562
563                         edje_object_part_swallow(elm_layout_edje_get(win->layout), str_text, win->_fixed_box[i]);
564                         eina_strbuf_free(temp_str);
565                         free(str_text);
566                 }
567         }
568
569         /* Make Non Fixed Box(SYSTEM) Object */
570         win->_non_fixed_box = _box_add(win->layout);
571         ret_if(!(win->_non_fixed_box));
572
573         evas_object_size_hint_align_set(win->_non_fixed_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
574         edje_object_part_swallow(elm_layout_edje_get(win->layout), SYSTEM_BOX_PART_NAME, win->_non_fixed_box);
575
576         /* Make Non Fixed Box(MINICTRL) Object */
577         win->_minictrl_box = _box_add(win->layout);
578         ret_if(!(win->_minictrl_box));
579
580         evas_object_size_hint_align_set(win->_minictrl_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
581         edje_object_part_swallow(elm_layout_edje_get(win->layout), MINICTRL_BOX_PART_NAME, win->_minictrl_box);
582
583         /* Make Non Fixed Box(NOTI) Box Object */
584         win->_noti_box = _box_add(win->layout);
585         ret_if(!(win->_noti_box));
586
587         evas_object_size_hint_align_set(win->_noti_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
588         edje_object_part_swallow(elm_layout_edje_get(win->layout), NOTI_BOX_PART_NAME, win->_noti_box);
589
590         win->_alarm_box = _box_add(win->layout);
591         ret_if(!(win->_alarm_box));
592
593         evas_object_size_hint_align_set(win->_alarm_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
594         edje_object_part_swallow(elm_layout_edje_get(win->layout), "indicator.alarm.icon", win->_alarm_box);
595
596         win->_digit_box = _box_add(win->layout);
597         ret_if(!(win->_digit_box));
598
599         evas_object_size_hint_align_set(win->_digit_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
600         edje_object_part_swallow(elm_layout_edje_get(win->layout), DIGIT_BOX_PART_NAME, win->_digit_box);
601
602         return;
603 }
604
605
606
607
608 extern void box_fini(win_info *win)
609 {
610         int i = 0;
611
612         ret_if(!win);
613         ret_if(!(win->layout));
614
615         if (win->_digit_box != NULL) {
616                 edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_digit_box);
617                 elm_box_unpack_all(win->_digit_box);
618                 evas_object_del(win->_digit_box);
619                 win->_digit_box = NULL;
620         }
621
622         if (win->_non_fixed_box != NULL) {
623                 edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_non_fixed_box);
624                 elm_box_unpack_all(win->_non_fixed_box);
625                 evas_object_del(win->_non_fixed_box);
626                 win->_non_fixed_box = NULL;
627         }
628
629         if (win->_minictrl_box != NULL) {
630                 edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_minictrl_box);
631                 elm_box_unpack_all(win->_minictrl_box);
632                 evas_object_del(win->_minictrl_box);
633                 win->_minictrl_box = NULL;
634         }
635
636         if (win->_noti_box != NULL) {
637                 edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_noti_box);
638                 elm_box_unpack_all(win->_noti_box);
639                 evas_object_del(win->_noti_box);
640                 win->_noti_box = NULL;
641         }
642
643         if (win->_alarm_box != NULL) {
644                 edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_alarm_box);
645                 elm_box_unpack_all(win->_alarm_box);
646                 evas_object_del(win->_alarm_box);
647                 win->_alarm_box = NULL;
648         }
649
650         for (i = 0; i < FIXED_COUNT; ++i) {
651                 if (win->_fixed_box[i] != NULL) {
652                         edje_object_part_unswallow(elm_layout_edje_get(win->layout), win->_fixed_box[i]);
653                         elm_box_unpack_all(win->_fixed_box[i]);
654                         evas_object_del(win->_fixed_box[i]);
655                         win->_fixed_box[i] = NULL;
656                 }
657         }
658
659         return;
660 }
661
662
663
664 unsigned int box_get_count_in_noti_list_except_minictrl(void)
665 {
666         icon_s *data;
667         Eina_List *l;
668         int count = 0;
669
670         EINA_LIST_FOREACH(_view_noti_list, l, data) {
671                 if (data->priority != INDICATOR_PRIORITY_NOTI_1) {
672                         count++;
673                 }
674         }
675         return count;
676
677 }
678
679
680
681 int box_get_enabled_noti_count(void)
682 {
683         int enabled_noti_cnt = 0;
684
685         int system_cnt = box_get_count(SYSTEM_LIST);
686         int minictrl_cnt = box_get_count(MINICTRL_LIST);
687         DBG("System Count : %d, Minictrl Count : %d", system_cnt, minictrl_cnt);
688
689         enabled_noti_cnt = MAX_NOTI_ICONS_PORT - system_cnt - minictrl_cnt;
690         if(enabled_noti_cnt <= 0) {
691                 enabled_noti_cnt = 1;    // Notification icon must show at least 1.
692         }
693
694         DBG("Notification icon enabled_noti_cnt %d",enabled_noti_cnt);
695
696         return enabled_noti_cnt;
697 }
698
699
700
701 int box_get_enabled_system_count(void)
702 {
703         int system_cnt = 0;
704         int noti_cnt = box_get_count(NOTI_LIST);
705         int minictrl_cnt = box_get_count(MINICTRL_LIST);
706
707         _D("Noti count : %d , MiniCtrl count : %d", noti_cnt, minictrl_cnt);
708
709         system_cnt = PORT_SYSTEM_ICON_COUNT;  // MAX = 5.
710
711         if(noti_cnt > 0) {
712                 system_cnt--;    // Notification icon must show at least 1.
713         }
714
715         if(minictrl_cnt > 0) {
716                 system_cnt--;    // Minictrl icon must show at least 1.
717         }
718
719         return system_cnt;
720 }
721
722
723
724 int box_get_minictrl_list(void)
725 {
726         int icon_count = 0;
727         int noti_count = box_get_count(NOTI_LIST);
728         int system_count = box_get_count(SYSTEM_LIST);
729
730         icon_count = PORT_MINICTRL_ICON_COUNT; // = 2.    MIN (1) / MAX (3)
731
732         if(noti_count) {        // noti_count >= 1
733                 if(system_count >= 3) {
734                         icon_count--;   // icon_count = 2 -> 1
735                 } else if(system_count <= 1) {
736                         icon_count++;   // icon_count = 2 -> 3
737                 }
738         } else {        // noti_count == 0
739                 if(system_count >= 4) {
740                         icon_count--;   // icon_count = 2 -> 1
741                 } else if(system_count <= 2) {
742                         icon_count++;   // icon_count = 2 -> 3
743                 }
744         }
745
746         _D("Noti count : %d, System count : %d, Minictrl count : %d", noti_count, system_count, icon_count);
747
748         return icon_count;
749 }
750
751
752
753 int box_get_max_count_in_non_fixed_list(void)
754 {
755         int added_count = 0;
756         int icon_count = 0;
757         int status = 0;
758
759         if (OK != vconf_get_bool(VCONFKEY_SETAPPL_BATTERY_PERCENTAGE_BOOL, &status)) {
760                 _E("Fail to get vconfkey");
761         }
762
763         if (status == EINA_TRUE) {
764                 added_count = BATTERY_TEXT_ON_COUNT;
765         } else {
766                 added_count = BATTERY_TEXT_OFF_COUNT;
767         }
768
769         icon_count = PORT_NONFIXED_ICON_COUNT + added_count;
770
771         return icon_count;
772 }
773
774
775
776 Icon_AddType box_is_enable_to_insert_in_non_fixed_list(icon_s *obj)
777 {
778         icon_s *icon;
779         Eina_List *l;
780
781         int higher_cnt = 0;
782         int same_cnt = 0;
783         int same_top_cnt = 0;
784         int lower_cnt = 0;
785         int noti_cnt = box_get_count(NOTI_LIST);
786         Eina_List * tmp_list = NULL;
787
788         retv_if(!obj, 0);
789
790         switch (obj->area) {
791         case INDICATOR_ICON_AREA_SYSTEM:
792                 tmp_list = _view_system_list;
793                 break;
794         case INDICATOR_ICON_AREA_MINICTRL:
795                 tmp_list = _view_minictrl_list;
796                 break;
797         case INDICATOR_ICON_AREA_NOTI:
798                 tmp_list = _view_noti_list;
799                 break;
800         default:
801                 _D("obj area does not exists");
802                 break;
803         }
804
805         EINA_LIST_FOREACH(tmp_list, l, icon) {
806                 /* If same Icon exist in non-fixed view list, it need not to add icon */
807                 if (!strcmp(icon->name, obj->name)) {
808                         return CANNOT_ADD;
809                 }
810
811                 if (icon->priority > obj->priority) {
812                         ++higher_cnt;
813                 } else if (icon->priority == obj->priority) {
814                         ++same_cnt;
815                         if (icon->always_top == EINA_TRUE) {
816                                 ++same_top_cnt;
817                         }
818                 } else {
819                         lower_cnt++;
820                 }
821         }
822
823         if (obj->area == INDICATOR_ICON_AREA_SYSTEM) {
824                 if (higher_cnt + same_cnt + lower_cnt >= box_get_enabled_system_count()) {
825                         if (obj->always_top == EINA_TRUE) {
826                                 if(same_top_cnt >= box_get_enabled_system_count()) {
827                                         return CANNOT_ADD;
828                                 } else {
829                                         return CAN_ADD_WITH_DEL_SYSTEM;
830                                 }
831                         } else {
832                                 if (higher_cnt >= box_get_enabled_system_count()) {
833                                         return CANNOT_ADD;
834                                 } else if (higher_cnt+same_cnt >= box_get_enabled_system_count()) {
835                                         return CAN_ADD_WITH_DEL_SYSTEM;
836                                 } else {
837                                         return CAN_ADD_WITH_DEL_SYSTEM;
838                                 }
839                         }
840                 } else {
841                         return CAN_ADD_WITHOUT_DEL;
842                 }
843         } else if (obj->area == INDICATOR_ICON_AREA_MINICTRL) {
844                 if (higher_cnt + same_cnt + lower_cnt >= box_get_minictrl_list()) {
845                         if (obj->always_top == EINA_TRUE) {
846                                 if (same_top_cnt >= box_get_minictrl_list()) {
847                                         return CANNOT_ADD;
848                                 } else {
849                                         return CAN_ADD_WITH_DEL_MINICTRL;
850                                 }
851                         } else {
852                                 if (higher_cnt >= box_get_minictrl_list()) {
853                                         return CANNOT_ADD;
854                                 } else if (higher_cnt+same_cnt >= box_get_minictrl_list()) {
855                                         return CAN_ADD_WITH_DEL_MINICTRL;
856                                 } else {
857                                         return CAN_ADD_WITH_DEL_MINICTRL;
858                                 }
859                         }
860                 } else {
861                         return CAN_ADD_WITHOUT_DEL;
862                 }
863         } else {
864                 if (noti_cnt > MAX_NOTI_ICONS_PORT) {
865                         return CAN_ADD_WITH_DEL_NOTI;
866                 } else {
867                         return CAN_ADD_WITHOUT_DEL;
868                 }
869         }
870
871         return CANNOT_ADD;
872 }
873
874
875
876 int box_get_priority_in_move_area(win_info *win, Evas_Coord curr_x, Evas_Coord curr_y)
877 {
878         Evas_Coord x, y, h, w;
879
880         /* Home Area Check for launching home */
881         evas_object_geometry_get(win->_fixed_box[INDICATOR_PRIORITY_FIXED1], &x, &y, &h, &w);
882
883         if (curr_x >= x - CORRECTION && curr_x <= x+h + CORRECTION) {
884                 if (curr_y == -1) {
885                         return INDICATOR_PRIORITY_FIXED1;
886                 } else if (curr_y >= y - CORRECTION && curr_y <= y+h + CORRECTION) {
887                         return INDICATOR_PRIORITY_FIXED1;
888                 }
889         }
890
891         /* Non Fixed Area check for show/hide quickpanel */
892         return -1;
893 }
894
895
896
897 int box_check_indicator_area(win_info *win, Evas_Coord curr_x, Evas_Coord curr_y)
898 {
899         Evas_Coord x, y, w, h;
900
901         /* Home Area Check for launching home */
902         evas_object_geometry_get(win->layout, &x, &y, &w, &h);
903
904         if (curr_x >= x && curr_x < x + w && curr_y >= y && curr_y < y + h) {
905                 return 1;
906         }
907
908         return 0;
909 }
910
911
912
913 int box_check_home_icon_area(win_info *win, Evas_Coord curr_x, Evas_Coord curr_y)
914 {
915         Evas_Coord x, y, w, h;
916
917         /* Home Area Check for launching home */
918         evas_object_geometry_get(win->_fixed_box[INDICATOR_PRIORITY_FIXED7], &x, &y, &w, &h);
919
920         if (curr_x >= x && curr_x < x + w && curr_y >= y && curr_y < y + h) {
921                 return 1;
922         }
923
924         return 0;
925 }
926
927
928
929 int box_check_more_icon_area(win_info *win, Evas_Coord curr_x, Evas_Coord curr_y)
930 {
931         Evas_Coord x, y, w, h;
932
933         /* Home Area Check for launching home */
934         evas_object_geometry_get(win->_fixed_box[INDICATOR_PRIORITY_FIXED11], &x, &y, &w, &h);
935
936         if (curr_x >= x && curr_x < x + w && curr_y >= y && curr_y < y + h) {
937                 return 1;
938         }
939
940         return 0;
941 }
942
943
944
945 void box_icon_state_set(int bShow, char* file, int line)
946 {
947         icon_show_state = bShow;
948 }
949
950
951
952 int box_icon_state_get(void)
953 {
954         return icon_show_state;
955 }
956
957
958
959 extern Eina_Bool box_exist_icon(icon_s *obj)
960 {
961         retv_if(!obj, ECORE_CALLBACK_CANCEL);
962
963         switch (obj->area) {
964         case INDICATOR_ICON_AREA_FIXED:
965                 if (eina_list_data_find(_view_fixed_list, obj)) {
966                         return EINA_TRUE;
967                 } else {
968                         return EINA_FALSE;
969                 }
970                 break;
971         case INDICATOR_ICON_AREA_SYSTEM:
972                 if (eina_list_data_find(_view_system_list, obj)) {
973                         return EINA_TRUE;
974                 } else {
975                         return EINA_FALSE;
976                 }
977                 break;
978         case INDICATOR_ICON_AREA_MINICTRL:
979                 if (eina_list_data_find(_view_minictrl_list, obj)) {
980                         return EINA_TRUE;
981                 } else {
982                         return EINA_FALSE;
983                 }
984                 break;
985         case INDICATOR_ICON_AREA_NOTI:
986                 if (eina_list_data_find(_view_noti_list, obj)) {
987                         return EINA_TRUE;
988                 } else {
989                         return EINA_FALSE;
990                 }
991                 break;
992         default:
993                 break;
994         }
995
996         return EINA_FALSE;
997 }
998
999
1000
1001 int box_handle_animated_gif(icon_s *icon)
1002 {
1003         int bPlay = true;
1004         int val = 0;
1005         Evas_Object *icon_eo = evas_object_data_get(icon->img_obj.obj, DATA_KEY_IMG_ICON);
1006
1007         retif(icon == NULL, FAIL, "Invalid parameter!");
1008
1009         if (elm_image_animated_available_get(icon_eo) == EINA_FALSE) {
1010                 return false;
1011         }
1012
1013         if (vconf_get_int(VCONFKEY_PM_STATE, &val) < 0) {
1014                 return false;
1015         }
1016
1017         switch (val) {
1018         case VCONFKEY_PM_STATE_LCDOFF : //LCD OFF
1019                 bPlay = false;
1020                 break;
1021         case VCONFKEY_PM_STATE_NORMAL : //LCD ON
1022                 bPlay = true;
1023                 break;
1024         default:
1025                 bPlay = true;
1026                 break;
1027         }
1028
1029         if (bPlay == true) {
1030                 if (elm_image_animated_get(icon_eo)==EINA_FALSE) {
1031                         elm_image_animated_set(icon_eo,EINA_TRUE);
1032                 }
1033
1034                 if (elm_image_animated_play_get(icon_eo) == EINA_FALSE) {
1035                         elm_image_animated_play_set(icon_eo, EINA_TRUE);
1036                 }
1037         } else {
1038                 if(elm_image_animated_play_get(icon_eo) == EINA_TRUE) {
1039                         elm_image_animated_play_set(icon_eo, EINA_FALSE);
1040                 }
1041         }
1042
1043         return true;
1044 }
1045
1046
1047
1048 void box_noti_ani_handle(int bStart)
1049 {
1050         icon_s *icon;
1051         Eina_List *l;
1052
1053         EINA_LIST_FOREACH(_view_noti_list, l, icon) {
1054                 if (icon->obj_exist == EINA_TRUE) {
1055                         if (bStart == 1) {
1056                                 util_start_noti_ani(icon);
1057                         } else {
1058                                 util_stop_noti_ani(icon);
1059                         }
1060                 }
1061         }
1062 }
1063
1064 /* End of file */