diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 2fd1097a2..be142940d 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -95,6 +95,8 @@ e.h \ e_hints.h \ e_icon.h \ e_ilist.h \ +e_import_config_dialog.h \ +e_import_dialog.h \ e_includes.h \ e_init.h \ e_int_border_locks.h \ @@ -247,6 +249,8 @@ e_grabinput.c \ e_hints.c \ e_icon.c \ e_ilist.c \ +e_import_config_dialog.c \ +e_import_dialog.c \ e_init.c \ e_int_border_locks.c \ e_int_border_menu.c \ diff --git a/src/bin/e_import_config_dialog.c b/src/bin/e_import_config_dialog.c new file mode 100644 index 000000000..43621112d --- /dev/null +++ b/src/bin/e_import_config_dialog.c @@ -0,0 +1,520 @@ +#include "e.h" + +#define IMPORT_STRETCH 0 +#define IMPORT_TILE 1 +#define IMPORT_CENTER 2 +#define IMPORT_SCALE_ASPECT_IN 3 +#define IMPORT_SCALE_ASPECT_OUT 4 +#define IMPORT_PAN 5 + +static void _import_edj_gen(E_Import_Config_Dialog *import); +static Eina_Bool _import_cb_edje_cc_exit(void *data, int type, void *event); + + +static void +_import_edj_gen(E_Import_Config_Dialog *import) +{ + Evas *evas; + Evas_Object *img; + int fd, num = 1; + int w = 0, h = 0; + const char *file, *locale; + char buf[PATH_MAX], cmd[PATH_MAX], tmpn[PATH_MAX], ipart[PATH_MAX], enc[128]; + char *imgdir = NULL, *fstrip; + int cr, cg, cb, ca; + FILE *f; + size_t len, off; + + evas = e_win_evas_get(import->dia->win); + file = ecore_file_file_get(import->file); + fstrip = ecore_file_strip_ext(file); + if (!fstrip) return; + len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip); + if (len >= sizeof(buf)) return; + off = len - (sizeof(".edj") - 1); + for (num = 1; ecore_file_exists(buf) && num < 100; num++) + snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num); + free(fstrip); + cr = import->color.r; + cg = import->color.g; + cb = import->color.b; + ca = import->color.a; + + if (num == 100) + { + printf("Couldn't come up with another filename for %s\n", buf); + return; + } + + strcpy(tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX"); + fd = mkstemp(tmpn); + if (fd < 0) + { + printf("Error Creating tmp file: %s\n", strerror(errno)); + return; + } + close(fd); + + f = fopen(tmpn, "w"); + if (!f) + { + printf("Cannot open %s for writing\n", tmpn); + return; + } + + imgdir = ecore_file_dir_get(import->file); + if (!imgdir) ipart[0] = '\0'; + else + { + snprintf(ipart, sizeof(ipart), "-id %s", e_util_filename_escape(imgdir)); + free(imgdir); + } + + img = evas_object_image_add(evas); + evas_object_image_file_set(img, import->file, NULL); + evas_object_image_size_get(img, &w, &h); + evas_object_del(img); + + if (import->external) + { + fstrip = strdup(e_util_filename_escape(import->file)); + snprintf(enc, sizeof(enc), "USER"); + } + else + { + fstrip = strdup(e_util_filename_escape(file)); + if (import->quality == 100) + snprintf(enc, sizeof(enc), "COMP"); + else + snprintf(enc, sizeof(enc), "LOSSY %i", import->quality); + } + switch (import->method) + { + case IMPORT_STRETCH: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"0\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, fstrip); + break; + + case IMPORT_TILE: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"1\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "image { normal: \"%s\"; }\n" + "fill { size {\n" + "relative: 0.0 0.0;\n" + "offset: %i %i;\n" + "} } } } } } }\n" + , fstrip, enc, w, h, fstrip, w, h); + break; + + case IMPORT_CENTER: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"2\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"col\"; type: RECT; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "color: %i %i %i %i;\n" + "} }\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "min: %i %i; max: %i %i;\n" + "image { normal: \"%s\"; }\n" + "} } } } }\n" + , fstrip, enc, w, h, cr, cg, cb, ca, w, h, w, h, fstrip); + break; + + case IMPORT_SCALE_ASPECT_IN: + locale = e_intl_language_get(); + setlocale(LC_NUMERIC, "C"); + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"3\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"col\"; type: RECT; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "color: %i %i %i %i;\n" + "} }\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "aspect: %1.9f %1.9f; aspect_preference: BOTH;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, cr, cg, cb, ca, (double)w / (double)h, (double)w / (double)h, fstrip); + setlocale(LC_NUMERIC, locale); + break; + + case IMPORT_SCALE_ASPECT_OUT: + locale = e_intl_language_get(); + setlocale(LC_NUMERIC, "C"); + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"4\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, (double)w / (double)h, (double)w / (double)h, fstrip); + setlocale(LC_NUMERIC, locale); + break; + + case IMPORT_PAN: + locale = e_intl_language_get(); + setlocale(LC_NUMERIC, "C"); + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"4\"; }\n" + "max: %i %i;\n" + "script {\n" + "public cur_anim; public cur_x; public cur_y; public prev_x;\n" + "public prev_y; public total_x; public total_y; \n" + "public pan_bg(val, Float:v) {\n" + "new Float:x, Float:y, Float:px, Float: py;\n" + + "px = get_float(prev_x); py = get_float(prev_y);\n" + "if (get_int(total_x) > 1) {\n" + "x = float(get_int(cur_x)) / (get_int(total_x) - 1);\n" + "x = px - (px - x) * v;\n" + "} else { x = 0.0; v = 1.0; }\n" + "if (get_int(total_y) > 1) {\n" + "y = float(get_int(cur_y)) / (get_int(total_y) - 1);\n" + "y = py - (py - y) * v;\n" + "} else { y = 0.0; v = 1.0; }\n" + + "set_state_val(PART:\"bg\", STATE_ALIGNMENT, x, y);\n" + + "if (v >= 1.0) {\n" + "set_int(cur_anim, 0); set_float(prev_x, x);\n" + "set_float(prev_y, y); return 0;\n" + "}\n" + "return 1;\n" + "}\n" + "public message(Msg_Type:type, id, ...) {\n" + "if ((type == MSG_FLOAT_SET) && (id == 0)) {\n" + "new ani;\n" + + "get_state_val(PART:\"bg\", STATE_ALIGNMENT, prev_x, prev_y);\n" + "set_int(cur_x, round(getfarg(3))); set_int(total_x, round(getfarg(4)));\n" + "set_int(cur_y, round(getfarg(5))); set_int(total_y, round(getfarg(6)));\n" + + "ani = get_int(cur_anim); if (ani > 0) cancel_anim(ani);\n" + "ani = anim(getfarg(2), \"pan_bg\", 0); set_int(cur_anim, ani);\n" + "} } }\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } }\n" + "programs { program {\n" + " name: \"init\";\n" + " signal: \"load\";\n" + " source: \"\";\n" + " script { custom_state(PART:\"bg\", \"default\", 0.0);\n" + " set_state(PART:\"bg\", \"custom\", 0.0);\n" + " set_float(prev_x, 0.0); set_float(prev_y, 0.0);\n" + "} } } } }\n" + , fstrip, enc, w, h, (double)w / (double)h, (double)w / (double)h, fstrip); + setlocale(LC_NUMERIC, locale); + break; + + default: + /* won't happen */ + break; + } + free(fstrip); + + fclose(f); + + snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s", + ipart, tmpn, e_util_filename_escape(buf)); + + import->tmpf = strdup(tmpn); + import->fdest = eina_stringshare_add(buf); + import->exe_handler = + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, + _import_cb_edje_cc_exit, import); + import->exe = ecore_exe_run(cmd, import); +} + +static Eina_Bool +_import_cb_edje_cc_exit(void *data, __UNUSED__ int type, void *event) +{ + E_Import_Config_Dialog *import; + Ecore_Exe_Event_Del *ev; + int r = 1; + + ev = event; + import = data; + if (ecore_exe_data_get(ev->exe) != import) return ECORE_CALLBACK_PASS_ON; + + if (ev->exit_code != 0) + { + e_util_dialog_show(_("Picture E_Import_Config_Dialog Error"), + _("Enlightenment was unable to import the picture
" + "due to conversion errors.")); + r = 0; + } + + if (r && import->ok) + { + e_object_ref(E_OBJECT(import)); + import->ok((void*)import->fdest, import); + e_object_del(E_OBJECT(import)); + e_object_unref(E_OBJECT(import)); + } + else + e_object_del(E_OBJECT(import)); + + return ECORE_CALLBACK_DONE; +} + +static void +_import_cb_close(void *data, E_Dialog *dia __UNUSED__) +{ + E_Import_Config_Dialog *import = data; + + e_object_ref(data); + if (import->cancel) import->cancel(import); + e_object_del(data); + e_object_unref(data); +} + +static void +_import_cb_ok(void *data, E_Dialog *dia __UNUSED__) +{ + E_Import_Config_Dialog *import = data; + const char *file; + char buf[PATH_MAX]; + int is_bg, is_theme, r; + + r = 0; + if (!import->file) return; + file = ecore_file_file_get(import->file); + if (!eina_str_has_extension(file, "edj")) + { + _import_edj_gen(import); + e_win_hide(import->dia->win); + return; + } + e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); + + is_bg = edje_file_group_exists(import->file, "e/desktop/background"); + is_theme = edje_file_group_exists(import->file, + "e/widgets/border/default/border"); + + if ((is_bg) && (!is_theme)) + { + if (!ecore_file_cp(import->file, buf)) + { + e_util_dialog_show(_("Import Error"), + _("Enlightenment was unable to " + "import the image
due to a " + "copy error.")); + } + else + r = 1; + } + else + { + e_util_dialog_show(_("Import Error"), + _("Enlightenment was unable to " + "import the image.

