summaryrefslogtreecommitdiff
path: root/lib/details/ct-detail-main.c
blob: 1df1621ce0872ab2ead2b0ad5c1c2ad7882106bd (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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
 * 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://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 <ui-gadget-module.h>

#include "phone.h"
#include "ct-detail.h"
#include "ct-detail-utils.h"
#include "ct-detail-view.h"
#include "ct-input-view.h"
#include "ct-input-utils.h"

static int create_ug_detail_view(Evas_Object *base, int request, ct_detail_data *cdetail_d)
{
	p_retvm_if(NULL == base, FALSE, "base is NULL");

	cdetail_d->navi = elm_naviframe_add(base);
	p_retvm_if (NULL == cdetail_d->navi, FALSE, "elm_naviframe_add() return NULL");
	elm_naviframe_prev_btn_auto_pushed_set(cdetail_d->navi, EINA_FALSE);
	evas_object_show(cdetail_d->navi);
	elm_object_part_content_set(base, "elm.swallow.content", cdetail_d->navi);

	cdetail_d->ug_detail = true;
	if (CT_UG_REQUEST_DETAIL == request) {
		Evas_Object *content;

		content = ct_detail_create_content(cdetail_d);
		if (NULL == content)
			return FALSE;

		cdetail_d->navi_item = elm_naviframe_item_push(cdetail_d->navi,
				T_(CT_GET_TEXT_BASIC, CTTEXT_DETAILS), NULL, NULL, content, NULL);
		ct_detail_set_navi(cdetail_d, DETAIL_VIEW_MODE_INFO);
	}
	else {
		CTSstruct *contact_dup = NULL;
		if (cdetail_d->contact)
			contact_dup = contacts_svc_struct_duplicate(cdetail_d->contact);
		ct_input_push_navi_content(cdetail_d, contact_dup, cdetail_d->contact_id);
	}

	return TRUE;
}

static void *detail_on_create(ui_gadget_h ug, enum ug_mode mode,
		service_h service, void *priv)
{
	int ret, request;
	Evas_Object *bg;
	Evas_Object *base;
	Evas_Object *parent;
	ct_detail_data *cdetail_d = priv;

	p_retvm_if(NULL == ug || NULL == priv, NULL,
			"The parameter is invalid(ug=%p, priv=%p)", ug, priv);

	cdetail_d->win = ug_get_window();
	parent = ug_get_parent_layout(ug);
	p_retvm_if(NULL == parent, NULL, "ug_get_parent_layout() return NULL");
	cdetail_d->ug = ug;

	bindtextdomain(PACKAGE, LOCALEDIR);

	ret = contacts_svc_connect();
	p_retvm_if(CTS_SUCCESS != ret, NULL, "contacts_svc_connect() Failed(%d)", ret);

	if (UG_MODE_FULLVIEW == mode)
		base = phone_create_base_layout(parent, true);
	else
		base = phone_create_base_layout(parent, false);

	request = ct_detail_parse_bundle(service, cdetail_d);
	if (-2 == request) {
		Evas_Object *popup;
		popup = elm_popup_add(base);
		evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		elm_object_text_set(popup, S_(PH_SYS_BODY_SELECTED_DATA_NOT_FOUND));
		elm_popup_timeout_set(popup, 1.5);
		evas_object_show(popup);
		evas_object_smart_callback_add(popup, "timeout", ctui_list_ug_hide_cb, cdetail_d->ug);
		return base;
	}
	p_retvm_if(request < 0, NULL, "ct_detail_parse_bundle() Failed(%d)", request);

	bg = phone_create_bg(base);
	if (NULL == bg) {
		ERR("phone_create_bg() return NULL");
		evas_object_del(base);
		ret = contacts_svc_disconnect();
		p_warn_if(CTS_SUCCESS != ret, "contacts_svc_disconnect() Failed(%d)", ret);
		return NULL;
	}

	if (!create_ug_detail_view(base, request, cdetail_d)) {
		evas_object_del(base);
		ret = contacts_svc_disconnect();
		p_warn_if(CTS_SUCCESS != ret, "contacts_svc_disconnect() Failed(%d)", ret);
	}
	return base;
}

static void detail_on_destroy(ui_gadget_h ug, service_h service, void *priv)
{
	int ret;
	ct_detail_data *cdetail_d = priv;
	p_retm_if(NULL == ug, "The parameter is invalid(ug=%p)", ug);

	if (cdetail_d && !cdetail_d->navi)
		free(cdetail_d);

	evas_object_del(ug_get_layout(ug));
	ret = contacts_svc_disconnect();
	p_warn_if(CTS_SUCCESS != ret, "contacts_svc_disconnect() Failed(%d)", ret);
}

static void detail_on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
{
	PH_FN_CALL;
	ct_detail_data *cdetail_d = priv;

	if (!ug)
		return;

	switch (event) {
	case UG_KEY_EVENT_END:
		if (cdetail_d->popup) {
			ct_detail_popup_hide_cb(cdetail_d, NULL, NULL);
		}
		else {
			if (elm_naviframe_top_item_get(cdetail_d->navi)
					== cdetail_d->navi_item) {
				ug_destroy_me(ug);
			}
			else
				elm_naviframe_item_pop(cdetail_d->navi);
		}
		break;
	default:
		break;
	}
}

static void detail_on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
{
	char* val = NULL;
	ct_detail_data *cdetail_d = priv;

	if (UG_MODE_FRAMEVIEW == ug_get_mode(ug)) {
		if (msg) {
			service_get_extra_data(service, "key_event", &val);
			if (val && CTUG_MSG_KEY_END == atoi(val)) {
				if (cdetail_d->popup) {
					ct_detail_popup_hide_cb(cdetail_d, NULL, NULL);
				}
				else {
					if (elm_naviframe_top_item_get(cdetail_d->navi)
							== cdetail_d->navi_item) {
						ug_destroy_me(ug);
					}
					else
						elm_naviframe_item_pop(cdetail_d->navi);
				}
			}
			free(val);
		}
	}
}

static void detail_on_pause(ui_gadget_h ug, service_h service, void *priv)
{
	ct_detail_data *cdetail_d = priv;
	cdetail_d->order_display = contacts_svc_get_order(CTS_ORDER_OF_DISPLAY);
}

static void detail_on_resume(ui_gadget_h ug, service_h service, void *priv)
{
	ct_detail_data *cdetail_d = priv;
	if (cdetail_d->order_display != contacts_svc_get_order(CTS_ORDER_OF_DISPLAY))
		ctui_detail_genlist_update(cdetail_d);
}

static void detail_on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
{
	Evas_Object *notify;
	ct_detail_data *cdetail_d = priv;

	switch (event) {
	case UG_EVENT_ROTATE_PORTRAIT:
	case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
		phone_resize_notify(cdetail_d->navi, 0);
		evas_object_data_set(cdetail_d->navi, "phone_rotate", (void *)0);
		notify = phone_get_notify(cdetail_d->navi);
		elm_layout_theme_set(elm_object_content_get(notify), "standard", "selectioninfo", "vertical/bottom_64");
		break;
	case UG_EVENT_ROTATE_LANDSCAPE:
	case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
		phone_resize_notify(cdetail_d->navi, 90);
		evas_object_data_set(cdetail_d->navi, "phone_rotate", (void *)90);
		notify = phone_get_notify(cdetail_d->navi);
		elm_layout_theme_set(elm_object_content_get(notify), "standard", "selectioninfo", "horizontal/bottom_64");
		break;
	default:
		break;
	}
}


API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	ct_detail_data *cdetail_d;

	p_retvm_if(!ops, -1, "ops is NULL");

	cdetail_d = calloc(1, sizeof(ct_detail_data));
	p_retvm_if(!cdetail_d, -1, "UG data is NULL, Not enough memory");

	ops->create = detail_on_create;
	ops->start = NULL;
	ops->pause = detail_on_pause;
	ops->resume = detail_on_resume;
	ops->destroy = detail_on_destroy;
	ops->message = detail_on_message;
	ops->event = detail_on_event;
	ops->key_event = detail_on_key_event;
	ops->priv = cdetail_d;
	ops->opt = UG_OPT_INDICATOR_ENABLE;

	return 0;
}

