summaryrefslogtreecommitdiff
path: root/popup-wifidirect/src/wfd-app-popup-view.c
blob: a754170824f632fc7289bf277123247bc0abc6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
/*
*  WiFi-Direct UG
*
* Copyright 2012  Samsung Electronics Co., Ltd

* Licensed under the Flora License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.tizenopensource.org/license

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
 * This file implements wifi direct system popup view  functions.
 *
 * @file    wfd-app-popup-view.c
 * @author  Sungsik Jang (sungsik.jang@samsung.com)
 * @version 0.1
 */

#include <libintl.h>
#include <glib.h>

#include "wifi-direct.h"
#include "wfd-app.h"
#include "wfd-app-strings.h"
#include "wfd-app-util.h"

extern wfd_appdata_t *g_wfd_ad;
extern wfd_popup_t *g_wfd_pop;
extern unsigned char g_wfd_peer_mac[6];
extern unsigned char g_wfd_peer_name[32];
static Ecore_Timer *pb_timer = NULL;

void wfd_tickernoti_popup(char *msg);

/**
 *	This function let the ug make a callback for click the button in popup
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] event_info the pointer to the event information
 */
static void __popup_resp_cb(void *data, Evas_Object * obj, void *event_info)
{
	__WDPOP_LOG_FUNC_ENTER__;
	wfd_appdata_t *ad = wfd_get_appdata();
	int result = -1;
	int resp = (int) data;
	char msg[WFD_POP_STR_MAX_LEN] = {0};

	WDPOP_LOGI( "popup resp : %d\n", resp);

	switch (resp) {
	case /* MT */ WFD_POP_RESP_APRV_CONNECT_PBC_YES:
	{
		WDPOP_LOGI(
				"WFD_POP_RESP_APRV_CONNECT_PBC_YES\n");
		wfd_destroy_popup();

		result = wifi_direct_accept_connection(ad->peer_mac);
		WDPOP_LOGD(
				"wifi_direct_accept_connection() result=[%d]\n",
				result);
		if (result == WIFI_DIRECT_ERROR_NONE) {
			/* tickernoti popup */
			wfd_tickernoti_popup(_("IDS_WFD_POP_CONNECTING"));
		} else {
			WDPOP_LOGE(
					"wifi_direct_accept_connection() FAILED!!\n");
			evas_object_hide(ad->win);

			/* tickernoti popup */
			snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
			wfd_tickernoti_popup(msg);
		}
	}
	break;

	case /* MT */ WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK:
	{
		char *pin = NULL;

		WDPOP_LOGI(
				"WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK\n");
		wfd_destroy_popup();

		if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE) {
			WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
			return;
		}

		if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
			WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
			return;
		}

		strncpy(ad->pin_number, pin, 64);
		free(pin);
		pin = NULL;
		WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);

		result = wifi_direct_accept_connection(ad->peer_mac);
		if (result == WIFI_DIRECT_ERROR_NONE) {
			wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
		} else {
			WDPOP_LOGD(
				"wifi_direct_accept_connection() failed. result=[%d]\n", result);
			/* tickernoti popup */
			wfd_tickernoti_popup(IDS_WFD_POP_CONNECT_FAILED);
		}
	}
	break;

	case /* MO */ WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK:
	{
		WDPOP_LOGI(
				"WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK\n");

		wfd_destroy_popup();

		int len = strlen(ad->pin_number);
		WDPOP_LOGD( "button ok: pin [%s]", ad->pin_number);

		if (len > 7 && len < 64) {
			int result = 0;
			WDPOP_LOGD( "pin=[%s]\n", ad->pin_number);

			result = wifi_direct_set_wps_pin(ad->pin_number);
			if (result != WIFI_DIRECT_ERROR_NONE) {
				/* tickernoti popup */
				snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
				wfd_tickernoti_popup(msg);
				return;
			}

			//result = wifi_direct_activate_pushbutton();
			result = wifi_direct_accept_connection(ad->peer_mac);
			WDPOP_LOGD(
					"wifi_direct_accept_connection(%s) result=[%d]\n",
					ad->peer_mac, result);
			if (result != WIFI_DIRECT_ERROR_NONE) {
				WDPOP_LOGE(
						"wifi_direct_accept_connection() FAILED!!\n");
				evas_object_hide(ad->win);

				/* tickernoti popup */
				snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
				wfd_tickernoti_popup(msg);
			}
		} else {
			WDPOP_LOGE( "Error, Incorrect PIN!!\n");

			/* tickernoti popup */
			wfd_tickernoti_popup(_("IDS_WFD_POP_PIN_INVALID"));

			/* redraw the popup */
			if (WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK == resp) {
				wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
			} else {
				wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, (void *) NULL);
			}

			return;
		}
	}
	break;

	case /* MT */ WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES:
	{
		WDPOP_LOGI(
				"WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES\n");
		wfd_destroy_popup();
		if (pb_timer) {
			ecore_timer_del(pb_timer);
			pb_timer = NULL;
		}

		wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
	}
	break;

	case /* MT */ WFD_POP_RESP_APRV_CONNECT_NO:
	{
		WDPOP_LOGI(
				"WFD_POP_RESP_APRV_CONNECT_NO: destroy_popup...\n");

		wfd_destroy_popup();
		if (pb_timer) {
			ecore_timer_del(pb_timer);
			pb_timer = NULL;
		}

		result = wifi_direct_disconnect(ad->peer_mac);
		WDPOP_LOGD(
				"wifi_direct_disconnect[%s] result=[%d]\n",
				ad->peer_mac, result);
	}
	break;

	default:
	{
		WDPOP_LOGE( "Unknown respone\n");
		evas_object_hide(ad->win);
	}
	break;
	}

	__WDPOP_LOG_FUNC_EXIT__;
}

