summaryrefslogtreecommitdiff
path: root/ug-wifidirect/src/wfd_ug_multiconnect_view.c
blob: 680179af0b337a8fa44bcd9ec1fd9772102b71f6 (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
/*
*  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.
*
*/

#include <libintl.h>

#include <assert.h>
#include <glib.h>

#include <Elementary.h>
#include <vconf.h>
#include <ui-gadget-module.h>
#include <wifi-direct.h>

#include "wfd_ug.h"
#include "wfd_ug_view.h"
#include "wfd_client.h"

Elm_Gen_Item_Class select_all_itc;
Elm_Gen_Item_Class device_itc;

/**
 *	This function let the ug call it when click 'back' button in multi connect view
 *	@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
 */
void _multiconnect_view_back_btn_cb(void *data, Evas_Object * obj, void *event_info)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;

	if (!ugd) {
		DBG(LOG_ERROR, "The param is NULL\n");
		return;
	}

	ugd->multiconn_view_genlist = NULL;
	elm_naviframe_item_pop(ugd->naviframe);

	__FUNC_EXIT__;
	return;
}

/**
 *	This function let the ug reset the connected failed peers
 *	@return   false
 *	@param[in] event_info the pointer to the event information
 */
gboolean __wfd_multi_connect_reset_cb(void *data)
{
	__FUNC_ENTER__;
	int i = 0;
	struct ug_data *ugd = (struct ug_data *)data;

	/* remove the failed peers*/
	for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
		if (ugd->raw_multi_selected_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
			memset(&ugd->raw_multi_selected_peers[i], 0x00, sizeof(device_type_s));
			ugd->raw_multi_selected_peer_cnt--;
		}
	}

	wfd_ug_view_update_peers(ugd);

	__FUNC_EXIT__;
	return false;
}

/**
 *	This function let the ug free the selected peers in multi connect view
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 */
void wfd_free_multi_selected_peers(void *data)
{
	__FUNC_ENTER__;
	int i = 0;
	struct ug_data *ugd = (struct ug_data *)data;

	/* destroy the created group */
	wifi_direct_destroy_group();

	/* release the selected peers */
	for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
		memset(&ugd->raw_multi_selected_peers[i], 0x00, sizeof(device_type_s));
	}

	ugd->raw_multi_selected_peer_cnt = 0;
	ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_NONE;

	__FUNC_EXIT__;

}

/**
 *	This function let the ug stop to connect to selected peer
 *	@return   If success, return 0, else return -1
 *	@param[in] data the pointer to the main data structure
 */
int wfd_stop_multi_connect(void *data)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;

	/* change the title of failed peers */
	ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_COMPLETED;
	wfd_ug_view_refresh_glitem(ugd->multi_connect_wfd_item);

	wfd_client_set_p2p_group_owner_intent(7);

	/* after 30s, remove the failed peers */
	g_timeout_add(30000 /*ms*/, __wfd_multi_connect_reset_cb, ugd);

	__FUNC_EXIT__;
	return 0;
}

/**
 *	This function let the ug start to connect the selected peers
 *	@return   If success, return 0, else return -1
 *	@param[in] data the pointer to the main data structure
 */
int wfd_start_multi_connect(void *data)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;
	int res;

	if (ugd->raw_multi_selected_peer_cnt > 0) {
		ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_IN_PROGRESS;

		res = wfd_client_group_add();
		if (res == -1) {
			DBG(LOG_ERROR, "Failed to add group");
			wfd_free_multi_selected_peers(ugd);

			__FUNC_EXIT__;
			return -1;
		}

	} else {
		DBG(LOG_VERBOSE, "No selected peers.\n");
		return -1;
	}

	__FUNC_EXIT__;
	return 0;
}

/**
 *	This function let the ug connect to the next selected peer automatically
 *	@return   If stop the timer, return false, else return true
 *	@param[in] data the pointer to the main data structure
 */
