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