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://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 void __one_btn_popup_resp(void *data, Evas_Object *obj, void *event_info)
25 __MOBILE_AP_FUNC_ENTER__;
27 if (data == NULL || obj == NULL) {
28 ERR("The param is NULL\n");
32 mh_appdata_t *ad = (mh_appdata_t *)data;
34 evas_object_del(ad->popup);
37 DBG("popup_type : %d\n", ad->popup_type);
38 switch (ad->popup_type) {
39 case MH_POP_USB_CONNECT:
40 _update_usb_item(ad, MH_STATE_NONE);
41 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
42 _handle_usb_mode_change);
45 case MH_POP_INFORMATION:
48 case MH_POP_WIFI_PASSWORD_SHORT:
49 if (ad->setup.pw_entry == NULL)
52 evas_object_show(ad->setup.pw_entry);
53 elm_object_focus_set(ad->setup.pw_entry, EINA_TRUE);
57 DBG("Unknown popup_type : %d\n", ad->popup_type);
61 __MOBILE_AP_FUNC_EXIT__;
64 static void __alert_popup_resp(void *data, Evas_Object *obj, void *event_info)
66 __MOBILE_AP_FUNC_ENTER__;
68 if (data == NULL || obj == NULL) {
69 ERR("The param is NULL\n");
73 mh_appdata_t *ad = (mh_appdata_t *)data;
75 evas_object_del(ad->popup);
78 DBG("popup_type : %d\n", ad->popup_type);
79 switch (ad->popup_type) {
80 case MH_POP_INFORMATION_WO_BUTTON:
84 DBG("Unknown popup_type : %d\n", ad->popup_type);
88 __MOBILE_AP_FUNC_EXIT__;
91 static void __popup_resp_yes(void *data, Evas_Object *obj, void *event_info)
93 __MOBILE_AP_FUNC_ENTER__;
95 if (data == NULL || obj == NULL) {
96 ERR("The param is NULL\n");
100 mh_appdata_t *ad = (mh_appdata_t *)data;
104 evas_object_del(ad->popup);
107 DBG("popup_type : %d\n", ad->popup_type);
108 switch (ad->popup_type) {
109 case MH_POP_WIFI_ON_CONF:
110 wifi_is_activated(&wifi_state);
111 if (wifi_state == true) {
112 if (_turn_off_wifi(ad) != 0) {
113 ERR("_turn_off_wifi is failed\n");
114 _update_wifi_item(ad, MH_STATE_NONE);
116 } else if (_is_wifi_direct_on() == true) {
117 if (_turn_off_wifi_direct(ad) != 0) {
118 ERR("_turn_off_wifi_direct is failed\n");
119 _update_wifi_item(ad, MH_STATE_NONE);
122 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
123 if (ret != TETHERING_ERROR_NONE) {
124 ERR("wifi tethering on is failed : %d\n", ret);
125 _update_wifi_item(ad, MH_STATE_NONE);
130 case MH_POP_WIFI_OFF_CONF:
131 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
132 if (ret != TETHERING_ERROR_NONE) {
133 ERR("wifi tethering off is failed : %d\n", ret);
134 _update_wifi_item(ad, MH_STATE_NONE);
138 case MH_POP_BT_ON_CONF:
139 ret = tethering_enable(ad->handle, TETHERING_TYPE_BT);
140 if (ret != TETHERING_ERROR_NONE) {
141 ERR("Error enable bt tethering : %d\n", ret);
142 _update_bt_item(ad, MH_STATE_NONE);
146 case MH_POP_USB_ON_CONF:
147 if (_get_vconf_usb_state() != VCONFKEY_SYSMAN_USB_AVAILABLE) {
148 _prepare_popup(ad, MH_POP_USB_CONNECT,
149 _("IDS_MOBILEAP_POP_CONNECT_USB_CABLE"));
151 vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
152 _handle_usb_mode_change, (void *)ad);
156 _prepare_popup(ad, MH_POP_USB_ON_PREVCONN_CONF,
157 _("IDS_MOBILEAP_POP_ENABLING_USB_TETHERING_WILL_DISCONNECT_PREVIOUS_USB_CONNECTION"));
161 case MH_POP_USB_ON_PREVCONN_CONF:
162 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
163 if (ret != TETHERING_ERROR_NONE) {
164 ERR("Error enable usb tethering : %d\n", ret);
165 _update_usb_item(ad, MH_STATE_NONE);
169 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
170 _update_wifi_item(ad, MH_STATE_PROCESS);
171 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
172 if (ret != TETHERING_ERROR_NONE) {
173 ERR("Wi-Fi tethering off is failed : %d\n", ret);
174 _update_wifi_item(ad, MH_STATE_NONE);
176 ad->main.need_recover_wifi_tethering = true;
178 mh_draw_wifi_setup_view(ad);
182 DBG("Unknown popup_type : %d\n", ad->popup_type);
186 __MOBILE_AP_FUNC_EXIT__;
189 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
191 __MOBILE_AP_FUNC_ENTER__;
193 if (data == NULL || obj == NULL) {
194 ERR("The param is NULL\n");
198 mh_appdata_t *ad = (mh_appdata_t *)data;
200 evas_object_del(ad->popup);
203 DBG("popup_type : %d\n", ad->popup_type);
204 switch (ad->popup_type) {
205 case MH_POP_WIFI_ON_CONF:
206 _update_wifi_item(ad, MH_STATE_NONE);
209 case MH_POP_WIFI_OFF_CONF:
210 _update_wifi_item(ad, MH_STATE_NONE);
213 case MH_POP_BT_ON_CONF:
214 _update_bt_item(ad, MH_STATE_NONE);
217 case MH_POP_USB_ON_CONF:
218 _update_usb_item(ad, MH_STATE_NONE);
221 case MH_POP_USB_ON_PREVCONN_CONF:
222 _update_usb_item(ad, MH_STATE_NONE);
225 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
229 DBG("Unknown popup_type : %d\n", ad->popup_type);
233 __MOBILE_AP_FUNC_EXIT__;
236 static bool _count_connected_clients_cb(tethering_client_h client, void *user_data)
238 if (user_data == NULL) {
239 ERR("user_data is NULL\n");
243 int *count = (int *)user_data;
250 void _prepare_popup(mh_appdata_t *ad, int type, const char *str)
252 __MOBILE_AP_FUNC_ENTER__;
254 if (ad == NULL || str == NULL) {
255 ERR("param is NULL : ad[%x], str[%x]\n", ad, str);
262 if (sizeof(ad->popup_string) <= nLen)
263 ERR("We should make the message[%s] less than %d",
264 str, sizeof(ad->popup_string));
266 ad->popup_type = type;
267 snprintf(ad->popup_string, sizeof(ad->popup_string), "%s", str);
269 __MOBILE_AP_FUNC_EXIT__;
272 Eina_Bool _create_popup(mh_appdata_t *ad)
274 __MOBILE_AP_FUNC_ENTER__;
276 Evas_Object *btn = NULL;
279 ERR("The param is NULL\n");
283 if (ad->popup != NULL) {
284 DBG("Pop-up already exists. Delete it.\n");
285 evas_object_del(ad->popup);
289 DBG("Create_popup %d\n", ad->popup_type);
290 switch (ad->popup_type) {
291 case MH_POP_WIFI_ON_CONF:
292 ad->popup = elm_popup_add(ad->win);
293 evas_object_size_hint_weight_set(ad->popup,
294 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296 elm_object_text_set(ad->popup, ad->popup_string);
298 btn = elm_button_add(ad->popup);
299 elm_object_style_set(btn, "popup_button/default");
300 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
301 elm_object_part_content_set(ad->popup, "button1", btn);
302 evas_object_smart_callback_add(btn, "clicked",
303 __popup_resp_yes, (void *)ad);
305 btn = elm_button_add(ad->popup);
306 elm_object_style_set(btn, "popup_button/default");
307 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
308 elm_object_part_content_set(ad->popup, "button2", btn);
309 evas_object_smart_callback_add(btn, "clicked",
310 __popup_resp_no, (void *)ad);
312 evas_object_show(ad->popup);
315 case MH_POP_WIFI_OFF_CONF:
316 ad->popup = elm_popup_add(ad->win);
317 evas_object_size_hint_weight_set(ad->popup,
318 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
320 elm_object_text_set(ad->popup, ad->popup_string);
322 btn = elm_button_add(ad->popup);
323 elm_object_style_set(btn, "popup_button/default");
324 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
325 elm_object_part_content_set(ad->popup, "button1", btn);
326 evas_object_smart_callback_add(btn, "clicked",
327 __popup_resp_yes, (void *)ad);
329 btn = elm_button_add(ad->popup);
330 elm_object_style_set(btn, "popup_button/default");
331 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
332 elm_object_part_content_set(ad->popup, "button2", btn);
333 evas_object_smart_callback_add(btn, "clicked",
334 __popup_resp_no, (void *)ad);
336 evas_object_show(ad->popup);
339 case MH_POP_USB_CONNECT:
340 ad->popup = elm_popup_add(ad->win);
341 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
344 elm_object_text_set(ad->popup, ad->popup_string);
346 btn = elm_button_add(ad->popup);
347 elm_object_style_set(btn, "popup_button/default");
348 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
349 elm_object_part_content_set(ad->popup, "button1", btn);
350 evas_object_smart_callback_add(btn, "clicked",
351 __one_btn_popup_resp, (void *)ad);
353 evas_object_show(ad->popup);
356 case MH_POP_BT_ON_CONF:
357 ad->popup = elm_popup_add(ad->win);
358 evas_object_size_hint_weight_set(ad->popup,
359 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
361 elm_object_text_set(ad->popup, ad->popup_string);
363 btn = elm_button_add(ad->popup);
364 elm_object_style_set(btn, "popup_button/default");
365 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
366 elm_object_part_content_set(ad->popup, "button1", btn);
367 evas_object_smart_callback_add(btn, "clicked",
368 __popup_resp_yes, (void *)ad);
370 btn = elm_button_add(ad->popup);
371 elm_object_style_set(btn, "popup_button/default");
372 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
373 elm_object_part_content_set(ad->popup, "button2", btn);
374 evas_object_smart_callback_add(btn, "clicked",
375 __popup_resp_no, (void *)ad);
377 evas_object_show(ad->popup);
380 case MH_POP_USB_ON_CONF:
381 case MH_POP_USB_ON_PREVCONN_CONF:
382 ad->popup = elm_popup_add(ad->win);
383 evas_object_size_hint_weight_set(ad->popup,
384 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
386 elm_object_text_set(ad->popup, ad->popup_string);
388 btn = elm_button_add(ad->popup);
389 elm_object_style_set(btn, "popup_button/default");
390 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
391 elm_object_part_content_set(ad->popup, "button1", btn);
392 evas_object_smart_callback_add(btn, "clicked",
393 __popup_resp_yes, (void *)ad);
395 btn = elm_button_add(ad->popup);
396 elm_object_style_set(btn, "popup_button/default");
397 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
398 elm_object_part_content_set(ad->popup, "button2", btn);
399 evas_object_smart_callback_add(btn, "clicked",
400 __popup_resp_no, (void *)ad);
402 evas_object_show(ad->popup);
405 case MH_POP_INFORMATION:
406 ad->popup = elm_popup_add(ad->win);
407 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
410 elm_object_text_set(ad->popup, ad->popup_string);
412 btn = elm_button_add(ad->popup);
413 elm_object_style_set(btn, "popup_button/default");
414 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
415 elm_object_part_content_set(ad->popup, "button1", btn);
416 evas_object_smart_callback_add(btn, "clicked",
417 __one_btn_popup_resp, (void *)ad);
419 evas_object_show(ad->popup);
422 case MH_POP_WIFI_PASSWORD_SHORT:
423 ad->popup = elm_popup_add(ad->win);
424 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
427 elm_object_text_set(ad->popup, ad->popup_string);
429 btn = elm_button_add(ad->popup);
430 elm_object_style_set(btn, "popup_button/default");
431 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
432 elm_object_part_content_set(ad->popup, "button1", btn);
433 evas_object_smart_callback_add(btn, "clicked",
434 __one_btn_popup_resp, (void *)ad);
436 evas_object_show(ad->popup);
439 case MH_POP_INFORMATION_WO_BUTTON:
440 ad->popup = elm_popup_add(ad->win);
441 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
444 elm_object_text_set(ad->popup, ad->popup_string);
446 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
447 evas_object_smart_callback_add(ad->popup, "timeout",
448 __alert_popup_resp, (void *)ad);
449 evas_object_smart_callback_add(ad->popup, "block,clicked",
450 __alert_popup_resp, (void *)ad);
452 evas_object_show(ad->popup);
455 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
456 ad->popup = elm_popup_add(ad->win);
457 evas_object_size_hint_weight_set(ad->popup,
458 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
460 elm_object_text_set(ad->popup, ad->popup_string);
462 btn = elm_button_add(ad->popup);
463 elm_object_style_set(btn, "popup_button/default");
464 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
465 elm_object_part_content_set(ad->popup, "button1", btn);
466 evas_object_smart_callback_add(btn, "clicked",
467 __popup_resp_yes, (void *)ad);
469 btn = elm_button_add(ad->popup);
470 elm_object_style_set(btn, "popup_button/default");
471 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
472 elm_object_part_content_set(ad->popup, "button2", btn);
473 evas_object_smart_callback_add(btn, "clicked",
474 __popup_resp_no, (void *)ad);
476 evas_object_show(ad->popup);
480 __MOBILE_AP_FUNC_EXIT__;
485 void _destroy_popup(mh_appdata_t *ad)
487 __MOBILE_AP_FUNC_ENTER__;
495 evas_object_del(ad->popup);
499 ad->popup_type = MH_POPUP_NONE;
501 __MOBILE_AP_FUNC_EXIT__;
506 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
508 __MOBILE_AP_FUNC_ENTER__;
510 if (parent == NULL || style == NULL) {
511 ERR("The param is NULL\n");
515 Evas_Object *bg = NULL;
517 bg = elm_bg_add(parent);
523 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
524 elm_object_style_set(bg, style);
525 evas_object_show(bg);
530 Evas_Object *_create_win_layout(mh_appdata_t *ad)
532 __MOBILE_AP_FUNC_ENTER__;
534 if (ad->win == NULL) {
535 ERR("There is no main window\n");
542 layout = elm_layout_add(ad->win);
543 if (layout == NULL) {
544 ERR("layout is NULL\n");
548 elm_layout_theme_set(layout, "layout", "application", "default");
549 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
552 bg = _create_bg(layout, "group_list");
555 evas_object_del(layout);
558 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
560 evas_object_show(layout);
565 __MOBILE_AP_FUNC_EXIT__;
570 Evas_Object *_create_naviframe(Evas_Object *parent)
572 __MOBILE_AP_FUNC_ENTER__;
574 if (parent == NULL) {
575 ERR("parent is NULL\n");
579 Evas_Object *naviframe;
581 naviframe = elm_naviframe_add(parent);
582 if (naviframe == NULL) {
583 ERR("naviframe is NULL\n");
586 evas_object_show(naviframe);
588 __MOBILE_AP_FUNC_EXIT__;
593 void _handle_usb_mode_change(keynode_t *key, void *data)
595 mh_appdata_t *ad = (mh_appdata_t *)data;
599 ERR("The param is NULL\n");
603 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
604 ERR("Invalid vconf key\n");
608 vconf_key = vconf_keynode_get_int(key);
609 DBG("vconf_key : %d\n", vconf_key);
610 if (vconf_key == SETTING_USB_NONE_MODE) {
611 DBG("usb-utilties is processing mode change\n");
615 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
616 _handle_usb_mode_change);
618 evas_object_del(ad->popup);
621 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
622 DBG("Error enable usb tethering\n");
623 _update_usb_item(ad, MH_STATE_NONE);
627 int _get_vconf_hotspot_mode(void)
629 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
631 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
632 ERR("vconf_get_int is failed\n");
636 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
641 Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_type_e type)
643 if (handle == NULL || no == NULL)
646 tethering_foreach_connected_clients(handle, type,
647 _count_connected_clients_cb, (void *)no);