Fix bug of invitation behavior
[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 }
404
405 /**
406  *      This function let the app make a callback for progressbar timer
407  *      @return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
408  *      @param[in] data the pointer to the wps structure
409  */
410 static Eina_Bool _fn_pb_timer(void *data)
411 {
412         int step = 0;
413         double value = 0.0;
414         char time_label[32] = {0};
415         wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;
416
417         if (NULL == wps_display_popup) {
418                 WDPOP_LOGE( "Param is NULL.\n");
419                 return ECORE_CALLBACK_CANCEL;
420         }
421
422         Evas_Object *progressbar = NULL;
423         Evas_Object *time = NULL;
424
425         progressbar = wps_display_popup->progressbar;
426         time = wps_display_popup->time;
427         value = elm_progressbar_value_get(progressbar);
428
429         if (value >= 1.0) {
430                 WDPOP_LOGE( "Progress end.\n");
431                 if (pb_timer) {
432                         ecore_timer_del(pb_timer);
433                         pb_timer = NULL;
434                 }
435                 wfd_destroy_popup();
436                 return ECORE_CALLBACK_CANCEL;
437         }
438
439         wps_display_popup->step++;
440         step = wps_display_popup->step;
441         value = ((double)step) / WFD_POP_TIMER_120;
442         elm_progressbar_value_set(progressbar, value);
443         WDPOP_LOGD( "step: %d, value: %f\n", wps_display_popup->step, value);
444
445         /* show the time label */
446         if (step < 60) {
447                 if (step < 10) {
448                         snprintf(time_label, 32, "00:0%d", step);
449                 } else {
450                         snprintf(time_label, 32, "00:%d", step);
451                 }
452         } else {
453                 if (step%60 < 10) {
454                         snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
455                 } else {
456                         snprintf(time_label, 32, "0%d:%d", step/60, step%60);
457                 }
458         }
459
460         elm_object_text_set(time, time_label);
461
462         return ECORE_CALLBACK_RENEW;
463 }
464
465 /**
466  *      This function let the app create a edit filed
467  *      @return   edit filed
468  *      @param[in] parent the parent object
469  *      @param[in] title the pointer to the title of edit field
470  *      @param[in] guide the pointer to the text of guide
471  *      @param[in] single_line whether it can support single line
472  *      @param[in] is_editable whether it is avaliable to edit
473  */
474 static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
475 {
476         assertm_if(NULL == parent, "parent is NULL!!");
477
478         Evas_Object *layout = elm_layout_add(parent);
479         assertm_if(NULL == layout, "layout is NULL!!");
480
481         if (title && title[0] != '\0') {
482                 elm_layout_theme_set(layout, "layout", "editfield", "title");
483                 elm_object_part_text_set(layout, "elm.text", title);
484         } else {
485                 elm_layout_theme_set(layout, "layout", "editfield", "default");
486         }
487
488         Evas_Object *entry = elm_entry_add(parent);
489         assertm_if(NULL == entry, "entry is NULL!!");
490
491         elm_object_part_content_set(layout, "elm.swallow.content", entry);
492         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
493
494         if (guide && guide[0] != '\0') {
495                 elm_object_part_text_set(layout, "elm.guidetext", guide);
496         }
497
498         elm_entry_single_line_set(entry, single_line);
499         elm_entry_scrollable_set(entry, single_line);
500         elm_entry_editable_set(entry, is_editable);
501         elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
502         evas_object_show(layout);
503
504         return layout;
505 }
506
507 /**
508  *      This function let the app create a display popup
509  *      @return   display popup
510  *      @param[in] win the window object
511  *      @param[in] pop the pointer to the prepared popup
512  */
513 Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
514 {
515         __WDPOP_LOG_FUNC_ENTER__;
516
517         Evas_Object *popup = NULL;
518         Evas_Object *label = NULL;
519         Evas_Object *progressbar = NULL;
520         Evas_Object *time = NULL;
521         static wfd_wps_display_popup_t wps_display_popup;
522
523         popup = elm_popup_add(win);
524         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);
525
526         Evas_Object *box = elm_box_add(popup);
527         if (!box) {
528                 evas_object_del(popup);
529                 popup = NULL;
530                 return NULL;
531         }
532
533         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
534         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
535         elm_object_part_content_set(popup, NULL, box);
536         evas_object_show(box);
537
538         /* add label */
539         label = elm_label_add(box);
540         elm_object_style_set(label, "popup/default");
541         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
542         elm_object_text_set(label, pop->text);
543         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
544         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.0);
545         elm_box_pack_end(box, label);
546         evas_object_show(label);
547
548         /* add progressbar */
549         progressbar = elm_progressbar_add(box);
550         elm_object_style_set(progressbar, "list_progress");
551         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
552         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.0);
553         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, 0.0);
554         elm_progressbar_value_set(progressbar, 0.0);
555         elm_box_pack_end(box, progressbar);
556         evas_object_show(progressbar);
557
558         /* add time */
559         time = elm_label_add(box);
560         elm_object_style_set(time, "popup/default");
561         elm_object_text_set(time, "00:00");
562         evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
563         evas_object_size_hint_align_set(time, EVAS_HINT_FILL, 0.0);
564         elm_box_pack_end(box, time);
565         evas_object_show(time);
566
567         /* start progressbar timer */
568         wps_display_popup.step = 0;
569         wps_display_popup.progressbar = progressbar;
570         wps_display_popup.time = time;
571         if(pb_timer)
572                 ecore_timer_del(pb_timer);
573         pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);
574
575         /* add buttons */
576         if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES ||
577                 pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_NO) {
578                 Evas_Object *btn1 = NULL;
579                 btn1 = elm_button_add(popup);
580                 elm_object_style_set(btn1, "popup_button/default");
581                 elm_object_text_set(btn1, pop->label1);
582                 elm_object_part_content_set(popup, "button1", btn1);
583                 evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
584                         (void *) pop->resp_data1);
585         }
586
587         if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
588                 Evas_Object *btn2 = NULL;
589                 btn2 = elm_button_add(popup);
590                 elm_object_style_set(btn2, "popup_button/default");
591                 elm_object_text_set(btn2, pop->label2);
592                 elm_object_part_content_set(popup, "button2", btn2);
593                 evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
594                         (void *) pop->resp_data2);
595         }
596
597         elm_object_content_set(popup, box);
598         evas_object_show(popup);
599         evas_object_show(win);
600
601         __WDPOP_LOG_FUNC_EXIT__;
602         return popup;
603 }
604
605 /**
606  *      This function let the app create a keypad popup
607  *      @return   keypad popup
608  *      @param[in] win the window object
609  *      @param[in] pop the pointer to the prepared popup
610  */
611 Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
612 {
613         __WDPOP_LOG_FUNC_ENTER__;
614         wfd_appdata_t *ad = wfd_get_appdata();
615
616         Evas_Object *conformant = NULL;
617         Evas_Object *layout = NULL;
618         Evas_Object *pinpopup = NULL;
619         Evas_Object *label = NULL;
620         Evas_Object *btn1 = NULL, *btn2 = NULL;
621
622         conformant = elm_conformant_add(win);
623         assertm_if(NULL == conformant, "conformant is NULL!!");
624         elm_win_conformant_set(win, EINA_TRUE);
625         elm_win_resize_object_add(win, conformant);
626         evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, 0.0);
627         evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, 0.0);
628         evas_object_show(conformant);
629
630         layout = elm_layout_add(conformant);
631         elm_object_content_set(conformant, layout);
632
633         pinpopup = elm_popup_add(layout);
634         assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
635         evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, 0.0);
636         elm_object_part_text_set(pinpopup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
637
638         Evas_Object *box = elm_box_add(pinpopup);
639         if (!box) {
640                 evas_object_del(pinpopup);
641                 pinpopup = NULL;
642                 return NULL;
643         }
644
645         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
646         evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
647         elm_object_part_content_set(pinpopup, NULL, box);
648         evas_object_show(box);
649
650         /* add label */
651         label = elm_label_add(box);
652         elm_object_style_set(label, "popup/default");
653         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
654         elm_object_text_set(label, pop->text);
655         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
656         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
657         elm_box_pack_end(box, label);
658         evas_object_show(label);
659
660         /* add password */
661         Evas_Object *body = elm_layout_add(box);
662         if (!body) {
663                 evas_object_del(pinpopup);
664                 pinpopup = NULL;
665                 return NULL;
666         }
667
668         elm_layout_theme_set(body, "layout", "dialogue", "1icon");
669         evas_object_size_hint_weight_set(body, EVAS_HINT_EXPAND, 0.0);
670         evas_object_size_hint_align_set(body, EVAS_HINT_FILL, 0.0);
671
672         Evas_Object *editfield_pin = _add_edit_field(body, NULL, NULL, EINA_TRUE, EINA_TRUE);
673         Evas_Object *entry_pin = elm_object_part_content_get(editfield_pin, "elm.swallow.content");
674         ad->pin_entry = entry_pin;
675         evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb, NULL);
676         elm_object_part_content_set(body, "elm.icon", editfield_pin);
677         elm_box_pack_end(box, body);
678         evas_object_show(body);
679
680         elm_entry_password_set(ad->pin_entry, TRUE);
681
682         Evas_Object *check = elm_check_add(box);
683         elm_object_text_set(check, _("Show password"));
684         elm_object_focus_allow_set(check, EINA_FALSE);
685         evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
686         evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.0);
687         evas_object_smart_callback_add(check, "changed", _check_changed_cb, NULL);
688         evas_object_show(check);
689         elm_box_pack_end(box, check);
690
691         /* add buttons */
692         btn1 = elm_button_add(pinpopup);
693         elm_object_style_set(btn1, "popup_button/default");
694         elm_object_text_set(btn1, pop->label1);
695         elm_object_part_content_set(pinpopup, "button1", btn1);
696         evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb, (void *)pop->resp_data1);
697
698         btn2 = elm_button_add(pinpopup);
699         elm_object_style_set(btn2, "popup_button/default");
700         elm_object_text_set(btn2, pop->label2);
701         elm_object_part_content_set(pinpopup, "button2", btn2);
702         evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb, (void *)pop->resp_data2);
703
704         elm_object_content_set(pinpopup, box);
705         evas_object_show(pinpopup);
706         evas_object_show(win);
707         elm_object_focus_set(ad->pin_entry, EINA_TRUE);
708
709         __WDPOP_LOG_FUNC_EXIT__;
710         return pinpopup;
711 }
712
713 /**
714  *      This function let the app create a popup
715  *      @return   void
716  *      @param[in] type the type of popup
717  *      @param[in] userdata the pointer to the data which will be used
718  */
719 void wfd_prepare_popup(int type, void *userdata)
720 {
721         __WDPOP_LOG_FUNC_ENTER__;
722         wfd_appdata_t *ad = wfd_get_appdata();
723         wfd_popup_t *pop = ad->popup_data;
724
725         wfd_destroy_popup();
726
727         memset(pop, 0, sizeof(wfd_popup_t));
728
729         pop->type = type;
730
731         switch (pop->type) {
732         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
733                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
734                                 ad->peer_name);
735                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
736                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
737                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
738                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
739
740                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
741                 break;
742
743         case WFD_POP_APRV_CONNECTION_INVITATION_REQ:
744                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
745                                 ad->peer_name);
746                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
747                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
748                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_INVITATION_YES;
749                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
750
751                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
752                 break;
753
754         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
755                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN_WITH_KEYPAD,
756                                 ad->peer_name);
757                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
758                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
759                 pop->timeout = WFD_POP_TIMER_120;
760                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
761                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
762
763                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
764                 break;
765
766         case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
767                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN,
768                                 ad->peer_name, WFD_POP_TIMER_120);
769                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
770                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
771                 pop->timeout = WFD_POP_TIMER_120;
772                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
773                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
774
775                 ad->popup = wfd_draw_pop_type_c(ad->win, pop);
776                 break;
777
778         case /* MT */ WFD_POP_PROG_CONNECT:
779                 snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTING"));
780                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
781                 pop->timeout = WFD_POP_TIMER_120;
782                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
783
784                 ad->popup = wfd_draw_pop_type_b(ad->win, pop);
785                 break;
786
787         case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
788                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_KEYPAD,
789                                 ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
790                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
791                 snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
792                 pop->timeout = WFD_POP_TIMER_120;
793                 pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
794                 pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;
795
796                 ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
797                 break;
798
799         case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
800                 snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_PIN,
801                         ad->peer_name, WFD_POP_TIMER_120, ad->pin_number);
802                 snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
803                 pop->timeout = WFD_POP_TIMER_120;
804                 pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;
805
806                 ad->popup = wfd_draw_pop_type_display(ad->win, pop);
807                 break;
808
809         case WFD_POP_PROG_CONNECT_CANCEL:
810                 snprintf(pop->text, sizeof(pop->text), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
811                 pop->timeout = WFD_POP_TIMER_120;
812                 ad->popup = wfd_draw_pop_type_a(ad->win, pop);
813                 break;
814
815         default:
816                 break;
817         }
818
819         __WDPOP_LOG_FUNC_EXIT__;
820         return;
821 }
822
823 /**
824  *      This function let the app create a tickernoti syspopup
825  *      @return   void
826  *      @param[in] msg the pointer to message of tickernoti
827  */
828 void wfd_tickernoti_popup(char *msg)
829 {
830         __WDPOP_LOG_FUNC_ENTER__;
831
832         int ret = -1;
833         bundle *b = NULL;
834
835         b = bundle_create();
836         if (!b) {
837                 WDPOP_LOGD( "FAIL: bundle_create()\n");
838                 return;
839         }
840
841         /* tickernoti style */
842         ret = bundle_add(b, "0", "info");
843         if (ret) {
844                 WDPOP_LOGD( "Fail to add tickernoti style\n");
845                 bundle_free(b);
846                 return;
847         }
848
849         /* popup text */
850         ret = bundle_add(b, "1", msg);
851         if (ret) {
852                 WDPOP_LOGD( "Fail to add popup text\n");
853                 bundle_free(b);
854                 return;
855         }
856
857         /* orientation of tickernoti */
858         ret = bundle_add(b, "2", "0");
859         if (ret) {
860                 WDPOP_LOGD( "Fail to add orientation of tickernoti\n");
861                 bundle_free(b);
862                 return;
863         }
864
865         /* timeout(second) of tickernoti */
866         ret = bundle_add(b, "3", "3");
867         if (ret) {
868                 WDPOP_LOGD( "Fail to add timeout of tickernoti\n");
869                 bundle_free(b);
870                 return;
871         }
872
873         /* launch tickernoti */
874         ret = syspopup_launch(TICKERNOTI_SYSPOPUP, b);
875         if (ret) {
876                 WDPOP_LOGD( "Fail to launch syspopup\n");
877         }
878
879         bundle_free(b);
880         __WDPOP_LOG_FUNC_EXIT__;
881 }
882