480668c332522c9b0de1029afac37ad56fc6a7ed
[apps/native/ug-wifi-direct.git] / ug-wifidirect / src / wfd_ug_multiconnect_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 #include <libintl.h>
21
22 #include <assert.h>
23 #include <glib.h>
24
25 #include <Elementary.h>
26 #include <vconf.h>
27 #include <ui-gadget-module.h>
28 #include <wifi-direct.h>
29
30 #include "wfd_ug.h"
31 #include "wfd_ug_view.h"
32 #include "wfd_client.h"
33
34 Elm_Gen_Item_Class select_all_itc;
35 Elm_Gen_Item_Class device_itc;
36
37 /**
38  *      This function let the ug call it when click 'back' button in multi connect view
39  *      @return   void
40  *      @param[in] data the pointer to the main data structure
41  *      @param[in] obj the pointer to the evas object
42  *      @param[in] event_info the pointer to the event information
43  */
44 void _multiconnect_view_back_btn_cb(void *data, Evas_Object * obj, void *event_info)
45 {
46         __WDUG_LOG_FUNC_ENTER__;
47         struct ug_data *ugd = (struct ug_data *)data;
48
49         if (!ugd) {
50                 WDUG_LOGE("The param is NULL\n");
51                 return;
52         }
53
54         ugd->multiconn_view_genlist = NULL;
55         elm_naviframe_item_pop(ugd->naviframe);
56
57         __WDUG_LOG_FUNC_EXIT__;
58         return;
59 }
60
61 /**
62  *      This function let the ug reset the connected failed peers
63  *      @return   false
64  *      @param[in] event_info the pointer to the event information
65  */
66 gboolean __wfd_multi_connect_reset_cb(void *data)
67 {
68         __WDUG_LOG_FUNC_ENTER__;
69         int i = 0;
70         struct ug_data *ugd = (struct ug_data *)data;
71
72         /* remove the failed peers*/
73         for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
74                 if (ugd->raw_multi_selected_peers[i].conn_status == PEER_CONN_STATUS_FAILED_TO_CONNECT) {
75                         memset(&ugd->raw_multi_selected_peers[i], 0x00, sizeof(device_type_s));
76                         ugd->raw_multi_selected_peer_cnt--;
77                 }
78         }
79
80         wfd_ug_view_update_peers(ugd);
81
82         __WDUG_LOG_FUNC_EXIT__;
83         return false;
84 }
85
86 /**
87  *      This function let the ug free the selected peers in multi connect view
88  *      @return   void
89  *      @param[in] data the pointer to the main data structure
90  */
91 void wfd_free_multi_selected_peers(void *data)
92 {
93         __WDUG_LOG_FUNC_ENTER__;
94         int i = 0;
95         struct ug_data *ugd = (struct ug_data *)data;
96
97         /* destroy the created group */
98         wifi_direct_destroy_group();
99
100         /* release the selected peers */
101         for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
102                 memset(&ugd->raw_multi_selected_peers[i], 0x00, sizeof(device_type_s));
103         }
104
105         ugd->raw_multi_selected_peer_cnt = 0;
106         ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_NONE;
107
108         __WDUG_LOG_FUNC_EXIT__;
109
110 }
111
112 /**
113  *      This function let the ug stop to connect to selected peer
114  *      @return   If success, return 0, else return -1
115  *      @param[in] data the pointer to the main data structure
116  */
117 int wfd_stop_multi_connect(void *data)
118 {
119         __WDUG_LOG_FUNC_ENTER__;
120         struct ug_data *ugd = (struct ug_data *)data;
121
122         /* change the title of failed peers */
123         ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_COMPLETED;
124         wfd_ug_view_refresh_glitem(ugd->multi_connect_wfd_item);
125
126         wfd_client_set_p2p_group_owner_intent(7);
127
128         /* after 30s, remove the failed peers */
129         g_timeout_add(30000 /*ms*/, __wfd_multi_connect_reset_cb, ugd);
130
131         __WDUG_LOG_FUNC_EXIT__;
132         return 0;
133 }
134
135 /**
136  *      This function let the ug start to connect the selected peers
137  *      @return   If success, return 0, else return -1
138  *      @param[in] data the pointer to the main data structure
139  */
140 int wfd_start_multi_connect(void *data)
141 {
142         __WDUG_LOG_FUNC_ENTER__;
143         struct ug_data *ugd = (struct ug_data *)data;
144         int res;
145
146         if (ugd->raw_multi_selected_peer_cnt > 0) {
147                 ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_IN_PROGRESS;
148
149                 res = wfd_client_group_add();
150                 if (res == -1) {
151                         WDUG_LOGE("Failed to add group");
152                         wfd_free_multi_selected_peers(ugd);
153
154                         __WDUG_LOG_FUNC_EXIT__;
155                         return -1;
156                 }
157
158         } else {
159                 WDUG_LOGD("No selected peers.\n");
160                 return -1;
161         }
162
163         __WDUG_LOG_FUNC_EXIT__;
164         return 0;
165 }
166
167 /**
168  *      This function let the ug connect to the next selected peer automatically
169  *      @return   If stop the timer, return false, else return true
170  *      @param[in] data the pointer to the main data structure
171  */
172 gboolean wfd_multi_connect_next_cb(void *data)
173 {
174         __WDUG_LOG_FUNC_ENTER__;
175         struct ug_data *ugd = (struct ug_data *)data;
176         int i;
177         int res;
178
179         // Reset g_source handler..
180         ugd->g_source_multi_connect_next = 0;
181
182         if (ugd->raw_multi_selected_peer_cnt > 0) {
183                 ugd->multi_connect_mode = WFD_MULTI_CONNECT_MODE_IN_PROGRESS;
184                 for (i = 0; i < ugd->raw_multi_selected_peer_cnt; i++) {
185                         if (ugd->raw_multi_selected_peers[i].conn_status == PEER_CONN_STATUS_WAIT_FOR_CONNECT) {
186                                 res = wfd_client_connect(ugd->raw_multi_selected_peers[i].mac_addr);
187                                 if (res == -1) {
188                                         WDUG_LOGD("Failed to connect [%s].\n", ugd->raw_multi_selected_peers[i].ssid);
189                                         ugd->raw_multi_selected_peers[i].conn_status = PEER_CONN_STATUS_FAILED_TO_CONNECT;
190                                 } else {
191                                         ugd->raw_multi_selected_peers[i].conn_status = PEER_CONN_STATUS_CONNECTING;
192                                         break;
193                                 }
194                         }
195                 }
196
197                 if (i >= ugd->raw_multi_selected_peer_cnt) {
198                         // All selected peers are touched.
199                         WDUG_LOGD("Stop Multi Connect...\n");
200                         wfd_stop_multi_connect(ugd);
201                 }
202         } else {
203                 WDUG_LOGD("No selected peers.\n");
204                 return -1;
205         }
206
207         __WDUG_LOG_FUNC_EXIT__;
208         return false;
209 }
210
211 /**
212  *      This function let the ug call it when click 'connect' button in multi connect view
213  *      @return   void
214  *      @param[in] data the pointer to the main data structure
215  *      @param[in] obj the pointer to the evas object
216  *      @param[in] event_info the pointer to the event information
217  */
218 void _connect_btn_cb(void *data, Evas_Object *obj, void *event_info)
219 {
220         __WDUG_LOG_FUNC_ENTER__;
221         struct ug_data *ugd = (struct ug_data *)data;
222         int i = 0;
223         int count = 0;
224         char popup_text[MAX_POPUP_TEXT_SIZE] = {0};
225         WDUG_LOGD("_connect_btn_cb \n");
226
227         for (i = 0; i < ugd->gl_available_peer_cnt ; i++) {
228                 if (TRUE == ugd->multi_conn_dev_list[i].dev_sel_state) {
229                         WDUG_LOGD("ugd->peers[i].mac_addr = %s, i = %d\n", ugd->multi_conn_dev_list[i].peer.mac_addr, i);
230
231                         memcpy(&ugd->raw_multi_selected_peers[count], &ugd->multi_conn_dev_list[i].peer, sizeof(device_type_s));
232                         ugd->raw_multi_selected_peers[count].conn_status = PEER_CONN_STATUS_WAIT_FOR_CONNECT;
233                         count++;
234                 }
235         }
236
237         ugd->raw_multi_selected_peer_cnt = count;
238
239         /* if more than 7 device selected, show the popup */
240         if (count > MAX_POPUP_PEER_NUM) {
241                 snprintf(popup_text, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_MULTI_CONNECT"), count);
242                 wfd_ug_warn_popup(ugd, popup_text, POP_TYPE_MULTI_CONNECT_POPUP);
243         }
244
245         /* start multi connection */
246         wfd_start_multi_connect(ugd);
247
248         elm_naviframe_item_pop(ugd->naviframe);
249
250         //ToDo: Do we need to free multiconn_view_genlist?
251         ugd->multiconn_view_genlist = NULL;
252         _change_multi_button_title(ugd);
253
254         __WDUG_LOG_FUNC_EXIT__;
255         return;
256 }
257
258 /**
259  *      This function let the ug delete 'select(n)' notify
260  *      @return   void
261  *      @param[in] data the pointer to the main data structure
262  */
263 static void _wfd_multi_del_select_info_label(void *data)
264 {
265         __WDUG_LOG_FUNC_ENTER__;
266         struct ug_data *ugd = (struct ug_data *)data;
267
268         if (NULL == ugd) {
269                 WDUG_LOGE("The param is NULL\n");
270                 return;
271         }
272
273         if (ugd->notify) {
274                 evas_object_del(ugd->notify);
275                 ugd->notify = NULL;
276         }
277
278         if (ugd->notify_layout) {
279                 evas_object_del(ugd->notify_layout);
280                 ugd->notify_layout = NULL;
281         }
282
283         __WDUG_LOG_FUNC_EXIT__;
284         return;
285 }
286
287 /**
288  *      This function let the ug add 'select(n)' notify
289  *      @return   void
290  *      @param[in] data the pointer to the main data structure
291  *      @param[in] count the number of selected peers
292  */
293 static void _wfd_multi_add_select_info_label(void *data, int count)
294 {
295         __WDUG_LOG_FUNC_ENTER__;
296
297         char select_lablel[MAX_POPUP_TEXT_SIZE] = {0};
298         struct ug_data *ugd = (struct ug_data *)data;
299
300         if (NULL == ugd || count <= 0) {
301                 WDUG_LOGE("The param is NULL\n");
302                 return;
303         }
304
305         /* delete previous notify */
306         _wfd_multi_del_select_info_label(ugd);
307
308         /* add notify */
309         ugd->notify = elm_notify_add(ugd->base);
310         if (NULL == ugd->notify) {
311                 WDUG_LOGE("Add notify failed\n");
312                 return;
313         }
314
315         /* set the align to center of bottom */
316         elm_notify_align_set(ugd->notify, ELM_NOTIFY_ALIGN_FILL, 1.0);
317
318         ugd->notify_layout = elm_layout_add(ugd->notify);
319         if (NULL == ugd->notify_layout) {
320                 evas_object_del(ugd->notify);
321                 ugd->notify = NULL;
322                 return;
323         }
324
325         elm_layout_theme_set(ugd->notify_layout, "standard", "selectioninfo", "vertical/bottom_64");
326         elm_object_content_set(ugd->notify, ugd->notify_layout);
327
328         snprintf(select_lablel, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), count);
329         elm_object_part_text_set(ugd->notify_layout, "elm.text", select_lablel);
330         elm_notify_timeout_set(ugd->notify, 3);
331         evas_object_show(ugd->notify);
332
333         __WDUG_LOG_FUNC_EXIT__;
334         return;
335 }
336
337 /**
338  *      This function let the ug call it when click the peer in multi connect view
339  *      @return   void
340  *      @param[in] data the pointer to the main data structure
341  *      @param[in] obj the pointer to the evas object
342  *      @param[in] event_info the pointer to the event information
343  */
344 static void _wfd_gl_multi_sel_cb(void *data, Evas_Object *obj, void *event_info)
345 {
346         __WDUG_LOG_FUNC_ENTER__;
347
348         int i = 0;
349         int index = 0;
350         int sel_count = 0;
351         bool is_sel = FALSE;
352         bool is_selct_all = TRUE;
353         Eina_Bool state = 0;
354         Evas_Object *chk_box = NULL;
355         char msg[MAX_POPUP_TEXT_SIZE] = {0};
356         struct ug_data *ugd = (struct ug_data *)data;
357         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
358
359         if (NULL == ugd || NULL == item) {
360                 WDUG_LOGE("The param is NULL\n");
361                 return;
362         }
363
364         elm_genlist_item_selected_set(item, EINA_FALSE);
365         index = elm_genlist_item_index_get(item) - 2; /* subtract the previous items */
366         WDUG_LOGD("selected index = %d \n", index);
367         if (index < 0) {
368                 WDUG_LOGE("The index is invalid.\n");
369                 return;
370         }
371
372         chk_box = elm_object_item_part_content_get((Elm_Object_Item *)event_info, "elm.icon.1");
373         state = elm_check_state_get(chk_box);
374         WDUG_LOGD("state = %d \n", state);
375         elm_check_state_set(chk_box, !state);
376
377         ugd->multi_conn_dev_list[index].dev_sel_state = !state;
378         WDUG_LOGD("ptr->dev_sel_state = %d \n", ugd->multi_conn_dev_list[index].dev_sel_state);
379         WDUG_LOGD("ptr->peer.mac_addr = %s \n", ugd->multi_conn_dev_list[index].peer.mac_addr);
380
381         /* update the checkbox and button */
382         for (; i < ugd->gl_available_dev_cnt_at_multiconn_view; i++) {
383                 if (ugd->multi_conn_dev_list[i].dev_sel_state) {
384                         is_sel = TRUE;
385                         sel_count++;
386                 } else {
387                         is_selct_all = FALSE;
388                 }
389         }
390
391         chk_box = elm_object_item_part_content_get(ugd->mcview_select_all_item, "elm.icon");
392         elm_check_state_set(chk_box, is_selct_all);
393
394         if (ugd->multi_connect_btn) {
395                 wfd_ug_view_refresh_button(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"), is_sel);
396         }
397
398         if (sel_count > 0) {
399                 snprintf(msg, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), sel_count);
400                 _wfd_multi_add_select_info_label(ugd, sel_count);
401         } else {
402                 _wfd_multi_del_select_info_label(ugd);
403         }
404
405         __WDUG_LOG_FUNC_EXIT__;
406 }
407
408 /**
409  *      This function let the ug call it when click the 'select all' item in multi connect view
410  *      @return   void
411  *      @param[in] data the pointer to the main data structure
412  *      @param[in] obj the pointer to the evas object
413  *      @param[in] event_info the pointer to the event information
414  */
415 static void _wfd_gl_sel_cb(void *data, Evas_Object *obj, void *event_info)
416 {
417         int sel_count = 0;
418         char msg[MAX_POPUP_TEXT_SIZE] = {0};
419         struct ug_data *ugd = (struct ug_data *)data;
420
421         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
422
423         if (NULL == ugd || NULL == obj) {
424                 WDUG_LOGE("NULL parameters.\n");
425                 return;
426         }
427
428         Evas_Object *sel_chkbox = elm_object_item_part_content_get(ugd->mcview_select_all_item, "elm.icon");
429         if (sel_chkbox == NULL) {
430                 WDUG_LOGD("select-all chkbox is NULL\n");
431                 return;
432         }
433
434         Eina_Bool state = elm_check_state_get(sel_chkbox);
435         if (state == TRUE) {
436                 state = FALSE;
437         } else {
438                 state = TRUE;
439         }
440
441         elm_check_state_set(sel_chkbox, state);
442         WDUG_LOGD("state = %d \n", state);
443
444         int i = 0;
445         bool is_sel = FALSE;
446         Elm_Object_Item *item = NULL;
447         Evas_Object *chk_box = NULL;
448
449         /* set the state of all the available devices */
450         for (i = 0; i < ugd->gl_available_dev_cnt_at_multiconn_view; i++) {
451                 is_sel = state;
452                 ugd->multi_conn_dev_list[i].dev_sel_state = state;
453                 item = ugd->multi_conn_dev_list[i].peer.gl_item;
454                 chk_box = elm_object_item_part_content_get(item, "elm.icon.1");
455                 elm_check_state_set(chk_box, state);
456
457                 if (state) {
458                         sel_count++;
459                 }
460         }
461
462         /* update the connect button */
463         if (ugd->multi_connect_btn) {
464                 wfd_ug_view_refresh_button(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"), is_sel);
465         }
466
467         /* tickernoti popup */
468         if (sel_count > 0) {
469                 snprintf(msg, MAX_POPUP_TEXT_SIZE, _("IDS_WFD_POP_SELECTED_DEVICE_NUM"), sel_count);
470                 _wfd_multi_add_select_info_label(ugd, sel_count);
471         } else {
472                 _wfd_multi_del_select_info_label(ugd);
473         }
474 }
475
476 /**
477  *      This function let the ug get the label of peer
478  *      @return   the label of peer
479  *      @param[in] data the pointer to the main data structure
480  *      @param[in] obj the pointer to the evas object
481  *      @param[in] part the pointer to the part of item
482  */
483 static char *_wfd_gl_device_label_get(void *data, Evas_Object *obj, const char *part)
484 {
485         WDUG_LOGD("part %s", part);
486         device_type_s *peer = (device_type_s *)data;
487
488         if (NULL == peer) {
489                 return NULL;
490         }
491
492         if (!strcmp(part, "elm.text")) {
493                 return strdup(peer->ssid);
494         }
495         return NULL;
496 }
497
498 /**
499  *      This function let the ug get the icon path of peer
500  *      @return   the  icon path of titile
501  *      @param[in] peer the pointer to the peer
502  */
503 static char *__wfd_get_device_icon_path(device_type_s *peer)
504 {
505         char *img_path = NULL;
506
507         switch (peer->category) {
508         case WFD_DEVICE_TYPE_COMPUTER:
509                 img_path = WFD_ICON_DEVICE_COMPUTER;
510                 break;
511         case WFD_DEVICE_TYPE_INPUT_DEVICE:
512                 img_path = WFD_ICON_DEVICE_INPUT_DEVICE;
513                 break;
514         case WFD_DEVICE_TYPE_PRINTER:
515                 img_path = WFD_ICON_DEVICE_PRINTER;
516                 break;
517         case WFD_DEVICE_TYPE_CAMERA:
518                 img_path = WFD_ICON_DEVICE_CAMERA;
519                 break;
520         case WFD_DEVICE_TYPE_STORAGE:
521                 img_path = WFD_ICON_DEVICE_STORAGE;
522                 break;
523         case WFD_DEVICE_TYPE_NW_INFRA:
524                 img_path = WFD_ICON_DEVICE_NETWORK_INFRA;
525                 break;
526         case WFD_DEVICE_TYPE_DISPLAYS:
527                 img_path = WFD_ICON_DEVICE_DISPLAY;
528                 break;
529         case WFD_DEVICE_TYPE_MM_DEVICES:
530                 img_path = WFD_ICON_DEVICE_MULTIMEDIA_DEVICE;
531                 break;
532         case WFD_DEVICE_TYPE_GAME_DEVICES:
533                 img_path = WFD_ICON_DEVICE_GAMING_DEVICE;
534                 break;
535         case WFD_DEVICE_TYPE_TELEPHONE:
536                 img_path = WFD_ICON_DEVICE_TELEPHONE;
537                 break;
538         case WFD_DEVICE_TYPE_AUDIO:
539                 img_path = WFD_ICON_DEVICE_AUDIO_DEVICE;
540                 break;
541         default:
542                 img_path = WFD_ICON_DEVICE_COMPUTER;
543                 break;
544         }
545
546         return img_path;
547 }
548
549
550 /**
551  *      This function let the ug call it when click the check box
552  *      @return   void
553  *      @param[in] data the pointer to the main data structure
554  *      @param[in] obj the pointer to the evas object
555  *      @param[in] event_info the pointer to the event information
556  */
557 static void _wfd_check_clicked_cb(void *data, Evas_Object *obj, void *event_info)
558 {
559         if (NULL == obj) {
560                 WDUG_LOGE("NULL parameters.\n");
561                 return;
562         }
563
564         Eina_Bool state = elm_check_state_get(obj);
565         elm_check_state_set(obj, !state);
566         WDUG_LOGD("state = %d \n", state);
567 }
568
569 /**
570  *      This function let the ug get the icon of peer
571  *      @return   the icon of peer
572  *      @param[in] data the pointer to the main data structure
573  *      @param[in] obj the pointer to the evas object
574  *      @param[in] part the pointer to the part of item
575  */
576 static Evas_Object *_wfd_gl_device_icon_get(void *data, Evas_Object *obj, const char *part)
577 {
578         char *img_path = NULL;
579         device_type_s *peer = (device_type_s *) data;
580         Evas_Object *icon = NULL;
581
582         WDUG_LOGD("Part %s", part);
583
584         if (!strcmp(part, "elm.icon.1")) {
585                 WDUG_LOGD("Part %s", part);
586                 icon = elm_check_add(obj);
587                 elm_check_state_set(icon, EINA_FALSE);
588                 evas_object_smart_callback_add(icon, "changed", _wfd_check_clicked_cb, (void *)data);
589         } else if (!strcmp(part, "elm.icon.2")) {
590                 img_path = __wfd_get_device_icon_path(peer);
591                 icon = elm_icon_add(obj);
592                 elm_icon_file_set(icon, img_path, NULL);
593                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
594                 elm_icon_resizable_set(icon, 1, 1);
595                 evas_object_show(icon);
596         }
597
598         return icon;
599 }
600
601 /**
602  *      This function let the ug get the label of select all
603  *      @return   the label of select all
604  *      @param[in] data the pointer to the main data structure
605  *      @param[in] obj the pointer to the evas object
606  *      @param[in] part the pointer to the part of item
607  */
608 static char *_wfd_gl_select_all_label_get(void *data, Evas_Object *obj, const char *part)
609 {
610         if (!strcmp(part, "elm.text")) {
611                 WDUG_LOGD("Adding text %s", part);
612                 return strdup("Select all");
613         }
614         return NULL;
615 }
616
617 /**
618  *      This function let the ug get the icon of select all
619  *      @return   the icon of select all
620  *      @param[in] data the pointer to the main data structure
621  *      @param[in] obj the pointer to the evas object
622  *      @param[in] part the pointer to the part of item
623  */
624 static Evas_Object *_wfd_gl_select_all_icon_get(void *data, Evas_Object *obj, const char *part)
625 {
626         Evas_Object *icon = NULL;
627
628         if (!strcmp(part, "elm.icon")) {
629                 WDUG_LOGD("Part %s", part);
630                 icon = elm_check_add(obj);
631                 elm_check_state_set(icon, EINA_FALSE);
632                 evas_object_smart_callback_add(icon, "changed", _wfd_check_clicked_cb, (void *)data);
633         }
634
635         return icon;
636 }
637
638 /**
639  *      This function let the ug fee the multi connect devices
640  *      @return   0
641  *      @param[in] data the pointer to the main data structure
642  */
643 int wfd_free_multiconnect_device(struct ug_data *ugd)
644 {
645         __WDUG_LOG_FUNC_ENTER__;
646
647         int i = 0;
648
649         if (ugd->multiconn_view_genlist == NULL) {
650                 return 0;
651         }
652
653         if (ugd->mcview_title_item != NULL) {
654                 elm_object_item_del(ugd->mcview_title_item);
655                 ugd->mcview_title_item = NULL;
656         }
657
658         if (ugd->mcview_select_all_item != NULL) {
659                 elm_object_item_del(ugd->mcview_select_all_item);
660                 ugd->mcview_select_all_item = NULL;
661         }
662
663         if (ugd->mcview_nodevice_item != NULL) {
664                 elm_object_item_del(ugd->mcview_nodevice_item);
665                 ugd->mcview_nodevice_item = NULL;
666         }
667
668         for (i = 0; i < ugd->gl_available_dev_cnt_at_multiconn_view;  i++) {
669                 if (ugd->multi_conn_dev_list[i].peer.gl_item != NULL) {
670                         elm_object_item_del(ugd->multi_conn_dev_list[i].peer.gl_item);
671                         ugd->multi_conn_dev_list[i].peer.gl_item = NULL;
672                 }
673         }
674         ugd->gl_available_dev_cnt_at_multiconn_view = 0;
675
676         __WDUG_LOG_FUNC_EXIT__;
677         return 0;
678 }
679
680 /**
681  *      This function let the ug update the multi connect devices
682  *      @return   0
683  *      @param[in] data the pointer to the main data structure
684  */
685 int wfd_update_multiconnect_device(struct ug_data *ugd)
686 {
687         __WDUG_LOG_FUNC_ENTER__;
688
689         int count = 0;
690         device_type_s *device = NULL;
691         Evas_Object *genlist = NULL;
692         int i = 0;
693
694         genlist = ugd->multiconn_view_genlist;
695         if (ugd->multiconn_view_genlist == NULL) {
696                 return 0;
697         }
698
699         wfd_free_multiconnect_device(ugd);
700
701         count = 0;
702         for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
703                 device = &ugd->raw_discovered_peers[i];
704                 if (device->is_connected == FALSE) {
705                         count++;
706                 }
707         }
708         ugd->gl_available_dev_cnt_at_multiconn_view = count;
709
710         if (ugd->gl_available_dev_cnt_at_multiconn_view == 0) {
711                 WDUG_LOGE("There are No peers\n");
712                 ugd->mcview_title_item = elm_genlist_item_append(genlist, &title_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
713                 elm_genlist_item_select_mode_set(ugd->mcview_title_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
714                 ugd->mcview_nodevice_item = elm_genlist_item_append(genlist, &noitem_itc, (void *)ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
715                 elm_genlist_item_select_mode_set(ugd->mcview_nodevice_item , ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
716         } else {
717                 ugd->mcview_title_item = elm_genlist_item_append(genlist, &title_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
718                 elm_genlist_item_select_mode_set(ugd->mcview_title_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
719                 ugd->mcview_select_all_item = elm_genlist_item_append(genlist, &select_all_itc, ugd, NULL, ELM_GENLIST_ITEM_NONE, _wfd_gl_sel_cb, ugd);
720
721                 count = 0;
722                 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
723                         device = &ugd->raw_discovered_peers[i];
724                         if (device->is_connected == FALSE) {
725                                 WDUG_LOGD("%dth peer being added on genlist\n", i);
726
727                                 if (ugd->multi_conn_dev_list[count].peer.gl_item != NULL) {
728                                         elm_object_item_del(ugd->multi_conn_dev_list[count].peer.gl_item);
729                                 }
730
731                                 ugd->multi_conn_dev_list[count].peer.gl_item = NULL;
732                                 memcpy(&ugd->multi_conn_dev_list[count].peer, device, sizeof(device_type_s));
733                                 ugd->multi_conn_dev_list[count].dev_sel_state = FALSE;
734                                 ugd->multi_conn_dev_list[count].peer.gl_item = elm_genlist_item_append(genlist, &device_itc,
735                                         (void *)&ugd->multi_conn_dev_list[count].peer, NULL, ELM_GENLIST_ITEM_NONE, _wfd_gl_multi_sel_cb, ugd);
736                                 count++;
737                         }
738                 }
739         }
740
741         __WDUG_LOG_FUNC_EXIT__;
742         return 0;
743 }
744
745 /**
746  *      This function let the ug create the view for multi connection
747  *      @return   void
748  *      @param[in] ugd the pointer to the main data structure
749  */
750 void wfd_create_multiconnect_view(struct ug_data *ugd)
751 {
752         __WDUG_LOG_FUNC_ENTER__;
753
754         Evas_Object *back_btn = NULL;
755         Evas_Object *genlist = NULL;
756         Elm_Object_Item *navi_item = NULL;
757
758         if (ugd == NULL) {
759                 WDUG_LOGE("Incorrect parameter(NULL)");
760                 return;
761         }
762
763         select_all_itc.item_style = "1text.1icon.3";
764         select_all_itc.func.text_get = _wfd_gl_select_all_label_get;
765         select_all_itc.func.content_get = _wfd_gl_select_all_icon_get;
766         select_all_itc.func.state_get = NULL;
767         select_all_itc.func.del = NULL;
768
769         device_itc.item_style = "1text.2icon.2";
770         device_itc.func.text_get = _wfd_gl_device_label_get;
771         device_itc.func.content_get = _wfd_gl_device_icon_get;
772         device_itc.func.state_get = NULL;
773         device_itc.func.del = NULL;
774
775         WDUG_LOGD("_wifid_create_multiconnect_view");
776         back_btn = elm_button_add(ugd->naviframe);
777         elm_object_style_set(back_btn, "naviframe/back_btn/default");
778         evas_object_smart_callback_add(back_btn, "clicked", _multiconnect_view_back_btn_cb, (void *)ugd);
779         elm_object_focus_allow_set(back_btn, EINA_FALSE);
780
781         genlist = elm_genlist_add(ugd->naviframe);
782         ugd->multiconn_view_genlist = genlist;
783         ugd->mcview_title_item = NULL;
784
785         wfd_update_multiconnect_device(ugd);
786
787         evas_object_show(genlist);
788
789         navi_item = elm_naviframe_item_push(ugd->naviframe, _("Multi connect"), back_btn, NULL, genlist, NULL);
790
791         /* create scan button */
792         ugd->multi_scan_btn = elm_button_add(ugd->naviframe);
793         elm_object_style_set(ugd->multi_scan_btn, "naviframe/toolbar/default");
794         elm_object_text_set(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"));
795         evas_object_smart_callback_add(ugd->multi_scan_btn, "clicked", _scan_btn_cb, (void *)ugd);
796         elm_object_item_part_content_set(navi_item, "toolbar_button1", ugd->multi_scan_btn);
797
798         /* create connect button */
799         ugd->multi_connect_btn = elm_button_add(ugd->naviframe);
800         elm_object_style_set(ugd->multi_connect_btn, "naviframe/toolbar/default");
801         elm_object_text_set(ugd->multi_connect_btn, _("IDS_WFD_BUTTON_CONNECT"));
802         evas_object_smart_callback_add(ugd->multi_connect_btn, "clicked", _connect_btn_cb, (void *)ugd);
803         elm_object_disabled_set(ugd->multi_connect_btn, EINA_TRUE);
804         elm_object_item_part_content_set(navi_item, "toolbar_button2", ugd->multi_connect_btn);
805
806         __WDUG_LOG_FUNC_EXIT__;
807 }