diff options
Diffstat (limited to 'src/notification_view.c')
-rw-r--r-- | src/notification_view.c | 225 |
1 files changed, 217 insertions, 8 deletions
diff --git a/src/notification_view.c b/src/notification_view.c index 6a0bea3..b4ec9a4 100644 --- a/src/notification_view.c +++ b/src/notification_view.c @@ -18,17 +18,203 @@ #include <viewmgr.h> #include <inputmgr.h> #include <app_debug.h> +#include <notification.h> +#include <notification_noti.h> #include "define.h" +#define STYLE_GRID_ITEM "default_2text" +#define PART_ITEM_CONTENT "elm.text2" + +#define NOTIFICATION_CATEGORY_PADDING_X 62 +#define NOTIFICATION_CATEGORY_PADDING_Y 0 +#define NOTIFICATION_CATEGORY_HEIGHT 620 +#define NOTIFICATION_ITEM_WIDTH 489 +#define NOTIFICATION_ITEM_HEIGHT 134 +#define NOTIFICATION_ITEM_PADDING 26 +#define NOTIFICATION_ITEMS_IN_COL 4.0 + +enum notification_category { + CATEGORY_FIRST = 0, + CATEGORY_TODAY = CATEGORY_FIRST, + CATEGORY_ONGOING, + CATEGORY_TV, + CATEGORY_COMMUNICATION, + CATEGORY_EVENT, + CATEGORY_THINGS, + CATEGORY_INFORMATION, + CATEGORY_FILE, + CATEGORY_MAX +}; + struct _priv { Evas_Object *base; + Evas_Object *clear_btn; + Evas_Object *category_container; + Evas_Object *category[CATEGORY_MAX]; + Elm_Gengrid_Item_Class *grid_class; }; +static const char *_get_category_title(int category) +{ + switch (category) { + case CATEGORY_TODAY: + return STR_CATEGORY_TODAY; + case CATEGORY_ONGOING: + return STR_CATEGORY_ONGOING; + case CATEGORY_TV: + return STR_CATEGORY_TV; + case CATEGORY_COMMUNICATION: + return STR_CATEGORY_COMMUNICATION; + case CATEGORY_EVENT: + return STR_CATEGORY_EVENT; + case CATEGORY_THINGS: + return STR_CATEGORY_THINGS; + case CATEGORY_INFORMATION: + return STR_CATEGORY_INFORMATION; + case CATEGORY_FILE: + return STR_CATEGORY_FILE; + default: + return NULL; + } +} + +static void _draw_category(struct _priv *priv, int category, + notification_list_h noti_list) +{ + notification_h noti; + Evas_Object *ly; + int count = 0, col, w; + + if (category < CATEGORY_FIRST || + category >= CATEGORY_MAX) { + _ERR("Undefined category"); + return; + } + + ly = elm_layout_add(priv->category_container); + elm_layout_file_set(ly, EDJEFILE, GRP_NOTIFICATION_CATEGORY); + evas_object_size_hint_align_set(ly, 0.0, 0.0); + + elm_object_part_text_set(ly, PART_NOTIFICATION_CATEGORY_TITLE, + _get_category_title(category)); + + priv->category[category] = elm_gengrid_add(ly); + elm_gengrid_item_size_set(priv->category[category], + NOTIFICATION_ITEM_WIDTH, NOTIFICATION_ITEM_HEIGHT); + elm_gengrid_align_set(priv->category[category], 0.0, 0.0); + elm_gengrid_horizontal_set(priv->category[category], EINA_TRUE); + elm_scroller_policy_set(priv->category[category], + ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); + evas_object_size_hint_weight_set(priv->category[category], + EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_content_set(ly, priv->category[category]); + + elm_box_pack_end(priv->category_container, ly); + evas_object_show(ly); + + while (noti_list != NULL) { + noti = notification_list_get_data(noti_list); + elm_gengrid_item_append(priv->category[category], + priv->grid_class, noti, NULL, noti); + + noti_list = notification_list_remove(noti_list, noti); + count++; + } + + col = ceil(count / NOTIFICATION_ITEMS_IN_COL); + w = col * NOTIFICATION_ITEM_WIDTH + + (col - 1) * NOTIFICATION_ITEM_PADDING; + evas_object_size_hint_min_set(priv->category[category], + w, NOTIFICATION_CATEGORY_HEIGHT); +} + +static void _update_list(struct _priv *priv) +{ + notification_list_h noti_list = NULL; + + elm_box_clear(priv->category_container); + + notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬i_list); + if (noti_list) { + elm_object_signal_emit(priv->base, + SIGNAL_NOTIFICATION, SOURCE_PROGRAM); + + _draw_category(priv, CATEGORY_TODAY, noti_list); + } else { + elm_object_signal_emit(priv->base, + SIGNAL_NO_NOTIFICATION, SOURCE_PROGRAM); + } +} + +static char *_grid_label_get(void *data, + Evas_Object *obj, + const char *part) +{ + notification_h noti = data; + char *buf = NULL; + + if (!noti) + return NULL; + + if (!strcmp(part, PART_TITLE)) { + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &buf); + if (!buf) + notification_get_pkgname(noti, &buf); + + return buf ? strdup(buf) : NULL; + } else if (!strcmp(part, PART_ITEM_CONTENT)) { + notification_get_text(noti, + NOTIFICATION_TEXT_TYPE_CONTENT, &buf); + return buf ? strdup(buf) : NULL; + } + + return NULL; +} + +static Evas_Object *_grid_content_get(void *data, + Evas_Object *obj, + const char *part) +{ + notification_h noti = data; + char *icon_path = NULL; + + if (!noti) + return NULL; + + if (!strcmp(part, PART_ICON)) { + notification_get_image(noti, + NOTIFICATION_IMAGE_TYPE_ICON, + &icon_path); + + if (!icon_path) + return NULL; + + Evas_Object *icon = elm_image_add(obj); + + elm_image_file_set(icon, icon_path, NULL); + evas_object_show(icon); + + return icon; + } + + return NULL; +} + +static void _grid_del(void *data, Evas_Object *obj) +{ + notification_h noti = data; + + if (!noti) + return; + + notification_free(noti); +} + static Evas_Object *_create(Evas_Object *win, void *data) { struct _priv *priv; - Evas_Object *base; + Evas_Object *scroller; if (!win) { _ERR("failed to get win object"); @@ -41,22 +227,41 @@ static Evas_Object *_create(Evas_Object *win, void *data) return NULL; } - base = elm_layout_add(win); - if (!base) { + priv->base = elm_layout_add(win); + if (!priv->base) { _ERR("failed to create base object"); free(priv); return NULL; } - elm_layout_file_set(base, EDJEFILE, GRP_NOTIFICATION_VIEW); + elm_layout_file_set(priv->base, EDJEFILE, GRP_NOTIFICATION_VIEW); - evas_object_size_hint_weight_set(base, + evas_object_size_hint_weight_set(priv->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, base); + elm_win_resize_object_add(win, priv->base); + + scroller = elm_scroller_add(priv->base); + evas_object_size_hint_align_set(scroller, 0.0, 0.0); + elm_object_content_set(priv->base, scroller); + + priv->category_container = elm_box_add(priv->base); + elm_object_content_set(priv->base, priv->category_container); + elm_box_align_set(priv->category_container, 0.0, 0.0); + elm_box_horizontal_set(priv->category_container, EINA_TRUE); + elm_box_padding_set(priv->category_container, + NOTIFICATION_CATEGORY_PADDING_X, + NOTIFICATION_CATEGORY_PADDING_Y); + evas_object_show(priv->category_container); + + priv->grid_class = elm_gengrid_item_class_new(); + priv->grid_class->item_style = STYLE_GRID_ITEM; + priv->grid_class->func.text_get = _grid_label_get; + priv->grid_class->func.content_get = _grid_content_get; + priv->grid_class->func.state_get = NULL; + priv->grid_class->func.del = _grid_del; - priv->base = base; viewmgr_set_view_data(NOTIFICATION_VIEW, priv); - return base; + return priv->base; } static void _show(void *view_data) @@ -70,6 +275,8 @@ static void _show(void *view_data) priv = (struct _priv *) view_data; + _update_list(priv); + evas_object_show(priv->base); } @@ -100,6 +307,8 @@ static void _destroy(void *view_data) evas_object_del(priv->base); + elm_gengrid_item_class_free(priv->grid_class); + free(priv); } |