/* * 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 "calendar_private.h" #include "calendar.h" #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_CALENDAR" #define LOG_MODE (1) GList* _calendar_glist_next_until_not_deleted(GList* list) { if(list == NULL) return NULL; GList* glist = list; cal_value* value = glist->data; if(value == NULL) return NULL; while( (calendar_svc_value_get_int(value, CAL_VALUE_INT_DETAIL_DELETE) == true) && (glist != NULL) ) { glist = g_list_next(glist); if(glist != NULL) { value = glist->data; // codes below is for SVACE passed if(value == NULL) { glist = NULL; break; } } } return glist; } //int _calendar_event_foreach(calendar_foreach_query_event_cb callback, int account_db_id, int calendar_db_id, void* user_data) //{ // int ret_val = CALENDAR_ERROR_NONE; // cal_iter* iter = NULL; // bool callback_return = true; // // //fetch from DB // ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_SCHEDULE, &iter); // // if (ret_val != CAL_SUCCESS) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } // // if (iter == NULL) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } else { // while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { // calendar_event_s cal_event_from_db = {0,}; // if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { // calendar_svc_iter_remove(&iter); // return CALENDAR_ERROR_NONE; // consider this as no data // } // // if(cal_event_from_db.event_legacy == NULL) { // calendar_svc_iter_remove(&iter); // return CALENDAR_ERROR_NONE; // consider this as no data // } // // //execute callback // callback_return = callback((calendar_event_h)&cal_event_from_db, user_data); // // calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); // // if(callback_return == false) { // break; // } // } // calendar_svc_iter_remove(&iter); // // return CALENDAR_ERROR_NONE; // } // return CALENDAR_ERROR_NONE; //} // //int _calendar_todo_foreach(calendar_foreach_query_todo_cb callback, int account_db_id, int calendar_db_id, void* user_data) //{ // int ret_val = CALENDAR_ERROR_NONE; // cal_iter* iter = NULL; // bool callback_return = true; // // //fetch from DB // ret_val = calendar_svc_get_all(account_db_id, calendar_db_id, CAL_STRUCT_TODO, &iter); // // if (ret_val != CAL_SUCCESS) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } // // if (iter == NULL) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } else { // while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { // calendar_event_s cal_event_from_db = {0,}; // if(calendar_svc_iter_get_info(iter, (cal_struct**)&cal_event_from_db.event_legacy) != CAL_SUCCESS) { // calendar_svc_iter_remove(&iter); // return CALENDAR_ERROR_NONE; // consider this as no data // } // // if(cal_event_from_db.event_legacy == NULL) { // calendar_svc_iter_remove(&iter); // return CALENDAR_ERROR_NONE; // consider this as no data // } // // //execute callback // callback_return = callback((calendar_todo_h)&cal_event_from_db, user_data); // // calendar_svc_struct_free((cal_struct**)&cal_event_from_db.event_legacy); // // if(callback_return == false) { // break; // } // } // calendar_svc_iter_remove(&iter); // // return CALENDAR_ERROR_NONE; // } // return CALENDAR_ERROR_NONE; //} // //int _calendar_calendar_query(calendar_foreach_query_calendar_book_cb callback, // int account_db_id, int calendar_db_id, // const char* string_to_find, void* user_data) //{ // int ret_val = 0; // cal_iter* iter = NULL; // bool callback_return = true; // int search_field; // // search_field = CALS_SEARCH_FIELD_NONE; // search_field |= CALS_SEARCH_FIELD_SUMMARY; // search_field |= CALS_SEARCH_FIELD_DESCRIPTION; // search_field |= CALS_SEARCH_FIELD_LOCATION; // search_field |= CALS_SEARCH_FIELD_ATTENDEE; // // ret_val = calendar_svc_event_search(search_field, string_to_find, &iter); // // if (ret_val != CAL_SUCCESS) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } // // if (iter == NULL) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } else { // while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { // 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_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); // CALENDAR_INVALID_ARG_CHECK(account_id == -2); // // //fetch from DB // ret_val = calendar_svc_find_event_list(account_id, option, string_to_find, &iter); // // if (ret_val != CAL_SUCCESS) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } // // if (iter == NULL) { // LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); // return CALENDAR_ERROR_DB_FAILED; // } // // 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; //} 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); } }