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.
21 * This file implements wifi direct system popup view functions.
23 * @file wfd-app-popup-view.c
24 * @author Sungsik Jang (sungsik.jang@samsung.com)
31 #include <Elementary.h>
32 #include <efl-assist/efl_assist.h>
34 #include <X11/Xatom.h>
35 #include <X11/Xutil.h>
38 #include <notification.h>
40 #include <wifi-direct.h>
43 #include "wfd-app-strings.h"
44 #include "wfd-app-util.h"
45 #include "wfd-app-popup-view.h"
47 extern wfd_appdata_t *g_wfd_ad;
48 extern wfd_popup_t *g_wfd_pop;
49 extern unsigned char g_wfd_peer_mac[6];
50 extern unsigned char g_wfd_peer_name[32];
51 static Ecore_Timer *pb_timer = NULL;
52 static Ecore_Timer *keypad_popup_timer = NULL;
53 static int keypad_popup_timeout = 0;
55 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2);
57 static void mouseup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
59 Evas_Event_Mouse_Up *ev = event_info;
60 if (ev->button == 3) {
65 /*static void keydown_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
67 Evas_Event_Key_Down *ev = event_info;
68 if (!strcmp(ev->keyname, KEY_BACK)) {
72 static Eina_Bool __rotate(void *data, int type, void *event)
74 __WFD_APP_FUNC_ENTER__;
75 wfd_appdata_t *ad = (wfd_appdata_t *)data;
76 Ecore_X_Event_Client_Message *ev = event;
77 int rots[4] = {0, 90, 180, 270};
79 if (ad == NULL || ad->win == NULL) {
80 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Parameter NULL");
84 if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE) {
85 WFD_APP_LOG(WFD_APP_LOG_LOW, "ev->message_type: [%d]\n", ev->message_type);
86 elm_win_wm_rotation_available_rotations_set(ad->win, rots, 1);
89 __WFD_APP_FUNC_EXIT__;
94 * This function let the ug make a callback for click the button in popup
96 * @param[in] data the pointer to the main data structure
97 * @param[in] obj the pointer to the evas object
98 * @param[in] event_info the pointer to the event information
100 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
102 __WFD_APP_FUNC_ENTER__;
103 wfd_appdata_t *ad = wfd_get_appdata();
104 wfd_connection_info_s *connection = ad->connection;
106 int resp = (int) data;
107 char msg[WFD_POP_STR_MAX_LEN] = {0};
109 WFD_APP_LOG(WFD_APP_LOG_HIGH, "popup resp : %d\n", resp);
111 if (ad->rotate_event_handler) {
112 ecore_event_handler_del(ad->rotate_event_handler);
113 ad->rotate_event_handler = NULL;
117 case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
119 WFD_APP_LOG(WFD_APP_LOG_HIGH,
120 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
123 result = wifi_direct_accept_connection(connection->peer_addr);
124 if (result != WIFI_DIRECT_ERROR_NONE) {
125 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
126 evas_object_hide(ad->win);
128 /* tickernoti popup */
129 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
130 connection->peer_name);
131 notification_status_message_post(msg);
133 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to accept connection");
137 case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
139 WFD_APP_LOG(WFD_APP_LOG_HIGH,
140 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
143 result = wifi_direct_accept_connection(connection->peer_addr);
144 if (result == WIFI_DIRECT_ERROR_NONE) {
145 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
147 WFD_APP_LOG(WFD_APP_LOG_LOW,
148 "wifi_direct_accept_connection() failed. result=[%d]\n", result);
149 /* tickernoti popup */
150 notification_status_message_post(_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"));
155 case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
158 WFD_APP_LOG(WFD_APP_LOG_HIGH,
159 "WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");
163 int len = strlen(connection->wps_pin);
164 WFD_APP_LOGSECURE(WFD_APP_LOG_LOW, "PIN [%s]", connection->wps_pin);
166 if (len < 8 || len > 64) {
167 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error, Incorrect PIN!!\n");
168 keypad_popup_timeout--;
169 /* tickernoti popup */
170 notification_status_message_post(_("IDS_COM_BODY_PINS_DO_NOT_MATCH"));
172 /* redraw the popup */
173 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
176 keypad_popup_timeout = 0;
178 result = wifi_direct_set_wps_pin(connection->wps_pin);
179 if (result != WIFI_DIRECT_ERROR_NONE) {
180 /* tickernoti popup */
181 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
182 connection->peer_name);
183 notification_status_message_post(msg);
187 result = wifi_direct_accept_connection(connection->peer_addr);
188 if (result != WIFI_DIRECT_ERROR_NONE) {
189 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
190 evas_object_hide(ad->win);
192 /* tickernoti popup */
193 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
194 connection->peer_name);
195 notification_status_message_post(msg);
197 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with [%s]", connection->peer_addr);
201 case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
203 WFD_APP_LOG(WFD_APP_LOG_HIGH,
204 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
207 ecore_timer_del(pb_timer);
211 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
215 case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
217 WFD_APP_LOG(WFD_APP_LOG_HIGH,
218 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
220 if (connection->peer_addr[0] != '\0') {
221 result = wifi_direct_reject_connection(connection->peer_addr);
222 if (result != WIFI_DIRECT_ERROR_NONE)
223 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
225 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Peer's address is Zero MAC");
229 ecore_timer_del(pb_timer);
234 keypad_popup_timeout = 0;
240 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown respone\n");
246 __WFD_APP_FUNC_EXIT__;
250 * This function let the app destroy the popup
254 void wfd_destroy_popup()
256 __WFD_APP_FUNC_ENTER__;
257 wfd_appdata_t *ad = wfd_get_appdata();
260 WFD_APP_LOG(WFD_APP_LOG_ERROR, "ad is NULL\n");
264 if (keypad_popup_timer) {
265 ecore_timer_del(keypad_popup_timer);
266 keypad_popup_timer = NULL;
270 evas_object_del(ad->popup);
274 if (ad->popup_timeout_handle > 0) {
275 g_source_remove(ad->popup_timeout_handle);
276 ad->popup_timeout_handle = 0;
280 evas_object_hide(ad->win);
284 ecore_timer_del(pb_timer);
287 __WFD_APP_FUNC_EXIT__;
291 static int __get_window_property(Display *dpy, Window win, Atom atom,
292 Atom type, unsigned int *val, unsigned int len)
294 __WFD_APP_FUNC_ENTER__;
295 unsigned char *prop_ret = NULL;
297 unsigned long bytes_after = 0;
298 unsigned long num_ret = -1;
304 if (XGetWindowProperty(dpy, win, atom, 0, 0x7fffffff, False,
305 type, &type_ret, &format_ret, &num_ret,
306 &bytes_after, &prop_ret) != Success) {
310 if (type_ret != type || format_ret != 32) {
312 } else if (num_ret == 0 || !prop_ret) {
318 for (i = 0; i < len; i++) {
319 val[i] = ((unsigned long *)prop_ret)[i];
328 __WFD_APP_FUNC_EXIT__;
332 static int __x_rotation_get(Display *dpy, void* win)
334 __WFD_APP_FUNC_ENTER__;
335 Window active_win = 0;
340 Atom atom_active_win;
341 Atom atom_win_rotate_angle;
343 root_win = XDefaultRootWindow(dpy);
345 atom_active_win = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
346 ret = __get_window_property(dpy, root_win, atom_active_win,
347 XA_WINDOW, (unsigned int *)&active_win, 1);
353 atom_win_rotate_angle =
354 XInternAtom(dpy, "_E_ILLUME_ROTATE_WINDOW_ANGLE", False);
355 ret = __get_window_property(dpy, active_win ,
356 atom_win_rotate_angle, XA_CARDINAL,
357 (unsigned int *)&rotation, 1);
359 __WFD_APP_FUNC_EXIT__;
367 void __set_parent_rotate_angle(wfd_appdata_t *ad)
369 __WFD_APP_FUNC_ENTER__;
371 int rotate_angle = 0;
373 int rots2[4] = {0, 90, 180, 270};
375 if (ad == NULL || ad->win == NULL) {
376 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Parameter NULL");
380 rotate_angle = __x_rotation_get(ecore_x_display_get(), NULL);
381 WFD_APP_LOG(WFD_APP_LOG_LOW, "rotate_angle: [%d]\n", rotate_angle);
383 if (rotate_angle < 0) {
387 if (rotate_angle == 0) {
388 elm_win_wm_rotation_available_rotations_set(ad->win, rots1, 1);
390 elm_win_wm_rotation_available_rotations_set(ad->win, rots2, 1);
393 __WFD_APP_FUNC_EXIT__;
398 * This function let the app create a popup which includes no button
400 * @param[in] win the window object
401 * @param[in] pop the pointer to the prepared popup
403 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
405 __WFD_APP_FUNC_ENTER__;
407 wfd_appdata_t *ad = wfd_get_appdata();
410 popup = elm_popup_add(win);
411 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
412 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, NULL);
413 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
414 // evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
415 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
416 elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
417 elm_popup_timeout_set(popup, pop->timeout);
418 __set_parent_rotate_angle(ad);
419 evas_object_show(popup);
420 evas_object_show(win);
421 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __rotate, ad);
423 __WFD_APP_FUNC_EXIT__;
428 * This function let the app create a popup which includes one button
430 * @param[in] win the window object
431 * @param[in] pop the pointer to the prepared popup
433 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
435 __WFD_APP_FUNC_ENTER__;
436 Evas_Object *popup = NULL;
437 Evas_Object *btn = NULL;
438 wfd_appdata_t *ad = wfd_get_appdata();
440 popup = elm_popup_add(win);
441 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
442 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data1);
443 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
444 // evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
445 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
446 elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
448 btn = elm_button_add(popup);
449 elm_object_style_set(btn, "popup");
450 elm_object_domain_translatable_text_set(btn, PACKAGE, pop->label1);
451 elm_object_part_content_set(popup, "button1", btn);
452 evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) pop->resp_data1);
454 __set_parent_rotate_angle(ad);
455 evas_object_show(popup);
456 evas_object_show(win);
457 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __rotate, ad);
459 __WFD_APP_FUNC_EXIT__;
464 * This function let the app create a popup which includes two buttons
466 * @param[in] win the window object
467 * @param[in] pop the pointer to the prepared popup
469 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
471 __WFD_APP_FUNC_ENTER__;
472 Evas_Object *popup = NULL;
473 Evas_Object *btn1 = NULL, *btn2 = NULL;
474 wfd_appdata_t *ad = wfd_get_appdata();
476 popup = elm_popup_add(win);
477 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
478 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
479 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
480 // evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
481 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
482 elm_object_domain_translatable_part_text_set(popup, "title,text",
483 PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
484 elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
486 btn1 = elm_button_add(popup);
487 elm_object_style_set(btn1, "popup");
488 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
489 elm_object_part_content_set(popup, "button1", btn1);
490 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
491 (void *) pop->resp_data2);
493 btn2 = elm_button_add(popup);
494 elm_object_style_set(btn2, "popup");
495 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
496 elm_object_part_content_set(popup, "button2", btn2);
497 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
498 (void *) pop->resp_data1);
500 __set_parent_rotate_angle(ad);
502 evas_object_show(popup);
503 evas_object_show(win);
504 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __rotate, ad);
506 __WFD_APP_FUNC_EXIT__;
510 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
512 __WFD_APP_FUNC_ENTER__;
513 wfd_appdata_t *ad = wfd_get_appdata();
516 evas_object_del(ad->popup);
520 if (ad->rotate_event_handler) {
521 ecore_event_handler_del(ad->rotate_event_handler);
522 ad->rotate_event_handler = NULL;
526 evas_object_hide(ad->win);
529 __WFD_APP_FUNC_EXIT__;
532 Evas_Object *wfd_draw_pop_type_auto_deactivation(Evas_Object *win, void *userdata)
534 __WFD_APP_FUNC_ENTER__;
536 Evas_Object *popup = NULL;
537 Evas_Object *btn = NULL;
538 char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
539 wfd_appdata_t *ad = wfd_get_appdata();
541 popup = elm_popup_add(win);
542 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
543 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, _wfd_ug_automatic_turn_off_popup_cb, userdata);
544 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
545 // evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
546 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
547 elm_object_domain_translatable_part_text_set(popup, "title,text",
548 PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
549 snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
550 "IDS_WIFI_POP_THERE_HAS_BEEN_NO_ACTIVITY_FOR_PD_MINUTES_SINCE_WI_FI_DIRECT_WAS_ENABLED_MSG", 5);
551 elm_object_domain_translatable_text_set(popup, PACKAGE, popup_text);
553 btn = elm_button_add(popup);
554 elm_object_style_set(btn, "popup");
555 elm_object_domain_translatable_text_set(btn, PACKAGE, "IDS_BR_SK_OK");
556 elm_object_part_content_set(popup, "button1", btn);
557 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, userdata);
559 __set_parent_rotate_angle(ad);
560 evas_object_show(popup);
561 evas_object_show(win);
562 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __rotate, ad);
564 __WFD_APP_FUNC_EXIT__;
569 * This function let the ug make a change callback for password input
571 * @param[in] data the pointer to the main data structure
572 * @param[in] obj the pointer to the evas object
573 * @param[in] event_info the pointer to the event information
575 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
577 __WFD_APP_FUNC_ENTER__;
578 wfd_appdata_t *ad = wfd_get_appdata();
579 wfd_connection_info_s *connection = ad->connection;
581 Ecore_IMF_Context *imf_context = NULL;
582 imf_context = (Ecore_IMF_Context *) ad->pin_entry;
584 if (NULL == imf_context) {
585 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
589 char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
591 WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
592 strncpy(connection->wps_pin, txt, sizeof(connection->wps_pin) - 1);
593 WFD_IF_FREE_MEM(txt);
595 WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
598 __WFD_APP_FUNC_EXIT__;
602 * This function let the app make a callback for progressbar timer
603 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
604 * @param[in] data the pointer to the wps structure
606 static Eina_Bool _fn_pb_timer(void *data)
610 char time_label[32] = {0};
611 wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
613 if (NULL == wps_display_popup) {
614 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Param is NULL.\n");
615 return ECORE_CALLBACK_CANCEL;
618 Evas_Object *progressbar = NULL;
619 Evas_Object *time = NULL;
621 progressbar = wps_display_popup->progressbar;
622 time = wps_display_popup->time;
623 value = elm_progressbar_value_get(progressbar);
625 wps_display_popup->step++;
626 step = wps_display_popup->step;
627 value = ((double)step) / WFD_POP_TIMER_120;
630 WFD_APP_LOG(WFD_APP_LOG_LOW, "Progress end.\n");
632 ecore_timer_del(pb_timer);
636 return ECORE_CALLBACK_CANCEL;
639 elm_progressbar_value_set(progressbar, value);
640 WFD_APP_LOG(WFD_APP_LOG_LOW, "step: %d, value: %f\n", wps_display_popup->step, value);
642 /* show the time label */
645 snprintf(time_label, 32, "00:0%d", step);
647 snprintf(time_label, 32, "00:%d", step);
651 snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
653 snprintf(time_label, 32, "0%d:%d", step/60, step%60);
657 char *remaining_time_str = g_strdup_printf(
658 "<font_size=40><align=center>%s</align></font_size>", time_label);
659 elm_object_text_set(time, remaining_time_str);
660 g_free(remaining_time_str);
662 return ECORE_CALLBACK_RENEW;
665 static Eina_Bool _keypad_popup_timer_cb(void *data)
667 __WFD_APP_FUNC_ENTER__;
669 char msg1[WFD_POP_STR_MAX_LEN] = {0};
670 char msg2[WFD_POP_STR_MAX_LEN] = {0};
672 Evas_Object *label = (Evas_Object*) data;
673 wfd_appdata_t *ad = wfd_get_appdata();
674 wfd_connection_info_s *connection = ad->connection;
675 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters(ad)\n");
676 WFD_RETV_IF(NULL == label, FALSE, "NULL parameters(label)\n");
677 if (NULL == ad->popup) {
678 keypad_popup_timeout = 0;
679 return ECORE_CALLBACK_CANCEL;
682 keypad_popup_timeout --;
684 if (keypad_popup_timeout > 0) {
685 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
686 _("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
687 connection->peer_name, keypad_popup_timeout);
690 snprintf(msg2, sizeof(msg2), _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
691 connection->peer_name);
693 elm_object_domain_translatable_text_set(label, PACKAGE, msg1);
697 if (keypad_popup_timeout <= 0) {
699 keypad_popup_timeout = 0;
700 __WFD_APP_FUNC_EXIT__;
701 return ECORE_CALLBACK_CANCEL;
704 __WFD_APP_FUNC_EXIT__;
705 return ECORE_CALLBACK_RENEW;
708 /* This callback is for showing(hiding) X marked button. */
709 /*static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
711 if (elm_object_focus_get(obj)) {
712 if (elm_entry_is_empty(obj))
713 elm_object_signal_emit(data, "elm,state,eraser,hide", "");
715 elm_object_signal_emit(data, "elm,state,eraser,show", "");
719 /* Focused callback will show X marked button and hide guidetext. */
720 /*static void _focused_cb(void *data, Evas_Object *obj, void *event_info)
722 if (!elm_entry_is_empty(obj))
723 elm_object_signal_emit(data, "elm,state,eraser,show", "");
724 elm_object_signal_emit(data, "elm,state,rename,hide", "");
727 /* Unfocused callback will show guidetext and hide X marked button. */
728 /*static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info)
730 elm_object_signal_emit(data, "elm,state,eraser,hide", "");
731 elm_object_signal_emit(data, "elm,state,rename,show", "");
734 /* When X marked button clicked, make string as empty. */
735 /*static void _eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
737 elm_object_focus_set(data, EINA_TRUE);
738 elm_entry_entry_set(data, "");
742 * This function let the app create a edit filed
744 * @param[in] parent the parent object
745 * @param[in] title the pointer to the title of edit field
746 * @param[in] guide the pointer to the text of guide
747 * @param[in] single_line whether it can support single line
748 * @param[in] is_editable whether it is avaliable to edit
750 /*static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
752 assertm_if(NULL == parent, "parent is NULL!!");
754 Evas_Object *layout = elm_layout_add(parent);
755 assertm_if(NULL == layout, "layout is NULL!!");
757 if (title && title[0] != '\0') {
758 elm_layout_theme_set(layout, "layout", "dialogue/editfield/title", "default");
759 elm_object_part_text_set(layout, "elm.text", title);
761 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "default");
764 Evas_Object *entry = elm_entry_add(layout);
765 assertm_if(NULL == entry, "entry is NULL!!");
767 if (guide && guide[0] != '\0') {
768 elm_object_part_text_set(layout, "elm.guidetext", guide);
771 evas_object_smart_callback_add(entry, "changed", _changed_cb, layout);
772 evas_object_smart_callback_add(entry, "focused", _focused_cb, layout);
773 evas_object_smart_callback_add(entry, "unfocused", _unfocused_cb, layout);
775 elm_object_part_content_set(layout, "elm.icon.entry", entry);
776 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
777 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
779 elm_entry_single_line_set(entry, single_line);
780 elm_entry_scrollable_set(entry, single_line);
782 Evas_Object *button = elm_button_add(parent);
783 elm_object_style_set(button, "editfield_clear");
784 elm_object_part_content_set(layout, "elm.icon.eraser", button);
785 evas_object_smart_callback_add(button, "clicked", _eraser_btn_clicked_cb, entry);
790 * This function let the app create a display popup
791 * @return display popup
792 * @param[in] win the window object
793 * @param[in] pop the pointer to the prepared popup
795 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
797 __WFD_APP_FUNC_ENTER__;
798 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_draw_pop_type_display\n");
800 Evas_Object *popup = NULL;
801 Evas_Object *progressbar = NULL;
802 Evas_Object *time = NULL;
804 static wfd_wps_display_popup_t wps_display_popup;
805 wfd_appdata_t *ad = wfd_get_appdata();
807 popup = elm_popup_add(win);
808 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
809 evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
810 // evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
811 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
812 elm_object_domain_translatable_part_text_set(popup, "title,text",
813 PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
815 layout = elm_layout_add(popup);
816 if (layout == NULL) {
817 WFD_APP_LOG(WFD_APP_LOG_LOW, "Layout failed so returning !!");
821 elm_layout_file_set(layout, WFD_EDJ_POPUP_PATH, "popup_wps_pin_layout");
822 elm_object_domain_translatable_part_text_set(layout, "elm.text.description",
824 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
826 /* add progressbar */
827 progressbar = elm_progressbar_add(layout);
828 elm_object_style_set(progressbar, "list_progress");
829 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
830 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
831 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
832 elm_progressbar_value_set(progressbar, 0.0);
833 evas_object_show(progressbar);
836 time = elm_label_add(layout);
837 elm_object_style_set(time, "label3");
838 elm_label_line_wrap_set(time, ELM_WRAP_MIXED);
839 elm_object_text_set(time, _("<font_size=40><align=center>00:00</align></font_size>"));
840 evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
841 evas_object_size_hint_align_set(time, EVAS_HINT_FILL, EVAS_HINT_FILL);
842 evas_object_show(time);
844 elm_object_part_content_set(layout, "slider", progressbar);
845 elm_object_part_content_set(layout, "timer_label", time);
848 /* start progressbar timer */
849 wps_display_popup.step = 0;
850 wps_display_popup.progressbar = progressbar;
851 wps_display_popup.time = time;
852 pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
855 if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
856 Evas_Object *btn2 = NULL;
857 btn2 = elm_button_add(popup);
858 elm_object_style_set(btn2, "popup");
859 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label2);
860 elm_object_part_content_set(popup, "button1", btn2);
861 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
862 (void *) pop->resp_data2);
863 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
866 if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES || pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_PBC_YES ) {
867 Evas_Object *btn1 = NULL;
868 btn1 = elm_button_add(popup);
869 elm_object_style_set(btn1, "popup");
870 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label1);
871 elm_object_part_content_set(popup, "button2", btn1);
872 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
873 (void *) pop->resp_data1);
874 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data1);
877 elm_object_content_set(popup, layout);
878 __set_parent_rotate_angle(ad);
879 evas_object_show(popup);
880 evas_object_show(win);
881 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, __rotate, ad);
883 __WFD_APP_FUNC_EXIT__;
887 static void __popup_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
889 __WFD_APP_FUNC_ENTER__;
890 elm_entry_entry_set(data, "");
891 __WFD_APP_FUNC_EXIT__;
894 static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
896 __WFD_APP_FUNC_ENTER__;
897 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
898 if (elm_object_focus_get(obj)) {
899 if (elm_entry_is_empty(obj))
900 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
902 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
905 __WFD_APP_FUNC_EXIT__;
908 static void _entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
910 __WFD_APP_FUNC_ENTER__;
912 if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
913 if (!elm_entry_is_empty(obj))
914 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
916 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
918 elm_object_signal_emit(obj, "elm,state,focus,on", "");
919 __WFD_APP_FUNC_EXIT__;
922 static void _entry_keydown_cb(void *data, Evas *e, Evas_Object *obj,
925 __WFD_APP_FUNC_ENTER__;
927 Evas_Event_Key_Down *ev;
928 Evas_Object *entry = obj;
930 WFD_RET_IF(data == NULL, "Incorrect parameter data(NULL)\n");
931 WFD_RET_IF(event_info == NULL, "Incorrect parameter event_info(NULL)\n");
932 WFD_RET_IF(entry == NULL, "Incorrect parameter entry(NULL)\n");
934 ev = (Evas_Event_Key_Down *)event_info;
936 if (g_strcmp0(ev->key, "KP_Enter") == 0 || g_strcmp0(ev->key, "Return") == 0) {
937 Ecore_IMF_Context *imf_context;
939 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
941 ecore_imf_context_input_panel_hide(imf_context);
944 elm_object_focus_set(entry, EINA_FALSE);
948 static char *__wfd_main_desc_label_get(void *data, Evas_Object *obj,
951 __WFD_APP_FUNC_ENTER__;
952 if (obj == NULL || part == NULL) {
955 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_rename desc\n");
956 char msg1[WFD_POP_STR_MAX_LEN] = {0, };
957 char msg2[WFD_POP_STR_MAX_LEN] = {0, };
958 wfd_appdata_t *ad = wfd_get_appdata();
959 WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
960 wfd_connection_info_s *connection = ad->connection;
961 WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
963 if (!g_strcmp0(part, "elm.text.multiline")) {
964 if (keypad_popup_timeout > 0) {
965 ad->timeout = keypad_popup_timeout;
967 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
968 _("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
969 connection->peer_name, ad->timeout);
972 snprintf(msg2, sizeof(msg2),
973 _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
974 connection->peer_name);
976 WFD_APP_LOG(WFD_APP_LOG_LOW, "string %s", msg1);
977 __WFD_APP_FUNC_EXIT__;
978 return g_strdup(msg1);
980 __WFD_APP_FUNC_EXIT__;
984 static Evas_Object *__wfd_pin_entry_icon_get(void *data, Evas_Object *obj,
987 __WFD_APP_FUNC_ENTER__;
988 if (obj == NULL || part == NULL) {
991 wfd_appdata_t *ad = wfd_get_appdata();
992 WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
993 Evas_Object *entry = NULL;
994 Evas_Object *button = NULL;
995 Ecore_IMF_Context *imf_context;
996 if (g_strcmp0(part, "elm.icon.entry")) {
997 __WFD_APP_FUNC_EXIT__;
1000 static Elm_Entry_Filter_Accept_Set accept_set = {"0123456789", NULL};
1001 entry = ea_editfield_add(obj, EA_EDITFIELD_SCROLL_SINGLELINE_PASSWORD);
1002 ea_entry_selection_back_event_allow_set(entry, EINA_TRUE);
1003 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1004 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1005 elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
1006 elm_entry_password_set(entry, EINA_TRUE);
1007 elm_entry_prediction_allow_set(entry, EINA_FALSE);
1009 elm_entry_markup_filter_append(entry,
1010 elm_entry_filter_accept_set,&accept_set);
1011 elm_entry_input_panel_layout_set(entry,
1012 ELM_INPUT_PANEL_LAYOUT_DATETIME);
1013 elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
1014 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
1015 PACKAGE, _("IDS_WIFI_POP_PIN"));
1016 elm_entry_input_panel_return_key_autoenabled_set(entry,EINA_TRUE);
1017 elm_entry_input_panel_return_key_type_set(entry,
1018 ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
1020 ad->pin_entry = entry;
1021 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
1023 ecore_imf_context_input_panel_return_key_type_set(imf_context,
1024 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
1027 button = elm_button_add(obj);
1028 elm_object_style_set(button, "search_clear");
1029 elm_object_focus_allow_set(button, EINA_FALSE);
1030 elm_object_part_content_set(entry, "elm.swallow.clear", button);
1031 evas_object_smart_callback_add(button, "clicked",
1032 __popup_eraser_clicked_cb, entry);
1034 elm_object_signal_emit (entry, "elm,action,hide,search_icon", "");
1035 evas_object_smart_callback_add(entry, "changed",
1036 _entry_changed_cb, NULL);
1037 evas_object_smart_callback_add(entry, "preedit,changed",
1038 _entry_changed_cb, NULL);
1039 evas_object_smart_callback_add(entry, "focused",
1040 _entry_focused_cb, NULL);
1041 evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
1042 _entry_keydown_cb, ad);
1044 elm_object_content_set(obj,entry);
1045 evas_object_show(entry);
1046 evas_object_smart_callback_add(entry, "changed", _smart_ime_cb, NULL);
1047 elm_object_focus_set(entry, EINA_TRUE);
1048 __WFD_APP_FUNC_EXIT__;
1052 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
1054 __WFD_APP_FUNC_ENTER__;
1055 if (obj == NULL || data == NULL) {
1058 Eina_Bool state = elm_check_state_get(obj);
1060 elm_entry_password_set((Evas_Object *)data, EINA_FALSE);
1062 elm_entry_password_set((Evas_Object *)data, EINA_TRUE);
1064 __WFD_APP_FUNC_EXIT__;
1067 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
1069 __WFD_APP_FUNC_ENTER__;
1070 Elm_Object_Item *item = NULL;
1071 item = (Elm_Object_Item *)ei;
1075 wfd_appdata_t *ad = wfd_get_appdata();
1077 WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter(NULL)\n");
1080 Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.left");
1081 elm_genlist_item_selected_set(item, EINA_FALSE);
1082 Eina_Bool state = elm_check_state_get(ck);
1083 elm_check_state_set(ck, !state);
1085 _chk_changed_cb(ad->pin_entry, ck, NULL);
1087 __WFD_APP_FUNC_EXIT__;
1090 static char *__wfd_password_label(void *data, Evas_Object *obj, const char *part)
1092 __WFD_APP_FUNC_ENTER__;
1094 if (data == NULL || part == NULL) {
1097 WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
1099 if (!g_strcmp0(part, "elm.text.main.right")) {
1100 __WFD_APP_FUNC_EXIT__;
1101 return g_strdup(" Show password");
1103 __WFD_APP_FUNC_EXIT__;
1107 static Evas_Object *__wfd_password_check(void *data, Evas_Object *obj,
1110 __WFD_APP_FUNC_ENTER__;
1111 if (obj == NULL || part == NULL) {
1114 wfd_appdata_t *ad = wfd_get_appdata();
1115 WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1116 Evas_Object *check = NULL;
1118 WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
1120 if (!g_strcmp0(part, "elm.icon.left")) {
1121 check = elm_check_add(obj);
1122 evas_object_propagate_events_set(check, EINA_FALSE);
1123 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
1124 evas_object_size_hint_weight_set(check,
1125 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1126 evas_object_smart_callback_add(check, "changed",
1127 _chk_changed_cb, ad->pin_entry);
1128 elm_object_focus_allow_set(check, EINA_FALSE);
1129 __WFD_APP_FUNC_EXIT__;
1132 __WFD_APP_FUNC_EXIT__;
1138 * This function let the app create a keypad popup
1139 * @return keypad popup
1140 * @param[in] win the window object
1141 * @param[in] pop the pointer to the prepared popup
1143 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
1145 __WFD_APP_FUNC_ENTER__;
1146 wfd_appdata_t *ad = wfd_get_appdata();
1147 WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1148 wfd_connection_info_s *connection = ad->connection;
1149 WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
1151 Evas_Object *pinpopup = NULL;
1152 Evas_Object *btn1 = NULL, *btn2 = NULL;
1153 Evas_Object *genlist = NULL;
1154 Elm_Object_Item *git = NULL;
1156 ad->timeout = pop->timeout;
1158 pinpopup = elm_popup_add(ad->layout);
1159 elm_popup_align_set(pinpopup, ELM_NOTIFY_ALIGN_FILL, 1.0);
1160 ea_object_event_callback_add(pinpopup, EA_CALLBACK_BACK, ea_popup_back_cb,
1162 evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1163 elm_object_domain_translatable_part_text_set(pinpopup, "title,text",
1164 PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
1166 genlist = elm_genlist_add(pinpopup);
1167 elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1168 evas_object_size_hint_weight_set(genlist,
1169 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1170 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1171 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1172 elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
1174 /* Entry genlist item */
1175 ad->pin_desc_itc = elm_genlist_item_class_new();
1176 WFD_RETV_IF(ad->pin_desc_itc == NULL, NULL, "pin_desc_itc is NULL\n");
1177 ad->pin_desc_itc->item_style = "multiline_main";
1178 ad->pin_desc_itc->func.text_get = __wfd_main_desc_label_get;
1179 ad->pin_desc_itc->func.content_get = NULL;
1180 ad->pin_desc_itc->func.state_get = NULL;
1181 ad->pin_desc_itc->func.del = NULL;
1183 git = elm_genlist_item_append(genlist, ad->pin_desc_itc, ad, NULL,
1184 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1186 elm_genlist_item_select_mode_set(git,
1187 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1189 ad->pin_entry_itc = elm_genlist_item_class_new();
1190 WFD_RETV_IF(ad->pin_entry_itc == NULL, NULL, "pin_entry_itc is NULL\n");
1191 ad->pin_entry_itc->item_style = "entry";
1192 ad->pin_entry_itc->func.text_get = NULL;
1193 ad->pin_entry_itc->func.content_get = __wfd_pin_entry_icon_get;
1194 ad->pin_entry_itc->func.state_get = NULL;
1195 ad->pin_entry_itc->func.del = NULL;
1197 elm_genlist_item_append(genlist, ad->pin_entry_itc, pinpopup,
1198 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1200 keypad_popup_timeout = pop->timeout;
1201 keypad_popup_timer = ecore_timer_add(1, _keypad_popup_timer_cb,
1204 ad->paswd_itc = elm_genlist_item_class_new();
1205 WFD_RETV_IF(ad->paswd_itc == NULL, NULL, "paswd_itc is NULL\n");
1206 ad->paswd_itc->item_style = "1line";
1207 ad->paswd_itc->func.text_get = __wfd_password_label;
1208 ad->paswd_itc->func.content_get = __wfd_password_check;
1209 ad->paswd_itc->func.state_get = NULL;
1210 ad->paswd_itc->func.del = NULL;
1212 elm_genlist_item_append(genlist, ad->paswd_itc, pinpopup,
1213 NULL, ELM_GENLIST_ITEM_NONE, _gl_pswd_check_box_sel, (void *)ad );
1215 btn1 = elm_button_add(pinpopup);
1216 elm_object_style_set(btn1, "popup");
1217 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
1218 elm_object_part_content_set(pinpopup, "button1", btn1);
1219 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
1220 (void *)pop->resp_data2);
1222 btn2 = elm_button_add(pinpopup);
1223 elm_object_style_set(btn2, "popup");
1224 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
1225 elm_object_part_content_set(pinpopup, "button2", btn2);
1226 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
1227 (void *)pop->resp_data1);
1229 elm_genlist_realization_mode_set(genlist, EINA_TRUE);
1230 evas_object_show(genlist);
1231 elm_object_content_set(pinpopup, genlist);
1233 __set_parent_rotate_angle(ad);
1234 evas_object_show(pinpopup);
1235 evas_object_show(win);
1236 elm_object_focus_set(ad->pin_entry, EINA_TRUE);
1237 ad->rotate_event_handler = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
1240 __WFD_APP_FUNC_EXIT__;
1245 void _replace_int(char *haystack, int size, char *niddle, int value)
1247 __WFD_APP_FUNC_ENTER__;
1252 if (haystack == NULL || niddle == NULL || size <= 1)
1255 buf = g_strdup(haystack);
1256 p = strstr(buf, niddle);
1261 q = p + strlen(niddle);
1264 snprintf(haystack, size-1, "%s%d%s", buf, value, q);
1266 __WFD_APP_FUNC_EXIT__;
1269 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2)
1271 __WFD_APP_FUNC_ENTER__;
1272 char text[WFD_POP_STR_MAX_LEN] = {0, };
1274 strncpy(text, format_str, WFD_POP_STR_MAX_LEN-1);
1275 _replace_int(text, WFD_POP_STR_MAX_LEN, "%d", PD_2);
1276 _replace_int(text, WFD_POP_STR_MAX_LEN, "%2$d", PD_2);
1277 snprintf(buf, buf_len-1, text, SD_1);
1278 __WFD_APP_FUNC_EXIT__;
1283 * This function let the app create a popup
1285 * @param[in] type the type of popup
1286 * @param[in] userdata the pointer to the data which will be used
1288 void wfd_prepare_popup(int type, void *user_data)
1290 __WFD_APP_FUNC_ENTER__;
1291 wfd_appdata_t *ad = wfd_get_appdata();
1292 wfd_popup_t *pop = ad->popup_data;
1293 wfd_connection_info_s *connection = ad->connection;
1294 char text[WFD_POP_STR_MAX_LEN+1] = {0, };
1295 char text1[WFD_POP_STR_MAX_LEN+1] = {0, };
1296 wfd_destroy_popup();
1298 peer_name = elm_entry_utf8_to_markup(connection->peer_name);
1300 memset(pop, 0, sizeof(wfd_popup_t));
1304 switch (pop->type) {
1305 case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
1307 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1308 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1309 peer_name, WFD_POP_TIMER_120);
1311 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_SK2_OK"));
1312 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_WIFI_SK_CANCEL"));
1313 pop->timeout = WFD_POP_TIMER_120;
1314 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
1315 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1317 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1320 case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
1321 snprintf(pop->text, sizeof(pop->text),
1322 _("IDS_WIFI_BODY_PS_IS_REQUESTING_A_WI_FI_DIRECT_CONNECTION_ALLOW_Q"),
1324 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_BUTTON_ALLOW"));
1325 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1326 pop->timeout = WFD_POP_TIMER_120;
1327 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
1328 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1330 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
1333 case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
1334 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1335 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1336 peer_name, WFD_POP_TIMER_120);
1337 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_BR_SK_OK"));
1338 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1339 pop->timeout = WFD_POP_TIMER_120;
1340 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
1341 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1343 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1346 case /* MT */ WFD_POP_PROG_CONNECT:
1347 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WIFI_BODY_CONNECTING_ING"));
1348 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_BR_SK_CANCEL"));
1349 pop->timeout = WFD_POP_TIMER_120;
1350 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
1352 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
1355 case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
1356 _replace_1PS_2PD((char *)text, sizeof(text),
1357 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1358 peer_name, WFD_POP_TIMER_120);
1360 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s",
1361 text, _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"));
1363 snprintf(pop->text, sizeof(pop->text), text1, connection->peer_name);
1365 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_SK_CONNECT"));
1366 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1367 pop->timeout = WFD_POP_TIMER_120;
1368 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
1369 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1371 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
1374 case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
1375 _replace_1PS_2PD((char *)text, sizeof(text),
1376 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1377 peer_name, WFD_POP_TIMER_120);
1379 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s %s",
1382 _("IDS_WIFI_POP_PIN_CODE_PS"));
1383 snprintf(pop->text, sizeof(pop->text), text1, connection->wps_pin);
1385 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1386 pop->timeout = WFD_POP_TIMER_120;
1387 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1389 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1392 case WFD_POP_PROG_CONNECT_CANCEL:
1393 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_BR_SK_CANCEL"));
1394 pop->timeout = WFD_POP_TIMER_120;
1395 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
1404 ret = feedback_play(FEEDBACK_PATTERN_GENERAL);
1405 if (ret != FEEDBACK_ERROR_NONE) {
1406 WFD_APP_LOG(WFD_APP_LOG_ERROR,"feedback_play error : %d\n", ret);
1408 WFD_IF_FREE_MEM(peer_name);
1409 __WFD_APP_FUNC_EXIT__;