#include <inputmgr.h>
#include "defs.h"
-#include "view_user.h"
-#include "view_user_edit.h"
+#include "view.h"
#include "data_user.h"
#include "datamgr.h"
#include "utils.h"
+#define MESSAGE_POPUP_CONTENT "Can not add users more than 8.<br>If you want to add another user, delete one of users"
+
+enum input_handler_type {
+ INPUT_HANDLER_TYPE_BASE,
+ INPUT_HANDLER_TYPE_EO,
+ INPUT_HANDLER_TYPE_BUTTON
+};
+
struct _priv {
Evas_Object *win;
Evas_Object *base;
+ Evas_Object *scr;
+ Evas_Object *box;
+ Eina_List *list;
struct datamgr *dm;
+ struct _bar_item *foc;
+};
+
+struct _bar_item {
+ Evas_Object *eo;
+
+ struct datamgr_item *di;
+ struct _priv *priv;
+};
+
+static void _focused(int id, void *data, Evas_Object *obj,
+ Elm_Object_Item *item)
+{
+ struct _priv *priv;
+ struct _bar_item *bi;
+
+ if (id != INPUT_HANDLER_TYPE_EO)
+ return;
+
+ bi = data;
+ priv = bi->priv;
+ priv->foc = bi;
+
+ elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
+}
+
+static void _unfocused(int id, void *data, Evas_Object *obj,
+ Elm_Object_Item *item)
+{
+ if (id != INPUT_HANDLER_TYPE_EO)
+ return;
+
+ elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
+}
+
+static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Down *ev);
+
+static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Mouse_Down *ev);
+
+static input_handler handler = {
+ .focused = _focused,
+ .unfocused = _unfocused,
+ .key_down = _key_down,
+ .mouse_down = _mouse_down
};
+static void _add_popup(struct _priv *priv)
+{
+ Evas_Object *popup, *btn;
+
+ popup = utils_add_popup(priv->base, MESSAGE_ADD_USER,
+ MESSAGE_POPUP_CONTENT);
+ if (!popup) {
+ _ERR("failed to add popup");
+ return;
+ }
+
+ btn = utils_add_button(popup, MESSAGE_OK, PART_POPUP_BUTTON_1);
+ if (!btn) {
+ _ERR("failed to add button");
+ evas_object_del(popup);
+ return;
+ }
+ inputmgr_add_callback(btn, INPUT_HANDLER_TYPE_BUTTON, &handler, popup);
+ elm_object_focus_set(btn, EINA_TRUE);
+}
+
+static void _key_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Down *ev)
+{
+ struct _priv *priv;
+
+ if (!data) {
+ _ERR("Invalid argument");
+ return;
+ }
+
+ switch (id) {
+ case INPUT_HANDLER_TYPE_BUTTON:
+ if (!strcmp(ev->keyname, KEY_ENTER) ||
+ !strcmp(ev->keyname, KEY_ENTER_REMOTE) ||
+ !strcmp(ev->keyname, KEY_BACK) ||
+ !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+ inputmgr_remove_callback(obj, &handler);
+ evas_object_del(data);
+ }
+ break;
+ case INPUT_HANDLER_TYPE_BASE:
+ priv = data;
+ if (!strcmp(ev->keyname, KEY_ENTER) ||
+ !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
+ if ((priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
+ && (eina_list_count(priv->list)
+ >= MAX_USER_COUNT)) {
+ _add_popup(priv);
+ return;
+ }
+
+ viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
+ NULL);
+ datamgr_select_item(priv->dm, priv->foc->di);
+ } else if (!strcmp(ev->keyname, KEY_BACK) ||
+ !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
+ viewmgr_pop_view();
+ } else if (!strcmp(ev->keyname, KEY_DOWN)) {
+ if (priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
+ return;
+
+ viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
+ priv->foc->di);
+ viewmgr_push_view(VIEW_USER_EDIT);
+ }
+ break;
+ default:
+ return;
+ }
+}
+
+static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Mouse_Down *ev)
+{
+ struct _priv *priv;
+
+ if (!data) {
+ _ERR("Invalid argument");
+ return;
+ }
+
+ switch (id) {
+ case INPUT_HANDLER_TYPE_BASE:
+ priv = data;
+ if ((priv->foc->di->action == ITEM_SELECT_ACTION_PUSH)
+ && (eina_list_count(priv->list)
+ >= MAX_USER_COUNT)) {
+ _add_popup(priv);
+ return;
+ }
+
+ viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_EDIT,
+ NULL);
+ datamgr_select_item(priv->dm, priv->foc->di);
+ break;
+ case INPUT_HANDLER_TYPE_BUTTON:
+ inputmgr_remove_callback(obj, &handler);
+ evas_object_del(data);
+ break;
+ default:
+ return;
+ }
+}
+
static Evas_Object *_create(Evas_Object *win, void *data)
{
struct _priv *priv;
free(priv);
return NULL;
}
- evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, base);
priv->win = win;
viewmgr_set_view_data(VIEW_USER, priv);
viewmgr_add_view(view_user_edit_get_vclass(), dm);
+ inputmgr_add_callback(base, INPUT_HANDLER_TYPE_BASE, &handler, priv);
return base;
}
+static struct _bar_item *_pack_bar_item(struct _priv *priv, Evas_Object *box,
+ struct datamgr_item *di)
+{
+ struct _bar_item *bi;
+ Evas_Object *eo, *ic, *focus_ic, *lbl, *focus_lbl, *bg;
+
+ bi = calloc(1, sizeof(*bi));
+ if (!bi) {
+ _ERR("failed to calloc bar item");
+ return NULL;
+ }
+
+ if (di->title) {
+ eo = utils_add_layout(box, GRP_USER_ITEM, true, NULL);
+ if (!eo) {
+ _ERR("failed to add layout");
+ free(bi);
+ return NULL;
+ }
+ lbl = utils_add_label(eo, di->title, STYLE_LABEL_TITLE,
+ PART_BAR_ITEM_TITLE);
+ if (!lbl)
+ goto err;
+
+ focus_lbl = utils_add_label(eo, di->title,
+ STYLE_LABEL_TITLE_FOCUS,
+ PART_BAR_ITEM_TITLE_FOCUS);
+ if (!focus_lbl)
+ goto err;
+ } else {
+ eo = utils_add_layout(box, GRP_BAR_ITEM, true, NULL);
+ if (!eo) {
+ _ERR("failed to add layout");
+ free(bi);
+ return NULL;
+ }
+ }
+
+ ic = utils_add_icon(eo, di->icon, PART_BAR_ITEM_ICON);
+ if (!ic)
+ goto err;
+
+ focus_ic = utils_add_icon(eo, di->focus_icon,
+ PART_BAR_ITEM_ICON_FOCUS);
+ if (!focus_ic)
+ goto err;
+
+ if (!strcmp(di->icon, di->focus_icon))
+ elm_object_signal_emit(eo, SIG_SHOW_MASK, SRC_PROG);
+
+ bg = utils_add_bg(eo, COLOR_DEFAULT_R, COLOR_DEFAULT_G, COLOR_DEFAULT_B,
+ COLOR_DEFAULT_A, PART_BAR_ITEM_BG);
+ if (!bg)
+ goto err;
+
+ evas_object_size_hint_align_set(eo, 0.5, 0.0);
+ inputmgr_add_callback(eo, INPUT_HANDLER_TYPE_EO, &handler, bi);
+ elm_box_pack_end(box, eo);
+ evas_object_show(eo);
+
+ bi->priv = priv;
+ bi->eo = eo;
+ bi->di = di;
+
+ return bi;
+err:
+ _ERR("failed to add home item");
+ evas_object_del(eo);
+ free(bi);
+
+ return NULL;
+}
+
+static void _add_user(struct _priv *priv)
+{
+ Eina_List *list, *l;
+ Evas_Object *scr, *box;
+ struct _bar_item *bi;
+ struct datamgr_item *di;
+
+ scr = utils_add_scroller(priv->base);
+ if (!scr) {
+ _ERR("failed to add scroller");
+ return;
+ }
+
+ box = utils_add_box(scr, true);
+ if (!box) {
+ _ERR("failed to add box");
+ evas_object_del(scr);
+ return;
+ }
+ elm_object_content_set(scr, box);
+ elm_object_part_content_set(priv->base, PART_USER_BAR, scr);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+
+ list = datamgr_get_items(priv->dm);
+ if (!list) {
+ _ERR("failed to load list");
+ evas_object_del(scr);
+ return;
+ }
+
+ EINA_LIST_FOREACH(list, l, di) {
+ bi = _pack_bar_item(priv, box, di);
+ if (!bi)
+ continue;
+
+ priv->list = eina_list_append(priv->list, bi);
+ }
+
+ priv->scr = scr;
+ priv->box = box;
+}
+
static void _show(void *data)
{
struct _priv *priv;
priv = data;
evas_object_show(priv->base);
+
+ _add_user(priv);
+
+ if (!priv->foc)
+ priv->foc = eina_list_data_get(priv->list);
+
+ elm_object_focus_set(priv->foc->eo, EINA_TRUE);
+}
+
+static void _unload_user(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);
+ }
+
+ elm_box_clear(priv->box);
+ evas_object_del(priv->scr);
+ priv->box = NULL;
+ priv->scr = NULL;
+ priv->list = NULL;
+ priv->foc = NULL;
}
static void _hide(void *data)
priv = data;
+ _unload_user(priv);
+
evas_object_hide(priv->base);
}
priv = data;
+ _unload_user(priv);
+
viewmgr_remove_view(VIEW_USER_EDIT);
datamgr_fini(priv->dm);
+ inputmgr_remove_callback(priv->base, &handler);
evas_object_del(priv->base);
free(priv);
}