3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <unicode/ucal.h>
19 #include <unicode/ustring.h>
24 static GHashTable *__calendar_record_uri_hash_table = NULL;
26 static _calendar_book_color __calendar_default_color[] = {
35 void _calendar_init_hash()
39 if (__calendar_record_uri_hash_table)
42 __calendar_record_uri_hash_table = g_hash_table_new(g_str_hash, g_str_equal);
43 c_ret_if(!__calendar_record_uri_hash_table);
45 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_book._uri, (gpointer)_CALENDAR_RECORD_TYPE_CALENDARBOOK);
46 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_event._uri, (gpointer)_CALENDAR_RECORD_TYPE_EVENT);
47 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_todo._uri, (gpointer)_CALENDAR_RECORD_TYPE_TODO);
48 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_timezone._uri, (gpointer)_CALENDAR_RECORD_TYPE_TIMEZONE);
49 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_attendee._uri, (gpointer)_CALENDAR_RECORD_TYPE_ATTENDEE);
50 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_alarm._uri, (gpointer)_CALENDAR_RECORD_TYPE_ALARM);
51 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_updated_info._uri, (gpointer)_CALENDAR_RECORD_TYPE_UPDATED_INFO);
52 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_event_calendar_book._uri, (gpointer)_CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR);
53 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_todo_calendar_book._uri, (gpointer)_CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR);
54 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_event_calendar_book_attendee._uri, (gpointer)_CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE);
55 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_instance_normal_calendar_book._uri, (gpointer)_CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR);
56 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_instance_allday_calendar_book._uri, (gpointer)_CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR);
57 g_hash_table_insert(__calendar_record_uri_hash_table, (gpointer)_calendar_extended_property._uri, (gpointer)_CALENDAR_RECORD_TYPE_EXTENDED_PROPERTY);
62 _calendar_record_type _calendar_get_record_type(calendar_record_h record)
64 c_retv_if(!record, _CALENDAR_RECORD_TYPE_MAX);
66 char *view_uri = NULL;
68 calendar_error_e error = CALENDAR_ERROR_NONE;
70 error = calendar_record_get_uri_p(record, &view_uri);
71 c_retvm_if(error != CALENDAR_ERROR_NONE, _CALENDAR_RECORD_TYPE_MAX, "calendar_record_get_uri_p() is failed(%x)", error);
72 c_retv_if(!CAL_STRLEN(view_uri), _CALENDAR_RECORD_TYPE_MAX);
74 return (_calendar_record_type)g_hash_table_lookup(__calendar_record_uri_hash_table, view_uri);
77 Eina_List * _calendar_get_normal_instance_list(struct tm *start, struct tm *end)
79 c_retv_if(!start, NULL);
80 c_retv_if(!end, NULL);
82 Eina_List *normal_instance_list = NULL;
84 calendar_query_h query = NULL;
86 calendar_error_e error = CALENDAR_ERROR_NONE;
88 error = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &query);
89 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
91 calendar_time_s caltime_start = {0};
92 calendar_time_s caltime_end = {0};
94 long long int lli_start = 0;
95 long long int lli_end = 0;
97 cal_util_convert_tm_to_lli(NULL, start, &lli_start);
98 cal_util_convert_tm_to_lli(NULL, end, &lli_end);
100 caltime_start.type = CALENDAR_TIME_UTIME;
101 caltime_start.time.utime = lli_start;
103 caltime_end.type = CALENDAR_TIME_UTIME;
104 caltime_end.time.utime = lli_end;
106 calendar_filter_h filter = NULL;
108 error = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &filter);
109 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
111 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
112 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
114 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
115 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
117 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
118 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
120 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
121 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
123 error = calendar_filter_add_int(filter, _calendar_instance_normal_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
124 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
126 error = calendar_query_set_filter(query, filter);
127 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
129 calendar_list_h list = NULL;
131 error = calendar_db_get_records_with_query(query, 0, 0, &list);
132 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
136 error = calendar_list_get_count(list, &count);
137 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
139 error = calendar_list_first(list);
140 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
144 for (i = 0; i < count; i++) {
146 calendar_record_h record = NULL;
148 error = calendar_list_get_current_record_p(list, &record);
149 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
151 calendar_record_h new_record = NULL;
153 error = calendar_record_clone(record, &new_record);
154 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
156 normal_instance_list = eina_list_append(normal_instance_list, new_record);
157 c_warn_if(!normal_instance_list, "eina_list_append() is failed.");
159 calendar_list_next(list);
162 error = calendar_list_destroy(list, false);
163 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
165 error = calendar_filter_destroy(filter);
166 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
168 error = calendar_query_destroy(query);
169 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
171 return normal_instance_list;
174 Eina_List * _calendar_get_allday_instance_list(struct tm *start, struct tm *end)
176 c_retv_if(!start, NULL);
177 c_retv_if(!end, NULL);
179 Eina_List *allday_instance_list = NULL;
181 calendar_query_h query = NULL;
183 calendar_error_e error = CALENDAR_ERROR_NONE;
185 error = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &query);
186 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
188 calendar_time_s caltime_start = {0};
189 calendar_time_s caltime_end = {0};
191 caltime_start.type = CALENDAR_TIME_LOCALTIME;
192 caltime_start.time.date.year = start->tm_year + 1900;
193 caltime_start.time.date.month = start->tm_mon + 1;
194 caltime_start.time.date.mday = start->tm_mday;
196 caltime_end.type = CALENDAR_TIME_LOCALTIME;
197 caltime_end.time.date.year = end->tm_year + 1900;
198 caltime_end.time.date.month = end->tm_mon + 1;
199 caltime_end.time.date.mday = end->tm_mday;
201 calendar_filter_h filter = NULL;
203 error = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &filter);
204 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
206 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, caltime_start);
207 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
209 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
210 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
212 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
213 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
215 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
216 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
218 error = calendar_filter_add_int(filter, _calendar_instance_allday_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
219 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
221 error = calendar_query_set_filter(query, filter);
222 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
224 calendar_list_h list = NULL;
226 error = calendar_db_get_records_with_query(query, 0, 0, &list);
227 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
231 error = calendar_list_get_count(list,&count);
232 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
234 error = calendar_list_first(list);
235 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
239 for (i = 0; i < count; i++) {
241 calendar_record_h record = NULL;
243 error = calendar_list_get_current_record_p(list, &record);
244 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
246 calendar_record_h new_record = NULL;
248 error = calendar_record_clone(record, &new_record);
249 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
251 allday_instance_list = eina_list_append(allday_instance_list, new_record);
252 c_warn_if(!allday_instance_list, "eina_list_append() is failed.");
254 calendar_list_next(list);
257 error = calendar_list_destroy(list, false);
258 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
260 error = calendar_filter_destroy(filter);
261 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
263 error = calendar_query_destroy(query);
264 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
266 return allday_instance_list;
269 static int __calendar_compare_list_item(const void *data1, const void *data2)
271 c_retv_if(!data1, 1);
272 c_retv_if(!data2, -1);
274 calendar_record_h normal_instance = (calendar_record_h)data1;
275 calendar_record_h allday_instance = (calendar_record_h)data2;
277 calendar_error_e error = CALENDAR_ERROR_NONE;
279 calendar_time_s normal_instance_start_time = {0};
281 error = calendar_record_get_caltime(normal_instance, _calendar_instance_normal_calendar_book.start_time, &normal_instance_start_time);
282 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
284 long long int lli_normal = normal_instance_start_time.time.utime;
286 calendar_time_s allday_instance_start_time = {0};
288 error = calendar_record_get_caltime(allday_instance, _calendar_instance_allday_calendar_book.start_time, &allday_instance_start_time);
289 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
291 struct tm tm_allday = {0};
292 tm_allday.tm_year = allday_instance_start_time.time.date.year - 1900;
293 tm_allday.tm_mon = allday_instance_start_time.time.date.month - 1;
294 tm_allday.tm_mday = allday_instance_start_time.time.date.mday;
296 long long int lli_allday;
297 cal_util_convert_tm_to_lli(NULL, &tm_allday, &lli_allday);
299 return (lli_allday < lli_normal) ? 1 : -1;
302 static int __calendar_compare_event_record_list_item(const void *data1, const void *data2)
304 c_retv_if(!data1, 1);
305 c_retv_if(!data2, -1);
307 calendar_record_h record1 = data1;
308 calendar_record_h record2 = data2;
310 calendar_time_s record1_start_time = {0};
311 calendar_time_s record2_start_time = {0};
313 calendar_error_e error = CALENDAR_ERROR_NONE;
314 error = calendar_record_get_caltime(record1, _calendar_instance_normal_calendar_book.start_time, &record1_start_time);
315 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
317 error = calendar_record_get_caltime(record2, _calendar_instance_normal_calendar_book.start_time, &record2_start_time);
318 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
320 long long int lli_normal1 = record1_start_time.time.utime;
321 long long int lli_normal2 = record2_start_time.time.utime;
323 return (lli_normal1 > lli_normal2) ? 1 : -1;
327 Eina_List * _calendar_get_all_instance_list(struct tm *start, struct tm *end)
329 c_retv_if(start < 0, NULL);
330 c_retv_if(end < 0, NULL);
332 Eina_List *allday_instance_list = _calendar_get_allday_instance_list(start, end);
334 Eina_List *normal_instance_list = _calendar_get_normal_instance_list(start, end);
335 normal_instance_list = eina_list_sort(normal_instance_list, 0, __calendar_compare_event_record_list_item);
337 allday_instance_list = eina_list_merge(allday_instance_list, normal_instance_list);
339 return allday_instance_list;
342 Eina_List * _calendar_get_all_record_list(void)
344 calendar_query_h query =
345 cal_query_create_all_event_list_query();
346 c_retv_if(!query, NULL);
348 calendar_list_h list = NULL;
349 calendar_error_e error = CALENDAR_ERROR_NONE;
351 error = calendar_db_get_records_with_query(query, 0, 0, &list);
352 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
356 error = calendar_list_get_count(list, &count);
357 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
359 Eina_List *event_list = NULL;
361 error = calendar_list_first(list);
362 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
365 for (i = 0; i < count; i++) {
367 calendar_record_h record = NULL;
369 error = calendar_list_get_current_record_p(list, &record);
370 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
372 calendar_record_h new_record = NULL;
374 error = calendar_record_clone(record, &new_record);
375 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
377 event_list = eina_list_append(event_list, new_record);
378 c_warn_if(!event_list, "eina_list_append() is failed.");
380 calendar_list_next(list);
383 error = calendar_list_destroy(list, false);
384 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
386 error = calendar_query_destroy(query);
387 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
392 Eina_Bool _calendar_is_task_record(calendar_record_h record)
394 c_retv_if(!record, EINA_FALSE);
396 _calendar_record_type record_type = _calendar_get_record_type(record);
398 if (record_type == _CALENDAR_RECORD_TYPE_TODO)
400 else if (record_type == _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR)
406 Eina_Bool _calendar_is_allday_record(calendar_record_h record)
408 c_retv_if(!record, EINA_FALSE);
410 calendar_error_e error = CALENDAR_ERROR_NONE;
412 calendar_time_s start_time = {0};
414 _calendar_record_type record_type = _calendar_get_record_type(record);
416 switch (record_type) {
417 case _CALENDAR_RECORD_TYPE_EVENT:
418 error = calendar_record_get_caltime(record, _calendar_event.start_time, &start_time);
420 case _CALENDAR_RECORD_TYPE_TODO:
421 error = calendar_record_get_caltime(record, _calendar_todo.start_time, &start_time);
423 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
424 error = calendar_record_get_caltime(record, _calendar_event_calendar_book.start_time, &start_time);
426 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
427 error = calendar_record_get_caltime(record, _calendar_todo_calendar_book.start_time, &start_time);
429 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
430 error = calendar_record_get_caltime(record, _calendar_event_calendar_book_attendee.start_time, &start_time);
432 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
433 error = calendar_record_get_caltime(record, _calendar_instance_normal_calendar_book.start_time, &start_time);
435 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
436 error = calendar_record_get_caltime(record, _calendar_instance_allday_calendar_book.start_time, &start_time);
439 ERR("Invaild type : %d", record_type);
443 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
445 if (start_time.type == CALENDAR_TIME_LOCALTIME)
451 int _calendar_get_account_id(calendar_record_h record)
453 c_retv_if(!record, -1);
455 calendar_error_e error = CALENDAR_ERROR_NONE;
457 int calendar_book_id = 0;
460 _calendar_record_type record_type = _calendar_get_record_type(record);
462 switch (record_type) {
463 case _CALENDAR_RECORD_TYPE_EVENT:
464 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &calendar_book_id);
466 case _CALENDAR_RECORD_TYPE_TODO:
467 error = calendar_record_get_int(record, _calendar_todo.calendar_book_id, &calendar_book_id);
469 case _CALENDAR_RECORD_TYPE_CALENDARBOOK:
470 error = calendar_record_get_int(record, _calendar_book.account_id, &account_id);
471 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
475 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
476 error = calendar_record_get_int(record, _calendar_event_calendar_book.calendar_book_id, &calendar_book_id);
478 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
479 error = calendar_record_get_int(record, _calendar_todo_calendar_book.calendar_book_id, &calendar_book_id);
481 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
482 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.calendar_book_id, &calendar_book_id);
484 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
485 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.calendar_book_id, &calendar_book_id);
487 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
488 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.calendar_book_id, &calendar_book_id);
491 ERR("Invaild type : %d", record_type);
495 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
497 calendar_record_h calendar_book = NULL;
499 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
500 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
504 error = calendar_record_get_int(calendar_book, _calendar_book.account_id, &account_id);
505 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
508 error = calendar_record_destroy(calendar_book, true);
509 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
515 char * _calendar_get_calendar_name(calendar_record_h record)
517 c_retv_if(!record, NULL);
519 calendar_error_e error = CALENDAR_ERROR_NONE;
521 int calendar_book_id = 0;
523 calendar_record_h calendar_book = NULL;
525 _calendar_record_type record_type = _calendar_get_record_type(record);
527 switch (record_type) {
528 case _CALENDAR_RECORD_TYPE_CALENDARBOOK:
529 calendar_book = record;
531 case _CALENDAR_RECORD_TYPE_EVENT:
532 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &calendar_book_id);
534 case _CALENDAR_RECORD_TYPE_TODO:
535 error = calendar_record_get_int(record, _calendar_todo.calendar_book_id, &calendar_book_id);
537 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
538 error = calendar_record_get_int(record, _calendar_event_calendar_book.calendar_book_id, &calendar_book_id);
540 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
541 error = calendar_record_get_int(record, _calendar_todo_calendar_book.calendar_book_id, &calendar_book_id);
543 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
544 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.calendar_book_id, &calendar_book_id);
546 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
547 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.calendar_book_id, &calendar_book_id);
549 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
550 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.calendar_book_id, &calendar_book_id);
553 ERR("Invaild type : %d", record_type);
557 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
559 if (!calendar_book) {
561 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
562 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
565 char *calendar_name = NULL;
567 error = calendar_record_get_str(calendar_book, _calendar_book.name, &calendar_name);
568 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
570 if (calendar_book != record) {
571 error = calendar_record_destroy(calendar_book, true);
572 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
575 return CAL_STRDUP(calendar_name);
578 void _calendar_get_calendar_color(calendar_record_h record, _calendar_book_color* calendar_color )
581 c_ret_if(!calendar_color);
583 calendar_error_e error = CALENDAR_ERROR_NONE;
585 calendar_record_h calendar_book = NULL;
587 _calendar_record_type record_type = _calendar_get_record_type(record);
589 if (record_type == _CALENDAR_RECORD_TYPE_CALENDARBOOK)
590 calendar_book = record;
592 int calendar_book_id = _calendar_get_calendar_index(record);
594 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
595 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record(%d) is failed(%x)", calendar_book_id, error);
600 error = calendar_record_get_str(calendar_book, _calendar_book.color, &color);
601 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
606 if (8 < CAL_STRLEN(color)) {
608 token = strtok_r(color, ".", &temp);
610 calendar_color->red = atoi(token);
612 calendar_color->red = 0;
614 token = strtok_r(NULL, ".", &temp);
616 calendar_color->green = atoi(token);
618 calendar_color->green = 0;
620 token = strtok_r(NULL, ".", &temp);
622 calendar_color->blue = atoi(token);
624 calendar_color->blue = 0;
626 token = strtok_r(NULL, ".", &temp);
628 calendar_color->alpha = atoi(token);
630 calendar_color->alpha = 255;
632 *calendar_color = __calendar_default_color[_calendar_get_record_index(calendar_book)%6];
637 if (calendar_book != record) {
638 error = calendar_record_destroy(calendar_book, true);
639 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
643 int _calendar_get_calendar_index(calendar_record_h record)
645 c_retv_if(!record, -1);
647 calendar_error_e error = CALENDAR_ERROR_NONE;
649 _calendar_record_type record_type = _calendar_get_record_type(record);
651 int calendar_book_id = 0;
653 switch (record_type) {
654 case _CALENDAR_RECORD_TYPE_CALENDARBOOK:
655 error = calendar_record_get_int(record, _calendar_book.id, &calendar_book_id);
657 case _CALENDAR_RECORD_TYPE_EVENT:
658 error = calendar_record_get_int(record, _calendar_event.calendar_book_id, &calendar_book_id);
660 case _CALENDAR_RECORD_TYPE_TODO:
661 error = calendar_record_get_int(record, _calendar_todo.calendar_book_id, &calendar_book_id);
663 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
664 error = calendar_record_get_int(record, _calendar_event_calendar_book.calendar_book_id, &calendar_book_id);
666 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
667 error = calendar_record_get_int(record, _calendar_todo_calendar_book.calendar_book_id, &calendar_book_id);
669 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
670 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.calendar_book_id, &calendar_book_id);
672 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
673 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.calendar_book_id, &calendar_book_id);
675 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
676 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.calendar_book_id, &calendar_book_id);
679 ERR("Invaild type : %d", record_type);
683 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
685 return calendar_book_id;
688 static char * __calendar_get_birthday_contact_title(calendar_record_h record)
690 c_retv_if(!record, NULL);
692 calendar_record_h origin_calendar_record = NULL;
693 calendar_error_e error = CALENDAR_ERROR_NONE;
695 if (_calendar_get_record_type(record) == _CALENDAR_RECORD_TYPE_EVENT)
696 origin_calendar_record = record;
699 int id = _calendar_get_record_index(record);
701 error = calendar_db_get_record(_calendar_event._uri, id, &origin_calendar_record);
702 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record(%d) is failed(%x)", id, error);
705 char *sync_data1 = NULL;
706 char *summary = NULL;
708 error = calendar_record_get_str_p(origin_calendar_record, _calendar_event.sync_data1, &sync_data1);
709 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str_p() is failed(%x)", error);
711 error = calendar_record_get_str_p(origin_calendar_record, _calendar_event.summary, &summary);
712 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str_p() is failed(%x)", error);
714 int title_len = strlen(summary)+50;
715 char *contact_title = calloc(1, title_len);
716 c_retv_if(!contact_title, NULL);
719 if (!CAL_STRCMP(sync_data1, "anniversary"))
721 format = C_("IDS_CLD_BODY_PSS_ANNIVERSARY");
722 snprintf(contact_title, title_len-1, format, summary);
724 else if (!CAL_STRCMP(sync_data1, "birthday"))
726 format = C_("IDS_CLD_POP_NAMES_BIRTHDAY");
727 snprintf(contact_title, title_len-1, format, summary);
730 snprintf(contact_title, title_len-1, "%s.%s", summary, sync_data1);
732 if (origin_calendar_record != record) {
733 error = calendar_record_destroy(origin_calendar_record, true);
734 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
737 return contact_title;
740 static Eina_Bool __calendar_is_birthday_contact_record(calendar_record_h record)
742 c_retv_if(!record, EINA_FALSE);
744 int calendar_id = _calendar_get_calendar_index(record);
745 if(calendar_id == DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID )
751 char * _calendar_get_summary(calendar_record_h record)
753 c_retv_if(!record, NULL);
755 calendar_error_e error = CALENDAR_ERROR_NONE;
757 _calendar_record_type record_type = _calendar_get_record_type(record);
759 char *summary = NULL;
761 if(__calendar_is_birthday_contact_record(record))
763 summary = __calendar_get_birthday_contact_title(record);
767 switch (record_type) {
768 case _CALENDAR_RECORD_TYPE_EVENT:
769 error = calendar_record_get_str(record, _calendar_event.summary, &summary);
771 case _CALENDAR_RECORD_TYPE_TODO:
772 error = calendar_record_get_str(record, _calendar_todo.summary, &summary);
774 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
775 error = calendar_record_get_str(record, _calendar_event_calendar_book.summary, &summary);
777 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
778 error = calendar_record_get_str(record, _calendar_todo_calendar_book.summary, &summary);
780 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
781 error = calendar_record_get_str(record, _calendar_event_calendar_book_attendee.summary, &summary);
783 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
784 error = calendar_record_get_str(record, _calendar_instance_normal_calendar_book.summary, &summary);
786 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
787 error = calendar_record_get_str(record, _calendar_instance_allday_calendar_book.summary, &summary);
790 ERR("Invaild type : %d", record_type);
794 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
796 if (!CAL_STRLEN(summary)) {
800 return strdup(C_("IDS_CLD_BODY_NO_TITLE"));
806 char * _calendar_get_location(calendar_record_h record)
808 c_retv_if(!record, NULL);
810 calendar_error_e error = CALENDAR_ERROR_NONE;
812 _calendar_record_type record_type = _calendar_get_record_type(record);
814 char *location = NULL;
816 switch (record_type) {
817 case _CALENDAR_RECORD_TYPE_EVENT:
818 error = calendar_record_get_str(record, _calendar_event.location, &location);
820 case _CALENDAR_RECORD_TYPE_TODO:
821 error = calendar_record_get_str(record, _calendar_todo.location, &location);
823 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
824 error = calendar_record_get_str(record, _calendar_event_calendar_book.location, &location);
826 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
827 error = calendar_record_get_str(record, _calendar_todo_calendar_book.location, &location);
829 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
830 error = calendar_record_get_str(record, _calendar_event_calendar_book_attendee.location, &location);
832 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
833 error = calendar_record_get_str(record, _calendar_instance_normal_calendar_book.location, &location);
835 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
836 error = calendar_record_get_str(record, _calendar_instance_allday_calendar_book.location, &location);
839 ERR("Invaild type : %d", record_type);
843 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
849 void _calendar_free_record_list(Eina_List **record_list)
851 c_ret_if(!record_list);
856 calendar_record_h record = NULL;
857 Eina_List *list = NULL;
859 EINA_LIST_FOREACH(*record_list, list, record) {
863 calendar_error_e error = CALENDAR_ERROR_NONE;
865 error = calendar_record_destroy(record, true);
866 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
869 *record_list = eina_list_free(*record_list);
870 c_warn_if(*record_list, "eina_list_free() is failed()");
873 void _calendar_get_start_time(calendar_record_h record, calendar_time_s *start_time)
876 c_ret_if(!start_time);
878 calendar_error_e error = CALENDAR_ERROR_NONE;
880 _calendar_record_type record_type = _calendar_get_record_type(record);
882 switch (record_type) {
883 case _CALENDAR_RECORD_TYPE_EVENT:
884 error = calendar_record_get_caltime(record, _calendar_event.start_time, start_time);
886 case _CALENDAR_RECORD_TYPE_TODO:
887 error = calendar_record_get_caltime(record, _calendar_todo.due_time, start_time); // !!!
889 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
890 error = calendar_record_get_caltime(record, _calendar_event_calendar_book.start_time, start_time);
892 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
893 error = calendar_record_get_caltime(record, _calendar_todo_calendar_book.due_time, start_time); // !!!
895 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
896 error = calendar_record_get_caltime(record, _calendar_event_calendar_book_attendee.start_time, start_time);
898 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
899 error = calendar_record_get_caltime(record, _calendar_instance_normal_calendar_book.start_time, start_time);
901 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
902 error = calendar_record_get_caltime(record, _calendar_instance_allday_calendar_book.start_time, start_time);
905 ERR("Invaild type : %d", record_type);
909 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
912 void _calendar_get_end_time(calendar_record_h record, calendar_time_s *end_time)
917 calendar_error_e error = CALENDAR_ERROR_NONE;
919 _calendar_record_type record_type = _calendar_get_record_type(record);
921 switch (record_type) {
922 case _CALENDAR_RECORD_TYPE_EVENT:
923 error = calendar_record_get_caltime(record, _calendar_event.end_time, end_time);
925 case _CALENDAR_RECORD_TYPE_TODO:
926 error = calendar_record_get_caltime(record, _calendar_todo.due_time, end_time);
928 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
929 error = calendar_record_get_caltime(record, _calendar_event_calendar_book.end_time, end_time);
931 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
932 error = calendar_record_get_caltime(record, _calendar_todo_calendar_book.due_time, end_time);
934 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
935 error = calendar_record_get_caltime(record, _calendar_event_calendar_book_attendee.end_time, end_time);
937 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
938 error = calendar_record_get_caltime(record, _calendar_instance_normal_calendar_book.end_time, end_time);
940 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
941 error = calendar_record_get_caltime(record, _calendar_instance_allday_calendar_book.end_time, end_time);
944 ERR("Invaild type : %d", record_type);
948 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
951 void _calendar_set_start_time(calendar_record_h record, calendar_time_s *start_time)
954 c_ret_if(!start_time);
956 calendar_error_e error = CALENDAR_ERROR_NONE;
958 _calendar_record_type record_type = _calendar_get_record_type(record);
960 switch (record_type) {
961 case _CALENDAR_RECORD_TYPE_EVENT:
962 error = calendar_record_set_caltime(record, _calendar_event.start_time, *start_time);
964 case _CALENDAR_RECORD_TYPE_TODO:
965 error = calendar_record_set_caltime(record, _calendar_todo.start_time, *start_time);
967 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
968 error = calendar_record_set_caltime(record, _calendar_event_calendar_book.start_time, *start_time);
970 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
971 error = calendar_record_set_caltime(record, _calendar_todo_calendar_book.start_time, *start_time);
973 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
974 error = calendar_record_set_caltime(record, _calendar_event_calendar_book_attendee.start_time, *start_time);
976 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
977 error = calendar_record_set_caltime(record, _calendar_instance_normal_calendar_book.start_time, *start_time);
979 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
980 error = calendar_record_set_caltime(record, _calendar_instance_allday_calendar_book.start_time, *start_time);
983 ERR("Invaild type : %d", record_type);
987 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
990 void _calendar_set_end_time(calendar_record_h record, calendar_time_s *end_time)
995 calendar_error_e error = CALENDAR_ERROR_NONE;
997 _calendar_record_type record_type = _calendar_get_record_type(record);
999 switch (record_type) {
1000 case _CALENDAR_RECORD_TYPE_EVENT:
1001 error = calendar_record_set_caltime(record, _calendar_event.end_time, *end_time);
1003 case _CALENDAR_RECORD_TYPE_TODO:
1004 error = calendar_record_set_caltime(record, _calendar_todo.due_time, *end_time);
1006 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
1007 error = calendar_record_set_caltime(record, _calendar_event_calendar_book.end_time, *end_time);
1009 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
1010 error = calendar_record_set_caltime(record, _calendar_todo_calendar_book.due_time, *end_time);
1012 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
1013 error = calendar_record_set_caltime(record, _calendar_event_calendar_book_attendee.end_time, *end_time);
1015 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
1016 error = calendar_record_set_caltime(record, _calendar_instance_normal_calendar_book.end_time, *end_time);
1018 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
1019 error = calendar_record_set_caltime(record, _calendar_instance_allday_calendar_book.end_time, *end_time);
1022 ERR("Invaild type : %d", record_type);
1026 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() is failed(%x)", error);
1030 void _calendar_delete_record_with_index(int index)
1032 c_ret_if(index < 0);
1034 calendar_error_e error = CALENDAR_ERROR_NONE;
1036 error = calendar_db_delete_record(_calendar_event._uri, index);
1038 if (error != CALENDAR_ERROR_NONE)
1039 error = calendar_db_delete_record(_calendar_todo._uri, index);
1041 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_delete_record() is failed(%x)", error);
1044 void _calendar_delete_record(calendar_record_h record)
1048 calendar_error_e error = CALENDAR_ERROR_NONE;
1050 int index = _calendar_get_record_index(record);
1052 _calendar_record_type record_type = _calendar_get_record_type(record);
1054 switch (record_type) {
1055 case _CALENDAR_RECORD_TYPE_TODO:
1056 error = calendar_db_delete_record(_calendar_todo._uri, index);
1059 error = calendar_db_delete_record(_calendar_event._uri, index);
1063 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_delete_record() is failed(%x)", error);
1066 Eina_Bool _calendar_is_recurrent_record(calendar_record_h record)
1068 c_retv_if(!record, EINA_FALSE);
1070 calendar_error_e error = CALENDAR_ERROR_NONE;
1072 _calendar_record_type record_type = _calendar_get_record_type(record);
1074 calendar_recurrence_frequency_e frequency = CALENDAR_RECURRENCE_NONE;
1076 switch (record_type) {
1077 case _CALENDAR_RECORD_TYPE_EVENT:
1078 error = calendar_record_get_int(record, _calendar_event.freq, (int *)&frequency);
1080 case _CALENDAR_RECORD_TYPE_TODO:
1081 error = calendar_record_get_int(record, _calendar_todo.freq, (int *)&frequency);
1083 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
1084 error = calendar_record_get_int(record, _calendar_event_calendar_book.freq, (int *)&frequency);
1086 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
1087 error = calendar_record_get_int(record, _calendar_todo_calendar_book.freq, (int *)&frequency);
1089 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
1090 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.freq, (int *)&frequency);
1092 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
1093 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.has_rrule, (int *)&frequency);
1095 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
1096 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.has_rrule, (int *)&frequency);
1099 ERR("Invaild type : %d", record_type);
1103 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
1105 if (frequency == CALENDAR_RECURRENCE_NONE)
1111 Eina_Bool _calendar_has_reminder(calendar_record_h record)
1113 c_retv_if(!record, EINA_FALSE);
1115 calendar_error_e error = CALENDAR_ERROR_NONE;
1117 _calendar_record_type record_type = _calendar_get_record_type(record);
1119 int has_reminder = 0;
1121 switch (record_type) {
1122 case _CALENDAR_RECORD_TYPE_EVENT:
1123 error = calendar_record_get_int(record, _calendar_event.has_alarm, &has_reminder);
1125 case _CALENDAR_RECORD_TYPE_TODO:
1126 error = calendar_record_get_int(record, _calendar_todo.has_alarm, &has_reminder);
1128 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
1129 error = calendar_record_get_int(record, _calendar_event_calendar_book.has_alarm, &has_reminder);
1131 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
1132 error = calendar_record_get_int(record, _calendar_todo_calendar_book.has_alarm, &has_reminder);
1134 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
1135 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.has_alarm, &has_reminder);
1137 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
1138 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.has_alarm, &has_reminder);
1140 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
1141 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.has_alarm, &has_reminder);
1144 ERR("Invaild type : %d", record_type);
1148 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
1150 _calendar_show_error(error);
1159 calendar_record_h _calendar_get_record_with_index(int index)
1161 c_retv_if(index < 0, NULL);
1163 calendar_record_h record = NULL;
1165 calendar_error_e error = CALENDAR_ERROR_NONE;
1167 error = calendar_db_get_record(_calendar_event._uri, index, &record);
1169 if (error != CALENDAR_ERROR_NONE)
1170 error = calendar_db_get_record(_calendar_todo._uri, index, &record);
1172 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_delete_record() is failed(%x)", error);
1177 int _calendar_get_record_index(calendar_record_h record)
1179 c_retv_if(!record, -1);
1181 calendar_error_e error = CALENDAR_ERROR_NONE;
1185 _calendar_record_type record_type = _calendar_get_record_type(record);
1187 switch (record_type) {
1188 case _CALENDAR_RECORD_TYPE_EVENT:
1189 error = calendar_record_get_int(record, _calendar_event.id, &index);
1191 case _CALENDAR_RECORD_TYPE_TODO:
1192 error = calendar_record_get_int(record, _calendar_todo.id, &index);
1194 case _CALENDAR_RECORD_TYPE_CALENDARBOOK:
1195 error = calendar_record_get_int(record, _calendar_book.id, &index);
1197 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR:
1198 error = calendar_record_get_int(record, _calendar_event_calendar_book.event_id, &index);
1200 case _CALENDAR_RECORD_TYPE_SEARCH_TODO_CALENDAR:
1201 error = calendar_record_get_int(record, _calendar_todo_calendar_book.todo_id, &index);
1203 case _CALENDAR_RECORD_TYPE_SEARCH_EVENT_CALENDAR_ATTENDEE:
1204 error = calendar_record_get_int(record, _calendar_event_calendar_book_attendee.event_id, &index);
1206 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR:
1207 error = calendar_record_get_int(record, _calendar_instance_normal_calendar_book.event_id, &index);
1209 case _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR:
1210 error = calendar_record_get_int(record, _calendar_instance_allday_calendar_book.event_id, &index);
1212 case _CALENDAR_RECORD_TYPE_EXTENDED_PROPERTY:
1213 error = calendar_record_get_int(record, _calendar_extended_property.id, &index);
1216 ERR("Invaild type : %d", record_type);
1220 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
1225 void _calendar_export_record_to_vcs(calendar_record_h record, const char *file_path)
1228 c_ret_if(!file_path);
1230 calendar_list_h list = NULL;
1232 calendar_error_e error = CALENDAR_ERROR_NONE;
1234 error = calendar_list_create(&list);
1235 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_create() is failed(%x)");
1237 error = calendar_list_add(list, record);
1238 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_add() is failed(%x)");
1240 char *vcalendar_strem = NULL;
1242 error = calendar_vcalendar_make_from_records(list, &vcalendar_strem);
1243 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_vcalendar_make_from_records() is failed(%x)");
1245 int fd = open(file_path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
1247 ERR("open(%s) is failed.", file_path);
1248 free(vcalendar_strem);
1249 error = calendar_list_destroy(list, false);
1257 if (vcalendar_strem) {
1258 ret = write(fd, vcalendar_strem, strlen(vcalendar_strem));
1260 ERR("write() is failed");
1263 cal_util_update_media_db(file_path);
1265 free(vcalendar_strem);
1269 c_warn_if(ret < 0, "fsync(%d) is failed.", fd);
1274 error = calendar_list_destroy(list, false);
1277 int * _calendar_get_month(struct tm *start, struct tm *end, int is_display_completed_todo)
1281 c_retv_if(!start, NULL);
1282 c_retv_if(!end, NULL);
1284 int *month = calloc(31, sizeof(int));
1285 c_retv_if(!month, NULL);
1287 calendar_query_h query = NULL;
1289 calendar_error_e error = CALENDAR_ERROR_NONE;
1291 calendar_time_s caltime_start = {0};
1292 calendar_time_s caltime_end = {0};
1294 long long int lli_start = 0;
1295 long long int lli_end = 0;
1297 struct tm tm_start = {0};
1298 struct tm tm_end = {0};
1300 cal_util_convert_tm_to_lli(NULL, start, &lli_start);
1301 cal_util_convert_tm_to_lli(NULL, end, &lli_end);
1303 caltime_start.type = CALENDAR_TIME_UTIME;
1304 caltime_start.time.utime = lli_start;
1306 caltime_end.type = CALENDAR_TIME_UTIME;
1307 caltime_end.time.utime = lli_end;
1309 calendar_filter_h filter = NULL;
1311 error = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &query);
1312 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1314 error = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &filter);
1315 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1317 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
1318 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1320 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1321 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1323 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1324 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1326 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1327 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1329 error = calendar_filter_add_int(filter, _calendar_instance_normal_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1330 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1332 error = calendar_query_set_filter(query, filter);
1333 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1335 calendar_list_h list = NULL;
1337 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1338 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1342 error = calendar_list_get_count(list,&count);
1343 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
1345 error = calendar_list_first(list);
1346 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1351 for (index = 0; index < count; index++) {
1353 calendar_record_h record = NULL;
1355 error = calendar_list_get_current_record_p(list, &record);
1356 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
1358 _calendar_get_start_time(record, &caltime_start);
1359 _calendar_get_end_time(record, &caltime_end);
1361 cal_util_convert_lli_to_tm(NULL, caltime_start.time.utime, &tm_start);
1362 cal_util_convert_lli_to_tm(NULL, caltime_end.time.utime, &tm_end);
1364 for (i = tm_start.tm_mday; i <= tm_end.tm_mday; i++)
1367 calendar_list_next(list);
1370 error = calendar_list_destroy(list, true);
1371 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
1374 error = calendar_filter_destroy(filter);
1375 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1378 error = calendar_query_destroy(query);
1379 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1382 error = calendar_query_create(_calendar_todo_calendar_book._uri, &query);
1383 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1385 error = calendar_filter_create(_calendar_todo_calendar_book._uri, &filter);
1386 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1388 caltime_start.time.utime = lli_start;
1389 caltime_end.time.utime = lli_end;
1391 error = calendar_filter_add_caltime(filter, _calendar_todo_calendar_book.due_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
1392 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1394 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1395 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1397 error = calendar_filter_add_caltime(filter, _calendar_todo_calendar_book.due_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1398 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1400 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1401 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1403 error = calendar_filter_add_int(filter, _calendar_todo_calendar_book.is_deleted, CALENDAR_MATCH_EQUAL, 0);
1404 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1406 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1407 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1409 error = calendar_filter_add_int(filter, _calendar_todo_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1410 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1412 error = calendar_query_set_filter(query, filter);
1413 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1415 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1416 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1418 error = calendar_list_get_count(list,&count);
1419 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
1421 error = calendar_list_first(list);
1422 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1424 for (index = 0; index < count; index++) {
1426 calendar_record_h record = NULL;
1428 error = calendar_list_get_current_record_p(list, &record);
1429 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
1431 _calendar_get_end_time(record, &caltime_end);
1433 cal_util_convert_lli_to_tm(NULL, caltime_end.time.utime, &tm_end);
1435 if (!is_display_completed_todo) {
1437 calendar_record_get_int(record, _calendar_todo_calendar_book.todo_status, &todo_status);
1438 if (CALENDAR_TODO_STATUS_COMPLETED != todo_status)
1439 month[tm_end.tm_mday - 1] += 1;
1441 month[tm_end.tm_mday - 1] += 1;
1444 calendar_list_next(list);
1447 error = calendar_list_destroy(list, true);
1448 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
1451 error = calendar_filter_destroy(filter);
1452 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1455 error = calendar_query_destroy(query);
1456 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1459 caltime_start.type = CALENDAR_TIME_LOCALTIME;
1460 caltime_start.time.date.year = start->tm_year + 1900;
1461 caltime_start.time.date.month = start->tm_mon + 1;
1462 caltime_start.time.date.mday = start->tm_mday;
1464 caltime_end.type = CALENDAR_TIME_LOCALTIME;
1465 caltime_end.time.date.year = end->tm_year + 1900;
1466 caltime_end.time.date.month = end->tm_mon + 1;
1467 caltime_end.time.date.mday = end->tm_mday;
1469 error = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &query);
1470 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1472 error = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &filter);
1473 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1475 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, caltime_start);
1476 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1478 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1479 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1481 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1482 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1484 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1485 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1487 error = calendar_filter_add_int(filter, _calendar_instance_allday_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1488 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1490 error = calendar_query_set_filter(query, filter);
1491 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1493 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1494 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1496 error = calendar_list_get_count(list,&count);
1497 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
1499 error = calendar_list_first(list);
1500 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1503 for (index = 0; index < count; index++) {
1505 calendar_record_h record = NULL;
1507 error = calendar_list_get_current_record_p(list, &record);
1508 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
1510 _calendar_get_start_time(record, &caltime_start);
1511 _calendar_get_end_time(record, &caltime_end);
1513 for (i = caltime_start.time.date.mday; i <= caltime_end.time.date.mday; i++)
1516 calendar_list_next(list);
1519 error = calendar_list_destroy(list, true);
1520 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
1523 error = calendar_filter_destroy(filter);
1524 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1527 error = calendar_query_destroy(query);
1528 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1536 calendar_list_h _calendar_get_normal_instance_list_handler(struct tm *start, struct tm *end)
1538 c_retv_if(!start, NULL);
1539 c_retv_if(!end, NULL);
1541 calendar_query_h query = NULL;
1543 calendar_error_e error = CALENDAR_ERROR_NONE;
1545 error = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &query);
1546 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1548 calendar_time_s caltime_start = {0};
1549 calendar_time_s caltime_end = {0};
1551 long long int lli_start = 0;
1552 long long int lli_end = 0;
1554 cal_util_convert_tm_to_lli(NULL, start, &lli_start);
1555 cal_util_convert_tm_to_lli(NULL, end, &lli_end);
1557 caltime_start.type = CALENDAR_TIME_UTIME;
1558 caltime_start.time.utime = lli_start;
1560 caltime_end.type = CALENDAR_TIME_UTIME;
1561 caltime_end.time.utime = lli_end;
1563 calendar_filter_h filter = NULL;
1565 error = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &filter);
1566 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1568 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
1569 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1571 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1572 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1574 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1575 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1577 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1578 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1580 error = calendar_filter_add_int(filter, _calendar_instance_normal_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1581 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1583 error = calendar_query_set_filter(query, filter);
1584 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1586 calendar_list_h list = NULL;
1588 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1589 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1591 error = calendar_filter_destroy(filter);
1592 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1594 error = calendar_query_destroy(query);
1595 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1597 error = calendar_list_first(list);
1598 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1603 calendar_list_h _calendar_get_allday_instance_list_handler(struct tm *start, struct tm *end)
1605 c_retv_if(!start, NULL);
1606 c_retv_if(!end, NULL);
1608 calendar_query_h query = NULL;
1610 calendar_error_e error = CALENDAR_ERROR_NONE;
1612 error = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &query);
1613 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1615 calendar_time_s caltime_start = {0};
1616 calendar_time_s caltime_end = {0};
1618 caltime_start.type = CALENDAR_TIME_LOCALTIME;
1619 caltime_start.time.date.year = start->tm_year + 1900;
1620 caltime_start.time.date.month = start->tm_mon + 1;
1621 caltime_start.time.date.mday = start->tm_mday;
1623 caltime_end.type = CALENDAR_TIME_LOCALTIME;
1624 caltime_end.time.date.year = end->tm_year + 1900;
1625 caltime_end.time.date.month = end->tm_mon + 1;
1626 caltime_end.time.date.mday = end->tm_mday;
1628 calendar_filter_h filter = NULL;
1630 error = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &filter);
1631 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1633 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, caltime_start);
1634 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1636 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1637 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1639 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.start_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1640 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1642 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1643 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1645 error = calendar_filter_add_int(filter, _calendar_instance_allday_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1646 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1648 error = calendar_query_set_filter(query, filter);
1649 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1651 calendar_list_h list = NULL;
1653 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1654 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1656 error = calendar_filter_destroy(filter);
1657 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1659 error = calendar_query_destroy(query);
1660 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1662 error = calendar_list_first(list);
1663 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1668 calendar_list_h _calendar_get_task_list_handler(struct tm *start, struct tm *end, Eina_Bool is_show_completed_task, _calendar_task_sort_type sort_type)
1670 c_retv_if(!start, NULL);
1671 c_retv_if(!end, NULL);
1673 calendar_query_h query = NULL;
1675 calendar_error_e error = CALENDAR_ERROR_NONE;
1677 error = calendar_query_create(_calendar_todo_calendar_book._uri, &query);
1678 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1680 calendar_time_s caltime_start = {0};
1681 calendar_time_s caltime_end = {0};
1683 long long int lli_start = 0;
1684 long long int lli_end = 0;
1686 cal_util_convert_tm_to_lli(NULL, start, &lli_start);
1687 cal_util_convert_tm_to_lli(NULL, end, &lli_end);
1689 caltime_start.type = CALENDAR_TIME_UTIME;
1690 caltime_start.time.utime = lli_start;
1692 caltime_end.type = CALENDAR_TIME_UTIME;
1693 caltime_end.time.utime = lli_end;
1695 calendar_filter_h filter = NULL;
1696 calendar_filter_h status_filter = NULL;
1698 error = calendar_filter_create(_calendar_todo_calendar_book._uri, &filter);
1699 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1701 error = calendar_filter_add_caltime(filter, _calendar_todo_calendar_book.due_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
1702 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1704 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1705 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1707 error = calendar_filter_add_caltime(filter, _calendar_todo_calendar_book.due_time,CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
1708 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
1710 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1711 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1713 error = calendar_filter_add_int(filter, _calendar_todo_calendar_book.is_deleted, CALENDAR_MATCH_EQUAL, 0);
1714 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1716 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1717 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1719 error = calendar_filter_add_int(filter, _calendar_todo_calendar_book.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1720 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1722 if (!is_show_completed_task) {
1724 error = calendar_filter_create(_calendar_todo_calendar_book._uri, &status_filter);
1725 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1727 error = calendar_filter_add_int(status_filter, _calendar_todo_calendar_book.todo_status, CALENDAR_MATCH_EQUAL, CALENDAR_TODO_STATUS_NONE);
1728 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1730 error = calendar_filter_add_operator(status_filter, CALENDAR_FILTER_OPERATOR_OR);
1731 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1733 error = calendar_filter_add_int(status_filter, _calendar_todo_calendar_book.todo_status, CALENDAR_MATCH_EQUAL, CALENDAR_TODO_STATUS_NEEDS_ACTION);
1734 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1736 error = calendar_filter_add_operator(status_filter, CALENDAR_FILTER_OPERATOR_OR);
1737 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1739 error = calendar_filter_add_int(status_filter, _calendar_todo_calendar_book.todo_status, CALENDAR_MATCH_EQUAL, CALENDAR_TODO_STATUS_IN_PROCESS);
1740 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1742 error = calendar_filter_add_operator(status_filter, CALENDAR_FILTER_OPERATOR_OR);
1743 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1745 error = calendar_filter_add_int(status_filter, _calendar_todo_calendar_book.todo_status, CALENDAR_MATCH_EQUAL, CALENDAR_TODO_STATUS_CANCELED);
1746 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1748 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
1749 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1751 error = calendar_filter_add_filter(filter, status_filter);
1752 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_filter() is failed(%x)", error);
1755 error = calendar_query_set_filter(query, filter);
1756 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1758 switch (sort_type) {
1759 case _CALENDAR_TASK_SORT_TYPE_DUEDATE_ASC:
1760 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.due_time, true);
1762 case _CALENDAR_TASK_SORT_TYPE_DUEDATE_DES:
1763 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.due_time, false);
1765 case _CALENDAR_TASK_SORT_TYPE_PRIORITY_ASC:
1766 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.priority, true);
1768 case _CALENDAR_TASK_SORT_TYPE_PRIORITY_DES:
1769 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.priority, false);
1771 case _CALENDAR_TASK_SORT_TYPE_STATUS_ASC:
1772 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.todo_status, true);
1774 case _CALENDAR_TASK_SORT_TYPE_STATUS_DES:
1775 error = calendar_query_set_sort(query, _calendar_todo_calendar_book.todo_status, false);
1781 calendar_list_h list = NULL;
1783 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1784 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1786 error = calendar_filter_destroy(filter);
1787 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1789 error = calendar_filter_destroy(status_filter);
1790 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1792 error = calendar_query_destroy(query);
1793 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1795 error = calendar_list_first(list);
1796 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1801 calendar_list_h _calendar_search_event(const char *keyword)
1803 c_retv_if(!CAL_STRLEN(keyword), NULL);
1805 calendar_query_h query = NULL;
1807 calendar_error_e error = CALENDAR_ERROR_NONE;
1809 error = calendar_query_create(_calendar_event_calendar_book_attendee._uri, &query);
1810 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
1812 calendar_filter_h visibility_filter = NULL;
1814 error = calendar_filter_create(_calendar_event_calendar_book_attendee._uri, &visibility_filter);
1815 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1817 error = calendar_filter_add_int(visibility_filter, _calendar_event_calendar_book_attendee.calendar_book_visibility, CALENDAR_MATCH_EQUAL, 1);
1818 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
1820 calendar_filter_h filter = NULL;
1822 error = calendar_filter_create(_calendar_event_calendar_book_attendee._uri, &filter);
1823 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
1825 error = calendar_filter_add_str(filter, _calendar_event_calendar_book_attendee.summary, CALENDAR_MATCH_CONTAINS, keyword);
1826 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
1828 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_OR);
1829 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1831 error = calendar_filter_add_str(filter, _calendar_event_calendar_book_attendee.location, CALENDAR_MATCH_CONTAINS, keyword);
1832 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
1834 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_OR);
1835 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1837 error = calendar_filter_add_str(filter, _calendar_event_calendar_book_attendee.description, CALENDAR_MATCH_CONTAINS, keyword);
1838 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
1840 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_OR);
1841 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1843 error = calendar_filter_add_str(filter, _calendar_event_calendar_book_attendee.attendee_name, CALENDAR_MATCH_CONTAINS, keyword);
1844 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_str() is failed(%x)", error);
1846 error = calendar_filter_add_operator(visibility_filter, CALENDAR_FILTER_OPERATOR_AND);
1847 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
1849 error = calendar_filter_add_filter(visibility_filter, filter);
1850 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_filter() is failed(%x)", error);
1852 error = calendar_query_set_filter(query, visibility_filter);
1853 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
1855 calendar_list_h list = NULL;
1857 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1858 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1860 error = calendar_list_first(list);
1861 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1863 error = calendar_filter_destroy(visibility_filter);
1864 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1866 error = calendar_filter_destroy(filter);
1867 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
1869 error = calendar_query_destroy(query);
1870 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1875 calendar_list_h _calendar_search_task(const char* keyword)
1877 calendar_query_h query = cal_query_create_task_search_query(keyword);
1878 c_retv_if(!query, NULL);
1880 calendar_list_h list = NULL;
1881 calendar_error_e error = CALENDAR_ERROR_NONE;
1883 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1884 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1886 error = calendar_list_first(list);
1887 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1889 error = calendar_query_destroy(query);
1890 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1895 calendar_list_h _calendar_get_all_task_list(struct tm *start, struct tm *end, Eina_Bool is_show_completed_task, _calendar_task_sort_type sort_type)
1897 calendar_query_h query =
1898 cal_query_create_all_task_list_query(start, end, is_show_completed_task, sort_type);
1899 c_retv_if(!query, NULL);
1901 calendar_list_h list = NULL;
1902 calendar_error_e error = CALENDAR_ERROR_NONE;
1904 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1905 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1907 error = calendar_query_destroy(query);
1908 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1910 error = calendar_list_first(list);
1911 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1916 Eina_List* _calendar_get_all_task_list2(struct tm *start, struct tm *end, Eina_Bool is_show_completed_task, _calendar_task_sort_type sort_type)
1918 calendar_query_h query =
1919 cal_query_create_all_task_list_query(start, end, is_show_completed_task, sort_type);
1920 c_retv_if(!query, NULL);
1922 calendar_list_h list = NULL;
1923 calendar_error_e error = CALENDAR_ERROR_NONE;
1925 error = calendar_db_get_records_with_query(query, 0, 0, &list);
1926 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
1930 error = calendar_list_get_count(list, &count);
1931 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
1933 Eina_List *todo_list = NULL;
1935 error = calendar_list_first(list);
1936 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
1939 for (i = 0; i < count; i++) {
1941 calendar_record_h record = NULL;
1943 error = calendar_list_get_current_record_p(list, &record);
1944 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
1946 calendar_record_h new_record = NULL;
1948 error = calendar_record_clone(record, &new_record);
1949 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
1951 todo_list = eina_list_append(todo_list, new_record);
1952 c_warn_if(!todo_list, "eina_list_append() is failed.");
1954 calendar_list_next(list);
1957 error = calendar_list_destroy(list, false);
1958 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
1960 error = calendar_query_destroy(query);
1961 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
1966 static int __calendar_compare_todo_record_list_item(const void *data1, const void *data2)
1968 c_retv_if(!data1, 1);
1969 c_retv_if(!data2, -1);
1971 calendar_record_h record1 = data1;
1972 calendar_record_h record2 = data2;
1974 calendar_time_s record1_due_time = {0};
1975 calendar_time_s record2_due_time = {0};
1977 calendar_error_e error = CALENDAR_ERROR_NONE;
1978 error = calendar_record_get_caltime(record1, _calendar_todo_calendar_book.due_time, &record1_due_time);
1979 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
1981 error = calendar_record_get_caltime(record2, _calendar_todo_calendar_book.due_time, &record2_due_time);
1982 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() is failed(%x)", error);
1984 long long int lli_due1 = record1_due_time.time.utime;
1985 long long int lli_due2 = record2_due_time.time.utime;
1987 return (lli_due1 > lli_due2) ? 1 : -1;
1991 Eina_List* _calendar_get_due_date_task_list(struct tm *start, struct tm *end, Eina_Bool is_show_completed_task, _calendar_task_sort_type sort_type)
1993 calendar_query_h query =
1994 cal_query_create_due_date_task_list_query(start, end, is_show_completed_task, sort_type);
1995 c_retv_if(!query, NULL);
1997 calendar_list_h list = NULL;
1998 calendar_error_e error = CALENDAR_ERROR_NONE;
2000 error = calendar_db_get_records_with_query(query, 0, 0, &list);
2001 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
2005 error = calendar_list_get_count(list, &count);
2006 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
2008 Eina_List *todo_list = NULL;
2010 error = calendar_list_first(list);
2011 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
2014 for (i = 0; i < count; i++) {
2016 calendar_record_h record = NULL;
2018 error = calendar_list_get_current_record_p(list, &record);
2019 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
2021 calendar_record_h new_record = NULL;
2023 error = calendar_record_clone(record, &new_record);
2024 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_clone() is failed(%x)", error);
2026 todo_list = eina_list_append(todo_list, new_record);
2027 c_warn_if(!todo_list, "eina_list_append() is failed.");
2029 calendar_list_next(list);
2032 error = calendar_list_destroy(list, false);
2033 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
2035 error = calendar_query_destroy(query);
2036 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
2038 eina_list_sort(todo_list, 0, __calendar_compare_todo_record_list_item);
2042 Eina_List * _calendar_get_calendar_book_list_with_account_id(int account_id)
2044 c_retv_if(account_id < -1, NULL);
2046 Eina_List *calendar_book_list = NULL;
2048 calendar_error_e error = CALENDAR_ERROR_NONE;
2050 calendar_query_h query = NULL;
2052 error = calendar_query_create( _calendar_book._uri, &query);
2053 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
2055 calendar_filter_h filter = NULL;
2057 if (account_id != _CALENDAR_ALL_ACCOUNT_ID) {
2059 error = calendar_filter_create(_calendar_book._uri, &filter);
2060 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
2062 error = calendar_filter_add_int(filter, _calendar_book.is_deleted, CALENDAR_MATCH_EQUAL, 0);
2063 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
2065 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
2066 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
2068 error = calendar_filter_add_int(filter, _calendar_book.account_id, CALENDAR_MATCH_EQUAL, account_id);
2069 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
2071 error = calendar_query_set_filter(query, filter);
2072 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
2075 calendar_list_h list = NULL;
2077 error = calendar_db_get_records_with_query(query, 0, 0, &list);
2078 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
2082 error = calendar_list_get_count(list, &count);
2083 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
2085 error = calendar_list_first(list);
2086 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
2090 for (i = 0; i < count; i++) {
2092 calendar_record_h record = NULL;
2094 error = calendar_list_get_current_record_p(list, &record);
2095 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
2097 calendar_book_list = eina_list_append(calendar_book_list, record);
2098 c_warn_if(!calendar_book_list, "eina_list_append() is failed.");
2100 calendar_list_next(list);
2103 error = calendar_list_destroy(list, false);
2104 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
2106 if (account_id != _CALENDAR_ALL_ACCOUNT_ID) {
2107 error = calendar_filter_destroy(filter);
2108 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
2111 error = calendar_query_destroy(query);
2112 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
2114 return calendar_book_list;
2117 static char * __calendar_get_time_str_from_lli(long long int lli)
2119 UErrorCode status = U_ZERO_ERROR;
2121 UChar *tz_id = (UChar*)calloc(strlen("Etc/Unknown") + 1, sizeof(UChar));
2122 c_retv_if(!tz_id, NULL);
2124 u_uastrcpy(tz_id, "Etc/Unknown");
2126 UCalendar *cal = ucal_open(tz_id, u_strlen(tz_id), "en_US", UCAL_TRADITIONAL, &status);
2127 c_retv_if(U_FAILURE(status), NULL);
2138 ucal_setMillis(cal, lli * 1000, &status);
2140 year = ucal_get(cal, UCAL_YEAR, &status);
2141 month = ucal_get(cal, UCAL_MONTH, &status) + 1;
2142 day = ucal_get(cal, UCAL_DATE, &status);
2143 hour = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
2144 minute = ucal_get(cal, UCAL_MINUTE, &status);
2145 second = ucal_get(cal, UCAL_SECOND, &status);
2147 return g_strdup_printf("%04d%02d%02dT%02d%02d%02dZ", year, month, day, hour, minute, second);
2150 void _calendar_delete_recurrence_instance(calendar_record_h instance)
2152 c_ret_if(!instance);
2154 _calendar_record_type record_type = _calendar_get_record_type(instance);
2156 c_ret_if(record_type != _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR
2157 && record_type != _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_NORMAL_CALENDAR);
2159 calendar_record_h original_record = NULL;
2161 calendar_error_e error = CALENDAR_ERROR_NONE;
2165 if (record_type == _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR) {
2166 error = calendar_record_get_int(instance, _calendar_instance_allday_calendar_book.event_id, &event_id);
2168 error = calendar_record_get_int(instance, _calendar_instance_normal_calendar_book.event_id, &event_id);
2171 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2173 error = calendar_db_get_record(_calendar_event._uri, event_id, &original_record);
2174 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
2176 char *exdate = NULL;
2178 error = calendar_record_get_str(original_record, _calendar_event.exdate, &exdate);
2179 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
2181 calendar_time_s start_time = {0};
2183 _calendar_get_start_time(instance, &start_time);
2185 char *new_exdate = NULL;
2187 if (record_type == _CALENDAR_RECORD_TYPE_SEARCH_INSTANCE_ALLDAY_CALENDAR) {
2189 if (CAL_STRLEN(exdate))
2190 new_exdate = g_strdup_printf("%s,%04d%02d%02d", exdate, start_time.time.date.year, start_time.time.date.month, start_time.time.date.mday);
2192 new_exdate = g_strdup_printf("%04d%02d%02d", start_time.time.date.year, start_time.time.date.month, start_time.time.date.mday);
2195 char *lli = __calendar_get_time_str_from_lli(start_time.time.utime);
2198 if (CAL_STRLEN(exdate))
2199 new_exdate = g_strdup_printf("%s,%s", exdate, lli);
2201 new_exdate = g_strdup_printf("%s", lli);
2206 error = calendar_record_set_str(original_record, _calendar_event.exdate, new_exdate);
2207 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
2209 CAL_FREE(new_exdate);
2212 error = calendar_db_update_record(original_record);
2213 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_update_record() is failed(%x)", error);
2216 void _calendar_edit_recurrence_instance(calendar_record_h exception_record, int original_event_id)
2218 c_ret_if(!exception_record);
2219 c_ret_if(original_event_id <= 0);
2221 calendar_record_h original_record = NULL;
2223 calendar_error_e error = CALENDAR_ERROR_NONE;
2225 error = calendar_record_set_int(exception_record, _calendar_event.original_event_id, original_event_id);
2226 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_int() is failed(%x)", error);
2228 error = calendar_db_get_record(_calendar_event._uri, original_event_id, &original_record);
2229 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
2231 char *recurrence_id = NULL;
2233 error = calendar_record_get_str(original_record, _calendar_event.recurrence_id, &recurrence_id);
2234 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str() is failed(%x)", error);
2236 calendar_time_s time = {0};
2238 _calendar_get_start_time(exception_record, &time);
2240 char *new_recurrence_id = NULL;
2242 if (time.type == CALENDAR_TIME_LOCALTIME) {
2244 if (CAL_STRLEN(recurrence_id))
2245 new_recurrence_id = g_strdup_printf("%s,%04d%02d%02d", recurrence_id, time.time.date.year, time.time.date.month, time.time.date.mday);
2247 new_recurrence_id = g_strdup_printf("%04d%02d%02d", time.time.date.year, time.time.date.month, time.time.date.mday);
2250 char *lli = __calendar_get_time_str_from_lli(time.time.utime);
2253 if (CAL_STRLEN(recurrence_id))
2254 new_recurrence_id = g_strdup_printf("%s,%s", recurrence_id, lli);
2256 new_recurrence_id = g_strdup_printf("%s", lli);
2261 error = calendar_record_set_str(exception_record, _calendar_event.recurrence_id, new_recurrence_id);
2262 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_str() is failed(%x)", error);
2264 CAL_FREE(new_recurrence_id);
2265 CAL_FREE(recurrence_id);
2268 void _calendar_clear_child_record(calendar_record_h record, unsigned int property_id)
2272 calendar_error_e error = CALENDAR_ERROR_NONE;
2274 unsigned int child_record_count = 0;
2276 error = calendar_record_get_child_record_count(record, property_id, &child_record_count);
2277 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
2279 while (child_record_count--) {
2280 calendar_record_h child_record = NULL;
2282 error = calendar_record_get_child_record_at_p(record, property_id, 0, &child_record);
2283 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
2285 error = calendar_record_remove_child_record(record, property_id, child_record);
2286 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
2290 void _calendar_clear_child_record_by_key(calendar_record_h record, unsigned int property_id, const char *key)
2294 calendar_error_e error = CALENDAR_ERROR_NONE;
2296 unsigned int child_record_count = 0;
2297 char *item_key = NULL;
2299 error = calendar_record_get_child_record_count(record, property_id, &child_record_count);
2300 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() is failed(%x)", error);
2302 while (child_record_count--) {
2303 calendar_record_h child_record = NULL;
2305 error = calendar_record_get_child_record_at_p(record, property_id, 0, &child_record);
2306 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
2308 error = calendar_record_get_str_p(child_record, _calendar_extended_property.key, &item_key);
2309 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str_p() is failed(%x)", error);
2311 if (!CAL_STRCMP(item_key, key)) {
2312 error = calendar_record_remove_child_record(record, property_id, child_record);
2313 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() is failed(%x)", error);
2318 calendar_record_h _calendar_get_instance_from_record(calendar_record_h record, struct tm *start, struct tm *end)
2322 c_retv_if(!record, NULL);
2323 c_retv_if(!start, NULL);
2324 c_retv_if(!end, NULL);
2326 _calendar_record_type record_type = _calendar_get_record_type(record);
2327 c_retv_if(record_type != _CALENDAR_RECORD_TYPE_EVENT, NULL);
2329 calendar_error_e error = CALENDAR_ERROR_NONE;
2331 Eina_Bool is_allday_record = _calendar_is_allday_record(record);
2333 int record_index = 0;
2335 error = calendar_record_get_int(record, _calendar_event.id, &record_index);
2336 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
2338 calendar_time_s caltime_start = {0};
2339 calendar_time_s caltime_end = {0};
2341 calendar_query_h query = NULL;
2342 calendar_filter_h filter = NULL;
2344 if (is_allday_record) {
2345 error = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &query);
2346 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
2348 error = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &filter);
2349 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
2351 caltime_start.type = CALENDAR_TIME_LOCALTIME;
2352 caltime_end.type = CALENDAR_TIME_LOCALTIME;
2354 caltime_start.time.date.year = start->tm_year + 1900;
2355 caltime_start.time.date.month = start->tm_mon + 1;
2356 caltime_start.time.date.mday = start->tm_mday;
2358 caltime_end.time.date.year = end->tm_year + 1900;
2359 caltime_end.time.date.month = end->tm_mon + 1;
2360 caltime_end.time.date.mday = end->tm_mday;
2362 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, caltime_start);
2363 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
2365 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
2366 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
2368 error = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
2369 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
2371 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
2372 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
2374 error = calendar_filter_add_int(filter, _calendar_instance_allday_calendar_book.event_id, CALENDAR_MATCH_EQUAL, record_index);
2375 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
2379 error = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &query);
2380 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
2382 error = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &filter);
2383 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
2385 caltime_start.type = CALENDAR_TIME_UTIME;
2386 caltime_end.type = CALENDAR_TIME_UTIME;
2388 cal_util_convert_tm_to_lli(NULL, start, &caltime_start.time.utime);
2389 cal_util_convert_tm_to_lli(NULL, end, &caltime_end.time.utime);
2391 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_GREATER_THAN, caltime_start);
2392 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
2394 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
2395 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
2397 error = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, caltime_end);
2398 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_caltime() is failed(%x)", error);
2400 error = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
2401 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_operator() is failed(%x)", error);
2403 error = calendar_filter_add_int(filter, _calendar_instance_normal_calendar_book.event_id, CALENDAR_MATCH_EQUAL, record_index);
2404 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
2407 error = calendar_query_set_filter(query, filter);
2408 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_set_filter() is failed(%x)", error);
2410 calendar_list_h list = NULL;
2412 error = calendar_db_get_records_with_query(query, 0, 0, &list);
2413 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
2417 error = calendar_list_get_count(list, &count);
2418 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
2419 c_warn_if(count != 1, "count is not 1(%d)", count);
2421 error = calendar_list_first(list);
2422 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
2424 calendar_record_h instance = NULL;
2426 error = calendar_list_get_current_record_p(list, &instance);
2427 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
2429 error = calendar_list_destroy(list, false);
2430 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
2432 error = calendar_filter_destroy(filter);
2433 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
2435 error = calendar_query_destroy(query);
2436 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
2441 void _calendar_convert_calendar_time_to_tm(calendar_time_s *time, struct tm *tm)
2446 if (time->type == CALENDAR_TIME_UTIME) {
2447 cal_util_convert_lli_to_tm(NULL, time->time.utime, tm);
2449 tm->tm_year = time->time.date.year - 1900;
2450 tm->tm_mon = time->time.date.month - 1;
2451 tm->tm_mday = time->time.date.mday;
2458 char * _calendar_get_time_str(calendar_time_s *time, const char *date_format, const char *time_format)
2460 c_retv_if(!time, NULL);
2464 _calendar_convert_calendar_time_to_tm(time, &tm);
2466 char buffer[128] = {0};
2468 cal_util_get_time_text(buffer, sizeof(buffer), date_format, time_format, &tm);
2470 return strdup(buffer);
2473 const char* __calendar_get_time_format()
2476 return CAL_UTIL_TIME_FORMAT_6;
2478 return CAL_UTIL_TIME_FORMAT_1;
2481 char * _calendar_get_time_str_for_genlist(calendar_record_h record)
2483 c_retv_if(!record, NULL);
2485 if (_calendar_is_allday_record(record))
2486 return strdup(C_("IDS_COM_BODY_ALL_DAY"));
2488 calendar_time_s stat_time = {0};
2489 calendar_time_s end_time = {0};
2490 char buff[256] = {0};
2492 if (_calendar_is_task_record(record)) {
2493 calendar_time_s due_time;
2494 calendar_record_get_caltime(record, _calendar_todo_calendar_book.due_time, &due_time);
2495 if (due_time.time.utime == CALENDAR_TODO_NO_DUE_DATE) {
2496 return strdup(C_("IDS_CLD_BODY_NO_DUE_DATE_M_NOUN"));
2499 _calendar_get_end_time(record, &end_time);
2502 struct tm record_tm;
2504 time_t now = time(NULL);
2505 localtime_r(&now, &today_tm);
2507 _calendar_convert_calendar_time_to_tm(&end_time, &record_tm);
2509 if ((today_tm.tm_year == record_tm.tm_year) && (today_tm.tm_mon == record_tm.tm_mon) && (today_tm.tm_mday == record_tm.tm_mday)) {
2510 return _calendar_get_time_str(&end_time, NULL, __calendar_get_time_format());
2512 char *time = _calendar_get_time_str(&end_time, NULL, __calendar_get_time_format());
2513 char *date = _calendar_get_time_str(&end_time, NULL, CAL_UTIL_DATE_FORMAT_12);
2514 sprintf(buff, "%s %s", time, date);
2517 return strdup(buff);
2520 _calendar_get_start_time(record, &stat_time);
2521 _calendar_get_end_time(record, &end_time);
2522 char *start_str = _calendar_get_time_str(&stat_time, NULL, __calendar_get_time_format());
2523 char *end_str = _calendar_get_time_str(&end_time, NULL, __calendar_get_time_format());
2524 sprintf(buff, "%s-%s", start_str, end_str);
2527 return strdup(buff);
2531 static Eina_Bool __calendar_check_record_sync_data4(calendar_record_h record, const char *category)
2533 c_retv_if(!record, EINA_FALSE);
2534 c_retv_if(!CAL_STRLEN(category), EINA_FALSE);
2536 int calendar_book_id = _calendar_get_calendar_index(record);
2538 calendar_error_e error = CALENDAR_ERROR_NONE;
2540 calendar_record_h calendar_book = NULL;
2542 error = calendar_db_get_record(_calendar_book._uri, calendar_book_id, &calendar_book);
2543 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record(%d) is failed(%x)", calendar_book_id, error);
2545 char *sync_data4 = NULL;
2547 error = calendar_record_get_str_p(calendar_book, _calendar_book.sync_data4, &sync_data4);
2548 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_str_p() is failed(%x)", error);
2550 Eina_Bool result = EINA_FALSE;
2552 if (!CAL_STRCMP(sync_data4, category))
2555 error = calendar_record_destroy(calendar_book, true);
2556 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)", error);
2561 Eina_Bool _calendar_is_eas_record(calendar_record_h record)
2563 return __calendar_check_record_sync_data4(record, "exchange");
2566 Eina_Bool _calendar_is_facebook_record(calendar_record_h record)
2568 return __calendar_check_record_sync_data4(record, "facebook");
2571 void _calendar_get_recurrence_frequency_str(int freq, char *buf, int size)
2575 char *format = NULL;
2579 case CALENDAR_RECURRENCE_DAILY:
2581 snprintf(buf, size, "%s", C_("IDS_KC_BODY_EVERY_DAY"));
2584 case CAL_REPEAT_EVERY_3_DAY:
2586 format = C_("IDS_CLD_BODY_EVERY_PD_DAYS");
2587 snprintf(buf, size, format, 3);
2590 case CALENDAR_RECURRENCE_WEEKLY:
2592 snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_WEEK"));
2595 case CAL_REPEAT_EVERY_2_WEEK:
2597 format = C_("IDS_CLD_BODY_EVERY_PD_WEEKS");
2598 snprintf(buf, size, format, 2);
2601 case CALENDAR_RECURRENCE_MONTHLY:
2603 snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_MONTH"));
2606 case CALENDAR_RECURRENCE_YEARLY:
2608 snprintf(buf, size, "%s", C_("IDS_CLD_BODY_EVERY_YEAR"));
2613 snprintf(buf, size, "%s", S_("IDS_COM_BODY_OFF"));
2621 void _calendar_set_coordinates(calendar_record_h record, double latitude, double longitude)
2623 calendar_error_e error = CALENDAR_ERROR_NONE;
2625 if (_calendar_is_task_record(record)) {
2627 error = calendar_record_set_double(record, _calendar_todo.latitude, latitude);
2628 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
2630 error = calendar_record_set_double(record, _calendar_todo.longitude, longitude);
2631 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
2634 error = calendar_record_set_double(record, _calendar_event.latitude, latitude);
2635 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
2637 error = calendar_record_set_double(record, _calendar_event.longitude, longitude);
2638 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_set_double() is failed(%x)", error);
2643 void _calendar_get_coordinates(calendar_record_h record, double *latitude, double *longitude)
2645 calendar_error_e error = CALENDAR_ERROR_NONE;
2647 if (_calendar_is_task_record(record)) {
2649 error = calendar_record_get_double(record, _calendar_todo.latitude, latitude);
2650 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
2652 error = calendar_record_get_double(record, _calendar_todo.longitude, longitude);
2653 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
2656 error = calendar_record_get_double(record, _calendar_event.latitude, latitude);
2657 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);
2659 error = calendar_record_get_double(record, _calendar_event.longitude, longitude);
2660 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_double() is failed(%x)", error);