Initialize Tizen 2.3
[apps/home/mobileprint.git] / mobileprint / app / image_editor_conn.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 <ui-gadget.h>
21 #include "pts_common.h"
22 #include "pts_main_view.h"
23 #include "image_editor_conn.h"
24
25 #define IMAGE_EDITOR_STR_MAX_LEN        64
26
27 extern int size_index;
28
29 void image_editor_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
30 {
31         PTS_TRACE_BEGIN;
32         Evas_Object *base;
33         Evas_Object *win;
34
35         base = (Evas_Object *) ug_get_layout(ug);
36         win = ug_get_window();
37         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
38         elm_win_resize_object_add(win, base);
39
40         /* Disable effect to avoid BS caused by ui-gadget to
41              unset ug layout after deleting it */
42         ug_disable_effect(ug);
43         evas_object_show(base);
44
45         PTS_TRACE_END;
46 }
47
48 void image_editor_result_cb(ui_gadget_h ug, service_h result, void *priv)
49 {
50         PTS_TRACE_BEGIN;
51         pts_appdata_t *ad = (pts_appdata_t *)priv;
52         PTS_RET_IF(ad == NULL, "ad is NULL");
53
54         char *path = NULL;
55         int ret = -1;
56         ret = service_get_extra_data(result, "crop_image_path", &path);
57         PTS_RET_IF(ret != SERVICE_ERROR_NONE, "Failed to get crop_image_path(%d)", ret);
58         PTS_RET_IF(path == NULL, "path is NULL");
59
60         /* save path */
61         PTS_IF_FREE_MEM(ad->printing_data.request_files[0]);
62         ad->printing_data.request_files[0] = strdup(path);
63         PTS_DEBUG("crop_image_path: %s", path);
64         pts_main_view_rotate_image(ad, app_get_device_orientation());
65         size_index = ad->size_popup_info.image_size; // When crop is done, then save the index.
66
67         PTS_TRACE_END;
68 }
69
70
71 void image_editor_destroy_cb(ui_gadget_h ug, void *priv)
72 {
73         PTS_TRACE_BEGIN;
74         pts_appdata_t *ad = (pts_appdata_t *)priv;
75         PTS_RET_IF(ad == NULL || ug == NULL, "Invalid argument");
76         ug_destroy(ug);
77         PTS_TRACE_END;
78 }
79
80
81 int load_image_editor_ug(pts_appdata_t *ad)
82 {
83         PTS_TRACE_BEGIN;
84         PTS_RETV_IF(ad == NULL, -1, "ad is NULL");
85
86         struct ug_cbs image_editor_cbs;
87         ui_gadget_h ug = NULL;
88         service_h service = NULL;
89         char reso_str[IMAGE_EDITOR_STR_MAX_LEN + 1];
90         int w = 300;
91         int h = 300;
92
93         switch (ad->size_popup_info.image_size) {
94         case PTS_SIZE_FIT_TO_PAPER:
95                 break;
96         case PTS_SIZE_5X7:
97                 w = w * 1.2;
98                 break;
99         case PTS_SIZE_4X6:
100                 w = w * 1.5;
101                 break;
102         case PTS_SIZE_3_5X5:
103                 w = w * 1.43;
104                 break;
105         case PTS_SIZE_WALLET:
106                 w = w * 1.31;
107                 break;
108         case PTS_SIZE_CUSTOM:
109                 w = w * (ad->size_popup_info.custom_width / ad->size_popup_info.custom_height);
110                 PTS_DEBUG("Passed custom ratio : %dx%d", w, h);
111                 break;
112         default:
113                 break;
114         }
115
116         memset(&image_editor_cbs,0x00,sizeof(struct ug_cbs));
117         image_editor_cbs.layout_cb = image_editor_layout_cb;
118         image_editor_cbs.result_cb = image_editor_result_cb;
119         image_editor_cbs.destroy_cb = image_editor_destroy_cb;
120         image_editor_cbs.priv = ad;
121
122         service_create(&service);
123         service_add_extra_data(service, "View Mode", "SETAS");
124         service_add_extra_data(service, "Path", ad->printing_data.input_file);
125         service_add_extra_data(service, "Setas type", "Crop");
126         service_add_extra_data(service, "Fixed ratio", "TRUE");
127
128         snprintf(reso_str, IMAGE_EDITOR_STR_MAX_LEN, "%dx%d", w, h);
129         service_add_extra_data(service, "Resolution", reso_str);
130         PTS_DEBUG("Passed resolution : %s", reso_str);
131
132         ug_create(ug, "image-viewer-efl", UG_MODE_FULLVIEW, service, &image_editor_cbs);
133         service_destroy(service);
134
135         PTS_TRACE_END;
136         return 0;
137 }
138