summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 794438bc31f21a0d8545e214f81b509f4a2e74f3 (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
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * 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 <Elementary.h>
#include <Ecore_X.h>
#include <utilX.h>
#include <dlog.h>
#include <ui-gadget.h>
#include "dbg.h"
#include "def.h"
#include "viewmgr.h"
#include "utils.h"
#include "json_marco.h"
#include "settings_provider.h"

#define PARAM_SETTINGS_ITEM "settings-item"
#define MAIN_CATALOG "maincatalog"

struct _appdata {
	Evas_Object *win;
	struct setting_mgr *mgr;
	const char *name;
	char *item;
	unsigned int service;
};

/**
*  Refresh first view stored in view list.
*
*  Get first _settinginfo from view_list of setting_mgr, then call vclass->refresh
*  and vclass-update to refresh.
*
*  @param priv [in] The function specific data which holds _appdata pointer.
*  @return void.
*/
static void _refresh(void *priv)
{
	struct _appdata *data;

	if (!priv)
		return;

	data = priv;

	if (!data->mgr)
		return;

	settingmgr_view_refresh(data->mgr);
}

/**
*  Add a basic win for settings app.
*
*  @param name [in] Window name.
*  @return Window evas object, NULL on error.
*/
static Evas_Object *_add_win(const char *name)
{
	Evas_Object *win;

	win = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (!win) {
		_ERR("failed to create window!");
		return NULL;
	}

	elm_win_title_set(win, name);
	elm_win_alpha_set(win, EINA_TRUE);

	elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
	elm_win_focus_highlight_style_set(win, DEFAULT_FOCUS_INVISIBLE);

	evas_object_show(win);

	return win;
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked once as app is launched, this function will
*  initialize app.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return true if success, false if fail.
*/
static bool _create(void *data)
{
	struct _appdata *ad;
	Evas_Object *win;
	int r;

	ad = data;
	if (!ad)
		return false;

	elm_theme_overlay_add(NULL, EDJ_THEME);

	win = _add_win(ad->name);
	if (!win)
		return false;

	r = UG_INIT_EFL(win, UG_OPT_INDICATOR_ENABLE);
	if (r == -1) {
		_ERR("ug init efl failed.");
		evas_object_del(win);
		return false;
	}

	r = provider_init();
	if (r != 0) {
		_ERR("Fail to init provider module");
		evas_object_del(win);
		return false;
	}

	ad->win = win;
	ad->service = 0;

	return true;
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked once just before app is terminated,
*  this functions will release all resources.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _terminate(void *data)
{
	struct _appdata *ad;

	if (!data) {
		_ERR("Parameter error!");
		return;
	}

	ad = data;

	settingmgr_fini(ad->mgr);

	provider_fini();

	if (ad->win)
		evas_object_del(ad->win);

	free(ad->item);
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked when the window of app become invisible.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _pause(void *data)
{
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked when the window of app become visible.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _resume(void *data)
{
	_DBG("############################# _resume #############################");
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked after _create callback (just after app enters main loop)
*  or after "re-launch".
*
*  @param service [in] The launching arguments.
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _service(service_h service, void *data)
{
	_DBG("############################# START _service #############################");
	struct _appdata *ad;
	struct setting_mgr *mgr;
	int r;
	char *param;
	unsigned int relaunch, refresh;

	if (!data)
		return;

	ad = data;
	param = NULL;

	if (ad->service) {
		service_get_extra_data(service, PARAM_SETTINGS_ITEM, &param);
		if ((!param && !ad->item) ||
				(param && ad->item &&
				!strcmp(ad->item, param))) {
			refresh = 1;
			relaunch = 0;
		} else {
			refresh = 0;
			relaunch = 1;
		}

		if (relaunch) {
			settingmgr_fini(ad->mgr);
		} else {
			if (refresh)
				_refresh(ad);

			return;
		}
	}

	mgr = settingmgr_init(ad->win);
	if (!mgr)
		app_efl_exit();

	r = service_get_extra_data(service, PARAM_SETTINGS_ITEM, &param);
	if (r == SERVICE_ERROR_NONE && param) {
		r = settingmgr_launch_item(mgr, param);
		if (r != 0) {
			_ERR("the item is not exist.");
			app_efl_exit();
		}
	} else {
		settingmgr_view_push(mgr, MAIN_CATALOG, NULL);
	}

	ad->mgr = mgr;
	ad->service = 1;

	free(ad->item);
	ad->item = param;
	_DBG("############################# END _service #############################");
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked when system language is changed.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _lang_changed(void *data)
{
	struct _appdata *ad;

	if (!data) {
		_ERR("Invalid argument");
		return;
	}

	ad = data;
	if (!ad->mgr)
		return;

	settingmgr_lang_changed(ad->mgr);
}

/**
*  An app event callback for app_efl_main.
*
*  This callback is invoked when system region is changed.
*
*  @param data [in] The function specific data passed by app_efl_main.
*  @return void.
*/
static void _region_changed(void *data)
{
}

/**
*  App launching entry.
*
*  @param argc [in] The launching argument numbers.
*  @param argv [in] The launching argument array.
*  @return 0 if success.
*/
int main(int argc, char **argv)
{
	struct _appdata ad;
	app_event_callback_s cbs = {
		.create = _create,
		.terminate = _terminate,
		.pause = _pause,
		.resume = _resume,
		.service = _service,
		.low_memory = NULL,
		.low_battery = NULL,
		.device_orientation = NULL,
		.language_changed = _lang_changed,
		.region_format_changed = _region_changed,
	};

	memset(&ad, 0x00, sizeof(ad));
	ad.name = PACKAGE;

	i18n_init();

	app_efl_main(&argc, &argv, &cbs, &ad);

	return 0;
}