/**
 *	This function let the app destroy the popup
 *	@return   void
 *	@param[in] null
 */
void wfd_destroy_popup()
{
	__WDPOP_LOG_FUNC_ENTER__;
	wfd_appdata_t *ad = wfd_get_appdata();

	if (ad == NULL) {
		WDPOP_LOGE( "ad is NULL\n");
		return;
	}

	if (ad->popup) {
		evas_object_del(ad->popup);
		ad->popup = NULL;
	}

	if (ad->popup_timeout_handle > 0) {
		g_source_remove(ad->popup_timeout_handle);
		ad->popup_timeout_handle = 0;
	}

	evas_object_hide(ad->win);

	__WDPOP_LOG_FUNC_EXIT__;
	return;
}

/**
 *	This function let the app create a popup which includes no button
 *	@return   popup
 *	@param[in] win the window object
 *	@param[in] pop the pointer to the prepared popup
 */
static Evas_Object *wfd_draw_pop_type_a(Evas_Object * win, wfd_popup_t * pop)
{
	__WDPOP_LOG_FUNC_ENTER__;
	Evas_Object *popup;

	popup = elm_popup_add(win);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_text_set(popup, pop->text);
	elm_popup_timeout_set(popup, pop->timeout);
	evas_object_show(popup);
	evas_object_show(win);

	__WDPOP_LOG_FUNC_EXIT__;
	return popup;
}

/**
 *	This function let the app create a popup which includes one button
 *	@return   popup
 *	@param[in] win the window object
 *	@param[in] pop the pointer to the prepared popup
 */
static Evas_Object *wfd_draw_pop_type_b(Evas_Object * win, wfd_popup_t * pop)
{
	__WDPOP_LOG_FUNC_ENTER__;
	Evas_Object *popup = NULL;
	Evas_Object *btn = NULL;

	popup = elm_popup_add(win);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_text_set(popup, pop->text);

	btn = elm_button_add(popup);
	elm_object_style_set(btn, "popup_button/default");
	elm_object_text_set(btn, pop->label1);
	elm_object_part_content_set(popup, "button1", btn);
	evas_object_smart_callback_add(btn, "clicked", __popup_resp_cb, (void *) pop->resp_data1);

	evas_object_show(popup);
	evas_object_show(win);

	__WDPOP_LOG_FUNC_EXIT__;
	return popup;
}

/**
 *	This function let the app create a popup which includes two buttons
 *	@return   popup
 *	@param[in] win the window object
 *	@param[in] pop the pointer to the prepared popup
 */
