4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
25 #include <Elementary.h>
27 #include <ui-gadget-module.h>
28 #include <wifi-direct.h>
31 #include "wfd_ug_view.h"
32 #include "wfd_client.h"
35 * This function let the ug call it when click 'ok' button in hotspot action popup
37 * @param[in] data the pointer to the main data structure
38 * @param[in] obj the pointer to the evas object
39 * @param[in] event_info the pointer to the event information
41 static void _wfd_ug_act_popup_hotspot_ok_cb(void *data, Evas_Object *obj, void *event_info)
45 struct ug_data *ugd = (struct ug_data *) data;
47 result = wfd_mobile_ap_off(ugd);
49 /* refresh the header */
50 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
51 wfd_ug_view_refresh_glitem(ugd->head);
53 /* while activating/deactivating, disable the buttons */
55 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
58 if (ugd->multi_scan_btn) {
59 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
63 elm_object_disabled_set(ugd->back_btn, TRUE);
67 evas_object_del(ugd->act_popup);
68 ugd->act_popup = NULL;
73 * This function let the ug call it when click 'cancel' button in hotspot action popup
75 * @param[in] data the pointer to the main data structure
76 * @param[in] obj the pointer to the evas object
77 * @param[in] event_info the pointer to the event information
79 static void _wfd_ug_act_popup_hotspot_cancel_cb(void *data, Evas_Object *obj, void *event_info)
82 struct ug_data *ugd = (struct ug_data *) data;
84 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
85 wfd_ug_view_refresh_glitem(ugd->head);
87 evas_object_del(ugd->act_popup);
88 ugd->act_popup = NULL;
93 * This function let the ug call it when click 'ok' button in wifi action popup
95 * @param[in] data the pointer to the main data structure
96 * @param[in] obj the pointer to the evas object
97 * @param[in] event_info the pointer to the event information
99 static void _wfd_ug_act_popup_wifi_ok_cb(void *data, Evas_Object *obj, void *event_info)
103 struct ug_data *ugd = (struct ug_data *) data;
105 result = wfd_wifi_off(ugd);
107 /* refresh the header */
108 ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
109 wfd_ug_view_refresh_glitem(ugd->head);
111 /* while activating/deactivating, disable the buttons */
113 wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
116 if (ugd->multi_scan_btn) {
117 wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
121 elm_object_disabled_set(ugd->back_btn, TRUE);
125 evas_object_del(ugd->act_popup);
126 ugd->act_popup = NULL;
131 * This function let the ug call it when click 'cancel' button in wifi action popup
133 * @param[in] data the pointer to the main data structure
134 * @param[in] obj the pointer to the evas object
135 * @param[in] event_info the pointer to the event information
137 static void _wfd_ug_act_popup_wifi_cancel_cb(void *data, Evas_Object *obj, void *event_info)
140 struct ug_data *ugd = (struct ug_data *) data;
142 ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
143 wfd_ug_view_refresh_glitem(ugd->head);
145 evas_object_del(ugd->act_popup);
146 ugd->act_popup = NULL;
151 * This function let the ug call it when click 'ok' button in disconnect all popup
153 * @param[in] data the pointer to the main data structure
154 * @param[in] obj the pointer to the evas object
155 * @param[in] event_info the pointer to the event information
157 static void _wfd_ug_act_popup_disconnect_all_ok_cb(void *data, Evas_Object *obj, void *event_info)
161 struct ug_data *ugd = (struct ug_data *) data;
163 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
167 wfd_client_disconnect(NULL);
169 if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
170 wfd_free_multi_selected_peers(ugd);
172 /* update the connecting icon */
173 for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
174 ugd->raw_discovered_peers[i].conn_status = PEER_CONN_STATUS_DISCONNECTED;
175 wfd_ug_view_refresh_glitem(ugd->raw_discovered_peers[i].gl_item);
179 evas_object_del(ugd->act_popup);
180 ugd->act_popup = NULL;
186 * This function let the ug call it when click 'cancel' button in disconnect all popup
188 * @param[in] data the pointer to the main data structure
189 * @param[in] obj the pointer to the evas object
190 * @param[in] event_info the pointer to the event information
192 static void _wfd_ug_act_popup_disconnect_all_cancel_cb(void *data, Evas_Object *obj, void *event_info)
196 struct ug_data *ugd = (struct ug_data *) data;
198 DBG(LOG_ERROR, "Incorrect parameter(NULL)\n");
202 evas_object_del(ugd->act_popup);
203 ugd->act_popup = NULL;
209 * This function let the ug create a action popup
211 * @param[in] data the pointer to the main data structure
212 * @param[in] message the pointer to the text of popup
213 * @param[in] popup_type the message type
215 void wfd_ug_act_popup(void *data, const char *message, int popup_type)
218 struct ug_data *ugd = (struct ug_data *) data;
219 Evas_Object *popup = NULL;
220 Evas_Object *btn1 = NULL, *btn2 = NULL;
222 popup = elm_popup_add(ugd->base);
223 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
224 elm_object_text_set(popup, message);
226 btn1 = elm_button_add(popup);
227 btn2 = elm_button_add(popup);
228 elm_object_style_set(btn1, "popup_button/default");
229 elm_object_style_set(btn2, "popup_button/default");
231 /* set the different text by type */
232 if (popup_type == POPUP_TYPE_WIFI_OFF || popup_type == POPUP_TYPE_HOTSPOT_OFF) {
233 elm_object_text_set(btn1, S_("IDS_COM_SK_YES"));
234 elm_object_text_set(btn2, S_("IDS_COM_SK_NO"));
236 elm_object_text_set(btn1, S_("IDS_COM_SK_OK"));
237 elm_object_text_set(btn2, S_("IDS_COM_SK_CANCEL"));
240 elm_object_part_content_set(popup, "button1", btn1);
241 elm_object_part_content_set(popup, "button2", btn2);
243 /* set the different callback by type */
244 if (popup_type == POPUP_TYPE_WIFI_OFF) {
245 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_wifi_ok_cb, (void *)ugd);
246 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_wifi_cancel_cb, (void *)ugd);
247 } else if (popup_type == POPUP_TYPE_HOTSPOT_OFF) {
248 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_hotspot_ok_cb, (void *)ugd);
249 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_hotspot_cancel_cb, (void *)ugd);
250 } else if (popup_type == POP_TYPE_DISCONNECT ||
251 popup_type == POP_TYPE_DISCONNECT_ALL ||
252 popup_type == POP_TYPE_SCAN_AGAIN) {
253 evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void *)ugd);
254 evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_all_cancel_cb, (void *)ugd);
257 evas_object_show(popup);
258 ugd->act_popup = popup;
263 * This function let the ug remove the action popup
265 * @param[in] data the pointer to the main data structure
267 void wfg_ug_act_popup_remove(void *data)
270 struct ug_data *ugd = (struct ug_data *) data;
272 if (ugd->act_popup) {
273 evas_object_del(ugd->act_popup);
274 ugd->act_popup = NULL;
280 * This function let the ug call it when click 'ok' button in warning popup of terminated problem
282 * @param[in] data the pointer to the main data structure
283 * @param[in] obj the pointer to the evas object
284 * @param[in] event_info the pointer to the event information
286 static void _wfd_ug_terminate_popup_cb(void *data, Evas_Object *obj, void *event_info)
289 struct ug_data *ugd = (struct ug_data *) data;
291 evas_object_del(ugd->warn_popup);
292 ugd->warn_popup = NULL;
294 wfd_ug_view_free_peers(ugd);
296 ug_destroy_me(ugd->ug);
301 * This function let the ug call it when click 'ok' button in warning popup of turning off WFD automatically
303 * @param[in] data the pointer to the main data structure
304 * @param[in] obj the pointer to the evas object
305 * @param[in] event_info the pointer to the event information
307 static void _wfd_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
310 struct ug_data *ugd = (struct ug_data *) data;
312 evas_object_del(ugd->warn_popup);
313 ugd->warn_popup = NULL;
315 /* turn off the Wi-Fi Direct */
316 wfd_client_switch_off(ugd);
318 /* antomaticlly turn on tethering mode */
319 if (TRUE == ugd->is_hotspot_off) {
320 wfd_mobile_ap_on(ugd);
327 * This function let the ug call it when click 'ok' button in warning popup
329 * @param[in] data the pointer to the main data structure
330 * @param[in] obj the pointer to the evas object
331 * @param[in] event_info the pointer to the event information
333 static void _wfd_ug_warn_popup_cb(void *data, Evas_Object *obj, void *event_info)
336 struct ug_data *ugd = (struct ug_data *) data;
338 evas_object_del(ugd->warn_popup);
339 ugd->warn_popup = NULL;
345 * This function let the ug create a warning popup
347 * @param[in] data the pointer to the main data structure
348 * @param[in] message the pointer to the text of popup
349 * @param[in] popup_type the message type
351 void wfd_ug_warn_popup(void *data, const char *message, int popup_type)
354 struct ug_data *ugd = (struct ug_data *) data;
355 Evas_Object *popup = NULL;
356 Evas_Object *btn = NULL;
358 popup = elm_popup_add(ugd->base);
359 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360 elm_object_part_text_set(popup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
361 elm_object_text_set(popup, message);
363 btn = elm_button_add(popup);
364 elm_object_style_set(btn, "popup_button/default");
365 elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
366 elm_object_part_content_set(popup, "button1", btn);
367 if (popup_type == POPUP_TYPE_TERMINATE) {
368 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_terminate_popup_cb, (void *)ugd);
369 } else if (popup_type == POP_TYPE_AUTOMATIC_TURN_OFF) {
370 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, (void *)ugd);
372 evas_object_smart_callback_add(btn, "clicked", _wfd_ug_warn_popup_cb, (void *)ugd);
375 evas_object_show(popup);
376 ugd->warn_popup = popup;