Listmgr: Added listmgr 65/49065/1
authorHyojung Jo <hj903.jo@samsung.com>
Tue, 6 Oct 2015 05:50:07 +0000 (14:50 +0900)
committerHyojung Jo <hj903.jo@samsung.com>
Tue, 6 Oct 2015 05:50:07 +0000 (14:50 +0900)
Change-Id: I13cb6c3e9f200cc0625e30e79267d206827f5abf
Signed-off-by: Hyojung Jo <hj903.jo@samsung.com>
CMakeLists.txt
include/define.h
include/listmgr.h [new file with mode: 0644]
include/utils.h
src/common/listmgr.c [new file with mode: 0644]
src/common/utils.c

index 43cd5a3c79ed9c7d66743a7e5dbcbf58b8e838bf..8f0c9ed29af0d93ce8fec17a8498a7435aa43a55 100644 (file)
@@ -59,6 +59,7 @@ SET(SRCS
        src/view/view_base.c
        src/common/utils.c
        src/common/menumgr.c
+       src/common/listmgr.c
        src/common/datamgr.c
        src/layout/layout_picture.c
        src/layout/layout_sound.c
index b959c48cadc53ec6c4f45f9ede469012353c6551..8dce28443d457d55a513be63cc8a4ec2368822b8 100644 (file)
 #define SIZE_STR 1024
 #define SIZE_MENU_BOX_PAD_H (40 + 40)
 #define SIZE_MENU_BOX_PAD_V 0
+#define SIZE_LIST_ITEM_X (488 + 26)
+#define SIZE_LIST_ITEM_Y (134 + 26)
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
diff --git a/include/listmgr.h b/include/listmgr.h
new file mode 100644 (file)
index 0000000..92e677e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AIR_SETTINGS_LISTMGR_H__
+#define __AIR_SETTINGS_LISTMGR_H__
+
+struct listmgr;
+
+struct listmgr *listmgr_create(Evas_Object *parent);
+bool listmgr_destroy(struct listmgr *listmgr);
+
+bool listmgr_add_list(struct listmgr *listmgr, const char *list_id,
+               struct data_class *dclass, struct grid_class *gclass);
+bool listmgr_remove_list(struct listmgr *listmgr, const char *list_id);
+
+bool listmgr_update_list(struct listmgr *listmgr, const char *list_id,
+               void (*update_done_cb)(void *data), void *user_data);
+bool listmgr_show_list(struct listmgr *listmgr, const char *list_id,
+               const char *part);
+bool listmgr_hide_list(struct listmgr *listmgr, const char *list_id,
+               const char *part);
+
+#endif /* __AIR_SETTINGS_LISTMGR_H__ */
index d8d215792e2511fb15137dc070f7dde9f1685828..534b566461f9dfe01f5bc75c815fa9d6d8c44ca6 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __AIR_SETTINGS_UTILS_H__
 #define __AIR_SETTINGS_UTILS_H__
 
+#include <inputmgr.h>
+
 Evas_Object *utils_add_layout(Evas_Object *parent, const char *group,
                Eina_Bool win_resize);
 Evas_Object *utils_add_box(Evas_Object *parent, const char *part,
@@ -30,5 +32,7 @@ Evas_Object *utils_add_popup(Evas_Object *parent, const char *style,
 Evas_Object *utils_add_table(Evas_Object *parent, int padding_x, int padding_y);
 Evas_Object *utils_add_ctxpopup(Evas_Object *parent, int opt_size, int *opt_id,
                const char **opt_text, input_handler *opt_handler, void *data);
+Evas_Object *utils_add_gengrid(Evas_Object *parent, Eina_Bool horizontal,
+               int width, int height);
 
 #endif /* __AIR_SETTINGS_UTILS_H__ */
diff --git a/src/common/listmgr.c b/src/common/listmgr.c
new file mode 100644 (file)
index 0000000..090f7e6
--- /dev/null
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Elementary.h>
+#include <gridmgr.h>
+#include <app_debug.h>
+
+#include "datamgr.h"
+#include "utils.h"
+#include "define.h"
+
+struct listmgr {
+       Evas_Object *parent;
+       Eina_List *list;
+};
+
+struct list_item {
+       char *list_id;
+       struct datamgr *dmgr;
+       struct gridmgr *gmgr;
+       Evas_Object *grid;
+};
+
+struct listmgr *listmgr_create(Evas_Object *parent)
+{
+       struct listmgr *listmgr;
+
+       if (!parent) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       listmgr = calloc(1, sizeof(*listmgr));
+       if (!listmgr) {
+               _ERR("Calloc failed.");
+               return NULL;
+       }
+
+       listmgr->parent = parent;
+
+       return listmgr;
+}
+
+bool listmgr_destroy(struct listmgr *listmgr)
+{
+       struct list_item *litem;
+
+       if (!listmgr) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       EINA_LIST_FREE(listmgr->list, litem) {
+               gridmgr_destroy(litem->gmgr);
+               datamgr_destroy(litem->dmgr);
+               free(litem->list_id);
+               free(litem);
+       }
+
+       free(listmgr);
+       listmgr = NULL;
+
+       return true;
+}
+
+static struct list_item *_get_list_item(struct listmgr *listmgr,
+               const char *list_id)
+{
+       Eina_List *l;
+       struct list_item *litem;
+
+       EINA_LIST_FOREACH(listmgr->list, l, litem) {
+               if (!litem)
+                       continue;
+
+               if (!strcmp(litem->list_id, list_id))
+                       return litem;
+       }
+
+       return NULL;
+}
+
+static bool _add_grid(struct list_item *litem, Evas_Object *parent,
+               struct grid_class *gclass)
+{
+       struct gridmgr *gmgr;
+       Evas_Object *grid;
+
+       gmgr = gridmgr_create();
+       if (!gmgr) {
+               _ERR("Gridmgr create failed.");
+               return false;
+       }
+
+       grid = utils_add_gengrid(parent, EINA_TRUE,
+                       SIZE_LIST_ITEM_X, SIZE_LIST_ITEM_Y);
+       if (!grid) {
+               _ERR("Add gengrid failed.");
+               gridmgr_destroy(gmgr);
+               return false;
+       }
+
+       if (!gridmgr_add_grid(gmgr, litem->list_id, grid, gclass)) {
+               _ERR("Gridmgr add grid failed.");
+               evas_object_del(grid);
+               gridmgr_destroy(gmgr);
+               return false;
+       }
+
+       litem->gmgr = gmgr;
+       litem->grid = grid;
+
+       return true;
+}
+
+bool listmgr_add_list(struct listmgr *listmgr, const char *list_id,
+               struct data_class *dclass, struct grid_class *gclass)
+{
+       struct list_item *litem;
+
+       if (!listmgr || !list_id || !dclass || !gclass) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       litem = _get_list_item(listmgr, list_id);
+       if (litem) {
+               _ERR("LIST ID [%s] already exists.", list_id);
+               return false;
+       }
+
+       litem = calloc(1, sizeof(*litem));
+       if (!litem) {
+               _ERR("Calloc failed.");
+               return false;
+       }
+
+       litem->list_id = strdup(list_id);
+
+       litem->dmgr = datamgr_create(dclass);
+       if (!litem->dmgr) {
+               _ERR("Datamgr create failed.");
+               free(litem);
+               return false;
+       }
+
+       if (!_add_grid(litem, listmgr->parent, gclass)) {
+               _ERR("Add grid failed.");
+               datamgr_destroy(litem->dmgr);
+               free(litem);
+               return false;
+       }
+
+       listmgr->list = eina_list_append(listmgr->list, litem);
+
+       return true;
+}
+
+bool listmgr_remove_list(struct listmgr *listmgr, const char *list_id)
+{
+       struct list_item *litem;
+
+       if (!listmgr || !list_id) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       litem = _get_list_item(listmgr, list_id);
+       if (!litem) {
+               _ERR("List %s does not exist.", list_id);
+               return false;
+       }
+
+       gridmgr_destroy(litem->gmgr);
+       datamgr_destroy(litem->dmgr);
+
+       free(litem->list_id);
+
+       listmgr->list = eina_list_remove(listmgr->list, litem);
+
+       return true;
+}
+
+bool listmgr_update_list(struct listmgr *listmgr, const char *list_id,
+               void (*update_done_cb)(void *data), void *user_data)
+{
+       struct list_item *litem;
+
+       if (!listmgr || !list_id || !update_done_cb) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       litem = _get_list_item(listmgr, list_id);
+       if (!litem) {
+               _ERR("List %s does not exist.", list_id);
+               return false;
+       }
+
+       if (!datamgr_update(litem->dmgr, update_done_cb, user_data)) {
+               _ERR("Datamgr update failed.");
+               return false;
+       }
+
+       return true;
+}
+
+bool listmgr_show_list(struct listmgr *listmgr, const char *list_id,
+               const char *part)
+{
+       struct list_item *litem;
+
+       if (!listmgr || !list_id || !part) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       litem = _get_list_item(listmgr, list_id);
+       if (!litem) {
+               _ERR("List %s does not exist.", list_id);
+               return false;
+       }
+
+       if (!gridmgr_append_list(litem->gmgr, list_id, litem->dmgr->list)) {
+               _ERR("Gridmgr append list failed.");
+               return false;
+       }
+
+       elm_object_part_content_set(listmgr->parent, part, litem->grid);
+       evas_object_show(litem->grid);
+
+       return true;
+}
+
+bool listmgr_hide_list(struct listmgr *listmgr, const char *list_id,
+               const char *part)
+{
+       struct list_item *litem;
+
+       if (!listmgr || !list_id || !part) {
+               _ERR("Invalid argument.");
+               return false;
+       }
+
+       litem = _get_list_item(listmgr, list_id);
+       if (!litem) {
+               _ERR("List %s does not exist.", list_id);
+               return false;
+       }
+
+       elm_object_part_content_unset(listmgr->parent, part);
+       evas_object_hide(litem->grid);
+
+       return true;
+}
index 123c9317c93e9e54fa73fbbc7637912657ab1dba..5675c46ce57a5d18d13935eeb01b8786e6b1d542 100644 (file)
@@ -241,3 +241,37 @@ Evas_Object *utils_add_ctxpopup(Evas_Object *parent, int opt_size, int *opt_id,
 
        return ctxpopup;
 }
+
+
+Evas_Object *utils_add_gengrid(Evas_Object *parent, Eina_Bool horizontal,
+               int width, int height)
+{
+       Evas_Object *grid;
+
+       if (!parent) {
+               _ERR("Invalid argument.");
+               return NULL;
+       }
+
+       grid = elm_gengrid_add(parent);
+       if (!grid) {
+               _ERR("elm_gengrid_add failed.");
+               return NULL;
+       }
+
+       evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
+                       EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+       elm_gengrid_multi_select_set(grid, EINA_FALSE);
+       elm_gengrid_horizontal_set(grid, horizontal);
+       elm_gengrid_align_set(grid, 0.0, 0.0);
+       elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
+       elm_gengrid_item_size_set(grid,
+                       elm_config_scale_get() * width,
+                       elm_config_scale_get() * height);
+       elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF,
+                       ELM_SCROLLER_POLICY_OFF);
+
+       return grid;
+}