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_INSTALLING:
80 message = S_("IDS_COM_POP_INSTALLING_ING");
82 case DOWNLOAD_STATE_FINISHED:
83 message = strdup("Completed");
85 case DOWNLOAD_STATE_STOPPED:
86 message = S_("IDS_COM_POP_CANCELLED");
88 case DOWNLOAD_STATE_FAILED:
89 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)
187 if (!clientinfo->service_handle)
188 destroy_appfw_service(clientinfo);
189 if (service_create(&clientinfo->service_handle) < 0) {
190 TRACE_DEBUG_MSG("failed service_create (%s)", strerror(errno));
194 if (clientinfo->requestinfo
195 && clientinfo->requestinfo->client_packagename.str) {
196 if (service_set_package(clientinfo->service_handle,
197 clientinfo->requestinfo->
198 client_packagename.str) < 0)
199 TRACE_DEBUG_MSG("failed service_set_package (%s)",
205 int destroy_appfw_notification(download_clientinfo *clientinfo)
210 destroy_appfw_service(clientinfo);
211 if (clientinfo->ui_notification_handle) {
213 ui_notification_is_ongoing(clientinfo->ui_notification_handle,
216 if (ui_notification_cancel
217 (clientinfo->ui_notification_handle) < 0)
218 TRACE_DEBUG_MSG("Fail ui_notification_cancel");
220 ui_notification_destroy(clientinfo->ui_notification_handle);
222 clientinfo->ui_notification_handle = NULL;
226 int create_appfw_notification(download_clientinfo *clientinfo, bool ongoing)
233 if (ui_notification_create(ongoing, &clientinfo->ui_notification_handle)
235 TRACE_DEBUG_MSG("Fail to create notification handle");
239 if (clientinfo->downloadinfo) {
240 if (clientinfo->downloadinfo->content_name) {
241 if (ui_notification_set_title
242 (clientinfo->ui_notification_handle,
243 clientinfo->downloadinfo->content_name) < 0) {
245 ("failed ui_notification_set_title (%s)",
247 destroy_appfw_notification(clientinfo);
253 if (ui_notification_set_icon
254 (clientinfo->ui_notification_handle,
255 DP_NOTIFICATION_ICON_PATH) < 0) {
256 TRACE_DEBUG_MSG("Fail ui_notification_set_icon (%s)",
258 destroy_appfw_notification(clientinfo);
262 create_appfw_service(clientinfo);
264 if (clientinfo->service_handle) {
266 // view the special viewer by contents
267 if (clientinfo->service_handle
268 && clientinfo->downloadinginfo
269 && clientinfo->downloadinginfo->saved_path
270 && clientinfo->state == DOWNLOAD_STATE_FINISHED) {
271 if (service_set_operation
272 (clientinfo->service_handle,
273 SERVICE_OPERATION_VIEW) < 0) {
275 ("Fail service_set_operation");
276 destroy_appfw_service(clientinfo);
278 if (service_set_uri(clientinfo->service_handle,
279 clientinfo->downloadinginfo->saved_path)
281 TRACE_DEBUG_MSG("Fail service_set_uri");
282 destroy_appfw_service(clientinfo);
286 if (ui_notification_set_service
287 (clientinfo->ui_notification_handle,
288 clientinfo->service_handle) < 0) {
289 TRACE_DEBUG_MSG("Fail ui_notification_set_service");
290 destroy_appfw_service(clientinfo);
295 ui_notification_post(clientinfo->ui_notification_handle)) !=
296 UI_NOTIFICATION_ERROR_NONE) {
297 TRACE_DEBUG_MSG("Fail to post [%d]", ret);
298 print_notification_error_message(ret);
299 destroy_appfw_notification(clientinfo);
306 int set_downloadinginfo_appfw_notification(download_clientinfo *clientinfo)
308 if (!clientinfo || !clientinfo->downloadinginfo)
311 if (!clientinfo->ui_notification_handle) {
312 create_appfw_notification(clientinfo, true);
315 if (!clientinfo->ui_notification_handle)
318 if (clientinfo->downloadinfo && clientinfo->downloadinfo->file_size > 0) {
320 (double)clientinfo->downloadinginfo->received_size /
321 (double)clientinfo->downloadinfo->file_size;
322 if (ui_notification_update_progress
323 (clientinfo->ui_notification_handle,
324 UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE, progress) < 0) {
325 TRACE_DEBUG_MSG("Fail to update progress");
326 destroy_appfw_notification(clientinfo);
330 if (ui_notification_update_progress
331 (clientinfo->ui_notification_handle,
332 UI_NOTIFICATION_PROGRESS_TYPE_SIZE,
333 (double)(clientinfo->downloadinginfo->received_size)) <
335 TRACE_DEBUG_MSG("Fail to update size");
336 destroy_appfw_notification(clientinfo);
344 int set_downloadedinfo_appfw_notification(download_clientinfo *clientinfo)
349 destroy_appfw_notification(clientinfo);
351 if (!clientinfo->ui_notification_handle)
352 create_appfw_notification(clientinfo, false);
354 // fill downloaded info to post to notification bar.
355 char *message = __get_string_status(clientinfo->state);
356 TRACE_DEBUG_MSG("message : [%s]", message);
358 if (ui_notification_set_content
359 (clientinfo->ui_notification_handle, message) < 0)
360 TRACE_DEBUG_MSG("Fail to set content");
363 time_t tt = time(NULL);
364 struct tm *localTime = localtime(&tt);
366 if (ui_notification_set_time
367 (clientinfo->ui_notification_handle, localTime) < 0)
368 TRACE_DEBUG_MSG("Fail to set time");
370 if (ui_notification_update(clientinfo->ui_notification_handle) < 0)
371 TRACE_DEBUG_MSG("Fail to ui_notification_update");
373 destroy_appfw_notification(clientinfo);