1.Limit the max length of Network connection profile
[apps/core/preloaded/settings.git] / setting-common / src / setting-common-view.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-common-view.h>
22
23 #include <Elementary.h>
24
25 #include <setting-common-data-error.h>
26 #include <setting-debug.h>
27
28 #define MAX_VIEWNODE_NUM        15
29 typedef struct _SettingViewNode {
30         setting_view *view;
31         setting_view *topview;
32 } SettingViewNode;
33 static setting_view *g_cur_view;;       /* use by 'End Key' process */
34 static SettingViewNode g_view_node_table[MAX_VIEWNODE_NUM];
35 static int g_view_node_table_cur_size = 0;
36
37 int setting_view_node_set_cur_view(setting_view *view)
38 {
39         g_cur_view = view;
40         return 0;
41 }
42
43 setting_view *setting_view_node_get_cur_view()
44 {
45         return g_cur_view;
46 }
47
48 int setting_view_node_table_intialize()
49 {
50         g_cur_view = NULL;
51         g_view_node_table_cur_size = 0;
52         return 0;
53 }
54
55 int
56 setting_view_node_table_register(setting_view *view, setting_view *topview)
57 {
58         //SETTING_TRACE_BEGIN;
59         if (g_view_node_table_cur_size >= MAX_VIEWNODE_NUM) {
60                 return SETTING_RETURN_FAIL;
61         }
62
63         g_view_node_table[g_view_node_table_cur_size].view = view;
64         g_view_node_table[g_view_node_table_cur_size].topview = topview;
65         g_view_node_table_cur_size++;
66         return 0;
67 }
68
69 int setting_view_cb_at_endKey(void *cb)
70 {
71         SETTING_TRACE_BEGIN;
72         int idx = 0;
73         SettingViewNode *viewnode = NULL;
74         for (; idx < g_view_node_table_cur_size; idx++) {
75                 if (g_cur_view == g_view_node_table[idx].view) {
76                         viewnode = &(g_view_node_table[idx]);
77                         break;
78                 }
79         }
80         if (viewnode && viewnode->view && viewnode->topview) {
81                 setting_view_change(viewnode->view, viewnode->topview, cb);
82         }
83         return 0;
84 }
85
86 setting_view *setting_view_get_topview(setting_view *view)
87 {
88         SETTING_TRACE_BEGIN;
89         retv_if(NULL == view, NULL);
90         int idx = 0;
91         SettingViewNode *viewnode = NULL;
92         for (; idx < g_view_node_table_cur_size; idx++) {
93                 if (view == g_view_node_table[idx].view) {
94                         viewnode = &(g_view_node_table[idx]);
95                         break;
96                 }
97         }
98         if (viewnode && viewnode->topview) {
99                 return viewnode->topview;
100         }
101         else
102         {
103                 return NULL;
104         }
105 }
106
107 void setting_view_update_topview(setting_view *view, setting_view *topview)
108 {
109         SETTING_TRACE_BEGIN;
110         ret_if(NULL == view);
111         int idx = 0;
112         SettingViewNode *viewnode = NULL;
113         for (; idx < g_view_node_table_cur_size; idx++) {
114                 if (view == g_view_node_table[idx].view) {
115                         viewnode = &(g_view_node_table[idx]);
116                         break;
117                 }
118         }
119         if (viewnode) {
120                 viewnode->topview = topview;
121         }
122         else
123         {
124         }
125 }
126
127
128 int setting_view_create(setting_view *view, void *cb)
129 {
130         /* error check */
131         setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
132
133         int ret = SETTING_RETURN_FAIL;
134
135         if (!view->is_create && view->create) {//error handle:create only when the view doesn't exit
136                 ret = view->create(cb);
137         }
138
139         return ret;
140 }
141
142 int setting_view_destroy(setting_view *view, void *cb)
143 {
144         /* error check */
145         setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
146
147         int ret = SETTING_RETURN_FAIL;
148
149         if (view->is_create && view->destroy) {//error handle:destroy only when the view exits
150                 ret = view->destroy(cb);
151         }
152
153         return ret;
154 }
155
156 int setting_view_update(setting_view *view, void *cb)
157 {
158         /* error check */
159         setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
160
161         int ret = SETTING_RETURN_FAIL;
162
163         if (view->is_create && view->update) {//error handle:update only when the view exits
164                 ret = view->update(cb);
165         }
166
167         return ret;
168 }
169
170 int setting_view_cleanup(setting_view *view, void *cb)
171 {
172         /* error check */
173         setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
174
175         int ret = SETTING_RETURN_FAIL;
176
177         if (view->is_create && view->cleanup) {//error handle:cleanup only when the view exits
178                 ret = view->cleanup(cb);
179         }
180
181         return ret;
182 }
183
184 int
185 setting_view_change(setting_view *from_view, setting_view *to_view, void *cb)
186 {
187         /* error check */
188         setting_retvm_if(!from_view || !to_view || !cb ,
189                          SETTING_GENERAL_ERR_NULL_DATA_PARAMETER,
190                          "Invalid arguement");
191
192         int ret = SETTING_RETURN_SUCCESS;
193         if (from_view == setting_view_get_topview(to_view)) {
194                 //from a parent view to his child view, don't need cleanup parent view
195         } else {
196                 //from a child view to his parent view, need cleanup child view
197                 ret = setting_view_cleanup(from_view, cb);
198         }
199
200         if (ret == SETTING_RETURN_FAIL) {
201                 return SETTING_RETURN_FAIL;
202         }
203
204         if (to_view->is_create == 1) {
205                 ret = setting_view_update(to_view, cb);
206         } else {
207                 ret = setting_view_create(to_view, cb);
208         }
209         g_cur_view = to_view;   /* compute new value of g_cur_view. */
210         return ret;
211 }