summaryrefslogtreecommitdiff
path: root/lib/ct-front/ct-front-main.c
blob: 704ffcd94aaa65f71a4136291378fcc34738dedb (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
/*
* 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 <ui-gadget-module.h>

#include "phone.h"
#include "phone-common.h"
#include "contacts-ug.h"
#include "ct-front.h"
#include "ct-front-view.h"

static int cfront_parse_bundle(ct_front_data *cfront_d, service_h service)
{
	PH_FN_CALL;
	char* val = NULL;

	cfront_d->view_visible[CT_VIEW_CONTACT] = true;
	cfront_d->view_visible[CT_VIEW_GROUP] = true;
	cfront_d->view_visible[CT_VIEW_FAVORITE] = true;

	if (service) {
		service_get_extra_data(service, PH_UG_BUNDLE_TYPE, &val);
		if (val) cfront_d->ug_request = atoi(val);
		PH_DBG("type = %d", cfront_d->ug_request);
		free(val);
	}

	switch (cfront_d->ug_request) {
	case PH_UG_REQUEST_SELECT:
	case PH_UG_REQUEST_SELECT_NUMBER:
	case PH_UG_REQUEST_SELECT_EMAIL:
		cfront_d->view_visible[CT_VIEW_LOG] = true;
		break;
	case PH_UG_REQUEST_SET_WITH_NUM:
		service_get_extra_data(service, CT_UG_BUNDLE_NUM, &cfront_d->ug_data);
		break;
	case PH_UG_REQUEST_SET_WITH_EMAIL:
		service_get_extra_data(service, CT_UG_BUNDLE_EMAIL, &cfront_d->ug_data);
		break;
	case PH_UG_REQUEST_SET_WITH_WEB:
		service_get_extra_data(service, CT_UG_BUNDLE_WEB, &cfront_d->ug_data);
		break;
	case PH_UG_REQUEST_SET_WITH_IMG:
	case PH_UG_REQUEST_SET_WITH_RINGTONE:
		service_get_extra_data(service, CT_UG_BUNDLE_PATH, &cfront_d->ug_data);
		break;
	case PH_UG_REQUEST_CHECK:
	case PH_UG_REQUEST_CHECK_FOR_NUMBER:
	case PH_UG_REQUEST_CHECK_FOR_EMAIL:
	case PH_UG_REQUEST_CHECK_FOR_NUMBER_OR_EMAIL:
		cfront_d->view_visible[CT_VIEW_LOG] = true;
		val = NULL;
		service_get_extra_data(service, CT_UG_BUNDLE_MAX, &val);
		if (val) cfront_d->cnt_max = atoi(val);
		free(val);
	default:
		break;
	}
	return 0;
}

void *ct_tabui_on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
{
	PH_FN_CALL;
	int ret;
	contacts_error_e err = CONTACTS_ERROR_NONE;
	Evas_Object *bg;
	Evas_Object *parent;
	Evas_Object *layout;
	ct_front_data *cfront_d;

	if (!ug || !priv)
		return NULL;

	bindtextdomain(PACKAGE, LOCALEDIR);

	cfront_d = priv;
	ret = cfront_parse_bundle(cfront_d, service);
	p_retvm_if(-1 == ret, NULL, "ph_front_view_parse_bundle() Failed");

	err = contacts_connect2();
	p_retvm_if(CONTACTS_ERROR_NONE != err, NULL, "contacts_connect2() Failed(%d)", err);

	parent = ug_get_parent_layout(ug);
	if (!parent)
		return NULL;

	cfront_d = priv;
	cfront_d->win = ug_get_window();
	cfront_d->select_tab = CT_VIEW_NONE;
	cfront_d->ug = ug;

	layout = ct_front_view_create_toolbar(cfront_d);

	bg = phone_create_bg(layout);
	if (NULL == bg) {
		PH_DBG("phone_create_bg() return NULL");
		err = contacts_disconnect2();
		p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_disconnect2() Failed(%d)", err);
		return NULL;
	}

	return layout;
}

void ct_tabui_on_start(ui_gadget_h ug, service_h service, void *priv)
{
	PH_FN_CALL;
	ct_front_data *cfront_d = priv;

	elm_toolbar_select_mode_set(cfront_d->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);

	cfront_d->timer = ecore_timer_add(3.0, ctui_front_view_load_timer, cfront_d);
	PH_FN_END;
}

void ct_tabui_on_pause(ui_gadget_h ug, service_h service, void *priv)
{
}

void ct_tabui_on_resume(ui_gadget_h ug, service_h service, void *priv)
{
}

void ct_tabui_on_destroy(ui_gadget_h ug, service_h service, void *priv)
{
	PH_FN_CALL;
	contacts_error_e err = CONTACTS_ERROR_NONE;
	ct_front_data *cfront_d = priv;

	if (!ug)
		return;

	free(cfront_d->ug_data);

	if(cfront_d->ug) {
		evas_object_del(ug_get_layout(ug));
	}
	err = contacts_disconnect2();
	p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_disconnect2() Failed(%d)", err);
	PH_FN_END;
}

void ct_tabui_on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
{
}

void ct_tabui_on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
{
	ct_front_data *cfront_d = priv;
	switch (event) {
		case UG_EVENT_REGION_CHANGE:
			ctui_front_view_region_changed(cfront_d);
			break;
		case UG_EVENT_ROTATE_PORTRAIT:
		case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
			break;
		case UG_EVENT_ROTATE_LANDSCAPE:
		case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
			break;
		case UG_EVENT_LANG_CHANGE:
			ctui_front_view_language_changed(cfront_d);
			break;
		default:
			break;
	}
}

void ct_tabui_on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
{
}

API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	ct_front_data *cfront_d;

	if (!ops)
		return -1;

	cfront_d = calloc(1, sizeof(ct_front_data));
	if (!cfront_d)
		return -1;

	ops->create = ct_tabui_on_create;
	ops->start = ct_tabui_on_start;
	ops->pause = ct_tabui_on_pause;
	ops->resume = ct_tabui_on_resume;
	ops->destroy = ct_tabui_on_destroy;
	ops->message = ct_tabui_on_message;
	ops->event = ct_tabui_on_event;
	ops->key_event = ct_tabui_on_key_event;
	ops->priv = cfront_d;
	ops->opt = UG_OPT_INDICATOR_ENABLE;

	return 0;
}

API void UG_MODULE_EXIT(struct ug_module_ops *ops)
{
	PH_FN_CALL;
	if (!ops)
		return;

	free(ops->priv);
	ops->priv = NULL;
}