Initialize Tizen 2.3
[apps/home/mobileprint.git] / mobileprint / app / pts_common.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 #include <app.h>
21 #include <ui-gadget.h>
22 #include <vconf.h>
23 #include <vconf-keys.h>
24 #include <sysman.h>
25 #include <efl_assist.h>
26 #include <syspopup_caller.h>
27 #include "mobileprint.h"
28 #include "image_editor_conn.h"
29 #include "pts_main_view.h"
30 #include "preview_util.h"
31
32 Evas_Object *pts_create_custom_popup(Evas_Object *parent, pts_appdata_t *ad);
33 void __pts_main_view_create_list_view(pts_appdata_t *ad);
34 void main_quit_cb(void *data, Evas_Object *obj,
35                                   const char *emission, const char *source);
36
37 static Evas_Object *scaling_radio_main = NULL;
38 static Evas_Object *size_radio_main = NULL;
39 static Elm_Genlist_Item_Class scaling_itc;
40 static Elm_Genlist_Item_Class size_itc;
41 static Elm_Genlist_Item_Class title_itc;
42 static Elm_Genlist_Item_Class text_itc;
43 static Elm_Genlist_Item_Class check_itc;
44 static Elm_Genlist_Item_Class button_itc;
45 static int scaling_index = 0;
46 int size_index = 0;
47
48 static Eina_Bool aspect_ratio = 0;
49
50 static Evas_Object *width_layout;
51 static Evas_Object *width_entry;
52 static Evas_Object *height_layout;
53 static Evas_Object *height_entry;
54
55 int pts_unstandardization(char *name)
56 {
57         char *ptr = NULL;/* Pointer into name */
58         PTS_RETV_IF(name == NULL, -1, "Invalid argument");
59
60         for (ptr = name; *ptr; ptr++) {
61                 if (*ptr == '@') {
62                                 return 0;
63                 } else if ((*ptr >= 0 && *ptr < ' ') ||
64                                 *ptr == 127 || *ptr == '/' ||*ptr == '#') {
65                                 return -1;
66                 } else if (*ptr == 0x5F) {
67                                 *ptr = 0x20; /*convert _ to space*/
68                 } else if (*ptr == '[' || *ptr == '(') {
69                         *ptr='\0';
70                         while (name <= ptr) {
71                                 ptr--;
72                                 if (*ptr==0x20) {
73                                         *ptr='\0';
74                                 } else {
75                                         return 0;
76                                 }
77                         }
78                         return 0;
79                 }
80         }
81         return 0;
82 }
83
84 char* pts_parse_protocol(char *addr)
85 {
86         PTS_TRACE_BEGIN;
87         char *printer_protocol = NULL;
88
89         PTS_RETV_IF(addr == NULL, NULL, "Invalid argument");
90
91         if (strstr(addr, "_pdl-datastream.") != NULL) {
92                 printer_protocol = strdup("Network (RAW)");
93         } else if (strstr(addr, "_ipp.") != NULL) {
94                 printer_protocol = strdup("Network (IPP)");
95         } else if (strstr(addr, "_printer.") != NULL) {
96                 printer_protocol = strdup("Network (LPD)");
97         } else if (strstr(addr, "usb") != NULL) {
98                 printer_protocol = strdup("USB");
99         } else {
100                 printer_protocol = strdup("Unknown");
101         }
102
103         PTS_TRACE_END;
104         return printer_protocol;
105 }
106
107
108 /**
109  *      This function let the app create the label
110  *      @return  void
111  *      @param[in] parent the pointer to the parent of the label
112  *      @param[in] desc the pointer to label text
113  */
114 Evas_Object *pts_create_label_btn(Evas_Object *parent, const char *label)
115 {
116         PTS_TRACE_BEGIN;
117         Evas_Object *btn = elm_button_add(parent);
118         elm_object_text_set(btn, label);
119         evas_object_show(btn);
120         PTS_TRACE_END;
121         return btn;
122 }
123
124
125 /**
126  *      This function let the app create the base layout
127  *      @return  void
128  *      @param[in] parent the pointer to the parent of the base layout
129  *      @param[in] desc the pointer to group of the base layout
130  */
131 Evas_Object *pts_create_base_layout_with_conform(Evas_Object *parent, const char *group)
132 {
133         PTS_TRACE_BEGIN;
134         char edj_file[128] = {0};
135         Evas_Object *base = NULL;
136         Evas_Object *conform = NULL;
137         int r = 0;
138
139         /* load edje */
140         app_get_resource("edje/mobileprint.edj", edj_file, 128);
141
142         conform = elm_conformant_add(parent);
143         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
144         // Add
145         evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
146
147         elm_win_resize_object_add(parent, conform);
148
149         base = elm_layout_add(conform);
150         if (base) {
151                 r = elm_layout_file_set(base, edj_file, group);
152                 if (!r) {
153                         evas_object_del(base);
154                         return NULL;
155                 }
156                 elm_object_content_set(conform, base);
157         }
158         evas_object_show(conform);
159         PTS_TRACE_END;
160
161         return base;
162 }
163
164 Evas_Object *pts_create_base_layout(Evas_Object *parent, const char *group)
165 {
166         PTS_TRACE_BEGIN;
167         char edj_file[128] = {0};
168         Evas_Object *base = NULL;
169         int r = 0;
170
171         /* load edje */
172         app_get_resource("edje/mobileprint.edj", edj_file, 128);
173
174         base = elm_layout_add(parent);
175         if (base) {
176                 r = elm_layout_file_set(base, edj_file, group);
177                 if (!r) {
178                         evas_object_del(base);
179                         return NULL;
180                 }
181                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182         }
183         PTS_TRACE_END;
184
185         return base;
186 }
187
188
189 /**
190  *      This function let the app create the popup element
191  *      @return  void
192  *      @param[in] parent the pointer to the parent of the popup element
193  *      @param[in] desc the pointer to description of the popup element
194  *      @param[in] timeout the timeout value
195  */
196 Evas_Object *pts_create_popup(Evas_Object *parent, const char *desc, double timeout)
197 {
198         PTS_TRACE_BEGIN;
199         Evas_Object *notify = NULL;
200         notify = elm_popup_add(parent);
201         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
202         //elm_popup_mode_set(notify, ELM_POPUP_TYPE_ALERT);
203         elm_popup_timeout_set(notify, timeout);
204         elm_object_text_set(notify, desc);
205         evas_object_show(notify);
206         PTS_TRACE_END;
207         return notify;
208 }
209
210 static void _pts_scaling_set_cb(void *data, Evas_Object *obj, void *event_info)
211 {
212         PTS_TRACE_BEGIN;
213         pts_appdata_t *ad = (pts_appdata_t *)data;
214         PTS_RET_IF(ad == NULL, "ad is NULL");
215
216         PTS_IF_DEL_OBJ(scaling_radio_main);
217         PTS_IF_DEL_OBJ(ad->scaling_popup_info.scaling_popup);
218
219         pts_main_view_rotate_image(ad, app_get_device_orientation());
220         PTS_TRACE_END;
221 }
222
223 static char *__pts_scaling_label_get(void *data, Evas_Object *obj, const char *part)
224 {
225         PTS_TRACE_BEGIN;
226         int index = (int)data;
227         char *label = NULL;
228         char temp[1024] = {0};
229
230         if (strcmp(part, "elm.text") == 0) {
231                 switch (index) {
232                 case PT_SCALING_FIT_TO_PAGE:
233                         label = strdup(_("IDS_BT_OPT_FIT_TO_PAPER"));
234                         break;
235                 case PT_SCALING_2_PAGES:
236                         snprintf(temp,1024,_("IDS_PRT_BODY_PD_PAGES_ON_1_SHEET_ABB"),2);
237                         label = strdup(temp);
238                         break;
239                 case PT_SCALING_4_PAGES:
240                         snprintf(temp,1024,_("IDS_PRT_BODY_PD_PAGES_ON_1_SHEET_ABB"),4);
241                         label = strdup(temp);
242                         break;
243                 default:
244                         label = strdup("Unknown option");
245                         break;
246                 }
247         }
248
249         PTS_TRACE_END;
250         return label;
251 }
252
253 static Evas_Object *__pts_scaling_icon_get(void *data, Evas_Object *obj, const char *part)
254 {
255         PTS_TRACE_BEGIN;
256
257         int index = (int)data;
258         PTS_DEBUG("Passed index : %d", index);
259         Evas_Object *radio;
260
261         if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.swallow.icon")) {
262                 radio = elm_radio_add(obj);
263                 elm_radio_state_value_set(radio, index);
264                 elm_radio_group_add(radio, scaling_radio_main);
265                 PTS_DEBUG("scaling_index[%d]", scaling_index);
266                 // It's filter to avoid all radio selection
267                 if (scaling_index == index) {
268                         elm_radio_value_set(radio, scaling_index);
269                         PTS_DEBUG("OK...Set radio button using scaling_index[%d]", scaling_index);
270                 }
271
272                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
273                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
274
275                 return radio;
276         }
277
278         PTS_TRACE_END;
279         return NULL;
280 }
281
282 static void __pts_scaling_sel(void *data, Evas_Object *obj, void *event_info)
283 {
284         PTS_TRACE_BEGIN;
285
286         pts_appdata_t *ad = (pts_appdata_t *)data;
287         PTS_RET_IF(NULL == ad, "ad is NULL");
288
289         int scaling = -1;
290         Elm_Object_Item *item = event_info;
291
292         if (item != NULL) {
293                 elm_genlist_item_selected_set(item, EINA_FALSE);
294
295                 scaling = (int)elm_object_item_data_get(item);
296                 if (scaling > -1) {
297                         PTS_DEBUG("Selected scaling : %d", scaling);
298
299                         scaling_index = ad->list_info.active_printer->scaling = scaling;
300
301                         // Now call real event trigger to update radio button when selected.
302                         elm_genlist_item_update(item);
303                 }
304         }
305         PTS_TRACE_END;
306 }
307
308 static void _pts_scaling_cancel_cb(void *data, Evas_Object *obj, void *event_info)
309 {
310         PTS_TRACE_BEGIN;
311         pts_appdata_t *ad = (pts_appdata_t *)data;
312         PTS_RET_IF(NULL == ad, "ad is NULL");
313
314         PTS_IF_DEL_OBJ(scaling_radio_main);
315         PTS_IF_DEL_OBJ(obj);
316         PTS_IF_DEL_OBJ(ad->scaling_popup_info.scaling_popup);
317         PTS_TRACE_END;
318 }
319
320 Evas_Object *pts_create_scaling_popup(Evas_Object *parent, pts_appdata_t *ad)
321 {
322         PTS_TRACE_BEGIN;
323         Evas_Object *popup;
324         Evas_Object *genlist;
325         Evas_Object *btn1;
326         int index;
327
328         popup = elm_popup_add(parent);
329         elm_object_style_set(popup,"content_no_vhpad");
330         elm_object_part_text_set(popup, "title,text", _("IDS_PRT_BODY_SCALING_ABB"));
331
332         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333
334         Evas_Object *layout = elm_layout_add(popup);
335         elm_layout_theme_set(layout, "layout", "content", "min_menustyle");
336         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337
338         btn1 = elm_button_add(popup);
339         elm_object_style_set(btn1,"popup_button/default");
340         elm_object_text_set(btn1, _("IDS_PRT_BODY_SCALING_ABB"));
341         elm_object_part_content_set(popup, "button1", btn1);
342         evas_object_smart_callback_add(btn1, "clicked", _pts_scaling_set_cb, ad);
343
344         genlist = elm_genlist_add(popup);
345         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
346         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
347
348         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, _pts_scaling_cancel_cb, ad);
349
350
351         if (!scaling_radio_main) {
352                 scaling_radio_main = elm_radio_add(genlist);
353                 elm_radio_state_value_set(scaling_radio_main, scaling_index);
354                 elm_radio_value_set(scaling_radio_main, scaling_index);
355         }
356
357         scaling_itc.item_style = "1text.1icon.2";
358         scaling_itc.func.text_get = __pts_scaling_label_get;
359         scaling_itc.func.content_get = __pts_scaling_icon_get;
360         scaling_itc.func.state_get = NULL;
361         scaling_itc.func.del = NULL;
362
363         Elm_Object_Item  *item = NULL;
364         for (index = 0; index < (PT_SCALING_4_PAGES+1); index++) {
365                 item = elm_genlist_item_append(genlist, &scaling_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, __pts_scaling_sel, ad);
366                 PTS_DEBUG("index[%d] - item added : %s", index, (NULL == item)? "FAILURE" : "SUCCESS");
367         }
368
369         Evas_Object *box = elm_box_add(popup);
370         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
371
372         elm_box_pack_end(box, genlist);
373         evas_object_show(genlist);
374         evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), elm_genlist_items_count(genlist) * 114 * elm_config_scale_get());
375         evas_object_show(box);
376         elm_object_part_content_set(layout, "elm.swallow.content" , box);
377         elm_object_content_set(popup, box);
378         elm_object_focus_set(popup, EINA_TRUE);
379
380         evas_object_show(popup);
381
382         ad->scaling_popup_info.scaling_popup = popup;
383
384         PTS_TRACE_END;
385         return genlist;
386 }
387
388 static void _pts_size_cancel_cb(void *data, Evas_Object *obj, void *event_info)
389 {
390         PTS_TRACE_BEGIN;
391         pts_appdata_t *ad = (pts_appdata_t *)data;
392         PTS_RET_IF(NULL == ad, "ad is NULL");
393         PTS_IF_DEL_OBJ(size_radio_main);
394         PTS_IF_DEL_OBJ(obj);
395         PTS_IF_DEL_OBJ(ad->size_popup_info.size_popup);
396         PTS_TRACE_END;
397 }
398
399 static char *__pts_size_label_get(void *data, Evas_Object *obj, const char *part)
400 {
401         PTS_TRACE_BEGIN;
402         int index = (int)data;
403         char *label = NULL;
404         char custom[32] = {0,};
405         pts_appdata_t *ad = pts_get_appdata();
406
407         if (strcmp(part, "elm.text") == 0) {
408                 switch (index) {
409                 case PTS_SIZE_FIT_TO_PAPER:
410                         label = strdup(_("IDS_BT_OPT_FIT_TO_PAPER"));
411                         break;
412                 case PTS_SIZE_5X7:
413                         label = strdup(IDS_BR_OPT_5X7);
414                         break;
415                 case PTS_SIZE_4X6:
416                         label = strdup(IDS_BR_OPT_4X6);
417                         break;
418                 case PTS_SIZE_3_5X5:
419                         label = strdup(IDS_BR_OPT_3_5X5);
420                         break;
421                 case PTS_SIZE_WALLET:
422                         label = strdup(IDS_BR_OPT_WALLET);
423                         break;
424                 case PTS_SIZE_CUSTOM:
425                         if (ad->size_popup_info.custom_unit == 1) { // cm unit
426                                 snprintf(custom, 32, "%s (%.1lfx%.1lfcm)", _("IDS_COM_SK_CUSTOM"), ad->size_popup_info.custom_height, ad->size_popup_info.custom_width);
427                         } else if (ad->size_popup_info.custom_unit == 2) { // inch unit
428                                 snprintf(custom, 32, "%s (%.1lf\"x%.1lf\")", _("IDS_COM_SK_CUSTOM"), ad->size_popup_info.custom_height, ad->size_popup_info.custom_width);
429                         } else {
430                                 snprintf(custom, 32, "%s (%.1lfx%.1lf)", _("IDS_COM_SK_CUSTOM"), ad->size_popup_info.custom_height, ad->size_popup_info.custom_width);
431                         }
432
433                         label = strdup(custom);
434                         break;
435                 default:
436                         label = strdup("Unknown option");
437                         break;
438                 }
439         }
440
441         PTS_TRACE_END;
442         return label;
443 }
444
445 static Evas_Object *__pts_size_icon_get(void *data, Evas_Object *obj, const char *part)
446 {
447         PTS_TRACE_BEGIN;
448
449         int index = (int)data;
450         PTS_DEBUG("Passed index : %d", index);
451         Evas_Object *radio;
452
453         if (!strcmp(part, "elm.icon") || !strcmp(part, "elm.swallow.icon")) {
454                 radio = elm_radio_add(obj);
455                 elm_radio_state_value_set(radio, index);
456                 elm_radio_group_add(radio, size_radio_main);
457                 PTS_DEBUG("size_index[%d]", size_index);
458                 // It's filter to avoid all radio selection
459                 if (size_index == index) {
460                         elm_radio_value_set(radio, size_index);
461                         PTS_DEBUG("OK...Set radio button using size_index[%d]", size_index);
462                 }
463
464                 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
465                 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
466
467                 return radio;
468         }
469
470         PTS_TRACE_END;
471         return NULL;
472 }
473
474 static void __pts_size_sel(void *data, Evas_Object *obj, void *event_info)
475 {
476         PTS_TRACE_BEGIN;
477
478         pts_appdata_t *ad = (pts_appdata_t *)data;
479         PTS_RET_IF(ad == NULL, "ad is NULL");
480
481         int size = -1;
482         Elm_Object_Item *item = event_info;
483
484         if (item != NULL) {
485                 elm_genlist_item_selected_set(item, EINA_FALSE);
486
487                 size = (int)elm_object_item_data_get(item);
488                 if (size > PTS_SIZE_FIT_TO_PAPER && size < PTS_SIZE_CUSTOM) {
489                         PTS_DEBUG("Selected size : %d", size);
490
491                         ad->size_popup_info.image_size = size;
492
493                         // Now call real event trigger to update radio button when selected.
494                         elm_genlist_item_update(item);
495
496                         load_image_editor_ug(ad);
497                 } else if (size == PTS_SIZE_CUSTOM) {
498                         pts_create_custom_popup(ad->main_info.navi, ad);
499                 } else if (size == PTS_SIZE_FIT_TO_PAPER) {
500                         size_index = ad->size_popup_info.image_size = size;
501                         // just back to fit-to-paper of original image
502                         PTS_IF_FREE_MEM(ad->printing_data.request_files[0]);
503                         ad->printing_data.request_files[0] = strdup(ad->printing_data.input_file);
504                         PTS_DEBUG("original_image_path: %s", ad->printing_data.request_files[0]);
505                         pts_main_view_rotate_image(ad, app_get_device_orientation());
506                 } else {
507                         PTS_DEBUG("Unknown size");
508                 }
509                 PTS_IF_DEL_OBJ(obj);
510                 PTS_IF_DEL_OBJ(ad->size_popup_info.size_popup);
511                 PTS_IF_DEL_OBJ(size_radio_main);
512         }
513         PTS_TRACE_END;
514 }
515
516 Evas_Object *pts_create_size_popup(Evas_Object *parent, pts_appdata_t *ad)
517 {
518         PTS_TRACE_BEGIN;
519         Evas_Object *popup;
520         Evas_Object *genlist;
521         Evas_Object *btn1;
522         int index;
523
524         popup = elm_popup_add(parent);
525         elm_object_style_set(popup,"content_no_vhpad");
526         elm_object_part_text_set(popup, "title,text", _("IDS_IMGE_BODY_SIZE"));
527
528         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
529
530         Evas_Object *layout = elm_layout_add(popup);
531         elm_layout_theme_set(layout, "layout", "content", "min_menustyle");
532         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
533
534         btn1 = elm_button_add(popup);
535         elm_object_style_set(btn1, "popup_button/default");
536         elm_object_text_set(btn1, _("IDS_COM_SK_CANCEL"));
537         elm_object_part_content_set(popup, "button1", btn1);
538         evas_object_smart_callback_add(btn1, "clicked", _pts_size_cancel_cb, ad);
539         // Add cancel event
540         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, _pts_size_cancel_cb, ad);
541
542         genlist = elm_genlist_add(popup);
543         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
544         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
545
546         if (!size_radio_main) {
547                 size_radio_main = elm_radio_add(genlist);
548                 elm_radio_state_value_set(size_radio_main, size_index);
549                 elm_radio_value_set(size_radio_main, size_index);
550         }
551
552         size_itc.item_style = "1text.1icon.2";
553         size_itc.func.text_get = __pts_size_label_get;
554         size_itc.func.content_get = __pts_size_icon_get;
555         size_itc.func.state_get = NULL;
556         size_itc.func.del = NULL;
557
558         Elm_Object_Item  *item = NULL;
559         for (index = 0; index < PTS_SIZE_MAX; index++) {
560                 item = elm_genlist_item_append(genlist, &size_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, __pts_size_sel, ad);
561                 PTS_DEBUG("index[%d] - item added : %s", index, (NULL == item)? "FAILURE" : "SUCCESS");
562         }
563
564         Evas_Object *box = elm_box_add(popup);
565         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
566
567         elm_box_pack_end(box, genlist);
568
569         ad->size_popup_info.size_popup_portrait_height = elm_genlist_items_count(genlist) * 114 * elm_config_scale_get();
570         ad->size_popup_info.size_popup_landscape_height = 300;
571
572         int orientation = 0;
573         if (ad->win)
574                 orientation = elm_win_rotation_get(ad->win);
575
576         if (APP_DEVICE_ORIENTATION_0 == orientation ||
577                         APP_DEVICE_ORIENTATION_180 == orientation) {
578                 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.size_popup_portrait_height);
579         } else {
580                 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.size_popup_landscape_height);
581         }
582
583         evas_object_show(box);
584         elm_object_part_content_set(layout, "elm.swallow.content" , box);
585         elm_object_content_set(popup, box);
586         ad->size_popup_info.size_popup_box = box;
587         elm_object_focus_set(popup, EINA_TRUE);
588         evas_object_show(genlist);
589         evas_object_show(popup);
590
591         ad->size_popup_info.size_popup = popup;
592
593         PTS_TRACE_END;
594         return genlist;
595 }
596
597 static void _pts_custom_ok_cb(void *data, Evas_Object *obj, void *event_info)
598 {
599         PTS_TRACE_BEGIN;
600
601         pts_appdata_t *ad = (pts_appdata_t *)data;
602         PTS_RET_IF(ad == NULL, "ad is NULL");
603
604         ad->size_popup_info.image_size = PTS_SIZE_CUSTOM;
605         load_image_editor_ug(ad);
606
607         PTS_IF_DEL_OBJ(obj);
608         PTS_IF_DEL_OBJ(ad->size_popup_info.custom_popup);
609         elm_theme_extension_del(NULL, RESDIR"/edje/genlist_custom.edj");
610
611         PTS_TRACE_END;
612 }
613
614 static void _pts_custom_cancel_cb(void *data, Evas_Object *obj, void *event_info)
615 {
616         PTS_TRACE_BEGIN;
617
618         pts_appdata_t *ad = (pts_appdata_t *)data;
619         PTS_RET_IF(ad == NULL, "ad is NULL");
620         PTS_IF_DEL_OBJ(obj);
621         PTS_IF_DEL_OBJ(ad->size_popup_info.custom_popup);
622
623         // FIXME - just back to original size
624         int tmp_width = 0;
625         int tmp_height = 0;
626
627         get_image_resolution(ad->printing_data.input_file, &tmp_width, &tmp_height);
628         ad->size_popup_info.custom_width = (double)tmp_width;
629         ad->size_popup_info.custom_height = (double)tmp_height;
630         ad->size_popup_info.custom_w_ratio = ad->size_popup_info.custom_width / ad->size_popup_info.custom_height;
631         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);
632         // original image size (unit cm) calculated by 300dpi
633         ad->size_popup_info.custom_width = (ad->size_popup_info.custom_width / 300) * 2.54;
634         ad->size_popup_info.custom_height = (ad->size_popup_info.custom_height / 300) * 2.54;
635         ad->size_popup_info.custom_unit = 1; // cm unit
636
637         elm_theme_extension_del(NULL, RESDIR"/edje/genlist_custom.edj");
638
639         PTS_TRACE_END;
640 }
641
642 static char *__pts_custom_label_get(void *data, Evas_Object *obj, const char *part)
643 {
644         PTS_TRACE_BEGIN;
645         int index = (int)data;
646         char *label = NULL;
647
648         if (strcmp(part, "elm.text") == 0) {
649                 if (index == 0) {
650                         label = strdup(_("IDS_IMGE_BODY_WIDTH"));
651                 } else if (index == 2) {
652                         label = strdup(_("IDS_IMGE_BODY_HEIGHT"));
653                 } else if (index == 4) {
654                         label = strdup(_("IDS_PRT_BODY_KEEP_ASPECT_RATIO_ABB"));
655                 } else {
656                         label = strdup("Unknown label");
657                 }
658         }
659
660         PTS_TRACE_END;
661         return label;
662 }
663
664 static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
665 {
666         PTS_TRACE_BEGIN;
667         char *input_str = NULL;
668         const char *entry_text = NULL;
669         int index = (int)data;
670
671         entry_text = elm_entry_entry_get(obj);
672         if ((input_str = elm_entry_markup_to_utf8(entry_text))) {
673                 pts_appdata_t *ad = pts_get_appdata();
674
675                 if (index == 1) {
676                         ad->size_popup_info.custom_width = atoi(input_str);
677                 } else if (index == 3) {
678                         ad->size_popup_info.custom_height = atoi(input_str);
679                 } else {
680                         PTS_DEBUG("Unknown index : %d", index);
681                 }
682
683                 PTS_DEBUG("Typed custom value : width[%lf] x height[%lf]", ad->size_popup_info.custom_width, ad->size_popup_info.custom_height);
684
685                 PTS_IF_FREE_MEM(input_str);
686         }
687         PTS_TRACE_END;
688 }
689
690 static void _focused_cb(void *data, Evas_Object *obj, void *event_info) // Focused callback will show X marked button and hide guidetext.
691 {
692         PTS_TRACE_BEGIN;
693         elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
694         PTS_TRACE_END;
695 }
696
697 static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info) // Unfocused callback will show guidetext and hide X marked button.
698 {
699         PTS_TRACE_BEGIN;
700         char temp_size[32] = {0,};
701
702         if (elm_entry_is_empty(obj)) {
703                 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
704         }
705
706         if (aspect_ratio) {
707                 pts_appdata_t *ad = pts_get_appdata();
708
709                 if (obj == width_entry) {
710                         ad->size_popup_info.custom_height = ad->size_popup_info.custom_width / ad->size_popup_info.custom_w_ratio;
711                         snprintf(temp_size, 32, "%.1lf", ad->size_popup_info.custom_height);
712                         elm_object_signal_emit(height_layout, "elm,state,guidetext,hide", "elm");
713                         elm_entry_entry_set(height_entry, temp_size);
714                 } else if (obj == height_entry) {
715                         ad->size_popup_info.custom_width = ad->size_popup_info.custom_height * ad->size_popup_info.custom_w_ratio;
716                         snprintf(temp_size, 32, "%.1lf", ad->size_popup_info.custom_width);
717                         elm_object_signal_emit(width_layout, "elm,state,guidetext,hide", "elm");
718                         elm_entry_entry_set(width_entry, temp_size);
719                 } else {
720                         PTS_DEBUG("Unknown entry : %p", obj);
721                 }
722         }
723         PTS_TRACE_END;
724 }
725
726 static void _eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) // When X marked button clicked, make string as empty.
727 {
728         PTS_TRACE_BEGIN;
729         elm_entry_entry_set(data, "");
730         PTS_TRACE_END;
731 }
732
733 static Evas_Object *__pts_singleline_editfield_add(Evas_Object *parent, int index) // For single lined editfield without top title.
734 {
735         PTS_TRACE_BEGIN;
736         Evas_Object *layout, *entry;
737         static Elm_Entry_Filter_Accept_Set digits_filter_data;
738         char temp_size[32] = {0,};
739         pts_appdata_t *ad = pts_get_appdata();
740
741         layout = elm_layout_add(parent);
742         elm_layout_theme_set(layout, "layout", "editfield", "default"); // Default editfield layout style without top title.
743
744         entry = elm_entry_add(layout);
745         elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
746         elm_entry_scrollable_set(entry, EINA_TRUE); // Make entry as scrollable single line.
747         elm_entry_single_line_set(entry, EINA_TRUE);
748         elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
749         evas_object_smart_callback_add(entry, "changed", _changed_cb, (void *)index);
750         evas_object_smart_callback_add(entry, "focused", _focused_cb, layout);
751         evas_object_smart_callback_add(entry, "unfocused", _unfocused_cb, layout);
752
753         digits_filter_data.accepted = "0123456789.";
754         digits_filter_data.rejected = NULL;
755         elm_entry_markup_filter_append(entry, elm_entry_filter_accept_set, &digits_filter_data);
756
757         elm_object_part_content_set(layout, "elm.swallow.content", entry);
758         if (index == 1) {
759                 snprintf(temp_size, 32, "%.1lf", ad->size_popup_info.custom_width);
760                 elm_object_part_text_set(layout, "elm.guidetext", temp_size);
761                 width_layout = layout;
762                 width_entry = entry;
763         } else if (index == 3) {
764                 snprintf(temp_size, 32, "%.1lf", ad->size_popup_info.custom_height);
765                 elm_object_part_text_set(layout, "elm.guidetext", temp_size);
766                 height_layout = layout;
767                 height_entry = entry;
768         } else {
769                 elm_object_part_text_set(layout, "elm.guidetext", "Custom Size");
770         }
771
772         elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, entry);
773
774         evas_object_show(entry);
775
776         PTS_TRACE_END;
777         return layout;
778 }
779
780 static void _pts_custom_unit_cb(void *data, Evas_Object *obj, void *event_info)
781 {
782         PTS_TRACE_BEGIN;
783         char temp[32] = {0,};
784         pts_appdata_t *ad = pts_get_appdata();
785         PTS_DEBUG("Current unit : %d", ad->size_popup_info.custom_unit);
786
787         if (ad->size_popup_info.custom_unit == 1) { // cm to inch
788                 ad->size_popup_info.custom_unit = 2;
789                 ad->size_popup_info.custom_width = ad->size_popup_info.custom_width / 2.54;
790                 ad->size_popup_info.custom_height = ad->size_popup_info.custom_height / 2.54;
791                 snprintf(temp, 32, "%s", _("IDS_COM_BODY_UNIT_CM"));
792         } else if (ad->size_popup_info.custom_unit == 2) { // inch to cm
793                 ad->size_popup_info.custom_unit = 1;
794                 ad->size_popup_info.custom_width = ad->size_popup_info.custom_width * 2.54;
795                 ad->size_popup_info.custom_height = ad->size_popup_info.custom_height * 2.54;
796                 snprintf(temp, 32, "%s", _("IDS_COM_BODY_UNIT_INCH"));
797         } else {
798                 PTS_DEBUG("Unknown unit");
799                 PTS_TRACE_END;
800                 return;
801         }
802
803         elm_object_text_set(obj, temp);
804
805         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_width);
806         elm_object_signal_emit(width_layout, "elm,state,guidetext,hide", "elm");
807         elm_entry_entry_set(width_entry, temp);
808         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_height);
809         elm_object_signal_emit(height_layout, "elm,state,guidetext,hide", "elm");
810         elm_entry_entry_set(height_entry, temp);
811
812         PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
813         PTS_TRACE_END;
814 }
815
816 static void _pts_custom_unit_inch_cb(void *data, Evas_Object *obj, void *event_info)
817 {
818         PTS_TRACE_BEGIN;
819         char temp[32] = {0,};
820         pts_appdata_t *ad = pts_get_appdata();
821         PTS_DEBUG("Current unit : %d", ad->size_popup_info.custom_unit);
822
823         if (ad->size_popup_info.custom_unit == 1) { // cm to inch
824                 ad->size_popup_info.custom_unit = 2;
825                 ad->size_popup_info.custom_width = ad->size_popup_info.custom_width / 2.54;
826                 ad->size_popup_info.custom_height = ad->size_popup_info.custom_height / 2.54;
827         } else {
828                 PTS_DEBUG("Unknown unit");
829                 PTS_TRACE_END;
830                 return;
831         }
832
833         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_width);
834         elm_object_signal_emit(width_layout, "elm,state,guidetext,hide", "elm");
835         elm_entry_entry_set(width_entry, temp);
836         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_height);
837         elm_object_signal_emit(height_layout, "elm,state,guidetext,hide", "elm");
838         elm_entry_entry_set(height_entry, temp);
839
840         PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
841         PTS_TRACE_END;
842 }
843
844 static void _pts_custom_unit_cm_cb(void *data, Evas_Object *obj, void *event_info)
845 {
846         PTS_TRACE_BEGIN;
847         char temp[32] = {0,};
848         pts_appdata_t *ad = pts_get_appdata();
849         PTS_DEBUG("Current unit : %d", ad->size_popup_info.custom_unit);
850
851         if (ad->size_popup_info.custom_unit == 2) { // inch to cm
852                 ad->size_popup_info.custom_unit = 1;
853                 ad->size_popup_info.custom_width = ad->size_popup_info.custom_width * 2.54;
854                 ad->size_popup_info.custom_height = ad->size_popup_info.custom_height * 2.54;
855         } else {
856                 PTS_DEBUG("Unknown unit");
857                 PTS_TRACE_END;
858                 return;
859         }
860
861         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_width);
862         elm_object_signal_emit(width_layout, "elm,state,guidetext,hide", "elm");
863         elm_entry_entry_set(width_entry, temp);
864         snprintf(temp, 32, "%.1lf", ad->size_popup_info.custom_height);
865         elm_object_signal_emit(height_layout, "elm,state,guidetext,hide", "elm");
866         elm_entry_entry_set(height_entry, temp);
867
868         PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
869         PTS_TRACE_END;
870 }
871
872 static Evas_Object *__pts_custom_icon_get(void *data, Evas_Object *obj, const char *part)
873 {
874         PTS_TRACE_BEGIN;
875         Evas_Object *editfield = NULL;
876         Evas_Object *check = NULL;
877         Evas_Object *button = NULL;
878         int index = (int)data;
879         char unit[32] = {0,};
880
881         PTS_DEBUG("index: %d, passed part: %s", index, part);
882         if (!strcmp(part, "elm.icon")) {
883                 switch (index) {
884                 case 1: // width text field
885                 case 3: // height text field
886                         editfield = __pts_singleline_editfield_add(obj, index);
887                         return editfield;
888                 case 4: // check aspect ratio
889                         check = elm_check_add(obj);
890                         //set the State pointer to keep the current UI state of Checkbox.
891                         elm_check_state_pointer_set(check, &aspect_ratio);
892
893                         evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
894                         evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
895                         return check;
896                 case 5: // change unit button
897                         button = elm_button_add(obj);
898                         snprintf(unit, 32, "%s", _("IDS_COM_BODY_UNIT_INCH"));
899                         elm_object_text_set(button, unit);
900                         elm_object_part_content_set(obj, "button1", button);
901                         evas_object_smart_callback_add(button, "clicked", _pts_custom_unit_cb, obj);
902                         return button;
903                 }
904         } else if (!strcmp(part, "elm.icon.1")) {
905                 button = elm_button_add(obj);
906                 snprintf(unit, 32, "%s", _("IDS_COM_BODY_UNIT_INCH"));
907                 elm_object_text_set(button, unit);
908                 elm_object_part_content_set(obj, "button1", button);
909                 evas_object_smart_callback_add(button, "clicked", _pts_custom_unit_inch_cb, obj);
910                 return button;
911         } else if (!strcmp(part, "elm.icon.2")) {
912                 button = elm_button_add(obj);
913                 snprintf(unit, 32, "%s", _("IDS_COM_BODY_UNIT_CM"));
914                 elm_object_text_set(button, unit);
915                 elm_object_part_content_set(obj, "button2", button);
916                 evas_object_smart_callback_add(button, "clicked", _pts_custom_unit_cm_cb, obj);
917                 return button;
918         } else {
919                 PTS_DEBUG("Index: %d, Unknown part: %s", index, part);
920         }
921
922         PTS_TRACE_END;
923         return NULL;
924 }
925
926 static void __pts_custom_sel(void *data, Evas_Object *obj, void *event_info)
927 {
928         PTS_TRACE_BEGIN;
929
930         pts_appdata_t *ad = (pts_appdata_t *)data;
931         PTS_RET_IF(ad == NULL, "ad is NULL");
932
933         int index = -1;
934         Elm_Object_Item *item = event_info;
935
936         if (item != NULL) {
937                 elm_genlist_item_selected_set(item, EINA_FALSE);
938
939                 index = (int)elm_object_item_data_get(item);
940                 if (index == 4) {
941                         aspect_ratio = !aspect_ratio;
942                         PTS_DEBUG("Preserve aspect ratio : %d", aspect_ratio);
943
944                         elm_genlist_item_update(item);
945                 } else {
946                         PTS_DEBUG("Unknown index");
947                 }
948         }
949         PTS_TRACE_END;
950 }
951
952 Evas_Object *pts_create_custom_popup(Evas_Object *parent, pts_appdata_t *ad)
953 {
954         PTS_TRACE_BEGIN;
955         Evas_Object *popup;
956         Evas_Object *genlist;
957         Evas_Object *ok_button;
958         Evas_Object *cancel_button;
959         int index = -1;
960
961         popup = elm_popup_add(parent);
962         elm_object_style_set(popup,"content_no_vhpad");
963         elm_object_part_text_set(popup, "title,text", _("IDS_COM_SK_CUSTOM"));
964         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
965
966         Evas_Object *layout = elm_layout_add(popup);
967         elm_layout_theme_set(layout, "layout", "content", "min_menustyle");
968         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
969
970         cancel_button = elm_button_add(popup);
971         elm_object_style_set(cancel_button,"popup_button/default");
972         elm_object_text_set(cancel_button, _("IDS_COM_SK_CANCEL"));
973         elm_object_part_content_set(popup, "button1", cancel_button);
974         evas_object_smart_callback_add(cancel_button, "clicked", _pts_custom_cancel_cb, ad);
975
976         ok_button = elm_button_add(popup);
977         elm_object_style_set(ok_button,"popup_button/default");
978         elm_object_text_set(ok_button, _("IDS_COM_SK_OK"));
979         elm_object_part_content_set(popup, "button2", ok_button);
980         evas_object_smart_callback_add(ok_button, "clicked", _pts_custom_ok_cb, ad);
981
982         elm_theme_extension_add(NULL, RESDIR"/edje/genlist_custom.edj");
983         PTS_DEBUG("Added extension theme");
984
985         genlist = elm_genlist_add(popup);
986         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
987         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
988
989         title_itc.item_style = "dialogue/title";
990         title_itc.func.text_get = __pts_custom_label_get;
991         title_itc.func.content_get = NULL;
992         title_itc.func.state_get = NULL;
993         title_itc.func.del = NULL;
994
995         text_itc.item_style = "1icon";
996         text_itc.func.text_get = NULL;
997         text_itc.func.content_get = __pts_custom_icon_get;
998         text_itc.func.state_get = NULL;
999         text_itc.func.del = NULL;
1000
1001         check_itc.item_style = "1text.1icon.2";
1002         check_itc.func.text_get = __pts_custom_label_get;
1003         check_itc.func.content_get = __pts_custom_icon_get;
1004         check_itc.func.state_get = NULL;
1005         check_itc.func.del = NULL;
1006
1007         //button_itc.item_style = "dialogue/bg/2icon";
1008         button_itc.item_style = "custom/2icon";
1009         button_itc.func.text_get = NULL;
1010         button_itc.func.content_get = __pts_custom_icon_get;
1011         button_itc.func.state_get = NULL;
1012         button_itc.func.del = NULL;
1013
1014         Elm_Object_Item  *item = NULL;
1015         Elm_Genlist_Item_Class *temp_itc = NULL;
1016         Evas_Smart_Cb temp_cb = NULL;
1017
1018         for (index = 0; index < 6; index++) {
1019                 if (index == 0 || index == 2) { // width&height title
1020                         temp_itc = &title_itc;
1021                 } else if (index == 1 || index == 3) { // width&height text field
1022                         temp_itc = &text_itc;
1023                 } else if (index == 4) { // aspect ratio check
1024                         temp_itc = &check_itc;
1025                         temp_cb = __pts_custom_sel;
1026                 } else if (index == 5) { // change unit button
1027                         temp_itc = &button_itc;
1028                 } else {
1029                 }
1030
1031                 item = elm_genlist_item_append(genlist, temp_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, temp_cb, ad);
1032                 if (index != 4) {
1033                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_NONE);
1034                 }
1035                 PTS_DEBUG("index[%d] - item added : %s", index, (NULL == item)? "FAILURE" : "SUCCESS");
1036         }
1037
1038         Evas_Object *box = elm_box_add(popup);
1039         evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1040
1041         elm_box_pack_end(box, genlist);
1042
1043         ad->size_popup_info.custom_popup_portrait_height = (5 * 114 + 4) * elm_config_scale_get();
1044         ad->size_popup_info.custom_popup_landscape_height = 300;
1045         int orientation = 0;
1046         if (ad->win)
1047                 orientation = elm_win_rotation_get(ad->win);
1048
1049         if (APP_DEVICE_ORIENTATION_0 == orientation ||
1050                         APP_DEVICE_ORIENTATION_180 == orientation) {
1051                 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.custom_popup_portrait_height);
1052         } else {
1053                 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.custom_popup_landscape_height);
1054         }
1055
1056         elm_object_part_content_set(layout, "elm.swallow.content" , box);
1057         //evas_object_event_callback_add(popup, EVAS_CALLBACK_MOUSE_UP, _pts_mouse_cb, ad);
1058         ea_object_event_callback_add(popup, EA_CALLBACK_BACK, _pts_custom_cancel_cb, ad);
1059         elm_object_focus_set(popup, EINA_TRUE);
1060
1061         elm_object_content_set(popup, box);
1062         ad->size_popup_info.custom_popup_box = box;
1063
1064         evas_object_show(genlist);
1065         evas_object_show(popup);
1066
1067         ad->size_popup_info.custom_popup = popup;
1068
1069         PTS_TRACE_END;
1070         return genlist;
1071 }
1072
1073 static Evas_Object *__pts_utils_create_conformant(Evas_Object *parent)
1074 {
1075
1076         Evas_Object *conform = NULL;
1077         elm_win_conformant_set(parent, TRUE);
1078         conform = elm_conformant_add(parent);
1079
1080         elm_object_style_set(conform, "internal_layout");
1081
1082         //evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1083         //evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
1084
1085         evas_object_show(conform);
1086
1087         return conform;
1088 }
1089
1090 Evas_Object *pts_utils_create_layout(Evas_Object *navi_frame)
1091 {
1092         Evas_Object *layout;
1093         layout = elm_layout_add(navi_frame);
1094         elm_layout_theme_set(layout, "layout", "application", "default");
1095         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1096
1097         //Evas_Object *bg = elm_bg_add(layout);
1098         //evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1099         //elm_object_style_set(bg, "group_list");
1100         //elm_object_part_content_set(layout, "elm.swallow.bg", bg);
1101
1102         //Evas_Object *conform = __pts_utils_create_conformant(layout);
1103         //assertm_if(NULL == conform, "NULL!!");
1104         //elm_object_part_content_set(layout, "elm.swallow.content", conform);
1105         //elm_object_part_content_set(layout, "elm.swallow.content", layout);
1106         evas_object_show(layout);
1107
1108         return layout;
1109 }
1110
1111 /*
1112 * this function is used to compose folder and filename.
1113 */
1114 char **__compose_image_files_path(char *folder, const char **filesname, const int num_of_files)
1115 {
1116         PTS_TRACE_BEGIN;
1117         PTS_RETV_IF(folder == NULL, NULL, "folder is NULL");
1118         PTS_RETV_IF(filesname == NULL, NULL, "filesname is NULL");
1119         PTS_RETV_IF(num_of_files <= 0, NULL, "num is invalid(%d)",num_of_files);
1120
1121         char **paths = NULL;
1122         paths = (char **)malloc(sizeof(char *)*num_of_files);
1123         PTS_RETV_IF(paths == NULL , NULL, "malloc failed!");
1124
1125         int count = 0;
1126         int index = 0;
1127         char filepath[512] = {0};
1128
1129         for (; count < num_of_files ; count++) {
1130                 snprintf(filepath, 512, "%s/%s", folder, filesname[count]);
1131
1132                 paths[count] = strdup(filepath);
1133                 if (paths[count] == NULL) {
1134                         PTS_DEBUG("Failed to strdup");
1135                         for (index = 0 ; index < count ; index++) {
1136                                 PTS_IF_FREE_MEM(paths[index]);
1137                         }
1138                         PTS_IF_FREE_MEM(paths);
1139                         return NULL;
1140                 }
1141                 PTS_DEBUG("files[%d]: %s", count, paths[count]);
1142         }
1143
1144         PTS_TRACE_END;
1145         return paths;
1146 }
1147
1148 /*
1149 * validate the path of image files.
1150 */
1151 bool __validate_file_type(char **files, int num)
1152 {
1153         PTS_TRACE_BEGIN;
1154
1155         PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
1156
1157         int i = 0;
1158         char *path = NULL;
1159         const int filters_num = 16;
1160         /* the image type that cups supports */
1161         const char *filters[] = {".gif", ".bmp", ".sgi", ".ras", ".pbm", ".pgm", ".ppm", ".pcd",
1162                                                          ".pix", ".png", ".jpeg", ".jpg", ".jpe", ".tiff", ".tif", ".pdf"
1163                                                         };
1164
1165         for (; i < num; i++) {
1166                 path = *(files + i);
1167
1168                 /* check whether the file is exist */
1169                 int ret = -1;
1170                 struct stat buf;
1171
1172                 ret = stat(path, &buf);
1173                 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1174
1175                 /* check whether the file can be supported */
1176                 char *p = NULL;
1177                 p = strrchr(path, '.');
1178                 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1179
1180                 int j = 0;
1181                 int tag = 0;
1182
1183                 for (; j < filters_num; j++) {
1184                         if (0 == strcasecmp(p, filters[j])) {
1185                                 tag = 1;
1186                                 break;
1187                         }
1188                 }
1189                 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1190         }
1191
1192         PTS_TRACE_END;
1193         return true;
1194 }
1195
1196 /*
1197 * validate the path of image files.
1198 */
1199 bool _is_pdf_file_type(char **files, int num)
1200 {
1201         PTS_TRACE_BEGIN;
1202
1203         PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
1204
1205         int i = 0;
1206         char *path = NULL;
1207         const int filters_num = 1;
1208         /* the image type that cups supports */
1209         const char *filters[] = {".pdf"};
1210
1211         for (; i < num; i++) {
1212                 path = *(files + i);
1213
1214                 /* check whether the file is exist */
1215                 int ret = -1;
1216                 struct stat buf;
1217
1218                 ret = stat(path, &buf);
1219                 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1220
1221                 /* check whether the file can be supported */
1222                 char *p = NULL;
1223                 p = strrchr(path, '.');
1224                 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1225
1226                 int j = 0;
1227                 int tag = 0;
1228
1229                 for (; j < filters_num; j++) {
1230                         if (0 == strcasecmp(p, filters[j])) {
1231                                 tag = 1;
1232                                 break;
1233                         }
1234                 }
1235                 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1236         }
1237
1238         PTS_TRACE_END;
1239         return true;
1240 }
1241
1242 /*
1243 * validate the path of image files.
1244 */
1245 bool _is_img_file_type(char **files, int num)
1246 {
1247         PTS_TRACE_BEGIN;
1248
1249         PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
1250
1251         int i = 0;
1252         char *path = NULL;
1253         const int filters_num = 15;
1254         /* the image type that cups supports */
1255         const char *filters[] = {".gif", ".bmp", ".sgi", ".ras", ".pbm", ".pgm", ".ppm", ".pcd",
1256                                                          ".pix", ".png", ".jpeg", ".jpg", ".jpe", ".tiff", ".tif"};
1257
1258         for (; i < num; i++) {
1259                 path = *(files + i);
1260
1261                 /* check whether the file is exist */
1262                 int ret = -1;
1263                 struct stat buf;
1264
1265                 ret = stat(path, &buf);
1266                 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1267
1268                 /* check whether the file can be supported */
1269                 char *p = NULL;
1270                 p = strrchr(path, '.');
1271                 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1272
1273                 int j = 0;
1274                 int tag = 0;
1275
1276                 for (; j < filters_num; j++) {
1277                         if (0 == strcasecmp(p, filters[j])) {
1278                                 tag = 1;
1279                                 break;
1280                         }
1281                 }
1282                 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1283         }
1284
1285         PTS_TRACE_END;
1286         return true;
1287 }
1288
1289 inline char *_pts_printing_data_get_directory(pts_printing_data_t *data)
1290 {
1291         return data->directory;
1292 }
1293
1294 inline char **_pts_printing_data_get_request_files(pts_printing_data_t *data)
1295 {
1296         return data->request_files;
1297 }
1298 inline int _pts_printing_data_get_files_count(pts_printing_data_t *data)
1299 {
1300         return data->num_of_files;
1301 }
1302
1303 inline int _pts_printing_data_get_index(pts_printing_data_t *data)
1304 {
1305         return data->current_index;
1306 }
1307
1308 inline char *_pts_printing_data_get_type(pts_printing_data_t *data)
1309 {
1310         return data->type;
1311 }
1312
1313 Eina_Bool _pts_printing_data_set_directory(const char *directory, pts_printing_data_t *data)
1314 {
1315         PTS_RETV_IF(directory == NULL, EINA_FALSE, "directory is NULL");
1316         PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1317
1318         data->directory = strdup(directory);
1319
1320         PTS_RETV_IF(data->directory == NULL, EINA_FALSE, "Failed to strdup");
1321         return EINA_TRUE;
1322 }
1323
1324 Eina_Bool _pts_printing_data_set_request_files(const char **request_files, const int files_count, pts_printing_data_t *data)
1325 {
1326         PTS_RETV_IF(request_files == NULL, EINA_FALSE, "request_files is NULL");
1327         PTS_RETV_IF(files_count <= 0, EINA_FALSE, "files_count is less than zero");
1328
1329         int count = 0;
1330         count = _pts_printing_data_get_files_count(data);
1331         PTS_RETV_IF(count != files_count, EINA_FALSE, "files count is not same with argument");
1332
1333         char *temp                              = NULL;
1334         char **composite_files  = NULL;
1335         bool ret                                        = false;
1336
1337         temp = _pts_printing_data_get_directory(data);
1338         if (temp != NULL) {
1339                 composite_files = __compose_image_files_path(temp, request_files, count);
1340                 PTS_RETV_IF(composite_files == NULL, EINA_FALSE, "compose the path of print files failed!");
1341                 data->request_files = composite_files;
1342         } else {
1343                 data->request_files = (char **)calloc(count, sizeof(char *));
1344                 PTS_RETV_IF(data->request_files == NULL, EINA_FALSE, "Failed to calloc");
1345
1346                 int     index = 0;
1347                 for (index = 0 ; index < count ; index++) {
1348                         temp = strdup(request_files[index]);
1349                         PTS_RETV_IF(temp == NULL, EINA_FALSE, "Failed to strdup");
1350                         data->request_files[index] = temp;
1351                         temp = NULL;
1352                 }
1353         }
1354
1355         ret = __validate_file_type(data->request_files, files_count);
1356         PTS_RETV_IF(ret != true, EINA_FALSE, "files is invalid");
1357
1358
1359         return EINA_TRUE;
1360 }
1361
1362 Eina_Bool _pts_printing_data_set_files_count(const char *num_of_files, pts_printing_data_t *data)
1363 {
1364         PTS_RETV_IF(num_of_files == NULL, EINA_FALSE,"num_of_files is NULL");
1365         PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1366
1367         int count = 0;
1368         count = atoi(num_of_files);
1369         PTS_RETV_IF(count <=0, EINA_FALSE, "num_of_files is less or equal than zero");
1370         data->num_of_files = count;
1371         return EINA_TRUE;
1372 }
1373
1374 Eina_Bool _pts_printing_data_set_index(const char *current_index, pts_printing_data_t *data)
1375 {
1376         PTS_RETV_IF(current_index == NULL, EINA_FALSE,"current_index is NULL");
1377         PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1378
1379         int index = -1;
1380         index = atoi(current_index);
1381
1382         PTS_RETV_IF(index < 0, EINA_FALSE, "index is less than zero");
1383         if (index >= _pts_printing_data_get_files_count(data)) {
1384                 PTS_DEBUG("the current index of print files(%s) is invalid!", index);
1385                 return EINA_FALSE;
1386         } else {
1387                 data->current_index = index;
1388                 return EINA_TRUE;
1389         }
1390 }
1391
1392 Eina_Bool _is_document_ux_type(const char *type)
1393 {
1394         PTS_RETV_IF(type == NULL, EINA_FALSE, "type is NULL");
1395         if (strcasecmp(type, "DOC") == 0) {
1396                 return EINA_TRUE;
1397         }
1398         return EINA_FALSE;
1399 }
1400
1401 Eina_Bool _is_image_ux_type(const char *type)
1402 {
1403         PTS_RETV_IF(type == NULL, EINA_FALSE, "type is NULL");
1404         if (strcasecmp(type, "IMG") == 0) {
1405                 return EINA_TRUE;
1406         }
1407         return EINA_FALSE;
1408 }
1409
1410 Eina_Bool _is_valid_print_file_type(const char *type)
1411 {
1412         if (strcasecmp(type, "IMG") && strcasecmp(type,"DOC") && strcasecmp(type,"WEB")) {
1413                 PTS_DEBUG("the type of print files(%s) is invalid!", type);
1414                 return EINA_FALSE;
1415         }
1416
1417         return EINA_TRUE;
1418 }
1419
1420 Eina_Bool _pts_printing_data_set_type(const char *type, pts_printing_data_t *data)
1421 {
1422         PTS_RETV_IF(type == NULL, EINA_FALSE, "type is NULL");
1423         PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1424         PTS_RETV_IF(_is_valid_print_file_type(type) == EINA_FALSE, EINA_FALSE, "invalid type");
1425
1426         data->type = strdup(type);
1427         PTS_RETV_IF(data->type == NULL, EINA_FALSE, "Failed to strdup");
1428         return EINA_TRUE;
1429 }