static Evas_Object *wfd_draw_pop_type_c(Evas_Object * win, wfd_popup_t * pop)
{
	__WDPOP_LOG_FUNC_ENTER__;
	Evas_Object *popup = NULL;
	Evas_Object *btn1 = NULL, *btn2 = NULL;

	popup = elm_popup_add(win);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_text_set(popup, pop->text);

	btn1 = elm_button_add(popup);
	elm_object_style_set(btn1, "popup_button/default");
	elm_object_text_set(btn1, pop->label1);
	elm_object_part_content_set(popup, "button1", btn1);
	evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
		(void *) pop->resp_data1);

	btn2 = elm_button_add(popup);
	elm_object_style_set(btn2, "popup_button/default");
	elm_object_text_set(btn2, pop->label2);
	elm_object_part_content_set(popup, "button2", btn2);
	evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
		(void *) pop->resp_data2);

	evas_object_show(popup);
	evas_object_show(win);

	__WDPOP_LOG_FUNC_EXIT__;
	return popup;
}

/**
 *	This function let the ug make a change callback for password input
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] event_info the pointer to the event information
 */
static void _smart_ime_cb(void *data, Evas_Object * obj, void *event_info)
{
	__WDPOP_LOG_FUNC_ENTER__;
	wfd_appdata_t *ad = wfd_get_appdata();

	Ecore_IMF_Context *imf_context = NULL;
	imf_context = (Ecore_IMF_Context *) ad->pin_entry;

	if (NULL == imf_context) {
		WDPOP_LOGE( "Error!!! Ecore_IMF_Context is NULL!!");
		return;
	}

	const char *txt = elm_entry_markup_to_utf8(elm_entry_entry_get((const Evas_Object *) imf_context));
	if (NULL != txt) {
		WDPOP_LOGD( "* text [%s], len=[%d]", txt, strlen(txt));
		strncpy(ad->pin_number, txt, sizeof(ad->pin_number));
	} else {
		WDPOP_LOGD( "Err!");
	}

	__WDPOP_LOG_FUNC_EXIT__;
}

/**
 *	This function let the app make a change callback for password checkbox
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] event_info the pointer to the event information
 */
static void _check_changed_cb(void *data, Evas_Object * obj, void *event_info)
{
	wfd_appdata_t *ad = wfd_get_appdata();

	if (obj == NULL) {
		return;
	}

	Eina_Bool state = elm_check_state_get(obj);
	elm_entry_password_set(ad->pin_entry, !state);
}

/**
 *	This function let the app make a callback for progressbar timer
 *	@return   if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
 *	@param[in] data the pointer to the wps structure
 */
static Eina_Bool _fn_pb_timer(void *data)
{
	int step = 0;
	double value = 0.0;
	char time_label[32] = {0};
	wfd_wps_display_popup_t *wps_display_popup = (wfd_wps_display_popup_t *) data;

	if (NULL == wps_display_popup) {
		WDPOP_LOGE( "Param is NULL.\n");
		return ECORE_CALLBACK_CANCEL;
	}

	Evas_Object *progressbar = NULL;
	Evas_Object *time = NULL;

	progressbar = wps_display_popup->progressbar;
	time = wps_display_popup->time;
	value = elm_progressbar_value_get(progressbar);

	if (value >= 1.0) {
		WDPOP_LOGE( "Progress end.\n");
		if (pb_timer) {
			ecore_timer_del(pb_timer);
			pb_timer = NULL;
		}
		wfd_destroy_popup();
		return ECORE_CALLBACK_CANCEL;
	}

	wps_display_popup->step++;
	step = wps_display_popup->step;
	value = ((double)step) / WFD_POP_TIMER_120;
	elm_progressbar_value_set(progressbar, value);
	WDPOP_LOGD( "step: %d, value: %f\n", wps_display_popup->step, value);

	/* show the time label */
	if (step < 60) {
		if (step < 10) {
			snprintf(time_label, 32, "00:0%d", step);
		} else {
			snprintf(time_label, 32, "00:%d", step);
		}
	} else {
		if (step%60 < 10) {
			snprintf(time_label, 32, "0%d:0%d", step/60, step%60);
		} else {
			snprintf(time_label, 32, "0%d:%d", step/60, step%60);
		}
	}

	elm_object_text_set(time, time_label);

	return ECORE_CALLBACK_RENEW;
}

/**
 *	This function let the app create a edit filed
 *	@return   edit filed
 *	@param[in] parent the parent object
 *	@param[in] title the pointer to the title of edit field
 *	@param[in] guide the pointer to the text of guide
 *	@param[in] single_line whether it can support single line
 *	@param[in] is_editable whether it is avaliable to edit
 */