gboolean wfd_multi_connect_next_cb(void *data)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;
	int i;
	int res;

	// Reset g_source handler..
	ugd->g_source_multi_connect_next = 0;

	if (ugd->raw_multi_selected_peer_cnt > 0) {
		ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_IN_PROGRESS;
		for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
			if (ugd->raw_multi_selected_peers[i].conn_status == PEER_CONN_STATUS_WAIT_FOR_CONNECT) {
				res = wfd_client_connect(ugd->raw_multi_selected_peers[i].mac_addr);
				if (res == -1) {
					DBG(LOG_VERBOSE, "Failed to connect [%s].\n", ugd->raw_multi_selected_peers[i].ssid);
					ugd->raw_multi_selected_peers[i].conn_status = PEER_CONN_STATUS_FAILED_TO_CONNECT;
				} else {
					ugd->raw_multi_selected_peers[i].conn_status = PEER_CONN_STATUS_CONNECTING;
					break;
				}
			}
		}

		if (i >= ugd->raw_multi_selected_peer_cnt) {
			// All selected peers are touched.
			DBG(LOG_VERBOSE, "Stop Multi Connect...\n");
			wfd_stop_multi_connect(ugd);
		}
	} else {
		DBG(LOG_VERBOSE, "No selected peers.\n");
		return -1;
	}

	__FUNC_EXIT__;
	return false;
}

/**
 *	This function let the ug call it when click 'connect' button in multi connect view
 *	@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
 */
void _connect_btn_cb(void *data, Evas_Object *obj, void *event_info)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;
	int i = 0;
	int count = 0;
	char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
	DBG(LOG_VERBOSE, "_connect_btn_cb \n");

	for (i = 0; i < ugd->gl_available_peer_cnt ; i++) {
		if (TRUE == ugd->multi_conn_dev_list[i].dev_sel_state) {
			DBG(LOG_VERBOSE, "ugd->peers[i].mac_addr = %s, i = %d\n", ugd->multi_conn_dev_list[i].peer.mac_addr, i);

			memcpy(&ugd->raw_multi_selected_peers[count], &ugd->multi_conn_dev_list[i].peer, sizeof(device_type_s));
			ugd->raw_multi_selected_peers[count].conn_status = PEER_CONN_STATUS_WAIT_FOR_CONNECT;
			count++;
		}
	}

	ugd->raw_multi_selected_peer_cnt = count;

	/* if more than 7 device selected, show the popup */
	if (count > MAX_POPUP_PEER_NUM) {
		snprintf(popup_text, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_MULTI_CONNECT"), count);
		wfd_ug_warn_popup(ugd, popup_text, POP_TYPE_MULTI_CONNECT_POPUP);
	}

	/* start multi connection */
	wfd_start_multi_connect(ugd);

	elm_naviframe_item_pop(ugd->naviframe);

	//ToDo: Do we need to free multiconn_view_genlist?
	ugd->multiconn_view_genlist = NULL;
	_change_multi_button_title(ugd);

	__FUNC_EXIT__;
	return;
}

/**
 *	This function let the ug delete 'select(n)' notify
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 */
static void _wfd_multi_del_select_info_label(void *data)
{
	__FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *)data;

	if (NULL == ugd) {
		DBG(LOG_ERROR, "The param is NULL\n");
		return;
	}

	if (ugd->notify) {
		evas_object_del(ugd->notify);
		ugd->notify = NULL;
	}

	if (ugd->notify_layout) {
		evas_object_del(ugd->notify_layout);
		ugd->notify_layout = NULL;
	}

	__FUNC_EXIT__;
	return;
}

/**
 *	This function let the ug add 'select(n)' notify
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] count the number of selected peers
 */
static void _wfd_multi_add_select_info_label(void *data, int count)
{
	__FUNC_ENTER__;

	char select_lablel[MAX_POPUP_TEXT_SIZE] = {0};
	struct ug_data *ugd = (struct ug_data *)data;

	if (NULL == ugd || count <= 0) {
		DBG(LOG_ERROR, "The param is NULL\n");
		return;
	}

	/* delete previous notify */
	_wfd_multi_del_select_info_label(ugd);

	/* add notify */
	ugd->notify = elm_notify_add(ugd->base);
	if (NULL == ugd->notify) {
		DBG(LOG_ERROR, "Add notify failed\n");
		return;
	}

	/* set the align to center of bottom */
	elm_notify_align_set(ugd->notify, ELM_NOTIFY_ALIGN_FILL, 1.0);

	ugd->notify_layout = elm_layout_add(ugd->notify);
	if (NULL == ugd->notify_layout) {
		evas_object_del(ugd->notify);
		ugd->notify = NULL;
		return;
	}

	elm_layout_theme_set(ugd->notify_layout, "standard", "selectioninfo", "vertical/bottom_64");
	elm_object_content_set(ugd->notify, ugd->notify_layout);

	snprintf(select_lablel, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), count);
	elm_object_part_text_set(ugd->notify_layout, "elm.text", select_lablel);
	elm_notify_timeout_set(ugd->notify, 3);
	evas_object_show(ugd->notify);

	__FUNC_EXIT__;
	return;
}

