diff options
author | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:42:18 +0900 |
---|---|---|
committer | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:42:18 +0900 |
commit | 11da635c79ea21765a50d28cf81ff6b51dddefa0 (patch) | |
tree | 3a4f7487c498d852459d54e3a302ca0c625b310c | |
parent | f7d3bd8b3884553bbe42d6ece32974d3e26281ee (diff) | |
download | calendar-11da635c79ea21765a50d28cf81ff6b51dddefa0.tar.gz calendar-11da635c79ea21765a50d28cf81ff6b51dddefa0.tar.bz2 calendar-11da635c79ea21765a50d28cf81ff6b51dddefa0.zip |
Git init
-rwxr-xr-x | AUTHORS | 2 | ||||
-rwxr-xr-x | CMakeLists.txt | 90 | ||||
-rwxr-xr-x | LICENSE | 206 | ||||
-rwxr-xr-x | capi-social-calendar.pc.in | 15 | ||||
-rwxr-xr-x | debian/README | 0 | ||||
-rwxr-xr-x | debian/capi-social-calendar-dev.install | 4 | ||||
-rwxr-xr-x | debian/capi-social-calendar-dev.postinst | 1 | ||||
-rwxr-xr-x | debian/capi-social-calendar.install | 1 | ||||
-rwxr-xr-x | debian/capi-social-calendar.postinst | 1 | ||||
-rw-r--r-- | debian/changelog | 21 | ||||
-rwxr-xr-x | debian/compat | 1 | ||||
-rwxr-xr-x | debian/control | 22 | ||||
-rwxr-xr-x | debian/rules | 65 | ||||
-rwxr-xr-x | include/calendar.h | 1455 | ||||
-rwxr-xr-x | include/calendar_attendee.h | 203 | ||||
-rwxr-xr-x | include/calendar_private.h | 169 | ||||
-rwxr-xr-x | include/calendar_types.h | 271 | ||||
-rwxr-xr-x | packaging/capi-social-calendar.spec | 56 | ||||
-rwxr-xr-x | src/calendar.c | 2115 | ||||
-rwxr-xr-x | src/calendar_private.c | 104 |
20 files changed, 4802 insertions, 0 deletions
@@ -0,0 +1,2 @@ +Jonghoon Lim <j.h.lim@samsung.com> +Jongchul Park <jc0204.park@samsung.com>
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..741feb3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,90 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-social-calendar") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog calendar-service glib-2.0 capi-social-contacts") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/social + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${dependents}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/social) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) + +#ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
+
diff --git a/capi-social-calendar.pc.in b/capi-social-calendar.pc.in new file mode 100755 index 0000000..d48ca91 --- /dev/null +++ b/capi-social-calendar.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/social + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} @PC_CFLAGS@ + diff --git a/debian/README b/debian/README new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/debian/README diff --git a/debian/capi-social-calendar-dev.install b/debian/capi-social-calendar-dev.install new file mode 100755 index 0000000..761a28b --- /dev/null +++ b/debian/capi-social-calendar-dev.install @@ -0,0 +1,4 @@ +/usr/include/* +/usr/include/*/* +/usr/lib/pkgconfig/*.pc + diff --git a/debian/capi-social-calendar-dev.postinst b/debian/capi-social-calendar-dev.postinst new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-social-calendar-dev.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/capi-social-calendar.install b/debian/capi-social-calendar.install new file mode 100755 index 0000000..4a755a4 --- /dev/null +++ b/debian/capi-social-calendar.install @@ -0,0 +1 @@ +/usr/lib/lib*.so* diff --git a/debian/capi-social-calendar.postinst b/debian/capi-social-calendar.postinst new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/debian/capi-social-calendar.postinst @@ -0,0 +1 @@ +#!/bin/sh diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..65088d1 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,21 @@ +capi-social-calendar (0.1.1-27) unstable; urgency=low + + * version updated + * Git: api/calendar + * Tag: capi-social-calendar_0.1.1-27 + + -- Jonghoon Lim <j.h.lim@samsung.com> Mon, 19 Dec 2011 14:52:01 +0900 + +capi-social-calendar (0.1.1-26) unstable; urgency=low + + * version updated + * Git: api/calendar + * Tag: capi-social-calendar_0.1.1-26 + + -- Jonghoon Lim <j.h.lim@samsung.com> Thu, 15 Dec 2011 13:43:07 +0900 + +capi-social-calendar (0.0.1-1) unstable; urgency=low + + * Initial release. + + -- Jonghoon Lim <j.h.lim@samsung.com> Wed, 07 Dec 2011 12:48:12 +0900 diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..d462109 --- /dev/null +++ b/debian/control @@ -0,0 +1,22 @@ + +Source: capi-social-calendar +Section: libs +Priority: extra +Maintainer: Jongchul Park <jc0204.park@samsung.com>, Jonghoon Lim <j.h.lim@samsung.com> +Build-Depends: debhelper (>= 5), dlog-dev, libslp-calendar-dev, libglib2.0-dev, capi-base-common-dev, capi-social-contacts-dev + +Package: capi-social-calendar +Architecture: any +Depends: ${shilbs:Depends}, ${misc:Depends} +Description: Calendar library in Tizen Native API + +Package: capi-social-calendar-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-social-calendar (= ${Source-Version}), dlog-dev, libslp-calendar-dev, libglib2.0-dev, capi-base-common-dev, capi-social-contacts-dev +Description: Calendar library in Tizen Native API (DEV) + +Package: capi-social-calendar-dbg +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-social-calendar (= ${Source-Version}) +Description: Calendar library in Tizen Native API (DBG) + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..a463aa1 --- /dev/null +++ b/debian/rules @@ -0,0 +1,65 @@ +#!/usr/bin/make -f + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif +CMAKE_ROOT_DIR ?= $(CURDIR) +CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. + touch configure-stamp + + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + cd $(CMAKE_BUILD_DIR) && $(MAKE) + touch $@ + +clean: + cd $(CMAKE_ROOT_DIR) + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + rm -f + rm -rf $(CMAKE_BUILD_DIR) + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + +binary-indep: build install + +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp + dh_installman + dh_link + dh_strip --dbg-package=capi-social-calendar-dbg + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure + diff --git a/include/calendar.h b/include/calendar.h new file mode 100755 index 0000000..4fb4841 --- /dev/null +++ b/include/calendar.h @@ -0,0 +1,1455 @@ +/* + * 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. + */ + + +#ifndef __TIZEN_SOCIAL_CALENDAR_CALENDAR_H__ +#define __TIZEN_SOCIAL_CALENDAR_CALENDAR_H__ + +#include <tizen.h> +#include <time.h> +#include <calendar_attendee.h> +#include <calendar_types.h> + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_MODULE + * @{ + */ + +/** + * @brief Connects to the calendar service. + * + * @details Opening connection is necessary to access the calendar database. + * All operations like inserting, updating, or deleting calendar require opened connection to work properly. + + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @see calendar_disconnect() + * + */ +int calendar_connect(void); + +/** + * @brief Disconnects the calendar service. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @see calendar_connect() + * + */ +int calendar_disconnect(void); + +/** + * @brief Retrieves all timezone information supported on a device. + * + * @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 + * + * @post This function invokes calendar_foreach_timezone_cb(). + * + * @see calendar_foreach_timezone_cb() + * @see calendar_event_set_timezone() + * @see calendar_todo_set_timezone() + */ +int calendar_foreach_timezone(calendar_foreach_timezone_cb callback, void *user_data); + +/** + * @brief Registers a callback function to be invoked when any database change occur. + * + * @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 + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * @post calendar_db_changed_cb() will be invoked. + * + * @see calendar_db_changed_cb() + * @see calendar_unset_db_changed_cb() + * @see calendar_event_insert_to_db() + * @see calendar_event_update_to_db() + * @see calendar_event_delete_from_db() + */ +int calendar_set_db_changed_cb(calendar_db_changed_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function. + * + * @param[in] callback The callback function to unregister + * + * @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_db_changed_cb() + * @see calendar_set_db_changed_cb() + */ +int calendar_unset_db_changed_cb(calendar_db_changed_cb callback); + +/** + * @} + */ + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_EVENT_MODULE + * @{ + */ + + +/** + * @brief Creates a handle to the calendar event. + * @remarks The calendar event handle must be released with calendar_event_destroy() by you. + * @remarks The created handle is not added to calendar database until calendar_event_insert_to_db() is called + * + * @param[out] event A new handle to calendar event + * + * @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 + * + * @see calendar_event_destroy() + * + */ +int calendar_event_create(calendar_event_h *event); + +/** + * @brief Destroys the calendar event handle and releases all its resources. + * + * @param[out] event The calendar event handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_create() + * + */ +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 + * If the function fails, it is -1. + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @see calendar_connect() + * @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); + +/** + * @brief Removes the calendar event from the calendar database. + * + * @param[in] event_id The event ID to delete + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @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_update_to_db() + */ +int calendar_event_delete_from_db(int event_id); + +/** + * @brief Updates the calendar event in the calendar database. + * @details calendar_event_get_db_id() is called internally to update in the calendar database to get the event ID in the calendar database. + * + * @param[in] event The calendar event handle + * + * @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(). + * @pre The event is supposed to be in the calendar database already. + * + * @see calendar_connect() + * @see calendar_event_insert_to_db() + * @see calendar_event_delete_from_db() + * @see calendar_event_get_from_db() + * @see calendar_event_get_db_id() + */ +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 + * 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 + * + * @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_event_destroy() + */ +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 + * 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() + */ +int calendar_event_get_db_id(calendar_event_h event, int *event_db_id); + +/** + * @brief Gets the subject of the event from the calendar event handle . + * + * @remarks @a subject must be released with free() by you. + * + * @param [in] event The calendar event handle + * @param [out] subject The subject of the event \n If the subject 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 + * + * @see calendar_event_set_subject() + * +*/ +int calendar_event_get_subject(calendar_event_h event, char **subject); + + +/** + * @brief Sets the subject of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] subject The subject of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_subject() + */ +int calendar_event_set_subject(calendar_event_h event, const char *subject); + + +/** + * @brief Gets the description of the event from the calendar event handle. + * + * @remarks @a description must be released with free() by you. + * + * @param [in] event The calendar event handle + * @param [out] description The description of the event \n If the description 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 + * + * @see calendar_event_set_description() + */ +int calendar_event_get_description(calendar_event_h event, char **description); + + +/** + * @brief Sets a description of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] description The description of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_description() + */ +int calendar_event_set_description(calendar_event_h event, const char *description); + + +/** + * @brief Gets an all-day event property of the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [out] is_all_day_event @c true if the event lasts for an entire day, 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 + * + * @see calendar_event_set_is_all_day_event() + */ +int calendar_event_get_is_all_day_event(calendar_event_h event, bool *is_all_day_event); + + +/** + * @brief Sets an all-day event property of the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] is_all_day_event The all-day event type \n + * @c true if the event will last for an entire day, 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 + * + * @see calendar_event_get_is_all_day_event() + */ +int calendar_event_set_is_all_day_event(calendar_event_h event, bool is_all_day_event); + + +/** + * @brief Gets the location of the event from the calendar event handle. + * + * @remarks @a location must be released with free() by you. + * + * @param [in] event The calendar event handle + * @param [out] location The location of the event \n If the location 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 + * + * @see calendar_event_set_location() + */ +int calendar_event_get_location(calendar_event_h event, char **location); + + +/** + * @brief Sets a location of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] location The location of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_location() + */ +int calendar_event_set_location(calendar_event_h event, const char *location); + + +/** + * @brief Gets the reminder of the event from the calendar event handle. + * @details The function returns reminder type and interval of the event. + * + * + * @param [in] event The calendar event handle + * @param [out] reminder_interval_type The reminder type + * @param [out] reminder_interval The interval + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_set_reminder() + */ +int calendar_event_get_reminder(calendar_event_h event, calendar_reminder_interval_type_e *reminder_interval_type, int *reminder_interval); + + +/** + * @brief Sets a reminder of the event in the calendar event handle. + * + * @remarks If reminder is set, the alarm will remind the event with in-house calendar application. + * + * @param [in] event The calendar event handle + * @param [in] reminder_interval_type The reminder interval type + * @param [in] reminder_interval The reminder interval + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_reminder() + */ +int calendar_event_set_reminder(calendar_event_h event, calendar_reminder_interval_type_e reminder_interval_type, int reminder_interval); + +/** + * @brief Gets the recurrence frequency of the event from the calendar event handle. + * + * @param[in] event The calendar event handle + * @param[out] recurrence_frequency The recurrence type of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_set_recurrence_frequency() + * @see calendar_event_set_recurrence_week_flag() + * @see calendar_event_get_recurrence_week_flag() + * @see calendar_event_add_recurrence_exception_date() + */ +int calendar_event_get_recurrence_frequency(calendar_event_h event, calendar_recurrence_frequency_e *recurrence_frequency); + + +/** + * @brief Sets a recurrence frequency of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] recurrence_frequency The recurrence frequency of the event \n + * If you set it to #CALENDAR_RECURRENCE_WEEKLY, you have to set calendar_event_set_recurrence_week_flag(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_recurrence_frequency() + * @see calendar_event_set_recurrence_week_flag() + * @see calendar_event_get_recurrence_week_flag() + * @see calendar_event_add_recurrence_exception_date() + */ +int calendar_event_set_recurrence_frequency(calendar_event_h event, calendar_recurrence_frequency_e recurrence_frequency); + +/** + * @brief Gets the recurrence frequency of the event in the calendar event handle. + * + * @remarks This function is valid only if recurrence frequency of the event is #CALENDAR_RECURRENCE_WEEKLY. + * + * @param[in] event The calendar event handle + * @param[out] week_flag The days of week flag of the event \n It supports "OR"ing combination of #calendar_week_flag_e. \n eg) #CALENDAR_WEEK_FLAG_TUE | #CALENDAR_WEEK_FLAG_FRI + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_set_recurrence_week_flag() + * @see calendar_event_set_recurrence_frequency() + * @see calendar_event_get_recurrence_frequency() + */ +int calendar_event_get_recurrence_week_flag(calendar_event_h event, int *week_flag); + +/** + * @brief Sets the days of week flag to the calendar event handle. + * + * @remarks This function is valid only if recurrence frequency of the event is #CALENDAR_RECURRENCE_WEEKLY. + * + * @param[in] event The calendar event handle + * @param[in] week_flag The days of week flag of the event \n It supports "OR"ing combination of #calendar_week_flag_e. \n eg) #CALENDAR_WEEK_FLAG_TUE | #CALENDAR_WEEK_FLAG_FRI + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_recurrence_week_flag() + * @see calendar_event_set_recurrence_frequency() + * @see calendar_event_get_recurrence_frequency() + * + */ +int calendar_event_set_recurrence_week_flag(calendar_event_h event, int week_flag); + +/** + * @brief Gets the recurrence ending time of the event from the calendar event handle. + * @details If recurrence frequency of the event is activated, then @a recurrence_until_date indicates recurrence ending time. + * + * @param [in] event The calendar event handle + * @param [out] recurrence_until_date The ending time of the recurrence event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_event_set_recurrence_until_date() + */ +int calendar_event_get_recurrence_until_date(calendar_event_h event, struct tm *recurrence_until_date); + + +/** + * @brief Sets a recurrence end time of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] recurrence_until_date The end time of the recurrence event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre @a event has a recurrence frequency property using calendar_event_set_recurrence_frequency(). + * + * @see calendar_event_get_recurrence_until_date() + */ +int calendar_event_set_recurrence_until_date(calendar_event_h event, struct tm recurrence_until_date); + +/** + * @brief Adds a recurrence exception date to the calendar event handle. + * + * @param[in] event The calendar event handle + * @param[in] year The year of date \n It has to be more than 1900 + * @param[in] month The month of date [1-12] + * @param[in] day The day of date [1-31] + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_set_recurrence_frequency() + * @see calendar_event_get_recurrence_exception_iterator() + */ +int calendar_event_add_recurrence_exception_date(calendar_event_h event, int year, int month, int day); + + +/** + * @brief Gets the recurrence exception iterator handle from the event handle. + * + * @param[in] event The calendar event handle + * @param[out] iterator The recurrence exception iterator handle \n If the iterator 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 + * + * @see calendar_recurrence_exception_has_next() + * @see calendar_recurrence_exception_next() + */ +int calendar_event_get_recurrence_exception_iterator(calendar_event_h event, calendar_recurrence_exception_iterator_h *iterator); + +/** + * @brief Checks whether there is a next recurrence exception handle on the list. + * + * @param [in] iterator The recurrence exception iterator handle + * + * @return @c true If the next element exists or @c false If the next element doesn't exist + * + * @see calendar_event_get_recurrence_exception_iterator() + * @see calendar_recurrence_exception_next() + */ +bool calendar_recurrence_exception_has_next(calendar_recurrence_exception_iterator_h iterator); + +/** + * @brief Moves recurrence exception list iterator to the next position and gets recurrence exception date. + * @details If the next element for the current recurrence exception list exists, then the iterator is moved to + * the next position on the list and the recurrence exception handle for this position is returned. + * When the iterator reaches the last element of the list, all further calls will return + * #CALENDAR_ERROR_ITERATOR_END and @a recurrence exception will remain unchanged. + * + * @param [in] iterator The recurrent exception iterator handle + * @param [out] year The year of date \n It is supposed to be more than 1900 + * @param [out] month The month of date [1-12] + * @param [out] day The day of date [1-31] + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_ITERATOR_END Iterator is on the last position + * + * @see calendar_event_get_recurrence_exception_iterator() + * @see calendar_recurrence_exception_has_next() + */ +int calendar_recurrence_exception_next(calendar_recurrence_exception_iterator_h *iterator, int* year, int* month, int* day); + +/** + * @brief Gets the start time of the event from the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [out] start_time The start date of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_event_set_start_time() + */ +int calendar_event_get_start_time(calendar_event_h event, struct tm *start_time); + + +/** + * @brief Sets a start time of the event in the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [in] start_time The start date of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_start_time() + */ +int calendar_event_set_start_time(calendar_event_h event, struct tm start_time); + + +/** + * @brief Gets the end time of the event from the calendar event handle. + * + * @param [in] event The calendar event handle + * @param [out] end_time The end date of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_event_set_end_time() + */ +int calendar_event_get_end_time(calendar_event_h event, struct tm *end_time); + + +/** + * @brief Sets the end time of the event in the calendar event handle. + * + * @param[in] event The calendar event handle + * @param[in] end_time The end date of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_end_time() + */ +int calendar_event_set_end_time(calendar_event_h event, struct tm end_time); + +/** + * @brief Gets the total number of events from the calendar database. + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * + * @param[out] count The total number of events + * + * @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 + * + * @see calendar_connect() + */ +int calendar_event_get_total_count_from_db(int *count); + +/** + * @brief Creates a attendee handle and make adds it to the calendar event. + * + * @remarks The created handle is not added to calendar database until calendar_event_insert_to_db() is called + * + * @param[in] event The calendar event handle + * @param[out] attendee A new attendee handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_remove_attendee() + * @see calendar_attendee_set_name() + * @see calendar_attendee_set_email() + * @see calendar_attendee_set_phone_number() + * @see calendar_event_get_attendee_iterator() + */ +int calendar_event_add_attendee(calendar_event_h event, calendar_attendee_h* attendee); + +/** + * @brief Creates a attendee handle with contact ID and adds it to the calendar event. + * + * @details Adds an existing contact as an attendee to an event. A new attendee record is created, and the name, email address and phone number are populated from the values in the contact record. + * @remarks The created handle is not added to calendar database until calendar_event_insert_to_db() is called + * + * + * @param[in] event The calendar event handle + * @param[in] contact_db_id The contact DB ID which is related to attendee + * @param[out] attendee A new attendee handle from contact ID in the contacts database + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre This function requires an open connection to Contacts Service by contacts_connect(). + * + * @see calendar_event_remove_attendee() + * @see calendar_attendee_set_name() + * @see calendar_attendee_set_email() + * @see calendar_attendee_set_phone_number() + * @see calendar_event_get_attendee_iterator() + * @see contact_get_db_id() + * @see contact_get_from_db() + * @see calendar_attendee_get_phone_number() + */ +int calendar_event_add_attendee_with_contact(calendar_event_h event, int contact_db_id, calendar_attendee_h* attendee); + +/** + * @brief Removes the attendee from the calendar event handle. + * + * + * @param[in] event The calendar event handle + * @param[in] attendee The attendee handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_add_attendee() + * @see calendar_event_get_attendee_iterator() + */ +int calendar_event_remove_attendee(calendar_event_h event, calendar_attendee_h attendee); + +/** + * @brief Gets the attendee iterator handle from the event handle. + * + * @param[in] event The calendar event handle + * @param[out] iterator The attendee iterator handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_iterator_has_next() + * @see calendar_attendee_iterator_next() + * + */ +int calendar_event_get_attendee_iterator(calendar_event_h event, calendar_attendee_iterator_h *iterator); + +/** + * @brief Gets the last modified time of the event handle. + * + * @param[in] event The calendar event handle + * @param[out] modified_time The last modified time of event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_event_insert_to_db() + * @see calendar_event_update_to_db() + */ +int calendar_event_get_last_modified_time(calendar_event_h event, struct tm *modified_time); + +/** + * @brief Gets the visibility for the given calendar event handle. + * + * @param[in] event The calendar event handle + * @param[out] visibility The visibility of the event \n (default : #CALENDAR_VISIBILITY_PUBLIC) + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_set_visibility() + */ +int calendar_event_get_visibility(calendar_event_h event, calendar_visibility_e *visibility); + +/** + * @brief Sets a visibility for the given calendar event handle. + * + * @param[in] event The calendar event handle + * @param[in] visibility The visibility of the event + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_visibility() + */ +int calendar_event_set_visibility(calendar_event_h event, calendar_visibility_e visibility); + +/** + * @brief Gets the timezone details for the given calendar event handle. + * + * @remark @a timezone_name must be released with free() by you. + * + * @param[in] event The calendar event handle + * @param[out] timezone_name The time zone name + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_foreach_timezone() + * @see calendar_event_set_timezone() + */ +int calendar_event_get_timezone(calendar_event_h event, char** timezone_name); + +/** + * @brief Sets a timezone for the given calendar event handle. + * + * @param[in] event The calendar event handle + * @param[in] timezone_name The time zone name + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_foreach_timezone() + * @see calendar_event_get_timezone() + */ +int calendar_event_set_timezone(calendar_event_h event, const char* timezone_name); + +/** + * @brief Gets an event from vCalendar and returns a new event handle. + * + * @remarks The new event handle must be released with calendar_event_destroy() by you. + * + * @param[in] vcalendar_stream The vCalendar stream to convert + * @param[out] event The event handle + * + * @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 + * + * @see calendar_event_destroy() + * @see calendar_event_get_vcalendar_from_event() + */ +int calendar_event_get_from_vcalendar(const char *vcalendar_stream, calendar_event_h *event); + +/** + * @brief Gets vCalendar from the event handle. + * + * @remarks @a vcalendar_stream must be released with free() by you. + * + * @param[in] event The event handle + * @param[out] vcalendar_stream The vCalendar stream to convert + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_event_get_from_vcalendar() + */ +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. + * + * + * @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_event_cb() + */ +int calendar_foreach_event_from_db(calendar_foreach_query_event_cb callback, void *user_data); + +/** + * @brief Retrieves all calendar events with the given subject. + * + * @param[in] callback The callback function to invoke + * @param[in] subject_to_find The description to filter + * @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_event_get_subject() + * @see calendar_event_set_subject() + * @see calendar_foreach_query_event_cb() + * @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); + +/** + * @brief Retrieves all calendar events with the given description. + * + * + * @param[in] callback The callback function to invoke + * @param[in] description_to_find The description to filter + * @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_event_get_description() + * @see calendar_event_set_description() + * @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); + +/** + * @brief Retrieves all calendar events with the given location. + * + * @param[in] callback The callback function to invoke + * @param[in] location_to_find The location to filter + * @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_event_get_location() + * @see calendar_event_set_location() + * @see calendar_query_event_by_subject() + * @see calendar_query_event_by_description() + * @see calendar_query_event_by_period() + * @see calendar_foreach_query_event_cb() + */ +int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, 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] 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 + * + * @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_event_get_start_time() + * @see calendar_event_set_start_time() + * @see calendar_event_get_end_time() + * @see calendar_event_set_end_time() + * @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); + +/** + * @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] 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 + * + * @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_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); + +/** + * @} + */ + + + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_TODO_MODULE + * @{ + */ + +/** + * @brief Creates a handle to calendar to-do. + * @remarks The calendar to-do handle must be released with calendar_todo_destroy() by you. + * @remarks The created handle is not added to calendar database until calendar_todo_insert_to_db() is called + * + * @param[out] todo The new calendar to-do handle + * + * @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 + * + * @see calendar_todo_destroy() + * + */ +int calendar_todo_create(calendar_todo_h *todo); + +/** + * @brief Destroys the calendar to-do handle + * + * @param[in] todo The calendar to-do handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_create() + * + */ +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[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. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_DB_FAILED No access to database + * + * @pre This function requires an open connection to the calendar service by calendar_connect(). + * @see calendar_todo_delete_from_db() + * @see calendar_todo_update_to_db() + * + */ +int calendar_todo_insert_to_db(calendar_todo_h todo, int *todo_db_id); + +/** + * @brief Removes the to-do item from the calendar database. + * + * @param[in] todo_id The to-do ID to delete + * + * @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(). + * @see calendar_todo_insert_to_db() + * @see calendar_todo_update_to_db() + */ +int calendar_todo_delete_from_db(int todo_id); + +/** + * @brief Updates the to-do item on the calendar database. + * @details calendar_todo_get_db_id() is called internally to update the to-do item in the calendar database. + * + * @param[in] todo The calendar to-do handle + * + * @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(). + * + * @see calendar_todo_insert_to_db() + * @see calendar_todo_delete_from_db() + * @see calendar_todo_get_from_db() + * @see calendar_todo_get_db_id() + */ +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. + * A new calendar to-do handle will be created. + * + * @remarks The new to-do handle must be released with calendar_todo_destroy() by you. + * + * @param[in] todo_id The to-do Database ID + * @param[out] todo The calendar to-do handle + * + * @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_todo_destroy() + * @see calendar_todo_get_db_id() + */ +int calendar_todo_get_from_db(int todo_id, calendar_todo_h *todo); + +/** + * @brief Gets the database ID for the given calendar to-do handle. + * + * @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 + * + * @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() + * @see calendar_todo_delete_from_db() + */ +int calendar_todo_get_db_id(calendar_todo_h todo, int *todo_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. + * + * @param [in] todo The calendar to-do handle + * @param [out] subject The subject of the to-do \n If the subject 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 + * + * @see calendar_todo_set_subject() + */ +int calendar_todo_get_subject(calendar_todo_h todo, char **subject); + +/** + * @brief Sets a subject of the to-do handle. + * + * @param [in] todo The calendar to-do handle + * @param [in] subject The subject of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_subject() + */ +int calendar_todo_set_subject(calendar_todo_h todo, const char *subject); + +/** + * @brief Gets description of the to-do from the calendar to-do handle. + * + * @remarks @a description must be released with free() by you. + * + * @param [in] todo The calendar to-do handle + * @param [out] description The description of the to-do \n If the description 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 + * + * @see calendar_todo_set_description() + */ +int calendar_todo_get_description(calendar_todo_h todo, char **description); + +/** + * @brief Sets a description of the to-do in the calendar to-do handle. + * + * @param [in] todo The calendar to-do handle + * @param [in] description The description of the to-do + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_description() + * + */ +int calendar_todo_set_description(calendar_todo_h todo, const char *description); + +/** + * @brief Gets the priority for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[out] priority The priority of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_set_priority() + */ +int calendar_todo_get_priority(calendar_todo_h todo, calendar_todo_priority_e *priority); + +/** + * @brief Sets a priority for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[in] priority The priority of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_priority() + */ +int calendar_todo_set_priority(calendar_todo_h todo, calendar_todo_priority_e priority); + +/** + * @brief Gets the status for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[out] status The status of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_set_status() + */ +int calendar_todo_get_status(calendar_todo_h todo, calendar_todo_status_e *status); + +/** + * @brief Sets a status for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[in] status The status of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_status() + */ +int calendar_todo_set_status(calendar_todo_h todo, calendar_todo_status_e status); + +/** + * @brief Gets the visibility for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[out] visibility The visibility of the to-do \n (default : #CALENDAR_VISIBILITY_PUBLIC) + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_set_visibility() + */ +int calendar_todo_get_visibility(calendar_todo_h todo, calendar_visibility_e *visibility); + +/** + * @brief Sets a visibility for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[in] visibility The visibility of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_visibility() + */ +int calendar_todo_set_visibility(calendar_todo_h todo, calendar_visibility_e visibility); + +/** + * @brief Gets the location of the to-do from the calendar to-do handle. + * + * @remarks @a location must be released with free() by you. + * + * @param [in] todo The calendar to-do handle + * @param [out] location The location of the to-do \n If the location 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 + * + * @see calendar_todo_set_location() + * + */ +int calendar_todo_get_location(calendar_todo_h todo, char **location); + +/** + * @brief Sets a location of the to-do in the calendar to-do handle. + * + * @param [in] todo The calendar to-do handle + * @param [in] location The location of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_location() + */ +int calendar_todo_set_location(calendar_todo_h todo, const char *location); + +/** + * @brief Gets the last modified time of the to-do item. + * + * @param[in] todo The calendar to-do handle + * @param[out] modified_time The last modified time + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_todo_insert_to_db() + * @see calendar_todo_update_to_db() + * + */ +int calendar_todo_get_last_modified_time(calendar_todo_h todo, struct tm *modified_time); +/** + * @brief Gets the timezone details for the given calendar to-do handle. + * @remarks @a timezone_name must be released with free() by you. + * + * @param[in] todo The calendar to-do handle + * @param[out] timezone_name The time zone name eg. Europe/Paris + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_set_timezone() + * @see calendar_foreach_timezone() + */ +int calendar_todo_get_timezone(calendar_todo_h todo, char** timezone_name); + +/** + * @brief Sets the timezone for the given calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[in] timezone_name The timezone name eg. Europe/Paris + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_timezone() + * @see calendar_foreach_timezone() + */ +int calendar_todo_set_timezone(calendar_todo_h todo, const char* timezone_name); + +/** + * @brief Gets the start time of the to-do from the calendar to-do handle. + * + * @param [in] todo The calendar to-do handle + * @param [out] start_time The start date of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_todo_set_start_time() + */ +int calendar_todo_get_start_time(calendar_todo_h todo, struct tm *start_time); + +/** + * @brief Sets a start time of the to-do in the calendar to-do handle. + * + * @param [in] todo The calendar todo handle + * @param [in] start_time The start date of the todo + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_start_time() + * + */ +int calendar_todo_set_start_time(calendar_todo_h todo, struct tm start_time); + + +/** + * @brief Gets the due time of the to-do from the calendar to-do handle. + * + * @param [in] todo The calendar to-do handle + * @param [out] due_time The due date of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_NO_DATA Data not found + * + * @see calendar_todo_set_due_time() + * + */ +int calendar_todo_get_due_time(calendar_todo_h todo, struct tm *due_time); + +/** + * @brief Sets a due time of the to-do in the calendar to-do handle. + * + * @param[in] todo The calendar to-do handle + * @param[in] due_time The due date of the to-do + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_todo_get_due_time() + */ +int calendar_todo_set_due_time(calendar_todo_h todo, struct tm due_time); + +/** + * @brief Retrieves all to-do items 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_todo_cb(). + * + * @see calendar_foreach_query_todo_cb() + */ +int calendar_foreach_todo_from_db(calendar_foreach_query_todo_cb callback, void *user_data); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/calendar_attendee.h b/include/calendar_attendee.h new file mode 100755 index 0000000..8e4cf90 --- /dev/null +++ b/include/calendar_attendee.h @@ -0,0 +1,203 @@ +/* + * 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. + */ + + +#ifndef __TIZEN_SOCIAL_CALENDAR_CALENDAR_ATTENDEE_H__ +#define __TIZEN_SOCIAL_CALENDAR_CALENDAR_ATTENDEE_H__ + +#include <tizen.h> +#include <time.h> +#include <calendar_types.h> + + + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_ATTENDEE_MODULE + * @{ + */ + + +/** + * @brief Gets the name of the attendee. + * + * @remarks @a name must be released with free() by you. + * + * @param [in] attendee The attendee handle + * @param [out] name The name of the attendee \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 + * + * @see calendar_attendee_set_name() +*/ +int calendar_attendee_get_name(calendar_attendee_h attendee, char **name); + + +/** + * @brief Sets a name of the attendee. + * + * @param[in] attendee The attendee handle + * @param[in] name The name of the attendee + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_get_name() +*/ +int calendar_attendee_set_name(calendar_attendee_h attendee, const char *name); + +/** + * @brief Gets the email of the attendee. + * + * @remarks @a email must be released with free() by you. + * + * @param [in] attendee The attendee handle + * @param [out] email The email of the attendee \n If the email 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 + * + * @see calendar_attendee_set_email() + */ +int calendar_attendee_get_email(calendar_attendee_h attendee, char **email); + +/** + * @brief Sets a email of the attendee. + * + * @param[in] attendee The attendee handle + * @param[in] email The email of the attendee + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_get_email() + */ +int calendar_attendee_set_email(calendar_attendee_h attendee, const char *email); + +/** + * @brief Gets the phone number of the attendee. + * + * @remarks @a phone_number must be released with free() by you. + * + * @param [in] attendee The attendee handle + * @param [out] phone_number The phone number of the attendee \n If the phone number 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 + * + * @see calendar_attendee_set_phone_number() + */ +int calendar_attendee_get_phone_number(calendar_attendee_h attendee, char **phone_number); + +/** + * @brief Sets a phone number of the attendee. + * + * @param[in] attendee The attendee handle + * @param[in] phone_number The phone number of the attendee + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_get_phone_number() + */ +int calendar_attendee_set_phone_number(calendar_attendee_h attendee, const char *phone_number); + +/** + * @brief Gets the contact database ID associated with the given attendee handle. + * + * @param[in] attendee The calendar attendee handle + * @param[out] contact_db_id The contact database ID \n + * If the contact database ID has never set, @a contact_db_id is -1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_set_contact_db_id() + * @see calendar_event_add_attendee_with_contact() + * @see contact_get_db_id() + * @see contact_get_from_db() + */ +int calendar_attendee_get_contact_db_id(calendar_attendee_h attendee, int *contact_db_id); + +/** + * @brief Sets a contact database ID for the given attendee handle. + * + * @param[in] attendee The calendar attendee handle + * @param[in] contact_db_id The contact database ID + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see calendar_attendee_get_contact_db_id() + * @see contact_get_db_id() + * @see contact_get_from_db() + */ +int calendar_attendee_set_contact_db_id(calendar_attendee_h attendee, int contact_db_id); + +/** + * @brief Checks whether there is a next attendee handle on the list. + * + * @param [in] iterator The attendee iterator handle + * @return @c true If the next element exists or @c false If the next element doesn't exist + * + * @see calendar_event_get_attendee_iterator() + * @see calendar_attendee_iterator_next() +*/ +bool calendar_attendee_iterator_has_next(calendar_attendee_iterator_h iterator); + +/** + * @brief Moves attendee list iterator to the next position and gets attendee handle. + * @details If the next element for the current attendee list exists, then the iterator is moved to + * the next position on the list and the attendee handle for this position is returned. + * When the iterator reaches the last element of the list, all further calls will return + * #CALENDAR_ERROR_ITERATOR_END and @a attendee will remain unchanged. + * + * @param [in] iterator The attendee iterator handle + * @param [out] attendee The attendee handle + * + * @return 0 on success, otherwise a negative error value. + * @retval #CALENDAR_ERROR_NONE Successful + * @retval #CALENDAR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CALENDAR_ERROR_ITERATOR_END Iterator is on last position + * + * @see calendar_event_get_attendee_iterator() + * @see calendar_attendee_iterator_has_next() + */ +int calendar_attendee_iterator_next(calendar_attendee_iterator_h *iterator, calendar_attendee_h *attendee); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_SOCIAL_CALENDAR_CALENDAR_ATTENDEE_H__ */ diff --git a/include/calendar_private.h b/include/calendar_private.h new file mode 100755 index 0000000..505671c --- /dev/null +++ b/include/calendar_private.h @@ -0,0 +1,169 @@ +/* + * 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. + */ + + +#ifndef __TIZEN_SOCIAL_CALENDAR_PRIVATE_H__ +#define __TIZEN_SOCIAL_CALENDAR_PRIVATE_H__ + +#include <calendar.h> +#include <calendar_types.h> +//@20110427-vincent: real API +#include <calendar-svc-provider.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @internal + */ +typedef struct GList calendar_list_s; + +typedef struct { + int event_type; + void* user_data; +} calendar_event_legacy_s; + +typedef struct { + calendar_event_legacy_s* event_legacy; +} calendar_event_s; + +typedef struct +{ + int index; /**< Record index */ + int account_id; /**< Account_id */ + int cal_type; /**< Calendar event type */ + int sch_category; /**< Category of schedule */ + + char* summary; /**< Summary, appointment, task: subject, birthday:Name */ + char* description; /**< Description,appointment, task: description, anniversary,holiday:occasion*/ + char* location; /**< Location */ + GList* meeting_category; /**< collection of categories */ + bool all_day_event; /**< All day event flag */ + struct tm start_date_time; /**< schedule:start time, anniv,holiday,birthday,memo,todo: date */ + struct tm end_date_time; /**< end time */ + struct tm alarm_time; /**< alarm time */ + int remind_tick; /**< Alarms before remindTick */ + int remind_tick_unit; /**< Remind tick unit */ + char* alarm_tone; /**< Alert Sound File Name */ + int alarm_type; /**< Alert type(see 'cal_alert_type_t') */ + int alarm_id; /**< Alarm id */ + int repeat_term; /**< Repeat term */ + int repeat_interval; /**< Interval of repeat term */ + int repeat_occurrences; /**< occurrences of repeat */ + struct tm repeat_end_date; /**< End date for repeat */ + int sun_moon; /**< Using sun or lunar calendar */ + int week_start; /**< Start day of a week */ + char* week_flag;//[DAY_OF_A_WEEK + 1]; /**< Indicate which day is select in a week */ + int day_date; /**< 0- for weekday(sun,mon,etc.), 1- for specific day(1,2.. Etc) */ + struct tm last_modified_time; /**< for PC Sync */ + bool missed; /**< Miss alarm flag */ + int task_status; /**< current task status */ + int priority; /**< Priority */ + int timezone; /**< timezone of task */ + int file_id; /**< file id for attach or alarm tone*/ + int contact_id; /**< contact id for birthday in contact list */ + GList* attendee_list; /**< collection of attendee */ + int busy_status; /**< ACS, G : Flag of busy or not */ + int visibility; /**< ACS, G : The visibility of the task item (normal, presonal, private, confidential). */ + int meeting_status; /**< ACS, G : The status of the meeting. */ + char* uid; /**< ACS, G : Unique ID of the meeting item */ + char* organizer_name; /**< ACS, G : Name of organizer(author) */ + char* organizer_email; /**< ACS, G : Email of organizer */ + int calendar_type; /**< ACS, G : Type(all,phone,google) of calendar */ + char* gcal_id; /**< G : Server id of calendar */ + bool deleted; /**< G : Flag for deleted */ + char* updated; /**< G : Updated time stamp */ + int location_type; /**< G : Location type */ + char* location_summary; /**< G : A simple string value that can be used as a representation of this location */ + char* etag; /**< G : ETAG of this event */ + int calendar_id; /**< G : id to map from calendar table */ + int sync_status; /**< G : Indication for event entry whether added/ modified/ deleted */ + char* edit_uri; /**< G : EditUri for google calendar */ + char* gevent_id; /**< G : Server id of an event */ + int dst; /**< dst of event */ + GList* exception_date_list; /**< exception dates */ + int original_event_id; /**< original event id for recurrency exception */ + double latitude; + double longitude; + char* tz_name; + int is_deleted; +}calendar_schedule_s; + + +typedef struct { + int v_type; + void* user_data; + }calendar_attendee_s; + +typedef struct +{ + int event_id; + char* attendee_name; + char* attendee_email; + int attendee_status; + int attendee_type; + int attendee_ct_index; + 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); + +/** +* Internal Macros +*/ + +#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) { \ + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); \ + return CALENDAR_ERROR_INVALID_PARAMETER; \ + } \ +}while(0) + + +#ifdef __cplusplus +} +#endif + +#endif //__TIZEN_SOCIAL_CALENDAR_PRIVATE_H__ + + + diff --git a/include/calendar_types.h b/include/calendar_types.h new file mode 100755 index 0000000..9390764 --- /dev/null +++ b/include/calendar_types.h @@ -0,0 +1,271 @@ +/* + * 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. + */ + + +#ifndef __TIZEN_SOCIAL_CALENDAR_TYPES_H__ +#define __TIZEN_SOCIAL_CALENDAR_TYPES_H__ + +#include <stdbool.h> +#include <tizen.h> +#include <time.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_MODULE + * @{ + */ + +/** + * @brief Enumerations for calendar error type. + */ +typedef enum +{ + CALENDAR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + CALENDAR_ERROR_DB_FAILED = TIZEN_ERROR_SOCIAL_CLASS | 0x02, /**< No access to database */ + CALENDAR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + CALENDAR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + CALENDAR_ERROR_NO_DATA = TIZEN_ERROR_SOCIAL_CLASS | 0x03, /**< Requested data does not exist */ + CALENDAR_ERROR_ITERATOR_END = TIZEN_ERROR_SOCIAL_CLASS | 0x04, /**< Iterator is on last position */ +} calendar_error_e; + +/** + * @brief Enumerations for calendar visibility type. + */ +typedef enum +{ + CALENDAR_VISIBILITY_PUBLIC = 0, /**< Public visibility */ + CALENDAR_VISIBILITY_PRIVATE, /**< Private visibility */ + CALENDAR_VISIBILITY_CONFIDENTIAL /**< Confidential visibility */ +} calendar_visibility_e; + +/** + * @brief Enumerations for calendar timezone details. + */ +typedef struct +{ + char* timezone_name; /**< Timezone name eg. Europe/Paris */ + char* city_name; /**< City name eg. Paris */ + char* country_name; /**< Country name eg. France */ + char* time_offset; /**< Time offset eg. GMT+1 */ + char* timezone_detail_filepath; /**< Timezone detail file path eg. /.../Europe/Paris */ +}calendar_foreach_timezone_s ; + +/** + * @brief Called once for each timezone supported on a device. + * + * @param[out] timezone The timezone information + * @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 return @c false to break out of the loop. + * + * @pre calendar_foreach_timezone() will invoke this callback. + * + * @see calendar_foreach_timezone() + */ +typedef bool (*calendar_foreach_timezone_cb)(calendar_foreach_timezone_s *timezone, void *user_data); +/** + * @} + */ + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_ATTENDEE_MODULE + * @{ + */ + + /** + * @brief The calendar attendee handle. + * @see calendar_event_add_attendee() + * @see calendar_event_remove_attendee() + */ +typedef struct calendar_attendee_s *calendar_attendee_h; /* cal_value */ + + /** + * @brief The event attendee iterator. + * @see calendar_event_get_attendee_iterator() + */ +typedef struct calendar_list_s *calendar_attendee_iterator_h; + +/** + * @} + */ + + + /** + * @addtogroup CAPI_SOCIAL_CALENDAR_EVENT_MODULE + * @{ + */ + +/** + * @brief The calendar event handle. + */ +typedef struct calendar_event_s *calendar_event_h; + +/** + * @brief The calendar recurrence exception iterator handle. + * @see calendar_event_get_recurrence_exception_iterator() + */ +typedef struct calendar_list_s *calendar_recurrence_exception_iterator_h; + +/** + * @brief Reminder interval type of event such as minutes, hours, days, or etc. + */ +typedef enum +{ + CALENDAR_REMINDER_NONE = -1, /**< No reminder set */ + CALENDAR_REMINDER_TIME_UNIT_MINUTE = 0, /**< Reminder interval in minutes */ + CALENDAR_REMINDER_TIME_UNIT_HOUR, /**< Reminder interval in hours */ + CALENDAR_REMINDER_TIME_UNIT_DAY, /**< Reminder interval in days */ + CALENDAR_REMINDER_TIME_UNIT_WEEK, /**< Reminder interval in weeks */ + CALENDAR_REMINDER_TIME_UNIT_MONTH, /**< Reminder interval in months */ +} calendar_reminder_interval_type_e; + + +/** + * @brief Enumerations of the frequency of event recurrence. + */ +typedef enum +{ + CALENDAR_RECURRENCE_NONE, /**< No recurrence event */ + CALENDAR_RECURRENCE_DAILY, /**< A Event occurs every day */ + CALENDAR_RECURRENCE_WEEKLY, /**< A Event occurs on the same day of every week \n According to week flag, the event will recurrence every days of week */ + CALENDAR_RECURRENCE_MONTHLY, /**< A Event occurs on the same day of every month */ + CALENDAR_RECURRENCE_YEARLY, /**< A Event occurs on the same day of every year */ +} calendar_recurrence_frequency_e; + +/** + * @brief Enumerations of weekly recurrence event which days of week will be repeated. + */ +typedef enum +{ + CALENDAR_WEEK_FLAG_NONE = 0x00, /**< No repetition */ + CALENDAR_WEEK_FLAG_SUN = 0x01, /**< Repeat event each Sunday */ + CALENDAR_WEEK_FLAG_MON = 0x02, /**< Repeat event each Monday */ + CALENDAR_WEEK_FLAG_TUE = 0x04, /**< Repeat event each Tuesday */ + CALENDAR_WEEK_FLAG_WED = 0x08, /**< Repeat event each Wednesday */ + CALENDAR_WEEK_FLAG_THU = 0x10, /**< Repeat event each Thursday */ + CALENDAR_WEEK_FLAG_FRI = 0x20, /**< Repeat event each Friday */ + CALENDAR_WEEK_FLAG_SAT = 0x40, /**< Repeat event each Saturday */ + CALENDAR_WEEK_FLAG_ALL = 0xFF /**< Repeat event every day */ +} calendar_week_flag_e; + +/** + * @brief Called once for each event returned from the query. + * + * @param[in] event The calendar event handle + * @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 return @c false to break out of the loop. + * + * @pre calendar_foreach_event_from_db() will invoke this callback. + * @pre calendar_query_event_by_subject() will invoke this callback. + * @pre calendar_query_event_by_description() will invoke this callback. + * @pre calendar_query_event_by_location() will invoke this callback. + * @pre calendar_query_event_by_period() will invoke this callback. + * @pre calendar_query_event_by_time_last_modified() will invoke this callback. + * + * @see calendar_query_event_by_subject() + * @see calendar_query_event_by_description() + * @see calendar_query_event_by_location() + * @see calendar_query_event_by_period() + * @see calendar_foreach_event_from_db() + */ +typedef bool (*calendar_foreach_query_event_cb)(calendar_event_h event, void *user_data); + +/** + * @} + */ + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_MODULE + * @{ + */ + +/** + * @brief Called when any database changes has occurred. + * + * @param[in] user_data The user data passed from the callback registration function + * + * @pre calendar_set_db_changed_cb() will invoke this callback. + * @pre calendar_event_insert_to_db(), calendar_event_delete_from_db() or calendar_event_update_to_db() will invoke this callback. + * + * @see calendar_set_db_changed_cb() + * @see calendar_unset_db_changed_cb() + * @see calendar_event_insert_to_db() + * @see calendar_event_delete_from_db() + * @see calendar_event_update_to_db() + */ +typedef void (*calendar_db_changed_cb)(void *user_data); + +/** + * @} + */ + + +/** + * @addtogroup CAPI_SOCIAL_CALENDAR_TODO_MODULE + * @{ + */ +/** + * @brief The calendar to-do handle. + */ +typedef struct calendar_event_s *calendar_todo_h; + +/** + * @brief Calendar to-do item priority + */ +typedef enum +{ + CALENDAR_TODO_PRIORITY_LOW = 0, /**< Low priority */ + CALENDAR_TODO_PRIORITY_NORMAL, /**< Normal priority */ + CALENDAR_TODO_PRIORITY_HIGH /**< High priority */ +} calendar_todo_priority_e; + +typedef enum +{ + CALENDAR_TODO_STATUS_NONE = 0, /**< None */ + CALENDAR_TODO_STATUS_NEEDS_ACTION, /**< Needs action status */ + CALENDAR_TODO_STATUS_COMPLETED, /**< Completed status */ + CALENDAR_TODO_STATUS_IN_PROCESS, /**< Work in process status */ + CALENDAR_TODO_STATUS_CANCELED /**< Canceled status */ +} calendar_todo_status_e; + +/** + * @brief Called once for each calendar to-do item. + * + * @param[in] todo The calendar to-do handle + * @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 return @c false to break out of the loop. + * + * @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); +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_SOCIAL_CALENDAR_TYPES_H__ */ diff --git a/packaging/capi-social-calendar.spec b/packaging/capi-social-calendar.spec new file mode 100755 index 0000000..eec912a --- /dev/null +++ b/packaging/capi-social-calendar.spec @@ -0,0 +1,56 @@ +Name: capi-social-calendar +Summary: Calendar library in Tizen Native API +Version: 0.0.1 +Release: 1 +Group: TO_BE/FILLED_IN +License: TO BE FILLED IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(calendar) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(alarm-service) +BuildRequires: pkgconfig(capi-social-contacts) +BuildRequires: pkgconfig(capi-base-common) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + + +%package devel +Summary: Calendar library in Tizen Native API (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel + + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%{_libdir}/libcapi-social-calendar.so + +%files devel +%{_includedir}/social/*.h +%{_libdir}/pkgconfig/*.pc + + diff --git a/src/calendar.c b/src/calendar.c new file mode 100755 index 0000000..1e73ed1 --- /dev/null +++ b/src/calendar.c @@ -0,0 +1,2115 @@ +/* + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <calendar.h> +#include <calendar_private.h> + +#include <calendar-svc-provider.h> +#include <dlog.h> +#include <contacts.h> + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "TIZEN_N_CALENDAR" +#define LOG_MODE (1) + +/* +* Public Implementation +*/ +int calendar_connect(void) +{ + int ret_val = calendar_svc_connect(); + + if (ret_val == CAL_SUCCESS) { + return CALENDAR_ERROR_NONE; + } else { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } +} + +int calendar_disconnect(void) +{ + int ret_val = calendar_svc_close(); + + if (ret_val == CAL_SUCCESS) { + return CALENDAR_ERROR_NONE; + } else { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } +} + +int calendar_event_insert_to_db(calendar_event_h event, int *event_id) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(event_id); + + ret_val = -1; + ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)event)->event_legacy); + if (ret_val < 0) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + *event_id = ret_val; + + return CALENDAR_ERROR_NONE; +} + +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; + } + + int ret_val = CALENDAR_ERROR_NONE; + + ret_val = calendar_svc_delete(CAL_STRUCT_SCHEDULE, event_id); + + if (ret_val == CAL_SUCCESS) { + ret_val = CALENDAR_ERROR_NONE; + } + else { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + ret_val = CALENDAR_ERROR_DB_FAILED; + } + + return ret_val; +} + + +int calendar_event_update_to_db(calendar_event_h 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; + } + + int event_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_TABLE_INT_INDEX); + if(event_id <= 0) { + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); + return CALENDAR_ERROR_INVALID_PARAMETER; + } + + cal_struct* cal = NULL; + if(calendar_svc_get(CAL_STRUCT_SCHEDULE, event_id, NULL, &cal) == CAL_SUCCESS) { // referenced (SVACE) + if( ((calendar_schedule_s*)((calendar_event_legacy_s*)cal)->user_data)->is_deleted == true ) { // referenced (SVACE) + if(cal != NULL) { // referenced (SVACE) + calendar_svc_struct_free(&cal); + } + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); + return CALENDAR_ERROR_INVALID_PARAMETER; + } else { + if(cal != NULL) { // referenced (SVACE) + calendar_svc_struct_free(&cal); + } + } + } else { + if(cal != NULL) { // referenced (SVACE) + calendar_svc_struct_free(&cal); + } + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); + return CALENDAR_ERROR_INVALID_PARAMETER; + } + + ret_val = calendar_svc_update((cal_struct*)((calendar_event_s*)event)->event_legacy); + + if (ret_val != CAL_SUCCESS) { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + + 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); + *event = malloc(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; + } + + memset(*event, 0, sizeof(calendar_event_s)); + if(calendar_svc_get(CAL_STRUCT_SCHEDULE, event_id, NULL, (cal_struct**)&(*(calendar_event_s**)event)->event_legacy) != CAL_SUCCESS) { + free(*event); + *event = 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_event_get_db_id(calendar_event_h event, int *db_id) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(db_id); + + *db_id = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, (char*)CAL_VALUE_INT_INDEX); + if(*db_id < 0) + *db_id = 0; + return CALENDAR_ERROR_NONE; +} + +int calendar_event_get_total_count_from_db(int *count) +{ + CALENDAR_NULL_ARG_CHECK(count); + + *count = calendar_svc_get_count(0, 0, (char*)CAL_STRUCT_SCHEDULE); + if(*count == CAL_ERR_FAIL) + { + *count = 0; + 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_create (calendar_event_h *event) +{ + CALENDAR_NULL_ARG_CHECK(event); + + *event = malloc(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; + } + calendar_svc_struct_set_int((cal_struct*)(*(calendar_event_s**)event)->event_legacy, CAL_VALUE_INT_TIMEZONE, 100); // set default timezone + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_destroy(calendar_event_h event) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)event)->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(event); + ret_val = CALENDAR_ERROR_NONE; + } + + return ret_val; +} + +int calendar_event_get_subject(calendar_event_h event, char **subject) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(subject); + + *subject = NULL; + *subject = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_SUMMARY)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_subject(calendar_event_h event,const char *subject) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_SUMMARY, subject); + + if (ret_val != 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); + + *description = NULL; + *description = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_DESCRIPTION)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_description(calendar_event_h event, const char *description) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_DESCRIPTION, description); + + if (ret_val != 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); + + *is_all_day_event = (bool)calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_INT_ALL_DAY_EVENT); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_is_all_day_event(calendar_event_h event, bool is_all_day_event) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_INT_ALL_DAY_EVENT, is_all_day_event); + if (ret_val != 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_location(calendar_event_h event, char **location) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(location); + + *location = NULL; + *location = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_TXT_LOCATION)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_location(calendar_event_h event, const char *location) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_TXT_LOCATION, location); + + if (ret_val != 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_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); + + *reminder_interval_type = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_INT_ALARM_TICK_UNIT); + *reminder_interval = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_INT_ALARM_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); + + cal_value *value = calendar_svc_value_new(CAL_VALUE_LST_ALARM); + if(calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARM_TICK_UNIT, reminder_interval_type) != 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; + } + + if(calendar_svc_value_set_int(value, CAL_VALUE_INT_ALARMS_TICK, reminder_interval) != 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; + } + + GList* list = NULL; + calendar_svc_struct_store_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_ALARM, NULL); + list = g_list_append(list, value); + + if(calendar_svc_struct_store_list((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_LST_ALARM, list) != 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); + + *recurrence_frequency = (calendar_recurrence_frequency_e)calendar_svc_struct_get_int( + (cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_REPEAT_TERM); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_recurrence_frequency(calendar_event_h event,calendar_recurrence_frequency_e recurrence_frequency) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + calendar_event_legacy_s* event_legacy = ((calendar_event_s*)event)->event_legacy; + + ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_TERM, recurrence_frequency); + switch(recurrence_frequency) + { + case CALENDAR_RECURRENCE_DAILY: + ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_INTERVAL, 1); + break; + case CALENDAR_RECURRENCE_WEEKLY: + ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_INTERVAL, 1); + break; +// case CALENDAR_RECURRENCE_WEEKDAY: +// ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_INTERVAL, 1); +// break; + case CALENDAR_RECURRENCE_NONE: + ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_INTERVAL, 1); + break; + case CALENDAR_RECURRENCE_MONTHLY: + case CALENDAR_RECURRENCE_YEARLY: +// case CALENDAR_RECURRENCE_MONTHLY_ON_DAY: + ret_val = calendar_svc_struct_set_int((cal_struct*)event_legacy, CAL_VALUE_INT_REPEAT_INTERVAL, 1); + break; + } + + if (ret_val != 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_flag(calendar_event_h event, int *week_flag) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(week_flag); + + char* week_flag_string = calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_WEEK_FLAG); + + if(week_flag_string == NULL) { + *week_flag = 0; + return CALENDAR_ERROR_NONE; + } + + *week_flag = CALENDAR_WEEK_FLAG_NONE; + if(week_flag_string[0] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_SUN; + if(week_flag_string[1] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_MON; + if(week_flag_string[2] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_TUE; + if(week_flag_string[3] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_WED; + if(week_flag_string[4] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_THU; + if(week_flag_string[5] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_FRI; + if(week_flag_string[6] == '1') + *week_flag = *week_flag | CALENDAR_WEEK_FLAG_SAT; + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_recurrence_week_flag(calendar_event_h event, int week_flag) +{ + CALENDAR_NULL_ARG_CHECK(event); + + char week_flag_string[8]; // never overflows + if(week_flag & CALENDAR_WEEK_FLAG_SUN) week_flag_string[0] = '1'; + else week_flag_string[0] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_MON) week_flag_string[1] = '1'; + else week_flag_string[1] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_TUE) week_flag_string[2] = '1'; + else week_flag_string[2] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_WED) week_flag_string[3] = '1'; + else week_flag_string[3] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_THU) week_flag_string[4] = '1'; + else week_flag_string[4] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_FRI) week_flag_string[5] = '1'; + else week_flag_string[5] = '0'; + if(week_flag & CALENDAR_WEEK_FLAG_SAT) week_flag_string[6] = '1'; + else week_flag_string[6] = '0'; + week_flag_string[7] = 0x00; + + calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_WEEK_FLAG, week_flag_string); //days in which recurrence should be activated + + return CALENDAR_ERROR_NONE; +} + + +int calendar_event_get_recurrence_until_date(calendar_event_h event, struct tm *recurrence_until_date) +{ + time_t time; + struct tm *tmp_date = NULL; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(recurrence_until_date); + + time = calendar_svc_struct_get_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_REPEAT_END_DATE, CAL_TZ_FLAG_LOCAL); + + if(time == 0) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + tmp_date = localtime(&time); + + if (tmp_date == NULL) { + return CALENDAR_ERROR_NO_DATA; + } + + *recurrence_until_date = *tmp_date; + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_recurrence_until_date(calendar_event_h event, struct tm recurrence_until_date) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_REPEAT_END_DATE, CAL_TZ_FLAG_LOCAL, mktime(&recurrence_until_date)); + + if (ret_val != 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_recurrence_exception_date(calendar_event_h event, int year, int month, int day) +{ + CALENDAR_NULL_ARG_CHECK(event); + + int ret_val = CALENDAR_ERROR_NONE; + GList* exception_list = NULL; + struct tm date = {0}; + date.tm_year = year - 1900; + date.tm_mon = month - 1; + date.tm_mday = day; + + cal_value *value = calendar_svc_value_new(CAL_VALUE_LST_EXCEPTION_DATE); + if(value == NULL) { + LOGE("[%s] CALENDAR_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CALENDAR_ERROR_OUT_OF_MEMORY); + return CALENDAR_ERROR_OUT_OF_MEMORY; + } + calendar_svc_value_set_tm(value, CAL_VALUE_GMT_EXCEPTION_DATE_TIME, CAL_TZ_FLAG_LOCAL, &date); + + //get attendee list firstly + calendar_svc_struct_get_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_EXCEPTION_DATE, &exception_list); + exception_list = g_list_append(exception_list, value); + ret_val = calendar_svc_struct_store_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_EXCEPTION_DATE, exception_list); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_get_recurrence_exception_iterator(calendar_event_h event, calendar_recurrence_exception_iterator_h *iterator) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(iterator); + + GList* exception_list = NULL; + //get attendee list first + calendar_svc_struct_get_list((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_EXCEPTION_DATE, &exception_list); + *iterator = (calendar_recurrence_exception_iterator_h)exception_list; + + return CALENDAR_ERROR_NONE; +} + +bool calendar_recurrence_exception_has_next(calendar_recurrence_exception_iterator_h iterator) +{ + CALENDAR_NULL_ARG_CHECK(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_recurrence_exception_next(calendar_recurrence_exception_iterator_h *iterator, int* year, int* month, int* day) +{ + CALENDAR_NULL_ARG_CHECK(iterator); + CALENDAR_NULL_ARG_CHECK(year); + CALENDAR_NULL_ARG_CHECK(month); + CALENDAR_NULL_ARG_CHECK(day); + + cal_value *value = NULL; + *year = 0; + *month = 0; + *day = 0; + GList* glist = (GList*)*iterator; + glist = _calendar_glist_next_until_not_deleted(glist); + if(glist != NULL) + { + value = glist->data; + struct tm *date = calendar_svc_value_get_tm(value, CAL_VALUE_GMT_EXCEPTION_DATE_TIME, CAL_TZ_FLAG_LOCAL); + *year = date->tm_year + 1900; + *month = date->tm_mon + 1; + *day = date->tm_mday; + glist = g_list_next(glist); + *iterator = (calendar_recurrence_exception_iterator_h)glist; + return CALENDAR_ERROR_NONE; + } + *iterator = NULL; + return CALENDAR_ERROR_ITERATOR_END; +} + +int calendar_event_get_start_time(calendar_event_h event, struct tm *start_time) +{ + time_t time; + struct tm *tmp_date = NULL; + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(start_time); + + time = calendar_svc_struct_get_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL); + + if(time == 0) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + tmp_date = localtime(&time); + + if (tmp_date == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + *start_time = *tmp_date; + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_start_time(calendar_event_h event, struct tm start_time) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL, mktime(&start_time)); + + if (ret_val != 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, struct tm *end_time) +{ + time_t time; + struct tm *tmp_date = NULL; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(end_time); + + time = calendar_svc_struct_get_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL); + + if(time == 0) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + tmp_date = localtime(&time); + + if (tmp_date == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + *end_time = *tmp_date; + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_end_time(calendar_event_h event, struct tm end_time) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_time((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL, mktime(&end_time)); + + if (ret_val != 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 = NULL; + *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_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(attendee); + + ret_val = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, name); + + if (ret_val != 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 = NULL; + *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_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(attendee); + CALENDAR_NULL_ARG_CHECK(email); + + ret_val = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, email); + + if (ret_val != 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 = NULL; + *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_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(attendee); + CALENDAR_NULL_ARG_CHECK(phone_number); + + ret_val = calendar_svc_value_set_str((cal_value*)attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER, phone_number); + + if (ret_val != 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) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(attendee); + + ret_val = calendar_svc_value_set_int((cal_value*)attendee, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX, contact_db_id); + if (ret_val != 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) +{ + int ret_val = CALENDAR_ERROR_NONE; + GList* attendee_list = NULL; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(attendee); + + *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((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_LST_ATTENDEE_LIST, &attendee_list); + attendee_list = g_list_append(attendee_list, *attendee); + ret_val = calendar_svc_struct_store_list((cal_struct*)((calendar_event_s*)event)->event_legacy, 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_val = 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_val = 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_query_event_by_subject(calendar_foreach_query_event_cb callback, 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); +} + +int calendar_query_event_by_description(calendar_foreach_query_event_cb callback, 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); +} + +int calendar_query_event_by_location(calendar_foreach_query_event_cb callback, 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); +} + +int calendar_query_event_by_period(calendar_foreach_query_event_cb callback, 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; + + //fetch from DB + ret_val = calendar_svc_get_event_list_by_tm_period (0, 0, &start_time, &end_time, &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); + break; + } + + //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_set_db_changed_cb(calendar_db_changed_cb callback, void* user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + if(calendar_svc_subscribe_change(callback, user_data) == 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_unset_db_changed_cb(calendar_db_changed_cb callback) +{ + CALENDAR_NULL_ARG_CHECK(callback); + if(calendar_svc_unsubscribe_change(callback) == 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_event_get_last_modified_time(calendar_event_h event, struct tm *reviedtime) +{ + struct tm *tmp_date = NULL; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(reviedtime); + + tmp_date = calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_GMT_LAST_MODIFIED_TIME, CAL_TZ_FLAG_LOCAL); + + if (tmp_date == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + *reviedtime = *tmp_date; + + 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_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_INT_SENSITIVITY, visibility); + if (ret_val != 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_query_event_by_time_last_modified(calendar_foreach_query_event_cb callback, struct tm time, void *user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + int ret_val = 0; + cal_iter* iter = NULL; + bool callback_return = true; + + //fetch from DB + time_t timestamp = mktime(&time); + ret_val = calendar_svc_get_updated_event_list (0, timestamp, &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); + break; + } + + //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_timezone(calendar_event_h event, char** timezone_name) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(timezone_name); + +// *timezone_offset = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, +// CAL_VALUE_INT_TIMEZONE); + *timezone_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)event)->event_legacy, + CAL_VALUE_TXT_TZ_NAME)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_event_set_timezone(calendar_event_h event, const char* timezone_name) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(timezone_name); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_INT_TIMEZONE, 0); + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)event)->event_legacy, CAL_VALUE_TXT_TZ_NAME, timezone_name); + if (ret_val != CAL_SUCCESS) + { + LOGE("[%s] CALENDAR_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CALENDAR_ERROR_INVALID_PARAMETER); + return CALENDAR_ERROR_INVALID_PARAMETER; + } + + return CALENDAR_ERROR_NONE; +} + +typedef struct _calendar_time_zone_st _calendar_time_zone_s; +struct _calendar_time_zone_st +{ + char* city; + char* country; + char* gmt; + char* tz_path; +}; +const _calendar_time_zone_s _calendar_time_zone_array[] = +{ + {"Abidjan", "Ivory Coast", "GMT+0", "Africa/Abidjan"}, + {"Abu Dhabi", "United Arab Emirates", "GMT+4", "Asia/Dubai"}, + {"Accra", "Ghana", "GMT-10", "Africa/Accra"}, + {"Addis Ababa", "Ethiopia", "GMT+3", "Africa/Addis_Ababa"}, + {"Adelaide", "Australia", "GMT+9:30", "Australia/Adelaide"}, + {"Alaska", "United States of America", "GMT-9", "America/Nome"}, + {"Algiers", "Algeria", "GMT+1", "Africa/Algiers"}, + {"Almaty", "Kazakhstan", "GMT+6", "Asia/Almaty"}, + {"Ambon", "Indonesia", "GMT+1", "Asia/Jayapura"}, + {"Amman", "Jordan", "GMT+2", "Asia/Amman"}, + {"Amsterdam", "Netherlands", "GMT+1", "Europe/Amsterdam"}, + {"Anadyr", "Russia ", "GMT+12", "Asia/Anadyr"}, + {"Anchorage", "United States of America", "GMT-9", "America/Anchorage"}, + {"Ankara", "Turkey", "GMT+2", "Asia/Istanbul"}, + {"Antananarivo", "Madagascar", "GMT+3", "Indian/Antananarivo"}, + {"Ashgabat", "Turkmenistan", "GMT+5", "Asia/Ashgabat"}, + {"Asmera", "Eritrea", "GMT+3", "Africa/Asmara"/* not in zone.tab */ }, + {"Astana", "Kazakhstan", "GMT+6", "Asia/Almaty"/* not in zone.tab */ }, + {"Asuncion", "Paraguay", "GMT-4", "America/Asuncion"}, + {"Athens", "Greece", "GMT+2", "Europe/Athens"}, + {"Auckland", "New Zealand", "GMT+12", "Pacific/Auckland"}, + {"Austin", "United States of America", "GMT-6", "CST6CDT"}, + {"Azores", "Portugal", "GMT-1", "Atlantic/Azores"}, + {"Baghdad", "Iraq", "GMT+3", "Asia/Baghdad"}, + {"Baku", "Azerbaijan", "GMT+4", "Asia/Baku"}, + {"Baltimore", "United States of America", "GMT-5", "EST5EDT"}, + {"Bamako", "Mali", "GMT+0", "Africa/Bamako"}, + {"Bangkok", "Thailand", "GMT+7", "Asia/Bangkok"}, + {"Bangui", "Central African Republic", "GMT+1", "Africa/Bangui"}, + {"Barcelona", "Spain", "GMT+2", "Europe/Madrid"}, + {"Bari", "Italy", "GMT+1", "Europe/Rome"}, + {"Basse-Terre", "Guadeloupe", "GMT-4", "America/Guadeloupe"}, + {"Beijing", "China", "GMT+8", "Asia/Shanghai"}, + {"Beirut", "Lebanon", "GMT+2", "Asia/Beirut"}, + {"Belgrade", "Serbia", "GMT+1", "Europe/Belgrade"}, + {"Belize City", "Belize", "GMT-6", "America/Belize"}, + {"Berlin", "Germany", "GMT+1", "Europe/Berlin"}, + {"Bern", "Switzerland", "GMT+1", "Europe/Zurich"}, + {"Bishkek", "Kyrgyzstan", "GMT+6", "Asia/Bishkek"}, + {"Bissau", "Guinea Bissau", "GMT+0", "Africa/Bissau"}, + {"Bogota", "Colombia", "GMT-5", "America/Bogota"}, + {"Bologna", "Italy", "GMT+1", "Europe/Rome"}, + {"Boston", "United States of America", "GMT-5", "EST5EDT"}, + {"Brasilia", "Brazil", "GMT-3", "America/Sao_Paulo"}, + {"Bratislava", "Slovakia", "GMT+2", "Europe/Bratislava"}, + {"Bridgetown", "Barbados", "GMT-4", "America/Barbados"}, + {"Brisbane", "Australia", "GMT+10", "Australia/Brisbane"}, + {"Brussels", "Belgium", "GMT+1", "Europe/Brussels"}, + {"Bucharest", "Romania", "GMT+3", "Europe/Bucharest"}, + {"Budapest", "Hungary", "GMT+1", "Europe/Budapest"}, + {"Buenos Aires", "Argentina", "GMT-3", "America/Argentina/Buenos_Aires"}, + {"Cairo", "Egypt", "GMT+2", "Africa/Cairo"}, + {"Calgary", "Canada", "GMT-7", "MST7MDT"}, + {"Canary Islands", "Spain", "GMT+0", "Atlantic/Canary"}, + {"Canberra", "Australia", "GMT+10", "Australia/Canberra"}, + {"Canton", "China", "GMT+8", "Asia/Shanghai"}, + {"Cape Town", "Republic of South Africa", "GMT+2", "Africa/Johannesburg"}, + {"Caracas", "Venezuela", "GMT-4:30", "America/Caracas"}, + {"Cardiff", "Wales", "GMT+0", "Europe/London"}, + {"Casablanca", "Morocco", "GMT+0", "Africa/Casablanca"}, + {"Catanzaro", "Italy", "GMT+1", "Europe/Rome"}, + {"Cayenne", "French Guiana", "GMT-3", "America/Cayenne"}, + {"Charlotte", "United States of America", "GMT-5", "EST5EDT"}, + {"Charlotte Amalie", "United States Virgin Islands ", "GMT-5:30", "America/St_Thomas"}, + {"Chelyabinsk", "Russia ", "GMT+5", "Asia/Yekaterinburg"}, + {"Chennai", "India", "GMT+5:30", "Asia/Kolkata"}, + {"Chicago", "United States of America", "GMT-6", "America/Chicago"}, + {"Chisinau", "Moldova", "GMT+2", "Europe/Chisinau"}, + {"Chita", "Russia", "GMT+9", "Asia/Yakutsk"}, + {"Cleveland", "United States of America", "GMT-5", "EST5EDT"}, + {"Colombo", "Sri Lanka", "GMT+5:30", "Asia/Colombo"}, + {"Columbus", "United States of America", "GMT-5", "EST5EDT"}, + {"Conakry", "Guinea", "GMT+1", "Africa/Conakry"}, + {"Copenhagen", "Denmark", "GMT+1", "Europe/Copenhagen"}, + {"Cork", "Ireland", "GMT+0", "Europe/Dublin"}, + {"Crotone", "Italy", "GMT+1", "Europe/Rome"}, + {"Dakar", "Senegal", "GMT+0", "Africa/Dakar"}, + {"Dallas", "United States of America", "GMT-6", "CST6CDT"}, + {"Damascus", "Syria", "GMT+2", "Asia/Damascus"}, + {"Dar es Salaam", "Tanzania", "GMT+3", "Africa/Dar_es_Salaam"}, + {"Darwin", "Australia", "GMT+9:30", "Australia/Darwin"}, + {"Delhi", "India", "GMT+5:30", "Asia/Kolkata"}, + {"Denpasar", "Indonesia", "GMT+8", "Asia/Makassar"}, + {"Denver", "United States of America", "GMT-7", "America/Denver"}, + {"Detroit", "United States of America", "GMT-5", "America/Detroit"}, + {"Dhaka", "Bangladesh", "GMT+6", "Asia/Dhaka"}, + {"Diego Garcia", "United Kingdom", "GMT+5", "Indian/Chagos"/* not in zone.tab */ }, + {"Djibouti", "Djibouti", "GMT+3", "Africa/Djibouti"}, + {"Doha", "Qatar", "GMT+3", "Asia/Qatar"}, + {"Douala", "Cameroon", "GMT+1", "Africa/Douala"}, + {"Dubai", "United Arab Emirates", "GMT+4", "Asia/Dubai"}, + {"Dublin", "Ireland", "GMT+0", "Europe/Dublin"}, + {"Dushanbe", "Tajikistan", "GMT+5", "Asia/Dushanbe"}, + {"Easter Island", "Chile", "GMT-6", "Pacific/Easter"}, + {"Edinburgh", "Scotland", "GMT+0", "Europe/London"}, + {"El Paso", "United States of America", "GMT-7", "MST7MDT"}, + {"Florence", "Italy", "GMT+1", "Europe/Rome"}, + {"Fort-de-France", "Martinique", "GMT-4", "America/Martinique"}, + {"Freetown", "Sierra Leone", "GMT+0", "Africa/Freetown"}, + {"Gaborone", "Botswana", "GMT+2", "Africa/Gaborone"}, + {"Galapagos Islands", "Ecuador", "GMT-7", "Pacific/Galapagos"}, + {"Geneva", "Switzerland", "GMT+1", "Europe/Paris"}, + {"Genoa", "Italy", "GMT+1", "Europe/Rome"}, + {"Georgetown", "Guyana", "GMT-4", "America/Guyana"}, + {"Grytviken", "South Georgia", "GMT-2", "Atlantic/South_Georgia"}, + {"Guam", "United States of America", "GMT+10", "Pacific/Guam"}, + {"Guatemala City", "Guatemala", "GMT-6", "America/Guatemala"}, + {"Gustavia", "Saint Barthelemy", "GMT-4", "America/Antigua"}, + {"Halifax", "Canada", "GMT-4", "America/Halifax"}, + {"Hamburg", "Germany", "GMT+1", "Europe/Berlin"}, + {"Hanoi", "Vietnam", "GMT+7", "Asia/Ho_Chi_Minh"}, + {"Harare", "Zimbabwe", "GMT+2", "Africa/Harare"}, + {"Havana", "Cuba", "GMT-5", "America/Havana"}, + {"Hawaii", "United States of America", "GMT-10", "Pacific/Honolulu"}, + {"Helsinki", "Finland", "GMT+2", "Europe/Helsinki"}, + {"Hobart", "Australia", "GMT+10", "Australia/Hobart"}, + {"Hong Kong", "China", "GMT+8", "Asia/Hong_Kong"}, + {"Honolulu", "United States of America", "GMT-10", "Pacific/Honolulu"}, + {"Houston", "United States of America", "GMT-6", "CST6CDT"}, + {"Hovd", "Mongolia", "GMT+8", "Asia/Hovd"}, + {"Indianapolis", "United States of America", "GMT-5", "America/Indiana/Indianapolis"}, + {"Irkutsk", "Russia ", "GMT+8", "Asia/Irkutsk"}, + {"Islamabad", "Pakistan", "GMT+5", "Asia/Karachi"}, + {"Istanbul", "Turkey", "GMT+2", "Europe/Istanbul"}, + {"Izhevsk", "Russia ", "GMT+4", "Europe/Moscow"}, + {"Jakarta", "Indonesia", "GMT+7", "Asia/Jakarta"}, + {"Jeddah", "Saudi Arabia", "GMT+3", "Asia/Riyadh"}, + {"Jerusalem", "Israel", "GMT+2", "Asia/Jerusalem"}, + {"Johannesburg", "South Africa", "GMT+2", "Africa/Johannesburg"}, + {"Kabul", "Afghanistan", "GMT+4:30", "Asia/Kabul"}, + {"Kaliningrad", "Russia", "GMT+2", "Europe/Kaliningrad"}, + {"Kamchatka", "Russia ", "GMT+12", "Asia/Kamchatka"}, + {"Kampala", "Uganda", "GMT+3", "Africa/Kampala"}, + {"Karachi", "Pakistan", "GMT+5", "Asia/Karachi"}, + {"Kathmandu", "Nepal", "GMT+5:45", "Asia/Kathmandu"}, + {"Khabarovsk", "Russia ", "GMT+10", "Asia/Vladivostok"}, + {"Kharkiv", "Ukraine", "GMT+2", "Europe/Kiev"}, + {"Khartoum", "Sudan", "GMT+3", "Africa/Khartoum"}, + {"Kiev", "Ukraine", "GMT+2", "Europe/Kiev"}, + {"Kingston", "Canada", "GMT-5", "America/Toronto"}, /* not in zone.tab */ + {"Kingston", "Jamaica", "GMT-5", "America/Jamaica"}, + {"Kinshasa", "Democratic Republic of the Congo", "GMT+1", "Africa/Kinshasa"}, + {"Kolkata", "India", "GMT+5:30", "Asia/Kolkata"}, + {"Krasnoyarsk", "Russia ", "GMT+7", "Asia/Krasnoyarsk"}, + {"Kuala Lumpur", "Malaysia", "GMT+8", "Asia/Kuala_Lumpur"}, + {"Kuwait", "Kuwait", "GMT+3", "Asia/Kuwait"}, + {"Kyiv", "Ukraine", "GMT+2", "Europe/Kiev"/* not in zone.tab */ }, + {"Los Angeles", "United States of America", "GMT-7", "America/Los_Angeles"}, + {"La Paz", "Bolivia", "GMT-4", "America/La_Paz"}, + {"Lagos", "Nigeria", "GMT+1", "Africa/Lagos"}, + {"Las Vegas", "United States of America", "GMT-8", "PST8PDT"}, + {"Lima", "Peru", "GMT-5", "America/Lima"}, + {"Lisbon", "Portugal", "GMT+0", "Europe/Lisbon"}, + {"Ljubljana", "Slovakia", "GMT+1", "Europe/Ljubljana"}, + {"London", "United Kingdom", "GMT+0", "Europe/London"}, + {"Longhua", "China", "GMT+8", "Asia/Shanghai"}, + {"Louisville", "United States of America", "GMT-5", "America/Kentucky/Louisville"}, + {"Luanda", "Angola", "GMT+1", "Africa/Luanda"}, + {"Lubumbashi", "Democratic Republic of the Congo", "GMT+2", "Africa/Lubumbashi"}, + {"Lusaka", "Zambia", "GMT+2", "Africa/Lusaka"}, + {"Luxembourg", "Luxembourg", "GMT+1", "Europe/Luxembourg"}, + {"Lviv", "Ukraine", "GMT+2", "Europe/Kiev"}, + {"Macau", "China", "GMT+8", "Asia/Macau"}, + {"Madrid", "Spain", "GMT+2", "Europe/Madrid"}, + {"Magadan", "Russia ", "GMT+11", "Asia/Magadan"}, + {"Malabo", "Equaorial Guinea", "GMT+1", "Africa/Malabo"}, + {"Male", "Maldives", "GMT+5", "Indian/Maldives"}, + {"Managua", "Nicaragua", "GMT-6", "America/Managua"}, + {"Manama", "Bahrain", "GMT+3", "Asia/Bahrain"}, + {"Manila", "Philippines", "GMT+8", "Asia/Manila"}, + {"Maputo", "Mozambique", "GMT+2", "Africa/Maputo"}, + {"Marigot", "Saint Martin", "GMT-4", "America/Marigot"}, + {"Mazatlan", "Mexico", "GMT-7", "America/Mazatlan"}, + {"Mecca", "Saudi Arabia", "GMT+3", "Asia/Riyadh"}, + {"Melbourne", "Australia", "GMT+10", "Australia/Melbourne"}, + {"Memphis", "United States of America", "GMT-6", "CST6CDT"}, + {"Messina", "Italy", "GMT+1", "Europe/Rome"}, + {"Mexico City", "Mexico", "GMT-6", "America/Mexico_City"}, + {"Miami", "United States of America", "GMT-5", "EST5EDT"}, + {"Mid-Atlantic", "United States of America", "GMT-2", "America/New_York"/* not in zone.tab */ }, + {"Midway Atoll", "United States of America", "GMT-11", "Pacific/Midway"}, + {"Milan", "Italy", "GMT+1", "Europe/Rome"}, + {"Milwaukee", "United States of America", "GMT-6", "CST6CDT"}, + {"Minsk", "Belarus", "GMT+2", "Europe/Minsk"}, + {"Mogadishu", "Somalia", "GMT+2", "Africa/Mogadishu"}, + {"Monrovia", "Liberia", "GMT+0", "Africa/Monrovia"}, + {"Montevideo", "Uruguay", "GMT-3", "America/Montevideo"}, + {"Montreal", "Canada", "GMT-5", "America/Montreal"}, + {"Moscow", "Russia ", "GMT+3", "Europe/Moscow"}, + {"Mumbai", "India", "GMT+5:30", "Asia/Kolkata"}, + {"Munich", "Germany", "GMT+1", "Europe/Berlin"}, + {"Muscat", "Oman", "GMT+4", "Asia/Muscat"}, + {"Nairobi", "Kenya", "GMT+3", "Africa/Nairobi"}, + {"Naples", "Italy", "GMT+1", "Europe/Rome"}, + {"Naters", "Switzerland", "GMT+1", "Europe/Zurich"}, + {"Ndjamena", "Chad", "GMT+1", "Africa/Ndjamena"}, + {"New Delhi", "India", "GMT+5:30", "Asia/Kolkata"/* not in zone.tab */ }, + {"New York", "United States of America", "GMT-4", "America/New_York"}, + {"Newfoundland", "Canada", "GMT-3:30", "America/St_Johns"}, + {"Niamey", "Niger", "GMT+1", "Africa/Niamey"}, + {"Nouakchott", "Mauritania", "GMT+1", "Africa/Nouakchott"}, + {"Noumea", "New Caledonia", "GMT+11", "Pacific/Noumea"}, + {"Novokuznetsk", "Russia", "GMT+7", "Asia/Novokuznetsk"}, + {"Novosibirsk", "Russia", "GMT+6", "Asia/Novosibirsk"}, + {"Nuku'alofa", "Tonga", "GMT+13", "Pacific/Tongatapu"}, + {"Nuuk", "Greenland", "GMT-3", "America/Godthab"}, + {"Omsk", "Russia", "GMT+6", "Asia/Omsk"}, + {"Osaka", "Japan", "GMT+9", "Asia/Tokyo"}, + {"Ottawa", "Canada", "GMT-5", "EST5EDT"}, + {"Ouagadougou", "Burkina Faso", "GMT+0", "Africa/Ouagadougou"}, + {"Pago Pago", "Independent State of Samoa", "GMT-11", "Pacific/Pago_Pago"}, + {"Palermo", "Italy", "GMT+1", "Europe/Rome"}, + {"Panama City", "Panama", "GMT-6", "America/Panama"}, + {"Paramaribo", "Surinam", "GMT-3", "America/Paramaribo"}, + {"Paris", "France", "GMT+1", "Europe/Paris"}, + {"Perm", "Russia", "GMT+5", "Asia/Yekaterinburg"}, + {"Perth", "Australia", "GMT+8", "Australia/Perth"}, + {"Petropavlovsk-Kamchatskiy", "Russia ", "GMT+12", "Asia/Kamchatka"}, + {"Philadelphia", "United States of America", "GMT-5", "EST5EDT"}, + {"Phnom Penh ", "Cambodia", "GMT-5", "Asia/Phnom_Penh"}, + {"Phoenix", "United States of America", "GMT-7", "America/Phoenix"}, + {"Podgorica", "Montenegro", "GMT+1", "Europe/Podgorica"}, + {"Ponta Delgada", "Portugal", "GMT-1", "Atlantic/Azores"}, + {"Port Louis", "Mauritius", "GMT+4", "Indian/Mauritius"}, + {"Port-au-Prince", "Haiti", "GMT-5", "America/Port-au-Prince"}, + {"Portland", "United States of America", "GMT-8", "PST8PDT"}, + {"Prague", "Czech Republic", "GMT+1", "Europe/Prague"}, + {"Pyongyang", "North Korea", "GMT+9", "Asia/Pyongyang"}, + {"Quito", "Ecuador", "GMT-5", "America/Guayaquil"}, + {"Rabat", "Morocco", "GMT+0", "Africa/Casablanca"}, + {"Rangoon", "Burma", "GMT+6:30", "Asia/Rangoon"}, + {"Recife", "Brazil", "GMT-3", "America/Recife"}, + {"Regina", "Canada", "GMT-6", "America/Regina"}, + {"Reykjavik", "Iceland", "GMT+0", "Atlantic/Reykjavik"}, + {"Riga", "Latvia", "GMT+2", "Europe/Riga"}, + {"Rio de Janeiro", "Brazil", "GMT-2", "America/Sao_Paulo"}, + {"Riyadh", "Saudi Arabia", "GMT+3", "Asia/Riyadh"}, + {"Rome", "Italy", "GMT+1", "Europe/Rome"}, + {"Saint-Denis", "Reunion Island", "GMT+4", "Indian/Reunion"}, + {"Samara", "Russia ", "GMT+4", "Europe/Samara"}, + {"San Antonio", "United States of America", "GMT-6", "CST6CDT"}, + {"San Diego", "United States of America", "GMT-8", "PST8PDT"}, + {"San Francisco", "United States of America", "GMT-8", "America/Los_Angeles"}, + {"San Jose", "United States of America", "GMT-8", "PST8PDT"}, + {"San Jose", "Costa Rica", "GMT-6", "America/Costa_Rica"}, + {"San Juan", "Puerto Rico", "GMT-4", "America/Puerto_Rico"}, + {"San Marino", "Italy", "GMT+1", "Europe/San_Marino"}, + {"San Salvador", "El Salvador", "GMT-6", "America/El_Salvador"}, + {"Sanaa", "Yemen", "GMT+3", "Asia/Aden"/* not in zone.tab */ }, + {"Santiago", "Chile", "GMT-4", "America/Santiago"}, + {"Santo Domingo", "Dominican Republic", "GMT-4", "America/Santo_Domingo"}, + {"Sao Paulo", "Brazil", "GMT-2", "America/Sao_Paulo"}, + {"Seattle", "United States of America", "GMT-8", "PST8PDT"}, + {"Seoul", "Republic of Korea", "GMT+9", "Asia/Seoul"}, + {"Shanghai", "China", "GMT+8", "Asia/Shanghai"}, + {"Shenzhen", "China", "GMT+8", "Asia/Shanghai"}, + {"Singapore", "Republic of Singapore", "GMT+8", "Asia/Singapore"}, + {"Skopje", "Macedonia", "GMT+1", "Europe/Skopje"}, + {"Sofia ", "Bulgaria", "GMT+3", "Europe/Sofia"}, + {"St. John's", "Antigua and Barbuda", "GMT-4", "America/Antigua"}, + {"St. John's", "Canada", "GMT-3:30", "America/St_Johns"}, + {"St. Petersburg", "Russia", "GMT+3", "Europe/Moscow"}, + {"Stockholm", "Sweden", "GMT+2", "Europe/Stockholm"}, + {"Suva", "Fiji", "GMT+12", "Pacific/Fiji"}, + {"Sydney", "Australia", "GMT+11", "Australia/Sydney"}, + {"Tahiti", "French Polynesia", "GMT-10", "Pacific/Tahiti"}, + {"Taipei", "Taiwan", "GMT+8", "Asia/Taipei"}, + {"Tallinn", "Estonia", "GMT+2", "Europe/Tallinn"}, + {"Tarawa", "Kiribati", "GMT+12", "Pacific/Tarawa"}, + {"Tashkent", "Uzbekistan", "GMT+5", "Asia/Tashkent"}, + {"Tbilisi", "Georgia", "GMT+4", "Asia/Tbilisi"}, + {"Tegucigalpa", "Honduras", "GMT-6", "America/Tegucigalpa"}, + {"Tehran", "Iran", "GMT+3:30", "Asia/Tehran"}, + {"Thanh Pho Ho Chi Minh", "Vietnam", "GMT+7", "Asia/Ho_Chi_Minh"}, + {"The Settlement", "British Virgin Islands ", "GMT-4", "America/Tortola"}, + {"Tientsin", "China", "GMT+8", "Asia/Shanghai"/* not in zone.tab */ }, + {"Tijuana", "Mexico", "GMT-5", "America/Tijuana"}, + {"Tokyo", "Japan", "GMT+9", "Asia/Tokyo"}, + {"Toronto", "Canada", "GMT-4", "America/Toronto"}, + {"Trehet", "France", "GMT+1", "Europe/Paris"/* not in zone.tab */ }, + {"Tripoli", "Libya", "GMT+2", "Africa/Tripoli"}, + {"Tunis", "Tunisia", "GMT+2", "Africa/Tunis"}, + {"Turin", "Italy", "GMT+1", "Europe/Rome"}, + {"Ufa", "Bashkiriya", "GMT+5", "Asia/Yekaterinburg"}, + {"Ulan Bator", "Mongolia", "GMT+8", "Asia/Ulan_Bator"}, + {"Vaduz", "Liechtenstein", "GMT+1", "Europe/Vaduz"}, + {"Valletta", "Malta", "GMT+1", "Europe/Malta"}, + {"Vancouver", "Canada", "GMT-8", "America/Vancouver"}, + {"Verona", "Italy", "GMT+1", "Europe/Rome"}, + {"Victoria", "Seychelles", "GMT+4", "Australia/Melbourne"}, + {"Vienna", "Austria", "GMT+1", "Europe/Vienna"}, + {"Vilnius", "Lithuania", "GMT+3", "Europe/Vilnius"}, + {"Vladivostok", "Russia ", "GMT+10", "Asia/Vladivostok"}, + {"Volgograd", "Russia ", "GMT+4", "Europe/Volgograd"}, + {"Warsaw", "Poland", "GMT+2", "Europe/Warsaw"}, + {"Washington, D.C.", "United States of America", "GMT-5", "EST5EDT"}, + {"Wellington", "New Zealand", "GMT+12", "Pacific/Auckland"}, + {"Winnipeg", "Canada", "GMT-5", "America/Winnipeg"}, + {"Yakutsk", "Russia ", "GMT+9", "Asia/Yakutsk"}, + {"Yamoussoukro", "Ivory Coast", "GMT+0", "Africa/Abidjan"}, + {"Yaounde", "Cameroon", "GMT+1", "Africa/Douala"/* not in zone.tab */ }, + {"Yekaterinburg", "Russia ", "GMT+5", "Asia/Yekaterinburg"}, + {"Yerevan", "Armenia", "GMT+5", "Asia/Yerevan"}, + {"Yuzhno-Sakhalinsk", "Russia ", "GMT+11", "Asia/Sakhalin"}, + {"Zagreb", "Croatia", "GMT+1", "Europe/Zagreb"}, + {"Zurich", "Switzerland", "GMT+1", "Europe/Zurich"}, + {NULL, NULL, NULL, NULL} +}; + +#define _calendar_timezone_dumpfile_path "/opt/share/zoneinfo/" + +int calendar_foreach_timezone(calendar_foreach_timezone_cb callback, void* user_data) +{ + CALENDAR_NULL_ARG_CHECK(callback); + + int i = 0; + char temp_filepath[256]; // normal char definition + while(_calendar_time_zone_array[i].city != NULL) + { + calendar_foreach_timezone_s timezone; + timezone.timezone_name = _calendar_safe_strdup(_calendar_time_zone_array[i].tz_path); + timezone.city_name = _calendar_safe_strdup(_calendar_time_zone_array[i].city); + timezone.country_name = _calendar_safe_strdup(_calendar_time_zone_array[i].country); + timezone.time_offset = _calendar_safe_strdup(_calendar_time_zone_array[i].gmt); + // all structure members has proper string value. + snprintf(temp_filepath, sizeof(temp_filepath), "%s%s", + _calendar_timezone_dumpfile_path, _calendar_time_zone_array[i].tz_path); // proper snprintf + timezone.timezone_detail_filepath = _calendar_safe_strdup(temp_filepath); + + bool callback_return = callback(&timezone, user_data); + + _calendar_safe_free(timezone.timezone_name); + _calendar_safe_free(timezone.city_name); + _calendar_safe_free(timezone.country_name); + _calendar_safe_free(timezone.time_offset); + _calendar_safe_free(timezone.timezone_detail_filepath); + + if(callback_return == false) + break; + + i++; + } + return CALENDAR_ERROR_NONE; +} + + +int calendar_event_get_from_vcalendar(const char *vcalendar_stream, calendar_event_h *event) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(vcalendar_stream); + *event = malloc(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; + } + + memset(*event, 0, sizeof(calendar_event_s)); + if(calendar_svc_util_convert_vcs_to_event(vcalendar_stream, 0, (cal_struct**)&(*(calendar_event_s**)event)->event_legacy) != CAL_SUCCESS) { + free(*event); + *event = NULL; + + 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_vcalendar_from_event(calendar_event_h event, char **vcalendar_stream) +{ + CALENDAR_NULL_ARG_CHECK(event); + CALENDAR_NULL_ARG_CHECK(vcalendar_stream); + if(calendar_svc_util_convert_event_to_vcs((cal_struct*)((calendar_event_s*)event)->event_legacy, + vcalendar_stream, NULL) != 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_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; + } + calendar_svc_struct_set_int((cal_struct*)(*(calendar_event_s**)todo)->event_legacy, CAL_VALUE_INT_TIMEZONE, 100); // set default timezone + + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_destroy(calendar_todo_h todo) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_free((cal_struct **)&((calendar_event_s*)todo)->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(todo); + ret_val = CALENDAR_ERROR_NONE; + } + + return ret_val; +} + +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_insert_to_db(calendar_todo_h todo, int *todo_id) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(todo_id); + + ret_val = calendar_svc_insert((cal_struct*)((calendar_event_s*)todo)->event_legacy); + if (ret_val < 0) + { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + return CALENDAR_ERROR_DB_FAILED; + } + *todo_id = ret_val; + 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_val = CALENDAR_ERROR_NONE; + + ret_val = calendar_svc_delete(CAL_STRUCT_TODO, todo_id); + + if (ret_val == CAL_SUCCESS) { + ret_val = CALENDAR_ERROR_NONE; + } + else { + LOGE("[%s] CALENDAR_ERROR_DB_FAILED(0x%08x)", __FUNCTION__, CALENDAR_ERROR_DB_FAILED); + ret_val = CALENDAR_ERROR_DB_FAILED; + } + + return ret_val; +} + +int calendar_todo_update_to_db(calendar_todo_h todo) +{ + int ret_val = 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_val = calendar_svc_update((cal_struct*)((calendar_event_s*)todo)->event_legacy); + + if (ret_val != 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_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_INT_PRIORITY, priority); + if (ret_val != 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); + + int legacy_status = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_INT_TASK_STATUS); + + switch(legacy_status) { + case CALS_TODO_STATUS_NEEDS_ACTION: + *status = CALENDAR_TODO_STATUS_NEEDS_ACTION; + break; + case CALS_TODO_STATUS_COMPLETED: + *status = CALENDAR_TODO_STATUS_COMPLETED; + break; + case CALS_TODO_STATUS_IN_PROCESS: + *status = CALENDAR_TODO_STATUS_IN_PROCESS; + break; + case CALS_TODO_STATUS_CANCELLED: + *status = CALENDAR_TODO_STATUS_CANCELED; + break; + default: + *status = CALENDAR_TODO_STATUS_NONE; + break; + } + + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_set_status(calendar_todo_h todo, calendar_todo_status_e status) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + + int legacy_status = CALS_STATUS_NONE; + switch(status) { + case CALENDAR_TODO_STATUS_NEEDS_ACTION: + legacy_status = CALS_TODO_STATUS_NEEDS_ACTION; + break; + case CALENDAR_TODO_STATUS_COMPLETED: + legacy_status = CALS_TODO_STATUS_COMPLETED; + break; + case CALENDAR_TODO_STATUS_IN_PROCESS: + legacy_status = CALS_TODO_STATUS_IN_PROCESS; + break; + case CALENDAR_TODO_STATUS_CANCELED: + legacy_status = CALS_TODO_STATUS_CANCELLED; + break; + default: + legacy_status = CALENDAR_TODO_STATUS_NONE; + break; + } + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_INT_TASK_STATUS, legacy_status); + if (ret_val != 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_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_INT_SENSITIVITY, visibility); + if (ret_val != 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_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_SUMMARY, subject); + + if (ret_val != 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 = NULL; + *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_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_DESCRIPTION, description); + + if (ret_val != 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 = NULL; + *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_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_TXT_LOCATION, location); + + if (ret_val != 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, struct tm *reviedtime) +{ + struct tm *tmp_date = NULL; + + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(reviedtime); + + tmp_date = calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_GMT_LAST_MODIFIED_TIME, CAL_TZ_FLAG_LOCAL); + + if (tmp_date == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + + *reviedtime = *tmp_date; + + 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_offset = calendar_svc_struct_get_int((cal_struct*)((calendar_event_s*)event)->event_legacy, +// CAL_VALUE_INT_TIMEZONE); + *timezone_name = _calendar_safe_strdup(calendar_svc_struct_get_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_TXT_TZ_NAME)); + + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_set_timezone(calendar_todo_h todo, const char* timezone_name) +{ + int ret_val = CALENDAR_ERROR_NONE; + + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(timezone_name); + + ret_val = calendar_svc_struct_set_int((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_INT_TIMEZONE, 0); + ret_val = calendar_svc_struct_set_str((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_TXT_TZ_NAME, timezone_name); + if (ret_val != 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, struct tm *start_time) +{ + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(start_time); + + if(calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL) == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + memcpy(start_time, calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL), sizeof(struct tm)); // proper memcpy + + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_set_start_time(calendar_todo_h todo, struct tm start_time) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(todo); + ret_val = calendar_svc_struct_set_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_GMT_START_DATE_TIME, + CAL_TZ_FLAG_LOCAL, &start_time); + if(ret_val != 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, struct tm *due_time) +{ + CALENDAR_NULL_ARG_CHECK(todo); + CALENDAR_NULL_ARG_CHECK(due_time); + + if(calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL) == NULL) { + LOGE("[%s] CALENDAR_ERROR_NO_DATA(0x%08x)", __FUNCTION__, CALENDAR_ERROR_NO_DATA); + return CALENDAR_ERROR_NO_DATA; + } + memcpy(due_time, calendar_svc_struct_get_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, + CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL), sizeof(struct tm)); // proper memcpy + + return CALENDAR_ERROR_NONE; +} + +int calendar_todo_set_due_time(calendar_todo_h todo, struct tm due_time) +{ + int ret_val = CALENDAR_ERROR_NONE; + CALENDAR_NULL_ARG_CHECK(todo); + ret_val = calendar_svc_struct_set_tm((cal_struct*)((calendar_event_s*)todo)->event_legacy, CAL_VALUE_GMT_END_DATE_TIME, + CAL_TZ_FLAG_LOCAL, &due_time); + if(ret_val != 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_foreach_todo_from_db(calendar_foreach_query_todo_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); + + 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; +} diff --git a/src/calendar_private.c b/src/calendar_private.c new file mode 100755 index 0000000..362666e --- /dev/null +++ b/src/calendar_private.c @@ -0,0 +1,104 @@ +/* + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <calendar.h> +#include <calendar_private.h> +#include <calendar-svc-provider.h> +#include <dlog.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_query(calendar_foreach_query_event_cb callback, char* option, const char* string_to_find, void* user_data) +{ + int ret_val = 0; + cal_iter* iter = NULL; + bool callback_return = true; + + //fetch from DB + ret_val = calendar_svc_find_event_list(0, 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; + } 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; +} + + |