d4af841469022bf5d33dbc8f028850e73c68c347
[apps/home/ug-wifi-efl.git] / sources / ui-gadget / wifi-ui-list-callbacks.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *    http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17
18
19 #include "wifi.h"
20 #include "wifi-ui-list-callbacks.h"
21 #include "wlan_manager.h"
22 #include "view_detail.h"
23 #include "viewer_list.h"
24 #include "view_ime_password.h"
25 #include "view_eap.h"
26 #include "popup.h"
27
28
29 void radio_button_cb(void *data, Evas_Object *obj, void *event_info)
30 {
31         __COMMON_FUNC_ENTER__;
32
33         int ret = WLAN_MANAGER_ERR_UNKNOWN;
34         if (data == NULL) {
35                 ERROR_LOG(UG_NAME_NORMAL, "Error!!! Invalid argument device_info");
36                 goto radio_button_cb_process_end;
37         }
38
39         //selected UI and it`s data
40         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
41         wifi_device_info_t *device_info = (wifi_device_info_t *)data;
42
43         if (device_info->ssid == NULL) {
44                 ERROR_LOG(UG_NAME_NORMAL, "Error!!! Invalid argument device_info ssid");
45                 goto radio_button_cb_process_end;
46         }
47
48         viewer_manager_set_enabled_list_update(EINA_FALSE);
49         viewer_manager_current_selected_item_set(it);
50
51         genlist_data* gdata = (genlist_data*) viewer_list_item_data_get((Elm_Object_Item*)it, "data");
52         if(NULL == gdata) {
53                 ERROR_LOG(UG_NAME_NORMAL, "Error!!! list item data null");
54                 goto radio_button_cb_process_end;
55         }
56
57         int item_state = gdata->radio_mode;
58
59         INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
60         INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d\n", item_state);
61         INFO_LOG(UG_NAME_NORMAL, "selected item_state %d", item_state);
62
63         switch (item_state) {
64                 case VIEWER_ITEM_RADIO_MODE_NULL: //this is OFF too. of course, NULL should be un-state
65                 case VIEWER_ITEM_RADIO_MODE_OFF:
66                         break;
67                 case VIEWER_ITEM_RADIO_MODE_CONNECTED:
68                         INFO_LOG(UG_NAME_NORMAL, "want to disconnect for connected item");
69                         viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_DISCONNECTING);
70                         ret = wlan_manager_request_disconnection(device_info);
71                         if(ret == WLAN_MANAGER_ERR_NONE){
72                                 viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_DISCONNECTING);
73                                 viewer_manager_header_mode_set(HEADER_MODE_DISCONNECTING);
74                                 viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_DISCONNECTING);
75
76                         } else {
77                                 viewer_manager_item_radio_mode_set(NULL, it , VIEWER_ITEM_RADIO_MODE_OFF);
78                         }
79
80                         goto radio_button_cb_process_end;
81
82                 case VIEWER_ITEM_RADIO_MODE_CONNECTING:
83                         INFO_LOG(UG_NAME_NORMAL, "want to cancel connecting for connected item");
84
85                         ret = wlan_manager_request_cancel_connecting(device_info->profile_name);
86                         if(ret == WLAN_MANAGER_ERR_NONE){
87                                 viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_CANCEL_CONNECTING);
88                                 viewer_manager_header_mode_set(HEADER_MODE_CANCEL_CONNECTING);
89                                 viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_CANCEL_CONNECTING);
90                         } 
91                         goto radio_button_cb_process_end;
92
93                 default:
94                         ret = WLAN_MANAGER_ERR_UNKNOWN;
95                         goto radio_button_cb_process_end;
96         }
97
98         int current_state = -1;
99         current_state = viewer_manager_header_mode_get();
100
101         INFO_LOG(UG_NAME_NORMAL, "Clicked AP`s information\n");
102         INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
103
104         switch (current_state) {
105                 case HEADER_MODE_OFF:
106                         INFO_LOG(UG_NAME_NORMAL, "you can not connect when header off");
107                         break;
108                 case HEADER_MODE_CONNECTED:
109                         INFO_LOG(UG_NAME_NORMAL, "header mode connected. disconnect and connect needed");
110                 case HEADER_MODE_ON:
111                         viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_CONNECTING);
112
113                         ret = wlan_manager_request_connection(device_info);
114                         if (ret == WLAN_MANAGER_ERR_NONE) {
115                                 Elm_Object_Item* target_item = viewer_manager_current_selected_item_get();
116                                 viewer_manager_item_radio_mode_set(NULL, target_item, VIEWER_ITEM_RADIO_MODE_CONNECTING);
117                                 viewer_manager_header_mode_set(HEADER_MODE_CONNECTING);
118                                 viewer_manager_item_radio_mode_set(NULL, target_item, VIEWER_ITEM_RADIO_MODE_CONNECTING);
119                         } else {
120                                 viewer_manager_item_radio_mode_set(NULL, it, VIEWER_ITEM_RADIO_MODE_OFF);
121                         }
122                         break;
123
124                 case HEADER_MODE_SEARCHING:
125                 case HEADER_MODE_ACTIVATING:
126                 case HEADER_MODE_CONNECTING:
127                 case HEADER_MODE_DISCONNECTING:
128                 case HEADER_MODE_DEACTIVATING:
129                         viewer_manager_set_enabled_list_update(EINA_TRUE);
130                         viewer_manager_current_selected_item_set(NULL);
131                         INFO_LOG(UG_NAME_NORMAL, "Disable input");
132                         return;
133
134                 default:
135                         INFO_LOG(UG_NAME_NORMAL, "default");
136                         break;
137         }
138
139 radio_button_cb_process_end:
140
141         switch (ret) {
142         case WLAN_MANAGER_ERR_NONE:
143                 INFO_LOG(UG_NAME_NORMAL, "ERROR_NONE");
144                 break;
145         case WLAN_MANAGER_ERR_CONNECT_PASSWORD_NEEDED:
146                 view_ime_password(device_info);
147                 break;
148         case WLAN_MANAGER_ERR_CONNECT_EAP_SEC_TYPE:
149                 view_eap(device_info);
150                 break;
151         case WLAN_MANAGER_ERR_NOSERVICE:
152                 viewer_manager_set_enabled_list_update(EINA_TRUE);
153                 wlan_manager_scanned_profile_refresh(TRUE);
154                 break;
155         default:
156                 viewer_manager_set_enabled_list_update(EINA_TRUE);
157                 winset_popup_mode_set(NULL, POPUP_MODE_CONNECTING_FAILED, POPUP_OPTION_CONNECTING_FAILED_INVALID_OPERATION);
158                 ERROR_LOG(UG_NAME_NORMAL, "errro code [%d]", ret);
159                 break;
160         }
161
162         __COMMON_FUNC_EXIT__;
163 }
164
165 void list_select_cb(void *data, Evas_Object *obj, void *event_info)
166 {
167         __COMMON_FUNC_ENTER__;
168
169         INFO_LOG(UG_NAME_NORMAL,"=================\n");
170         INFO_LOG(UG_NAME_NORMAL," %s %d\n", __func__ ,__LINE__);
171         INFO_LOG(UG_NAME_NORMAL,"=================\n");
172
173         if (data == NULL) {
174                 __COMMON_FUNC_EXIT__;
175                 return;
176         }
177
178         wifi_device_info_t *device_info = (wifi_device_info_t *)data;
179
180         DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
181
182         viewer_manager_current_selected_item_set((Elm_Object_Item *)obj);
183
184         view_detail(device_info);
185
186         __COMMON_FUNC_EXIT__;
187 }
188