summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonghoon Lim <j.h.lim@samsung.com>2012-02-10 15:35:29 +0900
committerJonghoon Lim <j.h.lim@samsung.com>2012-02-10 15:35:29 +0900
commitb0f45ecd95bed424d5e21c229f2363e6e8f758d7 (patch)
tree0236b3c0af3ce878b3ea62775f0df28ff47e0716 /src
parent11da635c79ea21765a50d28cf81ff6b51dddefa0 (diff)
downloadcalendar-b0f45ecd95bed424d5e21c229f2363e6e8f758d7.tar.gz
calendar-b0f45ecd95bed424d5e21c229f2363e6e8f758d7.tar.bz2
calendar-b0f45ecd95bed424d5e21c229f2363e6e8f758d7.zip
capi-social-calendar_0.1.1-30
Diffstat (limited to 'src')
-rwxr-xr-xsrc/calendar.c306
-rwxr-xr-xsrc/calendar_private.c151
2 files changed, 376 insertions, 81 deletions
diff --git a/src/calendar.c b/src/calendar.c
index 1e73ed1..119617a 100755
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -60,12 +60,18 @@ int calendar_disconnect(void)
}
}
-int calendar_event_insert_to_db(calendar_event_h event, int *event_id)
+int calendar_event_insert_to_db(calendar_event_h event, int calendar_db_id, int *event_id)
{
- int ret_val = CALENDAR_ERROR_NONE;
-
CALENDAR_NULL_ARG_CHECK(event);
CALENDAR_NULL_ARG_CHECK(event_id);
+
+ int ret_val = CALENDAR_ERROR_NONE;
+
+ int account_db_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_db_id == -2);
+
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_CALENDAR_ID, calendar_db_id);
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_ACCOUNT_ID, account_db_id);
ret_val = -1;
ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)event)->event_legacy);
@@ -80,10 +86,7 @@ int calendar_event_insert_to_db(calendar_event_h event, int *event_id)
int calendar_event_delete_from_db(int event_id)
{
- if(event_id <= 0) {
- LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER);
- return CALENDAR_ERROR_INVALID_PARAMETER;
- }
+ CONTACTS_INVALID_ARG_CHECK(event_id <= 0);
int ret_val = CALENDAR_ERROR_NONE;
@@ -103,9 +106,10 @@ int calendar_event_delete_from_db(int event_id)
int calendar_event_update_to_db(calendar_event_h event)
{
+ CALENDAR_NULL_ARG_CHECK(event);
+
int ret_val = CALENDAR_ERROR_NONE;
- CALENDAR_NULL_ARG_CHECK(event);
if((cal_struct*)((calendar_event_s*)event)->event_legacy == NULL) {
LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER);
return CALENDAR_ERROR_INVALID_PARAMETER;
@@ -148,55 +152,6 @@ int calendar_event_update_to_db(calendar_event_h event)
return CALENDAR_ERROR_NONE;
}
-//Provide iterator instead of event
-int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data)
-{
- CALENDAR_NULL_ARG_CHECK(callback);
-
- int ret_val = CALENDAR_ERROR_NONE;
- cal_iter* iter = NULL;
- bool callback_return = true;
-
- //fetch from DB
- ret_val = calendar_svc_get_all(0, 0, CAL_STRUCT_SCHEDULE, &iter);
-
- if (ret_val != CAL_SUCCESS) {
- LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
- return CALENDAR_ERROR_DB_FAILED;
- }
-
- if (iter == NULL) {
- LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
- return CALENDAR_ERROR_DB_FAILED;
- } else {
- while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
- calendar_event_s cal_event_from_db = {0,};
- if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
- calendar_svc_iter_remove(&iter);
- return CALENDAR_ERROR_NONE; // consider this as no data
- }
-
- if(cal_event_from_db.event_legacy == NULL) {
- calendar_svc_iter_remove(&iter);
- return CALENDAR_ERROR_NONE; // consider this as no data
- }
-
- //execute callback
- callback_return = callback((calendar_event_h)&cal_event_from_db, user_data);
-
- calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
-
- if(callback_return == false) {
- break;
- }
- }
- calendar_svc_iter_remove(&iter);
-
- return CALENDAR_ERROR_NONE;
- }
- return CALENDAR_ERROR_NONE;
-}
-
int calendar_event_get_from_db(int event_id, calendar_event_h *event)
{
CALENDAR_NULL_ARG_CHECK(event);
@@ -228,6 +183,18 @@ int calendar_event_get_db_id(calendar_event_h event, int *db_id)
return CALENDAR_ERROR_NONE;
}
+int calendar_event_get_calendar_db_id(calendar_event_h event, int *calendar_db_id)
+{
+ CALENDAR_NULL_ARG_CHECK(event);
+ CALENDAR_NULL_ARG_CHECK(calendar_db_id);
+
+ *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy,
+ (char*)CAL_VALUE_INT_CALENDAR_ID);
+ if(*calendar_db_id < 0)
+ *calendar_db_id = 0;
+ return CALENDAR_ERROR_NONE;
+}
+
int calendar_event_get_total_count_from_db(int *count)
{
CALENDAR_NULL_ARG_CHECK(count);
@@ -1016,36 +983,56 @@ int calendar_attendee_iterator_next(calendar_attendee_iterator_h *iterator, cale
return CALENDAR_ERROR_ITERATOR_END;
}
-int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, const char *subject_to_find, void* user_data)
+//Provide iterator instead of event
+int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data)
+{
+ CALENDAR_NULL_ARG_CHECK(callback);
+ return _calendar_event_foreach(callback, ALL_ACCOUNT_ID, ALL_CALENDAR_ID, user_data);
+}
+
+int calendar_query_event_by_calendar(calendar_foreach_query_event_cb callback, int calendar_db_id, void *user_data)
+{
+ CALENDAR_NULL_ARG_CHECK(callback);
+ CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1);
+ int account_db_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_db_id == -2);
+
+ return _calendar_event_foreach(callback, account_db_id, calendar_db_id, user_data);
+}
+
+int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *subject_to_find, void* user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
CALENDAR_NULL_ARG_CHECK(subject_to_find);
- return _calendar_query(callback, CAL_VALUE_TXT_SUMMARY, subject_to_find, user_data);
+ return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_SUMMARY, subject_to_find, user_data);
}
-int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, const char *description_to_find, void* user_data)
+int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *description_to_find, void* user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
CALENDAR_NULL_ARG_CHECK(description_to_find);
- return _calendar_query(callback, CAL_VALUE_TXT_DESCRIPTION, description_to_find, user_data);
+ return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_DESCRIPTION, description_to_find, user_data);
}
-int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, const char *location_to_find, void* user_data)
+int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *location_to_find, void* user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
CALENDAR_NULL_ARG_CHECK(location_to_find);
- return _calendar_query(callback, CAL_VALUE_TXT_LOCATION, location_to_find, user_data);
+ return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_LOCATION, location_to_find, user_data);
}
-int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, struct tm start_time, struct tm end_time, void* user_data)
+int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm start_time, struct tm end_time, void* user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
int ret_val = 0;
cal_iter* iter = NULL;
bool callback_return = true;
+
+ int account_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_id == -2);
//fetch from DB
- ret_val = calendar_svc_get_event_list_by_tm_period (0, 0, &start_time, &end_time, &iter);
+ ret_val = calendar_svc_get_event_list_by_tm_period (account_id, calendar_db_id, &start_time, &end_time, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
@@ -1153,16 +1140,19 @@ int calendar_event_set_visibility(calendar_event_h event, calendar_visibility_e
return CALENDAR_ERROR_NONE;
}
-int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, struct tm time, void *user_data)
+int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm time, void *user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
int ret_val = 0;
cal_iter* iter = NULL;
bool callback_return = true;
-
+
+ int account_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_id == -2);
+
//fetch from DB
time_t timestamp = mktime(&time);
- ret_val = calendar_svc_get_updated_event_list (0, timestamp, &iter);
+ ret_val = calendar_svc_get_updated_event_list (account_id, timestamp, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
@@ -1677,12 +1667,30 @@ int calendar_todo_get_db_id(calendar_todo_h todo, int *db_id)
return CALENDAR_ERROR_NONE;
}
-int calendar_todo_insert_to_db(calendar_todo_h todo, int *todo_id)
+int calendar_todo_get_calendar_db_id(calendar_todo_h todo, int *calendar_db_id)
{
- int ret_val = CALENDAR_ERROR_NONE;
+ CALENDAR_NULL_ARG_CHECK(todo);
+ CALENDAR_NULL_ARG_CHECK(calendar_db_id);
+ *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy,
+ (char*)CAL_VALUE_INT_CALENDAR_ID);
+ if(*calendar_db_id < 0)
+ *calendar_db_id = 0;
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_todo_insert_to_db(calendar_todo_h todo, int calendar_db_id, int *todo_id)
+{
CALENDAR_NULL_ARG_CHECK(todo);
CALENDAR_NULL_ARG_CHECK(todo_id);
+
+ int ret_val = CALENDAR_ERROR_NONE;
+
+ int account_db_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_db_id == -2);
+
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_CALENDAR_ID, calendar_db_id);
+ calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_ACCOUNT_ID, account_db_id);
ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)todo)->event_legacy);
if (ret_val < 0)
@@ -2069,13 +2077,138 @@ int calendar_todo_set_due_time(calendar_todo_h todo, struct tm due_time)
int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void *user_data)
{
CALENDAR_NULL_ARG_CHECK(callback);
+
+ return _calendar_todo_foreach(callback, ALL_ACCOUNT_ID, ALL_CALENDAR_ID, user_data);
+}
+
+int calendar_query_todo_by_calendar(calendar_foreach_query_todo_cb callback, int calendar_db_id, void *user_data)
+{
+ CALENDAR_NULL_ARG_CHECK(callback);
+ CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1);
+ int account_db_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_db_id == -2);
+
+ return _calendar_todo_foreach(callback, account_db_id, calendar_db_id, user_data);
+}
+
+int calendar_get_from_db(int calendar_db_id, calendar_h *calendar)
+{
+ CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1);
+ CALENDAR_NULL_ARG_CHECK(calendar);
+
+ *calendar = malloc(sizeof(calendar_event_s));
+ if (*calendar == NULL) {
+ LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY);
+ return CALENDAR_ERROR_OUT_OF_MEMORY;
+ }
+
+ memset(*calendar, 0, sizeof(calendar_event_s));
+ if(calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_db_id, NULL, (cal_struct**)&(*(calendar_event_s**)calendar)->event_legacy) != CAL_SUCCESS) {
+ free(*calendar);
+ *calendar = NULL;
+
+ LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
+ return CALENDAR_ERROR_DB_FAILED;
+ }
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_destroy(calendar_h calendar)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ int ret_val = CALENDAR_ERROR_NONE;
+
+ ret_val = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)calendar)->event_legacy);
+ if (ret_val != CAL_SUCCESS) {
+ LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER);
+ ret_val = CALENDAR_ERROR_INVALID_PARAMETER;
+ } else {
+ free(calendar);
+ ret_val = CALENDAR_ERROR_NONE;
+ }
+
+ return ret_val;
+}
+
+int calendar_get_db_id(calendar_h calendar, int *calendar_db_id)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(calendar_db_id);
+
+ *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, (char*)CAL_TABLE_INT_INDEX);
+ if(*calendar_db_id < 0)
+ *calendar_db_id = 0;
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_get_is_default(calendar_h calendar, bool *is_default)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(is_default);
+
+ if(calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_INDEX) == 1) {
+ *is_default = true;
+ }
+ else {
+ *is_default = false;
+ }
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_get_name(calendar_h calendar, char **calendar_name)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(calendar_name);
+
+ *calendar_name = NULL;
+ *calendar_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_NAME));
+
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_get_is_visibile(calendar_h calendar, bool *is_visible)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(is_visible);
+
+ *is_visible = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_VISIBILITY) == 1 ? true : false;
+
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_get_color(calendar_h calendar, unsigned char *red, unsigned char *green, unsigned char *blue)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(red);
+ CALENDAR_NULL_ARG_CHECK(green);
+ CALENDAR_NULL_ARG_CHECK(blue);
+
+ _calendar_parse_color(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_COLOR),
+ red, green, blue);
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_get_account_db_id(calendar_h calendar, int *account_db_id)
+{
+ CALENDAR_NULL_ARG_CHECK(calendar);
+ CALENDAR_NULL_ARG_CHECK(account_db_id);
+
+ *account_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_ACCOUNT_ID) == 1 ? true : false;
+
+ return CALENDAR_ERROR_NONE;
+}
+
+int calendar_foreach_calendar_from_db(calendar_foreach_query_calendar_cb callback, void *user_data)
+{
+ CALENDAR_NULL_ARG_CHECK(callback);
+
int ret_val = CALENDAR_ERROR_NONE;
cal_iter* iter = NULL;
bool callback_return = true;
//fetch from DB
- ret_val = calendar_svc_get_all(0, 0, CAL_STRUCT_TODO, &iter);
+ ret_val = calendar_svc_get_all(ALL_ACCOUNT_ID, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
@@ -2087,21 +2220,33 @@ int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void
return CALENDAR_ERROR_DB_FAILED;
} else {
while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
- calendar_event_s cal_event_from_db = {0,};
- if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
+ cal_struct *calendar_struct = NULL;
+ if(calendar_svc_iter_get_info(iter, &calendar_struct) != CAL_SUCCESS) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
}
- if(cal_event_from_db.event_legacy == NULL) {
+ if(calendar_struct == NULL) {
calendar_svc_iter_remove(&iter);
return CALENDAR_ERROR_NONE; // consider this as no data
- }
+ }
- //execute callback
- callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data);
+ calendar_query_calendar_s query_data;
- calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
+ query_data.calendar_db_id = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_INDEX);
+ query_data.calendar_name = _calendar_safe_strdup(calendar_svc_struct_get_str(calendar_struct, CAL_TABLE_TXT_NAME));
+ query_data.calendar_is_default = query_data.calendar_db_id == 1 ? true : false;
+ query_data.calendar_is_visible = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_VISIBILITY) == 1 ? true : false;
+ _calendar_parse_color(calendar_svc_struct_get_str(calendar_struct, CAL_TABLE_TXT_COLOR),
+ &query_data.calendar_color_red, &query_data.calendar_color_green, &query_data.calendar_color_blue);
+ query_data.account_db_id = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_ACCOUNT_ID);
+
+ //execute callback
+ callback_return = callback(&query_data, user_data);
+
+ _calendar_safe_free(query_data.calendar_name);
+
+ calendar_svc_struct_free(&calendar_struct);
if(callback_return == false) {
break;
@@ -2111,5 +2256,8 @@ int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void
return CALENDAR_ERROR_NONE;
}
- return CALENDAR_ERROR_NONE;
+ return CALENDAR_ERROR_NONE;
+
+
}
+
diff --git a/src/calendar_private.c b/src/calendar_private.c
index 362666e..239e2f2 100755
--- a/src/calendar_private.c
+++ b/src/calendar_private.c
@@ -55,14 +55,109 @@ GList* _calendar_glist_next_until_not_deleted(GList* list)
return glist;
}
-int _calendar_query(calendar_foreach_query_event_cb callback, char* option, const char* string_to_find, void* user_data)
+int _calendar_event_foreach(calendar_foreach_query_event_cb callback, int account_db_id, int calendar_db_id, void* user_data)
+{
+ int ret_val = CALENDAR_ERROR_NONE;
+ cal_iter* iter = NULL;
+ bool callback_return = true;
+
+ //fetch from DB
+ ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_SCHEDULE, &iter);
+
+ if (ret_val != CAL_SUCCESS) {
+ LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
+ return CALENDAR_ERROR_DB_FAILED;
+ }
+
+ if (iter == NULL) {
+ LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
+ return CALENDAR_ERROR_DB_FAILED;
+ } else {
+ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
+ calendar_event_s cal_event_from_db = {0,};
+ if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
+ calendar_svc_iter_remove(&iter);
+ return CALENDAR_ERROR_NONE; // consider this as no data
+ }
+
+ if(cal_event_from_db.event_legacy == NULL) {
+ calendar_svc_iter_remove(&iter);
+ return CALENDAR_ERROR_NONE; // consider this as no data
+ }
+
+ //execute callback
+ callback_return = callback((calendar_event_h)&cal_event_from_db, user_data);
+
+ calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
+
+ if(callback_return == false) {
+ break;
+ }
+ }
+ calendar_svc_iter_remove(&iter);
+
+ return CALENDAR_ERROR_NONE;
+ }
+ return CALENDAR_ERROR_NONE;
+}
+
+int _calendar_todo_foreach(calendar_foreach_query_todo_cb callback, int account_db_id, int calendar_db_id, void* user_data)
+{
+ int ret_val = CALENDAR_ERROR_NONE;
+ cal_iter* iter = NULL;
+ bool callback_return = true;
+
+ //fetch from DB
+ ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_TODO, &iter);
+
+ if (ret_val != CAL_SUCCESS) {
+ LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
+ return CALENDAR_ERROR_DB_FAILED;
+ }
+
+ if (iter == NULL) {
+ LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
+ return CALENDAR_ERROR_DB_FAILED;
+ } else {
+ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
+ calendar_event_s cal_event_from_db = {0,};
+ if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) {
+ calendar_svc_iter_remove(&iter);
+ return CALENDAR_ERROR_NONE; // consider this as no data
+ }
+
+ if(cal_event_from_db.event_legacy == NULL) {
+ calendar_svc_iter_remove(&iter);
+ return CALENDAR_ERROR_NONE; // consider this as no data
+ }
+
+ //execute callback
+ callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data);
+
+ calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy);
+
+ if(callback_return == false) {
+ break;
+ }
+ }
+ calendar_svc_iter_remove(&iter);
+
+ return CALENDAR_ERROR_NONE;
+ }
+ return CALENDAR_ERROR_NONE;
+}
+
+int _calendar_event_query(calendar_foreach_query_event_cb callback, int calendar_db_id, char* option, const char* string_to_find, void* user_data)
{
int ret_val = 0;
cal_iter* iter = NULL;
bool callback_return = true;
+
+ int account_id = _calendar_get_account_db_id(calendar_db_id);
+ CONTACTS_INVALID_ARG_CHECK(account_id == -2);
//fetch from DB
- ret_val = calendar_svc_find_event_list(0, option, string_to_find, &iter);
+ ret_val = calendar_svc_find_event_list(account_id, option, string_to_find, &iter);
if (ret_val != CAL_SUCCESS) {
LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED);
@@ -101,4 +196,56 @@ int _calendar_query(calendar_foreach_query_event_cb callback, char* option, cons
return CALENDAR_ERROR_NONE;
}
+int _calendar_get_account_db_id(int calendar_db_id)
+{
+ int ret = -2;
+ if(calendar_svc_connect() != CAL_SUCCESS) {
+ return -2;
+ }
+
+ cal_struct* calendar = NULL;
+ if(calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_db_id, NULL, &calendar) != CAL_SUCCESS) {
+ calendar_svc_close();
+ calendar_svc_struct_free(&calendar);
+ return -2;
+ }
+
+ if((ret = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID)) < -1) {
+ ret = -2; // get account ID fail;
+ }
+ calendar_svc_struct_free(&calendar);
+ calendar_svc_close();
+ return ret;
+}
+
+void _calendar_parse_color(char* color_string, unsigned char* red, unsigned char* green, unsigned char* blue)
+{
+ *red = 0;
+ *green = 0;
+ *blue = 0;
+
+ if(color_string == NULL) {
+ return;
+ }
+ char* token = NULL;
+ char* temp = NULL;
+ // 0.0.0.0
+ if(strlen(color_string) < 7) {
+ return;
+ }
+ token = strtok_r(color_string, ".", &temp);
+ if(token) {
+ *red = atoi(token);
+ }
+
+ token = strtok_r(NULL, ".", &temp);
+ if(token) {
+ *green = atoi(token);
+ }
+
+ token = strtok_r(NULL, ".", &temp);
+ if(token) {
+ *blue = atoi(token);
+ }
+}