sync with private git. updated the license and the boilerplates
[apps/core/preloaded/quickpanel.git] / daemon / notifications / noti.c
index 74c53a9..dddc98f 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
- * Licensed under the Flora License, Version 1.0 (the License);
+ * Licensed under the Flora License, Version 1.1 (the License);
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
@@ -34,6 +34,9 @@
 #include "noti_section.h"
 #include "noti.h"
 #include "list_util.h"
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+#include "noti_led.h"
+#endif
 
 #ifndef VCONFKEY_QUICKPANEL_STARTED
 #define VCONFKEY_QUICKPANEL_STARTED "memory/private/"PACKAGE_NAME"/started"
@@ -46,7 +49,6 @@ static noti_node *g_noti_node;
 static Evas_Object *g_noti_section;
 static Evas_Object *g_noti_listbox;
 static Evas_Object *g_noti_gridbox;
-static Eina_List *g_animated_image_list;
 
 static int quickpanel_noti_init(void *data);
 static int quickpanel_noti_fini(void *data);
@@ -288,37 +290,6 @@ static void _quickpanel_noti_item_content_update_cb(void *data,
                _quickpanel_noti_update_progressbar(data, noti);
 }
 
-static void _quickpanel_noti_ani_image_control(Eina_Bool on)
-{
-       const Eina_List *l = NULL;
-       const Eina_List *ln = NULL;
-       Evas_Object *entry_obj = NULL;
-
-       retif(g_animated_image_list == NULL, ,"");
-
-       EINA_LIST_FOREACH_SAFE(g_animated_image_list, l, ln, entry_obj) {
-               if (entry_obj == NULL) continue;
-
-               if (on == EINA_TRUE) {
-                       if (elm_image_animated_play_get(entry_obj) == EINA_FALSE) {
-                               elm_image_animated_play_set(entry_obj, EINA_TRUE);
-                       }
-               } else {
-                       if (elm_image_animated_play_get(entry_obj) == EINA_TRUE) {
-                               elm_image_animated_play_set(entry_obj, EINA_FALSE);
-                       }
-               }
-       }
-}
-
-static void _quickpanel_noti_ani_image_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
-       retif(obj == NULL, , "obj is NULL");
-       retif(g_animated_image_list == NULL, , "list is empty");
-
-       g_animated_image_list = eina_list_remove(g_animated_image_list, obj);
-}
-
 static void _quickpanel_do_noti_delete(notification_h noti) {
        char *pkgname = NULL;
        char *caller_pkgname = NULL;
@@ -774,13 +745,35 @@ static void _quickpanel_noti_delete_volatil_data(void)
        notification_update(NULL);
 }
 
+inline static void _print_debuginfo_from_noti(notification_h noti) {
+       retif(noti == NULL, , "Invalid parameter!");
+
+       char *noti_pkgname = NULL;
+       char *noti_launch_pkgname = NULL;
+       notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
+
+       notification_get_pkgname(noti, &noti_pkgname);
+       notification_get_application(noti, &noti_launch_pkgname);
+       notification_get_type(noti, &noti_type);
+
+       if (noti_pkgname != NULL) {
+               ERR("pkg:%s", noti_pkgname);
+       }
+       if (noti_launch_pkgname != NULL) {
+               ERR("pkgl:%s", noti_launch_pkgname);
+       }
+
+       ERR("type:%d", noti_type);
+}
+
 static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e type, notification_op *op_list, int num_op)
 {
        int i = 0;
        int op_type = 0;
        int priv_id = 0;
        struct appdata *ad = NULL;
-       notification_h new_noti = NULL;
+       notification_h noti_new = NULL;
+       notification_h noti_from_master = NULL;
        notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
        int noti_applist = NOTIFICATION_DISPLAY_APP_ALL;
        notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
@@ -788,23 +781,34 @@ static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e
        retif(data == NULL, , "Invalid parameter!");
        ad = data;
 
-       DBG("test detailed quickpanel:%d", num_op);
+       ERR("num_op:%d", num_op);
 
        for (i = 0; i < num_op; i++) {
                notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_TYPE, &op_type);
-               DBG("op_type:%d", op_type);
                notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &priv_id);
