summaryrefslogtreecommitdiff
path: root/lib/log/ph-log-main.c
blob: 415bcf19966f6dfae7d90b7f9b9244e9205749fc (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
/*
 * 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 "phone-log.h"
#include "ph-log-utils.h"
#include "ph-log-main-view.h"
#include "ph-log-check-view.h"
#include "ph-log-detail-view.h"

static inline void log_init_time_format(void)
{
	static int already_init = FALSE;

	if (!already_init) {
		UErrorCode status = U_ZERO_ERROR;
		uloc_setDefault(getenv("LC_TIME"), &status);
		already_init = TRUE;
	}
}

static bool log_create_ug_view(int request, ph_log_data *log_d, Evas_Object *base)
{
	PH_FN_CALL;
	int ret;
	p_retvm_if(NULL == log_d, false, "Parameter is null");

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

	ret = ph_log_create_content(log_d);
	if (ret < 0) {
		ERR("Fail to ph_log_create_content");
		return false;
	}
	log_d->navi_item = elm_naviframe_item_push(log_d->navi, T_(PH_GET_TEXT_BASE_OP, PHTEXT_SELECT_LOGS),
			NULL, NULL, log_d->box, NULL);

	if (PH_UG_REQUEST_LOG_SELECT == request)
		log_d->view_type = LOG_VIEW_TYPE_SELECT;
	else if (PH_UG_REQUEST_LOG_CHECK == request)
		log_d->view_type = LOG_VIEW_TYPE_CHECK;

	if (LOG_VIEW_TYPE_CHECK == log_d->view_type)
		ph_log_check_mode_start(log_d);
	else
		phone_log_set_navi(log_d->navi);

	return true;
}

static void *log_on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *bd, void *priv)
{
	PH_FN_CALL;
	int ret;
	Evas_Object *bg;
	Evas_Object *parent;
	Evas_Object *base;
	ph_log_data *log_d;
	int request = PH_UG_REQUEST_LOG_CHECK;

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

	bindtextdomain(PACKAGE, LOCALEDIR);

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

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

	if (bd) {
		const char* val = NULL;
		val = bundle_get_val(bd, "type");
		if (val) request = atoi(val);
		PH_DBG("log request : %d", request);
	}

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

	log_d = priv;
	log_d->win = ug_get_window();
	log_d->ug = ug;

	bg = phone_create_bg(base);
	if (NULL == bg) {
		PH_DBG("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;
	}

	log_init_time_format();
	ph_log_util_generate_date_format(log_d->formatter);

	if (!log_create_ug_view(request, log_d, base)) {
		ph_log_util_delete_date_format(log_d->formatter);
		evas_object_del(base);
		ret = contacts_svc_disconnect();
		p_warn_if(CTS_SUCCESS != ret, "contacts_svc_disconnect() Failed(%d)", ret);
		return NULL;
	}

	return base;
}

static void log_on_start(struct ui_gadget *ug, bundle *data, void *priv)
{
}

static void log_on_pause(struct ui_gadget *ug, bundle *data, void *priv)
{
	PH_FN_CALL;
	ph_log_data *log_d = priv;
	log_d->is_background = true;

}

static void log_on_resume(struct ui_gadget *ug, bundle *data, void *priv)
{
	PH_FN_CALL;
	ph_log_data *log_d = priv;

	log_d->is_background = false;
	if (log_d->update_timer) {
		ecore_timer_del(log_d->update_timer);
		log_d->update_timer = NULL;
		ph_log_data_changed_cb(log_d);
	}
}

static void log_on_destroy(struct ui_gadget *ug, bundle *data, void *priv)
{
	PH_FN_CALL;

	if (!ug)
		return;

	evas_object_del(ug_get_layout(ug));
	contacts_svc_disconnect();
	PH_FN_END;
}

static void log_on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
{
}

static void log_on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
{
	ph_log_data *log_d = priv;

	switch (event) {
	case UG_EVENT_REGION_CHANGE:
		if (log_d->navi)
			phone_log_views_update(log_d->navi);
		break;
	default:
		break;
	}
}

static void log_on_key_event(struct ui_gadget *ug, enum ug_key_event event, bundle *data, void *priv)
{
	PH_FN_CALL;
	if (!ug)
		return;

	switch (event) {
	case UG_KEY_EVENT_END:
		ug_destroy_me(ug);
		break;
	default:
		break;
	}
}

API int UG_MODULE_INIT(struct ug_module_ops *ops)
{
	ph_log_data *log_d;

	if (!ops)
		return -1;

	log_d = calloc(1, sizeof(ph_log_data));
	p_retvm_if(NULL == log_d, -1, "calloc is failed");

	ops->create = log_on_create;
	ops->start = log_on_start;
	ops->pause = log_on_pause;
	ops->resume = log_on_resume;
	ops->destroy = log_on_destroy;
	ops->message = log_on_message;
	ops->event = log_on_event;
	ops->key_event = log_on_key_event;
	ops->priv = log_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;
	PH_FN_END;
}

API Evas_Object* phone_create_log_view(void *ug, Evas_Object *win, Evas_Object *parent)
{
	PH_FN_CALL;
	int ret;
	ph_log_data * log_d = calloc(1, sizeof(ph_log_data));
	p_retvm_if(NULL == log_d, NULL, "Fail to calloc ph_log_data");
	log_d->ug = ug;
	log_d->win = win;
	log_d->navi = parent;
	log_d->navi_item = elm_naviframe_bottom_item_get(log_d->navi);
	if (log_d->ug)
		log_d->view_type = LOG_VIEW_TYPE_VOICE_CALL;
	else
		log_d->view_type = LOG_VIEW_TYPE_NORMAL;

	log_init_time_format();
	ph_log_util_generate_date_format(log_d->formatter);

	ret = ph_log_create_content(log_d);
	if (ret < 0) {
		free(log_d);
		return NULL;
	}

	return log_d->box;
}