4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #define UG_MODULE_API __attribute__ ((visibility("default")))
25 #include <setting-cfg.h>
28 #include "mobile_hotspot.h"
29 #include "mh_view_main.h"
30 #include "mh_func_onoff.h"
31 #include "mh_common_utility.h"
33 #include "mh_string.h"
34 #include "mh_view_wifi_setup.h"
36 #if 0 /* Not support */
37 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname);
40 static Evas_Object *create_content(mh_appdata_t *ad)
42 __MOBILE_AP_FUNC_ENTER__;
44 ad->naviframe = _create_naviframe(ad->layout);
45 _main_draw_contents(ad);
47 __MOBILE_AP_FUNC_EXIT__;
52 static void __set_callbacks(tethering_h handle, void *user_data)
58 ret = tethering_set_enabled_cb(handle, TETHERING_TYPE_ALL,
59 _enabled_cb, user_data);
60 if (ret != TETHERING_ERROR_NONE)
61 ERR("tethering_set_enabled_cb [0x%X]\n", ret);
63 ret = tethering_wifi_set_passphrase_changed_cb(handle,
64 _passphrase_changed_cb, user_data);
65 if (ret != TETHERING_ERROR_NONE)
66 ERR("tethering_wifi_set_passphrase_changed_cb [0x%X]\n", ret);
68 ret = tethering_wifi_set_ssid_visibility_changed_cb(handle,
69 _visibility_changed_cb, user_data);
70 if (ret != TETHERING_ERROR_NONE)
71 ERR("tethering_wifi_set_ssid_visibility_changed_cb [0x%X]\n", ret);
73 ret = tethering_wifi_set_security_type_changed_cb(handle,
74 _security_type_changed_cb, user_data);
75 if (ret != TETHERING_ERROR_NONE)
76 ERR("tethering_wifi_set_security_type_changed_cb [0x%X]\n", ret);
78 ret = tethering_set_disabled_cb(handle, TETHERING_TYPE_ALL,
79 _disabled_cb, user_data);
80 if (ret != TETHERING_ERROR_NONE)
81 ERR("tethering_set_disabled_cb [0x%X]\n", ret);
83 ret = tethering_set_connection_state_changed_cb(handle,
85 _connection_changed_cb, user_data);
86 if (ret != TETHERING_ERROR_NONE)
87 ERR("tethering_set_connection_state_changed_cb [0x%X]\n", ret);
89 ret = wifi_set_device_state_changed_cb(_wifi_state_changed_cb, user_data);
90 if (ret != WIFI_ERROR_NONE)
91 ERR("wifi_set_device_state_changed_cb [0x%X]\n", ret);
92 vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
93 _device_name_changed_cb, user_data);
95 vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
96 _handle_network_cellular_state_changed_cb, user_data);
98 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
99 _handle_usb_status_change, (void *)user_data);
101 vconf_notify_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
102 _handle_mobileap_syspopup_popup_response, (void *)user_data);
107 static void __unset_callbacks(tethering_h handle)
113 ret = wifi_unset_device_state_changed_cb();
114 if (ret != WIFI_ERROR_NONE)
115 ERR("wifi_unset_device_state_changed_cb [0x%X]\n", ret);
117 ret = tethering_unset_connection_state_changed_cb(handle,
119 if (ret != TETHERING_ERROR_NONE)
120 ERR("tethering_unset_connection_state_changed_cb[0x%X]\n", ret);
122 ret = tethering_unset_disabled_cb(handle, TETHERING_TYPE_ALL);
123 if (ret != TETHERING_ERROR_NONE)
124 ERR("tethering_unset_disabled_cb [0x%X]\n", ret);
126 ret = tethering_wifi_unset_security_type_changed_cb(handle);
127 if (ret != TETHERING_ERROR_NONE)
128 ERR("tethering_wifi_unset_security_type_changed_cb [0x%X]\n", ret);
130 ret = tethering_wifi_unset_ssid_visibility_changed_cb(handle);
131 if (ret != TETHERING_ERROR_NONE)
132 ERR("tethering_wifi_unset_ssid_visibility_changed_cb [0x%X]\n", ret);
134 ret = tethering_wifi_unset_passphrase_changed_cb(handle);
135 if (ret != TETHERING_ERROR_NONE)
136 ERR("tethering_wifi_unset_passphrase_changed_cb [0x%X]\n", ret);
138 ret = tethering_unset_enabled_cb(handle, TETHERING_TYPE_ALL);
139 if (ret != TETHERING_ERROR_NONE)
140 ERR("tethering_unset_enabled [0x%X]\n", ret);
142 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
143 _device_name_changed_cb);
145 vconf_ignore_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
146 _handle_network_cellular_state_changed_cb);
148 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, _handle_usb_status_change);
150 vconf_ignore_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
151 _handle_mobileap_syspopup_popup_response);
156 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
157 app_control_h app_control, void *priv)
162 ERR("The param is NULL\n");
166 if (mode != UG_MODE_FULLVIEW) {
167 ERR("Only Fullview is supported\n");
172 Evas_Object *content;
177 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
178 dgettext(PACKAGE, LOCALEDIR);
180 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
182 ERR("Error!!! failed to allocate memory()\n");
185 memset(ad, 0x0, sizeof(mh_appdata_t));
187 ugd = (mh_ugdata_t *)priv;
192 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
196 ret = tethering_create(&ad->handle);
197 if (ret != TETHERING_ERROR_NONE) {
198 ERR("tethering_create is failed : %d\n", ret);
204 ad->win = ug_get_parent_layout(ug);
206 ERR("ad->win is NULL\n");
213 if (elm_win_wm_rotation_supported_get(ad->win)) {
214 int rots[4] = {0, 90, 180, 270};
215 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
218 layout = _create_win_layout(ad);
219 if (layout == NULL) {
220 ERR("_create_win_layout is failed\n");
226 content = create_content(ad);
227 if (content == NULL) {
228 ERR("create_content is failed\n");
234 elm_object_part_content_set(layout, "elm.swallow.content", content);
235 evas_object_show(layout);
236 ret = connection_create(&ad->conn_handle);
237 if (ret != CONNECTION_ERROR_NONE)
238 ERR("connection_create() is failed : %d\n", ret);
240 ret = wifi_initialize();
241 if (ret != WIFI_ERROR_NONE)
242 ERR("wifi_initialize() is failed : %d\n", ret);
244 __set_callbacks(ad->handle, (void *)ad);
250 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
254 char * viewtype = NULL;
256 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
257 mh_appdata_t *ad = ugd->ad;
259 ad->is_foreground = true;
261 if (_get_list_clients_count(ad) > 0) {
262 #ifdef TETHERING_DATA_USAGE_SUPPORT
263 _start_update_data_packet_usage(ad);
265 if (ad->connected_device.navi_it)
266 _start_update_device_conn_time(ad);
269 app_control_get_extra_data(app_control, "viewtype", &viewtype);
271 if (viewtype != NULL) {
272 if (strcmp(viewtype, "wifisettings") == 0)
273 mh_draw_wifi_setup_view(ad);
281 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
285 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
286 mh_appdata_t *ad = ugd->ad;
288 #ifdef TETHERING_DATA_USAGE_SUPPORT
289 _stop_update_data_packet_usage(ad);
291 _stop_update_device_conn_time(ad);
292 ad->is_foreground = false;
297 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
301 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
302 mh_appdata_t *ad = ugd->ad;
303 Elm_Object_Item *item = ad->main.device_item;
306 ad->is_foreground = true;
308 if (item && elm_genlist_item_expanded_get(item)) {
309 for (l = ad->client_list; l != NULL; l = g_slist_next(l)) {
310 item = elm_genlist_item_next_get(item);
311 elm_genlist_item_fields_update(item, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
315 if (_get_list_clients_count(ad) > 0) {
316 #ifdef TETHERING_DATA_USAGE_SUPPORT
317 _start_update_data_packet_usage(ad);
319 if (ad->connected_device.navi_it)
320 _start_update_device_conn_time(ad);
325 static void on_destroy(ui_gadget_h ug, app_control_h app_control, void *priv)
330 ERR("The param is NULL\n");
334 mh_ugdata_t *ugd = priv;
335 mh_appdata_t *ad = ugd->ad;
339 ERR("The param is NULL\n");
343 __unset_callbacks(ad->handle);
345 #ifdef TETHERING_DATA_USAGE_SUPPORT
346 _stop_update_data_packet_usage(ad);
348 _stop_update_device_conn_time(ad);
350 if (vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0) < 0)
351 ERR("vconf_set_int is failed\n");
353 ret = wifi_deinitialize();
354 if (ret != WIFI_ERROR_NONE)
355 ERR("wifi_deinitialize() is failed : %d\n", ret);
357 ret = connection_destroy(ad->conn_handle);
358 if (ret != CONNECTION_ERROR_NONE)
359 ERR("connection_destroy() is failed : %d\n", ret);
361 ret = tethering_destroy(ad->handle);
362 if (ret != TETHERING_ERROR_NONE)
363 ERR("tethering_destroy() is failed : %d\n", ret);
365 if (ad->layout == NULL) {
366 ERR("ad->layout is NULL\n");
373 evas_object_del(ad->popup);
377 if (ad->ps_recheck_timer_id > 0) {
378 g_source_remove(ad->ps_recheck_timer_id);
379 ad->ps_recheck_timer_id = 0;
382 evas_object_del(ad->bg);
385 evas_object_del(ad->layout);
388 _main_free_genlist_itc(ad);
390 ecore_imf_shutdown();
399 static void on_message(ui_gadget_h ug, app_control_h msg,
400 app_control_h app_control, void *priv)
404 static void on_event(ui_gadget_h ug, enum ug_event event,
405 app_control_h app_control, void *priv)
407 __MOBILE_AP_FUNC_ENTER__;
410 ERR("The param is NULL\n");
415 case UG_EVENT_LOW_MEMORY:
417 case UG_EVENT_LOW_BATTERY:
419 case UG_EVENT_LANG_CHANGE:
421 case UG_EVENT_ROTATE_PORTRAIT:
422 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
423 DBG("UG_EVENT_ROTATE_PORTRAIT[_UPSIDEDOWN]\n");
424 #if 0 /* device rename not supported */
425 _rotate_adjust_rename_popup();
428 case UG_EVENT_ROTATE_LANDSCAPE:
429 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
430 DBG("UG_EVENT_ROTATE_LANDSCAPE[_UPSIDEDOWN]\n");
431 #if 0 /* device rename not supported */
432 _rotate_adjust_rename_popup();
439 __MOBILE_AP_FUNC_EXIT__;
442 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
443 app_control_h app_control, void *priv)
445 __MOBILE_AP_FUNC_ENTER__;
447 if (priv == NULL || ug == NULL) {
448 ERR("The param is NULL\n");
452 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
453 mh_appdata_t *ad = ugd->ad;
461 case UG_KEY_EVENT_END:
462 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
463 if (NULL == ad->popup)
473 __MOBILE_AP_FUNC_EXIT__;
476 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
481 ERR("The param is NULL\n");
486 ugd = calloc(1, sizeof(mh_ugdata_t));
488 ERR("Quit : calloc failed(ugd)\n");
492 ops->create = on_create;
493 ops->start = on_start;
494 ops->pause = on_pause;
495 ops->resume = on_resume;
496 ops->destroy = on_destroy;
497 ops->message = on_message;
498 ops->event = on_event;
499 ops->key_event = on_key_event;
501 ops->opt = UG_OPT_INDICATOR_ENABLE;
506 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
511 ERR("The param is NULL\n");
515 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
521 static void __mh_reset_vconf(tethering_h handle)
525 ret = vconf_set_int(VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS, 0);
527 ERR("vconf_set_int failed\n");
529 ret = vconf_set_int(VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS, 0);
531 ERR("vconf_set_int failed\n");
533 ret = vconf_set_int(VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, 0);
535 ERR("vconf_set_int failed\n");
537 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
539 ERR("vconf_set_int failed\n");
541 ret = vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0);
543 ERR("vconf_set_int is failed\n");
545 ret = tethering_wifi_set_ssid_visibility(handle, true);
546 if (ret != TETHERING_ERROR_NONE)
547 ERR("tethering_wifi_set_ssid_visibility failed\n");
549 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
550 if (ret != TETHERING_ERROR_NONE)
551 ERR("tethering_wifi_set_security_type failed\n");
556 UG_MODULE_API int setting_plugin_reset(app_control_h app_control, void *priv)
561 tethering_h handle = NULL;
563 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
564 ERR("tethering_create failed\n");
568 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
569 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
570 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
571 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
572 if (ret != TETHERING_ERROR_NONE) {
573 ERR("tethering_disable failed : %d\n", ret);
574 tethering_destroy(handle);
580 __mh_reset_vconf(handle);
582 tethering_destroy(handle);
587 /* Below code is commented as search in setting is no more supported in kiran */
590 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname)
592 *domainname = strdup(PACKAGE":/usr/apps/ug-setting-mobileap-efl/res/locale");
594 Eina_List ** pplist = (Eina_List**)priv;
597 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_USB_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
598 *pplist = eina_list_append(*pplist, node);
600 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
601 *pplist = eina_list_append(*pplist, node);
603 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
604 *pplist = eina_list_append(*pplist, node);
606 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS", "viewtype:wifisettings", NULL, 5, NULL);
607 *pplist = eina_list_append(*pplist, node);
609 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_HIDE_MY_DEVICE", "viewtype:wifisettings", NULL, 5, NULL);
610 *pplist = eina_list_append(*pplist, node);
612 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_SECURITY", "viewtype:wifisettings", NULL, 5, NULL);
613 *pplist = eina_list_append(*pplist, node);