tizen 2.3.1 release
[apps/home/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 <setting-cfg.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 /**
37   * This function checks the USB connection status
38   */
39 int check_usb_jack_status()
40 {
41         SETTING_TRACE_BEGIN;
42         bool usb_connection = false;
43         int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &usb_connection);
44         if (ret == RUNTIME_INFO_ERROR_NONE && usb_connection == true) {
45                 return USB_CONNECTED;   /*  USB is connected */
46         } else {
47                 return USB_DISCONNECTED;       /*  USB is disconnected */
48         }
49 }
50
51 setting_view *__get_connective_view_to_load(app_control_h service)
52 {
53         SETTING_TRACE_BEGIN;
54         char *viewtype = NULL;
55
56         app_control_get_extra_data(service, "viewtype", &viewtype);
57         if (!viewtype)
58                 return NULL;
59
60         SETTING_TRACE("viewtype:%s", viewtype);
61
62         if (!safeStrCmp(viewtype, "usb")) {
63                 FREE(viewtype);
64                 return &setting_view_connectivity_usb;
65         } else {
66                 FREE(viewtype);
67                 return NULL;    /* &setting_view_connective_main; */
68         }
69
70 }
71
72 Evas_Object *__get_connective_layout_to_return(app_control_h service, void *priv)
73 {
74         SETTING_TRACE_BEGIN;
75         SettingConnectivityUG *connectiveUG = priv;
76         char *viewtype = NULL;
77
78         app_control_get_extra_data(service, "viewtype", &viewtype);
79         if (!viewtype)
80                 return NULL;
81
82         SETTING_TRACE("viewtype:%s", viewtype);
83
84         if (!safeStrCmp(viewtype, "usb")) {
85                 FREE(viewtype);
86                 return connectiveUG->ly_usb;
87         } else {
88                 FREE(viewtype);
89                 return NULL;    /* &setting_view_connective_main; */
90         }
91
92 }
93
94 static void setting_connective_ug_cb_resize(void *data, Evas *e,
95                                             Evas_Object *obj, void *event_info)
96 {
97         SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
98         /* setting_view_update(&setting_view_about_main, ad); */
99         setting_view_update(ad->view_to_load, ad);
100 }
101
102 static void *setting_connective_ug_on_create(ui_gadget_h ug,
103                                              enum ug_mode mode, app_control_h service,
104                                              void *priv)
105 {
106         setting_retvm_if((!priv), NULL, "!priv");
107
108         SettingConnectivityUG *connectiveUG = priv;
109         connectiveUG->ug = ug;
110
111         connectiveUG->win_main_layout =
112             (Evas_Object *) ug_get_parent_layout(ug);
113         connectiveUG->win_get = (Evas_Object *) ug_get_window();
114         evas_object_show(connectiveUG->win_main_layout);
115         connectiveUG->evas =
116             evas_object_evas_get(connectiveUG->win_main_layout);
117
118         setting_retvm_if(connectiveUG->win_main_layout == NULL, NULL,
119                          "cannot get main window ");
120
121         setting_set_i18n(SETTING_PACKAGE, SETTING_LOCALEDIR);
122
123         /* register view node table */
124         setting_view_node_table_intialize();
125         setting_view_node_table_register(&setting_view_connectivity_usb, NULL);
126         setting_view_node_table_register(&setting_view_connectivity_usb_help,
127                                          &setting_view_connectivity_usb);
128
129         /*  creating a view. */
130         setting_create_Gendial_itc("groupindex", &(connectiveUG->itc_title));
131         setting_create_Gendial_itc("1line", &(connectiveUG->itc_1text));
132         setting_create_Gendial_itc("1line", &(connectiveUG->itc_1text_1icon));
133         setting_create_Gendial_itc("1line", &(connectiveUG->itc_1text_1icon_gen));      /* toggle */
134         setting_create_Gendial_itc("dialogue/2text.3", &(connectiveUG->itc_2text_3));
135         setting_create_Gendial_itc("2line.top", &(connectiveUG->itc_2text_3_parent));
136         setting_create_Gendial_itc("1line", &(connectiveUG->itc_1icon_1text_sub));
137         setting_create_Gendial_itc("multiline_sub", &(connectiveUG->itc_help_style));
138
139         connectiveUG->view_to_load = __get_connective_view_to_load(service);
140         setting_retvm_if(NULL == connectiveUG->view_to_load, NULL,
141                          "NULL == connectiveUG->view_to_load");
142         setting_view_node_set_cur_view(connectiveUG->view_to_load);
143         setting_view_create(connectiveUG->view_to_load, (void *)connectiveUG);
144         evas_object_event_callback_add(connectiveUG->win_main_layout,
145                                        EVAS_CALLBACK_RESIZE,
146                                        setting_connective_ug_cb_resize,
147                                        connectiveUG);
148         return __get_connective_layout_to_return(service, connectiveUG);
149 }
150
151 static void setting_connective_ug_on_start(ui_gadget_h ug, app_control_h service,
152                                            void *priv)
153 {
154 }
155
156 static void setting_connective_ug_on_pause(ui_gadget_h ug, app_control_h service,
157                                            void *priv)
158 {
159 }
160
161 static void setting_connective_ug_on_resume(ui_gadget_h ug, app_control_h service,
162                                             void *priv)
163 {
164 }
165
166 static void setting_connective_ug_on_destroy(ui_gadget_h ug,
167                                              app_control_h service, void *priv)
168 {
169         SETTING_TRACE_BEGIN;
170         setting_retm_if((!priv), "!priv");
171         SettingConnectivityUG *connectiveUG = priv;
172
173         evas_object_event_callback_del(connectiveUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_connective_ug_cb_resize);   /* fix flash issue for gallery */
174         connectiveUG->ug = ug;
175
176         /*  called when this shared gadget is terminated. similar with app_exit */
177         if (&setting_view_connectivity_usb == connectiveUG->view_to_load) {
178                 setting_view_destroy(&setting_view_connectivity_usb_help,
179                                      connectiveUG);
180                 setting_view_destroy(&setting_view_connectivity_usb,
181                                      connectiveUG);
182         }
183
184         if (NULL != ug_get_layout(connectiveUG->ug)) {
185                 evas_object_hide((Evas_Object *)
186                                  ug_get_layout(connectiveUG->ug));
187                 evas_object_del((Evas_Object *)
188                                 ug_get_layout(connectiveUG->ug));
189         }
190
191         SETTING_TRACE_END;
192 }
193
194 static void setting_connective_ug_on_message(ui_gadget_h ug, app_control_h msg,
195                                              app_control_h service, void *priv)
196 {
197         SETTING_TRACE_BEGIN;
198 }
199
200 static void setting_connective_ug_on_event(ui_gadget_h ug,
201                                            enum ug_event event, app_control_h service,
202                                            void *priv)
203 {
204         SETTING_TRACE_BEGIN;
205         switch (event) {
206                 case UG_EVENT_LOW_MEMORY:
207                         break;
208                 case UG_EVENT_LOW_BATTERY:
209                         break;
210                 case UG_EVENT_LANG_CHANGE:
211                         break;
212                 case UG_EVENT_ROTATE_PORTRAIT:
213                         break;
214                 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
215                         break;
216                 case UG_EVENT_ROTATE_LANDSCAPE:
217                         break;
218                 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
219                         break;
220                 case UG_EVENT_REGION_CHANGE:
221                         break;
222                 default:
223                         break;
224         }
225 }
226
227 static void setting_connective_ug_on_key_event(ui_gadget_h ug,
228                                                enum ug_key_event event,
229                                                app_control_h service, void *priv)
230 {
231         SETTING_TRACE_BEGIN;
232         SettingConnectivityUG *ad = (SettingConnectivityUG *) priv;
233
234         switch (event) {
235                 case UG_KEY_EVENT_END: {
236                                 if (elm_naviframe_top_item_get(ad->navi_bar) ==
237                                     elm_naviframe_bottom_item_get(ad->navi_bar)) {
238                                         ug_destroy_me(ug);
239                                 } else {
240                                         /* elm_naviframe_item_pop(ad->navi_bar); */
241                                         setting_view_cb_at_endKey(ad);
242                                 }
243                         }
244                         break;
245                 default:
246                         break;
247         }
248 }
249
250 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
251 {
252         SETTING_TRACE_BEGIN;
253         SettingConnectivityUG *connectiveUG =
254             calloc(1, sizeof(SettingConnectivityUG));
255         setting_retvm_if(!connectiveUG, -1,
256                          "Create SettingConnectivityUG obj failed");
257
258         ops->create = setting_connective_ug_on_create;
259         ops->start = setting_connective_ug_on_start;
260         ops->pause = setting_connective_ug_on_pause;
261         ops->resume = setting_connective_ug_on_resume;
262         ops->destroy = setting_connective_ug_on_destroy;
263         ops->message = setting_connective_ug_on_message;
264         ops->event = setting_connective_ug_on_event;
265         ops->key_event = setting_connective_ug_on_key_event;
266         ops->priv = connectiveUG;
267         ops->opt = UG_OPT_INDICATOR_ENABLE;
268
269         return 0;
270 }
271
272 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
273 {
274         SETTING_TRACE_BEGIN;
275         struct SettingConnectivityUG *connectiveUG;
276         setting_retm_if(!ops, "ops == NULL");
277
278         connectiveUG = ops->priv;
279         if (connectiveUG) {
280                 FREE(connectiveUG);
281         }
282 }
283
284 UG_MODULE_API int setting_plugin_search_init(app_control_h service, void *priv,
285                                              char **applocale)
286 {
287         int i, size;
288         Setting_Cfg_Node_T *node;
289         Eina_List **pplist = priv;
290         const Setting_Cfg_Node_T search_configs[] = {
291                 {DEVOPTION_STR_USB_DEBUGGING, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
292                 {DEVOPTION_STR_SHOW_CPU_USAGE, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
293                 {DEVOPTION_STR_RENDERTING_ENGINE, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
294                 {DEVOPTION_STR_LIMIT_BACKGROUND_PRECESS, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL},
295                 {DEVOPTION_STR_CRASH_VIEWER, NULL, NULL, 0, Cfg_Item_unResetable, 0, Cfg_Item_View_Node, NULL, NULL, NULL, NULL}
296         };
297
298         retv_if(NULL == priv, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
299         retv_if(NULL == applocale, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
300
301         *applocale = strdup("setting:/usr/apps/org.tizen.setting/res/locale");
302
303         size = sizeof(search_configs) / sizeof(Setting_Cfg_Node_T);
304
305         for (i = 0; i < size; i++) {
306                 node = setting_plugin_search_item_subindex_add(
307                            search_configs[i].key_name,
308                            "viewtype:usb",
309                            IMG_USBconnection,
310                            search_configs[i].item_type,
311                            search_configs[i].data,
312                            "Developer options");
313
314                 *pplist = eina_list_append(*pplist, node);
315         }
316         return 0;
317 }
318