/**
 *	This function let the ug call it when click the peer in multi connect view
 *	@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 _wfd_gl_multi_sel_cb(void *data, Evas_Object *obj, void *event_info)
{
	__FUNC_ENTER__;

	int i = 0;
	int index = 0;
	int sel_count = 0;
	bool is_sel = FALSE;
	bool is_selct_all = TRUE;
	Eina_Bool state = 0;
	Evas_Object *chk_box = NULL;
	char msg[MAX_POPUP_TEXT_SIZE] = {0};
	struct ug_data *ugd = (struct ug_data *)data;
	Elm_Object_Item *item = (Elm_Object_Item *)event_info;

	if (NULL == ugd || NULL == item) {
		DBG(LOG_ERROR, "The param is NULL\n");
		return;
	}

	elm_genlist_item_selected_set(item, EINA_FALSE);
	index = elm_genlist_item_index_get(item) - 3; /* subtract the previous items */
	DBG(LOG_VERBOSE, "selected index = %d \n", index);
	if (index < 0) {
		DBG(LOG_ERROR, "The index is invalid.\n");
		return;
	}

	chk_box = elm_object_item_part_content_get((Elm_Object_Item *)event_info, "elm.icon.1");
	state = elm_check_state_get(chk_box);
	DBG(LOG_VERBOSE, "state = %d \n", state);
	elm_check_state_set(chk_box, !state);

	ugd->multi_conn_dev_list[index].dev_sel_state = !state;
	DBG(LOG_VERBOSE, "ptr->dev_sel_state = %d \n", ugd->multi_conn_dev_list[index].dev_sel_state);
	DBG(LOG_VERBOSE, "ptr->peer.mac_addr = %s \n", ugd->multi_conn_dev_list[index].peer.mac_addr);

	/* update the checkbox and button */
	for (; i < ugd->gl_available_dev_cnt_at_multiconn_view; i++) {
		if (ugd->multi_conn_dev_list[i].dev_sel_state) {
			is_sel = TRUE;
			sel_count++;
		} else {
			is_selct_all = FALSE;
		}
	}

	chk_box = elm_object_item_part_content_get(ugd->mcview_select_all_item, "elm.icon");
	elm_check_state_set(chk_box, is_selct_all);

	if (ugd->multi_connect_btn) {
		wfd_ug_view_refresh_button(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"), is_sel);
	}

	if (sel_count > 0) {
		snprintf(msg, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), sel_count);
		_wfd_multi_add_select_info_label(ugd, sel_count);
	} else {
		_wfd_multi_del_select_info_label(ugd);
	}

	__FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click the 'select all' item in multi connect view
 *	@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 _wfd_gl_sel_cb(void *data, Evas_Object *obj, void *event_info)
{
	int sel_count = 0;
	char msg[MAX_POPUP_TEXT_SIZE] = {0};
	struct ug_data *ugd = (struct ug_data *)data;

	elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);

	if (NULL == ugd || NULL == obj) {
		DBG(LOG_ERROR, "NULL parameters.\n");
		return;
	}

	Evas_Object *sel_chkbox = elm_object_item_part_content_get(ugd->mcview_select_all_item, "elm.icon");
	if (sel_chkbox == NULL) {
		DBG(LOG_VERBOSE, "select-all chkbox is NULL\n");
		return;
	}

	Eina_Bool state = elm_check_state_get(sel_chkbox);
	if (state == TRUE) {
		state = FALSE;
	} else {
		state = TRUE;
	}

	elm_check_state_set(sel_chkbox, state);
	DBG(LOG_VERBOSE, "state = %d \n", state);

	int i = 0;
	bool is_sel = FALSE;
	Elm_Object_Item *item = NULL;
	Evas_Object *chk_box = NULL;

	/* set the state of all the available devices */
	for (i = 0; i < ugd->gl_available_dev_cnt_at_multiconn_view; i++) {
		is_sel = state;
		ugd->multi_conn_dev_list[i].dev_sel_state = state;
		item = ugd->multi_conn_dev_list[i].peer.gl_item;
		chk_box = elm_object_item_part_content_get(item, "elm.icon.1");
		elm_check_state_set(chk_box, state);

		if (state) {
			sel_count++;
		}
	}

	/* update the connect button */
	if (ugd->multi_connect_btn) {
		wfd_ug_view_refresh_button(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"), is_sel);
	}

	/* tickernoti popup */
	if (sel_count > 0) {
		snprintf(msg, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), sel_count);
		_wfd_multi_add_select_info_label(ugd, sel_count);
	} else {
		_wfd_multi_del_select_info_label(ugd);
	}
}

