/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include "calendar_private.h" #include "calendar_types.h" #include "calendar.h" #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_CALENDAR" #define LOG_MODE (1) #ifndef CALS_TODO_NO_DUE_DATE #define CALS_TODO_NO_DUE_DATE INT64_MAX #endif /* * Public Implementation */ int calendar_connect(void) { if (calendar_svc_connect() != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_disconnect(void) { if (calendar_svc_close() != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_begin_transaction(void) { if (calendar_svc_begin_trans()!= CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_rollback_transaction(void) { if (calendar_svc_end_trans(false)!= CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_commit_transaction(void) { if (calendar_svc_end_trans(true)!= CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_book_delete_from_db(int calendar_db_id) { int ret; ret = calendar_svc_delete(CAL_STRUCT_CALENDAR, calendar_db_id); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_delete_all_by_account(int account_db_id) { int ret; ret = calendar_svc_delete(CAL_STRUCT_SCHEDULE, account_db_id); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_event_insert_to_db(calendar_event_h event, int calendar_db_id, int *event_id) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(event_id); int ret; int account_db_id; cal_struct *cs; account_db_id = _calendar_get_account_db_id(calendar_db_id); CALENDAR_INVALID_ARG_CHECK(account_db_id == -2); cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if (cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_ID, calendar_db_id); calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ACCOUNT_ID, account_db_id); ret = calendar_svc_insert(cs); if (ret < 0) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } *event_id = ret; return CALENDAR_ERROR_NONE; } int calendar_event_delete_from_db(int event_id) { CALENDAR_INVALID_ARG_CHECK(event_id <= 0); int ret; ret = calendar_svc_delete(CAL_STRUCT_SCHEDULE, event_id); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_event_update_to_db(calendar_event_h event) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_update(cs); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_event_get_from_db(int event_id, calendar_event_h *event) { CALENDAR_NULL_ARG_CHECK(event); int ret; calendar_event_s *ce; ce = calloc(1, sizeof(calendar_event_s)); if (ce == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } LOGD("event_id = %d", event_id); ret = calendar_svc_get(CAL_STRUCT_SCHEDULE, event_id, NULL, (cal_struct **)&(ce->event_legacy)); if(ret != CAL_SUCCESS) { free(*event); *event = NULL; LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } *event = (calendar_event_h)ce; return CALENDAR_ERROR_NONE; } int calendar_event_get_db_id(calendar_event_h event, int *db_id) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(db_id); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *db_id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_INDEX); if(*db_id < 0) *db_id = 0; return CALENDAR_ERROR_NONE; } int calendar_event_get_calendar_book_db_id(calendar_event_h event, int *calendar_book_db_id) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(calendar_book_db_id); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *calendar_book_db_id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_CALENDAR_ID); if(*calendar_book_db_id < 0) *calendar_book_db_id = 0; return CALENDAR_ERROR_NONE; } int calendar_event_get_status(calendar_event_h event, calendar_event_status_e *status) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(status); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *status = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_MEETING_STATUS); if (*status < 0) { *status = 0; } return CALENDAR_ERROR_NONE; } int calendar_event_set_status(calendar_event_h event, calendar_event_status_e status) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CAL_VALUE_INT_MEETING_STATUS, status); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_priority(calendar_event_h event, calendar_event_priority_e *priority) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(priority); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; *priority = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_PRIORITY); return CALENDAR_ERROR_NONE; } int calendar_event_set_priority(calendar_event_h event, calendar_event_priority_e priority) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PRIORITY, priority); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_busy_status(calendar_event_h event, calendar_event_busy_status_e *busy_status) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(busy_status); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; *busy_status = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_BUSY_STATUS); return CALENDAR_ERROR_NONE; } int calendar_event_set_busy_status(calendar_event_h event, calendar_event_busy_status_e busy_status) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CAL_VALUE_INT_BUSY_STATUS, busy_status); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } // TOREM int calendar_event_get_total_count_from_db(int calendar_book_db_id, int *count) { CALENDAR_NULL_ARG_CHECK(count); int cnt; int account_db_id; account_db_id = _calendar_get_account_db_id(calendar_book_db_id); CALENDAR_INVALID_ARG_CHECK(account_db_id == -2); cnt = calendar_svc_get_count(account_db_id, calendar_book_db_id, CAL_STRUCT_SCHEDULE); if(cnt == CAL_ERR_FAIL) { *count = 0; LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } *count = cnt; return CALENDAR_ERROR_NONE; } int calendar_event_get_reminder_sound_file_path(calendar_event_h event, char **sound_file_path) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(sound_file_path); cal_struct *cs; GList *alarm_list; int ret; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_get_list(cs, CAL_VALUE_LST_ALARM, &alarm_list); if (ret < CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } if (!alarm_list || !alarm_list->data) { *sound_file_path = NULL; return CALENDAR_ERROR_NONE; } *sound_file_path = _calendar_safe_strdup( calendar_svc_value_get_str(alarm_list->data, CAL_VALUE_TXT_ALARMS_TONE)); return CALENDAR_ERROR_NONE; } int calendar_event_set_reminder_sound_file_path(calendar_event_h event, const char *sound_file_path) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; GList *alarm_list = NULL; cal_value *value; GList* list = NULL; int svc_reminder_interval_type; int reminder_interval; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_get_list(cs, CAL_VALUE_LST_ALARM, &alarm_list); if (ret < CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } if (alarm_list) { if (!alarm_list->data) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } value = (cal_value *)alarm_list->data; svc_reminder_interval_type = calendar_svc_value_get_int(value, CAL_VALUE_INT_ALARMS_TICK_UNIT); reminder_interval = calendar_svc_value_get_int(value, CAL_VALUE_INT_ALARMS_TICK); calendar_svc_struct_free(&value); alarm_list = NULL; } value = calendar_svc_value_new(CAL_VALUE_LST_ALARM); if (value == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARMS_TICK_UNIT, svc_reminder_interval_type); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARMS_TICK, reminder_interval); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_value_set_str(value, CAL_VALUE_TXT_ALARMS_TONE, sound_file_path); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } calendar_svc_struct_store_list(cs, CAL_VALUE_LST_ALARM, NULL); list = g_list_append(list, value); ret = calendar_svc_struct_store_list(cs, CAL_VALUE_LST_ALARM, list); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); g_list_free(list); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_byday(calendar_event_h event, char **byday) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(byday); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *byday = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CALS_VALUE_TXT_RRULE_BYDAY)); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_byday(calendar_event_h event, const char* byday) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, byday); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_bysetpos(calendar_event_h event, char **bysetpos) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(bysetpos); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *bysetpos = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS)); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_bysetpos(calendar_event_h event, const char* bysetpos) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS, bysetpos); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_bymonthday(calendar_event_h event, char **bymonthday) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(bymonthday); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *bymonthday = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY)); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_bymonthday(calendar_event_h event, const char* bymonthday) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, bymonthday); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_bymonth(calendar_event_h event, char **bymonth) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(bymonth); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *bymonth = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH)); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_bymonth(calendar_event_h event, const char* bymonth) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, bymonth); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_week_start(calendar_event_h event, calendar_week_flag_e *week_start) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(week_start); int wkst; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } wkst = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_WKST); switch (wkst) { case CALS_SUNDAY: *week_start = CALENDAR_WEEK_FLAG_SUN; break; case CALS_MONDAY: *week_start = CALENDAR_WEEK_FLAG_MON; break; case CALS_TUESDAY: *week_start = CALENDAR_WEEK_FLAG_TUE; break; case CALS_WEDNESDAY: *week_start = CALENDAR_WEEK_FLAG_WED; break; case CALS_THURSDAY: *week_start = CALENDAR_WEEK_FLAG_THU; break; case CALS_FRIDAY: *week_start = CALENDAR_WEEK_FLAG_FRI; break; case CALS_SATURDAY: *week_start = CALENDAR_WEEK_FLAG_SAT; break; default: *week_start = CALENDAR_WEEK_FLAG_SUN; break; } return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_week_start(calendar_event_h event, calendar_week_flag_e week_start) { CALENDAR_NULL_ARG_CHECK(event); int ret = CALENDAR_ERROR_NONE; int wkst; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } switch (week_start) { case CALENDAR_WEEK_FLAG_SUN: wkst = CALS_SUNDAY; break; case CALENDAR_WEEK_FLAG_MON: wkst = CALS_MONDAY; break; case CALENDAR_WEEK_FLAG_TUE: wkst = CALS_TUESDAY; break; case CALENDAR_WEEK_FLAG_WED: wkst = CALS_WEDNESDAY; break; case CALENDAR_WEEK_FLAG_THU: wkst = CALS_THURSDAY; break; case CALENDAR_WEEK_FLAG_FRI: wkst = CALS_FRIDAY; break; case CALENDAR_WEEK_FLAG_SAT: wkst = CALS_SATURDAY; break; default: wkst = CALS_SUNDAY; break; } ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_WKST, wkst); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_delete_recurrence_instance_from_db(int event_db_id, long long int start_time) { int ret; if (event_db_id < 0) { LOGE("Invalid argument: event_db_id is NULL"); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_event_delete_normal_instance(event_db_id, start_time); if (ret != CAL_SUCCESS) { LOGE("Failed to delete normal instance"); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_event_delete_recurrence_all_day_instance_from_db(int event_db_id, int year, int month, int day) { int ret; if (event_db_id < 0) { LOGE("Invalid argument: event_db_id is NULL"); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_event_delete_allday_instance(event_db_id, year, month, day); if (ret != CAL_SUCCESS) { LOGE("Failed to delete normal instance"); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_exdate(calendar_event_h event, char** exdate) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(exdate); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if (cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *exdate = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_EXDATE)); return CALENDAR_ERROR_NONE; } int calendar_event_get_uid(calendar_event_h event, char **uid) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(uid); char *_uid; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } _uid = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_UID)); if (_uid == NULL || strlen(_uid) < 1) { *uid = NULL; } else { *uid = _uid; } return CALENDAR_ERROR_NONE; } int calendar_event_set_uid(calendar_event_h event, const char *uid) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_UID, uid); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_interval(calendar_event_h event, int *recurrence_interval) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(recurrence_interval); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *recurrence_interval = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_INTERVAL); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_interval(calendar_event_h event, int recurrence_interval) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_INTERVAL, recurrence_interval); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_count(calendar_event_h event, int *recurrence_count) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(recurrence_count); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *recurrence_count = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_COUNT); return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_count(calendar_event_h event, int recurrence_count) { CALENDAR_NULL_ARG_CHECK(event); int ret; int type; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } type = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTSTART_TYPE); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, type); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_COUNT); ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_COUNT, recurrence_count); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_status(calendar_attendee_h attendee, calendar_attendee_status_e *status) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(status); *status = calendar_svc_value_get_int( (cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS); if(*status < 0 || *status > CALENDAR_ATTENDEE_STATUS_MAX) { *status = -1; return CALENDAR_ERROR_NO_DATA; } return CALENDAR_ERROR_NONE; } int calendar_attendee_set_status(calendar_attendee_h attendee, calendar_attendee_status_e status) { CALENDAR_NULL_ARG_CHECK(attendee); int ret; ret = calendar_svc_value_set_int( (cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, status); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_role(calendar_attendee_h attendee, calendar_attendee_role_e *role) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(role); *role = calendar_svc_value_get_int( (cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_ROLE); if(*role < 0 || *role > CALENDAR_ATTENDEE_ROLE_MAX) { *role = -1; return CALENDAR_ERROR_NO_DATA; } return CALENDAR_ERROR_NONE; } int calendar_attendee_set_role(calendar_attendee_h attendee, calendar_attendee_role_e role) { CALENDAR_NULL_ARG_CHECK(attendee); int ret; ret = calendar_svc_value_set_int( (cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_ROLE, role); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_create (calendar_event_h *event) { CALENDAR_NULL_ARG_CHECK(event); *event = calloc(1, sizeof(calendar_event_s)); if (*event == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } (*(calendar_event_s**)event)->event_legacy = (calendar_event_legacy_s*)calendar_svc_struct_new(CAL_STRUCT_SCHEDULE); if ((*(calendar_event_s**)event)->event_legacy == NULL) { free(*event); *event = NULL; LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } return CALENDAR_ERROR_NONE; } int calendar_event_destroy(calendar_event_h event) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_free(&cs); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } free(event); return CALENDAR_ERROR_NONE; } int calendar_event_get_subject(calendar_event_h event, char **subject) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(subject); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *subject = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY)); return CALENDAR_ERROR_NONE; } int calendar_event_set_subject(calendar_event_h event,const char *subject) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, subject); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_categories(calendar_event_h event, char **categories) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(categories); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *categories = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_CATEGORIES)); return CALENDAR_ERROR_NONE; } int calendar_event_set_categories(calendar_event_h event,const char *categories) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_CATEGORIES, categories); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_description(calendar_event_h event,char **description) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(description); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *description = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION)); return CALENDAR_ERROR_NONE; } int calendar_event_set_description(calendar_event_h event, const char *description) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_DESCRIPTION, description); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_is_all_day_event(calendar_event_h event, bool *is_all_day_event) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(is_all_day_event); cal_struct *cs; bool all_day; int type; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } type = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTSTART_TYPE); if (type == CALS_TIME_LOCALTIME) all_day = true; else all_day = false; *is_all_day_event = all_day; return CALENDAR_ERROR_NONE; } int calendar_event_set_all_day_event(calendar_event_h event, int start_year, int start_month, int start_day, int end_year, int end_month, int end_day) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_LOCALTIME); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_YEAR, start_year); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MONTH, start_month); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MDAY, start_day); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_LOCALTIME); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_YEAR, end_year); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MONTH, end_month); ret |= calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MDAY, end_day); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_all_day_event(calendar_event_h event, int *start_year, int *start_month, int *start_day, int *end_year, int *end_month, int *end_day) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(start_year); CALENDAR_NULL_ARG_CHECK(start_month); CALENDAR_NULL_ARG_CHECK(start_day); CALENDAR_NULL_ARG_CHECK(end_year); CALENDAR_NULL_ARG_CHECK(end_month); CALENDAR_NULL_ARG_CHECK(end_day); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *start_year = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTSTART_YEAR); *start_month = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTSTART_MONTH); *start_day = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTSTART_MDAY); *end_year = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTEND_YEAR); *end_month = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTEND_MONTH); *end_day = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_DTEND_MDAY); return CALENDAR_ERROR_NONE; } int calendar_event_get_location(calendar_event_h event, char **location) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(location); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *location = _calendar_safe_strdup( calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_LOCATION) ); return CALENDAR_ERROR_NONE; } int calendar_event_set_location(calendar_event_h event, const char *location) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(location); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_LOCATION, location); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int _get_svc_reminder_interval_type(calendar_reminder_interval_type_e reminder_interval_type) { switch (reminder_interval_type) { case CALENDAR_REMINDER_NONE: return CAL_SCH_TIME_UNIT_OFF; case CALENDAR_REMINDER_TIME_UNIT_MINUTE: return CAL_SCH_TIME_UNIT_MIN; case CALENDAR_REMINDER_TIME_UNIT_HOUR: return CAL_SCH_TIME_UNIT_HOUR; case CALENDAR_REMINDER_TIME_UNIT_DAY: return CAL_SCH_TIME_UNIT_DAY; case CALENDAR_REMINDER_TIME_UNIT_WEEK: return CAL_SCH_TIME_UNIT_WEEK; case CALENDAR_REMINDER_TIME_UNIT_MONTH: return CAL_SCH_TIME_UNIT_MONTH; } return CAL_SCH_TIME_UNIT_OFF; } calendar_reminder_interval_type_e _set_svc_reminder_interval_type(int svc_reminder_interval_type) { switch (svc_reminder_interval_type) { case CAL_SCH_TIME_UNIT_OFF: return CALENDAR_REMINDER_NONE; case CAL_SCH_TIME_UNIT_MIN: return CALENDAR_REMINDER_TIME_UNIT_MINUTE; case CAL_SCH_TIME_UNIT_HOUR: return CALENDAR_REMINDER_TIME_UNIT_HOUR; case CAL_SCH_TIME_UNIT_DAY: return CALENDAR_REMINDER_TIME_UNIT_DAY; case CAL_SCH_TIME_UNIT_WEEK: return CALENDAR_REMINDER_TIME_UNIT_WEEK; case CAL_SCH_TIME_UNIT_MONTH: return CALENDAR_REMINDER_TIME_UNIT_MONTH; } return CALENDAR_REMINDER_NONE; } int calendar_event_get_reminder(calendar_event_h event,calendar_reminder_interval_type_e *reminder_interval_type, int *reminder_interval) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(reminder_interval_type); CALENDAR_NULL_ARG_CHECK(reminder_interval); GList *alarm_list; int r; int svc_reminder_interval_type; r = calendar_svc_struct_get_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_ALARM, &alarm_list); if (r < CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } if (!alarm_list || !alarm_list->data) { *reminder_interval_type = CALENDAR_REMINDER_NONE; *reminder_interval = 0; return CALENDAR_ERROR_NONE; } svc_reminder_interval_type = calendar_svc_value_get_int(alarm_list->data, CAL_VALUE_INT_ALARMS_TICK_UNIT); *reminder_interval_type = _set_svc_reminder_interval_type(svc_reminder_interval_type); *reminder_interval = calendar_svc_value_get_int(alarm_list->data, CAL_VALUE_INT_ALARMS_TICK); return CALENDAR_ERROR_NONE; } int calendar_event_set_reminder(calendar_event_h event,calendar_reminder_interval_type_e reminder_interval_type, int reminder_interval) { CALENDAR_NULL_ARG_CHECK(event); int ret; int svc_reminder_interval_type; cal_struct *cs; cal_value *value; GList* list = NULL; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } value = calendar_svc_value_new(CAL_VALUE_LST_ALARM); if (value == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } svc_reminder_interval_type = _get_svc_reminder_interval_type(reminder_interval_type); ret = calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARMS_TICK_UNIT, svc_reminder_interval_type); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARMS_TICK, reminder_interval); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } calendar_svc_struct_store_list(cs, CAL_VALUE_LST_ALARM, NULL); list = g_list_append(list, value); ret = calendar_svc_struct_store_list(cs, CAL_VALUE_LST_ALARM, list); if (ret != CAL_SUCCESS) { calendar_svc_value_free(&value); g_list_free(list); LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_frequency(calendar_event_h event,calendar_recurrence_frequency_e *recurrence_frequency) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(recurrence_frequency); int freq; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } freq = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_FREQ); switch (freq) { case CALS_FREQ_ONCE: *recurrence_frequency = CALENDAR_RECURRENCE_NONE; break; case CALS_FREQ_YEARLY: *recurrence_frequency = CALENDAR_RECURRENCE_YEARLY; break; case CALS_FREQ_MONTHLY: *recurrence_frequency = CALENDAR_RECURRENCE_MONTHLY; break; case CALS_FREQ_WEEKLY: *recurrence_frequency = CALENDAR_RECURRENCE_WEEKLY; break; case CALS_FREQ_DAILY: *recurrence_frequency = CALENDAR_RECURRENCE_DAILY; break; } return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_frequency(calendar_event_h event,calendar_recurrence_frequency_e recurrence_frequency) { CALENDAR_NULL_ARG_CHECK(event); int ret; int freq = CALS_FREQ_ONCE; cal_struct *cs; switch (recurrence_frequency) { case CALENDAR_RECURRENCE_NONE: freq = CALS_FREQ_ONCE; break; case CALENDAR_RECURRENCE_DAILY: freq = CALS_FREQ_DAILY; break; case CALENDAR_RECURRENCE_WEEKLY: freq = CALS_FREQ_WEEKLY; break; case CALENDAR_RECURRENCE_MONTHLY: freq = CALS_FREQ_MONTHLY; break; case CALENDAR_RECURRENCE_YEARLY: freq = CALS_FREQ_YEARLY; break; default: freq = CALS_FREQ_ONCE; break; } cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, freq); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_recurrence_until_date(calendar_event_h event, long long int *recurrence_until_date) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(recurrence_until_date); long long int lli; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_RRULE_UNTIL_UTIME); if (lli == CALS_TODO_NO_DUE_DATE) { return CALENDAR_ERROR_NO_DATA; } *recurrence_until_date = lli; return CALENDAR_ERROR_NONE; } int calendar_event_set_recurrence_until_date(calendar_event_h event, long long int recurrence_until_date) { CALENDAR_NULL_ARG_CHECK(event); int ret = CALENDAR_ERROR_NONE; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_UNTIL); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_UTIME); ret = calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_RRULE_UNTIL_UTIME, recurrence_until_date); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_start_time(calendar_event_h event, long long int *start_time) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(start_time); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *start_time = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME); return CALENDAR_ERROR_NONE; } int calendar_event_set_start_time(calendar_event_h event, long long int start_time) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_UTIME); ret = calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, start_time); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_end_time(calendar_event_h event, long long int *end_time) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(end_time); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *end_time = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTEND_UTIME); return CALENDAR_ERROR_NONE; } int calendar_event_set_end_time(calendar_event_h event, long long int end_time) { CALENDAR_NULL_ARG_CHECK(event); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, end_time); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_name(calendar_attendee_h attendee, char **name) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(name); *name = _calendar_safe_strdup(calendar_svc_value_get_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME)); return CALENDAR_ERROR_NONE; } int calendar_attendee_set_name(calendar_attendee_h attendee, const char *name) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(attendee); ret = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, name); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_email(calendar_attendee_h attendee, char **email) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(email); *email = _calendar_safe_strdup( calendar_svc_value_get_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL)); return CALENDAR_ERROR_NONE; } int calendar_attendee_set_email(calendar_attendee_h attendee, const char *email) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(email); ret = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, email); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_phone_number(calendar_attendee_h attendee, char **phone_number) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(phone_number); *phone_number = _calendar_safe_strdup(calendar_svc_value_get_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER)); return CALENDAR_ERROR_NONE; } int calendar_attendee_set_phone_number(calendar_attendee_h attendee, const char *phone_number) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(phone_number); ret = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER, phone_number); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_attendee_get_contact_db_id(calendar_attendee_h attendee, int *contact_db_id) { CALENDAR_NULL_ARG_CHECK(attendee); CALENDAR_NULL_ARG_CHECK(contact_db_id); *contact_db_id = -1; *contact_db_id = calendar_svc_value_get_int((cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX); if(*contact_db_id <= 0) *contact_db_id = -1; return CALENDAR_ERROR_NONE; } int calendar_attendee_set_contact_db_id(calendar_attendee_h attendee, int contact_db_id) { CALENDAR_NULL_ARG_CHECK(attendee); int ret; ret = calendar_svc_value_set_int((cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX, contact_db_id); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_add_attendee(calendar_event_h event, calendar_attendee_h* attendee) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(attendee); int ret = CALENDAR_ERROR_NONE; GList* attendee_list = NULL; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } *attendee = (calendar_attendee_h)calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST); if (*attendee == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } //get attendee list first calendar_svc_struct_get_list(cs, CAL_VALUE_LST_ATTENDEE_LIST, &attendee_list); attendee_list = g_list_append(attendee_list, *attendee); ret = calendar_svc_struct_store_list(cs, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list); return CALENDAR_ERROR_NONE; } int calendar_event_add_attendee_with_contact(calendar_event_h event, int contact_db_id, calendar_attendee_h* attendee) { int ret = CALENDAR_ERROR_NONE; contact_h contact = NULL; if(contact_get_from_db(contact_db_id, &contact) != CONTACTS_ERROR_NONE) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } if((ret = calendar_event_add_attendee(event, attendee)) != CALENDAR_ERROR_NONE) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } calendar_attendee_set_contact_db_id(*attendee, contact_db_id); contact_name_h name = NULL; if(contact_get_name(contact, &name) == CONTACTS_ERROR_NONE) { char *first_name = NULL; if(contact_name_get_detail(name, CONTACT_NAME_DETAIL_FIRST, &first_name) == CONTACTS_ERROR_NONE) { calendar_attendee_set_name(*attendee, first_name); } _calendar_safe_free(first_name); } contact_email_iterator_h email_iterator = NULL; if(contact_get_email_iterator(contact, &email_iterator) == CONTACTS_ERROR_NONE) { contact_email_h email = NULL; if(contact_email_iterator_next(&email_iterator, &email) == CONTACTS_ERROR_NONE) { char *email_address = NULL; if(contact_email_get_address(email, &email_address) == CONTACTS_ERROR_NONE) { calendar_attendee_set_email(*attendee, email_address); } _calendar_safe_free(email_address); } } contact_number_iterator_h number_iterator = NULL; if(contact_get_number_iterator(contact, &number_iterator) == CONTACTS_ERROR_NONE) { contact_number_h number = NULL; if(contact_number_iterator_next(&number_iterator, &number) == CONTACTS_ERROR_NONE) { char *number_string = NULL; if(contact_number_get_number(number, &number_string) == CONTACTS_ERROR_NONE) { calendar_attendee_set_phone_number(*attendee, number_string); } _calendar_safe_free(number_string); } } contact_destroy(contact); return CALENDAR_ERROR_NONE; } int calendar_event_remove_attendee(calendar_event_h event, calendar_attendee_h attendee) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(attendee); calendar_svc_value_set_int((cal_value*)attendee, CAL_VALUE_INT_DETAIL_DELETE, 1); return CALENDAR_ERROR_NONE; } int calendar_event_get_attendee_iterator(calendar_event_h event, calendar_attendee_iterator_h *iterator) { GList* attendee_list = NULL; CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(iterator); //get attendee list first calendar_svc_struct_get_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_ATTENDEE_LIST, &attendee_list); *iterator = (calendar_attendee_iterator_h)attendee_list; return CALENDAR_ERROR_NONE; } bool calendar_attendee_iterator_has_next(calendar_attendee_iterator_h iterator) { if(iterator == NULL) { return false; } GList* glist = (GList*)iterator; cal_value* value = (cal_value*)glist->data; if(value == NULL) { return false; } glist = _calendar_glist_next_until_not_deleted(glist); if(glist == NULL) { return false; } return true; } int calendar_attendee_iterator_next(calendar_attendee_iterator_h *iterator, calendar_attendee_h *attendee) { CALENDAR_NULL_ARG_CHECK(iterator); CALENDAR_NULL_ARG_CHECK(attendee); *attendee = NULL; GList* glist = (GList*)*iterator; glist = _calendar_glist_next_until_not_deleted(glist); if(glist != NULL) { *attendee = (calendar_attendee_h)(glist)->data; glist = g_list_next(glist); *iterator = (calendar_attendee_iterator_h)glist; return CALENDAR_ERROR_NONE; } *iterator = NULL; return CALENDAR_ERROR_ITERATOR_END; } int calendar_event_free_event_array(calendar_event_h *event_array) { int i; CALENDAR_NULL_ARG_CHECK(event_array); for (i = 0; event_array[i]; i++) { calendar_event_destroy(event_array[i]); } free(event_array); return CALENDAR_ERROR_NONE; } int calendar_event_free_modified_event_array(pcalendar_modified_event_s *modified_event_array) { CALENDAR_NULL_ARG_CHECK(modified_event_array); int i = 0; pcalendar_modified_event_s *p; p = modified_event_array; if (p) { while (p[i]) { free(p[i]); i++; } free(p); } return CALENDAR_ERROR_NONE; } void __free_event_data(gpointer data, gpointer user_data) { if (data) { calendar_event_h *event = (calendar_event_h *)data; if (event) free(event); } } static calendar_error_e _get_h_array_from_legacy_iter(const char fn[], cal_iter* iter, calendar_event_h **event_h_array, int *length) { int i; int is_error = 0; cal_struct *cs = NULL; calendar_event_s *ce; GList *cursor; GList *l = NULL; if (iter == NULL) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", fn, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { if(calendar_svc_iter_get_info(iter, &cs) != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", fn, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } ce = calloc(1, sizeof(calendar_event_s)); if (ce == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", fn, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; } ce->event_legacy = (calendar_event_legacy_s *)cs; l = g_list_append(l, ce); cs = NULL; } calendar_svc_iter_remove(&iter); if (is_error) { g_list_foreach(l, __free_event_data, NULL); g_list_free(l); return CALENDAR_ERROR_OUT_OF_MEMORY; } /* malloc array and fill data */ *length = g_list_length(l); /* plus 1 to fill null pointer*/ calendar_event_h *p = calloc(*length + 1, sizeof(calendar_event_h)); if (p == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", fn,CALENDAR_ERROR_OUT_OF_MEMORY); g_list_foreach(l, __free_event_data, NULL); g_list_free(l); return CALENDAR_ERROR_OUT_OF_MEMORY; } cursor = l; for (i = 0; cursor; i++) { p[i] = (calendar_event_h)cursor->data; cursor = g_list_next(cursor); } g_list_free(l); /* fill NULL pointer to indicate end of array */ p[i] = NULL; *event_h_array = p; return CALENDAR_ERROR_NONE; } static calendar_error_e _get_count_from_legacy_iter(const char fn[], cal_iter* iter, int *count) { int is_error = 0; cal_struct *cs = NULL; calendar_event_s *ce; GList *l = NULL; if (iter == NULL) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", fn, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { if(calendar_svc_iter_get_info(iter, &cs) != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", fn, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } ce = calloc(1, sizeof(calendar_event_s)); if (ce == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", fn, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; } ce->event_legacy = (calendar_event_legacy_s *)cs; l = g_list_append(l, ce); cs = NULL; } calendar_svc_iter_remove(&iter); if (is_error) { g_list_foreach(l, __free_event_data, NULL); g_list_free(l); return CALENDAR_ERROR_OUT_OF_MEMORY; } *count = g_list_length(l); g_list_free(l); return CALENDAR_ERROR_NONE; } int calendar_event_search_event_by_calendar_book(int calendar_book_db_id, calendar_event_h **event_array, int *length) { CALENDAR_NULL_ARG_CHECK(event_array); CALENDAR_NULL_ARG_CHECK(length); int ret; cal_iter *iter = NULL; ret = calendar_svc_get_all(0, calendar_book_db_id, CAL_STRUCT_SCHEDULE, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, event_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_event_search_extend_instance_by_period(int calendar_book_db_id, long long int period_start_time, long long int period_end_time, calendar_event_h **event_array, int *length) { CALENDAR_NULL_ARG_CHECK(event_array); CALENDAR_NULL_ARG_CHECK(length); cal_iter *iter = NULL; int ret = calendar_svc_event_get_normal_list_by_period(calendar_book_db_id, CALS_LIST_PERIOD_NORMAL_OSP, period_start_time, period_end_time, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, event_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_event_search_all_day_extend_instance_by_period(int calendar_book_db_id, int period_start_year, int period_start_month, int period_start_day, int period_end_year, int period_end_month, int period_end_day, calendar_event_h **event_array, int *length) { CALENDAR_NULL_ARG_CHECK(event_array); CALENDAR_NULL_ARG_CHECK(length); cal_iter *iter = NULL; int ret = calendar_svc_event_get_allday_list_by_period(calendar_book_db_id, CALS_LIST_PERIOD_ALLDAY_OSP, period_start_year, period_start_month, period_start_day, period_end_year, period_end_month, period_end_day, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, event_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_add_db_changed_cb(calendar_db_changed_cb callback, calendar_db_changed_cb_type_e type, void* user_data) { int ret; CALENDAR_NULL_ARG_CHECK(callback); switch(type) { case CALENDAR_DB_CHANGED_CB_TYPE_CALENDAR_BOOK: ret = calendar_svc_subscribe_db_change(CAL_STRUCT_CALENDAR, callback, user_data); break; case CALENDAR_DB_CHANGED_CB_TYPE_EVENT: ret = calendar_svc_subscribe_db_change(CAL_STRUCT_SCHEDULE, callback, user_data); break; case CALENDAR_DB_CHANGED_CB_TYPE_TODO: ret = calendar_svc_subscribe_db_change(CAL_STRUCT_TODO, callback, user_data); break; default: LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; break; } if(ret == CAL_SUCCESS) { return CALENDAR_ERROR_NONE; } LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } int calendar_remove_db_changed_cb(calendar_db_changed_cb callback, calendar_db_changed_cb_type_e type) { int ret; CALENDAR_NULL_ARG_CHECK(callback); switch(type) { case CALENDAR_DB_CHANGED_CB_TYPE_CALENDAR_BOOK: ret = calendar_svc_unsubscribe_db_change(CAL_STRUCT_CALENDAR, callback); break; case CALENDAR_DB_CHANGED_CB_TYPE_EVENT: ret = calendar_svc_unsubscribe_db_change(CAL_STRUCT_SCHEDULE, callback); break; case CALENDAR_DB_CHANGED_CB_TYPE_TODO: ret = calendar_svc_unsubscribe_db_change(CAL_STRUCT_TODO, callback); break; default: LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; break; } if(ret == CAL_SUCCESS) { return CALENDAR_ERROR_NONE; } LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } int calendar_get_db_version(int* calendar_db_version) { CALENDAR_NULL_ARG_CHECK(calendar_db_version); if (calendar_svc_begin_trans() != CAL_SUCCESS) { LOGE("%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } *calendar_db_version = calendar_svc_end_trans(true); return CALENDAR_ERROR_NONE; } int calendar_event_get_last_modified_time(calendar_event_h event, long long int *modified_time) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(modified_time); *modified_time = calendar_svc_struct_get_lli((cal_struct*)((calendar_event_s*)event)->event_legacy, CALS_VALUE_LLI_LASTMOD); return CALENDAR_ERROR_NONE; } int calendar_event_get_visibility(calendar_event_h event, calendar_visibility_e *visibility) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(visibility); *visibility = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_SENSITIVITY); return CALENDAR_ERROR_NONE; } int calendar_event_set_visibility(calendar_event_h event, calendar_visibility_e visibility) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(event); ret = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_SENSITIVITY, visibility); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_search_event_by_version(int calendar_book_db_id, int calendar_db_version, pcalendar_modified_event_s **modified_event_array, int *length) { CALENDAR_NULL_ARG_CHECK(modified_event_array); CALENDAR_NULL_ARG_CHECK(length); int i, ret; int is_error = 0; GList *l = NULL; GList *cursor; cal_iter *iter = NULL; cal_struct *cs = NULL; calendar_modified_event_s *cme; pcalendar_modified_event_s *p; *length = 0; ret = calendar_svc_event_get_changes(calendar_book_db_id, calendar_db_version, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALLENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } /* get event_db_id and append to glist */ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { if(calendar_svc_iter_get_info(iter, &cs) != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } cme = calloc(1, sizeof(calendar_modified_event_s)); if (cme == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } cme->modified_status = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_TYPE); cme->event_db_id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_ID); cme->calendar_db_version = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_VERSION); cme->calendar_book_db_id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_CALENDAR_ID); l = g_list_append(l, cme); calendar_svc_struct_free(&cs); } calendar_svc_iter_remove(&iter); if (is_error) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); g_list_free_full(l, free); return CALENDAR_ERROR_OUT_OF_MEMORY; } /* if there is no data */ if (l == NULL) { *length = 0; return CALENDAR_ERROR_NONE; } /* malloc array and fill data */ *length = g_list_length(l); /* plus 1 to fill null pointer*/ p = calloc(*length + 1, sizeof(pcalendar_modified_event_s)); if (p == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__,CALENDAR_ERROR_OUT_OF_MEMORY); g_list_free_full(l, free); return CALENDAR_ERROR_OUT_OF_MEMORY; } cursor = l; for (i = 0; cursor; i++) { p[i] = (calendar_modified_event_s*)(cursor->data); cursor = g_list_next(cursor); } /* free list after allocation */ g_list_free(l); /* fill NULL pointer to indicate end of array */ p[i] = NULL; *modified_event_array = p; return CALENDAR_ERROR_NONE; } int calendar_event_get_timezone(calendar_event_h event, char** timezone_name) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(timezone_name); *timezone_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CALS_VALUE_TXT_DTSTART_TZID)); return CALENDAR_ERROR_NONE; } int calendar_event_set_timezone(calendar_event_h event, const char* timezone_name) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(timezone_name); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CALS_VALUE_TXT_DTSTART_TZID, timezone_name); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_event_get_event_array_from_vcalendar(const char *vcalendar_stream, calendar_event_h **event_array, int *length) { CALENDAR_NULL_ARG_CHECK(event_array); CALENDAR_NULL_ARG_CHECK(vcalendar_stream); int i, ret; GList *schedules = NULL; GList *cursor; calendar_event_s *ces; calendar_event_h *ceh; ret = calendar_svc_read_schedules(vcalendar_stream, &schedules); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_READ_SCHEDULES(errno:%d)\n", __FUNCTION__, ret); return CALENDAR_ERROR_DB_FAILED; } if (schedules == NULL) { LOGW("[%s] CALENDAR_ERROR_NO_SCHEDULES", __FUNCTION__); *event_array = NULL; *length = 0; return CALENDAR_ERROR_NONE; } *length = g_list_length(schedules); ceh = calloc(*length + 1, sizeof(calendar_event_h)); if (ceh == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); g_list_free(schedules); return CALENDAR_ERROR_OUT_OF_MEMORY; } /* allocate list to array */ cursor = schedules; for (i = 0; cursor; i++) { ces = calloc(1, sizeof(calendar_event_s)); if (ces == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); break; } ceh[i] = (calendar_event_h)ces; ces->event_legacy = (calendar_event_legacy_s *)cursor->data; cursor = g_list_next(cursor); } g_list_free(schedules); ceh[i] = NULL; *event_array = ceh; return CALENDAR_ERROR_NONE; } int calendar_event_get_vcalendar_from_db(int *event_db_id_array, int length, char **vcalendar_stream) { CALENDAR_NULL_ARG_CHECK(event_db_id_array); CALENDAR_NULL_ARG_CHECK(vcalendar_stream); int i, ret; GList *schedules = NULL; cal_struct *cs = NULL; if (length < 1) { LOGD("[%s] EVENT_DB_LENGTH is 0", __FUNCTION__); return CALENDAR_ERROR_NONE; } for (i = 0; i < length; i++) { ret = calendar_svc_get(CAL_STRUCT_SCHEDULE, event_db_id_array[i], NULL, &cs); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_GET_EVENT(errno:%d)", __FUNCTION__, ret); break; } if (cs == NULL) { LOGE("[%s] CALENDAR_ERROR_GET_EVENT", __FUNCTION__); break; } schedules = g_list_append(schedules, cs); } ret = calendar_svc_write_schedules(schedules, vcalendar_stream); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_WRITE_SCHEDDULES", __FUNCTION__); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_todo_create(calendar_todo_h *todo) { CALENDAR_NULL_ARG_CHECK(todo); *todo = malloc(sizeof(calendar_event_s)); if (*todo == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } (*(calendar_event_s**)todo)->event_legacy = (calendar_event_legacy_s*)calendar_svc_struct_new(CAL_STRUCT_TODO); if ((*(calendar_event_s**)todo)->event_legacy == NULL) { free(*todo); *todo = NULL; LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } return CALENDAR_ERROR_NONE; } int calendar_todo_destroy(calendar_todo_h todo) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)todo)->event_legacy); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); ret = CALENDAR_ERROR_INVALID_PARAMETER; } else { free(todo); ret = CALENDAR_ERROR_NONE; } return ret; } int calendar_todo_get_db_id(calendar_todo_h todo, int *db_id) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(db_id); *db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, (char*)CAL_VALUE_INT_INDEX); if(*db_id < 0) { *db_id = 0; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_calendar_book_db_id(calendar_todo_h todo, int *calendar_db_id) { 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 = CALENDAR_ERROR_NONE; int account_db_id = _calendar_get_account_db_id(calendar_db_id); CALENDAR_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 = calendar_svc_insert((cal_struct*)((calendar_event_s*)todo)->event_legacy); if (ret < 0) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } *todo_id = ret; return CALENDAR_ERROR_NONE; } int calendar_todo_delete_from_db(int todo_id) { if(todo_id <= 0) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } int ret = CALENDAR_ERROR_NONE; ret = calendar_svc_delete(CAL_STRUCT_TODO, todo_id); if (ret == CAL_SUCCESS) { ret = CALENDAR_ERROR_NONE; } else { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); ret = CALENDAR_ERROR_DB_FAILED; } return ret; } int calendar_todo_update_to_db(calendar_todo_h todo) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); if((cal_struct*)((calendar_event_s*)todo)->event_legacy == NULL) { LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); return CALENDAR_ERROR_NO_DATA; } ret = calendar_svc_update((cal_struct*)((calendar_event_s*)todo)->event_legacy); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_from_db(int todo_id, calendar_todo_h *todo) { CALENDAR_NULL_ARG_CHECK(todo); *todo = malloc(sizeof(calendar_event_s)); if (*todo == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); return CALENDAR_ERROR_OUT_OF_MEMORY; } memset(*todo, 0, sizeof(calendar_event_s)); if(calendar_svc_get(CAL_STRUCT_TODO, todo_id, NULL, (cal_struct**)&(*(calendar_event_s**)todo)->event_legacy) != CAL_SUCCESS) { free(*todo); *todo = 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_todo_get_priority(calendar_todo_h todo, calendar_todo_priority_e *priority) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(priority); *priority = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_PRIORITY); return CALENDAR_ERROR_NONE; } int calendar_todo_set_priority(calendar_todo_h todo, calendar_todo_priority_e priority) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_PRIORITY, priority); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_status(calendar_todo_h todo, calendar_todo_status_e *status) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(status); *status = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_TASK_STATUS); return CALENDAR_ERROR_NONE; } int calendar_todo_set_status(calendar_todo_h todo, calendar_todo_status_e status) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_TASK_STATUS, status); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_visibility(calendar_todo_h todo, calendar_visibility_e *visibility) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(visibility); *visibility = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_SENSITIVITY); return CALENDAR_ERROR_NONE; } int calendar_todo_set_visibility(calendar_todo_h todo, calendar_visibility_e visibility) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_SENSITIVITY, visibility); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_subject(calendar_todo_h todo, char **subject) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(subject); *subject = NULL; *subject = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_SUMMARY)); return CALENDAR_ERROR_NONE; } int calendar_todo_set_subject(calendar_todo_h todo, const char *subject) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_SUMMARY, subject); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_categories(calendar_todo_h todo, char **categories) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(categories); *categories = NULL; *categories = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_CATEGORIES)); return CALENDAR_ERROR_NONE; } int calendar_todo_set_categories(calendar_todo_h todo, const char *categories) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_CATEGORIES, categories); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_description(calendar_todo_h todo, char **description) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(description); *description = _calendar_safe_strdup( calendar_svc_struct_get_str( (cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_DESCRIPTION) ); return CALENDAR_ERROR_NONE; } int calendar_todo_set_description(calendar_todo_h todo, const char *description) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_DESCRIPTION, description); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_location(calendar_todo_h todo, char **location) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(location); *location = _calendar_safe_strdup( calendar_svc_struct_get_str( (cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_LOCATION) ); return CALENDAR_ERROR_NONE; } int calendar_todo_set_location(calendar_todo_h todo, const char *location) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_LOCATION, location); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_last_modified_time(calendar_todo_h todo, long long int *modified_time) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(modified_time); *modified_time = calendar_svc_struct_get_lli((cal_struct*)((calendar_event_s*)todo)->event_legacy, CALS_VALUE_LLI_LASTMOD); return CALENDAR_ERROR_NONE; } int calendar_todo_get_timezone(calendar_todo_h todo, char** timezone_name) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(timezone_name); *timezone_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CALS_VALUE_TXT_DTSTART_TZID)); return CALENDAR_ERROR_NONE; } int calendar_todo_set_timezone(calendar_todo_h todo, const char* timezone_name) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(timezone_name); ret = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CALS_VALUE_TXT_DTSTART_TZID, timezone_name); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_start_time(calendar_todo_h todo, long long int *start_time) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(start_time); cal_struct *cs; long long int lli; cs = (cal_struct*)((calendar_event_s*)todo)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME); if (lli == CALS_TODO_NO_DUE_DATE) { return CALENDAR_ERROR_NO_DATA; } *start_time = lli; return CALENDAR_ERROR_NONE; } int calendar_todo_set_start_time(calendar_todo_h todo, long long int start_time) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_lli((cal_struct*)((calendar_event_s*)todo)->event_legacy, CALS_VALUE_LLI_DTSTART_UTIME, start_time); if(ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_due_time(calendar_todo_h todo, long long int *due_time) { CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(due_time); cal_struct *cs; long long int lli; cs = (cal_struct*)((calendar_event_s*)todo)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTEND_UTIME); if (lli == CALS_TODO_NO_DUE_DATE) { return CALENDAR_ERROR_NO_DATA; } *due_time = lli; return CALENDAR_ERROR_NONE; } int calendar_todo_set_due_time(calendar_todo_h todo, long long int due_time) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(todo); ret = calendar_svc_struct_set_lli((cal_struct*)((calendar_event_s*)todo)->event_legacy, CALS_VALUE_LLI_DTEND_UTIME, due_time); if(ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_get_total_count_from_db(int calendar_book_db_id, int todo_priority, int todo_status, int *count) { CALENDAR_NULL_ARG_CHECK(count); int ret; cal_iter *iter = NULL; *count = 0; ret = calendar_svc_todo_get_iter(calendar_book_db_id, todo_priority, todo_status, CALS_TODO_LIST_ORDER_END_DATE, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_count_from_legacy_iter(__FUNCTION__, iter, count)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_todo_get_total_count_by_duedate_range(int calendar_book_db_id, // TODO long long int start_duedate_range, long long int end_duedate_range, int todo_priority, int todo_status, int *count) { CALENDAR_NULL_ARG_CHECK(count); int ret; ret = calendar_svc_todo_get_count_by_period(calendar_book_db_id, start_duedate_range, end_duedate_range, todo_priority, todo_status, count); if (ret != CAL_SUCCESS) { LOGE("Failed to get count by period"); return CALENDAR_ERROR_DB_FAILED; } if (*count < 1) { LOGD("No data"); // return CALENDAR_ERROR_NO_DATA; check s1-7153 } return CALENDAR_ERROR_NONE; } int calendar_todo_free_todo_array(calendar_todo_h *todo_array) { int i; CALENDAR_NULL_ARG_CHECK(todo_array); for (i = 0; todo_array[i]; i++) { calendar_svc_struct_free(((cal_struct**)&((calendar_event_s*)(todo_array[i]))->event_legacy)); } free(todo_array); return CALENDAR_ERROR_NONE; } int calendar_todo_free_modified_todo_array(pcalendar_modified_todo_s *modified_todo_array) { CALENDAR_NULL_ARG_CHECK(modified_todo_array); int i = 0; pcalendar_modified_todo_s *p; p = modified_todo_array; if (p) { while (p[i]) { free(p[i]); i++; } free(p); } return CALENDAR_ERROR_NONE; } int calendar_todo_search_todo_by_calendar_book(int calendar_book_db_id, int todo_priority, int todo_status, calendar_todo_h **todo_array, int *length) { CALENDAR_NULL_ARG_CHECK(todo_array); CALENDAR_NULL_ARG_CHECK(length); int ret; cal_iter *iter = NULL; *todo_array = NULL; *length = 0; ret = calendar_svc_todo_get_iter(calendar_book_db_id, todo_priority, todo_status, CALS_TODO_LIST_ORDER_END_DATE, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, todo_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_todo_search_todo_by_duedate_range(int calendar_book_db_id, long long int start_duedate_range, long long int end_duedate_range, int todo_priority, int todo_status, calendar_todo_h **todo_array, int *length) { CALENDAR_NULL_ARG_CHECK(todo_array); CALENDAR_NULL_ARG_CHECK(length); int ret; cal_iter *iter = NULL; *todo_array = NULL; *length = 0; ret = calendar_svc_todo_get_list_by_period(calendar_book_db_id, start_duedate_range, end_duedate_range, todo_priority, todo_status, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALLENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, todo_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_todo_search_todo_by_version(int calendar_book_db_id, int calendar_db_version, pcalendar_modified_todo_s **modified_todo_array, int *length) { CALENDAR_NULL_ARG_CHECK(modified_todo_array); CALENDAR_NULL_ARG_CHECK(length); int i, ret; int is_error = 0; GList *l = NULL; GList *cursor; cal_iter *iter = NULL; cal_struct *cs = NULL; calendar_modified_todo_s *cmt; pcalendar_modified_todo_s *p; *length = 0; ret = calendar_svc_todo_get_changes(calendar_book_db_id, calendar_db_version, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALLENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } /* get event_db_id and append to glist */ while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { if(calendar_svc_iter_get_info(iter, &cs) != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } cmt = calloc(1, sizeof(calendar_modified_todo_s)); if (cmt == NULL) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); is_error = 1; break; } cmt->modified_status = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_TYPE); cmt->todo_db_id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_ID); cmt->calendar_db_version = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_VERSION); cmt->calendar_book_db_id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_CALENDAR_ID); l = g_list_append(l, cmt); calendar_svc_struct_free(&cs); } calendar_svc_iter_remove(&iter); if (is_error) { LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); g_list_free_full(l, free); return CALENDAR_ERROR_OUT_OF_MEMORY; } /* malloc array and fill data */ *length = g_list_length(l); /* plus 1 to set end of array as checking id -1 */ p = calloc(*length + 1, sizeof(pcalendar_modified_todo_s)); if (p == NULL) { g_list_free_full(l, free); return CALENDAR_ERROR_OUT_OF_MEMORY; } cursor = l; for (i = 0; cursor; i++) { p[i] = (pcalendar_modified_todo_s)(cursor->data); cursor = g_list_next(cursor); } /* free list after allocation */ g_list_free(l); /* fill NULL pointer to indicate end of array */ p[i] = NULL; *modified_todo_array = p; return CALENDAR_ERROR_NONE; } int calendar_book_get_from_db(int calendar_db_id, calendar_book_h *calendar) { CALENDAR_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_book_create(calendar_book_h *calendar) { 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)); (*(calendar_event_s**)calendar)->event_legacy = (calendar_event_legacy_s*)(calendar_svc_struct_new(CAL_STRUCT_CALENDAR)); return CALENDAR_ERROR_NONE; } int calendar_book_insert_to_db(calendar_book_h calendar, int *calendar_db_id) { CALENDAR_NULL_ARG_CHECK(calendar); int index = -1; index = calendar_svc_insert( (cal_struct*)((calendar_event_s*)calendar)->event_legacy ); *calendar_db_id = index; return CALENDAR_ERROR_NONE; } int calendar_book_update_to_db(calendar_book_h calendar) { CALENDAR_NULL_ARG_CHECK(calendar); int ret = CALENDAR_ERROR_NONE; if((cal_struct*)((calendar_event_s*)calendar)->event_legacy == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_update( (cal_struct*)((calendar_event_s*)calendar)->event_legacy ); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } return CALENDAR_ERROR_NONE; } // TOREM int calendar_book_set_is_default(calendar_book_h calendar, bool is_default) { CALENDAR_NULL_ARG_CHECK(calendar); /* is_default = calendar_svc_struct_get_int( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_VISIBILITY); */ return CALENDAR_ERROR_NONE; } int calendar_book_set_is_visible(calendar_book_h calendar, bool is_visible) { CALENDAR_NULL_ARG_CHECK(calendar); is_visible = calendar_svc_struct_get_int( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_VISIBILITY); return CALENDAR_ERROR_NONE; } int calendar_book_destroy(calendar_book_h calendar) { CALENDAR_NULL_ARG_CHECK(calendar); int ret = CALENDAR_ERROR_NONE; ret = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)calendar)->event_legacy); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); ret = CALENDAR_ERROR_INVALID_PARAMETER; } else { free(calendar); ret = CALENDAR_ERROR_NONE; } return ret; } int calendar_book_get_db_id(calendar_book_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_book_get_is_default(calendar_book_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_book_get_name(calendar_book_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_book_set_name(calendar_book_h calendar, const char *calnedar_name) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(calendar); ret = calendar_svc_struct_set_str( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_NAME, calnedar_name); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_book_get_is_visible(calendar_book_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_book_set_color(calendar_book_h calendar_book, unsigned char red, unsigned char green, unsigned char blue) { CALENDAR_NULL_ARG_CHECK(calendar_book); int ret; char buf[32] = {0, }; snprintf(buf, sizeof(buf), "%d.%d.%d.%d", (int)red, (int)green, (int)blue, 0); ret = calendar_svc_struct_set_str( (cal_struct*)((calendar_event_s*)calendar_book)->event_legacy, CAL_TABLE_TXT_COLOR, buf); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_book_unset_color(calendar_book_h calendar_book) { CALENDAR_NULL_ARG_CHECK(calendar_book); int ret; ret = calendar_svc_struct_set_str( (cal_struct*)((calendar_event_s*)calendar_book)->event_legacy, CAL_TABLE_TXT_COLOR, ""); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_book_get_color(calendar_book_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); char *color = NULL; color = calendar_svc_struct_get_str( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_COLOR); if (color == NULL || strlen(color) < 1) { *red = *green = *blue = 0; return CALENDAR_ERROR_NO_DATA; } _calendar_parse_color(color, red, green, blue); return CALENDAR_ERROR_NONE; } int calendar_book_get_account_db_id(calendar_book_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_book_set_account_db_id(calendar_book_h calendar, int account_db_id) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(calendar); ret = calendar_svc_struct_set_int( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_ACCOUNT_ID, account_db_id); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_book_get_type(calendar_book_h calendar, int *calendar_type) { CALENDAR_NULL_ARG_CHECK(calendar); CALENDAR_NULL_ARG_CHECK(calendar_type); *calendar_type = calendar_svc_struct_get_int( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_STORE_TYPE); return CALENDAR_ERROR_NONE; } int calendar_book_set_type(calendar_book_h calendar, int calendar_type) { int ret = CALENDAR_ERROR_NONE; CALENDAR_NULL_ARG_CHECK(calendar); ret = calendar_svc_struct_set_int( (cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_STORE_TYPE, calendar_type); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_book_free_calendar_book_array(calendar_book_h *calendar_book_array) // TODO { int i; calendar_book_h c; CALENDAR_NULL_ARG_CHECK(calendar_book_array); c = calendar_book_array[0]; for (i = 0; c ; c = calendar_book_array[++i] ) calendar_book_destroy(c); free(calendar_book_array); return CALENDAR_ERROR_NONE; } //int calendar_foreach_calendar_book_from_db(calendar_foreach_query_calendar_book_cb callback, void *user_data) //{ // CALENDAR_NULL_ARG_CHECK(callback); // // int ret = CALENDAR_ERROR_NONE; // cal_iter* iter = NULL; // bool callback_return = true; // // //fetch from DB // ret = calendar_svc_get_all(ALL_ACCOUNT_ID, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter); // // if (ret != 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) { // 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(calendar_struct == NULL) { // calendar_svc_iter_remove(&iter); // return CALENDAR_ERROR_NONE; // consider this as no data // } // // calendar_query_calendar_book_s query_data; // // 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; // } // } // calendar_svc_iter_remove(&iter); // // return CALENDAR_ERROR_NONE; // } // return CALENDAR_ERROR_NONE; //} int calendar_book_get_all_calendar_book(calendar_book_h **calendar_book_array, int *length) { CALENDAR_NULL_ARG_CHECK(calendar_book_array); CALENDAR_NULL_ARG_CHECK(length); int ret = CALENDAR_ERROR_NONE; cal_iter* iter = NULL; //fetch from DB ret = calendar_svc_get_all(ALL_ACCOUNT_ID, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, calendar_book_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_book_search_calendar_book_by_account(int account_db_id, calendar_book_h **calendar_book_array, int *length) { CALENDAR_NULL_ARG_CHECK(calendar_book_array); CALENDAR_NULL_ARG_CHECK(length); int ret = CALENDAR_ERROR_NONE; cal_iter* iter = NULL; //fetch from DB ret = calendar_svc_get_all(account_db_id, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter); if (CAL_SUCCESS != ret) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); return CALENDAR_ERROR_DB_FAILED; } if ((ret = _get_h_array_from_legacy_iter(__FUNCTION__, iter, calendar_book_array, length)) != CALENDAR_ERROR_NONE) return ret; return CALENDAR_ERROR_NONE; } int calendar_event_get_is_recurrence(calendar_event_h event, bool *is_recurrence) { CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(is_recurrence); int is_recur; is_recur = calendar_svc_struct_get_int( (cal_struct*)((calendar_event_s*)event)->event_legacy, CALS_VALUE_INT_RRULE_ID); *is_recurrence = is_recur > 0 ? 1 : 0; return CALENDAR_ERROR_NONE; } int calendar_event_get_all_day_recurrence_until_date(calendar_event_h event, int *until_year, int *until_month, int *until_day) { int y, m, d; CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(until_year); CALENDAR_NULL_ARG_CHECK(until_month); CALENDAR_NULL_ARG_CHECK(until_day); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } y = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_UNTIL_YEAR); m = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MONTH); d = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MDAY); if (y == 0 && m == 0 && d == 0) { return CALENDAR_ERROR_NO_DATA; } *until_year = y; *until_month = m; *until_day = d; return CALENDAR_ERROR_NONE; } int calendar_event_set_all_day_recurrence_until_date(calendar_event_h event, int until_year, int until_month, int until_day) { CALENDAR_NULL_ARG_CHECK(event); cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)event)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_UNTIL); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_LOCALTIME); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_YEAR, until_year); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MONTH, until_month); calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MDAY, until_day); return CALENDAR_ERROR_NONE; } int calendar_todo_unset_start_time(calendar_todo_h todo) { CALENDAR_NULL_ARG_CHECK(todo); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)todo)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, CALS_TODO_NO_DUE_DATE); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; } int calendar_todo_unset_due_time(calendar_todo_h todo) { CALENDAR_NULL_ARG_CHECK(todo); int ret; cal_struct *cs; cs = (cal_struct*)((calendar_event_s*)todo)->event_legacy; if(cs == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } ret = calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, CALS_TODO_NO_DUE_DATE); if (ret != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; } return CALENDAR_ERROR_NONE; }