3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (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
9 * http://floralicense.org/license/
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.
17 #include <setting-connectivity-usb.h>
18 #include <app_manager.h>
20 #define DEBUG_MODE_POPUP_TITLE "IDS_ST_HEADER_ALLOW_USB_DEBUGGING_Q_ABB"
21 #define DEBUG_MODE_POPUP_TEXT "IDS_ST_BODY_USB_DEBUGGING_IS_INTENDED_FOR_DEVELOPMENT_PURPOSES_ONLY_MSG"
23 static int setting_connectivity_usb_create(void *cb);
24 static int setting_connectivity_usb_destroy(void *cb);
25 static int setting_connectivity_usb_update(void *cb);
26 static int setting_connectivity_usb_cleanup(void *cb);
28 static void debug_mode_change_vconf_cb(keynode_t *key, void *data);
29 static void in_mode_change_vconf_cb(keynode_t *key, void *data);
30 static void unload_popup(void* data);
31 void load_usb_connection_popup(void* data);
33 /* This is pointer to indicate progressbars*/
34 static button_status button[NUM_PROGRESSBAR];
36 /* These variables are for the popup */
37 static Evas_Object *win_main, *popup_eo;
38 static char *popup_msg, *popup_title;
40 setting_view setting_view_connectivity_usb = {
41 .create = setting_connectivity_usb_create,
42 .destroy = setting_connectivity_usb_destroy,
43 .update = setting_connectivity_usb_update,
44 .cleanup = setting_connectivity_usb_cleanup,
47 static int setting_connectivity_change_debug_mode_toggle(SettingConnectivityUG *ad)
54 ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
56 SETTING_TRACE("FAIL: vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
59 SETTING_TRACE("debugMode: %d", debugMode);
61 elm_check_state_set(ad->debug_mode->eo_check, EINA_FALSE);
63 load_usb_connection_popup(ad);
65 ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 0);
67 SETTING_TRACE("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
76 static void setting_connectivity_main_chk_usb_debug_cb(void *data,
77 Evas_Object * obj, void *event_info)
80 retm_if(data == NULL, "Data parameter is NULL");
81 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
82 SettingConnectivityUG *ad = list_item->userdata;
84 if (0 > setting_connectivity_change_debug_mode_toggle(ad)) {
85 SETTING_TRACE("FAIL: setting_connectivity_change_debug_mode_toggle()");
91 static void setting_connectivity_usb_mouse_up_Gendial_list_cb(void *data,
92 Evas_Object *obj, void *event_info)
95 retm_if(data == NULL, "Invalid argument: data is NULL");
96 retm_if(event_info == NULL, "Invalid argument: event_info is NULL");
97 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
98 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
100 elm_genlist_item_selected_set(item, 0);
102 if (0 > setting_connectivity_change_debug_mode_toggle(ad)) {
103 SETTING_TRACE("FAIL: setting_connectivity_change_debug_mode_toggle()");
110 * To create the usb main view
116 static int setting_connectivity_usb_create(void *cb)
119 SETTING_TRACE("Start USB utilities\n");
121 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
123 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
124 Evas_Object *scroller;
129 /* win_main of the popup */
130 win_main = ad->win_get;
133 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
135 _(KeyStr_DeveloperOption),
136 dgettext("sys_string", "IDS_COM_BODY_BACK"),
137 _("IDS_COM_BODY_HELP"),
138 setting_connectivity_usb_click_softkey_cancel_cb,
139 setting_connectivity_usb_click_softkey_set_cb,
144 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
146 _(KeyStr_DeveloperOption),
147 dgettext("sys_string", "IDS_COM_BODY_BACK"),
149 setting_connectivity_usb_click_softkey_cancel_cb,
155 SETTING_TRACE("before init\n");
157 button[SETTING_USB_DEBUG_MODE].item = NULL;
158 button[SETTING_USB_DEBUG_MODE].pstate = STATE_NONE;
160 Elm_Object_Item *item = NULL;;
163 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
164 ELM_GENLIST_ITEM_NONE, NULL, NULL);
165 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
167 // [UI] USB debugging
171 err = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &toggle_dbg);
173 SETTING_TRACE_ERROR("FAIL: vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
174 /* set debug mode to true to find the problem*/
177 SETTING_TRACE("toggle_dbg: %d", toggle_dbg);
180 setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon_gen),
181 setting_connectivity_usb_mouse_up_Gendial_list_cb,
182 ad, SWALLOW_Type_1TOGGLE, NULL,
183 NULL, toggle_dbg, "IDS_ST_BODY_USB_DEBUGGING",
184 NULL, setting_connectivity_main_chk_usb_debug_cb);
186 if (ad->debug_mode) {
187 ad->debug_mode->userdata = ad;
188 button[SETTING_USB_DEBUG_MODE].item = ad->debug_mode->item;
190 SETTING_TRACE_ERROR("ad->debug_mode is NULL");
191 return SETTING_RETURN_FAIL;
194 setting_create_Gendial_field_def(scroller, &(ad->itc_help_style), NULL,
195 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
196 NULL, NULL, 0, SETTING_USB_DEBUGGING_DESC, NULL,
198 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
199 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
203 SETTING_TRACE("Second item of Second group is set\n");
205 //----------------------------------------------------------------------------------------------
206 /* Registering callback function for VCONFKEY_SETAPPL_USB_MODE_INT */
207 vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
208 debug_mode_change_vconf_cb, ad);
211 SETTING_TRACE("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
212 return SETTING_RETURN_FAIL;
215 /* Registering callback function for VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE */
216 vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE,
217 in_mode_change_vconf_cb, ad);
220 SETTING_TRACE("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)\n");
221 return SETTING_RETURN_FAIL;
225 vconf_ret = vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, &val);
226 if (vconf_ret == 0 && val == IN_MODE_CHANGE)
228 SETTING_TRACE("ad->blockUI: EINA_TRUE\n");
229 ad->blockUI = EINA_TRUE;
231 else /* val == CHANGE_COMPLETE */
233 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
234 ad->blockUI = EINA_FALSE;
237 setting_view_connectivity_usb.is_create = 1;
238 setting_view_update(&setting_view_connectivity_usb, ad);
241 return SETTING_RETURN_SUCCESS;
245 * This callback function is called when USB-setting changes VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE
249 static void in_mode_change_vconf_cb(keynode_t *key, void *data)
252 setting_retm_if(NULL == data, "ERROR:The parameter(data) is NULL\n");
253 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
254 SETTING_TRACE("ad->blockUI: %d\n", ad->blockUI);
259 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, &in_mode_change);
260 setting_retm_if (ret != 0, "vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE\n");
262 if (CHANGE_COMPLETE == in_mode_change) {
263 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
264 ad->blockUI = EINA_FALSE;
265 } else if (IN_MODE_CHANGE == in_mode_change) {
266 SETTING_TRACE("ad->blockUI: EINA_TRUE\n");
267 ad->blockUI = EINA_TRUE;
269 SETTING_TRACE("Getting in_mode_change failed\n");
276 * When VCONFKEY_SETAPPL_USB_MODE_INT is changed, all buttons are enabled
281 static void debug_mode_change_vconf_cb(keynode_t *key, void *data)
284 setting_retm_if (NULL == data, "ERROR:The parameter(data) is NULL\n");
285 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
290 ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
291 setting_retm_if (ret != 0, "ERROR: vconf_get_int(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
292 SETTING_TRACE("debugMode: %d", debugMode);
294 if (debugMode == 1) {
295 elm_check_state_set(ad->debug_mode->eo_check, EINA_TRUE);
296 } else if (debugMode == 0) {
297 elm_check_state_set(ad->debug_mode->eo_check, EINA_FALSE);
299 SETTING_TRACE("ERROR: debugMode value is improper");
302 /* Unblock setting UI */
303 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
304 ad->blockUI = EINA_FALSE;
310 * To destory the view of usb
316 static int setting_connectivity_usb_destroy(void *cb)
320 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
322 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
326 /* Removing the popup if the popup is loaded */
330 /* Closing vconf trace */
331 vconf_ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
332 debug_mode_change_vconf_cb);
335 SETTING_TRACE("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
339 vconf_ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, in_mode_change_vconf_cb);
342 SETTING_TRACE("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)\n");
346 if (ad->ly_usb != NULL) {
347 evas_object_del(ad->ly_usb);
348 setting_view_connectivity_usb.is_create = 0;
354 SETTING_TRACE("ERROR: the number of errors to destroy is %d\n", num_err);
355 return SETTING_RETURN_FAIL;
359 return SETTING_RETURN_SUCCESS;
365 * To update the view of usb
371 static int setting_connectivity_usb_update(void *cb)
375 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
376 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
378 if (ad->ly_usb != NULL) {
379 evas_object_show(ad->ly_usb);
382 return SETTING_RETURN_SUCCESS;
386 * To cleanup the view of usb
392 static int setting_connectivity_usb_cleanup(void *cb)
396 return SETTING_RETURN_SUCCESS;
400 * Do process when clicking '<-' button
407 setting_connectivity_usb_click_softkey_cancel_cb(void *data, Evas_Object *obj,
412 setting_retm_if(data == NULL, "Data parameter is NULL");
414 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
416 /* Not to block back(->) button */
417 /* Send destroy request */
418 ug_destroy_me(ad->ug);
424 * Do process when clicking 'Help' button
432 setting_connectivity_usb_click_softkey_set_cb(void *data, Evas_Object *obj,
437 setting_retm_if(data == NULL, "Data parameter is NULL");
439 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
441 /* Send destroy request */
442 setting_view_change(&setting_view_connectivity_usb,
443 &setting_view_connectivity_usb_help, ad);
450 * Here is for loading popup
456 static void unload_popup(void* data)
459 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
464 evas_object_del(ad->pop);
467 SETTING_TRACE("ad->pop == NULL\n");
470 if (popup_eo != NULL)
472 SETTING_TRACE("evas_object_del(popup_eo)\n");
473 evas_object_del(popup_eo);
478 SETTING_TRACE("popup_eo == NULL\n");
485 * Callback function to respond pushing cancel button of the usb connection popup
487 static void debug_mode_resp_cb(void *data, Evas_Object *obj, void *event_info)
491 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
493 int resp_type = btn_type(obj);
494 if (resp_type == POPUP_RESPONSE_OK) {
495 ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
497 SETTING_TRACE("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
507 * When a button on USB utilities is pushed,
508 * this function makes a popup if USB cable is not connected
510 void load_usb_connection_popup(void* data)
514 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
517 popup_msg = _(DEBUG_MODE_POPUP_TEXT);
518 popup_title = _(DEBUG_MODE_POPUP_TITLE);
520 ad->pop = setting_create_popup_with_btn(ad, win_main,//ad->win_get,
526 _("IDS_COM_SK_CANCEL"));
527 if (!(ad->pop)) SETTING_TRACE("FAIL: setting_create_popup_with_btn()");