summaryrefslogtreecommitdiff
path: root/lib/ph-front/ph-front-main.c
blob: 62242d069b3fd63b2ba7e285589e11feadabc269 (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
/*
* 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 "phone-ug.h"
#include "ph-front.h"
#include "ph-front-view.h"
#include <bundle.h>

// for removing build warning ////////////////////////////////////
int service_export_as_bundle(service_h service, bundle **data);
////////////////////////////////////////////////////////

void *phoneui_on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
{
	PH_FN_CALL;
	contacts_error_e err = CONTACTS_ERROR_NONE;
	Evas_Object *bg;
	Evas_Object *parent;
	Evas_Object *layout;
	ph_phoneui_data *phoneui_d;
	const char* val = NULL;
	bundle	*bd;

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

	bindtextdomain(PACKAGE, LOCALEDIR);

	service_export_as_bundle(service, &bd);

	phoneui_d = priv;
	if (bd) {
		val = bundle_get_val(bd, PH_UG_BUNDLE_TYPE);
		if (val) phoneui_d->ug_request = atoi(val);
		PH_DBG("type = %d", phoneui_d->ug_request);
		bundle_free(bd);
	}
	p_retvm_if(PH_UG_REQUEST_LAUNCH_VOICECALL != phoneui_d->ug_request, NULL, "Invalid ug request (%d)", phoneui_d->ug_request);

	phoneui_d->view_visible[PH_VIEW_DIALER] = true;
	phoneui_d->view_visible[PH_VIEW_LOG] = true;
	phoneui_d->view_visible[PH_VIEW_CONTACT] = false;
	phoneui_d->view_visible[PH_VIEW_FAVORITE] = false;

	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;

	phoneui_d = priv;
	phoneui_d->win = ug_get_window();
	elm_win_conformant_set(phoneui_d->win, EINA_TRUE);
	phoneui_d->select_tab = PH_VIEW_NONE;
	phoneui_d->ug = ug;

	layout = ph_front_create_toolbar(phoneui_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 phoneui_on_start(ui_gadget_h ug, service_h service, void *priv)
{
	PH_FN_CALL;
	ph_phoneui_data *phoneui_d = priv;

	elm_toolbar_select_mode_set(phoneui_d->tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);

	phoneui_d->timer = ecore_timer_add(3.0, phone_front_view_load_timer, phoneui_d);
	PH_FN_END;
}

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

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

void phoneui_on_destroy(ui_gadget_h ug, service_h service, void *priv)
{
	PH_FN_CALL;
	contacts_error_e err = CONTACTS_ERROR_NONE;
	p_retm_if(NULL == priv, "The parameter is invalid(priv=%p)", priv);
	p_retm_if(NULL == ug, "The parameter is invalid(ug=%p)", ug);
	ph_phoneui_data *phoneui_d = priv;
	if (!ug)
		return;

	free(phoneui_d->ug_data);

	if (phoneui_d && phoneui_d->ug == NULL) {
		 PH_DBG("view destroy already called, so clist_d free here");
		 free(phoneui_d);
	}
	else {
		phoneui_d->ug = NULL;
		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 phoneui_on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
{
}

void phoneui_on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
{
	ph_phoneui_data *phoneui_d = priv;
	switch (event) {
		case UG_EVENT_REGION_CHANGE:
			phone_front_view_region_changed(phoneui_d);
			break;
		case UG_EVENT_ROTATE_PORTRAIT:
		case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
		case UG_EVENT_ROTATE_LANDSCAPE:
		case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
			break;
		case UG_EVENT_LANG_CHANGE:
			phone_front_view_language_changed(phoneui_d);
			break;
		default:
			break;
	}
}

void phoneui_on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h data, void *priv)
{
}

API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	ph_phoneui_data *phoneui_d;

	if (!ops)
		return -1;

	phoneui_d = calloc(1, sizeof(ph_phoneui_data));
	if (!phoneui_d)
		return -1;

	ops->create = phoneui_on_create;
	ops->start = phoneui_on_start;
	ops->pause = phoneui_on_pause;
	ops->resume = phoneui_on_resume;
	ops->destroy = phoneui_on_destroy;
	ops->message = phoneui_on_message;
	ops->event = phoneui_on_event;
	ops->key_event = phoneui_on_key_event;
	ops->priv = phoneui_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;
	ops->priv = NULL;
}