95417613274224a4eff3549489e58051e81e3e2c
[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 <Elementary.h>
32 #include <efl-assist/efl_assist.h>
33 #include <vconf.h>
34 #include <notification.h>
35 #include <feedback.h>
36 #include <wifi-direct.h>
37 #include <efl_extension.h>
38
39 #include "wfd-app.h"
40 #include "wfd-app-strings.h"
41 #include "wfd-app-util.h"
42 #include "wfd-app-popup-view.h"
43
44 extern wfd_appdata_t *g_wfd_ad;
45 extern wfd_popup_t *g_wfd_pop;
46 extern unsigned char g_wfd_peer_mac[6];
47 extern unsigned char g_wfd_peer_name[32];
48 static Ecore_Timer *pb_timer = NULL;
49 static Ecore_Timer *keypad_popup_timer = NULL;
50 static int keypad_popup_timeout = 0;
51
52 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2);
53
54 static void mouseup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
55 {
56         Evas_Event_Mouse_Up *ev = event_info;
57         if (ev->button == 3) {
58                 evas_object_del(obj);
59         }
60 }
61
62 /*static void keydown_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
63 {
64         Evas_Event_Key_Down *ev = event_info;
65         if (!strcmp(ev->keyname, KEY_BACK)) {
66                 evas_object_del(obj);
67         }
68 }*/
69
70 /**
71  *      This function let the ug make a callback for click the button in popup
72  *      @return   void
73  *      @param[in] data the pointer to the main data structure
74  *      @param[in] obj the pointer to the evas object
75  *      @param[in] event_info the pointer to the event information
76  */
77 static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
78 {
79         __WFD_APP_FUNC_ENTER__;
80         wfd_appdata_t *ad = wfd_get_appdata();
81         wfd_connection_info_s *connection = ad->connection;
82         int result = -1;
83         int resp = (int) data;
84         char msg[WFD_POP_STR_MAX_LEN] = {0};
85
86         WFD_APP_LOG(WFD_APP_LOG_HIGH, "popup resp : %d\n", resp);
87
88         if (ad->rotate_event_handler) {
89                 ecore_event_handler_del(ad->rotate_event_handler);
90                 ad->rotate_event_handler = NULL;
91         }
92
93         switch (resp) {
94         case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
95         {
96                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
97                                 "WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
98                 wfd_destroy_popup();
99
100                 result = wifi_direct_accept_connection(connection->peer_addr);
101                 if (result != WIFI_DIRECT_ERROR_NONE) {
102                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
103                         evas_object_hide(ad->win);
104
105                         /* tickernoti popup */
106                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
107                                                         connection->peer_name);
108                         notification_status_message_post(msg);
109                 }
110                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to accept connection");
111         }
112         break;
113
114         case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
115         {
116                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
117                                 "WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
118                 wfd_destroy_popup();
119
120                 result = wifi_direct_accept_connection(connection->peer_addr);
121                 if (result == WIFI_DIRECT_ERROR_NONE) {
122                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
123                 } else {
124                         WFD_APP_LOG(WFD_APP_LOG_LOW,
125                                 "wifi_direct_accept_connection() failed. result=[%d]\n", result);
126                         /* tickernoti popup */
127                         notification_status_message_post(_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"));
128                 }
129         }
130         break;
131
132         case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
133         {
134                 int result = 0;
135                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
136                                 "WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");
137
138                 wfd_destroy_popup();
139
140                 int len = strlen(connection->wps_pin);
141                 WFD_APP_LOGSECURE(WFD_APP_LOG_LOW, "PIN [%s]", connection->wps_pin);
142
143                 if (len < 8 || len > 64) {
144                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error, Incorrect PIN!!\n");
145                         keypad_popup_timeout--;
146                         /* tickernoti popup */
147                         notification_status_message_post(_("IDS_COM_BODY_PINS_DO_NOT_MATCH"));
148
149                         /* redraw the popup */
150                         wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
151                         break;
152                 }
153                 keypad_popup_timeout = 0;
154
155                 result = wifi_direct_set_wps_pin(connection->wps_pin);
156                 if (result != WIFI_DIRECT_ERROR_NONE) {
157                         /* tickernoti popup */
158                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
159                                                         connection->peer_name);
160                         notification_status_message_post(msg);
161                         return;
162                 }
163
164                 result = wifi_direct_accept_connection(connection->peer_addr);
165                 if (result != WIFI_DIRECT_ERROR_NONE) {
166                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection(%d)", result);
167                         evas_object_hide(ad->win);
168
169                         /* tickernoti popup */
170                         snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
171                                                         connection->peer_name);
172                         notification_status_message_post(msg);
173                 }
174                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with [%s]", connection->peer_addr);
175         }
176         break;
177
178         case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
179         {
180                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
181                                 "WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
182                 wfd_destroy_popup();
183                 if (pb_timer) {
184                         ecore_timer_del(pb_timer);
185                         pb_timer = NULL;
186                 }
187
188                 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
189         }
190         break;
191
192         case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
193         {
194                 WFD_APP_LOG(WFD_APP_LOG_HIGH,
195                                 "WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");
196
197                 if (connection->peer_addr[0] != '\0') {
198                         result = wifi_direct_reject_connection(connection->peer_addr);
199                         if (result != WIFI_DIRECT_ERROR_NONE)
200                                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
201                 } else {
202                         WFD_APP_LOG(WFD_APP_LOG_ERROR, "Peer's address is Zero MAC");
203                 }
204
205                 if (pb_timer) {
206                         ecore_timer_del(pb_timer);
207                         pb_timer = NULL;
208                 }
209
210                 wfd_destroy_popup();
211                 keypad_popup_timeout = 0;
212         }
213         break;
214
215         default:
216         {
217                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown respone\n");
218                 wfd_destroy_popup();
219         }
220         break;
221         }
222
223         __WFD_APP_FUNC_EXIT__;
224 }
225
226 /**
227  *      This function let the app destroy the popup
228  *      @return   void
229  *      @param[in] null
230  */
231 void wfd_destroy_popup()
232 {
233         __WFD_APP_FUNC_ENTER__;
234         wfd_appdata_t *ad = wfd_get_appdata();
235
236         if (ad == NULL) {
237                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "ad is NULL\n");
238                 return;
239         }
240
241         if (keypad_popup_timer) {
242                 ecore_timer_del(keypad_popup_timer);
243                 keypad_popup_timer = NULL;
244         }
245
246         if (ad->popup) {
247                 evas_object_del(ad->popup);
248                 ad->popup = NULL;
249         }
250
251         if (ad->popup_timeout_handle > 0) {
252                 g_source_remove(ad->popup_timeout_handle);
253                 ad->popup_timeout_handle = 0;
254         }
255
256         if (ad->win) {
257                 evas_object_hide(ad->win);
258         }
259
260         if (pb_timer) {
261                 ecore_timer_del(pb_timer);
262                 pb_timer = NULL;
263         }
264         __WFD_APP_FUNC_EXIT__;
265         return;
266 }
267
268 void __set_parent_rotate_angle(wfd_appdata_t *ad)
269 {
270         __WFD_APP_FUNC_ENTER__;
271
272         int rots1[1] = {0};
273
274         if (ad == NULL || ad->win == NULL) {
275                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Parameter NULL");
276                 return;
277         }
278
279         elm_win_wm_rotation_available_rotations_set(ad->win, rots1, 1);
280
281         __WFD_APP_FUNC_EXIT__;
282         return;
283 }
284
285 /**
286  *      This function let the app create a popup which includes no button
287  *      @return   popup
288  *      @param[in] win the window object
289  *      @param[in] pop the pointer to the prepared popup
290  */
291 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
292 {
293         __WFD_APP_FUNC_ENTER__;
294
295         wfd_appdata_t *ad = wfd_get_appdata();
296         Evas_Object *popup;
297
298         popup = elm_popup_add(win);
299         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
300         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, NULL);
301         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
302 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
303         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
304         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
305         elm_popup_timeout_set(popup, pop->timeout);
306         __set_parent_rotate_angle(ad);
307         evas_object_show(popup);
308         evas_object_show(win);
309
310         __WFD_APP_FUNC_EXIT__;
311         return popup;
312 }
313
314 /**
315  *      This function let the app create a popup which includes one button
316  *      @return   popup
317  *      @param[in] win the window object
318  *      @param[in] pop the pointer to the prepared popup
319  */
320 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
321 {
322         __WFD_APP_FUNC_ENTER__;
323         Evas_Object *popup = NULL;
324         Evas_Object *btn = NULL;
325         wfd_appdata_t *ad = wfd_get_appdata();
326
327         popup = elm_popup_add(win);
328         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
329         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data1);
330         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
331 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
332         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
334
335         btn = elm_button_add(popup);
336         elm_object_style_set(btn, "popup");
337         elm_object_domain_translatable_text_set(btn, PACKAGE, pop->label1);
338         elm_object_part_content_set(popup, "button1", btn);
339         evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) pop->resp_data1);
340
341         __set_parent_rotate_angle(ad);
342         evas_object_show(popup);
343         evas_object_show(win);
344
345         __WFD_APP_FUNC_EXIT__;
346         return popup;
347 }
348
349 /**
350  *      This function let the app create a popup which includes two buttons
351  *      @return   popup
352  *      @param[in] win the window object
353  *      @param[in] pop the pointer to the prepared popup
354  */
355 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
356 {
357         __WFD_APP_FUNC_ENTER__;
358         Evas_Object *popup = NULL;
359         Evas_Object *btn1 = NULL, *btn2 = NULL;
360         wfd_appdata_t *ad = wfd_get_appdata();
361
362         popup = elm_popup_add(win);
363         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
364         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
365         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
366 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
367         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
368         elm_object_domain_translatable_part_text_set(popup, "title,text",
369                         PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
370         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
371
372         btn1 = elm_button_add(popup);
373         elm_object_style_set(btn1, "popup");
374         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
375         elm_object_part_content_set(popup, "button1", btn1);
376         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
377                 (void *) pop->resp_data2);
378
379         btn2 = elm_button_add(popup);
380         elm_object_style_set(btn2, "popup");
381         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
382         elm_object_part_content_set(popup, "button2", btn2);
383         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
384                 (void *) pop->resp_data1);
385
386         __set_parent_rotate_angle(ad);
387         evas_object_show(popup);
388         evas_object_show(win);
389
390         __WFD_APP_FUNC_EXIT__;
391         return popup;
392 }
393
394 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
395 {
396         __WFD_APP_FUNC_ENTER__;
397         wfd_appdata_t *ad = wfd_get_appdata();
398
399         if (ad->popup) {
400                 evas_object_del(ad->popup);
401                 ad->popup = NULL;
402         }
403
404         if (ad->rotate_event_handler) {
405                 ecore_event_handler_del(ad->rotate_event_handler);
406                 ad->rotate_event_handler = NULL;
407         }
408
409         if (ad->win) {
410                 evas_object_hide(ad->win);
411         }
412
413         __WFD_APP_FUNC_EXIT__;
414 }
415
416 Evas_Object *wfd_draw_pop_type_auto_deactivation(Evas_Object *win,  void *userdata)
417 {
418         __WFD_APP_FUNC_ENTER__;
419
420         Evas_Object *popup = NULL;
421         Evas_Object *btn = NULL;
422         char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
423         wfd_appdata_t *ad = wfd_get_appdata();
424
425         popup = elm_popup_add(win);
426         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
427         eext_object_event_callback_add(popup, EA_CALLBACK_BACK, _wfd_ug_automatic_turn_off_popup_cb, userdata);
428         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
429 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
430         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
431         elm_object_domain_translatable_part_text_set(popup, "title,text",
432                         PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
433         snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
434                 "IDS_WIFI_POP_THERE_HAS_BEEN_NO_ACTIVITY_FOR_PD_MINUTES_SINCE_WI_FI_DIRECT_WAS_ENABLED_MSG", 5);
435         elm_object_domain_translatable_text_set(popup, PACKAGE, popup_text);
436
437         btn = elm_button_add(popup);
438         elm_object_style_set(btn, "popup");
439         elm_object_domain_translatable_text_set(btn, PACKAGE, "IDS_BR_SK_OK");
440         elm_object_part_content_set(popup, "button1", btn);
441         evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, userdata);
442
443         __set_parent_rotate_angle(ad);
444         evas_object_show(popup);
445         evas_object_show(win);
446
447         __WFD_APP_FUNC_EXIT__;
448         return popup;
449 }
450
451 /**
452  *      This function let the ug make a change callback for password input
453  *      @return   void
454  *      @param[in] data the pointer to the main data structure
455  *      @param[in] obj the pointer to the evas object
456  *      @param[in] event_info the pointer to the event information
457  */
458 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
459 {
460         __WFD_APP_FUNC_ENTER__;
461         wfd_appdata_t *ad = wfd_get_appdata();
462         wfd_connection_info_s *connection = ad->connection;
463
464         Ecore_IMF_Context *imf_context = NULL;
465         imf_context = (Ecore_IMF_Context *) ad->pin_entry;
466
467         if (NULL == imf_context) {
468                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
469                 return;
470         }
471
472         char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
473         if (NULL != txt) {
474                 WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
475                 strncpy(connection->wps_pin, txt, sizeof(connection->wps_pin) - 1);
476                 WFD_IF_FREE_MEM(txt);
477         } else {
478                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
479         }
480
481         __WFD_APP_FUNC_EXIT__;
482 }
483
484 /**
485  *      This function let the app make a callback for progressbar timer
486  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
487  *      @param[in] data the pointer to the wps structure
488  */
489 static Eina_Bool _fn_pb_timer(void *data)
490 {
491         int step = 0;
492         double value = 0.0;
493         char time_label[32] = {0};
494         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
495
496         if (NULL == wps_display_popup) {
497                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Param is NULL.\n");
498                 return ECORE_CALLBACK_CANCEL;
499         }
500
501         Evas_Object *progressbar = NULL;
502         Evas_Object *time = NULL;
503
504         progressbar = wps_display_popup->progressbar;
505         time = wps_display_popup->time;
506         value = elm_progressbar_value_get(progressbar);
507
508         wps_display_popup->step++;
509         step = wps_display_popup->step;
510         value = ((double)step) / WFD_POP_TIMER_120;
511
512         if (value >= 1.0) {
513                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Progress end.\n");
514                 if (pb_timer) {
515                         ecore_timer_del(pb_timer);
516                         pb_timer = NULL;
517                 }
518                 wfd_destroy_popup();
519                 return ECORE_CALLBACK_CANCEL;
520         }
521
522         elm_progressbar_value_set(progressbar, value);
523         WFD_APP_LOG(WFD_APP_LOG_LOW, "step: %d, value: %f\n", wps_display_popup->step, value);
524
525         /* show the time label */
526         if (step < 60) {
527                 if (step < 10) {
528                         snprintf(time_label, 32, "00:0%d", step);
529                 } else {
530                         snprintf(time_label, 32, "00:%d", step);
531                 }
532         } else {
533                 if (step%60 < 10) {
534                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
535                 } else {
536                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
537                 }
538         }
539
540         char *remaining_time_str = g_strdup_printf(
541                         "<font_size=40><align=center>%s</align></font_size>", time_label);
542         elm_object_text_set(time, remaining_time_str);
543         g_free(remaining_time_str);
544
545         return ECORE_CALLBACK_RENEW;
546 }
547
548 static Eina_Bool _keypad_popup_timer_cb(void *data)
549 {
550         __WFD_APP_FUNC_ENTER__;
551
552         char msg1[WFD_POP_STR_MAX_LEN] = {0};
553         char msg2[WFD_POP_STR_MAX_LEN] = {0};
554
555         Evas_Object *label = (Evas_Object*) data;
556         wfd_appdata_t *ad = wfd_get_appdata();
557         wfd_connection_info_s *connection = ad->connection;
558         WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters(ad)\n");
559         WFD_RETV_IF(NULL == label, FALSE, "NULL parameters(label)\n");
560         if (NULL == ad->popup) {
561                 keypad_popup_timeout = 0;
562                 return ECORE_CALLBACK_CANCEL;
563         }
564
565         keypad_popup_timeout --;
566
567         if (keypad_popup_timeout > 0) {
568                 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
569                                 _("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
570                                 connection->peer_name, keypad_popup_timeout);
571
572                 strcat(msg1, " ");
573                 snprintf(msg2, sizeof(msg2), _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
574                                                 connection->peer_name);
575                 strcat(msg1, msg2);
576                 elm_object_domain_translatable_text_set(label, PACKAGE, msg1);
577
578         }
579
580         if (keypad_popup_timeout <= 0) {
581                 wfd_destroy_popup();
582                 keypad_popup_timeout = 0;
583                 __WFD_APP_FUNC_EXIT__;
584                 return ECORE_CALLBACK_CANCEL;
585         }
586
587         __WFD_APP_FUNC_EXIT__;
588         return ECORE_CALLBACK_RENEW;
589 }
590
591 /* This callback is for showing(hiding) X marked button. */
592 /*static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
593 {
594         if (elm_object_focus_get(obj)) {
595                 if (elm_entry_is_empty(obj))
596                         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
597                 else
598                         elm_object_signal_emit(data, "elm,state,eraser,show", "");
599         }
600 }*/
601
602 /* Focused callback will show X marked button and hide guidetext. */
603 /*static void _focused_cb(void *data, Evas_Object *obj, void *event_info)
604 {
605         if (!elm_entry_is_empty(obj))
606                 elm_object_signal_emit(data, "elm,state,eraser,show", "");
607         elm_object_signal_emit(data, "elm,state,rename,hide", "");
608 }*/
609
610 /*  Unfocused callback will show guidetext and hide X marked button. */
611 /*static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info)
612 {
613         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
614         elm_object_signal_emit(data, "elm,state,rename,show", "");
615 }*/
616
617 /* When X marked button clicked, make string as empty. */
618 /*static void _eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
619 {
620         elm_object_focus_set(data, EINA_TRUE);
621         elm_entry_entry_set(data, "");
622 }*/
623
624 /**
625  *      This function let the app create a edit filed
626  *      @return   edit filed
627  *      @param[in] parent the parent object
628  *      @param[in] title the pointer to the title of edit field
629  *      @param[in] guide the pointer to the text of guide
630  *      @param[in] single_line whether it can support single line
631  *      @param[in] is_editable whether it is avaliable to edit
632  */
633 /*static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
634 {
635         assertm_if(NULL == parent, "parent is NULL!!");
636
637         Evas_Object *layout = elm_layout_add(parent);
638         assertm_if(NULL == layout, "layout is NULL!!");
639
640         if (title && title[0] != '\0') {
641                 elm_layout_theme_set(layout, "layout", "dialogue/editfield/title", "default");
642                 elm_object_part_text_set(layout, "elm.text", title);
643         } else {
644                 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "default");
645         }
646
647         Evas_Object *entry = elm_entry_add(layout);
648         assertm_if(NULL == entry, "entry is NULL!!");
649
650         if (guide && guide[0] != '\0') {
651                 elm_object_part_text_set(layout, "elm.guidetext", guide);
652         }
653
654         evas_object_smart_callback_add(entry, "changed", _changed_cb, layout);
655         evas_object_smart_callback_add(entry, "focused", _focused_cb, layout);
656         evas_object_smart_callback_add(entry, "unfocused", _unfocused_cb, layout);
657
658         elm_object_part_content_set(layout, "elm.icon.entry", entry);
659         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
660         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
661
662         elm_entry_single_line_set(entry, single_line);
663         elm_entry_scrollable_set(entry, single_line);
664
665         Evas_Object *button = elm_button_add(parent);
666         elm_object_style_set(button, "editfield_clear");
667         elm_object_part_content_set(layout, "elm.icon.eraser", button);
668         evas_object_smart_callback_add(button, "clicked", _eraser_btn_clicked_cb, entry);
669         return layout;
670 }*/
671
672 /**
673  *      This function let the app create a display popup
674  *      @return   display popup
675  *      @param[in] win the window object
676  *      @param[in] pop the pointer to the prepared popup
677  */
678 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
679 {
680         __WFD_APP_FUNC_ENTER__;
681         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_draw_pop_type_display\n");
682
683         Evas_Object *popup = NULL;
684         Evas_Object *progressbar = NULL;
685         Evas_Object *time = NULL;
686         Evas_Object *layout;
687         static wfd_wps_display_popup_t wps_display_popup;
688         wfd_appdata_t *ad = wfd_get_appdata();
689
690         popup = elm_popup_add(win);
691         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
692         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
693 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
694         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
695         elm_object_domain_translatable_part_text_set(popup, "title,text",
696                          PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
697
698         layout = elm_layout_add(popup);
699         if (layout == NULL) {
700                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Layout failed so returning !!");
701                 return NULL;
702         }
703
704         elm_layout_file_set(layout, WFD_EDJ_POPUP_PATH, "popup_wps_pin_layout");
705         elm_object_domain_translatable_part_text_set(layout, "elm.text.description",
706                          PACKAGE, pop->text);
707         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
708
709         /* add progressbar */
710         progressbar = elm_progressbar_add(layout);
711         elm_object_style_set(progressbar, "list_progress");
712         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
713         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
714         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
715         elm_progressbar_value_set(progressbar, 0.0);
716         evas_object_show(progressbar);
717
718         /* add time */
719         time = elm_label_add(layout);
720         elm_label_line_wrap_set(time, ELM_WRAP_MIXED);
721         elm_object_text_set(time, _("<font_size=40><align=center>00:00</align></font_size>"));
722         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
723         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, EVAS_HINT_FILL);
724         evas_object_show(time);
725
726         elm_object_part_content_set(layout, "slider", progressbar);
727         elm_object_part_content_set(layout, "timer_label", time);
728
729
730         /* start progressbar timer */
731         wps_display_popup.step = 0;
732         wps_display_popup.progressbar = progressbar;
733         wps_display_popup.time = time;
734         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
735
736         /* add buttons */
737         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
738                 Evas_Object *btn2 = NULL;
739                 btn2 = elm_button_add(popup);
740                 elm_object_style_set(btn2, "popup");
741                 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label2);
742                 elm_object_part_content_set(popup, "button1", btn2);
743                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
744                         (void *) pop->resp_data2);
745                 eext_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
746         }
747
748         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES || pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_PBC_YES ) {
749                 Evas_Object *btn1 = NULL;
750                 btn1 = elm_button_add(popup);
751                 elm_object_style_set(btn1, "popup");
752                 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label1);
753                 elm_object_part_content_set(popup, "button2", btn1);
754                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
755                         (void *) pop->resp_data1);
756                 eext_object_event_callback_add(popup, EA_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data1);
757         }
758
759         elm_object_content_set(popup, layout);
760         __set_parent_rotate_angle(ad);
761         evas_object_show(popup);
762         evas_object_show(win);
763
764         __WFD_APP_FUNC_EXIT__;
765         return popup;
766 }
767
768 static void __popup_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
769 {
770         __WFD_APP_FUNC_ENTER__;
771         elm_entry_entry_set(data, "");
772         __WFD_APP_FUNC_EXIT__;
773 }
774
775 static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
776 {
777         __WFD_APP_FUNC_ENTER__;
778         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
779                 if (elm_object_focus_get(obj)) {
780                         if (elm_entry_is_empty(obj))
781                                 elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
782                         else
783                                 elm_object_signal_emit(obj, "elm,state,clear,visible", "");
784                 }
785         }
786         __WFD_APP_FUNC_EXIT__;
787 }
788
789 static void _entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
790 {
791         __WFD_APP_FUNC_ENTER__;
792
793         if (elm_object_part_content_get(obj, "elm.swallow.clear")) {
794                 if (!elm_entry_is_empty(obj))
795                         elm_object_signal_emit(obj, "elm,state,clear,visible", "");
796                 else
797                         elm_object_signal_emit(obj, "elm,state,clear,hidden", "");
798         }
799         elm_object_signal_emit(obj, "elm,state,focus,on", "");
800         __WFD_APP_FUNC_EXIT__;
801 }
802
803 static void _entry_keydown_cb(void *data, Evas *e, Evas_Object *obj,
804                 void *event_info)
805 {
806         __WFD_APP_FUNC_ENTER__;
807
808         Evas_Event_Key_Down *ev;
809         Evas_Object *entry = obj;
810
811         WFD_RET_IF(data == NULL, "Incorrect parameter data(NULL)\n");
812         WFD_RET_IF(event_info == NULL, "Incorrect parameter event_info(NULL)\n");
813         WFD_RET_IF(entry == NULL, "Incorrect parameter entry(NULL)\n");
814
815         ev = (Evas_Event_Key_Down *)event_info;
816
817         if (g_strcmp0(ev->key, "KP_Enter") == 0 || g_strcmp0(ev->key, "Return") == 0) {
818                 Ecore_IMF_Context *imf_context;
819
820                 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
821                 if (imf_context) {
822                         ecore_imf_context_input_panel_hide(imf_context);
823                 }
824
825                 elm_object_focus_set(entry, EINA_FALSE);
826         }
827 }
828
829 static char *__wfd_main_desc_label_get(void *data, Evas_Object *obj,
830                 const char *part)
831 {
832         __WFD_APP_FUNC_ENTER__;
833         if (obj == NULL || part == NULL) {
834                 return NULL;
835         }
836         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_rename desc\n");
837         char msg1[WFD_POP_STR_MAX_LEN] = {0, };
838         char msg2[WFD_POP_STR_MAX_LEN] = {0, };
839         wfd_appdata_t *ad = wfd_get_appdata();
840         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
841         wfd_connection_info_s *connection = ad->connection;
842         WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
843
844         if (!g_strcmp0(part, "elm.text.multiline")) {
845                 if (keypad_popup_timeout > 0) {
846                                 ad->timeout = keypad_popup_timeout;
847                 }
848                 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
849                                 _("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
850                                 connection->peer_name, ad->timeout);
851
852                 strcat(msg1, " ");
853                 snprintf(msg2, sizeof(msg2),
854                                 _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
855                                 connection->peer_name);
856                 strcat(msg1, msg2);
857                 WFD_APP_LOG(WFD_APP_LOG_LOW, "string %s", msg1);
858                 __WFD_APP_FUNC_EXIT__;
859                 return g_strdup(msg1);
860         }
861         __WFD_APP_FUNC_EXIT__;
862         return NULL;
863 }
864
865 static Evas_Object *__wfd_pin_entry_icon_get(void *data, Evas_Object *obj,
866                 const char *part)
867 {
868         __WFD_APP_FUNC_ENTER__;
869         if (obj == NULL || part == NULL) {
870                 return NULL;
871         }
872         wfd_appdata_t *ad = wfd_get_appdata();
873         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
874         Evas_Object *entry = NULL;
875         Evas_Object *button = NULL;
876         Ecore_IMF_Context *imf_context;
877         if (g_strcmp0(part, "elm.icon.entry")) {
878                 __WFD_APP_FUNC_EXIT__;
879                 return NULL;
880         }
881         static Elm_Entry_Filter_Accept_Set accept_set = {"0123456789", NULL};
882         entry = elm_entry_add(obj);
883         elm_entry_single_line_set(entry, EINA_TRUE);
884         elm_object_style_set(entry, "editfield");
885         elm_entry_scrollable_set(entry, EINA_TRUE);
886
887         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
888         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
889         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
890         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
891         elm_entry_password_set(entry, EINA_TRUE);
892         elm_entry_prediction_allow_set(entry, EINA_FALSE);
893
894         elm_entry_markup_filter_append(entry,
895                         elm_entry_filter_accept_set,&accept_set);
896         elm_entry_input_panel_layout_set(entry,
897                         ELM_INPUT_PANEL_LAYOUT_DATETIME);
898         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
899         elm_object_domain_translatable_part_text_set(entry, "elm.guide",
900                          PACKAGE, _("IDS_WIFI_POP_PIN"));
901         elm_entry_input_panel_return_key_autoenabled_set(entry,EINA_TRUE);
902         elm_entry_input_panel_return_key_type_set(entry,
903                         ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
904
905         ad->pin_entry = entry;
906         imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
907         if (imf_context) {
908                 ecore_imf_context_input_panel_return_key_type_set(imf_context,
909                 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
910         }
911
912         button = elm_button_add(obj);
913         elm_object_style_set(button, "search_clear");
914         elm_object_focus_allow_set(button, EINA_FALSE);
915         elm_object_part_content_set(entry, "elm.swallow.clear", button);
916         evas_object_smart_callback_add(button, "clicked",
917                         __popup_eraser_clicked_cb, entry);
918
919         elm_object_signal_emit (entry, "elm,action,hide,search_icon", "");
920         evas_object_smart_callback_add(entry, "changed",
921                         _entry_changed_cb, NULL);
922         evas_object_smart_callback_add(entry, "preedit,changed",
923                         _entry_changed_cb, NULL);
924         evas_object_smart_callback_add(entry, "focused",
925                         _entry_focused_cb, NULL);
926         evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
927                         _entry_keydown_cb, ad);
928
929         elm_object_content_set(obj,entry);
930         evas_object_show(entry);
931         evas_object_smart_callback_add(entry, "changed", _smart_ime_cb, NULL);
932         elm_object_focus_set(entry, EINA_TRUE);
933         __WFD_APP_FUNC_EXIT__;
934         return entry;
935 }
936
937 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
938 {
939         __WFD_APP_FUNC_ENTER__;
940         if (obj == NULL || data == NULL) {
941                 return;
942         }
943         Eina_Bool state = elm_check_state_get(obj);
944         if (state) {
945                 elm_entry_password_set((Evas_Object *)data, EINA_FALSE);
946         } else {
947                 elm_entry_password_set((Evas_Object *)data, EINA_TRUE);
948         }
949         __WFD_APP_FUNC_EXIT__;
950 }
951
952 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
953 {
954         __WFD_APP_FUNC_ENTER__;
955         Elm_Object_Item *item = NULL;
956         item = (Elm_Object_Item *)ei;
957         if (item == NULL) {
958                 return;
959         }
960         wfd_appdata_t *ad = wfd_get_appdata();
961         if (ad == NULL) {
962                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter(NULL)\n");
963                 return;
964         }
965         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.left");
966         elm_genlist_item_selected_set(item, EINA_FALSE);
967         Eina_Bool state = elm_check_state_get(ck);
968         elm_check_state_set(ck, !state);
969         if (ad) {
970                 _chk_changed_cb(ad->pin_entry, ck, NULL);
971         }
972         __WFD_APP_FUNC_EXIT__;
973 }
974
975 static char *__wfd_password_label(void *data, Evas_Object *obj, const char *part)
976 {
977         __WFD_APP_FUNC_ENTER__;
978
979         if (data == NULL || part == NULL) {
980                 return NULL;
981         }
982         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
983
984         if (!g_strcmp0(part, "elm.text.main.right")) {
985                 __WFD_APP_FUNC_EXIT__;
986                 return g_strdup(" Show password");
987         }
988         __WFD_APP_FUNC_EXIT__;
989         return NULL;
990 }
991
992 static Evas_Object *__wfd_password_check(void *data, Evas_Object *obj,
993                 const char *part)
994 {
995         __WFD_APP_FUNC_ENTER__;
996         if (obj == NULL || part == NULL) {
997                 return NULL;
998         }
999         wfd_appdata_t *ad = wfd_get_appdata();
1000         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1001         Evas_Object *check = NULL;
1002
1003         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
1004
1005         if (!g_strcmp0(part, "elm.icon.left")) {
1006                 check = elm_check_add(obj);
1007                 evas_object_propagate_events_set(check, EINA_FALSE);
1008                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
1009                 evas_object_size_hint_weight_set(check,
1010                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1011                 evas_object_smart_callback_add(check, "changed",
1012                                 _chk_changed_cb, ad->pin_entry);
1013                 elm_object_focus_allow_set(check, EINA_FALSE);
1014                 __WFD_APP_FUNC_EXIT__;
1015                 return check;
1016         }
1017         __WFD_APP_FUNC_EXIT__;
1018         return check;
1019 }
1020
1021
1022 /**
1023  *      This function let the app create a keypad popup
1024  *      @return   keypad popup
1025  *      @param[in] win the window object
1026  *      @param[in] pop the pointer to the prepared popup
1027  */
1028 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
1029 {
1030         __WFD_APP_FUNC_ENTER__;
1031         wfd_appdata_t *ad = wfd_get_appdata();
1032         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1033         wfd_connection_info_s *connection = ad->connection;
1034         WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
1035
1036         Evas_Object *pinpopup = NULL;
1037         Evas_Object *btn1 = NULL, *btn2 = NULL;
1038         Evas_Object *genlist = NULL;
1039         Elm_Object_Item *git = NULL;
1040
1041         ad->timeout = pop->timeout;
1042
1043         pinpopup = elm_popup_add(ad->layout);
1044         elm_popup_align_set(pinpopup, ELM_NOTIFY_ALIGN_FILL, 1.0);
1045         eext_object_event_callback_add(pinpopup, EA_CALLBACK_BACK, eext_popup_back_cb,
1046                         NULL);
1047         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1048         elm_object_domain_translatable_part_text_set(pinpopup, "title,text",
1049                          PACKAGE, _("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
1050
1051         genlist = elm_genlist_add(pinpopup);
1052         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1053         evas_object_size_hint_weight_set(genlist,
1054                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1055         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1056         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1057         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
1058
1059         /* Entry genlist item */
1060         ad->pin_desc_itc = elm_genlist_item_class_new();
1061         if(ad->pin_desc_itc != NULL) {
1062                 ad->pin_desc_itc->item_style = "multiline_main";
1063                 ad->pin_desc_itc->func.text_get = __wfd_main_desc_label_get;
1064                 ad->pin_desc_itc->func.content_get = NULL;
1065                 ad->pin_desc_itc->func.state_get = NULL;
1066                 ad->pin_desc_itc->func.del = NULL;
1067
1068                 git = elm_genlist_item_append(genlist, ad->pin_desc_itc, ad, NULL,
1069                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1070                 if(git != NULL)
1071                         elm_genlist_item_select_mode_set(git,
1072                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1073
1074                 keypad_popup_timeout = pop->timeout;
1075                 keypad_popup_timer = ecore_timer_add(1, _keypad_popup_timer_cb,
1076                                 ad->pin_desc_itc);
1077         }
1078
1079         ad->pin_entry_itc = elm_genlist_item_class_new();
1080         if(ad->pin_entry_itc != NULL) {
1081                 ad->pin_entry_itc->item_style = "entry";
1082                 ad->pin_entry_itc->func.text_get = NULL;
1083                 ad->pin_entry_itc->func.content_get = __wfd_pin_entry_icon_get;
1084                 ad->pin_entry_itc->func.state_get = NULL;
1085                 ad->pin_entry_itc->func.del = NULL;
1086
1087                 elm_genlist_item_append(genlist, ad->pin_entry_itc, pinpopup,
1088                                 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1089         }
1090
1091         ad->paswd_itc = elm_genlist_item_class_new();
1092         if(ad->paswd_itc != NULL) {
1093                 ad->paswd_itc->item_style = "1line";
1094                 ad->paswd_itc->func.text_get = __wfd_password_label;
1095                 ad->paswd_itc->func.content_get = __wfd_password_check;
1096                 ad->paswd_itc->func.state_get = NULL;
1097                 ad->paswd_itc->func.del = NULL;
1098
1099                 elm_genlist_item_append(genlist, ad->paswd_itc, pinpopup,
1100                                 NULL, ELM_GENLIST_ITEM_NONE, _gl_pswd_check_box_sel, (void *)ad );
1101         }
1102
1103         btn1 = elm_button_add(pinpopup);
1104         elm_object_style_set(btn1, "popup");
1105         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
1106         elm_object_part_content_set(pinpopup, "button1", btn1);
1107         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
1108                         (void *)pop->resp_data2);
1109
1110         btn2 = elm_button_add(pinpopup);
1111         elm_object_style_set(btn2, "popup");
1112         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
1113         elm_object_part_content_set(pinpopup, "button2", btn2);
1114         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
1115                         (void *)pop->resp_data1);
1116 #if defined(GENLIST_REALIZATION_MOTE_SET)
1117         elm_genlist_realization_mode_set(genlist, EINA_TRUE);
1118 #endif
1119         evas_object_show(genlist);
1120         elm_object_content_set(pinpopup, genlist);
1121
1122         __set_parent_rotate_angle(ad);
1123         evas_object_show(pinpopup);
1124         evas_object_show(win);
1125         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
1126
1127         __WFD_APP_FUNC_EXIT__;
1128         return pinpopup;
1129 }
1130
1131
1132 void _replace_int(char *haystack, int size, char *niddle, int value)
1133 {
1134         __WFD_APP_FUNC_ENTER__;
1135         char*buf = NULL;
1136         char *p = NULL;
1137         char *q = NULL;
1138
1139         if (haystack == NULL || niddle == NULL || size <= 1)
1140                 return;
1141
1142         buf = g_strdup(haystack);
1143         p = strstr(buf, niddle);
1144         if (p==NULL) {
1145                 free(buf);
1146                 return;
1147         }
1148         q = p + strlen(niddle);
1149         *p = '\0';
1150
1151         snprintf(haystack, size-1, "%s%d%s", buf, value, q);
1152         free(buf);
1153         __WFD_APP_FUNC_EXIT__;
1154 }
1155
1156 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2)
1157 {
1158         __WFD_APP_FUNC_ENTER__;
1159         char text[WFD_POP_STR_MAX_LEN] = {0, };
1160
1161         strncpy(text, format_str, WFD_POP_STR_MAX_LEN-1);
1162         _replace_int(text, WFD_POP_STR_MAX_LEN, "%d", PD_2);
1163         _replace_int(text, WFD_POP_STR_MAX_LEN, "%2$d", PD_2);
1164         snprintf(buf, buf_len-1, text, SD_1);
1165         __WFD_APP_FUNC_EXIT__;
1166 }
1167
1168
1169 /**
1170  *      This function let the app create a popup
1171  *      @return   void
1172  *      @param[in] type the type of popup
1173  *      @param[in] userdata the pointer to the data which will be used
1174  */
1175 void wfd_prepare_popup(int type, void *user_data)
1176 {
1177         __WFD_APP_FUNC_ENTER__;
1178         wfd_appdata_t *ad = wfd_get_appdata();
1179         wfd_popup_t *pop = ad->popup_data;
1180         wfd_connection_info_s *connection = ad->connection;
1181         char text[WFD_POP_STR_MAX_LEN+1] = {0, };
1182         char text1[WFD_POP_STR_MAX_LEN+1] = {0, };
1183         wfd_destroy_popup();
1184         char *peer_name;
1185         peer_name = elm_entry_utf8_to_markup(connection->peer_name);
1186
1187         memset(pop, 0, sizeof(wfd_popup_t));
1188
1189         pop->type = type;
1190
1191         switch (pop->type) {
1192         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
1193
1194                 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1195                                 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1196                                 peer_name, WFD_POP_TIMER_120);
1197
1198                 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_SK2_OK"));
1199                 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_WIFI_SK_CANCEL"));
1200                 pop->timeout = WFD_POP_TIMER_120;
1201                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
1202                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1203
1204                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1205                 break;
1206
1207         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
1208                 snprintf(pop->text, sizeof(pop->text),
1209                                 _("IDS_WIFI_BODY_PS_IS_REQUESTING_A_WI_FI_DIRECT_CONNECTION_ALLOW_Q"),
1210                                 peer_name);
1211                 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_BUTTON_ALLOW"));
1212                 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1213                 pop->timeout = WFD_POP_TIMER_120;
1214                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
1215                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1216
1217                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
1218                 break;
1219
1220         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
1221                 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1222                                         _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1223                                         peer_name, WFD_POP_TIMER_120);
1224                 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_BR_SK_OK"));
1225                 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1226                 pop->timeout = WFD_POP_TIMER_120;
1227                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
1228                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1229
1230                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1231                 break;
1232
1233         case /* MT */ WFD_POP_PROG_CONNECT:
1234                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WIFI_BODY_CONNECTING_ING"));
1235                 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_BR_SK_CANCEL"));
1236                 pop->timeout = WFD_POP_TIMER_120;
1237                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
1238
1239                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
1240                 break;
1241
1242         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
1243                 _replace_1PS_2PD((char *)text, sizeof(text),
1244                                                 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1245                                                 peer_name, WFD_POP_TIMER_120);
1246
1247                 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s",
1248                                 text, _("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"));
1249
1250                 snprintf(pop->text, sizeof(pop->text), text1, connection->peer_name);
1251
1252                 snprintf(pop->label1, sizeof(pop->label1), "%s", _("IDS_WIFI_SK_CONNECT"));
1253                 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1254                 pop->timeout = WFD_POP_TIMER_120;
1255                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
1256                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1257
1258                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
1259                 break;
1260
1261         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
1262                 _replace_1PS_2PD((char *)text, sizeof(text),
1263                                 _("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1264                                 peer_name, WFD_POP_TIMER_120);
1265
1266                 snprintf(text1, WFD_POP_STR_MAX_LEN, "%s %s %s",
1267                                 text,
1268                                 "<br>",
1269                                 _("IDS_WIFI_POP_PIN_CODE_PS"));
1270                 snprintf(pop->text, sizeof(pop->text), text1, connection->wps_pin);
1271
1272                 snprintf(pop->label2, sizeof(pop->label2), "%s", _("IDS_BR_SK_CANCEL"));
1273                 pop->timeout = WFD_POP_TIMER_120;
1274                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1275
1276                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1277                 break;
1278
1279         case WFD_POP_PROG_CONNECT_CANCEL:
1280                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_BR_SK_CANCEL"));
1281                 pop->timeout = WFD_POP_TIMER_120;
1282                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
1283                 break;
1284
1285         default:
1286                 break;
1287         }
1288
1289         /* feedback play */
1290         int ret = -1;
1291         ret = feedback_play(FEEDBACK_PATTERN_GENERAL);
1292         if (ret != FEEDBACK_ERROR_NONE) {
1293                 WFD_APP_LOG(WFD_APP_LOG_ERROR,"feedback_play error : %d\n", ret);
1294         }
1295         WFD_IF_FREE_MEM(peer_name);
1296         __WFD_APP_FUNC_EXIT__;
1297         return;
1298 }