/**
 *	This function let the ug get the label of peer
 *	@return   the label of peer
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] part the pointer to the part of item
 */
static char *_wfd_gl_device_label_get(void *data, Evas_Object *obj, const char *part)
{
	DBG(LOG_VERBOSE, "part %s", part);
	device_type_s *peer = (device_type_s *)data;

	if (NULL == peer) {
		return NULL;
	}

	if (!strcmp(part, "elm.text")) {
		return strdup(peer->ssid);
	}
	return NULL;
}

/**
 *	This function let the ug get the icon path of peer
 *	@return   the  icon path of titile
 *	@param[in] peer the pointer to the peer
 */
static char *__wfd_get_device_icon_path(device_type_s *peer)
{
	char *img_path = NULL;

	switch (peer->category) {
	case WFD_DEVICE_TYPE_COMPUTER:
		img_path = WFD_ICON_DEVICE_COMPUTER;
		break;
	case WFD_DEVICE_TYPE_INPUT_DEVICE:
		img_path = WFD_ICON_DEVICE_INPUT_DEVICE;
		break;
	case WFD_DEVICE_TYPE_PRINTER:
		img_path = WFD_ICON_DEVICE_PRINTER;
		break;
	case WFD_DEVICE_TYPE_CAMERA:
		img_path = WFD_ICON_DEVICE_CAMERA;
		break;
	case WFD_DEVICE_TYPE_STORAGE:
		img_path = WFD_ICON_DEVICE_STORAGE;
		break;
	case WFD_DEVICE_TYPE_NW_INFRA:
		img_path = WFD_ICON_DEVICE_NETWORK_INFRA;
		break;
	case WFD_DEVICE_TYPE_DISPLAYS:
		img_path = WFD_ICON_DEVICE_DISPLAY;
		break;
	case WFD_DEVICE_TYPE_MM_DEVICES:
		img_path = WFD_ICON_DEVICE_MULTIMEDIA_DEVICE;
		break;
	case WFD_DEVICE_TYPE_GAME_DEVICES:
		img_path = WFD_ICON_DEVICE_GAMING_DEVICE;
		break;
	case WFD_DEVICE_TYPE_TELEPHONE:
		img_path = WFD_ICON_DEVICE_TELEPHONE;
		break;
	case WFD_DEVICE_TYPE_AUDIO:
		img_path = WFD_ICON_DEVICE_AUDIO_DEVICE;
		break;
	default:
		img_path = WFD_ICON_DEVICE_COMPUTER;
		break;
	}

	return img_path;
}


/**
 *	This function let the ug call it when click the check box
 *	@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 _wfd_check_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
	if (NULL == obj) {
		DBG(LOG_ERROR, "NULL parameters.\n");
		return;
	}

	Eina_Bool state = elm_check_state_get(obj);
	elm_check_state_set(obj, !state);
	DBG(LOG_VERBOSE, "state = %d \n", state);
}

/**
 *	This function let the ug get the icon of peer
 *	@return   the icon of peer
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] part the pointer to the part of item
 */