-               DBG("op_priv_id:%d", priv_id);
+               notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, &noti_from_master);
+
+               ERR("noti operation:%d privid:%d", op_type, priv_id);
 
                if (op_type == NOTIFICATION_OP_INSERT) {
-                       new_noti = notification_load(NULL, priv_id);
-                       if (new_noti == NULL) continue;
 
-                       notification_get_type(new_noti, &noti_type);
-                       notification_get_display_applist(new_noti, &noti_applist);
-                       notification_get_layout(new_noti, &noti_layout);
+                       if (noti_from_master == NULL) {
+                               ERR("failed to get a notification from master");
+                               continue;
+                       }
+                       if (notification_clone(noti_from_master, &noti_new) != NOTIFICATION_ERROR_NONE) {
+                               ERR("failed to create a cloned notification");
+                               continue;
+                       }
 
-                       DBG("layout:%d", noti_layout);
+                       _print_debuginfo_from_noti(noti_new);
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+                       quickpanel_service_noti_led_on(noti_new);
+#endif
+
+                       notification_get_type(noti_new, &noti_type);
+                       notification_get_display_applist(noti_new, &noti_applist);
+                       notification_get_layout(noti_new, &noti_layout);
 
                        if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
                                noti_node_item *node = noti_node_get(g_noti_node, priv_id);
@@ -812,25 +816,29 @@ static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e
                                        if (noti_type == NOTIFICATION_TYPE_NOTI) {
                                                DBG("cb after inserted:%d", priv_id);
                                        }
+                                       notification_free(noti_new);
                                } else {
                                        if (noti_type == NOTIFICATION_TYPE_NOTI) {
-                                               _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
+                                               _quickpanel_noti_noti_add(ad->list, noti_new, GRIDBOX_PREPEND);
                                        } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
-                                               _quickpanel_noti_ongoing_add(ad->list, new_noti, LISTBOX_PREPEND);
+                                               _quickpanel_noti_ongoing_add(ad->list, noti_new, LISTBOX_PREPEND);
                                        }
                                }
-                               DBG("%d noti added", priv_id);
                        } else {
-                               notification_free(new_noti);
+                               notification_free(noti_new);
                        }
-               }
-               if (op_type == NOTIFICATION_OP_DELETE) {
+               } else if (op_type == NOTIFICATION_OP_DELETE) {
                        noti_node_item *node = noti_node_get(g_noti_node, priv_id);
 
                        if (node != NULL && node->noti != NULL) {
                                notification_h noti = node->noti;
                                notification_get_type(noti, &noti_type);
 
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+                               quickpanel_service_noti_led_off(noti);
+#endif
+                               _print_debuginfo_from_noti(noti);
+
                                if (noti_type == NOTIFICATION_TYPE_NOTI) {
                                        gridbox_remove_item(g_noti_gridbox, node->view, 0);
                                } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
@@ -838,29 +846,38 @@ static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e
                                }
                                noti_node_remove(g_noti_node, priv_id);
                        }
-                       DBG("%d noti deleted", priv_id);
-               }
-               if (op_type == NOTIFICATION_OP_UPDATE) {
+               } else if (op_type == NOTIFICATION_OP_UPDATE) {
                        noti_node_item *node = noti_node_get(g_noti_node, priv_id);
                        notification_h old_noti = NULL;
 
-                       new_noti = notification_load(NULL, priv_id);
-                       retif(new_noti == NULL, , "fail to load updated noti");
+                       if (noti_from_master == NULL) {
+                               ERR("failed to get a notification from master");
+                               continue;
+                       }
+                       if (notification_clone(noti_from_master, &noti_new) != NOTIFICATION_ERROR_NONE) {
+                               ERR("failed to create a cloned notification");
+                               continue;
+                       }
+
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+                       quickpanel_service_noti_led_on(noti_new);
+#endif
+                       _print_debuginfo_from_noti(noti_new);
 
                        if (node != NULL && node->view != NULL && node->noti != NULL) {
-                               notification_get_type(new_noti, &noti_type);
+                               notification_get_type(noti_new, &noti_type);
 
                                if (noti_type == NOTIFICATION_TYPE_NOTI) {
                                        gridbox_remove_item(g_noti_gridbox, node->view, 0);
-                                       _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
+                                       _quickpanel_noti_noti_add(ad->list, noti_new, GRIDBOX_PREPEND);
 /*
                                        gridbox_remove_and_add_item(g_noti_gridbox, node->view,
                                                        _quickpanel_noti_noti_add
-                                                       ,ad->list, new_noti, GRIDBOX_PREPEND);
+                                                       ,ad->list, noti_new, GRIDBOX_PREPEND);
 */
                                } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
                                        old_noti = node->noti;
-                                       node->noti = new_noti;
+                                       node->noti = noti_new;
 
                                        listbox_update_item(g_noti_listbox, node->view);
                                }
@@ -869,19 +886,27 @@ static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e
                                        notification_free(old_noti);
                                }
                        } else {
-                               notification_get_display_applist(new_noti, &noti_applist);
+                               notification_get_display_applist(noti_new, &noti_applist);
 
                                if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
-
                                        if (noti_type == NOTIFICATION_TYPE_NOTI) {
-                                               _quickpanel_noti_noti_add(ad->list, new_noti, GRIDBOX_PREPEND);
+                                               _quickpanel_noti_noti_add(ad->list, noti_new, GRIDBOX_PREPEND);
                                        } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
-                                               _quickpanel_noti_ongoing_add(ad->list, new_noti, GRIDBOX_PREPEND);
+                                               _quickpanel_noti_ongoing_add(ad->list, noti_new, GRIDBOX_PREPEND);
                                        }
