2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This file implements wifi direct system popup view functions.
20 * @file wfd-app-popup-view.c
21 * @author Sungsik Jang (sungsik.jang@samsung.com)
28 #include "wifi-direct.h"
30 #include "wfd-app-strings.h"
31 #include "wfd-app-util.h"
33 extern wfd_appdata_t *g_wfd_ad;
34 extern wfd_popup_t *g_wfd_pop;
35 extern unsigned char g_wfd_peer_mac[6];
36 extern unsigned char g_wfd_peer_name[32];
38 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
40 __WFD_APP_FUNC_ENTER__;
42 wfd_appdata_t *ad = wfd_get_appdata();
44 int resp = (int) data;
45 Evas_Object *btn = obj;
47 WFD_APP_LOG(WFD_APP_LOG_HIGH, "popup resp : %d\n", resp);
51 case WFD_POP_RESP_APRV_CONNECT_PBC_YES:
53 WFD_APP_LOG(WFD_APP_LOG_HIGH,
54 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
56 result = wifi_direct_accept_connection(ad->peer_mac);
57 WFD_APP_LOG(WFD_APP_LOG_LOW,
58 "wifi_direct_accept_connection() result=[%d]\n",
60 if (result == WIFI_DIRECT_ERROR_NONE)
62 wfd_prepare_popup(WFD_POP_PROG_CONNECT, NULL);
66 WFD_APP_LOG(WFD_APP_LOG_ERROR,
67 "wifi_direct_accept_connection() FAILED!!\n");
68 evas_object_hide(ad->win);
73 case WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES:
75 WFD_APP_LOG(WFD_APP_LOG_HIGH,
76 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES\n");
78 result = wifi_direct_accept_connection(ad->peer_mac);
79 WFD_APP_LOG(WFD_APP_LOG_LOW,
80 "wifi_direct_accept_connection() result=[%d]\n",
82 if (result == WIFI_DIRECT_ERROR_NONE)
84 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN,
89 WFD_APP_LOG(WFD_APP_LOG_ERROR,
90 "wifi_direct_client_send_connect_request() FAILED!!\n");
91 evas_object_hide(ad->win);
96 case WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
97 case WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
99 WFD_APP_LOG(WFD_APP_LOG_HIGH,
100 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
102 int len = strlen(ad->pin_number);
103 WFD_APP_LOG(WFD_APP_LOG_LOW, "button ok: pin [%s]", ad->pin_number);
105 if (len > 7 && len < 64)
108 WFD_APP_LOG(WFD_APP_LOG_LOW, "pin=[%s]\n", ad->pin_number);
110 result = wifi_direct_set_wps_pin(ad->pin_number);
112 if (result != WIFI_DIRECT_ERROR_NONE)
114 wfd_prepare_popup(WFD_POP_FAIL_CONNECT, NULL);
118 result = wifi_direct_activate_pushbutton();
119 result = wifi_direct_accept_connection(ad->peer_mac);
120 WFD_APP_LOG(WFD_APP_LOG_LOW,
121 "wifi_direct_accept_connection(%s) result=[%d]\n",
122 ad->peer_mac, result);
123 if (result == WIFI_DIRECT_ERROR_NONE)
125 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN,
130 WFD_APP_LOG(WFD_APP_LOG_ERROR,
131 "wifi_direct_accept_connection() FAILED!!\n");
132 evas_object_hide(ad->win);
137 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error, Incorrect PIN!!\n");
138 wfd_prepare_popup(WFD_POP_INCORRECT_PIN, NULL);
144 case WFD_POP_RESP_APRV_CONNECT_NO:
146 WFD_APP_LOG(WFD_APP_LOG_HIGH,
147 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
153 case WFD_POP_RESP_PROG_CONNECT_CANCEL:
155 WFD_APP_LOG(WFD_APP_LOG_HIGH, "WFD_POP_RESP_PROG_CONNECT_CANCEL\n");
156 result = wifi_direct_disconnect(ad->peer_mac);
157 WFD_APP_LOG(WFD_APP_LOG_LOW,
158 "wifi_direct_disconnect[%s] result=[%d]\n",
159 ad->peer_mac, result);
161 if (result == WIFI_DIRECT_ERROR_NONE)
163 wfd_prepare_popup(WFD_POP_PROG_CONNECT_CANCEL, NULL);
167 WFD_APP_LOG(WFD_APP_LOG_ERROR,
168 "wifi_direct_disconnect() FAILED!!\n");
169 wfd_prepare_popup(WFD_POP_FAIL_CONNECT, NULL);
176 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown respone\n");
177 evas_object_hide(ad->win);
182 __WFD_APP_FUNC_EXIT__;
185 static Evas_Object *__create_progress_layout(Evas_Object * parent,
188 __WFD_APP_FUNC_ENTER__;
190 if (parent == NULL || text == NULL)
192 WFD_APP_LOG(WFD_APP_LOG_ERROR, "param is NULL\n");
196 Evas_Object *progressbar = NULL, *layout = NULL;
197 Evas_Object *label = NULL;
200 layout = elm_layout_add(parent);
203 WFD_APP_LOG(WFD_APP_LOG_ERROR, "layout is NULL\n");
207 elm_layout_file_set(layout, EDJ_NAME, "progress_popup");
208 evas_object_size_hint_weight_set(layout,
209 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211 progressbar = elm_progressbar_add(layout);
212 if (progressbar == NULL)
214 WFD_APP_LOG(WFD_APP_LOG_ERROR, "progressbar is NULL\n");
215 evas_object_del(layout);
218 elm_object_style_set(progressbar, "list_process");
219 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
220 evas_object_size_hint_weight_set(progressbar,
221 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
222 elm_object_part_content_set(layout, "popup_pb", progressbar);
223 elm_progressbar_pulse(progressbar, EINA_TRUE);
225 label = elm_label_add(layout);
228 WFD_APP_LOG(WFD_APP_LOG_ERROR, "label is NULL\n");
229 evas_object_del(layout);
230 evas_object_del(progressbar);
233 elm_object_style_set(label, "popup_description/default");
234 elm_object_part_content_set(layout, "popup_progress_text", label);
235 edje_object_part_geometry_get(layout, "popup_progress_text", NULL, NULL, &w,
237 elm_label_line_wrap_set(label, ELM_WRAP_WORD);
238 elm_label_wrap_width_set(label, w);
239 elm_object_text_set(label, text);
241 evas_object_show(layout);
243 __WFD_APP_FUNC_EXIT__;
249 void wfd_destroy_popup()
251 __WFD_APP_FUNC_ENTER__;
253 wfd_appdata_t *ad = wfd_get_appdata();
257 WFD_APP_LOG(WFD_APP_LOG_ERROR, "ad is NULL\n");
263 //evas_object_smart_callback_del(ad->popup, "response", __popup_resp_cb);
264 evas_object_del(ad->popup);
268 if (ad->popup_timeout_handle > 0)
270 g_source_remove(ad->popup_timeout_handle);
271 ad->popup_timeout_handle = 0;
274 evas_object_hide(ad->win);
276 __WFD_APP_FUNC_EXIT__;
280 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
282 __WFD_APP_FUNC_ENTER__;
286 popup = elm_popup_add(win);
287 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
288 elm_object_text_set(popup, pop->text);
289 elm_popup_timeout_set(popup, pop->timeout);
290 evas_object_show(popup);
291 evas_object_show(win);
293 __WFD_APP_FUNC_EXIT__;
297 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
299 __WFD_APP_FUNC_ENTER__;
301 Evas_Object *popup = NULL;
302 Evas_Object *btn = NULL;
304 popup = elm_popup_add(win);
305 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
306 elm_object_text_set(popup, pop->text);
308 btn = elm_button_add(popup);
309 elm_object_text_set(btn, pop->label1);
310 elm_object_part_content_set(popup, "button1", btn);
311 evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb,
312 (void *) pop->resp_data1);
314 evas_object_show(popup);
315 evas_object_show(win);
317 __WFD_APP_FUNC_EXIT__;
321 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
323 __WFD_APP_FUNC_ENTER__;
325 Evas_Object *popup = NULL;
326 Evas_Object *btn1 = NULL, *btn2 = NULL;
328 popup = elm_popup_add(win);
329 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330 elm_object_text_set(popup, pop->text);
332 btn1 = elm_button_add(popup);
333 elm_object_text_set(btn1, pop->label1);
334 elm_object_part_content_set(popup, "button1", btn1);
335 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
336 (void *) pop->resp_data1);
338 btn2 = elm_button_add(popup);
339 elm_object_text_set(btn2, pop->label2);
340 elm_object_part_content_set(popup, "button2", btn2);
341 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
342 (void *) pop->resp_data2);
344 evas_object_show(popup);
345 evas_object_show(win);
347 __WFD_APP_FUNC_EXIT__;
351 static Evas_Object *wfd_draw_pop_type_d(Evas_Object * win, wfd_popup_t * pop)
353 __WFD_APP_FUNC_ENTER__;
358 popup = elm_popup_add(win);
359 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360 elm_object_style_set(popup, "customstyle");
361 layout = __create_progress_layout(popup, pop->text);
362 elm_popup_timeout_set(popup, pop->timeout);
363 elm_object_content_set(popup, layout);
364 evas_object_show(popup);
365 evas_object_show(win);
367 __WFD_APP_FUNC_EXIT__;
371 static void __popup_block_clicked_cb(void *data, Evas_Object * obj,
374 wfd_appdata_t *ad = wfd_get_appdata();
375 wfd_popup_t *pop = NULL;
381 evas_object_hide(ad->win);
383 if (ad->popup_timeout_handle > 0)
385 g_source_remove(ad->popup_timeout_handle);
386 ad->popup_timeout_handle = 0;
390 gboolean __popup_remove_timeout_cb(gpointer user_data)
392 wfd_appdata_t *ad = wfd_get_appdata();
393 wfd_popup_t *pop = NULL;
400 if (pop != user_data)
404 evas_object_hide(ad->win);
406 ad->popup_timeout_handle = 0;
410 static Evas_Object *wfd_draw_pop_type_e(Evas_Object * win, wfd_popup_t * pop)
412 __WFD_APP_FUNC_ENTER__;
414 wfd_appdata_t *ad = wfd_get_appdata();
420 popup = elm_popup_add(win);
421 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
422 elm_object_text_set(popup, pop->text);
423 evas_object_smart_callback_add(popup, "block,clicked",
424 __popup_block_clicked_cb, NULL);
425 ad->popup_timeout_handle =
426 g_timeout_add(3000, __popup_remove_timeout_cb, popup);
427 evas_object_show(popup);
428 evas_object_show(win);
430 __WFD_APP_FUNC_EXIT__;
435 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
437 __WFD_APP_FUNC_ENTER__;
438 wfd_appdata_t *ad = wfd_get_appdata();
440 Ecore_IMF_Context *imf_context = NULL;
441 imf_context = (Ecore_IMF_Context *) ad->pin_entry;
443 if (NULL == imf_context)
445 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
450 elm_entry_markup_to_utf8(elm_entry_entry_get
451 ((const Evas_Object *) imf_context));
455 WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
456 strncpy(ad->pin_number, txt, sizeof(ad->pin_number));
460 WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
463 __WFD_APP_FUNC_EXIT__;
466 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
468 __WFD_APP_FUNC_ENTER__;
469 wfd_appdata_t *ad = wfd_get_appdata();
471 Evas_Object *conformant = NULL;
472 Evas_Object *layout = NULL;
473 Evas_Object *pinpopup = NULL;
474 Evas_Object *btn1 = NULL, *btn2 = NULL;
476 conformant = elm_conformant_add(win);
477 assertm_if(NULL == conformant, "conformant is NULL!!");
478 elm_win_conformant_set(win, EINA_TRUE);
479 elm_win_resize_object_add(win, conformant);
480 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND,
482 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
483 evas_object_show(conformant);
486 layout = elm_layout_add(conformant);
487 elm_object_content_set(conformant, layout);
488 pinpopup = elm_popup_add(layout);
489 assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
490 elm_object_part_text_set(pinpopup, "title,text", pop->text);
492 Evas_Object *box = elm_box_add(pinpopup);
493 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
494 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
495 evas_object_show(box);
497 Evas_Object *editfield = elm_layout_add(box);
498 elm_layout_theme_set(editfield, "layout", "editfield", "default");
499 Evas_Object *editfield_entry = elm_layout_add(box);
500 elm_object_part_content_set(editfield, "elm.swallow.content",
502 elm_object_part_text_set(editfield, "elm.text", _("Enter PIN"));
503 elm_entry_single_line_set(editfield_entry, EINA_TRUE);
504 elm_entry_scrollable_set(editfield_entry, EINA_TRUE);
505 elm_object_signal_emit(editfield_entry, "elm,state,eraser,show", "elm");
506 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND,
508 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, EVAS_HINT_FILL);
509 ad->pin_entry = editfield_entry;
510 evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb,
512 evas_object_show(editfield);
513 elm_box_pack_end(box, editfield);
515 elm_object_content_set(pinpopup, box);
517 btn1 = elm_button_add(pinpopup);
518 elm_object_text_set(pinpopup, pop->label1);
519 elm_object_part_content_set(pinpopup, "button1", btn1);
520 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
521 (void *) pop->resp_data1);
523 btn2 = elm_button_add(pinpopup);
524 elm_object_text_set(btn2, pop->label2);
525 elm_object_part_content_set(pinpopup, "button2", btn2);
526 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
527 (void *) pop->resp_data2);
529 evas_object_show(pinpopup);
530 evas_object_show(win);
531 elm_object_focus_set(ad->pin_entry, EINA_TRUE);
533 __WFD_APP_FUNC_EXIT__;
538 void wfd_prepare_popup(int type, void *userdata)
540 __WFD_APP_FUNC_ENTER__;
541 wfd_appdata_t *ad = wfd_get_appdata();
542 wfd_popup_t *pop = ad->popup_data;
546 memset(pop, 0, sizeof(wfd_popup_t));
553 case WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
555 snprintf(pop->text, sizeof(pop->text), _("IDS_WFD_POP_CONNECT_Q"),
557 snprintf(pop->label1, sizeof(pop->label1), "%s",
558 dgettext("sys_string", "IDS_COM_SK_YES"));
559 snprintf(pop->label2, sizeof(pop->label2), "%s",
560 dgettext("sys_string", "IDS_COM_SK_NO"));
561 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
562 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
564 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
568 case WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
570 char *pin = (char *) userdata;
571 snprintf(pop->text, sizeof(pop->text),
572 _("IDS_WFD_POP_CONNECT_WITH_PIN_Q"), ad->peer_name,
574 snprintf(pop->label1, sizeof(pop->label1), "%s",
575 dgettext("sys_string", "IDS_COM_SK_YES"));
576 snprintf(pop->label2, sizeof(pop->label2), "%s",
577 dgettext("sys_string", "IDS_COM_SK_NO"));
579 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_YES;
580 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
582 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
586 case WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
588 char *pin = (char *) userdata;
589 snprintf(pop->text, sizeof(pop->text), _("IDS_WFD_POP_CONNECT_Q"),
591 snprintf(pop->label1, sizeof(pop->label1), "%s",
592 dgettext("sys_string", "IDS_COM_SK_YES"));
593 snprintf(pop->label2, sizeof(pop->label2), "%s",
594 dgettext("sys_string", "IDS_COM_SK_NO"));
595 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
596 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
598 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
602 case WFD_POP_PROG_CONNECT:
604 snprintf(pop->text, sizeof(pop->text), "%s",
605 _("IDS_WFD_POP_CONNECTING"));
606 snprintf(pop->label1, sizeof(pop->label1), "%s",
607 dgettext("sys_string", "IDS_COM_POP_CANCEL"));
608 pop->timeout = WFD_POP_TIMER_120;
609 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_CANCEL;
611 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
615 case WFD_POP_PROG_CONNECT_WITH_KEYPAD:
617 snprintf(pop->text, sizeof(pop->text), "%s",
618 _("IDS_WFD_POP_ENTER_PIN"));
619 snprintf(pop->label1, sizeof(pop->label1), "%s",
620 dgettext("sys_string", "IDS_COM_SK_OK"));
621 snprintf(pop->label2, sizeof(pop->label2), "%s",
622 dgettext("sys_string", "IDS_COM_POP_CANCEL"));
623 pop->timeout = WFD_POP_TIMER_120;
624 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
625 pop->resp_data2 = WFD_POP_RESP_PROG_CONNECT_CANCEL;
627 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
631 case WFD_POP_PROG_CONNECT_WITH_PIN:
632 snprintf(pop->text, sizeof(pop->text), "%s %s",
633 _("IDS_WFD_POP_CONNECTING_WITH_PIN"), ad->pin_number);
634 snprintf(pop->label1, sizeof(pop->label1), "%s",
635 dgettext("sys_string", "IDS_COM_POP_CANCEL"));
636 pop->timeout = WFD_POP_TIMER_120;
637 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_CANCEL;
639 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
642 case WFD_POP_PROG_CONNECT_CANCEL:
644 snprintf(pop->text, sizeof(pop->text), "%s",
645 dgettext("sys_string", "IDS_COM_POP_CANCEL"));
646 pop->timeout = WFD_POP_TIMER_120;
647 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
651 case WFD_POP_INCORRECT_PIN:
652 snprintf(pop->text, sizeof(pop->text), "%s",
653 _("IDS_WFD_POP_PIN_INVALID"));
654 snprintf(pop->label1, sizeof(pop->label1), "%s",
655 dgettext("sys_string", "IDS_COM_SK_OK"));
656 pop->timeout = WFD_POP_TIMER_3;
657 pop->resp_data1 = WFD_POP_RESP_OK;
660 case WFD_POP_NOTI_CONNECTED:
661 snprintf(pop->text, sizeof(pop->text), "%s",
662 _("IDS_WFD_POP_CONNECTED"));
663 pop->timeout = WFD_POP_TIMER_3;
665 ad->popup = wfd_draw_pop_type_e(ad->win, pop);
668 case WFD_POP_FAIL_CONNECT:
669 snprintf(pop->text, sizeof(pop->text), "%s",
670 _("IDS_WFD_POP_ERROR_OCCURRED"));
671 pop->timeout = WFD_POP_TIMER_3;
673 ad->popup = wfd_draw_pop_type_e(ad->win, pop);
680 __WFD_APP_FUNC_EXIT__;