2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "notification.h"
25 #include "download-provider-notification.h"
26 #include "download-provider-request.h"
27 #include "download-provider-db.h"
28 #include "download-provider-log.h"
31 #define S_(s) dgettext("sys_string", s)
33 #define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_Download_failed.png"
34 /* This should be same value of SERVICE_OPERATION_DOWNLOAD_NOTIFICATION from download.h */
35 #define DP_DOWNLOAD_NOTI_OPERATION "http://tizen.org/appcontrol/operation/download_notification"
37 static void __print_app_error_message(int ret)
41 TRACE_INFO("APPSVC_RET_OK");
43 case APPSVC_RET_ELAUNCH:
44 TRACE_ERROR("APPSVC_RET_ELAUNCH");
46 case APPSVC_RET_ENOMATCH:
47 TRACE_ERROR("APPSVC_RET_ENOMATCH");
49 case APPSVC_RET_EINVAL:
50 TRACE_ERROR("APPSVC_RET_EINVAL");
52 case APPSVC_RET_ERROR:
53 TRACE_ERROR("APPSVC_RET_ERROR");
58 static void __print_notification_error_message(int ret)
61 case NOTIFICATION_ERROR_INVALID_DATA:
62 TRACE_ERROR("NOTIFICATION_ERROR_INVALID_DATA");
64 case NOTIFICATION_ERROR_NO_MEMORY:
65 TRACE_ERROR("NOTIFICATION_ERROR_NO_MEMORY");
67 case NOTIFICATION_ERROR_FROM_DB:
68 TRACE_ERROR("NOTIFICATION_ERROR_FROM_DB");
70 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
71 TRACE_ERROR("NOTIFICATION_ERROR_ALREADY_EXIST_ID");
73 case NOTIFICATION_ERROR_FROM_DBUS:
74 TRACE_ERROR("NOTIFICATION_ERROR_FROM_DBUS");
76 case NOTIFICATION_ERROR_NOT_EXIST_ID:
77 TRACE_ERROR("NOTIFICATION_ERROR_NOT_EXIST_ID");
80 TRACE_ERROR("Unknown error");
85 static char *__get_string_status(dp_state_type state)
89 case DP_STATE_COMPLETED:
90 //message = S_("IDS_COM_POP_SUCCESS");
91 message = "Completed";
93 case DP_STATE_CANCELED:
94 //message = S_("IDS_COM_POP_CANCELLED");
98 //message = S_("IDS_COM_POP_FAILED");
107 int dp_set_downloadinginfo_notification(int id, char *packagename)
109 notification_h noti_handle = NULL;
110 notification_error_e err = NOTIFICATION_ERROR_NONE;
114 #ifdef NOTI_NEW_VERSION_API
115 noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
117 noti_handle = notification_new(NOTIFICATION_TYPE_ONGOING,
118 NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
122 TRACE_ERROR("[FAIL] create notification handle");
127 dp_db_get_text_column
128 (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
130 if (content_name == NULL)
131 content_name = strdup("No Name");
133 err = notification_set_text(noti_handle,
134 NOTIFICATION_TEXT_TYPE_TITLE, content_name, NULL,
135 NOTIFICATION_VARIABLE_TYPE_NONE);
139 if (err != NOTIFICATION_ERROR_NONE) {
140 TRACE_ERROR("[FAIL] set title [%d]", err);
141 notification_free(noti_handle);
145 err = notification_set_image(noti_handle,
146 NOTIFICATION_IMAGE_TYPE_ICON, DP_NOTIFICATION_ICON_PATH);
147 if (err != NOTIFICATION_ERROR_NONE) {
148 TRACE_ERROR("[FAIL] set icon [%d]", err);
149 notification_free(noti_handle);
155 TRACE_ERROR("[FAIL] create bundle");
156 notification_free(noti_handle);
161 appsvc_set_pkgname(b, packagename) != APPSVC_RET_OK) {
162 TRACE_ERROR("[FAIL] set pkg name");
164 notification_free(noti_handle);
168 if (appsvc_set_operation(b, DP_DOWNLOAD_NOTI_OPERATION) !=
170 TRACE_ERROR("[FAIL] set noti operation");
172 notification_free(noti_handle);
177 dp_db_get_text_column(id, DP_DB_TABLE_NOTIFICATION,
178 DP_DB_COL_EXTRA_KEY);
180 dp_db_get_text_column(id, DP_DB_TABLE_NOTIFICATION,
181 DP_DB_COL_EXTRA_VALUE);
183 if (extra_key && extra_value) {
184 if (appsvc_add_data(b, extra_key, extra_value) != APPSVC_RET_OK) {
185 TRACE_ERROR("[FAIL] set add data");
189 notification_free(noti_handle);
198 err = notification_set_execute_option(noti_handle,
199 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
201 if (err != NOTIFICATION_ERROR_NONE) {
202 TRACE_ERROR("[FAIL] set execute option [%d]", err);
204 notification_free(noti_handle);
209 err = notification_set_property(noti_handle,
210 NOTIFICATION_PROP_DISABLE_TICKERNOTI);
211 if (err != NOTIFICATION_ERROR_NONE) {
212 TRACE_ERROR("[FAIL] set property [%d]", err);
213 notification_free(noti_handle);
217 err = notification_insert(noti_handle, &privId);
218 if (err != NOTIFICATION_ERROR_NONE) {
219 TRACE_ERROR("[FAIL] set insert [%d]", err);
220 notification_free(noti_handle);
224 TRACE_INFO("m_noti_id [%d]", privId);
225 notification_free(noti_handle);
229 int dp_set_downloadedinfo_notification(int priv_id, int id, char *packagename, dp_state_type state)
231 notification_h noti_handle = NULL;
232 notification_error_e err = NOTIFICATION_ERROR_NONE;
237 err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_ONGOING,
239 if (err != NOTIFICATION_ERROR_NONE) {
240 TRACE_ERROR("[FAIL] delete notification handle, err", err);
244 #ifdef NOTI_NEW_VERSION_API
245 noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
247 noti_handle = notification_new(NOTIFICATION_TYPE_NOTI,
248 NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
252 TRACE_ERROR("[FAIL] create notification handle");
257 dp_db_get_text_column
258 (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_CONTENT_NAME);
260 if (content_name == NULL)
261 content_name = strdup("No Name");
263 err = notification_set_text(noti_handle,
264 NOTIFICATION_TEXT_TYPE_TITLE, content_name,
265 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
269 if (err != NOTIFICATION_ERROR_NONE) {
270 TRACE_ERROR("[FAIL] set title [%d]", err);
271 notification_free(noti_handle);
275 err = notification_set_text(noti_handle,
276 NOTIFICATION_TEXT_TYPE_CONTENT,
277 __get_string_status(state), NULL,
278 NOTIFICATION_VARIABLE_TYPE_NONE);
279 if (err != NOTIFICATION_ERROR_NONE) {
280 TRACE_ERROR("[FAIL] set text [%d]", err);
281 notification_free(noti_handle);
284 time_t tt = time(NULL);
286 err = notification_set_time(noti_handle, tt);
287 if (err != NOTIFICATION_ERROR_NONE) {
288 TRACE_ERROR("[FAIL] set time [%d]", err);
289 notification_free(noti_handle);
295 TRACE_ERROR("[FAIL] create bundle");
296 notification_free(noti_handle);
300 if (state == DP_STATE_COMPLETED) {
301 if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
302 TRACE_ERROR("[FAIL] appsvc set operation");
304 notification_free(noti_handle);
309 dp_db_get_text_column
310 (id, DP_DB_TABLE_DOWNLOAD_INFO, DP_DB_COL_SAVED_PATH);
311 if (savedpath && appsvc_set_uri(b, savedpath) !=
313 TRACE_ERROR("[FAIL] appsvc set uri");
316 notification_free(noti_handle);
321 err = notification_set_execute_option(noti_handle,
322 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
323 } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
324 if (appsvc_set_operation(b, DP_DOWNLOAD_NOTI_OPERATION) !=
326 TRACE_ERROR("[FAIL] set noti operation [%d]", err);
328 notification_free(noti_handle);
333 dp_db_get_text_column(id, DP_DB_TABLE_NOTIFICATION,
334 DP_DB_COL_EXTRA_KEY);
336 dp_db_get_text_column(id, DP_DB_TABLE_NOTIFICATION,
337 DP_DB_COL_EXTRA_VALUE);
338 if (extra_key && extra_value) {
339 if (appsvc_add_data(b, extra_key, extra_value) !=
341 TRACE_ERROR("[FAIL] set add data");
345 notification_free(noti_handle);
355 appsvc_set_pkgname(b, packagename) !=
357 TRACE_ERROR("[FAIL] set pkg name");
359 notification_free(noti_handle);
362 err = notification_set_execute_option(noti_handle,
363 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
365 TRACE_ERROR("[CRITICAL] invalid state");
367 notification_free(noti_handle);
371 if (err != NOTIFICATION_ERROR_NONE) {
372 TRACE_ERROR("[FAIL] set time [%d]", err);
373 notification_free(noti_handle);
380 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
381 DP_NOTIFICATION_ICON_PATH);
382 if (err != NOTIFICATION_ERROR_NONE) {
383 TRACE_ERROR("[FAIL] set icon [%d]", err);
384 notification_free(noti_handle);
388 err = notification_set_property(noti_handle,
389 NOTIFICATION_PROP_DISABLE_TICKERNOTI);
390 if (err != NOTIFICATION_ERROR_NONE) {
391 TRACE_ERROR("[FAIL] set property [%d]", err);
392 notification_free(noti_handle);
396 err = notification_insert(noti_handle, &privId);
397 if (err != NOTIFICATION_ERROR_NONE) {
398 TRACE_ERROR("[FAIL] set insert [%d]", err);
399 notification_free(noti_handle);
403 TRACE_INFO("m_noti_id [%d]", privId);
404 notification_free(noti_handle);
408 void dp_update_downloadinginfo_notification(int priv_id, double received_size, double file_size)
410 notification_error_e err = NOTIFICATION_ERROR_NONE;
412 TRACE_ERROR("[FAIL] Invalid priv_id[%d]", priv_id);
418 progress = received_size / file_size;
419 err = notification_update_progress(NULL, priv_id, progress);
420 if (err != NOTIFICATION_ERROR_NONE)
421 TRACE_ERROR("[FAIL] update noti progress[%d]", err);
423 err = notification_update_size(NULL, priv_id, received_size);
424 if (err != NOTIFICATION_ERROR_NONE)
425 TRACE_ERROR("[FAIL] update noti progress[%d]", err);
429 void dp_clear_downloadinginfo_notification()
431 notification_error_e err = NOTIFICATION_ERROR_NONE;
432 err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
433 if (err != NOTIFICATION_ERROR_NONE) {
434 TRACE_ERROR("[FAIL] clear noti [%d]", err);