summaryrefslogtreecommitdiff
path: root/src/bt-connection-main.c
blob: 96df31d76174f7c2af7852d59e079671b39999d0 (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
/*
* bt-connection-popup
*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Contact: Hocheol Seo <hocheol.seo@samsung.com>
*           Injun Yang <injun.yang@samsung.com>
*           Seungyoun Ju <sy39.ju@samsung.com>
*
* 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://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 <app.h>
#include <efl_assist.h>

#include "bt-connection-main.h"
#include "bt-connection-view.h"
#include "bt-connection-handler.h"
#include "bt-connection-ipc.h"

static Evas_Object* _create_win(const char *name)
{
	Evas_Object *eo;
	int w;
	int h;

	eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
	if (eo) {
		elm_win_title_set(eo, name);
		elm_win_borderless_set(eo, EINA_TRUE);
		ecore_x_window_size_get(ecore_x_window_root_first_get(),
					&w, &h);
		evas_object_resize(eo, w, h);
	}

	return eo;
}

static Eina_Bool _pop_cb(void *data, Elm_Object_Item *it)
{
	DBG("");

	if (!data) {
		return EINA_FALSE;
	}

	elm_exit();
	return EINA_FALSE;
}

void __destory_app_cb(void *data, Evas_Object *obj, void *event_info)
{
	if (data == NULL)
		return;

	DBG("EA Back on navi");

	bt_app_data_t *ad = (bt_app_data_t *)data;

	_bt_destroy_app(ad);
}

static Evas_Object* _create_layout_main(Evas_Object* parent)
{
	Evas_Object *layout;

	if (parent == NULL)
		return NULL;

	layout = elm_layout_add(parent);
	if (layout == NULL)
		return NULL;

	elm_layout_theme_set(layout, "layout", "application", "default");
	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_content_set(parent, "elm.swallow.content", layout);
	evas_object_show(layout);

	return layout;
}

static Evas_Object* _create_naviframe(Evas_Object* parent)
{
	Evas_Object *naviframe;

	if (parent == NULL)
		return NULL;
	naviframe = elm_naviframe_add(parent);
	elm_object_part_content_set(parent, "elm.swallow.content", naviframe);

	return naviframe;
}

static void _create_view_layout(bt_app_data_t *ad)
{
	if (ad == NULL || ad->navi == NULL)
		return;

	ea_object_event_callback_add(ad->navi, EA_CALLBACK_BACK,
		__destory_app_cb, ad);

	_bt_create_connection_query_popup(ad);

	DBG("-");
}

static int __initialize_view(bt_app_data_t *ad)
{
	DBG("+");

	Elm_Object_Item *navi_it;

	if (ad == NULL)
		return -1;

	ad->layout_main = _create_layout_main(ad->window);
	if (!ad->layout_main)
		return -1;

	ad->navi = _create_naviframe(ad->layout_main);

	_create_view_layout(ad);

	navi_it = elm_naviframe_item_push(ad->navi, NULL, NULL, NULL, ad->main_layout, NULL);
	elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE);
	elm_naviframe_item_pop_cb_set(navi_it, _pop_cb, ad);
	elm_naviframe_item_title_visible_set(navi_it, EINA_FALSE);

	DBG("-");

	return 0;
}

static bool app_create(void *data)
{
	DBG("");

	bt_app_data_t *ad;
	ad = (bt_app_data_t *)data;

	ad->initialize = FALSE;
	ad->window = _create_win(PACKAGE);
	if (ad->window == NULL)
		return FALSE;

	evas_object_show(ad->window);

	/* Handle rotation */
	if (elm_win_wm_rotation_supported_get(ad->window)) {
		int rots[4] = {0, 90, 180, 270};
		elm_win_wm_rotation_available_rotations_set(ad->window,
							(const int*)(&rots), 4);
	}

	_bt_register_vconf_handler(ad);

	return TRUE;
}

static void app_terminate(void *data)
{
	DBG("");

	int status;
	bt_app_data_t *ad = (bt_app_data_t *)data;
	if (ad == NULL)
		return;

	status = _bt_get_wms_status();
	if (status == WMS_DISCONNECTED) {
		/* In case WMS_CONNECTED, */
		/* we sent result on connected view */
		DBG("App terminiated. Send response (Not Connected)");
		_bt_send_result(ad, KEY_VAL_NOT_CONNECTED);
	}

	_bt_get_sap_status(); /* Check sap status */

	return;
}

static void app_pause(void *data)
{
	DBG("");
	return;
}

static void app_resume(void *data)
{
	DBG("");
	return;
}

static void app_service(service_h service, void *data)
{
	DBG("");

	char *caller = NULL;
	bt_app_data_t *ad;

	ad = (bt_app_data_t *)data;
	if (ad == NULL)
		return;

	if (ad->dbus_conn == NULL) {
		_bt_dbus_signal_init(ad);
	}

	ad->service = service;
	service_clone(&ad->service_clone, service);
	service_get_caller(service, &caller);
	DBG_SECURE("Launched by %s", caller);

	if (__initialize_view(ad) < 0) {
		ERR("__initialize_view failed");
	}

	return;
}

static void app_lang_changed(void *data)
{
	return;
}

static void app_regeion_changed(void *data)
{
	return;
}

/**
* @describe
*   The entry of the program
*
* @param    argc
* @param    argv
* @param    int
* @exception
*/
DLL_DEFAULT int main(int argc, char *argv[])
{
	bt_app_data_t ad;

	app_event_callback_s event_callback;

	event_callback.create = app_create;
	event_callback.terminate = app_terminate;
	event_callback.pause = app_pause;
	event_callback.resume = app_resume;
	event_callback.service = app_service;
	event_callback.low_memory = NULL;
	event_callback.low_battery = NULL;
	event_callback.device_orientation = NULL;
	event_callback.language_changed = app_lang_changed;
	event_callback.region_format_changed = app_regeion_changed;

	memset(&ad, 0x0, sizeof(bt_app_data_t));
	setenv("EVAS_NO_DRI_SWAPBUF", "1", 1);

	DBG("");
	return app_efl_main(&argc, &argv, &event_callback, &ad);

}