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")))
24 //#include <setting-cfg.h>
26 #include "mobile_hotspot.h"
27 #include "mh_view_main.h"
28 #include "mh_func_onoff.h"
29 #include "mh_common_utility.h"
31 #include "mh_string.h"
32 #include "mh_view_wifi_setup.h"
34 //UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname);
36 static Evas_Object *create_content(mh_appdata_t *ad)
38 __MOBILE_AP_FUNC_ENTER__;
40 ad->naviframe = _create_naviframe(ad->layout);
41 _main_draw_contents(ad);
43 __MOBILE_AP_FUNC_EXIT__;
48 static void __set_callbacks(tethering_h handle, void *user_data)
54 ret = tethering_set_enabled_cb(handle, TETHERING_TYPE_ALL,
55 _enabled_cb, user_data);
56 if (ret != TETHERING_ERROR_NONE)
57 ERR("tethering_set_enabled_cb [0x%X]\n", ret);
59 ret = tethering_wifi_set_passphrase_changed_cb(handle,
60 _passphrase_changed_cb, user_data);
61 if (ret != TETHERING_ERROR_NONE)
62 ERR("tethering_wifi_set_passphrase_changed_cb [0x%X]\n", ret);
64 ret = tethering_wifi_set_ssid_visibility_changed_cb(handle,
65 _visibility_changed_cb, user_data);
66 if (ret != TETHERING_ERROR_NONE)
67 ERR("tethering_wifi_set_ssid_visibility_changed_cb [0x%X]\n", ret);
69 ret = tethering_wifi_set_security_type_changed_cb(handle,
70 _security_type_changed_cb, user_data);
71 if (ret != TETHERING_ERROR_NONE)
72 ERR("tethering_wifi_set_security_type_changed_cb [0x%X]\n", ret);
74 ret = tethering_set_disabled_cb(handle, TETHERING_TYPE_ALL,
75 _disabled_cb, user_data);
76 if (ret != TETHERING_ERROR_NONE)
77 ERR("tethering_set_disabled_cb [0x%X]\n", ret);
79 ret = tethering_set_connection_state_changed_cb(handle,
81 _connection_changed_cb, user_data);
82 if (ret != TETHERING_ERROR_NONE)
83 ERR("tethering_set_connection_state_changed_cb [0x%X]\n", ret);
85 ret = wifi_set_device_state_changed_cb(_wifi_state_changed_cb, user_data);
86 if (ret != WIFI_ERROR_NONE)
87 ERR("wifi_set_device_state_changed_cb [0x%X]\n", ret);
88 vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
89 _device_name_changed_cb, user_data);
91 vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
92 _handle_network_cellular_state_changed_cb, user_data);
94 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
95 _handle_usb_status_change, (void *)user_data);
97 vconf_notify_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
98 _handle_mobileap_syspopup_popup_response, (void *)user_data);
103 static void __unset_callbacks(tethering_h handle)
109 ret = wifi_unset_device_state_changed_cb();
110 if (ret != WIFI_ERROR_NONE)
111 ERR("wifi_unset_device_state_changed_cb [0x%X]\n", ret);
113 ret = tethering_unset_connection_state_changed_cb(handle,
115 if (ret != TETHERING_ERROR_NONE)
116 ERR("tethering_unset_connection_state_changed_cb[0x%X]\n", ret);
118 ret = tethering_unset_disabled_cb(handle, TETHERING_TYPE_ALL);
119 if (ret != TETHERING_ERROR_NONE)
120 ERR("tethering_unset_disabled_cb [0x%X]\n", ret);
122 ret = tethering_wifi_unset_security_type_changed_cb(handle);
123 if (ret != TETHERING_ERROR_NONE)
124 ERR("tethering_wifi_unset_security_type_changed_cb [0x%X]\n", ret);
126 ret = tethering_wifi_unset_ssid_visibility_changed_cb(handle);
127 if (ret != TETHERING_ERROR_NONE)
128 ERR("tethering_wifi_unset_ssid_visibility_changed_cb [0x%X]\n", ret);
130 ret = tethering_wifi_unset_passphrase_changed_cb(handle);
131 if (ret != TETHERING_ERROR_NONE)
132 ERR("tethering_wifi_unset_passphrase_changed_cb [0x%X]\n", ret);
134 ret = tethering_unset_enabled_cb(handle, TETHERING_TYPE_ALL);
135 if (ret != TETHERING_ERROR_NONE)
136 ERR("tethering_unset_enabled [0x%X]\n", ret);
138 vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
139 _device_name_changed_cb);
141 vconf_ignore_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE,
142 _handle_network_cellular_state_changed_cb);
144 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, _handle_usb_status_change);
146 vconf_ignore_key_changed(VCONF_KEY_MOBILEAP_SYSPOPUP_RESPONSE,
147 _handle_mobileap_syspopup_popup_response);
152 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
153 app_control_h app_control, void *priv)
158 ERR("The param is NULL\n");
162 if (mode != UG_MODE_FULLVIEW) {
163 ERR("Only Fullview is supported\n");
168 Evas_Object *content;
173 bindtextdomain(MH_TEXT_DOMAIN, MH_LOCALEDIR);
174 dgettext(PACKAGE, LOCALEDIR);
176 ad = (mh_appdata_t *)malloc(sizeof(mh_appdata_t));
178 ERR("Error!!! failed to allocate memory()\n");
181 memset(ad, 0x0, sizeof(mh_appdata_t));
183 ugd = (mh_ugdata_t *)priv;
188 _send_signal_qp(QP_SIGNAL_PROGRESS_RESET);
192 ret = tethering_create(&ad->handle);
193 if (ret != TETHERING_ERROR_NONE) {
194 ERR("tethering_create is failed : %d\n", ret);
200 ad->win = ug_get_parent_layout(ug);
202 ERR("ad->win is NULL\n");
209 if (elm_win_wm_rotation_supported_get(ad->win)) {
210 int rots[4] = {0, 90, 180, 270};
211 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
214 layout = _create_win_layout(ad);
215 if (layout == NULL) {
216 ERR("_create_win_layout is failed\n");
222 content = create_content(ad);
223 if (content == NULL) {
224 ERR("create_content is failed\n");
230 elm_object_part_content_set(layout, "elm.swallow.content", content);
231 evas_object_show(layout);
232 ret = connection_create(&ad->conn_handle);
233 if (ret != CONNECTION_ERROR_NONE) {
234 ERR("connection_create() is failed : %d\n", ret);
237 ret = wifi_initialize();
238 if (ret != WIFI_ERROR_NONE) {
239 ERR("wifi_initialize() is failed : %d\n", ret);
242 __set_callbacks(ad->handle, (void *)ad);
248 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
252 char * viewtype = NULL;
254 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
255 mh_appdata_t *ad = ugd->ad;
257 ad->is_foreground = true;
259 if (_get_list_clients_count(ad) > 0) {
260 #ifdef TETHERING_DATA_USAGE_SUPPORT
261 _start_update_data_packet_usage(ad);
263 if (ad->connected_device.navi_it) {
264 _start_update_device_conn_time(ad);
268 app_control_get_extra_data(app_control, "viewtype", &viewtype);
270 if (viewtype != NULL) {
271 if(strcmp(viewtype, "wifisettings") == 0)
272 mh_draw_wifi_setup_view(ad);
280 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
284 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
285 mh_appdata_t *ad = ugd->ad;
287 #ifdef TETHERING_DATA_USAGE_SUPPORT
288 _stop_update_data_packet_usage(ad);
290 _stop_update_device_conn_time(ad);
291 ad->is_foreground = false;
296 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
300 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
301 mh_appdata_t *ad = ugd->ad;
302 Elm_Object_Item *item = ad->main.device_item;
305 ad->is_foreground = true;
307 if (item && elm_genlist_item_expanded_get(item)) {
308 for (l = ad->client_list; l != NULL; l = g_slist_next(l) ) {
309 item = elm_genlist_item_next_get(item);
310 elm_genlist_item_fields_update(item, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
314 if (_get_list_clients_count(ad) > 0) {
315 #ifdef TETHERING_DATA_USAGE_SUPPORT
316 _start_update_data_packet_usage(ad);
318 if (ad->connected_device.navi_it) {
319 _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");
354 ret = wifi_deinitialize();
355 if (ret != WIFI_ERROR_NONE) {
356 ERR("wifi_deinitialize() is failed : %d\n", ret);
359 ret = connection_destroy(ad->conn_handle);
360 if (ret != CONNECTION_ERROR_NONE) {
361 ERR("connection_destroy() is failed : %d\n", ret);
364 ret = tethering_destroy(ad->handle);
365 if (ret != TETHERING_ERROR_NONE) {
366 ERR("tethering_destroy() is failed : %d\n", ret);
369 if (ad->layout == NULL) {
370 ERR("ad->layout is NULL\n");
377 evas_object_del(ad->popup);
381 if(ad->ps_recheck_timer_id > 0) {
382 g_source_remove(ad->ps_recheck_timer_id);
383 ad->ps_recheck_timer_id = 0;
386 evas_object_del(ad->bg);
389 evas_object_del(ad->layout);
392 _main_free_genlist_itc(ad);
394 ecore_imf_shutdown();
403 static void on_message(ui_gadget_h ug, app_control_h msg,
404 app_control_h app_control, void *priv)
408 static void on_event(ui_gadget_h ug, enum ug_event event,
409 app_control_h app_control, void *priv)
411 __MOBILE_AP_FUNC_ENTER__;
414 ERR("The param is NULL\n");
419 case UG_EVENT_LOW_MEMORY:
421 case UG_EVENT_LOW_BATTERY:
423 case UG_EVENT_LANG_CHANGE:
425 case UG_EVENT_ROTATE_PORTRAIT:
426 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
427 DBG("UG_EVENT_ROTATE_PORTRAIT[_UPSIDEDOWN]\n");
428 #if 0 /* device rename not supported */
429 _rotate_adjust_rename_popup();
432 case UG_EVENT_ROTATE_LANDSCAPE:
433 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
434 DBG("UG_EVENT_ROTATE_LANDSCAPE[_UPSIDEDOWN]\n");
435 #if 0 /* device rename not supported */
436 _rotate_adjust_rename_popup();
443 __MOBILE_AP_FUNC_EXIT__;
446 static void on_key_event(ui_gadget_h ug, enum ug_key_event event,
447 app_control_h app_control, void *priv)
449 __MOBILE_AP_FUNC_ENTER__;
451 if (priv == NULL || ug == NULL) {
452 ERR("The param is NULL\n");
456 mh_ugdata_t *ugd = (mh_ugdata_t *)priv;
457 mh_appdata_t *ad = ugd->ad;
465 case UG_KEY_EVENT_END:
466 DBG("UG_KEY_EVENT_END is received : %p\n", ad->popup);
467 if (NULL == ad->popup)
477 __MOBILE_AP_FUNC_EXIT__;
480 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
485 ERR("The param is NULL\n");
490 ugd = calloc(1, sizeof(mh_ugdata_t));
492 ERR("Quit : calloc failed(ugd)\n");
496 ops->create = on_create;
497 ops->start = on_start;
498 ops->pause = on_pause;
499 ops->resume = on_resume;
500 ops->destroy = on_destroy;
501 ops->message = on_message;
502 ops->event = on_event;
503 ops->key_event = on_key_event;
505 ops->opt = UG_OPT_INDICATOR_ENABLE;
510 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
515 ERR("The param is NULL\n");
519 mh_ugdata_t *ugd = (mh_ugdata_t *)ops->priv;
525 static void __mh_reset_vconf(tethering_h handle)
529 ret = vconf_set_int(VCONF_MOBILE_AP_WIFI_POPUP_CHECKBOX_STATUS, 0);
531 ERR("vconf_set_int failed\n");
533 ret = vconf_set_int(VCONF_MOBILE_AP_BT_POPUP_CHECKBOX_STATUS, 0);
535 ERR("vconf_set_int failed\n");
537 ret = vconf_set_int(VCONF_MOBILE_AP_USB_POPUP_CHECKBOX_STATUS, 0);
539 ERR("vconf_set_int failed\n");
541 ret = vconf_set_int(VCONF_MOBILE_AP_PREV_WIFI_STATUS, 0);
543 ERR("vconf_set_int failed\n");
545 ret = vconf_set_int(VCONF_MOBILE_AP_CONNECT_USB_POPUP_STATUS, 0);
547 ERR("vconf_set_int is failed\n");
549 ret = tethering_wifi_set_ssid_visibility(handle, true);
550 if (ret != TETHERING_ERROR_NONE)
551 ERR("tethering_wifi_set_ssid_visibility failed\n");
553 ret = tethering_wifi_set_security_type(handle, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK);
554 if (ret != TETHERING_ERROR_NONE)
555 ERR("tethering_wifi_set_security_type failed\n");
560 UG_MODULE_API int setting_plugin_reset(app_control_h app_control, void *priv)
565 tethering_h handle = NULL;
567 if (tethering_create(&handle) != TETHERING_ERROR_NONE) {
568 ERR("tethering_create failed\n");
572 if (tethering_is_enabled(handle, TETHERING_TYPE_USB) ||
573 tethering_is_enabled(handle, TETHERING_TYPE_WIFI) ||
574 tethering_is_enabled(handle, TETHERING_TYPE_BT)) {
575 ret = tethering_disable(handle, TETHERING_TYPE_ALL);
576 if (ret != TETHERING_ERROR_NONE) {
577 ERR("tethering_disable failed : %d\n", ret);
578 tethering_destroy(handle);
584 __mh_reset_vconf(handle);
586 tethering_destroy(handle);
591 /* Below code is commented as search in setting is no more supported in kiran */
594 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void * priv, char ** domainname)
596 *domainname = strdup(PACKAGE":/usr/apps/ug-setting-mobileap-efl/res/locale");
598 Eina_List ** pplist = (Eina_List**)priv;
601 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_USB_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
602 *pplist = eina_list_append(*pplist, node);
604 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
605 *pplist = eina_list_append(*pplist, node);
607 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_BLUETOOTH_TETHERING", "viewtype:frontpage", NULL, 5, NULL);
608 *pplist = eina_list_append(*pplist, node);
610 node = setting_plugin_search_item_add("IDS_MOBILEAP_MBODY_WI_FI_TETHERING_SETTINGS", "viewtype:wifisettings", NULL, 5, NULL);
611 *pplist = eina_list_append(*pplist, node);
613 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_HIDE_MY_DEVICE", "viewtype:wifisettings", NULL, 5, NULL);
614 *pplist = eina_list_append(*pplist, node);
616 node = setting_plugin_search_item_add("IDS_MOBILEAP_BODY_SECURITY", "viewtype:wifisettings", NULL, 5, NULL);
617 *pplist = eina_list_append(*pplist, node);