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.
17 #include <Elementary.h>
18 #include <ui-gadget.h>
19 #include <ui-gadget-module.h> // ug_destroy_me, ug_send_result
21 #include "ivug-crop-view.h"
22 #include "ivug-crop-ug.h"
24 #include "ivug-debug.h"
25 #include "ivug-string.h"
26 #include "ivug-context.h"
29 #include "ivug-setas-view.h"
32 #define LOG_LVL DBG_MSG_LVL_MED
35 #define LOG_CAT "IV-CROP-UG"
38 _send_result(ui_gadget_h ug, const char *key1, const char *val1, const char *key2, const char *val2)
43 service_create(&service);
47 MSG_HIGH("Bundle 1 : [%s = %s]", key1, val1);
48 service_add_extra_data(service, key1, val1);
52 MSG_HIGH("Bundle 2 : [%s = %s]", key2, val2);
53 service_add_extra_data(service, key2, val2);
55 ug_send_result(gGetUGHandle(), service);
57 service_destroy(service);
60 static void _ivug_crop_view_ok_clicked_cb(void *data, Evas_Object *obj, void *event_info)
62 char *path = (char *)event_info;
64 evas_object_smart_callback_del(obj, "ok,clicked", _ivug_crop_view_ok_clicked_cb);
66 media_handle m_handle = NULL;
68 m_handle = ivug_db_insert_file_to_DB(path);
71 MSG_ERROR("ivug_db_insert_file_to_DB failed %s", path);
75 ivug_db_destroy_file_handle(m_handle);
78 _send_result(gGetUGHandle(), "crop_image_path", path, NULL, NULL);
80 MSG_HIGH("Start destroy ug");
81 ug_destroy_me(gGetUGHandle());
84 static void _ivug_setas_crop_view_ok_clicked_cb(void *data, Evas_Object *obj, void *event_info)
86 char *path = (char *)event_info;
88 MSG_MAIN_HIGH("_ivug_setas_view_ok_clicked_cb path = %s", path);
90 evas_object_smart_callback_del(obj, "ok,clicked", _ivug_setas_crop_view_ok_clicked_cb);
92 // do not insert to db
94 int setas_data = (int)evas_object_data_get(obj, "setas_type");
95 ivug_set_screen_type type = (ivug_set_screen_type)setas_data;
97 int setas_mode = (int)evas_object_data_get(obj, "setas_mode");
98 ivug_setas_mode mode = (ivug_setas_mode)setas_mode;
100 const char* homescreen_path = IVUG_HOME_SCREEN_PATH;
101 const char* lockscreen_path = IVUG_LOCK_SCREEN_PATH;
102 const char* appsvc_home_path = IVUG_APPSVC_HOME_SCREEN_PATH;
104 if(mode == IVUG_SETAS_CROP)
106 ivug_copy_file(path, appsvc_home_path);
107 _send_result(gGetUGHandle(), "crop_image_path", appsvc_home_path, NULL, NULL);
111 if(type == IVUG_CTRLBAR_SET_SCREEN_HOME)
113 ivug_copy_file(path, homescreen_path);
114 ivug_config_set_homescreen_image(homescreen_path);
115 _send_result(gGetUGHandle(), "homescreen_path", homescreen_path, NULL, NULL);
117 else if(type == IVUG_CTRLBAR_SET_SCREEN_LOCK)
119 ivug_copy_file(path, lockscreen_path);
120 ivug_config_set_lockscreen_image(lockscreen_path);
121 _send_result(gGetUGHandle(), "lockscreen_path", lockscreen_path, NULL, NULL);
123 else if(type == IVUG_CTRLBAR_SET_SCREEN_BOTH)
125 ivug_copy_file(path, homescreen_path);
126 ivug_config_set_homescreen_image(homescreen_path);
127 ivug_copy_file(path, lockscreen_path);
128 ivug_config_set_lockscreen_image(lockscreen_path);
129 _send_result(gGetUGHandle(), "homescreen_path", homescreen_path, "lockscreen_path", lockscreen_path);
133 MSG_HIGH("Start destroy ug");
134 ug_destroy_me(gGetUGHandle());
138 static void _ivug_crop_view_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
140 //ivug_crop_ug_destroy((IvugCropUG *)data);
142 evas_object_smart_callback_del(obj, "cancel,clicked", _ivug_crop_view_cancel_clicked_cb);
144 _send_result(gGetUGHandle(), "crop_image_path", NULL, NULL, NULL);
146 MSG_HIGH("Start destroy ug");
147 ug_destroy_me(gGetUGHandle());
150 static void _ivug_crop_view_destroyed_cb(void *data, Evas_Object *obj, void *event_info)
152 IvugCropUG *crop_ug = (IvugCropUG *)data;
154 ivug_crop_view_destroy(crop_ug->crop_view);
156 crop_ug->crop_view = NULL;
159 static void on_crop_view_btn_back_clicked(void *data, Evas_Object *obj, void *event_info)
161 IvugCropUG *crop_ug = (IvugCropUG *)data;
163 ivug_crop_view_destroy(crop_ug->crop_view);
165 crop_ug->crop_view = NULL;
167 _send_result(gGetUGHandle(), "crop_image_path", NULL, NULL, NULL);
169 MSG_HIGH("Start destroy ug");
170 ug_destroy_me(gGetUGHandle());
173 static void _ivug_crop_view_clicked_cb(void *data, Evas_Object *obj, void *event_info)
175 IvugCropUG *crop_ug = (IvugCropUG *)data;
176 bool bShowMenu = (bool)event_info;
180 elm_object_item_signal_emit(crop_ug->navi_it, "elm,state,toolbar,open", "");
184 elm_object_item_signal_emit(crop_ug->navi_it, "elm,state,toolbar,close", "");
189 _show_exit_popup( Evas_Object *parent, const char *title, const char *desc, void *data)
191 MSG_SETAS_HIGH( "title: %s, desc %s", title, desc);
193 Evas_Object* style1_popup = elm_popup_add(parent);
194 evas_object_size_hint_weight_set(style1_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195 elm_popup_timeout_set(style1_popup, (double)2.0);
196 elm_object_text_set(style1_popup, desc);
197 elm_object_part_text_set(style1_popup, "title,text", title);
199 evas_object_smart_callback_add(style1_popup, "timeout", _ivug_crop_view_cancel_clicked_cb, data);
201 evas_object_show(style1_popup);
202 evas_object_layer_set(style1_popup, EVAS_LAYER_MAX);
208 _on_msg_load_failed(void *data, Evas_Object *obj, void *event_info)
210 int error = (int)event_info;
212 const char *szMsg = NULL;
216 case CROP_ERROR_TYPE_INVALID_FILE:
217 szMsg = IDS_INVALID_IMAGE_FILE;
219 case CROP_ERROR_TYPE_PERMISSION_DENIED:
220 szMsg = IDS_PERMISSION_DENIED;
222 case CROP_ERROR_TYPE_UNKNOWN_FORMAT:
223 szMsg = "Unknown format";
225 case CROP_ERROR_TYPE_GENERAL:
231 MSG_ERROR("Load failed : %s", szMsg);
233 _show_exit_popup(obj, IDS_ERROR, szMsg, data);
236 IvugCropUG * ivug_crop_ug_create(Evas_Object *parent, int w, int h, bool bRatioFix, const char *filepath)
238 IvugCropUG *crop_ug = (IvugCropUG *)calloc(1, sizeof(IvugCropUG));
241 MSG_ERROR("crop_ug calloc error");
245 IvugCropView *crop_view = NULL;
246 Evas_Object *layout = NULL;
248 crop_view = ivug_crop_view_create(parent);
249 if(crop_view == NULL)
251 MSG_ERROR("ivug_crop_view_create error");
256 ivug_crop_view_box_size_set(crop_view, w, h);
257 //ivug_crop_view_file_set(crop_view, filepath);
258 ivug_crop_view_box_ratio_fix(crop_view, bRatioFix);
260 layout = ivug_crop_view_get_object(crop_view);
262 evas_object_smart_callback_add(layout, "ok,clicked", _ivug_crop_view_ok_clicked_cb, crop_ug);
263 evas_object_smart_callback_add(layout, "cancel,clicked", _ivug_crop_view_cancel_clicked_cb, crop_ug);
264 evas_object_smart_callback_add(layout, "destroyed", _ivug_crop_view_destroyed_cb, crop_ug);
265 evas_object_smart_callback_add(layout, "download,failed", _on_msg_load_failed, crop_ug);
266 //evas_object_smart_callback_add(layout, "clicked", _ivug_crop_view_clicked_cb, crop_ug);
268 crop_ug->crop_view = crop_view;
269 crop_ug->layout = layout;
270 crop_ug->parent = parent;
271 crop_ug->filepath = strdup(filepath);
273 crop_ug->navi_bar = elm_naviframe_add(parent);
275 #ifdef USE_CUSTOM_STYLE
276 elm_object_theme_set(crop_ug->navi_bar, gGetSystemTheme() );
278 const char *profile = elm_config_profile_get();
279 if (!strcmp(profile,"mobile"))
281 elm_object_style_set(crop_ug->navi_bar, "ivug-main/default");
283 else if (!strcmp(profile,"desktop"))
285 elm_object_style_set(crop_ug->navi_bar, "ivug-main/noindicator");
289 MSG_MAIN_ERROR("Unknown profile : %s", profile);
292 evas_object_name_set(crop_ug->navi_bar, "Crop ug naviframe");
294 // Layout life cycle is controlled by application explictily.
295 elm_naviframe_content_preserve_on_pop_set(crop_ug->navi_bar, EINA_TRUE);
297 Evas_Object *back_btn = ivug_button_add(crop_ug->navi_bar, "naviframe/end_btn/default",
298 IDS_BACK, NULL, on_crop_view_btn_back_clicked, crop_ug);
300 crop_ug->navi_it = elm_naviframe_item_push(crop_ug->navi_bar, IDS_LOADING, back_btn, NULL, crop_ug->layout, NULL);
301 elm_naviframe_item_title_visible_set(crop_ug->navi_it, EINA_FALSE);
303 ivug_crop_view_create_menu(crop_view, crop_ug->navi_bar);
305 Evas_Object *conformant = (Evas_Object *)ug_get_conformant();
306 elm_object_signal_emit(conformant, "elm,state,indicator,nooverlap", "");
311 IvugCropUG * ivug_setas_crop_ug_create(Evas_Object *parent, const char *filepath, ivug_setas_mode mode, ivug_set_screen_type type)
313 IvugCropUG *crop_ug = (IvugCropUG *)calloc(1, sizeof(IvugCropUG));
316 MSG_ERROR("crop_ug calloc error");
320 IvugCropView *crop_view = NULL;
321 Evas_Object *layout = NULL;
323 crop_view = ivug_crop_view_create(parent);
324 if(crop_view == NULL)
326 MSG_ERROR("ivug_crop_view_create error");
331 layout = ivug_crop_view_get_object(crop_view);
333 evas_object_smart_callback_add(layout, "ok,clicked", _ivug_setas_crop_view_ok_clicked_cb, crop_ug);
334 evas_object_smart_callback_add(layout, "cancel,clicked", _ivug_crop_view_cancel_clicked_cb, crop_ug);
335 evas_object_smart_callback_add(layout, "destroyed", _ivug_crop_view_destroyed_cb, crop_ug);
336 evas_object_smart_callback_add(layout, "download,failed", _on_msg_load_failed, crop_ug);
337 //evas_object_smart_callback_add(layout, "clicked", _ivug_crop_view_clicked_cb, crop_ug);
339 evas_object_data_set(layout, "setas_type", (void *)type);
340 evas_object_data_set(layout, "setas_mode", (void *)mode);
342 crop_ug->crop_view = crop_view;
343 crop_ug->layout = layout;
344 crop_ug->parent = parent;
345 crop_ug->filepath = strdup(filepath);
347 crop_ug->navi_bar = elm_naviframe_add(parent);
349 #ifdef USE_CUSTOM_STYLE
350 elm_object_theme_set(crop_ug->navi_bar, gGetSystemTheme() );
352 const char *profile = elm_config_profile_get();
353 if (!strcmp(profile,"mobile"))
355 elm_object_style_set(crop_ug->navi_bar, "ivug-main/default");
357 else if (!strcmp(profile,"desktop"))
359 elm_object_style_set(crop_ug->navi_bar, "ivug-main/noindicator");
363 MSG_MAIN_ERROR("Unknown profile : %s", profile);
366 evas_object_name_set(crop_ug->navi_bar, "Crop ug naviframe");
368 // Layout life cycle is controlled by application explictily.
369 elm_naviframe_content_preserve_on_pop_set(crop_ug->navi_bar, EINA_TRUE);
371 Evas_Object *back_btn = ivug_button_add(crop_ug->navi_bar, "naviframe/end_btn/default",
372 IDS_BACK, NULL, on_crop_view_btn_back_clicked, crop_ug);
374 crop_ug->navi_it = elm_naviframe_item_push(crop_ug->navi_bar, IDS_LOADING, back_btn, NULL, crop_ug->layout, NULL);
375 elm_naviframe_item_title_visible_set(crop_ug->navi_it, EINA_FALSE);
377 Evas_Object *conformant = (Evas_Object *)ug_get_conformant();
378 elm_object_signal_emit(conformant, "elm,state,indicator,nooverlap", "");
386 ivug_crop_view_create_menu(crop_view, crop_ug->navi_bar);
388 ivug_crop_view_destination_set(crop_view, DATA_PATH, ".iv_setas.jpg");
390 evas_object_geometry_get((Evas_Object *)ug_get_window(), &lcd_x, &lcd_y, &lcd_w, &lcd_h);
391 rot = gGetRotationDegree();
392 if(rot == 90 || rot == 270)
399 ivug_crop_view_box_size_set(crop_view, lcd_w, lcd_h);
401 ivug_crop_view_box_ratio_fix(crop_view, true);
406 Evas_Object * ivug_crop_ug_get_layout(IvugCropUG * crop_ug)
408 IV_ASSERT(crop_ug != NULL);
410 return crop_ug->navi_bar;
413 bool ivug_crop_ug_destroy(IvugCropUG * crop_ug)
415 IV_ASSERT(crop_ug != NULL);
417 if(crop_ug->filepath)
419 free(crop_ug->filepath);
420 crop_ug->filepath = NULL;
423 if(crop_ug->crop_view)
425 ivug_crop_view_destroy(crop_ug->crop_view);
426 crop_ug->crop_view = NULL;
428 crop_ug->layout = NULL;
435 bool ivug_crop_ug_start(IvugCropUG * crop_ug)
437 MSG_HIGH("ivug_crop_ug_start");
438 IV_ASSERT(crop_ug != NULL);
440 ivug_crop_view_file_set(crop_ug->crop_view, crop_ug->filepath);