4 * Copyright 2012-2013 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
20 #include "mh_common_utility.h"
21 #include "mobile_hotspot.h"
23 static mh_popup_type_e popup_type = MH_POPUP_NONE;
24 static Evas_Object *popup_content = NULL;
25 static char *popup_string = NULL;
27 static void __one_btn_popup_resp(void *data, Evas_Object *obj, void *event_info)
29 __MOBILE_AP_FUNC_ENTER__;
31 if (data == NULL || obj == NULL) {
32 ERR("The param is NULL\n");
36 mh_appdata_t *ad = (mh_appdata_t *)data;
38 evas_object_del(ad->popup);
41 DBG("popup_type : %d\n", popup_type);
43 case MH_POP_USB_CONNECT:
44 _update_usb_item(ad, MH_STATE_NONE);
45 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
46 _handle_usb_mode_change);
49 case MH_POP_INFORMATION:
53 DBG("Unknown popup_type : %d\n", popup_type);
57 __MOBILE_AP_FUNC_EXIT__;
60 static void __alert_popup_resp(void *data, Evas_Object *obj, void *event_info)
62 __MOBILE_AP_FUNC_ENTER__;
64 if (data == NULL || obj == NULL) {
65 ERR("The param is NULL\n");
69 mh_appdata_t *ad = (mh_appdata_t *)data;
71 evas_object_del(ad->popup);
74 DBG("popup_type : %d\n", popup_type);
76 case MH_POP_INFORMATION_WO_BUTTON:
80 DBG("Unknown popup_type : %d\n", popup_type);
84 __MOBILE_AP_FUNC_EXIT__;
87 static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
89 __MOBILE_AP_FUNC_ENTER__;
91 if (data == NULL || obj == NULL) {
92 ERR("The param is NULL\n");
96 mh_appdata_t *ad = (mh_appdata_t *)data;
100 evas_object_del(ad->popup);
103 DBG("popup_type : %d\n", popup_type);
104 switch (popup_type) {
105 case MH_POP_WIFI_ON_CONF:
106 wifi_is_activated(&wifi_state);
107 DBG("wifi_state : %d\n", wifi_state);
108 if (wifi_state == false) {
109 ret = vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_WIFI_STATE,
110 VCONFKEY_MOBILE_HOTSPOT_WIFI_PENDING_ON);
112 ERR("vconf_set_int() is failed : %d\n", ret);
114 if (_turn_on_wifi(ad) != 0) {
115 ERR("_turn_on_wifi is failed\n");
116 _update_wifi_item(ad, MH_STATE_NONE);
118 } else if (_is_wifi_direct_on() == true) {
119 if (_turn_off_wifi_direct(ad) != 0) {
120 ERR("_turn_off_wifi_direct is failed\n");
121 _update_wifi_item(ad, MH_STATE_NONE);
124 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
125 if (ret != TETHERING_ERROR_NONE) {
126 ERR("wifi tethering on is failed : %d\n", ret);
127 _update_wifi_item(ad, MH_STATE_NONE);
132 case MH_POP_WIFI_OFF_CONF:
133 ret = vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_WIFI_STATE,
134 VCONFKEY_MOBILE_HOTSPOT_WIFI_PENDING_OFF);
136 ERR("vconf_set_int() is failed : %d\n", ret);
138 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
139 if (ret != TETHERING_ERROR_NONE) {
140 ERR("wifi tethering off is failed : %d\n", ret);
141 _update_wifi_item(ad, MH_STATE_NONE);
145 case MH_POP_BT_ON_CONF:
146 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
147 if (ret != TETHERING_ERROR_NONE) {
148 ERR("Error enable bt tethering : %d\n", ret);
149 _update_bt_item(ad, MH_STATE_NONE);
153 case MH_POP_USB_ON_CONF:
154 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
155 _prepare_popup(MH_POP_USB_CONNECT,
156 _("IDS_MOBILEAP_POP_CONNECT_USB_CABLE"));
158 vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
159 _handle_usb_mode_change, (void *)ad);
163 _prepare_popup(MH_POP_USB_ON_PREVCONN_CONF,
164 _("IDS_MOBILEAP_POP_ENABLING_USB_TETHERING_WILL_DISCONNECT_PREVIOUS_USB_CONNECTION"));
168 case MH_POP_USB_ON_PREVCONN_CONF:
169 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
170 if (ret != TETHERING_ERROR_NONE) {
171 ERR("Error enable usb tethering : %d\n", ret);
172 _update_usb_item(ad, MH_STATE_NONE);
176 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
177 _update_wifi_item(ad, MH_STATE_PROCESS);
178 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
179 if (ret != TETHERING_ERROR_NONE) {
180 ERR("Wi-Fi tethering off is failed : %d\n", ret);
181 _update_wifi_item(ad, MH_STATE_NONE);
183 ad->main.need_recover_wifi_tethering = true;
185 mh_draw_wifi_setup_view(ad);
189 DBG("Unknown popup_type : %d\n", popup_type);
193 __MOBILE_AP_FUNC_EXIT__;
196 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
198 __MOBILE_AP_FUNC_ENTER__;
200 if (data == NULL || obj == NULL) {
201 ERR("The param is NULL\n");
205 mh_appdata_t *ad = (mh_appdata_t *)data;
207 evas_object_del(ad->popup);
210 DBG("popup_type : %d\n", popup_type);
211 switch (popup_type) {
212 case MH_POP_WIFI_ON_CONF:
213 _update_wifi_item(ad, MH_STATE_NONE);
216 case MH_POP_WIFI_OFF_CONF:
217 _update_wifi_item(ad, MH_STATE_NONE);
220 case MH_POP_BT_ON_CONF:
221 _update_bt_item(ad, MH_STATE_NONE);
224 case MH_POP_USB_ON_CONF:
225 _update_usb_item(ad, MH_STATE_NONE);
228 case MH_POP_USB_ON_PREVCONN_CONF:
229 _update_usb_item(ad, MH_STATE_NONE);
232 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
236 DBG("Unknown popup_type : %d\n", popup_type);
240 __MOBILE_AP_FUNC_EXIT__;
243 static bool _count_connected_clients_cb(tethering_client_h client, void *user_data)
245 if (user_data == NULL) {
246 ERR("user_data is NULL\n");
250 int *count = (int *)user_data;
257 void _prepare_popup_with_content(int type, Evas_Object *obj)
259 __MOBILE_AP_FUNC_ENTER__;
262 ERR("param is NULL\n");
269 evas_object_del(popup_content);
277 __MOBILE_AP_FUNC_EXIT__;
280 void _prepare_popup(int type, const char *str)
282 __MOBILE_AP_FUNC_ENTER__;
285 ERR("param is NULL\n");
290 popup_content = NULL;
295 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
296 if (popup_string == NULL)
297 ERR("strndup is failed\n");
299 __MOBILE_AP_FUNC_EXIT__;
302 Eina_Bool _create_popup(mh_appdata_t *ad)
304 __MOBILE_AP_FUNC_ENTER__;
306 Evas_Object *btn = NULL;
309 ERR("The param is NULL\n");
314 popup_content = NULL;
319 if (ad->popup != NULL) {
320 DBG("Pop-up already exists. Delete it.\n");
321 evas_object_del(ad->popup);
325 DBG("Create_popup %d\n", popup_type);
326 switch (popup_type) {
327 case MH_POP_WIFI_ON_CONF:
328 ad->popup = elm_popup_add(ad->win);
329 evas_object_size_hint_weight_set(ad->popup,
330 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
332 if (popup_content == NULL)
333 elm_object_text_set(ad->popup, popup_string);
335 elm_object_content_set(ad->popup, popup_content);
337 btn = elm_button_add(ad->popup);
338 elm_object_style_set(btn, "popup_button/default");
339 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
340 elm_object_part_content_set(ad->popup, "button1", btn);
341 evas_object_smart_callback_add(btn, "clicked",
342 __popup_resp_yes, (void *)ad);
344 btn = elm_button_add(ad->popup);
345 elm_object_style_set(btn, "popup_button/default");
346 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
347 elm_object_part_content_set(ad->popup, "button2", btn);
348 evas_object_smart_callback_add(btn, "clicked",
349 __popup_resp_no, (void *)ad);
351 evas_object_show(ad->popup);
354 case MH_POP_WIFI_OFF_CONF:
355 ad->popup = elm_popup_add(ad->win);
356 evas_object_size_hint_weight_set(ad->popup,
357 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
359 if (popup_content == NULL)
360 elm_object_text_set(ad->popup, popup_string);
362 elm_object_content_set(ad->popup, popup_content);
364 btn = elm_button_add(ad->popup);
365 elm_object_style_set(btn, "popup_button/default");
366 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
367 elm_object_part_content_set(ad->popup, "button1", btn);
368 evas_object_smart_callback_add(btn, "clicked",
369 __popup_resp_yes, (void *)ad);
371 btn = elm_button_add(ad->popup);
372 elm_object_style_set(btn, "popup_button/default");
373 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
374 elm_object_part_content_set(ad->popup, "button2", btn);
375 evas_object_smart_callback_add(btn, "clicked",
376 __popup_resp_no, (void *)ad);
378 evas_object_show(ad->popup);
381 case MH_POP_USB_CONNECT:
382 ad->popup = elm_popup_add(ad->win);
383 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
386 if (popup_content == NULL)
387 elm_object_text_set(ad->popup, popup_string);
389 elm_object_content_set(ad->popup, popup_content);
391 btn = elm_button_add(ad->popup);
392 elm_object_style_set(btn, "popup_button/default");
393 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
394 elm_object_part_content_set(ad->popup, "button1", btn);
395 evas_object_smart_callback_add(btn, "clicked",
396 __one_btn_popup_resp, (void *)ad);
398 evas_object_show(ad->popup);
401 case MH_POP_BT_ON_CONF:
402 ad->popup = elm_popup_add(ad->win);
403 evas_object_size_hint_weight_set(ad->popup,
404 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
406 if (popup_content == NULL)
407 elm_object_text_set(ad->popup, popup_string);
409 elm_object_content_set(ad->popup, popup_content);
411 btn = elm_button_add(ad->popup);
412 elm_object_style_set(btn, "popup_button/default");
413 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
414 elm_object_part_content_set(ad->popup, "button1", btn);
415 evas_object_smart_callback_add(btn, "clicked",
416 __popup_resp_yes, (void *)ad);
418 btn = elm_button_add(ad->popup);
419 elm_object_style_set(btn, "popup_button/default");
420 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
421 elm_object_part_content_set(ad->popup, "button2", btn);
422 evas_object_smart_callback_add(btn, "clicked",
423 __popup_resp_no, (void *)ad);
425 evas_object_show(ad->popup);
428 case MH_POP_USB_ON_CONF:
429 case MH_POP_USB_ON_PREVCONN_CONF:
430 ad->popup = elm_popup_add(ad->win);
431 evas_object_size_hint_weight_set(ad->popup,
432 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
434 if (popup_content == NULL)
435 elm_object_text_set(ad->popup, popup_string);
437 elm_object_content_set(ad->popup, popup_content);
439 btn = elm_button_add(ad->popup);
440 elm_object_style_set(btn, "popup_button/default");
441 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
442 elm_object_part_content_set(ad->popup, "button1", btn);
443 evas_object_smart_callback_add(btn, "clicked",
444 __popup_resp_yes, (void *)ad);
446 btn = elm_button_add(ad->popup);
447 elm_object_style_set(btn, "popup_button/default");
448 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
449 elm_object_part_content_set(ad->popup, "button2", btn);
450 evas_object_smart_callback_add(btn, "clicked",
451 __popup_resp_no, (void *)ad);
453 evas_object_show(ad->popup);
456 case MH_POP_INFORMATION:
457 ad->popup = elm_popup_add(ad->win);
458 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
461 if (popup_content == NULL)
462 elm_object_text_set(ad->popup, popup_string);
464 elm_object_content_set(ad->popup, popup_content);
466 btn = elm_button_add(ad->popup);
467 elm_object_style_set(btn, "popup_button/default");
468 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
469 elm_object_part_content_set(ad->popup, "button1", btn);
470 evas_object_smart_callback_add(btn, "clicked",
471 __one_btn_popup_resp, (void *)ad);
473 evas_object_show(ad->popup);
476 case MH_POP_INFORMATION_WO_BUTTON:
477 ad->popup = elm_popup_add(ad->win);
478 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
481 if (popup_content == NULL)
482 elm_object_text_set(ad->popup, popup_string);
484 elm_object_content_set(ad->popup, popup_content);
486 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
487 evas_object_smart_callback_add(ad->popup, "timeout",
488 __alert_popup_resp, (void *)ad);
489 evas_object_smart_callback_add(ad->popup, "block,clicked",
490 __alert_popup_resp, (void *)ad);
492 evas_object_show(ad->popup);
495 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
496 ad->popup = elm_popup_add(ad->win);
497 evas_object_size_hint_weight_set(ad->popup,
498 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
500 if (popup_content == NULL)
501 elm_object_text_set(ad->popup, popup_string);
503 elm_object_content_set(ad->popup, popup_content);
505 btn = elm_button_add(ad->popup);
506 elm_object_style_set(btn, "popup_button/default");
507 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
508 elm_object_part_content_set(ad->popup, "button1", btn);
509 evas_object_smart_callback_add(btn, "clicked",
510 __popup_resp_yes, (void *)ad);
512 btn = elm_button_add(ad->popup);
513 elm_object_style_set(btn, "popup_button/default");
514 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
515 elm_object_part_content_set(ad->popup, "button2", btn);
516 evas_object_smart_callback_add(btn, "clicked",
517 __popup_resp_no, (void *)ad);
519 evas_object_show(ad->popup);
522 ERR("Unknown popup_type : %d\n", popup_type);
530 popup_content = NULL;
532 __MOBILE_AP_FUNC_EXIT__;
537 void _destroy_popup(mh_appdata_t *ad)
539 __MOBILE_AP_FUNC_ENTER__;
541 if (ad && ad->popup) {
542 evas_object_del(ad->popup);
550 popup_content = NULL;
551 popup_type = MH_POPUP_NONE;
553 __MOBILE_AP_FUNC_EXIT__;
558 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
560 __MOBILE_AP_FUNC_ENTER__;
562 if (parent == NULL || style == NULL) {
563 ERR("The param is NULL\n");
567 Evas_Object *bg = NULL;
569 bg = elm_bg_add(parent);
575 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
576 elm_object_style_set(bg, style);
577 evas_object_show(bg);
582 Evas_Object *_create_win_layout(mh_appdata_t *ad)
584 __MOBILE_AP_FUNC_ENTER__;
586 if (ad->win == NULL) {
587 ERR("There is no main window\n");
594 layout = elm_layout_add(ad->win);
595 if (layout == NULL) {
596 ERR("layout is NULL\n");
600 elm_layout_theme_set(layout, "layout", "application", "default");
601 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
604 bg = _create_bg(layout, "group_list");
607 evas_object_del(layout);
610 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
612 evas_object_show(layout);
617 __MOBILE_AP_FUNC_EXIT__;
622 Evas_Object *_create_naviframe(Evas_Object *parent)
624 __MOBILE_AP_FUNC_ENTER__;
626 if (parent == NULL) {
627 ERR("parent is NULL\n");
631 Evas_Object *naviframe;
633 naviframe = elm_naviframe_add(parent);
634 if (naviframe == NULL) {
635 ERR("naviframe is NULL\n");
638 evas_object_show(naviframe);
640 __MOBILE_AP_FUNC_EXIT__;
645 void _handle_usb_mode_change(keynode_t *key, void *data)
647 mh_appdata_t *ad = (mh_appdata_t *)data;
651 ERR("The param is NULL\n");
655 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
656 ERR("Invalid vconf key\n");
660 vconf_key = vconf_keynode_get_int(key);
661 DBG("vconf_key : %d\n", vconf_key);
662 if (vconf_key == SETTING_USB_NONE_MODE) {
663 DBG("usb-utilties is processing mode change\n");
667 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
668 _handle_usb_mode_change);
670 evas_object_del(ad->popup);
673 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
674 DBG("Error enable usb tethering\n");
675 _update_usb_item(ad, MH_STATE_NONE);
679 int _get_vconf_hotspot_mode(void)
681 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
683 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
684 ERR("vconf_get_int is failed\n");
688 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
693 Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_type_e type)
695 if (handle == NULL || no == NULL)
698 tethering_foreach_connected_clients(handle, type,
699 _count_connected_clients_cb, (void *)no);
704 Evas_Object *_create_label(Evas_Object *parent, const char *text)
708 label = elm_entry_add(parent);
710 ERR("elm_entry_add is failed\n");
714 elm_entry_editable_set(label, EINA_FALSE);
715 elm_entry_context_menu_disabled_set(label, EINA_TRUE);
716 elm_object_text_set(label, text);
718 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
719 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
720 evas_object_show(label);
725 Evas_Object *_create_slide_title(Evas_Object *parent, const char *text)
727 if (parent == NULL || text == NULL)
732 label = elm_label_add(parent);
733 elm_object_style_set(label, "naviframe_title");
734 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
735 elm_label_wrap_width_set(label, 1);
736 elm_label_ellipsis_set(label, EINA_TRUE);
737 elm_object_text_set(label, text);
738 evas_object_show(label);
740 elm_access_object_unregister(label);