static Evas_Object *_add_edit_field(Evas_Object *parent, const char *title, const char *guide, Eina_Bool single_line, Eina_Bool is_editable)
{
	assertm_if(NULL == parent, "parent is NULL!!");

	Evas_Object *layout = elm_layout_add(parent);
	assertm_if(NULL == layout, "layout is NULL!!");

	if (title && title[0] != '\0') {
		elm_layout_theme_set(layout, "layout", "editfield", "title");
		elm_object_part_text_set(layout, "elm.text", title);
	} else {
		elm_layout_theme_set(layout, "layout", "editfield", "default");
	}

	Evas_Object *entry = elm_entry_add(parent);
	assertm_if(NULL == entry, "entry is NULL!!");

	elm_object_part_content_set(layout, "elm.swallow.content", entry);
	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	if (guide && guide[0] != '\0') {
		elm_object_part_text_set(layout, "elm.guidetext", guide);
	}

	elm_entry_single_line_set(entry, single_line);
	elm_entry_scrollable_set(entry, single_line);
	elm_entry_editable_set(entry, is_editable);
	elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
	evas_object_show(layout);

	return layout;
}

/**
 *	This function let the app create a display popup
 *	@return   display popup
 *	@param[in] win the window object
 *	@param[in] pop the pointer to the prepared popup
 */
Evas_Object *wfd_draw_pop_type_display(Evas_Object * win, wfd_popup_t * pop)
{
	__WDPOP_LOG_FUNC_ENTER__;

	Evas_Object *popup = NULL;
	Evas_Object *label = NULL;
	Evas_Object *progressbar = NULL;
	Evas_Object *time = NULL;
	static wfd_wps_display_popup_t wps_display_popup;

	popup = elm_popup_add(win);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, 0.0);

	Evas_Object *box = elm_box_add(popup);
	if (!box) {
		evas_object_del(popup);
		popup = NULL;
		return NULL;
	}

	evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
	elm_object_part_content_set(popup, NULL, box);
	evas_object_show(box);

	/* add label */
	label = elm_label_add(box);
	elm_object_style_set(label, "popup/default");
	elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
	elm_object_text_set(label, pop->text);
	evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(label, EVAS_HINT_FILL, 0.0);
	elm_box_pack_end(box, label);
	evas_object_show(label);

	/* add progressbar */
	progressbar = elm_progressbar_add(box);
	elm_object_style_set(progressbar, "list_progress");
	elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
	evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.0);
	evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, 0.0);
	elm_progressbar_value_set(progressbar, 0.0);
	elm_box_pack_end(box, progressbar);
	evas_object_show(progressbar);

	/* add time */
	time = elm_label_add(box);
	elm_object_style_set(time, "popup/default");
	elm_object_text_set(time, "00:00");
	evas_object_size_hint_weight_set(time, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(time, EVAS_HINT_FILL, 0.0);
	elm_box_pack_end(box, time);
	evas_object_show(time);

	/* start progressbar timer */
	wps_display_popup.step = 0;
	wps_display_popup.progressbar = progressbar;
	wps_display_popup.time = time;
	pb_timer = ecore_timer_add(1, _fn_pb_timer, &wps_display_popup);

	/* add buttons */
	if (pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES ||
		pop->resp_data1 == WFD_POP_RESP_APRV_CONNECT_NO) {
		Evas_Object *btn1 = NULL;
		btn1 = elm_button_add(popup);
		elm_object_style_set(btn1, "popup_button/default");
		elm_object_text_set(btn1, pop->label1);
		elm_object_part_content_set(popup, "button1", btn1);
		evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb,
			(void *) pop->resp_data1);
	}

	if (pop->resp_data2 == WFD_POP_RESP_APRV_CONNECT_NO) {
		Evas_Object *btn2 = NULL;
		btn2 = elm_button_add(popup);
		elm_object_style_set(btn2, "popup_button/default");
		elm_object_text_set(btn2, pop->label2);
		elm_object_part_content_set(popup, "button2", btn2);
		evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb,
			(void *) pop->resp_data2);
	}

	elm_object_content_set(popup, box);
	evas_object_show(popup);
	evas_object_show(win);

	__WDPOP_LOG_FUNC_EXIT__;
	return popup;
}