" + "Are you sure this is a valid " + "image?")); + } + + if (r) + { + e_object_ref(E_OBJECT(import)); + if (import->ok) import->ok((void*)buf, import); + e_object_del(E_OBJECT(import)); + e_object_unref(E_OBJECT(import)); + } + else + _import_cb_close(import, NULL); +} + +static void +_e_import_config_preview_size_get(int size, int w, int h,int *tw, int *th) +{ + if (size <= 0) return; + double aspect; + aspect = (double)w/h; + + if(w > size) + { + w = size; + h = (w/aspect); + } + *tw = w; + *th = h; +} + +static void +_e_import_config_dialog_del(void *data) +{ + E_Import_Config_Dialog *import = data; + + if (import->exe_handler) ecore_event_handler_del(import->exe_handler); + import->exe_handler = NULL; + if (import->tmpf) unlink(import->tmpf); + free(import->tmpf); + eina_stringshare_del(import->fdest); + import->exe = NULL; + eina_stringshare_del(import->file); + e_object_del(E_OBJECT(import->dia)); + free(import); +} + +static void +_e_import_config_dialog_win_del(E_Win *win) +{ + E_Dialog *dia; + E_Import_Config_Dialog *import; + + dia = win->data; + import = dia->data; + e_object_ref(E_OBJECT(import)); + if (import->cancel) import->cancel(import); + e_object_del(E_OBJECT(import)); + e_object_unref(E_OBJECT(import)); +} +/////////////////////////////////////////////////////////////////////////////////// + + +EAPI E_Import_Config_Dialog * +e_import_config_dialog_show(E_Container *con, const char *path, Ecore_End_Cb ok, Ecore_Cb cancel) +{ + Evas *evas; + E_Dialog *dia; + E_Import_Config_Dialog *import; + Evas_Object *o, *of, *ord, *ot, *ol, *preview, *frame; + E_Radio_Group *rg; + int w, h, tw, th; + + if (!path) return NULL; + + import = E_OBJECT_ALLOC(E_Import_Config_Dialog, E_IMPORT_CONFIG_DIALOG_TYPE, _e_import_config_dialog_del); + if (!import) return NULL; + + dia = e_dialog_new(con, "E", "_import_config_dialog"); + e_dialog_title_set(dia, _("Import Settings...")); + dia->data = import; + import->dia = dia; + import->ok = ok, import->cancel = cancel; + import->path = eina_stringshare_add(path); + e_win_delete_callback_set(dia->win, _e_import_config_dialog_win_del); + + evas = e_win_evas_get(dia->win); + + import->method = IMPORT_SCALE_ASPECT_OUT; + import->external = 0; + import->quality = 90; + import->file = eina_stringshare_add(path); + + evas = e_win_evas_get(dia->win); + + o = e_widget_list_add(evas, 0, 0); + + ot = e_widget_list_add(evas, 0, 0); + frame = e_widget_frametable_add(evas, _("Preview"), 1); + + preview = evas_object_image_add(evas); + evas_object_image_file_set(preview, path, NULL); + evas_object_image_size_get(preview,&w, &h); + evas_object_del(preview); + + _e_import_config_preview_size_get(320, w, h, &tw, &th); + + preview = e_widget_preview_add(evas, tw, th); + e_widget_preview_thumb_set(preview, path, NULL, tw, th); + + e_widget_frametable_object_append(frame, preview, 0, 0, 1, 1, 1, 1, 1, 0); + e_widget_list_object_append(ot, frame, 1, 1, 0); + of = e_widget_frametable_add(evas, _("Fill and Stretch Options"), 1); + rg = e_widget_radio_group_new(&import->method); + ord = e_widget_radio_icon_add(evas, _("Stretch"), + "enlightenment/wallpaper_stretch", + 24, 24, IMPORT_STRETCH, rg); + e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_radio_icon_add(evas, _("Center"), + "enlightenment/wallpaper_center", + 24, 24, IMPORT_CENTER, rg); + e_widget_frametable_object_append(of, ord, 1, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_radio_icon_add(evas, _("Tile"), + "enlightenment/wallpaper_tile", + 24, 24, IMPORT_TILE, rg); + e_widget_frametable_object_append(of, ord, 2, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_radio_icon_add(evas, _("Within"), + "enlightenment/wallpaper_scale_aspect_in", + 24, 24, IMPORT_SCALE_ASPECT_IN, rg); + e_widget_frametable_object_append(of, ord, 3, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_radio_icon_add(evas, _("Fill"), + "enlightenment/wallpaper_scale_aspect_out", + 24, 24, IMPORT_SCALE_ASPECT_OUT, rg); + e_widget_frametable_object_append(of, ord, 4, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_radio_icon_add(evas, _("Pan"), + "enlightenment/wallpaper_pan", + 24, 24, IMPORT_PAN, rg); + e_widget_frametable_object_append(of, ord, 5, 0, 1, 1, 1, 0, 1, 0); + e_widget_list_object_append(ot, of, 1, 1, 0); + + ol = e_widget_list_add(evas, 0, 1); + + of = e_widget_frametable_add(evas, _("File Quality"), 0); + ord = e_widget_check_add(evas, _("Use original file"), &(import->external)); + e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0); + ord = e_widget_slider_add(evas, 1, 0, _("%3.0f%%"), 0.0, 100.0, 1.0, 0, + NULL, &(import->quality), 150); + e_widget_frametable_object_append(of, ord, 0, 1, 1, 1, 1, 0, 1, 0); + e_widget_list_object_append(ol, of, 1, 1, 0); + + of = e_widget_framelist_add(evas, _("Fill Color"), 0); + ord = e_widget_color_well_add(evas, &import->color, 1); + e_widget_framelist_object_append(of, ord); + e_widget_list_object_append(ol, of, 1, 0, 1); + e_widget_list_object_append(ot, ol, 1, 1, 0); + + e_widget_list_object_append(o, ot, 0, 0, 0.5); + + e_widget_size_min_get(o, &w, &h); + e_dialog_content_set(dia, o, w, h); + e_dialog_button_add(dia, _("OK"), NULL, _import_cb_ok, import); + e_dialog_button_add(dia, _("Cancel"), NULL, _import_cb_close, import); + e_win_centered_set(dia->win, 1); + e_dialog_border_icon_set(dia, "folder-image"); + e_dialog_button_focus_num(dia, 0); + e_dialog_show(dia); + + return import; +} diff --git a/src/bin/e_import_config_dialog.h b/src/bin/e_import_config_dialog.h new file mode 100644 index 000000000..0bf09e121 --- /dev/null +++ b/src/bin/e_import_config_dialog.h @@ -0,0 +1,32 @@ +#ifdef E_TYPEDEFS +typedef struct _E_Import_Config_Dialog E_Import_Config_Dialog; +#else +#ifndef E_IMPORT_CONFIG_DIALOG_H +#define E_IMPORT_CONFIG_DIALOG_H + +#define E_IMPORT_CONFIG_DIALOG_TYPE 0xE0b01040 +struct _E_Import_Config_Dialog +{ + E_Object e_obj_inherit; + Ecore_End_Cb ok; + Ecore_Cb cancel; + + const char *file; + int method; + int external; + int quality; + E_Color color; + + Ecore_Exe *exe; + Ecore_Event_Handler *exe_handler; + const char *path; + char *tmpf; + const char *fdest; + + E_Dialog *dia; +}; + +EAPI E_Import_Config_Dialog *e_import_config_dialog_show(E_Container *con, const char *path, Ecore_End_Cb ok, Ecore_Cb cancel); + +#endif +#endif diff --git a/src/bin/e_import_dialog.c b/src/bin/e_import_dialog.c new file mode 100644 index 000000000..81c93b2fc --- /dev/null +++ b/src/bin/e_import_dialog.c @@ -0,0 +1,182 @@ +#include "e.h" + +static void +_fsel_path_save(E_Import_Dialog *id) +{ + const char *fdev = NULL, *fpath = NULL; + + e_widget_fsel_path_get(id->fsel_obj, &fdev, &fpath); + if ((fdev) || (fpath)) + { + eina_stringshare_replace(&e_config->wallpaper_import_last_dev, fdev); + eina_stringshare_replace(&e_config->wallpaper_import_last_path, fpath); + e_config_save_queue(); + } +} + +static void +_fsel_cb_close(void *data, E_Dialog *dia __UNUSED__) +{ + E_Import_Dialog *id = data; + + e_object_ref(data); + if (id->cancel) id->cancel(id); + e_object_del(data); + e_object_unref(data); +} + +static void +_import_ok(void *data, void *data2) +{ + E_Import_Dialog *id; + + id = e_object_data_get(data2); + e_object_ref(E_OBJECT(id)); + if (id->ok) id->ok(data, id); + e_object_del(E_OBJECT(id)); + e_object_unref(E_OBJECT(id)); +} + +static void +_fsel_cb_ok(void *data, E_Dialog *dia __UNUSED__) +{ + E_Import_Dialog *id; + const char *path, *p; + int is_bg, is_theme, r; + const char *file; + char buf[PATH_MAX]; + + id = data; + path = e_widget_fsel_selection_path_get(id->fsel_obj); + if (!path) return; + + p = strrchr(path, '.'); + if ((p) && (strcasecmp(p, ".edj"))) + { + E_Import_Config_Dialog *import; + import = e_import_config_dialog_show(id->dia->win->container, path, _import_ok, NULL); + e_object_data_set(E_OBJECT(import), id); + return; + } + r = 0; + file = ecore_file_file_get(path); + e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); + + is_bg = edje_file_group_exists(path, "e/desktop/background"); + is_theme = + edje_file_group_exists(path, "e/widgets/border/default/border"); + + if ((is_bg) && (!is_theme)) + { + if (!ecore_file_cp(path, buf)) + { + e_util_dialog_show(_("Import Error"), + _("Enlightenment was unable to " + "import the image
due to a " + "copy error.")); + } + else + r = 1; + } + else + { + e_util_dialog_show(_("Import Error"), + _("Enlightenment was unable to " + "import the image.

