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;
14 EAPI int starting = 1;
15 EAPI int stopping = 0;
17 typedef struct _E_Util_Fake_Mouse_Up_Info E_Util_Fake_Mouse_Up_Info;
18 typedef struct _E_Util_Image_Import_Settings E_Util_Image_Import_Settings;
20 struct _E_Util_Fake_Mouse_Up_Info
26 struct _E_Util_Image_Import_Settings
31 void (*func)(void *data, const char *path, Eina_Bool ok, Eina_Bool external, int quality, E_Image_Import_Mode mode);
41 struct _E_Util_Image_Import_Handle
44 Ecore_Event_Handler *handler;
47 void (*func)(void *data, Eina_Bool ok, const char *image_path, const char *edje_path);
52 const char *image, *edje, *temp;
56 /* local subsystem functions */
57 static Eina_Bool _e_util_cb_delayed_del(void *data);
58 static Eina_Bool _e_util_wakeup_cb(void *data);
60 static void _e_util_image_import_settings_do(void *data, E_Dialog *dia);
61 static void _e_util_image_import_settings_del(void *obj);
63 static Eina_Bool _e_util_image_import_exit(void *data, int type __UNUSED__, void *event);
64 static void _e_util_image_import_handle_free(E_Util_Image_Import_Handle *handle);
65 static Evas_Object *_e_util_icon_add(const char *path, Evas *evas, int size);
67 /* local subsystem globals */
68 static Ecore_Timer *_e_util_dummy_timer = NULL;
70 /* externally accessible functions */
74 if (_e_util_dummy_timer) return;
75 _e_util_dummy_timer = ecore_timer_add(0.0, _e_util_wakeup_cb, NULL);
79 e_util_env_set(const char *var, const char *val)
88 snprintf(buf, sizeof(buf), "%s=%s", var, val);
100 if (getenv(var)) putenv(var);
106 e_util_zone_current_get(E_Manager *man)
110 E_OBJECT_CHECK_RETURN(man, NULL);
111 E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);
112 con = e_container_current_get(man);
117 zone = e_zone_current_get(con);
124 e_util_glob_match(const char *str, const char *glob)
126 if ((!str) || (!glob)) return 0;
129 if (str[0] == 0) return 1;
132 if (!strcmp(glob, "*")) return 1;
133 if (!fnmatch(glob, str, 0)) return 1;
138 e_util_glob_case_match(const char *str, const char *glob)
141 char *tstr, *tglob, *tp;
145 if (str[0] == 0) return 1;
148 if (!strcmp(glob, "*")) return 1;
149 tstr = alloca(strlen(str) + 1);
150 for (tp = tstr, p = str; *p != 0; p++, tp++) *tp = tolower(*p);
152 tglob = alloca(strlen(glob) + 1);
153 for (tp = tglob, p = glob; *p != 0; p++, tp++) *tp = tolower(*p);
155 if (!fnmatch(tglob, tstr, 0)) return 1;
160 e_util_container_number_get(int num)
165 EINA_LIST_FOREACH(e_manager_list(), l, man)
169 con = e_container_number_get(man, num);
176 e_util_container_zone_number_get(int con_num, int zone_num)
180 con = e_util_container_number_get(con_num);
181 if (!con) return NULL;
182 return e_container_zone_number_get(con, zone_num);
186 e_util_container_zone_id_get(int con_num, int id)
190 con = e_util_container_number_get(con_num);
191 if (!con) return NULL;
192 return e_container_zone_id_get(con, id);
196 e_util_head_exec(int head, const char *cmd)
200 char buf[PATH_MAX], buf2[32];
204 penv_display = getenv("DISPLAY");
205 if (!penv_display) return 0;
206 penv_display = strdup(penv_display);
208 p1 = strrchr(penv_display, ':');
209 p2 = strrchr(penv_display, '.');
210 if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
212 /* yes it could overflow... but who will overflow DISPLAY eh? why? to
213 * "exploit" your own applications running as you?
215 strcpy(buf, penv_display);
216 buf[p2 - penv_display + 1] = 0;
217 snprintf(buf2, sizeof(buf2), "%i", head);
220 else if (p1) /* "blah:x */
222 strcpy(buf, penv_display);
223 snprintf(buf2, sizeof(buf2), ".%i", head);
227 strcpy(buf, penv_display);
230 e_util_library_path_strip();
231 exe = ecore_exe_run(cmd, NULL);
232 e_util_library_path_restore();
235 e_util_dialog_show(_("Run Error"),
236 _("Enlightenment was unable to fork a child process:<br>"
246 e_util_env_set("DISPLAY", penv_display);
253 e_util_strcmp(const char *s1, const char *s2)
256 return strcmp(s1, s2);
261 e_util_both_str_empty(const char *s1, const char *s2)
265 if ((!s1) && (!s2)) return 1;
266 if ((!s1) || ((s1) && (s1[0] == 0))) empty++;
267 if ((!s2) || ((s2) && (s2[0] == 0))) empty++;
268 if (empty == 2) return 1;
273 e_util_immortal_check(void)
277 wins = e_border_immortal_windows_get();
280 e_util_dialog_show(_("Cannot exit - immortal windows."),
281 _("Some windows are left still around with the Lifespan lock enabled. This means<br>"
282 "that Enlightenment will not allow itself to exit until these windows have<br>"
283 "been closed or have the lifespan lock removed.<br>"));
284 /* FIXME: should really display a list of these lifespan locked */
285 /* windows in a dialog and let the user disable their locks in */
287 eina_list_free(wins);
294 e_util_edje_icon_list_check(const char *list)
300 if ((!list) || (!list[0])) return 0;
301 buf = alloca(strlen(list) + 1);
308 strncpy(buf, p, c - p);
310 if (e_util_edje_icon_check(buf)) return 1;
317 if (e_util_edje_icon_check(buf)) return 1;
325 e_util_edje_icon_list_set(Evas_Object *obj, const char *list)
331 if ((!list) || (!list[0])) return 0;
332 buf = alloca(strlen(list) + 1);
339 strncpy(buf, p, c - p);
341 if (e_util_edje_icon_set(obj, buf)) return 1;
348 if (e_util_edje_icon_set(obj, buf)) return 1;
356 e_util_menu_item_edje_icon_list_set(E_Menu_Item *mi, const char *list)
362 if ((!list) || (!list[0])) return 0;
363 buf = alloca(strlen(list) + 1);
370 strncpy(buf, p, c - p);
372 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
379 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
387 e_util_edje_icon_check(const char *name)
392 if ((!name) || (!name[0])) return 0;
393 snprintf(buf, sizeof(buf), "e/icons/%s", name);
394 file = e_theme_edje_file_get("base/theme/icons", buf);
395 if (file[0]) return 1;
400 /* WARNING This function is deprecated,. must be made static.
401 * You should use e_util_icon_theme_set instead
404 e_util_edje_icon_set(Evas_Object *obj, const char *name)
409 if ((!name) || (!name[0])) return 0;
410 snprintf(buf, sizeof(buf), "e/icons/%s", name);
411 file = e_theme_edje_file_get("base/theme/icons", buf);
414 edje_object_file_set(obj, file, buf);
421 _e_util_icon_theme_set(Evas_Object *obj, const char *icon, Eina_Bool fallback)
426 if ((!icon) || (!icon[0])) return 0;
427 snprintf(buf, sizeof(buf), "e/icons/%s", icon);
430 file = e_theme_edje_icon_fallback_file_get(buf);
432 file = e_theme_edje_file_get("base/theme/icons", buf);
436 e_icon_file_edje_set(obj, file, buf);
444 _e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
446 const char *path = NULL;
449 if ((!icon) || (!icon[0])) return 0;
450 size = e_icon_scale_size_get(obj);
451 if (size < 16) size = 16;
452 size = e_util_icon_size_normalize(size * e_scale);
454 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
457 e_icon_file_set(obj, path);
461 /* use e_icon_size_scale_set(obj, size) to set the preferred icon size */
463 e_util_icon_theme_set(Evas_Object *obj, const char *icon)
465 if (e_config->icon_theme_overrides)
467 if (_e_util_icon_fdo_set(obj, icon))
469 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
471 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
475 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
477 if (_e_util_icon_fdo_set(obj, icon))
479 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
484 _e_util_menu_item_edje_icon_set(E_Menu_Item *mi, const char *name, Eina_Bool fallback)
489 if ((!name) || (!name[0])) return 0;
491 if ((!fallback) && (name[0]=='/') && ecore_file_exists(name))
493 e_menu_item_icon_edje_set(mi, name, "icon");
496 snprintf(buf, sizeof(buf), "e/icons/%s", name);
499 file = e_theme_edje_icon_fallback_file_get(buf);
501 file = e_theme_edje_file_get("base/theme/icons", buf);
505 e_menu_item_icon_edje_set(mi, file, buf);
512 e_util_icon_size_normalize(unsigned int desired)
514 const unsigned int *itr, known_sizes[] =
516 16, 22, 24, 32, 36, 48, 64, 72, 96, 128, 192, 256, -1
519 for (itr = known_sizes; *itr > 0; itr++)
523 return 256; /* largest know size? */
527 _e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
529 const char *path = NULL;
532 if ((!icon) || (!icon[0])) return 0;
533 size = e_util_icon_size_normalize(24 * e_scale);
534 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
536 e_menu_item_icon_file_set(mi, path);
541 e_util_menu_item_theme_icon_set(E_Menu_Item *mi, const char *icon)
543 if (e_config->icon_theme_overrides)
545 if (_e_util_menu_item_fdo_icon_set(mi, icon))
547 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
549 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
553 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
555 if (_e_util_menu_item_fdo_icon_set(mi, icon))
557 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
562 e_util_container_window_find(Ecore_X_Window win)
568 EINA_LIST_FOREACH(e_manager_list(), l, man)
570 EINA_LIST_FOREACH(man->containers, ll, con)
572 if ((con->win == win) || (con->bg_win == win) ||
573 (con->event_win == win))
581 e_util_zone_window_find(Ecore_X_Window win)
583 Eina_List *l, *ll, *lll;
588 EINA_LIST_FOREACH(e_manager_list(), l, man)
589 EINA_LIST_FOREACH(man->containers, ll, con)
590 EINA_LIST_FOREACH(con->zones, lll, zone)
591 if (zone->black_win == win) return zone;
597 e_util_desk_border_above(E_Border *bd)
599 E_Border *bd2, *above = NULL;
603 E_OBJECT_CHECK_RETURN(bd, NULL);
604 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
606 if (bd->layer == 0) pos = 0;
607 else if ((bd->layer > 0) && (bd->layer <= 50)) pos = 1;
608 else if ((bd->layer > 50) && (bd->layer <= 100)) pos = 2;
609 else if ((bd->layer > 100) && (bd->layer <= 150)) pos = 3;
610 else if ((bd->layer > 150) && (bd->layer <= 200)) pos = 4;
613 EINA_LIST_FOREACH(eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd), l, bd2)
615 if(!eina_list_next(l) || above) break;
616 above = eina_list_data_get(eina_list_next(l));
617 if ((above->desk != bd->desk) && (!above->sticky))
622 /* Need to check the layers above */
623 for (i = pos + 1; (i < 7) && (!above); i++)
625 EINA_LIST_FOREACH(bd->zone->container->layers[i].clients, l, bd2)
629 if ((above->desk != bd->desk) && (!above->sticky))
638 e_util_desk_border_below(E_Border *bd)
640 E_Border *below = NULL, *bd2;
644 E_OBJECT_CHECK_RETURN(bd, NULL);
645 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
647 if (bd->layer == 0) pos = 0;
648 else if ((bd->layer > 0) && (bd->layer <= 50)) pos = 1;
649 else if ((bd->layer > 50) && (bd->layer <= 100)) pos = 2;
650 else if ((bd->layer > 100) && (bd->layer <= 150)) pos = 3;
651 else if ((bd->layer > 150) && (bd->layer <= 200)) pos = 4;
654 for (l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd); l; l = l->prev)
656 if (!eina_list_prev(l) || below) break;
657 below = eina_list_data_get(eina_list_prev(l));
658 if ((below->desk != bd->desk) && (!below->sticky))
663 /* Need to check the layers below */
664 for (i = pos - 1; (i >= 0) && (!below); i--)
666 if (bd->zone->container->layers[i].clients)
668 l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd);
669 for (; l && !below; l = l->prev)
673 if ((below->desk != bd->desk) && (!below->sticky))
684 e_util_edje_collection_exists(const char *file, const char *coll)
686 Eina_List *clist, *l;
689 clist = edje_file_collection_list(file);
690 EINA_LIST_FOREACH(clist, l, str)
692 if (!strcmp(coll, str))
694 edje_file_collection_list_free(clist);
698 edje_file_collection_list_free(clist);
703 e_util_dialog_internal(const char *title, const char *txt)
707 dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_error_dialog");
709 e_dialog_title_set(dia, title);
710 e_dialog_text_set(dia, txt);
711 e_dialog_icon_set(dia, "dialog-error", 64);
712 e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
713 e_dialog_button_focus_num(dia, 0);
714 e_win_centered_set(dia->win, 1);
719 e_util_filename_escape(const char *filename)
723 static char buf[PATH_MAX];
725 if (!filename) return NULL;
730 if ((q - buf) > 4090) return NULL;
732 (*p == ' ') || (*p == '\t') || (*p == '\n') ||
733 (*p == '\\') || (*p == '\'') || (*p == '\"') ||
734 (*p == ';') || (*p == '!') || (*p == '#') ||
735 (*p == '$') || (*p == '%') || (*p == '&') ||
736 (*p == '*') || (*p == '(') || (*p == ')') ||
737 (*p == '[') || (*p == ']') || (*p == '{') ||
738 (*p == '}') || (*p == '|') || (*p == '<') ||
739 (*p == '>') || (*p == '?')
754 e_util_icon_save(Ecore_X_Icon *icon, const char *filename)
761 ee = ecore_evas_buffer_new(icon->width, icon->height);
763 evas = ecore_evas_get(ee);
764 evas_image_cache_set(evas, 0);
765 evas_font_cache_set(evas, 0);
767 im = evas_object_image_add(evas);
773 evas_object_move(im, 0, 0);
774 evas_object_resize(im, icon->width, icon->height);
775 evas_object_image_size_set(im, icon->width, icon->height);
776 evas_object_image_data_copy_set(im, icon->data);
777 evas_object_image_alpha_set(im, 1);
778 evas_object_show(im);
779 ret = evas_object_image_save(im, filename, NULL, NULL);
786 e_util_shell_env_path_eval(const char *path)
788 /* evaluate things like:
789 * $HOME/bling -> /home/user/bling
790 * $HOME/bin/$HOSTNAME/blah -> /home/user/bin/localhost/blah
793 const char *p, *v2, *v1 = NULL;
794 char buf[PATH_MAX], *pd, *s, *vp;
796 int esc = 0, invar = 0;
798 for (p = path, pd = buf; (pd < (buf + sizeof(buf) - 1)); p++)
802 if (!((isalnum(*p)) || (*p == '_')))
809 strncpy(s, v1 + 1, v2 - v1 - 1);
811 if (strncmp(s, "XDG", 3))
815 if (!strcmp(s, "XDG_CONFIG_HOME"))
816 v = (char *)efreet_config_home_get();
817 else if (!strcmp(s, "XDG_CACHE_HOME"))
818 v = (char *)efreet_cache_home_get();
819 else if (!strcmp(s, "XDG_DATA_HOME"))
820 v = (char *)efreet_data_home_get();
826 while ((*vp) && (pd < (buf + sizeof(buf) - 1)))
834 if (pd < (buf + sizeof(buf) - 1))
850 if (*p == '\\') esc = 1;
870 e_util_size_string_get(off_t size)
875 dsize = (double)size;
876 if (dsize < 1024.0) snprintf(buf, sizeof(buf), _("%'.0f Bytes"), dsize);
880 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f KB"), dsize);
884 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f MB"), dsize);
888 snprintf(buf, sizeof(buf), _("%'.1f GB"), dsize);
896 e_util_file_time_get(time_t ftime)
904 diff = ltime - ftime;
907 snprintf(buf, sizeof(buf), _("In the Future"));
911 snprintf(buf, sizeof(buf), _("In the last Minute"));
912 else if (diff >= 31526000)
913 snprintf(buf, sizeof(buf), _("%li Years ago"), (diff / 31526000));
914 else if (diff >= 2592000)
915 snprintf(buf, sizeof(buf), _("%li Months ago"), (diff / 2592000));
916 else if (diff >= 604800)
917 snprintf(buf, sizeof(buf), _("%li Weeks ago"), (diff / 604800));
918 else if (diff >= 86400)
919 snprintf(buf, sizeof(buf), _("%li Days ago"), (diff / 86400));
920 else if (diff >= 3600)
921 snprintf(buf, sizeof(buf), _("%li Hours ago"), (diff / 3600));
923 snprintf(buf, sizeof(buf), _("%li Minutes ago"), (diff / 60));
929 s = strdup(_("Unknown"));
933 static char *prev_ld_library_path = NULL;
934 static char *prev_path = NULL;
937 e_util_library_path_strip(void)
941 p = getenv("LD_LIBRARY_PATH");
942 E_FREE(prev_ld_library_path);
945 prev_ld_library_path = strdup(p);
948 e_util_env_set("LD_LIBRARY_PATH", p2);
954 prev_path = strdup(p);
957 e_util_env_set("PATH", p2);
962 e_util_library_path_restore(void)
964 if (prev_ld_library_path)
966 e_util_env_set("LD_LIBRARY_PATH", prev_ld_library_path);
967 E_FREE(prev_ld_library_path);
971 e_util_env_set("PATH", prev_path);
977 e_util_icon_add(const char *path, Evas *evas)
979 return _e_util_icon_add(path, evas, 64);
983 e_util_desktop_icon_add(Efreet_Desktop *desktop, unsigned int size, Evas *evas)
985 if ((!desktop) || (!desktop->icon)) return NULL;
986 return e_util_icon_theme_icon_add(desktop->icon, size, evas);
990 e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
992 if (!icon_name) return NULL;
993 if (icon_name[0] == '/') return e_util_icon_add(icon_name, evas);
999 path = efreet_icon_path_find(e_config->icon_theme, icon_name, size);
1002 obj = _e_util_icon_add(path, evas, size);
1010 e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_Menu_Item *mi)
1012 const char *path = NULL;
1014 if ((!desktop) || (!desktop->icon)) return;
1016 if (desktop->icon[0] == '/') path = desktop->icon;
1017 else path = efreet_icon_path_find(e_config->icon_theme, desktop->icon, size);
1023 ext = strrchr(path, '.');
1026 if (strcmp(ext, ".edj") == 0)
1027 e_menu_item_icon_edje_set(mi, path, "icon");
1029 e_menu_item_icon_file_set(mi, path);
1032 e_menu_item_icon_file_set(mi, path);
1037 e_util_dir_check(const char *dir)
1039 if (!ecore_file_exists(dir))
1041 if (!ecore_file_mkpath(dir))
1043 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>Check that you have correct permissions set.", dir);
1049 if (!ecore_file_is_dir(dir))
1051 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>A file of that name already exists.", dir);
1059 e_util_defer_object_del(E_Object *obj)
1064 ecore_idle_enterer_before_add(_e_util_cb_delayed_del, obj);
1068 e_util_winid_str_get(Ecore_X_Window win)
1070 const char *vals = "qWeRtYuIoP5-$&<~";
1074 val = (unsigned int)win;
1075 id[0] = vals[(val >> 28) & 0xf];
1076 id[1] = vals[(val >> 24) & 0xf];
1077 id[2] = vals[(val >> 20) & 0xf];
1078 id[3] = vals[(val >> 16) & 0xf];
1079 id[4] = vals[(val >> 12) & 0xf];
1080 id[5] = vals[(val >> 8) & 0xf];
1081 id[6] = vals[(val >> 4) & 0xf];
1082 id[7] = vals[(val ) & 0xf];
1088 _win_auto_size_calc(int max, int min)
1090 const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1};
1092 for (itr = scales; *itr > 0; itr++)
1094 int value = *itr * max;
1095 if (value > min) /* not >=, try a bit larger */
1103 e_util_win_auto_resize_fill(E_Win *win)
1105 E_Zone *zone = NULL;
1108 zone = win->border->zone;
1109 if ((!zone) && (win->container))
1110 zone = e_util_zone_current_get(win->container->manager);
1116 e_zone_useful_geometry_get(zone, NULL, NULL, &w, &h);
1118 w = _win_auto_size_calc(w, win->min_w);
1119 h = _win_auto_size_calc(h, win->min_h);
1120 e_win_resize(win, w, h);
1125 * Creates a new dialog to query image import settings, report results.
1127 * @param path may be used to display live preview (not used so far).
1128 * @param cb function to call before exit. Last parameter is mode of
1130 * @param data extra data to give to @a cb as first argument.
1132 * @return newly allocated window on success, @c NULL on failure. If
1133 * @c NULL is returned, then callback is never called!
1136 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)
1139 E_Util_Image_Import_Settings *ctxt;
1140 Evas_Object *vlist, *frame, *radio, *check, *slider;
1144 if (!path) return NULL;
1145 if (!cb) return NULL;
1147 ctxt = E_NEW(E_Util_Image_Import_Settings, 1);
1148 if (!ctxt) return NULL;
1150 ctxt->dia = e_dialog_new(NULL, "E", "_image_import_settings");
1157 ctxt->dia->data = ctxt;
1159 e_object_del_attach_func_set
1160 (E_OBJECT(ctxt->dia), _e_util_image_import_settings_del);
1161 e_dialog_title_set(ctxt->dia, _("Image Import Settings"));
1162 e_dialog_border_icon_set(ctxt->dia, "dialog-ask");
1165 (ctxt->dia, _("Import"), NULL, _e_util_image_import_settings_do, ctxt);
1167 (ctxt->dia, _("Cancel"), NULL, NULL, ctxt);
1168 e_dialog_button_focus_num(ctxt->dia, 0);
1171 ctxt->cb.data = (void *)data;
1172 ctxt->path = eina_stringshare_add(path);
1174 ctxt->ok = EINA_FALSE;
1175 ctxt->external = EINA_FALSE;
1176 ctxt->mode = E_IMAGE_IMPORT_STRETCH;
1178 evas = e_win_evas_get(ctxt->dia->win);
1180 vlist = e_widget_list_add(evas, 0, 0);
1182 frame = e_widget_frametable_add(evas, _("Fill and Stretch Options"), 1);
1183 rg = e_widget_radio_group_new(&ctxt->mode);
1185 #define RD(lbl, icon, val, col, row) \
1186 radio = e_widget_radio_icon_add \
1187 (evas, lbl, "enlightenment/wallpaper_"icon, 24, 24, val, rg); \
1188 e_widget_frametable_object_append(frame, radio, col, row, 1, 1, 1, 1, 0, 0)
1190 RD(_("Stretch"), "stretch", E_IMAGE_IMPORT_STRETCH, 0, 0);
1191 RD(_("Center"), "center", E_IMAGE_IMPORT_CENTER, 1, 0);
1192 RD(_("Title"), "tile", E_IMAGE_IMPORT_TILE, 2, 0);
1193 RD(_("Within"), "scale_aspect_in", E_IMAGE_IMPORT_SCALE_ASPECT_IN, 3, 0);
1194 RD(_("Fill"), "scale_aspect_out", E_IMAGE_IMPORT_SCALE_ASPECT_OUT, 4, 0);
1197 e_widget_list_object_append(vlist, frame, 1, 1, 0.5);
1199 frame = e_widget_frametable_add(evas, _("File Quality"), 0);
1201 check = e_widget_check_add(evas, _("Use original file"), &ctxt->external);
1202 e_widget_frametable_object_append(frame, check, 0, 0, 1, 1, 1, 0, 1, 0);
1204 slider = e_widget_slider_add
1205 (evas, 1, 0, _("%3.0f%%"), 0.0, 100.0, 1.0, 0, NULL, &ctxt->quality, 150);
1206 e_widget_frametable_object_append(frame, slider, 0, 1, 1, 1, 1, 0, 1, 0);
1208 e_widget_list_object_append(vlist, frame, 1, 1, 0.5);
1210 e_widget_size_min_get(vlist, &w, &h);
1212 e_dialog_content_set(ctxt->dia, vlist, w, h);
1214 e_win_centered_set(ctxt->dia->win, 1);
1220 * Request given image to be imported as an edje file.
1222 * This is useful to convert images to icons and background.
1224 * @param image_path path to source image to use.
1225 * @param edje_path path to destination edje to generate.
1226 * @param external if @c EINA_TRUE, then it will not embed image into edje,
1227 * but reference the original @a image_path.
1228 * @param quality quality value from 0-100.
1229 * @param mode how to resize image with edje.
1230 * @param cb function to callback when process finishes.
1231 * @param data extra context to give to callback.
1233 * @return handle so one can cancel the operation. This handle will be
1234 * invalid after @a cb is called!
1236 EAPI E_Util_Image_Import_Handle *
1237 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)
1239 static const char *tmpdir = NULL;
1240 E_Util_Image_Import_Handle *handle;
1244 const char *escaped_file;
1245 char cmd[PATH_MAX * 2], tmpn[PATH_MAX];
1248 if (!image_path) return NULL;
1249 if (!edje_path) return NULL;
1250 if (!edje_group) return NULL;
1251 if (!cb) return NULL;
1252 ee = ecore_evas_buffer_new(1, 1);
1253 img = evas_object_image_add(ecore_evas_get(ee));
1254 evas_object_image_file_set(img, image_path, NULL);
1255 if (evas_object_image_load_error_get(img) != EVAS_LOAD_ERROR_NONE)
1257 ecore_evas_free(ee);
1258 printf("Error loading image '%s'\n", image_path);
1261 evas_object_image_size_get(img, &w, &h);
1262 ecore_evas_free(ee);
1266 tmpdir = getenv("TMPDIR");
1267 if (!tmpdir) tmpdir = "/tmp";
1269 snprintf(tmpn, sizeof(tmpn), "%s/e_util_image_import-XXXXXX", tmpdir);
1273 printf("Error Creating tmp file: %s\n", strerror(errno));
1277 f = fdopen(fd, "wb");
1280 printf("Cannot open %s for writing\n", tmpn);
1285 escaped_file = e_util_filename_escape(image_path); // watch out ret buffer!
1287 fprintf(f, "images.image: \"%s\" ", escaped_file);
1290 else if (quality >= 100)
1293 fprintf(f, "LOSSY %d", (quality > 1) ? quality : 90);
1300 " data.item: \"style\" \"%d\";\n"
1303 edje_group, mode, w, h);
1305 if ((mode == E_IMAGE_IMPORT_CENTER) ||
1306 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN))
1311 " mouse_events: 0;\n"
1313 " state: \"default\" 0.0;\n"
1314 " color: 255 255 255 255;\n"
1323 " name: \"image\";\n"
1324 " mouse_events: 0;\n"
1326 " state: \"default\" 0.0;\n"
1328 " normal: \"%s\";\n"
1329 " scale_hint: STATIC;\n"
1333 if (mode == E_IMAGE_IMPORT_TILE)
1338 " relative: 0.0 0.0;\n"
1344 else if (mode == E_IMAGE_IMPORT_CENTER)
1352 else if ((mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN) ||
1353 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_OUT))
1355 const char *locale = e_intl_language_get();
1356 double aspect = (double)w / (double)h;
1357 setlocale(LC_NUMERIC, "C");
1359 " aspect: %1.9f %1.9f;\n"
1360 " aspect_preference: %s;\n",
1362 (mode == E_IMAGE_IMPORT_SCALE_ASPECT_IN) ? "BOTH" : "NONE");
1363 setlocale(LC_NUMERIC, locale);
1366 fputs(" }\n" // description
1370 "}\n", // collections
1373 fclose(f); // fd gets closed here
1375 snprintf(cmd, sizeof(cmd), "edje_cc %s %s",
1376 tmpn, e_util_filename_escape(edje_path));
1378 handle = E_NEW(E_Util_Image_Import_Handle, 1);
1385 handle->cb.func = cb;
1386 handle->cb.data = (void *)data;
1387 handle->path.image = eina_stringshare_add(image_path);
1388 handle->path.edje = eina_stringshare_add(edje_path);
1389 handle->path.temp = eina_stringshare_add(tmpn);
1390 handle->handler = ecore_event_handler_add
1391 (ECORE_EXE_EVENT_DEL, _e_util_image_import_exit, handle);
1392 handle->exe = ecore_exe_run(cmd, NULL);
1395 _e_util_image_import_handle_free(handle);
1403 e_util_image_import_cancel(E_Util_Image_Import_Handle *handle)
1405 if (!handle) return;
1406 ecore_exe_kill(handle->exe);
1410 e_util_container_desk_count_get(E_Container *con)
1416 E_OBJECT_CHECK_RETURN(con, 0);
1417 E_OBJECT_TYPE_CHECK_RETURN(con, E_CONTAINER_TYPE, 0);
1418 EINA_LIST_FOREACH(con->zones, zl, zone)
1423 e_zone_desk_count_get(zone, &cx, &cy);
1424 for (x = 0; x < cx; x++)
1426 for (y = 0; y < cy; y++)
1433 /* local subsystem functions */
1435 static Evas_Object *
1436 _e_util_icon_add(const char *path, Evas *evas, int size)
1438 Evas_Object *o = NULL;
1441 if (!path) return NULL;
1442 if (!ecore_file_exists(path)) return NULL;
1444 o = e_icon_add(evas);
1445 e_icon_scale_size_set(o, size);
1446 e_icon_preload_set(o, 1);
1447 ext = strrchr(path, '.');
1450 if (!strcmp(ext, ".edj"))
1451 e_icon_file_edje_set(o, path, "icon");
1453 e_icon_file_set(o, path);
1456 e_icon_file_set(o, path);
1457 e_icon_fill_inside_set(o, 1);
1463 _e_util_cb_delayed_del(void *data)
1465 e_object_del(E_OBJECT(data));
1466 return ECORE_CALLBACK_CANCEL;
1470 _e_util_wakeup_cb(void *data __UNUSED__)
1472 _e_util_dummy_timer = NULL;
1473 return ECORE_CALLBACK_CANCEL;
1477 _e_util_image_import_settings_do(void *data, E_Dialog *dia)
1479 E_Util_Image_Import_Settings *ctxt = data;
1481 ctxt->ok = EINA_TRUE;
1482 e_util_defer_object_del(E_OBJECT(dia));
1486 _e_util_image_import_settings_del(void *obj)
1488 E_Dialog *dia = obj;
1489 E_Util_Image_Import_Settings *ctxt = dia->data;
1491 ctxt->cb.func(ctxt->cb.data, ctxt->path,
1492 ctxt->ok, ctxt->external, ctxt->quality, ctxt->mode);
1494 eina_stringshare_del(ctxt->path);
1499 _e_util_image_import_exit(void *data, int type __UNUSED__, void *event)
1501 E_Util_Image_Import_Handle *handle = data;
1502 Ecore_Exe_Event_Del *ev = event;
1505 if (ev->exe != handle->exe) return ECORE_CALLBACK_PASS_ON;
1507 ok = (ev->exit_code == 0);
1509 if (!ok) unlink(handle->path.edje);
1510 handle->cb.func(handle->cb.data, ok, handle->path.image, handle->path.edje);
1512 _e_util_image_import_handle_free(handle);
1514 return ECORE_CALLBACK_CANCEL;
1518 _e_util_image_import_handle_free(E_Util_Image_Import_Handle *handle)
1520 unlink(handle->path.temp);
1521 eina_stringshare_del(handle->path.image);
1522 eina_stringshare_del(handle->path.edje);
1523 eina_stringshare_del(handle->path.temp);
1524 if (handle->handler) ecore_event_handler_del(handle->handler);
1529 _e_util_conf_timer_old(void *data)
1531 char *module_name = data;
1534 _("Configuration data needed "
1535 "upgrading. Your old configuration<br> has been"
1536 " wiped and a new set of defaults initialized. "
1537 "This<br>will happen regularly during "
1538 "development, so don't report a<br>bug. "
1539 "This simply means the module needs "
1540 "new configuration<br>data by default for "
1541 "usable functionality that your old<br>"
1542 "configuration simply lacks. This new set of "
1543 "defaults will fix<br>that by adding it in. "
1544 "You can re-configure things now to your<br>"
1545 "liking. Sorry for the inconvenience.<br>");
1547 snprintf(buf, sizeof(buf),N_("%s Configuration Updated"), module_name);
1548 e_util_dialog_internal(buf, msg);
1549 E_FREE(module_name);
1551 return ECORE_CALLBACK_CANCEL;
1555 _e_util_conf_timer_new(void *data)
1557 char *module_name = data;
1560 _("Your module configuration is NEWER "
1561 "than the module version. This is "
1562 "very<br>strange. This should not happen unless"
1563 " you downgraded<br>the module or "
1564 "copied the configuration from a place where"
1565 "<br>a newer version of the module "
1566 "was running. This is bad and<br>as a "
1567 "precaution your configuration has been now "
1568 "restored to<br>defaults. Sorry for the "
1569 "inconvenience.<br>");
1571 snprintf(buf, sizeof(buf),N_("%s Configuration Updated"), module_name);
1572 e_util_dialog_internal(buf, msg);
1573 E_FREE(module_name);
1575 return ECORE_CALLBACK_CANCEL;
1579 e_util_module_config_check(const char *module_name, int conf, int epoch, int version)
1581 if ((conf >> 16) < epoch)
1583 ecore_timer_add(1.0, _e_util_conf_timer_old, strdup(module_name));
1586 else if (conf > version)
1588 ecore_timer_add(1.0, _e_util_conf_timer_new, strdup(module_name));
1596 * Checks whenever the current manager/container/zone have fullscreen windows.
1599 e_util_fullscreen_curreny_any(void)
1601 E_Manager *man = e_manager_current_get();
1602 E_Container *con = e_container_current_get(man);
1603 E_Zone *zone = e_zone_current_get(con);
1606 if ((zone) && (zone->fullscreen > 0)) return EINA_TRUE;
1607 desk = e_desk_current_get(zone);
1608 if ((desk) && (desk->fullscreen_borders > 0)) return EINA_TRUE;
1613 * Checks whenever any manager/container/zone have fullscreen windows.
1616 e_util_fullscreen_any(void)
1619 Eina_List *lm, *lc, *lz;
1625 EINA_LIST_FOREACH(e_manager_list(), lm, man)
1627 EINA_LIST_FOREACH(man->containers, lc, con)
1629 EINA_LIST_FOREACH(con->zones, lz, zone)
1631 if (zone->fullscreen > 0) return EINA_TRUE;
1633 for (x = 0; x < zone->desk_x_count; x++)
1634 for (y = 0; y < zone->desk_y_count; y++)
1636 desk = e_desk_at_xy_get(zone, x, y);
1637 if ((desk) && (desk->fullscreen_borders > 0))