/**
 *	This function let the app create a keypad popup
 *	@return   keypad popup
 *	@param[in] win the window object
 *	@param[in] pop the pointer to the prepared popup
 */
Evas_Object *wfd_draw_pop_type_keypad(Evas_Object * win, wfd_popup_t * pop)
{
	__WDPOP_LOG_FUNC_ENTER__;
	wfd_appdata_t *ad = wfd_get_appdata();

	Evas_Object *conformant = NULL;
	Evas_Object *layout = NULL;
	Evas_Object *pinpopup = NULL;
	Evas_Object *label = NULL;
	Evas_Object *btn1 = NULL, *btn2 = NULL;

	conformant = elm_conformant_add(win);
	assertm_if(NULL == conformant, "conformant is NULL!!");
	elm_win_conformant_set(win, EINA_TRUE);
	elm_win_resize_object_add(win, conformant);
	evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, 0.0);
	evas_object_show(conformant);

	layout = elm_layout_add(conformant);
	elm_object_content_set(conformant, layout);

	pinpopup = elm_popup_add(layout);
	assertm_if(NULL == pinpopup, "pinpopup is NULL!!");
	evas_object_size_hint_weight_set(pinpopup, EVAS_HINT_EXPAND, 0.0);
	elm_object_part_text_set(pinpopup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));

	Evas_Object *box = elm_box_add(pinpopup);
	if (!box) {
		evas_object_del(pinpopup);
		pinpopup = NULL;
		return NULL;
	}

	evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
	elm_object_part_content_set(pinpopup, NULL, box);
	evas_object_show(box);

	/* add label */
	label = elm_label_add(box);
	elm_object_style_set(label, "popup/default");
	elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
	elm_object_text_set(label, pop->text);
	evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_box_pack_end(box, label);
	evas_object_show(label);

	/* add password */
	Evas_Object *body = elm_layout_add(box);
	if (!body) {
		evas_object_del(pinpopup);
		pinpopup = NULL;
		return NULL;
	}

	elm_layout_theme_set(body, "layout", "dialogue", "1icon");
	evas_object_size_hint_weight_set(body, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(body, EVAS_HINT_FILL, 0.0);

	Evas_Object *editfield_pin = _add_edit_field(body, NULL, NULL, EINA_TRUE, EINA_TRUE);
	Evas_Object *entry_pin = elm_object_part_content_get(editfield_pin, "elm.swallow.content");
	ad->pin_entry = entry_pin;
	evas_object_smart_callback_add(ad->pin_entry, "changed", _smart_ime_cb, NULL);
	elm_object_part_content_set(body, "elm.icon", editfield_pin);
	elm_box_pack_end(box, body);
	evas_object_show(body);

	elm_entry_password_set(ad->pin_entry, TRUE);

	Evas_Object *check = elm_check_add(box);
	elm_object_text_set(check, _("Show password"));
	elm_object_focus_allow_set(check, EINA_FALSE);
	evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
	evas_object_size_hint_align_set(check, EVAS_HINT_FILL, 0.0);
	evas_object_smart_callback_add(check, "changed", _check_changed_cb, NULL);
	evas_object_show(check);
	elm_box_pack_end(box, check);

	/* add buttons */
	btn1 = elm_button_add(pinpopup);
	elm_object_style_set(btn1, "popup_button/default");
	elm_object_text_set(btn1, pop->label1);
	elm_object_part_content_set(pinpopup, "button1", btn1);
	evas_object_smart_callback_add(btn1, "clicked", __popup_resp_cb, (void *)pop->resp_data1);

	btn2 = elm_button_add(pinpopup);
	elm_object_style_set(btn2, "popup_button/default");
	elm_object_text_set(btn2, pop->label2);
	elm_object_part_content_set(pinpopup, "button2", btn2);
	evas_object_smart_callback_add(btn2, "clicked", __popup_resp_cb, (void *)pop->resp_data2);

	elm_object_content_set(pinpopup, box);
	evas_object_show(pinpopup);
	evas_object_show(win);
	elm_object_focus_set(ad->pin_entry, EINA_TRUE);

	__WDPOP_LOG_FUNC_EXIT__;
	return pinpopup;
}

/**
 *	This function let the app create a popup
 *	@return   void
 *	@param[in] type the type of popup
 *	@param[in] userdata the pointer to the data which will be used
 */