static Evas_Object *_wfd_gl_device_icon_get(void *data, Evas_Object *obj, const char *part)
{
	char *img_path = NULL;
	device_type_s *peer = (device_type_s *) data;
	Evas_Object *icon = NULL;

	DBG(LOG_VERBOSE, "Part %s", part);

	if (!strcmp(part, "elm.icon.1")) {
		DBG(LOG_VERBOSE, "Part %s", part);
		icon = elm_check_add(obj);
		elm_check_state_set(icon, EINA_FALSE);
		evas_object_smart_callback_add(icon, "changed", _wfd_check_clicked_cb, (void *)data);
	} else if (!strcmp(part, "elm.icon.2")) {
		img_path = __wfd_get_device_icon_path(peer);
		icon = elm_icon_add(obj);
		elm_icon_file_set(icon, img_path, NULL);
		evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
		elm_icon_resizable_set(icon, 1, 1);
		evas_object_show(icon);
	}

	return icon;
}

/**
 *	This function let the ug get the label of select all
 *	@return   the label of select all
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] part the pointer to the part of item
 */
static char *_wfd_gl_select_all_label_get(void *data, Evas_Object *obj, const char *part)
{
	if (!strcmp(part, "elm.text")) {
		DBG(LOG_VERBOSE, "Adding text %s", part);
		return strdup("Select all");
	}
	return NULL;
}

/**
 *	This function let the ug get the icon of select all
 *	@return   the icon of select all
 *	@param[in] data the pointer to the main data structure
 *	@param[in] obj the pointer to the evas object
 *	@param[in] part the pointer to the part of item
 */
static Evas_Object *_wfd_gl_select_all_icon_get(void *data, Evas_Object *obj, const char *part)
{
	Evas_Object *icon = NULL;

	if (!strcmp(part, "elm.icon")) {
		DBG(LOG_VERBOSE, "Part %s", part);
		icon = elm_check_add(obj);
		elm_check_state_set(icon, EINA_FALSE);
		evas_object_smart_callback_add(icon, "changed", _wfd_check_clicked_cb, (void *)data);
	}

	return icon;
}

/**
 *	This function let the ug fee the multi connect devices
 *	@return   0
 *	@param[in] data the pointer to the main data structure
 */
int wfd_free_multiconnect_device(struct ug_data *ugd)
{
	__FUNC_ENTER__;

	int i = 0;

	if (ugd->multiconn_view_genlist == NULL) {
		return 0;
	}

	if (ugd->mcview_title_item != NULL) {
		elm_object_item_del(ugd->mcview_title_item);
		ugd->mcview_title_item = NULL;
	}

	if (ugd->mcview_select_all_item != NULL) {
		elm_object_item_del(ugd->mcview_select_all_item);
		ugd->mcview_select_all_item = NULL;
	}

	if (ugd->mcview_nodevice_item != NULL) {
		elm_object_item_del(ugd->mcview_nodevice_item);
		ugd->mcview_nodevice_item = NULL;
	}

	for (i = 0; i < ugd->gl_available_dev_cnt_at_multiconn_view;  i++) {
		if (ugd->multi_conn_dev_list[i].peer.gl_item != NULL) {
			elm_object_item_del(ugd->multi_conn_dev_list[i].peer.gl_item);
			ugd->multi_conn_dev_list[i].peer.gl_item = NULL;
		}
	}
	ugd->gl_available_dev_cnt_at_multiconn_view = 0;

	__FUNC_EXIT__;
	return 0;
}

/**
 *	This function let the ug update the multi connect devices
 *	@return   0
 *	@param[in] data the pointer to the main data structure
 */