" + "Are you sure this is a valid " + "image?")); + } + + if (r) + { + e_object_ref(E_OBJECT(id)); + if (id->ok) id->ok(buf, id); + e_object_del(E_OBJECT(id)); + e_object_unref(E_OBJECT(id)); + } + else + _fsel_cb_close(id, NULL); +} + + +static void +_e_import_dialog_del(void *data) +{ + E_Import_Dialog *id = data; + + _fsel_path_save(id); + e_object_del(E_OBJECT(id->dia)); + free(id); +} + +static void +_e_import_dialog_win_del(E_Win *win) +{ + E_Dialog *dia; + E_Import_Dialog *id; + + dia = win->data; + id = dia->data; + e_object_del(E_OBJECT(id)); +} +////////////////////////////////////////////////////////////////////////////////// + +EAPI E_Import_Dialog * +e_import_dialog_show(E_Container *con, const char *dev, const char *path, Ecore_End_Cb ok, Ecore_Cb cancel) +{ + Evas *evas; + E_Import_Dialog *id; + Evas_Object *ofm; + int w, h; + const char *fdev, *fpath; + char buf[PATH_MAX]; + E_Dialog *dia; + + id = E_OBJECT_ALLOC(E_Import_Dialog, E_IMPORT_DIALOG_TYPE, _e_import_dialog_del); + if (!id) return NULL; + + dia = e_dialog_new(con, "E", "_import_fsel_dialog"); + dia->data = id; + id->dia = dia; + id->ok = ok, id->cancel = cancel; + e_win_delete_callback_set(dia->win, _e_import_dialog_win_del); + + evas = e_win_evas_get(dia->win); + e_dialog_title_set(dia, _("Select a Picture...")); + + fdev = dev ?: e_config->wallpaper_import_last_dev; + fpath = path ?: e_config->wallpaper_import_last_path; + if (fdev) + snprintf(buf, sizeof(buf), "%s/%s", + fdev, path); + else + snprintf(buf, sizeof(buf), "%s", path); + + if (!ecore_file_exists(ecore_file_realpath(buf))) + fpath = "/"; + else + fpath = path ?: e_config->wallpaper_import_last_path; + + if ((!fdev) && (!fpath)) + { + fdev = "~/"; + fpath = "/"; + } + + printf("LAST: [%s] '%s' '%s'\n", buf, fdev, fpath); + ofm = e_widget_fsel_add(evas, fdev, fpath, NULL, NULL, NULL, NULL, + NULL, NULL, 1); + e_widget_fsel_window_object_set(ofm, E_OBJECT(dia->win)); + id->fsel_obj = ofm; + e_widget_size_min_get(ofm, &w, &h); + e_dialog_content_set(dia, ofm, w, h); + + e_dialog_button_add(dia, _("Import"), NULL, _fsel_cb_ok, id); + e_dialog_button_add(dia, _("Cancel"), NULL, _fsel_cb_close, id); + e_dialog_border_icon_set(dia, "enlightenment/background"); + e_dialog_show(dia); + e_win_centered_set(dia->win, 1); + e_widget_focus_set(ofm, 1); + + return id; +} diff --git a/src/bin/e_import_dialog.h b/src/bin/e_import_dialog.h new file mode 100644 index 000000000..5e3e22752 --- /dev/null +++ b/src/bin/e_import_dialog.h @@ -0,0 +1,21 @@ +#ifdef E_TYPEDEFS +typedef struct _E_Import_Dialog E_Import_Dialog; +#else +#ifndef E_IMPORT_DIALOG_H +#define E_IMPORT_DIALOG_H + +#define E_IMPORT_DIALOG_TYPE 0xE0b0103f +struct _E_Import_Dialog +{ + E_Object e_obj_inherit; + Evas_Object *fsel_obj; + Ecore_End_Cb ok; + Ecore_Cb cancel; + + E_Dialog *dia; +}; + +EAPI E_Import_Dialog *e_import_dialog_show(E_Container *con, const char *dev, const char *path, Ecore_End_Cb ok, Ecore_Cb cancel); + +#endif +#endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index 97e5e12a1..fd5159e86 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -144,3 +144,5 @@ #include "e_update.h" #include "e_xkb.h" #include "e_log.h" +#include "e_import_dialog.h" +#include "e_import_config_dialog.h" diff --git a/src/modules/conf_theme/Makefile.am b/src/modules/conf_theme/Makefile.am index 402990e69..c6c4a8fb1 100644 --- a/src/modules/conf_theme/Makefile.am +++ b/src/modules/conf_theme/Makefile.am @@ -42,8 +42,6 @@ module_la_SOURCES = e_mod_main.c \ e_int_config_transitions.h \ e_int_config_wallpaper.c \ e_int_config_wallpaper.h \ - e_int_config_wallpaper_import.c \ - e_int_config_wallpaper_import.h \ e_int_config_wallpaper_web.c \ e_int_config_wallpaper_web.h \ e_int_config_xsettings.c diff --git a/src/modules/conf_theme/e_int_config_wallpaper.c b/src/modules/conf_theme/e_int_config_wallpaper.c index 874b94b0b..5a59f7251 100644 --- a/src/modules/conf_theme/e_int_config_wallpaper.c +++ b/src/modules/conf_theme/e_int_config_wallpaper.c @@ -41,13 +41,13 @@ struct _E_Config_Dialog_Data Evas_Object *o_personal; Evas_Object *o_system; int fmdir, use_theme_bg; - char *bg; + const char *bg; /* advanced */ int all_this_desk_screen; /* dialogs */ - E_Win *win_import; + E_Import_Dialog *win_import; #ifdef HAVE_EXCHANGE E_Dialog *dia_web; #endif @@ -132,35 +132,6 @@ _bg_set(E_Config_Dialog_Data *cfdata) } } -void -e_int_config_wallpaper_update(E_Config_Dialog *dia, char *file) -{ - E_Config_Dialog_Data *cfdata; - char path[PATH_MAX]; - - cfdata = dia->cfdata; - cfdata->fmdir = 1; - e_widget_radio_toggle_set(cfdata->o_personal, 1); - e_user_dir_concat_static(path, "backgrounds"); - E_FREE(cfdata->bg); - cfdata->bg = strdup(file); - cfdata->use_theme_bg = 0; - if (cfdata->o_theme_bg) - e_widget_check_checked_set(cfdata->o_theme_bg, cfdata->use_theme_bg); - if (cfdata->o_fm) e_widget_flist_path_set(cfdata->o_fm, path, "/"); - _bg_set(cfdata); - if (cfdata->o_fm) e_widget_change(cfdata->o_fm); -} - -void -e_int_config_wallpaper_import_done(E_Config_Dialog *dia) -{ - E_Config_Dialog_Data *cfdata; - - cfdata = dia->cfdata; - cfdata->win_import = NULL; -} - #ifdef HAVE_EXCHANGE void e_int_config_wallpaper_web_done(E_Config_Dialog *dia) @@ -215,9 +186,7 @@ _cb_files_selection_change(void *data, Evas_Object *obj __UNUSED__, void *event_ eina_list_free(selected); if (ecore_file_is_dir(buf)) return; - E_FREE(cfdata->bg); - - cfdata->bg = strdup(buf); + eina_stringshare_replace(&cfdata->bg, buf); _bg_set(cfdata); if (cfdata->o_theme_bg) e_widget_check_checked_set(cfdata->o_theme_bg, 0); @@ -301,8 +270,7 @@ _cb_theme_wallpaper(void *data, Evas_Object *obj __UNUSED__, void *event_info __ { f = e_theme_edje_file_get("base/theme/backgrounds", "e/desktop/background"); - E_FREE(cfdata->bg); - cfdata->bg = strdup(f); + eina_stringshare_replace(&cfdata->bg, f); _bg_set(cfdata); } else @@ -327,6 +295,31 @@ _cb_dir(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) e_widget_flist_path_set(cfdata->o_fm, path, "/"); } +static void +_cb_import_ok(const char *path, void *data) +{ + E_Config_Dialog_Data *cfdata; + + cfdata = e_object_data_get(data); + cfdata->fmdir = 1; + e_widget_radio_toggle_set(cfdata->o_personal, cfdata->fmdir); + e_widget_change(cfdata->o_personal); + eina_stringshare_replace(&cfdata->bg, path); + cfdata->use_theme_bg = 0; + if (cfdata->o_theme_bg) + e_widget_check_checked_set(cfdata->o_theme_bg, cfdata->use_theme_bg); + _bg_set(cfdata); + if (cfdata->o_fm) e_widget_change(cfdata->o_fm); +} + +static void +_cb_import_del(void *data) +{ + E_Config_Dialog_Data *cfdata; + cfdata = e_object_data_get(data); + cfdata->win_import = NULL; +} + static void _cb_import(void *data1, void *data2 __UNUSED__) { @@ -334,9 +327,13 @@ _cb_import(void *data1, void *data2 __UNUSED__) cfdata = data1; if (cfdata->win_import) - e_win_raise(cfdata->win_import); - else - cfdata->win_import = e_int_config_wallpaper_fsel(cfdata->cfd); + { + e_win_raise(cfdata->win_import->dia->win); + return; + } + cfdata->win_import = e_import_dialog_show(cfdata->cfd->dia->win->container, NULL, NULL, (Ecore_End_Cb)_cb_import_ok, NULL); + e_object_data_set(E_OBJECT(cfdata->win_import), cfdata); + e_object_del_attach_func_set(E_OBJECT(cfdata->win_import), _cb_import_del); } #ifdef HAVE_EXCHANGE @@ -368,7 +365,7 @@ _fill_data(E_Config_Dialog_Data *cfdata) /* specific config passed in. set for that only */ bg = e_bg_file_get(cw->con_num, cw->zone_num, cw->desk_x, cw->desk_y); - if (bg) cfdata->bg = strdup(bg); + if (bg) cfdata->bg = eina_stringshare_add(bg); } else { @@ -392,13 +389,12 @@ _fill_data(E_Config_Dialog_Data *cfdata) else cfdata->all_this_desk_screen = E_CONFIG_WALLPAPER_SCREEN; } - E_FREE(cfdata->bg); - cfdata->bg = strdup(cfbg->file); + eina_stringshare_replace(&cfdata->bg, cfbg->file); } } if ((!cfdata->bg) && (e_config->desktop_default_background)) - cfdata->bg = strdup(e_config->desktop_default_background); + cfdata->bg = eina_stringshare_add(e_config->desktop_default_background); if (cfdata->bg) { @@ -430,13 +426,12 @@ _create_data(E_Config_Dialog *cfd) static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { - if (cfdata->win_import) - e_int_config_wallpaper_fsel_del(cfdata->win_import); + if (cfdata->win_import) e_object_del(E_OBJECT(cfdata->win_import)); #ifdef HAVE_EXCHANGE if (cfdata->dia_web) e_int_config_wallpaper_web_del(cfdata->dia_web); #endif - E_FREE(cfdata->bg); + eina_stringshare_del(cfdata->bg); E_FREE(cfd->data); E_FREE(cfdata); } diff --git a/src/modules/conf_theme/e_int_config_wallpaper_import.c b/src/modules/conf_theme/e_int_config_wallpaper_import.c deleted file mode 100644 index 5d4dd42cd..000000000 --- a/src/modules/conf_theme/e_int_config_wallpaper_import.c +++ /dev/null @@ -1,1041 +0,0 @@ -#include "e.h" -#include "e_mod_main.h" - -#define IMPORT_STRETCH 0 -#define IMPORT_TILE 1 -#define IMPORT_CENTER 2 -#define IMPORT_SCALE_ASPECT_IN 3 -#define IMPORT_SCALE_ASPECT_OUT 4 -#define IMPORT_PAN 5 - -typedef struct _FSel FSel; - -struct _FSel -{ - E_Config_Dialog *parent; - E_Config_Dialog_Data *cfdata; - - Evas_Object *bg_obj; - Evas_Object *box_obj; - Evas_Object *event_obj; - Evas_Object *content_obj; - Evas_Object *fsel_obj; - - Evas_Object *ok_obj; - Evas_Object *close_obj; - - E_Win *win; -}; - -typedef struct _Import Import; - -struct _Import -{ - E_Config_Dialog_Data *cfdata; - - Evas_Object *bg_obj; - Evas_Object *box_obj; - Evas_Object *event_obj; - Evas_Object *content_obj; - - Evas_Object *ok_obj; - Evas_Object *close_obj; - - Evas_Object *fill_stretch_obj; - Evas_Object *fill_center_obj; - Evas_Object *fill_tile_obj; - Evas_Object *fill_within_obj; - Evas_Object *fill_pan_obj; - Evas_Object *fill_fill_obj; - Evas_Object *external_obj; - Evas_Object *quality_obj; - Evas_Object *frame_fill_obj; - Evas_Object *frame_quality_obj; - Evas_Object *frame_color_obj; - Evas_Object *color_well; - - E_Win *win; - - FSel *fsel; - E_Color color; - - Ecore_Exe *exe; - Ecore_Event_Handler *exe_handler; - char *tmpf; - char *fdest; -}; - -struct _E_Config_Dialog_Data -{ - char *file; - int method; - int external; - int quality; -}; - -static void _fsel_path_save(FSel *fsel); -static void _import_edj_gen(Import *import); -static Eina_Bool _import_cb_edje_cc_exit(void *data, int type, void *event); -static void _import_cb_delete(E_Win *win); -static void _import_cb_resize(E_Win *win); -static void _import_cb_close(void *data, void *data2); -static void _import_cb_ok(void *data, void *data2); -static void _fsel_cb_delete(E_Win *win); -static void _fsel_cb_resize(E_Win *win); -static void _fsel_cb_close(void *data, void *data2); -static void _fsel_cb_ok(void *data, void *data2); -static void _import_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event); -static void _fsel_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event); - -E_Win * -e_int_config_wallpaper_import(void *data, const char *path) -{ - Evas *evas; - E_Win *win; - Import *import; - Evas_Object *o, *of, *ord, *ot, *ol; - E_Radio_Group *rg; - Evas_Coord w, h; - E_Config_Dialog_Data *cfdata; - Evas_Modifier_Mask mask; - Eina_Bool kg; - - if (!path) return NULL; - - import = E_NEW(Import, 1); - if (!import) return NULL; - - win = e_win_new(e_container_current_get(e_manager_current_get())); - - if (!win) - { - E_FREE(import); - return NULL; - } - - import->fsel = data; - - cfdata = E_NEW(E_Config_Dialog_Data, 1); - cfdata->method = IMPORT_SCALE_ASPECT_OUT; - cfdata->external = 0; - cfdata->quality = 90; - cfdata->file = strdup(path); - import->cfdata = cfdata; - import->win = win; - - evas = e_win_evas_get(win); - - e_win_title_set(win, _("Wallpaper settings...")); - e_win_delete_callback_set(win, _import_cb_delete); - e_win_resize_callback_set(win, _import_cb_resize); - e_win_dialog_set(win, 1); - e_win_name_class_set(win, "E", "_wallpaper_import_dialog"); - - o = edje_object_add(evas); - import->bg_obj = o; - e_theme_edje_object_set(o, "base/theme/dialog", "e/widgets/dialog/main"); - evas_object_move(o, 0, 0); - evas_object_show(o); - - o = e_widget_list_add(evas, 1, 1); - import->box_obj = o; - edje_object_part_swallow(import->bg_obj, "e.swallow.buttons", o); - - o = evas_object_rectangle_add(evas); - import->event_obj = o; - mask = 0; - kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o); - mask = evas_key_modifier_mask_get(evas, "Shift"); - kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o); - mask = 0; - kg = evas_object_key_grab(o, "Return", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Return\" key events to object %p.\n", o); - mask = 0; - kg = evas_object_key_grab(o, "KP_Enter", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"KP_Enter\" key events to object %p.\n", o); - evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, - _import_cb_key_down, import); - - o = e_widget_list_add(evas, 0, 0); - import->content_obj = o; - - ot = e_widget_list_add(evas, 1, 0); - - of = e_widget_frametable_add(evas, _("Fill and Stretch Options"), 1); - import->frame_fill_obj = of; - rg = e_widget_radio_group_new(&cfdata->method); - ord = e_widget_radio_icon_add(evas, _("Stretch"), - "enlightenment/wallpaper_stretch", - 24, 24, IMPORT_STRETCH, rg); - import->fill_stretch_obj = ord; - e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_radio_icon_add(evas, _("Center"), - "enlightenment/wallpaper_center", - 24, 24, IMPORT_CENTER, rg); - import->fill_center_obj = ord; - e_widget_frametable_object_append(of, ord, 1, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_radio_icon_add(evas, _("Tile"), - "enlightenment/wallpaper_tile", - 24, 24, IMPORT_TILE, rg); - import->fill_tile_obj = ord; - e_widget_frametable_object_append(of, ord, 2, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_radio_icon_add(evas, _("Within"), - "enlightenment/wallpaper_scale_aspect_in", - 24, 24, IMPORT_SCALE_ASPECT_IN, rg); - import->fill_within_obj = ord; - e_widget_frametable_object_append(of, ord, 3, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_radio_icon_add(evas, _("Fill"), - "enlightenment/wallpaper_scale_aspect_out", - 24, 24, IMPORT_SCALE_ASPECT_OUT, rg); - import->fill_pan_obj = ord; - e_widget_frametable_object_append(of, ord, 4, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_radio_icon_add(evas, _("Pan"), - "enlightenment/wallpaper_pan", - 24, 24, IMPORT_PAN, rg); - import->fill_fill_obj = ord; - e_widget_frametable_object_append(of, ord, 5, 0, 1, 1, 1, 0, 1, 0); - e_widget_list_object_append(ot, of, 1, 1, 0); - - ol = e_widget_list_add(evas, 0, 1); - - of = e_widget_frametable_add(evas, _("File Quality"), 0); - import->frame_quality_obj = of; - ord = e_widget_check_add(evas, _("Use original file"), &(cfdata->external)); - import->external_obj = ord; - e_widget_frametable_object_append(of, ord, 0, 0, 1, 1, 1, 0, 1, 0); - ord = e_widget_slider_add(evas, 1, 0, _("%3.0f%%"), 0.0, 100.0, 1.0, 0, - NULL, &(cfdata->quality), 150); - import->quality_obj = ord; - e_widget_frametable_object_append(of, ord, 0, 1, 1, 1, 1, 0, 1, 0); - e_widget_list_object_append(ol, of, 1, 1, 0); - - of = e_widget_framelist_add(evas, _("Fill Color"), 0); - import->frame_color_obj = of; - ord = e_widget_color_well_add(evas, &import->color, 1); - import->color_well = ord; - e_widget_framelist_object_append(of, ord); - e_widget_list_object_append(ol, of, 1, 0, 1); - e_widget_list_object_append(ot, ol, 1, 1, 0); - - e_widget_list_object_append(o, ot, 0, 0, 0.5); - - e_widget_size_min_get(o, &w, &h); - edje_extern_object_min_size_set(o, w, h); - edje_object_part_swallow(import->bg_obj, "e.swallow.content", o); - evas_object_show(o); - - import->ok_obj = e_widget_button_add(evas, _("OK"), NULL, - _import_cb_ok, win, cfdata); - e_widget_list_object_append(import->box_obj, import->ok_obj, 1, 0, 0.5); - - import->close_obj = e_widget_button_add(evas, _("Cancel"), NULL, - _import_cb_close, win, NULL); - e_widget_list_object_append(import->box_obj, import->close_obj, 1, 0, 0.5); - - e_win_centered_set(win, 1); - - o = import->box_obj; - e_widget_size_min_get(o, &w, &h); - edje_extern_object_min_size_set(o, w, h); - edje_object_part_swallow(import->bg_obj, "e.swallow.buttons", o); - - edje_object_size_min_calc(import->bg_obj, &w, &h); - evas_object_resize(import->bg_obj, w, h); - e_win_resize(win, w, h); - e_win_size_min_set(win, w, h); - e_win_size_max_set(win, 99999, 99999); - e_win_show(win); - e_win_border_icon_set(win, "folder-image"); - - if (!e_widget_focus_get(import->bg_obj)) - e_widget_focus_set(import->box_obj, 1); - - win->data = import; - - return win; -} - -E_Win * -e_int_config_wallpaper_fsel(E_Config_Dialog *parent) -{ - Evas *evas; - E_Win *win; - FSel *fsel; - Evas_Object *o, *ofm; - Evas_Coord w, h; - Evas_Modifier_Mask mask; - const char *fdev, *fpath; - char buf[PATH_MAX]; - Eina_Bool kg; - - fsel = E_NEW(FSel, 1); - if (!fsel) return NULL; - - if (parent) - win = e_win_new(parent->con); - else - win = e_win_new(e_container_current_get(e_manager_current_get())); - - if (!win) - { - E_FREE(fsel); - return NULL; - } - - fsel->win = win; - - evas = e_win_evas_get(win); - - if (parent) fsel->parent = parent; - - e_win_title_set(win, _("Select a Picture...")); - e_win_delete_callback_set(win, _fsel_cb_delete); - e_win_resize_callback_set(win, _fsel_cb_resize); - e_win_dialog_set(win, 1); - e_win_name_class_set(win, "E", "_wallpaper_fsel_dialog"); - - o = edje_object_add(evas); - fsel->bg_obj = o; - e_theme_edje_object_set(o, "base/theme/dialog", "e/widgets/dialog/main"); - evas_object_move(o, 0, 0); - evas_object_show(o); - - o = e_widget_list_add(evas, 1, 1); - fsel->box_obj = o; - edje_object_part_swallow(fsel->bg_obj, "e.swallow.buttons", o); - - o = evas_object_rectangle_add(evas); - fsel->event_obj = o; - mask = 0; - kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o); - mask = evas_key_modifier_mask_get(evas, "Shift"); - kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o); - mask = 0; - kg = evas_object_key_grab(o, "Return", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"Return\" key events to object %p.\n", o); - mask = 0; - kg = evas_object_key_grab(o, "KP_Enter", mask, ~mask, 0); - if (!kg) - fprintf(stderr, "ERROR: unable to redirect \"KP_Enter\" key events to object %p.\n", o); - evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, - _fsel_cb_key_down, fsel); - - o = e_widget_list_add(evas, 0, 0); - e_widget_can_focus_set(o, 0); - fsel->content_obj = o; - - fdev = e_config->wallpaper_import_last_dev; - if (fdev) - snprintf(buf, sizeof(buf), "%s/%s", - fdev, e_config->wallpaper_import_last_path); - else - snprintf(buf, sizeof(buf), "%s", e_config->wallpaper_import_last_path); - - if (!ecore_file_exists(ecore_file_realpath(buf))) - fpath = "/"; - else - fpath = e_config->wallpaper_import_last_path; - - if ((!fdev) && (!fpath)) - { - fdev = "~/"; - fpath = "/"; - } - - printf("LAST: [%s] '%s' '%s'\n", buf, fdev, fpath); - ofm = e_widget_fsel_add(evas, fdev, fpath, NULL, NULL, NULL, NULL, - NULL, NULL, 1); - e_widget_fsel_window_object_set(ofm, E_OBJECT(win)); - fsel->fsel_obj = ofm; - e_widget_list_object_append(o, ofm, 1, 1, 0.5); - - e_widget_size_min_get(o, &w, &h); - edje_extern_object_min_size_set(o, w, h); - edje_object_part_swallow(fsel->bg_obj, "e.swallow.content", o); - evas_object_show(o); - - fsel->ok_obj = e_widget_button_add(evas, _("OK"), NULL, - _fsel_cb_ok, win, NULL); - e_widget_list_object_append(fsel->box_obj, fsel->ok_obj, 1, 0, 0.5); - - fsel->close_obj = e_widget_button_add(evas, _("Cancel"), NULL, - _fsel_cb_close, win, NULL); - e_widget_list_object_append(fsel->box_obj, fsel->close_obj, 1, 0, 0.5); - - e_win_centered_set(win, 1); - - o = fsel->box_obj; - e_widget_size_min_get(o, &w, &h); - edje_extern_object_min_size_set(o, w, h); - edje_object_part_swallow(fsel->bg_obj, "e.swallow.buttons", o); - - edje_object_size_min_calc(fsel->bg_obj, &w, &h); - evas_object_resize(fsel->bg_obj, w, h); - e_win_resize(win, w, h); - e_win_size_min_set(win, w, h); - e_win_size_max_set(win, 99999, 99999); - e_win_show(win); - e_win_border_icon_set(win, "enlightenment/background"); - - win->data = fsel; - - return win; -} - -void -e_int_config_wallpaper_import_del(E_Win *win) -{ - Import *import; - - if (!(import = win->data)) return; - if (import->exe_handler) ecore_event_handler_del(import->exe_handler); - import->exe_handler = NULL; - if (import->tmpf) unlink(import->tmpf); - E_FREE(import->tmpf); - E_FREE(import->fdest); - import->exe = NULL; - if (import->win) e_object_del(E_OBJECT(import->win)); - E_FREE(import->cfdata->file); - E_FREE(import->cfdata); - E_FREE(import); -} - -void -e_int_config_wallpaper_fsel_del(E_Win *win) -{ - FSel *fsel; - - if (!(fsel = win->data)) return; - _fsel_path_save(fsel); - if (fsel->win) e_object_del(E_OBJECT(fsel->win)); - if (fsel->parent) - e_int_config_wallpaper_import_done(fsel->parent); - E_FREE(fsel); -} - -static void -_fsel_path_save(FSel *fsel) -{ - const char *fdev = NULL, *fpath = NULL; - - e_widget_fsel_path_get(fsel->fsel_obj, &fdev, &fpath); - if ((fdev) || (fpath)) - { - if (e_config->wallpaper_import_last_dev) - eina_stringshare_del(e_config->wallpaper_import_last_dev); - if (fdev) - e_config->wallpaper_import_last_dev = eina_stringshare_add(fdev); - else e_config->wallpaper_import_last_dev = NULL; - if (e_config->wallpaper_import_last_path) - eina_stringshare_del(e_config->wallpaper_import_last_path); - if (fpath) - e_config->wallpaper_import_last_path = eina_stringshare_add(fpath); - else e_config->wallpaper_import_last_path = NULL; - e_config_save_queue(); - } -} - -static void -_import_edj_gen(Import *import) -{ - Evas *evas; - Evas_Object *img; - int fd, num = 1; - int w = 0, h = 0; - const char *file, *locale; - char buf[PATH_MAX], cmd[PATH_MAX], tmpn[PATH_MAX], ipart[PATH_MAX], enc[128]; - char *imgdir = NULL, *fstrip; - int cr, cg, cb, ca; - FILE *f; - size_t len, off; - - evas = e_win_evas_get(import->win); - file = ecore_file_file_get(import->cfdata->file); - fstrip = ecore_file_strip_ext(file); - if (!fstrip) return; - len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip); - if (len >= sizeof(buf)) return; - off = len - (sizeof(".edj") - 1); - for (num = 1; ecore_file_exists(buf) && num < 100; num++) - snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num); - free(fstrip); - cr = import->color.r; - cg = import->color.g; - cb = import->color.b; - ca = import->color.a; - - if (num == 100) - { - printf("Couldn't come up with another filename for %s\n", buf); - return; - } - - strcpy(tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX"); - fd = mkstemp(tmpn); - if (fd < 0) - { - printf("Error Creating tmp file: %s\n", strerror(errno)); - return; - } - close(fd); - - f = fopen(tmpn, "w"); - if (!f) - { - printf("Cannot open %s for writing\n", tmpn); - return; - } - - imgdir = ecore_file_dir_get(import->cfdata->file); - if (!imgdir) ipart[0] = '\0'; - else - { - snprintf(ipart, sizeof(ipart), "-id %s", e_util_filename_escape(imgdir)); - free(imgdir); - } - - img = evas_object_image_add(evas); - evas_object_image_file_set(img, import->cfdata->file, NULL); - evas_object_image_size_get(img, &w, &h); - evas_object_del(img); - - if (import->cfdata->external) - { - fstrip = strdup(e_util_filename_escape(import->cfdata->file)); - snprintf(enc, sizeof(enc), "USER"); - } - else - { - fstrip = strdup(e_util_filename_escape(file)); - if (import->cfdata->quality == 100) - snprintf(enc, sizeof(enc), "COMP"); - else - snprintf(enc, sizeof(enc), "LOSSY %i", import->cfdata->quality); - } - switch (import->cfdata->method) - { - case IMPORT_STRETCH: - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"0\"; }\n" - "max: %i %i;\n" - "parts {\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "image { normal: \"%s\"; scale_hint: STATIC; }\n" - "} } } } }\n" - , fstrip, enc, w, h, fstrip); - break; - - case IMPORT_TILE: - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"1\"; }\n" - "max: %i %i;\n" - "parts {\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "image { normal: \"%s\"; }\n" - "fill { size {\n" - "relative: 0.0 0.0;\n" - "offset: %i %i;\n" - "} } } } } } }\n" - , fstrip, enc, w, h, fstrip, w, h); - break; - - case IMPORT_CENTER: - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"2\"; }\n" - "max: %i %i;\n" - "parts {\n" - "part { name: \"col\"; type: RECT; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "color: %i %i %i %i;\n" - "} }\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "min: %i %i; max: %i %i;\n" - "image { normal: \"%s\"; }\n" - "} } } } }\n" - , fstrip, enc, w, h, cr, cg, cb, ca, w, h, w, h, fstrip); - break; - - case IMPORT_SCALE_ASPECT_IN: - locale = e_intl_language_get(); - setlocale(LC_NUMERIC, "C"); - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"3\"; }\n" - "max: %i %i;\n" - "parts {\n" - "part { name: \"col\"; type: RECT; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "color: %i %i %i %i;\n" - "} }\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "aspect: %1.9f %1.9f; aspect_preference: BOTH;\n" - "image { normal: \"%s\"; scale_hint: STATIC; }\n" - "} } } } }\n" - , fstrip, enc, w, h, cr, cg, cb, ca, (double)w / (double)h, (double)w / (double)h, fstrip); - setlocale(LC_NUMERIC, locale); - break; - - case IMPORT_SCALE_ASPECT_OUT: - locale = e_intl_language_get(); - setlocale(LC_NUMERIC, "C"); - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"4\"; }\n" - "max: %i %i;\n" - "parts {\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" - "image { normal: \"%s\"; scale_hint: STATIC; }\n" - "} } } } }\n" - , fstrip, enc, w, h, (double)w / (double)h, (double)w / (double)h, fstrip); - setlocale(LC_NUMERIC, locale); - break; - - case IMPORT_PAN: - locale = e_intl_language_get(); - setlocale(LC_NUMERIC, "C"); - fprintf(f, - "images { image: \"%s\" %s; }\n" - "collections {\n" - "group { name: \"e/desktop/background\";\n" - "data { item: \"style\" \"4\"; }\n" - "max: %i %i;\n" - "script {\n" - "public cur_anim; public cur_x; public cur_y; public prev_x;\n" - "public prev_y; public total_x; public total_y; \n" - "public pan_bg(val, Float:v) {\n" - "new Float:x, Float:y, Float:px, Float: py;\n" - - "px = get_float(prev_x); py = get_float(prev_y);\n" - "if (get_int(total_x) > 1) {\n" - "x = float(get_int(cur_x)) / (get_int(total_x) - 1);\n" - "x = px - (px - x) * v;\n" - "} else { x = 0.0; v = 1.0; }\n" - "if (get_int(total_y) > 1) {\n" - "y = float(get_int(cur_y)) / (get_int(total_y) - 1);\n" - "y = py - (py - y) * v;\n" - "} else { y = 0.0; v = 1.0; }\n" - - "set_state_val(PART:\"bg\", STATE_ALIGNMENT, x, y);\n" - - "if (v >= 1.0) {\n" - "set_int(cur_anim, 0); set_float(prev_x, x);\n" - "set_float(prev_y, y); return 0;\n" - "}\n" - "return 1;\n" - "}\n" - "public message(Msg_Type:type, id, ...) {\n" - "if ((type == MSG_FLOAT_SET) && (id == 0)) {\n" - "new ani;\n" - - "get_state_val(PART:\"bg\", STATE_ALIGNMENT, prev_x, prev_y);\n" - "set_int(cur_x, round(getfarg(3))); set_int(total_x, round(getfarg(4)));\n" - "set_int(cur_y, round(getfarg(5))); set_int(total_y, round(getfarg(6)));\n" - - "ani = get_int(cur_anim); if (ani > 0) cancel_anim(ani);\n" - "ani = anim(getfarg(2), \"pan_bg\", 0); set_int(cur_anim, ani);\n" - "} } }\n" - "parts {\n" - "part { name: \"bg\"; mouse_events: 0;\n" - "description { state: \"default\" 0.0;\n" - "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" - "image { normal: \"%s\"; scale_hint: STATIC; }\n" - "} } }\n" - "programs { program {\n" - " name: \"init\";\n" - " signal: \"load\";\n" - " source: \"\";\n" - " script { custom_state(PART:\"bg\", \"default\", 0.0);\n" - " set_state(PART:\"bg\", \"custom\", 0.0);\n" - " set_float(prev_x, 0.0); set_float(prev_y, 0.0);\n" - "} } } } }\n" - , fstrip, enc, w, h, (double)w / (double)h, (double)w / (double)h, fstrip); - setlocale(LC_NUMERIC, locale); - break; - - default: - /* won't happen */ - break; - } - free(fstrip); - - fclose(f); - - snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s", - ipart, tmpn, e_util_filename_escape(buf)); - - import->tmpf = strdup(tmpn); - import->fdest = strdup(buf); - import->exe_handler = - ecore_event_handler_add(ECORE_EXE_EVENT_DEL, - _import_cb_edje_cc_exit, import); - import->exe = ecore_exe_run(cmd, NULL); -} - -static Eina_Bool -_import_cb_edje_cc_exit(void *data, __UNUSED__ int type, void *event) -{ - Import *import; - FSel *fsel; - Ecore_Exe_Event_Del *ev; - char *fdest; - int r = 1; - - ev = event; - import = data; - if (ev->exe != import->exe) return ECORE_CALLBACK_PASS_ON; - - if (ev->exit_code != 0) - { - e_util_dialog_show(_("Picture Import Error"), - _("Enlightenment was unable to import the picture
" - "due to conversion errors.")); - r = 0; - } - - fsel = import->fsel; - fdest = strdup(import->fdest); - e_int_config_wallpaper_import_del(import->win); - if (fsel) - { - if ((r) && (fsel->parent)) - e_int_config_wallpaper_update(fsel->parent, fdest); - e_int_config_wallpaper_fsel_del(fsel->win); - } - else - { - if (r) - { - e_bg_default_set(fdest); - e_bg_update(); - } - } - E_FREE(fdest); - - return ECORE_CALLBACK_DONE; -} - -static void -_import_cb_delete(E_Win *win) -{ - e_int_config_wallpaper_import_del(win); -} - -static void -_import_cb_resize(E_Win *win) -{ - Import *import; - - if (!(import = win->data)) return; - evas_object_resize(import->bg_obj, win->w, win->h); -} - -static void -_import_cb_close(void *data, void *data2 __UNUSED__) -{ - E_Win *win; - - win = data; - e_int_config_wallpaper_import_del(win); -} - -static void -_import_cb_ok(void *data, void *data2 __UNUSED__) -{ - Import *import; - FSel *fsel; - E_Win *win; - const char *file; - char buf[PATH_MAX]; - int is_bg, is_theme, r; - - r = 0; - win = data; - if (!(import = win->data)) return; - if (import->cfdata->file) - { - file = ecore_file_file_get(import->cfdata->file); - if (!e_util_glob_case_match(file, "*.edj")) - { - _import_edj_gen(import); - e_win_hide(win); - return; - } - else - { - e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); - - is_bg = edje_file_group_exists(import->cfdata->file, - "e/desktop/background"); - is_theme = - edje_file_group_exists(import->cfdata->file, - "e/widgets/border/default/border"); - - if ((is_bg) && (!is_theme)) - { - if (!ecore_file_cp(import->cfdata->file, buf)) - { - e_util_dialog_show(_("Wallpaper Import Error"), - _("Enlightenment was unable to " - "import the wallpaper
due to a " - "copy error.")); - } - else - r = 1; - } - else - { - e_util_dialog_show(_("Wallpaper Import Error"), - _("Enlightenment was unable to " - "import the wallpaper.

