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