int wfd_update_multiconnect_device(struct ug_data *ugd)
{
	__FUNC_ENTER__;

	int count = 0;
	device_type_s *device = NULL;
	Evas_Object *genlist = NULL;
	int i = 0;

	genlist = ugd->multiconn_view_genlist;
	if (ugd->multiconn_view_genlist == NULL) {
		return 0;
	}

	wfd_free_multiconnect_device(ugd);

	count = 0;
	for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
		device = &ugd->raw_discovered_peers[i];
		if (device->is_connected == FALSE) {
			count++;
		}
	}
	ugd->gl_available_dev_cnt_at_multiconn_view = count;

	if (ugd->gl_available_dev_cnt_at_multiconn_view == 0) {
		DBG(LOG_ERROR, "There are No peers\n");
		ugd->mcview_title_item = elm_genlist_item_append(genlist, &title_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		elm_genlist_item_select_mode_set(ugd->mcview_title_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
		ugd->mcview_nodevice_item = elm_genlist_item_append(genlist, &noitem_itc, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		elm_genlist_item_select_mode_set(ugd->mcview_nodevice_item , ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
	} else {
		ugd->mcview_title_item = elm_genlist_item_append(genlist, &title_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		elm_genlist_item_select_mode_set(ugd->mcview_title_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
		ugd->mcview_select_all_item = elm_genlist_item_append(genlist, &select_all_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, _wfd_gl_sel_cb, ugd);

		count = 0;
		for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
			device = &ugd->raw_discovered_peers[i];
			if (device->is_connected == FALSE) {
				DBG(LOG_VERBOSE, "%dth peer being added on genlist\n", i);

				if (ugd->multi_conn_dev_list[count].peer.gl_item != NULL) {
					elm_object_item_del(ugd->multi_conn_dev_list[count].peer.gl_item);
				}

				ugd->multi_conn_dev_list[count].peer.gl_item = NULL;
				memcpy(&ugd->multi_conn_dev_list[count].peer, device, sizeof(device_type_s));
				ugd->multi_conn_dev_list[count].dev_sel_state = FALSE;
				ugd->multi_conn_dev_list[count].peer.gl_item = elm_genlist_item_append(genlist, &device_itc,
					(void *)&ugd->multi_conn_dev_list[count].peer, NULL, ELM_GENLIST_ITEM_NONE, _wfd_gl_multi_sel_cb, ugd);
				count++;
			}
		}
	}

	__FUNC_EXIT__;
	return 0;
}

/**
 *	This function let the ug create the view for multi connection
 *	@return   void
 *	@param[in] ugd the pointer to the main data structure
 */
void wfd_create_multiconnect_view(struct ug_data *ugd)
{
	__FUNC_ENTER__;

	Evas_Object *back_btn = NULL;
	Evas_Object *genlist = NULL;
	Elm_Object_Item *navi_item = NULL;

	if (ugd == NULL) {
		DBG(LOG_ERROR, "Incorrect parameter(NULL)");
		return;
	}

	select_all_itc.item_style = "1text.1icon.3";
	select_all_itc.func.text_get = _wfd_gl_select_all_label_get;
	select_all_itc.func.content_get = _wfd_gl_select_all_icon_get;
	select_all_itc.func.state_get = NULL;
	select_all_itc.func.del = NULL;

	device_itc.item_style = "1text.2icon.2";
	device_itc.func.text_get = _wfd_gl_device_label_get;
	device_itc.func.content_get = _wfd_gl_device_icon_get;
	device_itc.func.state_get = NULL;
	device_itc.func.del = NULL;

	DBG(LOG_VERBOSE, "_wifid_create_multiconnect_view");
	back_btn = elm_button_add(ugd->naviframe);
	elm_object_style_set(back_btn, "naviframe/back_btn/default");
	evas_object_smart_callback_add(back_btn, "clicked", _multiconnect_view_back_btn_cb, (void *)ugd);
	elm_object_focus_allow_set(back_btn, EINA_FALSE);

	genlist = elm_genlist_add(ugd->naviframe);
	ugd->multiconn_view_genlist = genlist;
	ugd->mcview_title_item = NULL;

	wfd_update_multiconnect_device(ugd);

	evas_object_show(genlist);

	navi_item = elm_naviframe_item_push(ugd->naviframe, _("Multi connect"), back_btn, NULL, genlist, NULL);

	/* create scan button */
	ugd->multi_scan_btn = elm_button_add(ugd->naviframe);
	elm_object_style_set(ugd->multi_scan_btn, "naviframe/toolbar/default");
	elm_object_text_set(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"));
	evas_object_smart_callback_add(ugd->multi_scan_btn, "clicked", _scan_btn_cb, (void *)ugd);
	elm_object_item_part_content_set(navi_item, "toolbar_button1", ugd->multi_scan_btn);

	/* create connect button */
	ugd->multi_connect_btn = elm_button_add(ugd->naviframe);
	elm_object_style_set(ugd->multi_connect_btn, "naviframe/toolbar/default");
	elm_object_text_set(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"));
	evas_object_smart_callback_add(ugd->multi_connect_btn, "clicked", _connect_btn_cb, (void *)ugd);
	elm_object_disabled_set(ugd->multi_connect_btn, EINA_TRUE);
	elm_object_item_part_content_set(navi_item, "toolbar_button2", ugd->multi_connect_btn);

	__FUNC_EXIT__;
}