summaryrefslogtreecommitdiff
path: root/ug-wifidirect/src/wfd_ug_popup.c
blob: 585ff87c5d2e5fa331d37f1c5647ebca603770ce (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
/*
*  WiFi-Direct UG
*
* Copyright 2012-2013 Samsung Electronics Co., Ltd

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

* http://floralicense.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"

/**
 *	This function let the ug call it when click 'ok' button in hotspot action 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 _wfd_ug_act_popup_hotspot_ok_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	int result = -1;
	struct ug_data *ugd = (struct ug_data *) data;

	result = wfd_mobile_ap_off(ugd);
	if (0 == result) {
		/* refresh the header */
		ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
		wfd_ug_view_refresh_glitem(ugd->head);

		/* while activating/deactivating, disable the buttons */
		if (ugd->scan_btn) {
			wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
		}

		if (ugd->multi_scan_btn) {
			wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
		}

		if (ugd->back_btn) {
			elm_object_disabled_set(ugd->back_btn, TRUE);
		}
	}

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'cancel' button in hotspot action 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 _wfd_ug_act_popup_hotspot_cancel_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

	ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
	wfd_ug_view_refresh_glitem(ugd->head);

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'ok' button in wifi action 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 _wfd_ug_act_popup_wifi_ok_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	int result = -1;
	struct ug_data *ugd = (struct ug_data *) data;

	result = wfd_wifi_off(ugd);
	if (0 == result) {
		/* refresh the header */
		ugd->head_text_mode = HEAD_TEXT_TYPE_ACTIVATING;
		wfd_ug_view_refresh_glitem(ugd->head);

		/* while activating/deactivating, disable the buttons */
		if (ugd->scan_btn) {
			wfd_ug_view_refresh_button(ugd->scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
		}

		if (ugd->multi_scan_btn) {
			wfd_ug_view_refresh_button(ugd->multi_scan_btn, _("IDS_WFD_BUTTON_SCAN"), FALSE);
		}

		if (ugd->back_btn) {
			elm_object_disabled_set(ugd->back_btn, TRUE);
		}
	}

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'cancel' button in wifi action 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 _wfd_ug_act_popup_wifi_cancel_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

	ugd->head_text_mode = HEAD_TEXT_TYPE_DIRECT;
	wfd_ug_view_refresh_glitem(ugd->head);

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'ok' button in disconnect all 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 _wfd_ug_act_popup_disconnect_all_ok_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	int i = 0;
	struct ug_data *ugd = (struct ug_data *) data;
	if (NULL == ugd) {
		WDUG_LOGE("Incorrect parameter(NULL)\n");
		return;
	}

	wfd_client_disconnect(NULL);

	if (ugd->multi_connect_mode != WFD_MULTI_CONNECT_MODE_NONE) {
		wfd_free_multi_selected_peers(ugd);
	} else {
		/* update the connecting icon */
		for (i = 0; i < ugd->raw_discovered_peer_cnt; i++) {
			ugd->raw_discovered_peers[i].conn_status = PEER_CONN_STATUS_DISCONNECTED;
			wfd_ug_view_refresh_glitem(ugd->raw_discovered_peers[i].gl_item);
		}
	}

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;

	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'cancel' button in disconnect all 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 _wfd_ug_act_popup_disconnect_all_cancel_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;

	struct ug_data *ugd = (struct ug_data *) data;
	if (NULL == ugd) {
		WDUG_LOGE("Incorrect parameter(NULL)\n");
		return;
	}

	evas_object_del(ugd->act_popup);
	ugd->act_popup = NULL;

	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug create a action popup
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] message the pointer to the text of popup
 *	@param[in] popup_type the message type
 */
