1. Changed license year
[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
32 #include <page_preview.h>
33 #include <paper_size.h>
34 #include <previewgen.h>
35 #include "pt_api.h"
36
37 #include "pts_common.h"
38 #include "pts_main_view.h"
39 #include "pts_setting_view.h"
40 #include "preview_content.h"
41 #include "preview_util.h"
42
43
44 #define MOBILEPRINT_PACKAGENAME "org.tizen.mobileprint"
45 #define ICON_DIR "/usr/apps/org.tizen.mobileprint/res/images"
46 #define ICON_SETTING "/usr/apps/org.tizen.mobileprint/res/images/pt_printer_setting.png"
47 #define MOBILEPRINT_DEFAULTIMG "/usr/share/icons/default/small/org.tizen.mobileprint.png"
48 #define MOBILEPRINT_TMP_STR "_mobileprint.pdf"
49
50 char *g_current_preview_path = NULL;
51 int g_pages_count = 0;
52
53 void _wifi_qs_monitoring_cb(keynode_t *key, void *data);
54
55 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info);
56 static Eina_Bool __pts_main_view_start_print(void *data);
57
58 static void __pts_main_view_check_usb_printer_online(void *userdata);
59 static void __pts_main_view_check_usb_printer_offline(void *userdata);
60 static void __pts_main_view_check_printer_online(void *userdata);
61 static void __pts_main_view_check_printer_offline(void *userdata);
62 static void __pts_main_view_remove_job(void *userdata, int job_id);
63 static void __pts_main_view_job_error(void *userdata, int job_id);
64 static void __pts_main_view_last_job_error(void *user_data);
65 static Eina_Bool __pts_hide_main_view(void *data);
66 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling);
67
68 static int __pts_get_real_total_pages(int original_total_pages, int n_up_number, int copies)
69 {
70         return (int)ceil((double)original_total_pages / (double)n_up_number) * copies;
71 }
72
73 static pts_job_spooling_t *__pts_get_job_spooling(pts_appdata_t *ad, int job_id)
74 {
75         PTS_TRACE_BEGIN;
76         PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
77         PTS_RETV_IF(job_id <= 0, NULL, "job_id is invalid(%d)", job_id);
78
79         Eina_List *job_spooling_list = NULL;
80         pts_job_spooling_t *job_spooling = NULL;
81
82         EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
83                 if (job_spooling->job_id == job_id) {
84                         PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
85                         break;
86                 }
87         }
88
89         PTS_RETV_IF(job_spooling == NULL, NULL, "job_spooling is NULL");
90         PTS_RETV_IF(job_spooling->job_id <= 0, NULL, "job_spooling->job_id is invalid(%d)", job_spooling->job_id);
91         PTS_TRACE_END;
92         return job_spooling;
93 }
94
95 static pts_job_spooling_t *__pts_get_last_job_spooling(pts_appdata_t *ad)
96 {
97         PTS_TRACE_BEGIN;
98         PTS_RETV_IF(ad == NULL, NULL, "Invalid parameter for __pts_get_last_job_spooling");
99
100         Eina_List *job_spooling_list = NULL;
101         pts_job_spooling_t *job_spooling = NULL;
102
103         job_spooling_list = eina_list_last(ad->noti_info.job_spooling_list);
104         PTS_RETV_IF(job_spooling_list == NULL, NULL, "No found job_spooling_list for last job");
105
106         job_spooling = (pts_job_spooling_t *)eina_list_data_get(job_spooling_list);
107         PTS_RETV_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
108                                 , NULL, "No found job_spooling for last job");
109
110         PTS_TRACE_END;
111         return job_spooling;
112 }
113
114 int __pts_update_popup_progress(pts_appdata_t *ad, pt_progress_info_t *progress_info, pts_job_spooling_t *job_spooling)
115 {
116         PTS_TRACE_BEGIN;
117         PTS_RETV_IF(ad == NULL || ad->progress_info.progressbar == NULL || progress_info == NULL || job_spooling == NULL
118                                 , 1, "Invalid parameter for __pts_update_popup_progress");
119
120         PTS_DEBUG("progress popup [%d]\n", progress_info->progress);
121         double rate = progress_info->progress * 0.01;
122         char progress_value[8] = {0,};
123         char page_value[8] = {0,};
124         char aligned_label[128] = {0,};
125         int real_total_pages = -1;
126
127         if (EINA_TRUE == elm_progressbar_pulse_get(ad->progress_info.progressbar)) {
128                 PTS_DEBUG("Stop pulsing mode\n");
129                 elm_progressbar_pulse_set(ad->progress_info.progressbar, EINA_FALSE);
130                 elm_object_style_set(ad->progress_info.progressbar, "list_progress");
131                 elm_progressbar_value_set(ad->progress_info.progressbar, 0.00);
132         }
133
134         elm_progressbar_value_set(ad->progress_info.progressbar, rate);
135
136         if (rate > 0) {
137                 snprintf(aligned_label, 128, "<align=center>%s</align>",
138                                         _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
139                 elm_object_text_set(ad->progress_info.progress_label, aligned_label);
140         }
141
142         snprintf(progress_value, 8, "%d%%", progress_info->progress);
143         elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext1", progress_value);
144         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
145                 real_total_pages = 1;
146         } else {
147                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
148                                 job_spooling->n_up, job_spooling->copies);
149         }
150         if (job_spooling->page_printed <= real_total_pages) {
151                 PTS_DEBUG("real_total_pages:%d, page_printed:%d\n", real_total_pages, job_spooling->page_printed);
152                 snprintf(page_value, 8, "%d/%d", job_spooling->page_printed, real_total_pages);
153                 elm_object_part_text_set(ad->progress_info.progress_layout, "elm.text.subtext2", page_value);
154         }
155
156         if (rate >= 1.00 && job_spooling->page_printed == real_total_pages) {
157                 PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
158                 PTS_IF_DEL_OBJ(ad->progress_info.popup);
159                 PTS_IF_DEL_OBJ(ad->main_info.root_win);
160         }
161
162         PTS_TRACE_END;
163         return 0;
164 }
165
166 int __pts_update_notification(pts_appdata_t *ad,
167                                                           pt_progress_info_t *progress_info,
168                                                           pts_job_spooling_t *job_spooling)
169 {
170         PTS_TRACE_BEGIN;
171         PTS_RETV_IF(ad == NULL || progress_info == NULL || job_spooling == NULL
172                                 , -1 ,"Invalid parameters for update_notification");
173
174         double rate = progress_info->progress * 0.01;
175         PTS_RETV_IF(job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE || job_spooling->noti_handle == NULL
176                                 , -1 , "Invalid noti parameters for update_notification");
177
178         // Remove notification after all page is printed
179         if (progress_info->page_printed > job_spooling->page_printed) {
180                 if (job_spooling->noti_id != NOTIFICATION_PRIV_ID_NONE) {
181                         int ret;
182                         notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
183                         PTS_DEBUG("Notification is deleted");
184                         job_spooling->noti_id = NOTIFICATION_PRIV_ID_NONE;
185                         ret = notification_free(job_spooling->noti_handle);
186                         if (ret != NOTIFICATION_ERROR_NONE) {
187                                 PTS_DEBUG("Failed to free notification handle [%d]", ret);
188                         }
189                         job_spooling->noti_handle = NULL;
190                         job_spooling->page_printed = progress_info->page_printed; // XXX
191                 }
192         }
193
194         if (job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE && job_spooling->noti_handle == NULL) {
195                 int real_total_pages = -1;
196
197                 if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
198                         real_total_pages = 1;
199                 } else {
200                         real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
201                                                                                         job_spooling->n_up, job_spooling->copies);
202                 }
203                 if (job_spooling->page_printed <= real_total_pages) {
204                         PTS_DEBUG("Create new notification for page %d", job_spooling->page_printed);
205                         __pts_create_notification_by_page(ad, job_spooling);
206                 }
207                 PTS_TRACE_END;
208                 return 0;
209         }
210
211         notification_update_progress(NULL, job_spooling->noti_id, rate);
212
213         PTS_TRACE_END;
214         return 0;
215 }
216
217 int __pts_remove_notification(int noti_id)
218 {
219         PTS_TRACE_BEGIN;
220
221         if (noti_id != NOTIFICATION_PRIV_ID_NONE) {
222                 notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, noti_id);
223                 PTS_DEBUG("Notification is deleted");
224         }
225
226         PTS_TRACE_END;
227         return 0;
228 }
229
230 int __pts_create_dummy_notification(pts_appdata_t *ad)
231 {
232         PTS_TRACE_BEGIN;
233         PTS_RETV_IF(ad == NULL, -1, "Invalid paramter for __pts_create_dummy_notification");
234
235         int res = -1;
236         notification_h noti = NULL;
237
238         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
239                                                         NOTIFICATION_GROUP_ID_NONE,
240                                                         NOTIFICATION_PRIV_ID_NONE);
241
242         PTS_RETV_IF(noti == NULL, -1, "Failed to create Notification");
243
244         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"),
245                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
246         if (res != NOTIFICATION_ERROR_NONE) {
247                 PTS_DEBUG("Failed to set Notification title [%d]", res);
248                 goto ERR_CASE;
249         }
250
251         char *printer_label = strdup(ad->list_info.active_printer->name);
252         pts_unstandardization(printer_label);
253         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
254         if (res != NOTIFICATION_ERROR_NONE) {
255                 PTS_DEBUG("Failed to set Notification title [%d]", res);
256                 goto ERR_CASE;
257         }
258         if (printer_label != NULL) {
259                 free(printer_label);
260                 printer_label = NULL;
261         }
262
263         bundle *b = NULL;
264         b = bundle_create();
265         char value[4] = {0,};
266
267         if (!strcasecmp(ad->printing_data.type, "DOC") || !strcasecmp(ad->printing_data.type, "WEB")) {
268                 PTS_DEBUG("It's pdf file. [%s]", ad->printing_data.type);
269                 ad->printing_data.range.total_pages = get_pdf_pages_count(ad->printing_data.request_files[0]);
270         } else {
271                 PTS_DEBUG("It's not pdf file. [%s]", ad->printing_data.type);
272                 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
273         }
274         // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
275         int real_total_pages = -1;
276         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
277                 real_total_pages = 1;
278         } else {
279                 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
280                                                                 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
281         }
282         snprintf(value, 4, "%d", real_total_pages);
283         appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
284         appsvc_add_data(b, SERVICE_FILES, ad->printing_data.request_files[0]);
285         appsvc_add_data(b, SERVICE_PAGE_COUNT, value);
286         appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_DUMMY_NOTI);
287
288         res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
289         if (res != NOTIFICATION_ERROR_NONE) {
290                 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
291                 goto ERR_CASE;
292         }
293         bundle_free(b);
294
295         res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
296         if (res != NOTIFICATION_ERROR_NONE) {
297                 PTS_DEBUG("Failed to set image icon");
298                 goto ERR_CASE;
299         }
300
301         res = notification_insert(noti, &(ad->noti_info.dummy_noti_id));
302         if (res != NOTIFICATION_ERROR_NONE) {
303                 PTS_DEBUG("Failed to insert Notification [%d]", res);
304                 goto ERR_CASE;
305         }
306         PTS_DEBUG("Notification ID [%d]", ad->noti_info.dummy_noti_id);
307
308         PTS_TRACE_END;
309         return 0;
310
311 ERR_CASE:
312         if (printer_label != NULL) {
313                 free(printer_label);
314                 printer_label = NULL;
315         }
316
317         if (noti != NULL) {
318                 notification_free(noti);
319                 noti = NULL;
320         }
321
322         if (b != NULL) {
323                 bundle_free(b);
324                 b = NULL;
325         }
326
327         PTS_TRACE_END;
328         return -1;
329 }
330
331 static int __pts_create_notification_by_page(pts_appdata_t *ad, pts_job_spooling_t *job_spooling)
332 {
333         PTS_TRACE_BEGIN;
334         PTS_RETV_IF(ad == NULL || job_spooling == NULL
335                                 , -1, "Invalid parameter for __pts_create_notification_by_page");
336
337         int res = -1;
338         notification_h noti = NULL;
339         double rate = 0.00;
340         char title[32] = {0,};
341
342         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
343                                                         NOTIFICATION_GROUP_ID_NONE,
344                                                         NOTIFICATION_PRIV_ID_NONE);
345
346         if (noti == NULL) {
347                 PTS_DEBUG("Failed to create Notification");
348                 goto ERR_CASE;
349         }
350
351         //re-allocate noti handle
352         job_spooling->noti_handle = noti;
353
354         int real_total_pages = -1;
355         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
356                 real_total_pages = 1;
357         } else {
358                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
359                                                                         job_spooling->n_up, job_spooling->copies);
360         }
361         snprintf(title, 32, "%s (%d/%d)",
362                          _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), job_spooling->page_printed, real_total_pages);
363         PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
364
365         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
366                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
367         if (res != NOTIFICATION_ERROR_NONE) {
368                 PTS_DEBUG("Failed to set Notification title [%d]", res);
369                 goto ERR_CASE;
370         }
371
372         char *printer_label = strdup(ad->list_info.active_printer->name);
373         pts_unstandardization(printer_label);
374         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
375         if (res != NOTIFICATION_ERROR_NONE) {
376                 PTS_DEBUG("Failed to set Notification title [%d]", res);
377                 goto ERR_CASE;
378         }
379         if (printer_label != NULL) {
380                 free(printer_label);
381                 printer_label = NULL;
382         }
383
384         res = notification_set_progress(noti, rate);
385         if (res != NOTIFICATION_ERROR_NONE) {
386                 PTS_DEBUG("Failed to set Notification title [%d]", res);
387                 goto ERR_CASE;
388         }
389
390         bundle *b = NULL;
391         b = bundle_create();
392         char value1[4] = {0,};
393         char value2[4] = {0,};
394         snprintf(value1, 4, "%d", job_spooling->job_id);
395         snprintf(value2, 4, "%d", real_total_pages);
396         appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
397         appsvc_add_data(b, SERVICE_JOB_ID, value1);
398         appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
399         appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
400
401         res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
402         if (res != NOTIFICATION_ERROR_NONE) {
403                 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
404                 goto ERR_CASE;
405         }
406         bundle_free(b);
407
408         res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
409         if (res != NOTIFICATION_ERROR_NONE) {
410                 PTS_DEBUG("Failed to set image icon");
411                 goto ERR_CASE;
412         }
413
414         res = notification_insert(noti, &job_spooling->noti_id);
415         if (res != NOTIFICATION_ERROR_NONE) {
416                 PTS_DEBUG("Failed to insert Notification [%d]", res);
417                 goto ERR_CASE;
418         }
419         PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
420
421         PTS_TRACE_END;
422         return 0;
423
424 ERR_CASE:
425         if (printer_label != NULL) {
426                 free(printer_label);
427                 printer_label = NULL;
428         }
429
430         if (job_spooling->noti_handle != NULL) {
431                 notification_free(job_spooling->noti_handle);
432                 job_spooling->noti_handle = NULL;
433         }
434
435         if (b != NULL) {
436                 bundle_free(b);
437                 b = NULL;
438         }
439
440         PTS_TRACE_END;
441         return -1;
442 }
443
444 int __pts_create_job_notification(pts_appdata_t *ad, int job_id)
445 {
446         PTS_TRACE_BEGIN;
447         PTS_RETV_IF(ad == NULL || job_id <=0
448                                 , -1 , "Invalid parameter for __pts_create_job_notification");
449
450         int res = -1;
451         notification_h noti = NULL;
452         double rate = 0.00;
453         char title[32] = {0,};
454
455         pts_job_spooling_t *job_spooling = malloc(sizeof(pts_job_spooling_t));
456         PTS_RETV_IF(job_spooling == NULL, -1 , "Failed to malloc job_spooling");
457         memset(job_spooling, 0, sizeof(pts_job_spooling_t));
458
459         //FIXME - pt_files.files should be managed carefully during printing
460         job_spooling->pt_files.num_of_files = ad->printing_data.num_of_files;
461         job_spooling->pt_files.current_index = ad->printing_data.current_index;
462
463         job_spooling->pt_files.type = strdup(ad->printing_data.type); // need malloc
464         if (job_spooling->pt_files.type == NULL) {
465                 PTS_DEBUG("Failed to malloc job_spooling->pt_files.type");
466                 goto ERR_CASE;
467         }
468
469         job_spooling->pt_files.request_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.num_of_files);
470         if (job_spooling->pt_files.request_files == NULL) {
471                 PTS_DEBUG("Failed to malloc job_spooling->pt_files.request_files");
472                 goto ERR_CASE;
473         }
474         int i = 0;
475         for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
476                 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
477                 if (NULL != ad->printing_data.request_files[i]) {
478                         job_spooling->pt_files.request_files[i] = strdup(ad->printing_data.request_files[i]);
479                 } else {
480                         job_spooling->pt_files.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
481                 }
482                 PTS_DEBUG("file path is %s", job_spooling->pt_files.request_files[i]);
483         }
484
485         job_spooling->input_file = strdup(job_spooling->pt_files.request_files[0]);
486         if (job_spooling->input_file == NULL) {
487                 PTS_DEBUG("Failed to malloc job_spooling->input_file");
488                 goto ERR_CASE;
489         }
490
491         job_spooling->pt_files.range.from = ad->printing_data.range.from;
492         job_spooling->pt_files.range.to = ad->printing_data.range.to;
493         job_spooling->pt_files.range.total_pages = ad->printing_data.range.total_pages;
494
495         job_spooling->pt_files.range.selected_files = (char **)malloc(sizeof(char *) * job_spooling->pt_files.range.total_pages);
496         if (job_spooling->pt_files.range.selected_files == NULL) {
497                 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files");
498                 goto ERR_CASE;
499         }
500
501         job_spooling->pt_files.range.selected_files[0] = strdup(ad->printing_data.range.selected_files[0]);
502         if (job_spooling->pt_files.range.selected_files[0] == NULL) {
503                 PTS_DEBUG("Failed to malloc job_spooling->pt_files.range.selected_files[0]");
504                 goto ERR_CASE;
505         }
506
507         job_spooling->job_id = job_id;
508 #if 0 // Need to believe passed "Printing page X X" log have correct information.
509         if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
510                 job_spooling->page_printed = 1;    // FIXME
511         }
512 #endif
513
514         noti = notification_new(NOTIFICATION_TYPE_ONGOING,
515                                                         NOTIFICATION_GROUP_ID_NONE,
516                                                         NOTIFICATION_PRIV_ID_NONE);
517         if (noti == NULL) {
518                 PTS_DEBUG("Failed to create Notification");
519                 goto ERR_CASE;
520         }
521
522         job_spooling->noti_handle = noti;
523
524         job_spooling->n_up = printer_get_setting_n_up(ad->list_info.active_printer);
525
526         job_spooling->copies = ad->list_info.active_printer->copies;
527
528         int real_total_pages = -1;
529         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
530                 real_total_pages = 1;
531         } else {
532                 real_total_pages = __pts_get_real_total_pages(job_spooling->pt_files.range.total_pages,
533                                                                         job_spooling->n_up, job_spooling->copies);
534         }
535         snprintf(title, 32, "%s (1/%d)", _("IDS_PRT_HEADER_MEDIABOX_PRINTING"), real_total_pages);
536         PTS_DEBUG("notification update: handle[%d] title=[%s]", job_spooling->noti_handle, title);
537
538         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, title,
539                                                                 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
540         if (res != NOTIFICATION_ERROR_NONE) {
541                 PTS_DEBUG("Failed to set Notification title [%d]", res);
542                 goto ERR_CASE;
543         }
544
545         char *printer_label = strdup(ad->list_info.active_printer->name);
546         pts_unstandardization(printer_label);
547         res = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, printer_label, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
548         if (res != NOTIFICATION_ERROR_NONE) {
549                 PTS_DEBUG("Failed to set Notification title [%d]", res);
550                 goto ERR_CASE;
551         }
552         if (printer_label != NULL) {
553                 free(printer_label);
554                 printer_label = NULL;
555         }
556
557         res = notification_set_progress(noti, rate);
558         if (res != NOTIFICATION_ERROR_NONE) {
559                 PTS_DEBUG("Failed to set Notification title [%d]", res);
560                 goto ERR_CASE;
561         }
562
563         bundle *b = NULL;
564         b = bundle_create();
565         char value1[4] = {0,};
566         char value2[4] = {0,};
567         snprintf(value1, 4, "%d", job_id);
568         snprintf(value2, 4, "%d", real_total_pages);
569         appsvc_set_pkgname(b, MOBILEPRINT_PACKAGENAME);
570         appsvc_add_data(b, SERVICE_JOB_ID, value1);
571         appsvc_add_data(b, SERVICE_PAGE_COUNT, value2);
572         appsvc_add_data(b, SERVICE_LAUNCH_TYPE, LAUNCH_FROM_PROGRESS_NOTI);
573
574         res = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
575         if (res != NOTIFICATION_ERROR_NONE) {
576                 PTS_DEBUG("Failed to notification_set_execute_option. [%d]", res);
577                 bundle_free(b);
578                 goto ERR_CASE;
579         }
580         bundle_free(b);
581
582         res = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A01_print_popup_icon_print.png");
583         if (res != NOTIFICATION_ERROR_NONE) {
584                 PTS_DEBUG("Failed to set image icon");
585                 goto ERR_CASE;
586         }
587
588         res = notification_insert(noti, &job_spooling->noti_id);
589         if (res != NOTIFICATION_ERROR_NONE) {
590                 PTS_DEBUG("Failed to insert Notification [%d]", res);
591                 goto ERR_CASE;
592         }
593         PTS_DEBUG("Notification ID [%d]", job_spooling->noti_id);
594
595         ad->noti_info.job_spooling_list = eina_list_append(ad->noti_info.job_spooling_list, job_spooling);
596         if (eina_error_get()) {
597                 PTS_DEBUG("Failed to append job_spooling");
598                 goto ERR_CASE;
599         }
600
601         PTS_TRACE_END;
602
603         return 0;
604
605 ERR_CASE:
606         if (printer_label != NULL) {
607                 free(printer_label);
608                 printer_label = NULL;
609         }
610
611         if (job_spooling != NULL) {
612                 if (job_spooling->pt_files.type != NULL) {
613                         PTS_IF_FREE_MEM(job_spooling->pt_files.type);
614                         job_spooling->pt_files.type = NULL;
615                 }
616
617                 if (job_spooling->pt_files.request_files != NULL) {
618                         int i = 0;
619                         for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
620                                 if (job_spooling->pt_files.request_files[i] != NULL) {
621                                         PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]);
622                                         job_spooling->pt_files.request_files[i] = NULL;
623                                 }
624                         }
625                         PTS_IF_FREE_MEM(job_spooling->pt_files.request_files);
626                         job_spooling->pt_files.request_files = NULL;
627                 }
628
629                 if (job_spooling->input_file != NULL) {
630                         PTS_IF_FREE_MEM(job_spooling->input_file);
631                         job_spooling->input_file = NULL;
632                 }
633
634                 if (job_spooling->pt_files.range.selected_files != NULL) {
635                         if (job_spooling->pt_files.range.selected_files[0] != NULL) {
636                                 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
637                                 job_spooling->pt_files.range.selected_files[0] = NULL;
638                         }
639
640                         PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
641                         job_spooling->pt_files.range.selected_files = NULL;
642                 }
643
644                 if (job_spooling->noti_handle != NULL) {
645                         notification_free(job_spooling->noti_handle);
646                         job_spooling->noti_handle = NULL;
647                 }
648
649                 PTS_IF_FREE_MEM(job_spooling);
650                 job_spooling = NULL;
651         }
652
653         PTS_TRACE_END;
654         return -1;
655 }
656
657 static gboolean __pts_main_view_job_monitor_timeout_cb(void *data)
658 {
659         PTS_TRACE_BEGIN;
660         pts_appdata_t *ad = (pts_appdata_t *)data;
661         PTS_RETV_IF(ad == NULL, TRUE, "ad is NULL");
662
663         pt_job_state_e job_status = PT_JOB_ERROR;
664         gboolean ret = FALSE;
665
666         //char noti_name[512] = {0};
667
668         //FIXME - need to check one or all?
669         Eina_List *job_spooling_list = NULL;
670         pts_job_spooling_t *job_spooling = NULL;
671         EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
672                 job_status = pt_get_current_job_status(job_spooling->job_id);
673                 if (job_status == PT_JOB_PROCESSING || job_status == PT_JOB_PENDING) {
674                         PTS_DEBUG("job_id[%d] status is %d", job_spooling->job_id, job_status);
675                         //XXX - If any one of job list is processing or pending, then motinor cb will be called again.
676                         ret = TRUE;
677                 }
678         }
679
680         PTS_TRACE_END;
681
682         return ret;
683 }
684
685 void __pts_event_cb(pt_event_e event, void *user_data, pt_progress_info_t *progress_info)
686 {
687         PTS_TRACE_BEGIN;
688
689         // XXX - progress_info can be passed by NULL
690         PTS_RET_IF(event < 0 || user_data == NULL, "Invalid parameters for event cb");
691
692         pts_appdata_t *ad = (pts_appdata_t *)user_data;
693         pts_job_spooling_t *job_spooling = NULL;
694
695         switch (event) {
696         case PT_EVENT_USB_PRINTER_ONLINE:
697                 __pts_main_view_check_usb_printer_online(ad);
698                 break;
699         case PT_EVENT_USB_PRINTER_OFFLINE:
700                 __pts_main_view_check_usb_printer_offline(ad);
701                 break;
702         case PT_EVENT_PRINTER_ONLINE:
703                 __pts_main_view_check_printer_online(ad);
704                 break;
705         case PT_EVENT_PRINTER_OFFLINE:
706                 __pts_main_view_check_printer_offline(ad);
707                 break;
708         case PT_EVENT_JOB_COMPLETED:
709                 PTS_DEBUG("Job[%d] is completed.", progress_info->job_id);
710                 __pts_main_view_remove_job(ad, progress_info->job_id);
711                 break;
712         case PT_EVENT_JOB_STARTED:
713                 PTS_DEBUG("Job id %d is allocated", progress_info->job_id);
714                 __pts_remove_notification(ad->noti_info.dummy_noti_id);
715                 ad->noti_info.dummy_noti_id = 0;
716                 __pts_create_job_notification(ad, progress_info->job_id);
717                 g_timeout_add(5000, (GSourceFunc)__pts_main_view_job_monitor_timeout_cb, ad);
718                 break;
719         case PT_EVENT_JOB_PROCESSING:
720                 PTS_DEBUG("Job[%d] is processing.", progress_info->job_id);
721                 break;
722         case PT_EVENT_JOB_PROGRESS:
723                 job_spooling = __pts_get_job_spooling(ad, progress_info->job_id);
724                 if (job_spooling != NULL) {
725                         PTS_DEBUG("new - progress_info: job_id[%d] progress[%d] page_printed[%d]\n"
726                                 "old - job_spooling: job_id[%d] progress[%d] page_printed[%d]",
727                                 progress_info->job_id, progress_info->progress, progress_info->page_printed,
728                                 job_spooling->job_id, job_spooling->progress, job_spooling->page_printed);
729
730 #if 0
731                         //FIXME
732                         if (NULL == strcasestr(ugd->active_printer->name, "samsung")) {
733                                 if (progress_info->progress < job_spooling->progress) {
734                                         //FIXME - assume next page printing is started
735                                         job_spooling->page_printed++;
736                                 }
737                         }
738 #endif
739
740                         job_spooling->progress = progress_info->progress;
741                 }
742                 __pts_update_notification(ad, progress_info, job_spooling);
743                 __pts_update_popup_progress(ad, progress_info, job_spooling);
744                 break;
745         case PT_EVENT_JOB_PENDING:
746                 PTS_DEBUG("Job[%d] is waiting.", progress_info->job_id);
747                 break;
748         case PT_EVENT_JOB_HELD:
749                 PTS_DEBUG("Job[%d] is held.", progress_info->job_id);
750                 break;
751         case PT_EVENT_JOB_STOPPED:
752                 PTS_DEBUG("Job[%d] is stopped.", progress_info->job_id);
753                 __pts_main_view_job_error(ad, progress_info->job_id);
754                 __pts_main_view_remove_job(ad, progress_info->job_id);
755                 break;
756         case PT_EVENT_JOB_CANCELED:
757                 PTS_DEBUG("Job[%d] is canceled.", progress_info->job_id);
758                 __pts_main_view_job_error(ad, progress_info->job_id);
759                 __pts_main_view_remove_job(ad, progress_info->job_id);
760                 break;
761         case PT_EVENT_JOB_ABORTED:
762                 PTS_DEBUG("Job[%d] is aborted.", progress_info->job_id);
763                 if (progress_info->job_id > 0) {
764                         __pts_main_view_job_error(ad, progress_info->job_id);
765                         __pts_main_view_remove_job(ad, progress_info->job_id);
766                 } else { // XXX - for dummy job?
767                         __pts_main_view_last_job_error(ad);
768                 }
769                 break;
770         case PT_EVENT_JOB_ERROR:
771                 PTS_DEBUG("Job[%d] error", progress_info->job_id);
772                 __pts_main_view_job_error(ad, progress_info->job_id);
773                 __pts_main_view_remove_job(ad, progress_info->job_id);
774                 break;
775         case PT_EVENT_ALL_THREAD_COMPLETED:
776                 PTS_DEBUG("All thread is completed.");
777                 PTS_DEBUG("No more job, then terminate mobileprint");
778                 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
779                 pt_deinit();
780                 elm_exit();
781                 break;
782         default:
783                 break;
784         }
785
786         PTS_TRACE_END;
787 }
788
789 static void __pts_main_view_check_usb_printer_online(void *userdata)
790 {
791         PTS_TRACE_BEGIN;
792         pts_appdata_t *ad = (pts_appdata_t *)userdata;
793         PTS_RET_IF(ad == NULL, "ad is NULL");
794
795         /* if in ether searching or printing, ignore it */
796         PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
797
798         PTS_IF_DEL_OBJ(ad->progress_info.popup);
799
800         elm_naviframe_item_pop_to(ad->main_info.navi_it);
801
802         /* re-searching printers */
803         ad->search_info.print_search_mode = PTS_SEARCH_INITIAL;
804         ad->search_info.selection_done_cb = load_main_view;
805         ad->search_info.print_search_popup_parent = ad->main_info.root_win;
806         ad->search_info.printer_search_user_data = NULL;
807         pts_search_printer(ad);
808         //pts_main_view_search_printer(ugd);
809
810         PTS_TRACE_END;
811 }
812
813 static void __pts_main_view_check_usb_printer_offline(void *userdata)
814 {
815         PTS_TRACE_BEGIN;
816         pts_appdata_t *ad = (pts_appdata_t *)userdata;
817         PTS_RET_IF(ad == NULL, "ad is NULL");
818
819         /* if in searching or printing, return */
820         PTS_RET_IF(ad->search_info.is_process == 1, "searching or printing is processing");
821         PTS_IF_DEL_OBJ(ad->progress_info.popup);
822         PTS_IF_FREE_MEM(ad->list_info.active_printer);
823
824         elm_naviframe_item_pop_to(ad->main_info.navi_it);
825
826         pts_main_view_update_printer_label(ad);
827
828         PTS_TRACE_END;
829 }
830
831 static void __pts_main_view_remove_job(void *user_data, int job_id)
832 {
833         PTS_TRACE_BEGIN;
834         PTS_RET_IF(user_data == NULL || job_id <= 0,"Invalid parameter for job error processing");
835
836         pts_appdata_t *ad = (pts_appdata_t *)user_data;
837         int ret;
838
839         if (NULL != ad->progress_info.popup) {
840                 evas_object_del(ad->progress_info.popup);
841                 ad->progress_info.popup = NULL;
842                 evas_object_hide(ad->main_info.root_win);
843         }
844
845         Eina_List *job_spooling_list = NULL;
846         pts_job_spooling_t *job_spooling = NULL;
847
848         EINA_LIST_FOREACH(ad->noti_info.job_spooling_list, job_spooling_list, job_spooling) {
849                 if (job_spooling->job_id == job_id) {
850                         PTS_DEBUG("Found job_spooling for job_id[%d]", job_id);
851                         break;
852                 }
853         }
854
855         PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
856                            ,"No found job_spooling for job_id[%d]\n", job_id);
857
858         notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
859         ad->search_info.is_process = 0;/*process is complete*/
860
861         ad->noti_info.job_spooling_list = eina_list_remove_list(ad->noti_info.job_spooling_list, job_spooling_list);
862         if (0 == eina_list_count(ad->noti_info.job_spooling_list)) {
863                 PTS_DEBUG("Job spooling list is empty");
864                 ad->noti_info.job_spooling_list = NULL;
865         }
866
867         if (job_spooling->noti_handle != NULL) {
868                 ret = notification_free(job_spooling->noti_handle);
869                 if (ret != NOTIFICATION_ERROR_NONE) {
870                         PTS_DEBUG("Failed to free notification handle [%d]", ret);
871                 }
872                 job_spooling->noti_handle = NULL;
873         }
874
875         PTS_RET_IF(job_spooling->pt_files.range.selected_files == NULL, "job_spooling->pt_files.range.selected_files is NULL");
876
877         if (job_spooling->pt_files.range.selected_files[0]) {
878                 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files[0]);
879                 job_spooling->pt_files.range.selected_files[0] = NULL;
880         }
881
882         if (job_spooling->pt_files.range.selected_files) {
883                 PTS_IF_FREE_MEM(job_spooling->pt_files.range.selected_files);
884                 job_spooling->pt_files.range.selected_files = NULL;
885         }
886
887         if (job_spooling->input_file) {
888                 PTS_IF_FREE_MEM(job_spooling->input_file);
889                 job_spooling->input_file = NULL;
890         }
891
892         int i = 0;
893         for (i = 0; i < job_spooling->pt_files.num_of_files; i++) {
894                 if (job_spooling->pt_files.request_files[i]) {
895                         PTS_IF_FREE_MEM(job_spooling->pt_files.request_files[i]); // FIXME
896                         job_spooling->pt_files.request_files[i] = NULL;
897                 }
898         }
899
900         if (job_spooling->pt_files.request_files) {
901                 PTS_IF_FREE_MEM(job_spooling->pt_files.request_files); // FIXME
902                 job_spooling->pt_files.request_files = NULL;
903         }
904
905         if (job_spooling->pt_files.type) {
906                 PTS_IF_FREE_MEM(job_spooling->pt_files.type);
907                 job_spooling->pt_files.type = NULL;
908         }
909
910         if (job_spooling) {
911                 PTS_IF_FREE_MEM(job_spooling);
912                 job_spooling = NULL;
913         }
914
915         PTS_TRACE_END;
916 }
917
918 static void __pts_main_view_job_error(void *user_data, int job_id)
919 {
920         PTS_TRACE_BEGIN;
921         PTS_RET_IF(user_data == NULL || job_id <= 0, "Invalid parameter for job error processing");
922
923         pts_appdata_t *ad = (pts_appdata_t *)user_data;
924         PTS_IF_DEL_OBJ(ad->progress_info.popup);
925
926         pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
927
928         PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
929                            , "No found job_spooling for job_id[%d]\n", job_id);
930
931         notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
932         ad->search_info.is_process = 0;/*process is complete*/
933         pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
934         evas_object_show(ad->main_info.root_win);
935         ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
936         PTS_TRACE_END;
937 }
938
939 static void __pts_main_view_last_job_error(void *user_data)
940 {
941         PTS_TRACE_BEGIN;
942         PTS_RET_IF(user_data == NULL, "Invalid parameter for last job error processing");
943
944         pts_appdata_t *ad = (pts_appdata_t *)user_data;
945         PTS_IF_DEL_OBJ(ad->progress_info.popup);
946
947         pts_job_spooling_t *job_spooling = __pts_get_last_job_spooling(ad);
948         PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
949                            , "No found job_spooling for last_job");
950
951         notification_delete_by_priv_id(MOBILEPRINT_PACKAGENAME, NOTIFICATION_TYPE_ONGOING, job_spooling->noti_id);
952         ad->search_info.is_process = 0;/*process is complete*/
953         pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTINGERROR"), 2.0);
954         evas_object_show(ad->main_info.root_win);
955         ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
956         PTS_TRACE_END;
957 }
958
959
960 static void __pts_main_view_check_printer_online(void *user_data)
961 {
962         PTS_TRACE_BEGIN;
963         PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_online");
964
965         pts_appdata_t *ad = (pts_appdata_t *)user_data;
966         ecore_timer_add(1.0, (Ecore_Task_Cb)__pts_main_view_start_print, ad);
967
968         PTS_TRACE_END;
969 }
970
971 static void __pts_main_view_check_printer_offline(void *user_data)
972 {
973         PTS_TRACE_BEGIN;
974         PTS_RET_IF(user_data == NULL, "Invalid parameter for __pts_main_view_check_printer_offline");
975
976         pts_appdata_t *ad = (pts_appdata_t *)user_data;
977         PTS_IF_DEL_OBJ(ad->progress_info.popup);
978         PTS_IF_FREE_MEM(ad->list_info.active_printer);
979
980         pts_main_view_update_printer_label(ad);
981         pts_create_popup(ad->main_info.navi, _("IDS_PRT_POP_CHECKPRINTERSTATE"), 2.0);
982         ad->search_info.is_process = 0;/* process is complete */
983
984         PTS_TRACE_END;
985 }
986
987 static void __pts_main_view_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
988 {
989         PTS_TRACE_BEGIN;
990         pts_appdata_t *ad = (pts_appdata_t *)data;
991         PTS_RET_IF(ad == NULL, "ad is NULL");
992
993 #if 0
994         if (NULL != ugd->pt_files.request_files) {
995                 int i = 0;
996                 for (i = 0; i < ugd->pt_files.num_of_files; i++) {
997                         if (ugd->pt_files.request_files[i] != NULL) {
998                                 free(ugd->pt_files.request_files[i]);
999                                 ugd->pt_files.request_files[i] = NULL;
1000                         }
1001                 }
1002
1003                 if (ugd->pt_files.range.selected_files != NULL) {
1004                         free(ugd->pt_files.range.selected_files);
1005                         ugd->pt_files.range.selected_files = NULL;
1006                 }
1007
1008                 free(ugd->pt_files.request_files);
1009                 ugd->pt_files.request_files = NULL;
1010         }
1011 #endif
1012
1013         PTS_TRACE_END;
1014 }
1015
1016 static void __pts_main_view_navi_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
1017 {
1018         PTS_TRACE_BEGIN;
1019         pts_appdata_t *ad = (pts_appdata_t *)data;
1020         PTS_RET_IF(ad == NULL, "ad is NULL");
1021
1022         PTS_IF_FREE_MEM(ad->list_info.active_printer);
1023
1024         PTS_TRACE_END;
1025 }
1026
1027 /*
1028 * "back" button callback
1029 */
1030 void __pts_main_view_btn_back_cb(void *data, Evas_Object *obj, void *event_info)
1031 {
1032         PTS_TRACE_BEGIN;
1033         pts_appdata_t *ad = (pts_appdata_t *) data;
1034         PTS_RET_IF(ad == NULL, "ad is NULL");
1035         //TODO - check current spooling job status before app termination
1036         if (ad->noti_info.job_spooling_list == NULL) {
1037                 vconf_ignore_key_changed(VCONFKEY_WIFI_QS_EXIT, _wifi_qs_monitoring_cb);
1038                 pt_deinit();
1039                 elm_exit();
1040         } else {
1041                 PTS_DEBUG("Active job spooling list is existed. So just hide preview.");
1042                 __pts_hide_main_view(ad);
1043         }
1044         PTS_TRACE_END;
1045 }
1046
1047 static void __pts_main_view_dummy_cancel_print(void *data, Evas_Object *obj, void *event_info)
1048 {
1049         PTS_TRACE_BEGIN;
1050
1051         pts_appdata_t *ad = pts_get_appdata();
1052         PTS_RET_IF(ad == NULL, "ad is NULL");
1053
1054         PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1055         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1056
1057         pts_create_popup(ad->main_info.root_win, PTS_19, 2.0);
1058         evas_object_show(ad->main_info.root_win);
1059         ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1060
1061         PTS_TRACE_END;
1062 }
1063
1064 static void __pts_main_view_response_cancel_print(void *data, Evas_Object *obj, void *event_info)
1065 {
1066         PTS_TRACE_BEGIN;
1067         int job_id = (int)data;
1068         pts_appdata_t *ad = pts_get_appdata();
1069         PTS_RET_IF(ad == NULL || job_id <= 0, "Invalid parameter for __pts_main_view_response_cancel_print");
1070         PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1071         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1072
1073         pt_cancel_print(job_id);
1074
1075         pts_job_spooling_t *job_spooling = __pts_get_job_spooling(ad, job_id);
1076         PTS_RET_IF(job_spooling == NULL || job_spooling->noti_id == NOTIFICATION_PRIV_ID_NONE
1077                            , "No found job_spooling for job[%d]\n", job_id);
1078
1079         // FIXME - Is it better to do this job after received canceled evt_cb?
1080         __pts_remove_notification(job_spooling->noti_id);
1081
1082         pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PRINTING_CANCELED"), 2.0);
1083         evas_object_show(ad->main_info.root_win);
1084         ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1085
1086         PTS_TRACE_END;
1087 }
1088
1089 static void __pts_hide_progress_popup(void *data, Evas_Object *obj, void *event_info)
1090 {
1091         PTS_TRACE_BEGIN;
1092         pts_appdata_t *ad = (pts_appdata_t *)data;
1093         PTS_RET_IF(ad == NULL, "ad is NULL");
1094
1095         PTS_IF_DEL_OBJ(ad->progress_info.progressbar);
1096         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1097
1098         evas_object_hide(ad->main_info.root_win);
1099
1100         PTS_TRACE_END;
1101 }
1102
1103 void __pts_print_dummy_popup(pts_appdata_t *ad, char *files, int page_count)
1104 {
1105         PTS_TRACE_BEGIN;
1106         PTS_RET_IF(ad == NULL || files == NULL || page_count <= 0, "Invalid parameters for progress_popup");
1107
1108         Evas_Object *label1 = NULL;
1109         Evas_Object *label2 = NULL;
1110         Evas_Object *label3 = NULL;
1111         Evas_Object *popup = NULL;
1112         Evas_Object *layout = NULL;
1113         Evas_Object *progressbar = NULL;
1114         char page_info[8] = {0,};
1115         char aligned_label[128] = {0,};
1116
1117         popup = elm_popup_add(ad->main_info.main_layout);
1118
1119         label1 = elm_label_add(popup);
1120         elm_object_style_set(label1, "popup/progressview");
1121         elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1122         char *printer_label = strdup(ad->list_info.active_printer->name);
1123         pts_unstandardization(printer_label);
1124         snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1125         elm_object_text_set(label1, aligned_label);
1126         if (printer_label != NULL) {
1127                 /* accessability - screen reader support */
1128                 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1129                 free(printer_label);
1130                 printer_label = NULL;
1131         }
1132         evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1133         evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1134         evas_object_show(label1);
1135
1136         label2 = elm_label_add(popup);
1137         elm_object_style_set(label2, "popup/progressview");
1138         elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1139         snprintf(aligned_label, 128, "<align=center>%s</align>",
1140                                 _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1141         elm_object_text_set(label2, aligned_label);
1142         /* accessability - screen reader support */
1143         elm_access_info_set(label2, ELM_ACCESS_INFO, _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1144         evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1145         evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1146         evas_object_show(label2);
1147
1148         label3 = elm_label_add(popup);
1149         elm_object_style_set(label3, "popup/progressview");
1150         elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1151         snprintf(aligned_label, 128, "<align=center>%s</align>", basename(files));
1152         elm_object_text_set(label3, aligned_label);
1153         /* accessability - screen reader support */
1154         elm_access_info_set(label3, ELM_ACCESS_INFO, basename(files));
1155         evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1156         evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1157         evas_object_show(label3);
1158
1159         layout = pts_create_base_layout(popup, "popup_progress");
1160
1161         progressbar = elm_progressbar_add(popup);
1162         elm_object_style_set(progressbar, "pending_list");
1163         elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1164         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1165         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1166         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1167         evas_object_show(progressbar);
1168
1169         ad->progress_info.progress_label = label2;
1170         ad->progress_info.progress_layout = layout;
1171         ad->progress_info.progressbar = progressbar;
1172
1173         elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1174         elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1175         elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1176         elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1177         elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1178         // XXX - In this time, there's no job_spooling. So common pt_files field of ugd is used.
1179         int real_total_pages = -1;
1180         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1181                 real_total_pages = 1;
1182         } else {
1183                 real_total_pages = __pts_get_real_total_pages(ad->printing_data.range.total_pages,
1184                                                                 printer_get_setting_n_up(ad->list_info.active_printer), ad->list_info.active_printer->copies);
1185         }
1186         snprintf(page_info, 8, "1/%d", real_total_pages);
1187         elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1188
1189         Evas_Object *btn1 = NULL;
1190         btn1 = elm_button_add(popup);
1191         elm_object_style_set(btn1,"popup_button/default");
1192         elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1193         elm_object_part_content_set(popup, "button1", btn1);
1194         evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1195
1196         if (page_count > 1) {
1197                 Evas_Object *btn2 = NULL;
1198                 btn2 = elm_button_add(popup);
1199                 elm_object_style_set(btn2,"popup_button/default");
1200                 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1201                 elm_object_part_content_set(popup, "button2", btn2);
1202                 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_dummy_cancel_print, NULL);
1203         }
1204
1205         elm_object_content_set(popup, layout);
1206         evas_object_show(popup);
1207         evas_object_show(ad->main_info.root_win);
1208
1209         ad->progress_info.popup = popup;
1210
1211         PTS_TRACE_END;
1212 }
1213
1214
1215 void __pts_print_progress_popup(pts_appdata_t *ad, int job_id, int page_count)
1216 {
1217         PTS_TRACE_BEGIN;
1218         PTS_RET_IF(ad == NULL || job_id <= 0 || page_count <= 0, "Invalid parameters for progress_popup");
1219
1220         pts_job_spooling_t *job_spooling = NULL;
1221         job_spooling = __pts_get_job_spooling(ad, job_id);
1222         PTS_RET_IF(job_spooling == NULL, "No found job_spooling for job_id[%d]", job_id);
1223
1224         Evas_Object *label1 = NULL;
1225         Evas_Object *label2 = NULL;
1226         Evas_Object *label3 = NULL;
1227         Evas_Object *popup = NULL;
1228         Evas_Object *layout = NULL;
1229         Evas_Object *progressbar = NULL;
1230         char progress_info[8] = {0,};
1231         char page_info[8] = {0,};
1232         char aligned_label[128] = {0,};
1233
1234         popup = elm_popup_add(ad->main_info.main_layout);
1235
1236         label1 = elm_label_add(popup);
1237         elm_object_style_set(label1, "popup/progressview");
1238         elm_label_line_wrap_set(label1, ELM_WRAP_MIXED);
1239         char *printer_label = strdup(ad->list_info.active_printer->name);
1240         pts_unstandardization(printer_label);
1241         snprintf(aligned_label, 128, "<align=center>%s</align>", printer_label);
1242         elm_object_text_set(label1, aligned_label);
1243         if (printer_label != NULL) {
1244                 /* accessability - screen reader support */
1245                 elm_access_info_set(label1, ELM_ACCESS_INFO, printer_label);
1246
1247                 free(printer_label);
1248                 printer_label = NULL;
1249         }
1250         evas_object_size_hint_weight_set(label1, EVAS_HINT_EXPAND, 0.0);
1251         evas_object_size_hint_align_set(label1, EVAS_HINT_FILL, EVAS_HINT_FILL);
1252         evas_object_show(label1);
1253
1254         label2 = elm_label_add(popup);
1255         elm_object_style_set(label2, "popup/progressview");
1256         elm_label_line_wrap_set(label2, ELM_WRAP_MIXED);
1257         if (job_spooling->progress > 0) {
1258                 snprintf(aligned_label, 128, "<align=center>%s</align>",
1259                                         _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1260                 /* accessability - screen reader support */
1261                 elm_access_info_set(label2, ELM_ACCESS_INFO,
1262                                         _("IDS_PRT_HEADER_MEDIABOX_PRINTING"));
1263         } else {
1264                 snprintf(aligned_label, 128, "<align=center>%s</align>",
1265                                         _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1266                 /* accessability - screen reader support */
1267                 elm_access_info_set(label2, ELM_ACCESS_INFO,
1268                                         _("IDS_PRT_POP_WAITING_TO_PRINT_ING"));
1269         }
1270         elm_object_text_set(label2, aligned_label);
1271         evas_object_size_hint_weight_set(label2, EVAS_HINT_EXPAND, 0.0);
1272         evas_object_size_hint_align_set(label2, EVAS_HINT_FILL, EVAS_HINT_FILL);
1273         evas_object_show(label2);
1274
1275         label3 = elm_label_add(popup);
1276         elm_object_style_set(label3, "popup/progressview");
1277         elm_label_line_wrap_set(label3, ELM_WRAP_MIXED);
1278         char* label3_text = basename(job_spooling->pt_files.request_files[0]);
1279         snprintf(aligned_label, 128, "<align=center>%s</align>",
1280                                 label3_text);
1281         elm_object_text_set(label3, aligned_label);
1282         /* accessability - screen reader support */
1283         elm_access_info_set(label3, ELM_ACCESS_INFO, label3_text);
1284
1285         evas_object_size_hint_weight_set(label3, EVAS_HINT_EXPAND, 0.0);
1286         evas_object_size_hint_align_set(label3, EVAS_HINT_FILL, EVAS_HINT_FILL);
1287         evas_object_show(label3);
1288
1289         layout = pts_create_base_layout(popup, "popup_progress");
1290         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1291
1292         progressbar = elm_progressbar_add(popup);
1293         if (job_spooling->progress > 0) {
1294                 double rate = job_spooling->progress * 0.01;
1295                 elm_object_style_set(progressbar, "list_progress");
1296                 elm_progressbar_value_set(progressbar, rate);
1297         } else {
1298                 elm_object_style_set(progressbar, "pending_list");
1299                 elm_progressbar_pulse_set(progressbar, EINA_TRUE); // initial pending style
1300         }
1301         elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
1302         evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
1303         evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1304         evas_object_show(progressbar);
1305
1306         ad->progress_info.progress_label = label2;
1307         ad->progress_info.progress_layout = layout;
1308         ad->progress_info.progressbar = progressbar;
1309
1310         elm_object_part_content_set(layout, "elm.swallow.content.1", label1);
1311         elm_object_part_content_set(layout, "elm.swallow.content.2", label2);
1312         elm_object_part_content_set(layout, "elm.swallow.content.3", label3);
1313         elm_object_part_content_set(layout, "elm.swallow.end", progressbar);
1314         if (job_spooling->progress > 0) {
1315                 snprintf(progress_info, 8, "%d%%", job_spooling->progress);
1316                 elm_object_part_text_set(layout, "elm.text.subtext1", progress_info);
1317         } else {
1318                 elm_object_part_text_set(layout, "elm.text.subtext1", "0%");
1319         }
1320         snprintf(page_info, 8, "%d/%d", job_spooling->page_printed, page_count);
1321         elm_object_part_text_set(layout, "elm.text.subtext2", page_info);
1322
1323         Evas_Object *btn1 = NULL;
1324         btn1 = elm_button_add(popup);
1325         elm_object_style_set(btn1,"popup_button/default");
1326         elm_object_text_set(btn1, _("IDS_COM_SK_HIDE"));
1327         elm_object_part_content_set(popup, "button1", btn1);
1328         evas_object_smart_callback_add(btn1, "clicked", __pts_hide_progress_popup, ad);
1329
1330         // Show cancel button when total page is greater than 1 page.
1331 //      if (page_count > 1) {
1332                 Evas_Object *btn2 = NULL;
1333                 btn2 = elm_button_add(popup);
1334                 elm_object_style_set(btn2,"popup_button/default");
1335                 elm_object_text_set(btn2, _("IDS_COM_SK_CANCEL"));
1336                 elm_object_part_content_set(popup, "button2", btn2);
1337                 evas_object_smart_callback_add(btn2, "clicked", __pts_main_view_response_cancel_print, (void *)job_id);
1338                 elm_access_info_set(btn2, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_CANCEL_PRINTING);
1339 //      }
1340
1341         elm_object_content_set(popup, layout);
1342         evas_object_show(popup);
1343         evas_object_show(ad->main_info.root_win);
1344
1345         ad->progress_info.popup = popup;
1346
1347         PTS_TRACE_END;
1348 }
1349
1350 static Eina_Bool __pts_is_valid_printing_data(pts_appdata_t *ad)
1351 {
1352         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1353         PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1354
1355         if (ad->list_info.active_printer->copies <= 0) {
1356                 ad->list_info.active_printer->copies = 1;
1357                 PTS_DEBUG("copies is less than 0(%d)", ad->list_info.active_printer->copies);
1358                 return EINA_FALSE;
1359         }
1360
1361         /* get the range of print files */
1362         if (ad->printing_data.range.from <= 0 ||
1363                         ad->printing_data.range.to > ad->printing_data.range.total_pages ||
1364                         ad->printing_data.range.from > ad->printing_data.range.to) {
1365                 PTS_DEBUG("from(%d) to(%d) total(%d)"
1366                                         ,ad->printing_data.range.from
1367                                         ,ad->printing_data.range.to
1368                                         ,ad->printing_data.range.total_pages);
1369                 PTS_DEBUG("range checking error");
1370                 return EINA_FALSE;
1371         }
1372
1373         return EINA_TRUE;
1374 }
1375
1376 static Eina_Bool __pts_set_print_option_page_range(pts_appdata_t *ad)
1377 {
1378         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1379
1380         char temp[1024] = {0,};
1381         int index = 0;
1382
1383         if(_is_pdf_file_type(ad->printing_data.request_files, ad->printing_data.num_of_files) == true) {
1384                 for (index = 0 ; index <  ad->printing_data.num_of_files ; index++) {
1385                         ad->printing_data.range.total_pages += get_pdf_pages_count(ad->printing_data.request_files[index]);
1386                 }
1387         } else {
1388                 ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1389         }
1390
1391         PTS_DEBUG("Updated ad->printing_data.range.total_pages: %d", ad->printing_data.range.total_pages);
1392         ad->printing_data.range.to = ad->printing_data.range.total_pages;
1393
1394         if (ad->list_info.active_printer->range == PT_RANGE_CURRENT) {
1395                 ad->printing_data.range.from = ad->printing_data.range.to = evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1;
1396                 snprintf(temp, sizeof(temp), "%d", ad->printing_data.range.from);
1397                 pt_set_print_option_page_range(temp);
1398                 PTS_DEBUG("Set current page[%d] printing", ad->printing_data.range.from);
1399         }
1400
1401         return EINA_TRUE;
1402 }
1403
1404 static Eina_Bool __pts_set_print_scale_size(pts_appdata_t *ad)
1405 {
1406         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1407
1408         int num = 0;
1409         char *first_fname = NULL;
1410
1411         PTS_IF_FREE_MEM(ad->printing_data.range.selected_files);
1412         //FIXME - multiple page pdf will be changed to several image files.
1413         num = ad->printing_data.range.total_pages;
1414         ad->printing_data.range.selected_files = (char **)malloc(sizeof(char *)*num);
1415
1416         if (NULL == ad->printing_data.range.selected_files) {
1417                 PTS_DEBUG("selected_files malloc error");
1418                 return EINA_FALSE;
1419         }
1420
1421         first_fname = ad->printing_data.request_files[ad->printing_data.range.from - 1];
1422         if (1 == num && FILE_TYPE_IMAGE == get_file_type(first_fname)) {
1423                 int res_x = 0;
1424                 int res_y = 0;
1425                 if (get_image_resolution(first_fname, &res_x, &res_y) < 0) {
1426                         PTS_DEBUG("[ERROR] Failed to get image resolution(%s)",first_fname);
1427                         return EINA_FALSE;
1428                 }
1429                 pt_imagesize_t  crop_image_info;
1430                 crop_image_info.imagesize                       = ad->size_popup_info.image_size;
1431                 crop_image_info.resolution_width        = ad->size_popup_info.custom_width;
1432                 crop_image_info.resolution_height       = ad->size_popup_info.custom_height;
1433                 crop_image_info.ratio                           = ad->size_popup_info.custom_w_ratio;
1434                 crop_image_info.unit                            = ad->size_popup_info.custom_unit;
1435
1436                 pt_set_print_option_imagesize(&crop_image_info, first_fname, res_x, res_y);
1437                 ad->printing_data.range.selected_files[0] = ad->printing_data.request_files[0];
1438         } else {
1439                 pt_set_print_option_scaleimage(ad->list_info.active_printer->scaling);
1440                 num = 1;
1441                 ad->printing_data.range.selected_files[0] = ad->printing_data.input_file;
1442         }
1443
1444         return EINA_TRUE;
1445 }
1446
1447 static Eina_Bool __pts_set_print_options(pts_appdata_t *ad)
1448 {
1449         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1450         PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1451
1452         Eina_Bool eret = EINA_FALSE;
1453
1454         eret = __pts_set_print_option_page_range(ad);
1455         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set page ragnge");
1456
1457         pt_set_print_option_papersize();  //(ugd->active_printer->size);
1458         pt_set_print_option_copies(ad->list_info.active_printer->copies);
1459 //      pt_set_print_option_scaleimage(ugd->active_printer->scaling);
1460         pt_set_print_option_orientation(ad->list_info.active_printer->landscape);
1461         // FIXME : which field of ppd structure sholud be used for this?
1462         pt_set_print_option_quality();
1463         pt_set_print_option_paper_type();
1464         pt_set_print_option_color();
1465         pt_set_print_option_duplex(ad->list_info.active_printer->landscape);
1466         eret = __pts_set_print_scale_size(ad);
1467         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print scale size");
1468
1469         return EINA_TRUE;
1470 }
1471
1472 static Eina_Bool __pts_set_active_printer(pts_appdata_t *ad)
1473 {
1474         PTS_RETV_IF(ad == NULL, EINA_FALSE, "ad is NULL");
1475         PTS_RETV_IF(ad->list_info.active_printer == NULL, EINA_FALSE, "ad->list_info.active_printer is NULL");
1476
1477         int ret = 0;
1478
1479         if (1 != ad->list_info.active_printer->actived) {
1480                 /* use default printer, needs active */
1481                 ret = pt_set_active_printer(ad->list_info.active_printer);
1482                 if (PT_ERR_NONE != ret) {
1483                         PTS_DEBUG("pt_set_active_printer error");
1484                         return EINA_FALSE;
1485                 }
1486         }
1487
1488         return EINA_TRUE;
1489 }
1490
1491 static Eina_Bool __pts_main_view_start_print(void *data)
1492 {
1493         PTS_TRACE_BEGIN;
1494         pts_appdata_t *ad = (pts_appdata_t *)data;
1495         PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is NULL");
1496
1497         int ret = 0;
1498         int num = 1;
1499
1500         Eina_Bool eret = EINA_FALSE;
1501         eret = __pts_set_print_options(ad);
1502         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set print option");
1503
1504         eret = __pts_is_valid_printing_data(ad);
1505         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "It's not valid printing data");
1506
1507         eret = __pts_set_active_printer(ad);
1508         PTS_RETV_IF(eret == EINA_FALSE, EINA_FALSE, "Failed to set active printer");
1509
1510         __pts_create_dummy_notification(ad);
1511
1512         ret = pt_start_print((const char **)ad->printing_data.range.selected_files, num);
1513         if (PT_ERR_NONE != ret) {
1514                 PTS_DEBUG("pt_start_print error");
1515                 goto ERR_CASE;
1516         }
1517
1518         PTS_TRACE_END;
1519         return ECORE_CALLBACK_CANCEL;
1520
1521 ERR_CASE:
1522         ad->search_info.is_process = 0;/*process is complete*/
1523
1524         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1525
1526         if ((PT_ERR_NOT_USB_ACCESS == ret) || (PT_ERR_NOT_NETWORK_ACCESS == ret)) {
1527                 pts_create_popup(ad->main_info.navi, _("IDS_COM_POP_PRINTER_DISCONNECTED_ABB2"), 2.0);
1528         } else {
1529                 pts_create_popup(ad->main_info.navi, _("IDS_COM_BODY_UNSUPPORTED_FILE_TYPE"), 1.0);
1530         }
1531         return ECORE_CALLBACK_CANCEL;
1532 }
1533
1534 static Eina_Bool __pts_hide_main_view(void *data)
1535 {
1536         PTS_TRACE_BEGIN;
1537         pts_appdata_t *ad = (pts_appdata_t *) data;
1538         PTS_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL, "data is NULL");
1539
1540         PTS_IF_DEL_OBJ(ad->progress_info.popup);
1541         PTS_DEBUG("Hide main view of mobileprint");
1542         evas_object_hide(ad->main_info.root_win);
1543
1544         PTS_TRACE_END;
1545         return ECORE_CALLBACK_CANCEL;
1546 }
1547
1548 /*
1549 * "print" button callback
1550 */
1551 static void __pts_main_view_btn_print_cb(void *data, Evas_Object *obj, void *event_info)
1552 {
1553         PTS_TRACE_BEGIN;
1554         pts_appdata_t *ad = (pts_appdata_t *)data ;
1555         PTS_RET_IF(ad == NULL, "ad is NULL");
1556
1557         if ((NULL != ad->printing_data.request_files) && (NULL != ad->list_info.active_printer)) {
1558                 evas_object_hide(ad->main_info.main_layout);
1559                 pts_create_popup(ad->main_info.root_win, _("IDS_PRT_POP_PREPARING_TO_PRINT_ING"), 2.0);
1560                 ecore_timer_add(2.0, (Ecore_Task_Cb)__pts_hide_main_view, (void *)ad);
1561
1562                 ad->search_info.is_process = 1;/* in process */
1563                 __pts_main_view_start_print(ad);
1564         } else {
1565                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_SELECT_PRINTER"), 2.0);
1566         }
1567         PTS_TRACE_END;
1568 }
1569
1570 static void __pts_main_view_btn_size_cb(void *data, Evas_Object *obj, void *event_info)
1571 {
1572         PTS_TRACE_BEGIN;
1573         pts_appdata_t *ad = (pts_appdata_t *)data;
1574         PTS_RET_IF(ad == NULL, "ad is NULL");
1575
1576         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1577
1578         if (ad->list_info.active_printer) {
1579                 pts_create_size_popup(ad->main_info.navi, ad);
1580         } else {
1581                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1582         }
1583
1584         PTS_TRACE_END;
1585 }
1586
1587 static void __pts_main_view_btn_scaling_cb(void *data, Evas_Object *obj, void *event_info)
1588 {
1589         PTS_TRACE_BEGIN;
1590         pts_appdata_t *ad = (pts_appdata_t *)data;
1591         PTS_RET_IF(ad == NULL, "ad is NULL");
1592
1593         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1594
1595         if (ad->list_info.active_printer) {
1596                 pts_create_scaling_popup(ad->main_info.navi, ad);
1597         } else {
1598                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1599         }
1600
1601         PTS_TRACE_END;
1602 }
1603
1604
1605 static void __pts_main_view_btn_landscape_cb(void *data, Evas_Object *obj, void *event_info)
1606 {
1607         PTS_TRACE_BEGIN;
1608         pts_appdata_t *ad = (pts_appdata_t *)data;
1609         PTS_RET_IF(ad == NULL, "ad is NULL");
1610
1611         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1612
1613         if (ad->list_info.active_printer) {
1614                 PTS_DEBUG("initial ad->main_info.landscape_toggle : %d",
1615                         ad->main_info.landscape_toggle);
1616                 if (PT_ORIENTATION_PORTRAIT == ad->main_info.landscape_toggle) {
1617                         ad->main_info.landscape_toggle = PT_ORIENTATION_LANDSCAPE;
1618                 } else { /*FIXME if (PT_LANDSCAPE_LANDSCAPE == ugd->landscape_toggle)*/
1619                         ad->main_info.landscape_toggle = PT_ORIENTATION_PORTRAIT;
1620                 }
1621
1622                 PTS_DEBUG("ad->main_info.landscape_toggle : %d", ad->main_info.landscape_toggle);
1623
1624                 ad->list_info.active_printer->landscape = ad->main_info.landscape_toggle;
1625                 pts_main_view_rotate_image(ad, app_get_device_orientation());
1626         } else {
1627                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1628         }
1629
1630         PTS_TRACE_END;
1631 }
1632
1633 static void _dismissed_cb(void *data, Evas_Object *obj, void *event_info)
1634 {
1635         PTS_IF_DEL_OBJ(obj);
1636 }
1637
1638 static void _move_ctxpopup_more(Evas_Object *ctxpopup, Evas_Object *btn)
1639 {
1640         Evas_Coord x, y, w , h;
1641         evas_object_geometry_get(btn, &x, &y, &w, &h);
1642         evas_object_move(ctxpopup, x + (w / 2), y);
1643 }
1644
1645 static void _more_btn_cb(void *data, Evas_Object *obj, void *event_info)
1646 {
1647         PTS_TRACE_BEGIN;
1648         //struct appdata *ad = (struct appdata *) data;
1649         Evas_Object *icon;
1650         char buf[256];
1651
1652         pts_appdata_t *ad = pts_get_appdata();
1653         PTS_RET_IF(ad == NULL, "ad is NULL");
1654
1655         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1656
1657         ad->setting_info.ctxpopup = elm_ctxpopup_add(ad->main_info.navi);
1658         elm_object_style_set(ad->setting_info.ctxpopup, "more_button");
1659         evas_object_smart_callback_add(ad->setting_info.ctxpopup, "dismissed", _dismissed_cb, ad->setting_info.ctxpopup);
1660
1661         icon = elm_icon_add(ad->setting_info.ctxpopup);
1662         if (ad->printing_data.type != NULL) {
1663                 if (0 == strcasecmp(ad->printing_data.type, "IMG")) {
1664                         snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1665                         elm_icon_file_set(icon, buf, NULL);
1666                         elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1667                 } else if (0 == strcasecmp(ad->printing_data.type, "DOC") || 0 == strcasecmp(ad->printing_data.type, "WEB")) {
1668                         snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_scaling.png", ICON_DIR);
1669                         elm_icon_file_set(icon, buf, NULL);
1670                         elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_PRT_BODY_SCALING_ABB"), icon, __pts_main_view_btn_scaling_cb, ad);
1671                 }
1672         } else { /* Default IMG */
1673                 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_size.png", ICON_DIR);
1674                 elm_icon_file_set(icon, buf, NULL);
1675                 elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_BODY_SIZE"), icon, __pts_main_view_btn_size_cb, ad);
1676         }
1677
1678         icon = elm_icon_add(ad->setting_info.ctxpopup);
1679         if (ad->main_info.landscape_toggle == PT_ORIENTATION_PORTRAIT) {
1680                 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate.png", ICON_DIR);
1681         } else {
1682                 snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_Rotate02.png", ICON_DIR);
1683         }
1684         elm_icon_file_set(icon, buf, NULL);
1685         elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_IMGE_OPT_ROTATE"), icon, __pts_main_view_btn_landscape_cb, ad);
1686
1687         icon = elm_icon_add(ad->setting_info.ctxpopup);
1688         snprintf(buf, sizeof(buf), "%s/A01_print_popup_icon_setting.png", ICON_DIR);
1689         elm_icon_file_set(icon, buf, NULL);
1690         elm_ctxpopup_item_append(ad->setting_info.ctxpopup, _("IDS_COM_BODY_SETTING"), icon, __pts_main_view_btn_setting_cb, ad);
1691
1692         _move_ctxpopup_more(ad->setting_info.ctxpopup, obj);
1693
1694         evas_object_show(ad->setting_info.ctxpopup);
1695
1696         PTS_TRACE_END;
1697 }
1698
1699 static Evas_Object *create_toolbar_btn(Evas_Object *parent, const char *text, Evas_Smart_Cb func, void *data)
1700 {
1701         PTS_TRACE_BEGIN;
1702         Evas_Object *btn = elm_button_add(parent);
1703         if (!btn) {
1704                 return NULL;
1705         }
1706         elm_object_style_set(btn, "naviframe/toolbar/default");
1707         elm_object_text_set(btn, text);
1708         evas_object_smart_callback_add(btn, "clicked", func, data);
1709         PTS_TRACE_END;
1710         return btn;
1711 }
1712
1713 static Evas_Object *create_toolbar_more_btn(Evas_Object *parent, 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/more/default");
1721         elm_access_info_set(btn, ELM_ACCESS_INFO, IDS_SCRREAD_MENU_INFO);
1722         elm_access_info_set(btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_MENU_CONTEXT);
1723         evas_object_smart_callback_add(btn, "clicked", func, data);
1724         PTS_TRACE_END;
1725         return btn;
1726 }
1727
1728 #if 0
1729 char *get_preview_image_path(pts_core_data_t *ugd)
1730 {
1731         PTS_TRACE_BEGIN;
1732         PTS_RETV_IF(ugd == NULL, NULL, "ugd is NULL");
1733
1734         if (g_current_preview_path == NULL) {
1735                 g_current_preview_path = malloc(sizeof(char) * 4096);
1736         }
1737
1738         if ((ugd->pt_files.current_index >= 0)
1739                         && (ugd->pt_files.current_index < g_pages_count)) {
1740                 sprintf(g_current_preview_path, "/tmp/mobileprint/mobileprint_%04d.ppm",
1741                                 ugd->pt_files.current_index + 1);
1742                 PTS_DEBUG("Preview image path is %s", g_current_preview_path);
1743                 PTS_TRACE_END;
1744                 return g_current_preview_path;
1745         }
1746         PTS_TRACE_END;
1747         return NULL;
1748 }
1749 #endif
1750
1751 /*
1752  * Set accessability information - screen reader text
1753  */
1754 void generate_main_view_accessability_info(pts_appdata_t *ad,
1755                                                                                         char* main_view_accessability_text,
1756                                                                                         size_t text_max_length)
1757 {
1758         PTS_TRACE_BEGIN;
1759         PTS_RET_IF(NULL == ad || NULL == ad->list_info.active_printer, "Invalid argument");
1760
1761         char papersize[256]={0,};
1762         strncpy(papersize, pt_get_print_option_papersize(ad->list_info.active_printer->size), 256-1);
1763         char *quality, *papertype, *grayscale_mode, *print_range;
1764         int p_quality = pt_get_selected(PT_OPTION_ID_QUALITY);
1765         if (PT_QUALITY_DRAFT == p_quality) {
1766                 quality = _("IDS_PRT_OPT_PRINTSETTINGS_DRAFT");
1767         } else if (PT_QUALITY_STANDARD == p_quality) {
1768                 quality = _("IDS_PRT_OPT_PRINTSETTINGS_STANDARD");
1769         } else if (PT_QUALITY_HIGH == p_quality) {
1770                 quality = _("IDS_COM_BODY_HIGH");
1771         } else {
1772                 quality = NULL;
1773         }
1774         int p_type = pt_get_selected(PT_OPTION_ID_PAPER);
1775         if (PT_PAPER_NORMAL == p_type) {
1776                 papertype = _("IDS_ST_BODY_NORMAL");
1777         } else if (PT_PAPER_GLOSSY == p_type) {
1778                 papertype = _("IDS_ST_BODY_GLOSSY");
1779         } else if (PT_PAPER_PHOTO == p_type) {
1780                 papertype = _("IDS_PRT_BODY_PHOTOGRAPHIC_ABB");
1781         } else {
1782                 papertype = NULL;
1783         }
1784         int p_grayscale = pt_get_selected(PT_OPTION_ID_GRAYSCALE);
1785         if (PT_GRAYSCALE_COLOUR == p_grayscale) {
1786                 grayscale_mode = _("IDS_PRT_BODY_COLOUR");
1787         } else if (PT_GRAYSCALE_GRAYSCALE == p_grayscale) {
1788                 grayscale_mode = _("IDS_IMGE_HEADER_GREY");
1789         } else {
1790                 grayscale_mode = NULL;
1791         }
1792         pt_range_e p_range = ad->list_info.active_printer->range;
1793         if (PT_RANGE_ALL == p_range) {
1794                 print_range = _("IDS_DIC_BODY_ALL");
1795         } else {
1796                 print_range = _("IDS_BR_BODY_CURRENT_PAGE");
1797         }
1798
1799         snprintf(main_view_accessability_text, text_max_length, "%s, %d page of %d pages, %s size, %d %s,"
1800                                                                                                 " print %s, %s, "
1801                                                                                                 " %s orientation, %s quality, %s paper"
1802                                                                                                 " %s mode, send to %s",
1803                         basename(ad->printing_data.input_file), //printing file
1804                         evas_smart_smsc_calculate_page_number(ad->main_info.smsc) + 1, //current page
1805                         g_pages_count, //total pages
1806                         papersize,
1807                         ad->list_info.active_printer->copies,
1808                         (1 == ad->list_info.active_printer->copies) ? "copy" : "copies",
1809                         print_range,
1810                         (PT_SCALING_2_PAGES == ad->list_info.active_printer->scaling) ? "2 pages in 1 sheet" :
1811                         (PT_SCALING_4_PAGES == ad->list_info.active_printer->scaling) ? "4 pages in 1 sheet" :
1812                         "fit to paper",
1813                         PT_ORIENTATION_PORTRAIT == ad->list_info.active_printer->landscape ? "portrait" :
1814                         PT_ORIENTATION_LANDSCAPE == ad->list_info.active_printer->landscape ? "landscape" : "auto",
1815                         quality,
1816                         papertype,
1817                         grayscale_mode,
1818                         elm_access_info_get(ad->main_info.printer_label, ELM_ACCESS_INFO));
1819
1820         PTS_TRACE_END;
1821 }
1822
1823 /*
1824 * create content of the main view screen
1825 */
1826 static Evas_Object *__pts_main_view_create_content(pts_appdata_t *ad)
1827 {
1828         PTS_TRACE_BEGIN;
1829         PTS_RETV_IF(ad == NULL, NULL, "ad is NULL");
1830
1831         /*
1832          * load preview group
1833          */
1834         ad->main_info.printer_layout = pts_create_base_layout(ad->main_info.navi, "printer");
1835
1836         pts_main_view_update_printer_label(ad);
1837
1838         /*
1839          * load preview image group
1840          */
1841         ad->main_info.img_layout = pts_create_base_layout(ad->main_info.printer_layout, "image_view");
1842
1843         if (NULL != ad->printing_data.request_files) {
1844                 char *file_path = NULL;
1845                 file_path = ad->printing_data.request_files[ad->printing_data.current_index];
1846                 PTS_DEBUG("filepath is %s", file_path);
1847         }
1848
1849         ad->main_info.smsc = evas_smart_smsc_add(evas_object_evas_get(ad->main_info.img_layout));
1850         evas_smart_smsc_set_layout(ad->main_info.smsc, ad->main_info.img_layout);
1851         elm_object_part_content_set(ad->main_info.img_layout, "content", ad->main_info.smsc);
1852
1853         /*
1854          * Set preview layout
1855          */
1856         elm_object_part_content_set(ad->main_info.printer_layout, "image", ad->main_info.img_layout);
1857         evas_object_show(ad->main_info.img_layout);
1858         evas_object_show(ad->main_info.printer_layout);
1859
1860         static char main_view_accessability_text[2048] = {0,};
1861         generate_main_view_accessability_info(ad, main_view_accessability_text, 2048);
1862         init_smsc_accessability_support(ad->main_info.smsc);
1863         set_main_view_accessability_info(ad->main_info.smsc, ad->main_info.img_layout,
1864                                                                         main_view_accessability_text,
1865                                                                         IDS_SCRREAD_PREVIEW_IMAGE_TYPE,
1866                                                                         IDS_SCRREAD_PREVIEW_IMAGE_CONTEXT);
1867
1868         PTS_TRACE_END;
1869         return ad->main_info.printer_layout;
1870 }
1871
1872
1873 /*
1874 * setting button callback function
1875 */
1876 static void __pts_main_view_btn_setting_cb(void *data, Evas_Object *obj, void *event_info)
1877 {
1878         PTS_TRACE_BEGIN;
1879         pts_appdata_t *ad = (pts_appdata_t *)data;
1880         PTS_RET_IF(ad == NULL, "ad is NULL");
1881
1882         PTS_IF_DEL_OBJ(ad->setting_info.ctxpopup);
1883
1884         if (ad->list_info.active_printer) {
1885                 pts_create_setting_view(ad);
1886         } else {
1887                 pts_create_popup(ad->main_info.navi, _("IDS_PRT_BODY_NO_PRINTERS_AVAILABLE"), 1.0);
1888         }
1889
1890         PTS_TRACE_END;
1891 }
1892
1893 int pts_main_view_load_printing_data(pts_appdata_t *ad, pts_printing_data_t *printing_data)
1894 {
1895         PTS_TRACE_BEGIN;
1896         PTS_RETV_IF(ad == NULL || printing_data == NULL, -1, "Invalid argument");
1897
1898         PTS_IF_FREE_MEM(ad->printing_data.request_files);
1899         PTS_IF_FREE_MEM(ad->printing_data.type);
1900
1901         memset(&ad->printing_data, 0, sizeof(pts_printing_data_t));
1902
1903         ad->printing_data.num_of_files = printing_data->num_of_files;
1904         ad->printing_data.current_index = printing_data->current_index;
1905         ad->printing_data.type = printing_data->type;
1906         ad->printing_data.request_files = (char **)malloc(sizeof(char *) * ad->printing_data.num_of_files);
1907
1908         if (!ad->printing_data.request_files) {
1909                 PTS_IF_FREE_MEM(ad->printing_data.type);
1910                 //PTS_IF_FREE_MEM(ad->printing_data);
1911                 PTS_DEBUG("calloc print files failed");
1912                 PTS_TRACE_END;
1913                 return -1;
1914         }
1915
1916         int i = 0;
1917         for (i = 0; i < ad->printing_data.num_of_files; i++) {
1918                 PTS_DEBUG("file path is %s", printing_data->request_files[i]);
1919                 if (NULL != printing_data->request_files[i]) {
1920                         ad->printing_data.request_files[i] = strdup(printing_data->request_files[i]);
1921                 } else {
1922                         ad->printing_data.request_files[i] = strdup(MOBILEPRINT_DEFAULTIMG);
1923                 }
1924                 PTS_DEBUG("file path is %s", ad->printing_data.request_files[i]);
1925         }
1926         ad->printing_data.input_file = strdup(ad->printing_data.request_files[0]);
1927         PTS_DEBUG("ad->input_file: %s", ad->printing_data.input_file);
1928
1929         PTS_DEBUG("count: %d", ad->printing_data.num_of_files);
1930         PTS_DEBUG("current index: %d", ad->printing_data.current_index);
1931         PTS_DEBUG("filetype: %s", ad->printing_data.type);
1932
1933         /* init the print range(include all pages) */
1934         ad->printing_data.range.from = 1;
1935         ad->printing_data.range.to = ad->printing_data.range.total_pages = ad->printing_data.num_of_files;
1936         ad->printing_data.range.selected_files = NULL;
1937
1938         PTS_TRACE_END;
1939         return 0;
1940 }
1941
1942 /**
1943  *      This function let the app update printer label in the preview view
1944  *      @return  void
1945  *      @param[in] ugd the pointer to the main data structure
1946  */
1947 void pts_main_view_update_printer_label(pts_appdata_t *ad)
1948 {
1949         PTS_TRACE_BEGIN;
1950         PTS_RET_IF(ad == NULL, "ad is NULL");
1951
1952         char label_text[128] = {0,};
1953         char label_voice[128] = {0,};
1954
1955         if (ad->main_info.printer_label == NULL) {
1956                 ad->main_info.printer_label = elm_label_add(ad->main_info.printer_layout);
1957         }
1958         PTS_DEBUG("ad->list_info.active_printer is %p", ad->list_info.active_printer);
1959
1960         if (ad->list_info.active_printer != NULL) {
1961                 char *printer_name = strdup(ad->list_info.active_printer->name);
1962                 pts_unstandardization(printer_name);
1963                 snprintf(label_text, 128, "<align=center>%s</align>", printer_name);
1964                 snprintf(label_voice, 128, "%s", printer_name);
1965                 if (printer_name != NULL) {
1966                         free(printer_name);
1967                         printer_name = NULL;
1968                 }
1969         } else {
1970                 snprintf(label_text, 128, "<align=center>%s</align>", _("IDS_COM_BODY_NO_DEVICES"));
1971                 snprintf(label_voice, 128, "%s", _("IDS_COM_BODY_NO_DEVICES"));
1972         }
1973
1974         elm_object_text_set(ad->main_info.printer_label, label_text);
1975         elm_access_info_set(ad->main_info.printer_label, ELM_ACCESS_INFO, label_voice);
1976         evas_object_size_hint_weight_set(ad->main_info.printer_label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1977         evas_object_size_hint_align_set(ad->main_info.printer_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1978
1979         elm_object_part_content_set(ad->main_info.printer_layout, "printer_name", ad->main_info.printer_label);
1980
1981         PTS_TRACE_END;
1982 }
1983
1984 /**
1985  *      This function let the app rotate the image by the given landscape
1986  *      @return   void
1987  *      @param[in] ugd the pointer to the main data structure
1988  *      @param[in] landscape the landscape value
1989  */
1990 void pts_main_view_rotate_image(pts_appdata_t *ad,
1991                                                                 app_device_orientation_e orientation)
1992 {
1993         PTS_TRACE_BEGIN;
1994         PTS_RET_IF(ad == NULL, "ad is NULL");
1995
1996         generate_preview_images(ad, orientation);
1997         g_pages_count = 0;
1998
1999         PTS_TRACE_END;
2000 }
2001
2002 /**
2003  *      This function let the app create the main screen view
2004  *      @return  Evas_Object
2005  *      @param[in] win the pointer to the main window
2006  *      @param[in] pt_files the pointer to the path of print files
2007  */
2008 API Evas_Object *pts_create_main_view(pts_appdata_t *ad)
2009 {
2010         PTS_TRACE_BEGIN;
2011         PTS_RETV_IF((ad == NULL) || (ad->main_info.root_win == NULL), NULL, "Invalid argument");
2012
2013         Evas_Object *main_layout = NULL;
2014         Evas_Object *back_btn = NULL;
2015
2016         ad->main_info.main_layout = pts_create_base_layout_with_conform(ad->main_info.root_win, "navi");
2017         if (NULL == ad->main_info.main_layout) {
2018                 //PTS_IF_FREE_MEM(ad);
2019                 PTS_DEBUG("create base layout failed");
2020                 PTS_TRACE_END;
2021                 return NULL;
2022         }
2023
2024         ad->main_info.navi = elm_naviframe_add(ad->main_info.main_layout);
2025         elm_object_part_content_set(ad->main_info.main_layout, "navigation_bar", ad->main_info.navi);
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
2036         evas_object_event_callback_add(ad->main_info.navi, EVAS_CALLBACK_DEL, __pts_main_view_navi_delete_cb, ad);
2037
2038         ad->main_info.navi_it = elm_naviframe_item_push(ad->main_info.navi, _("IDS_PRT_SK_PRINT_PREVIEW"), back_btn, NULL, main_layout, NULL);
2039
2040         ad->main_info.print_btn = create_toolbar_btn(ad->main_info.navi, _("IDS_SMPOS_SK3_PRINT"), __pts_main_view_btn_print_cb, ad);
2041         elm_access_info_set(ad->main_info.print_btn, ELM_ACCESS_INFO, _("IDS_SMPOS_SK3_PRINT"));
2042         elm_access_info_set(ad->main_info.print_btn, ELM_ACCESS_CONTEXT_INFO, IDS_SCRREAD_PRINT_CONTEXT);
2043         elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar_button1", ad->main_info.print_btn);
2044
2045         ad->main_info.more_btn = create_toolbar_more_btn(ad->main_info.navi, _more_btn_cb, ad->main_info.navi_it);
2046         elm_object_item_part_content_set(ad->main_info.navi_it, "toolbar_more_btn", ad->main_info.more_btn);
2047
2048         evas_object_event_callback_add(main_layout, EVAS_CALLBACK_DEL, __pts_main_view_delete_cb, ad);
2049
2050
2051         int tmp_width = 0;
2052         int tmp_height = 0;
2053
2054         get_image_resolution(ad->printing_data.input_file, &tmp_width, &tmp_height);
2055         ad->size_popup_info.custom_width = (double)tmp_width;
2056         ad->size_popup_info.custom_height = (double)tmp_height;
2057         ad->size_popup_info.custom_w_ratio = ad->size_popup_info.custom_width / ad->size_popup_info.custom_height;
2058         PTS_DEBUG("Original image size : %lfx%lf(%lfx1)", ad->size_popup_info.custom_width, ad->size_popup_info.custom_height, ad->size_popup_info.custom_w_ratio);
2059         // original image size (unit cm) calculated by 300dpi
2060         ad->size_popup_info.custom_width = (ad->size_popup_info.custom_width / 300) * 2.54;
2061         ad->size_popup_info.custom_height = (ad->size_popup_info.custom_height / 300) * 2.54;
2062         ad->size_popup_info.custom_unit = 1; // cm unit
2063
2064         PTS_TRACE_END;
2065         return ad->main_info.main_layout;
2066 }