4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <setting-connectivity-usb.h>
22 #include <app_manager.h>
24 #define DEBUG_MODE_POPUP_TEXT \
25 "USB debugging is intended for development purposes only. " \
26 "It can be used to copy data between your computer and your " \
27 "device, install application on your device without " \
28 "notification, and read log data"
30 static int setting_connectivity_usb_create(void *cb);
31 static int setting_connectivity_usb_destroy(void *cb);
32 static int setting_connectivity_usb_update(void *cb);
33 static int setting_connectivity_usb_cleanup(void *cb);
35 static void debug_mode_change_vconf_cb(keynode_t *key, void *data);
36 static void in_mode_change_vconf_cb(keynode_t *key, void *data);
37 static void unload_popup(void* data);
38 void load_usb_connection_popup(void* data);
40 /* This is pointer to indicate progressbars*/
41 static button_status button[NUM_PROGRESSBAR];
43 /* These variables are for the popup */
44 static Evas_Object *win_main, *popup_eo;
45 static char *popup_msg, *popup_title;
47 setting_view setting_view_connectivity_usb = {
48 .create = setting_connectivity_usb_create,
49 .destroy = setting_connectivity_usb_destroy,
50 .update = setting_connectivity_usb_update,
51 .cleanup = setting_connectivity_usb_cleanup,
54 static int setting_connectivity_change_debug_mode_toggle(SettingConnectivityUG *ad)
61 ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
63 SETTING_TRACE("FAIL: vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
66 SETTING_TRACE("debugMode: %d", debugMode);
68 elm_check_state_set(ad->debug_mode->eo_check, EINA_FALSE);
70 load_usb_connection_popup(ad);
72 ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 0);
74 SETTING_TRACE("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
83 static void setting_connectivity_main_chk_usb_debug_cb(void *data,
84 Evas_Object * obj, void *event_info)
87 retm_if(data == NULL, "Data parameter is NULL");
88 Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) data;
89 SettingConnectivityUG *ad = list_item->userdata;
91 if (0 > setting_connectivity_change_debug_mode_toggle(ad)) {
92 SETTING_TRACE("FAIL: setting_connectivity_change_debug_mode_toggle()");
98 static void setting_connectivity_usb_mouse_up_Gendial_list_cb(void *data,
99 Evas_Object *obj, void *event_info)
102 retm_if(data == NULL, "Invalid argument: data is NULL");
103 retm_if(event_info == NULL, "Invalid argument: event_info is NULL");
104 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
105 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
107 elm_genlist_item_selected_set(item, 0);
109 if (0 > setting_connectivity_change_debug_mode_toggle(ad)) {
110 SETTING_TRACE("FAIL: setting_connectivity_change_debug_mode_toggle()");
117 * To create the usb main view
123 static int setting_connectivity_usb_create(void *cb)
126 SETTING_TRACE("Start USB utilities\n");
128 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
130 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
131 Evas_Object *scroller;
136 /* win_main of the popup */
137 win_main = ad->win_get;
140 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
142 _(KeyStr_DeveloperOption),
143 dgettext("sys_string", "IDS_COM_BODY_BACK"),
144 _("IDS_COM_BODY_HELP"),
145 setting_connectivity_usb_click_softkey_cancel_cb,
146 setting_connectivity_usb_click_softkey_set_cb,
151 setting_create_layout_navi_bar_genlist(ad->win_main_layout,
153 _(KeyStr_DeveloperOption),
154 dgettext("sys_string", "IDS_COM_BODY_BACK"),
156 setting_connectivity_usb_click_softkey_cancel_cb,
162 SETTING_TRACE("before init\n");
164 button[SETTING_USB_DEBUG_MODE].item = NULL;
165 button[SETTING_USB_DEBUG_MODE].pstate = STATE_NONE;
167 Elm_Object_Item *item = NULL;;
170 item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL,
171 ELM_GENLIST_ITEM_NONE, NULL, NULL);
172 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
174 // [UI] USB debugging
178 err = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &toggle_dbg);
180 SETTING_TRACE_ERROR("FAIL: vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
181 /* set debug mode to true to find the problem*/
184 SETTING_TRACE("toggle_dbg: %d", toggle_dbg);
187 setting_create_Gendial_field_def(scroller, &(ad->itc_1text_1icon_gen),
188 setting_connectivity_usb_mouse_up_Gendial_list_cb,
189 ad, SWALLOW_Type_1TOGGLE, NULL,
190 NULL, toggle_dbg, "IDS_ST_BODY_USB_DEBUGGING",
191 NULL, setting_connectivity_main_chk_usb_debug_cb);
193 if (ad->debug_mode) {
194 ad->debug_mode->userdata = ad;
195 button[SETTING_USB_DEBUG_MODE].item = ad->debug_mode->item;
197 SETTING_TRACE_ERROR("ad->debug_mode is NULL");
198 return SETTING_RETURN_FAIL;
201 setting_create_Gendial_field_def(scroller, &(ad->itc_help_style), NULL,
202 ad, SWALLOW_Type_LAYOUT_SPECIALIZTION_X,
203 NULL, NULL, 0, SETTING_USB_DEBUGGING_DESC, NULL,
205 elm_genlist_item_select_mode_set(elm_genlist_item_append(scroller, &(itc_seperator), NULL, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL),
206 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
210 SETTING_TRACE("Second item of Second group is set\n");
212 //----------------------------------------------------------------------------------------------
213 /* Registering callback function for VCONFKEY_SETAPPL_USB_MODE_INT */
214 vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
215 debug_mode_change_vconf_cb, ad);
218 SETTING_TRACE("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
219 return SETTING_RETURN_FAIL;
222 /* Registering callback function for VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE */
223 vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE,
224 in_mode_change_vconf_cb, ad);
227 SETTING_TRACE("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)\n");
228 return SETTING_RETURN_FAIL;
232 vconf_ret = vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, &val);
233 if (vconf_ret == 0 && val == IN_MODE_CHANGE)
235 SETTING_TRACE("ad->blockUI: EINA_TRUE\n");
236 ad->blockUI = EINA_TRUE;
238 else /* val == CHANGE_COMPLETE */
240 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
241 ad->blockUI = EINA_FALSE;
244 setting_view_connectivity_usb.is_create = 1;
245 setting_view_update(&setting_view_connectivity_usb, ad);
248 return SETTING_RETURN_SUCCESS;
252 * This callback function is called when USB-setting changes VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE
256 static void in_mode_change_vconf_cb(keynode_t *key, void *data)
259 setting_retm_if(NULL == data, "ERROR:The parameter(data) is NULL\n");
260 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
261 SETTING_TRACE("ad->blockUI: %d\n", ad->blockUI);
266 ret = vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, &in_mode_change);
267 setting_retm_if (ret != 0, "vconf_get_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE\n");
269 if (CHANGE_COMPLETE == in_mode_change) {
270 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
271 ad->blockUI = EINA_FALSE;
272 } else if (IN_MODE_CHANGE == in_mode_change) {
273 SETTING_TRACE("ad->blockUI: EINA_TRUE\n");
274 ad->blockUI = EINA_TRUE;
276 SETTING_TRACE("Getting in_mode_change failed\n");
283 * When VCONFKEY_SETAPPL_USB_MODE_INT is changed, all buttons are enabled
288 static void debug_mode_change_vconf_cb(keynode_t *key, void *data)
291 setting_retm_if (NULL == data, "ERROR:The parameter(data) is NULL\n");
292 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
297 ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
298 setting_retm_if (ret != 0, "ERROR: vconf_get_int(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
299 SETTING_TRACE("debugMode: %d", debugMode);
301 if (debugMode == 1) {
302 elm_check_state_set(ad->debug_mode->eo_check, EINA_TRUE);
303 } else if (debugMode == 0) {
304 elm_check_state_set(ad->debug_mode->eo_check, EINA_FALSE);
306 SETTING_TRACE("ERROR: debugMode value is improper");
309 /* Unblock setting UI */
310 SETTING_TRACE("ad->blockUI: EINA_FALSE\n");
311 ad->blockUI = EINA_FALSE;
317 * To destory the view of usb
323 static int setting_connectivity_usb_destroy(void *cb)
327 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
329 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
333 /* Removing the popup if the popup is loaded */
337 /* Closing vconf trace */
338 vconf_ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL,
339 debug_mode_change_vconf_cb);
342 SETTING_TRACE("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
346 vconf_ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, in_mode_change_vconf_cb);
349 SETTING_TRACE("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)\n");
353 if (ad->ly_usb != NULL) {
354 evas_object_del(ad->ly_usb);
355 setting_view_connectivity_usb.is_create = 0;
361 SETTING_TRACE("ERROR: the number of errors to destroy is %d\n", num_err);
362 return SETTING_RETURN_FAIL;
366 return SETTING_RETURN_SUCCESS;
372 * To update the view of usb
378 static int setting_connectivity_usb_update(void *cb)
382 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
383 SettingConnectivityUG *ad = (SettingConnectivityUG *) cb;
385 if (ad->ly_usb != NULL) {
386 evas_object_show(ad->ly_usb);
389 return SETTING_RETURN_SUCCESS;
393 * To cleanup the view of usb
399 static int setting_connectivity_usb_cleanup(void *cb)
403 return SETTING_RETURN_SUCCESS;
407 * Do process when clicking '<-' button
414 setting_connectivity_usb_click_softkey_cancel_cb(void *data, Evas_Object *obj,
419 setting_retm_if(data == NULL, "Data parameter is NULL");
421 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
423 /* Not to block back(->) button */
424 /* Send destroy request */
425 ug_destroy_me(ad->ug);
431 * Do process when clicking 'Help' button
439 setting_connectivity_usb_click_softkey_set_cb(void *data, Evas_Object *obj,
444 setting_retm_if(data == NULL, "Data parameter is NULL");
446 SettingConnectivityUG *ad = (SettingConnectivityUG *) data;
448 /* Send destroy request */
449 setting_view_change(&setting_view_connectivity_usb,
450 &setting_view_connectivity_usb_help, ad);
457 * Here is for loading popup
463 static void unload_popup(void* data)
466 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
471 evas_object_del(ad->pop);
474 SETTING_TRACE("ad->pop == NULL\n");
477 if (popup_eo != NULL)
479 SETTING_TRACE("evas_object_del(popup_eo)\n");
480 evas_object_del(popup_eo);
485 SETTING_TRACE("popup_eo == NULL\n");
492 * Callback function to respond pushing cancel button of the usb connection popup
494 static void debug_mode_resp_cb(void *data, Evas_Object *obj, void *event_info)
498 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
500 int resp_type = btn_type(obj);
501 if (resp_type == POPUP_RESPONSE_OK) {
502 ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1);
504 SETTING_TRACE("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
514 * When a button on USB utilities is pushed,
515 * this function makes a popup if USB cable is not connected
517 void load_usb_connection_popup(void* data)
521 SettingConnectivityUG *ad = (SettingConnectivityUG *)data;
524 popup_msg = _(DEBUG_MODE_POPUP_TEXT);
525 popup_title = _("Allow USB debugging?");
527 ad->pop = setting_create_popup_with_btn(ad, win_main,//ad->win_get,
533 _("IDS_COM_SK_CANCEL"));
534 if (!(ad->pop)) SETTING_TRACE("FAIL: setting_create_popup_with_btn()");