void wfd_ug_act_popup(void *data, const char *message, int popup_type)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;
	Evas_Object *popup = NULL;
	Evas_Object *btn1 = NULL, *btn2 = NULL;

	popup = elm_popup_add(ugd->base);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_text_set(popup, message);

	btn1 = elm_button_add(popup);
	btn2 = elm_button_add(popup);
	elm_object_style_set(btn1, "popup_button/default");
	elm_object_style_set(btn2, "popup_button/default");

	/* set the different text by type */
	if (popup_type == POPUP_TYPE_WIFI_OFF || popup_type == POPUP_TYPE_HOTSPOT_OFF) {
		elm_object_text_set(btn1, S_("IDS_COM_SK_YES"));
		elm_object_text_set(btn2, S_("IDS_COM_SK_NO"));
	} else {
		elm_object_text_set(btn1, S_("IDS_COM_SK_OK"));
		elm_object_text_set(btn2, S_("IDS_COM_SK_CANCEL"));
	}

	elm_object_part_content_set(popup, "button1", btn1);
	elm_object_part_content_set(popup, "button2", btn2);

	/* set the different callback by type */
	if (popup_type == POPUP_TYPE_WIFI_OFF) {
		evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_wifi_ok_cb, (void *)ugd);
		evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_wifi_cancel_cb, (void *)ugd);
	} else if (popup_type == POPUP_TYPE_HOTSPOT_OFF) {
		evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_hotspot_ok_cb, (void *)ugd);
		evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_hotspot_cancel_cb, (void *)ugd);
	} else if (popup_type == POP_TYPE_DISCONNECT ||
		popup_type == POP_TYPE_DISCONNECT_ALL ||
		popup_type == POP_TYPE_SCAN_AGAIN) {
		evas_object_smart_callback_add(btn1, "clicked", _wfd_ug_act_popup_disconnect_all_ok_cb, (void *)ugd);
		evas_object_smart_callback_add(btn2, "clicked", _wfd_ug_act_popup_disconnect_all_cancel_cb, (void *)ugd);
	}

	evas_object_show(popup);
	ugd->act_popup = popup;
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug remove the action popup
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 */
void wfg_ug_act_popup_remove(void *data)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

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

/**
 *	This function let the ug call it when click 'ok' button in warning popup of terminated problem
 *	@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_ug_terminate_popup_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

	evas_object_del(ugd->warn_popup);
	ugd->warn_popup = NULL;

	wfd_ug_view_free_peers(ugd);

	ug_destroy_me(ugd->ug);
	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'ok' button in warning popup of turning off WFD automatically
 *	@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_ug_automatic_turn_off_popup_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

	evas_object_del(ugd->warn_popup);
	ugd->warn_popup = NULL;

	/* turn off the Wi-Fi Direct */
	wfd_client_switch_off(ugd);

	/* antomaticlly turn on tethering mode */
	if (TRUE == ugd->is_hotspot_off) {
		wfd_mobile_ap_on(ugd);
	}

	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug call it when click 'ok' button in warning 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 _wfd_ug_warn_popup_cb(void *data, Evas_Object *obj, void *event_info)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;

	evas_object_del(ugd->warn_popup);
	ugd->warn_popup = NULL;

	__WDUG_LOG_FUNC_EXIT__;
}

/**
 *	This function let the ug create a warning popup
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] message the pointer to the text of popup
 *	@param[in] popup_type the message type
 */
void wfd_ug_warn_popup(void *data, const char *message, int popup_type)
{
	__WDUG_LOG_FUNC_ENTER__;
	struct ug_data *ugd = (struct ug_data *) data;
	Evas_Object *popup = NULL;
	Evas_Object *btn = NULL;

	popup = elm_popup_add(ugd->base);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_text_set(popup, "title,text", _("IDS_WFD_POP_TITILE_CONNECTION"));
	elm_object_text_set(popup, message);

	btn = elm_button_add(popup);
	elm_object_style_set(btn, "popup_button/default");
	elm_object_text_set(btn, S_("IDS_COM_SK_OK"));
	elm_object_part_content_set(popup, "button1", btn);
	if (popup_type == POPUP_TYPE_TERMINATE) {
		evas_object_smart_callback_add(btn, "clicked", _wfd_ug_terminate_popup_cb, (void *)ugd);
	} else if (popup_type == POP_TYPE_AUTOMATIC_TURN_OFF) {
		evas_object_smart_callback_add(btn, "clicked", _wfd_ug_automatic_turn_off_popup_cb, (void *)ugd);
	} else {
		evas_object_smart_callback_add(btn, "clicked", _wfd_ug_warn_popup_cb, (void *)ugd);
	}

	evas_object_show(popup);
	ugd->warn_popup = popup;
	__WDUG_LOG_FUNC_EXIT__;
}