+                               } else {
+                                       notification_free(noti_new);
                                }
                        }
-
-                       DBG("%d noti updated", priv_id);
+               } else if (op_type == NOTIFICATION_OP_REFRESH) {
+                       _quickpanel_noti_update_notilist(ad);
+               } else if (op_type == NOTIFICATION_OP_SERVICE_READY) {
+                       _quickpanel_noti_update_notilist(ad);
+
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+                       quickpanel_service_noti_init(ad);
+                       quickpanel_service_noti_led_on(NULL);
+#endif
                }
        }
 
@@ -889,15 +914,15 @@ static void _quickpanel_noti_detailed_changed_cb(void *data, notification_type_e
 
        if ((noti_count = noti_node_get_item_count(g_noti_node, NOTIFICATION_TYPE_NOTI))
                        <= 0) {
-               DBG("");
                _quickpanel_noti_clear_notilist();
                _quickpanel_noti_section_remove();
        } else {
                if (g_noti_section != NULL) {
-                       DBG("");
                        noti_section_update(g_noti_section, noti_count);
                }
        }
+
+       ERR("current noti count:%d", noti_count);
 }
 
 static void _quickpanel_noti_update_desktop_cb(keynode_t *node, void *data)
@@ -1041,8 +1066,7 @@ static int _quickpanel_noti_check_first_start(void)
        int ret = 0;
 
        ret = vconf_get_bool(VCONFKEY_QUICKPANEL_STARTED, &status);
-       if (ret) {
-               INFO("fail to get %s", VCONFKEY_QUICKPANEL_STARTED);
+       if (ret == 0 && status == 0) {
                /* reboot */
                ret = vconf_set_bool(VCONFKEY_QUICKPANEL_STARTED, 1);
                INFO("set : %s, result : %d", VCONFKEY_QUICKPANEL_STARTED, ret);
@@ -1076,9 +1100,6 @@ static void _quickpanel_noti_init(void *data)
                gridbox_set_item_deleted_cb(g_noti_gridbox, _quickpanel_noti_box_deleted_cb);
                quickpanel_list_util_sort_insert(ad->list, g_noti_gridbox);
        }
-
-       /* Update notification list */
-       _quickpanel_noti_update_notilist(ad);
 }
 
 static void _quickpanel_noti_fini(void *data)
@@ -1107,6 +1128,11 @@ static void _quickpanel_noti_fini(void *data)
        }
 }
 
+static void _quickpanel_noti_cleanup(void *data) {
+       notifiation_clear(NOTIFICATION_TYPE_ONGOING);
+       _quickpanel_noti_delete_volatil_data();
+}
+
 static int quickpanel_noti_init(void *data)
 {
        struct appdata *ad = data;
@@ -1118,9 +1144,11 @@ static int quickpanel_noti_init(void *data)
 
        is_first = _quickpanel_noti_check_first_start();
        if (is_first) {
-               /* Remove ongoing and volatile noti data */
-               notifiation_clear(NOTIFICATION_TYPE_ONGOING);
-               _quickpanel_noti_delete_volatil_data();
+               if (notification_is_service_ready()) {
+                       _quickpanel_noti_cleanup(ad);
+               } else {
+                       notification_add_deffered_task(_quickpanel_noti_cleanup, ad);
+               }
        }
 
        _quickpanel_noti_init(ad);
@@ -1135,6 +1163,11 @@ static int quickpanel_noti_fini(void *data)
        struct appdata *ad = data;
        retif(ad == NULL, QP_FAIL, "Invalid parameter!");
 
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+       quickpanel_service_noti_fini(ad);
+       quickpanel_service_noti_led_off(NULL);
+#endif
+
        /* Unregister event handler */
        _quickpanel_noti_unregister_event_handler(data);
 
@@ -1154,10 +1187,6 @@ static int quickpanel_noti_suspend(void *data)
        struct appdata *ad = data;
        retif(ad == NULL, QP_FAIL, "Invalid parameter!");
 
-       if (ad->list) {
-               _quickpanel_noti_ani_image_control(EINA_FALSE);
-       }
-
        return QP_OK;
 }
 
@@ -1168,8 +1197,6 @@ static int quickpanel_noti_resume(void *data)
 
        if (ad->list) {
                listbox_update(g_noti_listbox);
-
-               _quickpanel_noti_ani_image_control(EINA_TRUE);
        }
 
        return QP_OK;