3 #define IMPORT_STRETCH 0
5 #define IMPORT_CENTER 2
6 #define IMPORT_SCALE_ASPECT_IN 3
7 #define IMPORT_SCALE_ASPECT_OUT 4
10 static void _import_edj_gen(E_Import_Config_Dialog *import);
11 static Eina_Bool _import_cb_edje_cc_exit(void *data, int type, void *event);
15 _import_edj_gen(E_Import_Config_Dialog *import)
19 Eina_Bool anim = EINA_FALSE;
22 const char *file, *locale;
23 char buf[PATH_MAX], cmd[PATH_MAX], tmpn[PATH_MAX], ipart[PATH_MAX], enc[128];
24 char *imgdir = NULL, *fstrip;
29 evas = e_win_evas_get(import->dia->win);
30 file = ecore_file_file_get(import->file);
31 fstrip = ecore_file_strip_ext(file);
33 len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip);
34 if (len >= sizeof(buf))
39 off = len - (sizeof(".edj") - 1);
45 for (num = 1; ecore_file_exists(buf) && num < 100; num++)
46 snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num);
55 printf("Couldn't come up with another filename for %s\n", buf);
59 strcpy(tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX");
63 printf("Error Creating tmp file: %s\n", strerror(errno));
70 printf("Cannot open %s for writing\n", tmpn);
74 anim = eina_str_has_extension(import->file, "gif");
75 imgdir = ecore_file_dir_get(import->file);
76 if (!imgdir) ipart[0] = '\0';
79 snprintf(ipart, sizeof(ipart), "-id %s", e_util_filename_escape(imgdir));
83 img = evas_object_image_add(evas);
84 evas_object_image_file_set(img, import->file, NULL);
85 evas_object_image_size_get(img, &w, &h);
90 fstrip = strdupa(e_util_filename_escape(import->file));
91 snprintf(enc, sizeof(enc), "USER");
95 fstrip = strdupa(e_util_filename_escape(file));
96 if (import->quality == 100)
97 snprintf(enc, sizeof(enc), "COMP");
99 snprintf(enc, sizeof(enc), "LOSSY %i", import->quality);
101 switch (import->method)
105 "images { image: \"%s\" %s; }\n"
107 "group { name: \"e/desktop/background\";\n"
109 "data { item: \"style\" \"0\"; }\n"
112 "part { name: \"bg\"; mouse_events: 0;\n"
113 "description { state: \"default\" 0.0;\n"
114 "image { normal: \"%s\"; scale_hint: STATIC; }\n"
116 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n", w, h, fstrip);
121 "images { image: \"%s\" %s; }\n"
123 "group { name: \"e/desktop/background\";\n"
124 "data { item: \"style\" \"1\"; }\n"
128 "part { name: \"bg\"; mouse_events: 0;\n"
129 "description { state: \"default\" 0.0;\n"
130 "image { normal: \"%s\"; }\n"
132 "relative: 0.0 0.0;\n"
135 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n", w, h, fstrip, w, h);
140 "images { image: \"%s\" %s; }\n"
142 "group { name: \"e/desktop/background\";\n"
143 "data { item: \"style\" \"2\"; }\n"
147 "part { name: \"col\"; type: RECT; mouse_events: 0;\n"
148 "description { state: \"default\" 0.0;\n"
149 "color: %i %i %i %i;\n"
151 "part { name: \"bg\"; mouse_events: 0;\n"
152 "description { state: \"default\" 0.0;\n"
153 "min: %i %i; max: %i %i;\n"
154 "image { normal: \"%s\"; }\n"
156 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n", w, h, cr, cg, cb, ca, w, h, w, h, fstrip);
159 case IMPORT_SCALE_ASPECT_IN:
160 locale = e_intl_language_get();
161 setlocale(LC_NUMERIC, "C");
163 "images { image: \"%s\" %s; }\n"
165 "group { name: \"e/desktop/background\";\n"
166 "data { item: \"style\" \"3\"; }\n"
170 "part { name: \"col\"; type: RECT; mouse_events: 0;\n"
171 "description { state: \"default\" 0.0;\n"
172 "color: %i %i %i %i;\n"
174 "part { name: \"bg\"; mouse_events: 0;\n"
175 "description { state: \"default\" 0.0;\n"
176 "aspect: %1.9f %1.9f; aspect_preference: BOTH;\n"
177 "image { normal: \"%s\"; scale_hint: STATIC; }\n"
179 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n",
180 w, h, cr, cg, cb, ca, (double)w / (double)h, (double)w / (double)h, fstrip);
181 setlocale(LC_NUMERIC, locale);
184 case IMPORT_SCALE_ASPECT_OUT:
185 locale = e_intl_language_get();
186 setlocale(LC_NUMERIC, "C");
188 "images { image: \"%s\" %s; }\n"
190 "group { name: \"e/desktop/background\";\n"
191 "data { item: \"style\" \"4\"; }\n"
195 "part { name: \"bg\"; mouse_events: 0;\n"
196 "description { state: \"default\" 0.0;\n"
197 "aspect: %1.9f %1.9f; aspect_preference: NONE;\n"
198 "image { normal: \"%s\"; scale_hint: STATIC; }\n"
200 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n",
201 w, h, (double)w / (double)h, (double)w / (double)h, fstrip);
202 setlocale(LC_NUMERIC, locale);
206 locale = e_intl_language_get();
207 setlocale(LC_NUMERIC, "C");
209 "images { image: \"%s\" %s; }\n"
211 "group { name: \"e/desktop/background\";\n"
212 "data { item: \"style\" \"4\"; }\n"
216 "public cur_anim; public cur_x; public cur_y; public prev_x;\n"
217 "public prev_y; public total_x; public total_y; \n"
218 "public pan_bg(val, Float:v) {\n"
219 "new Float:x, Float:y, Float:px, Float: py;\n"
221 "px = get_float(prev_x); py = get_float(prev_y);\n"
222 "if (get_int(total_x) > 1) {\n"
223 "x = float(get_int(cur_x)) / (get_int(total_x) - 1);\n"
224 "x = px - (px - x) * v;\n"
225 "} else { x = 0.0; v = 1.0; }\n"
226 "if (get_int(total_y) > 1) {\n"
227 "y = float(get_int(cur_y)) / (get_int(total_y) - 1);\n"
228 "y = py - (py - y) * v;\n"
229 "} else { y = 0.0; v = 1.0; }\n"
231 "set_state_val(PART:\"bg\", STATE_ALIGNMENT, x, y);\n"
234 "set_int(cur_anim, 0); set_float(prev_x, x);\n"
235 "set_float(prev_y, y); return 0;\n"
239 "public message(Msg_Type:type, id, ...) {\n"
240 "if ((type == MSG_FLOAT_SET) && (id == 0)) {\n"
243 "get_state_val(PART:\"bg\", STATE_ALIGNMENT, prev_x, prev_y);\n"
244 "set_int(cur_x, round(getfarg(3))); set_int(total_x, round(getfarg(4)));\n"
245 "set_int(cur_y, round(getfarg(5))); set_int(total_y, round(getfarg(6)));\n"
247 "ani = get_int(cur_anim); if (ani > 0) cancel_anim(ani);\n"
248 "ani = anim(getfarg(2), \"pan_bg\", 0); set_int(cur_anim, ani);\n"
251 "part { name: \"bg\"; mouse_events: 0;\n"
252 "description { state: \"default\" 0.0;\n"
253 "aspect: %1.9f %1.9f; aspect_preference: NONE;\n"
254 "image { normal: \"%s\"; scale_hint: STATIC; }\n"
256 "programs { program {\n"
258 " signal: \"load\";\n"
260 " script { custom_state(PART:\"bg\", \"default\", 0.0);\n"
261 " set_state(PART:\"bg\", \"custom\", 0.0);\n"
262 " set_float(prev_x, 0.0); set_float(prev_y, 0.0);\n"
264 , fstrip, enc, anim ? "" : "data.item: \"noanimation\" \"1\";\n",
265 w, h, (double)w / (double)h, (double)w / (double)h, fstrip);
266 setlocale(LC_NUMERIC, locale);
276 snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s",
277 ipart, tmpn, e_util_filename_escape(buf));
279 import->tmpf = strdup(tmpn);
280 import->fdest = eina_stringshare_add(buf);
281 import->exe_handler =
282 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
283 _import_cb_edje_cc_exit, import);
284 import->exe = ecore_exe_run(cmd, import);
288 _import_cb_edje_cc_exit(void *data, __UNUSED__ int type, void *event)
290 E_Import_Config_Dialog *import;
291 Ecore_Exe_Event_Del *ev;
296 if (ecore_exe_data_get(ev->exe) != import) return ECORE_CALLBACK_PASS_ON;
298 if (ev->exit_code != 0)
300 e_util_dialog_show(_("Picture E_Import_Config_Dialog Error"),
301 _("Enlightenment was unable to import the picture<br>"
302 "due to conversion errors."));
308 e_object_ref(E_OBJECT(import));
309 import->ok((void*)import->fdest, import);
310 e_object_del(E_OBJECT(import));
311 e_object_unref(E_OBJECT(import));
314 e_object_del(E_OBJECT(import));
316 return ECORE_CALLBACK_DONE;
320 _import_cb_close(void *data, E_Dialog *dia __UNUSED__)
322 E_Import_Config_Dialog *import = data;
325 if (import->cancel) import->cancel(import);
327 e_object_unref(data);
331 _import_cb_ok(void *data, E_Dialog *dia __UNUSED__)
333 E_Import_Config_Dialog *import = data;
336 int is_bg, is_theme, r;
339 if (!import->file) return;
340 file = ecore_file_file_get(import->file);
341 if (!eina_str_has_extension(file, "edj"))
343 _import_edj_gen(import);
344 e_win_hide(import->dia->win);
347 e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file);
349 is_bg = edje_file_group_exists(import->file, "e/desktop/background");
350 is_theme = edje_file_group_exists(import->file,
351 "e/widgets/border/default/border");
353 if ((is_bg) && (!is_theme))
355 if (!ecore_file_cp(import->file, buf))
357 e_util_dialog_show(_("Import Error"),
358 _("Enlightenment was unable to "
359 "import the image<br>due to a "
367 e_util_dialog_show(_("Import Error"),
368 _("Enlightenment was unable to "
369 "import the image.<br><br>"
370 "Are you sure this is a valid "
376 e_object_ref(E_OBJECT(import));
377 if (import->ok) import->ok((void*)buf, import);
378 e_object_del(E_OBJECT(import));
379 e_object_unref(E_OBJECT(import));
382 _import_cb_close(import, NULL);
386 _e_import_config_preview_size_get(int size, int w, int h,int *tw, int *th)
388 if (size <= 0) return;
390 aspect = (double)w/h;
402 _e_import_config_dia_del(void *data)
404 E_Dialog *dia = data;
406 e_object_del(dia->data);
410 _e_import_config_dialog_del(void *data)
412 E_Import_Config_Dialog *import = data;
414 if (import->exe_handler) ecore_event_handler_del(import->exe_handler);
415 import->exe_handler = NULL;
416 if (import->tmpf) unlink(import->tmpf);
418 eina_stringshare_del(import->fdest);
420 eina_stringshare_del(import->file);
421 e_object_del(E_OBJECT(import->dia));
426 _e_import_config_dialog_win_del(E_Win *win)
429 E_Import_Config_Dialog *import;
433 e_object_ref(E_OBJECT(import));
434 if (import->cancel) import->cancel(import);
435 e_object_del(E_OBJECT(import));
436 e_object_unref(E_OBJECT(import));
438 ///////////////////////////////////////////////////////////////////////////////////
441 EAPI E_Import_Config_Dialog *
442 e_import_config_dialog_show(E_Container *con, const char *path, Ecore_End_Cb ok, Ecore_Cb cancel)
446 E_Import_Config_Dialog *import;
447 Evas_Object *o, *of, *ord, *ot, *ol, *preview, *frame;
451 if (!path) return NULL;
453 import = E_OBJECT_ALLOC(E_Import_Config_Dialog, E_IMPORT_CONFIG_DIALOG_TYPE, _e_import_config_dialog_del);
454 if (!import) return NULL;
456 dia = e_dialog_new(con, "E", "_import_config_dialog");
457 e_dialog_title_set(dia, _("Import Settings..."));
460 import->ok = ok, import->cancel = cancel;
461 import->path = eina_stringshare_add(path);
462 e_object_del_attach_func_set(E_OBJECT(dia), _e_import_config_dia_del);
463 e_win_delete_callback_set(dia->win, _e_import_config_dialog_win_del);
465 import->method = IMPORT_SCALE_ASPECT_OUT;
466 import->external = 0;
467 import->quality = 90;
468 import->file = eina_stringshare_add(path);
470 evas = e_win_evas_get(dia->win);
472 o = e_widget_list_add(evas, 0, 0);
474 ot = e_widget_list_add(evas, 0, 0);
475 frame = e_widget_frametable_add(evas, _("Preview"), 1);
477 preview = evas_object_image_add(evas);
478 evas_object_image_file_set(preview, path, NULL);
479 evas_object_image_size_get(preview,&w, &h);
480 evas_object_del(preview);
482 _e_import_config_preview_size_get(320, w, h, &tw, &th);
484 preview = e_widget_preview_add(evas, tw, th);
485 e_widget_preview_thumb_set(preview, path, NULL, tw, th);
487 e_widget_frametable_object_append(frame, preview, 0, 0, 1, 1, 1, 1, 1, 0);
488 e_widget_list_object_append(ot, frame, 1, 1, 0);
489 of = e_widget_frametable_add(evas, _("Fill and Stretch Options"), 1);
490 rg = e_widget_radio_group_new(&import->method);
491 ord = e_widget_radio_icon_add(evas, _("Stretch"),
492 "enlightenment/wallpaper_stretch",
493 24, 24, IMPORT_STRETCH, rg);
494 e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0);
495 ord = e_widget_radio_icon_add(evas, _("Center"),
496 "enlightenment/wallpaper_center",
497 24, 24, IMPORT_CENTER, rg);
498 e_widget_frametable_object_append(of, ord, 1, 0, 1, 1, 1, 0, 1, 0);
499 ord = e_widget_radio_icon_add(evas, _("Tile"),
500 "enlightenment/wallpaper_tile",
501 24, 24, IMPORT_TILE, rg);
502 e_widget_frametable_object_append(of, ord, 2, 0, 1, 1, 1, 0, 1, 0);
503 ord = e_widget_radio_icon_add(evas, _("Within"),
504 "enlightenment/wallpaper_scale_aspect_in",
505 24, 24, IMPORT_SCALE_ASPECT_IN, rg);
506 e_widget_frametable_object_append(of, ord, 3, 0, 1, 1, 1, 0, 1, 0);
507 ord = e_widget_radio_icon_add(evas, _("Fill"),
508 "enlightenment/wallpaper_scale_aspect_out",
509 24, 24, IMPORT_SCALE_ASPECT_OUT, rg);
510 e_widget_frametable_object_append(of, ord, 4, 0, 1, 1, 1, 0, 1, 0);
511 ord = e_widget_radio_icon_add(evas, _("Pan"),
512 "enlightenment/wallpaper_pan",
513 24, 24, IMPORT_PAN, rg);
514 e_widget_frametable_object_append(of, ord, 5, 0, 1, 1, 1, 0, 1, 0);
515 e_widget_list_object_append(ot, of, 1, 1, 0);
517 ol = e_widget_list_add(evas, 0, 1);
519 of = e_widget_frametable_add(evas, _("File Quality"), 0);
520 ord = e_widget_check_add(evas, _("Use original file"), &(import->external));
521 e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0);
522 ord = e_widget_slider_add(evas, 1, 0, _("%3.0f%%"), 0.0, 100.0, 1.0, 0,
523 NULL, &(import->quality), 150);
524 e_widget_frametable_object_append(of, ord, 0, 1, 1, 1, 1, 0, 1, 0);
525 e_widget_list_object_append(ol, of, 1, 1, 0);
527 of = e_widget_framelist_add(evas, _("Fill Color"), 0);
528 ord = e_widget_color_well_add(evas, &import->color, 1);
529 e_widget_framelist_object_append(of, ord);
530 e_widget_list_object_append(ol, of, 1, 0, 1);
531 e_widget_list_object_append(ot, ol, 1, 1, 0);
533 e_widget_list_object_append(o, ot, 0, 0, 0.5);
535 e_widget_size_min_get(o, &w, &h);
536 e_dialog_content_set(dia, o, w, h);
537 e_dialog_button_add(dia, _("OK"), NULL, _import_cb_ok, import);
538 e_dialog_button_add(dia, _("Cancel"), NULL, _import_cb_close, import);
539 e_win_centered_set(dia->win, 1);
540 e_dialog_border_icon_set(dia, "folder-image");
541 e_dialog_button_focus_num(dia, 0);