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 <setting-display-wallpaper.h>
20 static int setting_display_wallpaper_create(void *cb);
21 static int setting_display_wallpaper_destroy(void *cb);
22 static int setting_display_wallpaper_update(void *cb);
23 static int setting_display_wallpaper_cleanup(void *cb);
25 setting_view setting_view_display_wallpaper = {
26 .create = setting_display_wallpaper_create,
27 .destroy = setting_display_wallpaper_destroy,
28 .update = setting_display_wallpaper_update,
29 .cleanup = setting_display_wallpaper_cleanup,
32 //#define MAX_IMAGE_H_SIZE (600.0)
33 //#define MAX_IMAGE_W_SIZE (336.0)
35 /* ***************************************************
39 ***************************************************/
41 static void __destroy_gallery_ug_cb(struct ui_gadget *ug, void *priv)
45 /* restore the '<-' button on the navigate bar */
47 SettingDisplayUG *ad = (SettingDisplayUG *) priv; /* ad is point to priv */
51 ad->ug_loading = NULL;
54 Elm_Object_Item *navi_it = elm_naviframe_top_item_get(ad->navi_bar);
56 Evas_Object *back_btn = elm_object_item_part_content_get(navi_it, "prev_btn");
58 if (back_btn != NULL) {
59 elm_object_style_set(back_btn, NAVI_BACK_BUTTON_STYLE); /* take into effect */
63 static void setting_display_wallpaper_string_vconf_change_cb(keynode_t *key,
66 SettingDisplayUG *ad = data;
68 return; /* do nothing if ad is NULL */
69 char *value = vconf_keynode_get_str(key);
70 char *vconf_name = vconf_keynode_get_name(key);
74 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
76 double max_image_w_size = w/2 - w*0.03;
77 double max_image_h_size = h*0.46875;
79 if (!safeStrCmp(vconf_name, VCONFKEY_BGSET)) {
80 evas_object_image_file_set(ad->img_homescreen, NULL, NULL); /* give a littile time for gallery to copy the tmp file */
81 Evas_Object *temp_img = evas_object_image_add(ad->evas);
84 double ratio_w, ratio_h, ratio;
86 /* A:VCONFKEY_BGSET */
87 evas_object_image_file_set(temp_img, value, NULL);
88 evas_object_image_size_get(temp_img, &temp_w, &temp_h);
89 SETTING_TRACE("temp_w:%d, temp_h:%d", temp_w, temp_h);
90 ratio_w = temp_w / max_image_w_size;
91 ratio_h = temp_h / max_image_h_size;
92 ratio = (ratio_w > ratio_h ? ratio_w : ratio_h);
93 SETTING_TRACE("ratio_w:%f, ratio_h:%f, ratio:%f", ratio_w,
96 evas_object_image_file_set(ad->img_homescreen, value, NULL);
97 evas_object_image_fill_set(ad->img_homescreen, 0, 0,
98 temp_w / ratio, temp_h / ratio);
99 evas_object_size_hint_min_set(ad->img_homescreen,
100 temp_w / ratio, temp_h / ratio);
101 evas_object_del(temp_img);
103 } else if (!safeStrCmp(vconf_name, VCONFKEY_IDLE_LOCK_BGSET)) {
104 /* SETTING_TRACE("vconf_name is %s.\tvalue is %s", vconf_name, value); */
105 evas_object_image_file_set(ad->img_lockscreen, NULL, NULL); /* give a littile time for gallery to copy the tmp file */
106 Evas_Object *temp_img = evas_object_image_add(ad->evas);
109 double ratio_w, ratio_h, ratio;
110 /* A:VCONFKEY_BGSET */
111 evas_object_image_file_set(temp_img, value, NULL);
112 evas_object_image_size_get(temp_img, &temp_w, &temp_h);
113 SETTING_TRACE("temp_w:%d, temp_h:%d", temp_w, temp_h);
114 ratio_w = temp_w / max_image_w_size;
115 ratio_h = temp_h / max_image_h_size;
116 ratio = (ratio_w > ratio_h ? ratio_w : ratio_h);
117 SETTING_TRACE("ratio_w:%f, ratio_h:%f, ratio:%f", ratio_w,
120 evas_object_image_file_set(ad->img_lockscreen, value, NULL);
121 evas_object_image_fill_set(ad->img_lockscreen, 0, 0,
122 temp_w / ratio, temp_h / ratio);
123 evas_object_size_hint_min_set(ad->img_lockscreen,
124 temp_w / ratio, temp_h / ratio);
125 evas_object_del(temp_img);
130 int setting_display_wallpaper_listen_vconf_change(void *data)
135 vconf_notify_key_changed(VCONFKEY_BGSET,
136 setting_display_wallpaper_string_vconf_change_cb,
138 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
139 (char *)VCONFKEY_BGSET, ret);
142 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_BGSET,
143 setting_display_wallpaper_string_vconf_change_cb,
145 setting_retvm_if(ret < 0, ret, "%s notifications Failed(%d)",
146 (char *)VCONFKEY_IDLE_LOCK_BGSET, ret);
150 int setting_display_wallpaper_unlisten_vconf_change(void *data)
154 (void)vconf_ignore_key_changed(VCONFKEY_BGSET,
155 setting_display_wallpaper_string_vconf_change_cb);
156 (void)vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_BGSET,
157 setting_display_wallpaper_string_vconf_change_cb);
162 __wall_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
165 SettingDisplayUG *ad = (SettingDisplayUG *) data;
166 if (!ad) return; /* do nothing if ad is NULL */
168 if (ad->ug_loading) return; // prevent double-clicked
170 bundle *b = bundle_create();
175 bundle_add(b, "launch-type", "select-setas");
176 bundle_add(b, "setas-type", "wallpaper");
177 bundle_add(b, "file-type", "image");
179 struct ug_cbs *cbs = (struct ug_cbs *)calloc(1, sizeof(struct ug_cbs));
185 cbs->layout_cb = setting_display_layout_ug_cb;
186 cbs->result_cb = NULL;
187 cbs->destroy_cb = __destroy_gallery_ug_cb;
188 cbs->priv = (void *)ad;
191 ug_create(ad->ug, "gallery-efl", UG_MODE_FULLVIEW, b, cbs);
193 if (NULL == ad->ug_loading) { /* error handling */
194 SETTING_TRACE_ERROR("NULL == ad->ug_loading");
195 setting_create_popup_without_title(ad, ad->win_get, _("Cannot support this function"));
203 static int setting_display_wallpaper_create(void *cb)
206 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
208 SettingDisplayUG *ad = (SettingDisplayUG *) cb; /* ad is point to cb */
210 Evas_Object *sub_layout = elm_layout_add(ad->win_main_layout);
211 elm_layout_file_set(sub_layout, SETTING_THEME_EDJ_NAME,
213 evas_object_size_hint_weight_set(sub_layout, EVAS_HINT_EXPAND,
217 setting_create_layout_navi_bar_scroller(ad->win_main_layout,
220 (char *)dgettext("sys_string", "IDS_COM_BODY_BACK"),
222 setting_display_wallpaper_click_softkey_cancel_cb,
223 NULL, ad, &(ad->scrl_wall),
226 /* pack outer box into scroller */
227 elm_object_content_set(ad->scrl_wall, sub_layout);
231 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
233 double max_image_w_size = w/2 - w*0.03;
234 double max_image_h_size = h*0.46875;
236 /* elm_scroller_content_set(scroller, sub_layout); */
237 Evas_Object *eo_left, *eo_right;
238 Evas_Object *temp_img = evas_object_image_add(ad->evas);
241 double ratio_w, ratio_h, ratio;
242 char *pa_image_path = NULL;
244 /* A:VCONFKEY_BGSET */
245 pa_image_path = vconf_get_str(VCONFKEY_BGSET);
246 evas_object_image_file_set(temp_img, pa_image_path, NULL);
247 evas_object_image_size_get(temp_img, &temp_w, &temp_h);
248 SETTING_TRACE("temp_w:%d, temp_h:%d", temp_w, temp_h);
249 ratio_w = temp_w / max_image_w_size;
250 ratio_h = temp_h / max_image_h_size;
251 ratio = (ratio_w > ratio_h ? ratio_w : ratio_h);
252 SETTING_TRACE("ratio_w:%f, ratio_h:%f, ratio:%f", ratio_w, ratio_h,
254 create_image_box_add_ex(NULL, ad->win_main_layout, ad->evas, pa_image_path,
255 temp_w / ratio, temp_h / ratio, NULL, NULL,
256 &eo_left, &(ad->img_homescreen));
258 evas_object_del(temp_img);
261 /* temp_img are being used in both bgset & lock screen. */
262 Evas_Object *temp_img2 = evas_object_image_add(ad->evas);
264 /* B:VCONFKEY_IDLE_LOCK_BGSET */
265 pa_image_path = vconf_get_str(VCONFKEY_IDLE_LOCK_BGSET);
266 evas_object_image_file_set(temp_img2, pa_image_path, NULL);
267 evas_object_image_size_get(temp_img2, &temp_w, &temp_h);
268 SETTING_TRACE("temp_w:%d, temp_h:%d", temp_w, temp_h);
269 ratio_w = temp_w / max_image_w_size;
270 ratio_h = temp_h / max_image_h_size;
271 ratio = (ratio_w > ratio_h ? ratio_w : ratio_h);
272 SETTING_TRACE("ratio_w:%f, ratio_h:%f, ratio:%f", ratio_w, ratio_h,
274 create_image_box_add_ex(NULL, ad->win_main_layout, ad->evas, pa_image_path,
275 temp_w / ratio, temp_h / ratio, NULL, NULL,
276 &eo_right, &(ad->img_lockscreen));
277 evas_object_del(temp_img2);
280 elm_object_part_content_set(sub_layout, "left_swallow", eo_left);
281 elm_object_part_content_set(sub_layout, "right_swallow", eo_right);
283 edje_object_part_text_set(_EDJ(sub_layout), "left_text",
284 _(KeyStr_HomeScreen));
285 edje_object_part_text_set(_EDJ(sub_layout), "right_text",
286 _(KeyStr_LockedScreen));
288 /* button : change wallpaper */
289 Evas_Object *btn = elm_button_add(sub_layout);
290 elm_object_text_set(btn, _(SETING_DISPLAY_WALLPAPER_CHANGE_WALLPAPER_STR));
291 evas_object_smart_callback_add(btn, "clicked", __wall_button_clicked_cb,
293 elm_object_part_content_set(sub_layout, "btn", btn);
295 SETTING_TRACE_DEBUG("get theme : %d", setting_get_theme());
296 if (Theme_Tizen_Black == setting_get_theme()) {
297 SETTING_TRACE_DEBUG("black theme");
298 elm_object_style_set(btn, "sweep");
299 edje_object_signal_emit(_EDJ(sub_layout), "change,non-white,theme", "elm");
300 } else if (Theme_Tizen_Blue == setting_get_theme()) {
301 SETTING_TRACE_DEBUG("blue theme");
302 edje_object_signal_emit(_EDJ(sub_layout), "change,non-white,theme", "elm");
303 } else if (Theme_Tizen_Grey == setting_get_theme()) {
304 SETTING_TRACE_DEBUG("grey theme");
305 edje_object_signal_emit(_EDJ(sub_layout), "change,non-white,theme", "elm");
308 setting_view_display_wallpaper.is_create = 1;
309 setting_display_wallpaper_listen_vconf_change(ad);
310 return SETTING_RETURN_SUCCESS;
313 static int setting_display_wallpaper_destroy(void *cb)
317 retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
319 SettingDisplayUG *ad = (SettingDisplayUG *) cb; /* ad is point to cb */
320 setting_display_wallpaper_unlisten_vconf_change(ad);
322 if (ad->ly_wall != NULL) {
323 evas_object_del(ad->ly_wall);
325 setting_view_display_wallpaper.is_create = 0;
327 return SETTING_RETURN_SUCCESS;
330 static int setting_display_wallpaper_update(void *cb)
332 return SETTING_RETURN_SUCCESS;
335 static int setting_display_wallpaper_cleanup(void *cb)
337 return SETTING_RETURN_SUCCESS;
340 /* ***************************************************
344 ***************************************************/
346 /* ***************************************************
350 ***************************************************/
353 setting_display_wallpaper_click_softkey_cancel_cb(void *data, Evas_Object *obj,
358 retm_if(data == NULL, "Data parameter is NULL");
359 SettingDisplayUG *ad = (SettingDisplayUG *) data; /* ad is point to cb */
361 /* called when this shared gadget is terminated. similar with app_exit */
362 /* Send destroy request */
363 ug_destroy_me(ad->ug);