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