display the count of unread notification in recent list 78/48078/5
authorSoohye Shin <soohye.shin@samsung.com>
Mon, 14 Sep 2015 05:17:56 +0000 (14:17 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Mon, 14 Sep 2015 06:23:41 +0000 (15:23 +0900)
Change-Id: I35e798249916c56de4d3f617556f3939bc041913
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
include/defs.h
include/utils.h
src/data/data_home.c
src/data/data_recent.c
src/utils.c

index 74d7a1d..3a24413 100644 (file)
 #define IMAGE_RECENT_ICON_GALLERY IMAGEDIR"/ic_thumbnail_gallery.png"
 #define IMAGE_RECENT_ICON_MUSIC IMAGEDIR"/ic_thumbnail_music.png"
 #define IMAGE_RECENT_ICON_WEB IMAGEDIR"/ic_thumbnail_web.png"
+#define IMAGE_RECENT_THUMB_NOTI IMAGEDIR"/btn_menu_notification_foc.png"
 #define IMAGE_RECENT_THUMB_APP IMAGEDIR"/ic_default_app.png"
 #define IMAGE_RECENT_THUMB_CHANNEL IMAGEDIR"/ic_default_tv.png"
 #define IMAGE_RECENT_THUMB_SETTING IMAGEDIR"/ic_default_setting"
 #define MESSAGE_USER_ADD "is added."
 #define MESSAGE_USER_DELETE "is removed."
 #define MESSAGE_USER_UPDATE "is updated."
+#define MESSAGE_NOTIFICATION "Notification"
 
 #define GUM_ATTR_NAME "username"
 #define GUM_ATTR_USERTYPE "usertype"
index de543db..a09d665 100644 (file)
@@ -51,5 +51,6 @@ Evas_Object *utils_add_popup(Evas_Object *base, char *title, char *message);
 Evas_Object *utils_add_rectangle(Evas_Object *base, int r, int g, int b, int a);
 Evas_Object *utils_add_toast(Evas_Object *base, char *message);
 bool utils_launch_app(const char *pkg, const char *key, const char *value);
+int utils_get_notification_count(void);
 
 #endif /* __AIR_HOME_UTILS_H__ */
index 452d06c..81c4b28 100644 (file)
@@ -24,7 +24,6 @@
 #include <notification_internal.h>
 #include <pwd.h>
 #include <gum/gum-user.h>
-#include <app_contents.h>
 
 #include "data_home.h"
 #include "datamgr.h"
@@ -77,63 +76,6 @@ static inline gboolean _read_boolean(JsonReader *reader, char *member)
        return val;
 }
 
