summaryrefslogtreecommitdiff
path: root/lib/dialer/ph-dialer-main.c
blob: b0b19a86553f0ac25de0eee9efb6231b1af3295f (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
/*
* 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 <bundle.h>
#include <ui-gadget-module.h>

#include "phone.h"
#include "phone-dialer.h"

#include "ph-dialer-view.h"
#include "ph-dialer-utils.h"

static bool is_ug_exist = false;

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

static bool dialer_create_ug_view(ph_dialer_data *dial_d, Evas_Object *base)
{
	int ret;
	const char *title;
	p_retvm_if(NULL == dial_d, false, "Parameter is null");

	if (NULL == dial_d->navi) {
		dial_d->navi = elm_naviframe_add(base);
		p_retvm_if(NULL == dial_d->navi, false, "elm_naviframe_add is failed");
		elm_object_part_content_set(base, "elm.swallow.content", dial_d->navi);
		evas_object_show(dial_d->navi);
	}

	ret = ph_dialer_create_content(dial_d);
	p_retvm_if(ret < 0, false, "Fail to ph_dialer_create_content");
	if (dial_d->is_emergency)
		title = T_(PH_GET_TEXT_BASIC, PHTEXT_EMERGENCY_CALL);
	else
		title = T_(PH_GET_TEXT_BASIC, PHTEXT_KEYPAD);

	elm_naviframe_item_push(dial_d->navi, title, NULL, NULL, dial_d->layout, NULL);

	return true;
}

void* dialer_on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
{
	PH_FN_CALL;
	int ret;
	char *val = NULL;
	Evas_Object *bg;
	Evas_Object *parent;
	Evas_Object *base;
	ph_dialer_data *dial_d = priv;
	bundle	*data;

	p_retvm_if(true == is_ug_exist, NULL, "dialer_emergency ug already exist");
	is_ug_exist = true;

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

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

	bindtextdomain(PACKAGE, LOCALEDIR);

	service_export_as_bundle(service, &data);
	ret = contacts_connect2();
	if (CONTACTS_ERROR_NONE != ret)
	{
		bundle_free(data);
		p_warn_if(CONTACTS_ERROR_NONE != ret, "contacts_connect2() Failed(%d)", ret);
		return NULL;
	}

	val = (char*)bundle_get_val(data, "emergency_dialer");
	if (val && 0 == strcmp(val, "emergency"))
		dial_d->is_emergency = true;
	else
		dial_d->is_emergency = false;
	bundle_free(data);

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

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

	if (!dialer_create_ug_view(dial_d, base)) {
		evas_object_del(base);
		ret = contacts_disconnect2();
		p_warn_if(CONTACTS_ERROR_NONE != ret, "contacts_disconnect2() Failed(%d)", ret);
		base = NULL;
	}
	return base;
}

static void dialer_on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
{
	ph_dialer_data *dial_d = priv;

	switch (event) {
	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_dialer_view_language_changed(dial_d->layout);
		break;
	default:
		break;
	}
}

static void dialer_on_pause(ui_gadget_h ug, service_h service, void *priv)
{
	ph_dialer_data *dial_d = priv;
	dial_d->is_background = true;
}

static void dialer_on_resume(ui_gadget_h ug, service_h service, void *priv)
{
	ph_dialer_data *dial_d = priv;
	dial_d->is_background = false;
	if (dial_d->update_timer) {
		ecore_timer_del(dial_d->update_timer);
		dial_d->update_timer = NULL;
		ph_dialer_reload_data(dial_d);
	}
}

static void dialer_on_destroy(ui_gadget_h ug, service_h service, void *priv)
{
	PH_FN_CALL;
	if (!ug)
		return;

	evas_object_del(ug_get_layout(ug));
	contacts_disconnect2();
}

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

API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	ph_dialer_data *dial_d;
	p_retvm_if(NULL == ops, -1, "ops is NULL");

	dial_d = calloc(1, sizeof(ph_dialer_data));
	p_retvm_if(NULL == dial_d, -1, "dial_d is NULL, Not enough memory");

	ops->create = dialer_on_create;
	ops->start = NULL;
	ops->pause = dialer_on_pause;
	ops->resume = dialer_on_resume;
	ops->destroy = dialer_on_destroy;
	ops->message = dialer_on_message;
	ops->event = dialer_on_event;
	ops->priv = dial_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 Evas_Object* phone_create_dialer_view(ph_view_info *view_info)
{
	ph_dialer_data *dial_d;
	p_retvm_if(NULL == view_info, NULL, "The parameter(view_info) is NULL");

	dial_d = calloc(1, sizeof(ph_dialer_data));
	p_retvm_if(NULL == dial_d, NULL, "dial_d is NULL, Not enough memory");
	dial_d->ug = view_info->ug;
	dial_d->win = view_info->win;
	dial_d->navi = view_info->navi;
	dial_d->is_emergency = false;
	dial_d->is_background = true;

	if (!ph_dialer_create_content(dial_d)) {
		free(dial_d);
		return NULL;
	}
	return dial_d->layout;
}