EINTERN int E_EVENT_FILE_MONITOR_CREATED = -1;
/* local subsystem functions */
-static Eina_Bool _e_util_cb_delayed_del(void *data);
static Eina_Bool _e_util_wakeup_cb(void *data);
-static void _e_util_cb_delayed_cancel(void *data, void *obj);
-
/* local subsystem globals */
static Ecore_Timer *_e_util_dummy_timer = NULL;
static Eina_Hash *_e_file_monitor_hash = NULL;
return 0x7fffffff;
}
-EINTERN int
-e_util_strcasecmp(const char *s1, const char *s2)
-{
- if ((!s1) && (!s2)) return 0;
- if (!s1) return -1;
- if (!s2) return 1;
- return strcasecmp(s1, s2);
-}
-
-EINTERN int
-e_util_both_str_empty(const char *s1, const char *s2)
-{
- int empty = 0;
-
- if ((!s1) && (!s2)) return 1;
- if ((!s1) || ((s1) && (s1[0] == 0))) empty++;
- if ((!s2) || ((s2) && (s2[0] == 0))) empty++;
- if (empty == 2) return 1;
- return 0;
-}
-
-EINTERN unsigned int
-e_util_icon_size_normalize(unsigned int desired)
-{
- const unsigned int *itr, known_sizes[] =
- {
- 16, 22, 24, 32, 36, 48, 64, 72, 96, 128, 192, 256, 0
- };
-
- for (itr = known_sizes; *itr > 0; itr++)
- if (*itr >= desired)
- return *itr;
-
- return 256; /* largest know size? */
-}
-
-EINTERN E_Client *
-e_util_desk_client_above(E_Client *ec)
-{
- E_Client *ec2;
- E_Desk *desk;
-
- E_OBJECT_CHECK_RETURN(ec, NULL);
- E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
-
- desk = e_comp_desk_find_by_ec(ec);
- EINA_SAFETY_ON_NULL_RETURN_VAL(desk, NULL);
-
- for (ec2 = e_client_above_get(ec); ec2; ec2 = e_client_above_get(ec2))
- {
- if ((e_desk_has_ec(desk, ec2)) || (ec2->sticky)) return ec2;
- }
- return NULL;
-}
-
-EINTERN E_Client *
-e_util_desk_client_below(E_Client *ec)
-{
- E_Client *ec2;
- E_Desk *desk;
-
- E_OBJECT_CHECK_RETURN(ec, NULL);
- E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, NULL);
-
- desk = e_comp_desk_find_by_ec(ec);
- EINA_SAFETY_ON_NULL_RETURN_VAL(desk, NULL);
-
- for (ec2 = e_client_below_get(ec); ec2; ec2 = e_client_below_get(ec2))
- {
- if ((e_desk_has_ec(desk, ec2)) || (ec2->sticky)) return ec2;
- }
- return NULL;
-}
-
-EINTERN int
-e_util_edje_collection_exists(const char *file, const char *coll)
-{
- Eina_List *clist;
- Eina_Stringshare *str;
- Eina_Bool ret = EINA_FALSE;
-
- clist = edje_file_collection_list(file);
- EINA_LIST_FREE(clist, str)
- {
- if ((!ret) && (!strcmp(coll, str)))
- ret = EINA_TRUE;
- eina_stringshare_del(str);
- }
- return ret;
-}
-
-EINTERN const char *
-e_util_filename_escape(const char *filename)
-{
- const char *p;
- char *q;
- static char buf[PATH_MAX];
-
- if (!filename) return NULL;
- p = filename;
- q = buf;
- while (*p)
- {
- if ((q - buf) > 4090) return NULL;
- if (
- (*p == ' ') || (*p == '\t') || (*p == '\n') ||
- (*p == '\\') || (*p == '\'') || (*p == '\"') ||
- (*p == ';') || (*p == '!') || (*p == '#') ||
- (*p == '$') || (*p == '%') || (*p == '&') ||
- (*p == '*') || (*p == '(') || (*p == ')') ||
- (*p == '[') || (*p == ']') || (*p == '{') ||
- (*p == '}') || (*p == '|') || (*p == '<') ||
- (*p == '>') || (*p == '?')
- )
- {
- *q = '\\';
- q++;
- }
- *q = *p;
- q++;
- p++;
- }
- *q = 0;
- return buf;
-}
-
-EINTERN char *
-e_util_size_string_get(off_t size)
-{
- double dsize;
- char buf[256];
-
- dsize = (double)size;
- if (dsize < 1024.0) snprintf(buf, sizeof(buf), _("%'.0f bytes"), dsize);
- else
- {
- dsize /= 1024.0;
- if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f KiB"), dsize);
- else
- {
- dsize /= 1024.0;
- if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f MiB"), dsize);
- else
- {
- dsize /= 1024.0;
- if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f GiB"), dsize);
- else
- {
- dsize /= 1024.0;
- snprintf(buf, sizeof(buf), _("%'.1f TiB"), dsize);
- }
- }
- }
- }
- return strdup(buf);
-}
-
-EINTERN char *
-e_util_file_time_get(time_t ftime)
-{
- time_t diff, ltime, test;
- char buf[256];
- char *s = NULL;
-
- ltime = time(NULL);
- diff = ltime - ftime;
- buf[0] = 0;
- if (ftime > ltime)
- snprintf(buf, sizeof(buf), _("In the future"));
- else
- {
- if (diff <= 60)
- snprintf(buf, sizeof(buf), _("In the last minute"));
- else if (diff >= 31526000)
- {
- test = diff / 31526000;
- snprintf(buf, sizeof(buf), P_("Last year", "%li Years ago", test), test);
- }
- else if (diff >= 2592000)
- {
- test = diff / 2592000;
- snprintf(buf, sizeof(buf), P_("Last month", "%li Months ago", test), test);
- }
- else if (diff >= 604800)
- {
- test = diff / 604800;
- snprintf(buf, sizeof(buf), P_("Last week", "%li Weeks ago", test), test);
- }
- else if (diff >= 86400)
- {
- test = diff / 86400;
- snprintf(buf, sizeof(buf), P_("Yesterday", "%li Days ago", test), test);
- }
- else if (diff >= 3600)
- {
- test = diff / 3600;
- snprintf(buf, sizeof(buf), P_("An hour ago", "%li Hours ago", test), test);
- }
- else if (diff > 60)
- {
- test = diff / 60;
- snprintf(buf, sizeof(buf), P_("A minute ago", "%li Minutes ago", test), test);
- }
- }
-
- if (buf[0])
- s = strdup(buf);
- else
- s = strdup(_("Unknown"));
- return s;
-}
-
-EINTERN int
-e_util_dir_check(const char *dir)
-{
- if (!ecore_file_exists(dir))
- {
- if (!ecore_file_mkpath(dir))
- {
- ERR("Error creating directory. Failed to create directory: %s .Check that you have correct permissions set.", dir);
- return 0;
- }
- }
- else
- {
- if (!ecore_file_is_dir(dir))
- {
- ERR("Error creating directory. Failed to create directory: %s . A file of that name already exists.", dir);
- return 0;
- }
- }
- return 1;
-}
-
-EINTERN void
-e_util_defer_object_del(E_Object *obj)
-{
- if (stopping)
- e_object_del(obj);
- else
- {
- Ecore_Idle_Enterer *idler;
-
- idler = ecore_idle_enterer_before_add(_e_util_cb_delayed_del, obj);
- if (idler) e_object_delfn_add(obj, _e_util_cb_delayed_cancel, idler);
- }
-}
-
-static int
-_win_auto_size_calc(int max, int min)
-{
- const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1};
-
- for (itr = scales; *itr > 0; itr++)
- {
- int value = *itr * max;
- if (value > min) /* not >=, try a bit larger */
- {
- if (min > 10)
- value = E_CLAMP(value, min, min * 1.5);
- return value;
- }
- }
-
- return min;
-}
-
-EINTERN void
-e_util_win_auto_resize_fill(Evas_Object *win)
-{
- E_Zone *zone = NULL;
-
- zone = e_zone_current_get();
-
- if (zone)
- {
- int w, h, mw, mh;
-
- e_zone_useful_geometry_get(zone, NULL, NULL, &w, &h);
-
- evas_object_size_hint_min_get(win, &mw, &mh);
- w = _win_auto_size_calc(w, mw);
- h = _win_auto_size_calc(h, mh);
- evas_object_resize(win, w, h);
- }
-}
-
/* local subsystem functions */
-static Eina_Bool
-_e_util_cb_delayed_del(void *data)
-{
- e_object_del(E_OBJECT(data));
- return ECORE_CALLBACK_CANCEL;
-}
-
-static void
-_e_util_cb_delayed_cancel(void *data, void *obj EINA_UNUSED)
-{
- Ecore_Idle_Enterer *idler = data;
-
- ecore_idle_enterer_del(idler);
-}
-
static Eina_Bool
_e_util_wakeup_cb(void *data EINA_UNUSED)
{
return ECORE_CALLBACK_CANCEL;
}
-static Eina_Bool
-_e_util_conf_timer_old(void *data)
-{
- char *module_name = data;
-
- E_FREE(module_name);
-
- return ECORE_CALLBACK_CANCEL;
-}
-
-static Eina_Bool
-_e_util_conf_timer_new(void *data)
-{
- char *module_name = data;
-
- E_FREE(module_name);
-
- return ECORE_CALLBACK_CANCEL;
-}
-
-EINTERN Eina_Bool
-e_util_module_config_check(const char *module_name, int loaded, int current)
-{
- if (loaded > current)
- {
- ecore_timer_add(1.0, _e_util_conf_timer_new, strdup(module_name));
- return EINA_FALSE;
- }
- loaded -= loaded % 1000000, current -= current % 1000000;
- if (loaded < current)
- {
- ecore_timer_add(1.0, _e_util_conf_timer_old, strdup(module_name));
- return EINA_FALSE;
- }
-
- return EINA_TRUE;
-}
-
-EINTERN const char *
-e_util_time_str_get(long int seconds)
-{
- static char buf[1024];
- long int test;
-
- if (seconds < 0)
- snprintf(buf, sizeof(buf), _("Never"));
- else
- {
- if (seconds <= 60)
- snprintf(buf, sizeof(buf), P_("A second", "%li Seconds", seconds), seconds);
- else if (seconds >= 31526000)
- {
- test = seconds / 31526000;
- snprintf(buf, sizeof(buf), P_("One year", "%li Years", test), test);
- }
- else if (seconds >= 2592000)
- {
- test = seconds / 2592000;
- snprintf(buf, sizeof(buf), P_("One month", "%li Months", test), test);
- }
- else if (seconds >= 604800)
- {
- test = seconds / 604800;
- snprintf(buf, sizeof(buf), P_("One week", "%li Weeks", test), test);
- }
- else if (seconds >= 86400)
- {
- test = seconds / 86400;
- snprintf(buf, sizeof(buf), P_("One day", "%li Days", test), test);
- }
- else if (seconds >= 3600)
- {
- test = seconds / 3600;
- snprintf(buf, sizeof(buf), P_("An hour", "%li Hours", test), test);
- }
- else if (seconds > 60)
- {
- test = seconds / 60;
- snprintf(buf, sizeof(buf), P_("A minute", "%li Minutes", test), test);
- }
- }
- return buf;
-}
-
static void
_e_util_size_debug_free(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
}
}
-EINTERN void
-e_util_string_list_free(Eina_List *l)
-{
- char *s;
-
- EINA_LIST_FREE(l, s)
- free(s);
-}
-
EINTERN char *
e_util_string_append_char(char *str, size_t *size, size_t *len, char c)
{
return EINA_TRUE;
}
-EINTERN void
-e_util_evas_objects_above_print(Evas_Object *o)
-{
- Evas_Object *a, *oo;
-
- EINA_SAFETY_ON_NULL_RETURN(o);
- a = o;
- while ((a = evas_object_above_get(a)))
- {
- const Eina_List *l, *ll;
-
- l = evas_object_clipees_get(a);
- if (l)
- {
- fprintf(stderr, "[%p] - %s(%s) %s :: CLIPPEES: ", a, evas_object_type_get(a), evas_object_name_get(a), evas_object_visible_get(a) ? "VISIBLE" : "HIDDEN");
- EINA_LIST_FOREACH(l, ll, oo)
- fprintf(stderr, "[%p] - %s(%s) %s", oo, evas_object_type_get(oo), evas_object_name_get(oo), ll->next ? "| " : "");
- }
- else
- fprintf(stderr, "[%p] - %s(%s) %s\n", a, evas_object_type_get(a), evas_object_name_get(a), evas_object_visible_get(a) ? "VISIBLE" : "HIDDEN");
- }
-}
-
-EINTERN void
-e_util_evas_objects_above_print_smart(Evas_Object *o)
-{
- Evas_Object *a, *oo;
-
- EINA_SAFETY_ON_NULL_RETURN(o);
- a = o;
- while ((a = evas_object_above_get(a)))
- {
- const Eina_List *l, *ll;
-
- l = evas_object_clipees_get(a);
- if (l)
- {
- fprintf(stderr, "[%p] - %s(%s) %s :: CLIPPEES: ", a, evas_object_type_get(a), evas_object_name_get(a), evas_object_visible_get(a) ? "VISIBLE" : "HIDDEN");
- EINA_LIST_FOREACH(l, ll, oo)
- fprintf(stderr, "[%p] - %s(%s) %s", oo, evas_object_type_get(oo), evas_object_name_get(oo), ll->next ? "| " : "");
- fprintf(stderr, "\n");
- }
- else if (evas_object_smart_data_get(a))
- {
- fprintf(stderr, "[%p] - %s(%s) %s :: SMART MEMBERS: ", a, evas_object_type_get(a), evas_object_name_get(a), evas_object_visible_get(a) ? "VISIBLE" : "HIDDEN");
- EINA_LIST_FOREACH(evas_object_smart_members_get(a), l, oo)
- fprintf(stderr, "[%p] - %s(%s) %s", oo, evas_object_type_get(oo), evas_object_name_get(oo), l->next ? "| " : "");
- fprintf(stderr, "\n");
- }
- else
- fprintf(stderr, "[%p] - %s(%s) %s\n", a, evas_object_type_get(a), evas_object_name_get(a), evas_object_visible_get(a) ? "VISIBLE" : "HIDDEN");
- }
-}
-
-/*
- * NOTICE: This function should not be used by external modules!!!
- *
- * This function is just a hack to allow us to "securely" clear sensitive
- * info until memset_s() is readily available, or at least we move this hack
- * to Eina.
- *
- * This is going to work until link time optimizations are good enough.
- * Hopefully by then, we'll be able to properly use memset_s().
- */
-static void *(* const volatile memset_ptr)(void *, int, size_t) = memset;
-
-EINTERN void
-e_util_memclear(void *s, size_t n)
-{
- memset_ptr(s, 0, n);
-}
-
EINTERN Eina_Bool
e_util_file_realpath_check(const char* path, Eina_Bool del_link)
{