-static inline void _get_notification_count(notification_type_e type, int *count)
-{
-       int basis_time, r;
-       time_t noti_time;
-       notification_list_h list = NULL;
-       notification_h noti;
-
-       app_contents_get_basis_time(CONTENTS_NOTI, &basis_time);
-       if (basis_time < 0) {
-               _ERR("failed to get basis time");
-               return;
-       }
-
-       notification_get_list(type, -1, &list);
-       if (!list)
-               return;
-
-       while (list) {
-               noti = notification_list_get_data(list);
-               if (!noti) {
-                       _ERR("failed to get noti data");
-                       list = notification_list_get_next(list);
-                       continue;
-               }
-
-               r = notification_get_insert_time(noti, &noti_time);
-               if (r != NOTIFICATION_ERROR_NONE) {
-                       _ERR("failed to get time of notification");
-                       list = notification_list_get_next(list);
-                       continue;
-               }
-
-               if (noti_time < basis_time)
-                       break;
-
-               (*count)++;
-               list = notification_list_get_next(list);
-       }
-
-       notification_free_list(list);
-}
-
-static void _get_notification(char **noti)
-{
-       int count = 0;
-       char buf[MAX_BUF];
-
-       _get_notification_count(NOTIFICATION_TYPE_ONGOING, &count);
-       _get_notification_count(NOTIFICATION_TYPE_NOTI, &count);
-
-       if (count > 99)
-               count = 99;
-
-       snprintf(buf, sizeof(buf), "%d", count);
-       *noti = strdup(buf);
-}
-
 static void _get_login_user(char **name, char **icon, char **focus_icon)
 {
        GumUser *user;
@@ -164,6 +106,7 @@ static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
        struct datamgr_item *di;
        char *name, *icon, *parameter, *focus_icon, *action;
        gboolean noti;
+       char buf[MAX_BUF];
 
        if (!reader) {
                _ERR("Invalid argument");
@@ -212,8 +155,11 @@ static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
        di->focus_icon = strdup(focus_icon);
        di->parameter = strdup(parameter);
        di->noti = noti;
-       if (noti)
-               _get_notification(&di->subtitle);
+       if (noti) {
+               snprintf(buf, sizeof(buf), "%d",
+                               utils_get_notification_count());
+               di->subtitle = strdup(buf);
+       }
 
        return di;
 err:
@@ -328,6 +274,7 @@ static void _notification_cb(void *data, notification_type_e type)
        Eina_List *l;
        struct datamgr *dm;
        struct datamgr_item *di;
+       char buf[MAX_BUF];
 
        if (!data) {
                _ERR("Invalid argument");
@@ -336,9 +283,10 @@ static void _notification_cb(void *data, notification_type_e type)
 
        dm = data;
 
-       _get_notification(&noti);
-       viewmgr_update_view(VIEW_HOME, UPDATE_TYPE_NOTI, noti);
+       snprintf(buf, sizeof(buf), "%d", utils_get_notification_count());
+       noti = strdup(buf);
 
+       viewmgr_update_view(VIEW_HOME, UPDATE_TYPE_NOTI, noti);
        EINA_LIST_FOREACH(dm->list, l, di) {
                if (di->noti)
                        di->subtitle = noti;
index 30dd154..bbe084d 100644 (file)
@@ -25,6 +25,7 @@
 #include <media_content.h>
 #include <app_media.h>
 #include <app_define.h>
+#include <app_contents.h>
 #include <time.h>
 #include <ctype.h>
 
@@ -34,6 +35,7 @@
 #include "defs.h"
 
 #define BUF_TITLE_MAX 128
+#define MAX_BUF 64
 
 #define CHANNEL_GULLIVER IMAGEDIR"/gulliver.png"
 
@@ -424,6 +426,29 @@ static int _sort_list(const void *data1, const void *data2)
        return -1;
 }
 
+static bool _load_recent_notification(struct datamgr *dm)
+{
+       struct datamgr_item *di;
+       int time;
+       char buf[MAX_BUF];
+
+       snprintf(buf, sizeof(buf), "%d", utils_get_notification_count());
+
+       app_contents_get_basis_time(CONTENTS_NOTI, &time);
+       if (time < 0) {
+               _ERR("Invalid time");
+               return false;
+       }
+
+       di = _new_datamgr_item(MESSAGE_NOTIFICATION, IMAGE_RECENT_THUMB_NOTI,
+                       buf, APP_ID_INFOSQUARE, NULL, NULL,
+                       IMAGE_RECENT_ICON_APP, 0, time);
+       if (di)
+               dm->list = eina_list_append(dm->list, di);
+
+       return true;
+}
+
 static Eina_List *_get_items(struct datamgr *dm)
 {
        if (!dm) {
@@ -448,6 +473,9 @@ static Eina_List *_get_items(struct datamgr *dm)
        if (!_load_recent(dm, CONTENTS_MUSIC, 1, _music_list_foreach))
                _ERR("failed to load recent music contents");
 
+       if (!_load_recent_notification(dm))
+               _ERR("failed to load recent notification contents");
+
        dm->list = eina_list_sort(dm->list, 0, _sort_list);
 
        return dm->list;
index 6fb41cc..6f1a4da 100644 (file)
@@ -18,6 +18,9 @@
 #include <app_debug.h>
 #include <stdbool.h>
 #include <app.h>
+#include <notification.h>
+#include <notification_internal.h>
+#include <app_contents.h>
 
 #include "utils.h"
 #include "defs.h"
@@ -483,3 +486,58 @@ bool utils_launch_app(const char *pkg, const char *key, const char *value)
 
        return true;
 }
+
+static void _get_notification_count(notification_type_e type, int *count)
+{
+       int basis_time, r;
+       time_t noti_time;
+       notification_list_h list = NULL;
+       notification_h noti;
+
+       app_contents_get_basis_time(CONTENTS_NOTI, &basis_time);
+       if (basis_time < 0) {
+               _ERR("failed to get basis time");
+               return;
+       }
+
+       notification_get_list(type, -1, &list);
+       if (!list)
+               return;
+
+       while (list) {
+               noti = notification_list_get_data(list);
+               if (!noti) {
+                       _ERR("failed to get noti data");
+                       list = notification_list_get_next(list);
+                       continue;
+               }
+
+               r = notification_get_insert_time(noti, &noti_time);
+               if (r != NOTIFICATION_ERROR_NONE) {
+                       _ERR("failed to get time of notification");
+                       list = notification_list_get_next(list);
+                       continue;
+               }
+
+               if (noti_time < basis_time)
+                       break;
+
+               (*count)++;
+               list = notification_list_get_next(list);
+       }
+
+       notification_free_list(list);
+}
+
+int utils_get_notification_count(void)
+{
+       int count = 0;
+
+       _get_notification_count(NOTIFICATION_TYPE_ONGOING, &count);
+       _get_notification_count(NOTIFICATION_TYPE_NOTI, &count);
+
+       if (count > 99)
+               count = 99;
+
+       return count;
+}