[Other]Tizen 2.0 branch
[apps/core/preloaded/lockscreen.git] / src / noti.c
1 /*\r
2  * Copyright 2012  Samsung Electronics Co., Ltd\r
3  *\r
4  * Licensed under the Flora License, Version 1.0 (the License);\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *  http://www.tizenopensource.org/license\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an AS IS BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include <notification.h>\r
18 #include <vconf.h>\r
19 #include <vconf-keys.h>\r
20 \r
21 #include "lockscreen.h"\r
22 #include "log.h"\r
23 \r
24 #define PHONE_LAUNCH_PKG               "org.tizen.phone"\r
25 #define EMAIL_LAUNCH_PKG               "org.tizen.email"\r
26 #define MESSAGE_LAUNCH_PKG             "org.tizen.message"\r
27 #define MAX_NOTI_NUM                   3\r
28 \r
29 static void __noti_info_set(void *data, const char *pkgname, const char *title, int count, int line_num)\r
30 {\r
31         struct appdata *ad = (struct appdata *)data;\r
32         if(ad == NULL || pkgname == NULL){\r
33                 return;\r
34         }\r
35 \r
36         LOCK_SCREEN_TRACE_DBG("pkgname : %s, title : %s, count = %d, line_num = %d", pkgname, title, count, line_num);\r
37 \r
38         char buf1[512] = {0};\r
39         char buf2[512] = {0};\r
40 \r
41         snprintf(buf2, sizeof(buf2), "noti_title%d", line_num);\r
42 \r
43         if (!strcmp(pkgname, PHONE_LAUNCH_PKG)) {\r
44                 if(count == 1){\r
45                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("Missed call"));\r
46                 }else if(count > 1){\r
47                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("Missed calls"));\r
48                 }\r
49                 edje_object_part_text_set(_EDJ(ad->noti), buf2, buf1);\r
50         } else if (!strcmp(pkgname, MESSAGE_LAUNCH_PKG)) {\r
51                 if(count == 1){\r
52                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("New message"));\r
53                 }else if(count > 1){\r
54                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("New messages"));\r
55                 }\r
56                 edje_object_part_text_set(_EDJ(ad->noti), buf2, buf1);\r
57         } else if (!strcmp(pkgname, EMAIL_LAUNCH_PKG)) {\r
58                 if(count == 1){\r
59                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("New email"));\r
60                 }else if(count > 1){\r
61                         snprintf(buf1, sizeof(buf1), "%d %s", count, _NOT_LOCALIZED("New emails"));\r
62                 }\r
63                 edje_object_part_text_set(_EDJ(ad->noti), buf2, buf1);\r
64         } else {\r
65                 edje_object_part_text_set(_EDJ(ad->noti), buf2, title);\r
66         }\r
67 }\r
68 \r
69 static int __ticker_check_setting_event_value(notification_h noti)\r
70 {\r
71         char *pkgname = NULL;\r
72         char key[512] = {0, };\r
73         int ret = 0;\r
74         int boolval = 0;\r
75 \r
76         notification_get_application(noti, &pkgname);\r
77 \r
78         if (pkgname == NULL) {\r
79                 notification_get_pkgname(noti, &pkgname);\r
80         }\r
81 \r
82         if (pkgname == NULL) {\r
83                 return 0;\r
84         }\r
85 \r
86         if (!strcmp(pkgname, MESSAGE_LAUNCH_PKG)) {\r
87                 ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_MESSAGES_BOOL, &boolval);\r
88                 if (ret == 0 && boolval == 0) {\r
89                         return 0;\r
90                 }\r
91         } else if (!strcmp(pkgname, EMAIL_LAUNCH_PKG)) {\r
92                 ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_TICKER_NOTI_EMAIL_BOOL, &boolval);\r
93                 if (ret == 0 && boolval == 0) {\r
94                         return 0;\r
95                 }\r
96         }\r
97 \r
98         snprintf(key, sizeof(key), "db/app-settings/noti-enabled/%s", pkgname);\r
99         ret = vconf_get_int(key, &boolval);\r
100         if (ret == 0 && boolval == 0) {\r
101                 return 0;\r
102         }\r
103 \r
104         return 1;\r
105 }\r
106 \r
107 static void __noti_changed_cb(void *data, notification_type_e type)\r
108 {\r
109         notification_h noti = NULL;\r
110         notification_list_h notification_list = NULL;\r
111         notification_list_h get_list = NULL;\r
112         int count = 0, group_id = 0, priv_id = 0, show_noti = 0, num = 1;\r
113         char *pkgname = NULL;\r
114         char *title = NULL;\r
115         char *str_count = NULL;\r
116         int i = 1;\r
117         char buf[512] = {0};\r
118         struct appdata *ad = (struct appdata *)data;\r
119 \r
120         for(i = 1; i <= MAX_NOTI_NUM; i++){\r
121                 snprintf(buf, sizeof(buf), "noti_title%d", i);\r
122                 edje_object_part_text_set(_EDJ(ad->noti), buf, "");\r
123         }\r
124 \r
125         notification_get_list(NOTIFICATION_TYPE_NOTI, -1, &notification_list);\r
126         if (notification_list) {\r
127                 get_list = notification_list_get_head(notification_list);\r
128                 noti = notification_list_get_data(get_list);\r
129                 LOCK_SCREEN_TRACE_DBG("get_list : %p, noti : %p", get_list, noti);\r
130                 while(get_list != NULL) {\r
131                         notification_get_id(noti, &group_id, &priv_id);\r
132                         notification_get_pkgname(noti, &pkgname);\r
133                         if(pkgname == NULL){\r
134                                 notification_get_application(noti, &pkgname);\r
135                         }\r
136                         show_noti = __ticker_check_setting_event_value(noti);\r
137                         LOCK_SCREEN_TRACE_DBG("show noti : %d", show_noti);\r
138                         if (show_noti == 0) {\r
139                                 get_list = notification_list_get_next(get_list);\r
140                                 noti = notification_list_get_data(get_list);\r
141                                 continue;\r
142                         }\r
143 \r
144                         if(num > MAX_NOTI_NUM){\r
145                                 if (notification_list != NULL) {\r
146                                         notification_free_list(notification_list);\r
147                                         notification_list = NULL;\r
148                                 }\r
149                                 return;\r
150                         }\r
151 \r
152                         notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &str_count);\r
153                         if (!str_count) {\r
154                                 count = 0;\r
155                         } else {\r
156                                 count = atoi(str_count);\r
157                         }\r
158                         notification_get_title(noti, &title, NULL);\r
159                         __noti_info_set(data, pkgname, title, count, num);\r
160                         get_list = notification_list_get_next(get_list);\r
161                         noti = notification_list_get_data(get_list);\r
162                         num++;\r
163                 }\r
164         }\r
165         if (notification_list != NULL) {\r
166                 notification_free_list(notification_list);\r
167                 notification_list = NULL;\r
168         }\r
169 }\r
170 \r
171 void noti_process(void *data)\r
172 {\r
173         struct appdata *ad = (struct appdata *)data;\r
174         if(ad == NULL){\r
175                 return;\r
176         }\r
177 \r
178         ad->noti = elm_layout_add(ad->ly_main);\r
179         elm_layout_file_set(ad->noti, EDJEFILE, "lock-noti");\r
180         evas_object_show(ad->noti);\r
181         elm_object_part_content_set(ad->ly_main, "sw.noti", ad->noti);\r
182 \r
183         notification_resister_changed_cb(__noti_changed_cb, ad);\r
184         __noti_changed_cb(ad, NOTIFICATION_TYPE_NOTI);\r
185 }\r