3 EAPI E_Path *path_data = NULL;
4 EAPI E_Path *path_images = NULL;
5 EAPI E_Path *path_fonts = NULL;
6 EAPI E_Path *path_themes = NULL;
7 EAPI E_Path *path_icons = NULL;
8 EAPI E_Path *path_modules = NULL;
9 EAPI E_Path *path_backgrounds = NULL;
10 EAPI E_Path *path_messages = NULL;
12 typedef struct _E_Util_Fake_Mouse_Up_Info E_Util_Fake_Mouse_Up_Info;
13 typedef struct _E_Util_Image_Import_Settings E_Util_Image_Import_Settings;
15 struct _E_Util_Fake_Mouse_Up_Info
21 struct _E_Util_Image_Import_Settings
26 void (*func)(void *data, const char *path, Eina_Bool ok, Eina_Bool external, int quality, E_Image_Import_Mode mode);
36 struct _E_Util_Image_Import_Handle
39 Ecore_Event_Handler *handler;
42 void (*func)(void *data, Eina_Bool ok, const char *image_path, const char *edje_path);
47 const char *image, *edje, *temp;
51 /* local subsystem functions */
52 static Eina_Bool _e_util_cb_delayed_del(void *data);
53 static Eina_Bool _e_util_wakeup_cb(void *data);
55 static void _e_util_image_import_settings_do(void *data, E_Dialog *dia);
56 static void _e_util_image_import_settings_del(void *obj);
58 static Eina_Bool _e_util_image_import_exit(void *data, int type __UNUSED__, void *event);
59 static void _e_util_image_import_handle_free(E_Util_Image_Import_Handle *handle);
60 static Evas_Object *_e_util_icon_add(const char *path, Evas *evas, int size);
62 /* local subsystem globals */
63 static Ecore_Timer *_e_util_dummy_timer = NULL;
65 /* externally accessible functions */
69 if (_e_util_dummy_timer) return;
70 _e_util_dummy_timer = ecore_timer_add(0.0, _e_util_wakeup_cb, NULL);
74 e_util_env_set(const char *var, const char *val)
83 snprintf(buf, sizeof(buf), "%s=%s", var, val);
95 if (getenv(var)) putenv(var);
101 e_util_zone_current_get(E_Manager *man)
105 E_OBJECT_CHECK_RETURN(man, NULL);
106 E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);
107 con = e_container_current_get(man);
112 zone = e_zone_current_get(con);
119 e_util_glob_match(const char *str, const char *glob)
121 if ((!str) || (!glob)) return 0;
124 if (str[0] == 0) return 1;
127 if (!strcmp(glob, "*")) return 1;
128 if (!fnmatch(glob, str, 0)) return 1;
133 e_util_glob_case_match(const char *str, const char *glob)
136 char *tstr, *tglob, *tp;
140 if (str[0] == 0) return 1;
143 if (!strcmp(glob, "*")) return 1;
144 tstr = alloca(strlen(str) + 1);
145 for (tp = tstr, p = str; *p != 0; p++, tp++) *tp = tolower(*p);
147 tglob = alloca(strlen(glob) + 1);
148 for (tp = tglob, p = glob; *p != 0; p++, tp++) *tp = tolower(*p);
150 if (!fnmatch(tglob, tstr, 0)) return 1;
155 e_util_container_number_get(int num)
160 EINA_LIST_FOREACH(e_manager_list(), l, man)
164 con = e_container_number_get(man, num);
171 e_util_container_zone_number_get(int con_num, int zone_num)
175 con = e_util_container_number_get(con_num);
176 if (!con) return NULL;
177 return e_container_zone_number_get(con, zone_num);
181 e_util_container_zone_id_get(int con_num, int id)
185 con = e_util_container_number_get(con_num);
186 if (!con) return NULL;
187 return e_container_zone_id_get(con, id);
191 e_util_head_exec(int head, const char *cmd)
195 char buf[PATH_MAX], buf2[32];
199 penv_display = getenv("DISPLAY");
200 if (!penv_display) return 0;
201 penv_display = strdup(penv_display);
203 p1 = strrchr(penv_display, ':');
204 p2 = strrchr(penv_display, '.');
205 if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
207 /* yes it could overflow... but who will overflow DISPLAY eh? why? to
208 * "exploit" your own applications running as you?
210 strcpy(buf, penv_display);
211 buf[p2 - penv_display + 1] = 0;
212 snprintf(buf2, sizeof(buf2), "%i", head);
215 else if (p1) /* "blah:x */
217 strcpy(buf, penv_display);
218 snprintf(buf2, sizeof(buf2), ".%i", head);
222 strcpy(buf, penv_display);
225 e_util_library_path_strip();
226 exe = ecore_exe_run(cmd, NULL);
227 e_util_library_path_restore();
230 e_util_dialog_show(_("Run Error"),
231 _("Enlightenment was unable to fork a child process:<br>"
241 e_util_env_set("DISPLAY", penv_display);
248 e_util_strcmp(const char *s1, const char *s2)
251 return strcmp(s1, s2);
256 e_util_both_str_empty(const char *s1, const char *s2)
260 if ((!s1) && (!s2)) return 1;
261 if ((!s1) || ((s1) && (s1[0] == 0))) empty++;
262 if ((!s2) || ((s2) && (s2[0] == 0))) empty++;
263 if (empty == 2) return 1;
268 e_util_immortal_check(void)
272 wins = e_border_immortal_windows_get();
275 e_util_dialog_show(_("Cannot exit - immortal windows."),
276 _("Some windows are left still around with the Lifespan lock enabled. This means<br>"
277 "that Enlightenment will not allow itself to exit until these windows have<br>"
278 "been closed or have the lifespan lock removed.<br>"));
279 /* FIXME: should really display a list of these lifespan locked */
280 /* windows in a dialog and let the user disable their locks in */
282 eina_list_free(wins);
289 e_util_edje_icon_list_check(const char *list)
295 if ((!list) || (!list[0])) return 0;
296 buf = alloca(strlen(list) + 1);
303 strncpy(buf, p, c - p);
305 if (e_util_edje_icon_check(buf)) return 1;
312 if (e_util_edje_icon_check(buf)) return 1;
320 e_util_edje_icon_list_set(Evas_Object *obj, const char *list)
326 if ((!list) || (!list[0])) return 0;
327 buf = alloca(strlen(list) + 1);
334 strncpy(buf, p, c - p);
336 if (e_util_edje_icon_set(obj, buf)) return 1;
343 if (e_util_edje_icon_set(obj, buf)) return 1;
351 e_util_menu_item_edje_icon_list_set(E_Menu_Item *mi, const char *list)
357 if ((!list) || (!list[0])) return 0;
358 buf = alloca(strlen(list) + 1);
365 strncpy(buf, p, c - p);
367 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
374 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
382 e_util_edje_icon_check(const char *name)
387 if ((!name) || (!name[0])) return 0;
388 snprintf(buf, sizeof(buf), "e/icons/%s", name);
389 file = e_theme_edje_file_get("base/theme/icons", buf);
390 if (file[0]) return 1;
395 /* WARNING This function is deprecated,. must be made static.
396 * You should use e_util_icon_theme_set instead
399 e_util_edje_icon_set(Evas_Object *obj, const char *name)
404 if ((!name) || (!name[0])) return 0;
405 snprintf(buf, sizeof(buf), "e/icons/%s", name);
406 file = e_theme_edje_file_get("base/theme/icons", buf);
409 edje_object_file_set(obj, file, buf);
416 _e_util_icon_theme_set(Evas_Object *obj, const char *icon, Eina_Bool fallback)
421 if ((!icon) || (!icon[0])) return 0;
422 snprintf(buf, sizeof(buf), "e/icons/%s", icon);
425 file = e_theme_edje_icon_fallback_file_get(buf);
427 file = e_theme_edje_file_get("base/theme/icons", buf);
431 e_icon_file_edje_set(obj, file, buf);
439 _e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
441 const char *path = NULL;
444 if ((!icon) || (!icon[0])) return 0;
445 size = e_icon_scale_size_get(obj);
446 if (size < 16) size = 16;
447 size = e_util_icon_size_normalize(size * e_scale);
449 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
452 e_icon_file_set(obj, path);
456 /* use e_icon_size_scale_set(obj, size) to set the preferred icon size */
458 e_util_icon_theme_set(Evas_Object *obj, const char *icon)
460 if (e_config->icon_theme_overrides)
462 if (_e_util_icon_fdo_set(obj, icon))
464 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
466 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
470 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
472 if (_e_util_icon_fdo_set(obj, icon))
474 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
479 _e_util_menu_item_edje_icon_set(E_Menu_Item *mi, const char *name, Eina_Bool fallback)
484 if ((!name) || (!name[0])) return 0;
486 if ((!fallback) && (name[0]=='/') && ecore_file_exists(name))
488 e_menu_item_icon_edje_set(mi, name, "icon");
491 snprintf(buf, sizeof(buf), "e/icons/%s", name);
494 file = e_theme_edje_icon_fallback_file_get(buf);
496 file = e_theme_edje_file_get("base/theme/icons", buf);
500 e_menu_item_icon_edje_set(mi, file, buf);
507 e_util_icon_size_normalize(unsigned int desired)
509 const unsigned int *itr, known_sizes[] =
511 16, 22, 24, 32, 36, 48, 64, 72, 96, 128, 192, 256, -1
514 for (itr = known_sizes; *itr > 0; itr++)
518 return 256; /* largest know size? */
522 _e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
524 const char *path = NULL;
527 if ((!icon) || (!icon[0])) return 0;
528 size = e_util_icon_size_normalize(24 * e_scale);
529 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
531 e_menu_item_icon_file_set(mi, path);
536 e_util_menu_item_theme_icon_set(E_Menu_Item *mi, const char *icon)
538 if (e_config->icon_theme_overrides)
540 if (_e_util_menu_item_fdo_icon_set(mi, icon))
542 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
544 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
548 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
550 if (_e_util_menu_item_fdo_icon_set(mi, icon))
552 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
557 e_util_container_window_find(Ecore_X_Window win)
563 EINA_LIST_FOREACH(e_manager_list(), l, man)
565 EINA_LIST_FOREACH(man->containers, ll, con)
567 if ((con->win == win) || (con->bg_win == win) ||
568 (con->event_win == win))
576 e_util_zone_window_find(Ecore_X_Window win)
578 Eina_List *l, *ll, *lll;
583 EINA_LIST_FOREACH(e_manager_list(), l, man)
584 EINA_LIST_FOREACH(man->containers, ll, con)
585 EINA_LIST_FOREACH(con->zones, lll, zone)
586 if (zone->black_win == win) return zone;
592 e_util_desk_border_above(E_Border *bd)
594 E_Border *bd2, *above = NULL;
598 E_OBJECT_CHECK_RETURN(bd, NULL);
599 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
601 if (bd->layer == 0) pos = 0;
602 else if ((bd->layer > 0) && (bd->layer <= 50)) pos = 1;
603 else if ((bd->layer > 50) && (bd->layer <= 100)) pos = 2;
604 else if ((bd->layer > 100) && (bd->layer <= 150)) pos = 3;
605 else if ((bd->layer > 150) && (bd->layer <= 200)) pos = 4;
608 EINA_LIST_FOREACH(eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd), l, bd2)
610 if(!eina_list_next(l) || above) break;
611 above = eina_list_data_get(eina_list_next(l));
612 if ((above->desk != bd->desk) && (!above->sticky))
617 /* Need to check the layers above */
618 for (i = pos + 1; (i < 7) && (!above); i++)
620 EINA_LIST_FOREACH(bd->zone->container->layers[i].clients, l, bd2)
624 if ((above->desk != bd->desk) && (!above->sticky))
633 e_util_desk_border_below(E_Border *bd)
635 E_Border *below = NULL, *bd2;
639 E_OBJECT_CHECK_RETURN(bd, NULL);
640 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
642 if (bd->layer == 0) pos = 0;
643 else if ((bd->layer > 0) && (bd->layer <= 50)) pos = 1;
644 else if ((bd->layer > 50) && (bd->layer <= 100)) pos = 2;
645 else if ((bd->layer > 100) && (bd->layer <= 150)) pos = 3;
646 else if ((bd->layer > 150) && (bd->layer <= 200)) pos = 4;
649 for (l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd); l; l = l->prev)
651 if (!eina_list_prev(l) || below) break;
652 below = eina_list_data_get(eina_list_prev(l));
653 if ((below->desk != bd->desk) && (!below->sticky))
658 /* Need to check the layers below */
659 for (i = pos - 1; (i >= 0) && (!below); i--)
661 if (bd->zone->container->layers[i].clients)
663 l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd);
664 for (; l && !below; l = l->prev)
668 if ((below->desk != bd->desk) && (!below->sticky))
679 e_util_edje_collection_exists(const char *file, const char *coll)
681 Eina_List *clist, *l;
684 clist = edje_file_collection_list(file);
685 EINA_LIST_FOREACH(clist, l, str)
687 if (!strcmp(coll, str))
689 edje_file_collection_list_free(clist);
693 edje_file_collection_list_free(clist);
698 e_util_dialog_internal(const char *title, const char *txt)
702 dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_error_dialog");
704 e_dialog_title_set(dia, title);
705 e_dialog_text_set(dia, txt);
706 e_dialog_icon_set(dia, "dialog-error", 64);
707 e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
708 e_dialog_button_focus_num(dia, 0);
709 e_win_centered_set(dia->win, 1);
714 e_util_filename_escape(const char *filename)
718 static char buf[PATH_MAX];
720 if (!filename) return NULL;
725 if ((q - buf) > 4090) return NULL;
727 (*p == ' ') || (*p == '\t') || (*p == '\n') ||
728 (*p == '\\') || (*p == '\'') || (*p == '\"') ||
729 (*p == ';') || (*p == '!') || (*p == '#') ||
730 (*p == '$') || (*p == '%') || (*p == '&') ||
731 (*p == '*') || (*p == '(') || (*p == ')') ||
732 (*p == '[') || (*p == ']') || (*p == '{') ||
733 (*p == '}') || (*p == '|') || (*p == '<') ||
734 (*p == '>') || (*p == '?')
749 e_util_icon_save(Ecore_X_Icon *icon, const char *filename)
756 ee = ecore_evas_buffer_new(icon->width, icon->height);
758 evas = ecore_evas_get(ee);
759 evas_image_cache_set(evas, 0);
760 evas_font_cache_set(evas, 0);
762 im = evas_object_image_add(evas);
768 evas_object_move(im, 0, 0);
769 evas_object_resize(im, icon->width, icon->height);
770 evas_object_image_size_set(im, icon->width, icon->height);
771 evas_object_image_data_copy_set(im, icon->data);
772 evas_object_image_alpha_set(im, 1);
773 evas_object_show(im);
774 ret = evas_object_image_save(im, filename, NULL, NULL);
781 e_util_shell_env_path_eval(const char *path)
783 /* evaluate things like:
784 * $HOME/bling -> /home/user/bling
785 * $HOME/bin/$HOSTNAME/blah -> /home/user/bin/localhost/blah
788 const char *p, *v2, *v1 = NULL;
789 char buf[PATH_MAX], *pd, *s, *vp;
791 int esc = 0, invar = 0;
793 for (p = path, pd = buf; (pd < (buf + sizeof(buf) - 1)); p++)
797 if (!((isalnum(*p)) || (*p == '_')))
804 strncpy(s, v1 + 1, v2 - v1 - 1);
806 if (strncmp(s, "XDG", 3))
810 if (!strcmp(s, "XDG_CONFIG_HOME"))
811 v = (char *)efreet_config_home_get();
812 else if (!strcmp(s, "XDG_CACHE_HOME"))
813 v = (char *)efreet_cache_home_get();
814 else if (!strcmp(s, "XDG_DATA_HOME"))
815 v = (char *)efreet_data_home_get();
821 while ((*vp) && (pd < (buf + sizeof(buf) - 1)))
829 if (pd < (buf + sizeof(buf) - 1))
845 if (*p == '\\') esc = 1;
865 e_util_size_string_get(off_t size)
870 dsize = (double)size;
871 if (dsize < 1024.0) snprintf(buf, sizeof(buf), _("%'.0f Bytes"), dsize);
875 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f KB"), dsize);
879 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f MB"), dsize);
883 snprintf(buf, sizeof(buf), _("%'.1f GB"), dsize);
891 e_util_file_time_get(time_t ftime)
899 diff = ltime - ftime;
902 snprintf(buf, sizeof(buf), _("In the Future"));
906 snprintf(buf, sizeof(buf), _("In the last Minute"));
907 else if (diff >= 31526000)
908 snprintf(buf, sizeof(buf), _("%li Years ago"), (diff / 31526000));
909 else if (diff >= 2592000)
910 snprintf(buf, sizeof(buf), _("%li Months ago"), (diff / 2592000));
911 else if (diff >= 604800)
912 snprintf(buf, sizeof(buf), _("%li Weeks ago"), (diff / 604800));
913 else if (diff >= 86400)
914 snprintf(buf, sizeof(buf), _("%li Days ago"), (diff / 86400));
915 else if (diff >= 3600)
916 snprintf(buf, sizeof(buf), _("%li Hours ago"), (diff / 3600));
918 snprintf(buf, sizeof(buf), _("%li Minutes ago"), (diff / 60));
924 s = strdup(_("Unknown"));
928 static char *prev_ld_library_path = NULL;
929 static char *prev_path = NULL;
932 e_util_library_path_strip(void)
936 p = getenv("LD_LIBRARY_PATH");
937 E_FREE(prev_ld_library_path);
940 prev_ld_library_path = strdup(p);
943 e_util_env_set("LD_LIBRARY_PATH", p2);
949 prev_path = strdup(p);
952 e_util_env_set("PATH", p2);
957 e_util_library_path_restore(void)
959 if (prev_ld_library_path)
961 e_util_env_set("LD_LIBRARY_PATH", prev_ld_library_path);
962 E_FREE(prev_ld_library_path);
966 e_util_env_set("PATH", prev_path);
972 e_util_icon_add(const char *path, Evas *evas)
974 return _e_util_icon_add(path, evas, 64);
978 e_util_desktop_icon_add(Efreet_Desktop *desktop, unsigned int size, Evas *evas)
980 if ((!desktop) || (!desktop->icon)) return NULL;
981 return e_util_icon_theme_icon_add(desktop->icon, size, evas);
985 e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
987 if (!icon_name) return NULL;
988 if (icon_name[0] == '/') return _e_util_icon_add(icon_name, evas, size);
994 path = efreet_icon_path_find(e_config->icon_theme, icon_name, size);
997 obj = _e_util_icon_add(path, evas, size);
1005 e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_Menu_Item *mi)
1007 const char *path = NULL;
1009 if ((!desktop) || (!desktop->icon)) return;
1011 if (desktop->icon[0] == '/') path = desktop->icon;
1012 else path = efreet_icon_path_find(e_config->icon_theme, desktop->icon, size);
1018 ext = strrchr(path, '.');
1021 if (strcmp(ext, ".edj") == 0)
1022 e_menu_item_icon_edje_set(mi, path, "icon");
1024 e_menu_item_icon_file_set(mi, path);
1027 e_menu_item_icon_file_set(mi, path);
1032 e_util_dir_check(const char *dir)
1034 if (!ecore_file_exists(dir))
1036 if (!ecore_file_mkpath(dir))
1038 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>Check that you have correct permissions set.", dir);
1044 if (!ecore_file_is_dir(dir))
1046 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>A file of that name already exists.", dir);
1054 e_util_defer_object_del(E_Object *obj)
1059 ecore_idle_enterer_before_add(_e_util_cb_delayed_del, obj);
1063 e_util_winid_str_get(Ecore_X_Window win)
1065 const char *vals = "qWeRtYuIoP5-$&<~";
1069 val = (unsigned int)win;
1070 id[0] = vals[(val >> 28) & 0xf];
1071 id[1] = vals[(val >> 24) & 0xf];
1072 id[2] = vals[(val >> 20) & 0xf];
1073 id[3] = vals[(val >> 16) & 0xf];
1074 id[4] = vals[(val >> 12) & 0xf];
1075 id[5] = vals[(val >> 8) & 0xf];
1076 id[6] = vals[(val >> 4) & 0xf];
1077 id[7] = vals[(val ) & 0xf];
1083 _win_auto_size_calc(int max, int min)
1085 const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1};
1087 for (itr = scales; *itr > 0; itr++)
1089 int value = *itr * max;
1090 if (value > min) /* not >=, try a bit larger */
1098 e_util_win_auto_resize_fill(E_Win *win)
1100 E_Zone *zone = NULL;
1103 zone = win->border->zone;
1104 if ((!zone) && (win->container))
1105 zone = e_util_zone_current_get(win->container->manager);
1111 e_zone_useful_geometry_get(zone, NULL, NULL, &w, &h);
1113 w = _win_auto_size_calc(w, win->min_w);
1114 h = _win_auto_size_calc(h, win->min_h);
1115 e_win_resize(win, w, h);
1120 * Creates a new dialog to query image import settings, report results.
1122 * @param path may be used to display live preview (not used so far).
1123 * @param cb function to call before exit. Last parameter is mode of
1125 * @param data extra data to give to @a cb as first argument.
1127 * @return newly allocated window on success, @c NULL on failure. If
1128 * @c NULL is returned, then callback is never called!
1131 e_util_image_import_settings_new(const char *path, void (*cb)(void *data, const char *path, Eina_Bool ok, Eina_Bool external, int quality, E_Image_Import_Mode mode), const void *data)
1134 E_Util_Image_Import_Settings *ctxt;
1135 Evas_Object *vlist, *frame, *radio, *check, *slider;
1139 if (!path) return NULL;
1140 if (!cb) return NULL;
1142 ctxt = E_NEW(E_Util_Image_Import_Settings, 1);
1143 if (!ctxt) return NULL;
1145 ctxt->dia = e_dialog_new(NULL, "E", "_image_import_settings");
1152 ctxt->dia->data = ctxt;
1154 e_object_del_attach_func_set
1155 (E_OBJECT(ctxt->dia), _e_util_image_import_settings_del);
1156 e_dialog_title_set(ctxt->dia, _("Image Import Settings"));
1157 e_dialog_border_icon_set(ctxt->dia, "dialog-ask");
1160 (ctxt->dia, _("Import"), NULL, _e_util_image_import_settings_do, ctxt);
1162 (ctxt->dia, _("Cancel"), NULL, NULL, ctxt);
1163 e_dialog_button_focus_num(ctxt->dia, 0);
1166 ctxt->cb.data = (void *)data;
1167 ctxt->path = eina_stringshare_add(path);
1169 ctxt->ok = EINA_FALSE;
1170 ctxt->external = EINA_FALSE;
1171 ctxt->mode = E_IMAGE_IMPORT_STRETCH;
1173 evas = e_win_evas_get(ctxt->dia->win);
1175 vlist = e_widget_list_add(evas, 0, 0);
1177 frame = e_widget_frametable_add(evas, _("Fill and Stretch Options"), 1);
1178 rg = e_widget_radio_group_new(&ctxt->mode);
1180 #define RD(lbl, icon, val, col, row) \
1181 radio = e_widget_radio_icon_add \
1182 (evas, lbl, "enlightenment/wallpaper_"icon, 24, 24, val, rg); \
1183 e_widget_frametable_object_append(frame, radio, col, row, 1, 1, 1, 1, 0, 0)
1185 RD(_("Stretch"), "stretch", E_IMAGE_IMPORT_STRETCH, 0, 0);
1186 RD(_("Center"), "center", E_IMAGE_IMPORT_CENTER, 1, 0);
1187 RD(_("Title"), "tile", E_IMAGE_IMPORT_TILE, 2, 0);
1188 RD(_("Within"), "scale_aspect_in", E_IMAGE_IMPORT_SCALE_ASPECT_IN, 3, 0);
1189 RD(_("Fill"), "scale_aspect_out", E_IMAGE_IMPORT_SCALE_ASPECT_OUT, 4, 0);
1192 e_widget_list_object_append(vlist, frame, 1, 1, 0.5);
1194 frame = e_widget_frametable_add(evas, _("File Quality"), 0);
1196 check = e_widget_check_add(evas, _("Use original file"), &ctxt->external);
1197 e_widget_frametable_object_append(frame, check, 0, 0, 1, 1, 1, 0, 1, 0);
1199 slider = e_widget_slider_add
1200 (evas, 1, 0, _("%3.0f%%"), 0.0, 100.0, 1.0, 0, NULL, &ctxt->quality, 150);
1201 e_widget_frametable_object_append(frame, slider, 0, 1, 1, 1, 1, 0, 1, 0);
1203 e_widget_list_object_append(vlist, frame, 1, 1, 0.5);
1205 e_widget_size_min_get(vlist, &w, &h);
1207 e_dialog_content_set(ctxt->dia, vlist, w, h);
1209 e_win_centered_set(ctxt->dia->win, 1);
1215 * Request given image to be imported as an edje file.
1217 * This is useful to convert images to icons and background.
1219 * @param image_path path to source image to use.
1220 * @param edje_path path to destination edje to generate.
1221 * @param external if @c EINA_TRUE, then it will not embed image into edje,
1222 * but reference the original @a image_path.
1223 * @param quality quality value from 0-100.
1224 * @param mode how to resize image with edje.
1225 * @param cb function to callback when process finishes.
1226 * @param data extra context to give to callback.
1228 * @return handle so one can cancel the operation. This handle will be
1229 * invalid after @a cb is called!
1231 EAPI E_Util_Image_Import_Handle *
1232 e_util_image_import(const char *image_path, const char *edje_path, const char *edje_group, Eina_Bool external, int quality, E_Image_Import_Mode mode, void (*cb)(void *data, Eina_Bool ok, const char *image_path, const char *edje_path), const void *data)
1234 static const char *tmpdir = NULL;
1235 E_Util_Image_Import_Handle *handle;
1239 const char *escaped_file;
1240 char cmd[PATH_MAX * 2], tmpn[PATH_MAX];
1243 if (!image_path) return NULL;
1244 if (!edje_path) return NULL;
1245 if (!edje_group) return NULL;
1246 if (!cb) return NULL;
1247 ee = ecore_evas_buffer_new(1, 1);
1248 img = evas_object_image_add(ecore_evas_get(ee));
1249 evas_object_image_file_set(img, image_path, NULL);
1250 if (evas_object_image_load_error_get(img) != EVAS_LOAD_ERROR_NONE)
1252 ecore_evas_free(ee);
1253 printf("Error loading image '%s'\n", image_path);
1256 evas_object_image_size_get(img, &w, &h);
1257 ecore_evas_free(ee);
1261 tmpdir = getenv("TMPDIR");
1262 if (!tmpdir) tmpdir = "/tmp";
1264 snprintf(tmpn, sizeof(tmpn), "%s/e_util_image_import-XXXXXX", tmpdir);
1268 printf("Error Creating tmp file: %s\n", strerror(errno));
1272 f = fdopen(fd, "wb");
1275 printf("Cannot open %s for writing\n", tmpn);
1280 escaped_file = e_util_filename_escape(image_path); // watch out ret buffer!
1282 fprintf(f, "images.image: \"%s\" ", escaped_file);
1285 else if (quality >= 100)
1288 fprintf(f, "LOSSY %d", (quality > 1) ? quality : 90);
1295 " data.item: \"style\" \"%d\";\n"
1298 edje_group, mode, w, h);
1300 if ((mode == E_IMAGE_IMPORT_CENTER) ||
1301 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN))
1306 " mouse_events: 0;\n"
1308 " state: \"default\" 0.0;\n"
1309 " color: 255 255 255 255;\n"
1318 " name: \"image\";\n"
1319 " mouse_events: 0;\n"
1321 " state: \"default\" 0.0;\n"
1323 " normal: \"%s\";\n"
1324 " scale_hint: STATIC;\n"
1328 if (mode == E_IMAGE_IMPORT_TILE)
1333 " relative: 0.0 0.0;\n"
1339 else if (mode == E_IMAGE_IMPORT_CENTER)
1347 else if ((mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN) ||
1348 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_OUT))
1350 const char *locale = e_intl_language_get();
1351 double aspect = (double)w / (double)h;
1352 setlocale(LC_NUMERIC, "C");
1354 " aspect: %1.9f %1.9f;\n"
1355 " aspect_preference: %s;\n",
1357 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN) ? "BOTH" : "NONE");
1358 setlocale(LC_NUMERIC, locale);
1361 fputs(" }\n" // description
1365 "}\n", // collections
1368 fclose(f); // fd gets closed here
1370 snprintf(cmd, sizeof(cmd), "edje_cc %s %s",
1371 tmpn, e_util_filename_escape(edje_path));
1373 handle = E_NEW(E_Util_Image_Import_Handle, 1);
1380 handle->cb.func = cb;
1381 handle->cb.data = (void *)data;
1382 handle->path.image = eina_stringshare_add(image_path);
1383 handle->path.edje = eina_stringshare_add(edje_path);
1384 handle->path.temp = eina_stringshare_add(tmpn);
1385 handle->handler = ecore_event_handler_add
1386 (ECORE_EXE_EVENT_DEL, _e_util_image_import_exit, handle);
1387 handle->exe = ecore_exe_run(cmd, NULL);
1390 _e_util_image_import_handle_free(handle);
1398 e_util_image_import_cancel(E_Util_Image_Import_Handle *handle)
1400 if (!handle) return;
1401 ecore_exe_kill(handle->exe);
1405 e_util_container_desk_count_get(E_Container *con)
1411 E_OBJECT_CHECK_RETURN(con, 0);
1412 E_OBJECT_TYPE_CHECK_RETURN(con, E_CONTAINER_TYPE, 0);
1413 EINA_LIST_FOREACH(con->zones, zl, zone)
1418 e_zone_desk_count_get(zone, &cx, &cy);
1419 for (x = 0; x < cx; x++)
1421 for (y = 0; y < cy; y++)
1428 /* local subsystem functions */
1430 static Evas_Object *
1431 _e_util_icon_add(const char *path, Evas *evas, int size)
1433 Evas_Object *o = NULL;
1436 if (!path) return NULL;
1437 if (!ecore_file_exists(path)) return NULL;
1439 o = e_icon_add(evas);
1440 e_icon_scale_size_set(o, size);
1441 e_icon_preload_set(o, 1);
1442 ext = strrchr(path, '.');
1445 if (!strcmp(ext, ".edj"))
1446 e_icon_file_edje_set(o, path, "icon");
1448 e_icon_file_set(o, path);
1451 e_icon_file_set(o, path);
1452 e_icon_fill_inside_set(o, 1);
1458 _e_util_cb_delayed_del(void *data)
1460 e_object_del(E_OBJECT(data));
1461 return ECORE_CALLBACK_CANCEL;
1465 _e_util_wakeup_cb(void *data __UNUSED__)
1467 _e_util_dummy_timer = NULL;
1468 return ECORE_CALLBACK_CANCEL;
1472 _e_util_image_import_settings_do(void *data, E_Dialog *dia)
1474 E_Util_Image_Import_Settings *ctxt = data;
1476 ctxt->ok = EINA_TRUE;
1477 e_util_defer_object_del(E_OBJECT(dia));
1481 _e_util_image_import_settings_del(void *obj)
1483 E_Dialog *dia = obj;
1484 E_Util_Image_Import_Settings *ctxt = dia->data;
1486 ctxt->cb.func(ctxt->cb.data, ctxt->path,
1487 ctxt->ok, ctxt->external, ctxt->quality, ctxt->mode);
1489 eina_stringshare_del(ctxt->path);
1494 _e_util_image_import_exit(void *data, int type __UNUSED__, void *event)
1496 E_Util_Image_Import_Handle *handle = data;
1497 Ecore_Exe_Event_Del *ev = event;
1500 if (ev->exe != handle->exe) return ECORE_CALLBACK_PASS_ON;
1502 ok = (ev->exit_code == 0);
1504 if (!ok) unlink(handle->path.edje);
1505 handle->cb.func(handle->cb.data, ok, handle->path.image, handle->path.edje);
1507 _e_util_image_import_handle_free(handle);
1509 return ECORE_CALLBACK_CANCEL;
1513 _e_util_image_import_handle_free(E_Util_Image_Import_Handle *handle)
1515 unlink(handle->path.temp);
1516 eina_stringshare_del(handle->path.image);
1517 eina_stringshare_del(handle->path.edje);
1518 eina_stringshare_del(handle->path.temp);
1519 if (handle->handler) ecore_event_handler_del(handle->handler);
1524 _e_util_conf_timer_old(void *data)
1526 char *module_name = data;
1529 _("Configuration data needed "
1530 "upgrading. Your old configuration<br> has been"
1531 " wiped and a new set of defaults initialized. "
1532 "This<br>will happen regularly during "
1533 "development, so don't report a<br>bug. "
1534 "This simply means the module needs "
1535 "new configuration<br>data by default for "
1536 "usable functionality that your old<br>"
1537 "configuration simply lacks. This new set of "
1538 "defaults will fix<br>that by adding it in. "
1539 "You can re-configure things now to your<br>"
1540 "liking. Sorry for the inconvenience.<br>");
1542 snprintf(buf, sizeof(buf),N_("%s Configuration Updated"), module_name);
1543 e_util_dialog_internal(buf, msg);
1544 E_FREE(module_name);
1546 return ECORE_CALLBACK_CANCEL;
1550 _e_util_conf_timer_new(void *data)
1552 char *module_name = data;
1555 _("Your module configuration is NEWER "
1556 "than the module version. This is "
1557 "very<br>strange. This should not happen unless"
1558 " you downgraded<br>the module or "
1559 "copied the configuration from a place where"
1560 "<br>a newer version of the module "
1561 "was running. This is bad and<br>as a "
1562 "precaution your configuration has been now "
1563 "restored to<br>defaults. Sorry for the "
1564 "inconvenience.<br>");
1566 snprintf(buf, sizeof(buf),N_("%s Configuration Updated"), module_name);
1567 e_util_dialog_internal(buf, msg);
1568 E_FREE(module_name);
1570 return ECORE_CALLBACK_CANCEL;
1574 e_util_module_config_check(const char *module_name, int loaded, int current)
1576 if ((loaded >> 16) < (current >> 16))
1578 ecore_timer_add(1.0, _e_util_conf_timer_old, strdup(module_name));
1581 else if (loaded > current)
1583 ecore_timer_add(1.0, _e_util_conf_timer_new, strdup(module_name));
1591 * Checks whenever the current manager/container/zone have fullscreen windows.
1594 e_util_fullscreen_curreny_any(void)
1596 E_Manager *man = e_manager_current_get();
1597 E_Container *con = e_container_current_get(man);
1598 E_Zone *zone = e_zone_current_get(con);
1601 if ((zone) && (zone->fullscreen > 0)) return EINA_TRUE;
1602 desk = e_desk_current_get(zone);
1603 if ((desk) && (desk->fullscreen_borders > 0)) return EINA_TRUE;
1608 * Checks whenever any manager/container/zone have fullscreen windows.
1611 e_util_fullscreen_any(void)
1614 Eina_List *lm, *lc, *lz;
1620 EINA_LIST_FOREACH(e_manager_list(), lm, man)
1622 EINA_LIST_FOREACH(man->containers, lc, con)
1624 EINA_LIST_FOREACH(con->zones, lz, zone)
1626 if (zone->fullscreen > 0) return EINA_TRUE;
1628 for (x = 0; x < zone->desk_x_count; x++)
1629 for (y = 0; y < zone->desk_y_count; y++)
1631 desk = e_desk_at_xy_get(zone, x, y);
1632 if ((desk) && (desk->fullscreen_borders > 0))