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);
115 elm_object_item_disabled_set(ad->main.setup_item,
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);
122 elm_object_item_disabled_set(ad->main.setup_item,
127 ret = tethering_enable(ad->handle, TETHERING_TYPE_WIFI);
128 if (ret != TETHERING_ERROR_NONE) {
129 ERR("wifi tethering on is failed : %d\n", ret);
130 _update_wifi_item(ad, MH_STATE_NONE);
131 elm_object_item_disabled_set(ad->main.setup_item,
137 case MH_POP_WIFI_OFF_CONF:
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);
142 elm_object_item_disabled_set(ad->main.setup_item,
147 case MH_POP_USB_ON_CONF:
148 ret = tethering_enable(ad->handle, TETHERING_TYPE_USB);
149 if (ret != TETHERING_ERROR_NONE) {
150 ERR("Error enable usb tethering : %d\n", ret);
151 elm_check_state_set(ad->main.usb_btn, EINA_FALSE);
152 _update_usb_item(ad, MH_STATE_NONE);
157 DBG("Unknown popup_type : %d\n", ad->popup_type);
161 __MOBILE_AP_FUNC_EXIT__;
164 static void __popup_resp_no(void *data, Evas_Object *obj, void *event_info)
166 __MOBILE_AP_FUNC_ENTER__;
168 if (data == NULL || obj == NULL) {
169 ERR("The param is NULL\n");
173 mh_appdata_t *ad = (mh_appdata_t *)data;
175 evas_object_del(ad->popup);
178 DBG("popup_type : %d\n", ad->popup_type);
179 switch (ad->popup_type) {
180 case MH_POP_WIFI_ON_CONF:
181 _update_wifi_item(ad, MH_STATE_NONE);
182 elm_object_item_disabled_set(ad->main.setup_item, EINA_FALSE);
185 case MH_POP_WIFI_OFF_CONF:
186 _update_wifi_item(ad, MH_STATE_NONE);
187 elm_object_item_disabled_set(ad->main.setup_item, EINA_TRUE);
190 case MH_POP_USB_ON_CONF:
191 elm_check_state_set(ad->main.usb_btn, EINA_FALSE);
192 _update_usb_item(ad, MH_STATE_NONE);
196 DBG("Unknown popup_type : %d\n", ad->popup_type);
200 __MOBILE_AP_FUNC_EXIT__;
203 void _prepare_popup(mh_appdata_t *ad, int type, const char *str)
205 __MOBILE_AP_FUNC_ENTER__;
207 if (ad == NULL || str == NULL) {
208 ERR("param is NULL : ad[%x], str[%x]\n", ad, str);
215 if (sizeof(ad->popup_string) <= nLen)
216 ERR("We should make the message[%s] less than %d",
217 str, sizeof(ad->popup_string));
219 ad->popup_type = type;
220 snprintf(ad->popup_string, sizeof(ad->popup_string), "%s", str);
222 __MOBILE_AP_FUNC_EXIT__;
225 Eina_Bool _create_popup(mh_appdata_t *ad)
227 __MOBILE_AP_FUNC_ENTER__;
229 Evas_Object *btn = NULL;
232 ERR("The param is NULL\n");
236 if (ad->popup != NULL) {
237 DBG("Pop-up already exists. Delete it.\n");
238 evas_object_del(ad->popup);
242 DBG("Create_popup %d\n", ad->popup_type);
243 switch (ad->popup_type) {
244 case MH_POP_WIFI_ON_CONF:
245 ad->popup = elm_popup_add(ad->win);
246 evas_object_size_hint_weight_set(ad->popup,
247 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
249 elm_object_text_set(ad->popup, ad->popup_string);
251 btn = elm_button_add(ad->popup);
252 elm_object_style_set(btn, "popup_button/default");
253 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
254 elm_object_part_content_set(ad->popup, "button1", btn);
255 evas_object_smart_callback_add(btn, "clicked",
256 __popup_resp_yes, (void *)ad);
258 btn = elm_button_add(ad->popup);
259 elm_object_style_set(btn, "popup_button/default");
260 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
261 elm_object_part_content_set(ad->popup, "button2", btn);
262 evas_object_smart_callback_add(btn, "clicked",
263 __popup_resp_no, (void *)ad);
265 evas_object_show(ad->popup);
268 case MH_POP_WIFI_OFF_CONF:
269 ad->popup = elm_popup_add(ad->win);
270 evas_object_size_hint_weight_set(ad->popup,
271 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
273 elm_object_text_set(ad->popup, ad->popup_string);
275 btn = elm_button_add(ad->popup);
276 elm_object_style_set(btn, "popup_button/default");
277 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
278 elm_object_part_content_set(ad->popup, "button1", btn);
279 evas_object_smart_callback_add(btn, "clicked",
280 __popup_resp_yes, (void *)ad);
282 btn = elm_button_add(ad->popup);
283 elm_object_style_set(btn, "popup_button/default");
284 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
285 elm_object_part_content_set(ad->popup, "button2", btn);
286 evas_object_smart_callback_add(btn, "clicked",
287 __popup_resp_no, (void *)ad);
289 evas_object_show(ad->popup);
292 case MH_POP_USB_CONNECT:
293 ad->popup = elm_popup_add(ad->win);
294 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
297 elm_object_text_set(ad->popup, ad->popup_string);
299 btn = elm_button_add(ad->popup);
300 elm_object_style_set(btn, "popup_button/default");
301 elm_object_text_set(btn, S_("IDS_COM_SK_CANCEL"));
302 elm_object_part_content_set(ad->popup, "button1", btn);
303 evas_object_smart_callback_add(btn, "clicked",
304 __one_btn_popup_resp, (void *)ad);
306 evas_object_show(ad->popup);
309 case MH_POP_USB_ON_CONF:
310 ad->popup = elm_popup_add(ad->win);
311 evas_object_size_hint_weight_set(ad->popup,
312 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
314 elm_object_text_set(ad->popup, ad->popup_string);
316 btn = elm_button_add(ad->popup);
317 elm_object_style_set(btn, "popup_button/default");
318 elm_object_text_set(btn, S_("IDS_COM_SK_YES"));
319 elm_object_part_content_set(ad->popup, "button1", btn);
320 evas_object_smart_callback_add(btn, "clicked",
321 __popup_resp_yes, (void *)ad);
323 btn = elm_button_add(ad->popup);
324 elm_object_style_set(btn, "popup_button/default");
325 elm_object_text_set(btn, S_("IDS_COM_SK_NO"));
326 elm_object_part_content_set(ad->popup, "button2", btn);
327 evas_object_smart_callback_add(btn, "clicked",
328 __popup_resp_no, (void *)ad);
330 evas_object_show(ad->popup);
333 case MH_POP_INFORMATION:
334 ad->popup = elm_popup_add(ad->win);
335 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
338 elm_object_text_set(ad->popup, ad->popup_string);
340 btn = elm_button_add(ad->popup);
341 elm_object_style_set(btn, "popup_button/default");
342 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
343 elm_object_part_content_set(ad->popup, "button1", btn);
344 evas_object_smart_callback_add(btn, "clicked",
345 __one_btn_popup_resp, (void *)ad);
347 evas_object_show(ad->popup);
350 case MH_POP_WIFI_PASSWORD_SHORT:
351 ad->popup = elm_popup_add(ad->win);
352 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
355 elm_object_text_set(ad->popup, ad->popup_string);
357 btn = elm_button_add(ad->popup);
358 elm_object_style_set(btn, "popup_button/default");
359 elm_object_text_set(btn, S_("IDS_COM_POP_CLOSE"));
360 elm_object_part_content_set(ad->popup, "button1", btn);
361 evas_object_smart_callback_add(btn, "clicked",
362 __one_btn_popup_resp, (void *)ad);
364 evas_object_show(ad->popup);
367 case MH_POP_INFORMATION_WO_BUTTON:
368 ad->popup = elm_popup_add(ad->win);
369 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
372 elm_object_text_set(ad->popup, ad->popup_string);
374 elm_popup_timeout_set(ad->popup, MH_POPUP_TIMEOUT);
375 evas_object_smart_callback_add(ad->popup, "timeout",
376 __alert_popup_resp, (void *)ad);
377 evas_object_smart_callback_add(ad->popup, "block,clicked",
378 __alert_popup_resp, (void *)ad);
380 evas_object_show(ad->popup);
384 __MOBILE_AP_FUNC_EXIT__;
389 void _destroy_popup(mh_appdata_t *ad)
391 __MOBILE_AP_FUNC_ENTER__;
399 evas_object_del(ad->popup);
403 ad->popup_type = MH_POPUP_NONE;
405 __MOBILE_AP_FUNC_EXIT__;
410 Evas_Object *_create_bg(Evas_Object *parent, const char *style)
412 __MOBILE_AP_FUNC_ENTER__;
414 if (parent == NULL || style == NULL) {
415 ERR("The param is NULL\n");
419 Evas_Object *bg = NULL;
421 bg = elm_bg_add(parent);
427 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
428 elm_object_style_set(bg, style);
433 Evas_Object *_create_layout(Evas_Object *parent)
435 __MOBILE_AP_FUNC_ENTER__;
437 if (parent == NULL) {
438 ERR("The param is NULL\n");
442 Evas_Object *layout = NULL;
444 layout = elm_layout_add(parent);
445 if (layout == NULL) {
446 ERR("layout is NULL\n");
450 elm_layout_theme_set(layout, "layout", "application", "default");
451 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
454 evas_object_show(layout);
456 __MOBILE_AP_FUNC_EXIT__;
461 Evas_Object *_create_naviframe(Evas_Object *parent)
463 __MOBILE_AP_FUNC_ENTER__;
465 if (parent == NULL) {
466 ERR("parent is NULL\n");
470 Evas_Object *naviframe;
472 naviframe = elm_naviframe_add(parent);
473 if (naviframe == NULL) {
474 ERR("naviframe is NULL\n");
477 evas_object_show(naviframe);
479 __MOBILE_AP_FUNC_EXIT__;
484 void _handle_usb_mode_change(keynode_t *key, void *data)
486 mh_appdata_t *ad = (mh_appdata_t *)data;
490 ERR("The param is NULL\n");
494 if (vconf_keynode_get_type(key) != VCONF_TYPE_INT) {
495 ERR("Invalid vconf key\n");
499 vconf_key = vconf_keynode_get_int(key);
500 DBG("vconf_key : %d\n", vconf_key);
501 if (vconf_key == SETTING_USB_NONE_MODE) {
502 DBG("usb-utilties is processing mode change\n");
506 vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
507 _handle_usb_mode_change);
509 evas_object_del(ad->popup);
512 if (tethering_enable(ad->handle, TETHERING_TYPE_USB) != TETHERING_ERROR_NONE) {
513 DBG("Error enable usb tethering\n");
514 elm_check_state_set(ad->main.usb_btn, EINA_FALSE);
515 _update_usb_item(ad, MH_STATE_NONE);
519 Eina_Bool _hide_imf(Evas_Object *entry)
521 __MOBILE_AP_FUNC_ENTER__;
524 ERR("Invalid param\n");
528 Ecore_IMF_Context *context = NULL;
530 context = elm_entry_imf_context_get(entry);
531 if (context == NULL) {
532 ERR("context is NULL\n");
535 ecore_imf_context_input_panel_hide(context);
537 elm_object_focus_set(entry, EINA_FALSE);
539 __MOBILE_AP_FUNC_EXIT__;
544 int _get_vconf_hotspot_mode(void)
546 int value = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE;
548 if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &value) < 0) {
549 ERR("vconf_get_int is failed\n");
553 DBG("%s : %d\n", VCONFKEY_MOBILE_HOTSPOT_MODE, value);