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