summaryrefslogtreecommitdiff
path: root/src/main.c
blob: e50a5021d4b9686d94eb8dacccccaf58616d7d8c (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
/*
 * Copyright (c) 2015 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 <app_debug.h>
#include <viewmgr.h>
#include <key_define.h>
#include <app_define.h>
#include <Ecore_Wayland.h>
#include <ui-gadget.h>
#include <bundle.h>

#include "defs.h"
#include "view.h"
#include "utils.h"

#define VALUE_INFOSQUARE "infosquare"

#define VIEW_COUNT 7

SET_TAG(PACKAGE);

struct _appdata {
	const char *name;

	Evas_Object *win;
	Eina_Bool activated;
	Ecore_Event_Handler *key_down;
};

static Evas_Object *_add_win(const char *name)
{
	Evas_Object *win;

	win = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (!win)
		return NULL;

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

	return win;
}

static void _hide(struct _appdata *ad)
{
	int i;
	const char *view[VIEW_COUNT] = { VIEW_PHOTO, VIEW_PIN,
			VIEW_ACTION_MENU, VIEW_USER_EDIT,
			VIEW_USER, VIEW_RECENT, VIEW_HOME };

	for (i = 0; i < VIEW_COUNT; i++)
		viewmgr_hide_view(view[i]);

	elm_win_iconified_set(ad->win, EINA_TRUE);
	ad->activated = EINA_FALSE;
}

static void _show(struct _appdata *ad)
{
	elm_win_iconified_set(ad->win, EINA_FALSE);
	ad->activated = EINA_TRUE;

	viewmgr_push_view(VIEW_HOME);
}

static Eina_Bool _key_down(void *data, int type, void *ei)
{
	struct _appdata *ad;
	Evas_Event_Key_Down *ev;
	bundle *b;

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

	ev = ei;
	ad = data;

	if (!strcmp(ev->keyname, KEY_POWER)) {
		b = utils_add_bundle(PARAM_LAUNCH_TYPE, VALUE_INFOSQUARE, NULL);
		if (b) {
			utils_launch_app(APP_ID_INFOSQUARE, b);
			bundle_free(b);
		}
	} else if (!strcmp(ev->keyname, KEY_TV)) {
		utils_launch_app(APP_ID_LIVETV, NULL);
	} else if (!strcmp(ev->keyname, KEY_HOME) ||
			!strcmp(ev->keyname, KEY_HOMEPAGE)) {
		if (!ad->activated)
			_show(ad);
	} else if (!strcmp(ev->keyname, KEY_BACK) ||
			!strcmp(ev->keyname, KEY_ESC)) {
		if (ad->activated && viewmgr_active_view_count() == 1 &&
				viewmgr_get_view_state(VIEW_HOME) ==
						VIEW_STATE_VISIBLE)
			_hide(ad);
	}

	return ECORE_CALLBACK_CANCEL;
}

/* FIXME: Keygrab Hot Fix */
static Eina_Bool _key_timer(void *data)
{
	if (!data) {
		_ERR("Invalid argument");
		return ECORE_CALLBACK_CANCEL;
	}

	elm_win_keygrab_set(data, KEY_TV, 0, 0, 0, ELM_WIN_KEYGRAB_EXCLUSIVE);
	elm_win_keygrab_set(data, KEY_POWER, 0, 0, 0,
			ELM_WIN_KEYGRAB_EXCLUSIVE);
	elm_win_keygrab_set(data, KEY_HOME, 0, 0, 0, ELM_WIN_KEYGRAB_EXCLUSIVE);
	elm_win_keygrab_set(data, KEY_HOMEPAGE, 0, 0, 0,
			ELM_WIN_KEYGRAB_EXCLUSIVE);

	return ECORE_CALLBACK_CANCEL;
}

static bool _create(void *user_data)
{
	struct _appdata *ad;
	int r;

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

	ad = user_data;

	elm_theme_overlay_add(NULL, THEMEFILE);
	elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);

	ad->win = _add_win(ad->name);
	if (!ad->win) {
		_ERR("failed to create window");
		return false;
	}
	ecore_timer_add(3, _key_timer, ad->win);

	r = ug_init_efl(ad->win, UG_OPT_INDICATOR_ENABLE);
	if (r < 0)
		_ERR("failed to init ug");

	if (!viewmgr_create(ad->win)) {
		_ERR("failed to create viewmgr");
		evas_object_del(ad->win);
		ad->win = NULL;
		return false;
	}

	viewmgr_add_view(view_home_get_vclass(), NULL);
	viewmgr_add_view(view_recent_get_vclass(), NULL);
	viewmgr_add_view(view_user_get_vclass(), NULL);

	ad->key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down,
			ad);

	return true;
}

static void _terminate(void *user_data)
{
	struct _appdata *ad;

	if (!user_data)
		return;

	ad = user_data;

	if (ad->win) {
		if (ad->key_down)
			ecore_event_handler_del(ad->key_down);

		elm_win_keygrab_unset(ad->win, KEY_POWER, 0, 0);
		elm_win_keygrab_unset(ad->win, KEY_TV, 0, 0);
		elm_win_keygrab_unset(ad->win, KEY_HOME, 0, 0);
		elm_win_keygrab_unset(ad->win, KEY_HOMEPAGE, 0, 0);

		viewmgr_remove_view(VIEW_USER);
		viewmgr_remove_view(VIEW_RECENT);
		viewmgr_remove_view(VIEW_HOME);

		viewmgr_destroy();
		evas_object_del(ad->win);
	}
}

static void _pause(void *user_data)
{
	if (!user_data) {
		_ERR("Invalid argument");
		return;
	}

	_hide(user_data);
}

static void _resume(void *user_data)
{

}

static void _control(app_control_h app_control, void *user_data)
{
	struct _appdata *ad;

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

	ad = user_data;

	if (ad->win)
		_show(ad);
}

int main(int argc, char **argv)
{
	struct _appdata ad;

	ui_app_lifecycle_callback_s event_callback = {0,};

	event_callback.create = _create;
	event_callback.terminate = _terminate;
	event_callback.pause = _pause;
	event_callback.resume = _resume;
	event_callback.app_control = _control;

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

	return ui_app_main(argc, argv, &event_callback, &ad);
}