sync with private git. updated the license and the boilerplates
[apps/core/preloaded/quickpanel.git] / daemon / notifications / noti.c
index eb5e799..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
  *
 #include <vconf.h>
 #include <appcore-common.h>
 #include <app_service.h>
-#include <runtime_info.h>
 #include <Ecore_X.h>
-
-#include <unicode/uloc.h>
-#include <unicode/udat.h>
-#include <unicode/udatpg.h>
-#include <unicode/ustring.h>
 #include <notification.h>
 
 #include "quickpanel-ui.h"
 #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"
 #endif /* VCONFKEY_QUICKPANEL_STARTED */
 
-#define QP_NOTI_DAY_DEC        (24 * 60 * 60)
-
 #define QP_NOTI_ONGOING_DBUS_PATH      "/dbus/signal"
 #define QP_NOTI_ONGOING_DBUS_INTERFACE "notification.ongoing"
 
@@ -54,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);
@@ -296,147 +290,6 @@ static void _quickpanel_noti_item_content_update_cb(void *data,
                _quickpanel_noti_update_progressbar(data, noti);
 }
 
-char *quickpanel_noti_get_time(time_t t, char *buf, int buf_len)
-{
-       UErrorCode status = U_ZERO_ERROR;
-       UDateTimePatternGenerator *generator;
-       UDateFormat *formatter;
-       UChar skeleton[40] = { 0 };
-       UChar pattern[40] = { 0 };
-       UChar formatted[40] = { 0 };
-       int32_t patternCapacity, formattedCapacity;
-       int32_t skeletonLength, patternLength, formattedLength;
-       UDate date;
-       const char *locale;
-       const char customSkeleton[] = UDAT_YEAR_NUM_MONTH_DAY;
-       char bf1[32] = { 0, };
-       bool is_24hour_enabled = FALSE;
-
-       struct tm loc_time;
-       time_t today, yesterday;
-       int ret = 0;
-
-       today = time(NULL);
-       localtime_r(&today, &loc_time);
-
-       loc_time.tm_sec = 0;
-       loc_time.tm_min = 0;
-       loc_time.tm_hour = 0;
-       today = mktime(&loc_time);
-
-       yesterday = today - QP_NOTI_DAY_DEC;
-
-       localtime_r(&t, &loc_time);
-
-       if (t >= yesterday && t < today) {
-               ret = snprintf(buf, buf_len, _S("IDS_COM_BODY_YESTERDAY"));
-       } else if (t < yesterday) {
-               /* set UDate  from time_t */
-               date = (UDate) t * 1000;
-
-               /* get default locale  */
-               /* for thread saftey  */
-               uloc_setDefault(__secure_getenv("LC_TIME"), &status);
-               locale = uloc_getDefault();
-
-               /* open datetime pattern generator */
-               generator = udatpg_open(locale, &status);
-               if (generator == NULL)
-                       return NULL;
-
-               /* calculate pattern string capacity */
-               patternCapacity =
-                   (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
-
-               /* ascii to unicode for input skeleton */
-               u_uastrcpy(skeleton, customSkeleton);
-
-               /* get skeleton length */
-               skeletonLength = strlen(customSkeleton);
-
-               /* get best pattern using skeleton */
-               patternLength =
-                   udatpg_getBestPattern(generator, skeleton, skeletonLength,
-                                         pattern, patternCapacity, &status);
-
-               /* open datetime formatter using best pattern */
-               formatter =
-                   udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1,
-                             pattern, patternLength, &status);
-               if (formatter == NULL) {
-                       udatpg_close(generator);
-                       return NULL;
-               }
-
-               /* calculate formatted string capacity */
-               formattedCapacity =
-                   (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
-
-               /* formatting date using formatter by best pattern */
-               formattedLength =
-                   udat_format(formatter, date, formatted, formattedCapacity,
-                               NULL, &status);
-
-               /* unicode to ascii to display */
-               u_austrcpy(bf1, formatted);
-
-               /* close datetime pattern generator */
-               udatpg_close(generator);
-
-               /* close datetime formatter */
-               udat_close(formatter);
-
-               ret = snprintf(buf, buf_len, "%s", bf1);
-       } else {
-               ret = runtime_info_get_value_bool(
-                                       RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
-               if (ret == RUNTIME_INFO_ERROR_NONE && is_24hour_enabled == TRUE) {
-                       ret = strftime(buf, buf_len, "%H:%M", &loc_time);
-               } else {
-                       strftime(bf1, sizeof(bf1), "%l:%M", &loc_time);
-
-                       if (loc_time.tm_hour >= 0 && loc_time.tm_hour < 12)
-                               ret = snprintf(buf, buf_len, "%s%s", bf1, "AM");
-                       else
-                               ret = snprintf(buf, buf_len, "%s%s", bf1, "PM");
-               }
-
-       }
-
-       return ret <= 0 ? NULL : buf;
-}
-
-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;
@@ -715,7 +568,7 @@ static void _quickpanel_noti_section_remove(void)
        }
 }
 
-void _quickpanel_noti_box_deleted_cb(void *data, Evas_Object *obj) {
+static void _quickpanel_noti_box_deleted_cb(void *data, Evas_Object *obj) {
        int priv_id = -1;
 
        retif(data == NULL, , "Invalid parameter!");
@@ -730,7 +583,7 @@ void _quickpanel_noti_box_deleted_cb(void *data, Evas_Object *obj) {
        }
 }
 
-void _quickpanel_list_box_deleted_cb(void *data, Evas_Object *obj) {
+static void _quickpanel_list_box_deleted_cb(void *data, Evas_Object *obj) {
        int priv_id = -1;
 
        retif(data == NULL, , "Invalid parameter!");
@@ -812,7 +665,7 @@ static void _quickpanel_noti_noti_add(Evas_Object *list, void *data, int is_prep
                        data, noti_box, g_noti_gridbox);
 }
 
-void _quickpanel_noti_update_notilist(struct appdata *ad)
+static void _quickpanel_noti_update_notilist(struct appdata *ad)
 {
        Evas_Object *list = NULL;
        notification_h noti = NULL;
@@ -892,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;
@@ -906,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;
+                       }
+
+                       _print_debuginfo_from_noti(noti_new);
+#ifdef QP_SERVICE_NOTI_LED_ENABLE
+                       quickpanel_service_noti_led_on(noti_new);
+#endif
 
-                       DBG("layout:%d", noti_layout);
+                       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);
@@ -930,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) {
@@ -956,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);
                                }
@@ -987,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
                }
        }
 
@@ -1007,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)
@@ -1159,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);
@@ -1194,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)
@@ -1225,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;
@@ -1236,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);
@@ -1253,17 +1163,22 @@ 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);
 
-       if (g_noti_node != NULL) {
-               noti_node_destroy(&g_noti_node);
-       }
-
        _quickpanel_noti_clear_list_all();
 
        _quickpanel_noti_fini(ad);
 
+       if (g_noti_node != NULL) {
+               noti_node_destroy(&g_noti_node);
+       }
+
        return QP_OK;
 }
 
@@ -1272,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;
 }
 
@@ -1286,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;
@@ -1304,7 +1213,7 @@ static void quickpanel_noti_refresh(void *data) {
        }
 }
 
-void quickpanel_noti_lang_changed(void *data)
+static void quickpanel_noti_lang_changed(void *data)
 {
        struct appdata *ad = data;