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