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