Fix N_SE-13547 and N_SE-13516
[apps/core/preloaded/settings.git] / setting-connectivity / src / setting-connectivity.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
22 /**
23  *@defgroup setting-connectivity
24  *UG creation code for setting-connectivity
25  */
26
27 #include <setting-connectivity.h>
28 #include <devman.h>
29
30 #ifndef UG_MODULE_API
31 #define UG_MODULE_API __attribute__ ((visibility("default")))
32 #endif
33
34 #define USB_BTN_NO      0
35
36 setting_view *__get_connective_view_to_load(service_h service)
37 {
38         SETTING_TRACE_BEGIN;
39         char *viewtype = NULL;
40
41         service_get_extra_data(service, "viewtype", &viewtype);
42         if(!viewtype)
43                 return NULL;
44
45         SETTING_TRACE("viewtype:%s", viewtype);
46
47         if (!safeStrCmp(viewtype, "usb")) {
48                 return &setting_view_connectivity_usb;
49         } else {
50                 return NULL;    /* &setting_view_connective_main; */
51         }
52
53 }
54
55 Evas_Object *__get_connective_layout_to_return(service_h service, void *priv)
56 {
57         SETTING_TRACE_BEGIN;
58         SettingConnectivityUG *connectiveUG = priv;
59         char *viewtype = NULL;
60
61         service_get_extra_data(service, "viewtype", &viewtype);
62         if(!viewtype)
63                 return NULL;
64
65         SETTING_TRACE("viewtype:%s", viewtype);
66
67         if (!safeStrCmp(viewtype, "usb")) {
68                 return connectiveUG->ly_usb;
69         } else {
70                 return NULL;    /* &setting_view_connective_main; */
71         }
72
73 }
74
75 static void setting_connective_ug_cb_resize(void *data, Evas *e,
76                                             Evas_Object *obj, void *event_info)
77 {
78         SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
79         /* setting_view_update(&setting_view_about_main, ad); */
80         setting_view_update(ad->view_to_load, ad);
81 }
82
83 static void *setting_connective_ug_on_create(ui_gadget_h ug,
84                                              enum ug_mode mode, service_h service,
85                                              void *priv)
86 {
87         setting_retvm_if((!priv), NULL, "!priv");
88
89         SettingConnectivityUG *connectiveUG = priv;
90         connectiveUG->ug = ug;
91
92         connectiveUG->win_main_layout =
93             (Evas_Object *) ug_get_parent_layout(ug);
94         connectiveUG->win_get = (Evas_Object *) ug_get_window();
95         evas_object_show(connectiveUG->win_main_layout);
96         connectiveUG->evas =
97             evas_object_evas_get(connectiveUG->win_main_layout);
98
99         setting_retvm_if(connectiveUG->win_main_layout == NULL, NULL,
100                          "cannot get main window ");
101
102
103         /* register view node table */
104         setting_view_node_table_intialize();
105         setting_view_node_table_register(&setting_view_connectivity_usb, NULL);
106         setting_view_node_table_register(&setting_view_connectivity_usb_help,
107                                          &setting_view_connectivity_usb);
108
109         /*  creating a view. */
110         setting_create_Gendial_itc("dialogue/title", &(connectiveUG->itc_title));
111         setting_create_Gendial_itc("dialogue/1text", &(connectiveUG->itc_1text));
112         setting_create_Gendial_itc("dialogue/1text.1icon", &(connectiveUG->itc_1text_1icon));
113         setting_create_Gendial_itc("dialogue/1text.1icon", &(connectiveUG->itc_1text_1icon_gen));       /* toggle */
114         setting_create_Gendial_itc("dialogue/2text.3", &(connectiveUG->itc_2text_3));
115         setting_create_Gendial_itc("dialogue/2text.3/expandable", &(connectiveUG->itc_2text_3_parent));
116         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2", &(connectiveUG->itc_1icon_1text_sub));
117         setting_create_Gendial_itc("multiline/1text", &(connectiveUG->itc_help_style));
118
119         connectiveUG->itc_seperator.item_style = "dialogue/separator/21/with_line";
120         connectiveUG->itc_seperator.func.text_get = NULL;
121         connectiveUG->itc_seperator.func.content_get = NULL;
122         connectiveUG->itc_seperator.func.state_get = NULL;
123         connectiveUG->itc_seperator.func.del = NULL;
124
125
126
127         connectiveUG->view_to_load = __get_connective_view_to_load(service);
128         setting_retvm_if(NULL == connectiveUG->view_to_load, NULL,
129                          "NULL == connectiveUG->view_to_load");
130         setting_view_node_set_cur_view(connectiveUG->view_to_load);
131         setting_view_create(connectiveUG->view_to_load, (void *)connectiveUG);
132         evas_object_event_callback_add(connectiveUG->win_main_layout,
133                                        EVAS_CALLBACK_RESIZE,
134                                        setting_connective_ug_cb_resize,
135                                        connectiveUG);
136         return __get_connective_layout_to_return(service, connectiveUG);
137 }
138
139 static void setting_connective_ug_on_start(ui_gadget_h ug, service_h service,
140                                            void *priv)
141 {
142 }
143
144 static void setting_connective_ug_on_pause(ui_gadget_h ug, service_h service,
145                                            void *priv)
146 {
147 }
148
149 static void setting_connective_ug_on_resume(ui_gadget_h ug, service_h service,
150                                             void *priv)
151 {
152 }
153
154 static void setting_connective_ug_on_destroy(ui_gadget_h ug,
155                                              service_h service, void *priv)
156 {
157         SETTING_TRACE_BEGIN;
158         setting_retm_if((!priv), "!priv");
159         SettingConnectivityUG *connectiveUG = priv;
160
161         evas_object_event_callback_del(connectiveUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_connective_ug_cb_resize);   /* fix flash issue for gallery */
162         connectiveUG->ug = ug;
163
164         /*  called when this shared gadget is terminated. similar with app_exit */
165         if (&setting_view_connectivity_usb == connectiveUG->view_to_load) {
166                 setting_view_destroy(&setting_view_connectivity_usb_help,
167                                      connectiveUG);
168                 setting_view_destroy(&setting_view_connectivity_usb,
169                                      connectiveUG);
170         }
171
172         if (NULL != ug_get_layout(connectiveUG->ug)) {
173                 evas_object_hide((Evas_Object *)
174                                  ug_get_layout(connectiveUG->ug));
175                 evas_object_del((Evas_Object *)
176                                 ug_get_layout(connectiveUG->ug));
177         }
178
179         SETTING_TRACE_END;
180 }
181
182 static void setting_connective_ug_on_message(ui_gadget_h ug, service_h msg,
183                                              service_h service, void *priv)
184 {
185         SETTING_TRACE_BEGIN;
186 }
187
188 static void setting_connective_ug_on_event(ui_gadget_h ug,
189                                            enum ug_event event, service_h service,
190                                            void *priv)
191 {
192         SETTING_TRACE_BEGIN;
193         switch (event) {
194         case UG_EVENT_LOW_MEMORY:
195                 break;
196         case UG_EVENT_LOW_BATTERY:
197                 break;
198         case UG_EVENT_LANG_CHANGE:
199                 break;
200         case UG_EVENT_ROTATE_PORTRAIT:
201                 break;
202         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
203                 break;
204         case UG_EVENT_ROTATE_LANDSCAPE:
205                 break;
206         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
207                 break;
208         case UG_EVENT_REGION_CHANGE:
209                 break;
210         default:
211                 break;
212         }
213 }
214
215 static void setting_connective_ug_on_key_event(ui_gadget_h ug,
216                                                enum ug_key_event event,
217                                                service_h service, void *priv)
218 {
219         SETTING_TRACE_BEGIN;
220         SettingConnectivityUG *ad = (SettingConnectivityUG *) priv;
221
222         switch (event) {
223         case UG_KEY_EVENT_END:
224                 {
225                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
226                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
227                                 ug_destroy_me(ug);
228                         } else {
229                                 /* elm_naviframe_item_pop(ad->navi_bar); */
230                                 setting_view_cb_at_endKey(ad);
231                         }
232                 }
233                 break;
234         default:
235                 break;
236         }
237 }
238
239 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
240 {
241         SETTING_TRACE_BEGIN;
242         SettingConnectivityUG *connectiveUG =
243             calloc(1, sizeof(SettingConnectivityUG));
244         setting_retvm_if(!connectiveUG, -1,
245                          "Create SettingConnectivityUG obj failed");
246
247         ops->create = setting_connective_ug_on_create;
248         ops->start = setting_connective_ug_on_start;
249         ops->pause = setting_connective_ug_on_pause;
250         ops->resume = setting_connective_ug_on_resume;
251         ops->destroy = setting_connective_ug_on_destroy;
252         ops->message = setting_connective_ug_on_message;
253         ops->event = setting_connective_ug_on_event;
254         ops->key_event = setting_connective_ug_on_key_event;
255         ops->priv = connectiveUG;
256         ops->opt = UG_OPT_INDICATOR_ENABLE;
257
258         return 0;
259 }
260
261 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
262 {
263         SETTING_TRACE_BEGIN;
264         struct SettingConnectivityUG *connectiveUG;
265         setting_retm_if(!ops, "ops == NULL");
266
267         connectiveUG = ops->priv;
268         if (connectiveUG) {
269                 FREE(connectiveUG);
270         }
271 }
272
273 /*****/
274 UG_MODULE_API int setting_plugin_reset(service_h service, void *priv)
275 {
276         SETTING_TRACE_BEGIN;
277
278         int ret = 0;
279         char *ug_type = NULL;
280
281         service_get_extra_data(service, "viewtype", &ug_type);
282         if(!ug_type)
283                 return -1;
284
285         if (0 == safeStrCmp(ug_type, "usb")) {
286                 /* usb */
287 #if SUPPORT_RUN_SYSTEM_COMMAND
288                 ret += excuteCmd(SETTING_POSTINST_FILE, 1, "usbconnectivity");
289 #else
290                 ret += vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 0);
291                 /* Resetting VCONFKEY_SETAPPL_USB_MODE_INT (current mode) is not necessary.
292                  * If USB cable is removed, the key value is SETTING_USB_NONE_MODE by USB-setting.
293                  * If USB cable is connected, the key value is changed by selected mode. */
294                 ret += vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, CHANGE_COMPLETE);
295 #endif
296         }
297         return ret;
298 }