2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <appcore-common.h>
22 #include <app_service.h>
23 #include <runtime_info.h>
26 #include <unicode/uloc.h>
27 #include <unicode/udat.h>
28 #include <unicode/udatpg.h>
29 #include <unicode/ustring.h>
30 #include <notification.h>
32 #include "quickpanel-ui.h"
33 #include "quickpanel_def.h"
35 #include "noti_node.h"
36 #include "noti_gridbox.h"
38 #include "noti_listbox.h"
39 #include "noti_list_item.h"
40 #include "noti_section.h"
42 #include "list_util.h"
44 #ifndef VCONFKEY_QUICKPANEL_STARTED
45 #define VCONFKEY_QUICKPANEL_STARTED "memory/private/"PACKAGE_NAME"/started"
46 #endif /* VCONFKEY_QUICKPANEL_STARTED */
48 #define QP_NOTI_DAY_DEC (24 * 60 * 60)
50 #define QP_NOTI_ONGOING_DBUS_PATH "/dbus/signal"
51 #define QP_NOTI_ONGOING_DBUS_INTERFACE "notification.ongoing"
53 static noti_node *g_noti_node;
54 static Evas_Object *g_noti_section;
55 static Evas_Object *g_noti_listbox;
56 static Evas_Object *g_noti_gridbox;
57 static Eina_List *g_animated_image_list;
59 static int quickpanel_noti_init(void *data);
60 static int quickpanel_noti_fini(void *data);
61 static int quickpanel_noti_suspend(void *data);
62 static int quickpanel_noti_resume(void *data);
63 static void quickpanel_noti_lang_changed(void *data);
64 static void quickpanel_noti_refresh(void *data);
68 .init = quickpanel_noti_init,
69 .fini = quickpanel_noti_fini,
70 .suspend = quickpanel_noti_suspend,
71 .resume = quickpanel_noti_resume,
72 .lang_changed = quickpanel_noti_lang_changed,
75 .refresh = quickpanel_noti_refresh,
79 static notification_h _quickpanel_noti_update_item_progress(const char *pkgname,
83 char *noti_pkgname = NULL;
86 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
88 if (node != NULL && node->noti != NULL) {
89 notification_get_pkgname(node->noti, ¬i_pkgname);
90 notification_get_id(node->noti, NULL, ¬i_priv_id);
91 if (!strcmp(noti_pkgname, pkgname)
92 && priv_id == noti_priv_id) {
94 if (notification_set_progress(node->noti, progress) != NOTIFICATION_ERROR_NONE) {
95 ERR("fail to set progress");
104 static notification_h _quickpanel_noti_update_item_size(const char *pkgname,
108 char *noti_pkgname = NULL;
109 int noti_priv_id = 0;
111 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
113 if (node != NULL && node->noti != NULL) {
114 notification_get_pkgname(node->noti, ¬i_pkgname);
115 notification_get_id(node->noti, NULL, ¬i_priv_id);
116 if (!strcmp(noti_pkgname, pkgname)
117 && priv_id == noti_priv_id) {
118 notification_set_size(node->noti, size);
126 static notification_h _quickpanel_noti_update_item_content(const char *pkgname,
130 char *noti_pkgname = NULL;
131 int noti_priv_id = 0;
133 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
135 if (node != NULL && node->noti != NULL) {
136 notification_get_pkgname(node->noti, ¬i_pkgname);
137 notification_get_id(node->noti, NULL, ¬i_priv_id);
138 if (!strcmp(noti_pkgname, pkgname)
139 && priv_id == noti_priv_id) {
140 notification_set_text(node->noti,
141 NOTIFICATION_TEXT_TYPE_CONTENT,
143 NOTIFICATION_VARIABLE_TYPE_NONE);
151 static void _quickpanel_noti_update_progressbar(void *data,
152 notification_h update_noti)
154 struct appdata *ad = NULL;
155 Elm_Object_Item *found = NULL;
156 noti_node_item *node = NULL;
158 retif(!data, , "data is NULL");
161 retif(!ad->list, , "ad->list is NULL");
165 if (notification_get_id(update_noti, NULL, &priv_id) == NOTIFICATION_ERROR_NONE) {
166 node = noti_node_get(g_noti_node, priv_id);
173 retif(node == NULL, , "fail to find node of priv_id:%d", priv_id);
174 retif(node->view == NULL, , "fail to find %p", node->view);
176 listbox_update_item(g_noti_listbox, node->view);
179 static void _quickpanel_noti_item_progress_update_cb(void *data,
186 notification_h noti = NULL;
188 retif(data == NULL || msg == NULL, , "Invalid parameter!");
190 dbus_error_init(&err);
191 dbus_message_get_args(msg, &err,
192 DBUS_TYPE_STRING, &pkgname,
193 DBUS_TYPE_INT32, &priv_id,
194 DBUS_TYPE_DOUBLE, &progress,
197 if (dbus_error_is_set(&err)) {
198 ERR("dbus err: %s", err.message);
199 dbus_error_free(&err);
203 if (pkgname == NULL) {
204 ERR("pkgname is null");
208 /* check item on the list */
209 noti = _quickpanel_noti_update_item_progress(pkgname,
211 retif(noti == NULL, , "Can not found noti data.");
213 DBG("pkgname[%s], priv_id[%d], progress[%lf]",
214 pkgname, priv_id, progress);
215 if (!quickpanel_is_suspended())
216 _quickpanel_noti_update_progressbar(data, noti);
219 static void _quickpanel_noti_item_size_update_cb(void *data, DBusMessage * msg)
225 notification_h noti = NULL;
227 retif(data == NULL || msg == NULL, , "Invalid parameter!");
229 dbus_error_init(&err);
230 dbus_message_get_args(msg, &err,
231 DBUS_TYPE_STRING, &pkgname,
232 DBUS_TYPE_INT32, &priv_id,
233 DBUS_TYPE_DOUBLE, &size, DBUS_TYPE_INVALID);
234 if (dbus_error_is_set(&err)) {
235 ERR("dbus err: %s", err.message);
236 dbus_error_free(&err);
240 if (pkgname == NULL) {
241 ERR("pkgname is null");
245 /* check item on the list */
246 noti = _quickpanel_noti_update_item_size(pkgname, priv_id, size);
247 retif(noti == NULL, , "Can not found noti data.");
249 DBG("pkgname[%s], priv_id[%d], progress[%lf]",
250 pkgname, priv_id, size);
252 if (!quickpanel_is_suspended())
253 _quickpanel_noti_update_progressbar(data, noti);
256 static void _quickpanel_noti_item_content_update_cb(void *data,
260 char *pkgname = NULL;
262 char *content = NULL;
263 notification_h noti = NULL;
265 retif(data == NULL || msg == NULL, , "Invalid parameter!");
267 dbus_error_init(&err);
268 dbus_message_get_args(msg, &err,
269 DBUS_TYPE_STRING, &pkgname,
270 DBUS_TYPE_INT32, &priv_id,
271 DBUS_TYPE_STRING, &content, DBUS_TYPE_INVALID);
273 if (pkgname == NULL) {
274 ERR("pkgname is null");
277 if (content == NULL) {
278 ERR("content is null");
282 if (dbus_error_is_set(&err)) {
283 ERR("dbus err: %s", err.message);
284 dbus_error_free(&err);
288 DBG("pkgname[%s], priv_id[%d], content[%s]",
289 pkgname, priv_id, content);
291 /* check item on the list */
292 noti = _quickpanel_noti_update_item_content(pkgname, priv_id, content);
293 retif(noti == NULL, , "Can not found noti data.");
295 if (!quickpanel_is_suspended())
296 _quickpanel_noti_update_progressbar(data, noti);
299 char *quickpanel_noti_get_time(time_t t, char *buf, int buf_len)
301 UErrorCode status = U_ZERO_ERROR;
302 UDateTimePatternGenerator *generator;
303 UDateFormat *formatter;
304 UChar skeleton[40] = { 0 };
305 UChar pattern[40] = { 0 };
306 UChar formatted[40] = { 0 };
307 int32_t patternCapacity, formattedCapacity;
308 int32_t skeletonLength, patternLength, formattedLength;
311 const char customSkeleton[] = UDAT_YEAR_NUM_MONTH_DAY;
312 char bf1[32] = { 0, };
313 bool is_24hour_enabled = FALSE;
316 time_t today, yesterday;
320 localtime_r(&today, &loc_time);
324 loc_time.tm_hour = 0;
325 today = mktime(&loc_time);
327 yesterday = today - QP_NOTI_DAY_DEC;
329 localtime_r(&t, &loc_time);
331 if (t >= yesterday && t < today) {
332 ret = snprintf(buf, buf_len, _S("IDS_COM_BODY_YESTERDAY"));
333 } else if (t < yesterday) {
334 /* set UDate from time_t */
335 date = (UDate) t * 1000;
337 /* get default locale */
338 /* for thread saftey */
339 uloc_setDefault(__secure_getenv("LC_TIME"), &status);
340 locale = uloc_getDefault();
342 /* open datetime pattern generator */
343 generator = udatpg_open(locale, &status);
344 if (generator == NULL)
347 /* calculate pattern string capacity */
349 (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
351 /* ascii to unicode for input skeleton */
352 u_uastrcpy(skeleton, customSkeleton);
354 /* get skeleton length */
355 skeletonLength = strlen(customSkeleton);
357 /* get best pattern using skeleton */
359 udatpg_getBestPattern(generator, skeleton, skeletonLength,
360 pattern, patternCapacity, &status);
362 /* open datetime formatter using best pattern */
364 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1,
365 pattern, patternLength, &status);
366 if (formatter == NULL) {
367 udatpg_close(generator);
371 /* calculate formatted string capacity */
373 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
375 /* formatting date using formatter by best pattern */
377 udat_format(formatter, date, formatted, formattedCapacity,
380 /* unicode to ascii to display */
381 u_austrcpy(bf1, formatted);
383 /* close datetime pattern generator */
384 udatpg_close(generator);
386 /* close datetime formatter */
387 udat_close(formatter);
389 ret = snprintf(buf, buf_len, "%s", bf1);
391 ret = runtime_info_get_value_bool(
392 RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
393 if (ret == RUNTIME_INFO_ERROR_NONE && is_24hour_enabled == TRUE) {
394 ret = strftime(buf, buf_len, "%H:%M", &loc_time);
396 strftime(bf1, sizeof(bf1), "%l:%M", &loc_time);
398 if (loc_time.tm_hour >= 0 && loc_time.tm_hour < 12)
399 ret = snprintf(buf, buf_len, "%s%s", bf1, "AM");
401 ret = snprintf(buf, buf_len, "%s%s", bf1, "PM");
406 return ret <= 0 ? NULL : buf;
409 static void _quickpanel_noti_ani_image_control(Eina_Bool on)
411 const Eina_List *l = NULL;
412 const Eina_List *ln = NULL;
413 Evas_Object *entry_obj = NULL;
415 retif(g_animated_image_list == NULL, ,"");
417 EINA_LIST_FOREACH_SAFE(g_animated_image_list, l, ln, entry_obj) {
418 if (entry_obj == NULL) continue;
420 if (on == EINA_TRUE) {
421 if (elm_image_animated_play_get(entry_obj) == EINA_FALSE) {
422 elm_image_animated_play_set(entry_obj, EINA_TRUE);
425 if (elm_image_animated_play_get(entry_obj) == EINA_TRUE) {
426 elm_image_animated_play_set(entry_obj, EINA_FALSE);
432 static void _quickpanel_noti_ani_image_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
434 retif(obj == NULL, , "obj is NULL");
435 retif(g_animated_image_list == NULL, , "list is empty");
437 g_animated_image_list = eina_list_remove(g_animated_image_list, obj);
440 static void _quickpanel_do_noti_delete(notification_h noti) {
441 char *pkgname = NULL;
442 char *caller_pkgname = NULL;
443 int flags = 0, priv_id = 0, flag_delete = 0;
444 notification_type_e type = NOTIFICATION_TYPE_NONE;
446 quickpanel_play_feedback();
448 retif(noti == NULL, , "Invalid parameter!");
450 notification_get_pkgname(noti, &caller_pkgname);
451 notification_get_application(noti, &pkgname);
453 pkgname = caller_pkgname;
455 notification_get_id(noti, NULL, &priv_id);
456 notification_get_property(noti, &flags);
457 notification_get_type(noti, &type);
459 if (flags & NOTIFICATION_PROP_PERMANENT_DISPLAY)
464 if (flag_delete == 1 && type == NOTIFICATION_TYPE_NOTI) {
465 notification_delete_by_priv_id(caller_pkgname, NOTIFICATION_TYPE_NOTI,
470 static void _quickpanel_do_noti_press(notification_h noti, int pressed_area) {
472 char *pkgname = NULL;
473 char *caller_pkgname = NULL;
475 bundle *group_args = NULL;
476 bundle *responding_service_handle = NULL;
477 bundle *single_service_handle = NULL;
478 bundle *multi_service_handle = NULL;
479 int flags = 0, group_id = 0, priv_id = 0, count = 0, flag_launch = 0,
481 notification_type_e type = NOTIFICATION_TYPE_NONE;
483 quickpanel_play_feedback();
485 retif(noti == NULL, , "Invalid parameter!");
487 notification_get_pkgname(noti, &caller_pkgname);
488 notification_get_application(noti, &pkgname);
490 pkgname = caller_pkgname;
492 notification_get_id(noti, &group_id, &priv_id);
493 notification_get_property(noti, &flags);
494 notification_get_type(noti, &type);
496 if (flags & NOTIFICATION_PROP_DISABLE_APP_LAUNCH)
501 if (flags & NOTIFICATION_PROP_DISABLE_AUTO_DELETE)
506 notification_get_execute_option(noti,
507 NOTIFICATION_EXECUTE_TYPE_RESPONDING,
508 NULL, &responding_service_handle);
509 notification_get_execute_option(noti,
510 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
511 NULL, &single_service_handle);
512 notification_get_execute_option(noti,
513 NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
514 NULL, &multi_service_handle);
516 if (pressed_area == NOTI_PRESS_BUTTON_1 && responding_service_handle != NULL) {
518 quickpanel_close_quickpanel(true);
519 ret = quickpanel_launch_app(NULL, responding_service_handle);
520 quickpanel_launch_app_inform_result(pkgname, ret);
521 } else if (flag_launch == 1) {
522 /* Hide quickpanel */
523 quickpanel_close_quickpanel(true);
525 char *text_count = NULL;
526 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &text_count);
528 if (text_count != NULL) {
529 count = atoi(text_count);
534 if (single_service_handle != NULL && multi_service_handle == NULL) {
536 ret = quickpanel_launch_app(NULL, single_service_handle);
537 quickpanel_launch_app_inform_result(pkgname, ret);
539 if (single_service_handle == NULL && multi_service_handle != NULL) {
541 ret = quickpanel_launch_app(NULL, multi_service_handle);
542 quickpanel_launch_app_inform_result(pkgname, ret);
544 if (single_service_handle != NULL && multi_service_handle != NULL) {
547 ret = quickpanel_launch_app(NULL, single_service_handle);
548 quickpanel_launch_app_inform_result(pkgname, ret);
550 ret = quickpanel_launch_app(NULL, multi_service_handle);
551 quickpanel_launch_app_inform_result(pkgname, ret);
554 if (single_service_handle == NULL && multi_service_handle == NULL) {
556 notification_get_args(noti, &args, &group_args);
558 if (count > 1 && group_args != NULL) {
559 ret = quickpanel_launch_app(pkgname, group_args);
560 quickpanel_launch_app_inform_result(pkgname, ret);
562 ret = quickpanel_launch_app(pkgname, args);
563 quickpanel_launch_app_inform_result(pkgname, ret);
568 if (flag_delete == 1 && type == NOTIFICATION_TYPE_NOTI) {
569 notification_delete_by_priv_id(caller_pkgname,
570 NOTIFICATION_TYPE_NOTI,
575 static void quickpanel_notibox_delete_cb(void *data, Evas_Object * obj) {
577 noti_node_item *item = data;
578 retif(item == NULL, , "Invalid parameter!");
580 notification_h noti = item->noti;
581 retif(noti == NULL, , "Invalid parameter!");
583 _quickpanel_do_noti_delete(noti);
587 static void quickpanel_notibox_button_1_cb(void *data, Evas_Object * obj) {
589 noti_node_item *item = data;
590 retif(item == NULL, , "Invalid parameter!");
592 notification_h noti = item->noti;
593 retif(noti == NULL, , "Invalid parameter!");
595 _quickpanel_do_noti_press(noti, NOTI_PRESS_BUTTON_1);
598 static void quickpanel_notibox_select_cb(void *data, Evas_Object * obj) {
600 noti_node_item *item = data;
601 retif(item == NULL, , "Invalid parameter!");
603 notification_h noti = item->noti;
604 retif(noti == NULL, , "Invalid parameter!");
606 _quickpanel_do_noti_press(noti, NOTI_PRESS_BG);
609 static void quickpanel_noti_listitem_select_cb(void *data, Evas_Object * obj) {
611 noti_node_item *item = data;
612 retif(item == NULL, , "Invalid parameter!");
614 notification_h noti = item->noti;
615 retif(noti == NULL, , "Invalid parameter!");
617 _quickpanel_do_noti_press(noti, NOTI_PRESS_BG);
620 static inline void __ongoing_comp_n_copy(notification_h old, notification_h new)
624 char *pkgname = NULL;
625 char *new_pkgname = NULL;
633 notification_get_id(old, NULL, &priv_id);
634 notification_get_id(new, NULL, &new_priv_id);
636 notification_get_pkgname(old, &pkgname);
637 notification_get_pkgname(new, &new_pkgname);
639 if (!pkgname || !new_pkgname)
642 if (!strcmp(pkgname, new_pkgname) && priv_id == new_priv_id) {
643 double percentage = 0.0;
645 time_t insert_time = 0;
646 time_t new_insert_time = 0;
648 notification_get_progress(old, &percentage);
649 notification_get_size(old, &size);
650 if (notification_set_progress(new, percentage) != NOTIFICATION_ERROR_NONE) {
651 ERR("fail to set progress");
653 if (notification_set_size(new, size) != NOTIFICATION_ERROR_NONE) {
654 ERR("fail to set size");
656 notification_get_insert_time(old, &insert_time);
657 notification_get_insert_time(new, &new_insert_time);
659 if (insert_time == new_insert_time) {
660 char *content = NULL;
661 notification_get_text(old,
662 NOTIFICATION_TEXT_TYPE_CONTENT, &content);
663 notification_set_text(new,
664 NOTIFICATION_TEXT_TYPE_CONTENT, content,
665 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
670 static void _quickpanel_noti_clear_ongoinglist()
672 if (g_noti_listbox != NULL) {
673 listbox_remove_all_item(g_noti_listbox, EINA_FALSE);
677 static void _quickpanel_noti_clear_notilist(void)
679 if (g_noti_gridbox != NULL) {
680 gridbox_remove_all_item(g_noti_gridbox, EINA_FALSE);
684 static void _quickpanel_noti_clear_list_all(void)
686 _quickpanel_noti_clear_ongoinglist();
687 _quickpanel_noti_clear_notilist();
690 static void _quickpanel_noti_section_add(void)
692 struct appdata *ad = quickpanel_get_app_data();
693 retif(ad == NULL, , "Invalid parameter!");
694 retif(ad->list == NULL, , "Invalid parameter!");
696 if (g_noti_section == NULL) {
697 g_noti_section = noti_section_create(ad->list);
698 if (g_noti_section != NULL) {
699 quickpanel_list_util_sort_insert(ad->list, g_noti_section);
700 DBG("noti section[%p]", g_noti_section);
705 static void _quickpanel_noti_section_remove(void)
707 struct appdata *ad = quickpanel_get_app_data();
708 retif(ad == NULL, , "Invalid parameter!");
709 retif(ad->list == NULL, , "Invalid parameter!");
711 if (g_noti_section != NULL) {
712 quickpanel_list_util_item_unpack_by_type(ad->list, QP_ITEM_TYPE_NOTI_GROUP);
713 noti_section_remove(g_noti_section);
714 g_noti_section = NULL;
718 void _quickpanel_noti_box_deleted_cb(void *data, Evas_Object *obj) {
721 retif(data == NULL, , "Invalid parameter!");
722 DBG("deleting:%p", data);
724 noti_node_item *item = data;
725 notification_h noti = item->noti;
728 notification_get_id(noti, NULL, &priv_id);
729 noti_node_remove(g_noti_node, priv_id);
733 void _quickpanel_list_box_deleted_cb(void *data, Evas_Object *obj) {
736 retif(data == NULL, , "Invalid parameter!");
737 DBG("deleting:%p", data);
739 noti_node_item *item = data;
740 notification_h noti = item->noti;
743 notification_get_id(noti, NULL, &priv_id);
744 noti_node_remove(g_noti_node, priv_id);
748 static void _quickpanel_noti_ongoing_add(Evas_Object *list, void *data, int is_prepend)
750 Evas_Object *noti_list_item = NULL;
751 notification_ly_type_e layout = NOTIFICATION_LY_ONGOING_EVENT;
753 retif(list == NULL, , "Invalid parameter!");
754 notification_h noti = data;
757 notification_get_layout(noti, &layout);
758 noti_list_item = noti_list_item_create(g_noti_listbox, layout);
760 if (noti_list_item != NULL) {
761 noti_node_item *item = noti_node_add(g_noti_node, (void*)data, (void*)noti_list_item);
763 noti_list_item_node_set(noti_list_item, item);
764 noti_list_item_set_item_selected_cb(noti_list_item, quickpanel_noti_listitem_select_cb);
765 listbox_add_item(g_noti_listbox, noti_list_item, is_prepend);
768 ERR("fail to insert item to list : %p", data);
771 DBG("noti[%p] data[%p] added listbox[%p]",
772 data, noti_list_item, g_noti_listbox);
775 static void _quickpanel_noti_noti_add(Evas_Object *list, void *data, int is_prepend)
777 notification_h noti = data;
778 notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
779 Evas_Object *noti_box = NULL;
781 retif(list == NULL, , "Invalid parameter!");
783 if (g_noti_section == NULL) {
784 _quickpanel_noti_section_add();
788 notification_get_layout(noti, &layout);
789 Evas_Object *noti_box = noti_box_create(g_noti_gridbox, layout);
791 if (noti_box != NULL) {
792 noti_node_item *item = noti_node_add(g_noti_node, (void*)data, (void*)noti_box);
794 noti_box_node_set(noti_box, item);
795 noti_box_set_item_selected_cb(noti_box, quickpanel_notibox_select_cb);
796 noti_box_set_item_button_1_cb(noti_box, quickpanel_notibox_button_1_cb);
797 noti_box_set_item_deleted_cb(noti_box, quickpanel_notibox_delete_cb);
798 gridbox_add_item(g_noti_gridbox, noti_box, is_prepend);
801 ERR("fail to insert item to list : %p", data);
805 noti_node_get_item_count(g_noti_node, NOTIFICATION_TYPE_NOTI);
807 if (g_noti_section != NULL) {
808 noti_section_update(g_noti_section, noti_count);
811 DBG("noti[%p] view[%p] added gridbox[%p]",
812 data, noti_box, g_noti_gridbox);
815 void _quickpanel_noti_update_notilist(struct appdata *ad)
817 Evas_Object *list = NULL;
818 notification_h noti = NULL;
819 notification_h noti_save = NULL;
820 notification_list_h get_list = NULL;
821 int applist = NOTIFICATION_DISPLAY_APP_ALL;
825 retif(ad == NULL, , "Invalid parameter!");
828 retif(list == NULL, , "Failed to get noti genlist.");
830 _quickpanel_noti_clear_list_all();
832 notification_get_list(NOTIFICATION_TYPE_ONGOING, -1, &get_list);
833 while (get_list != NULL) {
834 noti = notification_list_get_data(get_list);
835 notification_get_display_applist(noti, &applist);
838 NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
839 notification_clone(noti, ¬i_save);
840 _quickpanel_noti_ongoing_add(list, noti_save, LISTBOX_APPEND);
842 get_list = notification_list_get_next(get_list);
844 notification_free_list(get_list);
846 notification_get_list(NOTIFICATION_TYPE_NOTI , -1, &get_list);
847 while (get_list != NULL) {
848 noti = notification_list_get_data(get_list);
849 notification_get_display_applist(noti, &applist);
852 NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
853 notification_clone(noti, ¬i_save);
854 _quickpanel_noti_noti_add(list, noti_save, GRIDBOX_APPEND);
856 get_list = notification_list_get_next(get_list);
858 notification_free_list(get_list);
860 if (g_noti_gridbox != NULL) {
861 elm_box_recalculate(g_noti_gridbox);
865 static void _quickpanel_noti_delete_volatil_data(void)
867 notification_list_h noti_list = NULL;
868 notification_list_h noti_list_head = NULL;
869 notification_h noti = NULL;
872 notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list);
874 noti_list_head = noti_list;
876 while (noti_list != NULL) {
877 noti = notification_list_get_data(noti_list);
878 notification_get_property(noti, &property);
880 if (property & NOTIFICATION_PROP_VOLATILE_DISPLAY) {
881 notification_set_property(noti,
883 NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE);
884 notification_delete(noti);
887 noti_list = notification_list_get_next(noti_list);
890 notification_free_list(noti_list_head);
892 notification_update(NULL);
895 static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e type, notification_op *op_list, int num_op)
900 struct appdata *ad = NULL;
901 notification_h new_noti = NULL;
902 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
903 int noti_applist = NOTIFICATION_DISPLAY_APP_ALL;
904 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
906 retif(data == NULL, , "Invalid parameter!");
909 DBG("test detailed quickpanel:%d", num_op);
911 for (i = 0; i < num_op; i++) {
912 notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_TYPE, &op_type);
913 DBG("op_type:%d", op_type);
914 notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &priv_id);
915 DBG("op_priv_id:%d", priv_id);
917 if (op_type == NOTIFICATION_OP_INSERT) {
918 new_noti = notification_load(NULL, priv_id);
919 if (new_noti == NULL) continue;
921 notification_get_type(new_noti, ¬i_type);
922 notification_get_display_applist(new_noti, ¬i_applist);
923 notification_get_layout(new_noti, ¬i_layout);
925 DBG("layout:%d", noti_layout);
927 if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
928 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
930 if (noti_type == NOTIFICATION_TYPE_NOTI) {
931 DBG("cb after inserted:%d", priv_id);
934 if (noti_type == NOTIFICATION_TYPE_NOTI) {
935 _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
936 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
937 _quickpanel_noti_ongoing_add(ad->list, new_noti, LISTBOX_PREPEND);
940 DBG("%d noti added", priv_id);
942 notification_free(new_noti);
945 if (op_type == NOTIFICATION_OP_DELETE) {
946 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
948 if (node != NULL && node->noti != NULL) {
949 notification_h noti = node->noti;
950 notification_get_type(noti, ¬i_type);
952 if (noti_type == NOTIFICATION_TYPE_NOTI) {
953 gridbox_remove_item(g_noti_gridbox, node->view, 0);
954 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
955 listbox_remove_item(g_noti_listbox, node->view, 0);
957 noti_node_remove(g_noti_node, priv_id);
959 DBG("%d noti deleted", priv_id);
961 if (op_type == NOTIFICATION_OP_UPDATE) {
962 noti_node_item *node = noti_node_get(g_noti_node, priv_id);
963 notification_h old_noti = NULL;
965 new_noti = notification_load(NULL, priv_id);
966 retif(new_noti == NULL, , "fail to load updated noti");
968 if (node != NULL && node->view != NULL && node->noti != NULL) {
969 notification_get_type(new_noti, ¬i_type);
971 if (noti_type == NOTIFICATION_TYPE_NOTI) {
972 gridbox_remove_item(g_noti_gridbox, node->view, 0);
973 _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
975 gridbox_remove_and_add_item(g_noti_gridbox, node->view,
976 _quickpanel_noti_noti_add
977 ,ad->list, new_noti, GRIDBOX_PREPEND);
979 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
980 old_noti = node->noti;
981 node->noti = new_noti;
983 listbox_update_item(g_noti_listbox, node->view);
986 if (old_noti != NULL) {
987 notification_free(old_noti);
990 notification_get_display_applist(new_noti, ¬i_applist);
992 if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
994 if (noti_type == NOTIFICATION_TYPE_NOTI) {
995 _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
996 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
997 _quickpanel_noti_ongoing_add(ad->list, new_noti, GRIDBOX_PREPEND);
1002 DBG("%d noti updated", priv_id);
1008 if ((noti_count = noti_node_get_item_count(g_noti_node, NOTIFICATION_TYPE_NOTI))
1011 _quickpanel_noti_clear_notilist();
1012 _quickpanel_noti_section_remove();
1014 if (g_noti_section != NULL) {
1016 noti_section_update(g_noti_section, noti_count);
1021 static void _quickpanel_noti_update_desktop_cb(keynode_t *node, void *data)
1024 char type[10] = {0,};
1025 char package[1024] = {0,};
1027 event = vconf_get_str(vconf_keynode_get_name(node));
1028 retif(NULL == event, , "invalid event");
1032 if (sscanf(event, "%10[^:]:%1023s", type, package) != 2) {
1033 DBG("Failed to parse the event format : [%s], [%s]", type, package);
1036 if (strncasecmp(type, "delete", strlen(type)) == 0) {
1037 notification_delete_all_by_type(package, NOTIFICATION_TYPE_NONE);
1044 static void _quickpanel_noti_update_sim_status_cb(keynode_t *node, void *data)
1046 struct appdata *ad = data;
1048 if (ad != NULL && ad->list != NULL) {
1049 _quickpanel_noti_update_notilist(ad);
1053 static int _quickpanel_noti_register_event_handler(struct appdata *ad)
1056 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
1058 /* Add dbus signal */
1060 ad->dbus_connection = e_dbus_bus_get(DBUS_BUS_SYSTEM);
1061 if (ad->dbus_connection == NULL) {
1062 ERR("noti register : failed to get dbus bus");
1066 ad->dbus_handler_size =
1067 e_dbus_signal_handler_add(ad->dbus_connection, NULL,
1068 QP_NOTI_ONGOING_DBUS_PATH,
1069 QP_NOTI_ONGOING_DBUS_INTERFACE, "update_progress",
1070 _quickpanel_noti_item_progress_update_cb,
1072 if (ad->dbus_handler_size == NULL)
1073 ERR("fail to add size signal");
1075 ad->dbus_handler_progress =
1076 e_dbus_signal_handler_add(ad->dbus_connection, NULL,
1077 QP_NOTI_ONGOING_DBUS_PATH,
1078 QP_NOTI_ONGOING_DBUS_INTERFACE, "update_size",
1079 _quickpanel_noti_item_size_update_cb,
1081 if (ad->dbus_handler_progress == NULL)
1082 ERR("fail to add progress signal");
1084 ad->dbus_handler_content =
1085 e_dbus_signal_handler_add(ad->dbus_connection, NULL,
1086 QP_NOTI_ONGOING_DBUS_PATH,
1087 QP_NOTI_ONGOING_DBUS_INTERFACE, "update_content",
1088 _quickpanel_noti_item_content_update_cb,
1090 if (ad->dbus_handler_content == NULL)
1091 ERR("fail to add content signal");
1093 /* Notify vconf key */
1094 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
1095 _quickpanel_noti_update_sim_status_cb,
1098 ERR("Failed to register SIM_SLOT change callback!");
1100 /* Notify vconf key */
1101 ret = vconf_notify_key_changed(VCONFKEY_MENUSCREEN_DESKTOP,
1102 _quickpanel_noti_update_desktop_cb,
1105 ERR("Failed to register DESKTOP change callback!");
1107 /* Register notification changed cb */
1108 notification_register_detailed_changed_cb(_quickpanel_noti_detailed_changed_cb, ad);
1113 static int _quickpanel_noti_unregister_event_handler(struct appdata *ad)
1117 /* Unregister notification changed cb */
1118 notification_unregister_detailed_changed_cb(_quickpanel_noti_detailed_changed_cb, (void *)ad);
1120 /* Ignore vconf key */
1121 ret = vconf_ignore_key_changed(VCONFKEY_MENUSCREEN_DESKTOP,
1122 _quickpanel_noti_update_desktop_cb);
1124 ERR("Failed to ignore DESKTOP change callback!");
1126 ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
1127 _quickpanel_noti_update_sim_status_cb);
1129 ERR("Failed to ignore SIM_SLOT change callback!");
1131 /* Delete dbus signal */
1132 if (ad->dbus_handler_size != NULL) {
1133 e_dbus_signal_handler_del(ad->dbus_connection,
1134 ad->dbus_handler_size);
1135 ad->dbus_handler_size = NULL;
1137 if (ad->dbus_handler_progress != NULL) {
1138 e_dbus_signal_handler_del(ad->dbus_connection,
1139 ad->dbus_handler_progress);
1140 ad->dbus_handler_progress = NULL;
1142 if (ad->dbus_handler_content != NULL) {
1143 e_dbus_signal_handler_del(ad->dbus_connection,
1144 ad->dbus_handler_content);
1145 ad->dbus_handler_content = NULL;
1148 if (ad->dbus_connection != NULL) {
1149 e_dbus_connection_close(ad->dbus_connection);
1150 ad->dbus_connection = NULL;
1156 static int _quickpanel_noti_check_first_start(void)
1161 ret = vconf_get_bool(VCONFKEY_QUICKPANEL_STARTED, &status);
1163 INFO("fail to get %s", VCONFKEY_QUICKPANEL_STARTED);
1165 ret = vconf_set_bool(VCONFKEY_QUICKPANEL_STARTED, 1);
1166 INFO("set : %s, result : %d", VCONFKEY_QUICKPANEL_STARTED, ret);
1175 static void _quickpanel_noti_init(void *data)
1177 struct appdata *ad = NULL;
1179 retif(data == NULL, , "Invalid parameter!");
1182 retif(ad->list == NULL, , "Invalid parameter!");
1186 if (g_noti_listbox == NULL) {
1187 g_noti_listbox = listbox_create(ad->list, quickpanel_get_app_data());
1188 listbox_set_item_deleted_cb(g_noti_listbox, _quickpanel_list_box_deleted_cb);
1189 quickpanel_list_util_sort_insert(ad->list, g_noti_listbox);
1192 if (g_noti_gridbox == NULL) {
1193 g_noti_gridbox = gridbox_create(ad->list, quickpanel_get_app_data());
1194 gridbox_set_item_deleted_cb(g_noti_gridbox, _quickpanel_noti_box_deleted_cb);
1195 quickpanel_list_util_sort_insert(ad->list, g_noti_gridbox);
1198 /* Update notification list */
1199 _quickpanel_noti_update_notilist(ad);
1202 static void _quickpanel_noti_fini(void *data)
1204 struct appdata *ad = NULL;
1206 retif(data == NULL, , "Invalid parameter!");
1209 retif(ad->list == NULL, , "Invalid parameter!");
1213 if (g_noti_listbox != NULL) {
1214 quickpanel_list_util_item_unpack_by_object(ad->list
1216 listbox_remove(g_noti_listbox);
1217 g_noti_listbox = NULL;
1220 if (g_noti_gridbox != NULL) {
1221 quickpanel_list_util_item_unpack_by_object(ad->list
1223 gridbox_remove(g_noti_gridbox);
1224 g_noti_gridbox = NULL;
1228 static int quickpanel_noti_init(void *data)
1230 struct appdata *ad = data;
1233 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
1235 noti_node_create(&g_noti_node);
1237 is_first = _quickpanel_noti_check_first_start();
1239 /* Remove ongoing and volatile noti data */
1240 notifiation_clear(NOTIFICATION_TYPE_ONGOING);
1241 _quickpanel_noti_delete_volatil_data();
1244 _quickpanel_noti_init(ad);
1246 _quickpanel_noti_register_event_handler(ad);
1251 static int quickpanel_noti_fini(void *data)
1253 struct appdata *ad = data;
1254 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
1256 /* Unregister event handler */
1257 _quickpanel_noti_unregister_event_handler(data);
1259 if (g_noti_node != NULL) {
1260 noti_node_destroy(&g_noti_node);
1263 _quickpanel_noti_clear_list_all();
1265 _quickpanel_noti_fini(ad);
1270 static int quickpanel_noti_suspend(void *data)
1272 struct appdata *ad = data;
1273 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
1276 _quickpanel_noti_ani_image_control(EINA_FALSE);
1282 static int quickpanel_noti_resume(void *data)
1284 struct appdata *ad = data;
1285 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
1288 listbox_update(g_noti_listbox);
1290 _quickpanel_noti_ani_image_control(EINA_TRUE);
1296 static void quickpanel_noti_refresh(void *data) {
1297 struct appdata *ad = NULL;
1299 retif(data == NULL, , "Invalid parameter!");
1302 if (g_noti_gridbox != NULL) {
1303 gridbox_rotation(g_noti_gridbox, ad->angle);
1307 void quickpanel_noti_lang_changed(void *data)
1309 struct appdata *ad = data;
1311 retif(ad == NULL, , "Invalid parameter!");
1313 _quickpanel_noti_update_notilist(ad);