integrate with notification for displaying badge of noti count 06/44206/2
authorSoohye Shin <soohye.shin@samsung.com>
Sun, 19 Jul 2015 05:29:34 +0000 (14:29 +0900)
committerSoohye Shin <soohye.shin@samsung.com>
Sun, 19 Jul 2015 05:33:15 +0000 (14:33 +0900)
Change-Id: Ibd0b84189f77bac4c4d123310515cf7eae886619
Signed-off-by: Soohye Shin <soohye.shin@samsung.com>
CMakeLists.txt
packaging/org.tizen.home.spec
src/data/data_home.c
src/view/view_home.c

index e7a5be0..18cd8d8 100644 (file)
@@ -69,6 +69,7 @@ pkg_check_modules(PKGS REQUIRED
                libgum
                app-utils
                pkgmgr-info
+               notification
                capi-appfw-application)
 
 FOREACH(flag ${PKGS_CFLAGS})
index 11b37b6..c2b9785 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(libgum)
 BuildRequires: pkgconfig(app-utils)
 BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(notification)
 BuildRequires: edje-bin
 BuildRequires: gettext-devel
 
index 335ee02..f2a8b20 100644 (file)
 #include <stdbool.h>
 #include <Evas.h>
 #include <viewmgr.h>
+#include <notification.h>
+#include <notification_internal.h>
 
 #include "data_home.h"
 #include "datamgr.h"
 #include "utils.h"
+#include "view.h"
 
 #define STR_SELECT_ACTION_PUSH "push"
 #define STR_SELECT_ACTION_LAUNCH "launch"
@@ -36,6 +39,8 @@
 #define MEMBER_STR_PARAMETER "parameter"
 #define MEMBER_INT_NOTIFICATION "notification"
 
+#define MAX_BUF 64
+
 static inline char *_read_string(JsonReader *reader, char *member)
 {
        char *val;
@@ -68,6 +73,34 @@ static inline gboolean _read_boolean(JsonReader *reader, char *member)
        return val;
 }
 
+static inline void _get_notification_count(notification_type_e type, int *count)
+{
+       notification_list_h list = NULL;
+
+       notification_get_list(type, -1, &list);
+       if (!list)
+               return;
+
+       while (list) {
+               (*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);
+
+       snprintf(buf, sizeof(buf), "%d", count);
+       *noti = strdup(buf);
+}
+
 static struct datamgr_item *_pack_home_item(JsonReader *reader, int i)
 {
        struct datamgr_item *di;
@@ -120,6 +153,8 @@ 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);
 
        return di;
 err:
@@ -160,47 +195,11 @@ static Eina_List *_load_home_data(JsonReader *reader)
        return list;
 }
 
