From b0f45ecd95bed424d5e21c229f2363e6e8f758d7 Mon Sep 17 00:00:00 2001 From: Jonghoon Lim Date: Fri, 10 Feb 2012 15:35:29 +0900 Subject: [PATCH] capi-social-calendar_0.1.1-30 --- debian/changelog | 8 ++ include/calendar.h | 283 +++++++++++++++++++++++++++++++++++++---- include/calendar_private.h | 38 +++--- include/calendar_types.h | 67 +++++++++- src/calendar.c | 306 +++++++++++++++++++++++++++++++++------------ src/calendar_private.c | 151 +++++++++++++++++++++- 6 files changed, 722 insertions(+), 131 deletions(-) diff --git a/debian/changelog b/debian/changelog index 65088d1..1b32aaf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +capi-social-calendar (0.1.1-30) unstable; urgency=low + + * Multiple calendar feature added + * Git: api/calendar + * Tag: capi-social-calendar_0.1.1-30 + + -- Jonghoon Lim Fri, 10 Feb 2012 15:31:07 +0900 + capi-social-calendar (0.1.1-27) unstable; urgency=low * version updated diff --git a/include/calendar.h b/include/calendar.h index 4fb4841..cb12a45 100755 --- a/include/calendar.h +++ b/include/calendar.h @@ -158,8 +158,10 @@ int calendar_event_destroy(calendar_event_h event); /** * @brief Adds a calendar event to the calendar database. * - * @param[in] event The calendar event handle - * @param[out] event_db_id The event db ID associated with the calendar event \n + * @param[in] event The calendar event handle + * @param[in] calendar_db_id The calendar database ID to which the event insert. \n + * 1 means the default calendar on the device + * @param[out] event_db_id The event db ID associated with the calendar event \n * If the function fails, it is -1. * * @return 0 on success, otherwise a negative error value. @@ -172,7 +174,7 @@ int calendar_event_destroy(calendar_event_h event); * @see calendar_event_update_to_db() * @see calendar_event_delete_from_db() */ -int calendar_event_insert_to_db(calendar_event_h event, int *event_db_id); +int calendar_event_insert_to_db(calendar_event_h event, int calendar_db_id, int *event_db_id); /** * @brief Removes the calendar event from the calendar database. @@ -215,14 +217,14 @@ int calendar_event_update_to_db(calendar_event_h event); /** * @brief Gets the calendar event from the calendar database. - * @details This function gets the new calendar handle with the given event ID from the calendar database. \n + * @details This function gets the new calendar event handle with the given event database ID from the calendar database. \n * The new calendar event handle will be created. * * @remarks The created calendar event handle must be released with calendar_event_destroy() by you. * * * @param[in] event_id The event ID - * @param[out] event The calendar event handle associated with the event ID + * @param[out] event The calendar event handle associated with the event database ID * * @return 0 on success, otherwise a negative error value. * @retval #CALENDAR_ERROR_NONE Successful @@ -239,20 +241,34 @@ int calendar_event_get_from_db(int event_id, calendar_event_h *event); * @brief Gets the database ID associated with the given calendar event handle. * * @param[in] event The calendar event handle - * @param[out] event_db_id The event ID fetched from the calendar database (default : 0) \n + * @param[out] event_db_id The event database ID fetched from the calendar event handle (default : 0) \n * 0 means the event is not in calendar database. * * @return 0 on success, otherwise a negative error value. * @retval #CALENDAR_ERROR_NONE Successful * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter - * @pre This function requires an open connection to the calendar service by calendar_connect(). - * - * @see calendar_connect() + * * @see calendar_event_insert_to_db() + * @see calendar_event_delete_from_db() */ int calendar_event_get_db_id(calendar_event_h event, int *event_db_id); /** + * @brief Gets the calendar database ID associated with the given calendar event handle. + * + * @param[in] event The calendar event handle + * @param[out] calendar_db_id The calendar database ID fetched from the calendar event handle (default : 0) \n + * 0 means the event is not in calendar database. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_insert_to_db() + */ +int calendar_event_get_calendar_db_id(calendar_event_h event, int *calendar_db_id); + +/** * @brief Gets the subject of the event from the calendar event handle . * * @remarks @a subject must be released with free() by you. @@ -860,8 +876,7 @@ int calendar_event_get_from_vcalendar(const char *vcalendar_stream, calendar_eve int calendar_event_get_vcalendar_from_event(calendar_event_h event, char **vcalendar_stream); /** - * @brief Retrieves all calendar events by invoking the given callback function iteratively. - * + * @brief Retrieves all calendar events from all of calendars by invoking the given callback function iteratively. * * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -880,9 +895,36 @@ int calendar_event_get_vcalendar_from_event(calendar_event_h event, char **vcale int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data); /** + * @brief Retrieves all calendar events with the given calendar database ID. + * + * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @post This function invokes calendar_foreach_query_event_cb(). + * + * @see calendar_foreach_query_event_cb() + * @see calendar_foreach_event_from_db() + * @see calendar_query_event_by_description() + * @see calendar_query_event_by_location() + * @see calendar_query_event_by_period() + */ +int calendar_query_event_by_calendar(calendar_foreach_query_event_cb callback, int calendar_db_id, void *user_data); + +/** * @brief Retrieves all calendar events with the given subject. * * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device * @param[in] subject_to_find The description to filter * @param[in] user_data The user data to be passed to the callback function * @@ -898,17 +940,19 @@ int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, voi * @see calendar_event_get_subject() * @see calendar_event_set_subject() * @see calendar_foreach_query_event_cb() + * @see calendar_query_event_by_calendar() * @see calendar_query_event_by_description() * @see calendar_query_event_by_location() * @see calendar_query_event_by_period() */ -int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, const char *subject_to_find, void *user_data); +int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *subject_to_find, void *user_data); /** * @brief Retrieves all calendar events with the given description. * - * * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device * @param[in] description_to_find The description to filter * @param[in] user_data The user data to be passed to the callback function * @@ -923,17 +967,21 @@ int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, co * * @see calendar_event_get_description() * @see calendar_event_set_description() + * @see calendar_foreach_query_event_cb() + * @see calendar_query_event_by_calendar() * @see calendar_query_event_by_subject() * @see calendar_query_event_by_location() * @see calendar_query_event_by_period() * @see calendar_foreach_query_event_cb() */ -int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, const char *description_to_find, void *user_data); +int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *description_to_find, void *user_data); /** * @brief Retrieves all calendar events with the given location. * * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device * @param[in] location_to_find The location to filter * @param[in] user_data The user data to be passed to the callback function * @@ -948,17 +996,20 @@ int calendar_query_event_by_description(calendar_foreach_query_event_cb callback * * @see calendar_event_get_location() * @see calendar_event_set_location() + * @see calendar_foreach_query_event_cb() + * @see calendar_query_event_by_calendar() * @see calendar_query_event_by_subject() - * @see calendar_query_event_by_description() - * @see calendar_query_event_by_period() - * @see calendar_foreach_query_event_cb() + * @see calendar_query_event_by_description() + * @see calendar_query_event_by_period() */ -int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, const char *location_to_find, void *user_data); +int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *location_to_find, void *user_data); /** * @brief Retrieves all calendar events between the given start_time and end_time. * * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device * @param[in] start_time The start date * @param[in] end_time The end date * @param[in] user_data The user data to be passed to the callback function @@ -976,20 +1027,23 @@ int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, c * @see calendar_event_set_start_time() * @see calendar_event_get_end_time() * @see calendar_event_set_end_time() + * @see calendar_foreach_query_event_cb() + * @see calendar_query_event_by_calendar() * @see calendar_query_event_by_subject() * @see calendar_query_event_by_description() * @see calendar_query_event_by_location() * @see calendar_foreach_query_event_cb() * */ -int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, struct tm start_time, struct tm end_time, void *user_data); +int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm start_time, struct tm end_time, void *user_data); /** * @brief Retrieves all calendar events that have been modified since the given time. * @details This function will find all changed event since the given time * - * * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device * @param[in] time The time to find events which are changed since when * @param[in] user_data The user data to be passed to the callback function * @@ -1005,7 +1059,7 @@ int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, str * @see calendar_event_get_last_modified_time() * @see calendar_foreach_query_event_cb() */ -int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, struct tm time, void *user_data); +int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm time, void *user_data); /** * @} @@ -1053,6 +1107,8 @@ int calendar_todo_destroy(calendar_todo_h todo); * @brief Adds the given to-do item to the calendar database. * * @param[in] todo The calendar to-do handle + * @param[in] calendar_db_id The calendar database ID to which the event insert. \n + * 1 means the default calendar on the device * @param[out] todo_db_id The to-do ID to be assigned to the to-do item * * @return 0 on success, otherwise a negative error value. @@ -1064,7 +1120,7 @@ int calendar_todo_destroy(calendar_todo_h todo); * @see calendar_todo_update_to_db() * */ -int calendar_todo_insert_to_db(calendar_todo_h todo, int *todo_db_id); +int calendar_todo_insert_to_db(calendar_todo_h todo, int calendar_db_id, int *todo_db_id); /** * @brief Removes the to-do item from the calendar database. @@ -1104,7 +1160,7 @@ int calendar_todo_update_to_db(calendar_todo_h todo); /** * @brief Gets the to-do item handle associated with the given to-do DB ID. - * @details This function gets the new to-do handle with the given to-do ID from the calendar database. + * @details This function gets the new to-do handle with the given to-do database ID from the calendar database. * A new calendar to-do handle will be created. * * @remarks The new to-do handle must be released with calendar_todo_destroy() by you. @@ -1129,7 +1185,7 @@ int calendar_todo_get_from_db(int todo_id, calendar_todo_h *todo); * * @param[in] todo The calendar to-do handle * @param[out] todo_db_id The database ID of the to-do item (default : 0) \n - * 0 means the event is not in calendar database + * 0 means the to-do is not in calendar database * * @return 0 on success, otherwise a negative error value. * @retval #CALENDAR_ERROR_NONE Successful @@ -1141,6 +1197,21 @@ int calendar_todo_get_from_db(int todo_id, calendar_todo_h *todo); int calendar_todo_get_db_id(calendar_todo_h todo, int *todo_db_id); /** + * @brief Gets the calendar database ID associated with the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[out] calendar_db_id The calendar database ID fetched from the calendar to-do handle (default : 0) \n + * 0 means the to-do is not in calendar database. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_insert_to_db() + */ +int calendar_todo_get_calendar_db_id(calendar_todo_h todo, int *calendar_db_id); + +/** * @brief Gets the subject of the to-do from the calendar to-do handle. * * @remarks @a subject must be released with free() by you. @@ -1443,9 +1514,173 @@ int calendar_todo_set_due_time(calendar_todo_h todo, struct tm due_time); int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void *user_data); /** + * @brief Retrieves all to-do items with the given calendar database ID by invoking the given callback function iteratively. + * + * @param[in] callback The callback function to invoke + * @param[in] calendar_db_id The calendar database ID to filter \n + * 1 means the default calendar on the device + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @post This function invokes calendar_foreach_query_todo_cb(). + * + * @see calendar_foreach_query_todo_cb() + */ +int calendar_query_todo_by_calendar(calendar_foreach_query_todo_cb callback, int calendar_db_id, void *user_data); + +/** * @} */ +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_MULTIPLECALENDAR_MODULE + * @{ + */ + +/** + * @brief Gets the calendar from the calendar database. + * @details This function gets the new calendar handle with the given calendar database ID from the calendar database. \n + * The new calendar handle will be created. + * + * @remarks The created calendar handle must be released with calendar_destroy() by you. + * + * @param[in] calendar_db_id The calendar database ID + * @param[out] calendar The calendar handle associated with the calendar database ID + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @see calendar_destroy() + */ +int calendar_get_from_db(int calendar_db_id, calendar_h *calendar); + +/** + * @brief Destroys the calendar handle and releases all its resources. + * + * @param[out] calendar The calendar handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_get_from_db() + * + */ +int calendar_destroy(calendar_h calendar); + +/** + * @brief Gets the database ID associated with the given calendar handle. + * + * @param[in] calendar The calendar handle + * @param[out] calendar_db_id The calendar database ID fetched from the calendar handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_get_from_db() + */ +int calendar_get_db_id(calendar_h calendar, int *calendar_db_id); + +/** + * @brief Gets the status whether the calendar is default calendar is or not in the device. + * + * @param [in] calendar The calendar handle + * @param [out] is_default @c true if the calendar is the default calendar in the device @c false \n + * (default : @c false) + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int calendar_get_is_default(calendar_h calendar, bool *is_default); + +/** + * @brief Gets the name of the calendar from the calendar handle. + * + * @remarks @a calendar_name must be released with free() by you. + * + * @param [in] calendar The calendar handle + * @param [out] calendar_name The name of the calendar \n If the name does not exist, it is NULL + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int calendar_get_name(calendar_h calendar, char **calendar_name); + +/** + * @brief Gets the visible status of the calendar handle. + * + * @param [in] calendar The calendar handle + * @param [out] is_visible @c true if the calendar is visible in the device, otherwise @c false \n + * (default : @c false) + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int calendar_get_is_visibile(calendar_h calendar, bool *is_visible); + +/** + * @brief Gets the color of the calendar from the calendar handle. + * + * @param [in] calendar The calendar handle + * @param [out] red The calendar color which represents red among RGB + * @param [out] green The calendar color which represents green among RGB + * @param [out] blue The calendar color which represents blue among RGB + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int calendar_get_color(calendar_h calendar, unsigned char *red, unsigned char *green, unsigned char *blue); + +/** + * @brief Gets the account database ID associated with the given calendar handle. + * + * @param[in] calendar The calendar handle + * @param[out] account_db_id The account database ID(default : 0) \n + * 0 means the calendar is not related to any accounts. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + */ +int calendar_get_account_db_id(calendar_h calendar, int *account_db_id); + +/** + * @brief Retrieves all calendars by invoking the given callback function iteratively. + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @post This function invokes calendar_foreach_query_event_cb(). + * + * @see calendar_foreach_query_calendar_cb() + */ +int calendar_foreach_calendar_from_db(calendar_foreach_query_calendar_cb callback, void *user_data); + +/** + * @} + */ #ifdef __cplusplus } diff --git a/include/calendar_private.h b/include/calendar_private.h index 505671c..68c7967 100755 --- a/include/calendar_private.h +++ b/include/calendar_private.h @@ -20,7 +20,6 @@ #include #include -//@20110427-vincent: real API #include #ifdef __cplusplus @@ -120,29 +119,13 @@ typedef struct int is_deleted; }_cal_participant_info_t; - - - -/** - * @internal - * @brief Recurrence frequency between event occurrences. - */ -/* -typedef enum -{ - CALENDAR_RECURRENCE_NONE, // Occurs once - CALENDAR_RECURRENCE_DAILY, // Occurs every day - CALENDAR_RECURRENCE_WEEKLY, // Occurs same day every week - CALENDAR_RECURRENCE_MONTHLY, // Occurs same date every month, like 3rd day of month - CALENDAR_RECURRENCE_YEARLY, // Occurs same date every year like every June 1st - CALENDAR_RECURRENCE_WEEKDAY, // Occurs Mon-Fri every week - CALENDAR_RECURRENCE_MONTHLY_ON_DAY // Occurs on the same type of day every month, like second Tuesday -} calendar_recurrence_frequency_e; -*/ - GList* _calendar_glist_next_until_not_deleted(GList* list); -int _calendar_query(calendar_foreach_query_event_cb callback, char* option, const char* string_to_find, void* user_data); +int _calendar_event_foreach(calendar_foreach_query_event_cb callback, int account_db_id, int calendar_db_id, void* user_data); +int _calendar_todo_foreach(calendar_foreach_query_todo_cb callback, int account_db_id, int calendar_db_id, void* user_data); +int _calendar_event_query(calendar_foreach_query_event_cb callback, int calendar_db_id, char* option, const char* string_to_find, void* user_data); +int _calendar_get_account_db_id(int calendar_db_id); +void _calendar_parse_color(char* color_string, unsigned char* red, unsigned char* green, unsigned char* blue); /** * Internal Macros @@ -151,8 +134,15 @@ int _calendar_query(calendar_foreach_query_event_cb callback, char* option, con #define _calendar_safe_strdup(_srcx_) (NULL != _srcx_) ? strdup(_srcx_):NULL #define _calendar_safe_free(_srcx_) { if(NULL != _srcx_) free(_srcx_); } -#define CALENDAR_NULL_ARG_CHECK(arg) do { \ - if(arg == NULL) { \ +#define CALENDAR_NULL_ARG_CHECK(_arg_) do { \ + if(_arg_ == NULL) { \ + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); \ + return CALENDAR_ERROR_INVALID_PARAMETER; \ + } \ +}while(0) + +#define CONTACTS_INVALID_ARG_CHECK(_condition_) do { \ + if(_condition_) { \ LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); \ return CALENDAR_ERROR_INVALID_PARAMETER; \ } \ diff --git a/include/calendar_types.h b/include/calendar_types.h index 9390764..890a711 100755 --- a/include/calendar_types.h +++ b/include/calendar_types.h @@ -216,12 +216,12 @@ typedef void (*calendar_db_changed_cb)(void *user_data); /** * @} */ - /** * @addtogroup CAPI_SOCIAL_CALENDAR_TODO_MODULE * @{ */ + /** * @brief The calendar to-do handle. */ @@ -256,13 +256,76 @@ typedef enum * * @pre calendar_foreach_todo_from_db() will invoke this callback. * @see calendar_foreach_todo_from_db() - * */ typedef bool (*calendar_foreach_query_todo_cb)(calendar_todo_h todo, void *user_data); /** * @} */ +/** + * @ingroup CAPI_SOCIAL_CALENDAR_MODULE + * @defgroup CAPI_SOCIAL_CALENDAR_MULTIPLECALENDAR_MODULE Multiple Calendar + * + * @brief Calendar definition and Calendar related operations. + * + * @section CAPI_SOCIAL_CALENDAR_MULTIPLECALENDAR_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_SOCIAL_CALENDAR_MULTIPLECALENDAR_MODULE_OVERVIEW Overview + * Calendar + * + *
+ */ + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_MULTIPLECALENDAR_MODULE + * @{ + */ + +/** + * @brief The calendar handle. + */ +typedef struct calendar_event_s *calendar_h; + +/** + * @brief Definition for default calendar database ID + */ +#define DEFAULT_CALENDAR_DB_ID 1 + +/** + * @brief The structure of calendar in search results. + * + * @see calendar_foreach_query_calendar_cb() + */ +typedef struct { + int calendar_db_id; /**< calendar database ID */ + char* calendar_name; /**< calendar name */ + bool calendar_is_default; /**< default calendar status */ + bool calendar_is_visible; /**< calendar visible status */ + unsigned char calendar_color_red; /**< calendar color red among RGB */ + unsigned char calendar_color_green; /**< calendar color green among RGB */ + unsigned char calendar_color_blue; /**< calendar color blue among RGB */ + int account_db_id; /**< account database ID */ +}calendar_query_calendar_s; + +/** + * @brief The callback function to get the calendar + * + * @param[in] calendar The calendar + * @param[in] user_data The user data passed from the foreach function + * + * @return @c true to continue with the next iteration of the loop or @c false to break out of the loop. + * + * @pre calendar_foreach_calendar_from_db() will invoke this callback. + * + * @see calendar_foreach_calendar_from_db() + */ +typedef bool (*calendar_foreach_query_calendar_cb)(calendar_query_calendar_s *calendar, void *user_data); + +/** + * @} + */ + #ifdef __cplusplus } diff --git a/src/calendar.c b/src/calendar.c index 1e73ed1..119617a 100755 --- a/src/calendar.c +++ b/src/calendar.c @@ -60,12 +60,18 @@ int calendar_disconnect(void) } } -int calendar_event_insert_to_db(calendar_event_h event, int *event_id) +int calendar_event_insert_to_db(calendar_event_h event, int calendar_db_id, int *event_id) { - int ret_val = CALENDAR_ERROR_NONE; - CALENDAR_NULL_ARG_CHECK(event); CALENDAR_NULL_ARG_CHECK(event_id); + + int ret_val = CALENDAR_ERROR_NONE; + + int account_db_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_db_id == -2); + + calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_CALENDAR_ID, calendar_db_id); + calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_ACCOUNT_ID, account_db_id); ret_val = -1; ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)event)->event_legacy); @@ -80,10 +86,7 @@ int calendar_event_insert_to_db(calendar_event_h event, int *event_id) int calendar_event_delete_from_db(int event_id) { - if(event_id <= 0) { - LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); - return CALENDAR_ERROR_INVALID_PARAMETER; - } + CONTACTS_INVALID_ARG_CHECK(event_id <= 0); int ret_val = CALENDAR_ERROR_NONE; @@ -103,9 +106,10 @@ int calendar_event_delete_from_db(int event_id) int calendar_event_update_to_db(calendar_event_h event) { + CALENDAR_NULL_ARG_CHECK(event); + int ret_val = CALENDAR_ERROR_NONE; - CALENDAR_NULL_ARG_CHECK(event); if((cal_struct*)((calendar_event_s*)event)->event_legacy == NULL) { LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); return CALENDAR_ERROR_INVALID_PARAMETER; @@ -148,55 +152,6 @@ int calendar_event_update_to_db(calendar_event_h event) return CALENDAR_ERROR_NONE; } -//Provide iterator instead of event -int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data) -{ - CALENDAR_NULL_ARG_CHECK(callback); - - int ret_val = CALENDAR_ERROR_NONE; - cal_iter* iter = NULL; - bool callback_return = true; - - //fetch from DB - ret_val = calendar_svc_get_all(0, 0, CAL_STRUCT_SCHEDULE, &iter); - - if (ret_val != CAL_SUCCESS) { - LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); - return CALENDAR_ERROR_DB_FAILED; - } - - if (iter == NULL) { - LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); - return CALENDAR_ERROR_DB_FAILED; - } else { - while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { - calendar_event_s cal_event_from_db = {0,}; - if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { - calendar_svc_iter_remove(&iter); - return CALENDAR_ERROR_NONE; // consider this as no data - } - - if(cal_event_from_db.event_legacy == NULL) { - calendar_svc_iter_remove(&iter); - return CALENDAR_ERROR_NONE; // consider this as no data - } - - //execute callback - callback_return = callback((calendar_event_h)&cal_event_from_db, user_data); - - calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); - - if(callback_return == false) { - break; - } - } - calendar_svc_iter_remove(&iter); - - return CALENDAR_ERROR_NONE; - } - return CALENDAR_ERROR_NONE; -} - int calendar_event_get_from_db(int event_id, calendar_event_h *event) { CALENDAR_NULL_ARG_CHECK(event); @@ -228,6 +183,18 @@ int calendar_event_get_db_id(calendar_event_h event, int *db_id) return CALENDAR_ERROR_NONE; } +int calendar_event_get_calendar_db_id(calendar_event_h event, int *calendar_db_id) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(calendar_db_id); + + *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + (char*)CAL_VALUE_INT_CALENDAR_ID); + if(*calendar_db_id < 0) + *calendar_db_id = 0; + return CALENDAR_ERROR_NONE; +} + int calendar_event_get_total_count_from_db(int *count) { CALENDAR_NULL_ARG_CHECK(count); @@ -1016,36 +983,56 @@ int calendar_attendee_iterator_next(calendar_attendee_iterator_h *iterator, cale return CALENDAR_ERROR_ITERATOR_END; } -int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, const char *subject_to_find, void* user_data) +//Provide iterator instead of event +int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + return _calendar_event_foreach(callback, ALL_ACCOUNT_ID, ALL_CALENDAR_ID, user_data); +} + +int calendar_query_event_by_calendar(calendar_foreach_query_event_cb callback, int calendar_db_id, void *user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1); + int account_db_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_db_id == -2); + + return _calendar_event_foreach(callback, account_db_id, calendar_db_id, user_data); +} + +int calendar_query_event_by_subject(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *subject_to_find, void* user_data) { CALENDAR_NULL_ARG_CHECK(callback); CALENDAR_NULL_ARG_CHECK(subject_to_find); - return _calendar_query(callback, CAL_VALUE_TXT_SUMMARY, subject_to_find, user_data); + return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_SUMMARY, subject_to_find, user_data); } -int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, const char *description_to_find, void* user_data) +int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *description_to_find, void* user_data) { CALENDAR_NULL_ARG_CHECK(callback); CALENDAR_NULL_ARG_CHECK(description_to_find); - return _calendar_query(callback, CAL_VALUE_TXT_DESCRIPTION, description_to_find, user_data); + return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_DESCRIPTION, description_to_find, user_data); } -int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, const char *location_to_find, void* user_data) +int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, int calendar_db_id, const char *location_to_find, void* user_data) { CALENDAR_NULL_ARG_CHECK(callback); CALENDAR_NULL_ARG_CHECK(location_to_find); - return _calendar_query(callback, CAL_VALUE_TXT_LOCATION, location_to_find, user_data); + return _calendar_event_query(callback, calendar_db_id, CAL_VALUE_TXT_LOCATION, location_to_find, user_data); } -int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, struct tm start_time, struct tm end_time, void* user_data) +int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm start_time, struct tm end_time, void* user_data) { CALENDAR_NULL_ARG_CHECK(callback); int ret_val = 0; cal_iter* iter = NULL; bool callback_return = true; + + int account_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_id == -2); //fetch from DB - ret_val = calendar_svc_get_event_list_by_tm_period (0, 0, &start_time, &end_time, &iter); + ret_val = calendar_svc_get_event_list_by_tm_period (account_id, calendar_db_id, &start_time, &end_time, &iter); if (ret_val != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); @@ -1153,16 +1140,19 @@ int calendar_event_set_visibility(calendar_event_h event, calendar_visibility_e return CALENDAR_ERROR_NONE; } -int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, struct tm time, void *user_data) +int calendar_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, int calendar_db_id, struct tm time, void *user_data) { CALENDAR_NULL_ARG_CHECK(callback); int ret_val = 0; cal_iter* iter = NULL; bool callback_return = true; - + + int account_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_id == -2); + //fetch from DB time_t timestamp = mktime(&time); - ret_val = calendar_svc_get_updated_event_list (0, timestamp, &iter); + ret_val = calendar_svc_get_updated_event_list (account_id, timestamp, &iter); if (ret_val != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); @@ -1677,12 +1667,30 @@ int calendar_todo_get_db_id(calendar_todo_h todo, int *db_id) return CALENDAR_ERROR_NONE; } -int calendar_todo_insert_to_db(calendar_todo_h todo, int *todo_id) +int calendar_todo_get_calendar_db_id(calendar_todo_h todo, int *calendar_db_id) { - int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(calendar_db_id); + *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, + (char*)CAL_VALUE_INT_CALENDAR_ID); + if(*calendar_db_id < 0) + *calendar_db_id = 0; + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_insert_to_db(calendar_todo_h todo, int calendar_db_id, int *todo_id) +{ CALENDAR_NULL_ARG_CHECK(todo); CALENDAR_NULL_ARG_CHECK(todo_id); + + int ret_val = CALENDAR_ERROR_NONE; + + int account_db_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_db_id == -2); + + calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_CALENDAR_ID, calendar_db_id); + calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_ACCOUNT_ID, account_db_id); ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)todo)->event_legacy); if (ret_val < 0) @@ -2069,13 +2077,138 @@ int calendar_todo_set_due_time(calendar_todo_h todo, struct tm due_time) int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void *user_data) { CALENDAR_NULL_ARG_CHECK(callback); + + return _calendar_todo_foreach(callback, ALL_ACCOUNT_ID, ALL_CALENDAR_ID, user_data); +} + +int calendar_query_todo_by_calendar(calendar_foreach_query_todo_cb callback, int calendar_db_id, void *user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1); + int account_db_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_db_id == -2); + + return _calendar_todo_foreach(callback, account_db_id, calendar_db_id, user_data); +} + +int calendar_get_from_db(int calendar_db_id, calendar_h *calendar) +{ + CONTACTS_INVALID_ARG_CHECK(calendar_db_id < 1); + CALENDAR_NULL_ARG_CHECK(calendar); + + *calendar = malloc(sizeof(calendar_event_s)); + if (*calendar == NULL) { + LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); + return CALENDAR_ERROR_OUT_OF_MEMORY; + } + + memset(*calendar, 0, sizeof(calendar_event_s)); + if(calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_db_id, NULL, (cal_struct**)&(*(calendar_event_s**)calendar)->event_legacy) != CAL_SUCCESS) { + free(*calendar); + *calendar = NULL; + + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + return CALENDAR_ERROR_NONE; +} + +int calendar_destroy(calendar_h calendar) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + int ret_val = CALENDAR_ERROR_NONE; + + ret_val = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)calendar)->event_legacy); + if (ret_val != CAL_SUCCESS) { + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); + ret_val = CALENDAR_ERROR_INVALID_PARAMETER; + } else { + free(calendar); + ret_val = CALENDAR_ERROR_NONE; + } + + return ret_val; +} + +int calendar_get_db_id(calendar_h calendar, int *calendar_db_id) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(calendar_db_id); + + *calendar_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, (char*)CAL_TABLE_INT_INDEX); + if(*calendar_db_id < 0) + *calendar_db_id = 0; + return CALENDAR_ERROR_NONE; +} + +int calendar_get_is_default(calendar_h calendar, bool *is_default) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(is_default); + + if(calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_INDEX) == 1) { + *is_default = true; + } + else { + *is_default = false; + } + return CALENDAR_ERROR_NONE; +} + +int calendar_get_name(calendar_h calendar, char **calendar_name) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(calendar_name); + + *calendar_name = NULL; + *calendar_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_NAME)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_get_is_visibile(calendar_h calendar, bool *is_visible) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(is_visible); + + *is_visible = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_VISIBILITY) == 1 ? true : false; + + return CALENDAR_ERROR_NONE; +} + +int calendar_get_color(calendar_h calendar, unsigned char *red, unsigned char *green, unsigned char *blue) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(red); + CALENDAR_NULL_ARG_CHECK(green); + CALENDAR_NULL_ARG_CHECK(blue); + + _calendar_parse_color(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_TXT_COLOR), + red, green, blue); + return CALENDAR_ERROR_NONE; +} + +int calendar_get_account_db_id(calendar_h calendar, int *account_db_id) +{ + CALENDAR_NULL_ARG_CHECK(calendar); + CALENDAR_NULL_ARG_CHECK(account_db_id); + + *account_db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)calendar)->event_legacy, CAL_TABLE_INT_ACCOUNT_ID) == 1 ? true : false; + + return CALENDAR_ERROR_NONE; +} + +int calendar_foreach_calendar_from_db(calendar_foreach_query_calendar_cb callback, void *user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + int ret_val = CALENDAR_ERROR_NONE; cal_iter* iter = NULL; bool callback_return = true; //fetch from DB - ret_val = calendar_svc_get_all(0, 0, CAL_STRUCT_TODO, &iter); + ret_val = calendar_svc_get_all(ALL_ACCOUNT_ID, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR, &iter); if (ret_val != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); @@ -2087,21 +2220,33 @@ int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void return CALENDAR_ERROR_DB_FAILED; } else { while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { - calendar_event_s cal_event_from_db = {0,}; - if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { + cal_struct *calendar_struct = NULL; + if(calendar_svc_iter_get_info(iter, &calendar_struct) != CAL_SUCCESS) { calendar_svc_iter_remove(&iter); return CALENDAR_ERROR_NONE; // consider this as no data } - if(cal_event_from_db.event_legacy == NULL) { + if(calendar_struct == NULL) { calendar_svc_iter_remove(&iter); return CALENDAR_ERROR_NONE; // consider this as no data - } + } - //execute callback - callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data); + calendar_query_calendar_s query_data; - calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); + query_data.calendar_db_id = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_INDEX); + query_data.calendar_name = _calendar_safe_strdup(calendar_svc_struct_get_str(calendar_struct, CAL_TABLE_TXT_NAME)); + query_data.calendar_is_default = query_data.calendar_db_id == 1 ? true : false; + query_data.calendar_is_visible = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_VISIBILITY) == 1 ? true : false; + _calendar_parse_color(calendar_svc_struct_get_str(calendar_struct, CAL_TABLE_TXT_COLOR), + &query_data.calendar_color_red, &query_data.calendar_color_green, &query_data.calendar_color_blue); + query_data.account_db_id = calendar_svc_struct_get_int(calendar_struct, CAL_TABLE_INT_ACCOUNT_ID); + + //execute callback + callback_return = callback(&query_data, user_data); + + _calendar_safe_free(query_data.calendar_name); + + calendar_svc_struct_free(&calendar_struct); if(callback_return == false) { break; @@ -2111,5 +2256,8 @@ int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void return CALENDAR_ERROR_NONE; } - return CALENDAR_ERROR_NONE; + return CALENDAR_ERROR_NONE; + + } + diff --git a/src/calendar_private.c b/src/calendar_private.c index 362666e..239e2f2 100755 --- a/src/calendar_private.c +++ b/src/calendar_private.c @@ -55,14 +55,109 @@ GList* _calendar_glist_next_until_not_deleted(GList* list) return glist; } -int _calendar_query(calendar_foreach_query_event_cb callback, char* option, const char* string_to_find, void* user_data) +int _calendar_event_foreach(calendar_foreach_query_event_cb callback, int account_db_id, int calendar_db_id, void* user_data) +{ + int ret_val = CALENDAR_ERROR_NONE; + cal_iter* iter = NULL; + bool callback_return = true; + + //fetch from DB + ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_SCHEDULE, &iter); + + if (ret_val != CAL_SUCCESS) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + + if (iter == NULL) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } else { + while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { + calendar_event_s cal_event_from_db = {0,}; + if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { + calendar_svc_iter_remove(&iter); + return CALENDAR_ERROR_NONE; // consider this as no data + } + + if(cal_event_from_db.event_legacy == NULL) { + calendar_svc_iter_remove(&iter); + return CALENDAR_ERROR_NONE; // consider this as no data + } + + //execute callback + callback_return = callback((calendar_event_h)&cal_event_from_db, user_data); + + calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); + + if(callback_return == false) { + break; + } + } + calendar_svc_iter_remove(&iter); + + return CALENDAR_ERROR_NONE; + } + return CALENDAR_ERROR_NONE; +} + +int _calendar_todo_foreach(calendar_foreach_query_todo_cb callback, int account_db_id, int calendar_db_id, void* user_data) +{ + int ret_val = CALENDAR_ERROR_NONE; + cal_iter* iter = NULL; + bool callback_return = true; + + //fetch from DB + ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_TODO, &iter); + + if (ret_val != CAL_SUCCESS) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + + if (iter == NULL) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } else { + while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { + calendar_event_s cal_event_from_db = {0,}; + if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { + calendar_svc_iter_remove(&iter); + return CALENDAR_ERROR_NONE; // consider this as no data + } + + if(cal_event_from_db.event_legacy == NULL) { + calendar_svc_iter_remove(&iter); + return CALENDAR_ERROR_NONE; // consider this as no data + } + + //execute callback + callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data); + + calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); + + if(callback_return == false) { + break; + } + } + calendar_svc_iter_remove(&iter); + + return CALENDAR_ERROR_NONE; + } + return CALENDAR_ERROR_NONE; +} + +int _calendar_event_query(calendar_foreach_query_event_cb callback, int calendar_db_id, char* option, const char* string_to_find, void* user_data) { int ret_val = 0; cal_iter* iter = NULL; bool callback_return = true; + + int account_id = _calendar_get_account_db_id(calendar_db_id); + CONTACTS_INVALID_ARG_CHECK(account_id == -2); //fetch from DB - ret_val = calendar_svc_find_event_list(0, option, string_to_find, &iter); + ret_val = calendar_svc_find_event_list(account_id, option, string_to_find, &iter); if (ret_val != CAL_SUCCESS) { LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); @@ -101,4 +196,56 @@ int _calendar_query(calendar_foreach_query_event_cb callback, char* option, cons return CALENDAR_ERROR_NONE; } +int _calendar_get_account_db_id(int calendar_db_id) +{ + int ret = -2; + if(calendar_svc_connect() != CAL_SUCCESS) { + return -2; + } + + cal_struct* calendar = NULL; + if(calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_db_id, NULL, &calendar) != CAL_SUCCESS) { + calendar_svc_close(); + calendar_svc_struct_free(&calendar); + return -2; + } + + if((ret = calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID)) < -1) { + ret = -2; // get account ID fail; + } + calendar_svc_struct_free(&calendar); + calendar_svc_close(); + return ret; +} + +void _calendar_parse_color(char* color_string, unsigned char* red, unsigned char* green, unsigned char* blue) +{ + *red = 0; + *green = 0; + *blue = 0; + + if(color_string == NULL) { + return; + } + char* token = NULL; + char* temp = NULL; + // 0.0.0.0 + if(strlen(color_string) < 7) { + return; + } + token = strtok_r(color_string, ".", &temp); + if(token) { + *red = atoi(token); + } + + token = strtok_r(NULL, ".", &temp); + if(token) { + *green = atoi(token); + } + + token = strtok_r(NULL, ".", &temp); + if(token) { + *blue = atoi(token); + } +} -- 2.7.4