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