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
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <calendar.h>
#include <calendar_private.h>
#include <calendar-svc-provider.h>
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_CALENDAR"
#define LOG_MODE (1)
GList* _calendar_glist_next_until_not_deleted(GList* list)
{
if(list == NULL)
return NULL;
GList* glist = list;
cal_value* value = glist->data;
if(value == NULL)
return NULL;
while( (calendar_svc_value_get_int(value, CAL_VALUE_INT_DETAIL_DELETE) == true) &&
(glist != NULL) ) {
glist = g_list_next(glist);
if(glist != NULL) {
value = glist->data;
// codes below is for SVACE passed
if(value == NULL) {
glist = NULL;
break;
}
}
}
return glist;
}
int _calendar_event_foreach(calendar_foreach_query_event_cb callback, int account_db_id, int calendar_db_id, void* user_data)
{
int ret_val = CALENDAR_ERROR_NONE;
cal_iter* iter = NULL;
bool callback_return = true;
//fetch from DB
ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_SCHEDULE, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
}
if (iter == NULL) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
} else {
while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
calendar_event_s cal_event_from_db = {0,};
if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
if(cal_event_from_db.event_legacy == NULL) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
//execute callback
callback_return = callback((calendar_event_h)&cal_event_from_db, user_data);
calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
if(callback_return == false) {
break;
}
}
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE;
}
return CALENDAR_ERROR_NONE;
}
int _calendar_todo_foreach(calendar_foreach_query_todo_cb callback, int account_db_id, int calendar_db_id, void* user_data)
{
int ret_val = CALENDAR_ERROR_NONE;
cal_iter* iter = NULL;
bool callback_return = true;
//fetch from DB
ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_TODO, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
}
if (iter == NULL) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
} else {
while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
calendar_event_s cal_event_from_db = {0,};
if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
if(cal_event_from_db.event_legacy == NULL) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
//execute callback
callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data);
calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
if(callback_return == false) {
break;
}
}
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE;
}
return CALENDAR_ERROR_NONE;
}
int _calendar_event_query(calendar_foreach_query_event_cb callback, int calendar_db_id, char* option, const char* string_to_find, void* user_data)
{
int ret_val = 0;
cal_iter* iter = NULL;
bool callback_return = true;
int account_id = _calendar_get_account_db_id(calendar_db_id);
CONTACTS_INVALID_ARG_CHECK(account_id == -2);
//fetch from DB
ret_val = calendar_svc_find_event_list(account_id, option, string_to_find, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
}
if (iter == NULL) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
return CALENDAR_ERROR_DB_FAILED;
} else {
while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
calendar_event_s cal_event_from_db = {0,};
if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
if(cal_event_from_db.event_legacy == NULL) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
//execute callback
callback_return = callback((calendar_event_h)&cal_event_from_db, user_data);
calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
if(callback_return == false) {
break;
}
}
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE;
}
return CALENDAR_ERROR_NONE;
}
int _calendar_get_account_db_id(int calendar_db_id)
{
int ret = -2;
if(calendar_svc_connect() != CAL_SUCCESS) {
return -2;
}
cal_struct* calendar = NULL;
if(calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_db_id, NULL, &calendar) != CAL_SUCCESS) {
calendar_svc_close();
calendar_svc_struct_free(&calendar);
return -2;
}
if((ret = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID)) < -1) {
ret = -2; // get account ID fail;
}
calendar_svc_struct_free(&calendar);
calendar_svc_close();
return ret;
}
void _calendar_parse_color(char* color_string, unsigned char* red, unsigned char* green, unsigned char* blue)
{
*red = 0;
*green = 0;
*blue = 0;
if(color_string == NULL) {
return;
}
char* token = NULL;
char* temp = NULL;
// 0.0.0.0
if(strlen(color_string) < 7) {
return;
}
token = strtok_r(color_string, ".", &temp);
if(token) {
*red = atoi(token);
}
token = strtok_r(NULL, ".", &temp);
if(token) {
*green = atoi(token);
}
token = strtok_r(NULL, ".", &temp);
if(token) {
*blue = atoi(token);
}
}
|