" - "Are you sure this is a valid " - "wallpaper?")); - } - } - } - - fsel = import->fsel; - e_int_config_wallpaper_import_del(win); - if (fsel) - { - if ((r) && (fsel->parent)) - e_int_config_wallpaper_update(fsel->parent, buf); - e_int_config_wallpaper_fsel_del(fsel->win); - } - else - { - if (r) - { - e_bg_default_set(buf); - e_bg_update(); - } - } -} - -static void -_fsel_cb_delete(E_Win *win) -{ - e_int_config_wallpaper_fsel_del(win); -} - -static void -_fsel_cb_resize(E_Win *win) -{ - FSel *fsel; - - if (!(fsel = win->data)) return; - evas_object_resize(fsel->bg_obj, win->w, win->h); -} - -static void -_fsel_cb_close(void *data, void *data2 __UNUSED__) -{ - E_Win *win; - - win = data; - e_int_config_wallpaper_fsel_del(win); -} - -static void -_fsel_cb_ok(void *data, void *data2 __UNUSED__) -{ - FSel *fsel; - E_Win *win; - const char *path, *p; - - win = data; - if (!(fsel = win->data)) return; - path = e_widget_fsel_selection_path_get(fsel->fsel_obj); - if (!path) return; - - p = strrchr(path, '.'); - if ((!p) || (!strcasecmp(p, ".edj"))) - { - int is_bg, is_theme, r; - const char *file; - char buf[PATH_MAX]; - - r = 0; - file = ecore_file_file_get(path); - e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s", file); - - is_bg = edje_file_group_exists(path, "e/desktop/background"); - is_theme = - edje_file_group_exists(path, "e/widgets/border/default/border"); - - if ((is_bg) && (!is_theme)) - { - if (!ecore_file_cp(path, buf)) - { - e_util_dialog_show(_("Wallpaper Import Error"), - _("Enlightenment was unable to " - "import the wallpaper
due to a " - "copy error.")); - } - else - r = 1; - } - else - { - e_util_dialog_show(_("Wallpaper Import Error"), - _("Enlightenment was unable to " - "import the wallpaper.

" - "Are you sure this is a valid " - "wallpaper?")); - } - - if ((r) && (fsel->parent)) - e_int_config_wallpaper_update(fsel->parent, buf); - e_int_config_wallpaper_fsel_del(fsel->win); - } - else - e_int_config_wallpaper_import(fsel, path); -} - -static void -_import_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event) -{ - Evas_Event_Key_Down *ev; - Import *import; - - ev = event; - import = data; - if (!strcmp(ev->keyname, "Tab")) - { - if (evas_key_modifier_is_set(evas_key_modifier_get(e_win_evas_get(import->win)), "Shift")) - { - if (e_widget_focus_get(import->box_obj)) - { - if (!e_widget_focus_jump(import->box_obj, 0)) - { - e_widget_focus_set(import->content_obj, 0); - if (!e_widget_focus_get(import->content_obj)) - e_widget_focus_set(import->box_obj, 0); - } - } - else - { - if (!e_widget_focus_jump(import->content_obj, 0)) - e_widget_focus_set(import->box_obj, 0); - } - } - else - { - if (e_widget_focus_get(import->box_obj)) - { - if (!e_widget_focus_jump(import->box_obj, 1)) - { - e_widget_focus_set(import->content_obj, 1); - if (!e_widget_focus_get(import->content_obj)) - e_widget_focus_set(import->box_obj, 1); - } - } - else - { - if (!e_widget_focus_jump(import->content_obj, 1)) - e_widget_focus_set(import->box_obj, 1); - } - } - } - else if (((!strcmp(ev->keyname, "Return")) || - (!strcmp(ev->keyname, "KP_Enter")) || - (!strcmp(ev->keyname, "space")))) - { - Evas_Object *o = NULL; - - if ((import->content_obj) && (e_widget_focus_get(import->content_obj))) - o = e_widget_focused_object_get(import->content_obj); - else - o = e_widget_focused_object_get(import->box_obj); - if (o) e_widget_activate(o); - } -} - -static void -_fsel_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event) -{ - Evas_Event_Key_Down *ev; - FSel *fsel; - - ev = event; - fsel = data; - if ((!e_widget_fsel_typebuf_visible_get(fsel->fsel_obj)) && (!strcmp(ev->keyname, "Tab"))) - { - if (evas_key_modifier_is_set(evas_key_modifier_get(e_win_evas_get(fsel->win)), "Shift")) - { - if (e_widget_focus_get(fsel->box_obj)) - { - if (!e_widget_focus_jump(fsel->box_obj, 0)) - { - e_widget_focus_set(fsel->content_obj, 0); - if (!e_widget_focus_get(fsel->content_obj)) - e_widget_focus_set(fsel->box_obj, 0); - } - } - else - { - if (!e_widget_focus_jump(fsel->content_obj, 0)) - e_widget_focus_set(fsel->box_obj, 0); - } - } - else - { - if (e_widget_focus_get(fsel->box_obj)) - { - if (!e_widget_focus_jump(fsel->box_obj, 1)) - { - e_widget_focus_set(fsel->content_obj, 1); - if (!e_widget_focus_get(fsel->content_obj)) - e_widget_focus_set(fsel->box_obj, 1); - } - } - else - { - if (!e_widget_focus_jump(fsel->content_obj, 1)) - e_widget_focus_set(fsel->box_obj, 1); - } - } - } - else if (((!strcmp(ev->keyname, "Return")) || - (!strcmp(ev->keyname, "KP_Enter")) || - (!strcmp(ev->keyname, "space")))) - { - Evas_Object *o = NULL; - - if ((fsel->content_obj) && (e_widget_focus_get(fsel->content_obj))) - o = e_widget_focused_object_get(fsel->content_obj); - else - o = e_widget_focused_object_get(fsel->box_obj); - if (o) e_widget_activate(o); - } -} - diff --git a/src/modules/conf_theme/e_int_config_wallpaper_import.h b/src/modules/conf_theme/e_int_config_wallpaper_import.h deleted file mode 100644 index 7eabaa898..000000000 --- a/src/modules/conf_theme/e_int_config_wallpaper_import.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef E_TYPEDEFS -#else -#ifndef E_INT_CONFIG_WALLPAPER_IMPORT_H -#define E_INT_CONFIG_WALLPAPER_IMPORT_H - -E_Win *e_int_config_wallpaper_fsel(E_Config_Dialog *parent); -E_Win *e_int_config_wallpaper_import(void *data, const char *path); -void e_int_config_wallpaper_del(E_Win *win); -void e_int_config_wallpaper_fsel_del(E_Win *win); -void e_int_config_wallpaper_import_del(E_Win *win); - -#endif -#endif diff --git a/src/modules/conf_theme/e_mod_main.h b/src/modules/conf_theme/e_mod_main.h index 758c05ae4..1f3df4519 100644 --- a/src/modules/conf_theme/e_mod_main.h +++ b/src/modules/conf_theme/e_mod_main.h @@ -12,7 +12,6 @@ #include "e_int_config_theme_web.h" #include "e_int_config_transitions.h" #include "e_int_config_wallpaper.h" -#include "e_int_config_wallpaper_import.h" #include "e_int_config_wallpaper_web.h" #undef E_TYPEDEFS @@ -26,7 +25,6 @@ #include "e_int_config_theme_web.h" #include "e_int_config_transitions.h" #include "e_int_config_wallpaper.h" -#include "e_int_config_wallpaper_import.h" #include "e_int_config_wallpaper_web.h" EAPI extern E_Module_Api e_modapi;