diff options
author | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:50:19 +0900 |
---|---|---|
committer | Kibum Kim <kb0929.kim@samsung.com> | 2012-01-07 00:50:19 +0900 |
commit | f82d616f46273ffbb9f043ad162b8d6f1c6d410d (patch) | |
tree | 013875b2cdcbc0e5c404dc284b5c295592d032bb | |
parent | bbe023c911411370c4896540a424a455885cc87b (diff) | |
download | notification-f82d616f46273ffbb9f043ad162b8d6f1c6d410d.tar.gz notification-f82d616f46273ffbb9f043ad162b8d6f1c6d410d.tar.bz2 notification-f82d616f46273ffbb9f043ad162b8d6f1c6d410d.zip |
Git init
-rwxr-xr-x | AUTHORS | 4 | ||||
-rwxr-xr-x | CMakeLists.txt | 56 | ||||
-rwxr-xr-x | LICENSE | 204 | ||||
-rw-r--r-- | debian/changelog | 16 | ||||
-rwxr-xr-x | debian/compat | 1 | ||||
-rwxr-xr-x | debian/control | 27 | ||||
-rwxr-xr-x | debian/libnotification-0.install.in | 1 | ||||
-rwxr-xr-x | debian/libnotification-0.postinst.in | 92 | ||||
-rwxr-xr-x | debian/libnotification-dev.install.in | 2 | ||||
-rwxr-xr-x | debian/rules | 116 | ||||
-rwxr-xr-x | include/notification.h | 1776 | ||||
-rwxr-xr-x | include/notification_db.h | 53 | ||||
-rwxr-xr-x | include/notification_debug.h | 46 | ||||
-rwxr-xr-x | include/notification_error.h | 46 | ||||
-rwxr-xr-x | include/notification_group.h | 57 | ||||
-rwxr-xr-x | include/notification_internal.h | 76 | ||||
-rwxr-xr-x | include/notification_list.h | 271 | ||||
-rwxr-xr-x | include/notification_noti.h | 52 | ||||
-rwxr-xr-x | include/notification_ongoing.h | 33 | ||||
-rwxr-xr-x | include/notification_type.h | 253 | ||||
-rwxr-xr-x | notification.pc.in | 11 | ||||
-rwxr-xr-x | src/notification.c | 2755 | ||||
-rwxr-xr-x | src/notification_db.c | 110 | ||||
-rwxr-xr-x | src/notification_group.c | 473 | ||||
-rwxr-xr-x | src/notification_list.c | 211 | ||||
-rwxr-xr-x | src/notification_noti.c | 1035 | ||||
-rwxr-xr-x | src/notification_ongoing.c | 129 |
27 files changed, 7906 insertions, 0 deletions
@@ -0,0 +1,4 @@ +Seungtaek Chung <seungtaek.chung@samsung.com> +Mi-Ju Lee <miju52.lee@samsung.com> +Xi zhichan <zhichan.xi@samsung.com> + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..4380100 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,56 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(notification C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(ICONDIR "${PREFIX}/share/${PROJECT_NAME}") +SET(DBDIR "/opt/dbspace") +SET(DBFILE ".notification.db") +SET(MAJOR_VER 0) +SET(VERSION ${MAJOR_VER}.1.0) + +SET(SRCS ./src/notification.c + ./src/notification_noti.c + ./src/notification_ongoing.c + ./src/notification_group.c + ./src/notification_db.c + ./src/notification_list.c) +SET(HEADERS ./include/notification.h + ./include/notification_error.h + ./include/notification_type.h + ./include/notification_list.h) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED sqlite3 db-util heynoti vconf bundle dbus-1 dlog ail aul appsvc) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -g -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +SET(CMAKE_SKIP_BUILD_RPATH TRUE) + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DICONDIR=\"${ICONDIR}\"") +ADD_DEFINITIONS("-DDBDIR=\"${DBDIR}\"") +ADD_DEFINITIONS("-DDBFILE=\"${DBFILE}\"") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJOR_VER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +FOREACH(hfile ${HEADERS}) + INSTALL(FILES ${CMAKE_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) +ENDFOREACH(hfile) + @@ -0,0 +1,204 @@ +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/debian/changelog b/debian/changelog new file mode 100644 index 0000000..8f686ab --- /dev/null +++ b/debian/changelog @@ -0,0 +1,16 @@ +libnotification (0.1.1-4) unstable; urgency=low + + * Update pkgname to org.tizen + * Git: pkgs/n/notification + * Tag: libnotification_0.1.1-4 + + -- Mi-Ju Lee <miju52.lee@samsung.com> Fri, 23 Dec 2011 15:56:33 +0900 + +libnotification (0.1.1-3) unstable; urgency=low + + * Initial Release + * Git: pkgs/n/notification + * Tag: libnotification_0.1.1-3 + + -- Mi-Ju Lee <miju52.lee@samsung.com> Wed, 07 Dec 2011 11:13:10 +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..d1060e9 --- /dev/null +++ b/debian/control @@ -0,0 +1,27 @@ +Source: libnotification +Section: libs +Priority: optional +Maintainer: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> +Build-Depends: debhelper (>= 5), libsqlite3-dev, libslp-db-util-dev, libheynoti-dev, libvconf-dev, libbundle-dev, libdbus-1-dev, dlog-dev, libail-0-dev, libaul-1-dev, libappsvc-dev +Standards-Version: 3.7.2 + +Package: libnotification-dev +Section: libdevel +Architecture: any +Depends: libnotification-0 (= ${Source-Version}), libsqlite3-dev, libslp-db-util-dev, libheynoti-dev, libvconf-dev, libbundle-dev, dlog-dev, libail-0-dev, libaul-1-dev +Description: Notification library + This package contains devel content. + +Package: libnotification-0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, sqlite3, libdlog-0 +Description: Notification library + This package contains notification library. + +Package: libnotification-dbg +Section: debug +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libnotification-0 (= ${Source-Version}) +Description: Notification library + This package is for debug diff --git a/debian/libnotification-0.install.in b/debian/libnotification-0.install.in new file mode 100755 index 0000000..bf766f0 --- /dev/null +++ b/debian/libnotification-0.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/*.so* diff --git a/debian/libnotification-0.postinst.in b/debian/libnotification-0.postinst.in new file mode 100755 index 0000000..fcf05fb --- /dev/null +++ b/debian/libnotification-0.postinst.in @@ -0,0 +1,92 @@ +#!/bin/sh + + +if [ ! -d @DATADIR@/dbspace ] +then + mkdir @DATADIR@/dbspace +fi + +if [ ! -f @DATADIR@/dbspace/.notification.db ] +then + sqlite3 @DATADIR@/dbspace/.notification.db 'PRAGMA journal_mode = PERSIST; + create table if not exists noti_list ( + type INTEGER NOT NULL, + caller_pkgname TEXT NOT NULL, + launch_pkgname TEXT, + image_path TEXT, + group_id INTEGER default 0, + internal_group_id INTEGER default 0, + priv_id INTERGER NOT NULL, + title_key TEXT, + b_text TEXT, + b_key TEXT, + b_format_args TEXT, + num_format_args INTEGER default 0, + text_domain TEXT, + text_dir TEXT, + time INTEGER default 0, + insert_time INTEGER default 0, + args TEXT, + group_args TEXT, + b_execute_option TEXT, + b_service_responding TEXT, + b_service_single_launch TEXT, + b_service_multi_launch TEXT, + sound_type INTEGER default 0, + sound_path TEXT, + vibration_type INTEGER default 0, + vibration_path TEXT, + flags_for_property INTEGER default 0, + flag_simmode INTEGER default 0, + display_applist INTEGER, + progress_size DOUBLE default 0, + progress_percentage DOUBLE default 0, + rowid INTEGER PRIMARY KEY AUTOINCREMENT, + UNIQUE (caller_pkgname, priv_id) + ); + create table if not exists noti_group_data ( + caller_pkgname TEXT NOT NULL, + group_id INTEGER default 0, + badge INTEGER default 0, + title TEXT, + content TEXT, + loc_title TEXT, + loc_content TEXT, + count_display_title INTEGER, + count_display_content INTEGER, + rowid INTEGER PRIMARY KEY AUTOINCREMENT, + UNIQUE (caller_pkgname, group_id) + ); + create table if not exists ongoing_list ( + caller_pkgname TEXT NOT NULL, + launch_pkgname TEXT, + icon_path TEXT, + group_id INTEGER default 0, + internal_group_id INTEGER default 0, + priv_id INTERGER NOT NULL, + title TEXT, + content TEXT, + default_content TEXT, + loc_title TEXT, + loc_content TEXT, + loc_default_content TEXT, + text_domain TEXT, + text_dir TEXT, + args TEXT, + group_args TEXT, + flag INTEGER default 0, + progress_size DOUBLE default 0, + progress_percentage DOUBLE default 0, + rowid INTEGER PRIMARY KEY AUTOINCREMENT, + UNIQUE (caller_pkgname, priv_id) + ); + ' +fi + +if [ ${USER} = "root" ] +then + chown root:5000 @DATADIR@/dbspace/.notification.db + chown root:5000 @DATADIR@/dbspace/.notification.db-journal +fi +chmod 660 @DATADIR@/dbspace/.notification.db +chmod 660 @DATADIR@/dbspace/.notification.db-journal diff --git a/debian/libnotification-dev.install.in b/debian/libnotification-dev.install.in new file mode 100755 index 0000000..0f2a4da --- /dev/null +++ b/debian/libnotification-dev.install.in @@ -0,0 +1,2 @@ +@PREFIX@/include/* +@PREFIX@/lib/pkgconfig/*.pc diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..8cd299e --- /dev/null +++ b/debian/rules @@ -0,0 +1,116 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS ?= -Wall -g +CXXFLAGS ?= -Wall -g +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 + CXXFLAGS += -O0 +else + CFLAGS += -O2 + CXXFLAGS += -O2 +endif + +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \ + CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + cd $(CMAKE_BUILD_DIR) && $(MAKE) + + #docbook-to-man debian/wavplayer.sgml > wavplayer.1 + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + rm -rf $(CMAKE_BUILD_DIR) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/wavplayer. + cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip --dbg-package=libnotification-dbg + dh_compress + dh_fixperms +# dh_perl + 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/notification.h b/include/notification.h new file mode 100755 index 0000000..a833560 --- /dev/null +++ b/include/notification.h @@ -0,0 +1,1776 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_H__ +#define __NOTIFICATION_H__ + +#include <time.h> +#include <bundle.h> + +#include <notification_error.h> +#include <notification_type.h> +#include <notification_list.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup NOTIFICATION_LIBRARY Notification Library + * @brief This notification library provides UI notification event. Inserted notification event is displaying Notification Tray, Indicator, etc. + */ + +/** + * @ingroup NOTIFICATION_LIBRARY + * @defgroup NOTIFICATION notification core API + * @brief Notification core API + */ + +/** + * @addtogroup NOTIFICATION + * @{ + */ + +/** + * @brief This function will be deprecated. + * @see notification_set_image() + * + */ +notification_error_e notification_set_icon(notification_h noti, + const char *icon_path); + +/** + * @brief This function will be deprecated. + * @see notification_get_image() + * + */ +notification_error_e notification_get_icon(notification_h noti, + char **icon_path); + +/** + * @brief This function set image path according to type. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] type notification image type + * @param[in] image_path image file full path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre Notification handle should be created by notification_new() + * @post + * @see #notification_image_type_e + * @see notification_new() + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, APP_IMAGE_FULL_PATH); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_image(notification_h noti, + notification_image_type_e type, + const char *image_path); + +/** + * @brief This function get image path according to type. + * @details + * @remarks Do not free image_path. It will be freed when notification_free() or notification_free_list(). + * @param[in] noti notification handle + * @param[in] type notification image type + * @param[out] image_path image file full path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre Notification handle should be created by notification_new() + * @post + * @see #notification_image_type_e + * @see notification_new() + * @par Sample code: + * @code + #include <notification.h> + ... + { + char *image_path = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_image(notification_h noti, + notification_image_type_e type, + char **image_path); + +/** + * @brief This function set time infomation. + * @details If input_time is 0, time information is set by current time. + * @remarks + * @param[in] noti notification handle + * @param[in] input_time input time + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre Notification handle should be created by notification_new() + * @post + * @see notification_new() + * @par Sample code: + * @code +#include <notification.h> + ... + { + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_time(noti, time(NULL)); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } + } + * @endcode + */ +notification_error_e notification_set_time(notification_h noti, + time_t input_time); + +/** + * @brief This function get time information. + * @details If ret_time is 0, time information is not set before. + * @remarks + * @param[in] noti notification handle + * @param[out] ret_time return time value + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre Notification handle should be created by notification_new() + * @post + * @see notification_new() + * @par Sample code: + * @code + #include <notification.h> + ... + { + time_t ret_time; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_time(noti, &ret_time); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_time(notification_h noti, + time_t * ret_time); + +/** + * @brief This function get insert time information. + * @details If ret_time is 0, this notification data is not inserted before. + * @remarks + * @param[in] noti notification handle + * @param[out] ret_time return time value + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code + #include <notification.h> + ... + { + time_t ret_time; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_insert_time(noti, &ret_time); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + } + * @endcode + */ +notification_error_e notification_get_insert_time(notification_h noti, + time_t * ret_time); + +/** + * @brief This function will be deprecated. + * @see notification_set_text() + * + */ +notification_error_e notification_set_title(notification_h noti, + const char *title, + const char *loc_title); + +/** + * @brief This function will be deprecated. + * @see notification_get_text() + * + */ +notification_error_e notification_get_title(notification_h noti, + char **title, + char **loc_title); + +/** + * @brief This function will be deprecated. + * @see notification_set_text() + * + */ +notification_error_e notification_set_group_title(const char *pkgname, + int group_id, + const char *title, + const char *loc_title, + notification_count_display_type_e + count_display); + +/** + * @brief This function will be deprecated. + * @see notification_get_text() + * + */ +notification_error_e notification_get_group_title(const char *pkgname, + int group_id, + char **title, + char **loc_title, + notification_count_display_type_e *count_display); + +/** + * @brief This function will be deprecated. + * @see notification_set_text() + * + */ +notification_error_e notification_set_content(notification_h noti, + const char *content, + const char *loc_content); + +/** + * @brief This function will be deprecated. + * @see notification_get_text() + * + */ +notification_error_e notification_get_content(notification_h noti, + char **content, + char **loc_content); + +/** + * @brief This function will be deprecated. + * @see notification_set_text() + * + */ +notification_error_e notification_set_default_content(notification_h noti, + const char *content, + const char *loc_content); + +/** + * @brief This function will be deprecated. + * @see notification_get_text() + * + */ +notification_error_e notification_get_default_content(notification_h noti, + char **content, + char **loc_content); + +/** + * @brief This function will be deprecated. + * @see notification_set_text() + * + */ +notification_error_e notification_set_group_content(const char *pkgname, + int group_id, + const char *content, + const char *loc_content, + notification_count_display_type_e count_display); + +/** + * @brief This function will be deprecated. + * @see notification_get_text() + * + */ +notification_error_e notification_get_group_content(const char *pkgname, + int group_id, + char **content, + char **loc_content, + notification_count_display_type_e *count_display); + +/** + * @brief This function set text. + * @details Set title, content string. If text is formated data(only support %d, %f, %s), type - value pair should be set. + * If %d, type NOTIFICATION_VARIABLE_TYPE_INT and value is integer value. + * If %f, type NOTIFICATION_VARIABLE_TYPE_DOUBLE and value is double value. + * If %s, type NOTIFICATION_VARIABLE_TYPE_STRING and value is character string. + * If type is NOTIFICATION_VARIABLE_TYPE_COUNT, notification count is displaying with text. + * If value is NOTIFICATION_COUNT_POS_LEFT, count is displaying at the left of the text. + * If value is NOTIFICATION_COUNT_POS_IN, count is displaying in the text that text has %d format. + * If value is NOTIFICATION_COUNT_POS_RIGHT, count is displaying at the right of the text. + * Variable parameter should be terminated NOTIFICATION_VARIABLE_TYPE_NONE. + * @remarks + * @param[in] noti notification handle + * @param[in] type notification text type + * @param[in] text basic text + * @param[in] key text key for localization + * @param[in] args_type variable parameter that type - value pair. + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre notification handle should be created by notification_new(). + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "I'm Title", "IDS_APP_BODY_IM_TITLE", NOTIFICATION_VARIABLE_TYPE_NONE); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_text(notification_h noti, + notification_text_type_e type, + const char *text, + const char *key, + int args_type, ...); + +/** + * @brief This function get text. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] type notification text type. + * @param[out] text text + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + char *text = NULL; + + noti_err = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, &text); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_text(notification_h noti, + notification_text_type_e type, + char **text); + +/** + * @brief This function set text domain. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] domain text domain + * @param[in] dir text dir + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_text_domain(noti, PACKAGE, LOCALEDIR); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_text_domain(notification_h noti, + const char *domain, + const char *dir); + +/** + * @brief This function get text domain. + * @details + * @remarks Do not free returned domain and dir. These are freed when notification_free or notification_free_list. + * @param[in] noti notification handle + * @param[out] domain domain + * @param[out] dir locale dir + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + char *domain = NULL; + char *dir = NULL; + + noti_err = notification_get_text_domain(noti, &domain, &dir); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_text_domain(notification_h noti, + char **domain, + char **dir); + +/** + * @brief This function set notification sound. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] type notification sound type + * @param[in] path user sound file path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_set_sound(notification_h noti, + notification_sound_type_e type, + const char *path); + +/** + * @brief This function get notification sound. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] type notification sound type + * @param[out] path user sound file path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE; + + noti_err = notification_get_sound(noti, &type, NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_sound(notification_h noti, + notification_sound_type_e *type, + const char **path); + +/** + * @brief This function set notification vibration. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] type notification vibration type + * @param[in] path user vibration file path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_vibration(noti, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_set_vibration(notification_h noti, + notification_vibration_type_e type, + const char *path); + +/** + * @brief This function get notification vibration. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] type notification sound type + * @param[out] path user vibration file path + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + notification_vibration_type_e type = NOTIFICATION_VIBRATION_TYPE_NONE; + + noti_err = notification_get_vibration(noti, &type, NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_vibration(notification_h noti, + notification_vibration_type_e *type, + const char **path); + +/** + * @brief This function will be deprecated. + * @see notification_set_execute_option() + * + */ +notification_error_e notification_set_application(notification_h noti, const char *pkgname); /* Do not use this */ + +/** + * @brief This function will be deprecated. + * @see notification_get_execute_option() + * + */ +notification_error_e notification_get_application(notification_h noti, char **pkgname); /* Do not use this */ + +/** + * @brief This function will be deprecated. + * @see notification_set_execute_option() + * + */ +notification_error_e notification_set_args(notification_h noti, bundle * args, bundle * group_args); /* Do not use this */ + +/** + * @brief This function will be deprecated. + * @see notification_get_execute_option() + * + */ +notification_error_e notification_get_args(notification_h noti, bundle ** args, bundle ** group_args); /* Do not use this */ + +/** + * @brief This function will be deprecated. + * @see notification_set_execute_option() + * + */ +notification_error_e notification_set_service_data(notification_h noti, + bundle *service_data, + bundle *group_service_data); + +/** + * @brief This function will be deprecated. + * @see notification_get_execute_option() + * + */ +notification_error_e notification_get_service_data(notification_h noti, + bundle **service_data, + bundle **group_service_data); + +/** + * @brief This function set execute option. + * @details When notification data selected in display application, application launched by appsvc_run_service with service_handle. + * @remarks + * @param[in] noti notification handle + * @param[in] type notification execute type + * @param[in] text basic text for button + * @param[in] key value for localizaed text + * @param[in] service_handle appsvc bundle data + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + */ +notification_error_e notification_set_execute_option(notification_h noti, + notification_execute_type_e type, + const char *text, + const char *key, + bundle *service_handle); + +/** + * @brief This function get execute option. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] type notification execute type + * @param[out] text text for button + * @param[out] service_handle appsvc bundle data + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + bundle *b = NULL; + + ... + + noti_err = notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, &b); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_get_execute_option(notification_h noti, + notification_execute_type_e type, + const char **text, + bundle **service_handle); + +/** + * @brief This function set notification property. + * @details + * @remarks + * @param[in] noti notification handle + * @param[in] flags property with | operation + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + bundle *b = NULL; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE | NOTIFICATION_PROP_DISABLE_APP_LAUNCH); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_property(notification_h noti, + int flags); + +/** + * @brief This function get notification property. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] flags notification property + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int flags = 0; + + noti_err = notification_get_property(noti, &flags); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_property(notification_h noti, + int *flags); + +/** + * @brief This function set display application list. + * @details All display application is enable(NOTIFICATION_DISPLAY_APP_ALL) if you are not call this API. + * @remarks + * @param[in] noti notification handle + * @param[in] applist with | operation + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + bundle *b = NULL; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} +} + * @endcode + */ +notification_error_e notification_set_display_applist(notification_h noti, + int applist); + +/** + * @brief This function get display application list. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] applist display application list. + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int applist = 0; + + noti_err = notification_get_display_applist(noti, &applist); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_display_applist(notification_h noti, + int *applist); + +/** + * @brief This function set initial size for ongoing type. + * @details After notification_insert, it does not upate size. If you want to update size, please call notification_update_size(). + * @remarks + * @param[in] noti notification handle + * @param[in] size double type size. + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_size(noti, 0.0); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_size(notification_h noti, + double size); + +/** + * @brief This function get progress size. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] size progress size + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + double size = 0.0; + + noti_err = notification_get_size(noti, &size); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_size(notification_h noti, + double *size); + +/** + * @brief This function set initial progress for ongoing type. + * @details After notification_insert, it does not upate progress. If you want to update progress, please call notification_update_progress(). + * @remarks + * @param[in] noti notification handle + * @param[in] percentage progress percentage + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_progress(noti, 0.0); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_progress(notification_h noti, + double percentage); + +/** + * @brief This function get progress percentage. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] percentage progress percentage + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + double percentage = 0.0; + + noti_err = notification_get_progress(noti, &percentage); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_progress(notification_h noti, + double *percentage); + +/** + * @brief This function set caller_pkgname. + * @details caller_pkgname is set automatically when notification_new. We are not recommend to use this API. + * @remarks + * @param[in] noti notification handle + * @param[in] pkgname caller package name + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_err = notification_set_pkgname(noti, "org.tizen.phone"); + if(noti_err != NOTIFICATION_ERROR_NONE) { + notification_free(noti); + return; + } +} + * @endcode + */ +notification_error_e notification_set_pkgname(notification_h noti, + const char *pkgname); + +/** + * @brief This function get caller pkgname. + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] pkgname caller package name + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + char *pkgname = NULL; + + noti_err = notification_get_pkgname(noti, &pkgname); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_pkgname(notification_h noti, + char **pkgname); + +/** + * @brief This function will be deprecated. + * @see notification_set_badge() + * + */ +notification_error_e notification_set_unread_count(const char *pkgname, + int group_id, + int unread_count); + +/** + * @brief This function will be deprecated. + * @see notification_get_badge() + * + */ +notification_error_e notification_get_unread_count(const char *pkgname, + int group_id, + int *unread_count); + +/** + * @brief This function set application badge count. + * @details + * @remarks + * @param[in] pkgname If NULL, caller pkgname is set internally. + * @param[in] group_id group id + * @param[in] count badge count + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: +#include <notification.h> + ... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, 5); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + } + * @endcode + */ +notification_error_e notification_set_badge(const char *pkgname, + int group_id, int count); + +/** + * @brief This function get application badge count. + * @details + * @remarks + * @param[in] pkgname If NULL, caller pkgname is set internally. + * @param[in] group_id group id + * @param[out] count badge count + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: +#include <notification.h> + ... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int count = 0; + + noti_err = notification_get_badge(NULL, NOTIFICATION_GROUP_ID_NONE, &count); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + } + * @endcode + */ +notification_error_e notification_get_badge(const char *pkgname, + int group_id, int *count); + +/** + * @brief This function get Group ID and Private ID + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] group_id Group ID + * @param[out] priv_id Private ID + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> + ... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int group_id, priv_id; + + noti_err = notification_get_id(noti, &group_id, &priv_id); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + } + * @endcode + */ +notification_error_e notification_get_id(notification_h noti, + int *group_id, int *priv_id); + +/** + * @brief This function get notification type + * @details + * @remarks + * @param[in] noti notification handle + * @param[out] type notification type + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide parameter + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + notification_type_e type; + + noti_err = notification_get_type(noti, &type); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_type(notification_h noti, + notification_type_e * type); + +/** + * @brief This function insert notification data. + * @details Notification data is inserted to DB and then notification data is displaying display application. + * When notification_new() call, if priv_id is NOTIFICATION_PRIV_ID_NONE, priv_id is return internally set priv_id. + * @remarks + * @param[in] noti notification handle + * @param[out] priv_id private ID + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre notification_new() + * @post notification_free() + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_insert(noti, NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_insert(notification_h noti, + int *priv_id); + +/** + * @brief This function update notification data. Not fully implemented yet. + * @details Display application update UI. + * @remarks + * @param[in] noti notification handle that is created by notification_new(). + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_update(NULL); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_update(notification_h noti); + +/** + * @brief This function clear all notification of type. + * @details Not recommand API. Only for notification tray's clear button operation. + * @remarks + * @param[in] type notification type + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see #notification_type_e + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notifiation_clear(NOTIFICATION_TYPE_NOTI); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notifiation_clear(notification_type_e type); + +/** + * @brief This function delete notification by type. + * @details If pkgname is NULL, caller_pkgname is set internally. + * @remarks + * @param[in] pkgname caller application package name or NULL + * @param[in] type notification type + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_delete_all_by_type(const char *pkgname, + notification_type_e type); + +/** + * @brief This function delete group notification data by group ID. + * @details If pkgname is NULL, caller_pkgname is set internally. + * @remarks + * @param[in] pkgname caller application package name or NULL + * @param[in] type notification type + * @param[in] group_id group ID + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_delete_group_by_group_id(NULL, NOTIFICATION_TYPE_NOTI, APP_GROUP_ID); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_delete_group_by_group_id(const char *pkgname, + notification_type_e type, + int group_id); + +/** + * @brief This function delete group notification data that include priv_id. + * @details If pkgname is NULL, caller_pkgname is set internally. + * @remarks + * @param[in] pkgname caller application package name or NULL + * @param[in] type notification type + * @param[in] priv_id priv ID + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_delete_group_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, APP_PRIV_ID); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_delete_group_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id); + +/** + * @brief This function delete notification data that private ID is priv_id. + * @details If pkgname is NULL, caller_pkgname is set internally. + * @remarks + * @param[in] pkgname caller application package name or NULL + * @param[in] type notification type + * @param[in] priv_id priv ID + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, APP_PRIV_ID); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_delete_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id); + +/** + * @brief This function delete notification data from DB + * @details notification_delete() remove notification data from DB and notification_free release menory of notification data. + * @remarks + * @param[in] noti notification handle + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... + { + notificaton_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + ... + + noti_err = notification_delete(noti); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + +} + * @endcode + */ +notification_error_e notification_delete(notification_h noti); + +/** + * @brief This function update progressive data of inserted notification data. Only work at NOTIFICATION_TYPE_ONGOING type. + * @details Display application update UI. + * @remarks + * @param[in] noti notification handle or NULL if priv_id is valid + * @param[in] priv_id private ID + * @param[in] progress % value of progressive data + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_update_progress(NULL, APP_NOTI_PRIV_ID, 0.6); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_update_progress(notification_h noti, + int priv_id, + double progress); + +/** + * @brief This function update progressive data of inserted notification data. Only work at NOTIFICATION_TYPE_ONGOING type. + * @details Display application update UI. + * @remarks + * @param[in] noti notification handle or NULL if priv_id is valid + * @param[in] priv_id private ID + * @param[in] size bytes of progressive data + * @return NOTIFICATION_ERROR_NONE if success, other value if failure + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - Invalide input value + * @pre + * @post + * @par Sample code: + * @code +#include <notification.h> +... + { + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_update_size(NULL, APP_NOTI_PRIV_ID, 3000000); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_update_size(notification_h noti, + int priv_id, double size); + +/** + * @brief This function create internal structure data and return notification handle. + * @details Available type is #NOTIFICATION_TYPE_NOTI and #NOTIFICATION_TYPE_ONGOING. + * #NOTIFICATION_TYPE_NOTI is remaining notification data evenif device is restarted. + * #NOTIFICATION_TYPE_ONGOING can display progressive feather, but notification data is removed after device is restarted. + * If group_id is #NOTIFICATION_GROUP_ID_NONE, notification data is not grouping. #NOTIFICATION_GROUP_ID_DEFAULT, + * notification data is grouping with same title. Positive number ( > 0 ) is grouping with same number. + * If priv_id is #NOTIFICATION_PRIV_ID_NONE, priv_id is set internally and return it when notification_insert() call. + * Positive number and zero ( >= 0 ) is application set private ID. These ID should have be unique each application package. + * @remarks + * @param[in] type notification type + * @param[in] group_id Group ID + * @param[in] priv_id Priv ID + * @return notification handle(#notification_h) if success, NULL if failure. + * @retval #notification_h - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_type_e + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + ... +} + * @endcode + */ +notification_h notification_new(notification_type_e type, int group_id, + int priv_id); + +/** + * @brief This function free internal structure data of notification handle. + * @details Internal data of notification handle is released. Notification data that inserted is not deleted. + * @remarks + * @param[in] noti notification handle + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre notification_new() + * @post + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, APP_GROUP_ID, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + ... + + noti_err = notification_free(noti); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_free(notification_h noti); + +/** + * @brief This function register notification chagned callback. + * @details + * @remarks + * @param[in] changed_cb callback function + * @param[in] user_data user data + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre notification_new() + * @post + * @see notification_unresister_changed_cb() + * @par Sample code: + * @code +#include <notification.h> +... +{ + noti_err = notification_resister_changed_cb(app_changed_cb, user_data); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e +notification_resister_changed_cb( + void (*changed_cb)(void *data, notification_type_e type), + void *user_data); + +/** + * @brief This function unregister notification chagned callback. + * @details + * @remarks + * @param[in] changed_cb callback function + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre notification_new() + * @post + * @see notification_resister_changed_cb() + * @par Sample code: + * @code +#include <notification.h> +... +{ + noti_err = notification_unresister_changed_cb(app_changed_cb); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e +notification_unresister_changed_cb( + void (*changed_cb)(void *data, notification_type_e type)); + +/** + * @brief This function get notification data count. + * @details Count is the result of the conditions that type, pkgname, group_id, priv_id. + * @remarks + * @param[in] type notification type + * @param[in] pkgname caller application package name + * @param[in] group_id group id + * @param[in] priv_id private id + * @param[out] count notification data number + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre + * @post + * @see #notification_type_e + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int count = 0; + + noti_err = notification_get_count(NOTIFICATION_TYPE_NONE, NULL, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE, &count); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_count(notification_type_e type, + const char *pkgname, + int group_id, int priv_id, + int *count); + +/** + * @brief This function will be deprecated. + * @see notification_get_grouping_list() + * + */ +notification_error_e notification_get_list(notification_type_e type, + int count, + notification_list_h * list); + +/** + * @brief This function return notification grouping list handle. + * @details If count is -1, all of notification list is returned. + * @remarks + * @param[in] type notification type + * @param[in] count returned notification data number + * @param[out] list notification list handle + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_grouping_list(notification_type_e type, + int count, + notification_list_h *list); + +/** + * @brief This function return notification detail list handle of grouping data. + * @details If count is -1, all of notification list is returned. + * @remarks + * @param[in] pkgname caller application package name + * @param[in] group_id group id + * @param[in] priv_id private id + * @param[in] count returned notification data number + * @param[out] list notification list handle + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_detail_list(pkgname, group_id, priv_id, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_get_detail_list(const char *pkgname, + int group_id, + int priv_id, + int count, + notification_list_h *list); + +/** + * @brief This function release notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @return NOTIFICATION_ERROR_NONE if success, other value if failure. + * @retval NOTIFICATION_ERROR_NONE - success + * @retval NOTIFICATION_ERROR_INVALID_DATA - invalid parameter + * @pre notification_get_grouping_list() or notification_get_detail_list () + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + ... + + noti_err = notification_free_list(noti_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } +} + * @endcode + */ +notification_error_e notification_free_list(notification_list_h list); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* __NOTIFICATION_H__ */ diff --git a/include/notification_db.h b/include/notification_db.h new file mode 100755 index 0000000..a7fb204 --- /dev/null +++ b/include/notification_db.h @@ -0,0 +1,53 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_DB_H__ +#define __NOTIFICATION_DB_H__ + +#include <bundle.h> +#include <sqlite3.h> + +#ifndef DBDIR +#error "DBDIR not defined" +#endif + +#ifndef DBFILE +#error "DBFILE not defined" +#endif + +#define DBPATH DBDIR"/"DBFILE + +#define NOTIFICATION_QUERY_MAX 4096 + +#define NOTIFICATION_EMPTY_STR "" +#define NOTIFICATION_CHECK_STR(p) ((p)?(p):NOTIFICATION_EMPTY_STR) + +sqlite3 *notification_db_open(const char *dbfile); + +int notification_db_close(sqlite3 ** db); + +int notification_db_exec(sqlite3 * db, const char *query); + +char *notification_db_column_text(sqlite3_stmt * stmt, int col); + +bundle *notification_db_column_bundle(sqlite3_stmt * stmt, int col); + +#endif /* __NOTIFICATION_DB_H__ */ diff --git a/include/notification_debug.h b/include/notification_debug.h new file mode 100755 index 0000000..feebbb7 --- /dev/null +++ b/include/notification_debug.h @@ -0,0 +1,46 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_DEBUG_H__ +#define __NOTIFICATION_DEBUG_H__ + +#define LOG_TAG "notification" +#include <dlog.h> + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef _DLOG_H_ +#include <stdio.h> +#define NOTIFICATION_ERR(fmt, arg...)\ + do { fprintf(stderr, "["LOG_TAG"] %s(%d):"fmt"\n", __FUNCTION__, __LINE__, ##arg); } while (0) +#define NOTIFICATION_INFO(fmt, arg...)\ + do { fprintf(stdout, "["LOG_TAG"] %s(%d):"fmt"\n", __FUNCTION__, __LINE__, ##arg); } while (0) +#define NOTIFICATION_DBG(fmt, arg...)\ + do { fprintf(stdout, "["LOG_TAG"] %s(%d):"fmt"\n", __FUNCTION__, __LINE__, ##arg); } while (0) +#else +#define NOTIFICATION_ERR(...) LOGE(__VA_ARGS__) +#define NOTIFICATION_INFO(...) LOGI(__VA_ARGS__) +#define NOTIFICATION_DBG(...) LOGD(__VA_ARGS__) +#endif + +#endif /* __NOTIFICATION_DEBUG_H__ */ diff --git a/include/notification_error.h b/include/notification_error.h new file mode 100755 index 0000000..034a465 --- /dev/null +++ b/include/notification_error.h @@ -0,0 +1,46 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_ERROR_H__ +#define __NOTIFICATION_ERROR_H__ + +/** + * @addtogroup NOTIFICATION_TYPE + * @{ + */ + +/** + * @breief Enumeration for notification error + */ +typedef enum _notification_error { + NOTIFICATION_ERROR_NONE = 0, /**< Success */ + NOTIFICATION_ERROR_INVALID_DATA = -1, /**< Invalid parameter */ + NOTIFICATION_ERROR_NO_MEMORY = -2, /**< No memory */ + NOTIFICATION_ERROR_FROM_DB = -3, /**< Error from DB query */ + NOTIFICATION_ERROR_ALREADY_EXIST_ID = -4, /**< Already exist private ID */ + NOTIFICATION_ERROR_FROM_DBUS = -5, /**< Error from DBus */ +} notification_error_e; + +/** + * @} + */ + +#endif /* __NOTIFICATION_ERROR_H__ */ diff --git a/include/notification_group.h b/include/notification_group.h new file mode 100755 index 0000000..5c79232 --- /dev/null +++ b/include/notification_group.h @@ -0,0 +1,57 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_GROUP_H__ +#define __NOTIFICATION_GROUP_H__ + +#include <notification.h> + +notification_error_e notification_group_set_title(const char *pkgname, + int group_id, + const char *title, + const char *loc_title, + notification_count_display_type_e count_display); + +notification_error_e notification_group_get_title(const char *pkgname, + int group_id, + char **ret_title, + char **ret_loc_title, + notification_count_display_type_e *count_display); + +notification_error_e notification_group_set_content(const char *pkgname, + int group_id, + const char *content, + const char *loc_content, + notification_count_display_type_e count_display); + +notification_error_e notification_group_get_content(const char *pkgname, + int group_id, + char **ret_content, + char **ret_loc_content, + notification_count_display_type_e *count_display); + +notification_error_e notification_group_set_badge(const char *pkgname, + int group_id, int count); + +notification_error_e notification_group_get_badge(const char *pkgname, + int group_id, int *count); + +#endif /* __NOTIFICATION_GROUP_H__ */ diff --git a/include/notification_internal.h b/include/notification_internal.h new file mode 100755 index 0000000..77b75c3 --- /dev/null +++ b/include/notification_internal.h @@ -0,0 +1,76 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_INTERNAL_H__ +#define __NOTIFICATION_INTERNAL_H__ + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +struct _notification { + notification_type_e type; + + int group_id; /* Group ID */ + int internal_group_id; /* Internal Group ID */ + int priv_id; /* Private ID */ + + char *caller_pkgname; /* Caller App package name */ + char *launch_pkgname; /* Launch App package name. It will be from appsvc_set_pkgname */ + bundle *args; /* Will be removed. */ + bundle *group_args; /* Will be removed. */ + + bundle *b_execute_option; + bundle *b_service_responding; + bundle *b_service_single_launch; + bundle *b_service_multi_launch; + + char *domain; /* Text domain for localization */ + char *dir; /* Text dir for localization */ + + bundle *b_text; /* basic text */ + bundle *b_key; /* key for localized text */ + bundle *b_format_args; /* args type and value for format string */ + int num_format_args; /* number of format string args */ + + bundle *b_image_path; /* image path */ + + notification_sound_type_e sound_type; + char *sound_path; + notification_vibration_type_e vibration_type; + char *vibration_path; + + time_t time; /* time set by application */ + time_t insert_time; /* insert time */ + + int flags_for_property; /* property NOTIFICATION_PROP_XXX */ + int display_applist; /* display app list NOTIFICATION_DISPLAY_APP_XXX */ + + double progress_size; /* size of progress */ + double progress_percentage; /* percentage of progress */ + + char *app_icon_path; /* Temporary stored app icon path from AIL */ + char *app_name; /* Temporary stored app name from AIL */ + char *temp_title; + char *temp_content; +}; + +#endif /* __NOTIFICATION_INTERNAL_H__ */ diff --git a/include/notification_list.h b/include/notification_list.h new file mode 100755 index 0000000..2a490e3 --- /dev/null +++ b/include/notification_list.h @@ -0,0 +1,271 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_LIST_H__ +#define __NOTIFICATION_LIST_H__ + +#include <notification.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup NOTIFICATION_LIBRARY + * @defgroup NOTIFICATION_LIST notification list + * @brief Notification List API + */ + +/** + * @addtogroup NOTIFICATION_LIST + * @{ + */ + +/** + * @breief Notification list handle + */ +typedef struct _notification_list *notification_list_h; + +/** + * @brief This function get head pointer of the notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @return notification list handle if success, NULL if failure. + * @retval notification list handle(#notification_list_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_list = notification_list_get_head(noti_list); +} + * @endcode + */ +notification_list_h notification_list_get_head(notification_list_h list); + +/** + * @brief This function get tail pointer of the notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @return notification list handle if success, NULL if failure. + * @retval notification list handle(#notification_list_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_list = notification_list_get_tail(noti_list); +} + * @endcode + */ +notification_list_h notification_list_get_tail(notification_list_h list); + +/** + * @brief This function get previous pointer of the current notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @return notification list handle if success, NULL if failure. + * @retval notification list handle(#notification_list_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_list = notification_list_get_prev(noti_list); +} + * @endcode + */ +notification_list_h notification_list_get_prev(notification_list_h list); + +/** + * @brief This function get next pointer of the current notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @return notification list handle if success, NULL if failure. + * @retval notification list handle(#notification_list_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti_list = notification_list_get_next(noti_list); +} + * @endcode + */ +notification_list_h notification_list_get_next(notification_list_h list); + +/** + * @brief This function get notification handle that list has. + * @details + * @remarks + * @param[in] list notification list handle + * @return notification handle if success, NULL if failure. + * @retval notification handle(#notification_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_get_grouping_list(NOTIFICATION_TYPE_NONE, -1, ¬i_list); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + noti = notification_list_get_data(noti_list); +} + * @endcode + */ +notification_h notification_list_get_data(notification_list_h list); + +/** + * @brief This function append notification data in notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @param[in] noti notification handle + * @return notification handle if success, NULL if failure. + * @retval notification handle(#notification_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE); + if(noti == NULL) { + return; + } + + noti_list = notification_list_append(noti_list, noti); +} + * @endcode + */ +notification_list_h notification_list_append(notification_list_h list, + notification_h noti); + +/** + * @brief This function remove notification data from notification list. + * @details + * @remarks + * @param[in] list notification list handle + * @param[in] noti notification handle + * @return notification handle if success, NULL if failure. + * @retval notification handle(#notification_h) - success + * @retval NULL - failure + * @pre + * @post + * @see #notification_list_h + * @see #notification_h + * @par Sample code: + * @code +#include <notification.h> +... +{ + notification_h noti = NULL; + notification_list_h noti_list = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + ... + + noti_list = notification_list_remove(noti_list, noti); +} + * @endcode + */ +notification_list_h notification_list_remove(notification_list_h list, + notification_h noti); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* __NOTIFICATION_LIST_H__ */ diff --git a/include/notification_noti.h b/include/notification_noti.h new file mode 100755 index 0000000..a5d934e --- /dev/null +++ b/include/notification_noti.h @@ -0,0 +1,52 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_NOTI_H__ +#define __NOTIFICATION_NOTI_H__ + +#include <notification.h> + +int notification_noti_insert(notification_h noti); + +int notification_noti_delete_all(notification_type_e type, const char *pkgname); + +int notification_noti_delete_group_by_group_id(const char *pkgname, + int group_id); + +int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id); + +int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id); + +notification_error_e notification_noti_get_count(notification_type_e type, + const char *pkgname, + int group_id, int priv_id, + int *count); + +notification_error_e notification_noti_get_grouping_list(notification_type_e type, + int count, + notification_list_h *list); + +notification_error_e notification_noti_get_detail_list(const char *pkgname, + int group_id, + int priv_id, int count, + notification_list_h *list); + +#endif /* __NOTIFICATION_NOTI_H__ */ diff --git a/include/notification_ongoing.h b/include/notification_ongoing.h new file mode 100755 index 0000000..6d04798 --- /dev/null +++ b/include/notification_ongoing.h @@ -0,0 +1,33 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_ONGOING_H__ +#define __NOTIFICATION_ONGOING_H__ + +#include <notification.h> +notification_error_e notification_ongoing_update_progress(const char *caller_pkgname, + int priv_id, + double progress); + +notification_error_e notification_ongoing_update_size(const char *caller_pkgname, + int priv_id, double size); + +#endif /* __NOTIFICATION_ONGOING_H__ */ diff --git a/include/notification_type.h b/include/notification_type.h new file mode 100755 index 0000000..b2584ba --- /dev/null +++ b/include/notification_type.h @@ -0,0 +1,253 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 __NOTIFICATION_TYPE_H__ +#define __NOTIFICATION_TYPE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup NOTIFICATION_LIBRARY + * @defgroup NOTIFICATION_TYPE notification type + * @brief Notification type + */ + +/** + * @addtogroup NOTIFICATION_TYPE + * @{ + */ + +/** + * @breief Enumeration for notification sound type. + */ +typedef enum _notification_sound_type { + NOTIFICATION_SOUND_TYPE_NONE = -1, + /**< Default value. Disable sound */ + NOTIFICATION_SOUND_TYPE_DEFAULT = 0, + /**< New chat sound */ + NOTIFICATION_SOUND_TYPE_USER_DATA, + /**< User sound data */ + NOTIFICATION_SOUND_TYPE_MAX, + /**< Max flag */ +} notification_sound_type_e; + +/** + * @breief Enumeration for notification vibration type. + */ +typedef enum _notification_vibration_type { + NOTIFICATION_VIBRATION_TYPE_NONE = -1, + /**< Default value. Disable vibration */ + NOTIFICATION_VIBRATION_TYPE_DEFAULT = 0,/**< New chat vibration */ + NOTIFICATION_VIBRATION_TYPE_USER_DATA, + /**< User vibration data */ + NOTIFICATION_VIBRATION_TYPE_MAX,/**< Max flag */ +} notification_vibration_type_e; + +/** + * @breief Will be deprecated. + */ +typedef enum _notification_count_display_type { + NOTIFICATION_COUNT_DISPLAY_TYPE_NONE = -1, + NOTIFICATION_COUNT_DISPLAY_TYPE_LEFT = 0, + NOTIFICATION_COUNT_DISPLAY_TYPE_IN, + NOTIFICATION_COUNT_DISPLAY_TYPE_RIGHT, + NOTIFICATION_COUNT_DISPLAY_TYPE_MAX, +} notification_count_display_type_e; + +/** + * @breief Enumeration for notification count position in the text. + */ +typedef enum _notifcation_count_pos_type { + NOTIFICATION_COUNT_POS_NONE = -1, + /**< Count data is not displaying in the text */ + NOTIFICATION_COUNT_POS_LEFT = 0,/**< Count data is displaying at the left of the text */ + NOTIFICATION_COUNT_POS_IN, + /**< Count data is displaying in the text */ + NOTIFICATION_COUNT_POS_RIGHT, + /**< Count data is displaying at the right of the text */ + NOTIFICATION_COUNT_POS_MAX, + /**< Max flag */ +} notification_count_pos_type_e; + +/** + * @breief Enumeration for notification variable parameter type + */ +typedef enum _notification_variable_type { + NOTIFICATION_VARIABLE_TYPE_NONE = -1, + /**< Variable parameter type is NONE */ + NOTIFICATION_VARIABLE_TYPE_INT = 0, + /**< Variable parameter type is int */ + NOTIFICATION_VARIABLE_TYPE_DOUBLE, + /**< Variable parameter type is double */ + NOTIFICATION_VARIABLE_TYPE_STRING, + /**< Variable parameter type is string */ + NOTIFICATION_VARIABLE_TYPE_COUNT, + /**< Variable parameter type is count */ + NOTIFICATION_VARIABLE_TYPE_MAX, + /**< Max flag */ +} notification_variable_type_e; + +/** + * @breief Enumeration for notification text type. + */ +typedef enum _notification_text_type { + NOTIFICATION_TEXT_TYPE_NONE = -1, + /**< NONE */ + NOTIFICATION_TEXT_TYPE_TITLE = 0, + /**< Title */ + NOTIFICATION_TEXT_TYPE_CONTENT, + /**< Content */ + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + /**< Content for content display option is off of the Settings */ + NOTIFICATION_TEXT_TYPE_GROUP_TITLE, + /**< Group title */ + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT, + /**< Group content */ + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + /**< Group content for content display option is off of the Settings */ + NOTIFICATION_TEXT_TYPE_MAX, + /**< Max flag */ +} notification_text_type_e; + +/** + * @breief Enumeration for image text type. + */ +typedef enum _notification_image_type { + NOTIFICATION_IMAGE_TYPE_NONE = -1, + /**< NONE */ + NOTIFICATION_IMAGE_TYPE_ICON = 0, + /**< Icon */ + NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, + /**< Indicator icon */ + NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, + /**< Lock screen icon */ + NOTIFICATION_IMAGE_TYPE_THUMBNAIL, + /**< Thumbnail */ + NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK, + /**< Lock screen thumbnail */ + NOTIFICATION_IMAGE_TYPE_MAX, + /**< Max flag */ +} notification_image_type_e; + +/*typedef enum _notification_button_type { + NOTIFICATION_BUTTON_TYPE_NONE = -1, + NOTIFICATION_BUTTON_TYPE_RUN = 0, + NOTIFICATION_BUTTON_TYPE_VIEW, + NOTIFICATION_BUTTON_TYPE_DISMISS, + NOTIFICATION_BUTTON_TYPE_MAX, +}notification_button_type_e;*/ + +/** + * @breief Enumeration for application execution type. + */ +typedef enum _notification_execute_type { + NOTIFICATION_EXECUTE_TYPE_NONE = -1, + /**< No operation */ + NOTIFICATION_EXECUTE_TYPE_RESPONDING = 0, + /**< Responding */ + NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,/**< Launching when notification data is single */ + NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, + /**< Launching when notification data is grouping(multi) */ + NOTIFICATION_EXECUTE_TYPE_MAX, + /**< Max flag */ +} notification_execute_type_e; + +/** + * @breief Enumeration for notification type. + */ +typedef enum _notification_type { + NOTIFICATION_TYPE_NONE = -1, + /**< None */ + NOTIFICATION_TYPE_NOTI = 0, + /**< Notification type */ + NOTIFICATION_TYPE_ONGOING, + /**< Ongoing type */ + NOTIFICATION_TYPE_MAX, + /**< Max flag */ +} notification_type_e; + +/** + * @breief Enumeration for Group ID. + */ +enum _notification_group_id { + NOTIFICATION_GROUP_ID_NONE = -1,/**< Not Grouping */ + NOTIFICATION_GROUP_ID_DEFAULT = 0, + /**< Notification that has same title is grouping */ +}; + +/** + * @breief Enumeration for Private ID. + */ +enum _notification_priv_id { + NOTIFICATION_PRIV_ID_NONE = -1, + /**< Internally set priv_id */ +}; + +/** + * @breief Enumeration for notification property + */ +enum _notification_property { + NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE = 0x00000001, + /**< Display only SIM card inserted */ + NOTIFICATION_PROP_DISABLE_APP_LAUNCH = 0x00000002, + /**< Disable application launch when it selected */ + NOTIFICATION_PROP_DISABLE_AUTO_DELETE = 0x00000004, + /**< Disable auto delete when it selected */ + NOTIFICATION_PROP_LAUNCH_UG = 0x00000008, + /**< Will be deprecated. Notification Tray should launch application using appsvc API */ + NOTIFICATION_PROP_DISABLE_TICKERNOTI = 0x00000010, + /**< Will be deprecated. Use notification_set_display_applist API */ + NOTIFICATION_PROP_PERMANENT_DISPLAY = 0x00000020, + /** < Will be deprecated. */ + NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT = 0x00000040,/**< Disable update when it inserted. */ + NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE = 0x00000080,/**< Disable update when it deleted. */ + NOTIFICATION_PROP_VOLATILE_DISPLAY = 0x00000100,/**< Deleted when device is rebooted eventhough NOTIFICATION_TYPE_NOTI type */ +}; + +/** + * @breief Enumeration for display application list + */ +enum _notificaton_display_applist { + NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY = 0x00000001,/**< Notification Tray(Quickpanel) */ + NOTIFICATION_DISPLAY_APP_TICKER = 0x00000002, + /**< Ticker notification */ + NOTIFICATION_DISPLAY_APP_LOCK = 0x00000004, + /**< Lock screen */ + NOTIFICATION_DISPLAY_APP_INDICATOR = 0x00000004,/**< Indicator */ + NOTIFICATION_DISPLAY_APP_ALL = 0xffffffff, + /**< All display application */ +}; + +/** + * @brief Notification handle + */ +typedef struct _notification *notification_h; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* __NOTIFICATION_TYPE_H__ */ diff --git a/notification.pc.in b/notification.pc.in new file mode 100755 index 0000000..a43f5b8 --- /dev/null +++ b/notification.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: notification +Description: Notification Library +Version: @VERSION@ +Requires: sqlite3 heynoti bundle db-util ail aul +Libs: -L${libdir} -lnotification +Cflags: -I${includedir} diff --git a/src/notification.c b/src/notification.c new file mode 100755 index 0000000..d5fdacf --- /dev/null +++ b/src/notification.c @@ -0,0 +1,2755 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <unistd.h> +#include <fcntl.h> +#include <libintl.h> + +#include <aul.h> +#include <ail.h> +#include <appsvc.h> +#include <heynoti.h> +#include <vconf-keys.h> +#include <vconf.h> + +#include <notification.h> +#include <notification_list.h> +#include <notification_debug.h> +#include <notification_internal.h> +#include <notification_noti.h> +#include <notification_ongoing.h> +#include <notification_group.h> + +typedef struct _notification_cb_list notification_cb_list_s; + +struct _notification_cb_list { + notification_cb_list_s *prev; + notification_cb_list_s *next; + + void (*changed_cb) (void *data, notification_type_e type); + void *data; +}; + +static notification_cb_list_s *g_notification_cb_list = NULL; +static int g_notification_heynoti_fd = -1; + +#define NOTI_PKGNAME_LEN 512 +#define NOTI_CHANGED_NOTI "notification_noti_changed" +#define NOTI_CHANGED_ONGOING "notification_ontoing_changed" + +static char *_notification_get_pkgname_by_pid(void) +{ + char buf[NOTI_PKGNAME_LEN] = { 0, }; + char pkgname[NOTI_PKGNAME_LEN] = { 0, }; + int pid = 0, ret = AUL_R_OK; + int fd; + + pid = getpid(); + + ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)); + if (ret != AUL_R_OK) { + snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); + + fd = open(buf, O_RDONLY); + if (fd < 0) { + return NULL; + } + + ret = read(fd, pkgname, sizeof(pkgname) - 1); + if (ret <= 0) { + close(fd); + return NULL; + } + + buf[ret] = 0; + + close(fd); + } + + if (pkgname == NULL || pkgname[0] == '\0') { + return NULL; + } else { + return strdup(pkgname); + } +} + +static char *_notification_get_icon(const char *package) +{ + ail_appinfo_h handle; + ail_error_e ret; + char *str = NULL; + char *icon = NULL; + + ret = ail_package_get_appinfo(package, &handle); + if (ret != AIL_ERROR_OK) { + return NULL; + } + + ret = ail_appinfo_get_str(handle, AIL_PROP_ICON_STR, &str); + if (ret != AIL_ERROR_OK) { + ail_package_destroy_appinfo(handle); + return NULL; + } + + icon = strdup(str); + + ret = ail_package_destroy_appinfo(handle); + if (ret != AIL_ERROR_OK) { + NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo"); + } + + return icon; +} + +static char *_notification_get_name(const char *package) +{ + ail_appinfo_h handle; + ail_error_e ret; + char *str = NULL; + char *name = NULL; + + ret = ail_package_get_appinfo(package, &handle); + if (ret != AIL_ERROR_OK) { + return NULL; + } + + ret = ail_appinfo_get_str(handle, AIL_PROP_NAME_STR, &str); + if (ret != AIL_ERROR_OK) { + ail_package_destroy_appinfo(handle); + return NULL; + } + + name = strdup(str); + + ret = ail_package_destroy_appinfo(handle); + if (ret != AIL_ERROR_OK) { + NOTIFICATION_ERR("Fail to ail_package_destroy_appinfo"); + } + + return name; +} + +static void _notification_get_text_domain(notification_h noti) +{ + if (noti->domain != NULL) { + + } + + if (noti->dir != NULL) { + + } +} + +static void _notification_chagned_noti_cb(void *data) +{ + notification_cb_list_s *noti_cb_list = NULL; + + if (g_notification_cb_list == NULL) { + return; + } + + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + while (noti_cb_list != NULL) { + if (noti_cb_list->changed_cb) { + noti_cb_list->changed_cb(noti_cb_list->data, + NOTIFICATION_TYPE_NOTI); + } + + noti_cb_list = noti_cb_list->next; + } +} + +#if 0 +static void _notification_chagned_ongoing_cb(void *data) +{ + notification_cb_list_s *noti_cb_list = NULL; + + if (g_notification_cb_list == NULL) { + return; + } + + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + while (noti_cb_list != NULL) { + if (noti_cb_list->changed_cb) { + noti_cb_list->changed_cb(noti_cb_list->data, + NOTIFICATION_TYPE_ONGOING); + } + + noti_cb_list = noti_cb_list->next; + } +} +#endif + +static void _notification_changed(const char *type) +{ + heynoti_publish(type); +} + +/* notification_set_icon will be removed */ +EXPORT_API notification_error_e notification_set_icon(notification_h noti, + const char *icon_path) +{ + int ret_err = NOTIFICATION_ERROR_NONE; + + ret_err = + notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + icon_path); + + return ret_err; +} + +/* notification_get_icon will be removed */ +EXPORT_API notification_error_e notification_get_icon(notification_h noti, + char **icon_path) +{ + int ret_err = NOTIFICATION_ERROR_NONE; + char *ret_image_path = NULL; + + ret_err = + notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + &ret_image_path); + + if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL) { + *icon_path = ret_image_path; + + //NOTIFICATION_DBG("Get icon : %s", *icon_path); + } + + return ret_err; +} + +EXPORT_API notification_error_e notification_set_image(notification_h noti, + notification_image_type_e type, + const char *image_path) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + + /* Check noti and image_path are valid data */ + if (noti == NULL || image_path == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image type is valid type */ + if (type <= NOTIFICATION_IMAGE_TYPE_NONE + || type >= NOTIFICATION_IMAGE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image path bundle is exist */ + if (noti->b_image_path) { + /* If image path bundle is exist, store local bundle value */ + b = noti->b_image_path; + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If key is exist, remove this value to store new image path */ + bundle_del(b, buf_key); + } + + /* Add new image path with type key */ + bundle_add(b, buf_key, image_path); + } else { + /* If image path bundle is not exist, create new one */ + b = bundle_create(); + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Add new image path with type key */ + bundle_add(b, buf_key, image_path); + + /* Save to image path bundle */ + noti->b_image_path = b; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_image(notification_h noti, + notification_image_type_e type, + char **image_path) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + const char *pkgname = NULL; + + /* Check noti and image_path is valid data */ + if (noti == NULL || image_path == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image type is valid data */ + if (type <= NOTIFICATION_IMAGE_TYPE_NONE + || type >= NOTIFICATION_IMAGE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check image path bundle exist */ + if (noti->b_image_path) { + /* If image path bundle exist, store local bundle data */ + b = noti->b_image_path; + + /* Set image type to key as char string type */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value of key */ + ret_val = bundle_get_val(b, buf_key); + + *image_path = (char *)ret_val; + } else { + /* If image path bundle does not exist, image path is NULL */ + *image_path = NULL; + } + + /* If image path is NULL and type is ICON, icon path set from AIL */ + /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */ + if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) { + /* Check App icon path is already set */ + if (noti->app_icon_path != NULL) { + /* image path will be app icon path */ + *image_path = noti->app_icon_path; + } else { + /* Get image path using launch_pkgname */ + if (noti->launch_pkgname != NULL) { + noti->app_icon_path = + _notification_get_icon(noti->launch_pkgname); + } + + /* If app icon path is NULL, get image path using caller_pkgname */ + if (noti->app_icon_path == NULL + && noti->caller_pkgname != NULL) { + noti->app_icon_path = + _notification_get_icon(noti->caller_pkgname); + } + + /* If app icon path is NULL, get image path using service data */ + if (noti->app_icon_path == NULL + && noti->b_service_single_launch != NULL) { + pkgname = + appsvc_get_pkgname(noti->b_service_single_launch); + if (pkgname != NULL) { + noti->app_icon_path = + _notification_get_icon(pkgname); + } + } + + *image_path = noti->app_icon_path; + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_time(notification_h noti, + time_t input_time) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (input_time == 0) { + /* If input time is 0, set current time */ + noti->time = time(NULL); + } else { + /* save input time */ + noti->time = input_time; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_time(notification_h noti, + time_t * ret_time) +{ + /* Check noti and time is valid data */ + if (noti == NULL || ret_time == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set time infomation */ + *ret_time = noti->time; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_insert_time(notification_h noti, + time_t * ret_time) +{ + /* Check noti and ret_time is valid data */ + if (noti == NULL || ret_time == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set insert time information */ + *ret_time = noti->insert_time; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_title(notification_h noti, + const char *title, + const char *loc_title) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + title, loc_title, + NOTIFICATION_VARIABLE_TYPE_NONE); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_title(notification_h noti, + char **title, + char **loc_title) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + char *ret_text = NULL; + + noti_err = + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + &ret_text); + + if (title != NULL) { + *title = ret_text; + } + + if (loc_title != NULL) { + *loc_title = NULL; + } + + return noti_err; +} + +EXPORT_API notification_error_e notification_set_group_title(const char *pkgname, + int group_id, + const char *title, + const char *loc_title, + notification_count_display_type_e count_display) +{ + char *caller_pkgname = NULL; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + if ((title == NULL && loc_title == NULL)) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + + noti_err = + notification_group_set_title(caller_pkgname, group_id, + title, loc_title, + count_display); + + if (caller_pkgname != NULL) { + free(caller_pkgname); + } + } else { + noti_err = + notification_group_set_title(pkgname, group_id, title, + loc_title, count_display); + } + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_group_title(const char *pkgname, + int group_id, + char **title, + char **loc_title, + notification_count_display_type_e *count_display) +{ + char *caller_pkgname = NULL; + char *ret_title = NULL; + char *ret_loc_title = NULL; + notification_count_display_type_e ret_count_display; + int ret = NOTIFICATION_ERROR_NONE; + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + + ret = + notification_group_get_title(caller_pkgname, group_id, + &ret_title, &ret_loc_title, + &ret_count_display); + + if (caller_pkgname != NULL) { + free(caller_pkgname); + } + } else { + ret = + notification_group_get_title(pkgname, group_id, &ret_title, + &ret_loc_title, + &ret_count_display); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *title = ret_title; + *loc_title = ret_loc_title; + *count_display = ret_count_display; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_content(notification_h noti, + const char *content, + const char *loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + content, loc_content, + NOTIFICATION_VARIABLE_TYPE_NONE); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_content(notification_h noti, + char **content, + char **loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + char *ret_text = NULL; + + noti_err = + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + &ret_text); + + if (content != NULL) { + *content = ret_text; + } + + if (loc_content != NULL) { + *loc_content = NULL; + } + + return noti_err; + +#if 0 + ret = + vconf_get_bool + (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval); + + if (ret == -1 || boolval == 0) { + if (content != NULL && noti->default_content != NULL) { + *content = noti->default_content; + } + + if (loc_content != NULL && noti->loc_default_content != NULL) { + *loc_content = noti->loc_default_content; + } + } +#endif +} + +EXPORT_API notification_error_e notification_set_default_content(notification_h noti, + const char *content, + const char *loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = + notification_set_text(noti, + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + content, loc_content, + NOTIFICATION_VARIABLE_TYPE_NONE); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_default_content(notification_h noti, + char **content, + char **loc_content) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + char *ret_text = NULL; + + noti_err = + notification_get_text(noti, + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + &ret_text); + + if (content != NULL) { + *content = ret_text; + } + + if (loc_content != NULL) { + *loc_content = NULL; + } + + return noti_err; +} + +EXPORT_API notification_error_e notification_set_group_content(const char *pkgname, + int group_id, + const char *content, + const char *loc_content, + notification_count_display_type_e count_display) +{ + const char *caller_pkgname = NULL; + if ((content == NULL && loc_content == NULL)) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (group_id < NOTIFICATION_GROUP_ID_DEFAULT) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) + caller_pkgname = _notification_get_pkgname_by_pid(); + else + caller_pkgname = pkgname; + + notification_group_set_content(caller_pkgname, group_id, content, + loc_content, count_display); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_group_content(const char *pkgname, + int group_id, + char **content, + char **loc_content, + notification_count_display_type_e *count_display) +{ + const char *caller_pkgname = NULL; + char *ret_content = NULL; + char *ret_loc_content = NULL; + notification_count_display_type_e ret_count_display; + int ret = NOTIFICATION_ERROR_NONE; + + if (pkgname == NULL) + caller_pkgname = _notification_get_pkgname_by_pid(); + else + caller_pkgname = pkgname; + + ret = + notification_group_get_content(caller_pkgname, group_id, + &ret_content, &ret_loc_content, + &ret_count_display); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *content = ret_content; + *loc_content = ret_loc_content; + *count_display = ret_count_display; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_text(notification_h noti, + notification_text_type_e type, + const char *text, + const char *key, + int args_type, ...) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + char buf_val[1024] = { 0, }; + const char *ret_val = NULL; + va_list var_args; + notification_variable_type_e var_type; + int num_args = 0; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + int var_value_int = 0; + double var_value_double = 0.0; + char *var_value_string = NULL; + notification_count_pos_type_e var_value_count = + NOTIFICATION_COUNT_POS_NONE; + + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text type is valid type */ + if (type <= NOTIFICATION_TEXT_TYPE_NONE + || type >= NOTIFICATION_TEXT_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text bundle exist */ + if (text != NULL) { + if (noti->b_text != NULL) { + /* If text bundle exist, store local bundle data */ + b = noti->b_text; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this to add new value */ + bundle_del(b, buf_key); + } + + snprintf(buf_val, sizeof(buf_val), "%s", text); + + /* Add new text value */ + bundle_add(b, buf_key, buf_val); + } else { + /* If text bundle does not exist, create new one */ + b = bundle_create(); + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + snprintf(buf_val, sizeof(buf_val), "%s", text); + + /* Add new text value */ + bundle_add(b, buf_key, buf_val); + + /* Save text bundle */ + noti->b_text = b; + } + } + + /* Save key if key is valid data */ + if (key != NULL) { + /* Check key bundle exist */ + if (noti->b_key != NULL) { + /* If key bundle exist, store local bundle data */ + b = noti->b_key; + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + /* Get value using type key */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* If value exist, remove this to add new value */ + bundle_del(b, buf_key); + } + + snprintf(buf_val, sizeof(buf_val), "%s", key); + + /* Add new key value */ + bundle_add(b, buf_key, buf_val); + } else { + /* If key bundle does not exist, create new one */ + b = bundle_create(); + + /* Make type to key as char string */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + snprintf(buf_val, sizeof(buf_val), "%s", key); + + /* Add new key value */ + bundle_add(b, buf_key, buf_val); + + /* Save key bundle */ + noti->b_key = b; + } + } + + if (noti->b_format_args != NULL) { + b = noti->b_format_args; + } else { + b = bundle_create(); + } + + va_start(var_args, args_type); + + var_type = args_type; + num_args = 0; + + while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) { + /* Type */ + snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args); + snprintf(buf_val, sizeof(buf_val), "%d", var_type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + + switch (var_type) { + case NOTIFICATION_VARIABLE_TYPE_INT: + var_value_int = va_arg(var_args, int); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%d", var_value_int); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_DOUBLE: + var_value_double = va_arg(var_args, double); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%.2f", + var_value_double); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_STRING: + var_value_string = va_arg(var_args, char *); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%s", + var_value_string); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + case NOTIFICATION_VARIABLE_TYPE_COUNT: + var_value_count = + va_arg(var_args, notification_count_pos_type_e); + + /* Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type, + num_args); + snprintf(buf_val, sizeof(buf_val), "%d", + var_value_count); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + break; + default: + NOTIFICATION_ERR("Error. invalid variable type. : %d", + var_type); + noti_err = NOTIFICATION_ERROR_INVALID_DATA; + break; + } + + num_args++; + var_type = va_arg(var_args, notification_variable_type_e); + } + va_end(var_args); + + if (noti_err == NOTIFICATION_ERROR_NONE) { + noti->num_format_args = num_args; + } else { + noti->num_format_args = 0; + } + + snprintf(buf_key, sizeof(buf_key), "num%d", type); + snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + bundle_del(b, buf_key); + } + + bundle_add(b, buf_key, buf_val); + + noti->b_format_args = b; + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_text(notification_h noti, + notification_text_type_e type, + char **text) +{ + bundle *b = NULL; + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + const char *pkgname = NULL; + const char *get_str = NULL; + const char *get_check_type_str = NULL; + int ret = 0; + int boolval = 0; + notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE; + int display_option_flag = 0; + + char *temp_str = NULL; + char result_str[1024] = { 0, }; + char buf_str[1024] = { 0, }; + int num_args = 0; + notification_variable_type_e ret_var_type = 0; + int ret_variable_int = 0; + double ret_variable_double = 0.0; + + /* Check noti is valid data */ + if (noti == NULL || text == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check text type is valid type */ + if (type <= NOTIFICATION_TEXT_TYPE_NONE + || type >= NOTIFICATION_TEXT_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check content display option of setting */ + if (type == NOTIFICATION_TEXT_TYPE_CONTENT + || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) { + ret = + vconf_get_bool + (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, + &boolval); + if (ret == -1 || boolval == 0) { + /* Set flag as display option is OFF */ + display_option_flag = 1; + } + } + + /* Check key */ + if (noti->b_key != NULL) { + b = noti->b_key; + + /* Get text domain and dir */ + _notification_get_text_domain(noti); + + snprintf(buf_key, sizeof(buf_key), "%d", type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_str = dgettext(noti->domain, ret_val); + } else if (ret_val != NULL) { + /* Get system string */ + get_str = dgettext("sys_string", ret_val); + } else { + get_str = NULL; + } + } + + if (get_str == NULL && noti->b_text != NULL) { + b = noti->b_text; + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "%d", type); + + get_str = bundle_get_val(b, buf_key); + } + + check_type = type; + + /* Set display option is off type when option is off, type is noti */ + if (get_str != NULL && display_option_flag == 1 + && noti->type == NOTIFICATION_TYPE_NOTI) { + if (type == NOTIFICATION_TEXT_TYPE_CONTENT + || type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) { + /* Set check_type to option content string */ + if (type == NOTIFICATION_TEXT_TYPE_CONTENT) { + check_type = + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF; + } else if (type == NOTIFICATION_TEXT_TYPE_GROUP_CONTENT) { + check_type = + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF; + } + + /* Check key */ + if (noti->b_key != NULL) { + b = noti->b_key; + + /* Get text domain and dir */ + _notification_get_text_domain(noti); + + snprintf(buf_key, sizeof(buf_key), "%d", + check_type); + + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_check_type_str = + dgettext(noti->domain, ret_val); + } else if (ret_val != NULL) { + /* Get system string */ + get_check_type_str = + dgettext("sys_string", ret_val); + } else { + get_check_type_str = NULL; + } + } + + if (get_check_type_str == NULL && noti->b_text != NULL) { + b = noti->b_text; + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "%d", + check_type); + + get_check_type_str = bundle_get_val(b, buf_key); + } + } + + if (get_check_type_str != NULL) { + /* Replace option off type string */ + get_str = get_check_type_str; + } else { + /* Set default string */ + get_str = + dgettext("sys_string", "IDS_COM_POP_MISSED_EVENT"); + } + } + + if (get_str != NULL) { + /* Get number format args */ + b = noti->b_format_args; + noti->num_format_args = 0; + + if (b != NULL) { + snprintf(buf_key, sizeof(buf_key), "num%d", check_type); + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + noti->num_format_args = atoi(ret_val); + } + } + + if (noti->num_format_args == 0) { + *text = (char *)get_str; + } else { + /* Check first variable is count, LEFT pos */ + snprintf(buf_key, sizeof(buf_key), "%dtype%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + + if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) { + /* Get var Value */ + snprintf(buf_key, sizeof(buf_key), "%dvalue%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_variable_int = atoi(ret_val); + + if (ret_variable_int == + NOTIFICATION_COUNT_POS_LEFT) { + notification_noti_get_count(noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + snprintf(buf_str, sizeof(buf_str), + "%d ", ret_variable_int); + strncat(result_str, buf_str, + sizeof(result_str)); + + num_args++; + } + + } + + /* Check variable IN pos */ + for (temp_str = (char *)get_str; *temp_str != '\0'; + temp_str++) { + if (*temp_str != '%') { + strncat(result_str, temp_str, 1); + } else { + if (*(temp_str + 1) == '%') { + strncat(result_str, temp_str, + 1); + } else if (*(temp_str + 1) == 'd') { + /* Get var Type */ + ret_variable_int = 0; + + snprintf(buf_key, + sizeof(buf_key), + "%dtype%d", check_type, + num_args); + ret_val = + bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + if (ret_var_type == + NOTIFICATION_VARIABLE_TYPE_COUNT) + { + /* Get notification count */ + notification_noti_get_count + (noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + } else { + /* Get var Value */ + snprintf(buf_key, + sizeof + (buf_key), + "%dvalue%d", + check_type, + num_args); + ret_val = + bundle_get_val(b, + buf_key); + ret_variable_int = + atoi(ret_val); + } + + snprintf(buf_str, + sizeof(buf_str), "%d", + ret_variable_int); + strncat(result_str, buf_str, + sizeof(result_str)); + + temp_str++; + + num_args++; + } else if (*(temp_str + 1) == 's') { + /* Get var Value */ + snprintf(buf_key, + sizeof(buf_key), + "%dvalue%d", + check_type, num_args); + ret_val = + bundle_get_val(b, buf_key); + + snprintf(buf_str, + sizeof(buf_str), "%s", + ret_val); + strncat(result_str, buf_str, + sizeof(result_str)); + + temp_str++; + + num_args++; + } else if (*(temp_str + 1) == 'f') { + /* Get var Value */ + snprintf(buf_key, + sizeof(buf_key), + "%dvalue%d", + check_type, num_args); + ret_val = + bundle_get_val(b, buf_key); + ret_variable_double = + atof(ret_val); + + snprintf(buf_str, + sizeof(buf_str), + "%.2f", + ret_variable_double); + strncat(result_str, buf_str, + sizeof(result_str)); + + temp_str++; + + num_args++; + } + } + + } + + /* Check last variable is count, LEFT pos */ + if (num_args < noti->num_format_args) { + snprintf(buf_key, sizeof(buf_key), "%dtype%d", + check_type, num_args); + ret_val = bundle_get_val(b, buf_key); + ret_var_type = atoi(ret_val); + if (ret_var_type == + NOTIFICATION_VARIABLE_TYPE_COUNT) { + /* Get var Value */ + snprintf(buf_key, sizeof(buf_key), + "%dvalue%d", check_type, + num_args); + ret_val = bundle_get_val(b, buf_key); + ret_variable_int = atoi(ret_val); + + if (ret_variable_int == + NOTIFICATION_COUNT_POS_RIGHT) { + notification_noti_get_count + (noti->type, + noti->caller_pkgname, + noti->group_id, + noti->priv_id, + &ret_variable_int); + snprintf(buf_str, + sizeof(buf_str), " %d", + ret_variable_int); + strncat(result_str, buf_str, + sizeof(result_str)); + + num_args++; + } + + } + } + + switch (check_type) { + case NOTIFICATION_TEXT_TYPE_TITLE: + case NOTIFICATION_TEXT_TYPE_GROUP_TITLE: + if (noti->temp_title != NULL) + free(noti->temp_title); + + noti->temp_title = strdup(result_str); + + *text = noti->temp_title; + break; + case NOTIFICATION_TEXT_TYPE_CONTENT: + case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF: + case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT: + case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF: + if (noti->temp_content != + NULL) + free(noti->temp_content); + + noti->temp_content = strdup(result_str); + + *text = noti->temp_content; + break; + default: + break; + } + + } + + } else { + if (check_type == NOTIFICATION_TEXT_TYPE_TITLE + || check_type == NOTIFICATION_TEXT_TYPE_GROUP_TITLE) { + /* Remove app name if exist, because pkgname is changed according to language setting */ + if (noti->app_name != NULL) { + free(noti->app_name); + noti->app_name = NULL; + } + + /* First, get app name from launch_pkgname */ + if (noti->launch_pkgname != NULL) { + noti->app_name = + _notification_get_name(noti-> + launch_pkgname); + } + + /* Second, get app name from caller_pkgname */ + if (noti->app_name == NULL + && noti->caller_pkgname != NULL) { + noti->app_name = + _notification_get_name(noti-> + caller_pkgname); + } + + /* Third, get app name from service data */ + if (noti->app_name == NULL + && noti->b_service_single_launch != NULL) { + pkgname = + appsvc_get_pkgname(noti-> + b_service_single_launch); + + if (pkgname != NULL) { + noti->app_name = + _notification_get_name(pkgname); + } + } + + *text = noti->app_name; + } else { + *text = NULL; + } + } + + NOTIFICATION_INFO("Get text : %s", *text); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_text_domain(notification_h noti, + const char *domain, + const char *dir) +{ + /* check noti and domain is valid data */ + if (noti == NULL || domain == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check domain */ + if (noti->domain) { + /* Remove previous domain */ + free(noti->domain); + } + /* Copy domain */ + noti->domain = strdup(domain); + + /* Check locale dir */ + if (noti->dir) { + /* Remove previous locale dir */ + free(noti->dir); + } + /* Copy locale dir */ + noti->dir = strdup(dir); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_text_domain(notification_h noti, + char **domain, + char **dir) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Get domain */ + if (domain != NULL && noti->domain != NULL) { + *domain = noti->domain; + } + + /* Get locale dir */ + if (dir != NULL && noti->dir != NULL) { + *dir = noti->dir; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_sound(notification_h noti, + notification_sound_type_e type, + const char *path) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check type is valid */ + if (type < NOTIFICATION_SOUND_TYPE_NONE + || type >= NOTIFICATION_SOUND_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save sound type */ + noti->sound_type = type; + + /* Save sound path if user data type */ + if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) { + if (noti->sound_path != NULL) { + free(noti->sound_path); + } + + noti->sound_path = strdup(path); + } else { + if (noti->sound_path != NULL) { + free(noti->sound_path); + noti->sound_path = NULL; + } + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_sound(notification_h noti, + notification_sound_type_e *type, + const char **path) +{ + /* check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set sound type */ + *type = noti->sound_type; + + /* Set sound path if user data type */ + if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA + && path != NULL) { + *path = noti->sound_path; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_vibration(notification_h noti, + notification_vibration_type_e type, + const char *path) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check type is valid */ + if (type < NOTIFICATION_VIBRATION_TYPE_NONE + || type >= NOTIFICATION_VIBRATION_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save vibration type */ + noti->vibration_type = type; + + /* Save sound path if user data type */ + if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) { + if (noti->vibration_path != NULL) { + free(noti->vibration_path); + } + + noti->vibration_path = strdup(path); + } else { + if (noti->vibration_path != NULL) { + free(noti->vibration_path); + noti->vibration_path = NULL; + } + } + + return NOTIFICATION_ERROR_NONE; + +} + +EXPORT_API notification_error_e notification_get_vibration(notification_h noti, + notification_vibration_type_e *type, + const char **path) +{ + /* check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set vibration type */ + *type = noti->vibration_type; + + /* Set sound path if user data type */ + if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA + && path != NULL) { + *path = noti->vibration_path; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_application(notification_h noti, + const char *pkgname) +{ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->launch_pkgname) { + free(noti->launch_pkgname); + } + + noti->launch_pkgname = strdup(pkgname); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_application(notification_h noti, + char **pkgname) +{ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->launch_pkgname) { + *pkgname = noti->launch_pkgname; + } else { + *pkgname = noti->caller_pkgname; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_args(notification_h noti, + bundle * args, + bundle * group_args) +{ + if (noti == NULL || args == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->args) { + bundle_free(noti->args); + } + + noti->args = bundle_dup(args); + + if (noti->group_args) { + bundle_free(noti->group_args); + noti->group_args = NULL; + } + + if (group_args != NULL) { + noti->group_args = bundle_dup(group_args); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_args(notification_h noti, + bundle ** args, + bundle ** group_args) +{ + if (noti == NULL || args == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->args) { + *args = noti->args; + } else { + *args = NULL; + } + + if (group_args != NULL && noti->group_args) { + *group_args = noti->group_args; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_service_data(notification_h noti, + bundle * service_data, + bundle * group_service_data) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + + noti_err = + notification_set_execute_option(noti, + NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, + NULL, NULL, service_data); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return noti_err; + } + + noti_err = + notification_set_execute_option(noti, + NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, + NULL, NULL, group_service_data); + + return noti_err; +} + +EXPORT_API notification_error_e notification_get_service_data(notification_h noti, + bundle ** service_data, + bundle ** group_service_data) +{ + int noti_err = NOTIFICATION_ERROR_NONE; + bundle *get_service_data = NULL; + + noti_err = + notification_get_execute_option(noti, + NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, + NULL, &get_service_data); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return noti_err; + } + + if (service_data != NULL) { + *service_data = get_service_data; + } + + noti_err = + notification_get_execute_option(noti, + NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, + NULL, &get_service_data); + if (noti_err != NOTIFICATION_ERROR_NONE) { + return noti_err; + } + + if (service_data != NULL) { + *group_service_data = get_service_data; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_execute_option(notification_h noti, + notification_execute_type_e type, + const char *text, + const char *key, + bundle *service_handle) +{ + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + bundle *b = NULL; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (type <= NOTIFICATION_EXECUTE_TYPE_NONE + || type >= NOTIFICATION_EXECUTE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Create execute option bundle if does not exist */ + if (noti->b_execute_option != NULL) { + noti->b_execute_option = bundle_create(); + } + + b = noti->b_execute_option; + + /* Save text */ + if (text != NULL) { + /* Make text key */ + snprintf(buf_key, sizeof(buf_key), "text%d", type); + + /* Check text key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* Remove previous data */ + bundle_del(b, buf_key); + } + + /* Add text data */ + bundle_add(b, buf_key, text); + } + + /* Save key */ + if (key != NULL) { + /* Make key key */ + snprintf(buf_key, sizeof(buf_key), "key%d", type); + + /* Check key key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL) { + /* Remove previous data */ + bundle_del(b, buf_key); + } + + /* Add text data */ + bundle_add(b, buf_key, key); + } + + switch (type) { + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + /* Remove previous data if exist */ + if (noti->b_service_responding != NULL) { + bundle_free(noti->b_service_responding); + noti->b_service_responding = NULL; + } + + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_responding = bundle_dup(service_handle); + } + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + /* Remove previous data if exist */ + if (noti->b_service_single_launch != NULL) { + bundle_free(noti->b_service_single_launch); + noti->b_service_single_launch = NULL; + } + + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_single_launch = + bundle_dup(service_handle); + } + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + /* Remove previous data if exist */ + if (noti->b_service_multi_launch != NULL) { + bundle_free(noti->b_service_multi_launch); + noti->b_service_multi_launch = NULL; + } + + /* Save service handle */ + if (service_handle != NULL) { + noti->b_service_multi_launch = + bundle_dup(service_handle); + } + break; + default: + break; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_execute_option(notification_h noti, + notification_execute_type_e type, + const char **text, + bundle **service_handle) +{ + char buf_key[32] = { 0, }; + const char *ret_val = NULL; + char *get_str = NULL; + bundle *b = NULL; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (type <= NOTIFICATION_EXECUTE_TYPE_NONE + || type >= NOTIFICATION_EXECUTE_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + switch (type) { + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + b = noti->b_service_responding; + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + b = noti->b_service_single_launch; + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + b = noti->b_service_multi_launch; + break; + default: + b = NULL; + break; + } + + if (b != NULL) { + // Return text + if (text != NULL) { + // Get text domain and dir + if (noti->domain == NULL || noti->dir == NULL) { + _notification_get_text_domain(noti); + } + + /* Make key */ + snprintf(buf_key, sizeof(buf_key), "key%d", type); + + /* Check key key exist */ + ret_val = bundle_get_val(b, buf_key); + if (ret_val != NULL && noti->domain != NULL + && noti->dir != NULL) { + /* Get application string */ + bindtextdomain(noti->domain, noti->dir); + + get_str = dgettext(noti->domain, ret_val); + + *text = get_str; + } else if (ret_val != NULL) { + /* Get system string */ + get_str = dgettext("sys_string", ret_val); + + *text = get_str; + } else { + /* Get basic text */ + snprintf(buf_key, sizeof(buf_key), "text%d", + type); + + ret_val = bundle_get_val(b, buf_key); + + *text = ret_val; + } + } + } + + switch (type) { + case NOTIFICATION_EXECUTE_TYPE_RESPONDING: + b = noti->b_service_responding; + break; + case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH: + b = noti->b_service_single_launch; + break; + case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH: + b = noti->b_service_multi_launch; + break; + default: + b = NULL; + break; + } + + if (service_handle != NULL) { + *service_handle = b; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_property(notification_h noti, + int flags) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set flags */ + noti->flags_for_property = flags; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_property(notification_h noti, + int *flags) +{ + /* Check noti and flags are valid data */ + if (noti == NULL || flags == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set flags */ + *flags = noti->flags_for_property; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_display_applist(notification_h noti, + int applist) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set app list */ + noti->display_applist = applist; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_display_applist(notification_h noti, + int *applist) +{ + /* Check noti and applist are valid data */ + if (noti == NULL || applist == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set app list */ + *applist = noti->display_applist; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_size(notification_h noti, + double size) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save progress size */ + noti->progress_size = size; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_size(notification_h noti, + double *size) +{ + /* Check noti and size is valid data */ + if (noti == NULL || size == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set progress size */ + *size = noti->progress_size; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_progress(notification_h noti, + double percentage) +{ + /* Check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save progress percentage */ + noti->progress_percentage = percentage; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_progress(notification_h noti, + double *percentage) +{ + /* Check noti and percentage are valid data */ + if (noti == NULL || percentage == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set progress percentage */ + *percentage = noti->progress_percentage; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_pkgname(notification_h noti, + const char *pkgname) +{ + /* check noti and pkgname are valid data */ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Remove previous caller pkgname */ + if (noti->caller_pkgname) { + free(noti->caller_pkgname); + noti->caller_pkgname = NULL; + } + + noti->caller_pkgname = strdup(pkgname); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_pkgname(notification_h noti, + char **pkgname) +{ + /* Check noti and pkgname are valid data */ + if (noti == NULL || pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Get caller pkgname */ + if (noti->caller_pkgname) { + *pkgname = noti->caller_pkgname; + } else { + *pkgname = NULL; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_set_unread_count(const char *pkgname, + int group_id, + int unread_count) +{ + int ret = NOTIFICATION_ERROR_NONE; + + ret = notification_set_badge(pkgname, group_id, unread_count); + + return ret; +} + +EXPORT_API notification_error_e notification_get_unread_count(const char *pkgname, + int group_id, + int *unread_count) +{ + int ret = NOTIFICATION_ERROR_NONE; + int ret_unread_count = 0; + + ret = notification_get_badge(pkgname, group_id, &ret_unread_count); + + if (unread_count != NULL) { + *unread_count = ret_unread_count; + } + + return ret; +} + +EXPORT_API notification_error_e notification_set_badge(const char *pkgname, + int group_id, int count) +{ + char *caller_pkgname = NULL; + int ret = NOTIFICATION_ERROR_NONE; + + /* Check count is valid count */ + if (count < 0) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check pkgname */ + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + + /* Set count into Group DB */ + ret = + notification_group_set_badge(caller_pkgname, group_id, + count); + + if (caller_pkgname != NULL) { + free(caller_pkgname); + } + } else { + /* Set count into Group DB */ + ret = notification_group_set_badge(pkgname, group_id, count); + } + + return ret; +} + +EXPORT_API notification_error_e notification_get_badge(const char *pkgname, + int group_id, int *count) +{ + char *caller_pkgname = NULL; + int ret = NOTIFICATION_ERROR_NONE; + int ret_unread_count = 0; + + /* Check pkgname */ + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + + /* Get count from Group DB */ + ret = + notification_group_get_badge(caller_pkgname, group_id, + &ret_unread_count); + + if (caller_pkgname != NULL) { + free(caller_pkgname); + } + } else { + /* Get count from Group DB */ + ret = + notification_group_get_badge(pkgname, group_id, + &ret_unread_count); + } + + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* Set count */ + if (count != NULL) { + *count = ret_unread_count; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_id(notification_h noti, + int *group_id, int *priv_id) +{ + /* check noti is valid data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check group_id is valid data */ + if (group_id) { + /* Set group id */ + if (noti->group_id < NOTIFICATION_GROUP_ID_NONE) { + *group_id = NOTIFICATION_GROUP_ID_NONE; + } else { + *group_id = noti->group_id; + } + } + + /* Check priv_id is valid data */ + if (priv_id) { + /* Set priv_id */ + *priv_id = noti->priv_id; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_type(notification_h noti, + notification_type_e *type) +{ + /* Check noti and type is valid data */ + if (noti == NULL || type == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Set noti type */ + *type = noti->type; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_insert(notification_h noti, + int *priv_id) +{ + int ret = 0; + + /* Check noti is vaild data */ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Check noti type is valid type */ + if (noti->type <= NOTIFICATION_TYPE_NONE + || noti->type >= NOTIFICATION_TYPE_MAX) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Save insert time */ + noti->insert_time = time(NULL); + + /* Insert into DB */ + ret = notification_noti_insert(noti); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* Check disable update on insert property */ + if (noti->flags_for_property + & NOTIFICATION_PROP_DISABLE_UPDATE_ON_INSERT) { + /* Disable changed cb */ + } else { + /* Enable changed cb */ + _notification_changed(NOTI_CHANGED_NOTI); + } + + /* If priv_id is valid data, set priv_id */ + if (priv_id != NULL) { + *priv_id = noti->priv_id; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update(notification_h noti) +{ + /* Check noti is valid data */ + if (noti != NULL) { + /* TODO : Update noti */ + } + + /* Send changed notification */ + _notification_changed(NOTI_CHANGED_NOTI); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notifiation_clear(notification_type_e type) +{ + int ret = 0; + + /* Delete all notification of type */ + ret = notification_noti_delete_all(type, NULL); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* Send chagned notification */ + _notification_changed(NOTI_CHANGED_NOTI); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_delete_all_by_type(const char *pkgname, + notification_type_e type) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = notification_noti_delete_all(type, caller_pkgname); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + _notification_changed(NOTI_CHANGED_NOTI); + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete_group_by_group_id(const char *pkgname, + notification_type_e type, + int group_id) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (group_id < NOTIFICATION_GROUP_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = + notification_noti_delete_group_by_group_id(caller_pkgname, + group_id); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + _notification_changed(NOTI_CHANGED_NOTI); + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete_group_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (priv_id < NOTIFICATION_PRIV_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = + notification_noti_delete_group_by_priv_id(caller_pkgname, priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + _notification_changed(NOTI_CHANGED_NOTI); + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete_by_priv_id(const char *pkgname, + notification_type_e type, + int priv_id) +{ + int ret = 0; + char *caller_pkgname = NULL; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (pkgname == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(pkgname); + } + + ret = notification_noti_delete_by_priv_id(caller_pkgname, priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + free(caller_pkgname); + return ret; + } + + _notification_changed(NOTI_CHANGED_NOTI); + + free(caller_pkgname); + + return ret; +} + +EXPORT_API notification_error_e notification_delete(notification_h noti) +{ + int ret = 0; + + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = + notification_noti_delete_by_priv_id(noti->caller_pkgname, + noti->priv_id); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + if (noti->flags_for_property + & NOTIFICATION_PROP_DISABLE_UPDATE_ON_DELETE) { + NOTIFICATION_INFO("Disabled update while delete."); + } else { + _notification_changed(NOTI_CHANGED_NOTI); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update_progress(notification_h noti, + int priv_id, + double progress) +{ + char *caller_pkgname = NULL; + int input_priv_id = 0; + double input_progress = 0.0; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } else { + input_priv_id = noti->priv_id; + } + } else { + input_priv_id = priv_id; + } + + if (noti == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(noti->caller_pkgname); + } + + if (progress < 0.0) { + input_progress = 0.0; + } else if (progress > 1.0) { + input_progress = 1.0; + } else { + input_progress = progress; + } + + notification_ongoing_update_progress(caller_pkgname, input_priv_id, + input_progress); + + if (caller_pkgname) { + free(caller_pkgname); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_update_size(notification_h noti, + int priv_id, + double size) +{ + char *caller_pkgname = NULL; + int input_priv_id = 0; + double input_size = 0.0; + + if (priv_id <= NOTIFICATION_PRIV_ID_NONE) { + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } else { + input_priv_id = noti->priv_id; + } + } else { + input_priv_id = priv_id; + } + + if (noti == NULL) { + caller_pkgname = _notification_get_pkgname_by_pid(); + } else { + caller_pkgname = strdup(noti->caller_pkgname); + } + + if (size < 0.0) { + input_size = 0.0; + } else { + input_size = size; + } + + notification_ongoing_update_size(caller_pkgname, input_priv_id, + input_size); + + if (caller_pkgname) { + free(caller_pkgname); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_h notification_new(notification_type_e type, + int group_id, int priv_id) +{ + notification_h noti = NULL; + + if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) { + NOTIFICATION_ERR("INVALID TYPE : %d", type); + return NULL; + } + + if (group_id < NOTIFICATION_GROUP_ID_NONE) { + NOTIFICATION_ERR("INVALID GROUP ID : %d", group_id); + return NULL; + } + + if (priv_id < NOTIFICATION_PRIV_ID_NONE) { + NOTIFICATION_ERR("INVALID PRIV ID : %d", priv_id); + return NULL; + } + + noti = (notification_h) malloc(sizeof(struct _notification)); + if (noti == NULL) { + NOTIFICATION_ERR("NO MEMORY : noti == NULL"); + return NULL; + } + memset(noti, 0x00, sizeof(struct _notification)); + + noti->type = type; + + noti->group_id = group_id; + noti->internal_group_id = 0; + noti->priv_id = priv_id; + + noti->caller_pkgname = _notification_get_pkgname_by_pid(); + noti->launch_pkgname = NULL; + noti->args = NULL; + noti->group_args = NULL; + + noti->b_execute_option = NULL; + noti->b_service_responding = NULL; + noti->b_service_single_launch = NULL; + noti->b_service_multi_launch = NULL; + + noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE; + noti->sound_path = NULL; + + noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE; + noti->vibration_path = NULL; + + noti->domain = NULL; + noti->dir = NULL; + + noti->b_text = NULL; + noti->b_key = NULL; + noti->b_format_args = NULL; + noti->num_format_args = 0; + + noti->b_image_path = NULL; + + noti->time = 0; + noti->insert_time = 0; + + noti->flags_for_property = 0; + noti->display_applist = NOTIFICATION_DISPLAY_APP_ALL; + + noti->progress_size = 0.0; + noti->progress_percentage = 0.0; + + noti->app_icon_path = NULL; + noti->app_name = NULL; + noti->temp_title = NULL; + noti->temp_content = NULL; + + return noti; +} + +EXPORT_API notification_error_e notification_free(notification_h noti) +{ + if (noti == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + if (noti->caller_pkgname) { + free(noti->caller_pkgname); + } + if (noti->launch_pkgname) { + free(noti->launch_pkgname); + } + if (noti->args) { + bundle_free(noti->args); + } + if (noti->group_args) { + bundle_free(noti->group_args); + } + + if (noti->b_execute_option) { + bundle_free(noti->b_execute_option); + } + if (noti->b_service_responding) { + bundle_free(noti->b_service_responding); + } + if (noti->b_service_single_launch) { + bundle_free(noti->b_service_single_launch); + } + if (noti->b_service_multi_launch) { + bundle_free(noti->b_service_multi_launch); + } + + if (noti->sound_path) { + free(noti->sound_path); + } + if (noti->vibration_path) { + free(noti->vibration_path); + } + + if (noti->domain) { + free(noti->domain); + } + if (noti->dir) { + free(noti->dir); + } + + if (noti->b_text) { + bundle_free(noti->b_text); + } + if (noti->b_key) { + bundle_free(noti->b_key); + } + if (noti->b_format_args) { + bundle_free(noti->b_format_args); + } + + if (noti->b_image_path) { + bundle_free(noti->b_image_path); + } + + if (noti->app_icon_path) { + free(noti->app_icon_path); + } + if (noti->app_name) { + free(noti->app_name); + } + if (noti->temp_title) { + free(noti->temp_title); + } + if (noti->temp_content) { + free(noti->temp_content); + } + + free(noti); + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_resister_changed_cb(void (*changed_cb) + (void *data, notification_type_e type), + void *user_data) +{ + notification_cb_list_s *noti_cb_list_new = NULL; + notification_cb_list_s *noti_cb_list = NULL; + + noti_cb_list_new = + (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s)); + + noti_cb_list_new->next = NULL; + noti_cb_list_new->prev = NULL; + + noti_cb_list_new->changed_cb = changed_cb; + noti_cb_list_new->data = user_data; + + if (g_notification_cb_list == NULL) { + g_notification_cb_list = noti_cb_list_new; + } else { + noti_cb_list = g_notification_cb_list; + + while (noti_cb_list->next != NULL) { + noti_cb_list = noti_cb_list->next; + } + + noti_cb_list->next = noti_cb_list_new; + noti_cb_list_new->prev = noti_cb_list; + } + + if (g_notification_heynoti_fd < 0) { + g_notification_heynoti_fd = heynoti_init(); + + heynoti_subscribe(g_notification_heynoti_fd, NOTI_CHANGED_NOTI, + _notification_chagned_noti_cb, NULL); + + heynoti_attach_handler(g_notification_heynoti_fd); + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_unresister_changed_cb(void (*changed_cb) + (void *data, notification_type_e type)) +{ + notification_cb_list_s *noti_cb_list = NULL; + notification_cb_list_s *noti_cb_list_prev = NULL; + notification_cb_list_s *noti_cb_list_next = NULL; + + noti_cb_list = g_notification_cb_list; + + if (noti_cb_list == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + while (noti_cb_list->prev != NULL) { + noti_cb_list = noti_cb_list->prev; + } + + do { + if (noti_cb_list->changed_cb == changed_cb) { + noti_cb_list_prev = noti_cb_list->prev; + noti_cb_list_next = noti_cb_list->next; + + if (noti_cb_list_prev == NULL) { + g_notification_cb_list = noti_cb_list_next; + } else { + noti_cb_list_prev->next = noti_cb_list_next; + } + + if (noti_cb_list_next == NULL) { + if (noti_cb_list_prev != NULL) { + noti_cb_list_prev->next = NULL; + } + } else { + noti_cb_list_next->prev = noti_cb_list_prev; + } + + free(noti_cb_list); + + if (g_notification_cb_list == NULL) { + heynoti_detach_handler + (g_notification_heynoti_fd); + heynoti_close(g_notification_heynoti_fd); + g_notification_heynoti_fd = -1; + } + + return NOTIFICATION_ERROR_NONE; + } + noti_cb_list = noti_cb_list->next; + } while (noti_cb_list != NULL); + + return NOTIFICATION_ERROR_INVALID_DATA; +} + +EXPORT_API notification_error_e +notification_resister_badge_changed_cb(void (*changed_cb) + (void *data, const char *pkgname, + int group_id), void *user_data) +{ + // Add DBus signal handler + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_unresister_badge_changed_cb(void (*changed_cb) + (void *data, const char *pkgname, + int group_id)) +{ + // Del DBus signal handler + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_count(notification_type_e type, + const char *pkgname, + int group_id, + int priv_id, int *count) +{ + int ret = 0; + int noti_count = 0; + + ret = + notification_noti_get_count(type, pkgname, group_id, priv_id, + ¬i_count); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + if (count != NULL) { + *count = noti_count; + } + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_list(notification_type_e type, + int count, + notification_list_h *list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = notification_noti_get_grouping_list(type, count, &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e +notification_get_grouping_list(notification_type_e type, int count, + notification_list_h * list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = notification_noti_get_grouping_list(type, count, &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_get_detail_list(const char *pkgname, + int group_id, + int priv_id, + int count, + notification_list_h *list) +{ + notification_list_h get_list = NULL; + int ret = 0; + + ret = + notification_noti_get_detail_list(pkgname, group_id, priv_id, count, + &get_list); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + *list = get_list; + + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API notification_error_e notification_free_list(notification_list_h list) +{ + notification_list_h cur_list = NULL; + notification_h noti = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NOTIFICATION_ERROR_INVALID_DATA; + } + + cur_list = notification_list_get_head(list); + + while (cur_list != NULL) { + noti = notification_list_get_data(cur_list); + cur_list = notification_list_remove(cur_list, noti); + + notification_free(noti); + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_db.c b/src/notification_db.c new file mode 100755 index 0000000..2f7d41a --- /dev/null +++ b/src/notification_db.c @@ -0,0 +1,110 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> + +#include <sqlite3.h> +#include <db-util.h> + +#include <notification_error.h> +#include <notification_debug.h> +#include <notification_db.h> + +#define SDFTET "/opt/dbspace/.notification_noti.db" + +sqlite3 *notification_db_open(const char *dbfile) +{ + int ret = 0; + sqlite3 *db; + + ret = db_util_open(dbfile, &db, 0); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("DB open error(%d), %s", ret, dbfile); + return NULL; + } + + return db; +} + +int notification_db_close(sqlite3 ** db) +{ + int ret = 0; + + if (db == NULL || *db == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = db_util_close(*db); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("DB close error(%d)", ret); + return NOTIFICATION_ERROR_FROM_DB; + } + + *db = NULL; + + return NOTIFICATION_ERROR_NONE; +} + +int notification_db_exec(sqlite3 * db, const char *query) +{ + int ret = 0; + char *err_msg = NULL; + + if (db == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + ret = sqlite3_exec(db, query, NULL, NULL, &err_msg); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("SQL error(%d) : %s", ret, err_msg); + sqlite3_free(err_msg); + return NOTIFICATION_ERROR_FROM_DB; + } + + return NOTIFICATION_ERROR_NONE; +} + +char *notification_db_column_text(sqlite3_stmt * stmt, int col) +{ + const unsigned char *col_text = NULL; + + col_text = sqlite3_column_text(stmt, col); + if (col_text == NULL || col_text[0] == '\0') { + return NULL; + } + + return strdup((char *)col_text); +} + +bundle *notification_db_column_bundle(sqlite3_stmt * stmt, int col) +{ + const unsigned char *col_bundle = NULL; + + col_bundle = sqlite3_column_text(stmt, col); + if (col_bundle == NULL || col_bundle[0] == '\0') { + return NULL; + } + + return bundle_decode(col_bundle, strlen((char *)col_bundle)); +} diff --git a/src/notification_group.c b/src/notification_group.c new file mode 100755 index 0000000..c310f8e --- /dev/null +++ b/src/notification_group.c @@ -0,0 +1,473 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <notification_debug.h> +#include <notification_group.h> +#include <notification_db.h> + +static int _notification_group_bind_query(sqlite3_stmt * stmt, const char *name, + const char *str) +{ + int ret = 0; + int index = 0; + + index = sqlite3_bind_parameter_index(stmt, name); + if (index == 0) { + NOTIFICATION_ERR("Insert : invalid column name"); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = + sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1, + SQLITE_STATIC); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert text : %s", + NOTIFICATION_CHECK_STR(str)); + return NOTIFICATION_ERROR_FROM_DB; + } + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_group_check_data_inserted(const char *pkgname, + int group_id, sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + snprintf(query, sizeof(query), + "select count(*) from noti_group_data where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, + sqlite3_errmsg(db)); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + result = 0; + } + + NOTIFICATION_INFO("Check Data Inserted : query[%s], result : [%d]", + query, result); + + sqlite3_finalize(stmt); + + if (result > 0) { + return NOTIFICATION_ERROR_ALREADY_EXIST_ID; + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_group_set_title(const char *pkgname, + int group_id, + const char *title, + const char *loc_title, + notification_count_display_type_e count_display) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int result = NOTIFICATION_ERROR_NONE; + + // db open + db = notification_db_open(DBPATH); + + // Check pkgname & group_id + ret = _notification_group_check_data_inserted(pkgname, group_id, db); + if (ret == NOTIFICATION_ERROR_NONE) { + // not exist -> insert + snprintf(query, sizeof(query), "insert into noti_group_data (" + "caller_pkgname, group_id, unread_count, title, loc_title, count_display_title) values (" + "'%s', %d, 0, $title, $loc_title, %d)", + pkgname, group_id, count_display); + + } else { + // exist -> update + // not exist -> insert + snprintf(query, sizeof(query), "update noti_group_data " + "set title = $title, loc_title = $loc_title, count_display_title = %d " + "where caller_pkgname = '%s' and group_id = %d", + count_display, pkgname, group_id); + } + + // insert + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = _notification_group_bind_query(stmt, "$title", title); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + + ret = _notification_group_bind_query(stmt, "$loc_title", loc_title); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + result = NOTIFICATION_ERROR_NONE; + } else { + result = NOTIFICATION_ERROR_FROM_DB; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + + return result; +} + +notification_error_e notification_group_get_title(const char *pkgname, + int group_id, + char **ret_title, + char **ret_loc_title, + notification_count_display_type_e *count_display) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int col = 0; + + // db open + db = notification_db_open(DBPATH); + + snprintf(query, sizeof(query), "select " + "title, loc_title, count_display_title " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + *ret_title = notification_db_column_text(stmt, col++); + *ret_loc_title = notification_db_column_text(stmt, col++); + *count_display = sqlite3_column_int(stmt, col++); + } + + sqlite3_finalize(stmt); + + // db close + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_group_set_content(const char *pkgname, + int group_id, + const char *content, + const char *loc_content, + notification_count_display_type_e count_display) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int result = NOTIFICATION_ERROR_NONE; + + // db open + db = notification_db_open(DBPATH); + + // Check pkgname & group_id + ret = _notification_group_check_data_inserted(pkgname, group_id, db); + if (ret == NOTIFICATION_ERROR_NONE) { + // not exist -> insert + snprintf(query, sizeof(query), "insert into noti_group_data (" + "caller_pkgname, group_id, unread_count, content, loc_content, count_display_content) values (" + "'%s', %d, 0, $content, $loc_content, %d)", + pkgname, group_id, count_display); +// NOTIFICATION_INFO("Insert Query : %s", query); + } else { + // exist -> update + // not exist -> insert + snprintf(query, sizeof(query), "update noti_group_data " + "set content = $content, loc_content = $loc_content, count_display_content = %d " + "where caller_pkgname = '%s' and group_id = %d", + count_display, pkgname, group_id); +// NOTIFICATION_INFO("Insert Query : %s", query); + } + + // insert + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = _notification_group_bind_query(stmt, "$content", content); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + + ret = _notification_group_bind_query(stmt, "$loc_content", loc_content); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + result = NOTIFICATION_ERROR_NONE; + } else { + result = NOTIFICATION_ERROR_FROM_DB; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + + return result; +} + +notification_error_e notification_group_get_content(const char *pkgname, + int group_id, + char **ret_content, + char **ret_loc_content, + notification_count_display_type_e *count_display) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int col = 0; + + // db open + db = notification_db_open(DBPATH); + + snprintf(query, sizeof(query), "select " + "content, loc_content, count_display_content " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + *ret_content = notification_db_column_text(stmt, col++); + *ret_loc_content = notification_db_column_text(stmt, col++); + *count_display = sqlite3_column_int(stmt, col++); + } + + sqlite3_finalize(stmt); + + // db close + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_group_set_badge(const char *pkgname, + int group_id, int count) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int result = NOTIFICATION_ERROR_NONE; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check pkgname & group_id */ + ret = _notification_group_check_data_inserted(pkgname, group_id, db); + + /* Make query */ + if (ret == NOTIFICATION_ERROR_NONE) { + /* Insert if does not exist */ + snprintf(query, sizeof(query), "insert into noti_group_data (" + "caller_pkgname, group_id, badge, content, loc_content) values (" + "'%s', %d, %d, '', '')", pkgname, group_id, count); + + } else { + /* Update if exist */ + snprintf(query, sizeof(query), "update noti_group_data " + "set badge = %d " + "where caller_pkgname = '%s' and group_id = %d", + count, pkgname, group_id); + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + result = NOTIFICATION_ERROR_NONE; + } else { + result = NOTIFICATION_ERROR_FROM_DB; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return result; +} + +notification_error_e notification_group_get_badge(const char *pkgname, + int group_id, int *count) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + int col = 0; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + if (group_id == NOTIFICATION_GROUP_ID_NONE) { + /* Check Group id None is exist */ + ret = + _notification_group_check_data_inserted(pkgname, group_id, + db); + + if (ret == NOTIFICATION_ERROR_NONE) { + /* Get all of pkgname count if none group id is not exist */ + snprintf(query, sizeof(query), + "select sum(badge) " + "from noti_group_data " + "where caller_pkgname = '%s'", pkgname); + } else { + /* Get none group id count */ + snprintf(query, sizeof(query), + "select badge " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + } + } else { + snprintf(query, sizeof(query), + "select badge " + "from noti_group_data " + "where caller_pkgname = '%s' and group_id = %d", + pkgname, group_id); + } + + NOTIFICATION_INFO("Get badge : query[%s]", query); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + *count = sqlite3_column_int(stmt, col++); + } + + sqlite3_finalize(stmt); + + // db close + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_list.c b/src/notification_list.c new file mode 100755 index 0000000..b066c74 --- /dev/null +++ b/src/notification_list.c @@ -0,0 +1,211 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <stdlib.h> + +#include <notification.h> +#include <notification_list.h> +#include <notification_debug.h> +#include <notification_internal.h> + +struct _notification_list { + notification_list_h prev; + notification_list_h next; + + notification_h noti; +}; + +notification_list_h _notification_list_create(void) +{ + notification_list_h list = NULL; + + list = (notification_list_h) malloc(sizeof(struct _notification_list)); + if (list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + list->prev = NULL; + list->next = NULL; + + list->noti = NULL; + + return list; +} + +EXPORT_API notification_list_h notification_list_get_head(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + while (cur_list->prev != NULL) { + cur_list = cur_list->prev; + } + + return cur_list; +} + +EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + while (cur_list->next != NULL) { + cur_list = cur_list->next; + } + + return cur_list; +} + +EXPORT_API notification_list_h notification_list_get_prev(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->prev; +} + +EXPORT_API notification_list_h notification_list_get_next(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->next; +} + +EXPORT_API notification_h notification_list_get_data(notification_list_h list) +{ + notification_list_h cur_list = NULL; + + if (list == NULL) { + NOTIFICATION_ERR("INVALID DATA : list == NULL"); + return NULL; + } + + cur_list = list; + + return cur_list->noti; +} + +EXPORT_API notification_list_h notification_list_append(notification_list_h list, + notification_h noti) +{ + notification_list_h new_list = NULL; + notification_list_h cur_list = NULL; + + if (noti == NULL) { + NOTIFICATION_ERR("INVALID DATA : data == NULL"); + return NULL; + } + + if (list != NULL) { + cur_list = notification_list_get_tail(list); + + new_list = _notification_list_create(); + if (new_list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + cur_list->next = new_list; + new_list->prev = cur_list; + + new_list->noti = noti; + } else { + cur_list = _notification_list_create(); + if (cur_list == NULL) { + NOTIFICATION_ERR("NO MEMORY"); + return NULL; + } + + new_list = cur_list; + new_list->noti = noti; + } + + return new_list; +} + +EXPORT_API notification_list_h notification_list_remove(notification_list_h list, + notification_h noti) +{ + notification_list_h cur_list = NULL; + notification_list_h prev_list = NULL; + notification_list_h next_list = NULL; + + cur_list = notification_list_get_head(list); + while (cur_list != NULL) { + if (cur_list->noti == noti) { + //remove + prev_list = cur_list->prev; + next_list = cur_list->next; + + if (next_list != NULL) { + if (prev_list != NULL) { + prev_list->next = next_list; + next_list->prev = prev_list; + } else { + next_list->prev = NULL; + } + } else { + if (prev_list != NULL) { + prev_list->next = NULL; + } + } + + free(cur_list); + break; + } + + cur_list = cur_list->next; + } + + if (prev_list != NULL) { + return notification_list_get_head(prev_list); + } else if (next_list != NULL) { + return next_list; + } + + return NULL; +} diff --git a/src/notification_noti.c b/src/notification_noti.c new file mode 100755 index 0000000..07fae45 --- /dev/null +++ b/src/notification_noti.c @@ -0,0 +1,1035 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <string.h> +#include <stdlib.h> + +#include <vconf.h> + +#include <notification.h> +#include <notification_db.h> +#include <notification_noti.h> +#include <notification_debug.h> +#include <notification_internal.h> + +static int _notification_noti_bind_query(sqlite3_stmt * stmt, const char *name, + const char *str) +{ + int ret = 0; + int index = 0; + + index = sqlite3_bind_parameter_index(stmt, name); + if (index == 0) { + NOTIFICATION_ERR("Insert : invalid column name"); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = + sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1, + SQLITE_STATIC); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert text : %s", + NOTIFICATION_CHECK_STR(str)); + return NOTIFICATION_ERROR_FROM_DB; + } + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + /* Make query to check priv_id exist */ + snprintf(query, sizeof(query), + "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d", + noti->caller_pkgname, noti->priv_id); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, + sqlite3_errmsg(db)); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + result = 0; + } + + sqlite3_finalize(stmt); + + /* If result > 0, there is priv_id in DB */ + if (result > 0) { + return NOTIFICATION_ERROR_ALREADY_EXIST_ID; + } + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_noti_get_priv_id(notification_h noti, sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + /* Make query to get max priv_id */ + snprintf(query, sizeof(query), + "select max(priv_id) from noti_list where caller_pkgname = '%s'", + noti->caller_pkgname); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, + sqlite3_errmsg(db)); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + result = 0; + } + + sqlite3_finalize(stmt); + + if (result < 0) { + return NOTIFICATION_ERROR_FROM_DB; + } + + /* Increase result(max priv_id value) for next priv_id */ + noti->priv_id = result + 1; + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname, + int priv_id, + sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + snprintf(query, sizeof(query), + "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d", + pkgname, priv_id); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, + sqlite3_errmsg(db)); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + result = 0; + } + + sqlite3_finalize(stmt); + + return result; +} + +static int _notification_noti_get_max_internal_group_id(notification_h noti, + sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + + /* Get max internal group id */ + snprintf(query, sizeof(query), + "select max(internal_group_id) from noti_list"); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Get count DB err(%d) : %s", ret, + sqlite3_errmsg(db)); + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + result = 0; + } + + sqlite3_finalize(stmt); + + return result; +} + +static int _notification_noti_get_internal_group_id(notification_h noti, + sqlite3 * db) +{ + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = NOTIFICATION_ERROR_NONE, result = 0; + const char *ret_title = NULL; + char buf_key[32] = { 0, }; + + if (noti->group_id == NOTIFICATION_GROUP_ID_NONE) { + /* If Group ID is NONE Get max internal group ID */ + result = _notification_noti_get_max_internal_group_id(noti, db); + if (result < 0) { + return NOTIFICATION_ERROR_FROM_DB; + } + + /* Internal Group ID is max internal group ID + 1 */ + noti->internal_group_id = result + 1; + + return NOTIFICATION_ERROR_NONE; + } else if (noti->group_id == NOTIFICATION_GROUP_ID_DEFAULT) { + /* If Group ID is DEFAULT, Get internal group id if it exist */ + if (noti->b_key != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + ret_title = bundle_get_val(noti->b_key, buf_key); + } + + if (ret_title == NULL && noti->b_text != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + ret_title = bundle_get_val(noti->b_text, buf_key); + } + + if (ret_title == NULL) { + ret_title = noti->caller_pkgname; + } + + snprintf(query, sizeof(query), + "select internal_group_id from noti_list where title_key = $title_key and group_id = %d", + NOTIFICATION_GROUP_ID_DEFAULT); + } else { + /* If Group ID is > DEFAULT, Get internal group id if it exit */ + snprintf(query, sizeof(query), + "select internal_group_id from noti_list where caller_pkgname = '%s' and group_id = %d", + NOTIFICATION_CHECK_STR(noti->caller_pkgname), + noti->group_id); + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + /* Bind query */ + if (ret_title != NULL) { + ret = + _notification_noti_bind_query(stmt, "$title_key", + NOTIFICATION_CHECK_STR + (ret_title)); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + result = sqlite3_column_int(stmt, 0); + } else { + /* If there is not internal_group_id, create new one */ + result = _notification_noti_get_max_internal_group_id(noti, db); + result++; + } + + sqlite3_finalize(stmt); + + noti->internal_group_id = result; + + return NOTIFICATION_ERROR_NONE; +} + +static int _notification_noti_make_query(notification_h noti, char *query, + int query_size) +{ + char *args = NULL; + char *group_args = NULL; + char *b_image_path = NULL; + char *b_execute_option = NULL; + char *b_service_responding = NULL; + char *b_service_single_launch = NULL; + char *b_service_multi_launch = NULL; + char *b_text = NULL; + char *b_key = NULL; + char *b_format_args = NULL; + int flag_simmode = 0; + + /* Decode bundle to insert DB */ + if (noti->args) { + bundle_encode(noti->args, (bundle_raw **) & args, NULL); + } + if (noti->group_args) { + bundle_encode(noti->group_args, (bundle_raw **) & group_args, + NULL); + } + + if (noti->b_execute_option) { + bundle_encode(noti->b_execute_option, + (bundle_raw **) & b_execute_option, NULL); + } + if (noti->b_service_responding) { + bundle_encode(noti->b_service_responding, + (bundle_raw **) & b_service_responding, NULL); + } + if (noti->b_service_single_launch) { + bundle_encode(noti->b_service_single_launch, + (bundle_raw **) & b_service_single_launch, NULL); + } + if (noti->b_service_multi_launch) { + bundle_encode(noti->b_service_multi_launch, + (bundle_raw **) & b_service_multi_launch, NULL); + } + + if (noti->b_text) { + bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL); + } + if (noti->b_key) { + bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL); + } + if (noti->b_format_args) { + bundle_encode(noti->b_format_args, + (bundle_raw **) & b_format_args, NULL); + } + + if (noti->b_image_path) { + bundle_encode(noti->b_image_path, + (bundle_raw **) & b_image_path, NULL); + } + + /* Check only simmode property is enable */ + if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) { + flag_simmode = 1; + } + + /* Make query */ + snprintf(query, query_size, "insert into noti_list (" + "type, " + "caller_pkgname, launch_pkgname, " + "image_path, " + "group_id, internal_group_id, priv_id, " + "title_key, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, " + "time, insert_time, " + "args, group_args, " + "b_execute_option, " + "b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, flag_simmode, display_applist, " + "progress_size, progress_percentage) values (" + "%d, " + "'%s', '%s', " + "'%s', " + "%d, %d, %d, " + "$title_key, " + "'%s', '%s', '%s', %d, " + "'%s', '%s', " + "%d, %d, " + "'%s', '%s', " + "'%s', " + "'%s', '%s', '%s', " + "%d, '%s', %d, '%s', " + "%d, %d, %d, " + "%f, %f)", + noti->type, + NOTIFICATION_CHECK_STR(noti->caller_pkgname), + NOTIFICATION_CHECK_STR(noti->launch_pkgname), + NOTIFICATION_CHECK_STR(b_image_path), noti->group_id, + noti->internal_group_id, noti->priv_id, + NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key), + NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args, + NOTIFICATION_CHECK_STR(noti->domain), + NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time, + (int)noti->insert_time, NOTIFICATION_CHECK_STR(args), + NOTIFICATION_CHECK_STR(group_args), + NOTIFICATION_CHECK_STR(b_execute_option), + NOTIFICATION_CHECK_STR(b_service_responding), + NOTIFICATION_CHECK_STR(b_service_single_launch), + NOTIFICATION_CHECK_STR(b_service_multi_launch), + noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path), + noti->vibration_type, + NOTIFICATION_CHECK_STR(noti->vibration_path), + noti->flags_for_property, flag_simmode, noti->display_applist, + noti->progress_size, noti->progress_percentage); + + /* Free decoded data */ + if (args) { + free(args); + } + if (group_args) { + free(group_args); + } + + if (b_execute_option) { + free(b_execute_option); + } + if (b_service_responding) { + free(b_service_responding); + } + if (b_service_single_launch) { + free(b_service_single_launch); + } + if (b_service_multi_launch) { + free(b_service_multi_launch); + } + + if (b_text) { + free(b_text); + } + if (b_key) { + free(b_key); + } + if (b_format_args) { + free(b_format_args); + } + + if (b_image_path) { + free(b_image_path); + } + + return NOTIFICATION_ERROR_NONE; +} + +static notification_h _notification_noti_get_item(sqlite3_stmt * stmt) +{ + notification_h noti = NULL; + int col = 0; + + noti = malloc(sizeof(struct _notification)); + if (noti == NULL) { + return NULL; + } + + noti->type = sqlite3_column_int(stmt, col++); + noti->caller_pkgname = notification_db_column_text(stmt, col++); + noti->launch_pkgname = notification_db_column_text(stmt, col++); + noti->b_image_path = notification_db_column_bundle(stmt, col++); + noti->group_id = sqlite3_column_int(stmt, col++); + noti->internal_group_id = 0; + noti->priv_id = sqlite3_column_int(stmt, col++); + + noti->b_text = notification_db_column_bundle(stmt, col++); + noti->b_key = notification_db_column_bundle(stmt, col++); + noti->b_format_args = notification_db_column_bundle(stmt, col++); + noti->num_format_args = sqlite3_column_int(stmt, col++); + + noti->domain = notification_db_column_text(stmt, col++); + noti->dir = notification_db_column_text(stmt, col++); + noti->time = sqlite3_column_int(stmt, col++); + noti->insert_time = sqlite3_column_int(stmt, col++); + noti->args = notification_db_column_bundle(stmt, col++); + noti->group_args = notification_db_column_bundle(stmt, col++); + + noti->b_execute_option = notification_db_column_bundle(stmt, col++); + noti->b_service_responding = notification_db_column_bundle(stmt, col++); + noti->b_service_single_launch = + notification_db_column_bundle(stmt, col++); + noti->b_service_multi_launch = + notification_db_column_bundle(stmt, col++); + + noti->sound_type = sqlite3_column_int(stmt, col++); + noti->sound_path = notification_db_column_text(stmt, col++); + noti->vibration_type = sqlite3_column_int(stmt, col++); + noti->vibration_path = notification_db_column_text(stmt, col++); + + noti->flags_for_property = sqlite3_column_int(stmt, col++); + noti->display_applist = sqlite3_column_int(stmt, col++); + noti->progress_size = sqlite3_column_double(stmt, col++); + noti->progress_percentage = sqlite3_column_double(stmt, col++); + + noti->app_icon_path = NULL; + noti->app_name = NULL; + noti->temp_title = NULL; + noti->temp_content = NULL; + return noti; +} + +int notification_noti_insert(notification_h noti) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0, result = 0; + char buf_key[32] = { 0, }; + const char *title_key = NULL; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Get private ID */ + if (noti->priv_id == NOTIFICATION_PRIV_ID_NONE) { + ret = _notification_noti_get_priv_id(noti, db); + } else { + ret = _notification_noti_check_priv_id(noti, db); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + } + + /* Get internal group ID */ + ret = _notification_noti_get_internal_group_id(noti, db); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + /* make query */ + ret = _notification_noti_make_query(noti, query, sizeof(query)); + if (ret != NOTIFICATION_ERROR_NONE) { + return ret; + } + + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Insert Query : %s", query); + NOTIFICATION_ERR("Insert DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + if (stmt) { + sqlite3_finalize(stmt); + } + + if (db) { + notification_db_close(&db); + } + return NOTIFICATION_ERROR_FROM_DB; + } + + /* Get title key */ + if (noti->b_key != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + title_key = bundle_get_val(noti->b_key, buf_key); + } + + if (title_key == NULL && noti->b_text != NULL) { + snprintf(buf_key, sizeof(buf_key), "%d", + NOTIFICATION_TEXT_TYPE_TITLE); + + title_key = bundle_get_val(noti->b_text, buf_key); + } + + if (title_key == NULL) { + title_key = noti->caller_pkgname; + } + + /* Bind query */ + ret = _notification_noti_bind_query(stmt, "$title_key", title_key); + if (ret != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db)); + return ret; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_OK || ret == SQLITE_DONE) { + result = NOTIFICATION_ERROR_NONE; + } else { + result = NOTIFICATION_ERROR_FROM_DB; + } + + if (stmt) { + sqlite3_finalize(stmt); + } + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return result; +} + +int notification_noti_delete_all(notification_type_e type, const char *pkgname) +{ + sqlite3 *db; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + snprintf(query_base, sizeof(query_base), "delete from noti_list "); + + if (pkgname == NULL) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d ", type); + } + } else { + if (type == NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' ", pkgname); + } else { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and type = %d ", + pkgname, type); + } + } + + snprintf(query, sizeof(query), "%s %s", query_base, query_where); + + //NOTIFICATION_INFO("Delete All : [%s]", query); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +int notification_noti_delete_group_by_group_id(const char *pkgname, + int group_id) +{ + sqlite3 *db; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and group_id = %d", pkgname, + group_id); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id) +{ + sqlite3 *db; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int internal_group_id = 0; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Get internal group id using priv id */ + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id(pkgname, + priv_id, db); + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and internal_group_id = %d", + pkgname, internal_group_id); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id) +{ + sqlite3 *db; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + + /* Check pkgname is valid */ + if (pkgname == NULL) { + return NOTIFICATION_ERROR_INVALID_DATA; + } + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Make query */ + snprintf(query, sizeof(query), "delete from noti_list " + "where caller_pkgname = '%s' and priv_id = %d", pkgname, + priv_id); + + /* execute DB */ + notification_db_exec(db, query); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_noti_get_count(notification_type_e type, + const char *pkgname, + int group_id, int priv_id, + int *count) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, }; + + int ret = 0, get_count = 0, internal_group_id = 0; + int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN; + int flag_where = 0; + int flag_where_more = 0; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), + "select count(*) from noti_list "); + + if (pkgname != NULL) { + if (group_id == NOTIFICATION_GROUP_ID_NONE) { + if (priv_id == NOTIFICATION_PRIV_ID_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' ", + pkgname); + flag_where = 1; + } else { + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id + (pkgname, priv_id, db); + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + flag_where = 1; + } + } else { + if (priv_id == NOTIFICATION_PRIV_ID_NONE) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and group_id = %d ", + pkgname, group_id); + flag_where = 1; + } else { + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id + (pkgname, priv_id, db); + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + flag_where = 1; + } + } + + } + + if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where_more, sizeof(query_where_more), + "type = %d ", type); + flag_where_more = 1; + } + } else { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where_more, sizeof(query_where_more), + "type = %d and flag_simmode = 0 ", type); + flag_where_more = 1; + } else { + snprintf(query_where_more, sizeof(query_where_more), + "flag_simmode = 0 "); + flag_where_more = 1; + } + } + + if (flag_where == 1) { + if (flag_where_more == 1) { + snprintf(query, sizeof(query), "%s %s and %s", + query_base, query_where, query_where_more); + } else { + snprintf(query, sizeof(query), "%s %s", query_base, + query_where); + } + + } else { + if (flag_where_more == 1) { + snprintf(query, sizeof(query), "%s where %s", + query_base, query_where_more); + } else { + snprintf(query, sizeof(query), "%s", query_base); + } + } + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) { + get_count = sqlite3_column_int(stmt, 0); + } + + sqlite3_finalize(stmt); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + *count = get_count; + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_noti_get_grouping_list(notification_type_e type, + int count, + notification_list_h * + list) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + int ret = 0; + notification_list_h get_list = NULL; + notification_h noti = NULL; + int internal_count = 0; + int status; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), "select " + "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, time, insert_time, args, group_args, " + "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, display_applist, progress_size, progress_percentage " + "from noti_list "); + + if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d ", type); + } + } else { + if (type != NOTIFICATION_TYPE_NONE) { + snprintf(query_where, sizeof(query_where), + "where type = %d and flag_simmode = 0 ", type); + } else { + snprintf(query_where, sizeof(query_where), + "where flag_simmode = 0 "); + } + } + + snprintf(query, sizeof(query), + "%s %s " + "group by internal_group_id " + "order by rowid desc, time desc", query_base, query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + while (ret == SQLITE_ROW) { + /* Make notification list */ + noti = _notification_noti_get_item(stmt); + if (noti != NULL) { + internal_count++; + + get_list = notification_list_append(get_list, noti); + + if (count != -1 && internal_count >= count) { + NOTIFICATION_INFO + ("internal count %d >= count %d", + internal_count, count); + break; + } + } + + ret = sqlite3_step(stmt); + } + + sqlite3_finalize(stmt); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + if (get_list != NULL) { + *list = notification_list_get_head(get_list); + } + + return NOTIFICATION_ERROR_NONE; +} + +notification_error_e notification_noti_get_detail_list(const char *pkgname, + int group_id, + int priv_id, int count, + notification_list_h *list) +{ + sqlite3 *db; + sqlite3_stmt *stmt = NULL; + char query_base[NOTIFICATION_QUERY_MAX] = { 0, }; + char query_where[NOTIFICATION_QUERY_MAX] = { 0, }; + + char query[NOTIFICATION_QUERY_MAX] = { 0, }; + int ret = 0; + notification_list_h get_list = NULL; + notification_h noti = NULL; + int internal_count = 0; + int internal_group_id = 0; + int status; + + /* Open DB */ + db = notification_db_open(DBPATH); + + /* Check current sim status */ + ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status); + + /* Make query */ + snprintf(query_base, sizeof(query_base), "select " + "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, " + "b_text, b_key, b_format_args, num_format_args, " + "text_domain, text_dir, time, insert_time, args, group_args, " + "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, " + "sound_type, sound_path, vibration_type, vibration_path, " + "flags_for_property, display_applist, progress_size, progress_percentage " + "from noti_list "); + + internal_group_id = + _notification_noti_get_internal_group_id_by_priv_id(pkgname, + priv_id, db); + + if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d ", + pkgname, internal_group_id); + } else { + snprintf(query_where, sizeof(query_where), + "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ", + pkgname, internal_group_id); + } + + snprintf(query, sizeof(query), + "%s %s " + "order by rowid desc, time desc", query_base, query_where); + + ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + NOTIFICATION_ERR("Select Query : %s", query); + NOTIFICATION_ERR("Select DB error(%d) : %s", ret, + sqlite3_errmsg(db)); + + return NOTIFICATION_ERROR_FROM_DB; + } + + ret = sqlite3_step(stmt); + while (ret == SQLITE_ROW) { + /* Make notification list */ + noti = _notification_noti_get_item(stmt); + if (noti != NULL) { + internal_count++; + + get_list = notification_list_append(get_list, noti); + + if (count != -1 && internal_count >= count) { + NOTIFICATION_INFO + ("internal count %d >= count %d", + internal_count, count); + break; + } + } + + ret = sqlite3_step(stmt); + } + + sqlite3_finalize(stmt); + + /* Close DB */ + if (db) { + notification_db_close(&db); + } + + if (get_list != NULL) { + *list = notification_list_get_head(get_list); + } + + return NOTIFICATION_ERROR_NONE; +} diff --git a/src/notification_ongoing.c b/src/notification_ongoing.c new file mode 100755 index 0000000..cd911d8 --- /dev/null +++ b/src/notification_ongoing.c @@ -0,0 +1,129 @@ +/* + * libnotification + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> + * + * 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 <string.h> +#include <stdlib.h> + +#include <dbus/dbus.h> + +#include <notification_db.h> +#include <notification_debug.h> +#include <notification_ongoing.h> +#include <notification_internal.h> + +notification_error_e notification_ongoing_update_progress(const char *caller_pkgname, + int priv_id, + double progress) +{ + DBusConnection *connection = NULL; + DBusMessage *signal = NULL; + DBusError err; + dbus_bool_t ret; + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + signal = + dbus_message_new_signal("/dbus/signal", "notification.ongoing", + "update_progress"); + if (!signal) { + NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &caller_pkgname, + DBUS_TYPE_INT32, &priv_id, + DBUS_TYPE_DOUBLE, &progress, + DBUS_TYPE_INVALID); + + if (ret) { + ret = dbus_connection_send(connection, signal, NULL); + if (ret) { + dbus_connection_flush(connection); + } + } + + dbus_message_unref(signal); + + if (ret) { + NOTIFICATION_INFO("Send progress info : %s(%d) %.2f", + caller_pkgname, priv_id, progress); + return NOTIFICATION_ERROR_NONE; + } + + return NOTIFICATION_ERROR_FROM_DBUS; +} + +notification_error_e notification_ongoing_update_size(const char *caller_pkgname, + int priv_id, double size) +{ + DBusConnection *connection = NULL; + DBusMessage *signal = NULL; + DBusError err; + dbus_bool_t ret; + + dbus_error_init(&err); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err); + if (!connection) { + NOTIFICATION_ERR("Fail to dbus_bus_get"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + signal = + dbus_message_new_signal("/dbus/signal", "notification.ongoing", + "update_size"); + if (!signal) { + NOTIFICATION_ERR("Fail to dbus_message_new_signal"); + return NOTIFICATION_ERROR_FROM_DBUS; + } + + ret = dbus_message_append_args(signal, + DBUS_TYPE_STRING, &caller_pkgname, + DBUS_TYPE_INT32, &priv_id, + DBUS_TYPE_DOUBLE, &size, + DBUS_TYPE_INVALID); + NOTIFICATION_INFO("arg..."); + if (ret) { + ret = dbus_connection_send(connection, signal, NULL); + NOTIFICATION_INFO("Send size info : %s(%d) %.2f", + caller_pkgname, priv_id, size); + + if (ret) { + dbus_connection_flush(connection); + } + } + + dbus_message_unref(signal); + + if (ret) { + NOTIFICATION_INFO("Send size info : %s(%d) %.2f", + caller_pkgname, priv_id, size); + return NOTIFICATION_ERROR_NONE; + } + + return NOTIFICATION_ERROR_FROM_DBUS; +} |