summaryrefslogtreecommitdiff
path: root/contacts-appservice/contacts-appservice.c
blob: a612ac75640cbe3dd9f1f75f4130b73a945b6356 (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
/*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.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://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 <stdio.h>
#include <aul.h>
#include <Ecore_X.h>
#include <ui-gadget.h>
#include <app.h>
#include <utilX.h>

#include "phone.h"

#if !defined(APPSERVICE_PACKAGE)
#  define APPSERVICE_PACKAGE "contacts-appservice"
#endif

#define CONTACTS_LIST_UG "contacts-list-efl"
#define CONTACTS_DETAILS_UG "contacts-details-efl"

#define CT_LIST_UG_SELECT_CONTACT_ADD_TO_HOME "15"
#define CT_LIST_UG_SELECT_GROUP_ADD_TO_HOME "16"
#define CT_DETAILS_UG_REQUEST_ADD_WITH_NUM "22"
#define CT_DETAILS_UG_REQUEST_DETAIL "0"

#define CT_APPSERVICE_REQUEST_DETAIL 0
#define CT_APPSERVICE_ADD_CONTACT_LIVEBOX 1
#define CT_APPSERVICE_ADD_GROUP_LIVEBOX 2
#define CT_APPSERVICE_ADD_WITH_NUM 22

typedef struct {
	Evas_Object *win;
	Evas_Object *layout;
	ui_gadget_h ug;
	Ecore_Event_Handler *event_handler;
} ct_app_service_data;

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

	eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (eo) {
		elm_win_title_set(eo, name);
		elm_win_conformant_set(eo, EINA_TRUE);
#ifdef _PHONE_CONTACTS_DESKTOP_MODE_
#else
		elm_win_borderless_set(eo, EINA_TRUE);
#endif
		ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
		evas_object_resize(eo, w, h);
		elm_win_indicator_mode_set(eo, ELM_WIN_INDICATOR_SHOW);
	}

	return eo;
}

static Eina_Bool __appservice_hard_key_down(void *data, int type, void *event_info)
{
	Ecore_Event_Key *ev = event_info;
	if (0 == strcmp(ev->keyname, KEY_HOME))
		elm_exit();
	return ECORE_CALLBACK_DONE;
}

static void __appservice_grab_key(ct_app_service_data *cappservice_d)
{
	Ecore_X_Window xwin;
	Ecore_X_Display *disp = NULL;

	disp = ecore_x_display_get();
	xwin = elm_win_xwindow_get(cappservice_d->win);
	utilx_grab_key(disp, xwin, KEY_HOME, TOP_POSITION_GRAB);
	cappservice_d->event_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __appservice_hard_key_down, cappservice_d);
}

static void __appservice_ungrab_key(ct_app_service_data *cappservice_d)
{
	Ecore_X_Window xwin;
	Ecore_X_Display *disp = NULL;

	disp = ecore_x_display_get();
	xwin = elm_win_xwindow_get(cappservice_d->win);
	utilx_ungrab_key(disp, xwin, KEY_HOME);
	if (cappservice_d->event_handler) {
		ecore_event_handler_del(cappservice_d->event_handler);
		cappservice_d->event_handler = NULL;
	}
}

static bool appservice_create(void *data)
{
	PH_FN_CALL;
	ct_app_service_data *cappservice_d = data;
	Evas_Object *win;

	/* create window */
	win = appservice_create_win(APPSERVICE_PACKAGE);
	p_retvm_if(NULL == win, false, "ctapp_create_win() Failed");
	cappservice_d->win = win;

	bindtextdomain(PACKAGE, LOCALEDIR);
	evas_object_show(win);

 	UG_INIT_EFL(cappservice_d->win, UG_OPT_INDICATOR_ENABLE);
	__appservice_grab_key(cappservice_d);

	return true;
}

static void appservice_terminate(void *data)
{
	PH_FN_CALL;
	ct_app_service_data *cappservice_d = data;

	__appservice_ungrab_key(cappservice_d);

	if (cappservice_d->ug)
		ug_destroy(cappservice_d->ug);

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

	return;
}

static void appservice_pause(void *data)
{
	PH_FN_CALL;
	return;
}

static void appservice_resume(void *data)
{
	PH_FN_CALL;
	return;
}

static void appservice_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
{
	ct_app_service_data *cappservice_d = priv;
	Evas_Object *base;

	if (!ug)
		return;

	base = ug_get_layout(ug);
	if (!base) {
		ERR("ug_get_layout() return NULL");
		ug_destroy(ug);
		return;
	}
	evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	ug_disable_effect(ug);
	elm_object_content_set(cappservice_d->layout, base);
	evas_object_show(base);
}

static void appservice_ug_destroy_cb(ui_gadget_h ug, void *priv)
{
	ct_app_service_data *cappservice_d = priv;
	p_retm_if(NULL == ug, "ug is NULL");

	ug_destroy(ug);
	cappservice_d->ug = NULL;

	elm_exit();
}

