summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 031bea0b44dfacef0a626565faff6f5f1837c190 (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
/*
 * 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 <ui-gadget.h>
#include "dbg.h"
#include "def.h"
#include "viewmgr.h"
#include "utils.h"
#include "json_marco.h"
#include "settings_provider.h"

#include <BaseApp.h>

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

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;
}

class CApp : public CBaseApp {

	struct _appdata {
		Evas_Object *win;
		struct setting_mgr *mgr;
		const char *name;
		char *item;
		unsigned int app_control;
	} ad;
protected:

	virtual bool OnCreate(void)
	{
		Evas_Object *win;
		int r;

		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.item = NULL;
		ad.app_control = 0;

		return true;
	}

	virtual void OnTerminate(void)
	{
		settingmgr_fini(ad.mgr);

		provider_fini();

		if (ad.win)
			evas_object_del(ad.win);

		if(ad.item)
			free(ad.item);
	}
	virtual void OnAppControl(app_control_h app_control)
	{
		_DBG("  ******************* OnAppControl *********************");
		struct setting_mgr *mgr;
		int r;
		char *param;
		unsigned int relaunch, refresh;

		param = NULL;

		if (ad.app_control) {
			app_control_get_extra_data(app_control, 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)
				{
					if (!ad.mgr)
						return;

					settingmgr_view_refresh(ad.mgr);
				}
			}
		}

		mgr = settingmgr_init(ad.win);
		if (!mgr)
			app_efl_exit();

		r = app_control_get_extra_data(app_control, PARAM_SETTINGS_ITEM, &param);
		if (r == APP_CONTROL_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.app_control = 1;

		free(ad.item);
		ad.item = param;
	}

public:

	virtual int Run(int argc, char **argv) {
		memset(&ad, 0x00, sizeof(_appdata));
		ad.name = PACKAGE;

		return CBaseApp::Run(argc, argv);
	}
};

int main(int argc, char **argv)
{
	CApp app;
	app.Run(argc, argv);

	return 0;
}