4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <ui-gadget.h>
23 #include <vconf-keys.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"
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);
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;
47 static Eina_Bool aspect_ratio = 0;
49 static Evas_Object *width_layout;
50 static Evas_Object *width_entry;
51 static Evas_Object *height_layout;
52 static Evas_Object *height_entry;
54 int pts_unstandardization(char *name)
56 char *ptr = NULL;/* Pointer into name */
57 PTS_RETV_IF(name == NULL, -1, "Invalid argument");
59 for (ptr = name; *ptr; ptr++) {
62 } else if ((*ptr >= 0 && *ptr < ' ') ||
63 *ptr == 127 || *ptr == '/' ||*ptr == '#') {
65 } else if (*ptr == 0x5F) {
66 *ptr = 0x20; /*convert _ to space*/
67 } else if (*ptr == '[' || *ptr == '(') {
83 char* pts_parse_protocol(char *addr)
86 char *printer_protocol = NULL;
88 PTS_RETV_IF(addr == NULL, NULL, "Invalid argument");
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");
99 printer_protocol = strdup("Unknown");
103 return printer_protocol;
108 * This function let the app create the label
110 * @param[in] parent the pointer to the parent of the label
111 * @param[in] desc the pointer to label text
113 Evas_Object *pts_create_label_btn(Evas_Object *parent, const char *label)
116 Evas_Object *btn = elm_button_add(parent);
117 elm_object_text_set(btn, label);
118 evas_object_show(btn);
125 * This function let the app create the base layout
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
130 Evas_Object *pts_create_base_layout_with_conform(Evas_Object *parent, const char *group)
133 char edj_file[128] = {0};
134 Evas_Object *base = NULL;
135 Evas_Object *conform = NULL;
139 app_get_resource("edje/mobileprint.edj", edj_file, 128);
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);
146 base = elm_layout_add(conform);
147 //base = elm_layout_add(parent);
149 r = elm_layout_file_set(base, edj_file, group);
151 evas_object_del(base);
154 elm_object_content_set(conform, base);
155 //evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
162 Evas_Object *pts_create_base_layout(Evas_Object *parent, const char *group)
165 char edj_file[128] = {0};
166 Evas_Object *base = NULL;
170 app_get_resource("edje/mobileprint.edj", edj_file, 128);
172 base = elm_layout_add(parent);
174 r = elm_layout_file_set(base, edj_file, group);
176 evas_object_del(base);
179 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
188 * This function let the app create the popup element
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
194 Evas_Object *pts_create_popup(Evas_Object *parent, const char *desc, double timeout)
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);
208 static void _pts_scaling_set_cb(void *data, Evas_Object *obj, void *event_info)
211 pts_appdata_t *ad = (pts_appdata_t *)data;
212 PTS_RET_IF(ad == NULL, "ad is NULL");
214 PTS_IF_DEL_OBJ(scaling_radio_main);
215 PTS_IF_DEL_OBJ(ad->scaling_popup_info.scaling_popup);
217 pts_main_view_rotate_image(ad, app_get_device_orientation());
221 static char *__pts_scaling_label_get(void *data, Evas_Object *obj, const char *part)
224 int index = (int)data;
226 char temp[1024] = {0};
228 if (strcmp(part, "elm.text") == 0) {
230 case PT_SCALING_FIT_TO_PAGE:
231 label = strdup(_("IDS_BT_OPT_FIT_TO_PAPER"));
233 case PT_SCALING_2_PAGES:
234 snprintf(temp,1024,_("IDS_PRT_BODY_PD_PAGES_ON_1_SHEET_ABB"),2);
235 label = strdup(temp);
237 case PT_SCALING_4_PAGES:
238 snprintf(temp,1024,_("IDS_PRT_BODY_PD_PAGES_ON_1_SHEET_ABB"),4);
239 label = strdup(temp);
242 label = strdup("Unknown option");
251 static Evas_Object *__pts_scaling_icon_get(void *data, Evas_Object *obj, const char *part)
255 int index = (int)data;
256 PTS_DEBUG("Passed index : %d", index);
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);
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);
280 static void __pts_scaling_sel(void *data, Evas_Object *obj, void *event_info)
284 pts_appdata_t *ad = (pts_appdata_t *)data;
285 PTS_RET_IF(NULL == ad, "ad is NULL");
288 Elm_Object_Item *item = event_info;
291 elm_genlist_item_selected_set(item, EINA_FALSE);
293 scaling = (int)elm_object_item_data_get(item);
295 PTS_DEBUG("Selected scaling : %d", scaling);
297 scaling_index = ad->list_info.active_printer->scaling = scaling;
299 // Now call real event trigger to update radio button when selected.
300 elm_genlist_item_update(item);
306 Evas_Object *pts_create_scaling_popup(Evas_Object *parent, pts_appdata_t *ad)
310 Evas_Object *genlist;
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"));
318 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
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);
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);
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);
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;
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");
348 Evas_Object *box = elm_box_add(popup);
349 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
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);
355 evas_object_show(genlist);
356 evas_object_show(popup);
358 ad->scaling_popup_info.scaling_popup = popup;
364 static void _pts_size_cancel_cb(void *data, Evas_Object *obj, void *event_info)
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);
371 PTS_IF_DEL_OBJ(ad->size_popup_info.size_popup);
375 static char *__pts_size_label_get(void *data, Evas_Object *obj, const char *part)
378 int index = (int)data;
380 char custom[32] = {0,};
381 pts_appdata_t *ad = pts_get_appdata();
383 if (strcmp(part, "elm.text") == 0) {
385 case PTS_SIZE_FIT_TO_PAPER:
386 label = strdup(_("IDS_BT_OPT_FIT_TO_PAPER"));
389 label = strdup(IDS_BR_OPT_5X7);
392 label = strdup(IDS_BR_OPT_4X6);
395 label = strdup(IDS_BR_OPT_3_5X5);
397 case PTS_SIZE_WALLET:
398 label = strdup(IDS_BR_OPT_WALLET);
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);
406 snprintf(custom, 32, "%s (%.1lfx%.1lf)", _("IDS_COM_SK_CUSTOM"), ad->size_popup_info.custom_height, ad->size_popup_info.custom_width);
409 label = strdup(custom);
412 label = strdup("Unknown option");
421 static Evas_Object *__pts_size_icon_get(void *data, Evas_Object *obj, const char *part)
425 int index = (int)data;
426 PTS_DEBUG("Passed index : %d", index);
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);
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);
450 static void __pts_size_sel(void *data, Evas_Object *obj, void *event_info)
454 pts_appdata_t *ad = (pts_appdata_t *)data;
455 PTS_RET_IF(ad == NULL, "ad is NULL");
458 Elm_Object_Item *item = event_info;
461 elm_genlist_item_selected_set(item, EINA_FALSE);
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);
467 ad->size_popup_info.image_size = size;
469 // Now call real event trigger to update radio button when selected.
470 elm_genlist_item_update(item);
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());
483 PTS_DEBUG("Unknown size");
486 PTS_IF_DEL_OBJ(ad->size_popup_info.size_popup);
487 PTS_IF_DEL_OBJ(size_radio_main);
492 Evas_Object *pts_create_size_popup(Evas_Object *parent, pts_appdata_t *ad)
496 Evas_Object *genlist;
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"));
504 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
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);
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);
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);
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;
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");
534 Evas_Object *box = elm_box_add(popup);
535 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
537 elm_box_pack_end(box, genlist);
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;
544 orientation = elm_win_rotation_get(ad->win);
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);
550 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.size_popup_landscape_height);
553 elm_object_content_set(popup, box);
554 ad->size_popup_info.size_popup_box = box;
556 evas_object_show(genlist);
557 evas_object_show(popup);
559 ad->size_popup_info.size_popup = popup;
565 static void _pts_custom_ok_cb(void *data, Evas_Object *obj, void *event_info)
569 pts_appdata_t *ad = (pts_appdata_t *)data;
570 PTS_RET_IF(ad == NULL, "ad is NULL");
572 ad->size_popup_info.image_size = PTS_SIZE_CUSTOM;
573 load_image_editor_ug(ad);
576 PTS_IF_DEL_OBJ(ad->size_popup_info.custom_popup);
577 elm_theme_extension_del(NULL, RESDIR"/edje/genlist_custom.edj");
582 static void _pts_custom_cancel_cb(void *data, Evas_Object *obj, void *event_info)
586 pts_appdata_t *ad = (pts_appdata_t *)data;
587 PTS_RET_IF(ad == NULL, "ad is NULL");
589 PTS_IF_DEL_OBJ(ad->size_popup_info.custom_popup);
591 // FIXME - just back to original size
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
605 elm_theme_extension_del(NULL, RESDIR"/edje/genlist_custom.edj");
610 static char *__pts_custom_label_get(void *data, Evas_Object *obj, const char *part)
613 int index = (int)data;
616 if (strcmp(part, "elm.text") == 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"));
624 label = strdup("Unknown label");
632 static void _changed_cb(void *data, Evas_Object *obj, void *event_info)
635 char *input_str = NULL;
636 const char *entry_text = NULL;
637 int index = (int)data;
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();
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);
648 PTS_DEBUG("Unknown index : %d", index);
651 PTS_DEBUG("Typed custom value : width[%lf] x height[%lf]", ad->size_popup_info.custom_width, ad->size_popup_info.custom_height);
653 PTS_IF_FREE_MEM(input_str);
658 static void _focused_cb(void *data, Evas_Object *obj, void *event_info) // Focused callback will show X marked button and hide guidetext.
661 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
665 static void _unfocused_cb(void *data, Evas_Object *obj, void *event_info) // Unfocused callback will show guidetext and hide X marked button.
668 char temp_size[32] = {0,};
670 if (elm_entry_is_empty(obj)) {
671 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
675 pts_appdata_t *ad = pts_get_appdata();
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);
688 PTS_DEBUG("Unknown entry : %p", obj);
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.
697 elm_entry_entry_set(data, "");
701 static Evas_Object *__pts_singleline_editfield_add(Evas_Object *parent, int index) // For single lined editfield without top title.
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();
709 layout = elm_layout_add(parent);
710 elm_layout_theme_set(layout, "layout", "editfield", "default"); // Default editfield layout style without top title.
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);
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);
725 elm_object_part_content_set(layout, "elm.swallow.content", entry);
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;
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;
737 elm_object_part_text_set(layout, "elm.guidetext", "Custom Size");
740 elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, entry);
742 evas_object_show(entry);
748 static void _pts_custom_unit_cb(void *data, Evas_Object *obj, void *event_info)
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);
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"));
766 PTS_DEBUG("Unknown unit");
771 elm_object_text_set(obj, temp);
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);
780 PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
784 static void _pts_custom_unit_inch_cb(void *data, Evas_Object *obj, void *event_info)
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);
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;
796 PTS_DEBUG("Unknown unit");
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);
808 PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
812 static void _pts_custom_unit_cm_cb(void *data, Evas_Object *obj, void *event_info)
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);
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;
824 PTS_DEBUG("Unknown unit");
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);
836 PTS_DEBUG("Changed unit : %d", ad->size_popup_info.custom_unit);
840 static Evas_Object *__pts_custom_icon_get(void *data, Evas_Object *obj, const char *part)
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,};
849 PTS_DEBUG("index: %d, passed part: %s", index, part);
850 if (!strcmp(part, "elm.icon")) {
852 case 1: // width text field
853 case 3: // height text field
854 editfield = __pts_singleline_editfield_add(obj, index);
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);
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);
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);
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);
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);
887 PTS_DEBUG("Index: %d, Unknown part: %s", index, part);
894 static void __pts_custom_sel(void *data, Evas_Object *obj, void *event_info)
898 pts_appdata_t *ad = (pts_appdata_t *)data;
899 PTS_RET_IF(ad == NULL, "ad is NULL");
902 Elm_Object_Item *item = event_info;
905 elm_genlist_item_selected_set(item, EINA_FALSE);
907 index = (int)elm_object_item_data_get(item);
909 aspect_ratio = !aspect_ratio;
910 PTS_DEBUG("Preserve aspect ratio : %d", aspect_ratio);
912 elm_genlist_item_update(item);
914 PTS_DEBUG("Unknown index");
920 Evas_Object *pts_create_custom_popup(Evas_Object *parent, pts_appdata_t *ad)
924 Evas_Object *genlist;
927 Evas_Object *layout = NULL;
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"));
934 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
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);
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);
948 elm_theme_extension_add(NULL, RESDIR"/edje/genlist_custom.edj");
949 PTS_DEBUG("Added extension theme");
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);
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;
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;
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;
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;
980 Elm_Object_Item *item = NULL;
981 Elm_Genlist_Item_Class *temp_itc = NULL;
982 Evas_Smart_Cb temp_cb = NULL;
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;
997 item = elm_genlist_item_append(genlist, temp_itc, (void *)index, NULL, ELM_GENLIST_ITEM_NONE, temp_cb, ad);
999 elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_NONE);
1001 PTS_DEBUG("index[%d] - item added : %s", index, (NULL == item)? "FAILURE" : "SUCCESS");
1004 Evas_Object *box = elm_box_add(popup);
1005 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1007 elm_box_pack_end(box, genlist);
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;
1013 orientation = elm_win_rotation_get(ad->win);
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);
1019 evas_object_size_hint_min_set(box, 400 * elm_config_scale_get(), ad->size_popup_info.custom_popup_landscape_height);
1022 elm_object_content_set(popup, box);
1023 ad->size_popup_info.custom_popup_box = box;
1025 evas_object_show(genlist);
1026 evas_object_show(popup);
1028 ad->size_popup_info.custom_popup = popup;
1034 static Evas_Object *__pts_utils_create_conformant(Evas_Object *parent)
1037 Evas_Object *conform = NULL;
1038 elm_win_conformant_set(parent, TRUE);
1039 conform = elm_conformant_add(parent);
1041 elm_object_style_set(conform, "internal_layout");
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);
1046 evas_object_show(conform);
1051 Evas_Object *pts_utils_create_layout(Evas_Object *navi_frame)
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);
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);
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);
1073 * this function is used to compose folder and filename.
1075 char **__compose_image_files_path(char *folder, const char **filesname, const int num_of_files)
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);
1082 char **paths = NULL;
1083 paths = (char **)malloc(sizeof(char *)*num_of_files);
1084 PTS_RETV_IF(paths == NULL , NULL, "malloc failed!");
1088 char filepath[512] = {0};
1090 for (; count < num_of_files ; count++) {
1091 snprintf(filepath, 512, "%s/%s", folder, filesname[count]);
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]);
1099 PTS_IF_FREE_MEM(paths);
1102 PTS_DEBUG("files[%d]: %s", count, paths[count]);
1110 * validate the path of image files.
1112 bool __validate_file_type(char **files, int num)
1116 PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
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"
1126 for (; i < num; i++) {
1127 path = *(files + i);
1129 /* check whether the file is exist */
1133 ret = stat(path, &buf);
1134 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1136 /* check whether the file can be supported */
1138 p = strrchr(path, '.');
1139 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1144 for (; j < filters_num; j++) {
1145 if (0 == strcasecmp(p, filters[j])) {
1150 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1158 * validate the path of image files.
1160 bool _is_pdf_file_type(char **files, int num)
1164 PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
1168 const int filters_num = 1;
1169 /* the image type that cups supports */
1170 const char *filters[] = {".pdf"};
1172 for (; i < num; i++) {
1173 path = *(files + i);
1175 /* check whether the file is exist */
1179 ret = stat(path, &buf);
1180 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1182 /* check whether the file can be supported */
1184 p = strrchr(path, '.');
1185 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1190 for (; j < filters_num; j++) {
1191 if (0 == strcasecmp(p, filters[j])) {
1196 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1204 * validate the path of image files.
1206 bool _is_img_file_type(char **files, int num)
1210 PTS_RETV_IF(files == NULL || num <= 0, false, "the input param is invalid!");
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"};
1219 for (; i < num; i++) {
1220 path = *(files + i);
1222 /* check whether the file is exist */
1226 ret = stat(path, &buf);
1227 PTS_RETV_IF(ret != 0, false, "get file(%s) status failed!", path);
1229 /* check whether the file can be supported */
1231 p = strrchr(path, '.');
1232 PTS_RETV_IF(p == NULL, false, "get file(%s) filter failed!", path);
1237 for (; j < filters_num; j++) {
1238 if (0 == strcasecmp(p, filters[j])) {
1243 PTS_RETV_IF(tag == 0, false, "the file(%s) can't be supported!", path);
1250 inline char *_pts_printing_data_get_directory(pts_printing_data_t *data)
1252 return data->directory;
1255 inline char **_pts_printing_data_get_request_files(pts_printing_data_t *data)
1257 return data->request_files;
1259 inline int _pts_printing_data_get_files_count(pts_printing_data_t *data)
1261 return data->num_of_files;
1264 inline int _pts_printing_data_get_index(pts_printing_data_t *data)
1266 return data->current_index;
1269 inline char *_pts_printing_data_get_type(pts_printing_data_t *data)
1274 Eina_Bool _pts_printing_data_set_directory(const char *directory, pts_printing_data_t *data)
1276 PTS_RETV_IF(directory == NULL, EINA_FALSE, "directory is NULL");
1277 PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1279 data->directory = strdup(directory);
1281 PTS_RETV_IF(data->directory == NULL, EINA_FALSE, "Failed to strdup");
1285 Eina_Bool _pts_printing_data_set_request_files(const char **request_files, const int files_count, pts_printing_data_t *data)
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");
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");
1295 char **composite_files = NULL;
1298 temp = _pts_printing_data_get_directory(data);
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;
1304 data->request_files = (char **)calloc(count, sizeof(char *));
1305 PTS_RETV_IF(data->request_files == NULL, EINA_FALSE, "Failed to calloc");
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;
1316 ret = __validate_file_type(data->request_files, files_count);
1317 PTS_RETV_IF(ret != true, EINA_FALSE, "files is invalid");
1323 Eina_Bool _pts_printing_data_set_files_count(const char *num_of_files, pts_printing_data_t *data)
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");
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;
1335 Eina_Bool _pts_printing_data_set_index(const char *current_index, pts_printing_data_t *data)
1337 PTS_RETV_IF(current_index == NULL, EINA_FALSE,"current_index is NULL");
1338 PTS_RETV_IF(data == NULL, EINA_FALSE, "data is NULL");
1341 index = atoi(current_index);
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);
1348 data->current_index = index;
1353 Eina_Bool _is_document_ux_type(const char *type)
1355 PTS_RETV_IF(type == NULL, EINA_FALSE, "type is NULL");
1356 if (strcasecmp(type, "DOC") == 0) {
1362 Eina_Bool _is_image_ux_type(const char *type)
1364 PTS_RETV_IF(type == NULL, EINA_FALSE, "type is NULL");
1365 if (strcasecmp(type, "IMG") == 0) {
1371 Eina_Bool _is_valid_print_file_type(const char *type)
1373 if (strcasecmp(type, "IMG") && strcasecmp(type,"DOC") && strcasecmp(type,"WEB")) {
1374 PTS_DEBUG("the type of print files(%s) is invalid!", type);
1381 Eina_Bool _pts_printing_data_set_type(const char *type, pts_printing_data_t *data)
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");
1387 data->type = strdup(type);
1388 PTS_RETV_IF(data->type == NULL, EINA_FALSE, "Failed to strdup");