2 #include <app_ui_notification.h>
3 #include <app_service.h>
11 #include "download-provider-notification.h"
12 #include "download-provider-utils.h"
13 #include "download-provider-log.h"
17 #define S_(s) dgettext("sys_string", s)
19 #define DP_NOTIFICATION_ICON_PATH IMAGE_DIR"/Q02_Notification_Download_failed.png"
21 void print_app_error_message(int ret)
25 TRACE_DEBUG_MSG("APP_ERROR_NONE");
27 case APP_ERROR_INVALID_PARAMETER:
28 TRACE_DEBUG_MSG("APP_ERROR_INVALID_PARAMETER");
30 case APP_ERROR_OUT_OF_MEMORY:
31 TRACE_DEBUG_MSG("APP_ERROR_OUT_OF_MEMORY");
33 case APP_ERROR_INVALID_CONTEXT:
34 TRACE_DEBUG_MSG("APP_ERROR_INVALID_CONTEXT");
36 case APP_ERROR_NO_SUCH_FILE:
37 TRACE_DEBUG_MSG("APP_ERROR_NO_SUCH_FILE");
39 case APP_ERROR_ALREADY_RUNNING:
40 TRACE_DEBUG_MSG("APP_ERROR_ALREADY_RUNNING");
43 TRACE_DEBUG_MSG("Unknown error");
48 void print_notification_error_message(int ret)
51 case UI_NOTIFICATION_ERROR_NONE:
52 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_NONE");
54 case UI_NOTIFICATION_ERROR_INVALID_PARAMETER:
55 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_INVALID_PARAMETER");
57 case UI_NOTIFICATION_ERROR_OUT_OF_MEMORY:
58 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_OUT_OF_MEMORY");
60 case UI_NOTIFICATION_ERROR_DB_FAILED:
61 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_DB_FAILED");
63 case UI_NOTIFICATION_ERROR_NO_SUCH_FILE:
64 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_NO_SUCH_FILE");
66 case UI_NOTIFICATION_ERROR_INVALID_STATE:
67 TRACE_DEBUG_MSG("UI_NOTIFICATION_ERROR_INVALID_STATE");
70 TRACE_DEBUG_MSG("Unknown error");
75 char *__get_string_status(int state)
79 case DOWNLOAD_STATE_FINISHED:
80 //message = S_("IDS_COM_POP_SUCCESS");
81 message = "Completed";
83 case DOWNLOAD_STATE_STOPPED:
84 //message = S_("IDS_COM_POP_CANCELLED");
87 case DOWNLOAD_STATE_FAILED:
88 //message = S_("IDS_COM_POP_FAILED");
97 bool download_provider_appfw_notification_cb(ui_notification_h notification,
102 download_clientinfo *clientinfo = (download_clientinfo *) user_data;
103 if (!clientinfo->downloadinfo)
106 bool checkInfo = false;
108 char *content = NULL;
109 ui_notification_get_title(notification, &title);
110 ui_notification_get_content(notification, &content);
112 TRACE_DEBUG_MSG("title [%s]", title);
113 TRACE_DEBUG_MSG("content [%s]", content);
116 if (title && clientinfo->downloadinfo->content_name) {
117 int title_length = strlen(title);
118 int content_name_length =
119 strlen(clientinfo->downloadinfo->content_name);
120 if (title_length == content_name_length)
122 (title, clientinfo->downloadinfo->content_name,
126 // Only when matched title.
127 if (checkInfo && content) {
128 char *failed_content =
129 __get_string_status(DOWNLOAD_STATE_FAILED);
130 if (failed_content) {
131 int content_length = strlen(content);
132 int content_name_length = strlen(failed_content);
133 if (content_length == content_name_length)
135 (content, failed_content,
136 content_length) == 0)
138 free(failed_content);
141 char *stopped_content =
142 __get_string_status(DOWNLOAD_STATE_STOPPED);
143 if (stopped_content) {
144 int content_length = strlen(content);
145 int content_name_length =
146 strlen(stopped_content);
147 if (content_length == content_name_length)
149 (content, stopped_content,
150 content_length) == 0)
152 free(stopped_content);
162 if (checkInfo) { // compare info with noti info.
163 TRACE_DEBUG_MSG("ui_notification_cancel");
164 ui_notification_cancel(notification);
165 return false; // do not search noti item anymore.
170 int destroy_appfw_service(download_clientinfo *clientinfo)
175 if (clientinfo->service_handle) {
176 service_destroy(clientinfo->service_handle);
178 clientinfo->service_handle = NULL;
182 int create_appfw_service(download_clientinfo *clientinfo, bool ongoing)
188 if (!clientinfo->service_handle) {
189 if (service_create(&clientinfo->service_handle) < 0) {
190 TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
193 if (clientinfo->requestinfo
194 && clientinfo->requestinfo->client_packagename.str) {
195 if (service_set_package(clientinfo->service_handle,
196 clientinfo->requestinfo->
197 client_packagename.str) < 0)
198 TRACE_DEBUG_MSG("failed service_set_package (%s)",
203 if (clientinfo->service_handle) {
204 destroy_appfw_service(clientinfo);
206 if (service_create(&clientinfo->service_handle) < 0) {
207 TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
214 int destroy_appfw_notification(download_clientinfo *clientinfo)
219 destroy_appfw_service(clientinfo);
220 if (clientinfo->ui_notification_handle) {
222 ui_notification_is_ongoing(clientinfo->ui_notification_handle,
225 if (ui_notification_cancel
226 (clientinfo->ui_notification_handle) < 0)
227 TRACE_DEBUG_MSG("Fail ui_notification_cancel");
229 ui_notification_destroy(clientinfo->ui_notification_handle);
231 clientinfo->ui_notification_handle = NULL;
235 int create_appfw_notification(download_clientinfo *clientinfo, bool ongoing)
242 if (ui_notification_create(ongoing, &clientinfo->ui_notification_handle)
244 TRACE_DEBUG_MSG("Fail to create notification handle");
248 if (clientinfo->downloadinfo) {
249 TRACE_DEBUG_MSG("###content_name[%s]", clientinfo->downloadinfo->content_name);
250 char *title = clientinfo->downloadinfo->content_name;
252 //title = S_("IDS_COM_BODY_NO_NAME");
254 if (ui_notification_set_title(
255 clientinfo->ui_notification_handle, title) < 0) {
257 ("failed ui_notification_set_title (%s)",
259 destroy_appfw_notification(clientinfo);
264 if (ui_notification_set_icon
265 (clientinfo->ui_notification_handle,
266 DP_NOTIFICATION_ICON_PATH) < 0) {
267 TRACE_DEBUG_MSG("Fail ui_notification_set_icon (%s)",
269 destroy_appfw_notification(clientinfo);
274 create_appfw_service(clientinfo, ongoing);
276 // view the special viewer by contents
277 if (clientinfo->downloadinginfo
278 && clientinfo->downloadinginfo->saved_path
279 && clientinfo->state == DOWNLOAD_STATE_FINISHED) {
280 if (service_set_operation
281 (clientinfo->service_handle,
282 SERVICE_OPERATION_VIEW) < 0) {
284 ("Fail service_set_operation");
285 destroy_appfw_service(clientinfo);
287 if (service_set_uri(clientinfo->service_handle,
288 clientinfo->downloadinginfo->saved_path)
290 TRACE_DEBUG_MSG("Fail service_set_uri");
291 destroy_appfw_service(clientinfo);
294 if (service_set_package(clientinfo->service_handle,
295 clientinfo->requestinfo->
296 client_packagename.str) < 0)
297 TRACE_DEBUG_MSG("failed service_set_package (%s)",
301 if (ui_notification_set_service
302 (clientinfo->ui_notification_handle,
303 clientinfo->service_handle) < 0) {
304 TRACE_DEBUG_MSG("Fail ui_notification_set_service");
305 destroy_appfw_service(clientinfo);
309 ui_notification_post(clientinfo->ui_notification_handle)) !=
310 UI_NOTIFICATION_ERROR_NONE) {
311 TRACE_DEBUG_MSG("Fail to post [%d]", ret);
312 print_notification_error_message(ret);
313 destroy_appfw_notification(clientinfo);
320 int set_downloadinginfo_appfw_notification(download_clientinfo *clientinfo)
322 if (!clientinfo || !clientinfo->downloadinginfo)
325 if (!clientinfo->ui_notification_handle) {
326 create_appfw_notification(clientinfo, true);
329 if (!clientinfo->ui_notification_handle)
332 if (clientinfo->downloadinfo && clientinfo->downloadinfo->file_size > 0) {
334 (double)clientinfo->downloadinginfo->received_size /
335 (double)clientinfo->downloadinfo->file_size;
336 if (ui_notification_update_progress
337 (clientinfo->ui_notification_handle,
338 UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE, progress) < 0) {
339 TRACE_DEBUG_MSG("Fail to update progress");
340 destroy_appfw_notification(clientinfo);
344 if (ui_notification_update_progress
345 (clientinfo->ui_notification_handle,
346 UI_NOTIFICATION_PROGRESS_TYPE_SIZE,
347 (double)(clientinfo->downloadinginfo->received_size)) <
349 TRACE_DEBUG_MSG("Fail to update size");
350 destroy_appfw_notification(clientinfo);
358 int set_downloadedinfo_appfw_notification(download_clientinfo *clientinfo)
363 destroy_appfw_notification(clientinfo);
365 if (!clientinfo->ui_notification_handle)
366 create_appfw_notification(clientinfo, false);
368 // fill downloaded info to post to notification bar.
369 char *message = __get_string_status(clientinfo->state);
370 TRACE_DEBUG_MSG("message : [%s]", message);
372 if (ui_notification_set_content
373 (clientinfo->ui_notification_handle, message) < 0)
374 TRACE_DEBUG_MSG("Fail to set content");
377 time_t tt = time(NULL);
378 struct tm *localTime = localtime(&tt);
380 if (ui_notification_set_time
381 (clientinfo->ui_notification_handle, localTime) < 0)
382 TRACE_DEBUG_MSG("Fail to set time");
384 if (ui_notification_update(clientinfo->ui_notification_handle) < 0)
385 TRACE_DEBUG_MSG("Fail to ui_notification_update");
387 destroy_appfw_notification(clientinfo);
391 void clear_downloadinginfo_appfw_notification()
393 ui_notification_cancel_all_by_type(true);