void wfd_prepare_popup(int type, void *userdata)
{
	__WDPOP_LOG_FUNC_ENTER__;
	wfd_appdata_t *ad = wfd_get_appdata();
	wfd_popup_t *pop = ad->popup_data;

	wfd_destroy_popup();

	memset(pop, 0, sizeof(wfd_popup_t));

	pop->type = type;

	switch (pop->type) {
	case /* MT */ WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ:
		snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECT_Q,
				ad->peer_name);
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_YES"));
		snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_SK_NO"));
		pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_PBC_YES;
		pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_c(ad->win, pop);
 		break;

	case /* MT */ WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ:
		snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN_WITH_KEYPAD,
				ad->peer_name);
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
		snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_DISPLAY_OK;
		pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_c(ad->win, pop);
 		break;

	case /* MT */ WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ:
		snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_ENTER_PIN,
				ad->peer_name, WFD_POP_TIMER_120);
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
		snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_KEYPAD_YES;
		pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_display(ad->win, pop);
 		break;

	case /* MT */ WFD_POP_PROG_CONNECT:
		snprintf(pop->text, sizeof(pop->text), "%s", _("IDS_WFD_POP_CONNECTING"));
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_b(ad->win, pop);
 		break;

	case /* MO */ WFD_POP_PROG_CONNECT_WITH_KEYPAD:
		snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_KEYPAD,
				ad->peer_name, WFD_POP_TIMER_120, ad->peer_name);
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_SK_OK"));
		snprintf(pop->label2, sizeof(pop->label2), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		pop->resp_data1 = WFD_POP_RESP_PROG_CONNECT_KEYPAD_OK;
		pop->resp_data2 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_keypad(ad->win, pop);
 		break;

	case /* MO/MT */ WFD_POP_PROG_CONNECT_WITH_PIN:
		snprintf(pop->text, sizeof(pop->text), IDS_WFD_POP_CONNECTING_WITH_PIN,
			ad->peer_name, WFD_POP_TIMER_120, ad->pin_number);
		snprintf(pop->label1, sizeof(pop->label1), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		pop->resp_data1 = WFD_POP_RESP_APRV_CONNECT_NO;

		ad->popup = wfd_draw_pop_type_display(ad->win, pop);
 		break;

	case WFD_POP_PROG_CONNECT_CANCEL:
		snprintf(pop->text, sizeof(pop->text), "%s", dgettext("sys_string", "IDS_COM_POP_CANCEL"));
		pop->timeout = WFD_POP_TIMER_120;
		ad->popup = wfd_draw_pop_type_a(ad->win, pop);
 		break;

	default:
		break;
	}

	__WDPOP_LOG_FUNC_EXIT__;
	return;
}

/**
 *	This function let the app create a tickernoti syspopup
 *	@return   void
 *	@param[in] msg the pointer to message of tickernoti
 */
void wfd_tickernoti_popup(char *msg)
{
	__WDPOP_LOG_FUNC_ENTER__;

	int ret = -1;
	bundle *b = NULL;

	b = bundle_create();
	if (!b) {
		WDPOP_LOGD( "FAIL: bundle_create()\n");
		return;
	}

	/* tickernoti style */
	ret = bundle_add(b, "0", "info");
	if (ret) {
		WDPOP_LOGD( "Fail to add tickernoti style\n");
		bundle_free(b);
		return;
	}

	/* popup text */
	ret = bundle_add(b, "1", msg);
	if (ret) {
		WDPOP_LOGD( "Fail to add popup text\n");
		bundle_free(b);
		return;
	}

	/* orientation of tickernoti */
	ret = bundle_add(b, "2", "0");
	if (ret) {
		WDPOP_LOGD( "Fail to add orientation of tickernoti\n");
		bundle_free(b);
		return;
	}

	/* timeout(second) of tickernoti */
	ret = bundle_add(b, "3", "3");
	if (ret) {
		WDPOP_LOGD( "Fail to add timeout of tickernoti\n");
		bundle_free(b);
		return;
	}

	/* launch tickernoti */
	ret = syspopup_launch(TICKERNOTI_SYSPOPUP, b);
	if (ret) {
		WDPOP_LOGD( "Fail to launch syspopup\n");
	}

	bundle_free(b);
	__WDPOP_LOG_FUNC_EXIT__;
}