4d16f57bdfeb16ca151432e245fc38410bd002c9
[apps/core/preloaded/quickpanel.git] / daemon / service / smart_alert.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 #include <vconf.h>
20 #include "common.h"
21 #include "noti_util.h"
22 #include "smart_alert.h"
23
24 static inline int __quickpanel_service_update_event_count(const char *pkgname, const char *vconfkey)
25 {
26         int ret = 0, count = 0;
27         notification_h noti = NULL;
28         notification_list_h noti_list = NULL;
29
30         retif(pkgname == NULL, 0, "Invalid parameter!");
31         retif(vconfkey == NULL, 0, "Invalid parameter!");
32
33         notification_get_detail_list(pkgname, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
34         if (noti_list != NULL) {
35                 noti = notification_list_get_data(noti_list);
36                 if (noti != NULL) {
37                         count = quickpanel_noti_util_get_event_count_from_noti(noti);
38                         ret = vconf_set_int(vconfkey, count);
39
40                         ERR("event set:%s, count:%d", pkgname, count);
41
42                         if (ret != 0) {
43                                 ERR("failed to set vconf key[%s] : %d", vconfkey, ret);
44                         }
45                 } else {
46                         ERR("no data found:%s", pkgname);
47                 }
48                 notification_free_list(noti_list);
49                 return count;
50         } else {
51                 ret = vconf_set_int(vconfkey, 0);
52
53                 ERR("event unset:%s", pkgname);
54
55                 if (ret != 0) {
56                         ERR("failed to set vconf key[%s] : %d", vconfkey, ret);
57                 }
58         }
59
60         return 0;
61 }
62
63 HAPI void quickpanel_smart_alert_update_info(notification_h noti)
64 {
65         char *pkgname = NULL;
66         int event_count_call = 0;
67         int event_count_vtcall = 0;
68
69         if (noti == NULL) {
70                 event_count_call = quickpanel_noti_util_get_event_count_by_pkgname(SMART_ALARM_CALL_PKGNAME);
71                 event_count_vtcall = quickpanel_noti_util_get_event_count_by_pkgname(SMART_ALARM_VTCALL_PKGNAME);
72                 ERR("call event set, count:%d", MAX(event_count_call, event_count_vtcall));
73         } else {
74                 notification_get_pkgname(noti, &pkgname);
75                 retif(pkgname == NULL, , "Invalid parameter!");
76
77                 if (strncmp(pkgname, SMART_ALARM_CALL_PKGNAME, strlen(pkgname)) == 0
78                         || strncmp(pkgname, SMART_ALARM_VTCALL_PKGNAME, strlen(pkgname)) == 0) {
79                         event_count_call = quickpanel_noti_util_get_event_count_by_pkgname(SMART_ALARM_CALL_PKGNAME);
80                         event_count_vtcall = quickpanel_noti_util_get_event_count_by_pkgname(SMART_ALARM_VTCALL_PKGNAME);
81
82                         ERR("call event set, count:%d", MAX(event_count_call, event_count_vtcall));
83                 }
84         }
85 }