Fix bug N_SE-34398(Wrong PIN message not displayed)
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-popup-view.c
1 /*
2 *  WiFi-Direct UG
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
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
9
10 * http://www.tizenopensource.org/license
11
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.
17 *
18 */
19
20 /**
21  * This file implements wifi direct system popup view  functions.
22  *
23  * @file    wfd-app-popup-view.c
24  * @author  Sungsik Jang (sungsik.jang@samsung.com)
25  * @version 0.1
26  */
27
28 #include <libintl.h>
29 #include <glib.h>
30
31 #include <notification.h>
32
33 #include "wifi-direct.h"
34 #include "wfd-app.h"
35 #include "wfd-app-strings.h"
36 #include "wfd-app-util.h"
37
38 extern wfd_appdata_t *g_wfd_ad;
39 extern wfd_popup_t *g_wfd_pop;
40 extern unsigned char g_wfd_peer_mac[6];
41 extern unsigned char g_wfd_peer_name[32];
42 static Ecore_Timer *pb_timer = NULL;
43
44
45 /**
46  *      This function let the ug make a callback for click the button in popup
47  *      @return   void
48  *      @param[in] data the pointer to the main data structure
49  *      @param[in] obj the pointer to the evas object
50  *      @param[in] event_info the pointer to the event information
51  */
52 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
53 {
54         __WDPOP_LOG_FUNC_ENTER__;
55         wfd_appdata_t *ad = wfd_get_appdata();
56         int result = -1;
57         int resp = (int) data;
58         char msg[WFD_POP_STR_MAX_LEN] = {0};
59
60         WDPOP_LOGI( "popup resp : %d\n", resp);
61
62         switch (resp) {
63         case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
64         {
65                 WDPOP_LOGI(
66                                 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
67                 wfd_destroy_popup();
68
69                 result = wifi_direct_accept_connection(ad->peer_mac);
70                 WDPOP_LOGD(
71                                 "wifi_direct_accept_connection() result=[%d]\n",
72                                 result);
73                 if (result == WIFI_DIRECT_ERROR_NONE) {
74                         /* tickernoti popup */
75                         notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
76                 } else {
77                         WDPOP_LOGE(
78                                         "wifi_direct_accept_connection() FAILED!!\n");
79                         evas_object_hide(ad->win);
80
81                         /* tickernoti popup */
82                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
83                         notification_status_message_post(msg);
84                 }
85         }
86         break;
87
88         case WFD_POP_RESP_APRV_CONNECT_INVITATION_YES:
89                 WDPOP_LOGI(
90                                 "WFD_POP_RESP_APRV_CONNECT_INVITATION_YES [" MACSTR "]\n", MAC2STR(ad->peer_mac));
91                 wfd_destroy_popup();
92
93                 result = wifi_direct_connect(ad->peer_mac);
94                 WDPOP_LOGD(
95                                 "wifi_direct_connect() result=[%d]\n",
96                                 result);
97                 if (result == WIFI_DIRECT_ERROR_NONE) {
98                         /* tickernoti popup */
99                         notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
100                 } else {
101                         WDPOP_LOGE(
102                                         "wifi_direct_connect() FAILED!!\n");
103                         evas_object_hide(ad->win);
104
105                         /* tickernoti popup */
106                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
107                         notification_status_message_post(msg);
108                 }
109
110         break;
111
112         case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
113         {
114                 char *pin = NULL;
115
116                 WDPOP_LOGI(
117                                 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
118                 wfd_destroy_popup();
119
120                 if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE) {
121                         WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
122                         return;
123                 }
124
125                 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
126                         WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
127                         return;
128                 }
129
130                 strncpy(ad->pin_number, pin, 64);
131                 free(pin);
132                 pin = NULL;
133                 WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);
134
135                 result = wifi_direct_accept_connection(ad->peer_mac);
136                 if (result == WIFI_DIRECT_ERROR_NONE) {
137                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
138                 } else {
139                         WDPOP_LOGD(
140                                 "wifi_direct_accept_connection() failed. result=[%d]\n", result);
141                         /* tickernoti popup */
142                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
143                         notification_status_message_post(msg);
144                 }
145         }
146         break;
147
148         case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
149         {
150                 WDPOP_LOGI(
151                                 "WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");
152
153                 wfd_destroy_popup();
154
155                 int len = strlen(ad->pin_number);
156                 WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);
157
158                 if (len != 8) {
159                         if (len > 8)
160                                 notification_status_message_post(_("IDS_CST_BODY_PASSWORD_TOO_LONG"));
161                         else
162                                 notification_status_message_post(_("IDS_ST_BODY_PASSWORD_TOO_SHORT"));
163                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
164                         return;
165                 }
166
167                 int result = 0;
168                 WDPOP_LOGD( "pin=[%s]\n", ad->pin_number);
169
170                 result = wifi_direct_set_wps_pin(ad->pin_number);
171                 if (result != WIFI_DIRECT_ERROR_NONE) {
172                         /* tickernoti popup */
173                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
174                         notification_status_message_post(msg);
175                         return;
176                 }
177
178                 //result = wifi_direct_activate_pushbutton();
179                 result = wifi_direct_accept_connection(ad->peer_mac);
180                 WDPOP_LOGD(
181                                 "wifi_direct_accept_connection(%s) result=[%d]\n",
182                                 ad->peer_mac, result);
183                 if (result != WIFI_DIRECT_ERROR_NONE) {
184                         WDPOP_LOGE(
185                                         "wifi_direct_accept_connection() FAILED!!\n");
186                         evas_object_hide(ad->win);
187
188                         /* tickernoti popup */
189                         snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
190                         notification_status_message_post(msg);
191                 }
192         }
193         break;
194
195         case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
196         {
197                 WDPOP_LOGI(
198                                 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
199                 wfd_destroy_popup();
200                 if (pb_timer) {
201                         ecore_timer_del(pb_timer);
202                         pb_timer = NULL;
203                 }
204
205                 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
206         }
207         break;
208
209         case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
210         {
211                 WDPOP_LOGI(
212                                 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
213
214                 wfd_destroy_popup();
215                 if (pb_timer) {
216                         ecore_timer_del(pb_timer);
217                         pb_timer = NULL;
218                 }
219
220                 result = wifi_direct_disconnect(ad->peer_mac);
221                 WDPOP_LOGD(
222                                 "wifi_direct_disconnect[%s] result=[%d]\n",
223                                 ad->peer_mac, result);
224         }
225         break;
226
227         default:
228         {
229                 WDPOP_LOGE( "Unknown respone\n");
230                 evas_object_hide(ad->win);
231         }
232         break;
233         }
234
235         __WDPOP_LOG_FUNC_EXIT__;
236 }
237
238 /**
239  *      This function let the app destroy the popup
240  *      @return   void
241  *      @param[in] null
242  */
243 void wfd_destroy_popup()
244 {
245         __WDPOP_LOG_FUNC_ENTER__;
246         wfd_appdata_t *ad = wfd_get_appdata();
247
248         if (ad == NULL) {
249                 WDPOP_LOGE( "ad is NULL\n");
250                 return;
251         }
252
253         if (ad->popup) {
254                 evas_object_del(ad->popup);
255                 ad->popup = NULL;
256         }
257
258         if (ad->popup_timeout_handle > 0) {
259                 g_source_remove(ad->popup_timeout_handle);
260                 ad->popup_timeout_handle = 0;
261         }
262
263         evas_object_hide(ad->win);
264
265         __WDPOP_LOG_FUNC_EXIT__;
266         return;
267 }
268
269 /**
270  *      This function let the app create a popup which includes no button
271  *      @return   popup
272  *      @param[in] win the window object
273  *      @param[in] pop the pointer to the prepared popup
274  */
275 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
276 {
277         __WDPOP_LOG_FUNC_ENTER__;
278         Evas_Object *popup;
279
280         popup = elm_popup_add(win);
281         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282         elm_object_text_set(popup, pop->text);
283         elm_popup_timeout_set(popup, pop->timeout);
284         evas_object_show(popup);
285         evas_object_show(win);
286
287         __WDPOP_LOG_FUNC_EXIT__;
288         return popup;
289 }
290
291 /**
292  *      This function let the app create a popup which includes one button
293  *      @return   popup
294  *      @param[in] win the window object
295  *      @param[in] pop the pointer to the prepared popup
296  */
297 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
298 {
299         __WDPOP_LOG_FUNC_ENTER__;
300         Evas_Object *popup = NULL;
301         Evas_Object *btn = NULL;
302
303         popup = elm_popup_add(win);
304         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
305         elm_object_text_set(popup, pop->text);
306
307         btn = elm_button_add(popup);
308         elm_object_style_set(btn, "popup_button/default");
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, (void *) pop->resp_data1);
312
313         evas_object_show(popup);
314         evas_object_show(win);
315
316         __WDPOP_LOG_FUNC_EXIT__;
317         return popup;
318 }
319
320 /**
321  *      This function let the app create a popup which includes two buttons
322  *      @return   popup
323  *      @param[in] win the window object
324  *      @param[in] pop the pointer to the prepared popup
325  */
326 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
327 {
328         __WDPOP_LOG_FUNC_ENTER__;
329         Evas_Object *popup = NULL;
330         Evas_Object *btn1 = NULL, *btn2 = NULL;
331
332         popup = elm_popup_add(win);
333         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
334         elm_object_text_set(popup, pop->text);
335
336         btn1 = elm_button_add(popup);
337         elm_object_style_set(btn1, "popup_button/default");
338         elm_object_text_set(btn1, pop->label1);
339         elm_object_part_content_set(popup, "button1", btn1);
340         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
341                 (void *) pop->resp_data1);
342
343         btn2 = elm_button_add(popup);
344         elm_object_style_set(btn2, "popup_button/default");
345         elm_object_text_set(btn2, pop->label2);
346         elm_object_part_content_set(popup, "button2", btn2);
347         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
348                 (void *) pop->resp_data2);
349
350         evas_object_show(popup);
351         evas_object_show(win);
352
353         __WDPOP_LOG_FUNC_EXIT__;
354         return popup;
355 }
356
357 /**
358  *      This function let the ug make a change callback for password input
359  *      @return   void
360  *      @param[in] data the pointer to the main data structure
361  *      @param[in] obj the pointer to the evas object
362  *      @param[in] event_info the pointer to the event information
363  */
364 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
365 {
366         __WDPOP_LOG_FUNC_ENTER__;
367         wfd_appdata_t *ad = wfd_get_appdata();
368
369         Ecore_IMF_Context *imf_context = NULL;
370         imf_context = (Ecore_IMF_Context *) ad->pin_entry;
371
372         if (NULL == imf_context) {
373                 WDPOP_LOGE( "Error!!! Ecore_IMF_Context is NULL!!");
374                 return;
375         }
376
377         const char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
378         if (NULL != txt) {
379                 WDPOP_LOGD( "* text [%s], len=[%d]", txt, strlen(txt));
380                 strncpy(ad->pin_number, txt, sizeof(ad->pin_number));
381         } else {
382                 WDPOP_LOGD( "Err!");
383         }
384
385         __WDPOP_LOG_FUNC_EXIT__;
386 }
387
388 /**
389  *      This function let the app make a change callback for password checkbox
390  *      @return   void
391  *      @param[in] data the pointer to the main data structure
392  *      @param[in] obj the pointer to the evas object
393  *      @param[in] event_info the pointer to the event information
394  */
395 static void _check_changed_cb(void *data, Evas_Object * obj, void *event_info)
396 {
397         wfd_appdata_t *ad = wfd_get_appdata();
398
399         if (obj == NULL) {
400                 return;
401         }
402
403         Eina_Bool state = elm_check_state_get(obj);
404         elm_entry_password_set(ad->pin_entry, !state);
405         elm_entry_autocapital_type_set(ad->pin_entry, ELM_AUTOCAPITAL_TYPE_NONE);
406 }
407
408 /**
409  *      This function let the app make a callback for progressbar timer
410  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
411  *      @param[in] data the pointer to the wps structure
412  */
413 static Eina_Bool _fn_pb_timer(void *data)
414 {
415         int step = 0;
416         double value = 0.0;
417         char time_label[32] = {0};
418         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
419
420         if (NULL == wps_display_popup) {
421                 WDPOP_LOGE( "Param is NULL.\n");
422                 return ECORE_CALLBACK_CANCEL;
423         }
424
425         Evas_Object *progressbar = NULL;
426         Evas_Object *time = NULL;
427
428         progressbar = wps_display_popup->progressbar;
429         time = wps_display_popup->time;
430         value = elm_progressbar_value_get(progressbar);
431
432         if (value >= 1.0) {
433                 WDPOP_LOGE( "Progress end.\n");
434                 if (pb_timer) {
435                         ecore_timer_del(pb_timer);
436                         pb_timer = NULL;
437                 }
438                 wfd_destroy_popup();
439                 return ECORE_CALLBACK_CANCEL;
440         }
441
442         wps_display_popup->step++;
443         step = wps_display_popup->step;
444         value = ((double)step) / WFD_POP_TIMER_120;
445         elm_progressbar_value_set(progressbar, value);
446         WDPOP_LOGD( "step: %d, value: %f\n", wps_display_popup->step, value);
447
448         /* show the time label */
449         if (step < 60) {
450                 if (step < 10) {
451                         snprintf(time_label, 32, "00:0%d", step);
452                 } else {
453                         snprintf(time_label, 32, "00:%d", step);
454                 }
455         } else {
456                 if (step%60 < 10) {
457                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
458                 } else {
459                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
460                 }
461         }
462
463         elm_object_text_set(time, time_label);
464
465         return ECORE_CALLBACK_RENEW;
466 }
467
468 /**
469  *      This function let the app create a edit filed
470  *      @return   edit filed
471  *      @param[in] parent the parent object
472  *      @param[in] title the pointer to the title of edit field
473  *      @param[in] guide the pointer to the text of guide
474  *      @param[in] single_line whether it can support single line
475  *      @param[in] is_editable whether it is avaliable to edit
476  */
477 static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
478 {
479         assertm_if(NULL == parent, "parent is NULL!!");
480
481         Evas_Object *layout = elm_layout_add(parent);
482         assertm_if(NULL == layout, "layout is NULL!!");
483
484         if (title && title[0] != '\0') {
485                 elm_layout_theme_set(layout, "layout", "editfield", "title");
486                 elm_object_part_text_set(layout, "elm.text", title);
487         } else {
488                 elm_layout_theme_set(layout, "layout", "editfield", "default");
489         }
490
491         Evas_Object *entry = elm_entry_add(parent);
492         assertm_if(NULL == entry, "entry is NULL!!");
493
494         elm_object_part_content_set(layout, "elm.swallow.content", entry);
495         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
496
497         if (guide && guide[0] != '\0') {
498                 elm_object_part_text_set(layout, "elm.guidetext", guide);
499         }
500
501         elm_entry_single_line_set(entry, single_line);
502         elm_entry_scrollable_set(entry, single_line);
503         elm_entry_editable_set(entry, is_editable);
504         elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
505         evas_object_show(layout);
506
507         return layout;
508 }
509
510 /**
511  *      This function let the app create a display popup
512  *      @return   display popup
513  *      @param[in] win the window object
514  *      @param[in] pop the pointer to the prepared popup
515  */
516 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
517 {
518         __WDPOP_LOG_FUNC_ENTER__;
519
520         Evas_Object *popup = NULL;
521         Evas_Object *label = NULL;
522         Evas_Object *progressbar = NULL;
523         Evas_Object *time = NULL;
524         static wfd_wps_display_popup_t wps_display_popup;
525
526         popup = elm_popup_add(win);
527         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
528
529         Evas_Object *box = elm_box_add(popup);
530         if (!box) {
531                 evas_object_del(popup);
532                 popup = NULL;
533                 return NULL;
534         }
535
536         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
537         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
538         elm_object_part_content_set(popup, NULL, box);
539         evas_object_show(box);
540
541         /* add label */
542         label = elm_label_add(box);
543         elm_object_style_set(label, "popup/default");
544         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
545         elm_object_text_set(label, pop->text);
546         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
547         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.0);
548         elm_box_pack_end(box, label);
549         evas_object_show(label);
550
551         /* add progressbar */
552         progressbar = elm_progressbar_add(box);
553         elm_object_style_set(progressbar, "list_progress");
554         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
555         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.0);
556         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, 0.0);
557         elm_progressbar_value_set(progressbar, 0.0);
558         elm_box_pack_end(box, progressbar);
559         evas_object_show(progressbar);
560
561         /* add time */
562         time = elm_label_add(box);
563         elm_object_style_set(time, "popup/default");
564         elm_object_text_set(time, "00:00");
565         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
566         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, 0.0);
567         elm_box_pack_end(box, time);
568         evas_object_show(time);
569
570         /* start progressbar timer */
571         wps_display_popup.step = 0;
572         wps_display_popup.progressbar = progressbar;
573         wps_display_popup.time = time;
574         if(pb_timer)
575                 ecore_timer_del(pb_timer);
576         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
577
578         /* add buttons */
579         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES ||
580                 pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_NO) {
581                 Evas_Object *btn1 = NULL;
582                 btn1 = elm_button_add(popup);
583                 elm_object_style_set(btn1, "popup_button/default");
584                 elm_object_text_set(btn1, pop->label1);
585                 elm_object_part_content_set(popup, "button1", btn1);
586                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
587                         (void *) pop->resp_data1);
588         }
589
590         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
591                 Evas_Object *btn2 = NULL;
592                 btn2 = elm_button_add(popup);
593                 elm_object_style_set(btn2, "popup_button/default");
594                 elm_object_text_set(btn2, pop->label2);
595                 elm_object_part_content_set(popup, "button2", btn2);
596                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
597                         (void *) pop->resp_data2);
598         }
599
600         elm_object_content_set(popup, box);
601         evas_object_show(popup);
602         evas_object_show(win);
603
604         __WDPOP_LOG_FUNC_EXIT__;
605         return popup;
606 }
607
608 /**
609  *      This function let the app create a keypad popup
610  *      @return   keypad popup
611  *      @param[in] win the window object
612  *      @param[in] pop the pointer to the prepared popup
613  */
614 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
615 {
616         __WDPOP_LOG_FUNC_ENTER__;
617         wfd_appdata_t *ad = wfd_get_appdata();
618
619         Evas_Object *conformant = NULL;
620         Evas_Object *layout = NULL;
621         Evas_Object *pinpopup = NULL;
622         Evas_Object *label = NULL;
623         Evas_Object *btn1 = NULL, *btn2 = NULL;
624
625         conformant = elm_conformant_add(win);
626         assertm_if(NULL == conformant, "conformant is NULL!!");
627         elm_win_conformant_set(win, EINA_TRUE);
628         elm_win_resize_object_add(win, conformant);
629         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, 0.0);
630         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, 0.0);
631         evas_object_show(conformant);
632
633         layout = elm_layout_add(conformant);
634         elm_object_content_set(conformant, layout);
635
636         pinpopup = elm_popup_add(layout);
637         assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
638         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, 0.0);
639         elm_object_part_text_set(pinpopup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
640
641         Evas_Object *box = elm_box_add(pinpopup);
642         if (!box) {
643                 evas_object_del(pinpopup);
644                 pinpopup = NULL;
645                 return NULL;
646         }
647
648         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
649         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
650         elm_object_part_content_set(pinpopup, NULL, box);
651         evas_object_show(box);
652
653         /* add label */
654         label = elm_label_add(box);
655         elm_object_style_set(label, "popup/default");
656         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
657         elm_object_text_set(label, pop->text);
658         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
659         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
660         elm_box_pack_end(box, label);
661         evas_object_show(label);
662
663         /* add password */
664         Evas_Object *body = elm_layout_add(box);
665         if (!body) {
666                 evas_object_del(pinpopup);
667                 pinpopup = NULL;
668                 return NULL;
669         }
670
671         elm_layout_theme_set(body, "layout", "dialogue", "1icon");
672         evas_object_size_hint_weight_set(body, EVAS_HINT_EXPAND, 0.0);
673         evas_object_size_hint_align_set(body, EVAS_HINT_FILL, 0.0);
674
675         Evas_Object *editfield_pin = _add_edit_field(body, NULL, NULL, EINA_TRUE, EINA_TRUE);
676         Evas_Object *entry_pin = elm_object_part_content_get(editfield_pin, "elm.swallow.content");
677         ad->pin_entry = entry_pin;
678         evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb, NULL);
679         elm_object_part_content_set(body, "elm.icon", editfield_pin);
680         elm_box_pack_end(box, body);
681         evas_object_show(body);
682
683         elm_entry_password_set(ad->pin_entry, TRUE);
684
685         Evas_Object *check = elm_check_add(box);
686         elm_object_text_set(check, _("Show password"));
687         elm_object_focus_allow_set(check, EINA_FALSE);
688         evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
689         evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.0);
690         evas_object_smart_callback_add(check, "changed", _check_changed_cb, NULL);
691         evas_object_show(check);
692         elm_box_pack_end(box, check);
693
694         /* add buttons */
695         btn1 = elm_button_add(pinpopup);
696         elm_object_style_set(btn1, "popup_button/default");
697         elm_object_text_set(btn1, pop->label1);
698         elm_object_part_content_set(pinpopup, "button1", btn1);
699         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb, (void *)pop->resp_data1);
700
701         btn2 = elm_button_add(pinpopup);
702         elm_object_style_set(btn2, "popup_button/default");
703         elm_object_text_set(btn2, pop->label2);
704         elm_object_part_content_set(pinpopup, "button2", btn2);
705         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb, (void *)pop->resp_data2);
706
707         elm_object_content_set(pinpopup, box);
708         evas_object_show(pinpopup);
709         evas_object_show(win);
710         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
711
712         __WDPOP_LOG_FUNC_EXIT__;
713         return pinpopup;
714 }
715
716 /**
717  *      This function let the app create a popup
718  *      @return   void
719  *      @param[in] type the type of popup
720  *      @param[in] userdata the pointer to the data which will be used
721  */
722 void wfd_prepare_popup(int type, void *userdata)
723 {
724         __WDPOP_LOG_FUNC_ENTER__;
725         wfd_appdata_t *ad = wfd_get_appdata();
726         wfd_popup_t *pop = ad->popup_data;
727
728         wfd_destroy_popup();
729
730         memset(pop, 0, sizeof(wfd_popup_t));
731
732         pop->type = type;
733
734         switch (pop->type) {
735         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
736                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
737                                 ad->peer_name);
738                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
739                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
740                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
741                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
742
743                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
744                 break;
745
746         case WFD_POP_APRV_CONNECTION_INVITATION_REQ:
747                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
748                                 ad->peer_name);
749                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
750                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
751                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_INVITATION_YES;
752                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
753
754                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
755                 break;
756
757         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
758                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN_WITH_KEYPAD,
759                                 ad->peer_name);
760                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
761                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
762                 pop->timeout = WFD_POP_TIMER_120;
763                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
764                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
765
766                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
767                 break;
768
769         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
770                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN,
771                                 ad->peer_name, WFD_POP_TIMER_120);
772                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
773                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
774                 pop->timeout = WFD_POP_TIMER_120;
775                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
776                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
777
778                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
779                 break;
780
781         case /* MT */ WFD_POP_PROG_CONNECT:
782                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTING"));
783                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
784                 pop->timeout = WFD_POP_TIMER_120;
785                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
786
787                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
788                 break;
789
790         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
791                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_KEYPAD,
792                                 ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
793                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
794                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
795                 pop->timeout = WFD_POP_TIMER_120;
796                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
797                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
798
799                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
800                 break;
801
802         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
803                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_PIN,
804                         ad->peer_name, WFD_POP_TIMER_120, ad->pin_number);
805                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
806                 pop->timeout = WFD_POP_TIMER_120;
807                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
808
809                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
810                 break;
811
812         case WFD_POP_PROG_CONNECT_CANCEL:
813                 snprintf(pop->text, sizeof(pop->text), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
814                 pop->timeout = WFD_POP_TIMER_120;
815                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
816                 break;
817
818         default:
819                 break;
820         }
821
822         __WDPOP_LOG_FUNC_EXIT__;
823         return;
824 }