4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <Elementary.h>
32 #include <notification.h>
33 #include <notification_db.h>
34 #include <notification_noti.h>
35 #include <notification_debug.h>
36 #include <notification_private.h>
38 #define NOTI_BURST_DELETE_UNIT 10
39 static int toast_height;
40 static Eina_List *toast_list;
41 static Eina_List *toast_popup;
43 static void __free_and_set(void **target_ptr, void *new_ptr) {
44 if (target_ptr != NULL) {
45 if (*target_ptr != NULL) {
48 *target_ptr = new_ptr;
52 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
58 index = sqlite3_bind_parameter_index(stmt, name);
60 NOTIFICATION_ERR("Insert : invalid column name");
61 return NOTIFICATION_ERROR_FROM_DB;
65 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
67 if (ret != SQLITE_OK) {
68 NOTIFICATION_ERR("Insert text : %s",
69 NOTIFICATION_CHECK_STR(str));
70 return NOTIFICATION_ERROR_FROM_DB;
73 return NOTIFICATION_ERROR_NONE;
76 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
82 index = sqlite3_bind_parameter_index(stmt, name);
84 NOTIFICATION_ERR("Insert : invalid column name");
85 return NOTIFICATION_ERROR_FROM_DB;
88 ret = sqlite3_bind_double(stmt, index, val);
89 if (ret != SQLITE_OK) {
90 NOTIFICATION_ERR("Insert double : %f", val);
91 return NOTIFICATION_ERROR_FROM_DB;
94 return NOTIFICATION_ERROR_NONE;
97 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
100 int ret = NOTIFICATION_ERROR_NONE;
102 sqlite3_stmt *stmt = NULL;
104 /* Make query to check priv_id exist */
105 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
106 noti->caller_pkgname, noti->priv_id);
108 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
112 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
113 if (ret != SQLITE_OK) {
114 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
116 ret = NOTIFICATION_ERROR_FROM_DB;
120 ret = sqlite3_step(stmt);
121 if (ret == SQLITE_ROW) {
122 result = sqlite3_column_int(stmt, 0);
127 sqlite3_finalize(stmt);
129 /* If result > 0, there is priv_id in DB */
131 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
142 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
147 sqlite3_stmt *stmt = NULL;
148 int ret = NOTIFICATION_ERROR_NONE, result = 0;
150 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
153 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
157 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
158 if (ret != SQLITE_OK) {
159 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
161 ret = NOTIFICATION_ERROR_FROM_DB;
165 ret = sqlite3_step(stmt);
166 if (ret == SQLITE_ROW) {
167 result = sqlite3_column_int(stmt, 0);
174 sqlite3_finalize(stmt);
181 if (ret != NOTIFICATION_ERROR_NONE) {
182 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
188 static int _insertion_query_create(notification_h noti, char **query)
190 int b_encode_len = 0;
192 char *group_args = NULL;
193 char *b_image_path = NULL;
194 char *b_execute_option = NULL;
195 char *b_service_responding = NULL;
196 char *b_service_single_launch = NULL;
197 char *b_service_multi_launch = NULL;
200 char *b_format_args = NULL;
201 int flag_simmode = 0;
204 return NOTIFICATION_ERROR_INVALID_PARAMETER;
207 /* Decode bundle to insert DB */
209 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
211 if (noti->group_args) {
212 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
216 if (noti->b_execute_option) {
217 bundle_encode(noti->b_execute_option,
218 (bundle_raw **) & b_execute_option, &b_encode_len);
220 if (noti->b_service_responding) {
221 bundle_encode(noti->b_service_responding,
222 (bundle_raw **) & b_service_responding, &b_encode_len);
224 if (noti->b_service_single_launch) {
225 bundle_encode(noti->b_service_single_launch,
226 (bundle_raw **) & b_service_single_launch, &b_encode_len);
228 if (noti->b_service_multi_launch) {
229 bundle_encode(noti->b_service_multi_launch,
230 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
234 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
237 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
239 if (noti->b_format_args) {
240 bundle_encode(noti->b_format_args,
241 (bundle_raw **) & b_format_args, &b_encode_len);
244 if (noti->b_image_path) {
245 bundle_encode(noti->b_image_path,
246 (bundle_raw **) & b_image_path, &b_encode_len);
249 /* Check only simmode property is enable */
250 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
255 *query = sqlite3_mprintf("INSERT INTO noti_list ("
258 "caller_pkgname, launch_pkgname, "
260 "group_id, internal_group_id, priv_id, "
262 "b_text, b_key, tag, b_format_args, num_format_args, "
263 "text_domain, text_dir, "
264 "time, insert_time, "
267 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
268 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
269 "flags_for_property, flag_simmode, display_applist, "
270 "progress_size, progress_percentage) values ("
277 "'%s', '%s', $tag, '%s', %d, "
283 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
285 "$progress_size, $progress_percentage)",
288 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
289 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
290 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
291 noti->internal_group_id, noti->priv_id,
292 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
293 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
294 NOTIFICATION_CHECK_STR(noti->domain),
295 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
296 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
297 NOTIFICATION_CHECK_STR(group_args),
298 NOTIFICATION_CHECK_STR(b_execute_option),
299 NOTIFICATION_CHECK_STR(b_service_responding),
300 NOTIFICATION_CHECK_STR(b_service_single_launch),
301 NOTIFICATION_CHECK_STR(b_service_multi_launch),
302 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
303 noti->vibration_type,
304 NOTIFICATION_CHECK_STR(noti->vibration_path),
309 noti->flags_for_property, flag_simmode, noti->display_applist);
311 /* Free decoded data */
319 if (b_execute_option) {
320 free(b_execute_option);
322 if (b_service_responding) {
323 free(b_service_responding);
325 if (b_service_single_launch) {
326 free(b_service_single_launch);
328 if (b_service_multi_launch) {
329 free(b_service_multi_launch);
346 if (*query == NULL) {
347 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
350 return NOTIFICATION_ERROR_NONE;
354 static int _update_query_create(notification_h noti, char **query)
356 int b_encode_len = 0;
358 char *group_args = NULL;
359 char *b_image_path = NULL;
360 char *b_execute_option = NULL;
361 char *b_service_responding = NULL;
362 char *b_service_single_launch = NULL;
363 char *b_service_multi_launch = NULL;
366 char *b_format_args = NULL;
367 int flag_simmode = 0;
370 return NOTIFICATION_ERROR_INVALID_PARAMETER;
373 /* Decode bundle to update DB */
375 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
377 if (noti->group_args) {
378 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
382 if (noti->b_execute_option) {
383 bundle_encode(noti->b_execute_option,
384 (bundle_raw **) & b_execute_option, &b_encode_len);
386 if (noti->b_service_responding) {
387 bundle_encode(noti->b_service_responding,
388 (bundle_raw **) & b_service_responding, &b_encode_len);
390 if (noti->b_service_single_launch) {
391 bundle_encode(noti->b_service_single_launch,
392 (bundle_raw **) & b_service_single_launch, &b_encode_len);
394 if (noti->b_service_multi_launch) {
395 bundle_encode(noti->b_service_multi_launch,
396 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
400 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
403 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
405 if (noti->b_format_args) {
406 bundle_encode(noti->b_format_args,
407 (bundle_raw **) & b_format_args, &b_encode_len);
410 if (noti->b_image_path) {
411 bundle_encode(noti->b_image_path,
412 (bundle_raw **) & b_image_path, &b_encode_len);
415 /* Check only simmode property is enable */
416 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
421 *query = sqlite3_mprintf("UPDATE noti_list SET "
424 "launch_pkgname = '%s', "
425 "image_path = '%s', "
426 "b_text = '%s', b_key = '%s', tag = $tag, "
427 "b_format_args = '%s', num_format_args = %d, "
428 "text_domain = '%s', text_dir = '%s', "
429 "time = %d, insert_time = %d, "
430 "args = '%s', group_args = '%s', "
431 "b_execute_option = '%s', "
432 "b_service_responding = '%s', "
433 "b_service_single_launch = '%s', "
434 "b_service_multi_launch = '%s', "
435 "sound_type = %d, sound_path = '%s', "
436 "vibration_type = %d, vibration_path = '%s', "
437 "led_operation = %d, led_argb = %d, "
438 "led_on_ms = %d, led_off_ms = %d, "
439 "flags_for_property = %d, flag_simmode = %d, "
440 "display_applist = %d, "
441 "progress_size = $progress_size, progress_percentage = $progress_percentage "
442 "where priv_id = %d ",
445 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
446 NOTIFICATION_CHECK_STR(b_image_path),
447 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
448 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
449 NOTIFICATION_CHECK_STR(noti->domain),
450 NOTIFICATION_CHECK_STR(noti->dir),
451 (int)noti->time, (int)noti->insert_time,
452 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
453 NOTIFICATION_CHECK_STR(b_execute_option),
454 NOTIFICATION_CHECK_STR(b_service_responding),
455 NOTIFICATION_CHECK_STR(b_service_single_launch),
456 NOTIFICATION_CHECK_STR(b_service_multi_launch),
457 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
458 noti->vibration_type,
459 NOTIFICATION_CHECK_STR(noti->vibration_path),
464 noti->flags_for_property, flag_simmode, noti->display_applist,
467 /* Free decoded data */
475 if (b_execute_option) {
476 free(b_execute_option);
478 if (b_service_responding) {
479 free(b_service_responding);
481 if (b_service_single_launch) {
482 free(b_service_single_launch);
484 if (b_service_multi_launch) {
485 free(b_service_multi_launch);
502 if (*query == NULL) {
503 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
506 return NOTIFICATION_ERROR_NONE;
509 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
512 if (stmt == NULL || noti == NULL) {
516 noti->type = sqlite3_column_int(stmt, col++);
517 noti->layout = sqlite3_column_int(stmt, col++);
518 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
519 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
520 noti->b_image_path = notification_db_column_bundle(stmt, col++);
521 noti->group_id = sqlite3_column_int(stmt, col++);
522 noti->internal_group_id = 0;
523 noti->priv_id = sqlite3_column_int(stmt, col++);
524 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
526 noti->b_text = notification_db_column_bundle(stmt, col++);
527 noti->b_key = notification_db_column_bundle(stmt, col++);
528 noti->b_format_args = notification_db_column_bundle(stmt, col++);
529 noti->num_format_args = sqlite3_column_int(stmt, col++);
531 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
532 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
533 noti->time = sqlite3_column_int(stmt, col++);
534 noti->insert_time = sqlite3_column_int(stmt, col++);
535 noti->args = notification_db_column_bundle(stmt, col++);
536 noti->group_args = notification_db_column_bundle(stmt, col++);
538 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
539 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
540 noti->b_service_single_launch =
541 notification_db_column_bundle(stmt, col++);
542 noti->b_service_multi_launch =
543 notification_db_column_bundle(stmt, col++);
545 noti->sound_type = sqlite3_column_int(stmt, col++);
546 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
547 noti->vibration_type = sqlite3_column_int(stmt, col++);
548 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
549 noti->led_operation = sqlite3_column_int(stmt, col++);
550 noti->led_argb = sqlite3_column_int(stmt, col++);
551 noti->led_on_ms = sqlite3_column_int(stmt, col++);
552 noti->led_off_ms = sqlite3_column_int(stmt, col++);
554 noti->flags_for_property = sqlite3_column_int(stmt, col++);
555 noti->display_applist = sqlite3_column_int(stmt, col++);
556 noti->progress_size = sqlite3_column_double(stmt, col++);
557 noti->progress_percentage = sqlite3_column_double(stmt, col++);
559 noti->app_icon_path = NULL;
560 noti->app_name = NULL;
561 noti->temp_title = NULL;
562 noti->temp_content = NULL;
565 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
567 notification_h noti = NULL;
569 noti = (notification_h) calloc(1, sizeof(struct _notification));
574 _notification_noti_populate_from_stmt(stmt, noti);
579 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
583 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
585 if (buf_len <= len_total)
586 return NOTIFICATION_ERROR_INVALID_PARAMETER;
588 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
590 return NOTIFICATION_ERROR_NONE;
593 char *notification_noti_strip_tag(const char *tagged_str)
595 if (tagged_str == NULL)
598 int len_total = strlen(tagged_str);
603 char *b_f_e = strstr(tagged_str, ">");
604 char *b_e_s = strstr(tagged_str, "</");
606 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
609 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
612 int notification_noti_get_tag_type(const char *tagged_str)
614 if (tagged_str == NULL)
615 return TAG_TYPE_INVALID;
617 if (strlen(tagged_str)== 0)
618 return TAG_TYPE_INVALID;
620 char *b_f_s = strstr(tagged_str, "<");
621 char *b_f_e = strstr(tagged_str, ">");
623 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
624 return TAG_TYPE_INVALID;
626 char *start = b_f_s + 1;
627 int len_tag = b_f_e - b_f_s - 1;
629 if (strncmp(start,TAG_TIME,len_tag) == 0) {
630 return TAG_TYPE_TIME;
633 return TAG_TYPE_INVALID;
636 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
638 int ret = NOTIFICATION_ERROR_NONE;
642 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
646 query = sqlite3_mprintf("UPDATE noti_list SET "
647 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
648 rowid, rowid, rowid);
650 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
654 ret = notification_db_exec(db, query, NULL);
664 EXPORT_API int notification_noti_insert(notification_h noti)
668 sqlite3_stmt *stmt = NULL;
670 char buf_key[32] = { 0, };
671 const char *title_key = NULL;
674 db = notification_db_open(DBPATH);
676 return get_last_result();
679 /* Initialize private ID */
680 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
681 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
682 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
685 ret = _insertion_query_create(noti, &query);
686 if (ret != NOTIFICATION_ERROR_NONE) {
690 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
691 if (ret != SQLITE_OK) {
692 NOTIFICATION_ERR("Insert Query : %s", query);
693 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
695 ret = NOTIFICATION_ERROR_FROM_DB;
700 if (noti->b_key != NULL) {
701 snprintf(buf_key, sizeof(buf_key), "%d",
702 NOTIFICATION_TEXT_TYPE_TITLE);
704 title_key = bundle_get_val(noti->b_key, buf_key);
707 if (title_key == NULL && noti->b_text != NULL) {
708 snprintf(buf_key, sizeof(buf_key), "%d",
709 NOTIFICATION_TEXT_TYPE_TITLE);
711 title_key = bundle_get_val(noti->b_text, buf_key);
714 if (title_key == NULL) {
715 title_key = noti->caller_pkgname;
719 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
720 if (ret != NOTIFICATION_ERROR_NONE) {
721 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
724 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
725 if (ret != NOTIFICATION_ERROR_NONE) {
726 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
729 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
730 if (ret != NOTIFICATION_ERROR_NONE) {
731 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
733 sqlite3_finalize(stmt);
737 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
738 if (ret != NOTIFICATION_ERROR_NONE) {
739 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
741 sqlite3_finalize(stmt);
746 ret = sqlite3_step(stmt);
747 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
748 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
749 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
750 ret = NOTIFICATION_ERROR_NONE;
752 ret = NOTIFICATION_ERROR_FROM_DB;
755 ret = NOTIFICATION_ERROR_FROM_DB;
759 sqlite3_finalize(stmt);
764 notification_db_close(&db);
774 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
779 sqlite3_stmt *stmt = NULL;
781 if (priv_id < 0 || noti == NULL) {
782 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
787 db = notification_db_open(DBPATH);
789 return get_last_result();
792 char *base_query = "select "
793 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
794 "tag, b_text, b_key, b_format_args, num_format_args, "
795 "text_domain, text_dir, time, insert_time, args, group_args, "
796 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
797 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
798 "flags_for_property, display_applist, progress_size, progress_percentage "
801 if (pkgname != NULL) {
802 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
803 base_query ,pkgname, priv_id);
805 query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
808 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
812 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
813 if (ret != SQLITE_OK) {
814 NOTIFICATION_ERR("select Query : %s", query);
815 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
817 ret = NOTIFICATION_ERROR_FROM_DB;
821 ret = sqlite3_step(stmt);
822 if (ret == SQLITE_ROW) {
823 _notification_noti_populate_from_stmt(stmt, noti);
824 ret = NOTIFICATION_ERROR_NONE;
826 ret = NOTIFICATION_ERROR_FROM_DB;
834 sqlite3_finalize(stmt);
839 notification_db_close(&db);
845 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
850 sqlite3_stmt *stmt = NULL;
852 if (tag == NULL || noti == NULL) {
853 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
858 db = notification_db_open(DBPATH);
860 return get_last_result();
863 if (pkgname != NULL) {
864 ret = sqlite3_prepare_v2(db, "select "
865 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
866 "tag, b_text, b_key, b_format_args, num_format_args, "
867 "text_domain, text_dir, time, insert_time, args, group_args, "
868 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
869 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
870 "flags_for_property, display_applist, progress_size, progress_percentage "
871 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
872 if (ret != SQLITE_OK) {
873 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
874 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
877 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
878 if (ret != SQLITE_OK) {
879 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
883 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
884 if (ret != SQLITE_OK) {
885 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
889 ret = sqlite3_prepare_v2(db, "select "
890 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
891 "tag, b_text, b_key, b_format_args, num_format_args, "
892 "text_domain, text_dir, time, insert_time, args, group_args, "
893 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
894 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
895 "flags_for_property, display_applist, progress_size, progress_percentage "
896 "from noti_list where tag = ?", -1, &stmt, NULL);
897 if (ret != SQLITE_OK) {
898 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
899 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
902 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
903 if (ret != SQLITE_OK) {
904 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
909 char *base_query = "select "
910 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
911 "tag, b_text, b_key, b_format_args, num_format_args, "
912 "text_domain, text_dir, time, insert_time, args, group_args, "
913 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
914 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
915 "flags_for_property, display_applist, progress_size, progress_percentage "
918 if (pkgname != NULL) {
919 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and tag = '%s'",
920 base_query ,pkgname, tag);
922 query = sqlite3_mprintf("%s where tag = '%s'", base_query, tag);
925 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
929 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
930 if (ret != SQLITE_OK) {
931 NOTIFICATION_ERR("select Query : %s", query);
932 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
934 ret = NOTIFICATION_ERROR_FROM_DB;
938 ret = sqlite3_step(stmt);
939 if (ret == SQLITE_ROW) {
940 _notification_noti_populate_from_stmt(stmt, noti);
941 ret = NOTIFICATION_ERROR_NONE;
943 ret = NOTIFICATION_ERROR_FROM_DB;
951 sqlite3_finalize(stmt);
956 notification_db_close(&db);
962 EXPORT_API int notification_noti_update(notification_h noti)
966 sqlite3_stmt *stmt = NULL;
970 db = notification_db_open(DBPATH);
972 return get_last_result();
975 /* Check private ID is exist */
976 ret = _notification_noti_check_priv_id(noti, db);
977 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
978 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
982 /* make update query */
983 ret = _update_query_create(noti, &query);
984 if (ret != NOTIFICATION_ERROR_NONE) {
988 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
989 if (ret != SQLITE_OK) {
990 NOTIFICATION_ERR("Insert Query : %s", query);
991 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
993 ret = NOTIFICATION_ERROR_FROM_DB;
997 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
998 if (ret != NOTIFICATION_ERROR_NONE) {
999 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1002 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1003 if (ret != NOTIFICATION_ERROR_NONE) {
1004 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1007 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1008 if (ret != NOTIFICATION_ERROR_NONE) {
1009 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1013 ret = sqlite3_step(stmt);
1014 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1015 ret = NOTIFICATION_ERROR_NONE;
1017 ret = NOTIFICATION_ERROR_FROM_DB;
1021 sqlite3_finalize(stmt);
1026 notification_db_close(&db);
1030 sqlite3_free(query);
1036 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1038 int ret = NOTIFICATION_ERROR_NONE;
1039 int ret_tmp = NOTIFICATION_ERROR_NONE;
1040 int i = 0, data_cnt = 0;
1042 sqlite3_stmt *stmt = NULL;
1043 char buf[128] = { 0, };
1044 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1045 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1046 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1049 db = notification_db_open(DBPATH);
1051 return get_last_result();
1054 if (pkgname == NULL) {
1055 if (type != NOTIFICATION_TYPE_NONE) {
1056 snprintf(query_where, sizeof(query_where),
1057 "where type = %d ", type);
1060 if (type == NOTIFICATION_TYPE_NONE) {
1061 snprintf(query_where, sizeof(query_where),
1062 "where caller_pkgname = '%s' ", pkgname);
1064 snprintf(query_where, sizeof(query_where),
1065 "where caller_pkgname = '%s' and type = %d ",
1070 if (num_deleted != NULL) {
1073 if (list_deleted_rowid != NULL) {
1074 *list_deleted_rowid = NULL;
1075 snprintf(query, sizeof(query),
1076 "select priv_id from noti_list %s ", query_where);
1078 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1079 if (ret != SQLITE_OK) {
1080 NOTIFICATION_ERR("Select Query : %s", query);
1081 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1082 sqlite3_errmsg(db));
1084 ret = NOTIFICATION_ERROR_FROM_DB;
1088 while(sqlite3_step(stmt) == SQLITE_ROW) {
1089 if (data_cnt % 8 == 0) {
1092 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1094 *list_deleted_rowid = tmp;
1096 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
1099 * How can I handle this?
1101 free(*list_deleted_rowid);
1102 *list_deleted_rowid = NULL;
1103 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1107 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1112 sqlite3_finalize(stmt);
1117 query_where[0] = '\0';
1118 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1119 for (i = 0; i < data_cnt ; i++) {
1120 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1121 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1122 ret_tmp = notification_db_exec(db, query, NULL);
1123 query_where[0] = '\0';
1124 if (ret == NOTIFICATION_ERROR_NONE) {
1128 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1129 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1131 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1132 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1133 ret_tmp = notification_db_exec(db, query, NULL);
1134 if (ret == NOTIFICATION_ERROR_NONE) {
1139 free(*list_deleted_rowid);
1140 *list_deleted_rowid = NULL;
1143 if (num_deleted != NULL) {
1144 *num_deleted = data_cnt;
1147 /* Make main query */
1148 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1149 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1151 ret = notification_db_exec(db, query, NULL);
1153 if (num_deleted != NULL) {
1154 *num_deleted = sqlite3_changes(db);
1160 sqlite3_finalize(stmt);
1164 notification_db_close(&db);
1170 int notification_noti_delete_group_by_group_id(const char *pkgname,
1171 int group_id, int *num_deleted, int **list_deleted_rowid)
1173 int ret = NOTIFICATION_ERROR_NONE;
1174 int ret_tmp = NOTIFICATION_ERROR_NONE;
1176 int i = 0, data_cnt = 0;
1177 sqlite3_stmt *stmt = NULL;
1178 char buf[128] = { 0, };
1179 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1180 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1181 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1183 /* Check pkgname is valid */
1184 if (pkgname == NULL) {
1185 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1188 snprintf(query_where, sizeof(query_where),
1189 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1192 db = notification_db_open(DBPATH);
1194 return get_last_result();
1197 if (num_deleted != NULL) {
1200 if (list_deleted_rowid != NULL) {
1201 *list_deleted_rowid = NULL;
1202 snprintf(query, sizeof(query),
1203 "select priv_id from noti_list %s ", query_where);
1205 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1206 if (ret != SQLITE_OK) {
1207 NOTIFICATION_ERR("Select Query : %s", query);
1208 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1209 sqlite3_errmsg(db));
1211 ret = NOTIFICATION_ERROR_FROM_DB;
1215 while(sqlite3_step(stmt) == SQLITE_ROW) {
1216 if (data_cnt % 8 == 0) {
1218 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1220 *list_deleted_rowid = tmp;
1222 free(*list_deleted_rowid);
1223 *list_deleted_rowid = NULL;
1224 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1228 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1233 sqlite3_finalize(stmt);
1238 query_where[0] = '\0';
1239 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1240 for (i = 0; i < data_cnt ; i++) {
1241 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1242 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1243 ret_tmp = notification_db_exec(db, query, NULL);
1244 query_where[0] = '\0';
1245 if (ret == NOTIFICATION_ERROR_NONE) {
1249 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1250 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1252 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1253 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1254 ret_tmp = notification_db_exec(db, query, NULL);
1255 if (ret == NOTIFICATION_ERROR_NONE) {
1260 free(*list_deleted_rowid);
1261 *list_deleted_rowid = NULL;
1264 if (num_deleted != NULL) {
1265 *num_deleted = data_cnt;
1269 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1272 ret = notification_db_exec(db, query, NULL);
1277 sqlite3_finalize(stmt);
1281 notification_db_close(&db);
1287 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1290 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1291 int internal_group_id = 0;
1294 /* Check pkgname is valid */
1295 if (pkgname == NULL) {
1296 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1300 db = notification_db_open(DBPATH);
1302 return get_last_result();
1305 /* Get internal group id using priv id */
1307 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1311 snprintf(query, sizeof(query), "delete from noti_list "
1312 "where caller_pkgname = '%s' and internal_group_id = %d",
1313 pkgname, internal_group_id);
1316 ret = notification_db_exec(db, query, NULL);
1319 notification_db_close(&db);
1324 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1327 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1330 /* Check pkgname is valid */
1331 if (pkgname == NULL) {
1332 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1336 db = notification_db_open(DBPATH);
1338 return get_last_result();
1342 snprintf(query, sizeof(query), "delete from noti_list "
1343 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1347 ret = notification_db_exec(db, query, NULL);
1351 notification_db_close(&db);
1357 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1360 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1363 /* Check pkgname is valid */
1364 if (pkgname == NULL) {
1365 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1369 db = notification_db_open(DBPATH);
1371 return get_last_result();
1375 snprintf(query, sizeof(query), "delete from noti_list "
1376 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1380 ret = notification_db_exec(db, query, num_changes);
1382 if (num_changes != NULL) {
1383 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1388 notification_db_close(&db);
1394 int notification_noti_get_count(notification_type_e type,
1395 const char *pkgname,
1396 int group_id, int priv_id,
1400 sqlite3_stmt *stmt = NULL;
1401 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1402 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1403 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1404 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1406 int ret = 0, get_count = 0, internal_group_id = 0;
1407 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1409 int flag_where_more = 0;
1413 db = notification_db_open(DBPATH);
1415 return get_last_result();
1418 /* Check current sim status */
1419 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1422 snprintf(query_base, sizeof(query_base),
1423 "select count(*) from noti_list ");
1425 if (pkgname != NULL) {
1426 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1427 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1428 snprintf(query_where, sizeof(query_where),
1429 "where caller_pkgname = '%s' ",
1434 _notification_noti_get_internal_group_id_by_priv_id
1435 (pkgname, priv_id, db);
1436 snprintf(query_where, sizeof(query_where),
1437 "where caller_pkgname = '%s' and internal_group_id = %d ",
1438 pkgname, internal_group_id);
1442 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1443 snprintf(query_where, sizeof(query_where),
1444 "where caller_pkgname = '%s' and group_id = %d ",
1449 _notification_noti_get_internal_group_id_by_priv_id
1450 (pkgname, priv_id, db);
1451 snprintf(query_where, sizeof(query_where),
1452 "where caller_pkgname = '%s' and internal_group_id = %d ",
1453 pkgname, internal_group_id);
1460 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1461 if (type != NOTIFICATION_TYPE_NONE) {
1462 snprintf(query_where_more, sizeof(query_where_more),
1463 "type = %d ", type);
1464 flag_where_more = 1;
1467 if (type != NOTIFICATION_TYPE_NONE) {
1468 snprintf(query_where_more, sizeof(query_where_more),
1469 "type = %d and flag_simmode = 0 ", type);
1470 flag_where_more = 1;
1472 snprintf(query_where_more, sizeof(query_where_more),
1473 "flag_simmode = 0 ");
1474 flag_where_more = 1;
1478 if (flag_where == 1) {
1479 if (flag_where_more == 1) {
1480 snprintf(query, sizeof(query), "%s %s and %s",
1481 query_base, query_where, query_where_more);
1483 snprintf(query, sizeof(query), "%s %s", query_base,
1488 if (flag_where_more == 1) {
1489 snprintf(query, sizeof(query), "%s where %s",
1490 query_base, query_where_more);
1492 snprintf(query, sizeof(query), "%s", query_base);
1496 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1497 if (ret != SQLITE_OK) {
1498 NOTIFICATION_ERR("Select Query : %s", query);
1499 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1500 sqlite3_errmsg(db));
1502 ret = NOTIFICATION_ERROR_FROM_DB;
1506 ret = sqlite3_step(stmt);
1507 if (ret == SQLITE_ROW) {
1508 get_count = sqlite3_column_int(stmt, 0);
1511 ret = NOTIFICATION_ERROR_NONE;
1515 sqlite3_finalize(stmt);
1520 notification_db_close(&db);
1528 int notification_noti_get_grouping_list(notification_type_e type,
1530 notification_list_h *
1534 sqlite3_stmt *stmt = NULL;
1535 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1536 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1537 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1540 notification_list_h get_list = NULL;
1541 notification_h noti = NULL;
1542 int internal_count = 0;
1546 db = notification_db_open(DBPATH);
1548 return get_last_result();
1551 /* Check current sim status */
1552 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1555 snprintf(query_base, sizeof(query_base), "select "
1556 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1557 "tag, b_text, b_key, b_format_args, num_format_args, "
1558 "text_domain, text_dir, time, insert_time, args, group_args, "
1559 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1560 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1561 "flags_for_property, display_applist, progress_size, progress_percentage "
1564 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1565 if (type != NOTIFICATION_TYPE_NONE) {
1566 snprintf(query_where, sizeof(query_where),
1567 "where type = %d ", type);
1570 if (type != NOTIFICATION_TYPE_NONE) {
1571 snprintf(query_where, sizeof(query_where),
1572 "where type = %d and flag_simmode = 0 ", type);
1574 snprintf(query_where, sizeof(query_where),
1575 "where flag_simmode = 0 ");
1579 snprintf(query, sizeof(query),
1581 "group by internal_group_id "
1582 "order by rowid desc, time desc", query_base, query_where);
1584 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1585 if (ret != SQLITE_OK) {
1586 NOTIFICATION_ERR("Select Query : %s", query);
1587 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1588 sqlite3_errmsg(db));
1590 ret = NOTIFICATION_ERROR_FROM_DB;
1594 while (sqlite3_step(stmt) == SQLITE_ROW) {
1595 /* Make notification list */
1596 noti = _notification_noti_get_item(stmt);
1600 get_list = notification_list_append(get_list, noti);
1602 if (count != -1 && internal_count >= count) {
1604 ("internal count %d >= count %d",
1605 internal_count, count);
1611 ret = NOTIFICATION_ERROR_NONE;
1615 sqlite3_finalize(stmt);
1620 notification_db_close(&db);
1623 if (get_list != NULL) {
1624 *list = notification_list_get_head(get_list);
1630 int notification_noti_get_detail_list(const char *pkgname,
1632 int priv_id, int count,
1633 notification_list_h *list)
1636 sqlite3_stmt *stmt = NULL;
1637 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1638 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1640 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1642 notification_list_h get_list = NULL;
1643 notification_h noti = NULL;
1644 int internal_count = 0;
1645 int internal_group_id = 0;
1646 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1649 db = notification_db_open(DBPATH);
1651 return get_last_result();
1654 /* Check current sim status */
1655 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1658 snprintf(query_base, sizeof(query_base), "select "
1659 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1660 "tag, b_text, b_key, b_format_args, num_format_args, "
1661 "text_domain, text_dir, time, insert_time, args, group_args, "
1662 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1663 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1664 "flags_for_property, display_applist, progress_size, progress_percentage "
1667 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1668 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1669 snprintf(query_where, sizeof(query_where),
1670 "where caller_pkgname = '%s' ", pkgname);
1672 snprintf(query_where, sizeof(query_where),
1673 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1677 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1680 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1681 snprintf(query_where, sizeof(query_where),
1682 "where caller_pkgname = '%s' and internal_group_id = %d ",
1683 pkgname, internal_group_id);
1685 snprintf(query_where, sizeof(query_where),
1686 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1687 pkgname, internal_group_id);
1691 snprintf(query, sizeof(query),
1693 "order by rowid desc, time desc", query_base, query_where);
1695 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1696 if (ret != SQLITE_OK) {
1697 NOTIFICATION_ERR("Select Query : %s", query);
1698 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1699 sqlite3_errmsg(db));
1701 ret = NOTIFICATION_ERROR_FROM_DB;
1705 while (sqlite3_step(stmt) == SQLITE_ROW) {
1706 /* Make notification list */
1707 noti = _notification_noti_get_item(stmt);
1711 get_list = notification_list_append(get_list, noti);
1713 if (count != -1 && internal_count >= count) {
1715 ("internal count %d >= count %d",
1716 internal_count, count);
1722 ret = NOTIFICATION_ERROR_NONE;
1726 sqlite3_finalize(stmt);
1731 notification_db_close(&db);
1734 if (get_list != NULL) {
1735 *list = notification_list_get_head(get_list);
1741 EXPORT_API int notification_noti_check_tag(notification_h noti)
1744 int ret = NOTIFICATION_ERROR_NONE;
1747 sqlite3_stmt *stmt = NULL;
1749 if (noti->tag == NULL) {
1750 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1754 db = notification_db_open(DBPATH);
1756 return get_last_result();
1759 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1760 if (ret != SQLITE_OK) {
1761 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1762 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1765 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1766 if (ret != SQLITE_OK) {
1767 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1771 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1772 if (ret != SQLITE_OK) {
1773 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1778 query = sqlite3_mprintf("select priv_id from noti_list where caller_pkgname = '%s' and tag = '%s'",
1779 noti->caller_pkgname, noti->tag);
1780 if (query == NULL) {
1781 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1785 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1786 if (ret != SQLITE_OK) {
1787 NOTIFICATION_ERR("Get priv id DB err(%d) : %s", ret,
1788 sqlite3_errmsg(db));
1789 ret = NOTIFICATION_ERROR_FROM_DB;
1793 ret = sqlite3_step(stmt);
1794 if (ret == SQLITE_ROW) {
1795 result = sqlite3_column_int(stmt, 0);
1800 sqlite3_finalize(stmt);
1802 /* If result > 0, there is priv_id in DB */
1804 noti->priv_id = result;
1805 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1807 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1812 sqlite3_free(query);
1819 popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
1821 Eina_List *list = NULL;
1825 evas_object_del(toast_popup);
1827 evas_object_del((Evas_Object *)data);
1829 count = eina_list_count(toast_list);
1832 msg = (char *)eina_list_data_get(toast_list);
1835 eina_list_free(toast_list);
1837 } else if (count > 1) {
1838 msg = (char *)eina_list_data_get(toast_list);
1839 toast_list = eina_list_remove(toast_list, msg);
1841 _post_toast_message((char *)eina_list_data_get(toast_list));
1845 int _post_toast_message(char *message)
1848 Evas_Object *toast_window;
1851 double scale = elm_config_scale_get();
1854 toast_window = elm_win_add(NULL, "toast", ELM_WIN_BASIC);
1856 elm_win_alpha_set(toast_window, EINA_TRUE);
1857 elm_win_title_set(toast_window, "toast");
1859 elm_win_indicator_mode_set(toast_window, ELM_WIN_INDICATOR_SHOW);
1860 elm_win_indicator_type_set(toast_window,ELM_WIN_INDICATOR_TYPE_1);
1862 //elm_win_autodel_set(toast_win, EINA_TRUE);
1863 if (elm_win_wm_rotation_supported_get(toast_window)) {
1864 int rots[4] = { 0, 90, 180, 270 };
1865 elm_win_wm_rotation_available_rotations_set(toast_window, (const int*)(&rots), 4);
1868 e = evas_object_evas_get(toast_window);
1869 ee = ecore_evas_ecore_evas_get(e);
1870 ecore_evas_name_class_set(ee, "TOAST_POPUP", "SYSTEM_POPUP");
1872 evas_object_resize(toast_window, (480 * scale), (650 * scale));
1873 ecore_x_window_shape_input_rectangle_set(elm_win_xwindow_get(toast_window), 0, 0, (480 * scale), (650 * scale));
1875 toast_popup = elm_popup_add(toast_window);
1877 elm_object_style_set(toast_popup, "toast");
1878 evas_object_size_hint_weight_set(toast_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1880 elm_object_part_text_set(toast_popup,"elm.text", message);
1882 if (eina_list_count(toast_list) != 1) {
1883 elm_popup_timeout_set(toast_popup, 1.0);
1886 elm_popup_timeout_set(toast_popup, 3.0);
1888 evas_object_smart_callback_add(toast_popup, "timeout", popup_timeout_cb, (void *)toast_window);
1890 elm_win_prop_focus_skip_set(toast_window, EINA_TRUE);
1892 evas_object_show(toast_window);
1893 evas_object_show(toast_popup);
1898 EXPORT_API int notification_noti_post_toast_message(const char *message)
1904 msg = (char *)calloc(strlen(message) + 1, sizeof(char));
1905 strcpy(msg, message);
1908 if (eina_list_count(toast_list) == 10) {
1909 toast_list = eina_list_last(toast_list);
1910 eina_list_data_set(toast_list, msg);
1911 toast_list = eina_list_nth_list(toast_list, 0);
1916 count = eina_list_count(toast_list);
1918 toast_list = eina_list_append(toast_list, msg);
1919 let = _post_toast_message(msg);
1921 else if (count == 1) {
1922 if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) {
1923 elm_popup_timeout_set(toast_popup, 3.0);
1926 toast_list = eina_list_append(toast_list, msg);
1927 elm_popup_timeout_set(toast_popup, 1.0);
1930 else if (count >= 2) {
1931 if (strcmp(msg, (char *)eina_list_nth(toast_list, count - 1)) == 0) {
1936 toast_list = eina_list_append(toast_list, msg);