2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "ge-ext-ug-load.h"
20 #include "ge-ui-util.h"
22 #include "ge-albums.h"
23 #include "ge-gridview.h"
25 #define GE_IV_UG_NAME "image-viewer-efl"
26 #define GE_IV_STR_LEN_MAX 32
28 static bool ge_destroy_me = false;
30 static void _ge_ext_destroy_me(ge_ugdata *ugd)
34 GE_CHECK(ugd->ug_called_by_me);
36 GE_CHECK(ugd->service);
37 bool send_result = false;
44 if(ge_destroy_me == false)
46 ge_dbg("Destroy ug_called_by_me");
47 ug_destroy(ugd->ug_called_by_me);
48 ugd->ug_called_by_me = NULL;
50 if(ugd->file_select_mode == GE_File_Select_Setas)
52 if(ugd->file_setas_image_path)
54 ge_dbg("GE_SETAS_IMAGE_PATH:%s", ugd->file_setas_image_path);
55 service_add_extra_data(ugd->service,
57 ugd->file_setas_image_path);
59 free(ugd->file_setas_image_path);
60 ugd->file_setas_image_path = NULL;
64 if(ugd->file_setas_crop_image_path &&
65 (ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID ||
66 ugd->file_select_setas_mode == GE_FILE_SELECT_SETAS_MODE_CROP_WALLPAPER)) {
67 ge_dbg("GE_SETAS_CALLERID_CROP_IMAGE_PATH:%s",
68 ugd->file_setas_crop_image_path);
69 service_add_extra_data(ugd->service,
70 GE_SETAS_CALLERID_CROP_IMAGE_PATH,
71 ugd->file_setas_crop_image_path);
73 free(ugd->file_setas_crop_image_path);
74 ugd->file_setas_crop_image_path = NULL;
80 ge_dbg("Call ug_send_result() to send result.");
81 ug_send_result(ugd->ug, ugd->service);
87 ge_dbg("Setting is appllied, destroy gallery UG.");
88 ge_destroy_me = false;
90 ug_destroy_me(ugd->ug);
91 /* ug_called_by_me would be destroyed by ui-gadget */
92 ugd->ug_called_by_me = NULL;
96 ge_dbg("Cancel button tapped, back to thumbnails view.");
100 static void _ge_ext_iv_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
106 Evas_Object *base = (Evas_Object *) ug_get_layout(ug);
108 ge_dbgE("ug_get_layout failed!");
113 ge_ugdata *ugd = (ge_ugdata *)priv;
115 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116 elm_win_resize_object_add(ugd->win, base);
117 /* Disable effect to avoid BS caused by ui-gadget to
118 unset ug layout after deleting it */
119 ug_disable_effect(ug);
120 evas_object_show(base);
123 static void _ge_ext_iv_result_cb(ui_gadget_h ug, service_h result, void *priv)
128 ge_ugdata *ugd = (ge_ugdata *)priv;
131 if(ugd->file_select_mode == GE_File_Select_Setas)
133 service_get_extra_data(result, GE_IMAGEVIEWER_IMAGE_PATH, &path);
134 ge_dbg("SETAS_IMAGE_PATH");
135 ge_destroy_me = true;
139 ugd->file_setas_image_path = path;
143 if(ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID ||
144 ugd->file_select_setas_mode == GE_FILE_SELECT_SETAS_MODE_CROP_WALLPAPER) {
145 service_get_extra_data(result,
146 GE_IMAGEVIEWER_CROP_IMAGE_PATH,
148 ge_dbg("CALLERID_CROP_IMAGE_PATH");
152 ugd->file_setas_crop_image_path = path;
157 char *error_state = NULL;
158 service_get_extra_data(result, GE_IMAGEVIEWER_RETURN_ERROR,
162 ge_dbg("error string : %s", error_state);
164 if (!g_strcmp0(error_state, "not_supported_file_type")) {
165 ge_destroy_me = FALSE;
166 ge_item* cur_item = _ge_get_current_item();
167 if(cur_item == NULL || cur_item->item == NULL ||
168 cur_item->item->file_url == NULL) {
169 ge_dbgE("current item is NULL");
170 GE_FREE_MEM(error_state);
174 service_create(&service);
176 service_set_operation(service, SERVICE_OPERATION_VIEW);
177 service_set_uri(service, cur_item->item->file_url);
178 service_send_launch_request(service, NULL, NULL);
179 service_destroy(service);
181 GE_FREE_MEM(error_state);
185 static void _ge_ext_iv_destroy_cb(ui_gadget_h ug, void *priv)
189 ge_ugdata *ad = (ge_ugdata *) priv;
191 _ge_ext_destroy_me(ad);
194 int ge_ext_load_iv_ug(ge_ugdata* ugd)
197 GE_CHECK_VAL(ugd, -1);
200 ui_gadget_h ug = NULL;
201 service_h service = NULL;
203 if(ugd->ug_called_by_me)
205 ge_dbg("Already exits some UG called by me");
209 ge_item* cur_item = _ge_get_current_item();
210 if(cur_item == NULL || cur_item->item == NULL)
212 ge_dbg("current item is NULL");
215 memset(&cbs,0x00,sizeof(struct ug_cbs));
216 cbs.layout_cb = _ge_ext_iv_layout_cb;
217 cbs.result_cb = _ge_ext_iv_result_cb;
218 cbs.destroy_cb = _ge_ext_iv_destroy_cb;
221 service_create(&service);
222 GE_CHECK_VAL(service, -1);
226 service_add_extra_data(service, "View Mode", "SETAS" );
227 service_add_extra_data(service, "Path", cur_item->item->file_url);
229 if(ugd->file_select_setas_mode == GE_File_Select_Setas_Wallpaper) {
230 service_add_extra_data(service, "Setas type", "Wallpaper");
232 if(ugd->file_setas_homescreen_path)
234 ge_dbg("homescreen_path:%s", ugd->file_setas_homescreen_path);
235 service_add_extra_data(service, GE_IMAGEVIEWER_HOMESCREEN_PATH, ugd->file_setas_homescreen_path);
236 free(ugd->file_setas_homescreen_path);
237 ugd->file_setas_homescreen_path = NULL;
240 if(ugd->file_setas_lockscreen_path)
242 ge_dbg("lockscreen_path:%s", ugd->file_setas_lockscreen_path);
243 service_add_extra_data(service, GE_IMAGEVIEWER_LOCKSCREEN_PATH, ugd->file_setas_lockscreen_path);
244 free(ugd->file_setas_lockscreen_path);
245 ugd->file_setas_lockscreen_path = NULL;
247 } else if(ugd->file_select_setas_mode == GE_FILE_SELECT_SETAS_MODE_CROP_WALLPAPER) {
248 service_add_extra_data(service, "Setas type", "Crop");
249 service_add_extra_data(service, "Fixed ratio", "TRUE");
253 ecore_x_window_size_get(ecore_x_window_root_first_get(),
255 char *reso_str = (char *)calloc(1, GE_IV_STR_LEN_MAX);
256 GE_CHECK_VAL(reso_str, -1);
257 snprintf(reso_str, GE_IV_STR_LEN_MAX, "%dx%d", w, h);
258 ge_dbgW("Window Resolution: %dx%d, %s", w, h, reso_str);
259 service_add_extra_data(service, "Resolution", reso_str);
262 } else if(ugd->file_select_setas_mode == GE_File_Select_Setas_CallerID) {
263 service_add_extra_data(service, "Setas type", "CallerID");
264 if(ugd->file_setas_callid_size)
266 ge_dbg("callerid_size:%s", ugd->file_setas_callid_size);
267 service_add_extra_data(service, GE_IMAGEVIEWER_CALLERID_SIZE, ugd->file_setas_callid_size);
268 free(ugd->file_setas_callid_size);
269 ugd->file_setas_callid_size = NULL;
272 if(ugd->file_setas_callid_path)
274 ge_dbg("callerid_path:%s", ugd->file_setas_callid_path);
275 service_add_extra_data(service, GE_IMAGEVIEWER_CALLERID_PATH, ugd->file_setas_callid_path);
276 free(ugd->file_setas_callid_path);
277 ugd->file_setas_callid_path = NULL;
280 ug = ug_create(ugd->ug, GE_IV_UG_NAME, UG_MODE_FULLVIEW, service, &cbs);
281 ugd->ug_called_by_me = ug;
282 service_destroy(service);