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 = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
134 if (ret != TETHERING_ERROR_NONE) {
135 ERR("wifi tethering off is failed : %d\n", ret);
136 _update_wifi_item(ad, MH_STATE_NONE);
140 case MH_POP_BT_ON_CONF:
141 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
142 if (ret != TETHERING_ERROR_NONE) {
143 ERR("Error enable bt tethering : %d\n", ret);
144 _update_bt_item(ad, MH_STATE_NONE);
148 case MH_POP_USB_ON_CONF:
149 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
150 _prepare_popup(MH_POP_USB_CONNECT,
151 _("IDS_MOBILEAP_POP_CONNECT_USB_CABLE"));
153 vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
154 _handle_usb_mode_change, (void *)ad);
158 _prepare_popup(MH_POP_USB_ON_PREVCONN_CONF,
159 _("IDS_MOBILEAP_POP_ENABLING_USB_TETHERING_WILL_DISCONNECT_PREVIOUS_USB_CONNECTION"));
163 case MH_POP_USB_ON_PREVCONN_CONF:
164 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
165 if (ret != TETHERING_ERROR_NONE) {
166 ERR("Error enable usb tethering : %d\n", ret);
167 _update_usb_item(ad, MH_STATE_NONE);
171 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
172 _update_wifi_item(ad, MH_STATE_PROCESS);
173 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
174 if (ret != TETHERING_ERROR_NONE) {
175 ERR("Wi-Fi tethering off is failed : %d\n", ret);
176 _update_wifi_item(ad, MH_STATE_NONE);
178 ad->main.need_recover_wifi_tethering = true;
180 mh_draw_wifi_setup_view(ad);
184 DBG("Unknown popup_type : %d\n", popup_type);
188 __MOBILE_AP_FUNC_EXIT__;
191 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
193 __MOBILE_AP_FUNC_ENTER__;
195 if (data == NULL || obj == NULL) {
196 ERR("The param is NULL\n");
200 mh_appdata_t *ad = (mh_appdata_t *)data;
202 evas_object_del(ad->popup);
205 DBG("popup_type : %d\n", popup_type);
206 switch (popup_type) {
207 case MH_POP_WIFI_ON_CONF:
208 _update_wifi_item(ad, MH_STATE_NONE);
211 case MH_POP_WIFI_OFF_CONF:
212 _update_wifi_item(ad, MH_STATE_NONE);
215 case MH_POP_BT_ON_CONF:
216 _update_bt_item(ad, MH_STATE_NONE);
219 case MH_POP_USB_ON_CONF:
220 _update_usb_item(ad, MH_STATE_NONE);
223 case MH_POP_USB_ON_PREVCONN_CONF:
224 _update_usb_item(ad, MH_STATE_NONE);
227 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
231 DBG("Unknown popup_type : %d\n", popup_type);
235 __MOBILE_AP_FUNC_EXIT__;
238 static bool _count_connected_clients_cb(tethering_client_h client, void *user_data)
240 if (user_data == NULL) {
241 ERR("user_data is NULL\n");
245 int *count = (int *)user_data;
252 void _prepare_popup_with_content(int type, Evas_Object *obj)
254 __MOBILE_AP_FUNC_ENTER__;
257 ERR("param is NULL\n");
264 evas_object_del(popup_content);
272 __MOBILE_AP_FUNC_EXIT__;
275 void _prepare_popup(int type, const char *str)
277 __MOBILE_AP_FUNC_ENTER__;
280 ERR("param is NULL\n");
285 popup_content = NULL;
290 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
291 if (popup_string == NULL)
292 ERR("strndup is failed\n");
294 __MOBILE_AP_FUNC_EXIT__;
297 Eina_Bool _create_popup(mh_appdata_t *ad)
299 __MOBILE_AP_FUNC_ENTER__;
301 Evas_Object *btn = NULL;
304 ERR("The param is NULL\n");
309 popup_content = NULL;
314 if (ad->popup != NULL) {
315 DBG("Pop-up already exists. Delete it.\n");
316 evas_object_del(ad->popup);
320 DBG("Create_popup %d\n", popup_type);
321 switch (popup_type) {
322 case MH_POP_WIFI_ON_CONF:
323 ad->popup = elm_popup_add(ad->win);
324 evas_object_size_hint_weight_set(ad->popup,
325 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
327 if (popup_content == NULL)
328 elm_object_text_set(ad->popup, popup_string);
330 elm_object_content_set(ad->popup, popup_content);
332 btn = elm_button_add(ad->popup);
333 elm_object_style_set(btn, "popup_button/default");
334 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
335 elm_object_part_content_set(ad->popup, "button1", btn);
336 evas_object_smart_callback_add(btn, "clicked",
337 __popup_resp_yes, (void *)ad);
339 btn = elm_button_add(ad->popup);
340 elm_object_style_set(btn, "popup_button/default");
341 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
342 elm_object_part_content_set(ad->popup, "button2", btn);
343 evas_object_smart_callback_add(btn, "clicked",
344 __popup_resp_no, (void *)ad);
346 evas_object_show(ad->popup);
349 case MH_POP_WIFI_OFF_CONF:
350 ad->popup = elm_popup_add(ad->win);
351 evas_object_size_hint_weight_set(ad->popup,
352 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
354 if (popup_content == NULL)
355 elm_object_text_set(ad->popup, popup_string);
357 elm_object_content_set(ad->popup, popup_content);
359 btn = elm_button_add(ad->popup);
360 elm_object_style_set(btn, "popup_button/default");
361 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
362 elm_object_part_content_set(ad->popup, "button1", btn);
363 evas_object_smart_callback_add(btn, "clicked",
364 __popup_resp_yes, (void *)ad);
366 btn = elm_button_add(ad->popup);
367 elm_object_style_set(btn, "popup_button/default");
368 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
369 elm_object_part_content_set(ad->popup, "button2", btn);
370 evas_object_smart_callback_add(btn, "clicked",
371 __popup_resp_no, (void *)ad);
373 evas_object_show(ad->popup);
376 case MH_POP_USB_CONNECT:
377 ad->popup = elm_popup_add(ad->win);
378 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
381 if (popup_content == NULL)
382 elm_object_text_set(ad->popup, popup_string);
384 elm_object_content_set(ad->popup, popup_content);
386 btn = elm_button_add(ad->popup);
387 elm_object_style_set(btn, "popup_button/default");
388 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
389 elm_object_part_content_set(ad->popup, "button1", btn);
390 evas_object_smart_callback_add(btn, "clicked",
391 __one_btn_popup_resp, (void *)ad);
393 evas_object_show(ad->popup);
396 case MH_POP_BT_ON_CONF:
397 ad->popup = elm_popup_add(ad->win);
398 evas_object_size_hint_weight_set(ad->popup,
399 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
401 if (popup_content == NULL)
402 elm_object_text_set(ad->popup, popup_string);
404 elm_object_content_set(ad->popup, popup_content);
406 btn = elm_button_add(ad->popup);
407 elm_object_style_set(btn, "popup_button/default");
408 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
409 elm_object_part_content_set(ad->popup, "button1", btn);
410 evas_object_smart_callback_add(btn, "clicked",
411 __popup_resp_yes, (void *)ad);
413 btn = elm_button_add(ad->popup);
414 elm_object_style_set(btn, "popup_button/default");
415 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
416 elm_object_part_content_set(ad->popup, "button2", btn);
417 evas_object_smart_callback_add(btn, "clicked",
418 __popup_resp_no, (void *)ad);
420 evas_object_show(ad->popup);
423 case MH_POP_USB_ON_CONF:
424 case MH_POP_USB_ON_PREVCONN_CONF:
425 ad->popup = elm_popup_add(ad->win);
426 evas_object_size_hint_weight_set(ad->popup,
427 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
429 if (popup_content == NULL)
430 elm_object_text_set(ad->popup, popup_string);
432 elm_object_content_set(ad->popup, popup_content);
434 btn = elm_button_add(ad->popup);
435 elm_object_style_set(btn, "popup_button/default");
436 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
437 elm_object_part_content_set(ad->popup, "button1", btn);
438 evas_object_smart_callback_add(btn, "clicked",
439 __popup_resp_yes, (void *)ad);
441 btn = elm_button_add(ad->popup);
442 elm_object_style_set(btn, "popup_button/default");
443 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
444 elm_object_part_content_set(ad->popup, "button2", btn);
445 evas_object_smart_callback_add(btn, "clicked",
446 __popup_resp_no, (void *)ad);
448 evas_object_show(ad->popup);
451 case MH_POP_INFORMATION:
452 ad->popup = elm_popup_add(ad->win);
453 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
456 if (popup_content == NULL)
457 elm_object_text_set(ad->popup, popup_string);
459 elm_object_content_set(ad->popup, popup_content);
461 btn = elm_button_add(ad->popup);
462 elm_object_style_set(btn, "popup_button/default");
463 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
464 elm_object_part_content_set(ad->popup, "button1", btn);
465 evas_object_smart_callback_add(btn, "clicked",
466 __one_btn_popup_resp, (void *)ad);
468 evas_object_show(ad->popup);
471 case MH_POP_INFORMATION_WO_BUTTON:
472 ad->popup = elm_popup_add(ad->win);
473 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
476 if (popup_content == NULL)
477 elm_object_text_set(ad->popup, popup_string);
479 elm_object_content_set(ad->popup, popup_content);
481 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
482 evas_object_smart_callback_add(ad->popup, "timeout",
483 __alert_popup_resp, (void *)ad);
484 evas_object_smart_callback_add(ad->popup, "block,clicked",
485 __alert_popup_resp, (void *)ad);
487 evas_object_show(ad->popup);
490 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
491 ad->popup = elm_popup_add(ad->win);
492 evas_object_size_hint_weight_set(ad->popup,
493 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
495 if (popup_content == NULL)
496 elm_object_text_set(ad->popup, popup_string);
498 elm_object_content_set(ad->popup, popup_content);
500 btn = elm_button_add(ad->popup);
501 elm_object_style_set(btn, "popup_button/default");
502 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
503 elm_object_part_content_set(ad->popup, "button1", btn);
504 evas_object_smart_callback_add(btn, "clicked",
505 __popup_resp_yes, (void *)ad);
507 btn = elm_button_add(ad->popup);
508 elm_object_style_set(btn, "popup_button/default");
509 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
510 elm_object_part_content_set(ad->popup, "button2", btn);
511 evas_object_smart_callback_add(btn, "clicked",
512 __popup_resp_no, (void *)ad);
514 evas_object_show(ad->popup);
517 ERR("Unknown popup_type : %d\n", popup_type);
525 popup_content = NULL;
527 __MOBILE_AP_FUNC_EXIT__;
532 void _destroy_popup(mh_appdata_t *ad)
534 __MOBILE_AP_FUNC_ENTER__;
536 if (ad && ad->popup) {
537 evas_object_del(ad->popup);
545 popup_content = NULL;
546 popup_type = MH_POPUP_NONE;
548 __MOBILE_AP_FUNC_EXIT__;
553 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
555 __MOBILE_AP_FUNC_ENTER__;
557 if (parent == NULL || style == NULL) {
558 ERR("The param is NULL\n");
562 Evas_Object *bg = NULL;
564 bg = elm_bg_add(parent);
570 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
571 elm_object_style_set(bg, style);
572 evas_object_show(bg);
577 Evas_Object *_create_win_layout(mh_appdata_t *ad)
579 __MOBILE_AP_FUNC_ENTER__;
581 if (ad->win == NULL) {
582 ERR("There is no main window\n");
589 layout = elm_layout_add(ad->win);
590 if (layout == NULL) {
591 ERR("layout is NULL\n");
595 elm_layout_theme_set(layout, "layout", "application", "default");
596 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
599 bg = _create_bg(layout, "group_list");
602 evas_object_del(layout);
605 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
607 evas_object_show(layout);
612 __MOBILE_AP_FUNC_EXIT__;
617 Evas_Object *_create_naviframe(Evas_Object *parent)
619 __MOBILE_AP_FUNC_ENTER__;
621 if (parent == NULL) {
622 ERR("parent is NULL\n");
626 Evas_Object *naviframe;
628 naviframe = elm_naviframe_add(parent);
629 if (naviframe == NULL) {
630 ERR("naviframe is NULL\n");
633 evas_object_show(naviframe);
635 __MOBILE_AP_FUNC_EXIT__;
640 void _handle_usb_mode_change(keynode_t *key, void *data)
642 mh_appdata_t *ad = (mh_appdata_t *)data;
646 ERR("The param is NULL\n");
650 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
651 ERR("Invalid vconf key\n");
655 vconf_key = vconf_keynode_get_int(key);
656 DBG("vconf_key : %d\n", vconf_key);
657 if (vconf_key == SETTING_USB_NONE_MODE) {
658 DBG("usb-utilties is processing mode change\n");
662 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
663 _handle_usb_mode_change);
665 evas_object_del(ad->popup);
668 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
669 DBG("Error enable usb tethering\n");
670 _update_usb_item(ad, MH_STATE_NONE);
674 int _get_vconf_hotspot_mode(void)
676 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
678 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
679 ERR("vconf_get_int is failed\n");
683 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
688 Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_type_e type)
690 if (handle == NULL || no == NULL)
693 tethering_foreach_connected_clients(handle, type,
694 _count_connected_clients_cb, (void *)no);
699 Evas_Object *_create_label(Evas_Object *parent, const char *text)
703 label = elm_entry_add(parent);
705 ERR("elm_entry_add is failed\n");
709 elm_entry_editable_set(label, EINA_FALSE);
710 elm_entry_context_menu_disabled_set(label, EINA_TRUE);
711 elm_object_text_set(label, text);
713 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
714 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
715 evas_object_show(label);
720 Evas_Object *_create_slide_title(Evas_Object *parent, const char *text)
722 if (parent == NULL || text == NULL)
727 label = elm_label_add(parent);
728 elm_object_style_set(label, "naviframe_title");
729 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
730 elm_label_wrap_width_set(label, 1);
731 elm_label_ellipsis_set(label, EINA_TRUE);
732 elm_object_text_set(label, text);
733 evas_object_show(label);
735 elm_access_object_unregister(label);