4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <ui-gadget.h>
28 #include <notification.h>
30 #include <vconf-keys.h>
32 #include <page_preview.h>
33 #include <paper_size.h>
34 #include <previewgen.h>
37 #include "pts_common.h"
38 #include "pts_main_view.h"
39 #include "pts_setting_view.h"
40 #include "preview_content.h"
41 #include "preview_util.h"
44 #define MOBILEPRINT_PACKAGENAME "org.tizen.mobileprint"
45 #define ICON_DIR "/usr/apps/org.tizen.mobileprint/res/images"
46 #define ICON_SETTING "/usr/apps/org.tizen.mobileprint/res/images/pt_printer_setting.png"
47 #define MOBILEPRINT_DEFAULTIMG "/usr/share/icons/default/small/org.tizen.mobileprint.png"
48 #define MOBILEPRINT_TMP_STR "_mobileprint.pdf"
50 char *g_current_preview_path = NULL;
51 int g_pages_count = 0;
53 void _wifi_qs_monitoring_cb(keynode_t *key, void *data);
55 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info);
56 static Eina_Bool __pts_main_view_start_print(void *data);
58 static void __pts_main_view_check_usb_printer_online(void *userdata);
59 static void __pts_main_view_check_usb_printer_offline(void *userdata);
60 static void __pts_main_view_check_printer_online(void *userdata);
61 static void __pts_main_view_check_printer_offline(void *userdata);
62 static void __pts_main_view_remove_job(void *userdata, int job_id);
63 static void __pts_main_view_job_error(void *userdata, int job_id);
64 static void __pts_main_view_last_job_error(void *user_data);
65 static Eina_Bool __pts_hide_main_view(void *data);
66 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling);
68 static int __pts_get_real_total_pages(int original_total_pages, int n_up_number, int copies)
70 return (int)ceil((double)original_total_pages / (double)n_up_number) * copies;
73 static pts_job_spooling_t *__pts_get_job_spooling(pts_appdata_t *ad, int job_id)
76 PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
77 PTS_RETV_IF(job_id <= 0, NULL, "job_id is invalid(%d)", job_id);
79 Eina_List *job_spooling_list = NULL;
80 pts_job_spooling_t *job_spooling = NULL;
82 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
83 if (job_spooling->job_id == job_id) {
84 PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
89 PTS_RETV_IF(job_spooling == NULL, NULL, "job_spooling is NULL");
90 PTS_RETV_IF(job_spooling->job_id <= 0, NULL, "job_spooling->job_id is invalid(%d)", job_spooling->job_id);
95 static pts_job_spooling_t *__pts_get_last_job_spooling(pts_appdata_t *ad)
98 PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
100 Eina_List *job_spooling_list = NULL;
101 pts_job_spooling_t *job_spooling = NULL;
103 job_spooling_list = eina_list_last(ad->noti_info.job_spooling_list);
104 PTS_RETV_IF(job_spooling_list == NULL, NULL, "No found job_spooling_list for last job");
106 job_spooling = (pts_job_spooling_t *)eina_list_data_get(job_spooling_list);
107 PTS_RETV_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
108 , NULL, "No found job_spooling for last job");
114 int __pts_update_popup_progress(pts_appdata_t *ad, pt_progress_info_t *progress_info, pts_job_spooling_t *job_spooling)
117 PTS_RETV_IF(ad == NULL || ad->progress_info.progressbar == NULL || progress_info == NULL || job_spooling == NULL
118 , 1, "Invalid parameter for __pts_update_popup_progress");
120 PTS_DEBUG("progress popup [%d]\n", progress_info->progress);
121 double rate = progress_info->progress * 0.01;
122 char progress_value[8] = {0,};
123 char page_value[8] = {0,};
124 char aligned_label[128] = {0,};
125 int real_total_pages = -1;
127 if (EINA_TRUE == elm_progressbar_pulse_get(ad->progress_info.progressbar)) {
128 PTS_DEBUG("Stop pulsing mode\n");
129 elm_progressbar_pulse_set(ad->progress_info.progressbar, EINA_FALSE);
130 elm_object_style_set(ad->progress_info.progressbar, "list_progress");
131 elm_progressbar_value_set(ad->progress_info.progressbar, 0.00);
134 elm_progressbar_value_set(ad->progress_info.progressbar, rate);
137 snprintf(aligned_label, 128, "<align=center>%s</align>",
138 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
139 elm_object_text_set(ad->progress_info.progress_label, aligned_label);
142 snprintf(progress_value, 8, "%d%%", progress_info->progress);
143 elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext1", progress_value);
144 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
145 real_total_pages = 1;
147 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
148 job_spooling->n_up, job_spooling->copies);
150 if (job_spooling->page_printed <= real_total_pages) {
151 PTS_DEBUG("real_total_pages:%d, page_printed:%d\n", real_total_pages, job_spooling->page_printed);
152 snprintf(page_value, 8, "%d/%d", job_spooling->page_printed, real_total_pages);
153 elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext2", page_value);
156 if (rate >= 1.00 && job_spooling->page_printed == real_total_pages) {
157 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
158 PTS_IF_DEL_OBJ(ad->progress_info.popup);
159 PTS_IF_DEL_OBJ(ad->main_info.root_win);
166 int __pts_update_notification(pts_appdata_t *ad,
167 pt_progress_info_t *progress_info,
168 pts_job_spooling_t *job_spooling)
171 PTS_RETV_IF(ad == NULL || progress_info == NULL || job_spooling == NULL
172 , -1 ,"Invalid parameters for update_notification");
174 double rate = progress_info->progress * 0.01;
175 PTS_RETV_IF(job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE || job_spooling->noti_handle == NULL
176 , -1 , "Invalid noti parameters for update_notification");
178 // Remove notification after all page is printed
179 if (progress_info->page_printed > job_spooling->page_printed) {
180 if (job_spooling->noti_id != NOTIFICATION_PRIV_ID_NONE) {
182 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
183 PTS_DEBUG("Notification is deleted");
184 job_spooling->noti_id = NOTIFICATION_PRIV_ID_NONE;
185 ret = notification_free(job_spooling->noti_handle);
186 if (ret != NOTIFICATION_ERROR_NONE) {
187 PTS_DEBUG("Failed to free notification handle [%d]", ret);
189 job_spooling->noti_handle = NULL;
190 job_spooling->page_printed = progress_info->page_printed; // XXX
194 if (job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE && job_spooling->noti_handle == NULL) {
195 int real_total_pages = -1;
197 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
198 real_total_pages = 1;
200 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
201 job_spooling->n_up, job_spooling->copies);
203 if (job_spooling->page_printed <= real_total_pages) {
204 PTS_DEBUG("Create new notification for page %d", job_spooling->page_printed);
205 __pts_create_notification_by_page(ad, job_spooling);
211 notification_update_progress(NULL, job_spooling->noti_id, rate);
217 int __pts_remove_notification(int noti_id)
221 if (noti_id != NOTIFICATION_PRIV_ID_NONE) {
222 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, noti_id);
223 PTS_DEBUG("Notification is deleted");
230 int __pts_create_dummy_notification(pts_appdata_t *ad)
233 PTS_RETV_IF(ad == NULL, -1, "Invalid paramter for __pts_create_dummy_notification");
236 notification_h noti = NULL;
238 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
239 NOTIFICATION_GROUP_ID_NONE,
240 NOTIFICATION_PRIV_ID_NONE);
242 PTS_RETV_IF(noti == NULL, -1, "Failed to create Notification");
244 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"),
245 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
246 if (res != NOTIFICATION_ERROR_NONE) {
247 PTS_DEBUG("Failed to set Notification title [%d]", res);
251 char *printer_label = strdup(ad->list_info.active_printer->name);
252 pts_unstandardization(printer_label);
253 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
254 if (res != NOTIFICATION_ERROR_NONE) {
255 PTS_DEBUG("Failed to set Notification title [%d]", res);
258 if (printer_label != NULL) {
260 printer_label = NULL;
265 char value[4] = {0,};
267 if (!strcasecmp(ad->printing_data.type, "DOC") || !strcasecmp(ad->printing_data.type, "WEB")) {
268 PTS_DEBUG("It's pdf file. [%s]", ad->printing_data.type);
269 ad->printing_data.range.total_pages = get_pdf_pages_count(ad->printing_data.request_files[0]);
271 PTS_DEBUG("It's not pdf file. [%s]", ad->printing_data.type);
272 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
274 // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
275 int real_total_pages = -1;
276 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
277 real_total_pages = 1;
279 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
280 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
282 snprintf(value, 4, "%d", real_total_pages);
283 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
284 appsvc_add_data(b, SERVICE_FILES, ad->printing_data.request_files[0]);
285 appsvc_add_data(b, SERVICE_PAGE_COUNT, value);
286 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_DUMMY_NOTI);
288 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
289 if (res != NOTIFICATION_ERROR_NONE) {
290 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
295 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
296 if (res != NOTIFICATION_ERROR_NONE) {
297 PTS_DEBUG("Failed to set image icon");
301 res = notification_insert(noti, &(ad->noti_info.dummy_noti_id));
302 if (res != NOTIFICATION_ERROR_NONE) {
303 PTS_DEBUG("Failed to insert Notification [%d]", res);
306 PTS_DEBUG("Notification ID [%d]", ad->noti_info.dummy_noti_id);
312 if (printer_label != NULL) {
314 printer_label = NULL;
318 notification_free(noti);
331 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling)
334 PTS_RETV_IF(ad == NULL || job_spooling == NULL
335 , -1, "Invalid parameter for __pts_create_notification_by_page");
338 notification_h noti = NULL;
340 char title[32] = {0,};
342 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
343 NOTIFICATION_GROUP_ID_NONE,
344 NOTIFICATION_PRIV_ID_NONE);
347 PTS_DEBUG("Failed to create Notification");
351 //re-allocate noti handle
352 job_spooling->noti_handle = noti;
354 int real_total_pages = -1;
355 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
356 real_total_pages = 1;
358 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
359 job_spooling->n_up, job_spooling->copies);
361 snprintf(title, 32, "%s (%d/%d)",
362 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), job_spooling->page_printed, real_total_pages);
363 PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
365 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
366 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
367 if (res != NOTIFICATION_ERROR_NONE) {
368 PTS_DEBUG("Failed to set Notification title [%d]", res);
372 char *printer_label = strdup(ad->list_info.active_printer->name);
373 pts_unstandardization(printer_label);
374 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
375 if (res != NOTIFICATION_ERROR_NONE) {
376 PTS_DEBUG("Failed to set Notification title [%d]", res);
379 if (printer_label != NULL) {
381 printer_label = NULL;
384 res = notification_set_progress(noti, rate);
385 if (res != NOTIFICATION_ERROR_NONE) {
386 PTS_DEBUG("Failed to set Notification title [%d]", res);
392 char value1[4] = {0,};
393 char value2[4] = {0,};
394 snprintf(value1, 4, "%d", job_spooling->job_id);
395 snprintf(value2, 4, "%d", real_total_pages);
396 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
397 appsvc_add_data(b, SERVICE_JOB_ID, value1);
398 appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
399 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
401 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
402 if (res != NOTIFICATION_ERROR_NONE) {
403 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
408 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
409 if (res != NOTIFICATION_ERROR_NONE) {
410 PTS_DEBUG("Failed to set image icon");
414 res = notification_insert(noti, &job_spooling->noti_id);
415 if (res != NOTIFICATION_ERROR_NONE) {
416 PTS_DEBUG("Failed to insert Notification [%d]", res);
419 PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
425 if (printer_label != NULL) {
427 printer_label = NULL;
430 if (job_spooling->noti_handle != NULL) {
431 notification_free(job_spooling->noti_handle);
432 job_spooling->noti_handle = NULL;
444 int __pts_create_job_notification(pts_appdata_t *ad, int job_id)
447 PTS_RETV_IF(ad == NULL || job_id <=0
448 , -1 , "Invalid parameter for __pts_create_job_notification");
451 notification_h noti = NULL;
453 char title[32] = {0,};
455 pts_job_spooling_t *job_spooling = malloc(sizeof(pts_job_spooling_t));
456 PTS_RETV_IF(job_spooling == NULL, -1 , "Failed to malloc job_spooling");
457 memset(job_spooling, 0, sizeof(pts_job_spooling_t));
459 //FIXME - pt_files.files should be managed carefully during printing
460 job_spooling->pt_files.num_of_files = ad->printing_data.num_of_files;
461 job_spooling->pt_files.current_index = ad->printing_data.current_index;
463 job_spooling->pt_files.type = strdup(ad->printing_data.type); // need malloc
464 if (job_spooling->pt_files.type == NULL) {
465 PTS_DEBUG("Failed to malloc job_spooling->pt_files.type");
469 job_spooling->pt_files.request_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.num_of_files);
470 if (job_spooling->pt_files.request_files == NULL) {
471 PTS_DEBUG("Failed to malloc job_spooling->pt_files.request_files");
475 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
476 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
477 if (NULL != ad->printing_data.request_files[i]) {
478 job_spooling->pt_files.request_files[i] = strdup(ad->printing_data.request_files[i]);
480 job_spooling->pt_files.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
482 PTS_DEBUG("file path is %s", job_spooling->pt_files.request_files[i]);
485 job_spooling->input_file = strdup(job_spooling->pt_files.request_files[0]);
486 if (job_spooling->input_file == NULL) {
487 PTS_DEBUG("Failed to malloc job_spooling->input_file");
491 job_spooling->pt_files.range.from = ad->printing_data.range.from;
492 job_spooling->pt_files.range.to = ad->printing_data.range.to;
493 job_spooling->pt_files.range.total_pages = ad->printing_data.range.total_pages;
495 job_spooling->pt_files.range.selected_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.range.total_pages);
496 if (job_spooling->pt_files.range.selected_files == NULL) {
497 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files");
501 job_spooling->pt_files.range.selected_files[0] = strdup(ad->printing_data.range.selected_files[0]);
502 if (job_spooling->pt_files.range.selected_files[0] == NULL) {
503 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files[0]");
507 job_spooling->job_id = job_id;
508 #if 0 // Need to believe passed "Printing page X X" log have correct information.
509 if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
510 job_spooling->page_printed = 1; // FIXME
514 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
515 NOTIFICATION_GROUP_ID_NONE,
516 NOTIFICATION_PRIV_ID_NONE);
518 PTS_DEBUG("Failed to create Notification");
522 job_spooling->noti_handle = noti;
524 job_spooling->n_up = printer_get_setting_n_up(ad->list_info.active_printer);
526 job_spooling->copies = ad->list_info.active_printer->copies;
528 int real_total_pages = -1;
529 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
530 real_total_pages = 1;
532 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
533 job_spooling->n_up, job_spooling->copies);
535 snprintf(title, 32, "%s (1/%d)", _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), real_total_pages);
536 PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
538 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
539 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
540 if (res != NOTIFICATION_ERROR_NONE) {
541 PTS_DEBUG("Failed to set Notification title [%d]", res);
545 char *printer_label = strdup(ad->list_info.active_printer->name);
546 pts_unstandardization(printer_label);
547 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
548 if (res != NOTIFICATION_ERROR_NONE) {
549 PTS_DEBUG("Failed to set Notification title [%d]", res);
552 if (printer_label != NULL) {
554 printer_label = NULL;
557 res = notification_set_progress(noti, rate);
558 if (res != NOTIFICATION_ERROR_NONE) {
559 PTS_DEBUG("Failed to set Notification title [%d]", res);
565 char value1[4] = {0,};
566 char value2[4] = {0,};
567 snprintf(value1, 4, "%d", job_id);
568 snprintf(value2, 4, "%d", real_total_pages);
569 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
570 appsvc_add_data(b, SERVICE_JOB_ID, value1);
571 appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
572 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
574 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
575 if (res != NOTIFICATION_ERROR_NONE) {
576 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
582 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
583 if (res != NOTIFICATION_ERROR_NONE) {
584 PTS_DEBUG("Failed to set image icon");
588 res = notification_insert(noti, &job_spooling->noti_id);
589 if (res != NOTIFICATION_ERROR_NONE) {
590 PTS_DEBUG("Failed to insert Notification [%d]", res);
593 PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
595 ad->noti_info.job_spooling_list = eina_list_append(ad->noti_info.job_spooling_list, job_spooling);
596 if (eina_error_get()) {
597 PTS_DEBUG("Failed to append job_spooling");
606 if (printer_label != NULL) {
608 printer_label = NULL;
611 if (job_spooling != NULL) {
612 if (job_spooling->pt_files.type != NULL) {
613 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
614 job_spooling->pt_files.type = NULL;
617 if (job_spooling->pt_files.request_files != NULL) {
619 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
620 if (job_spooling->pt_files.request_files[i] != NULL) {
621 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]);
622 job_spooling->pt_files.request_files[i] = NULL;
625 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files);
626 job_spooling->pt_files.request_files = NULL;
629 if (job_spooling->input_file != NULL) {
630 PTS_IF_FREE_MEM(job_spooling->input_file);
631 job_spooling->input_file = NULL;
634 if (job_spooling->pt_files.range.selected_files != NULL) {
635 if (job_spooling->pt_files.range.selected_files[0] != NULL) {
636 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
637 job_spooling->pt_files.range.selected_files[0] = NULL;
640 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
641 job_spooling->pt_files.range.selected_files = NULL;
644 if (job_spooling->noti_handle != NULL) {
645 notification_free(job_spooling->noti_handle);
646 job_spooling->noti_handle = NULL;
649 PTS_IF_FREE_MEM(job_spooling);
657 static gboolean __pts_main_view_job_monitor_timeout_cb(void *data)
660 pts_appdata_t *ad = (pts_appdata_t *)data;
661 PTS_RETV_IF(ad == NULL, TRUE, "ad is NULL");
663 pt_job_state_e job_status = PT_JOB_ERROR;
664 gboolean ret = FALSE;
666 //char noti_name[512] = {0};
668 //FIXME - need to check one or all?
669 Eina_List *job_spooling_list = NULL;
670 pts_job_spooling_t *job_spooling = NULL;
671 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
672 job_status = pt_get_current_job_status(job_spooling->job_id);
673 if (job_status == PT_JOB_PROCESSING || job_status == PT_JOB_PENDING) {
674 PTS_DEBUG("job_id[%d] status is %d", job_spooling->job_id, job_status);
675 //XXX - If any one of job list is processing or pending, then motinor cb will be called again.
685 void __pts_event_cb(pt_event_e event, void *user_data, pt_progress_info_t *progress_info)
689 // XXX - progress_info can be passed by NULL
690 PTS_RET_IF(event < 0 || user_data == NULL, "Invalid parameters for event cb");
692 pts_appdata_t *ad = (pts_appdata_t *)user_data;
693 pts_job_spooling_t *job_spooling = NULL;
696 case PT_EVENT_USB_PRINTER_ONLINE:
697 __pts_main_view_check_usb_printer_online(ad);
699 case PT_EVENT_USB_PRINTER_OFFLINE:
700 __pts_main_view_check_usb_printer_offline(ad);
702 case PT_EVENT_PRINTER_ONLINE:
703 __pts_main_view_check_printer_online(ad);
705 case PT_EVENT_PRINTER_OFFLINE:
706 __pts_main_view_check_printer_offline(ad);
708 case PT_EVENT_JOB_COMPLETED:
709 PTS_DEBUG("Job[%d] is completed.", progress_info->job_id);
710 __pts_main_view_remove_job(ad, progress_info->job_id);
712 case PT_EVENT_JOB_STARTED:
713 PTS_DEBUG("Job id %d is allocated", progress_info->job_id);
714 __pts_remove_notification(ad->noti_info.dummy_noti_id);
715 ad->noti_info.dummy_noti_id = 0;
716 __pts_create_job_notification(ad, progress_info->job_id);
717 g_timeout_add(5000, (GSourceFunc)__pts_main_view_job_monitor_timeout_cb, ad);
719 case PT_EVENT_JOB_PROCESSING:
720 PTS_DEBUG("Job[%d] is processing.", progress_info->job_id);
722 case PT_EVENT_JOB_PROGRESS:
723 job_spooling = __pts_get_job_spooling(ad, progress_info->job_id);
724 if (job_spooling != NULL) {
725 PTS_DEBUG("new - progress_info: job_id[%d] progress[%d] page_printed[%d]\n"
726 "old - job_spooling: job_id[%d] progress[%d] page_printed[%d]",
727 progress_info->job_id, progress_info->progress, progress_info->page_printed,
728 job_spooling->job_id, job_spooling->progress, job_spooling->page_printed);
732 if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
733 if (progress_info->progress < job_spooling->progress) {
734 //FIXME - assume next page printing is started
735 job_spooling->page_printed++;
740 job_spooling->progress = progress_info->progress;
742 __pts_update_notification(ad, progress_info, job_spooling);
743 __pts_update_popup_progress(ad, progress_info, job_spooling);
745 case PT_EVENT_JOB_PENDING:
746 PTS_DEBUG("Job[%d] is waiting.", progress_info->job_id);
748 case PT_EVENT_JOB_HELD:
749 PTS_DEBUG("Job[%d] is held.", progress_info->job_id);
751 case PT_EVENT_JOB_STOPPED:
752 PTS_DEBUG("Job[%d] is stopped.", progress_info->job_id);
753 __pts_main_view_job_error(ad, progress_info->job_id);
754 __pts_main_view_remove_job(ad, progress_info->job_id);
756 case PT_EVENT_JOB_CANCELED:
757 PTS_DEBUG("Job[%d] is canceled.", progress_info->job_id);
758 __pts_main_view_job_error(ad, progress_info->job_id);
759 __pts_main_view_remove_job(ad, progress_info->job_id);
761 case PT_EVENT_JOB_ABORTED:
762 PTS_DEBUG("Job[%d] is aborted.", progress_info->job_id);
763 if (progress_info->job_id > 0) {
764 __pts_main_view_job_error(ad, progress_info->job_id);
765 __pts_main_view_remove_job(ad, progress_info->job_id);
766 } else { // XXX - for dummy job?
767 __pts_main_view_last_job_error(ad);
770 case PT_EVENT_JOB_ERROR:
771 PTS_DEBUG("Job[%d] error", progress_info->job_id);
772 __pts_main_view_job_error(ad, progress_info->job_id);
773 __pts_main_view_remove_job(ad, progress_info->job_id);
775 case PT_EVENT_ALL_THREAD_COMPLETED:
776 PTS_DEBUG("All thread is completed.");
777 PTS_DEBUG("No more job, then terminate mobileprint");
778 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
789 static void __pts_main_view_check_usb_printer_online(void *userdata)
792 pts_appdata_t *ad = (pts_appdata_t *)userdata;
793 PTS_RET_IF(ad == NULL, "ad is NULL");
795 /* if in ether searching or printing, ignore it */
796 PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
798 PTS_IF_DEL_OBJ(ad->progress_info.popup);
800 elm_naviframe_item_pop_to(ad->main_info.navi_it);
802 /* re-searching printers */
803 ad->search_info.print_search_mode = PTS_SEARCH_INITIAL;
804 ad->search_info.selection_done_cb = load_main_view;
805 ad->search_info.print_search_popup_parent = ad->main_info.root_win;
806 ad->search_info.printer_search_user_data = NULL;
807 pts_search_printer(ad);
808 //pts_main_view_search_printer(ugd);
813 static void __pts_main_view_check_usb_printer_offline(void *userdata)
816 pts_appdata_t *ad = (pts_appdata_t *)userdata;
817 PTS_RET_IF(ad == NULL, "ad is NULL");
819 /* if in searching or printing, return */
820 PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
821 PTS_IF_DEL_OBJ(ad->progress_info.popup);
822 PTS_IF_FREE_MEM(ad->list_info.active_printer);
824 elm_naviframe_item_pop_to(ad->main_info.navi_it);
826 pts_main_view_update_printer_label(ad);
831 static void __pts_main_view_remove_job(void *user_data, int job_id)
834 PTS_RET_IF(user_data == NULL || job_id <= 0,"Invalid parameter for job error processing");
836 pts_appdata_t *ad = (pts_appdata_t *)user_data;
839 if (NULL != ad->progress_info.popup) {
840 evas_object_del(ad->progress_info.popup);
841 ad->progress_info.popup = NULL;
842 evas_object_hide(ad->main_info.root_win);
845 Eina_List *job_spooling_list = NULL;
846 pts_job_spooling_t *job_spooling = NULL;
848 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
849 if (job_spooling->job_id == job_id) {
850 PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
855 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
856 ,"No found job_spooling for job_id[%d]\n", job_id);
858 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
859 ad->search_info.is_process = 0;/*process is complete*/
861 ad->noti_info.job_spooling_list = eina_list_remove_list(ad->noti_info.job_spooling_list, job_spooling_list);
862 if (0 == eina_list_count(ad->noti_info.job_spooling_list)) {
863 PTS_DEBUG("Job spooling list is empty");
864 ad->noti_info.job_spooling_list = NULL;
867 if (job_spooling->noti_handle != NULL) {
868 ret = notification_free(job_spooling->noti_handle);
869 if (ret != NOTIFICATION_ERROR_NONE) {
870 PTS_DEBUG("Failed to free notification handle [%d]", ret);
872 job_spooling->noti_handle = NULL;
875 PTS_RET_IF(job_spooling->pt_files.range.selected_files == NULL, "job_spooling->pt_files.range.selected_files is NULL");
877 if (job_spooling->pt_files.range.selected_files[0]) {
878 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
879 job_spooling->pt_files.range.selected_files[0] = NULL;
882 if (job_spooling->pt_files.range.selected_files) {
883 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
884 job_spooling->pt_files.range.selected_files = NULL;
887 if (job_spooling->input_file) {
888 PTS_IF_FREE_MEM(job_spooling->input_file);
889 job_spooling->input_file = NULL;
893 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
894 if (job_spooling->pt_files.request_files[i]) {
895 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]); // FIXME
896 job_spooling->pt_files.request_files[i] = NULL;
900 if (job_spooling->pt_files.request_files) {
901 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files); // FIXME
902 job_spooling->pt_files.request_files = NULL;
905 if (job_spooling->pt_files.type) {
906 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
907 job_spooling->pt_files.type = NULL;
911 PTS_IF_FREE_MEM(job_spooling);
918 static void __pts_main_view_job_error(void *user_data, int job_id)
921 PTS_RET_IF(user_data == NULL || job_id <= 0, "Invalid parameter for job error processing");
923 pts_appdata_t *ad = (pts_appdata_t *)user_data;
924 PTS_IF_DEL_OBJ(ad->progress_info.popup);
926 pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
928 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
929 , "No found job_spooling for job_id[%d]\n", job_id);
931 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
932 ad->search_info.is_process = 0;/*process is complete*/
933 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
934 evas_object_show(ad->main_info.root_win);
935 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
939 static void __pts_main_view_last_job_error(void *user_data)
942 PTS_RET_IF(user_data == NULL, "Invalid parameter for last job error processing");
944 pts_appdata_t *ad = (pts_appdata_t *)user_data;
945 PTS_IF_DEL_OBJ(ad->progress_info.popup);
947 pts_job_spooling_t *job_spooling = __pts_get_last_job_spooling(ad);
948 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
949 , "No found job_spooling for last_job");
951 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
952 ad->search_info.is_process = 0;/*process is complete*/
953 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
954 evas_object_show(ad->main_info.root_win);
955 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
960 static void __pts_main_view_check_printer_online(void *user_data)
963 PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_online");
965 pts_appdata_t *ad = (pts_appdata_t *)user_data;
966 ecore_timer_add(1.0, (Ecore_Task_Cb)__pts_main_view_start_print, ad);
971 static void __pts_main_view_check_printer_offline(void *user_data)
974 PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_offline");
976 pts_appdata_t *ad = (pts_appdata_t *)user_data;
977 PTS_IF_DEL_OBJ(ad->progress_info.popup);
978 PTS_IF_FREE_MEM(ad->list_info.active_printer);
980 pts_main_view_update_printer_label(ad);
981 pts_create_popup(ad->main_info.navi, _("IDS_PRT_POP_CHECKPRINTERSTATE"), 2.0);
982 ad->search_info.is_process = 0;/* process is complete */
987 static void __pts_main_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
990 pts_appdata_t *ad = (pts_appdata_t *)data;
991 PTS_RET_IF(ad == NULL, "ad is NULL");
994 if (NULL != ugd->pt_files.request_files) {
996 for (i = 0; i < ugd->pt_files.num_of_files; i++) {
997 if (ugd->pt_files.request_files[i] != NULL) {
998 free(ugd->pt_files.request_files[i]);
999 ugd->pt_files.request_files[i] = NULL;
1003 if (ugd->pt_files.range.selected_files != NULL) {
1004 free(ugd->pt_files.range.selected_files);
1005 ugd->pt_files.range.selected_files = NULL;
1008 free(ugd->pt_files.request_files);
1009 ugd->pt_files.request_files = NULL;
1016 static void __pts_main_view_navi_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1019 pts_appdata_t *ad = (pts_appdata_t *)data;
1020 PTS_RET_IF(ad == NULL, "ad is NULL");
1022 PTS_IF_FREE_MEM(ad->list_info.active_printer);
1028 * "back" button callback
1030 void __pts_main_view_btn_back_cb(void *data, Evas_Object *obj, void *event_info)
1033 pts_appdata_t *ad = (pts_appdata_t *) data;
1034 PTS_RET_IF(ad == NULL, "ad is NULL");
1035 //TODO - check current spooling job status before app termination
1036 if (ad->noti_info.job_spooling_list == NULL) {
1037 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
1041 PTS_DEBUG("Active job spooling list is existed. So just hide preview.");
1042 __pts_hide_main_view(ad);
1047 static void __pts_main_view_dummy_cancel_print(void *data, Evas_Object *obj, void *event_info)
1051 pts_appdata_t *ad = pts_get_appdata();
1052 PTS_RET_IF(ad == NULL, "ad is NULL");
1054 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1055 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1057 pts_create_popup(ad->main_info.root_win, PTS_19, 2.0);
1058 evas_object_show(ad->main_info.root_win);
1059 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1064 static void __pts_main_view_response_cancel_print(void *data, Evas_Object *obj, void *event_info)
1067 int job_id = (int)data;
1068 pts_appdata_t *ad = pts_get_appdata();
1069 PTS_RET_IF(ad == NULL || job_id <= 0, "Invalid parameter for __pts_main_view_response_cancel_print");
1070 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1071 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1073 pt_cancel_print(job_id);
1075 pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
1076 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
1077 , "No found job_spooling for job[%d]\n", job_id);
1079 // FIXME - Is it better to do this job after received canceled evt_cb?
1080 __pts_remove_notification(job_spooling->noti_id);
1082 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTING_CANCELED"), 2.0);
1083 evas_object_show(ad->main_info.root_win);
1084 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1089 static void __pts_hide_progress_popup(void *data, Evas_Object *obj, void *event_info)
1092 pts_appdata_t *ad = (pts_appdata_t *)data;
1093 PTS_RET_IF(ad == NULL, "ad is NULL");
1095 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1096 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1098 evas_object_hide(ad->main_info.root_win);
1103 void __pts_print_dummy_popup(pts_appdata_t *ad, char *files, int page_count)
1106 PTS_RET_IF(ad == NULL || files == NULL || page_count <= 0, "Invalid parameters for progress_popup");
1108 Evas_Object *label1 = NULL;
1109 Evas_Object *label2 = NULL;
1110 Evas_Object *label3 = NULL;
1111 Evas_Object *popup = NULL;
1112 Evas_Object *layout = NULL;
1113 Evas_Object *progressbar = NULL;
1114 char page_info[8] = {0,};
1115 char aligned_label[128] = {0,};
1117 popup = elm_popup_add(ad->main_info.main_layout);
1119 label1 = elm_label_add(popup);
1120 elm_object_style_set(label1, "popup/progressview");
1121 elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1122 char *printer_label = strdup(ad->list_info.active_printer->name);
1123 pts_unstandardization(printer_label);
1124 snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1125 elm_object_text_set(label1, aligned_label);
1126 if (printer_label != NULL) {
1127 /* accessability - screen reader support */
1128 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1129 free(printer_label);
1130 printer_label = NULL;
1132 evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1133 evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1134 evas_object_show(label1);
1136 label2 = elm_label_add(popup);
1137 elm_object_style_set(label2, "popup/progressview");
1138 elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1139 snprintf(aligned_label, 128, "<align=center>%s</align>",
1140 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1141 elm_object_text_set(label2, aligned_label);
1142 /* accessability - screen reader support */
1143 elm_access_info_set(label2, ELM_ACCESS_INFO, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1144 evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1145 evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1146 evas_object_show(label2);
1148 label3 = elm_label_add(popup);
1149 elm_object_style_set(label3, "popup/progressview");
1150 elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1151 snprintf(aligned_label, 128, "<align=center>%s</align>", basename(files));
1152 elm_object_text_set(label3, aligned_label);
1153 /* accessability - screen reader support */
1154 elm_access_info_set(label3, ELM_ACCESS_INFO, basename(files));
1155 evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1156 evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1157 evas_object_show(label3);
1159 layout = pts_create_base_layout(popup, "popup_progress");
1161 progressbar = elm_progressbar_add(popup);
1162 elm_object_style_set(progressbar, "pending_list");
1163 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1164 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1165 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1166 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1167 evas_object_show(progressbar);
1169 ad->progress_info.progress_label = label2;
1170 ad->progress_info.progress_layout = layout;
1171 ad->progress_info.progressbar = progressbar;
1173 elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1174 elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1175 elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1176 elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1177 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1178 // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
1179 int real_total_pages = -1;
1180 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1181 real_total_pages = 1;
1183 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
1184 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
1186 snprintf(page_info, 8, "1/%d", real_total_pages);
1187 elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1189 Evas_Object *btn1 = NULL;
1190 btn1 = elm_button_add(popup);
1191 elm_object_style_set(btn1,"popup_button/default");
1192 elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1193 elm_object_part_content_set(popup, "button1", btn1);
1194 evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1196 if (page_count > 1) {
1197 Evas_Object *btn2 = NULL;
1198 btn2 = elm_button_add(popup);
1199 elm_object_style_set(btn2,"popup_button/default");
1200 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1201 elm_object_part_content_set(popup, "button2", btn2);
1202 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_dummy_cancel_print, NULL);
1205 elm_object_content_set(popup, layout);
1206 evas_object_show(popup);
1207 evas_object_show(ad->main_info.root_win);
1209 ad->progress_info.popup = popup;
1215 void __pts_print_progress_popup(pts_appdata_t *ad, int job_id, int page_count)
1218 PTS_RET_IF(ad == NULL || job_id <= 0 || page_count <= 0, "Invalid parameters for progress_popup");
1220 pts_job_spooling_t *job_spooling = NULL;
1221 job_spooling = __pts_get_job_spooling(ad, job_id);
1222 PTS_RET_IF(job_spooling == NULL, "No found job_spooling for job_id[%d]", job_id);
1224 Evas_Object *label1 = NULL;
1225 Evas_Object *label2 = NULL;
1226 Evas_Object *label3 = NULL;
1227 Evas_Object *popup = NULL;
1228 Evas_Object *layout = NULL;
1229 Evas_Object *progressbar = NULL;
1230 char progress_info[8] = {0,};
1231 char page_info[8] = {0,};
1232 char aligned_label[128] = {0,};
1234 popup = elm_popup_add(ad->main_info.main_layout);
1236 label1 = elm_label_add(popup);
1237 elm_object_style_set(label1, "popup/progressview");
1238 elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1239 char *printer_label = strdup(ad->list_info.active_printer->name);
1240 pts_unstandardization(printer_label);
1241 snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1242 elm_object_text_set(label1, aligned_label);
1243 if (printer_label != NULL) {
1244 /* accessability - screen reader support */
1245 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1247 free(printer_label);
1248 printer_label = NULL;
1250 evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1251 evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1252 evas_object_show(label1);
1254 label2 = elm_label_add(popup);
1255 elm_object_style_set(label2, "popup/progressview");
1256 elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1257 if (job_spooling->progress > 0) {
1258 snprintf(aligned_label, 128, "<align=center>%s</align>",
1259 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1260 /* accessability - screen reader support */
1261 elm_access_info_set(label2, ELM_ACCESS_INFO,
1262 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1264 snprintf(aligned_label, 128, "<align=center>%s</align>",
1265 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1266 /* accessability - screen reader support */
1267 elm_access_info_set(label2, ELM_ACCESS_INFO,
1268 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1270 elm_object_text_set(label2, aligned_label);
1271 evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1272 evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1273 evas_object_show(label2);
1275 label3 = elm_label_add(popup);
1276 elm_object_style_set(label3, "popup/progressview");
1277 elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1278 char* label3_text = basename(job_spooling->pt_files.request_files[0]);
1279 snprintf(aligned_label, 128, "<align=center>%s</align>",
1281 elm_object_text_set(label3, aligned_label);
1282 /* accessability - screen reader support */
1283 elm_access_info_set(label3, ELM_ACCESS_INFO, label3_text);
1285 evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1286 evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1287 evas_object_show(label3);
1289 layout = pts_create_base_layout(popup, "popup_progress");
1290 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1292 progressbar = elm_progressbar_add(popup);
1293 if (job_spooling->progress > 0) {
1294 double rate = job_spooling->progress * 0.01;
1295 elm_object_style_set(progressbar, "list_progress");
1296 elm_progressbar_value_set(progressbar, rate);
1298 elm_object_style_set(progressbar, "pending_list");
1299 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1301 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1302 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1303 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1304 evas_object_show(progressbar);
1306 ad->progress_info.progress_label = label2;
1307 ad->progress_info.progress_layout = layout;
1308 ad->progress_info.progressbar = progressbar;
1310 elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1311 elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1312 elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1313 elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1314 if (job_spooling->progress > 0) {
1315 snprintf(progress_info, 8, "%d%%", job_spooling->progress);
1316 elm_object_part_text_set(layout, "elm.text.subtext1", progress_info);
1318 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1320 snprintf(page_info, 8, "%d/%d", job_spooling->page_printed, page_count);
1321 elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1323 Evas_Object *btn1 = NULL;
1324 btn1 = elm_button_add(popup);
1325 elm_object_style_set(btn1,"popup_button/default");
1326 elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1327 elm_object_part_content_set(popup, "button1", btn1);
1328 evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1330 // Show cancel button when total page is greater than 1 page.
1331 // if (page_count > 1) {
1332 Evas_Object *btn2 = NULL;
1333 btn2 = elm_button_add(popup);
1334 elm_object_style_set(btn2,"popup_button/default");
1335 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1336 elm_object_part_content_set(popup, "button2", btn2);
1337 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_response_cancel_print, (void *)job_id);
1338 elm_access_info_set(btn2, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_PRINTING);
1341 elm_object_content_set(popup, layout);
1342 evas_object_show(popup);
1343 evas_object_show(ad->main_info.root_win);
1345 ad->progress_info.popup = popup;
1350 static Eina_Bool __pts_is_valid_printing_data(pts_appdata_t *ad)
1352 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1353 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1355 if (ad->list_info.active_printer->copies <= 0) {
1356 ad->list_info.active_printer->copies = 1;
1357 PTS_DEBUG("copies is less than 0(%d)", ad->list_info.active_printer->copies);
1361 /* get the range of print files */
1362 if (ad->printing_data.range.from <= 0 ||
1363 ad->printing_data.range.to > ad->printing_data.range.total_pages ||
1364 ad->printing_data.range.from > ad->printing_data.range.to) {
1365 PTS_DEBUG("from(%d) to(%d) total(%d)"
1366 ,ad->printing_data.range.from
1367 ,ad->printing_data.range.to
1368 ,ad->printing_data.range.total_pages);
1369 PTS_DEBUG("range checking error");
1376 static Eina_Bool __pts_set_print_option_page_range(pts_appdata_t *ad)
1378 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1380 char temp[1024] = {0,};
1383 if(_is_pdf_file_type(ad->printing_data.request_files, ad->printing_data.num_of_files) == true) {
1384 for (index = 0 ; index < ad->printing_data.num_of_files ; index++) {
1385 ad->printing_data.range.total_pages += get_pdf_pages_count(ad->printing_data.request_files[index]);
1388 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1391 PTS_DEBUG("Updated ad->printing_data.range.total_pages: %d", ad->printing_data.range.total_pages);
1392 ad->printing_data.range.to = ad->printing_data.range.total_pages;
1394 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1395 ad->printing_data.range.from = ad->printing_data.range.to = evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1;
1396 snprintf(temp, sizeof(temp), "%d", ad->printing_data.range.from);
1397 pt_set_print_option_page_range(temp);
1398 PTS_DEBUG("Set current page[%d] printing", ad->printing_data.range.from);
1404 static Eina_Bool __pts_set_print_scale_size(pts_appdata_t *ad)
1406 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1409 char *first_fname = NULL;
1411 PTS_IF_FREE_MEM(ad->printing_data.range.selected_files);
1412 //FIXME - multiple page pdf will be changed to several image files.
1413 num = ad->printing_data.range.total_pages;
1414 ad->printing_data.range.selected_files = (char **)malloc(sizeof(char *)*num);
1416 if (NULL == ad->printing_data.range.selected_files) {
1417 PTS_DEBUG("selected_files malloc error");
1421 first_fname = ad->printing_data.request_files[ad->printing_data.range.from - 1];
1422 if (1 == num && FILE_TYPE_IMAGE == get_file_type(first_fname)) {
1425 if (get_image_resolution(first_fname, &res_x, &res_y) < 0) {
1426 PTS_DEBUG("[ERROR] Failed to get image resolution(%s)",first_fname);
1429 pt_imagesize_t crop_image_info;
1430 crop_image_info.imagesize = ad->size_popup_info.image_size;
1431 crop_image_info.resolution_width = ad->size_popup_info.custom_width;
1432 crop_image_info.resolution_height = ad->size_popup_info.custom_height;
1433 crop_image_info.ratio = ad->size_popup_info.custom_w_ratio;
1434 crop_image_info.unit = ad->size_popup_info.custom_unit;
1436 pt_set_print_option_imagesize(&crop_image_info, first_fname, res_x, res_y);
1437 ad->printing_data.range.selected_files[0] = ad->printing_data.request_files[0];
1439 pt_set_print_option_scaleimage(ad->list_info.active_printer->scaling);
1441 ad->printing_data.range.selected_files[0] = ad->printing_data.input_file;
1447 static Eina_Bool __pts_set_print_options(pts_appdata_t *ad)
1449 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1450 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1452 Eina_Bool eret = EINA_FALSE;
1454 eret = __pts_set_print_option_page_range(ad);
1455 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set page ragnge");
1457 pt_set_print_option_papersize(); //(ugd->active_printer->size);
1458 pt_set_print_option_copies(ad->list_info.active_printer->copies);
1459 // pt_set_print_option_scaleimage(ugd->active_printer->scaling);
1460 pt_set_print_option_orientation(ad->list_info.active_printer->landscape);
1461 // FIXME : which field of ppd structure sholud be used for this?
1462 pt_set_print_option_quality();
1463 pt_set_print_option_paper_type();
1464 pt_set_print_option_color();
1465 pt_set_print_option_duplex(ad->list_info.active_printer->landscape);
1466 eret = __pts_set_print_scale_size(ad);
1467 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print scale size");
1472 static Eina_Bool __pts_set_active_printer(pts_appdata_t *ad)
1474 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1475 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1479 if (1 != ad->list_info.active_printer->actived) {
1480 /* use default printer, needs active */
1481 ret = pt_set_active_printer(ad->list_info.active_printer);
1482 if (PT_ERR_NONE != ret) {
1483 PTS_DEBUG("pt_set_active_printer error");
1491 static Eina_Bool __pts_main_view_start_print(void *data)
1494 pts_appdata_t *ad = (pts_appdata_t *)data;
1495 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
1500 Eina_Bool eret = EINA_FALSE;
1501 eret = __pts_set_print_options(ad);
1502 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print option");
1504 eret = __pts_is_valid_printing_data(ad);
1505 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "It's not valid printing data");
1507 eret = __pts_set_active_printer(ad);
1508 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set active printer");
1510 __pts_create_dummy_notification(ad);
1512 ret = pt_start_print((const char **)ad->printing_data.range.selected_files, num);
1513 if (PT_ERR_NONE != ret) {
1514 PTS_DEBUG("pt_start_print error");
1519 return ECORE_CALLBACK_CANCEL;
1522 ad->search_info.is_process = 0;/*process is complete*/
1524 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1526 if ((PT_ERR_NOT_USB_ACCESS == ret) || (PT_ERR_NOT_NETWORK_ACCESS == ret)) {
1527 pts_create_popup(ad->main_info.navi, _("IDS_COM_POP_PRINTER_DISCONNECTED_ABB2"), 2.0);
1529 pts_create_popup(ad->main_info.navi, _("IDS_COM_BODY_UNSUPPORTED_FILE_TYPE"), 1.0);
1531 return ECORE_CALLBACK_CANCEL;
1534 static Eina_Bool __pts_hide_main_view(void *data)
1537 pts_appdata_t *ad = (pts_appdata_t *) data;
1538 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "data is NULL");
1540 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1541 PTS_DEBUG("Hide main view of mobileprint");
1542 evas_object_hide(ad->main_info.root_win);
1545 return ECORE_CALLBACK_CANCEL;
1549 * "print" button callback
1551 static void __pts_main_view_btn_print_cb(void *data, Evas_Object *obj, void *event_info)
1554 pts_appdata_t *ad = (pts_appdata_t *)data ;
1555 PTS_RET_IF(ad == NULL, "ad is NULL");
1557 if ((NULL != ad->printing_data.request_files) && (NULL != ad->list_info.active_printer)) {
1558 evas_object_hide(ad->main_info.main_layout);
1559 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PREPARING_TO_PRINT_ING"), 2.0);
1560 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1562 ad->search_info.is_process = 1;/* in process */
1563 __pts_main_view_start_print(ad);
1565 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_SELECT_PRINTER"), 2.0);
1570 static void __pts_main_view_btn_size_cb(void *data, Evas_Object *obj, void *event_info)
1573 pts_appdata_t *ad = (pts_appdata_t *)data;
1574 PTS_RET_IF(ad == NULL, "ad is NULL");
1576 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1578 if (ad->list_info.active_printer) {
1579 pts_create_size_popup(ad->main_info.navi, ad);
1581 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1587 static void __pts_main_view_btn_scaling_cb(void *data, Evas_Object *obj, void *event_info)
1590 pts_appdata_t *ad = (pts_appdata_t *)data;
1591 PTS_RET_IF(ad == NULL, "ad is NULL");
1593 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1595 if (ad->list_info.active_printer) {
1596 pts_create_scaling_popup(ad->main_info.navi, ad);
1598 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1605 static void __pts_main_view_btn_landscape_cb(void *data, Evas_Object *obj, void *event_info)
1608 pts_appdata_t *ad = (pts_appdata_t *)data;
1609 PTS_RET_IF(ad == NULL, "ad is NULL");
1611 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1613 if (ad->list_info.active_printer) {
1614 PTS_DEBUG("initial ad->main_info.landscape_toggle : %d",
1615 ad->main_info.landscape_toggle);
1616 if (PT_ORIENTATION_PORTRAIT == ad->main_info.landscape_toggle) {
1617 ad->main_info.landscape_toggle = PT_ORIENTATION_LANDSCAPE;
1618 } else { /*FIXME if (PT_LANDSCAPE_LANDSCAPE == ugd->landscape_toggle)*/
1619 ad->main_info.landscape_toggle = PT_ORIENTATION_PORTRAIT;
1622 PTS_DEBUG("ad->main_info.landscape_toggle : %d", ad->main_info.landscape_toggle);
1624 ad->list_info.active_printer->landscape = ad->main_info.landscape_toggle;
1625 pts_main_view_rotate_image(ad, app_get_device_orientation());
1627 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1633 static void _dismissed_cb(void *data, Evas_Object *obj, void *event_info)
1635 PTS_IF_DEL_OBJ(obj);
1638 static void _move_ctxpopup_more(Evas_Object *ctxpopup, Evas_Object *btn)
1640 Evas_Coord x, y, w , h;
1641 evas_object_geometry_get(btn, &x, &y, &w, &h);
1642 evas_object_move(ctxpopup, x + (w / 2), y);
1645 static void _more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1648 //struct appdata *ad = (struct appdata *) data;
1652 pts_appdata_t *ad = pts_get_appdata();
1653 PTS_RET_IF(ad == NULL, "ad is NULL");
1655 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1657 ad->setting_info.ctxpopup = elm_ctxpopup_add(ad->main_info.navi);
1658 elm_object_style_set(ad->setting_info.ctxpopup, "more_button");
1659 evas_object_smart_callback_add(ad->setting_info.ctxpopup, "dismissed", _dismissed_cb, ad->setting_info.ctxpopup);
1661 icon = elm_icon_add(ad->setting_info.ctxpopup);
1662 if (ad->printing_data.type != NULL) {
1663 if (0 == strcasecmp(ad->printing_data.type, "IMG")) {
1664 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1665 elm_icon_file_set(icon, buf, NULL);
1666 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1667 } else if (0 == strcasecmp(ad->printing_data.type, "DOC") || 0 == strcasecmp(ad->printing_data.type, "WEB")) {
1668 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_scaling.png", ICON_DIR);
1669 elm_icon_file_set(icon, buf, NULL);
1670 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_PRT_BODY_SCALING_ABB"), icon, __pts_main_view_btn_scaling_cb, ad);
1672 } else { /* Default IMG */
1673 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1674 elm_icon_file_set(icon, buf, NULL);
1675 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1678 icon = elm_icon_add(ad->setting_info.ctxpopup);
1679 if (ad->main_info.landscape_toggle == PT_ORIENTATION_PORTRAIT) {
1680 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate.png", ICON_DIR);
1682 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate02.png", ICON_DIR);
1684 elm_icon_file_set(icon, buf, NULL);
1685 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_OPT_ROTATE"), icon, __pts_main_view_btn_landscape_cb, ad);
1687 icon = elm_icon_add(ad->setting_info.ctxpopup);
1688 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_setting.png", ICON_DIR);
1689 elm_icon_file_set(icon, buf, NULL);
1690 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_COM_BODY_SETTING"), icon, __pts_main_view_btn_setting_cb, ad);
1692 _move_ctxpopup_more(ad->setting_info.ctxpopup, obj);
1694 evas_object_show(ad->setting_info.ctxpopup);
1699 static Evas_Object *create_toolbar_btn(Evas_Object *parent, const char *text, Evas_Smart_Cb func, void *data)
1702 Evas_Object *btn = elm_button_add(parent);
1706 elm_object_style_set(btn, "naviframe/toolbar/default");
1707 elm_object_text_set(btn, text);
1708 evas_object_smart_callback_add(btn, "clicked", func, data);
1713 static Evas_Object *create_toolbar_more_btn(Evas_Object *parent, Evas_Smart_Cb func, void *data)
1716 Evas_Object *btn = elm_button_add(parent);
1720 elm_object_style_set(btn, "naviframe/more/default");
1721 elm_access_info_set(btn, ELM_ACCESS_INFO, IDS_SCRREAD_MENU_INFO);
1722 elm_access_info_set(btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_MENU_CONTEXT);
1723 evas_object_smart_callback_add(btn, "clicked", func, data);
1729 char *get_preview_image_path(pts_core_data_t *ugd)
1732 PTS_RETV_IF(ugd == NULL, NULL, "ugd is NULL");
1734 if (g_current_preview_path == NULL) {
1735 g_current_preview_path = malloc(sizeof(char) * 4096);
1738 if ((ugd->pt_files.current_index >= 0)
1739 && (ugd->pt_files.current_index < g_pages_count)) {
1740 sprintf(g_current_preview_path, "/tmp/mobileprint/mobileprint_%04d.ppm",
1741 ugd->pt_files.current_index + 1);
1742 PTS_DEBUG("Preview image path is %s", g_current_preview_path);
1744 return g_current_preview_path;
1752 * Set accessability information - screen reader text
1754 void generate_main_view_accessability_info(pts_appdata_t *ad,
1755 char* main_view_accessability_text,
1756 size_t text_max_length)
1759 PTS_RET_IF(NULL == ad || NULL == ad->list_info.active_printer, "Invalid argument");
1761 char papersize[256]={0,};
1762 strncpy(papersize, pt_get_print_option_papersize(ad->list_info.active_printer->size), 256-1);
1763 char *quality, *papertype, *grayscale_mode, *print_range;
1764 int p_quality = pt_get_selected(PT_OPTION_ID_QUALITY);
1765 if (PT_QUALITY_DRAFT == p_quality) {
1766 quality = _("IDS_PRT_OPT_PRINTSETTINGS_DRAFT");
1767 } else if (PT_QUALITY_STANDARD == p_quality) {
1768 quality = _("IDS_PRT_OPT_PRINTSETTINGS_STANDARD");
1769 } else if (PT_QUALITY_HIGH == p_quality) {
1770 quality = _("IDS_COM_BODY_HIGH");
1774 int p_type = pt_get_selected(PT_OPTION_ID_PAPER);
1775 if (PT_PAPER_NORMAL == p_type) {
1776 papertype = _("IDS_ST_BODY_NORMAL");
1777 } else if (PT_PAPER_GLOSSY == p_type) {
1778 papertype = _("IDS_ST_BODY_GLOSSY");
1779 } else if (PT_PAPER_PHOTO == p_type) {
1780 papertype = _("IDS_PRT_BODY_PHOTOGRAPHIC_ABB");
1784 int p_grayscale = pt_get_selected(PT_OPTION_ID_GRAYSCALE);
1785 if (PT_GRAYSCALE_COLOUR == p_grayscale) {
1786 grayscale_mode = _("IDS_PRT_BODY_COLOUR");
1787 } else if (PT_GRAYSCALE_GRAYSCALE == p_grayscale) {
1788 grayscale_mode = _("IDS_IMGE_HEADER_GREY");
1790 grayscale_mode = NULL;
1792 pt_range_e p_range = ad->list_info.active_printer->range;
1793 if (PT_RANGE_ALL == p_range) {
1794 print_range = _("IDS_DIC_BODY_ALL");
1796 print_range = _("IDS_BR_BODY_CURRENT_PAGE");
1799 snprintf(main_view_accessability_text, text_max_length, "%s, %d page of %d pages, %s size, %d %s,"
1801 " %s orientation, %s quality, %s paper"
1802 " %s mode, send to %s",
1803 basename(ad->printing_data.input_file), //printing file
1804 evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1, //current page
1805 g_pages_count, //total pages
1807 ad->list_info.active_printer->copies,
1808 (1 == ad->list_info.active_printer->copies) ? "copy" : "copies",
1810 (PT_SCALING_2_PAGES == ad->list_info.active_printer->scaling) ? "2 pages in 1 sheet" :
1811 (PT_SCALING_4_PAGES == ad->list_info.active_printer->scaling) ? "4 pages in 1 sheet" :
1813 PT_ORIENTATION_PORTRAIT == ad->list_info.active_printer->landscape ? "portrait" :
1814 PT_ORIENTATION_LANDSCAPE == ad->list_info.active_printer->landscape ? "landscape" : "auto",
1818 elm_access_info_get(ad->main_info.printer_label, ELM_ACCESS_INFO));
1824 * create content of the main view screen
1826 static Evas_Object *__pts_main_view_create_content(pts_appdata_t *ad)
1829 PTS_RETV_IF(ad == NULL, NULL, "ad is NULL");
1832 * load preview group
1834 ad->main_info.printer_layout = pts_create_base_layout(ad->main_info.navi, "printer");
1836 pts_main_view_update_printer_label(ad);
1839 * load preview image group
1841 ad->main_info.img_layout = pts_create_base_layout(ad->main_info.printer_layout, "image_view");
1843 if (NULL != ad->printing_data.request_files) {
1844 char *file_path = NULL;
1845 file_path = ad->printing_data.request_files[ad->printing_data.current_index];
1846 PTS_DEBUG("filepath is %s", file_path);
1849 ad->main_info.smsc = evas_smart_smsc_add(evas_object_evas_get(ad->main_info.img_layout));
1850 evas_smart_smsc_set_layout(ad->main_info.smsc, ad->main_info.img_layout);
1851 elm_object_part_content_set(ad->main_info.img_layout, "content", ad->main_info.smsc);
1854 * Set preview layout
1856 elm_object_part_content_set(ad->main_info.printer_layout, "image", ad->main_info.img_layout);
1857 evas_object_show(ad->main_info.img_layout);
1858 evas_object_show(ad->main_info.printer_layout);
1860 static char main_view_accessability_text[2048] = {0,};
1861 generate_main_view_accessability_info(ad, main_view_accessability_text, 2048);
1862 init_smsc_accessability_support(ad->main_info.smsc);
1863 set_main_view_accessability_info(ad->main_info.smsc, ad->main_info.img_layout,
1864 main_view_accessability_text,
1865 IDS_SCRREAD_PREVIEW_IMAGE_TYPE,
1866 IDS_SCRREAD_PREVIEW_IMAGE_CONTEXT);
1869 return ad->main_info.printer_layout;
1874 * setting button callback function
1876 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info)
1879 pts_appdata_t *ad = (pts_appdata_t *)data;
1880 PTS_RET_IF(ad == NULL, "ad is NULL");
1882 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1884 if (ad->list_info.active_printer) {
1885 pts_create_setting_view(ad);
1887 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1893 int pts_main_view_load_printing_data(pts_appdata_t *ad, pts_printing_data_t *printing_data)
1896 PTS_RETV_IF(ad == NULL || printing_data == NULL, -1, "Invalid argument");
1898 PTS_IF_FREE_MEM(ad->printing_data.request_files);
1899 PTS_IF_FREE_MEM(ad->printing_data.type);
1901 memset(&ad->printing_data, 0, sizeof(pts_printing_data_t));
1903 ad->printing_data.num_of_files = printing_data->num_of_files;
1904 ad->printing_data.current_index = printing_data->current_index;
1905 ad->printing_data.type = printing_data->type;
1906 ad->printing_data.request_files = (char **)malloc(sizeof(char *) * ad->printing_data.num_of_files);
1908 if (!ad->printing_data.request_files) {
1909 PTS_IF_FREE_MEM(ad->printing_data.type);
1910 //PTS_IF_FREE_MEM(ad->printing_data);
1911 PTS_DEBUG("calloc print files failed");
1917 for (i = 0; i < ad->printing_data.num_of_files; i++) {
1918 PTS_DEBUG("file path is %s", printing_data->request_files[i]);
1919 if (NULL != printing_data->request_files[i]) {
1920 ad->printing_data.request_files[i] = strdup(printing_data->request_files[i]);
1922 ad->printing_data.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
1924 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
1926 ad->printing_data.input_file = strdup(ad->printing_data.request_files[0]);
1927 PTS_DEBUG("ad->input_file: %s", ad->printing_data.input_file);
1929 PTS_DEBUG("count: %d", ad->printing_data.num_of_files);
1930 PTS_DEBUG("current index: %d", ad->printing_data.current_index);
1931 PTS_DEBUG("filetype: %s", ad->printing_data.type);
1933 /* init the print range(include all pages) */
1934 ad->printing_data.range.from = 1;
1935 ad->printing_data.range.to = ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1936 ad->printing_data.range.selected_files = NULL;
1943 * This function let the app update printer label in the preview view
1945 * @param[in] ugd the pointer to the main data structure
1947 void pts_main_view_update_printer_label(pts_appdata_t *ad)
1950 PTS_RET_IF(ad == NULL, "ad is NULL");
1952 char label_text[128] = {0,};
1953 char label_voice[128] = {0,};
1955 if (ad->main_info.printer_label == NULL) {
1956 ad->main_info.printer_label = elm_label_add(ad->main_info.printer_layout);
1958 PTS_DEBUG("ad->list_info.active_printer is %p", ad->list_info.active_printer);
1960 if (ad->list_info.active_printer != NULL) {
1961 char *printer_name = strdup(ad->list_info.active_printer->name);
1962 pts_unstandardization(printer_name);
1963 snprintf(label_text, 128, "<align=center>%s</align>", printer_name);
1964 snprintf(label_voice, 128, "%s", printer_name);
1965 if (printer_name != NULL) {
1967 printer_name = NULL;
1970 snprintf(label_text, 128, "<align=center>%s</align>", _("IDS_COM_BODY_NO_DEVICES"));
1971 snprintf(label_voice, 128, "%s", _("IDS_COM_BODY_NO_DEVICES"));
1974 elm_object_text_set(ad->main_info.printer_label, label_text);
1975 elm_access_info_set(ad->main_info.printer_label, ELM_ACCESS_INFO, label_voice);
1976 evas_object_size_hint_weight_set(ad->main_info.printer_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1977 evas_object_size_hint_align_set(ad->main_info.printer_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1979 elm_object_part_content_set(ad->main_info.printer_layout, "printer_name", ad->main_info.printer_label);
1985 * This function let the app rotate the image by the given landscape
1987 * @param[in] ugd the pointer to the main data structure
1988 * @param[in] landscape the landscape value
1990 void pts_main_view_rotate_image(pts_appdata_t *ad,
1991 app_device_orientation_e orientation)
1994 PTS_RET_IF(ad == NULL, "ad is NULL");
1996 generate_preview_images(ad, orientation);
2003 * This function let the app create the main screen view
2004 * @return Evas_Object
2005 * @param[in] win the pointer to the main window
2006 * @param[in] pt_files the pointer to the path of print files
2008 API Evas_Object *pts_create_main_view(pts_appdata_t *ad)
2011 PTS_RETV_IF((ad == NULL) || (ad->main_info.root_win == NULL), NULL, "Invalid argument");
2013 Evas_Object *main_layout = NULL;
2014 Evas_Object *back_btn = NULL;
2016 ad->main_info.main_layout = pts_create_base_layout_with_conform(ad->main_info.root_win, "navi");
2017 if (NULL == ad->main_info.main_layout) {
2018 //PTS_IF_FREE_MEM(ad);
2019 PTS_DEBUG("create base layout failed");
2024 ad->main_info.navi = elm_naviframe_add(ad->main_info.main_layout);
2025 elm_object_part_content_set(ad->main_info.main_layout, "navigation_bar", ad->main_info.navi);
2027 main_layout = __pts_main_view_create_content(ad);
2029 back_btn = pts_create_label_btn(ad->main_info.navi, _("IDS_COM_SK_BACK"));
2030 elm_access_info_set(back_btn, ELM_ACCESS_INFO, _("IDS_COM_SK_BACK"));
2031 elm_access_info_set(back_btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_PRINTING);
2032 elm_object_style_set(back_btn, "naviframe/back_btn/default");
2034 evas_object_smart_callback_add(back_btn, "clicked", __pts_main_view_btn_back_cb, ad);
2036 evas_object_event_callback_add(ad->main_info.navi, EVAS_CALLBACK_DEL, __pts_main_view_navi_delete_cb, ad);
2038 ad->main_info.navi_it = elm_naviframe_item_push(ad->main_info.navi, _("IDS_PRT_SK_PRINT_PREVIEW"), back_btn, NULL, main_layout, NULL);
2040 ad->main_info.print_btn = create_toolbar_btn(ad->main_info.navi, _("IDS_SMPOS_SK3_PRINT"), __pts_main_view_btn_print_cb, ad);
2041 elm_access_info_set(ad->main_info.print_btn, ELM_ACCESS_INFO, _("IDS_SMPOS_SK3_PRINT"));
2042 elm_access_info_set(ad->main_info.print_btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_PRINT_CONTEXT);
2043 elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar_button1", ad->main_info.print_btn);
2045 ad->main_info.more_btn = create_toolbar_more_btn(ad->main_info.navi, _more_btn_cb, ad->main_info.navi_it);
2046 elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar_more_btn", ad->main_info.more_btn);
2048 evas_object_event_callback_add(main_layout, EVAS_CALLBACK_DEL, __pts_main_view_delete_cb, ad);
2054 get_image_resolution(ad->printing_data.input_file, &tmp_width, &tmp_height);
2055 ad->size_popup_info.custom_width = (double)tmp_width;
2056 ad->size_popup_info.custom_height = (double)tmp_height;
2057 ad->size_popup_info.custom_w_ratio = ad->size_popup_info.custom_width / ad->size_popup_info.custom_height;
2058 PTS_DEBUG("Original image size : %lfx%lf(%lfx1)", ad->size_popup_info.custom_width, ad->size_popup_info.custom_height, ad->size_popup_info.custom_w_ratio);
2059 // original image size (unit cm) calculated by 300dpi
2060 ad->size_popup_info.custom_width = (ad->size_popup_info.custom_width / 300) * 2.54;
2061 ad->size_popup_info.custom_height = (ad->size_popup_info.custom_height / 300) * 2.54;
2062 ad->size_popup_info.custom_unit = 1; // cm unit
2065 return ad->main_info.main_layout;