3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 #include <notification.h>
30 #include "noti-handler.h"
31 #include "cld-images.h"
33 #define SERVICE_CALENDAR_NAME "operation"
34 #define SERVICE_CALENDAR_INDEX_NAME "index"
36 static calendar_record_h __cal_noti_handler_get_record_from_calendar_alarm(calendar_record_h calendar_alarm)
38 c_retv_if(!calendar_alarm, NULL);
42 calendar_error_e error = CALENDAR_ERROR_NONE;
44 calendar_record_h record = NULL;
46 error = calendar_record_get_int(calendar_alarm, _calendar_alarm.event_id, &record_index);
47 if (error != CALENDAR_ERROR_NONE) {
48 error = calendar_db_get_record(_calendar_event._uri, record_index, &record);
50 error = calendar_record_get_int(calendar_alarm, _calendar_alarm.todo_id, &record_index);
51 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_get_int() is failed(%x)", error);
53 error = calendar_db_get_record(_calendar_todo._uri, record_index, &record);
56 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_record() is failed(%x)", error);
61 static void __cal_noti_handler_add_noti(struct appdata* ad, calendar_record_h record)
68 calendar_time_s start_time = {0};
70 _calendar_get_start_time(record, &start_time);
74 if (_calendar_is_allday_record(record)) {
75 tm.tm_year = start_time.time.date.year - 1900;
76 tm.tm_mon = start_time.time.date.month - 1;
77 tm.tm_mday = start_time.time.date.mday;
79 cal_util_convert_lli_to_tm(NULL, start_time.time.utime, &tm);
81 char *title = _calendar_get_summary(record);
83 notification_h notification = NULL;
85 notification_error_e error = NOTIFICATION_ERROR_NONE;
87 int notification_id = 0;
89 int ret = vconf_get_int(CAL_VCONFKEY_NOTIFICATION_ID, ¬ification_id);
90 c_warn_if(ret != 0,"vconf_get_int(CAL_VCONFKEY_NOTIFICATION_ID) is failed(%d)", ret);
92 Eina_Bool is_first_notification = EINA_FALSE;
94 notification = notification_load(CALENDAR_PACKAGE, notification_id);
96 notification = notification_create(NOTIFICATION_TYPE_NOTI);
100 c_retm_if(!notification, "notification_create() is failed.");
103 is_first_notification = EINA_TRUE;
106 if (is_first_notification) {
107 error = notification_set_layout(notification, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
108 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_layout() is failed(%x)", error);
110 error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, S_("IDS_COM_BODY_S_PLANNER"), "IDS_COM_BODY_S_PLANNER", NOTIFICATION_VARIABLE_TYPE_NONE);
111 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_text() is failed(%x)", error);
113 error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_CONTENT, S_("IDS_COM_POP_MISSED_EVENT"), "IDS_COM_POP_MISSED_EVENT", NOTIFICATION_VARIABLE_TYPE_NONE);
114 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_text() is failed(%x)", error);
116 error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_INFO_1, title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
117 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_text() is failed(%x)", error);
119 time_t current = time(NULL);
121 error = notification_set_time_to_text(notification, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, current);
122 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_time_to_text() is failed(%x)", error);
125 int notification_count = 0;
127 error = notification_get_count(NOTIFICATION_TYPE_NOTI, CALENDAR_PACKAGE, NOTIFICATION_GROUP_ID_NONE, notification_id, ¬ification_count);
128 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_get_count() is failed(%x)", error);
130 if (notification_count == 1) {
132 error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_INFO_2, title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
133 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_text() is failed(%x)", error);
135 time_t current = time(NULL);
137 error = notification_set_time_to_text(notification, NOTIFICATION_TEXT_TYPE_INFO_SUB_2, current);
138 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_time_to_text() is failed(%x)", error);
141 char text[128] = {0};
144 snprintf(text, sizeof(text), "%d %s", notification_count + 1, S_("IDS_COM_POP_MISSED_EVENTS"));
146 error = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_CONTENT, text, "IDS_COM_POP_MISSED_EVENTS", NOTIFICATION_VARIABLE_TYPE_NONE);
147 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_text() is failed(%x)", error);
150 error = notification_set_time(notification, mktime(&tm));
151 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_time() is failed(%x)", error);
157 ERR("bundle_create() is failed");
159 notification_free(notification);
164 ret = appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
165 c_warn_if(ret, "appsvc_set_operation() is failed");
167 ret = appsvc_set_appid(b, CALENDAR_PACKAGE);
168 c_warn_if(ret, "appsvc_set_appid() is failed");
170 char item_id[8] = {0};
172 snprintf(item_id, sizeof(item_id), "%d", _calendar_get_record_index(record));
174 ret = bundle_add(b, CAL_APPSVC_PARAM_INDEX, item_id);
175 c_warn_if(ret, "bundle_add() is failed");
177 _calendar_record_type type = _calendar_get_record_type(record);
179 if (type == _CALENDAR_RECORD_TYPE_EVENT) {
180 ret = bundle_add(b, CAL_APPSVC_PARAM_TYPE, "event");
181 } else if (type == _CALENDAR_RECORD_TYPE_TODO) {
182 ret = bundle_add(b, CAL_APPSVC_PARAM_TYPE, "todo");
185 c_warn_if(ret, "bundle_add() is failed");
187 error = notification_set_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
188 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_execute_option() is failed(%x)", error);
190 error = notification_set_execute_option(notification, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, b);
191 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_execute_option() is failed(%x)", error);
193 error = notification_set_pkgname(notification, CALENDAR_PACKAGE);
194 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_set_pkgname() is failed(%x)", error);
196 if (is_first_notification) {
198 error = notification_insert(notification, ¬ification_id);
199 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_insert() is failed(%x)", error);
201 ret = vconf_set_int(CAL_VCONFKEY_NOTIFICATION_ID, notification_id);
202 c_warn_if(ret != 0,"vconf_set_int(CAL_VCONFKEY_NOTIFICATION_ID, %d) is failed(%d)", notification_id, ret);
204 error = notification_update(notification);
205 c_warn_if(error != NOTIFICATION_ERROR_NONE, "notification_update() is failed(%x)", error);
209 notification_free(notification);
213 static void __cal_noti_handler_add_noti_for_reminder(struct appdata* ad, calendar_record_h calendar_alarm)
216 c_ret_if(!calendar_alarm);
218 calendar_record_h record = __cal_noti_handler_get_record_from_calendar_alarm(calendar_alarm);
221 __cal_noti_handler_add_noti(ad, record);
223 calendar_error_e error = CALENDAR_ERROR_NONE;
225 error = calendar_record_destroy(record, true);
226 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_record_destroy() is failed(%x)");
229 int cal_noti_handler_show_for_reminder(int record_index, void *data)
233 c_retv_if(!data, -1);
235 struct appdata *ad = data;
237 calendar_error_e error = CALENDAR_ERROR_NONE;
239 calendar_query_h query = NULL;
241 error = calendar_query_create(_calendar_alarm._uri, &query);
242 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_create() is failed(%x)", error);
244 calendar_filter_h filter = NULL;
246 error = calendar_filter_create(_calendar_alarm._uri, &filter);
247 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_create() is failed(%x)", error);
249 error = calendar_filter_add_int(filter, _calendar_alarm.alarm_id, CALENDAR_MATCH_EQUAL, (int)record_index);
250 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_add_int() is failed(%x)", error);
252 error = calendar_query_set_filter(query, filter);
253 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_add_filter() is failed(%x)", error);
255 calendar_list_h list = NULL;
257 error = calendar_db_get_records_with_query(query, 0, 0, &list);
258 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_db_get_records_with_query() is failed(%x)", error);
264 error = calendar_list_get_count(list, &count);
265 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_count() is failed(%x)", error);
267 Eina_Bool is_driving_mode = EINA_FALSE;
268 Eina_Bool is_driving_mode_schedule = EINA_FALSE;
270 int ret = vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE, (int *)&is_driving_mode);
271 c_warn_if(ret != 0, "vconf_get_int(VCONFKEY_SETAPPL_DRIVINGMODE_DRIVINGMODE) is failed(%d)", ret);
273 if (is_driving_mode) {
274 ret = vconf_get_bool(VCONFKEY_SETAPPL_DRIVINGMODE_SCHEDULE, (int *)&is_driving_mode_schedule);
275 c_warn_if(ret != 0, "vconf_get_int(VCONFKEY_SETAPPL_DRIVINGMODE_SCHEDULE) is failed(%d)", ret);
278 error = calendar_list_first(list);
279 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_first() is failed(%x)", error);
281 for (i = 0; i < count; i++) {
282 calendar_record_h calendar_alarm = NULL;
284 error = calendar_list_get_current_record_p(list, &calendar_alarm);
285 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_get_current_record_p() is failed(%x)", error);
287 __cal_noti_handler_add_noti_for_reminder(ad, calendar_alarm);
289 calendar_list_next(list);
292 error = calendar_list_destroy(list, true);
293 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
295 error = calendar_filter_destroy(filter);
296 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
298 error = calendar_query_destroy(query);
299 c_warn_if(error != CALENDAR_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
304 int cal_noti_handler_show_for_location_reminder(int record_index, void *data)
308 c_retv_if(!data, -1);
310 struct appdata *ad = data;
312 calendar_record_h record = _calendar_get_record_with_index(record_index);
314 __cal_noti_handler_add_noti(ad, record);