Apply tizen coding rule
[platform/framework/web/download-provider.git] / provider / download-provider-notification.c
1 /*
2  * Copyright (c) 2013 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 #ifdef SUPPORT_NOTIFICATION
18 #include <time.h>
19 #include <sys/time.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22
23 #include "download-provider.h"
24 #include "download-provider-notification.h"
25 #include "download-provider-db-defs.h"
26 #include "download-provider-db.h"
27 #include "download-provider-log.h"
28 #include "download-provider-client.h"
29 #include "download-provider-utils.h"
30
31 #include <bundle.h>
32 #include <bundle_internal.h>
33 #include <notification.h>
34
35 #include "notification_text_domain.h"
36 #include "notification_internal.h"
37 #include "notification_error.h"
38
39 #include <appsvc.h>
40
41 #include <vconf.h>
42 #include <locale.h>
43 #include <libintl.h>
44
45 #include <tzplatform_config.h>
46
47 #define __(s) dgettext(PKG_NAME, s)
48
49 #define DP_DOMAIN PKG_NAME
50 #define DP_LOCALEDIR LOCALE_DIR
51 #define DP_NOTIFICATION_NO_SUBJECT "No Name"
52
53 #ifdef _TIZEN_2_3_UX
54 #define DP_NOTIFICATION_DRM_ICON_PATH IMAGE_DIR"/download_manager_icon_drm.png"
55 #define DP_NOTIFICATION_UNKNOWN_ICON_PATH IMAGE_DIR"/download_manager_icon_unknown.png"
56 #define DP_NOTIFICATION_EXCEL_ICON_PATH IMAGE_DIR"/download_manager_icon_xls.png"
57 #define DP_NOTIFICATION_HTML_ICON_PATH IMAGE_DIR"/download_manager_icon_html.png"
58 #define DP_NOTIFICATION_MUSIC_ICON_PATH IMAGE_DIR"/download_manager_icon_music.png"
59 #define DP_NOTIFICATION_PDF_ICON_PATH IMAGE_DIR"/download_manager_icon_pdf.png"
60 #define DP_NOTIFICATION_PPT_ICON_PATH IMAGE_DIR"/download_manager_icon_ppt.png"
61 #define DP_NOTIFICATION_TEXT_ICON_PATH IMAGE_DIR"/download_manager_icon_text.png"
62 #define DP_NOTIFICATION_WORD_ICON_PATH IMAGE_DIR"/download_manager_icon_word.png"
63 #define DP_NOTIFICATION_VIDEO_ICON_PATH IMAGE_DIR"/download_manager_icon_movie.png"
64 #define DP_NOTIFICATION_IMAGE_ICON_PATH IMAGE_DIR"/download_manager_icon_img.png"
65 #define DP_NOTIFICATION_FALSH_ICON_PATH IMAGE_DIR"/download_manager_icon_swf.png"
66 #define DP_NOTIFICATION_TPK_ICON_PATH IMAGE_DIR"/download_manager_icon_tpk.png"
67 #define DP_NOTIFICATION_VCAL_ICON_PATH IMAGE_DIR"/download_manager_icon_date.png"
68
69 // base path
70 #define QP_PRELOAD_NOTI_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons")
71
72 // each application path
73 #define QP_PRELOAD_COMMON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common")
74 #define DP_NOTIFICATION_COMPLETED_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common/noti_download_complete.png")
75 #define DP_NOTIFICATION_FAILED_ICON_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "com.samsung.quickpanel/shared/res/noti_icons/Common/noti_download_failed.png")
76
77 #define DP_NOTIFICATION_ONGOING_ICON_PATH "reserved://quickpanel/ani/downloading"
78 #define DP_NOTIFICATION_DOWNLOADING_ICON_PATH "reserved://indicator/ani/downloading"
79 #define DP_NOTIFICATION_FAILED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_Processing_download_failed.png"
80 #define DP_NOTIFICATION_COMPLETED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_Processing_download_complete.png"
81 #else
82 #define DP_NOTIFICATION_DRM_ICON_PATH IMAGE_DIR"/U01_icon_drm.png"
83 #define DP_NOTIFICATION_UNKNOWN_ICON_PATH IMAGE_DIR"/U01_icon_unkown.png"
84 #define DP_NOTIFICATION_EXCEL_ICON_PATH IMAGE_DIR"/U01_icon_excel.png"
85 #define DP_NOTIFICATION_HTML_ICON_PATH IMAGE_DIR"/U01_icon_html.png"
86 #define DP_NOTIFICATION_MUSIC_ICON_PATH IMAGE_DIR"/U01_list_icon_mp3.png"
87 #define DP_NOTIFICATION_PDF_ICON_PATH IMAGE_DIR"/U01_icon_pdf.png"
88 #define DP_NOTIFICATION_PPT_ICON_PATH IMAGE_DIR"/U01_icon_ppt.png"
89 #define DP_NOTIFICATION_TEXT_ICON_PATH IMAGE_DIR"/U01_icon_text.png"
90 #define DP_NOTIFICATION_WORD_ICON_PATH IMAGE_DIR"/U01_icon_word.png"
91 #define DP_NOTIFICATION_VIDEO_ICON_PATH IMAGE_DIR"/U01_list_icon_mp4.png"
92 #define DP_NOTIFICATION_IMAGE_ICON_PATH IMAGE_DIR"/U01_list_icon_image.png"
93 #define DP_NOTIFICATION_FALSH_ICON_PATH IMAGE_DIR"/U01_icon_swf.png"
94 #define DP_NOTIFICATION_TPK_ICON_PATH IMAGE_DIR"/U01_icon_tpk.png"
95 #define DP_NOTIFICATION_VCAL_ICON_PATH IMAGE_DIR"/U01_icon_vcs.png"
96
97 #define DP_NOTIFICATION_FAILED_ICON_PATH IMAGE_DIR"/noti_download_failed.png"
98 #define DP_NOTIFICATION_COMPLETED_ICON_PATH IMAGE_DIR"/noti_download_complete.png"
99
100 #define DP_NOTIFICATION_ONGOING_ICON_PATH "reserved://quickpanel/ani/downloading"
101 #define DP_NOTIFICATION_DOWNLOADING_ICON_PATH "reserved://indicator/ani/downloading"
102 #define DP_NOTIFICATION_FAILED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_processing_download_fail.png"
103 #define DP_NOTIFICATION_COMPLETED_INDICATOR_ICON_PATH IMAGE_DIR"/B03_processing_download_complete.png"
104 #endif
105
106 #define DP_MAX_ICONS_TABLE_COUNT 15
107
108 char *file_icons_table[DP_MAX_ICONS_TABLE_COUNT] = {
109         //unknown file type
110         DP_NOTIFICATION_UNKNOWN_ICON_PATH,
111         //image
112         DP_NOTIFICATION_IMAGE_ICON_PATH,
113         //video
114         DP_NOTIFICATION_VIDEO_ICON_PATH,
115         // audio /music
116         DP_NOTIFICATION_MUSIC_ICON_PATH,
117         // PDF
118         DP_NOTIFICATION_PDF_ICON_PATH,
119         // word
120         DP_NOTIFICATION_WORD_ICON_PATH,
121         // ppt
122         DP_NOTIFICATION_PPT_ICON_PATH,
123         // excel
124         DP_NOTIFICATION_EXCEL_ICON_PATH,
125         // html
126         DP_NOTIFICATION_HTML_ICON_PATH,
127         // txt
128         DP_NOTIFICATION_TEXT_ICON_PATH,
129         // DRM
130         DP_NOTIFICATION_DRM_ICON_PATH,
131         DP_NOTIFICATION_DRM_ICON_PATH,
132         DP_NOTIFICATION_FALSH_ICON_PATH,
133         DP_NOTIFICATION_TPK_ICON_PATH,
134         DP_NOTIFICATION_VCAL_ICON_PATH,
135 };
136
137 static const char *__dp_noti_error_str(int err)
138 {
139         switch (err) {
140         case NOTIFICATION_ERROR_INVALID_PARAMETER:
141                 return "NOTIFICATION_ERROR_INVALID_PARAMETER";
142         case NOTIFICATION_ERROR_OUT_OF_MEMORY:
143                 return "NOTIFICATION_ERROR_OUT_OF_MEMORY";
144         case NOTIFICATION_ERROR_FROM_DB:
145                 return "NOTIFICATION_ERROR_FROM_DB";
146         case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
147                 return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
148         case NOTIFICATION_ERROR_FROM_DBUS:
149                 return "NOTIFICATION_ERROR_FROM_DBUS";
150         case NOTIFICATION_ERROR_NOT_EXIST_ID:
151                 return "NOTIFICATION_ERROR_NOT_EXIST_ID";
152         default:
153                 break;
154         }
155         return "Unknown error";
156 }
157
158 char *__dp_noti_get_sender(char *url)
159 {
160         char *temp = NULL;
161         char *found = NULL;
162         char *found1 = NULL;
163         char *sender = NULL;
164         char *credential_sender = NULL;
165
166         if (url == NULL)
167                 return NULL;
168
169         found = strstr(url, "://");
170         if (found != NULL)
171                 temp = found + 3;
172         else
173                 temp = url;
174
175         found = strchr(temp, '/');
176         if (found != NULL) {
177                 int len = 0;
178                 len = found - temp;
179                 sender = calloc(len + 1, sizeof(char));
180                 if (sender == NULL)
181                         return NULL;
182                 snprintf(sender, len + 1, "%s", temp);
183         } else {
184                 sender = dp_strdup(temp);
185                 if (sender == NULL)
186                         return NULL;
187         }
188
189         // For credential URL
190         found = strchr(sender, '@');
191         found1 = strchr(sender, ':');
192         if (found != NULL && found1 != NULL && found1 < found) {
193                 int len = 0;
194                 found = found + 1;
195                 len = strlen(found);
196                 credential_sender = calloc(len + 1, sizeof(char));
197                 if (credential_sender == NULL) {
198                         free(sender);
199                         return NULL;
200                 }
201                 snprintf(credential_sender, len + 1, "%s", found);
202                 free(sender);
203                 return credential_sender;
204         } else {
205                 return sender;
206         }
207 }
208
209 static char *__dp_noti_status(dp_state_type state)
210 {
211         char *message = NULL;
212         switch (state) {
213         case DP_STATE_COMPLETED:
214                 message = "IDS_DM_HEADER_DOWNLOAD_COMPLETE";
215                 break;
216         case DP_STATE_CANCELED:
217         case DP_STATE_FAILED:
218                 message = "IDS_DM_BODY_DOWNLOAD_FAILED_M_STATUS_ABB";
219                 break;
220         default:
221                 break;
222         }
223         return message;
224 }
225
226 void __lang_changed_cb(keynode_t *key, void* data)
227 {
228         char *str = NULL;
229         str = vconf_get_str(VCONFKEY_LANGSET);
230         if (str != NULL) {
231                 setlocale(LC_ALL, str);
232                 bindtextdomain(PKG_NAME, LOCALE_DIR);
233                 textdomain(PKG_NAME);
234         }
235         free(str);
236 }
237
238 void dp_notification_set_locale()
239 {
240         // move to notification.c
241         // locale
242         __lang_changed_cb(NULL, NULL);
243         if (vconf_notify_key_changed(VCONFKEY_LANGSET, __lang_changed_cb, NULL) != 0)
244                 TRACE_ERROR("Fail to set language changed vconf callback");
245 }
246
247 void dp_notification_clear_locale()
248 {
249         // move to notification.c
250         if (vconf_ignore_key_changed(VCONFKEY_LANGSET, __lang_changed_cb) != 0)
251                 TRACE_ERROR("Fail to unset language changed vconf callback");
252 }
253
254 void dp_notification_clear_ongoings()
255 {
256         int err = NOTIFICATION_ERROR_NONE;
257         err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
258         if (err != NOTIFICATION_ERROR_NONE)
259                 TRACE_DEBUG("[FAIL] clear noti [%s]", __dp_noti_error_str(err));
260         return;
261 }
262
263 int dp_notification_ongoing_new(const char *pkgname, const char *subject, unsigned char *raws_buffer, const int raws_length)
264 {
265         int err = NOTIFICATION_ERROR_NONE;
266         notification_h noti_handle = NULL;
267         noti_handle = notification_create(NOTIFICATION_TYPE_ONGOING);
268         if (noti_handle == NULL) {
269                 TRACE_ERROR("failed to create notification handle");
270                 return -1;
271         }
272
273         if (subject != NULL) {
274                 err = notification_set_text(noti_handle,
275                                 NOTIFICATION_TEXT_TYPE_TITLE, subject, NULL,
276                                 NOTIFICATION_VARIABLE_TYPE_NONE);
277         } else {
278                 err = notification_set_text(noti_handle,
279                                 NOTIFICATION_TEXT_TYPE_TITLE, DP_NOTIFICATION_NO_SUBJECT, NULL,
280                                 NOTIFICATION_VARIABLE_TYPE_NONE);
281         }
282         if (err != NOTIFICATION_ERROR_NONE)
283                 TRACE_ERROR("failed to set subject error:%s", __dp_noti_error_str(err));
284
285         err = notification_set_image(noti_handle,
286                         NOTIFICATION_IMAGE_TYPE_ICON,
287                         DP_NOTIFICATION_ONGOING_ICON_PATH);
288         if (err != NOTIFICATION_ERROR_NONE)
289                 TRACE_ERROR("failed to set icon error:%s", __dp_noti_error_str(err));
290
291         if (raws_buffer != NULL && raws_length > 0) {
292                 bundle *b = NULL;
293                 b = bundle_decode_raw((bundle_raw *)raws_buffer, raws_length);
294                 if (b != NULL) {
295                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
296                 } else {
297                         b = bundle_create();
298                         if (b != NULL && pkgname != NULL) {
299                                 if (appsvc_set_pkgname(b, pkgname) != APPSVC_RET_OK)
300                                         TRACE_ERROR("failed to set set pkgname");
301                                 else
302                                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
303                         } else {
304                                 TRACE_ERROR("failed to create bundle");
305                         }
306                 }
307                 if (err != NOTIFICATION_ERROR_NONE)
308                         TRACE_ERROR("failed to set service error:%s", __dp_noti_error_str(err));
309
310                 if (b != NULL)
311                         bundle_free(b);
312         }
313
314         err = notification_set_property(noti_handle,
315                         NOTIFICATION_PROP_DISABLE_TICKERNOTI);
316         if (err != NOTIFICATION_ERROR_NONE) {
317                 TRACE_ERROR("failed to set property error:%s", __dp_noti_error_str(err));
318                 notification_free(noti_handle);
319                 return -1;
320         }
321         err = notification_set_image(noti_handle,
322                         NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
323                         DP_NOTIFICATION_DOWNLOADING_ICON_PATH);
324         if (err != NOTIFICATION_ERROR_NONE) {
325                 TRACE_ERROR("failed to set icon indicator error:%s", __dp_noti_error_str(err));
326                 notification_free(noti_handle);
327                 return -1;
328         }
329         err = notification_set_display_applist(noti_handle,
330                         NOTIFICATION_DISPLAY_APP_ALL);
331         if (err != NOTIFICATION_ERROR_NONE) {
332                 TRACE_ERROR("failed to set display app all error:%s", __dp_noti_error_str(err));
333                 notification_free(noti_handle);
334                 return -1;
335         }
336
337         int priv_id = 0;
338         err = notification_insert(noti_handle, &priv_id);
339         if (err != NOTIFICATION_ERROR_NONE) {
340                 TRACE_ERROR("failed to set priv_id error:%s", __dp_noti_error_str(err));
341                 notification_free(noti_handle);
342                 return -1;
343         }
344
345         //TRACE_DEBUG("m_noti_id [%d]", priv_id);
346         notification_free(noti_handle);
347
348         return priv_id; // store on memory for reuse it
349 }
350
351
352
353 int dp_notification_ongoing_update(const int noti_priv_id, const double received_size, const double file_size, const char *subject)
354 {
355         if (noti_priv_id > 0) {
356                 int err = NOTIFICATION_ERROR_NONE;
357                 if (file_size > 0)
358                         err = notification_update_progress(NULL, noti_priv_id, (received_size / file_size));
359                 else
360                         err = notification_update_size(NULL, noti_priv_id, received_size);
361                 if (err != NOTIFICATION_ERROR_NONE) {
362                         TRACE_ERROR("failed to update error:%s", __dp_noti_error_str(err));
363                         // return 0 because progress is called frequently
364                 }
365                 if (subject != NULL) {
366                         notification_h noti_handle = NULL;
367                         noti_handle = notification_load(NULL, noti_priv_id);
368                         if (noti_handle != NULL) {
369                                 err = notification_set_text(noti_handle,
370                                                 NOTIFICATION_TEXT_TYPE_TITLE, subject, NULL,
371                                                 NOTIFICATION_VARIABLE_TYPE_NONE);
372                                 err = notification_update(noti_handle);
373                                 if (err != NOTIFICATION_ERROR_NONE)
374                                         TRACE_ERROR("failed to update by priv_id:%d", noti_priv_id);
375                                 notification_free(noti_handle);
376                         } else {
377                                 TRACE_ERROR("failed to load handle by priv_id:%d", noti_priv_id);
378                                 return -1;
379                         }
380                 }
381         }
382         return 0;
383 }
384
385
386 int dp_notification_delete_ongoing(const int noti_priv_id)
387 {
388         int err = NOTIFICATION_ERROR_NONE;
389         err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_ONGOING, noti_priv_id);
390         if (err != NOTIFICATION_ERROR_NONE)
391                 TRACE_ERROR("failed to delete notification by priv_id:%d error:%s", noti_priv_id, __dp_noti_error_str(err));
392
393         return 0;
394 }
395
396 int dp_notification_delete(const int noti_priv_id)
397 {
398         int err = NOTIFICATION_ERROR_NONE;
399         err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, noti_priv_id);
400         if (err != NOTIFICATION_ERROR_NONE)
401                 TRACE_ERROR("failed to delete notification by priv_id:%d error:%s", noti_priv_id, __dp_noti_error_str(err));
402
403         return 0;
404 }
405
406
407 int dp_notification_new(void *dbhandle, const int download_id, const int state, int content_type, const char *pkgname)
408 {
409         int errorcode = DP_ERROR_NONE;
410         int err = NOTIFICATION_ERROR_NONE;
411
412         if (state != DP_STATE_COMPLETED &&
413                         state != DP_STATE_CANCELED &&
414                         state != DP_STATE_FAILED) {
415                 TRACE_ERROR("deny by invalid state:%d id:%d", state, download_id);
416                 return -1;
417         }
418
419
420         notification_h noti_handle = NULL;
421         noti_handle = notification_create(NOTIFICATION_TYPE_NOTI);
422         if (noti_handle == NULL) {
423                 TRACE_ERROR("failed to create notification handle");
424                 return -1;
425         }
426
427         err = notification_set_layout(noti_handle, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
428         if (err != NOTIFICATION_ERROR_NONE) {
429                 TRACE_ERROR("Fail to set notification layout [%d]", err);
430                 notification_free(noti_handle);
431                 return -1;
432         }
433
434         err = notification_set_text_domain(noti_handle, DP_DOMAIN, DP_LOCALEDIR);
435         if (err != NOTIFICATION_ERROR_NONE) {
436                 TRACE_ERROR("Fail to set text domain [%d]", err);
437                 notification_free(noti_handle);
438                 return -1;
439         }
440
441         char *string = NULL;
442         unsigned length = 0;
443         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_DESCRIPTION, (unsigned char **)&string, &length, &errorcode) < 0)
444                 TRACE_ERROR("failed to get description id:%d error:%s", download_id, dp_print_errorcode(errorcode));
445
446         if (string != NULL) {
447 #ifdef _TIZEN_2_3_UX
448                 err = notification_set_text(noti_handle,
449                                 NOTIFICATION_TEXT_TYPE_CONTENT, string, NULL,
450                                 NOTIFICATION_VARIABLE_TYPE_NONE);
451 #else
452                 err = notification_set_text(noti_handle,
453                                 NOTIFICATION_TEXT_TYPE_TITLE, string, NULL,
454                                 NOTIFICATION_VARIABLE_TYPE_NONE);
455 #endif
456                 free(string);
457                 if (err != NOTIFICATION_ERROR_NONE)
458                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
459         } else {
460                 string = __dp_noti_status(state);
461 #ifdef _TIZEN_2_3_UX
462                 err = notification_set_text(noti_handle,
463                                 NOTIFICATION_TEXT_TYPE_CONTENT, __(string), string,
464                                 NOTIFICATION_VARIABLE_TYPE_NONE);
465 #else
466                 err = notification_set_text(noti_handle,
467                                 NOTIFICATION_TEXT_TYPE_TITLE, __(string), string,
468                                 NOTIFICATION_VARIABLE_TYPE_NONE);
469 #endif
470                 if (err != NOTIFICATION_ERROR_NONE)
471                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
472         }
473
474         string = NULL;
475         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_SUBJECT, (unsigned char **)&string, &length, &errorcode) < 0)
476                 TRACE_ERROR("failed to get subject id:%d error:%s", download_id, dp_print_errorcode(errorcode));
477         err = NOTIFICATION_ERROR_NONE;
478         if (string == NULL && dp_db_get_property_string(dbhandle, download_id, DP_TABLE_DOWNLOAD, DP_DB_COL_CONTENT_NAME, (unsigned char **)&string, &length, &errorcode) < 0)
479                 TRACE_ERROR("failed to get content_name id:%d error:%s", download_id, dp_print_errorcode(errorcode));
480         if (string == NULL)
481                 string = dp_strdup(DP_NOTIFICATION_NO_SUBJECT);
482         if (string != NULL) {
483 #ifdef _TIZEN_2_3_UX
484                 err = notification_set_text(noti_handle,
485                                 NOTIFICATION_TEXT_TYPE_TITLE, string, NULL,
486                                 NOTIFICATION_VARIABLE_TYPE_NONE);
487 #else
488                 err = notification_set_text(noti_handle,
489                                 NOTIFICATION_TEXT_TYPE_CONTENT, string, NULL,
490                                 NOTIFICATION_VARIABLE_TYPE_NONE);
491 #endif
492                 free(string);
493                 string = NULL;
494                 if (err != NOTIFICATION_ERROR_NONE)
495                         TRACE_ERROR("failed to set state id:%d error:%s", download_id, __dp_noti_error_str(err));
496         }
497         err = notification_set_time(noti_handle, time(NULL));
498         if (err != NOTIFICATION_ERROR_NONE)
499                 TRACE_ERROR("failed to set time id:%d error:%s", download_id, __dp_noti_error_str(err));
500
501         bundle *b = NULL;
502         bundle_raw *raws_buffer = NULL;
503         if (state == DP_STATE_COMPLETED) {
504                 if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_RAW_COMPLETE, &raws_buffer, &length, &errorcode) < 0)
505                         TRACE_ERROR("failed to get bundle raws id:%d", download_id);
506
507                 if (raws_buffer != NULL) {
508                         b = bundle_decode_raw(raws_buffer, length);
509                         bundle_free_encoded_rawdata(&raws_buffer);
510                 }
511                 if (b != NULL) {
512                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
513                 } else {
514                         b = bundle_create();
515                         if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_DOWNLOAD, DP_DB_COL_SAVED_PATH, (unsigned char **)&string, &length, &errorcode) < 0)
516                                 TRACE_ERROR("failed to get saved_path id:%d error:%s", download_id, dp_print_errorcode(errorcode));
517
518                         if (b != NULL && string != NULL) {
519                                 if (appsvc_set_operation(b, APPSVC_OPERATION_VIEW) != APPSVC_RET_OK) {
520                                         TRACE_ERROR("failed to set service operation id:%d", download_id);
521                                 } else {
522                                         if (appsvc_set_uri(b, string) != APPSVC_RET_OK) {
523                                                 TRACE_ERROR("failed to set service uri id:%d", download_id);
524                                         } else {
525                                                 err = notification_set_execute_option(noti_handle,
526                                                                 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
527                                         }
528                                 }
529                         } else {
530                                 TRACE_SECURE_ERROR("failed to create bundle id:%d path:%s", download_id, string);
531                         }
532                         free(string);
533                         string = NULL;
534                 }
535                 if (err != NOTIFICATION_ERROR_NONE)
536                         TRACE_ERROR("failed to set service id:%d error:%s", download_id, __dp_noti_error_str(err));
537
538                 char *file_type_icon = DP_NOTIFICATION_UNKNOWN_ICON_PATH;
539                 if (content_type > 0 && content_type < DP_MAX_ICONS_TABLE_COUNT)
540                         file_type_icon = file_icons_table[content_type];
541
542                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, file_type_icon);
543                 if (err != NOTIFICATION_ERROR_NONE)
544                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
545
546                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
547                                 DP_NOTIFICATION_COMPLETED_INDICATOR_ICON_PATH);
548                 if (err != NOTIFICATION_ERROR_NONE)
549                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
550         } else if (state == DP_STATE_CANCELED || state == DP_STATE_FAILED) {
551
552                 if (dp_db_get_property_string(dbhandle, download_id, DP_TABLE_NOTIFICATION, DP_DB_COL_NOTI_RAW_FAIL, &raws_buffer, &length, &errorcode) < 0)
553                         TRACE_ERROR("failed to get bundle raws id:%d", download_id);
554
555                 if (raws_buffer != NULL) {
556                         b = bundle_decode_raw(raws_buffer, length);
557                         bundle_free_encoded_rawdata(&raws_buffer);
558                 }
559                 if (b != NULL) {
560                         err = notification_set_execute_option(noti_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
561                 } else {
562                         b = bundle_create();
563                         if (b != NULL && pkgname != NULL) {
564                                 if (appsvc_set_pkgname(b, pkgname) != APPSVC_RET_OK) {
565                                         TRACE_ERROR("failed to set set pkgname id:%d", download_id);
566                                 } else {
567                                         err = notification_set_execute_option(noti_handle,
568                                                         NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "View", NULL, b);
569                                 }
570                         } else {
571                                 TRACE_ERROR("failed to create bundle id:%d", download_id);
572                         }
573                 }
574                 if (err != NOTIFICATION_ERROR_NONE)
575                         TRACE_ERROR("failed to set service id:%d error:%s", download_id, __dp_noti_error_str(err));
576
577                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
578                                 DP_NOTIFICATION_FAILED_ICON_PATH);
579                 if (err != NOTIFICATION_ERROR_NONE)
580                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
581
582                 err = notification_set_image(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
583                                 DP_NOTIFICATION_FAILED_INDICATOR_ICON_PATH);
584                 if (err != NOTIFICATION_ERROR_NONE)
585                         TRACE_ERROR("failed to set icon id:%d error:%s", download_id, __dp_noti_error_str(err));
586         }
587
588         if (b != NULL)
589                 bundle_free(b);
590
591         err = notification_set_property(noti_handle,
592                         NOTIFICATION_PROP_DISABLE_TICKERNOTI);
593         if (err != NOTIFICATION_ERROR_NONE)
594                 TRACE_ERROR("failed to set property id:%d error:%s", download_id, __dp_noti_error_str(err));
595
596         err = notification_set_display_applist(noti_handle,
597                         NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
598         if (err != NOTIFICATION_ERROR_NONE)
599                 TRACE_ERROR("failed to set display app all id:%d error:%s", download_id, __dp_noti_error_str(err));
600
601         int priv_id = 0;
602         err = notification_insert(noti_handle, &priv_id);
603         if (err != NOTIFICATION_ERROR_NONE)
604                 TRACE_ERROR("failed to set priv_id id:%d error:%s", download_id, __dp_noti_error_str(err));
605
606         //TRACE_DEBUG("m_noti_id [%d]", priv_id);
607         notification_free(noti_handle);
608
609         return priv_id;
610 }
611 #else
612 void dp_notification_clear_ongoings()
613 {
614         return;
615 }
616 #endif