Tizen directory path migration
[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         int resp = (int) data;
82         char msg[WFD_POP_STR_MAX_LEN] = {0};
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                         snprintf(msg, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
100                                                         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                         snprintf(msg, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
152                                                         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                         snprintf(msg, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
164                                                         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
253         if (pb_timer) {
254                 ecore_timer_del(pb_timer);
255                 pb_timer = NULL;
256         }
257         __WFD_APP_FUNC_EXIT__;
258         return;
259 }
260
261 /**
262  *      This function let the app create a popup which includes no button
263  *      @return   popup
264  *      @param[in] win the window object
265  *      @param[in] pop the pointer to the prepared popup
266  */
267 static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
268 {
269         __WFD_APP_FUNC_ENTER__;
270
271         wfd_appdata_t *ad = wfd_get_appdata();
272         Evas_Object *popup;
273
274         popup = elm_popup_add(win);
275         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
276         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, NULL);
277         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
278 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
279         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
281         elm_popup_timeout_set(popup, pop->timeout);
282
283         evas_object_show(popup);
284         evas_object_show(win);
285
286         __WFD_APP_FUNC_EXIT__;
287         return popup;
288 }
289
290 /**
291  *      This function let the app create a popup which includes one button
292  *      @return   popup
293  *      @param[in] win the window object
294  *      @param[in] pop the pointer to the prepared popup
295  */
296 static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
297 {
298         __WFD_APP_FUNC_ENTER__;
299         Evas_Object *popup = NULL;
300         Evas_Object *btn = NULL;
301         wfd_appdata_t *ad = wfd_get_appdata();
302
303         popup = elm_popup_add(win);
304         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
305         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data1);
306         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
307 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
308         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
309         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
310
311         btn = elm_button_add(popup);
312         elm_object_style_set(btn, "popup");
313         elm_object_domain_translatable_text_set(btn, PACKAGE, pop->label1);
314         elm_object_part_content_set(popup, "button1", btn);
315         evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) pop->resp_data1);
316
317         evas_object_show(popup);
318         evas_object_show(win);
319
320         __WFD_APP_FUNC_EXIT__;
321         return popup;
322 }
323
324 /**
325  *      This function let the app create a popup which includes two buttons
326  *      @return   popup
327  *      @param[in] win the window object
328  *      @param[in] pop the pointer to the prepared popup
329  */
330 static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
331 {
332         __WFD_APP_FUNC_ENTER__;
333         Evas_Object *popup = NULL;
334         Evas_Object *btn1 = NULL, *btn2 = NULL;
335         wfd_appdata_t *ad = wfd_get_appdata();
336
337         popup = elm_popup_add(win);
338         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
339         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
340         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
341 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
342         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
343         elm_object_domain_translatable_part_text_set(popup, "title,text",
344                         PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
345         elm_object_domain_translatable_text_set(popup, PACKAGE, pop->text);
346
347         btn1 = elm_button_add(popup);
348         elm_object_style_set(btn1, "popup");
349         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
350         elm_object_part_content_set(popup, "button1", btn1);
351         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
352                 (void *) pop->resp_data2);
353
354         btn2 = elm_button_add(popup);
355         elm_object_style_set(btn2, "popup");
356         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
357         elm_object_part_content_set(popup, "button2", btn2);
358         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
359                 (void *) pop->resp_data1);
360
361         evas_object_show(popup);
362         evas_object_show(win);
363
364         __WFD_APP_FUNC_EXIT__;
365         return popup;
366 }
367
368 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
369 {
370         __WFD_APP_FUNC_ENTER__;
371         wfd_appdata_t *ad = wfd_get_appdata();
372
373         if (ad->popup) {
374                 evas_object_del(ad->popup);
375                 ad->popup = NULL;
376         }
377
378         if (ad->win) {
379                 evas_object_hide(ad->win);
380         }
381
382         __WFD_APP_FUNC_EXIT__;
383 }
384
385 Evas_Object *wfd_draw_pop_type_auto_deactivation(Evas_Object *win,  void *userdata)
386 {
387         __WFD_APP_FUNC_ENTER__;
388
389         Evas_Object *popup = NULL;
390         Evas_Object *btn = NULL;
391         char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
392         wfd_appdata_t *ad = wfd_get_appdata();
393
394         popup = elm_popup_add(win);
395         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
396         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _wfd_ug_automatic_turn_off_popup_cb, userdata);
397         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
398 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
399         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
400         elm_object_domain_translatable_part_text_set(popup, "title,text",
401                         PACKAGE, "IDS_WIFI_BODY_WI_FI_DIRECT_ABB");
402         snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
403                 "IDS_WIFI_POP_THERE_HAS_BEEN_NO_ACTIVITY_FOR_PD_MINUTES_SINCE_WI_FI_DIRECT_WAS_ENABLED_MSG", 5);
404         elm_object_domain_translatable_text_set(popup, PACKAGE, popup_text);
405
406         btn = elm_button_add(popup);
407         elm_object_style_set(btn, "popup");
408         elm_object_domain_translatable_text_set(btn, PACKAGE, "IDS_BR_SK_OK");
409         elm_object_part_content_set(popup, "button1", btn);
410         evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, userdata);
411
412         evas_object_show(popup);
413         evas_object_show(win);
414
415         __WFD_APP_FUNC_EXIT__;
416         return popup;
417 }
418
419 /**
420  *      This function let the ug make a change callback for password input
421  *      @return   void
422  *      @param[in] data the pointer to the main data structure
423  *      @param[in] obj the pointer to the evas object
424  *      @param[in] event_info the pointer to the event information
425  */
426 static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
427 {
428         __WFD_APP_FUNC_ENTER__;
429         wfd_appdata_t *ad = wfd_get_appdata();
430         wfd_connection_info_s *connection = ad->connection;
431
432         Ecore_IMF_Context *imf_context = NULL;
433         imf_context = (Ecore_IMF_Context *) ad->pin_entry;
434
435         if (NULL == imf_context) {
436                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error!!! Ecore_IMF_Context is NULL!!");
437                 return;
438         }
439
440         char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
441         if (NULL != txt) {
442                 WFD_APP_LOG(WFD_APP_LOG_LOW, "* text [%s], len=[%d]", txt, strlen(txt));
443                 strncpy(connection->wps_pin, txt, sizeof(connection->wps_pin) - 1);
444                 WFD_IF_FREE_MEM(txt);
445         } else {
446                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Err!");
447         }
448
449         __WFD_APP_FUNC_EXIT__;
450 }
451
452 /**
453  *      This function let the app make a callback for progressbar timer
454  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
455  *      @param[in] data the pointer to the wps structure
456  */
457 static Eina_Bool _fn_pb_timer(void *data)
458 {
459         int step = 0;
460         double value = 0.0;
461         char time_label[32] = {0};
462         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
463
464         if (NULL == wps_display_popup) {
465                 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Param is NULL.\n");
466                 return ECORE_CALLBACK_CANCEL;
467         }
468
469         Evas_Object *progressbar = NULL;
470         Evas_Object *time = NULL;
471
472         progressbar = wps_display_popup->progressbar;
473         time = wps_display_popup->time;
474         value = elm_progressbar_value_get(progressbar);
475
476         wps_display_popup->step++;
477         step = wps_display_popup->step;
478         value = ((double)step) / WFD_POP_TIMER_120;
479
480         if (value >= 1.0) {
481                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Progress end.\n");
482                 if (pb_timer) {
483                         ecore_timer_del(pb_timer);
484                         pb_timer = NULL;
485                 }
486                 wfd_destroy_popup();
487                 return ECORE_CALLBACK_CANCEL;
488         }
489
490         elm_progressbar_value_set(progressbar, value);
491         WFD_APP_LOG(WFD_APP_LOG_LOW, "step: %d, value: %f\n", wps_display_popup->step, value);
492
493         /* show the time label */
494         if (step < 60) {
495                 if (step < 10) {
496                         snprintf(time_label, 32, "00:0%d", step);
497                 } else {
498                         snprintf(time_label, 32, "00:%d", step);
499                 }
500         } else {
501                 if (step%60 < 10) {
502                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
503                 } else {
504                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
505                 }
506         }
507
508         char *remaining_time_str = g_strdup_printf(
509                         "<font_size=40><align=center>%s</align></font_size>", time_label);
510         elm_object_text_set(time, remaining_time_str);
511         g_free(remaining_time_str);
512
513         return ECORE_CALLBACK_RENEW;
514 }
515
516 static Eina_Bool _keypad_popup_timer_cb(void *data)
517 {
518         __WFD_APP_FUNC_ENTER__;
519
520         char msg1[WFD_POP_STR_MAX_LEN] = {0};
521         char msg2[WFD_POP_STR_MAX_LEN] = {0};
522         char label_str[WFD_POP_STR_MAX_LEN] = {0, };
523
524         Evas_Object *label = (Evas_Object*) data;
525         wfd_appdata_t *ad = wfd_get_appdata();
526         wfd_connection_info_s *connection = ad->connection;
527         WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters(ad)\n");
528         WFD_RETV_IF(NULL == label, FALSE, "NULL parameters(label)\n");
529         if (NULL == ad->popup) {
530                 keypad_popup_timeout = 0;
531                 return ECORE_CALLBACK_CANCEL;
532         }
533
534         keypad_popup_timeout --;
535
536         if (keypad_popup_timeout > 0) {
537                 _replace_1PS_2PD((char *)msg1, sizeof(msg1),
538                                 D_("IDS_ST_BODY_CONNECT_WITH_PS_IN_PD_SECS_ABB"),
539                                 connection->peer_name, keypad_popup_timeout);
540
541                 snprintf(msg2, sizeof(msg2), D_("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
542                                                 connection->peer_name);
543                 snprintf(label_str, sizeof(label_str), "%s %s", msg1, msg2);
544                 elm_object_domain_translatable_text_set(label, PACKAGE, label_str);
545
546         }
547
548         if (keypad_popup_timeout <= 0) {
549                 wfd_destroy_popup();
550                 keypad_popup_timeout = 0;
551                 __WFD_APP_FUNC_EXIT__;
552                 return ECORE_CALLBACK_CANCEL;
553         }
554
555         __WFD_APP_FUNC_EXIT__;
556         return ECORE_CALLBACK_RENEW;
557 }
558
559 /* This callback is for showing(hiding) X marked button. */
560 /*static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
561 {
562         if (elm_object_focus_get(obj)) {
563                 if (elm_entry_is_empty(obj))
564                         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
565                 else
566                         elm_object_signal_emit(data, "elm,state,eraser,show", "");
567         }
568 }*/
569
570 /* Focused callback will show X marked button and hide guidetext. */
571 /*static void _focused_cb(void *data, Evas_Object *obj, void *event_info)
572 {
573         if (!elm_entry_is_empty(obj))
574                 elm_object_signal_emit(data, "elm,state,eraser,show", "");
575         elm_object_signal_emit(data, "elm,state,rename,hide", "");
576 }*/
577
578 /*  Unfocused callback will show guidetext and hide X marked button. */
579 /*static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info)
580 {
581         elm_object_signal_emit(data, "elm,state,eraser,hide", "");
582         elm_object_signal_emit(data, "elm,state,rename,show", "");
583 }*/
584
585 /* When X marked button clicked, make string as empty. */
586 /*static void _eraser_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
587 {
588         elm_object_focus_set(data, EINA_TRUE);
589         elm_entry_entry_set(data, "");
590 }*/
591
592 /**
593  *      This function let the app create a edit filed
594  *      @return   edit filed
595  *      @param[in] parent the parent object
596  *      @param[in] title the pointer to the title of edit field
597  *      @param[in] guide the pointer to the text of guide
598  *      @param[in] single_line whether it can support single line
599  *      @param[in] is_editable whether it is avaliable to edit
600  */
601 /*static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
602 {
603         assertm_if(NULL == parent, "parent is NULL!!");
604
605         Evas_Object *layout = elm_layout_add(parent);
606         assertm_if(NULL == layout, "layout is NULL!!");
607
608         if (title && title[0] != '\0') {
609                 elm_layout_theme_set(layout, "layout", "dialogue/editfield/title", "default");
610                 elm_object_part_text_set(layout, "elm.text", title);
611         } else {
612                 elm_layout_theme_set(layout, "layout", "dialogue/editfield", "default");
613         }
614
615         Evas_Object *entry = elm_entry_add(layout);
616         assertm_if(NULL == entry, "entry is NULL!!");
617
618         if (guide && guide[0] != '\0') {
619                 elm_object_part_text_set(layout, "elm.guidetext", guide);
620         }
621
622         evas_object_smart_callback_add(entry, "changed", _changed_cb, layout);
623         evas_object_smart_callback_add(entry, "focused", _focused_cb, layout);
624         evas_object_smart_callback_add(entry, "unfocused", _unfocused_cb, layout);
625
626         elm_object_part_content_set(layout, "elm.icon.entry", entry);
627         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
628         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
629
630         elm_entry_single_line_set(entry, single_line);
631         elm_entry_scrollable_set(entry, single_line);
632
633         Evas_Object *button = elm_button_add(parent);
634         elm_object_style_set(button, "editfield_clear");
635         elm_object_part_content_set(layout, "elm.icon.eraser", button);
636         evas_object_smart_callback_add(button, "clicked", _eraser_btn_clicked_cb, entry);
637         return layout;
638 }*/
639
640 /**
641  *      This function let the app create a display popup
642  *      @return   display popup
643  *      @param[in] win the window object
644  *      @param[in] pop the pointer to the prepared popup
645  */
646 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
647 {
648         __WFD_APP_FUNC_ENTER__;
649         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_draw_pop_type_display\n");
650
651         Evas_Object *popup = NULL;
652         Evas_Object *progressbar = NULL;
653         Evas_Object *time = NULL;
654         Evas_Object *layout;
655         static wfd_wps_display_popup_t wps_display_popup;
656         wfd_appdata_t *ad = wfd_get_appdata();
657
658         popup = elm_popup_add(win);
659         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
660         evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, mouseup_cb, ad);
661 //      evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN, keydown_cb, ad);
662         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
663         elm_object_domain_translatable_part_text_set(popup, "title,text",
664                          PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
665
666         layout = elm_layout_add(popup);
667         if (layout == NULL) {
668                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Layout failed so returning !!");
669                 return NULL;
670         }
671
672         elm_layout_file_set(layout, WFD_EDJ_POPUP_PATH, "popup_wps_pin_layout");
673         elm_object_domain_translatable_part_text_set(layout, "elm.text.description",
674                          PACKAGE, pop->text);
675         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
676
677         /* add progressbar */
678         progressbar = elm_progressbar_add(layout);
679         elm_object_style_set(progressbar, "list_progress");
680         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
681         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
682         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
683         elm_progressbar_value_set(progressbar, 0.0);
684         evas_object_show(progressbar);
685
686         /* add time */
687         time = elm_label_add(layout);
688         elm_label_line_wrap_set(time, ELM_WRAP_MIXED);
689         elm_object_text_set(time, D_("<font_size=40><align=center>00:00</align></font_size>"));
690         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
691         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, EVAS_HINT_FILL);
692         evas_object_show(time);
693
694         elm_object_part_content_set(layout, "slider", progressbar);
695         elm_object_part_content_set(layout, "timer_label", time);
696
697
698         /* start progressbar timer */
699         wps_display_popup.step = 0;
700         wps_display_popup.progressbar = progressbar;
701         wps_display_popup.time = time;
702         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
703
704         /* add buttons */
705         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
706                 Evas_Object *btn2 = NULL;
707                 btn2 = elm_button_add(popup);
708                 elm_object_style_set(btn2, "popup");
709                 elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label2);
710                 elm_object_part_content_set(popup, "button1", btn2);
711                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
712                         (void *) pop->resp_data2);
713                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) pop->resp_data2);
714         }
715
716         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES || pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_PBC_YES ) {
717                 Evas_Object *btn1 = NULL;
718                 btn1 = elm_button_add(popup);
719                 elm_object_style_set(btn1, "popup");
720                 elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label1);
721                 elm_object_part_content_set(popup, "button2", btn1);
722                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
723                         (void *) pop->resp_data1);
724                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, __popup_resp_cb, (void *) 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
792                 elm_object_focus_set(entry, EINA_FALSE);
793         }
794 }
795
796 static char *__wfd_main_desc_label_get(void *data, Evas_Object *obj,
797                 const char *part)
798 {
799         __WFD_APP_FUNC_ENTER__;
800         if (obj == NULL || part == NULL) {
801                 return NULL;
802         }
803         WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_rename desc\n");
804         char buf[WFD_POP_STR_MAX_LEN] = {0, };
805         char msg1[WFD_POP_STR_MAX_LEN] = {0, };
806         char msg2[WFD_POP_STR_MAX_LEN] = {0, };
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                 snprintf(msg2, WFD_POP_STR_MAX_LEN,
821                                 D_("IDS_WIFI_POP_ENTER_PIN_TO_CONNECT_TO_PS"),
822                                 connection->peer_name);
823
824                 WFD_APP_LOG(WFD_APP_LOG_LOW, "string %s %s", msg1, msg2);
825                 snprintf(buf, WFD_POP_STR_MAX_LEN,
826                                 "<font_size=30>%s %s</font_size>",
827                                 msg1, msg2);
828                 __WFD_APP_FUNC_EXIT__;
829                 return g_strdup(buf);
830         }
831         __WFD_APP_FUNC_EXIT__;
832         return NULL;
833 }
834
835 static Evas_Object *__wfd_pin_entry_icon_get(void *data, Evas_Object *obj,
836                 const char *part)
837 {
838         __WFD_APP_FUNC_ENTER__;
839         if (obj == NULL || part == NULL) {
840                 return NULL;
841         }
842         wfd_appdata_t *ad = wfd_get_appdata();
843         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
844         Evas_Object *entry = NULL;
845         Evas_Object *button = NULL;
846         Ecore_IMF_Context *imf_context;
847         if (g_strcmp0(part, "elm.icon.entry")) {
848                 __WFD_APP_FUNC_EXIT__;
849                 return NULL;
850         }
851         static Elm_Entry_Filter_Accept_Set accept_set = {"0123456789", NULL};
852         entry = elm_entry_add(obj);
853         elm_entry_single_line_set(entry, EINA_TRUE);
854         elm_object_style_set(entry, "editfield");
855         elm_entry_scrollable_set(entry, EINA_TRUE);
856
857         eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
858         evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
859         evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
860         elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
861         elm_entry_password_set(entry, EINA_TRUE);
862         elm_entry_prediction_allow_set(entry, EINA_FALSE);
863
864         elm_entry_markup_filter_append(entry,
865                         elm_entry_filter_accept_set,&accept_set);
866         elm_entry_input_panel_layout_set(entry,
867                         ELM_INPUT_PANEL_LAYOUT_DATETIME);
868         elm_object_signal_emit(entry, "elm,action,hide,search_icon", "");
869         elm_object_domain_translatable_part_text_set(entry, "elm.guide",
870                          PACKAGE, D_("IDS_WIFI_POP_PIN"));
871         elm_entry_input_panel_return_key_autoenabled_set(entry,EINA_TRUE);
872         elm_entry_input_panel_return_key_type_set(entry,
873                         ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
874
875         ad->pin_entry = entry;
876         imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
877         if (imf_context) {
878                 ecore_imf_context_input_panel_return_key_type_set(imf_context,
879                 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
880         }
881
882         button = elm_button_add(obj);
883         elm_object_style_set(button, "search_clear");
884         elm_object_focus_allow_set(button, EINA_FALSE);
885         elm_object_part_content_set(entry, "elm.swallow.clear", button);
886         evas_object_smart_callback_add(button, "clicked",
887                         __popup_eraser_clicked_cb, entry);
888
889         elm_object_signal_emit (entry, "elm,action,hide,search_icon", "");
890         evas_object_smart_callback_add(entry, "changed",
891                         _entry_changed_cb, NULL);
892         evas_object_smart_callback_add(entry, "preedit,changed",
893                         _entry_changed_cb, NULL);
894         evas_object_smart_callback_add(entry, "focused",
895                         _entry_focused_cb, NULL);
896         evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN,
897                         _entry_keydown_cb, ad);
898
899         elm_object_content_set(obj,entry);
900         evas_object_show(entry);
901         evas_object_smart_callback_add(entry, "changed", _smart_ime_cb, NULL);
902         elm_object_focus_set(entry, EINA_TRUE);
903         __WFD_APP_FUNC_EXIT__;
904         return entry;
905 }
906
907 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
908 {
909         __WFD_APP_FUNC_ENTER__;
910         if (obj == NULL || data == NULL) {
911                 return;
912         }
913         Eina_Bool state = elm_check_state_get(obj);
914         if (state) {
915                 elm_entry_password_set((Evas_Object *)data, EINA_FALSE);
916         } else {
917                 elm_entry_password_set((Evas_Object *)data, EINA_TRUE);
918         }
919         __WFD_APP_FUNC_EXIT__;
920 }
921
922 static void _gl_pswd_check_box_sel(void *data, Evas_Object *obj, void *ei)
923 {
924         __WFD_APP_FUNC_ENTER__;
925         Elm_Object_Item *item = NULL;
926         item = (Elm_Object_Item *)ei;
927         if (item == NULL) {
928                 return;
929         }
930         wfd_appdata_t *ad = wfd_get_appdata();
931         if (ad == NULL) {
932                 WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter(NULL)\n");
933                 return;
934         }
935         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.left");
936         elm_genlist_item_selected_set(item, EINA_FALSE);
937         Eina_Bool state = elm_check_state_get(ck);
938         elm_check_state_set(ck, !state);
939         if (ad) {
940                 _chk_changed_cb(ad->pin_entry, ck, NULL);
941         }
942         __WFD_APP_FUNC_EXIT__;
943 }
944
945 static char *__wfd_password_label(void *data, Evas_Object *obj, const char *part)
946 {
947         __WFD_APP_FUNC_ENTER__;
948
949         if (data == NULL || part == NULL) {
950                 return NULL;
951         }
952         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
953
954         if (!strcmp("elm.text", part)) {
955                 __WFD_APP_FUNC_EXIT__;
956                 return g_strdup(" Show password");
957         }
958         __WFD_APP_FUNC_EXIT__;
959         return NULL;
960 }
961
962 static Evas_Object *__wfd_password_check(void *data, Evas_Object *obj,
963                 const char *part)
964 {
965         __WFD_APP_FUNC_ENTER__;
966         if (obj == NULL || part == NULL) {
967                 return NULL;
968         }
969         wfd_appdata_t *ad = wfd_get_appdata();
970         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
971         Evas_Object *check = NULL;
972
973         WFD_APP_LOG(WFD_APP_LOG_LOW, "Part %s", part);
974
975         if (!strcmp("elm.swallow.icon", part)) {
976                 check = elm_check_add(obj);
977                 evas_object_propagate_events_set(check, EINA_FALSE);
978                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
979                 evas_object_size_hint_weight_set(check,
980                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
981                 evas_object_smart_callback_add(check, "changed",
982                                 _chk_changed_cb, ad->pin_entry);
983                 elm_object_focus_allow_set(check, EINA_FALSE);
984                 __WFD_APP_FUNC_EXIT__;
985                 return check;
986         }
987         __WFD_APP_FUNC_EXIT__;
988         return check;
989 }
990
991
992 /**
993  *      This function let the app create a keypad popup
994  *      @return   keypad popup
995  *      @param[in] win the window object
996  *      @param[in] pop the pointer to the prepared popup
997  */
998 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
999 {
1000         __WFD_APP_FUNC_ENTER__;
1001         wfd_appdata_t *ad = wfd_get_appdata();
1002         WFD_RETV_IF(ad == NULL, NULL, "Incorrect parameter(NULL)\n");
1003         wfd_connection_info_s *connection = ad->connection;
1004         WFD_RETV_IF(connection == NULL, NULL, "Incorrect parameter(NULL)\n");
1005
1006         Evas_Object *pinpopup = NULL;
1007         Evas_Object *btn1 = NULL, *btn2 = NULL;
1008         Evas_Object *genlist = NULL;
1009         Elm_Object_Item *git = NULL;
1010
1011         ad->timeout = pop->timeout;
1012
1013         pinpopup = elm_popup_add(ad->layout);
1014         elm_popup_align_set(pinpopup, ELM_NOTIFY_ALIGN_FILL, 1.0);
1015         eext_object_event_callback_add(pinpopup, EEXT_CALLBACK_BACK, eext_popup_back_cb,
1016                         NULL);
1017         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1018         elm_object_domain_translatable_part_text_set(pinpopup, "title,text",
1019                          PACKAGE, D_("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB"));
1020
1021         genlist = elm_genlist_add(pinpopup);
1022         elm_genlist_homogeneous_set(genlist, EINA_TRUE);
1023         evas_object_size_hint_weight_set(genlist,
1024                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1025         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
1026         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1027         elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);
1028
1029         /* Entry genlist item */
1030         ad->pin_desc_itc = elm_genlist_item_class_new();
1031         if(ad->pin_desc_itc != NULL) {
1032                 ad->pin_desc_itc->item_style = WFD_GENLIST_MULTILINE_TEXT_STYLE;
1033                 ad->pin_desc_itc->func.text_get = __wfd_main_desc_label_get;
1034                 ad->pin_desc_itc->func.content_get = NULL;
1035                 ad->pin_desc_itc->func.state_get = NULL;
1036                 ad->pin_desc_itc->func.del = NULL;
1037
1038                 git = elm_genlist_item_append(genlist, ad->pin_desc_itc, ad, NULL,
1039                                 ELM_GENLIST_ITEM_NONE, NULL, NULL);
1040                 if(git != NULL)
1041                         elm_genlist_item_select_mode_set(git,
1042                                                  ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1043
1044                 keypad_popup_timeout = pop->timeout;
1045                 keypad_popup_timer = ecore_timer_add(1, _keypad_popup_timer_cb,
1046                                 ad->pin_desc_itc);
1047         }
1048
1049         ad->pin_entry_itc = elm_genlist_item_class_new();
1050         if(ad->pin_entry_itc != NULL) {
1051                 ad->pin_entry_itc->item_style = "entry";
1052                 ad->pin_entry_itc->func.text_get = NULL;
1053                 ad->pin_entry_itc->func.content_get = __wfd_pin_entry_icon_get;
1054                 ad->pin_entry_itc->func.state_get = NULL;
1055                 ad->pin_entry_itc->func.del = NULL;
1056
1057                 elm_genlist_item_append(genlist, ad->pin_entry_itc, pinpopup,
1058                                 NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
1059         }
1060
1061         ad->paswd_itc = elm_genlist_item_class_new();
1062         if(ad->paswd_itc != NULL) {
1063                 ad->paswd_itc->item_style = WFD_GENLIST_1LINE_TEXT_ICON_STYLE;
1064                 ad->paswd_itc->func.text_get = __wfd_password_label;
1065                 ad->paswd_itc->func.content_get = __wfd_password_check;
1066                 ad->paswd_itc->func.state_get = NULL;
1067                 ad->paswd_itc->func.del = NULL;
1068
1069                 elm_genlist_item_append(genlist, ad->paswd_itc, pinpopup,
1070                                 NULL, ELM_GENLIST_ITEM_NONE, _gl_pswd_check_box_sel, (void *)ad );
1071         }
1072
1073         btn1 = elm_button_add(pinpopup);
1074         elm_object_style_set(btn1, "popup");
1075         elm_object_domain_translatable_text_set(btn1, PACKAGE, pop->label2);
1076         elm_object_part_content_set(pinpopup, "button1", btn1);
1077         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
1078                         (void *)pop->resp_data2);
1079
1080         btn2 = elm_button_add(pinpopup);
1081         elm_object_style_set(btn2, "popup");
1082         elm_object_domain_translatable_text_set(btn2, PACKAGE, pop->label1);
1083         elm_object_part_content_set(pinpopup, "button2", btn2);
1084         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
1085                         (void *)pop->resp_data1);
1086 #if defined(GENLIST_REALIZATION_MOTE_SET)
1087         elm_genlist_realization_mode_set(genlist, EINA_TRUE);
1088 #endif
1089         evas_object_show(genlist);
1090         elm_object_content_set(pinpopup, genlist);
1091
1092         evas_object_show(pinpopup);
1093         evas_object_show(win);
1094         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
1095
1096         __WFD_APP_FUNC_EXIT__;
1097         return pinpopup;
1098 }
1099
1100
1101 void _replace_int(char *haystack, int size, char *niddle, int value)
1102 {
1103         __WFD_APP_FUNC_ENTER__;
1104         char*buf = NULL;
1105         char *p = NULL;
1106         char *q = NULL;
1107
1108         if (haystack == NULL || niddle == NULL || size <= 1)
1109                 return;
1110
1111         buf = g_strdup(haystack);
1112         p = strstr(buf, niddle);
1113         if (p==NULL) {
1114                 free(buf);
1115                 return;
1116         }
1117         q = p + strlen(niddle);
1118         *p = '\0';
1119
1120         snprintf(haystack, size-1, "%s%d%s", buf, value, q);
1121         free(buf);
1122         __WFD_APP_FUNC_EXIT__;
1123 }
1124
1125 void _replace_1PS_2PD(char *buf, int buf_len, char *format_str, char* SD_1, int PD_2)
1126 {
1127         __WFD_APP_FUNC_ENTER__;
1128         char text[WFD_POP_STR_MAX_LEN] = {0, };
1129
1130         strncpy(text, format_str, WFD_POP_STR_MAX_LEN-1);
1131         _replace_int(text, WFD_POP_STR_MAX_LEN, "%d", PD_2);
1132         _replace_int(text, WFD_POP_STR_MAX_LEN, "%2$d", PD_2);
1133         snprintf(buf, buf_len-1, text, SD_1);
1134         __WFD_APP_FUNC_EXIT__;
1135 }
1136
1137
1138 /**
1139  *      This function let the app create a popup
1140  *      @return   void
1141  *      @param[in] type the type of popup
1142  *      @param[in] userdata the pointer to the data which will be used
1143  */
1144 void wfd_prepare_popup(int type, void *user_data)
1145 {
1146         __WFD_APP_FUNC_ENTER__;
1147         wfd_appdata_t *ad = wfd_get_appdata();
1148         wfd_popup_t *pop = ad->popup_data;
1149         wfd_connection_info_s *connection = ad->connection;
1150         char text[WFD_POP_STR_MAX_LEN+1] = {0, };
1151         char text1[WFD_POP_STR_MAX_LEN+1] = {0, };
1152         wfd_destroy_popup();
1153         char *peer_name;
1154         peer_name = elm_entry_utf8_to_markup(connection->peer_name);
1155
1156         memset(pop, 0, sizeof(wfd_popup_t));
1157
1158         pop->type = type;
1159
1160         switch (pop->type) {
1161         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
1162
1163                 _replace_1PS_2PD((char *)pop->text, sizeof(pop->text),
1164                                 D_("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS"),
1165                                 peer_name, WFD_POP_TIMER_120);
1166
1167                 snprintf(pop->label1, sizeof(pop->label1), "%s", D_("IDS_WIFI_SK2_OK"));
1168                 snprintf(pop->label2, sizeof(pop->label2), "%s", D_("IDS_WIFI_SK_CANCEL"));
1169                 pop->timeout = WFD_POP_TIMER_120;
1170                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
1171                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
1172
1173                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
1174                 break;
1175
1176         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
1177                 snprintf(pop->text, sizeof(pop->text),
1178                                 D_("IDS_WIFI_BODY_PS_IS_REQUESTING_A_WI_FI_DIRECT_CONNECTION_ALLOW_Q"),
1179                                 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 }