static void appservice_lauch_list_ug(ct_app_service_data *cappservice_d, int type)
{
	service_h service;
	struct ug_cbs cbs = {0};

	p_retm_if(NULL == cappservice_d, "parameter(cappservice_d) is NULL");

	service_create(&service);

	if (2 == type)
		service_add_extra_data(service, "type", CT_LIST_UG_SELECT_GROUP_ADD_TO_HOME);
	else
		service_add_extra_data(service, "type", CT_LIST_UG_SELECT_CONTACT_ADD_TO_HOME);

	cbs.layout_cb = appservice_ug_layout_cb;
	cbs.result_cb = NULL;
	cbs.destroy_cb = appservice_ug_destroy_cb;
	cbs.priv = cappservice_d;

	cappservice_d->ug = ug_create(NULL, CONTACTS_LIST_UG, UG_MODE_FULLVIEW, service, &cbs);
	service_destroy(service);
}

static void appservice_launch_details_ug(ct_app_service_data *cappservice_d, const char *type, char *val)
{
	service_h service;
	struct ug_cbs cbs = {0};

	p_retm_if(NULL == cappservice_d, "parameter(cappservice_d) is NULL");

	service_create(&service);
	if (type == CT_APPSERVICE_REQUEST_DETAIL) {
		service_add_extra_data(service, "type", CT_DETAILS_UG_REQUEST_DETAIL);
		PH_DBG("val=%s",val);
		if (val && *val)
			service_add_extra_data(service, "person_id", val);
	}
	else if (type == CT_APPSERVICE_ADD_WITH_NUM) {
		service_add_extra_data(service, "type", CT_DETAILS_UG_REQUEST_ADD_WITH_NUM);
		if (val && *val)
			service_add_extra_data(service, "ct_num", val);
	}

	cbs.layout_cb = appservice_ug_layout_cb;
	cbs.result_cb = NULL;
	cbs.destroy_cb = appservice_ug_destroy_cb;
	cbs.priv = cappservice_d;

	cappservice_d->ug = ug_create(NULL, CONTACTS_DETAILS_UG, UG_MODE_FULLVIEW, service, &cbs);
	service_destroy(service);

}

static Evas_Object* __appservice_create_base_layout(Evas_Object *parent, bool is_fullview)
{
	Evas_Object *base;

	base = elm_layout_add(parent);
	p_retvm_if(NULL == base, NULL, "elm_layout_add() Failed");
	if (is_fullview)
		elm_layout_theme_set(base, "layout", "application", "default");
	else
		elm_layout_theme_set(base, "layout", "application", "noindicator");
	evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	elm_object_content_set(parent, base);

	return base;
}

static void __appservice_create_bg(Evas_Object *win)
{
	Evas_Object *bg;

	bg = elm_bg_add(win);
	p_retm_if(NULL == bg, "elm_bg_add() return NULL");
	evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_content_set(win, "elm.swallow.bg", bg);
	elm_win_resize_object_add(win, bg);
	evas_object_show(bg);
}

static Evas_Object* __appservice_create_conformant(Evas_Object *win)
{
	Evas_Object *conform;

	conform = elm_conformant_add(win);
	p_retvm_if(NULL == conform, NULL, "elm_conformant_add() Failed");
	evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_win_resize_object_add(win, conform);
	evas_object_show(conform);

	return conform;
}

static void __appservice_create_content(ct_app_service_data *cappservice_data)
{
	Evas_Object *bg = NULL;
	Evas_Object *conform = NULL;

	__appservice_create_bg(cappservice_data->win);
	conform = __appservice_create_conformant(cappservice_data->win);
	cappservice_data->layout = __appservice_create_base_layout(conform, true);
}


static void appservice_service(service_h service, void *data)
{
	PH_FN_CALL;
	char *val = NULL;
	int ret;
	int type;
	ct_app_service_data *cappservice_d = data;

	__appservice_create_content(cappservice_d);

	ret = service_get_extra_data(service, "type", &val);
	if (SERVICE_ERROR_NONE != ret) {
		ERR("service_get_operation is failed(%d)", ret);
		elm_exit();
		return;
	}

	if (val && *val) {
		char *extra_data = NULL;
		type = atoi(val);
		free(val);

		if (type == CT_APPSERVICE_ADD_CONTACT_LIVEBOX ||  type == CT_APPSERVICE_ADD_GROUP_LIVEBOX)
			appservice_lauch_list_ug(cappservice_d, type);
		else if (type == CT_APPSERVICE_REQUEST_DETAIL) {
			ret = service_get_extra_data(service, "person_id", &extra_data);
			appservice_launch_details_ug(cappservice_d,CT_APPSERVICE_REQUEST_DETAIL, extra_data);
			free(extra_data);
		}
		else if (type == CT_APPSERVICE_ADD_WITH_NUM) {
			ret = service_get_extra_data(service, "ct_num", &extra_data);
			appservice_launch_details_ug(cappservice_d, CT_APPSERVICE_ADD_WITH_NUM, extra_data);
			free(extra_data);
		}
		else {
			ERR("Invalid type(%d)", type);
			elm_exit();
			return;
		}
	}
	elm_win_activate(cappservice_d->win);
	return;
}

API int main(int argc, char *argv[])
{
	PH_FN_CALL;

	ct_app_service_data ad = {0};
	app_event_callback_s event_callback = {0,};
	event_callback.create = appservice_create;
	event_callback.terminate = appservice_terminate;
	event_callback.pause = appservice_pause;
	event_callback.resume = appservice_resume;
	event_callback.service = appservice_service;
	event_callback.low_memory = NULL;
	event_callback.low_battery = NULL;
	event_callback.device_orientation = NULL;
	event_callback.language_changed = NULL;
	event_callback.region_format_changed = NULL;

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