API void UG_MODULE_EXIT(struct ug_module_ops *ops)
{
	p_retm_if(!ops, "ops is NULL");

	ops->priv = NULL;
}

API int ctui_create_detail_view(ct_list_data *clist_d, ct_contact_list *info)
{
	PH_FN_CALL;
	PH_START_TIME_CHECK;
	ct_detail_data *cdetail_d;
	Evas_Object *content;

	cdetail_d = calloc(1, sizeof(ct_detail_data));
	p_retvm_if(!cdetail_d, -1, "cdetail_d is NULL, Not enough memory");

	ctui_ld_to_dd(clist_d, cdetail_d);
	cdetail_d->contact_id = info->id;
	cdetail_d->person_id = info->id_person;
	cdetail_d->titem = NULL;
	cdetail_d->ctrl_item = NULL;
	cdetail_d->contact = contacts_svc_struct_duplicate(info->contact);

	content = ct_detail_create_content(cdetail_d);
	if (NULL == content) {
		ERR("ct_detail_create_content() Failed");
		free(cdetail_d);
		return -1;
	}

	cdetail_d->navi_item = elm_naviframe_item_push(cdetail_d->navi,
			T_(CT_GET_TEXT_BASIC, CTTEXT_DETAILS), NULL, NULL, content, NULL);

	ct_detail_set_navi(cdetail_d, DETAIL_VIEW_MODE_INFO);

	PH_END_TIME_CHECK();
	return 0;
}