-static Eina_List *_get_items(struct datamgr *dm)
-{
-       if (!dm) {
-               _ERR("Invalid argument");
-               return NULL;
-       }
-
-       return dm->list;
-}
-
-static void _fini(struct datamgr *dm)
-{
-       struct datamgr_item *di;
-
-       if (!dm) {
-               _ERR("Invalid argument");
-               return;
-       }
-
-       EINA_LIST_FREE(dm->list, di) {
-               free(di->title);
-               free(di->icon);
-               free(di->focus_icon);
-               free(di->parameter);
-
-               free(di);
-       }
-
-       dm->list = NULL;
-}
-
-static bool _init(struct datamgr *dm)
+static bool _load_home(struct datamgr *dm)
 {
        JsonParser *parser;
        JsonReader *reader;
 
-       if (!dm) {
-               _ERR("Invalid argument");
-               return false;
-       }
-
        parser = json_parser_new();
        if (!parser) {
                _ERR("failed to new parser");
@@ -234,6 +233,65 @@ static bool _init(struct datamgr *dm)
        return true;
 }
 
+static void _unload_home(struct datamgr *dm)
+{
+       struct datamgr_item *di;
+
+       EINA_LIST_FREE(dm->list, di) {
+               free(di->title);
+               free(di->icon);
+               free(di->focus_icon);
+               free(di->parameter);
+               free(di->subtitle);
+
+               free(di);
+       }
+
+       dm->list = NULL;
+}
+
+static Eina_List *_get_items(struct datamgr *dm)
+{
+       if (!dm) {
+               _ERR("Invalid argument");
+               return NULL;
+       }
+
+       _unload_home(dm);
+       _load_home(dm);
+
+       return dm->list;
+}
+
+static void _notification_cb(void *data, notification_type_e type)
+{
+       /* It should be implemented later for loading a count of notification */
+}
+
+static void _fini(struct datamgr *dm)
+{
+       if (!dm) {
+               _ERR("Invalid argument");
+               return;
+       }
+
+       _unload_home(dm);
+
+       notification_unresister_changed_cb(_notification_cb);
+}
+
+static bool _init(struct datamgr *dm)
+{
+       if (!dm) {
+               _ERR("Invalid argument");
+               return false;
+       }
+
+       notification_resister_changed_cb(_notification_cb, dm);
+
+       return _load_home(dm);
+}
+
 static void _select(struct datamgr_item *di)
 {
        if (!di || !di->parameter)
index 7954945..1580e1f 100644 (file)
@@ -36,6 +36,7 @@ struct _priv {
        Evas_Object *win;
        Evas_Object *base;
        Evas_Object *down;
+       Evas_Object *scr;
        Eina_List *list;
 
        struct datamgr *dm;
@@ -44,6 +45,7 @@ struct _priv {
 
 struct bar_item {
        Evas_Object *eo;
+       Evas_Object *badge;
 
        struct datamgr_item *di;
        struct _priv *priv;
@@ -159,6 +161,24 @@ static bool _add_navigations(struct _priv *priv, Evas_Object *base)
        return true;
 }
 
+static Evas_Object *_add_notification_badge(Evas_Object *eo, char *noti)
+{
+       Evas_Object *badge;
+
+       if (!strcmp(noti, "0"))
+               return NULL;
+
+       badge = utils_add_icon(eo, IMAGE_BADGE, PART_BAR_ITEM_BADGE);
+       if (!badge) {
+               _ERR("failed to add badge");
+               return NULL;
+       }
+       elm_object_part_text_set(eo, PART_BAR_ITEM_BADGE_COUNT, noti);
+       evas_object_color_set(badge, 238, 67, 49, 255);
+
+       return badge;
+}
+
 static struct bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
                struct datamgr_item *di)
 {
@@ -206,6 +226,9 @@ static struct bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
        if (!bg)
                goto err;
 
+       if (di->noti)
+               bi->badge = _add_notification_badge(eo, di->subtitle);
+
        inputmgr_add_callback(eo, INPUT_HANDLER_TYPE_EO, &handler, bi);
        elm_box_pack_end(box, eo);
        evas_object_show(eo);
@@ -244,6 +267,7 @@ static bool _add_home_menu(struct _priv *priv, Evas_Object *base)
        }
        elm_object_content_set(scr, box);
        elm_object_part_content_set(base, PART_HOME_MENU_BAR, scr);
+       priv->scr = scr;
 
        list = datamgr_get_items(priv->dm);
        if (!list) {
@@ -263,22 +287,6 @@ static bool _add_home_menu(struct _priv *priv, Evas_Object *base)
        return true;
 }
 
-static bool _add_home(struct _priv *priv, Evas_Object *base)
-{
-
-       if (!_add_navigations(priv, base)) {
-               _ERR("failed to add navigations");
-               return false;
-       }
-
-       if (!_add_home_menu(priv, base)) {
-               _ERR("failed to add menu");
-               return false;
-       }
-
-       return true;
-}
-
 static Evas_Object *_create(Evas_Object *win, void *data)
 {
        struct _priv *priv;
@@ -313,7 +321,7 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        priv->base = base;
        priv->dm = dm;
 
-       if (!_add_home(priv, base)) {
+       if (!_add_navigations(priv, base)) {
                _ERR("failed to load home");
                datamgr_fini(dm);
                evas_object_del(base);
@@ -338,6 +346,8 @@ static void _show(void *data)
 
        priv = data;
 
+       _add_home_menu(priv, priv->base);
+
        evas_object_show(priv->base);
        elm_object_signal_emit(priv->base, SIG_SHOW_NAVIGATION, SRC_PROG);
 
@@ -346,6 +356,21 @@ static void _show(void *data)
        elm_object_focus_set(priv->foc->eo, EINA_TRUE);
 }
 
+static void _unload_home(struct _priv *priv)
+{
+       struct bar_item *bi;
+
+       EINA_LIST_FREE(priv->list, bi) {
+               inputmgr_remove_callback(bi->eo, &handler);
+               evas_object_del(bi->eo);
+               free(bi);
+       }
+       evas_object_del(priv->scr);
+
+       priv->foc = NULL;
+       priv->list = NULL;
+}
+
 static void _hide(void *data)
 {
        struct _priv *priv;
@@ -357,6 +382,8 @@ static void _hide(void *data)
 
        priv = data;
 
+       _unload_home(priv);
+
        elm_object_signal_emit(priv->base, SIG_HIDE_NAVIGATION, SRC_PROG);
        evas_object_hide(priv->base);
 }
@@ -364,7 +391,6 @@ static void _hide(void *data)
 static void _destroy(void *data)
 {
        struct _priv *priv;
-       struct bar_item *bi;
 
        if (!data) {
                _ERR("Invalid argument");
@@ -373,18 +399,11 @@ static void _destroy(void *data)
 
        priv = data;
 
-       EINA_LIST_FREE(priv->list, bi) {
-               inputmgr_remove_callback(bi->eo, &handler);
-               evas_object_del(bi->eo);
-               free(bi);
-       }
-
        datamgr_fini(priv->dm);
        inputmgr_remove_callback(priv->base, &handler);
        inputmgr_remove_callback(priv->down, &handler);
        evas_object_del(priv->base);
 
-       priv->list = NULL;
        free(priv);
 }