From: Soohye Shin Date: Fri, 3 Jul 2015 05:33:16 +0000 (+0900) Subject: enable to create/update/delete user in data_user X-Git-Tag: accepted/tizen/tv/20150728.070602~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fbfb92e5e52bb0886ad9f3c4b51f9faa64cb14b;p=profile%2Ftv%2Fapps%2Fnative%2Fair_home.git enable to create/update/delete user in data_user Change-Id: Ib241f6bfe99c931432c10d58dd5f6de1ad157b04 Signed-off-by: Soohye Shin --- diff --git a/include/datamgr.h b/include/datamgr.h index 853f14c..b0e39ad 100644 --- a/include/datamgr.h +++ b/include/datamgr.h @@ -25,6 +25,8 @@ enum datamgr_item_select_action { ITEM_SELECT_ACTION_PUSH, ITEM_SELECT_ACTION_POP, ITEM_SELECT_ACTION_SWITCH, + ITEM_SELECT_ACTION_UPDATE, + ITEM_SELECT_ACTION_DELETE, ITEM_SELECT_ACTION_MAX }; @@ -58,6 +60,8 @@ struct data_class { void (*select)(struct datamgr_item *di); Eina_List *(*get_items)(struct datamgr *dm); void (*clear)(struct datamgr *dm); + void (*add)(struct datamgr *dm, const char *title, const char *icon, + const char *parameter); /* It should be added later */ }; @@ -66,5 +70,7 @@ void datamgr_fini(struct datamgr *dm); Eina_List *datamgr_get_items(struct datamgr *dm); void datamgr_select_item(struct datamgr *dm, struct datamgr_item *di); void datamgr_clear_item(struct datamgr *dm); +void datamgr_add_item(struct datamgr *dm, const char *title, const char *icon, + const char *parameter); #endif /* __AIR_HOME_DATAMGR_H__ */ diff --git a/src/data/data_user.c b/src/data/data_user.c index e2ab5c4..1f34e5f 100644 --- a/src/data/data_user.c +++ b/src/data/data_user.c @@ -34,6 +34,7 @@ #define GUM_ATTR_USERTYPE "usertype" #define GUM_ATTR_UID "uid" #define GUM_ATTR_ICON "icon" +#define GUM_ATTR_PASSWORD "secret" #define GUM_LIST_USERTYPE "normal" #define ADDRESS_BUF_MAX 128 @@ -127,6 +128,47 @@ err: return; } +static void _update(struct datamgr_item *di) +{ + GumUser *user; + gboolean r; + + user = gum_user_get_by_name_sync(di->title, FALSE); + if (!user) { + _ERR("failed to get user"); + return; + } + + g_object_set(G_OBJECT(user), GUM_ATTR_PASSWORD, di->parameter, + GUM_ATTR_ICON, di->icon, NULL); + + r = gum_user_update_sync(user); + if (!r) { + _ERR("failed to update user"); + return; + } + + g_object_unref(user); +} + +static void _delete(struct datamgr_item *di) +{ + GumUser *user; + gboolean r; + + user = gum_user_get_by_name_sync(di->title, FALSE); + if (!user) { + _ERR("failed to get user"); + return; + } + + r = gum_user_delete_sync(user, FALSE); + if (!r) + _ERR("failed to delete user"); + + g_object_unref(user); +} + static void _select(struct datamgr_item *di) { if (!di) @@ -143,6 +185,12 @@ static void _select(struct datamgr_item *di) case ITEM_SELECT_ACTION_POP: viewmgr_pop_view(); break; + case ITEM_SELECT_ACTION_UPDATE: + _update(di); + break; + case ITEM_SELECT_ACTION_DELETE: + _delete(di); + break; default: _ERR("Invalid state"); return; @@ -368,11 +416,41 @@ static bool _init(struct datamgr *dm) return _load_user(dm); } +static void _add(struct datamgr *dm, const char *title, const char *icon, + const char *parameter) +{ + GumUser *user; + gboolean r; + + if (!dm || !title || !icon) { + _ERR("Invalid argument"); + return; + } + + user = gum_user_create_sync(FALSE); + if (!user) { + _ERR("failed to get user"); + return; + } + + g_object_set(G_OBJECT(user), GUM_ATTR_NAME, title, + GUM_ATTR_ICON, icon, + GUM_ATTR_PASSWORD, parameter, + GUM_ATTR_USERTYPE, GUM_USERTYPE_NORMAL, NULL); + + r = gum_user_add_sync(user); + if (!r) + _ERR("failed to add user"); + + g_object_unref(user); +} + static struct data_class dclass = { .init = _init, .fini = _fini, .get_items = _get_items, - .select = _select + .select = _select, + .add = _add }; struct data_class *datamgr_user_get_dclass(void) diff --git a/src/data/datamgr.c b/src/data/datamgr.c index ac19f2d..6448db9 100644 --- a/src/data/datamgr.c +++ b/src/data/datamgr.c @@ -98,3 +98,17 @@ void datamgr_clear_item(struct datamgr *dm) dm->dclass->clear(dm); } + +void datamgr_add_item(struct datamgr *dm, const char *title, const char *icon, + const char *parameter) +{ + if (!dm || !dm->dclass) { + _ERR("Invalid argument"); + return; + } + + if (!dm->dclass->add) + return; + + dm->dclass->add(dm, title, icon, parameter); +}