API int ctui_create_input_view(ct_detail_data *cdetail_d)
{
	CTSstruct *contact_dup = NULL;
	PH_FN_CALL;
	PH_START_TIME_CHECK;

	p_retvm_if(!cdetail_d, -1, "cdetail_d is NULL");

	if (cdetail_d->contact) {
		contact_dup = contacts_svc_struct_duplicate(cdetail_d->contact);
		p_retvm_if(NULL == contact_dup, -1, "contacts_svc_struct_duplicate() return NULL");
	}
	ct_input_push_navi_content(cdetail_d, contact_dup, cdetail_d->contact_id);

	PH_END_TIME_CHECK("ct_input_push_navi_content");
	return 0;
}

API Evas_Object* ctui_contacts_viewer(Evas_Object *win, Evas_Object *navi, int ct_id, const char *vcard_stream)
{
	int ret;
	ct_detail_data *cdetail_d;
	Evas_Object *bg;
	Evas_Object *base = NULL;
	Evas_Object *content;

	cdetail_d = calloc(1, sizeof(ct_detail_data));
	p_retvm_if(!cdetail_d, NULL, "cdetail_d is NULL, Not enough memory");

	cdetail_d->win = win;
	if (navi)
		cdetail_d->navi = navi;
	else {
		base = phone_create_base_layout(win, true);
		cdetail_d->navi = elm_naviframe_add(base);
		evas_object_show(cdetail_d->navi);

		bg = phone_create_bg(base);
		if (NULL == bg) {
			ERR("phone_create_bg() return NULL");
			evas_object_del(base);
			free(cdetail_d);
			return NULL;
		}
		elm_object_style_set(bg, "group_list");
	}

	if (ct_id) {
		cdetail_d->is_shortcut = true;
		cdetail_d->contact_id = ct_id;
		cdetail_d->person_id = ctui_get_person_id(ct_id);
		ret = contacts_svc_get_contact(ct_id, &(cdetail_d->contact));
		if (CTS_SUCCESS != ret) {
			ERR("contacts_svc_get_contact() Failed(%d)", ret);
			if (base)
				evas_object_del(base);
			free(cdetail_d);
			return NULL;
		}
	}
	else {
		cdetail_d->vcard = (char *)vcard_stream;
		ret = contacts_svc_get_contact_from_vcard(vcard_stream, &(cdetail_d->contact));
		if (CTS_SUCCESS != ret) {
			ERR("contacts_svc_get_contact_from_vcard() Failed(%d)", ret);
			if (base)
				evas_object_del(base);
			free(cdetail_d);
			return NULL;
		}
	}

	if (cdetail_d->contact_id <= 0)
		cdetail_d->base_ab = -1;

	content = ct_detail_create_content(cdetail_d);
	if (NULL == content) {
		ERR("ct_detail_create_content() Failed");
		if (base)
			evas_object_del(base);
		ret = contacts_svc_struct_free(cdetail_d->contact);
		p_warn_if(CTS_SUCCESS != ret, "contacts_svc_struct_free() Failed(%d)", ret);
		free(cdetail_d);
		return NULL;
	}

	cdetail_d->navi_item = elm_naviframe_item_push(cdetail_d->navi,
			T_(CT_GET_TEXT_BASIC, CTTEXT_DETAILS), NULL, NULL, content, NULL);

	if (ct_id)
		ct_detail_set_navi(cdetail_d, DETAIL_VIEW_MODE_INFO);
	else
		ct_detail_set_navi(cdetail_d, DETAIL_VIEW_MODE_VCARD);

	if (navi)
		return navi;
	else {
		elm_object_part_content_set(base, "elm.swallow.content", cdetail_d->navi);
		evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		elm_win_resize_object_add(win, base);
		evas_object_show(base);
		return base;
	}
}

API int ctui_create_detail_view_from_phone(Evas_Object *win, Evas_Object *navi, ui_gadget_h ug, int id)
{
	PH_FN_CALL;
	PH_START_TIME_CHECK;
	ct_detail_data *cdetail_d;
	Evas_Object *content;

	cdetail_d = calloc(1, sizeof(ct_detail_data));
	p_retvm_if(!cdetail_d, -1, "cdetail_d is NULL, Not enough memory");

	cdetail_d->win = win;
	cdetail_d->navi = navi;
	cdetail_d->ug = ug;
	cdetail_d->prev_navi_item = elm_naviframe_top_item_get(navi);
	cdetail_d->contact_id = id;
	cdetail_d->person_id = ctui_get_person_id(id);

	content = ct_detail_create_content(cdetail_d);
	if (NULL == content) {
		ERR("ct_detail_create_content() Failed");
		free(cdetail_d);
		return -1;
	}

	cdetail_d->navi_item = elm_naviframe_item_push(cdetail_d->navi,
			T_(CT_GET_TEXT_BASIC, CTTEXT_DETAILS), NULL, NULL, content, NULL);

	ct_detail_set_navi(cdetail_d, DETAIL_VIEW_MODE_INFO);

	PH_END_TIME_CHECK();
	return 0;
}