Merge from TIZEN 2.3
[platform/core/uifw/e17.git] / src / bin / e_utils.c
1 #include "e.h"
2
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;
11
12 typedef struct _E_Util_Fake_Mouse_Up_Info    E_Util_Fake_Mouse_Up_Info;
13
14 struct _E_Util_Fake_Mouse_Up_Info
15 {
16    Evas *evas;
17    int   button;
18 };
19
20 /* local subsystem functions */
21 static Eina_Bool    _e_util_cb_delayed_del(void *data);
22 static Eina_Bool    _e_util_wakeup_cb(void *data);
23
24 static Evas_Object *_e_util_icon_add(const char *path, Evas *evas, int size);
25
26 static void         _e_util_cb_delayed_cancel(void *data, void *obj);
27
28 /* local subsystem globals */
29 static Ecore_Timer *_e_util_dummy_timer = NULL;
30
31 /* externally accessible functions */
32 EAPI void
33 e_util_wakeup(void)
34 {
35    if (_e_util_dummy_timer) return;
36    _e_util_dummy_timer = ecore_timer_add(0.0, _e_util_wakeup_cb, NULL);
37 }
38
39 EAPI void
40 e_util_env_set(const char *var, const char *val)
41 {
42    if (val)
43      {
44 #ifdef HAVE_SETENV
45         setenv(var, val, 1);
46 #else
47         char buf[8192];
48
49         snprintf(buf, sizeof(buf), "%s=%s", var, val);
50         if (getenv(var))
51           putenv(buf);
52         else
53           putenv(strdup(buf));
54 #endif
55      }
56    else
57      {
58 #ifdef HAVE_UNSETENV
59         unsetenv(var);
60 #else
61         if (getenv(var)) putenv(var);
62 #endif
63      }
64 }
65
66 EAPI E_Zone *
67 e_util_zone_current_get(E_Manager *man)
68 {
69    E_Container *con;
70
71    E_OBJECT_CHECK_RETURN(man, NULL);
72    E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);
73    con = e_container_current_get(man);
74    if (con)
75      {
76         E_Zone *zone;
77
78         zone = e_zone_current_get(con);
79         return zone;
80      }
81    return NULL;
82 }
83
84 EAPI int
85 e_util_glob_match(const char *str, const char *pattern)
86 {
87    if ((!str) || (!pattern)) return 0;
88    if (pattern[0] == 0)
89      {
90         if (str[0] == 0) return 1;
91         return 0;
92      }
93    if (!strcmp(pattern, "*")) return 1;
94    if (!fnmatch(pattern, str, 0)) return 1;
95    return 0;
96 }
97
98 EAPI int
99 e_util_glob_case_match(const char *str, const char *pattern)
100 {
101    const char *p;
102    char *tstr, *tglob, *tp;
103
104    if (pattern[0] == 0)
105      {
106         if (str[0] == 0) return 1;
107         return 0;
108      }
109    if (!strcmp(pattern, "*")) return 1;
110    tstr = alloca(strlen(str) + 1);
111    for (tp = tstr, p = str; *p != 0; p++, tp++)
112      *tp = tolower(*p);
113    *tp = 0;
114    tglob = alloca(strlen(pattern) + 1);
115    for (tp = tglob, p = pattern; *p != 0; p++, tp++)
116      *tp = tolower(*p);
117    *tp = 0;
118    if (!fnmatch(tglob, tstr, 0)) return 1;
119    return 0;
120 }
121
122 EAPI E_Container *
123 e_util_container_number_get(int num)
124 {
125    Eina_List *l;
126    E_Manager *man;
127
128    EINA_LIST_FOREACH(e_manager_list(), l, man)
129      {
130         E_Container *con;
131
132         con = e_container_number_get(man, num);
133         if (con) return con;
134      }
135    return NULL;
136 }
137
138 EAPI E_Zone *
139 e_util_container_zone_number_get(int con_num, int zone_num)
140 {
141    E_Container *con;
142
143    con = e_util_container_number_get(con_num);
144    if (!con) return NULL;
145    return e_container_zone_number_get(con, zone_num);
146 }
147
148 EAPI E_Zone *
149 e_util_container_zone_id_get(int con_num, int id)
150 {
151    E_Container *con;
152
153    con = e_util_container_number_get(con_num);
154    if (!con) return NULL;
155    return e_container_zone_id_get(con, id);
156 }
157
158 EAPI int
159 e_util_head_exec(int head, const char *cmd)
160 {
161    char *penv_display;
162    char *p1, *p2;
163    char buf[4096], buf2[32];
164    int ok = 0;
165    Ecore_Exe *exe;
166
167    penv_display = getenv("DISPLAY");
168    if (!penv_display) return 0;
169    penv_display = strdup(penv_display);
170    /* set env vars */
171    p1 = strrchr(penv_display, ':');
172    p2 = strrchr(penv_display, '.');
173    if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
174      {
175         /* yes it could overflow... but who will overflow DISPLAY eh? why? to
176          * "exploit" your own applications running as you?
177          */
178         strcpy(buf, penv_display);
179         buf[p2 - penv_display + 1] = 0;
180         snprintf(buf2, sizeof(buf2), "%i", head);
181         strcat(buf, buf2);
182      }
183    else if (p1) /* "blah:x */
184      {
185         strcpy(buf, penv_display);
186         snprintf(buf2, sizeof(buf2), ".%i", head);
187         strcat(buf, buf2);
188      }
189    else
190      strcpy(buf, penv_display);
191
192    ok = 1;
193    e_util_library_path_strip();
194    exe = ecore_exe_run(cmd, NULL);
195    e_util_library_path_restore();
196    if (!exe)
197      {
198         e_util_dialog_show(_("Run Error"),
199                            _("Enlightenment was unable to fork a child process:<br>"
200                              "<br>"
201                              "%s<br>"),
202                            cmd);
203         ok = 0;
204      }
205
206    /* reset env vars */
207    if (penv_display)
208      {
209         e_util_env_set("DISPLAY", penv_display);
210         free(penv_display);
211      }
212    return ok;
213 }
214
215 EAPI int
216 e_util_strcmp(const char *s1, const char *s2)
217 {
218    if ((s1) && (s2))
219      return strcmp(s1, s2);
220    return 0x7fffffff;
221 }
222
223 EAPI int
224 e_util_strcasecmp(const char *s1, const char *s2)
225 {
226    if ((!s1) && (!s2)) return 0;
227    if (!s1) return -1;
228    if (!s2) return 1;
229    return strcasecmp(s1, s2);
230 }
231
232 EAPI int
233 e_util_both_str_empty(const char *s1, const char *s2)
234 {
235    int empty = 0;
236
237    if ((!s1) && (!s2)) return 1;
238    if ((!s1) || ((s1) && (s1[0] == 0))) empty++;
239    if ((!s2) || ((s2) && (s2[0] == 0))) empty++;
240    if (empty == 2) return 1;
241    return 0;
242 }
243
244 EAPI int
245 e_util_immortal_check(void)
246 {
247    Eina_List *wins;
248
249    wins = e_border_immortal_windows_get();
250    if (wins)
251      {
252         e_util_dialog_show(_("Cannot exit - immortal windows."),
253                            _("Some windows are left still around with the Lifespan lock enabled. This means<br>"
254                              "that Enlightenment will not allow itself to exit until these windows have<br>"
255                              "been closed or have the lifespan lock removed.<br>"));
256         /* FIXME: should really display a list of these lifespan locked */
257         /* windows in a dialog and let the user disable their locks in */
258         /* this dialog */
259         eina_list_free(wins);
260         return 1;
261      }
262    return 0;
263 }
264
265 EAPI int
266 e_util_edje_icon_list_check(const char *list)
267 {
268    char *buf;
269    const char *p;
270    const char *c;
271
272    if ((!list) || (!list[0])) return 0;
273    buf = alloca(strlen(list) + 1);
274    p = list;
275    while (p)
276      {
277         c = strchr(p, ',');
278         if (c)
279           {
280              strncpy(buf, p, c - p);
281              buf[c - p] = 0;
282              if (e_util_edje_icon_check(buf)) return 1;
283              p = c + 1;
284              if (!*p) return 0;
285           }
286         else
287           {
288              strcpy(buf, p);
289              if (e_util_edje_icon_check(buf)) return 1;
290              return 0;
291           }
292      }
293    return 0;
294 }
295
296 EAPI int
297 e_util_edje_icon_list_set(Evas_Object *obj, const char *list)
298 {
299    char *buf;
300    const char *p;
301    const char *c;
302
303    if ((!list) || (!list[0])) return 0;
304    buf = alloca(strlen(list) + 1);
305    p = list;
306    while (p)
307      {
308         c = strchr(p, ',');
309         if (c)
310           {
311              strncpy(buf, p, c - p);
312              buf[c - p] = 0;
313              if (e_util_edje_icon_set(obj, buf)) return 1;
314              p = c + 1;
315              if (!*p) return 0;
316           }
317         else
318           {
319              strcpy(buf, p);
320              if (e_util_edje_icon_set(obj, buf)) return 1;
321              return 0;
322           }
323      }
324    return 0;
325 }
326
327 EAPI int
328 e_util_menu_item_edje_icon_list_set(E_Menu_Item *mi, const char *list)
329 {
330    char *buf;
331    const char *p;
332    char *c;
333
334    if ((!list) || (!list[0])) return 0;
335    buf = alloca(strlen(list) + 1);
336    p = list;
337    while (p)
338      {
339         c = strchr(p, ',');
340         if (c)
341           {
342              strncpy(buf, p, c - p);
343              buf[c - p] = 0;
344              if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
345              p = c + 1;
346              if (!*p) return 0;
347           }
348         else
349           {
350              strcpy(buf, p);
351              if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
352              return 0;
353           }
354      }
355    return 0;
356 }
357
358 EAPI int
359 e_util_edje_icon_check(const char *name)
360 {
361    const char *file;
362    char buf[4096];
363
364    if ((!name) || (!name[0])) return 0;
365    snprintf(buf, sizeof(buf), "e/icons/%s", name);
366    file = e_theme_edje_file_get("base/theme/icons", buf);
367    if (file[0]) return 1;
368    return 0;
369 }
370
371 /* WARNING This function is deprecated,. must be made static.
372  * You should use e_util_icon_theme_set instead
373  */
374 EAPI int
375 e_util_edje_icon_set(Evas_Object *obj, const char *name)
376 {
377    const char *file;
378    char buf[4096];
379
380    if ((!name) || (!name[0])) return 0;
381    snprintf(buf, sizeof(buf), "e/icons/%s", name);
382    file = e_theme_edje_file_get("base/theme/icons", buf);
383    if (file[0])
384      {
385         edje_object_file_set(obj, file, buf);
386         return 1;
387      }
388    return 0;
389 }
390
391 static int
392 _e_util_icon_theme_set(Evas_Object *obj, const char *icon, Eina_Bool fallback)
393 {
394    const char *file;
395    char buf[4096];
396
397    if ((!icon) || (!icon[0])) return 0;
398    snprintf(buf, sizeof(buf), "e/icons/%s", icon);
399
400    if (fallback)
401      file = e_theme_edje_icon_fallback_file_get(buf);
402    else
403      file = e_theme_edje_file_get("base/theme/icons", buf);
404
405    if (file[0])
406      {
407         e_icon_file_edje_set(obj, file, buf);
408         return 1;
409      }
410
411    return 0;
412 }
413
414 static int
415 _e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
416 {
417    const char *path = NULL;
418    unsigned int size;
419
420    if ((!icon) || (!icon[0])) return 0;
421    size = e_icon_scale_size_get(obj);
422    if (size < 16) size = 16;
423    size = e_util_icon_size_normalize(size * e_scale);
424
425    path = efreet_icon_path_find(e_config->icon_theme, icon, size);
426    if (!path) return 0;
427
428    e_icon_file_set(obj, path);
429    return 1;
430 }
431
432 /* use e_icon_size_scale_set(obj, size) to set the preferred icon size */
433 EAPI int
434 e_util_icon_theme_set(Evas_Object *obj, const char *icon)
435 {
436    if (e_config->icon_theme_overrides)
437      {
438         if (_e_util_icon_fdo_set(obj, icon))
439           return 1;
440         if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
441           return 1;
442         return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
443      }
444    else
445      {
446         if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
447           return 1;
448         if (_e_util_icon_fdo_set(obj, icon))
449           return 1;
450         return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
451      }
452 }
453
454 int
455 _e_util_menu_item_edje_icon_set(E_Menu_Item *mi, const char *name, Eina_Bool fallback)
456 {
457    const char *file;
458    char buf[4096];
459
460    if ((!name) || (!name[0])) return 0;
461
462    if ((!fallback) && (name[0] == '/') && ecore_file_exists(name))
463      {
464         e_menu_item_icon_edje_set(mi, name, "icon");
465         return 1;
466      }
467    snprintf(buf, sizeof(buf), "e/icons/%s", name);
468
469    if (fallback)
470      file = e_theme_edje_icon_fallback_file_get(buf);
471    else
472      file = e_theme_edje_file_get("base/theme/icons", buf);
473
474    if (file[0])
475      {
476         e_menu_item_icon_edje_set(mi, file, buf);
477         return 1;
478      }
479    return 0;
480 }
481
482 EAPI unsigned int
483 e_util_icon_size_normalize(unsigned int desired)
484 {
485    const unsigned int *itr, known_sizes[] =
486    {
487       16, 22, 24, 32, 36, 48, 64, 72, 96, 128, 192, 256, 0
488    };
489
490    for (itr = known_sizes; *itr > 0; itr++)
491      if (*itr >= desired)
492        return *itr;
493
494    return 256; /* largest know size? */
495 }
496
497 static int
498 _e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
499 {
500    const char *path = NULL;
501    unsigned int size;
502
503    if ((!icon) || (!icon[0])) return 0;
504    size = e_util_icon_size_normalize(24 * e_scale);
505    path = efreet_icon_path_find(e_config->icon_theme, icon, size);
506    if (!path) return 0;
507    e_menu_item_icon_file_set(mi, path);
508    return 1;
509 }
510
511 EAPI int
512 e_util_menu_item_theme_icon_set(E_Menu_Item *mi, const char *icon)
513 {
514    if (e_config->icon_theme_overrides)
515      {
516         if (_e_util_menu_item_fdo_icon_set(mi, icon))
517           return 1;
518         if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
519           return 1;
520         return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
521      }
522    else
523      {
524         if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
525           return 1;
526         if (_e_util_menu_item_fdo_icon_set(mi, icon))
527           return 1;
528         return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
529      }
530 }
531
532 EAPI const char *
533 e_util_mime_icon_get(const char *mime, unsigned int size)
534 {
535    char buf[1024];
536    const char *file = NULL;
537
538    if (e_config->icon_theme_overrides)
539      file = efreet_mime_type_icon_get(mime, e_config->icon_theme, e_util_icon_size_normalize(size));
540    if (file) return file;
541
542    if (snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", mime) >= (int)sizeof(buf))
543      return NULL;
544
545    file = e_theme_edje_file_get("base/theme/icons", buf);
546    if (file && file[0]) return file;
547    return efreet_mime_type_icon_get(mime, e_config->icon_theme, e_util_icon_size_normalize(size));
548 }
549
550 EAPI E_Container *
551 e_util_container_window_find(Ecore_X_Window win)
552 {
553    Eina_List *l, *ll;
554    E_Manager *man;
555    E_Container *con;
556
557    EINA_LIST_FOREACH(e_manager_list(), l, man)
558      {
559         EINA_LIST_FOREACH(man->containers, ll, con)
560           {
561              if ((con->win == win) || (con->bg_win == win) ||
562                  (con->event_win == win))
563                return con;
564           }
565      }
566    return NULL;
567 }
568
569 EAPI E_Zone *
570 e_util_zone_window_find(Ecore_X_Window win)
571 {
572    Eina_List *l, *ll, *lll;
573    E_Manager *man;
574    E_Container *con;
575    E_Zone *zone;
576
577    EINA_LIST_FOREACH(e_manager_list(), l, man)
578      EINA_LIST_FOREACH(man->containers, ll, con)
579        EINA_LIST_FOREACH(con->zones, lll, zone)
580          if (zone->black_win == win) return zone;
581
582    return NULL;
583 }
584
585 static int
586 _e_util_layer_map(int layer)
587 {
588    int pos = 0;
589    
590    if (layer < 0) layer = 0;
591    pos = 1 + (layer / 50);
592    if (pos > 10) pos = 10;
593    return pos;
594 }
595
596 EAPI E_Border *
597 e_util_desk_border_above(E_Border *bd)
598 {
599    E_Border *bd2, *above = NULL;
600    Eina_List *l;
601    int pos, i;
602
603    E_OBJECT_CHECK_RETURN(bd, NULL);
604    E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
605
606    pos = _e_util_layer_map(bd->layer);
607
608    EINA_LIST_FOREACH(eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd), l, bd2)
609      {
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))
613           above = NULL;
614      }
615    if (!above)
616      {
617         /* Need to check the layers above */
618         for (i = pos + 1; (i < 7) && (!above); i++)
619           {
620              EINA_LIST_FOREACH(bd->zone->container->layers[i].clients, l, bd2)
621                {
622                   if (above) break;
623                   above = bd2;
624                   if ((above->desk != bd->desk) && (!above->sticky))
625                     above = NULL;
626                }
627           }
628      }
629    return above;
630 }
631
632 EAPI E_Border *
633 e_util_desk_border_below(E_Border *bd)
634 {
635    E_Border *below = NULL, *bd2;
636    Eina_List *l;
637    int pos, i;
638
639    E_OBJECT_CHECK_RETURN(bd, NULL);
640    E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
641
642    pos = _e_util_layer_map(bd->layer);
643
644    for (l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd); l; l = l->prev)
645      {
646         if (!eina_list_prev(l) || below) break;
647         below = eina_list_data_get(eina_list_prev(l));
648         if ((below->desk != bd->desk) && (!below->sticky))
649           below = NULL;
650      }
651    if (!below)
652      {
653         /* Need to check the layers below */
654         for (i = pos - 1; (i >= 0) && (!below); i--)
655           {
656              if (bd->zone->container->layers[i].clients)
657                {
658                   l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd);
659                   for (; l && !below; l = l->prev)
660                     {
661                        bd2 = l->data;
662                        below = bd2;
663                        if ((below->desk != bd->desk) && (!below->sticky))
664                          below = NULL;
665                     }
666                }
667           }
668      }
669
670    return below;
671 }
672
673 EAPI int
674 e_util_edje_collection_exists(const char *file, const char *coll)
675 {
676    Eina_List *clist, *l;
677    char *str;
678
679    clist = edje_file_collection_list(file);
680    EINA_LIST_FOREACH(clist, l, str)
681      {
682         if (!strcmp(coll, str))
683           {
684              edje_file_collection_list_free(clist);
685              return 1;
686           }
687      }
688    edje_file_collection_list_free(clist);
689    return 0;
690 }
691
692 EAPI E_Dialog *
693 e_util_dialog_internal(const char *title, const char *txt)
694 {
695    E_Dialog *dia;
696
697    dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_error_dialog");
698    if (!dia) return NULL;
699    e_dialog_title_set(dia, title);
700    e_dialog_text_set(dia, txt);
701    e_dialog_icon_set(dia, "dialog-error", 64);
702    e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
703    e_dialog_button_focus_num(dia, 0);
704    e_win_centered_set(dia->win, 1);
705    e_dialog_show(dia);
706    return dia;
707 }
708
709 EAPI const char *
710 e_util_filename_escape(const char *filename)
711 {
712    const char *p;
713    char *q;
714    static char buf[PATH_MAX];
715
716    if (!filename) return NULL;
717    p = filename;
718    q = buf;
719    while (*p)
720      {
721         if ((q - buf) > 4090) return NULL;
722         if (
723           (*p == ' ') || (*p == '\t') || (*p == '\n') ||
724           (*p == '\\') || (*p == '\'') || (*p == '\"') ||
725           (*p == ';') || (*p == '!') || (*p == '#') ||
726           (*p == '$') || (*p == '%') || (*p == '&') ||
727           (*p == '*') || (*p == '(') || (*p == ')') ||
728           (*p == '[') || (*p == ']') || (*p == '{') ||
729           (*p == '}') || (*p == '|') || (*p == '<') ||
730           (*p == '>') || (*p == '?')
731           )
732           {
733              *q = '\\';
734              q++;
735           }
736         *q = *p;
737         q++;
738         p++;
739      }
740    *q = 0;
741    return buf;
742 }
743
744 EAPI int
745 e_util_icon_save(Ecore_X_Icon *icon, const char *filename)
746 {
747    Ecore_Evas *ee;
748    Evas *evas;
749    Evas_Object *im;
750    int ret;
751
752    ee = ecore_evas_buffer_new(icon->width, icon->height);
753    if (!ee) return 0;
754    evas = ecore_evas_get(ee);
755    evas_image_cache_set(evas, 0);
756    evas_font_cache_set(evas, 0);
757
758    im = evas_object_image_add(evas);
759    if (!im)
760      {
761         ecore_evas_free(ee);
762         return 0;
763      }
764    evas_object_move(im, 0, 0);
765    evas_object_resize(im, icon->width, icon->height);
766    evas_object_image_size_set(im, icon->width, icon->height);
767    evas_object_image_data_copy_set(im, icon->data);
768    evas_object_image_alpha_set(im, 1);
769    evas_object_show(im);
770    ret = evas_object_image_save(im, filename, NULL, NULL);
771    evas_object_del(im);
772    ecore_evas_free(ee);
773    return ret;
774 }
775
776 EAPI char *
777 e_util_shell_env_path_eval(const char *path)
778 {
779    /* evaluate things like:
780     * $HOME/bling -> /home/user/bling
781     * $HOME/bin/$HOSTNAME/blah -> /home/user/bin/localhost/blah
782     * etc. etc.
783     */
784    const char *p, *v2, *v1 = NULL;
785    char buf[PATH_MAX], *pd, *s, *vp;
786    char *v = NULL;
787    int esc = 0, invar = 0;
788
789    for (p = path, pd = buf; (pd < (buf + sizeof(buf) - 1)); p++)
790      {
791         if (invar)
792           {
793              if (!((isalnum(*p)) || (*p == '_')))
794                {
795                   v2 = p;
796                   invar = 0;
797                   if ((v2 - v1) > 1)
798                     {
799                        s = alloca(v2 - v1);
800                        strncpy(s, v1 + 1, v2 - v1 - 1);
801                        s[v2 - v1 - 1] = 0;
802                        if (strncmp(s, "XDG", 3))
803                          v = getenv(s);
804                        else
805                          {
806                             if (!strcmp(s, "XDG_CONFIG_HOME"))
807                               v = (char *)efreet_config_home_get();
808                             else if (!strcmp(s, "XDG_CACHE_HOME"))
809                               v = (char *)efreet_cache_home_get();
810                             else if (!strcmp(s, "XDG_DATA_HOME"))
811                               v = (char *)efreet_data_home_get();
812                          }
813
814                        if (v)
815                          {
816                             vp = v;
817                             while ((*vp) && (pd < (buf + sizeof(buf) - 1)))
818                               {
819                                  *pd = *vp;
820                                  vp++;
821                                  pd++;
822                               }
823                          }
824                     }
825                   if (pd < (buf + sizeof(buf) - 1))
826                     {
827                        *pd = *p;
828                        pd++;
829                     }
830                }
831           }
832         else
833           {
834              if (esc)
835                {
836                   *pd = *p;
837                   pd++;
838                }
839              else
840                {
841                   if (*p == '\\') esc = 1;
842                   else if (*p == '$')
843                     {
844                        invar = 1;
845                        v1 = p;
846                     }
847                   else
848                     {
849                        *pd = *p;
850                        pd++;
851                     }
852                }
853           }
854         if (*p == 0) break;
855      }
856    *pd = 0;
857    return strdup(buf);
858 }
859
860 EAPI char *
861 e_util_size_string_get(off_t size)
862 {
863    double dsize;
864    char buf[256];
865
866    dsize = (double)size;
867    if (dsize < 1024.0) snprintf(buf, sizeof(buf), _("%'.0f bytes"), dsize);
868    else
869      {
870         dsize /= 1024.0;
871         if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f KiB"), dsize);
872         else
873           {
874              dsize /= 1024.0;
875              if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f MiB"), dsize);
876              else
877                {
878                   dsize /= 1024.0;
879                   if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f GiB"), dsize);
880                   else
881                     {
882                        dsize /= 1024.0;
883                        snprintf(buf, sizeof(buf), _("%'.1f TiB"), dsize);
884                     }
885                }
886           }
887      }
888    return strdup(buf);
889 }
890
891 EAPI char *
892 e_util_file_time_get(time_t ftime)
893 {
894    time_t diff, ltime, test;
895    char buf[256];
896    char *s = NULL;
897
898    ltime = time(NULL);
899    diff = ltime - ftime;
900    buf[0] = 0;
901    if (ftime > ltime)
902      snprintf(buf, sizeof(buf), _("In the future"));
903    else
904      {
905         if (diff <= 60)
906           snprintf(buf, sizeof(buf), _("In the last minute"));
907         else if (diff >= 31526000)
908           {
909              test = diff / 31526000;
910              if (test == 1)
911                snprintf(buf, sizeof(buf), _("Last year"));
912              else
913                snprintf(buf, sizeof(buf), _("%li Years ago"), test);
914           }
915         else if (diff >= 2592000)
916           {
917              test = diff / 2592000;
918              if (test == 1)
919                snprintf(buf, sizeof(buf), _("Last month"));
920              else
921                snprintf(buf, sizeof(buf), _("%li Months ago"), test);
922           }
923         else if (diff >= 604800)
924           {
925              test = diff / 604800;
926              if (test == 1)
927                snprintf(buf, sizeof(buf), _("Last week"));
928              else
929                snprintf(buf, sizeof(buf), _("%li Weeks ago"), test);
930           }
931         else if (diff >= 86400)
932           {
933              test = diff / 86400;
934              if (test == 1)
935                snprintf(buf, sizeof(buf), _("Yesterday"));
936              else
937                snprintf(buf, sizeof(buf), _("%li Days ago"), test);
938           }
939         else if (diff >= 3600)
940           {
941              test = diff / 3600;
942              if (test == 1)
943                snprintf(buf, sizeof(buf), _("An hour ago"));
944              else
945                snprintf(buf, sizeof(buf), _("%li Hours ago"), test);
946           }
947         else if (diff > 60)
948           {
949              test = diff / 60;
950              if (test == 1)
951                snprintf(buf, sizeof(buf), _("A minute ago"));
952              else
953                snprintf(buf, sizeof(buf), _("%li Minutes ago"), test);
954           }
955      }
956
957    if (buf[0])
958      s = strdup(buf);
959    else
960      s = strdup(_("Unknown"));
961    return s;
962 }
963
964 //static char *prev_ld_library_path = NULL;
965 //static char *prev_path = NULL;
966
967 EAPI void
968 e_util_library_path_strip(void)
969 {
970 /* disabled as i think we dont need/want this anymore - leftover from a bygone era
971    char *p, *p2;
972
973    p = getenv("LD_LIBRARY_PATH");
974    E_FREE(prev_ld_library_path);
975    if (p)
976      {
977         prev_ld_library_path = strdup(p);
978         p2 = strchr(p, ':');
979         if (p2) p2++;
980         e_util_env_set("LD_LIBRARY_PATH", p2);
981      }
982    p = getenv("PATH");
983    E_FREE(prev_path);
984    if (p)
985      {
986         prev_path = strdup(p);
987         p2 = strchr(p, ':');
988         if (p2) p2++;
989         e_util_env_set("PATH", p2);
990      }
991  */
992 }
993
994 EAPI void
995 e_util_library_path_restore(void)
996 {
997 /* disabled as i think we dont need/want this anymore - leftover from a bygone era
998    if (prev_ld_library_path)
999      {
1000         e_util_env_set("LD_LIBRARY_PATH", prev_ld_library_path);
1001         E_FREE(prev_ld_library_path);
1002      }
1003    if (prev_path)
1004      {
1005         e_util_env_set("PATH", prev_path);
1006         E_FREE(prev_path);
1007      }
1008  */
1009 }
1010
1011 EAPI Evas_Object *
1012 e_util_icon_add(const char *path, Evas *evas)
1013 {
1014    return _e_util_icon_add(path, evas, 64);
1015 }
1016
1017 EAPI Evas_Object *
1018 e_util_desktop_icon_add(Efreet_Desktop *desktop, unsigned int size, Evas *evas)
1019 {
1020    if ((!desktop) || (!desktop->icon)) return NULL;
1021    return e_util_icon_theme_icon_add(desktop->icon, size, evas);
1022 }
1023
1024 EAPI Evas_Object *
1025 e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
1026 {
1027    if (!icon_name) return NULL;
1028    if (icon_name[0] == '/') return _e_util_icon_add(icon_name, evas, size);
1029    else
1030      {
1031         Evas_Object *obj;
1032         const char *path;
1033
1034         path = efreet_icon_path_find(e_config->icon_theme, icon_name, size);
1035         if (path)
1036           {
1037              obj = _e_util_icon_add(path, evas, size);
1038              return obj;
1039           }
1040      }
1041    return NULL;
1042 }
1043
1044 EAPI void
1045 e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_Menu_Item *mi)
1046 {
1047    const char *path = NULL;
1048
1049    if ((!desktop) || (!desktop->icon)) return;
1050
1051    if (desktop->icon[0] == '/') path = desktop->icon;
1052    else path = efreet_icon_path_find(e_config->icon_theme, desktop->icon, size);
1053
1054    if (path)
1055      {
1056         const char *ext;
1057
1058         ext = strrchr(path, '.');
1059         if (ext)
1060           {
1061              if (strcmp(ext, ".edj") == 0)
1062                e_menu_item_icon_edje_set(mi, path, "icon");
1063              else
1064                e_menu_item_icon_file_set(mi, path);
1065           }
1066         else
1067           e_menu_item_icon_file_set(mi, path);
1068      }
1069 }
1070
1071 EAPI int
1072 e_util_dir_check(const char *dir)
1073 {
1074    if (!ecore_file_exists(dir))
1075      {
1076         if (!ecore_file_mkpath(dir))
1077           {
1078              e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>Check that you have correct permissions set.", dir);
1079              return 0;
1080           }
1081      }
1082    else
1083      {
1084         if (!ecore_file_is_dir(dir))
1085           {
1086              e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>A file of that name already exists.", dir);
1087              return 0;
1088           }
1089      }
1090    return 1;
1091 }
1092
1093 EAPI void
1094 e_util_defer_object_del(E_Object *obj)
1095 {
1096    if (stopping)
1097      e_object_del(obj);
1098    else
1099      {
1100         Ecore_Idle_Enterer *idler;
1101
1102         idler = ecore_idle_enterer_before_add(_e_util_cb_delayed_del, obj);
1103         if (idler) e_object_delfn_add(obj, _e_util_cb_delayed_cancel, idler);
1104      }
1105 }
1106
1107 EAPI const char *
1108 e_util_winid_str_get(Ecore_X_Window win)
1109 {
1110    const char *vals = "qWeRtYuIoP5-$&<~";
1111    static char id[9];
1112    unsigned int val;
1113
1114    val = (unsigned int)win;
1115    id[0] = vals[(val >> 28) & 0xf];
1116    id[1] = vals[(val >> 24) & 0xf];
1117    id[2] = vals[(val >> 20) & 0xf];
1118    id[3] = vals[(val >> 16) & 0xf];
1119    id[4] = vals[(val >> 12) & 0xf];
1120    id[5] = vals[(val >> 8) & 0xf];
1121    id[6] = vals[(val >> 4) & 0xf];
1122    id[7] = vals[(val) & 0xf];
1123    id[8] = 0;
1124    return id;
1125 }
1126
1127 static int
1128 _win_auto_size_calc(int max, int min)
1129 {
1130    const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1};
1131
1132    for (itr = scales; *itr > 0; itr++)
1133      {
1134         int value = *itr * max;
1135         if (value > min) /* not >=, try a bit larger */
1136           return value;
1137      }
1138
1139    return min;
1140 }
1141
1142 EAPI void
1143 e_util_win_auto_resize_fill(E_Win *win)
1144 {
1145    E_Zone *zone = NULL;
1146
1147    if (win->border)
1148      zone = win->border->zone;
1149    if ((!zone) && (win->container))
1150      zone = e_util_zone_current_get(win->container->manager);
1151
1152    if (zone)
1153      {
1154         int w, h;
1155
1156         e_zone_useful_geometry_get(zone, NULL, NULL, &w, &h);
1157
1158         w = _win_auto_size_calc(w, win->min_w);
1159         h = _win_auto_size_calc(h, win->min_h);
1160         e_win_resize(win, w, h);
1161      }
1162 }
1163
1164 EAPI int
1165 e_util_container_desk_count_get(E_Container *con)
1166 {
1167    Eina_List *zl;
1168    E_Zone *zone;
1169    int count = 0;
1170
1171    E_OBJECT_CHECK_RETURN(con, 0);
1172    E_OBJECT_TYPE_CHECK_RETURN(con, E_CONTAINER_TYPE, 0);
1173    EINA_LIST_FOREACH(con->zones, zl, zone)
1174      {
1175         int x, y;
1176         int cx = 0, cy = 0;
1177
1178         e_zone_desk_count_get(zone, &cx, &cy);
1179         for (x = 0; x < cx; x++)
1180           {
1181              for (y = 0; y < cy; y++)
1182                count += 1;
1183           }
1184      }
1185    return count;
1186 }
1187
1188 /* local subsystem functions */
1189
1190 static Evas_Object *
1191 _e_util_icon_add(const char *path, Evas *evas, int size)
1192 {
1193    Evas_Object *o = NULL;
1194    const char *ext;
1195
1196    if (!path) return NULL;
1197    if (!ecore_file_exists(path)) return NULL;
1198
1199    o = e_icon_add(evas);
1200    e_icon_scale_size_set(o, size);
1201    e_icon_preload_set(o, 1);
1202    ext = strrchr(path, '.');
1203    if (ext)
1204      {
1205         if (!strcmp(ext, ".edj"))
1206           e_icon_file_edje_set(o, path, "icon");
1207         else
1208           e_icon_file_set(o, path);
1209      }
1210    else
1211      e_icon_file_set(o, path);
1212    e_icon_fill_inside_set(o, 1);
1213
1214    return o;
1215 }
1216
1217 static Eina_Bool
1218 _e_util_cb_delayed_del(void *data)
1219 {
1220    e_object_del(E_OBJECT(data));
1221    return ECORE_CALLBACK_CANCEL;
1222 }
1223
1224 static void
1225 _e_util_cb_delayed_cancel(void *data, void *obj __UNUSED__)
1226 {
1227    Ecore_Idle_Enterer *idler = data;
1228
1229    ecore_idle_enterer_del(idler);
1230 }
1231
1232 static Eina_Bool
1233 _e_util_wakeup_cb(void *data __UNUSED__)
1234 {
1235    _e_util_dummy_timer = NULL;
1236    return ECORE_CALLBACK_CANCEL;
1237 }
1238
1239 static Eina_Bool
1240 _e_util_conf_timer_old(void *data)
1241 {
1242    char *module_name = data;
1243    char buf[4096];
1244    char *msg = _("Configuration data needed upgrading. Your old configuration<br>"
1245                  "has been wiped and a new set of defaults initialized. This<br>"
1246                  "will happen regularly during development, so don't report a<br>"
1247                  "bug. This means the module needs new configuration<br>"
1248                  "data by default for usable functionality that your old<br>"
1249                  "configuration lacked. This new set of defaults will fix<br>"
1250                  "that by adding it in. You can re-configure things now to your<br>"
1251                  "liking. Sorry for the hiccup in your configuration.<br>");
1252
1253    snprintf(buf, sizeof(buf), N_("%s Configuration Updated"), module_name);
1254    e_util_dialog_internal(buf, msg);
1255    E_FREE(module_name);
1256
1257    return ECORE_CALLBACK_CANCEL;
1258 }
1259
1260 static Eina_Bool
1261 _e_util_conf_timer_new(void *data)
1262 {
1263    char *module_name = data;
1264    char buf[4096];
1265    char *msg =
1266      _("Your module configuration is NEWER "
1267        "than the module version. This is "
1268        "very<br>strange. This should not happen unless"
1269        " you downgraded<br>the module or "
1270        "copied the configuration from a place where"
1271        "<br>a newer version of the module "
1272        "was running. This is bad and<br>as a "
1273        "precaution your configuration has been now "
1274        "restored to<br>defaults. Sorry for the "
1275        "inconvenience.<br>");
1276
1277    snprintf(buf, sizeof(buf), N_("%s Configuration Updated"), module_name);
1278    e_util_dialog_internal(buf, msg);
1279    E_FREE(module_name);
1280
1281    return ECORE_CALLBACK_CANCEL;
1282 }
1283
1284 EAPI Eina_Bool
1285 e_util_module_config_check(const char *module_name, int loaded, int current)
1286 {
1287    if ((loaded >> 16) < (current >> 16))
1288      {
1289         ecore_timer_add(1.0, _e_util_conf_timer_old, strdup(module_name));
1290         return EINA_FALSE;
1291      }
1292    else if (loaded > current)
1293      {
1294         ecore_timer_add(1.0, _e_util_conf_timer_new, strdup(module_name));
1295         return EINA_FALSE;
1296      }
1297
1298    return EINA_TRUE;
1299 }
1300
1301 /**
1302  * Checks whenever the current manager/container/zone have fullscreen windows.
1303  */
1304 EAPI Eina_Bool
1305 e_util_fullscreen_curreny_any(void)
1306 {
1307    E_Manager *man = e_manager_current_get();
1308    E_Container *con = e_container_current_get(man);
1309    E_Zone *zone = e_zone_current_get(con);
1310    E_Desk *desk;
1311
1312    if ((zone) && (zone->fullscreen > 0)) return EINA_TRUE;
1313    desk = e_desk_current_get(zone);
1314    if ((desk) && (desk->fullscreen_borders > 0)) return EINA_TRUE;
1315    return EINA_FALSE;
1316 }
1317
1318 /**
1319  * Checks whenever any manager/container/zone have fullscreen windows.
1320  */
1321 EAPI Eina_Bool
1322 e_util_fullscreen_any(void)
1323 {
1324    E_Zone *zone;
1325    Eina_List *lm, *lc, *lz;
1326    E_Container *con;
1327    E_Manager *man;
1328    E_Desk *desk;
1329    int x, y;
1330
1331    EINA_LIST_FOREACH(e_manager_list(), lm, man)
1332      {
1333         EINA_LIST_FOREACH(man->containers, lc, con)
1334           {
1335              EINA_LIST_FOREACH(con->zones, lz, zone)
1336                {
1337                   if (zone->fullscreen > 0) return EINA_TRUE;
1338
1339                   for (x = 0; x < zone->desk_x_count; x++)
1340                     for (y = 0; y < zone->desk_y_count; y++)
1341                       {
1342                          desk = e_desk_at_xy_get(zone, x, y);
1343                          if ((desk) && (desk->fullscreen_borders > 0))
1344                            return EINA_TRUE;
1345                       }
1346                }
1347           }
1348      }
1349    return EINA_FALSE;
1350 }
1351
1352 EAPI const char *
1353 e_util_time_str_get(long int seconds)
1354 {
1355    static char buf[1024];
1356    long int test;
1357
1358    if (seconds < 0)
1359      snprintf(buf, sizeof(buf), _("Never"));
1360    else
1361      {
1362         if (seconds <= 60)
1363           snprintf(buf, sizeof(buf), _("%li Seconds"), seconds);
1364         else if (seconds >= 31526000)
1365           {
1366              test = seconds / 31526000;
1367              if (test == 1)
1368                snprintf(buf, sizeof(buf), _("One year"));
1369              else
1370                snprintf(buf, sizeof(buf), _("%li Years"), test);
1371           }
1372         else if (seconds >= 2592000)
1373           {
1374              test = seconds / 2592000;
1375              if (test == 1)
1376                snprintf(buf, sizeof(buf), _("One month"));
1377              else
1378                snprintf(buf, sizeof(buf), _("%li Months"), test);
1379           }
1380         else if (seconds >= 604800)
1381           {
1382              test = seconds / 604800;
1383              if (test == 1)
1384                snprintf(buf, sizeof(buf), _("One week"));
1385              else
1386                snprintf(buf, sizeof(buf), _("%li Weeks"), test);
1387           }
1388         else if (seconds >= 86400)
1389           {
1390              test = seconds / 86400;
1391              if (test == 1)
1392                snprintf(buf, sizeof(buf), _("One day"));
1393              else
1394                snprintf(buf, sizeof(buf), _("%li Days"), test);
1395           }
1396         else if (seconds >= 3600)
1397           {
1398              test = seconds / 3600;
1399              if (test == 1)
1400                snprintf(buf, sizeof(buf), _("An hour"));
1401              else
1402                snprintf(buf, sizeof(buf), _("%li Hours"), test);
1403           }
1404         else if (seconds > 60)
1405           {
1406              test = seconds / 60;
1407              if (test == 1)
1408                snprintf(buf, sizeof(buf), _("A minute"));
1409              else
1410                snprintf(buf, sizeof(buf), _("%li Minutes"), test);
1411           }
1412      }
1413    return buf;
1414 }
1415
1416 static void
1417 _e_util_size_debug(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1418 {
1419    int x, y, w, h;
1420
1421    evas_object_geometry_get(obj, &x, &y, &w, &h);
1422    fprintf(stderr, "OBJ[%p]: (%d,%d) - %dx%d\n", obj, x, y, w, h);
1423 }
1424
1425 EAPI void
1426 e_util_size_debug_set(Evas_Object *obj, Eina_Bool enable)
1427 {
1428    if (enable)
1429      {
1430         evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, 
1431                                        _e_util_size_debug, NULL);
1432         evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, 
1433                                        _e_util_size_debug, NULL);
1434      }
1435    else
1436      {
1437         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE, 
1438                                             _e_util_size_debug, NULL);
1439         evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, 
1440                                             _e_util_size_debug, NULL);
1441      }
1442 }
1443
1444 static Efreet_Desktop *
1445 _e_util_default_terminal_get(const char *defaults_list)
1446 {
1447    Efreet_Desktop *tdesktop = NULL;
1448    Efreet_Ini *ini;
1449    const char *s;
1450    
1451    ini = efreet_ini_new(defaults_list);
1452    if ((ini) && (ini->data) &&
1453        (efreet_ini_section_set(ini, "Default Applications")) &&
1454        (ini->section))
1455      {
1456         s = efreet_ini_string_get(ini, "x-scheme-handler/terminal");
1457         if (s) tdesktop = efreet_util_desktop_file_id_find(s);
1458      }
1459    if (ini) efreet_ini_free(ini);
1460    return tdesktop;
1461 }
1462
1463 EAPI Efreet_Desktop *
1464 e_util_terminal_desktop_get(void)
1465 {
1466    const char *terms[] =
1467      {
1468         "terminology.desktop",
1469         "xterm.desktop",
1470         "rxvt.desktop",
1471         "gnome-terminal.desktop",
1472         "konsole.desktop",
1473         NULL
1474      };
1475    const char *s;
1476    char buf[PATH_MAX];
1477    Efreet_Desktop *tdesktop = NULL, *td;
1478    Eina_List *l;
1479    int i;
1480
1481    s = efreet_data_home_get();
1482    if (s)
1483      {
1484         snprintf(buf, sizeof(buf), "%s/applications/defaults.list", s);
1485         tdesktop = _e_util_default_terminal_get(buf);
1486      }
1487    if (tdesktop) return tdesktop;
1488    EINA_LIST_FOREACH(efreet_data_dirs_get(), l, s)
1489      {
1490         snprintf(buf, sizeof(buf), "%s/applications/defaults.list", s);
1491         tdesktop = _e_util_default_terminal_get(buf);
1492         if (tdesktop) return tdesktop;
1493      }
1494    
1495    for (i = 0; terms[i]; i++)
1496      {
1497         tdesktop = efreet_util_desktop_file_id_find(terms[i]);
1498         if (tdesktop) return tdesktop;
1499      }
1500    if (!tdesktop)
1501      {
1502         l = efreet_util_desktop_category_list("TerminalEmulator");
1503         if (l)
1504           {
1505              // just take first one since above list doesn't work.
1506              tdesktop = l->data;
1507              EINA_LIST_FREE(l, td)
1508                {
1509                   // free/unref the desktosp we are not going to use
1510                   if (td != tdesktop) efreet_desktop_free(td);
1511                }
1512           }
1513      }
1514    return tdesktop;
1515 }
1516
1517
1518 EAPI E_Config_Binding_Key *
1519 e_util_binding_match(const Eina_List *bindlist, Ecore_Event_Key *ev, unsigned int *num, const E_Config_Binding_Key *skip)
1520 {
1521    E_Config_Binding_Key *bi;
1522    const Eina_List *l;
1523    unsigned int mod = E_BINDING_MODIFIER_NONE;
1524
1525    if (num) *num = 0;
1526
1527    if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1528      mod |= E_BINDING_MODIFIER_SHIFT;
1529    if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1530      mod |= E_BINDING_MODIFIER_CTRL;
1531    if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT)
1532      mod |= E_BINDING_MODIFIER_ALT;
1533    if (ev->modifiers & ECORE_EVENT_MODIFIER_WIN)
1534      mod |= E_BINDING_MODIFIER_WIN;
1535    /* see comment in e_bindings on numlock
1536       if (ev->modifiers & ECORE_X_LOCK_NUM)
1537       mod |= ECORE_X_LOCK_NUM;
1538     */
1539    EINA_LIST_FOREACH(bindlist ?: e_config->key_bindings, l, bi)
1540      {
1541         if (bi != skip)
1542           {
1543              if ((bi->modifiers == mod) && (!strcmp(bi->key, ev->keyname)))
1544                return bi;
1545           }
1546         if (num) (*num)++;
1547      }
1548    if (num) *num = 0;
1549    return NULL;
1550 }
1551
1552 EAPI void
1553 e_util_gadcon_orient_icon_set(E_Gadcon_Orient orient, Evas_Object *obj)
1554 {
1555    switch (orient)
1556      {
1557       case E_GADCON_ORIENT_LEFT:
1558         e_util_icon_theme_set(obj, "preferences-position-left");
1559         break;
1560
1561       case E_GADCON_ORIENT_RIGHT:
1562         e_util_icon_theme_set(obj, "preferences-position-right");
1563         break;
1564
1565       case E_GADCON_ORIENT_TOP:
1566         e_util_icon_theme_set(obj, "preferences-position-top");
1567         break;
1568
1569       case E_GADCON_ORIENT_BOTTOM:
1570         e_util_icon_theme_set(obj, "preferences-position-bottom");
1571         break;
1572
1573       case E_GADCON_ORIENT_CORNER_TL:
1574         e_util_icon_theme_set(obj, "preferences-position-top-left");
1575         break;
1576
1577       case E_GADCON_ORIENT_CORNER_TR:
1578         e_util_icon_theme_set(obj, "preferences-position-top-right");
1579         break;
1580
1581       case E_GADCON_ORIENT_CORNER_BL:
1582         e_util_icon_theme_set(obj, "preferences-position-bottom-left");
1583         break;
1584
1585       case E_GADCON_ORIENT_CORNER_BR:
1586         e_util_icon_theme_set(obj, "preferences-position-bottom-right");
1587         break;
1588
1589       case E_GADCON_ORIENT_CORNER_LT:
1590         e_util_icon_theme_set(obj, "preferences-position-left-top");
1591         break;
1592
1593       case E_GADCON_ORIENT_CORNER_RT:
1594         e_util_icon_theme_set(obj, "preferences-position-right-top");
1595         break;
1596
1597       case E_GADCON_ORIENT_CORNER_LB:
1598         e_util_icon_theme_set(obj, "preferences-position-left-bottom");
1599         break;
1600
1601       case E_GADCON_ORIENT_CORNER_RB:
1602         e_util_icon_theme_set(obj, "preferences-position-right-bottom");
1603         break;
1604
1605       default:
1606         e_util_icon_theme_set(obj, "enlightenment");
1607         break;
1608      }
1609 }
1610
1611 EAPI void
1612 e_util_gadcon_orient_menu_item_icon_set(E_Gadcon_Orient orient, E_Menu_Item *mi)
1613 {
1614    switch (orient)
1615      {
1616       case E_GADCON_ORIENT_LEFT:
1617         e_util_menu_item_theme_icon_set(mi, "preferences-position-left");
1618         break;
1619
1620       case E_GADCON_ORIENT_RIGHT:
1621         e_util_menu_item_theme_icon_set(mi, "preferences-position-right");
1622         break;
1623
1624       case E_GADCON_ORIENT_TOP:
1625         e_util_menu_item_theme_icon_set(mi, "preferences-position-top");
1626         break;
1627
1628       case E_GADCON_ORIENT_BOTTOM:
1629         e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom");
1630         break;
1631
1632       case E_GADCON_ORIENT_CORNER_TL:
1633         e_util_menu_item_theme_icon_set(mi, "preferences-position-top-left");
1634         break;
1635
1636       case E_GADCON_ORIENT_CORNER_TR:
1637         e_util_menu_item_theme_icon_set(mi, "preferences-position-top-right");
1638         break;
1639
1640       case E_GADCON_ORIENT_CORNER_BL:
1641         e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom-left");
1642         break;
1643
1644       case E_GADCON_ORIENT_CORNER_BR:
1645         e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom-right");
1646         break;
1647
1648       case E_GADCON_ORIENT_CORNER_LT:
1649         e_util_menu_item_theme_icon_set(mi, "preferences-position-left-top");
1650         break;
1651
1652       case E_GADCON_ORIENT_CORNER_RT:
1653         e_util_menu_item_theme_icon_set(mi, "preferences-position-right-top");
1654         break;
1655
1656       case E_GADCON_ORIENT_CORNER_LB:
1657         e_util_menu_item_theme_icon_set(mi, "preferences-position-left-bottom");
1658         break;
1659
1660       case E_GADCON_ORIENT_CORNER_RB:
1661         e_util_menu_item_theme_icon_set(mi, "preferences-position-right-bottom");
1662         break;
1663
1664       default:
1665         e_util_menu_item_theme_icon_set(mi, "enlightenment");
1666         break;
1667      }
1668 }
1669
1670 #if _F_USE_EXTN_DIALOG_
1671 /**
1672  * Using external elementary dialog util instead of e_dialog to display error or warning
1673  * messages. It is a temporary solution for supporting consistent UX theme. The external
1674  * dialog is a simple EFL application which is based on elementary. Thus window manager
1675  * can display message using elementary UX theme, along with other system popup.
1676  */
1677 EAPI void
1678 e_util_extn_dialog_show(const char *title,
1679                         const char *txt)
1680 {
1681    Ecore_Exe *exe;
1682    char cmd[4096];
1683
1684    /* external_dialog_name, icccm_name, icccm_class, popup_title, popup_contents */
1685    snprintf(cmd, sizeof(cmd), "/usr/bin/extndialog E _extn_dialog \'%s\' \'%s\'", title, txt);
1686    exe = ecore_exe_run(cmd, NULL);
1687    if (exe) ecore_exe_free(exe);
1688 }
1689 #endif