#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"
#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;
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;
di->focus_icon = strdup(focus_icon);
di->parameter = strdup(parameter);
di->noti = noti;
+ if (noti)
+ _get_notification(&di->subtitle);
return di;
err:
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");
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)
Evas_Object *win;
Evas_Object *base;
Evas_Object *down;
+ Evas_Object *scr;
Eina_List *list;
struct datamgr *dm;
struct bar_item {
Evas_Object *eo;
+ Evas_Object *badge;
struct datamgr_item *di;
struct _priv *priv;
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)
{
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);
}
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) {
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;
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);
priv = data;
+ _add_home_menu(priv, priv->base);
+
evas_object_show(priv->base);
elm_object_signal_emit(priv->base, SIG_SHOW_NAVIGATION, SRC_PROG);
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;
priv = data;
+ _unload_home(priv);
+
elm_object_signal_emit(priv->base, SIG_HIDE_NAVIGATION, SRC_PROG);
evas_object_hide(priv->base);
}
static void _destroy(void *data)
{
struct _priv *priv;
- struct bar_item *bi;
if (!data) {
_ERR("Invalid argument");
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);
}