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 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 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
157 if (ret != TETHERING_ERROR_NONE) {
158 ERR("Error enable usb tethering : %d\n", ret);
159 _update_usb_item(ad, MH_STATE_NONE);
163 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
164 _update_wifi_item(ad, MH_STATE_PROCESS);
165 ret = tethering_disable(ad->handle, TETHERING_TYPE_WIFI);
166 if (ret != TETHERING_ERROR_NONE) {
167 ERR("wifi tethering off is failed : %d\n", ret);
168 _update_wifi_item(ad, MH_STATE_NONE);
170 ad->main.old_wifi_state = true;
172 mh_draw_wifi_setup_view(ad);
176 DBG("Unknown popup_type : %d\n", ad->popup_type);
180 __MOBILE_AP_FUNC_EXIT__;
183 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
185 __MOBILE_AP_FUNC_ENTER__;
187 if (data == NULL || obj == NULL) {
188 ERR("The param is NULL\n");
192 mh_appdata_t *ad = (mh_appdata_t *)data;
194 evas_object_del(ad->popup);
197 DBG("popup_type : %d\n", ad->popup_type);
198 switch (ad->popup_type) {
199 case MH_POP_WIFI_ON_CONF:
200 _update_wifi_item(ad, MH_STATE_NONE);
203 case MH_POP_WIFI_OFF_CONF:
204 _update_wifi_item(ad, MH_STATE_NONE);
207 case MH_POP_BT_ON_CONF:
208 _update_bt_item(ad, MH_STATE_NONE);
211 case MH_POP_USB_ON_CONF:
212 _update_usb_item(ad, MH_STATE_NONE);
215 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
219 DBG("Unknown popup_type : %d\n", ad->popup_type);
223 __MOBILE_AP_FUNC_EXIT__;
226 static bool _count_connected_clients_cb(tethering_client_h client, void *user_data)
228 if (user_data == NULL) {
229 ERR("user_data is NULL\n");
233 int *count = (int *)user_data;
240 void _prepare_popup(mh_appdata_t *ad, int type, const char *str)
242 __MOBILE_AP_FUNC_ENTER__;
244 if (ad == NULL || str == NULL) {
245 ERR("param is NULL : ad[%x], str[%x]\n", ad, str);
252 if (sizeof(ad->popup_string) <= nLen)
253 ERR("We should make the message[%s] less than %d",
254 str, sizeof(ad->popup_string));
256 ad->popup_type = type;
257 snprintf(ad->popup_string, sizeof(ad->popup_string), "%s", str);
259 __MOBILE_AP_FUNC_EXIT__;
262 Eina_Bool _create_popup(mh_appdata_t *ad)
264 __MOBILE_AP_FUNC_ENTER__;
266 Evas_Object *btn = NULL;
269 ERR("The param is NULL\n");
273 if (ad->popup != NULL) {
274 DBG("Pop-up already exists. Delete it.\n");
275 evas_object_del(ad->popup);
279 DBG("Create_popup %d\n", ad->popup_type);
280 switch (ad->popup_type) {
281 case MH_POP_WIFI_ON_CONF:
282 ad->popup = elm_popup_add(ad->win);
283 evas_object_size_hint_weight_set(ad->popup,
284 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
286 elm_object_text_set(ad->popup, ad->popup_string);
288 btn = elm_button_add(ad->popup);
289 elm_object_style_set(btn, "popup_button/default");
290 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
291 elm_object_part_content_set(ad->popup, "button1", btn);
292 evas_object_smart_callback_add(btn, "clicked",
293 __popup_resp_yes, (void *)ad);
295 btn = elm_button_add(ad->popup);
296 elm_object_style_set(btn, "popup_button/default");
297 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
298 elm_object_part_content_set(ad->popup, "button2", btn);
299 evas_object_smart_callback_add(btn, "clicked",
300 __popup_resp_no, (void *)ad);
302 evas_object_show(ad->popup);
305 case MH_POP_WIFI_OFF_CONF:
306 ad->popup = elm_popup_add(ad->win);
307 evas_object_size_hint_weight_set(ad->popup,
308 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
310 elm_object_text_set(ad->popup, ad->popup_string);
312 btn = elm_button_add(ad->popup);
313 elm_object_style_set(btn, "popup_button/default");
314 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
315 elm_object_part_content_set(ad->popup, "button1", btn);
316 evas_object_smart_callback_add(btn, "clicked",
317 __popup_resp_yes, (void *)ad);
319 btn = elm_button_add(ad->popup);
320 elm_object_style_set(btn, "popup_button/default");
321 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
322 elm_object_part_content_set(ad->popup, "button2", btn);
323 evas_object_smart_callback_add(btn, "clicked",
324 __popup_resp_no, (void *)ad);
326 evas_object_show(ad->popup);
329 case MH_POP_USB_CONNECT:
330 ad->popup = elm_popup_add(ad->win);
331 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
334 elm_object_text_set(ad->popup, ad->popup_string);
336 btn = elm_button_add(ad->popup);
337 elm_object_style_set(btn, "popup_button/default");
338 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
339 elm_object_part_content_set(ad->popup, "button1", btn);
340 evas_object_smart_callback_add(btn, "clicked",
341 __one_btn_popup_resp, (void *)ad);
343 evas_object_show(ad->popup);
346 case MH_POP_BT_ON_CONF:
347 ad->popup = elm_popup_add(ad->win);
348 evas_object_size_hint_weight_set(ad->popup,
349 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351 elm_object_text_set(ad->popup, ad->popup_string);
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_ON_CONF:
371 ad->popup = elm_popup_add(ad->win);
372 evas_object_size_hint_weight_set(ad->popup,
373 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
375 elm_object_text_set(ad->popup, ad->popup_string);
377 btn = elm_button_add(ad->popup);
378 elm_object_style_set(btn, "popup_button/default");
379 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
380 elm_object_part_content_set(ad->popup, "button1", btn);
381 evas_object_smart_callback_add(btn, "clicked",
382 __popup_resp_yes, (void *)ad);
384 btn = elm_button_add(ad->popup);
385 elm_object_style_set(btn, "popup_button/default");
386 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
387 elm_object_part_content_set(ad->popup, "button2", btn);
388 evas_object_smart_callback_add(btn, "clicked",
389 __popup_resp_no, (void *)ad);
391 evas_object_show(ad->popup);
394 case MH_POP_INFORMATION:
395 ad->popup = elm_popup_add(ad->win);
396 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
399 elm_object_text_set(ad->popup, ad->popup_string);
401 btn = elm_button_add(ad->popup);
402 elm_object_style_set(btn, "popup_button/default");
403 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
404 elm_object_part_content_set(ad->popup, "button1", btn);
405 evas_object_smart_callback_add(btn, "clicked",
406 __one_btn_popup_resp, (void *)ad);
408 evas_object_show(ad->popup);
411 case MH_POP_WIFI_PASSWORD_SHORT:
412 ad->popup = elm_popup_add(ad->win);
413 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
416 elm_object_text_set(ad->popup, ad->popup_string);
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_POP_CLOSE"));
421 elm_object_part_content_set(ad->popup, "button1", btn);
422 evas_object_smart_callback_add(btn, "clicked",
423 __one_btn_popup_resp, (void *)ad);
425 evas_object_show(ad->popup);
428 case MH_POP_INFORMATION_WO_BUTTON:
429 ad->popup = elm_popup_add(ad->win);
430 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
433 elm_object_text_set(ad->popup, ad->popup_string);
435 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
436 evas_object_smart_callback_add(ad->popup, "timeout",
437 __alert_popup_resp, (void *)ad);
438 evas_object_smart_callback_add(ad->popup, "block,clicked",
439 __alert_popup_resp, (void *)ad);
441 evas_object_show(ad->popup);
444 case MH_POP_ENTER_TO_WIFI_SETUP_CONF:
445 ad->popup = elm_popup_add(ad->win);
446 evas_object_size_hint_weight_set(ad->popup,
447 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
449 elm_object_text_set(ad->popup, ad->popup_string);
451 btn = elm_button_add(ad->popup);
452 elm_object_style_set(btn, "popup_button/default");
453 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
454 elm_object_part_content_set(ad->popup, "button1", btn);
455 evas_object_smart_callback_add(btn, "clicked",
456 __popup_resp_yes, (void *)ad);
458 btn = elm_button_add(ad->popup);
459 elm_object_style_set(btn, "popup_button/default");
460 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
461 elm_object_part_content_set(ad->popup, "button2", btn);
462 evas_object_smart_callback_add(btn, "clicked",
463 __popup_resp_no, (void *)ad);
465 evas_object_show(ad->popup);
469 __MOBILE_AP_FUNC_EXIT__;
474 void _destroy_popup(mh_appdata_t *ad)
476 __MOBILE_AP_FUNC_ENTER__;
484 evas_object_del(ad->popup);
488 ad->popup_type = MH_POPUP_NONE;
490 __MOBILE_AP_FUNC_EXIT__;
495 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
497 __MOBILE_AP_FUNC_ENTER__;
499 if (parent == NULL || style == NULL) {
500 ERR("The param is NULL\n");
504 Evas_Object *bg = NULL;
506 bg = elm_bg_add(parent);
512 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
513 elm_object_style_set(bg, style);
514 evas_object_show(bg);
519 Evas_Object *_create_win_layout(mh_appdata_t *ad)
521 __MOBILE_AP_FUNC_ENTER__;
523 if (ad->win == NULL) {
524 ERR("There is no main window\n");
531 layout = elm_layout_add(ad->win);
532 if (layout == NULL) {
533 ERR("layout is NULL\n");
537 elm_layout_theme_set(layout, "layout", "application", "default");
538 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
541 bg = _create_bg(layout, "group_list");
544 evas_object_del(layout);
547 elm_object_part_content_set(layout, "elm.swallow.bg", bg);
549 evas_object_show(layout);
554 __MOBILE_AP_FUNC_EXIT__;
559 Evas_Object *_create_naviframe(Evas_Object *parent)
561 __MOBILE_AP_FUNC_ENTER__;
563 if (parent == NULL) {
564 ERR("parent is NULL\n");
568 Evas_Object *naviframe;
570 naviframe = elm_naviframe_add(parent);
571 if (naviframe == NULL) {
572 ERR("naviframe is NULL\n");
575 evas_object_show(naviframe);
577 __MOBILE_AP_FUNC_EXIT__;
582 void _handle_usb_mode_change(keynode_t *key, void *data)
584 mh_appdata_t *ad = (mh_appdata_t *)data;
588 ERR("The param is NULL\n");
592 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
593 ERR("Invalid vconf key\n");
597 vconf_key = vconf_keynode_get_int(key);
598 DBG("vconf_key : %d\n", vconf_key);
599 if (vconf_key == SETTING_USB_NONE_MODE) {
600 DBG("usb-utilties is processing mode change\n");
604 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
605 _handle_usb_mode_change);
607 evas_object_del(ad->popup);
610 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
611 DBG("Error enable usb tethering\n");
612 _update_usb_item(ad, MH_STATE_NONE);
616 Eina_Bool _hide_imf(Evas_Object *entry)
618 __MOBILE_AP_FUNC_ENTER__;
621 ERR("Invalid param\n");
625 Ecore_IMF_Context *context = NULL;
627 context = elm_entry_imf_context_get(entry);
628 if (context == NULL) {
629 ERR("context is NULL\n");
632 ecore_imf_context_input_panel_hide(context);
634 elm_object_focus_set(entry, EINA_FALSE);
636 __MOBILE_AP_FUNC_EXIT__;
641 int _get_vconf_hotspot_mode(void)
643 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
645 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
646 ERR("vconf_get_int is failed\n");
650 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);
655 Eina_Bool _get_no_of_connected_device(tethering_h handle, int *no, tethering_type_e type)
657 if (handle == NULL || no == NULL)
660 tethering_foreach_connected_clients(handle, type,
661 _count_connected_clients_cb, (void *)no);