add initial view_user_edit
[profile/tv/apps/native/air_home.git] / src / view / view_user.c
1 /*
2
3  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <Elementary.h>
19 #include <app_debug.h>
20 #include <viewmgr.h>
21 #include <inputmgr.h>
22
23 #include "defs.h"
24 #include "view_user.h"
25 #include "view_user_edit.h"
26 #include "data_user.h"
27 #include "datamgr.h"
28 #include "utils.h"
29
30 struct _priv {
31         Evas_Object *win;
32         Evas_Object *base;
33
34         struct datamgr *dm;
35 };
36
37 static Evas_Object *_create(Evas_Object *win, void *data)
38 {
39         struct _priv *priv;
40         struct datamgr *dm;
41         Evas_Object *base;
42
43         if (!win) {
44                 _ERR("Invalid argument");
45                 return NULL;
46         }
47
48         priv = calloc(1, sizeof(*priv));
49         if (!priv) {
50                 _ERR("failed to calloc priv");
51                 return NULL;
52         }
53
54         dm = datamgr_init(datamgr_user_get_dclass(), VIEW_USER);
55         if (!dm) {
56                 _ERR("failed to initialize datamgr");
57                 free(priv);
58                 return NULL;
59         }
60
61         base = utils_add_layout(win, GRP_USER, false, NULL);
62         if (!base) {
63                 _ERR("failed to create base");
64                 datamgr_fini(dm);
65                 free(priv);
66                 return NULL;
67         }
68         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69         elm_win_resize_object_add(win, base);
70
71         priv->win = win;
72         priv->base = base;
73         priv->dm = dm;
74
75         viewmgr_set_view_data(VIEW_USER, priv);
76         viewmgr_add_view(view_user_edit_get_vclass(), dm);
77
78         return base;
79 }
80
81 static void _show(void *data)
82 {
83         struct _priv *priv;
84
85         if (!data) {
86                 _ERR("Invalid argument");
87                 return;
88         }
89
90         priv = data;
91
92         evas_object_show(priv->base);
93 }
94
95 static void _hide(void *data)
96 {
97         struct _priv *priv;
98
99         if (!data) {
100                 _ERR("Invalid argument");
101                 return;
102         }
103
104         priv = data;
105
106         evas_object_hide(priv->base);
107 }
108
109 static void _destroy(void *data)
110 {
111         struct _priv *priv;
112
113         if (!data) {
114                 _ERR("Invalid argument");
115                 return;
116         }
117
118         priv = data;
119
120         viewmgr_remove_view(VIEW_USER_EDIT);
121         datamgr_fini(priv->dm);
122         evas_object_del(priv->base);
123         free(priv);
124 }
125
126 static view_class vclass = {
127         .view_id = VIEW_USER,
128         .create = _create,
129         .show = _show,
130         .hide = _hide,
131         .destroy = _destroy
132 };
133
134 view_class *view_user_get_vclass(void)
135 {
136         return &vclass;
137 }
138