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>
31 #include <efl_assist.h>
33 #include <page_preview.h>
34 #include <paper_size.h>
35 #include <previewgen.h>
38 #include "pts_common.h"
39 #include "pts_main_view.h"
40 #include "pts_setting_view.h"
41 #include "preview_content.h"
42 #include "preview_util.h"
45 #define MOBILEPRINT_PACKAGENAME "org.tizen.mobileprint"
46 #define ICON_DIR "/usr/apps/org.tizen.mobileprint/res/images"
47 #define ICON_SETTING "/usr/apps/org.tizen.mobileprint/res/images/pt_printer_setting.png"
48 #define MOBILEPRINT_DEFAULTIMG "/usr/share/icons/default/small/org.tizen.mobileprint.png"
49 #define MOBILEPRINT_TMP_STR "_mobileprint.pdf"
51 char *g_current_preview_path = NULL;
52 int g_pages_count = 0;
54 void _wifi_qs_monitoring_cb(keynode_t *key, void *data);
56 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info);
57 static Eina_Bool __pts_main_view_start_print(void *data);
59 static void __pts_main_view_check_usb_printer_online(void *userdata);
60 static void __pts_main_view_check_usb_printer_offline(void *userdata);
61 static void __pts_main_view_check_printer_online(void *userdata);
62 static void __pts_main_view_check_printer_offline(void *userdata);
63 static void __pts_main_view_remove_job(void *userdata, int job_id);
64 static void __pts_main_view_job_error(void *userdata, int job_id);
65 static void __pts_main_view_last_job_error(void *user_data);
66 static Eina_Bool __pts_hide_main_view(void *data);
67 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling);
69 static int __pts_get_real_total_pages(int original_total_pages, int n_up_number, int copies)
71 return (int)ceil((double)original_total_pages / (double)n_up_number) * copies;
74 static pts_job_spooling_t *__pts_get_job_spooling(pts_appdata_t *ad, int job_id)
77 PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
78 PTS_RETV_IF(job_id <= 0, NULL, "job_id is invalid(%d)", job_id);
80 Eina_List *job_spooling_list = NULL;
81 pts_job_spooling_t *job_spooling = NULL;
83 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
84 if (job_spooling->job_id == job_id) {
85 PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
90 PTS_RETV_IF(job_spooling == NULL, NULL, "job_spooling is NULL");
91 PTS_RETV_IF(job_spooling->job_id <= 0, NULL, "job_spooling->job_id is invalid(%d)", job_spooling->job_id);
96 static pts_job_spooling_t *__pts_get_last_job_spooling(pts_appdata_t *ad)
99 PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
101 Eina_List *job_spooling_list = NULL;
102 pts_job_spooling_t *job_spooling = NULL;
104 job_spooling_list = eina_list_last(ad->noti_info.job_spooling_list);
105 PTS_RETV_IF(job_spooling_list == NULL, NULL, "No found job_spooling_list for last job");
107 job_spooling = (pts_job_spooling_t *)eina_list_data_get(job_spooling_list);
108 PTS_RETV_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
109 , NULL, "No found job_spooling for last job");
115 int __pts_update_popup_progress(pts_appdata_t *ad, pt_progress_info_t *progress_info, pts_job_spooling_t *job_spooling)
118 PTS_RETV_IF(ad == NULL || ad->progress_info.progressbar == NULL || progress_info == NULL || job_spooling == NULL
119 , 1, "Invalid parameter for __pts_update_popup_progress");
121 PTS_DEBUG("progress popup [%d]\n", progress_info->progress);
122 double rate = progress_info->progress * 0.01;
123 char progress_value[8] = {0,};
124 char page_value[8] = {0,};
125 char aligned_label[128] = {0,};
126 int real_total_pages = -1;
128 if (EINA_TRUE == elm_progressbar_pulse_get(ad->progress_info.progressbar)) {
129 PTS_DEBUG("Stop pulsing mode\n");
130 elm_progressbar_pulse_set(ad->progress_info.progressbar, EINA_FALSE);
131 elm_object_style_set(ad->progress_info.progressbar, "list_progress");
132 elm_progressbar_value_set(ad->progress_info.progressbar, 0.00);
135 elm_progressbar_value_set(ad->progress_info.progressbar, rate);
138 snprintf(aligned_label, 128, "<align=center>%s</align>",
139 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
140 elm_object_text_set(ad->progress_info.progress_label, aligned_label);
143 snprintf(progress_value, 8, "%d%%", progress_info->progress);
144 elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext1", progress_value);
145 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
146 real_total_pages = 1;
148 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
149 job_spooling->n_up, job_spooling->copies);
151 if (job_spooling->page_printed <= real_total_pages) {
152 PTS_DEBUG("real_total_pages:%d, page_printed:%d\n", real_total_pages, job_spooling->page_printed);
153 snprintf(page_value, 8, "%d/%d", job_spooling->page_printed, real_total_pages);
154 elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext2", page_value);
157 if (rate >= 1.00 && job_spooling->page_printed == real_total_pages) {
158 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
159 PTS_IF_DEL_OBJ(ad->progress_info.popup);
160 PTS_IF_DEL_OBJ(ad->main_info.root_win);
167 int __pts_update_notification(pts_appdata_t *ad,
168 pt_progress_info_t *progress_info,
169 pts_job_spooling_t *job_spooling)
172 PTS_RETV_IF(ad == NULL || progress_info == NULL || job_spooling == NULL
173 , -1 ,"Invalid parameters for update_notification");
175 double rate = progress_info->progress * 0.01;
176 PTS_RETV_IF(job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE || job_spooling->noti_handle == NULL
177 , -1 , "Invalid noti parameters for update_notification");
179 // Remove notification after all page is printed
180 if (progress_info->page_printed > job_spooling->page_printed) {
181 if (job_spooling->noti_id != NOTIFICATION_PRIV_ID_NONE) {
183 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
184 PTS_DEBUG("Notification is deleted");
185 job_spooling->noti_id = NOTIFICATION_PRIV_ID_NONE;
186 ret = notification_free(job_spooling->noti_handle);
187 if (ret != NOTIFICATION_ERROR_NONE) {
188 PTS_DEBUG("Failed to free notification handle [%d]", ret);
190 job_spooling->noti_handle = NULL;
191 job_spooling->page_printed = progress_info->page_printed; // XXX
195 if (job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE && job_spooling->noti_handle == NULL) {
196 int real_total_pages = -1;
198 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
199 real_total_pages = 1;
201 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
202 job_spooling->n_up, job_spooling->copies);
204 if (job_spooling->page_printed <= real_total_pages) {
205 PTS_DEBUG("Create new notification for page %d", job_spooling->page_printed);
206 __pts_create_notification_by_page(ad, job_spooling);
212 notification_update_progress(NULL, job_spooling->noti_id, rate);
218 int __pts_remove_notification(int noti_id)
222 if (noti_id != NOTIFICATION_PRIV_ID_NONE) {
223 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, noti_id);
224 PTS_DEBUG("Notification is deleted");
231 int __pts_create_dummy_notification(pts_appdata_t *ad)
234 PTS_RETV_IF(ad == NULL, -1, "Invalid paramter for __pts_create_dummy_notification");
237 notification_h noti = NULL;
239 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
240 NOTIFICATION_GROUP_ID_NONE,
241 NOTIFICATION_PRIV_ID_NONE);
243 PTS_RETV_IF(noti == NULL, -1, "Failed to create Notification");
245 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"),
246 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
247 if (res != NOTIFICATION_ERROR_NONE) {
248 PTS_DEBUG("Failed to set Notification title [%d]", res);
252 char *printer_label = strdup(ad->list_info.active_printer->name);
253 pts_unstandardization(printer_label);
254 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
255 if (res != NOTIFICATION_ERROR_NONE) {
256 PTS_DEBUG("Failed to set Notification title [%d]", res);
259 if (printer_label != NULL) {
261 printer_label = NULL;
266 char value[4] = {0,};
268 if (!strcasecmp(ad->printing_data.type, "DOC") || !strcasecmp(ad->printing_data.type, "WEB")) {
269 PTS_DEBUG("It's pdf file. [%s]", ad->printing_data.type);
270 ad->printing_data.range.total_pages = get_pdf_pages_count(ad->printing_data.request_files[0]);
272 PTS_DEBUG("It's not pdf file. [%s]", ad->printing_data.type);
273 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
275 // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
276 int real_total_pages = -1;
277 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
278 real_total_pages = 1;
280 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
281 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
283 snprintf(value, 4, "%d", real_total_pages);
284 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
285 appsvc_add_data(b, SERVICE_FILES, ad->printing_data.request_files[0]);
286 appsvc_add_data(b, SERVICE_PAGE_COUNT, value);
287 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_DUMMY_NOTI);
289 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
290 if (res != NOTIFICATION_ERROR_NONE) {
291 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
296 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
297 if (res != NOTIFICATION_ERROR_NONE) {
298 PTS_DEBUG("Failed to set image icon");
302 res = notification_insert(noti, &(ad->noti_info.dummy_noti_id));
303 if (res != NOTIFICATION_ERROR_NONE) {
304 PTS_DEBUG("Failed to insert Notification [%d]", res);
307 PTS_DEBUG("Notification ID [%d]", ad->noti_info.dummy_noti_id);
313 if (printer_label != NULL) {
315 printer_label = NULL;
319 notification_free(noti);
332 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling)
335 PTS_RETV_IF(ad == NULL || job_spooling == NULL
336 , -1, "Invalid parameter for __pts_create_notification_by_page");
339 notification_h noti = NULL;
341 char title[32] = {0,};
343 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
344 NOTIFICATION_GROUP_ID_NONE,
345 NOTIFICATION_PRIV_ID_NONE);
348 PTS_DEBUG("Failed to create Notification");
352 //re-allocate noti handle
353 job_spooling->noti_handle = noti;
355 int real_total_pages = -1;
356 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
357 real_total_pages = 1;
359 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
360 job_spooling->n_up, job_spooling->copies);
362 snprintf(title, 32, "%s (%d/%d)",
363 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), job_spooling->page_printed, real_total_pages);
364 PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
366 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
367 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
368 if (res != NOTIFICATION_ERROR_NONE) {
369 PTS_DEBUG("Failed to set Notification title [%d]", res);
373 char *printer_label = strdup(ad->list_info.active_printer->name);
374 pts_unstandardization(printer_label);
375 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
376 if (res != NOTIFICATION_ERROR_NONE) {
377 PTS_DEBUG("Failed to set Notification title [%d]", res);
380 if (printer_label != NULL) {
382 printer_label = NULL;
385 res = notification_set_progress(noti, rate);
386 if (res != NOTIFICATION_ERROR_NONE) {
387 PTS_DEBUG("Failed to set Notification title [%d]", res);
393 char value1[4] = {0,};
394 char value2[4] = {0,};
395 snprintf(value1, 4, "%d", job_spooling->job_id);
396 snprintf(value2, 4, "%d", real_total_pages);
397 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
398 appsvc_add_data(b, SERVICE_JOB_ID, value1);
399 appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
400 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
402 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
403 if (res != NOTIFICATION_ERROR_NONE) {
404 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
409 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
410 if (res != NOTIFICATION_ERROR_NONE) {
411 PTS_DEBUG("Failed to set image icon");
415 res = notification_insert(noti, &job_spooling->noti_id);
416 if (res != NOTIFICATION_ERROR_NONE) {
417 PTS_DEBUG("Failed to insert Notification [%d]", res);
420 PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
426 if (printer_label != NULL) {
428 printer_label = NULL;
431 if (job_spooling->noti_handle != NULL) {
432 notification_free(job_spooling->noti_handle);
433 job_spooling->noti_handle = NULL;
445 int __pts_create_job_notification(pts_appdata_t *ad, int job_id)
448 PTS_RETV_IF(ad == NULL || job_id <=0
449 , -1 , "Invalid parameter for __pts_create_job_notification");
452 notification_h noti = NULL;
454 char title[32] = {0,};
456 pts_job_spooling_t *job_spooling = malloc(sizeof(pts_job_spooling_t));
457 PTS_RETV_IF(job_spooling == NULL, -1 , "Failed to malloc job_spooling");
458 memset(job_spooling, 0, sizeof(pts_job_spooling_t));
460 //FIXME - pt_files.files should be managed carefully during printing
461 job_spooling->pt_files.num_of_files = ad->printing_data.num_of_files;
462 job_spooling->pt_files.current_index = ad->printing_data.current_index;
464 job_spooling->pt_files.type = strdup(ad->printing_data.type); // need malloc
465 if (job_spooling->pt_files.type == NULL) {
466 PTS_DEBUG("Failed to malloc job_spooling->pt_files.type");
470 job_spooling->pt_files.request_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.num_of_files);
471 if (job_spooling->pt_files.request_files == NULL) {
472 PTS_DEBUG("Failed to malloc job_spooling->pt_files.request_files");
476 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
477 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
478 if (NULL != ad->printing_data.request_files[i]) {
479 job_spooling->pt_files.request_files[i] = strdup(ad->printing_data.request_files[i]);
481 job_spooling->pt_files.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
483 PTS_DEBUG("file path is %s", job_spooling->pt_files.request_files[i]);
486 job_spooling->input_file = strdup(job_spooling->pt_files.request_files[0]);
487 if (job_spooling->input_file == NULL) {
488 PTS_DEBUG("Failed to malloc job_spooling->input_file");
492 job_spooling->pt_files.range.from = ad->printing_data.range.from;
493 job_spooling->pt_files.range.to = ad->printing_data.range.to;
494 job_spooling->pt_files.range.total_pages = ad->printing_data.range.total_pages;
496 job_spooling->pt_files.range.selected_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.range.total_pages);
497 if (job_spooling->pt_files.range.selected_files == NULL) {
498 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files");
502 job_spooling->pt_files.range.selected_files[0] = strdup(ad->printing_data.range.selected_files[0]);
503 if (job_spooling->pt_files.range.selected_files[0] == NULL) {
504 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files[0]");
508 job_spooling->job_id = job_id;
509 #if 0 // Need to believe passed "Printing page X X" log have correct information.
510 if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
511 job_spooling->page_printed = 1; // FIXME
515 noti = notification_new(NOTIFICATION_TYPE_ONGOING,
516 NOTIFICATION_GROUP_ID_NONE,
517 NOTIFICATION_PRIV_ID_NONE);
519 PTS_DEBUG("Failed to create Notification");
523 job_spooling->noti_handle = noti;
525 job_spooling->n_up = printer_get_setting_n_up(ad->list_info.active_printer);
527 job_spooling->copies = ad->list_info.active_printer->copies;
529 int real_total_pages = -1;
530 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
531 real_total_pages = 1;
533 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
534 job_spooling->n_up, job_spooling->copies);
536 snprintf(title, 32, "%s (1/%d)", _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), real_total_pages);
537 PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
539 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
540 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
541 if (res != NOTIFICATION_ERROR_NONE) {
542 PTS_DEBUG("Failed to set Notification title [%d]", res);
546 char *printer_label = strdup(ad->list_info.active_printer->name);
547 pts_unstandardization(printer_label);
548 res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
549 if (res != NOTIFICATION_ERROR_NONE) {
550 PTS_DEBUG("Failed to set Notification title [%d]", res);
553 if (printer_label != NULL) {
555 printer_label = NULL;
558 res = notification_set_progress(noti, rate);
559 if (res != NOTIFICATION_ERROR_NONE) {
560 PTS_DEBUG("Failed to set Notification title [%d]", res);
566 char value1[4] = {0,};
567 char value2[4] = {0,};
568 snprintf(value1, 4, "%d", job_id);
569 snprintf(value2, 4, "%d", real_total_pages);
570 appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
571 appsvc_add_data(b, SERVICE_JOB_ID, value1);
572 appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
573 appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
575 res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
576 if (res != NOTIFICATION_ERROR_NONE) {
577 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
583 res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
584 if (res != NOTIFICATION_ERROR_NONE) {
585 PTS_DEBUG("Failed to set image icon");
589 res = notification_insert(noti, &job_spooling->noti_id);
590 if (res != NOTIFICATION_ERROR_NONE) {
591 PTS_DEBUG("Failed to insert Notification [%d]", res);
594 PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
596 ad->noti_info.job_spooling_list = eina_list_append(ad->noti_info.job_spooling_list, job_spooling);
597 if (eina_error_get()) {
598 PTS_DEBUG("Failed to append job_spooling");
607 if (printer_label != NULL) {
609 printer_label = NULL;
612 if (job_spooling != NULL) {
613 if (job_spooling->pt_files.type != NULL) {
614 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
615 job_spooling->pt_files.type = NULL;
618 if (job_spooling->pt_files.request_files != NULL) {
620 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
621 if (job_spooling->pt_files.request_files[i] != NULL) {
622 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]);
623 job_spooling->pt_files.request_files[i] = NULL;
626 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files);
627 job_spooling->pt_files.request_files = NULL;
630 if (job_spooling->input_file != NULL) {
631 PTS_IF_FREE_MEM(job_spooling->input_file);
632 job_spooling->input_file = NULL;
635 if (job_spooling->pt_files.range.selected_files != NULL) {
636 if (job_spooling->pt_files.range.selected_files[0] != NULL) {
637 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
638 job_spooling->pt_files.range.selected_files[0] = NULL;
641 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
642 job_spooling->pt_files.range.selected_files = NULL;
645 if (job_spooling->noti_handle != NULL) {
646 notification_free(job_spooling->noti_handle);
647 job_spooling->noti_handle = NULL;
650 PTS_IF_FREE_MEM(job_spooling);
658 static gboolean __pts_main_view_job_monitor_timeout_cb(void *data)
661 pts_appdata_t *ad = (pts_appdata_t *)data;
662 PTS_RETV_IF(ad == NULL, TRUE, "ad is NULL");
664 pt_job_state_e job_status = PT_JOB_ERROR;
665 gboolean ret = FALSE;
667 //char noti_name[512] = {0};
669 //FIXME - need to check one or all?
670 Eina_List *job_spooling_list = NULL;
671 pts_job_spooling_t *job_spooling = NULL;
672 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
673 job_status = pt_get_current_job_status(job_spooling->job_id);
674 if (job_status == PT_JOB_PROCESSING || job_status == PT_JOB_PENDING) {
675 PTS_DEBUG("job_id[%d] status is %d", job_spooling->job_id, job_status);
676 //XXX - If any one of job list is processing or pending, then motinor cb will be called again.
686 void __pts_event_cb(pt_event_e event, void *user_data, pt_progress_info_t *progress_info)
690 // XXX - progress_info can be passed by NULL
691 PTS_RET_IF(event < 0 || user_data == NULL, "Invalid parameters for event cb");
693 pts_appdata_t *ad = (pts_appdata_t *)user_data;
694 pts_job_spooling_t *job_spooling = NULL;
697 case PT_EVENT_USB_PRINTER_ONLINE:
698 __pts_main_view_check_usb_printer_online(ad);
700 case PT_EVENT_USB_PRINTER_OFFLINE:
701 __pts_main_view_check_usb_printer_offline(ad);
703 case PT_EVENT_PRINTER_ONLINE:
704 __pts_main_view_check_printer_online(ad);
706 case PT_EVENT_PRINTER_OFFLINE:
707 __pts_main_view_check_printer_offline(ad);
709 case PT_EVENT_JOB_COMPLETED:
710 PTS_DEBUG("Job[%d] is completed.", progress_info->job_id);
711 __pts_main_view_remove_job(ad, progress_info->job_id);
713 case PT_EVENT_JOB_STARTED:
714 PTS_DEBUG("Job id %d is allocated", progress_info->job_id);
715 __pts_remove_notification(ad->noti_info.dummy_noti_id);
716 ad->noti_info.dummy_noti_id = 0;
717 __pts_create_job_notification(ad, progress_info->job_id);
718 g_timeout_add(5000, (GSourceFunc)__pts_main_view_job_monitor_timeout_cb, ad);
720 case PT_EVENT_JOB_PROCESSING:
721 PTS_DEBUG("Job[%d] is processing.", progress_info->job_id);
723 case PT_EVENT_JOB_PROGRESS:
724 job_spooling = __pts_get_job_spooling(ad, progress_info->job_id);
725 if (job_spooling != NULL) {
726 PTS_DEBUG("new - progress_info: job_id[%d] progress[%d] page_printed[%d]\n"
727 "old - job_spooling: job_id[%d] progress[%d] page_printed[%d]",
728 progress_info->job_id, progress_info->progress, progress_info->page_printed,
729 job_spooling->job_id, job_spooling->progress, job_spooling->page_printed);
733 if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
734 if (progress_info->progress < job_spooling->progress) {
735 //FIXME - assume next page printing is started
736 job_spooling->page_printed++;
741 job_spooling->progress = progress_info->progress;
743 __pts_update_notification(ad, progress_info, job_spooling);
744 __pts_update_popup_progress(ad, progress_info, job_spooling);
746 case PT_EVENT_JOB_PENDING:
747 PTS_DEBUG("Job[%d] is waiting.", progress_info->job_id);
749 case PT_EVENT_JOB_HELD:
750 PTS_DEBUG("Job[%d] is held.", progress_info->job_id);
752 case PT_EVENT_JOB_STOPPED:
753 PTS_DEBUG("Job[%d] is stopped.", progress_info->job_id);
754 __pts_main_view_job_error(ad, progress_info->job_id);
755 __pts_main_view_remove_job(ad, progress_info->job_id);
757 case PT_EVENT_JOB_CANCELED:
758 PTS_DEBUG("Job[%d] is canceled.", progress_info->job_id);
759 __pts_main_view_job_error(ad, progress_info->job_id);
760 __pts_main_view_remove_job(ad, progress_info->job_id);
762 case PT_EVENT_JOB_ABORTED:
763 PTS_DEBUG("Job[%d] is aborted.", progress_info->job_id);
764 if (progress_info->job_id > 0) {
765 __pts_main_view_job_error(ad, progress_info->job_id);
766 __pts_main_view_remove_job(ad, progress_info->job_id);
767 } else { // XXX - for dummy job?
768 __pts_main_view_last_job_error(ad);
771 case PT_EVENT_JOB_ERROR:
772 PTS_DEBUG("Job[%d] error", progress_info->job_id);
773 __pts_main_view_job_error(ad, progress_info->job_id);
774 __pts_main_view_remove_job(ad, progress_info->job_id);
776 case PT_EVENT_ALL_THREAD_COMPLETED:
777 PTS_DEBUG("All thread is completed.");
778 PTS_DEBUG("No more job, then terminate mobileprint");
779 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
790 static void __pts_main_view_check_usb_printer_online(void *userdata)
793 pts_appdata_t *ad = (pts_appdata_t *)userdata;
794 PTS_RET_IF(ad == NULL, "ad is NULL");
796 /* if in ether searching or printing, ignore it */
797 PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
799 PTS_IF_DEL_OBJ(ad->progress_info.popup);
801 elm_naviframe_item_pop_to(ad->main_info.navi_it);
803 /* re-searching printers */
804 ad->search_info.print_search_mode = PTS_SEARCH_INITIAL;
805 ad->search_info.selection_done_cb = load_main_view;
806 ad->search_info.print_search_popup_parent = ad->main_info.root_win;
807 ad->search_info.printer_search_user_data = NULL;
808 pts_search_printer(ad);
809 //pts_main_view_search_printer(ugd);
814 static void __pts_main_view_check_usb_printer_offline(void *userdata)
817 pts_appdata_t *ad = (pts_appdata_t *)userdata;
818 PTS_RET_IF(ad == NULL, "ad is NULL");
820 /* if in searching or printing, return */
821 PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
822 PTS_IF_DEL_OBJ(ad->progress_info.popup);
823 PTS_IF_FREE_MEM(ad->list_info.active_printer);
825 elm_naviframe_item_pop_to(ad->main_info.navi_it);
827 pts_main_view_update_printer_label(ad);
832 static void __pts_main_view_remove_job(void *user_data, int job_id)
835 PTS_RET_IF(user_data == NULL || job_id <= 0,"Invalid parameter for job error processing");
837 pts_appdata_t *ad = (pts_appdata_t *)user_data;
840 if (NULL != ad->progress_info.popup) {
841 evas_object_del(ad->progress_info.popup);
842 ad->progress_info.popup = NULL;
843 evas_object_hide(ad->main_info.root_win);
846 Eina_List *job_spooling_list = NULL;
847 pts_job_spooling_t *job_spooling = NULL;
849 EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
850 if (job_spooling->job_id == job_id) {
851 PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
856 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
857 ,"No found job_spooling for job_id[%d]\n", job_id);
859 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
860 ad->search_info.is_process = 0;/*process is complete*/
862 ad->noti_info.job_spooling_list = eina_list_remove_list(ad->noti_info.job_spooling_list, job_spooling_list);
863 if (0 == eina_list_count(ad->noti_info.job_spooling_list)) {
864 PTS_DEBUG("Job spooling list is empty");
865 ad->noti_info.job_spooling_list = NULL;
868 if (job_spooling->noti_handle != NULL) {
869 ret = notification_free(job_spooling->noti_handle);
870 if (ret != NOTIFICATION_ERROR_NONE) {
871 PTS_DEBUG("Failed to free notification handle [%d]", ret);
873 job_spooling->noti_handle = NULL;
876 PTS_RET_IF(job_spooling->pt_files.range.selected_files == NULL, "job_spooling->pt_files.range.selected_files is NULL");
878 if (job_spooling->pt_files.range.selected_files[0]) {
879 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
880 job_spooling->pt_files.range.selected_files[0] = NULL;
883 if (job_spooling->pt_files.range.selected_files) {
884 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
885 job_spooling->pt_files.range.selected_files = NULL;
888 if (job_spooling->input_file) {
889 PTS_IF_FREE_MEM(job_spooling->input_file);
890 job_spooling->input_file = NULL;
894 for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
895 if (job_spooling->pt_files.request_files[i]) {
896 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]); // FIXME
897 job_spooling->pt_files.request_files[i] = NULL;
901 if (job_spooling->pt_files.request_files) {
902 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files); // FIXME
903 job_spooling->pt_files.request_files = NULL;
906 if (job_spooling->pt_files.type) {
907 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
908 job_spooling->pt_files.type = NULL;
912 PTS_IF_FREE_MEM(job_spooling);
919 static void __pts_main_view_job_error(void *user_data, int job_id)
922 PTS_RET_IF(user_data == NULL || job_id <= 0, "Invalid parameter for job error processing");
924 pts_appdata_t *ad = (pts_appdata_t *)user_data;
925 PTS_IF_DEL_OBJ(ad->progress_info.popup);
927 pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
929 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
930 , "No found job_spooling for job_id[%d]\n", job_id);
932 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
933 ad->search_info.is_process = 0;/*process is complete*/
934 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
935 evas_object_show(ad->main_info.root_win);
936 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
940 static void __pts_main_view_last_job_error(void *user_data)
943 PTS_RET_IF(user_data == NULL, "Invalid parameter for last job error processing");
945 pts_appdata_t *ad = (pts_appdata_t *)user_data;
946 PTS_IF_DEL_OBJ(ad->progress_info.popup);
948 pts_job_spooling_t *job_spooling = __pts_get_last_job_spooling(ad);
949 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
950 , "No found job_spooling for last_job");
952 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
953 ad->search_info.is_process = 0;/*process is complete*/
954 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
955 evas_object_show(ad->main_info.root_win);
956 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
961 static void __pts_main_view_check_printer_online(void *user_data)
964 PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_online");
966 pts_appdata_t *ad = (pts_appdata_t *)user_data;
967 ecore_timer_add(1.0, (Ecore_Task_Cb)__pts_main_view_start_print, ad);
972 static void __pts_main_view_check_printer_offline(void *user_data)
975 PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_offline");
977 pts_appdata_t *ad = (pts_appdata_t *)user_data;
978 PTS_IF_DEL_OBJ(ad->progress_info.popup);
979 PTS_IF_FREE_MEM(ad->list_info.active_printer);
981 pts_main_view_update_printer_label(ad);
982 pts_create_popup(ad->main_info.navi, _("IDS_PRT_POP_CHECKPRINTERSTATE"), 2.0);
983 ad->search_info.is_process = 0;/* process is complete */
988 static void __pts_main_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
991 pts_appdata_t *ad = (pts_appdata_t *)data;
992 PTS_RET_IF(ad == NULL, "ad is NULL");
995 if (NULL != ugd->pt_files.request_files) {
997 for (i = 0; i < ugd->pt_files.num_of_files; i++) {
998 if (ugd->pt_files.request_files[i] != NULL) {
999 free(ugd->pt_files.request_files[i]);
1000 ugd->pt_files.request_files[i] = NULL;
1004 if (ugd->pt_files.range.selected_files != NULL) {
1005 free(ugd->pt_files.range.selected_files);
1006 ugd->pt_files.range.selected_files = NULL;
1009 free(ugd->pt_files.request_files);
1010 ugd->pt_files.request_files = NULL;
1017 static void __pts_main_view_navi_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1020 pts_appdata_t *ad = (pts_appdata_t *)data;
1021 PTS_RET_IF(ad == NULL, "ad is NULL");
1023 PTS_IF_FREE_MEM(ad->list_info.active_printer);
1029 * "back" button callback
1031 void __pts_main_view_btn_back_cb(void *data, Evas_Object *obj, void *event_info)
1034 pts_appdata_t *ad = (pts_appdata_t *) data;
1035 PTS_RET_IF(ad == NULL, "ad is NULL");
1036 //TODO - check current spooling job status before app termination
1037 if (ad->noti_info.job_spooling_list == NULL) {
1038 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
1042 PTS_DEBUG("Active job spooling list is existed. So just hide preview.");
1043 __pts_hide_main_view(ad);
1048 static void __pts_main_view_dummy_cancel_print(void *data, Evas_Object *obj, void *event_info)
1052 pts_appdata_t *ad = pts_get_appdata();
1053 PTS_RET_IF(ad == NULL, "ad is NULL");
1055 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1056 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1058 pts_create_popup(ad->main_info.root_win, PTS_19, 2.0);
1059 evas_object_show(ad->main_info.root_win);
1060 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1065 static void __pts_main_view_response_cancel_print(void *data, Evas_Object *obj, void *event_info)
1068 int job_id = (int)data;
1069 pts_appdata_t *ad = pts_get_appdata();
1070 PTS_RET_IF(ad == NULL || job_id <= 0, "Invalid parameter for __pts_main_view_response_cancel_print");
1071 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1072 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1074 pt_cancel_print(job_id);
1076 pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
1077 PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
1078 , "No found job_spooling for job[%d]\n", job_id);
1080 // FIXME - Is it better to do this job after received canceled evt_cb?
1081 __pts_remove_notification(job_spooling->noti_id);
1083 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTING_CANCELED"), 2.0);
1084 evas_object_show(ad->main_info.root_win);
1085 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1090 static void __pts_hide_progress_popup(void *data, Evas_Object *obj, void *event_info)
1093 pts_appdata_t *ad = (pts_appdata_t *)data;
1094 PTS_RET_IF(ad == NULL, "ad is NULL");
1096 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1097 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1099 evas_object_hide(ad->main_info.root_win);
1104 void __pts_print_dummy_popup(pts_appdata_t *ad, char *files, int page_count)
1107 PTS_RET_IF(ad == NULL || files == NULL || page_count <= 0, "Invalid parameters for progress_popup");
1109 Evas_Object *label1 = NULL;
1110 Evas_Object *label2 = NULL;
1111 Evas_Object *label3 = NULL;
1112 Evas_Object *popup = NULL;
1113 Evas_Object *layout = NULL;
1114 Evas_Object *progressbar = NULL;
1115 char page_info[8] = {0,};
1116 char aligned_label[128] = {0,};
1118 popup = elm_popup_add(ad->main_info.main_layout);
1120 label1 = elm_label_add(popup);
1121 elm_object_style_set(label1, "popup/progressview");
1122 elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1123 char *printer_label = strdup(ad->list_info.active_printer->name);
1124 pts_unstandardization(printer_label);
1125 snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1126 elm_object_text_set(label1, aligned_label);
1127 if (printer_label != NULL) {
1128 /* accessability - screen reader support */
1129 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1130 free(printer_label);
1131 printer_label = NULL;
1133 evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1134 evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1135 evas_object_show(label1);
1137 label2 = elm_label_add(popup);
1138 elm_object_style_set(label2, "popup/progressview");
1139 elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1140 snprintf(aligned_label, 128, "<align=center>%s</align>",
1141 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1142 elm_object_text_set(label2, aligned_label);
1143 /* accessability - screen reader support */
1144 elm_access_info_set(label2, ELM_ACCESS_INFO, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1145 evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1146 evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1147 evas_object_show(label2);
1149 label3 = elm_label_add(popup);
1150 elm_object_style_set(label3, "popup/progressview");
1151 elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1152 snprintf(aligned_label, 128, "<align=center>%s</align>", basename(files));
1153 elm_object_text_set(label3, aligned_label);
1154 /* accessability - screen reader support */
1155 elm_access_info_set(label3, ELM_ACCESS_INFO, basename(files));
1156 evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1157 evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1158 evas_object_show(label3);
1160 layout = pts_create_base_layout(popup, "popup_progress");
1162 progressbar = elm_progressbar_add(popup);
1163 elm_object_style_set(progressbar, "pending_list");
1164 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1165 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1166 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1167 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1168 evas_object_show(progressbar);
1170 ad->progress_info.progress_label = label2;
1171 ad->progress_info.progress_layout = layout;
1172 ad->progress_info.progressbar = progressbar;
1174 elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1175 elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1176 elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1177 elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1178 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1179 // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
1180 int real_total_pages = -1;
1181 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1182 real_total_pages = 1;
1184 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
1185 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
1187 snprintf(page_info, 8, "1/%d", real_total_pages);
1188 elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1190 Evas_Object *btn1 = NULL;
1191 btn1 = elm_button_add(popup);
1192 elm_object_style_set(btn1,"popup_button/default");
1193 elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1194 elm_object_part_content_set(popup, "button1", btn1);
1195 evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1197 if (page_count > 1) {
1198 Evas_Object *btn2 = NULL;
1199 btn2 = elm_button_add(popup);
1200 elm_object_style_set(btn2,"popup_button/default");
1201 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1202 elm_object_part_content_set(popup, "button2", btn2);
1203 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_dummy_cancel_print, NULL);
1206 elm_object_content_set(popup, layout);
1207 evas_object_show(popup);
1208 evas_object_show(ad->main_info.root_win);
1210 ad->progress_info.popup = popup;
1216 void __pts_print_progress_popup(pts_appdata_t *ad, int job_id, int page_count)
1219 PTS_RET_IF(ad == NULL || job_id <= 0 || page_count <= 0, "Invalid parameters for progress_popup");
1221 pts_job_spooling_t *job_spooling = NULL;
1222 job_spooling = __pts_get_job_spooling(ad, job_id);
1223 PTS_RET_IF(job_spooling == NULL, "No found job_spooling for job_id[%d]", job_id);
1225 Evas_Object *label1 = NULL;
1226 Evas_Object *label2 = NULL;
1227 Evas_Object *label3 = NULL;
1228 Evas_Object *popup = NULL;
1229 Evas_Object *layout = NULL;
1230 Evas_Object *progressbar = NULL;
1231 char progress_info[8] = {0,};
1232 char page_info[8] = {0,};
1233 char aligned_label[128] = {0,};
1235 popup = elm_popup_add(ad->main_info.main_layout);
1237 label1 = elm_label_add(popup);
1238 elm_object_style_set(label1, "popup/progressview");
1239 elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1240 char *printer_label = strdup(ad->list_info.active_printer->name);
1241 pts_unstandardization(printer_label);
1242 snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1243 elm_object_text_set(label1, aligned_label);
1244 if (printer_label != NULL) {
1245 /* accessability - screen reader support */
1246 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1248 free(printer_label);
1249 printer_label = NULL;
1251 evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1252 evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1253 evas_object_show(label1);
1255 label2 = elm_label_add(popup);
1256 elm_object_style_set(label2, "popup/progressview");
1257 elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1258 if (job_spooling->progress > 0) {
1259 snprintf(aligned_label, 128, "<align=center>%s</align>",
1260 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1261 /* accessability - screen reader support */
1262 elm_access_info_set(label2, ELM_ACCESS_INFO,
1263 _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1265 snprintf(aligned_label, 128, "<align=center>%s</align>",
1266 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1267 /* accessability - screen reader support */
1268 elm_access_info_set(label2, ELM_ACCESS_INFO,
1269 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1271 elm_object_text_set(label2, aligned_label);
1272 evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1273 evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1274 evas_object_show(label2);
1276 label3 = elm_label_add(popup);
1277 elm_object_style_set(label3, "popup/progressview");
1278 elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1279 char* label3_text = basename(job_spooling->pt_files.request_files[0]);
1280 snprintf(aligned_label, 128, "<align=center>%s</align>",
1282 elm_object_text_set(label3, aligned_label);
1283 /* accessability - screen reader support */
1284 elm_access_info_set(label3, ELM_ACCESS_INFO, label3_text);
1286 evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1287 evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1288 evas_object_show(label3);
1290 layout = pts_create_base_layout(popup, "popup_progress");
1291 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1293 progressbar = elm_progressbar_add(popup);
1294 if (job_spooling->progress > 0) {
1295 double rate = job_spooling->progress * 0.01;
1296 elm_object_style_set(progressbar, "list_progress");
1297 elm_progressbar_value_set(progressbar, rate);
1299 elm_object_style_set(progressbar, "pending_list");
1300 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1302 elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1303 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1304 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1305 evas_object_show(progressbar);
1307 ad->progress_info.progress_label = label2;
1308 ad->progress_info.progress_layout = layout;
1309 ad->progress_info.progressbar = progressbar;
1311 elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1312 elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1313 elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1314 elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1315 if (job_spooling->progress > 0) {
1316 snprintf(progress_info, 8, "%d%%", job_spooling->progress);
1317 elm_object_part_text_set(layout, "elm.text.subtext1", progress_info);
1319 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1321 snprintf(page_info, 8, "%d/%d", job_spooling->page_printed, page_count);
1322 elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1324 Evas_Object *btn1 = NULL;
1325 btn1 = elm_button_add(popup);
1326 elm_object_style_set(btn1,"popup_button/default");
1327 elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1328 elm_object_part_content_set(popup, "button1", btn1);
1329 evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1331 // Show cancel button when total page is greater than 1 page.
1332 // if (page_count > 1) {
1333 Evas_Object *btn2 = NULL;
1334 btn2 = elm_button_add(popup);
1335 elm_object_style_set(btn2,"popup_button/default");
1336 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1337 elm_object_part_content_set(popup, "button2", btn2);
1338 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_response_cancel_print, (void *)job_id);
1339 elm_access_info_set(btn2, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_PRINTING);
1342 elm_object_content_set(popup, layout);
1343 evas_object_show(popup);
1344 evas_object_show(ad->main_info.root_win);
1346 ad->progress_info.popup = popup;
1351 static Eina_Bool __pts_is_valid_printing_data(pts_appdata_t *ad)
1353 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1354 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1356 if (ad->list_info.active_printer->copies <= 0) {
1357 ad->list_info.active_printer->copies = 1;
1358 PTS_DEBUG("copies is less than 0(%d)", ad->list_info.active_printer->copies);
1362 /* get the range of print files */
1363 if (ad->printing_data.range.from <= 0 ||
1364 ad->printing_data.range.to > ad->printing_data.range.total_pages ||
1365 ad->printing_data.range.from > ad->printing_data.range.to) {
1366 PTS_DEBUG("from(%d) to(%d) total(%d)"
1367 ,ad->printing_data.range.from
1368 ,ad->printing_data.range.to
1369 ,ad->printing_data.range.total_pages);
1370 PTS_DEBUG("range checking error");
1377 static Eina_Bool __pts_set_print_option_page_range(pts_appdata_t *ad)
1379 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1381 char temp[1024] = {0,};
1384 if(_is_pdf_file_type(ad->printing_data.request_files, ad->printing_data.num_of_files) == true) {
1385 for (index = 0 ; index < ad->printing_data.num_of_files ; index++) {
1386 ad->printing_data.range.total_pages += get_pdf_pages_count(ad->printing_data.request_files[index]);
1389 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1392 PTS_DEBUG("Updated ad->printing_data.range.total_pages: %d", ad->printing_data.range.total_pages);
1393 ad->printing_data.range.to = ad->printing_data.range.total_pages;
1395 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1396 ad->printing_data.range.from = ad->printing_data.range.to = evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1;
1397 snprintf(temp, sizeof(temp), "%d", ad->printing_data.range.from);
1398 pt_set_print_option_page_range(temp);
1399 PTS_DEBUG("Set current page[%d] printing", ad->printing_data.range.from);
1405 static Eina_Bool __pts_set_print_scale_size(pts_appdata_t *ad)
1407 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1410 char *first_fname = NULL;
1412 PTS_IF_FREE_MEM(ad->printing_data.range.selected_files);
1413 //FIXME - multiple page pdf will be changed to several image files.
1414 num = ad->printing_data.range.total_pages;
1415 ad->printing_data.range.selected_files = (char **)malloc(sizeof(char *)*num);
1417 if (NULL == ad->printing_data.range.selected_files) {
1418 PTS_DEBUG("selected_files malloc error");
1422 first_fname = ad->printing_data.request_files[ad->printing_data.range.from - 1];
1423 if (1 == num && FILE_TYPE_IMAGE == get_file_type(first_fname)) {
1426 if (get_image_resolution(first_fname, &res_x, &res_y) < 0) {
1427 PTS_DEBUG("[ERROR] Failed to get image resolution(%s)",first_fname);
1430 pt_imagesize_t crop_image_info;
1431 crop_image_info.imagesize = ad->size_popup_info.image_size;
1432 crop_image_info.resolution_width = ad->size_popup_info.custom_width;
1433 crop_image_info.resolution_height = ad->size_popup_info.custom_height;
1434 crop_image_info.ratio = ad->size_popup_info.custom_w_ratio;
1435 crop_image_info.unit = ad->size_popup_info.custom_unit;
1437 pt_set_print_option_imagesize(&crop_image_info, first_fname, res_x, res_y);
1438 ad->printing_data.range.selected_files[0] = ad->printing_data.request_files[0];
1440 pt_set_print_option_scaleimage(ad->list_info.active_printer->scaling);
1442 ad->printing_data.range.selected_files[0] = ad->printing_data.input_file;
1448 static Eina_Bool __pts_set_print_options(pts_appdata_t *ad)
1450 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1451 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1453 Eina_Bool eret = EINA_FALSE;
1455 eret = __pts_set_print_option_page_range(ad);
1456 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set page ragnge");
1458 pt_set_print_option_papersize(); //(ugd->active_printer->size);
1459 pt_set_print_option_copies(ad->list_info.active_printer->copies);
1460 // pt_set_print_option_scaleimage(ugd->active_printer->scaling);
1461 pt_set_print_option_orientation(ad->list_info.active_printer->landscape);
1462 // FIXME : which field of ppd structure sholud be used for this?
1463 pt_set_print_option_quality();
1464 pt_set_print_option_paper_type();
1465 pt_set_print_option_color();
1466 pt_set_print_option_duplex(ad->list_info.active_printer->landscape);
1467 eret = __pts_set_print_scale_size(ad);
1468 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print scale size");
1473 static Eina_Bool __pts_set_active_printer(pts_appdata_t *ad)
1475 PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1476 PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1480 if (1 != ad->list_info.active_printer->actived) {
1481 /* use default printer, needs active */
1482 ret = pt_set_active_printer(ad->list_info.active_printer);
1483 if (PT_ERR_NONE != ret) {
1484 PTS_DEBUG("pt_set_active_printer error");
1492 static Eina_Bool __pts_main_view_start_print(void *data)
1495 pts_appdata_t *ad = (pts_appdata_t *)data;
1496 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
1501 Eina_Bool eret = EINA_FALSE;
1502 eret = __pts_set_print_options(ad);
1503 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print option");
1505 eret = __pts_is_valid_printing_data(ad);
1506 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "It's not valid printing data");
1508 eret = __pts_set_active_printer(ad);
1509 PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set active printer");
1511 __pts_create_dummy_notification(ad);
1513 ret = pt_start_print((const char **)ad->printing_data.range.selected_files, num);
1514 if (PT_ERR_NONE != ret) {
1515 PTS_DEBUG("pt_start_print error");
1520 return ECORE_CALLBACK_CANCEL;
1523 ad->search_info.is_process = 0;/*process is complete*/
1525 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1527 if ((PT_ERR_NOT_USB_ACCESS == ret) || (PT_ERR_NOT_NETWORK_ACCESS == ret)) {
1528 pts_create_popup(ad->main_info.navi, _("IDS_COM_POP_PRINTER_DISCONNECTED_ABB2"), 2.0);
1530 pts_create_popup(ad->main_info.navi, _("IDS_COM_BODY_UNSUPPORTED_FILE_TYPE"), 1.0);
1532 return ECORE_CALLBACK_CANCEL;
1535 static Eina_Bool __pts_hide_main_view(void *data)
1538 pts_appdata_t *ad = (pts_appdata_t *) data;
1539 PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "data is NULL");
1541 PTS_IF_DEL_OBJ(ad->progress_info.popup);
1542 PTS_DEBUG("Hide main view of mobileprint");
1543 evas_object_hide(ad->main_info.root_win);
1546 return ECORE_CALLBACK_CANCEL;
1550 * "print" button callback
1552 static void __pts_main_view_btn_print_cb(void *data, Evas_Object *obj, void *event_info)
1555 pts_appdata_t *ad = (pts_appdata_t *)data ;
1556 PTS_RET_IF(ad == NULL, "ad is NULL");
1558 if ((NULL != ad->printing_data.request_files) && (NULL != ad->list_info.active_printer)) {
1559 evas_object_hide(ad->main_info.main_layout);
1560 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PREPARING_TO_PRINT_ING"), 2.0);
1561 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1563 ad->search_info.is_process = 1;/* in process */
1564 __pts_main_view_start_print(ad);
1566 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_SELECT_PRINTER"), 2.0);
1571 static void __pts_main_view_btn_size_cb(void *data, Evas_Object *obj, void *event_info)
1574 pts_appdata_t *ad = (pts_appdata_t *)data;
1575 PTS_RET_IF(ad == NULL, "ad is NULL");
1577 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1579 if (ad->list_info.active_printer) {
1580 pts_create_size_popup(ad->main_info.navi, ad);
1582 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1588 static void __pts_main_view_btn_scaling_cb(void *data, Evas_Object *obj, void *event_info)
1591 pts_appdata_t *ad = (pts_appdata_t *)data;
1592 PTS_RET_IF(ad == NULL, "ad is NULL");
1594 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1596 if (ad->list_info.active_printer) {
1597 pts_create_scaling_popup(ad->main_info.navi, ad);
1599 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1606 static void __pts_main_view_btn_landscape_cb(void *data, Evas_Object *obj, void *event_info)
1609 pts_appdata_t *ad = (pts_appdata_t *)data;
1610 PTS_RET_IF(ad == NULL, "ad is NULL");
1612 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1614 if (ad->list_info.active_printer) {
1615 PTS_DEBUG("initial ad->main_info.landscape_toggle : %d",
1616 ad->main_info.landscape_toggle);
1617 if (PT_ORIENTATION_PORTRAIT == ad->main_info.landscape_toggle) {
1618 ad->main_info.landscape_toggle = PT_ORIENTATION_LANDSCAPE;
1619 } else { /*FIXME if (PT_LANDSCAPE_LANDSCAPE == ugd->landscape_toggle)*/
1620 ad->main_info.landscape_toggle = PT_ORIENTATION_PORTRAIT;
1623 PTS_DEBUG("ad->main_info.landscape_toggle : %d", ad->main_info.landscape_toggle);
1625 ad->list_info.active_printer->landscape = ad->main_info.landscape_toggle;
1626 pts_main_view_rotate_image(ad, app_get_device_orientation());
1628 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1634 static void _dismissed_cb(void *data, Evas_Object *obj, void *event_info)
1636 PTS_IF_DEL_OBJ(obj);
1639 static void _move_ctxpopup_more(Evas_Object *ctxpopup, Evas_Object *btn)
1641 pts_appdata_t *ad = pts_get_appdata();
1643 elm_win_screen_size_get(ad->win, NULL, NULL, &w, &h);
1645 int rot = elm_win_rotation_get(ad->win);
1646 if (rot == APP_DEVICE_ORIENTATION_0 || rot == APP_DEVICE_ORIENTATION_180) {
1647 evas_object_move(ctxpopup, 0, h);
1648 } else if (rot == APP_DEVICE_ORIENTATION_90) {
1649 evas_object_move(ctxpopup, 0, w);
1651 evas_object_move(ctxpopup, h, w);
1655 static void _more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1658 //struct appdata *ad = (struct appdata *) data;
1662 pts_appdata_t *ad = pts_get_appdata();
1663 PTS_RET_IF(ad == NULL, "ad is NULL");
1665 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1667 ad->setting_info.ctxpopup = elm_ctxpopup_add(ad->main_info.navi);
1668 elm_object_style_set(ad->setting_info.ctxpopup, "more/default");
1669 evas_object_smart_callback_add(ad->setting_info.ctxpopup, "dismissed", _dismissed_cb, ad->setting_info.ctxpopup);
1671 icon = elm_icon_add(ad->setting_info.ctxpopup);
1672 if (ad->printing_data.type != NULL) {
1673 if (0 == strcasecmp(ad->printing_data.type, "IMG")) {
1674 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1675 elm_icon_file_set(icon, buf, NULL);
1676 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1677 } else if (0 == strcasecmp(ad->printing_data.type, "DOC") || 0 == strcasecmp(ad->printing_data.type, "WEB")) {
1678 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_scaling.png", ICON_DIR);
1679 elm_icon_file_set(icon, buf, NULL);
1680 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_PRT_BODY_SCALING_ABB"), icon, __pts_main_view_btn_scaling_cb, ad);
1682 } else { /* Default IMG */
1683 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1684 elm_icon_file_set(icon, buf, NULL);
1685 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1688 icon = elm_icon_add(ad->setting_info.ctxpopup);
1689 if (ad->main_info.landscape_toggle == PT_ORIENTATION_PORTRAIT) {
1690 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate.png", ICON_DIR);
1692 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate02.png", ICON_DIR);
1694 elm_icon_file_set(icon, buf, NULL);
1695 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_OPT_ROTATE"), icon, __pts_main_view_btn_landscape_cb, ad);
1697 icon = elm_icon_add(ad->setting_info.ctxpopup);
1698 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_setting.png", ICON_DIR);
1699 elm_icon_file_set(icon, buf, NULL);
1700 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_COM_BODY_SETTING"), icon, __pts_main_view_btn_setting_cb, ad);
1702 _move_ctxpopup_more(ad->setting_info.ctxpopup, obj);
1704 ea_object_event_callback_add(ad->setting_info.ctxpopup, EA_CALLBACK_BACK, ea_ctxpopup_back_cb, NULL);
1705 ea_object_event_callback_add(ad->setting_info.ctxpopup, EA_CALLBACK_MORE, ea_ctxpopup_back_cb, NULL);
1706 elm_object_focus_set(ad->setting_info.ctxpopup, EINA_TRUE);
1708 evas_object_show(ad->setting_info.ctxpopup);
1713 static Evas_Object *create_toolbar_btn(Evas_Object *parent, const char *text, Evas_Smart_Cb func, void *data)
1716 Evas_Object *btn = elm_button_add(parent);
1720 elm_object_style_set(btn, "naviframe/toolbar/default");
1721 elm_object_text_set(btn, text);
1722 evas_object_smart_callback_add(btn, "clicked", func, data);
1727 static Evas_Object *create_toolbar_more_btn(Evas_Object *parent, Evas_Smart_Cb func, void *data)
1730 Evas_Object *btn = elm_button_add(parent);
1734 elm_object_style_set(btn, "naviframe/more/default");
1735 elm_access_info_set(btn, ELM_ACCESS_INFO, IDS_SCRREAD_MENU_INFO);
1736 elm_access_info_set(btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_MENU_CONTEXT);
1737 evas_object_smart_callback_add(btn, "clicked", func, data);
1743 * Set accessability information - screen reader text
1745 void generate_main_view_accessability_info(pts_appdata_t *ad,
1746 char* main_view_accessability_text,
1747 size_t text_max_length)
1750 PTS_RET_IF(NULL == ad || NULL == ad->list_info.active_printer, "Invalid argument");
1752 char papersize[256]={0,};
1753 strncpy(papersize, pt_get_print_option_papersize(ad->list_info.active_printer->size), 256-1);
1754 char *quality, *papertype, *grayscale_mode, *print_range;
1755 int p_quality = pt_get_selected(PT_OPTION_ID_QUALITY);
1756 if (PT_QUALITY_DRAFT == p_quality) {
1757 quality = _("IDS_PRT_OPT_PRINTSETTINGS_DRAFT");
1758 } else if (PT_QUALITY_STANDARD == p_quality) {
1759 quality = _("IDS_PRT_OPT_PRINTSETTINGS_STANDARD");
1760 } else if (PT_QUALITY_HIGH == p_quality) {
1761 quality = _("IDS_COM_BODY_HIGH");
1765 int p_type = pt_get_selected(PT_OPTION_ID_PAPER);
1766 if (PT_PAPER_NORMAL == p_type) {
1767 papertype = _("IDS_ST_BODY_NORMAL");
1768 } else if (PT_PAPER_GLOSSY == p_type) {
1769 papertype = _("IDS_ST_BODY_GLOSSY");
1770 } else if (PT_PAPER_PHOTO == p_type) {
1771 papertype = _("IDS_PRT_BODY_PHOTOGRAPHIC_ABB");
1775 int p_grayscale = pt_get_selected(PT_OPTION_ID_GRAYSCALE);
1776 if (PT_GRAYSCALE_COLOUR == p_grayscale) {
1777 grayscale_mode = _("IDS_PRT_BODY_COLOUR");
1778 } else if (PT_GRAYSCALE_GRAYSCALE == p_grayscale) {
1779 grayscale_mode = _("IDS_IMGE_HEADER_GREY");
1781 grayscale_mode = NULL;
1783 pt_range_e p_range = ad->list_info.active_printer->range;
1784 if (PT_RANGE_ALL == p_range) {
1785 print_range = _("IDS_DIC_BODY_ALL");
1787 print_range = _("IDS_BR_BODY_CURRENT_PAGE");
1790 snprintf(main_view_accessability_text, text_max_length, "%s, %d page of %d pages, %s size, %d %s,"
1792 " %s orientation, %s quality, %s paper"
1793 " %s mode, send to %s",
1794 basename(ad->printing_data.input_file), //printing file
1795 evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1, //current page
1796 g_pages_count, //total pages
1798 ad->list_info.active_printer->copies,
1799 (1 == ad->list_info.active_printer->copies) ? "copy" : "copies",
1801 (PT_SCALING_2_PAGES == ad->list_info.active_printer->scaling) ? "2 pages in 1 sheet" :
1802 (PT_SCALING_4_PAGES == ad->list_info.active_printer->scaling) ? "4 pages in 1 sheet" :
1804 PT_ORIENTATION_PORTRAIT == ad->list_info.active_printer->landscape ? "portrait" :
1805 PT_ORIENTATION_LANDSCAPE == ad->list_info.active_printer->landscape ? "landscape" : "auto",
1809 elm_access_info_get(ad->main_info.printer_label, ELM_ACCESS_INFO));
1815 * create content of the main view screen
1817 static Evas_Object *__pts_main_view_create_content(pts_appdata_t *ad)
1820 PTS_RETV_IF(ad == NULL, NULL, "ad is NULL");
1823 * load preview group
1825 ad->main_info.printer_layout = pts_create_base_layout(ad->main_info.navi, "printer");
1827 pts_main_view_update_printer_label(ad);
1830 * load preview image group
1832 ad->main_info.img_layout = pts_create_base_layout(ad->main_info.printer_layout, "image_view");
1834 if (NULL != ad->printing_data.request_files) {
1835 char *file_path = NULL;
1836 file_path = ad->printing_data.request_files[ad->printing_data.current_index];
1837 PTS_DEBUG("filepath is %s", file_path);
1840 ad->main_info.smsc = evas_smart_smsc_add(evas_object_evas_get(ad->main_info.img_layout));
1841 evas_smart_smsc_set_layout(ad->main_info.smsc, ad->main_info.img_layout);
1842 elm_object_part_content_set(ad->main_info.img_layout, "content", ad->main_info.smsc);
1845 * Set preview layout
1847 elm_object_part_content_set(ad->main_info.printer_layout, "image", ad->main_info.img_layout);
1848 evas_object_show(ad->main_info.img_layout);
1849 evas_object_show(ad->main_info.printer_layout);
1851 static char main_view_accessability_text[2048] = {0,};
1852 generate_main_view_accessability_info(ad, main_view_accessability_text, 2048);
1853 init_smsc_accessability_support(ad->main_info.smsc);
1854 set_main_view_accessability_info(ad->main_info.smsc, ad->main_info.img_layout,
1855 main_view_accessability_text,
1856 IDS_SCRREAD_PREVIEW_IMAGE_TYPE,
1857 IDS_SCRREAD_PREVIEW_IMAGE_CONTEXT);
1860 return ad->main_info.printer_layout;
1865 * setting button callback function
1867 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info)
1870 pts_appdata_t *ad = (pts_appdata_t *)data;
1871 PTS_RET_IF(ad == NULL, "ad is NULL");
1873 PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1875 if (ad->list_info.active_printer) {
1876 pts_create_setting_view(ad);
1878 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1884 int pts_main_view_load_printing_data(pts_appdata_t *ad, pts_printing_data_t *printing_data)
1887 PTS_RETV_IF(ad == NULL || printing_data == NULL, -1, "Invalid argument");
1889 PTS_IF_FREE_MEM(ad->printing_data.request_files);
1890 PTS_IF_FREE_MEM(ad->printing_data.type);
1892 memset(&ad->printing_data, 0, sizeof(pts_printing_data_t));
1894 ad->printing_data.num_of_files = printing_data->num_of_files;
1895 ad->printing_data.current_index = printing_data->current_index;
1896 ad->printing_data.type = printing_data->type;
1897 ad->printing_data.request_files = (char **)malloc(sizeof(char *) * ad->printing_data.num_of_files);
1899 if (!ad->printing_data.request_files) {
1900 PTS_IF_FREE_MEM(ad->printing_data.type);
1901 //PTS_IF_FREE_MEM(ad->printing_data);
1902 PTS_DEBUG("calloc print files failed");
1908 for (i = 0; i < ad->printing_data.num_of_files; i++) {
1909 PTS_DEBUG("file path is %s", printing_data->request_files[i]);
1910 if (NULL != printing_data->request_files[i]) {
1911 ad->printing_data.request_files[i] = strdup(printing_data->request_files[i]);
1913 ad->printing_data.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
1915 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
1917 ad->printing_data.input_file = strdup(ad->printing_data.request_files[0]);
1918 PTS_DEBUG("ad->input_file: %s", ad->printing_data.input_file);
1920 PTS_DEBUG("count: %d", ad->printing_data.num_of_files);
1921 PTS_DEBUG("current index: %d", ad->printing_data.current_index);
1922 PTS_DEBUG("filetype: %s", ad->printing_data.type);
1924 /* init the print range(include all pages) */
1925 ad->printing_data.range.from = 1;
1926 ad->printing_data.range.to = ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1927 ad->printing_data.range.selected_files = NULL;
1934 * This function let the app update printer label in the preview view
1936 * @param[in] ugd the pointer to the main data structure
1938 void pts_main_view_update_printer_label(pts_appdata_t *ad)
1941 PTS_RET_IF(ad == NULL, "ad is NULL");
1943 char label_text[128] = {0,};
1944 char label_voice[128] = {0,};
1946 if (ad->main_info.printer_label == NULL) {
1947 ad->main_info.printer_label = elm_label_add(ad->main_info.printer_layout);
1949 PTS_DEBUG("ad->list_info.active_printer is %p", ad->list_info.active_printer);
1951 if (ad->list_info.active_printer != NULL) {
1952 char *printer_name = strdup(ad->list_info.active_printer->name);
1953 pts_unstandardization(printer_name);
1954 snprintf(label_text, 128, "<align=center>%s</align>", printer_name);
1955 snprintf(label_voice, 128, "%s", printer_name);
1956 if (printer_name != NULL) {
1958 printer_name = NULL;
1961 snprintf(label_text, 128, "<align=center>%s</align>", _("IDS_COM_BODY_NO_DEVICES"));
1962 snprintf(label_voice, 128, "%s", _("IDS_COM_BODY_NO_DEVICES"));
1965 elm_object_text_set(ad->main_info.printer_label, label_text);
1966 elm_access_info_set(ad->main_info.printer_label, ELM_ACCESS_INFO, label_voice);
1967 evas_object_size_hint_weight_set(ad->main_info.printer_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1968 evas_object_size_hint_align_set(ad->main_info.printer_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1970 elm_object_part_content_set(ad->main_info.printer_layout, "printer_name", ad->main_info.printer_label);
1976 * This function let the app rotate the image by the given landscape
1978 * @param[in] ugd the pointer to the main data structure
1979 * @param[in] landscape the landscape value
1981 void pts_main_view_rotate_image(pts_appdata_t *ad,
1982 app_device_orientation_e orientation)
1985 PTS_RET_IF(ad == NULL, "ad is NULL");
1987 generate_preview_images(ad, orientation);
1994 * This function let the app create the main screen view
1995 * @return Evas_Object
1996 * @param[in] win the pointer to the main window
1997 * @param[in] pt_files the pointer to the path of print files
1999 API Evas_Object *pts_create_main_view(pts_appdata_t *ad)
2002 PTS_RETV_IF((ad == NULL) || (ad->main_info.root_win == NULL), NULL, "Invalid argument");
2004 Evas_Object *main_layout = NULL;
2005 Evas_Object *back_btn = NULL;
2006 Evas_Object *toolbar;
2008 ad->main_info.main_layout = pts_create_base_layout_with_conform(ad->main_info.root_win, "navi");
2009 if (NULL == ad->main_info.main_layout) {
2010 //PTS_IF_FREE_MEM(ad);
2011 PTS_DEBUG("create base layout failed");
2016 ad->main_info.navi = elm_naviframe_add(ad->main_info.main_layout);
2017 elm_object_part_content_set(ad->main_info.main_layout, "navigation_bar", ad->main_info.navi);
2019 /* add navigation frame toolbar */
2020 toolbar = elm_toolbar_add(ad->main_info.navi);
2021 PTS_RETV_IF(NULL == toolbar, NULL, "Toolbar adding error");
2022 elm_object_style_set(toolbar, "default");
2023 elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
2024 elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
2025 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_NONE);
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);
2035 evas_object_event_callback_add(ad->main_info.navi, EVAS_CALLBACK_DEL, __pts_main_view_navi_delete_cb, ad);
2037 ad->main_info.navi_it = elm_naviframe_item_push(ad->main_info.navi, _("IDS_PRT_SK_PRINT_PREVIEW"), back_btn, NULL, main_layout, NULL);
2038 elm_naviframe_prev_btn_auto_pushed_set(ad->main_info.navi, EINA_FALSE);
2039 elm_naviframe_item_pop_cb_set(ad->main_info.navi_it, __pts_main_view_btn_back_cb, ad);
2040 ea_object_event_callback_add(ad->main_info.navi, EA_CALLBACK_BACK, ea_naviframe_back_cb, NULL);
2041 ea_object_event_callback_add(ad->main_info.navi, EA_CALLBACK_MORE, ea_naviframe_more_cb, NULL);
2043 /* insert printing button */
2044 elm_toolbar_item_append(toolbar, NULL, _("IDS_SMPOS_SK3_PRINT"), __pts_main_view_btn_print_cb, ad);
2045 elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar", toolbar);
2047 /* we have only one item in toolbar, so we could set
2048 accessibility on all toolbar */
2049 elm_access_info_set(toolbar, ELM_ACCESS_INFO, _("IDS_SMPOS_SK3_PRINT"));
2050 elm_access_info_set(toolbar, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_PRINT_CONTEXT);
2052 ad->main_info.more_btn = create_toolbar_more_btn(ad->main_info.navi, _more_btn_cb, ad->main_info.navi_it);
2053 elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar_more_btn", ad->main_info.more_btn);
2054 evas_object_event_callback_add(main_layout, EVAS_CALLBACK_DEL, __pts_main_view_delete_cb, ad);
2059 get_image_resolution(ad->printing_data.input_file, &tmp_width, &tmp_height);
2060 ad->size_popup_info.custom_width = (double)tmp_width;
2061 ad->size_popup_info.custom_height = (double)tmp_height;
2062 ad->size_popup_info.custom_w_ratio = ad->size_popup_info.custom_width / ad->size_popup_info.custom_height;
2063 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);
2064 // original image size (unit cm) calculated by 300dpi
2065 ad->size_popup_info.custom_width = (ad->size_popup_info.custom_width / 300) * 2.54;
2066 ad->size_popup_info.custom_height = (ad->size_popup_info.custom_height / 300) * 2.54;
2067 ad->size_popup_info.custom_unit = 1; // cm unit
2070 return ad->main_info.main_layout;