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.
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 if (wifi_state == true) {
108 if (_turn_off_wifi(ad) != 0) {
109 ERR("_turn_off_wifi is failed\n");
110 _update_wifi_item(ad, MH_STATE_NONE);
112 } else if (_is_wifi_direct_on() == true) {
113 if (_turn_off_wifi_direct(ad) != 0) {
114 ERR("_turn_off_wifi_direct is failed\n");
115 _update_wifi_item(ad, MH_STATE_NONE);
118 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
119 if (ret != TETHERING_ERROR_NONE) {
120 ERR("wifi tethering on is failed : %d\n", ret);
121 _update_wifi_item(ad, MH_STATE_NONE);
126 case MH_POP_WIFI_OFF_CONF:
127 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
128 if (ret != TETHERING_ERROR_NONE) {
129 ERR("wifi tethering off is failed : %d\n", ret);
130 _update_wifi_item(ad, MH_STATE_NONE);
134 case MH_POP_BT_ON_CONF:
135 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
136 if (ret != TETHERING_ERROR_NONE) {
137 ERR("Error enable bt tethering : %d\n", ret);
138 _update_bt_item(ad, MH_STATE_NONE);
142 case MH_POP_USB_ON_CONF:
143 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
144 _prepare_popup(MH_POP_USB_CONNECT,
145 _("IDS_MOBILEAP_POP_CONNECT_USB_CABLE"));
147 vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
148 _handle_usb_mode_change, (void *)ad);
152 _prepare_popup(MH_POP_USB_ON_PREVCONN_CONF,
153 _("IDS_MOBILEAP_POP_ENABLING_USB_TETHERING_WILL_DISCONNECT_PREVIOUS_USB_CONNECTION"));
157 case MH_POP_USB_ON_PREVCONN_CONF:
158 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
159 if (ret != TETHERING_ERROR_NONE) {
160 ERR("Error enable usb tethering : %d\n", ret);
161 _update_usb_item(ad, MH_STATE_NONE);
165 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
166 _update_wifi_item(ad, MH_STATE_PROCESS);
167 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
168 if (ret != TETHERING_ERROR_NONE) {
169 ERR("Wi-Fi tethering off is failed : %d\n", ret);
170 _update_wifi_item(ad, MH_STATE_NONE);
172 ad->main.need_recover_wifi_tethering = true;
174 mh_draw_wifi_setup_view(ad);
178 DBG("Unknown popup_type : %d\n", popup_type);
182 __MOBILE_AP_FUNC_EXIT__;
185 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
187 __MOBILE_AP_FUNC_ENTER__;
189 if (data == NULL || obj == NULL) {
190 ERR("The param is NULL\n");
194 mh_appdata_t *ad = (mh_appdata_t *)data;
196 evas_object_del(ad->popup);
199 DBG("popup_type : %d\n", popup_type);
200 switch (popup_type) {
201 case MH_POP_WIFI_ON_CONF:
202 _update_wifi_item(ad, MH_STATE_NONE);
205 case MH_POP_WIFI_OFF_CONF:
206 _update_wifi_item(ad, MH_STATE_NONE);
209 case MH_POP_BT_ON_CONF:
210 _update_bt_item(ad, MH_STATE_NONE);
213 case MH_POP_USB_ON_CONF:
214 _update_usb_item(ad, MH_STATE_NONE);
217 case MH_POP_USB_ON_PREVCONN_CONF:
218 _update_usb_item(ad, MH_STATE_NONE);
221 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
225 DBG("Unknown popup_type : %d\n", popup_type);
229 __MOBILE_AP_FUNC_EXIT__;
232 static bool _count_connected_clients_cb(tethering_client_h client, void *user_data)
234 if (user_data == NULL) {
235 ERR("user_data is NULL\n");
239 int *count = (int *)user_data;
246 void _prepare_popup_with_content(int type, Evas_Object *obj)
248 __MOBILE_AP_FUNC_ENTER__;
251 ERR("param is NULL\n");
258 evas_object_del(popup_content);
266 __MOBILE_AP_FUNC_EXIT__;
269 void _prepare_popup(int type, const char *str)
271 __MOBILE_AP_FUNC_ENTER__;
274 ERR("param is NULL\n");
279 popup_content = NULL;
284 popup_string = strndup(str, MH_LABEL_LENGTH_MAX);
285 if (popup_string == NULL)
286 ERR("strndup is failed\n");
288 __MOBILE_AP_FUNC_EXIT__;
291 Eina_Bool _create_popup(mh_appdata_t *ad)
293 __MOBILE_AP_FUNC_ENTER__;
295 Evas_Object *btn = NULL;
298 ERR("The param is NULL\n");
303 popup_content = NULL;
308 if (ad->popup != NULL) {
309 DBG("Pop-up already exists. Delete it.\n");
310 evas_object_del(ad->popup);
314 DBG("Create_popup %d\n", popup_type);
315 switch (popup_type) {
316 case MH_POP_WIFI_ON_CONF:
317 ad->popup = elm_popup_add(ad->win);
318 evas_object_size_hint_weight_set(ad->popup,
319 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
321 if (popup_content == NULL)
322 elm_object_text_set(ad->popup, popup_string);
324 elm_object_content_set(ad->popup, popup_content);
326 btn = elm_button_add(ad->popup);
327 elm_object_style_set(btn, "popup_button/default");
328 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
329 elm_object_part_content_set(ad->popup, "button1", btn);
330 evas_object_smart_callback_add(btn, "clicked",
331 __popup_resp_yes, (void *)ad);
333 btn = elm_button_add(ad->popup);
334 elm_object_style_set(btn, "popup_button/default");
335 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
336 elm_object_part_content_set(ad->popup, "button2", btn);
337 evas_object_smart_callback_add(btn, "clicked",
338 __popup_resp_no, (void *)ad);
340 evas_object_show(ad->popup);
343 case MH_POP_WIFI_OFF_CONF:
344 ad->popup = elm_popup_add(ad->win);
345 evas_object_size_hint_weight_set(ad->popup,
346 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
348 if (popup_content == NULL)
349 elm_object_text_set(ad->popup, popup_string);
351 elm_object_content_set(ad->popup, popup_content);
353 btn = elm_button_add(ad->popup);
354 elm_object_style_set(btn, "popup_button/default");
355 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
356 elm_object_part_content_set(ad->popup, "button1", btn);
357 evas_object_smart_callback_add(btn, "clicked",
358 __popup_resp_yes, (void *)ad);
360 btn = elm_button_add(ad->popup);
361 elm_object_style_set(btn, "popup_button/default");
362 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
363 elm_object_part_content_set(ad->popup, "button2", btn);
364 evas_object_smart_callback_add(btn, "clicked",
365 __popup_resp_no, (void *)ad);
367 evas_object_show(ad->popup);
370 case MH_POP_USB_CONNECT:
371 ad->popup = elm_popup_add(ad->win);
372 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
375 if (popup_content == NULL)
376 elm_object_text_set(ad->popup, popup_string);
378 elm_object_content_set(ad->popup, popup_content);
380 btn = elm_button_add(ad->popup);
381 elm_object_style_set(btn, "popup_button/default");
382 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
383 elm_object_part_content_set(ad->popup, "button1", btn);
384 evas_object_smart_callback_add(btn, "clicked",
385 __one_btn_popup_resp, (void *)ad);
387 evas_object_show(ad->popup);
390 case MH_POP_BT_ON_CONF:
391 ad->popup = elm_popup_add(ad->win);
392 evas_object_size_hint_weight_set(ad->popup,
393 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
395 if (popup_content == NULL)
396 elm_object_text_set(ad->popup, popup_string);
398 elm_object_content_set(ad->popup, popup_content);
400 btn = elm_button_add(ad->popup);
401 elm_object_style_set(btn, "popup_button/default");
402 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
403 elm_object_part_content_set(ad->popup, "button1", btn);
404 evas_object_smart_callback_add(btn, "clicked",
405 __popup_resp_yes, (void *)ad);
407 btn = elm_button_add(ad->popup);
408 elm_object_style_set(btn, "popup_button/default");
409 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
410 elm_object_part_content_set(ad->popup, "button2", btn);
411 evas_object_smart_callback_add(btn, "clicked",
412 __popup_resp_no, (void *)ad);
414 evas_object_show(ad->popup);
417 case MH_POP_USB_ON_CONF:
418 case MH_POP_USB_ON_PREVCONN_CONF:
419 ad->popup = elm_popup_add(ad->win);
420 evas_object_size_hint_weight_set(ad->popup,
421 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
423 if (popup_content == NULL)
424 elm_object_text_set(ad->popup, popup_string);
426 elm_object_content_set(ad->popup, popup_content);
428 btn = elm_button_add(ad->popup);
429 elm_object_style_set(btn, "popup_button/default");
430 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
431 elm_object_part_content_set(ad->popup, "button1", btn);
432 evas_object_smart_callback_add(btn, "clicked",
433 __popup_resp_yes, (void *)ad);
435 btn = elm_button_add(ad->popup);
436 elm_object_style_set(btn, "popup_button/default");
437 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
438 elm_object_part_content_set(ad->popup, "button2", btn);
439 evas_object_smart_callback_add(btn, "clicked",
440 __popup_resp_no, (void *)ad);
442 evas_object_show(ad->popup);
445 case MH_POP_INFORMATION:
446 ad->popup = elm_popup_add(ad->win);
447 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
450 if (popup_content == NULL)
451 elm_object_text_set(ad->popup, popup_string);
453 elm_object_content_set(ad->popup, popup_content);
455 btn = elm_button_add(ad->popup);
456 elm_object_style_set(btn, "popup_button/default");
457 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
458 elm_object_part_content_set(ad->popup, "button1", btn);
459 evas_object_smart_callback_add(btn, "clicked",
460 __one_btn_popup_resp, (void *)ad);
462 evas_object_show(ad->popup);
465 case MH_POP_INFORMATION_WO_BUTTON:
466 ad->popup = elm_popup_add(ad->win);
467 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
470 if (popup_content == NULL)
471 elm_object_text_set(ad->popup, popup_string);
473 elm_object_content_set(ad->popup, popup_content);
475 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
476 evas_object_smart_callback_add(ad->popup, "timeout",
477 __alert_popup_resp, (void *)ad);
478 evas_object_smart_callback_add(ad->popup, "block,clicked",
479 __alert_popup_resp, (void *)ad);
481 evas_object_show(ad->popup);
484 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
485 ad->popup = elm_popup_add(ad->win);
486 evas_object_size_hint_weight_set(ad->popup,
487 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
489 if (popup_content == NULL)
490 elm_object_text_set(ad->popup, popup_string);
492 elm_object_content_set(ad->popup, popup_content);
494 btn = elm_button_add(ad->popup);
495 elm_object_style_set(btn, "popup_button/default");
496 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
497 elm_object_part_content_set(ad->popup, "button1", btn);
498 evas_object_smart_callback_add(btn, "clicked",
499 __popup_resp_yes, (void *)ad);
501 btn = elm_button_add(ad->popup);
502 elm_object_style_set(btn, "popup_button/default");
503 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
504 elm_object_part_content_set(ad->popup, "button2", btn);
505 evas_object_smart_callback_add(btn, "clicked",
506 __popup_resp_no, (void *)ad);
508 evas_object_show(ad->popup);
511 ERR("Unknown popup_type : %d\n", popup_type);
519 popup_content = NULL;
521 __MOBILE_AP_FUNC_EXIT__;
526 void _destroy_popup(mh_appdata_t *ad)
528 __MOBILE_AP_FUNC_ENTER__;
530 if (ad && ad->popup) {
531 evas_object_del(ad->popup);
539 popup_content = NULL;
540 popup_type = MH_POPUP_NONE;
542 __MOBILE_AP_FUNC_EXIT__;
547 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
549 __MOBILE_AP_FUNC_ENTER__;
551 if (parent == NULL || style == NULL) {
552 ERR("The param is NULL\n");
556 Evas_Object *bg = NULL;
558 bg = elm_bg_add(parent);
564 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
565 elm_object_style_set(bg, style);
566 evas_object_show(bg);
571 Evas_Object *_create_win_layout(mh_appdata_t *ad)
573 __MOBILE_AP_FUNC_ENTER__;
575 if (ad->win == NULL) {
576 ERR("There is no main window\n");
583 layout = elm_layout_add(ad->win);
584 if (layout == NULL) {
585 ERR("layout is NULL\n");
589 elm_layout_theme_set(layout, "layout", "application", "default");
590 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
593 bg = _create_bg(layout, "group_list");
596 evas_object_del(layout);
599 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
601 evas_object_show(layout);
606 __MOBILE_AP_FUNC_EXIT__;
611 Evas_Object *_create_naviframe(Evas_Object *parent)
613 __MOBILE_AP_FUNC_ENTER__;
615 if (parent == NULL) {
616 ERR("parent is NULL\n");
620 Evas_Object *naviframe;
622 naviframe = elm_naviframe_add(parent);
623 if (naviframe == NULL) {
624 ERR("naviframe is NULL\n");
627 evas_object_show(naviframe);
629 __MOBILE_AP_FUNC_EXIT__;
634 void _handle_usb_mode_change(keynode_t *key, void *data)
636 mh_appdata_t *ad = (mh_appdata_t *)data;
640 ERR("The param is NULL\n");
644 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
645 ERR("Invalid vconf key\n");
649 vconf_key = vconf_keynode_get_int(key);
650 DBG("vconf_key : %d\n", vconf_key);
651 if (vconf_key == SETTING_USB_NONE_MODE) {
652 DBG("usb-utilties is processing mode change\n");
656 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
657 _handle_usb_mode_change);
659 evas_object_del(ad->popup);
662 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
663 DBG("Error enable usb tethering\n");
664 _update_usb_item(ad, MH_STATE_NONE);
668 int _get_vconf_hotspot_mode(void)
670 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
672 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
673 ERR("vconf_get_int is failed\n");
677 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
682 Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_type_e type)
684 if (handle == NULL || no == NULL)
687 tethering_foreach_connected_clients(handle, type,
688 _count_connected_clients_cb, (void *)no);
693 Evas_Object *_create_label(Evas_Object *parent, const char *text)
697 label = elm_entry_add(parent);
699 ERR("elm_entry_add is failed\n");
703 elm_entry_editable_set(label, EINA_FALSE);
704 elm_entry_context_menu_disabled_set(label, EINA_TRUE);
705 elm_object_text_set(label, text);
707 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
708 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
709 evas_object_show(label);
714 Evas_Object *_create_slide_title(Evas_Object *parent, const char *text)
716 if (parent == NULL || text == NULL)
721 label = elm_label_add(parent);
722 elm_object_style_set(label, "naviframe_title");
723 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
724 elm_label_wrap_width_set(label, 1);
725 elm_label_ellipsis_set(label, EINA_TRUE);
726 elm_object_text_set(label, text);
727 evas_object_show(label);
729 elm_access_object_unregister(label);