Initialize Tizen 2.3
[apps/home/mobileprint.git] / mobileprint / app / pts_main_view.c
1 /*
2 *  Mobileprint
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
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
9
10 * http://floralicense.org/license/
11
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.
17 *
18 */
19
20 #define _GNU_SOURCE
21 #include <string.h>
22 #include <math.h>
23 #include <fcntl.h>
24 #include <glib.h>
25 #include <app.h>
26 #include <appsvc.h>
27 #include <ui-gadget.h>
28 #include <notification.h>
29 #include <vconf.h>
30 #include <vconf-keys.h>
31 #include <efl_assist.h>
32
33 #include <page_preview.h>
34 #include <paper_size.h>
35 #include <previewgen.h>
36 #include "pt_api.h"
37
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"
43
44
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"
50
51 char *g_current_preview_path = NULL;
52 int g_pages_count = 0;
53
54 void _wifi_qs_monitoring_cb(keynode_t *key, void *data);
55
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);
58
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);
68
69 static int __pts_get_real_total_pages(int original_total_pages, int n_up_number, int copies)
70 {
71         return (int)ceil((double)original_total_pages / (double)n_up_number) * copies;
72 }
73
74 static pts_job_spooling_t *__pts_get_job_spooling(pts_appdata_t *ad, int job_id)
75 {
76         PTS_TRACE_BEGIN;
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);
79
80         Eina_List *job_spooling_list = NULL;
81         pts_job_spooling_t *job_spooling = NULL;
82
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);
86                         break;
87                 }
88         }
89
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);
92         PTS_TRACE_END;
93         return job_spooling;
94 }
95
96 static pts_job_spooling_t *__pts_get_last_job_spooling(pts_appdata_t *ad)
97 {
98         PTS_TRACE_BEGIN;
99         PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
100
101         Eina_List *job_spooling_list = NULL;
102         pts_job_spooling_t *job_spooling = NULL;
103
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");
106
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");
110
111         PTS_TRACE_END;
112         return job_spooling;
113 }
114
115 int __pts_update_popup_progress(pts_appdata_t *ad, pt_progress_info_t *progress_info, pts_job_spooling_t *job_spooling)
116 {
117         PTS_TRACE_BEGIN;
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");
120
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;
127
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);
133         }
134
135         elm_progressbar_value_set(ad->progress_info.progressbar, rate);
136
137         if (rate > 0) {
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);
141         }
142
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;
147         } else {
148                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
149                                 job_spooling->n_up, job_spooling->copies);
150         }
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);
155         }
156
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);
161         }
162
163         PTS_TRACE_END;
164         return 0;
165 }
166
167 int __pts_update_notification(pts_appdata_t *ad,
168                                                           pt_progress_info_t *progress_info,
169                                                           pts_job_spooling_t *job_spooling)
170 {
171         PTS_TRACE_BEGIN;
172         PTS_RETV_IF(ad == NULL || progress_info == NULL || job_spooling == NULL
173                                 , -1 ,"Invalid parameters for update_notification");
174
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");
178
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) {
182                         int ret;
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);
189                         }
190                         job_spooling->noti_handle = NULL;
191                         job_spooling->page_printed = progress_info->page_printed; // XXX
192                 }
193         }
194
195         if (job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE && job_spooling->noti_handle == NULL) {
196                 int real_total_pages = -1;
197
198                 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
199                         real_total_pages = 1;
200                 } else {
201                         real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
202                                                                                         job_spooling->n_up, job_spooling->copies);
203                 }
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);
207                 }
208                 PTS_TRACE_END;
209                 return 0;
210         }
211
212         notification_update_progress(NULL, job_spooling->noti_id, rate);
213
214         PTS_TRACE_END;
215         return 0;
216 }
217
218 int __pts_remove_notification(int noti_id)
219 {
220         PTS_TRACE_BEGIN;
221
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");
225         }
226
227         PTS_TRACE_END;
228         return 0;
229 }
230
231 int __pts_create_dummy_notification(pts_appdata_t *ad)
232 {
233         PTS_TRACE_BEGIN;
234         PTS_RETV_IF(ad == NULL, -1, "Invalid paramter for __pts_create_dummy_notification");
235
236         int res = -1;
237         notification_h noti = NULL;
238
239         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
240                                                         NOTIFICATION_GROUP_ID_NONE,
241                                                         NOTIFICATION_PRIV_ID_NONE);
242
243         PTS_RETV_IF(noti == NULL, -1, "Failed to create Notification");
244
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);
249                 goto ERR_CASE;
250         }
251
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);
257                 goto ERR_CASE;
258         }
259         if (printer_label != NULL) {
260                 free(printer_label);
261                 printer_label = NULL;
262         }
263
264         bundle *b = NULL;
265         b = bundle_create();
266         char value[4] = {0,};
267
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]);
271         } else {
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;
274         }
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;
279         } else {
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);
282         }
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);
288
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);
292                 goto ERR_CASE;
293         }
294         bundle_free(b);
295
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");
299                 goto ERR_CASE;
300         }
301
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);
305                 goto ERR_CASE;
306         }
307         PTS_DEBUG("Notification ID [%d]", ad->noti_info.dummy_noti_id);
308
309         PTS_TRACE_END;
310         return 0;
311
312 ERR_CASE:
313         if (printer_label != NULL) {
314                 free(printer_label);
315                 printer_label = NULL;
316         }
317
318         if (noti != NULL) {
319                 notification_free(noti);
320                 noti = NULL;
321         }
322
323         if (b != NULL) {
324                 bundle_free(b);
325                 b = NULL;
326         }
327
328         PTS_TRACE_END;
329         return -1;
330 }
331
332 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling)
333 {
334         PTS_TRACE_BEGIN;
335         PTS_RETV_IF(ad == NULL || job_spooling == NULL
336                                 , -1, "Invalid parameter for __pts_create_notification_by_page");
337
338         int res = -1;
339         notification_h noti = NULL;
340         double rate = 0.00;
341         char title[32] = {0,};
342
343         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
344                                                         NOTIFICATION_GROUP_ID_NONE,
345                                                         NOTIFICATION_PRIV_ID_NONE);
346
347         if (noti == NULL) {
348                 PTS_DEBUG("Failed to create Notification");
349                 goto ERR_CASE;
350         }
351
352         //re-allocate noti handle
353         job_spooling->noti_handle = noti;
354
355         int real_total_pages = -1;
356         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
357                 real_total_pages = 1;
358         } else {
359                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
360                                                                         job_spooling->n_up, job_spooling->copies);
361         }
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);
365
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);
370                 goto ERR_CASE;
371         }
372
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);
378                 goto ERR_CASE;
379         }
380         if (printer_label != NULL) {
381                 free(printer_label);
382                 printer_label = NULL;
383         }
384
385         res = notification_set_progress(noti, rate);
386         if (res != NOTIFICATION_ERROR_NONE) {
387                 PTS_DEBUG("Failed to set Notification title [%d]", res);
388                 goto ERR_CASE;
389         }
390
391         bundle *b = NULL;
392         b = bundle_create();
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);
401
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);
405                 goto ERR_CASE;
406         }
407         bundle_free(b);
408
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");
412                 goto ERR_CASE;
413         }
414
415         res = notification_insert(noti, &job_spooling->noti_id);
416         if (res != NOTIFICATION_ERROR_NONE) {
417                 PTS_DEBUG("Failed to insert Notification [%d]", res);
418                 goto ERR_CASE;
419         }
420         PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
421
422         PTS_TRACE_END;
423         return 0;
424
425 ERR_CASE:
426         if (printer_label != NULL) {
427                 free(printer_label);
428                 printer_label = NULL;
429         }
430
431         if (job_spooling->noti_handle != NULL) {
432                 notification_free(job_spooling->noti_handle);
433                 job_spooling->noti_handle = NULL;
434         }
435
436         if (b != NULL) {
437                 bundle_free(b);
438                 b = NULL;
439         }
440
441         PTS_TRACE_END;
442         return -1;
443 }
444
445 int __pts_create_job_notification(pts_appdata_t *ad, int job_id)
446 {
447         PTS_TRACE_BEGIN;
448         PTS_RETV_IF(ad == NULL || job_id <=0
449                                 , -1 , "Invalid parameter for __pts_create_job_notification");
450
451         int res = -1;
452         notification_h noti = NULL;
453         double rate = 0.00;
454         char title[32] = {0,};
455
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));
459
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;
463
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");
467                 goto ERR_CASE;
468         }
469
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");
473                 goto ERR_CASE;
474         }
475         int i = 0;
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]);
480                 } else {
481                         job_spooling->pt_files.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
482                 }
483                 PTS_DEBUG("file path is %s", job_spooling->pt_files.request_files[i]);
484         }
485
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");
489                 goto ERR_CASE;
490         }
491
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;
495
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");
499                 goto ERR_CASE;
500         }
501
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]");
505                 goto ERR_CASE;
506         }
507
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
512         }
513 #endif
514
515         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
516                                                         NOTIFICATION_GROUP_ID_NONE,
517                                                         NOTIFICATION_PRIV_ID_NONE);
518         if (noti == NULL) {
519                 PTS_DEBUG("Failed to create Notification");
520                 goto ERR_CASE;
521         }
522
523         job_spooling->noti_handle = noti;
524
525         job_spooling->n_up = printer_get_setting_n_up(ad->list_info.active_printer);
526
527         job_spooling->copies = ad->list_info.active_printer->copies;
528
529         int real_total_pages = -1;
530         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
531                 real_total_pages = 1;
532         } else {
533                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
534                                                                         job_spooling->n_up, job_spooling->copies);
535         }
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);
538
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);
543                 goto ERR_CASE;
544         }
545
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);
551                 goto ERR_CASE;
552         }
553         if (printer_label != NULL) {
554                 free(printer_label);
555                 printer_label = NULL;
556         }
557
558         res = notification_set_progress(noti, rate);
559         if (res != NOTIFICATION_ERROR_NONE) {
560                 PTS_DEBUG("Failed to set Notification title [%d]", res);
561                 goto ERR_CASE;
562         }
563
564         bundle *b = NULL;
565         b = bundle_create();
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);
574
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);
578                 bundle_free(b);
579                 goto ERR_CASE;
580         }
581         bundle_free(b);
582
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");
586                 goto ERR_CASE;
587         }
588
589         res = notification_insert(noti, &job_spooling->noti_id);
590         if (res != NOTIFICATION_ERROR_NONE) {
591                 PTS_DEBUG("Failed to insert Notification [%d]", res);
592                 goto ERR_CASE;
593         }
594         PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
595
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");
599                 goto ERR_CASE;
600         }
601
602         PTS_TRACE_END;
603
604         return 0;
605
606 ERR_CASE:
607         if (printer_label != NULL) {
608                 free(printer_label);
609                 printer_label = NULL;
610         }
611
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;
616                 }
617
618                 if (job_spooling->pt_files.request_files != NULL) {
619                         int i = 0;
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;
624                                 }
625                         }
626                         PTS_IF_FREE_MEM(job_spooling->pt_files.request_files);
627                         job_spooling->pt_files.request_files = NULL;
628                 }
629
630                 if (job_spooling->input_file != NULL) {
631                         PTS_IF_FREE_MEM(job_spooling->input_file);
632                         job_spooling->input_file = NULL;
633                 }
634
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;
639                         }
640
641                         PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
642                         job_spooling->pt_files.range.selected_files = NULL;
643                 }
644
645                 if (job_spooling->noti_handle != NULL) {
646                         notification_free(job_spooling->noti_handle);
647                         job_spooling->noti_handle = NULL;
648                 }
649
650                 PTS_IF_FREE_MEM(job_spooling);
651                 job_spooling = NULL;
652         }
653
654         PTS_TRACE_END;
655         return -1;
656 }
657
658 static gboolean __pts_main_view_job_monitor_timeout_cb(void *data)
659 {
660         PTS_TRACE_BEGIN;
661         pts_appdata_t *ad = (pts_appdata_t *)data;
662         PTS_RETV_IF(ad == NULL, TRUE, "ad is NULL");
663
664         pt_job_state_e job_status = PT_JOB_ERROR;
665         gboolean ret = FALSE;
666
667         //char noti_name[512] = {0};
668
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.
677                         ret = TRUE;
678                 }
679         }
680
681         PTS_TRACE_END;
682
683         return ret;
684 }
685
686 void __pts_event_cb(pt_event_e event, void *user_data, pt_progress_info_t *progress_info)
687 {
688         PTS_TRACE_BEGIN;
689
690         // XXX - progress_info can be passed by NULL
691         PTS_RET_IF(event < 0 || user_data == NULL, "Invalid parameters for event cb");
692
693         pts_appdata_t *ad = (pts_appdata_t *)user_data;
694         pts_job_spooling_t *job_spooling = NULL;
695
696         switch (event) {
697         case PT_EVENT_USB_PRINTER_ONLINE:
698                 __pts_main_view_check_usb_printer_online(ad);
699                 break;
700         case PT_EVENT_USB_PRINTER_OFFLINE:
701                 __pts_main_view_check_usb_printer_offline(ad);
702                 break;
703         case PT_EVENT_PRINTER_ONLINE:
704                 __pts_main_view_check_printer_online(ad);
705                 break;
706         case PT_EVENT_PRINTER_OFFLINE:
707                 __pts_main_view_check_printer_offline(ad);
708                 break;
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);
712                 break;
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);
719                 break;
720         case PT_EVENT_JOB_PROCESSING:
721                 PTS_DEBUG("Job[%d] is processing.", progress_info->job_id);
722                 break;
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);
730
731 #if 0
732                         //FIXME
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++;
737                                 }
738                         }
739 #endif
740
741                         job_spooling->progress = progress_info->progress;
742                 }
743                 __pts_update_notification(ad, progress_info, job_spooling);
744                 __pts_update_popup_progress(ad, progress_info, job_spooling);
745                 break;
746         case PT_EVENT_JOB_PENDING:
747                 PTS_DEBUG("Job[%d] is waiting.", progress_info->job_id);
748                 break;
749         case PT_EVENT_JOB_HELD:
750                 PTS_DEBUG("Job[%d] is held.", progress_info->job_id);
751                 break;
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);
756                 break;
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);
761                 break;
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);
769                 }
770                 break;
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);
775                 break;
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);
780                 pt_deinit();
781                 elm_exit();
782                 break;
783         default:
784                 break;
785         }
786
787         PTS_TRACE_END;
788 }
789
790 static void __pts_main_view_check_usb_printer_online(void *userdata)
791 {
792         PTS_TRACE_BEGIN;
793         pts_appdata_t *ad = (pts_appdata_t *)userdata;
794         PTS_RET_IF(ad == NULL, "ad is NULL");
795
796         /* if in ether searching or printing, ignore it */
797         PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
798
799         PTS_IF_DEL_OBJ(ad->progress_info.popup);
800
801         elm_naviframe_item_pop_to(ad->main_info.navi_it);
802
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);
810
811         PTS_TRACE_END;
812 }
813
814 static void __pts_main_view_check_usb_printer_offline(void *userdata)
815 {
816         PTS_TRACE_BEGIN;
817         pts_appdata_t *ad = (pts_appdata_t *)userdata;
818         PTS_RET_IF(ad == NULL, "ad is NULL");
819
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);
824
825         elm_naviframe_item_pop_to(ad->main_info.navi_it);
826
827         pts_main_view_update_printer_label(ad);
828
829         PTS_TRACE_END;
830 }
831
832 static void __pts_main_view_remove_job(void *user_data, int job_id)
833 {
834         PTS_TRACE_BEGIN;
835         PTS_RET_IF(user_data == NULL || job_id <= 0,"Invalid parameter for job error processing");
836
837         pts_appdata_t *ad = (pts_appdata_t *)user_data;
838         int ret;
839
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);
844         }
845
846         Eina_List *job_spooling_list = NULL;
847         pts_job_spooling_t *job_spooling = NULL;
848
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);
852                         break;
853                 }
854         }
855
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);
858
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*/
861
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;
866         }
867
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);
872                 }
873                 job_spooling->noti_handle = NULL;
874         }
875
876         PTS_RET_IF(job_spooling->pt_files.range.selected_files == NULL, "job_spooling->pt_files.range.selected_files is NULL");
877
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;
881         }
882
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;
886         }
887
888         if (job_spooling->input_file) {
889                 PTS_IF_FREE_MEM(job_spooling->input_file);
890                 job_spooling->input_file = NULL;
891         }
892
893         int i = 0;
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;
898                 }
899         }
900
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;
904         }
905
906         if (job_spooling->pt_files.type) {
907                 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
908                 job_spooling->pt_files.type = NULL;
909         }
910
911         if (job_spooling) {
912                 PTS_IF_FREE_MEM(job_spooling);
913                 job_spooling = NULL;
914         }
915
916         PTS_TRACE_END;
917 }
918
919 static void __pts_main_view_job_error(void *user_data, int job_id)
920 {
921         PTS_TRACE_BEGIN;
922         PTS_RET_IF(user_data == NULL || job_id <= 0, "Invalid parameter for job error processing");
923
924         pts_appdata_t *ad = (pts_appdata_t *)user_data;
925         PTS_IF_DEL_OBJ(ad->progress_info.popup);
926
927         pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
928
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);
931
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);
937         PTS_TRACE_END;
938 }
939
940 static void __pts_main_view_last_job_error(void *user_data)
941 {
942         PTS_TRACE_BEGIN;
943         PTS_RET_IF(user_data == NULL, "Invalid parameter for last job error processing");
944
945         pts_appdata_t *ad = (pts_appdata_t *)user_data;
946         PTS_IF_DEL_OBJ(ad->progress_info.popup);
947
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");
951
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);
957         PTS_TRACE_END;
958 }
959
960
961 static void __pts_main_view_check_printer_online(void *user_data)
962 {
963         PTS_TRACE_BEGIN;
964         PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_online");
965
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);
968
969         PTS_TRACE_END;
970 }
971
972 static void __pts_main_view_check_printer_offline(void *user_data)
973 {
974         PTS_TRACE_BEGIN;
975         PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_offline");
976
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);
980
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 */
984
985         PTS_TRACE_END;
986 }
987
988 static void __pts_main_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
989 {
990         PTS_TRACE_BEGIN;
991         pts_appdata_t *ad = (pts_appdata_t *)data;
992         PTS_RET_IF(ad == NULL, "ad is NULL");
993
994 #if 0
995         if (NULL != ugd->pt_files.request_files) {
996                 int i = 0;
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;
1001                         }
1002                 }
1003
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;
1007                 }
1008
1009                 free(ugd->pt_files.request_files);
1010                 ugd->pt_files.request_files = NULL;
1011         }
1012 #endif
1013
1014         PTS_TRACE_END;
1015 }
1016
1017 static void __pts_main_view_navi_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1018 {
1019         PTS_TRACE_BEGIN;
1020         pts_appdata_t *ad = (pts_appdata_t *)data;
1021         PTS_RET_IF(ad == NULL, "ad is NULL");
1022
1023         PTS_IF_FREE_MEM(ad->list_info.active_printer);
1024
1025         PTS_TRACE_END;
1026 }
1027
1028 /*
1029 * "back" button callback
1030 */
1031 void __pts_main_view_btn_back_cb(void *data, Evas_Object *obj, void *event_info)
1032 {
1033         PTS_TRACE_BEGIN;
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);
1039                 pt_deinit();
1040                 elm_exit();
1041         } else {
1042                 PTS_DEBUG("Active job spooling list is existed. So just hide preview.");
1043                 __pts_hide_main_view(ad);
1044         }
1045         PTS_TRACE_END;
1046 }
1047
1048 static void __pts_main_view_dummy_cancel_print(void *data, Evas_Object *obj, void *event_info)
1049 {
1050         PTS_TRACE_BEGIN;
1051
1052         pts_appdata_t *ad = pts_get_appdata();
1053         PTS_RET_IF(ad == NULL, "ad is NULL");
1054
1055         PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1056         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1057
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);
1061
1062         PTS_TRACE_END;
1063 }
1064
1065 static void __pts_main_view_response_cancel_print(void *data, Evas_Object *obj, void *event_info)
1066 {
1067         PTS_TRACE_BEGIN;
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);
1073
1074         pt_cancel_print(job_id);
1075
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);
1079
1080         // FIXME - Is it better to do this job after received canceled evt_cb?
1081         __pts_remove_notification(job_spooling->noti_id);
1082
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);
1086
1087         PTS_TRACE_END;
1088 }
1089
1090 static void __pts_hide_progress_popup(void *data, Evas_Object *obj, void *event_info)
1091 {
1092         PTS_TRACE_BEGIN;
1093         pts_appdata_t *ad = (pts_appdata_t *)data;
1094         PTS_RET_IF(ad == NULL, "ad is NULL");
1095
1096         PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1097         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1098
1099         evas_object_hide(ad->main_info.root_win);
1100
1101         PTS_TRACE_END;
1102 }
1103
1104 void __pts_print_dummy_popup(pts_appdata_t *ad, char *files, int page_count)
1105 {
1106         PTS_TRACE_BEGIN;
1107         PTS_RET_IF(ad == NULL || files == NULL || page_count <= 0, "Invalid parameters for progress_popup");
1108
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,};
1117
1118         popup = elm_popup_add(ad->main_info.main_layout);
1119
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;
1132         }
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);
1136
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);
1148
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);
1159
1160         layout = pts_create_base_layout(popup, "popup_progress");
1161
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);
1169
1170         ad->progress_info.progress_label = label2;
1171         ad->progress_info.progress_layout = layout;
1172         ad->progress_info.progressbar = progressbar;
1173
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;
1183         } else {
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);
1186         }
1187         snprintf(page_info, 8, "1/%d", real_total_pages);
1188         elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1189
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);
1196
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);
1204         }
1205
1206         elm_object_content_set(popup, layout);
1207         evas_object_show(popup);
1208         evas_object_show(ad->main_info.root_win);
1209
1210         ad->progress_info.popup = popup;
1211
1212         PTS_TRACE_END;
1213 }
1214
1215
1216 void __pts_print_progress_popup(pts_appdata_t *ad, int job_id, int page_count)
1217 {
1218         PTS_TRACE_BEGIN;
1219         PTS_RET_IF(ad == NULL || job_id <= 0 || page_count <= 0, "Invalid parameters for progress_popup");
1220
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);
1224
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,};
1234
1235         popup = elm_popup_add(ad->main_info.main_layout);
1236
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);
1247
1248                 free(printer_label);
1249                 printer_label = NULL;
1250         }
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);
1254
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"));
1264         } else {
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"));
1270         }
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);
1275
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>",
1281                                 label3_text);
1282         elm_object_text_set(label3, aligned_label);
1283         /* accessability - screen reader support */
1284         elm_access_info_set(label3, ELM_ACCESS_INFO, label3_text);
1285
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);
1289
1290         layout = pts_create_base_layout(popup, "popup_progress");
1291         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1292
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);
1298         } else {
1299                 elm_object_style_set(progressbar, "pending_list");
1300                 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1301         }
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);
1306
1307         ad->progress_info.progress_label = label2;
1308         ad->progress_info.progress_layout = layout;
1309         ad->progress_info.progressbar = progressbar;
1310
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);
1318         } else {
1319                 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1320         }
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);
1323
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);
1330
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);
1340 //      }
1341
1342         elm_object_content_set(popup, layout);
1343         evas_object_show(popup);
1344         evas_object_show(ad->main_info.root_win);
1345
1346         ad->progress_info.popup = popup;
1347
1348         PTS_TRACE_END;
1349 }
1350
1351 static Eina_Bool __pts_is_valid_printing_data(pts_appdata_t *ad)
1352 {
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");
1355
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);
1359                 return EINA_FALSE;
1360         }
1361
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");
1371                 return EINA_FALSE;
1372         }
1373
1374         return EINA_TRUE;
1375 }
1376
1377 static Eina_Bool __pts_set_print_option_page_range(pts_appdata_t *ad)
1378 {
1379         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1380
1381         char temp[1024] = {0,};
1382         int index = 0;
1383
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]);
1387                 }
1388         } else {
1389                 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1390         }
1391
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;
1394
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);
1400         }
1401
1402         return EINA_TRUE;
1403 }
1404
1405 static Eina_Bool __pts_set_print_scale_size(pts_appdata_t *ad)
1406 {
1407         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1408
1409         int num = 0;
1410         char *first_fname = NULL;
1411
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);
1416
1417         if (NULL == ad->printing_data.range.selected_files) {
1418                 PTS_DEBUG("selected_files malloc error");
1419                 return EINA_FALSE;
1420         }
1421
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)) {
1424                 int res_x = 0;
1425                 int res_y = 0;
1426                 if (get_image_resolution(first_fname, &res_x, &res_y) < 0) {
1427                         PTS_DEBUG("[ERROR] Failed to get image resolution(%s)",first_fname);
1428                         return EINA_FALSE;
1429                 }
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;
1436
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];
1439         } else {
1440                 pt_set_print_option_scaleimage(ad->list_info.active_printer->scaling);
1441                 num = 1;
1442                 ad->printing_data.range.selected_files[0] = ad->printing_data.input_file;
1443         }
1444
1445         return EINA_TRUE;
1446 }
1447
1448 static Eina_Bool __pts_set_print_options(pts_appdata_t *ad)
1449 {
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");
1452
1453         Eina_Bool eret = EINA_FALSE;
1454
1455         eret = __pts_set_print_option_page_range(ad);
1456         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set page ragnge");
1457
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");
1469
1470         return EINA_TRUE;
1471 }
1472
1473 static Eina_Bool __pts_set_active_printer(pts_appdata_t *ad)
1474 {
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");
1477
1478         int ret = 0;
1479
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");
1485                         return EINA_FALSE;
1486                 }
1487         }
1488
1489         return EINA_TRUE;
1490 }
1491
1492 static Eina_Bool __pts_main_view_start_print(void *data)
1493 {
1494         PTS_TRACE_BEGIN;
1495         pts_appdata_t *ad = (pts_appdata_t *)data;
1496         PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
1497
1498         int ret = 0;
1499         int num = 1;
1500
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");
1504
1505         eret = __pts_is_valid_printing_data(ad);
1506         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "It's not valid printing data");
1507
1508         eret = __pts_set_active_printer(ad);
1509         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set active printer");
1510
1511         __pts_create_dummy_notification(ad);
1512
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");
1516                 goto ERR_CASE;
1517         }
1518
1519         PTS_TRACE_END;
1520         return ECORE_CALLBACK_CANCEL;
1521
1522 ERR_CASE:
1523         ad->search_info.is_process = 0;/*process is complete*/
1524
1525         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1526
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);
1529         } else {
1530                 pts_create_popup(ad->main_info.navi, _("IDS_COM_BODY_UNSUPPORTED_FILE_TYPE"), 1.0);
1531         }
1532         return ECORE_CALLBACK_CANCEL;
1533 }
1534
1535 static Eina_Bool __pts_hide_main_view(void *data)
1536 {
1537         PTS_TRACE_BEGIN;
1538         pts_appdata_t *ad = (pts_appdata_t *) data;
1539         PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "data is NULL");
1540
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);
1544
1545         PTS_TRACE_END;
1546         return ECORE_CALLBACK_CANCEL;
1547 }
1548
1549 /*
1550 * "print" button callback
1551 */
1552 static void __pts_main_view_btn_print_cb(void *data, Evas_Object *obj, void *event_info)
1553 {
1554         PTS_TRACE_BEGIN;
1555         pts_appdata_t *ad = (pts_appdata_t *)data ;
1556         PTS_RET_IF(ad == NULL, "ad is NULL");
1557
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);
1562
1563                 ad->search_info.is_process = 1;/* in process */
1564                 __pts_main_view_start_print(ad);
1565         } else {
1566                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_SELECT_PRINTER"), 2.0);
1567         }
1568         PTS_TRACE_END;
1569 }
1570
1571 static void __pts_main_view_btn_size_cb(void *data, Evas_Object *obj, void *event_info)
1572 {
1573         PTS_TRACE_BEGIN;
1574         pts_appdata_t *ad = (pts_appdata_t *)data;
1575         PTS_RET_IF(ad == NULL, "ad is NULL");
1576
1577         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1578
1579         if (ad->list_info.active_printer) {
1580                 pts_create_size_popup(ad->main_info.navi, ad);
1581         } else {
1582                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1583         }
1584
1585         PTS_TRACE_END;
1586 }
1587
1588 static void __pts_main_view_btn_scaling_cb(void *data, Evas_Object *obj, void *event_info)
1589 {
1590         PTS_TRACE_BEGIN;
1591         pts_appdata_t *ad = (pts_appdata_t *)data;
1592         PTS_RET_IF(ad == NULL, "ad is NULL");
1593
1594         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1595
1596         if (ad->list_info.active_printer) {
1597                 pts_create_scaling_popup(ad->main_info.navi, ad);
1598         } else {
1599                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1600         }
1601
1602         PTS_TRACE_END;
1603 }
1604
1605
1606 static void __pts_main_view_btn_landscape_cb(void *data, Evas_Object *obj, void *event_info)
1607 {
1608         PTS_TRACE_BEGIN;
1609         pts_appdata_t *ad = (pts_appdata_t *)data;
1610         PTS_RET_IF(ad == NULL, "ad is NULL");
1611
1612         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1613
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;
1621                 }
1622
1623                 PTS_DEBUG("ad->main_info.landscape_toggle : %d", ad->main_info.landscape_toggle);
1624
1625                 ad->list_info.active_printer->landscape = ad->main_info.landscape_toggle;
1626                 pts_main_view_rotate_image(ad, app_get_device_orientation());
1627         } else {
1628                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1629         }
1630
1631         PTS_TRACE_END;
1632 }
1633
1634 static void _dismissed_cb(void *data, Evas_Object *obj, void *event_info)
1635 {
1636         PTS_IF_DEL_OBJ(obj);
1637 }
1638
1639 static void _move_ctxpopup_more(Evas_Object *ctxpopup, Evas_Object *btn)
1640 {
1641                 pts_appdata_t *ad = pts_get_appdata();
1642                 Evas_Coord w , h;
1643                 elm_win_screen_size_get(ad->win, NULL, NULL, &w, &h);
1644
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);
1650                 } else {
1651                         evas_object_move(ctxpopup, h, w);
1652                 }
1653 }
1654
1655 static void _more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1656 {
1657         PTS_TRACE_BEGIN;
1658         //struct appdata *ad = (struct appdata *) data;
1659         Evas_Object *icon;
1660         char buf[256];
1661
1662         pts_appdata_t *ad = pts_get_appdata();
1663         PTS_RET_IF(ad == NULL, "ad is NULL");
1664
1665         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1666
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);
1670
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);
1681                 }
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);
1686         }
1687
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);
1691         } else {
1692                 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate02.png", ICON_DIR);
1693         }
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);
1696
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);
1701
1702         _move_ctxpopup_more(ad->setting_info.ctxpopup, obj);
1703
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);
1707
1708         evas_object_show(ad->setting_info.ctxpopup);
1709
1710         PTS_TRACE_END;
1711 }
1712
1713 static Evas_Object *create_toolbar_btn(Evas_Object *parent, const char *text, Evas_Smart_Cb func, void *data)
1714 {
1715         PTS_TRACE_BEGIN;
1716         Evas_Object *btn = elm_button_add(parent);
1717         if (!btn) {
1718                 return NULL;
1719         }
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);
1723         PTS_TRACE_END;
1724         return btn;
1725 }
1726
1727 static Evas_Object *create_toolbar_more_btn(Evas_Object *parent, Evas_Smart_Cb func, void *data)
1728 {
1729         PTS_TRACE_BEGIN;
1730         Evas_Object *btn = elm_button_add(parent);
1731         if (!btn) {
1732                 return NULL;
1733         }
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);
1738         PTS_TRACE_END;
1739         return btn;
1740 }
1741
1742 /*
1743  * Set accessability information - screen reader text
1744  */
1745 void generate_main_view_accessability_info(pts_appdata_t *ad,
1746                                                                                         char* main_view_accessability_text,
1747                                                                                         size_t text_max_length)
1748 {
1749         PTS_TRACE_BEGIN;
1750         PTS_RET_IF(NULL == ad || NULL == ad->list_info.active_printer, "Invalid argument");
1751
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");
1762         } else {
1763                 quality = NULL;
1764         }
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");
1772         } else {
1773                 papertype = NULL;
1774         }
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");
1780         } else {
1781                 grayscale_mode = NULL;
1782         }
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");
1786         } else {
1787                 print_range = _("IDS_BR_BODY_CURRENT_PAGE");
1788         }
1789
1790         snprintf(main_view_accessability_text, text_max_length, "%s, %d page of %d pages, %s size, %d %s,"
1791                                                                                                 " print %s, %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
1797                         papersize,
1798                         ad->list_info.active_printer->copies,
1799                         (1 == ad->list_info.active_printer->copies) ? "copy" : "copies",
1800                         print_range,
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" :
1803                         "fit to paper",
1804                         PT_ORIENTATION_PORTRAIT == ad->list_info.active_printer->landscape ? "portrait" :
1805                         PT_ORIENTATION_LANDSCAPE == ad->list_info.active_printer->landscape ? "landscape" : "auto",
1806                         quality,
1807                         papertype,
1808                         grayscale_mode,
1809                         elm_access_info_get(ad->main_info.printer_label, ELM_ACCESS_INFO));
1810
1811         PTS_TRACE_END;
1812 }
1813
1814 /*
1815 * create content of the main view screen
1816 */
1817 static Evas_Object *__pts_main_view_create_content(pts_appdata_t *ad)
1818 {
1819         PTS_TRACE_BEGIN;
1820         PTS_RETV_IF(ad == NULL, NULL, "ad is NULL");
1821
1822         /*
1823          * load preview group
1824          */
1825         ad->main_info.printer_layout = pts_create_base_layout(ad->main_info.navi, "printer");
1826
1827         pts_main_view_update_printer_label(ad);
1828
1829         /*
1830          * load preview image group
1831          */
1832         ad->main_info.img_layout = pts_create_base_layout(ad->main_info.printer_layout, "image_view");
1833
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);
1838         }
1839
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);
1843
1844         /*
1845          * Set preview layout
1846          */
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);
1850
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);
1858
1859         PTS_TRACE_END;
1860         return ad->main_info.printer_layout;
1861 }
1862
1863
1864 /*
1865 * setting button callback function
1866 */
1867 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info)
1868 {
1869         PTS_TRACE_BEGIN;
1870         pts_appdata_t *ad = (pts_appdata_t *)data;
1871         PTS_RET_IF(ad == NULL, "ad is NULL");
1872
1873         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1874
1875         if (ad->list_info.active_printer) {
1876                 pts_create_setting_view(ad);
1877         } else {
1878                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1879         }
1880
1881         PTS_TRACE_END;
1882 }
1883
1884 int pts_main_view_load_printing_data(pts_appdata_t *ad, pts_printing_data_t *printing_data)
1885 {
1886         PTS_TRACE_BEGIN;
1887         PTS_RETV_IF(ad == NULL || printing_data == NULL, -1, "Invalid argument");
1888
1889         PTS_IF_FREE_MEM(ad->printing_data.request_files);
1890         PTS_IF_FREE_MEM(ad->printing_data.type);
1891
1892         memset(&ad->printing_data, 0, sizeof(pts_printing_data_t));
1893
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);
1898
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");
1903                 PTS_TRACE_END;
1904                 return -1;
1905         }
1906
1907         int i = 0;
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]);
1912                 } else {
1913                         ad->printing_data.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
1914                 }
1915                 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
1916         }
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);
1919
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);
1923
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;
1928
1929         PTS_TRACE_END;
1930         return 0;
1931 }
1932
1933 /**
1934  *      This function let the app update printer label in the preview view
1935  *      @return  void
1936  *      @param[in] ugd the pointer to the main data structure
1937  */
1938 void pts_main_view_update_printer_label(pts_appdata_t *ad)
1939 {
1940         PTS_TRACE_BEGIN;
1941         PTS_RET_IF(ad == NULL, "ad is NULL");
1942
1943         char label_text[128] = {0,};
1944         char label_voice[128] = {0,};
1945
1946         if (ad->main_info.printer_label == NULL) {
1947                 ad->main_info.printer_label = elm_label_add(ad->main_info.printer_layout);
1948         }
1949         PTS_DEBUG("ad->list_info.active_printer is %p", ad->list_info.active_printer);
1950
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) {
1957                         free(printer_name);
1958                         printer_name = NULL;
1959                 }
1960         } else {
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"));
1963         }
1964
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);
1969
1970         elm_object_part_content_set(ad->main_info.printer_layout, "printer_name", ad->main_info.printer_label);
1971
1972         PTS_TRACE_END;
1973 }
1974
1975 /**
1976  *      This function let the app rotate the image by the given landscape
1977  *      @return   void
1978  *      @param[in] ugd the pointer to the main data structure
1979  *      @param[in] landscape the landscape value
1980  */
1981 void pts_main_view_rotate_image(pts_appdata_t *ad,
1982                                                                 app_device_orientation_e orientation)
1983 {
1984         PTS_TRACE_BEGIN;
1985         PTS_RET_IF(ad == NULL, "ad is NULL");
1986
1987         generate_preview_images(ad, orientation);
1988         g_pages_count = 0;
1989
1990         PTS_TRACE_END;
1991 }
1992
1993 /**
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
1998  */
1999 API Evas_Object *pts_create_main_view(pts_appdata_t *ad)
2000 {
2001         PTS_TRACE_BEGIN;
2002         PTS_RETV_IF((ad == NULL) || (ad->main_info.root_win == NULL), NULL, "Invalid argument");
2003
2004         Evas_Object *main_layout = NULL;
2005         Evas_Object *back_btn = NULL;
2006         Evas_Object *toolbar;
2007
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");
2012                 PTS_TRACE_END;
2013                 return NULL;
2014         }
2015
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);
2018
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);
2026
2027         main_layout = __pts_main_view_create_content(ad);
2028
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");
2033
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);
2036
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);
2042
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);
2046
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);
2051
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);
2055
2056         int tmp_width = 0;
2057         int tmp_height = 0;
2058
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
2068
2069         PTS_TRACE_END;
2070         return ad->main_info.main_layout;
2071 }