Eet cache for efreet desktop

SVN revision: 46726
devs/devilhorns/wayland_egl
Sebastian Dransfeld 13 years ago
parent cf5a3517b9
commit f72d4f9342
  1. 28
      legacy/efreet/configure.ac
  2. 2
      legacy/efreet/src/Makefile.am
  3. 39
      legacy/efreet/src/bin/Makefile.am
  4. 48
      legacy/efreet/src/bin/ef_cache.c
  5. 254
      legacy/efreet/src/bin/efreet_desktop_cache_create.c
  6. 1
      legacy/efreet/src/lib/Makefile.am
  7. 8
      legacy/efreet/src/lib/efreet.c
  8. 38
      legacy/efreet/src/lib/efreet_base.c
  9. 225
      legacy/efreet/src/lib/efreet_desktop.c
  10. 15
      legacy/efreet/src/lib/efreet_desktop.h
  11. 4
      legacy/efreet/src/lib/efreet_icon.c
  12. 7
      legacy/efreet/src/lib/efreet_ini.c
  13. 14
      legacy/efreet/src/lib/efreet_menu.c
  14. 22
      legacy/efreet/src/lib/efreet_private.h
  15. 1151
      legacy/efreet/src/lib/efreet_utils.c
  16. 19
      legacy/efreet/src/lib/efreet_utils.h
  17. 0
      legacy/efreet/src/tests/.cvsignore
  18. 43
      legacy/efreet/src/tests/Makefile.am
  19. 0
      legacy/efreet/src/tests/compare/.cvsignore
  20. 0
      legacy/efreet/src/tests/compare/Makefile.am
  21. 0
      legacy/efreet/src/tests/compare/comp.h
  22. 0
      legacy/efreet/src/tests/compare/efreet_alloc.c
  23. 0
      legacy/efreet/src/tests/compare/efreet_menu_alloc.c
  24. 0
      legacy/efreet/src/tests/data/.cvsignore
  25. 0
      legacy/efreet/src/tests/data/Makefile.am
  26. 0
      legacy/efreet/src/tests/data/entry
  27. 0
      legacy/efreet/src/tests/data/entry.png
  28. 0
      legacy/efreet/src/tests/data/long.ini
  29. 0
      legacy/efreet/src/tests/data/preferences.menu
  30. 0
      legacy/efreet/src/tests/data/sub/.cvsignore
  31. 0
      legacy/efreet/src/tests/data/sub/Makefile.am
  32. 0
      legacy/efreet/src/tests/data/sub/test.desktop
  33. 0
      legacy/efreet/src/tests/data/test.desktop
  34. 0
      legacy/efreet/src/tests/data/test.ini
  35. 0
      legacy/efreet/src/tests/data/test.menu
  36. 0
      legacy/efreet/src/tests/data/test_garbage
  37. 0
      legacy/efreet/src/tests/data/test_menu_bad_comment.menu
  38. 0
      legacy/efreet/src/tests/data/test_menu_slash_bad.menu
  39. 0
      legacy/efreet/src/tests/data/test_type.desktop
  40. 143
      legacy/efreet/src/tests/ef_cache.c
  41. 6
      legacy/efreet/src/tests/ef_data_dirs.c
  42. 8
      legacy/efreet/src/tests/ef_desktop.c
  43. 0
      legacy/efreet/src/tests/ef_icon_theme.c
  44. 0
      legacy/efreet/src/tests/ef_ini.c
  45. 0
      legacy/efreet/src/tests/ef_locale.c
  46. 0
      legacy/efreet/src/tests/ef_menu.c
  47. 0
      legacy/efreet/src/tests/ef_mime.c
  48. 0
      legacy/efreet/src/tests/ef_test.h
  49. 6
      legacy/efreet/src/tests/ef_utils.c
  50. 0
      legacy/efreet/src/tests/efreet_spec_test.c
  51. 0
      legacy/efreet/src/tests/main.c

@ -73,7 +73,7 @@ AC_FUNC_ALLOCA
AC_CHECK_HEADERS([arpa/inet.h])
PKG_CHECK_MODULES(EFREET, [eina-0 ecore >= 0.9.9 ecore-file >= 0.9.9])
PKG_CHECK_MODULES(EFREET, [eet eina-0 ecore >= 0.9.9 ecore-file >= 0.9.9])
PKG_CHECK_MODULES(EINA, [eina-0])
requirements="ecore-file ecore eina-0"
@ -92,15 +92,16 @@ if test "x$enable_sloppy_spec" = "xyes" ; then
AC_DEFINE(SLOPPY_SPEC, 1, [Sloppy Spec Compliance])
fi
AC_ARG_ENABLE(hidden-visibility,
[AC_HELP_STRING([--enable-hidden-visibility],[Enable hidden visibility])],
[enable_hidden_visibility=$enableval], [enable_hidden_visibility="auto"])
if test "x$enable_hidden_visibility" = "xyes" ; then
CPPFLAGS="$CPPFLAGS -fvisibility=hidden"
else
AC_DEFINE(DEFAULT_VISIBLITY, 1, [Default visibility])
fi
AM_CONDITIONAL(DEFAULT_VISIBILITY, test "x$enable_hidden_visibility" != "xyes")
#AC_ARG_ENABLE(hidden-visibility,
# [AC_HELP_STRING([--enable-hidden-visibility],[Enable hidden visibility])],
# [enable_hidden_visibility=$enableval], [enable_hidden_visibility="auto"])
#if test "x$enable_hidden_visibility" = "xyes" ; then
# CPPFLAGS="$CPPFLAGS -fvisibility=hidden"
#else
# AC_DEFINE(DEFAULT_VISIBLITY, 1, [Default visibility])
#fi
#AM_CONDITIONAL(DEFAULT_VISIBILITY, test "x$enable_hidden_visibility" != "xyes")
AM_CONDITIONAL(DEFAULT_VISIBILITY, 0)
EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
AC_SUBST(requirements)
@ -114,10 +115,11 @@ doc/Makefile
doc/Doxyfile
src/Makefile
src/lib/Makefile
src/tests/Makefile
src/tests/data/Makefile
src/tests/data/sub/Makefile
src/tests/compare/Makefile
src/bin/Makefile
src/bin/data/Makefile
src/bin/data/sub/Makefile
src/bin/compare/Makefile
], []
)

@ -1,4 +1,4 @@
SUBDIRS = lib bin
SUBDIRS = lib bin tests
MAINTAINERCLEANFILES = Makefile.in

@ -1,6 +1,4 @@
SUBDIRS = data compare
MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \
@ -11,33 +9,14 @@ AM_CPPFLAGS = \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
@EFREET_CFLAGS@
bin_PROGRAMS = efreet_test efreet_spec_test efreet_cache_test
efreet_test_DEPENDENCIES = $(top_builddir)/src/lib/libefreet.la \
$(top_builddir)/src/lib/libefreet_mime.la
efreet_test_LDADD = $(top_builddir)/src/lib/libefreet.la \
$(top_builddir)/src/lib/libefreet_mime.la \
@EFREET_LIBS@
efreet_test_SOURCES = \
ef_test.h \
ef_data_dirs.c \
ef_icon_theme.c \
ef_ini.c \
ef_utils.c \
ef_desktop.c \
ef_menu.c \
ef_mime.c \
main.c
if DEFAULT_VISIBILITY
efreet_test_SOURCES += \
ef_locale.c
endif
bin_PROGRAMS = \
efreet_desktop_cache_create
efreet_spec_test_LDADD = $(top_builddir)/src/lib/libefreet.la @EINA_LIBS@
efreet_spec_test_SOURCES = \
efreet_spec_test.c
efreet_desktop_cache_create_DEPENDENCIES = \
$(top_builddir)/src/lib/libefreet.la
efreet_desktop_cache_create_LDADD = \
$(top_builddir)/src/lib/libefreet.la \
@EFREET_LIBS@
efreet_cache_test_LDADD = $(top_builddir)/src/lib/libefreet.la @EFREET_LIBS@
efreet_cache_test_SOURCES = \
ef_cache.c
efreet_desktop_cache_create_SOURCES = \
efreet_desktop_cache_create.c

@ -1,48 +0,0 @@
#include "Efreet.h"
#include <stdio.h>
#include <Ecore.h>
#include "ef_test.h"
static int
timer(void *data __UNUSED__)
{
Eina_List *list;
Eina_List *l;
Efreet_Desktop *desktop;
double start;
start = ecore_time_get();
desktop = efreet_util_desktop_name_find("Mozilla Firefox");
printf("Mozilla Firefox: %p %.3f\n", desktop, (ecore_time_get() - start));
start = ecore_time_get();
desktop = efreet_util_desktop_generic_name_find("Mail/News");
printf("Mail/News: %p %.3f\n", desktop, (ecore_time_get() - start));
start = ecore_time_get();
desktop = efreet_util_desktop_wm_class_find("Mozilla-firefox-bin", NULL);
printf("Mozilla-firefox-bin: %p %.3f\n", desktop, (ecore_time_get() - start));
list = efreet_util_desktop_mime_list("application/ogg");
if (list)
{
EINA_LIST_FOREACH(list, l, desktop)
{
printf("application/ogg: %s\n", desktop->name);
}
while (list)
list = eina_list_remove_list(list, list);
}
return 0;
}
int
main(int argc __UNUSED__, char **argv __UNUSED__)
{
if (!efreet_init()) return 1;
if (!efreet_util_init()) return 1;
ecore_timer_add(2.0, timer, NULL);
ecore_main_loop_begin();
efreet_util_shutdown();
efreet_shutdown();
return 0;
}

@ -0,0 +1,254 @@
/* vim: set sw=4 ts=4 sts=4 et: */
#include <limits.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <fcntl.h>
#include <unistd.h>
#include <Eina.h>
#include <Ecore_File.h>
#include "Efreet.h"
#include "efreet_private.h"
static Eet_Data_Descriptor *edd = NULL;
static Eet_File *ef = NULL;
static Eet_File *util_ef = NULL;
static Eina_Hash *file_ids = NULL;
static int
cache_add(const char *path, const char *file_id, int priority)
{
Efreet_Desktop *desk;
char *ext;
ext = strrchr(path, '.');
if (!ext || strcmp(ext, ".desktop")) return 1;
desk = efreet_desktop_new(path);
if (!desk || desk->type != EFREET_DESKTOP_TYPE_APPLICATION)
{
if (desk) efreet_desktop_free(desk);
return 1;
}
if (!eet_data_write(ef, edd, desk->orig_path, desk, 0))
return 0;
if (!eina_hash_find(file_ids, file_id))
{
int id;
char key[PATH_MAX];
char *data;
int i = 0;
Eina_List *l;
id = eina_hash_population(file_ids);
i = 0;
EINA_LIST_FOREACH(desk->mime_types, l, data)
{
snprintf(key, sizeof(key), "%d::%d::m", id, i++);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
i = 0;
EINA_LIST_FOREACH(desk->categories, l, data)
{
snprintf(key, sizeof(key), "%d::%d::ca", id, i++);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->startup_wm_class)
{
data = desk->startup_wm_class;
snprintf(key, sizeof(key), "%d::swc", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->name)
{
data = desk->name;
snprintf(key, sizeof(key), "%d::n", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->generic_name)
{
data = desk->generic_name;
snprintf(key, sizeof(key), "%d::gn", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->comment)
{
data = desk->comment;
snprintf(key, sizeof(key), "%d::co", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->exec)
{
data = desk->exec;
snprintf(key, sizeof(key), "%d::e", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
if (desk->orig_path)
{
data = desk->orig_path;
snprintf(key, sizeof(key), "%d::op", id);
if (!eet_write(util_ef, key, data, strlen(data) + 1, 0)) return 0;
}
snprintf(key, sizeof(key), "%d::fi", id);
if (!eet_write(util_ef, key, file_id, strlen(file_id) + 1, 0)) return 0;
eina_hash_add(file_ids, file_id, (void *)1);
}
efreet_desktop_free(desk);
return 1;
}
static int
cache_scan(const char *path, const char *base_id, int priority)
{
char file_id[PATH_MAX];
char buf[PATH_MAX];
DIR *files;
struct dirent *file;
if (!ecore_file_is_dir(path)) return 1;
files = opendir(path);
file_id[0] = '\0';
while ((file = readdir(files)))
{
if (!file) break;
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
snprintf(buf, sizeof(buf), "%s/%s", path, file->d_name);
if (*base_id)
snprintf(file_id, sizeof(file_id), "%s-%s", base_id, file->d_name);
else
strcpy(file_id, file->d_name);
if (ecore_file_is_dir(buf))
{
cache_scan(buf, file_id, priority);
}
else
{
if (!cache_add(buf, file_id, priority)) return 0;
}
}
closedir(files);
return 1;
}
int
main(int argc, char **argv)
{
/* TODO:
* - Add file monitor on files, so that we catch changes on files
* during whilst this program runs.
* - When creating new cache, do it on a tmp file, then rename tmp file
* to cache file.
*/
char file[PATH_MAX];
Eina_List *dirs;
int priority = 0;
char *dir = NULL;
int fd = 0;
/* init external subsystems */
if (!eet_init()) goto eet_error;
if (!eina_init()) goto eina_error;
/* create homedir */
snprintf(file, sizeof(file), "%s/.efreet", efreet_home_dir_get());
if (!ecore_file_mkpath(file)) goto efreet_error;
/* create dir for desktop cache */
dir = ecore_file_dir_get(efreet_desktop_cache_file());
if (!ecore_file_mkpath(dir)) goto efreet_error;
free(dir);
/* create desktop cache file, so that efreet_init wont run another instance of this program */
fd = open(efreet_desktop_cache_file(), O_CREAT | O_TRUNC | O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) goto efreet_error;
close(fd);
/* create dir for util cache */
dir = ecore_file_dir_get(efreet_util_cache_file());
if (!ecore_file_mkpath(dir)) goto efreet_error;
free(dir);
/* create util cache file */
fd = open(efreet_util_cache_file(), O_CREAT | O_TRUNC | O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) goto efreet_error;
close(fd);
/* lock process, so that we only run one copy of this program */
snprintf(file, sizeof(file), "%s/.efreet/lock", efreet_home_dir_get());
fd = open(file, O_CREAT | O_TRUNC | O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) goto efreet_error;
if (flock(fd, LOCK_EX | LOCK_NB) < 0)
{
close(fd);
goto efreet_error;
}
/* finish efreet init */
if (!efreet_init()) goto efreet_error;
edd = efreet_desktop_edd_init();
if (!edd) goto edd_error;
/* create cache */
ef = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_WRITE);
if (!ef) goto error;
util_ef = eet_open(efreet_util_cache_file(), EET_FILE_MODE_WRITE);
if (!util_ef) goto error;
file_ids = eina_hash_string_superfast_new(NULL);
if (!file_ids) goto error;
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
"applications");
if (!dirs) goto error;
while (dirs)
{
char file_id[PATH_MAX] = { '\0' };
char *path;
path = eina_list_data_get(dirs);
if (path)
{
if (!cache_scan(path, file_id, priority++)) goto error;
free(path);
}
dirs = eina_list_remove_list(dirs, dirs);
}
eina_hash_free(file_ids);
/* cleanup */
eet_close(util_ef);
eet_close(ef);
efreet_desktop_edd_shutdown(edd);
efreet_shutdown();
eet_shutdown();
eina_shutdown();
close(fd);
return 0;
error:
printf("error\n");
IF_FREE(dir);
efreet_desktop_edd_shutdown(edd);
edd_error:
printf("error\n");
efreet_shutdown();
efreet_error:
printf("error\n");
eina_shutdown();
eina_error:
printf("error\n");
eet_shutdown();
eet_error:
printf("error\n");
if (fd > 0) close(fd);
return 1;
}

@ -31,6 +31,7 @@ dist_installed_headers_DATA = $(EFREETHEADERS) Efreet_Mime.h Efreet_Trash.h
libefreet_la_SOURCES = $(EFREETSOURCES)
libefreet_la_CPPFLAGS = \
-DPACKAGE_DATA_DIR=\"$(datadir)\" \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-I$(top_builddir)/src/lib \
-I$(top_srcdir)/src/lib \
@EFL_EFREET_BUILD@ \

@ -33,12 +33,14 @@ efreet_init(void)
if (!eina_init())
return --_efreet_init_count;
if (!eet_init())
goto shutdown_eina;
_efreet_log_domain_global = eina_log_domain_register("Efreet", EFREET_DEFAULT_LOG_COLOR);
if (_efreet_log_domain_global < 0)
{
printf("Efreet could create a general log domain.\n");
goto shutdown_eina;
goto shutdown_eet;
}
if (!efreet_base_init())
@ -73,6 +75,8 @@ shutdown_efreet_base:
efreet_base_shutdown();
unregister_log_domain:
eina_log_domain_unregister(_efreet_log_domain_global);
shutdown_eet:
eet_shutdown();
shutdown_eina:
eina_shutdown();
@ -98,6 +102,7 @@ efreet_shutdown(void)
efreet_xml_shutdown();
efreet_base_shutdown();
eina_log_domain_unregister(_efreet_log_domain_global);
eet_shutdown();
eina_shutdown();
IF_FREE(efreet_lang);
@ -234,6 +239,7 @@ efreet_parse_locale_setting(const char *env)
size_t
efreet_array_cat(char *buffer, size_t size, const char *strs[])
{
/* TODO: Most functions calling this use static strings. Make a version which handles this, use sizeof and memcpy */
int i;
size_t n;
for (i = 0, n = 0; n < size && strs[i]; i++)

@ -35,6 +35,7 @@ static int _efreet_base_log_dom = -1;
static const char *efreet_dir_get(const char *key, const char *fallback);
static Eina_List *efreet_dirs_get(const char *key,
const char *fallback);
static const char *efreet_path_clean(const char *path);
/**
* @internal
@ -76,8 +77,10 @@ efreet_base_shutdown(void)
* @internal
* @return Returns the users home directory
* @brief Gets the users home directory and returns it.
*
* Needs EAPI because of helper binaries
*/
const char *
EAPI const char *
efreet_home_dir_get(void)
{
if (efreet_home_dir) return efreet_home_dir;
@ -90,7 +93,7 @@ efreet_home_dir_get(void)
if (!efreet_home_dir || efreet_home_dir[0] == '\0')
efreet_home_dir = "/tmp";
efreet_home_dir = eina_stringshare_add(efreet_home_dir);
efreet_home_dir = efreet_path_clean(efreet_home_dir);
return efreet_home_dir;
}
@ -201,10 +204,10 @@ efreet_dir_get(const char *key, const char *fallback)
dir = malloc(sizeof(char) * len);
snprintf(dir, len, "%s%s", user, fallback);
t = eina_stringshare_add(dir);
t = efreet_path_clean(dir);
FREE(dir);
}
else t = eina_stringshare_add(dir);
else t = efreet_path_clean(dir);
return t;
}
@ -237,14 +240,37 @@ efreet_dirs_get(const char *key, const char *fallback)
{
*p = '\0';
if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
dirs = eina_list_append(dirs, (void *)eina_stringshare_add(s));
dirs = eina_list_append(dirs, (void *)efreet_path_clean(s));
s = ++p;
p = strchr(s, EFREET_PATH_SEP);
}
if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
dirs = eina_list_append(dirs, (void *)eina_stringshare_add(s));
dirs = eina_list_append(dirs, (void *)efreet_path_clean(s));
FREE(tmp);
return dirs;
}
static const char *
efreet_path_clean(const char *path)
{
char *p, *pp;
const char *ret;
if (!path) return eina_stringshare_add("");
if (!*path) return eina_stringshare_add("");
p = strdup(path);
if (!p) return eina_stringshare_add("");
for (pp = p; *pp; pp++)
{
if (*pp == '/' && *(pp + 1) == '/')
memmove(pp, pp + 1, strlen(pp + 1) + 1);
if (*pp == '/' && *(pp + 1) == '\0')
*pp = '\0';
}
ret = eina_stringshare_add(p);
free(p);
return ret;
}

@ -44,7 +44,9 @@ static Eina_List *efreet_desktop_types = NULL;
*/
static int efreet_desktop_command_file_id = 0;
static int cache_flush = 0;
static char *cache_file = NULL;
static Eet_File *cache = NULL;
static Eet_Data_Descriptor *edd = NULL;
#ifdef EFREET_MODULE_LOG_DOM
#undef EFREET_MODULE_LOG_DOM
@ -72,7 +74,9 @@ struct Efreet_Desktop_Type_Info
};
static int efreet_desktop_read(Efreet_Desktop *desktop);
#if 0
static void efreet_desktop_clear(Efreet_Desktop *desktop);
#endif
static Efreet_Desktop_Type_Info *efreet_desktop_type_parse(const char *type_str);
static void *efreet_desktop_application_fields_parse(Efreet_Desktop *desktop,
Efreet_Ini *ini);
@ -148,10 +152,10 @@ efreet_desktop_init(void)
return 0;
}
if (!ecore_file_init())
{
eina_log_domain_unregister(_efreet_desktop_log_dom);
return 0;
}
goto ecore_error;
edd = efreet_desktop_edd_init();
if (!edd)
goto edd_error;
efreet_desktop_cache = eina_hash_string_superfast_new(NULL);
efreet_desktop_types = NULL;
@ -166,7 +170,26 @@ efreet_desktop_init(void)
EFREET_DESKTOP_TYPE_DIRECTORY = efreet_desktop_type_add("Directory", NULL,
NULL, NULL);
/* TODO:
* Should add a lock here, so that several programs starting at the same
* time wont run several copies of efreet_desktop_cache_create
*
* Or do the right thing and run the exe with ecore_exe
*/
if (!ecore_file_exists(efreet_desktop_cache_file()))
system(PACKAGE_BIN_DIR "/efreet_desktop_cache_create");
/* TODO: Need file monitor on cache in case it is updated */
cache = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_READ);
//if (!cache) goto error;
return 1;
error:
efreet_desktop_edd_shutdown(edd);
edd_error:
ecore_file_shutdown();
ecore_error:
eina_log_domain_unregister(_efreet_desktop_log_dom);
return 0;
}
/**
@ -188,8 +211,40 @@ efreet_desktop_shutdown(void)
efreet_desktop_types = eina_list_remove_list(efreet_desktop_types,
efreet_desktop_types);
}
if (cache) eet_close(cache);
efreet_desktop_edd_shutdown(edd);
ecore_file_shutdown();
eina_log_domain_unregister(_efreet_desktop_log_dom);
IF_FREE(cache_file);
}
/*
* Needs EAPI because of helper binaries
*/
EAPI const char *
efreet_desktop_cache_file(void)
{
char tmp[PATH_MAX] = { '\0' };
const char *home, *lang, *country, *modifier;
if (cache_file) return cache_file;
home = efreet_home_dir_get();
lang = efreet_lang_get();
country = efreet_lang_country_get();
modifier = efreet_lang_modifier_get();
if (lang && country && modifier)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s_%s@%s.cache", home, lang, country, modifier);
else if (lang && country)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s_%s.cache", home, lang, country);
else if (lang)
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop_%s.cache", home, lang);
else
snprintf(tmp, sizeof(tmp), "%s/.efreet/desktop.cache", home);
cache_file = strdup(tmp);
return cache_file;
}
/**
@ -203,9 +258,13 @@ efreet_desktop_cache_check(Efreet_Desktop *desktop)
{
if (!desktop) return 0;
/* TODO:
* We always accept files in cache, but we should update cache
* when a file has changed on disk
*/
if (desktop->eet) return 1;
/* have we modified this file since we last read it in? */
if ((desktop->cache_flush != cache_flush) ||
(ecore_file_mod_time(desktop->orig_path) != desktop->load_time))
if (ecore_file_mod_time(desktop->orig_path) != desktop->load_time)
return 0;
return 1;
@ -234,14 +293,16 @@ efreet_desktop_get(const char *file)
return desktop;
}
#if 0
efreet_desktop_clear(desktop);
if (efreet_desktop_read(desktop))
{
desktop->ref++;
desktop->cache_flush = cache_flush;
return desktop;
}
#endif
/* TODO: Submit event to signal that this file has changed */
desktop->cached = 0;
eina_hash_del(efreet_desktop_cache, file, NULL);
}
@ -250,7 +311,7 @@ efreet_desktop_get(const char *file)
desktop = efreet_desktop_new(file);
if (!desktop) return NULL;
eina_hash_add(efreet_desktop_cache, file, desktop);
if (efreet_desktop_cache) eina_hash_add(efreet_desktop_cache, file, desktop);
desktop->cached = 1;
return desktop;
}
@ -298,7 +359,20 @@ efreet_desktop_empty_new(const char *file)
EAPI Efreet_Desktop *
efreet_desktop_new(const char *file)
{
Efreet_Desktop *desktop;
/* TODO: Need file monitor on file and events to notify change */
Efreet_Desktop *desktop = NULL;
if (cache)
{
/* TODO: Check if the cached version is out of date */
desktop = eet_data_read(cache, edd, file);
if (desktop)
{
desktop->ref = 1;
desktop->eet = 1;
return desktop;
}
}
if (!ecore_file_exists(file)) return NULL;
@ -314,7 +388,6 @@ efreet_desktop_new(const char *file)
}
desktop->ref = 1;
desktop->cache_flush = cache_flush;
return desktop;
}
@ -387,6 +460,7 @@ efreet_desktop_read(Efreet_Desktop *desktop)
* @return Returns no value
* @brief Frees the Efreet_Desktop's data
*/
#if 0
static void
efreet_desktop_clear(Efreet_Desktop *desktop)
{
@ -428,6 +502,7 @@ efreet_desktop_clear(Efreet_Desktop *desktop)
info->free_func(desktop->type_data);
}
}
#endif
/**
* @param desktop: The desktop file to save
@ -477,6 +552,7 @@ efreet_desktop_save(Efreet_Desktop *desktop)
efreet_ini_string_set(ini, "Version", DESKTOP_VERSION);
if (!efreet_ini_save(ini, desktop->orig_path)) ok = 0;
#if 0
else
{
if (desktop != eina_hash_find(efreet_desktop_cache, desktop->orig_path))
@ -487,6 +563,7 @@ efreet_desktop_save(Efreet_Desktop *desktop)
desktop);
}
}
#endif
}
efreet_ini_free(ini);
return ok;
@ -501,7 +578,8 @@ efreet_desktop_save(Efreet_Desktop *desktop)
EAPI int
efreet_desktop_save_as(Efreet_Desktop *desktop, const char *file)
{
if (desktop == eina_hash_find(efreet_desktop_cache, desktop->orig_path))
if (desktop->cached && efreet_desktop_cache &&
desktop == eina_hash_find(efreet_desktop_cache, desktop->orig_path))
{
desktop->cached = 0;
eina_hash_del(efreet_desktop_cache, desktop->orig_path, NULL);
@ -520,8 +598,6 @@ efreet_desktop_save_as(Efreet_Desktop *desktop, const char *file)
EAPI void
efreet_desktop_free(Efreet_Desktop *desktop)
{
char *str;
if (!desktop) return;
desktop->ref--;
@ -530,36 +606,49 @@ efreet_desktop_free(Efreet_Desktop *desktop)
if (desktop->cached && efreet_desktop_cache)
eina_hash_del(efreet_desktop_cache, desktop->orig_path, NULL);
IF_FREE(desktop->orig_path);
if (desktop->eet)
{
eina_list_free(desktop->only_show_in);
eina_list_free(desktop->not_show_in);
eina_list_free(desktop->categories);
eina_list_free(desktop->mime_types);
IF_FREE_HASH(desktop->x);
}
else
{
char *str;
IF_FREE(desktop->version);
IF_FREE(desktop->name);
IF_FREE(desktop->generic_name);
IF_FREE(desktop->comment);
IF_FREE(desktop->icon);
IF_FREE(desktop->url);
IF_FREE(desktop->orig_path);
IF_FREE(desktop->try_exec);
IF_FREE(desktop->exec);
IF_FREE(desktop->path);
IF_FREE(desktop->startup_wm_class);
IF_FREE(desktop->version);
IF_FREE(desktop->name);
IF_FREE(desktop->generic_name);
IF_FREE(desktop->comment);
IF_FREE(desktop->icon);
IF_FREE(desktop->url);
IF_FREE_LIST(desktop->only_show_in, free);
IF_FREE_LIST(desktop->not_show_in, free);
IF_FREE(desktop->try_exec);
IF_FREE(desktop->exec);
IF_FREE(desktop->path);
IF_FREE(desktop->startup_wm_class);
EINA_LIST_FREE(desktop->categories, str)
eina_stringshare_del(str);
EINA_LIST_FREE(desktop->mime_types, str)
eina_stringshare_del(str);
IF_FREE_LIST(desktop->only_show_in, free);
IF_FREE_LIST(desktop->not_show_in, free);
IF_FREE_HASH(desktop->x);
EINA_LIST_FREE(desktop->categories, str)
eina_stringshare_del(str);
EINA_LIST_FREE(desktop->mime_types, str)
eina_stringshare_del(str);
if (desktop->type_data)
{
Efreet_Desktop_Type_Info *info;
info = eina_list_nth(efreet_desktop_types, desktop->type);
if (info->free_func)
info->free_func(desktop->type_data);
IF_FREE_HASH(desktop->x);
if (desktop->type_data)
{
Efreet_Desktop_Type_Info *info;
info = eina_list_nth(efreet_desktop_types, desktop->type);
if (info->free_func)
info->free_func(desktop->type_data);
}
}
FREE(desktop);
@ -837,19 +926,6 @@ efreet_desktop_string_list_join(Eina_List *list)
return string;
}
/**
* @brief Tell Efreet to flush any cached desktop entries so it reloads on get.
*
* This flags the cache to be invalid, so next time a desktop file is fetched
* it will force it to be re-read off disk next time efreet_desktop_get() is
* called.
*/
EAPI void
efreet_desktop_cache_flush(void)
{
cache_flush++;
}
/**
* @internal
* @param desktop: the Efreet_Desktop to store parsed fields in
@ -1881,3 +1957,50 @@ efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key)
return eina_hash_del(desktop->x, key, NULL);
}
/*
* Needs EAPI because of helper binaries
*/
EAPI Eet_Data_Descriptor *
efreet_desktop_edd_init(void)
{
Eet_Data_Descriptor *edd;
Eet_Data_Descriptor_Class eddc;
if (!eet_eina_file_data_descriptor_class_set(&eddc, "cache", sizeof(Efreet_Desktop))) return NULL;
edd = eet_data_descriptor_file_new(&eddc);
if (!edd) return NULL;
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "type", type, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "version", version, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "orig_path", orig_path, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "load_time", load_time, EET_T_LONG_LONG);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "name", name, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "generic_name", generic_name, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "comment", comment, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "icon", icon, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "try_exec", try_exec, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "exec", exec, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "path", path, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "startup_wm_class", startup_wm_class, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "url", url, EET_T_STRING);
eet_data_descriptor_element_add(edd, "only_show_in", EET_T_STRING, EET_G_LIST, offsetof(Efreet_Desktop, only_show_in), 0, NULL, NULL);
eet_data_descriptor_element_add(edd, "not_show_in", EET_T_STRING, EET_G_LIST, offsetof(Efreet_Desktop, not_show_in), 0, NULL, NULL);
eet_data_descriptor_element_add(edd, "categories", EET_T_STRING, EET_G_LIST, offsetof(Efreet_Desktop, categories), 0, NULL, NULL);
eet_data_descriptor_element_add(edd, "mime_types", EET_T_STRING, EET_G_LIST, offsetof(Efreet_Desktop, mime_types), 0, NULL, NULL);
eet_data_descriptor_element_add(edd, "x", EET_T_STRING, EET_G_HASH, offsetof(Efreet_Desktop, x), 0, NULL, NULL);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "no_display", no_display, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "hidden", hidden, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "terminal", terminal, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Efreet_Desktop, "startup_notify", startup_notify, EET_T_UCHAR);
return edd;
}
/*
* Needs EAPI because of helper binaries
*/
EAPI void
efreet_desktop_edd_shutdown(Eet_Data_Descriptor *edd)
{
eet_data_descriptor_free(edd);
}

@ -57,7 +57,6 @@ struct _Efreet_Desktop
int type; /**< type of desktop file */
int ref; /**< reference count - internal */
int cache_flush; /**< cache flush value - internal */
char *version; /**< version of spec file conforms to */
@ -82,11 +81,12 @@ struct _Efreet_Desktop
Eina_List *categories; /**< Categories in which item should be shown */
Eina_List *mime_types; /**< The mime types supppored by this app */
unsigned char no_display:1; /**< Don't display this application in menus */
unsigned char hidden:1; /**< User delete the item */
unsigned char terminal:1; /**< Does the program run in a terminal */
unsigned char startup_notify:1; /**< The starup notify settings of the app */
unsigned char cached:1; /**< The desktop file is cached by Efreet */
unsigned char no_display; /**< Don't display this application in menus */
unsigned char hidden; /**< User delete the item */
unsigned char terminal; /**< Does the program run in a terminal */
unsigned char startup_notify; /**< The starup notify settings of the app */
unsigned char cached:1; /**< The desktop file is cached by Efreet */
unsigned char eet:1; /**< The desktop file is in eet cache */
Eina_Hash *x; /**< Keep track of all user extensions, keys that begin with X- */
void *type_data; /**< Type specific data for custom types */
@ -97,6 +97,7 @@ EAPI int efreet_desktop_ref(Efreet_Desktop *desktop);
EAPI Efreet_Desktop *efreet_desktop_empty_new(const char *file);
EAPI Efreet_Desktop *efreet_desktop_new(const char *file);
EAPI void efreet_desktop_free(Efreet_Desktop *desktop);
#define efreet_desktop_unref(desktop) efreet_desktop_free((desktop))
EAPI int efreet_desktop_save(Efreet_Desktop *desktop);
EAPI int efreet_desktop_save_as(Efreet_Desktop *desktop,
@ -140,8 +141,6 @@ EAPI Eina_Bool efreet_desktop_x_field_set(Efreet_Desktop *desktop, const
EAPI const char * efreet_desktop_x_field_get(Efreet_Desktop *desktop, const char *key);
EAPI Eina_Bool efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key);
EAPI void efreet_desktop_cache_flush(void);
/**
* @}
*/

@ -87,7 +87,9 @@ static int efreet_icon_theme_cache_check_dir(Efreet_Icon_Theme *theme,
const char *dir);
static int efreet_icon_cache_find(Efreet_Icon_Cache *value, const char *key);
#if 0
static void efreet_icon_cache_flush(Efreet_Icon_Theme *theme, Eina_List *list);
#endif
static void efreet_icon_cache_free(Efreet_Icon_Cache *value);
static char *efreet_icon_cache_check(Efreet_Icon_Theme *theme, const char *icon, unsigned int size);
static void efreet_icon_cache_add(Efreet_Icon_Theme *theme, const char *icon, unsigned int size, const char *value);
@ -1537,6 +1539,7 @@ efreet_icon_cache_find(Efreet_Icon_Cache *value, const char *key)
return strcmp(value->key, key);
}
#if 0
static void
efreet_icon_cache_flush(Efreet_Icon_Theme *theme, Eina_List *list)
{
@ -1557,6 +1560,7 @@ efreet_icon_cache_flush(Efreet_Icon_Theme *theme, Eina_List *list)
eina_hash_modify(efreet_icon_cache, theme, list);
}
#endif
static void
efreet_icon_cache_free(Efreet_Icon_Cache *value)

@ -278,6 +278,13 @@ next_line:
munmap((char*) buffer, file_stat.st_size);
fclose(f);
#if 0
if (!eina_hash_population(data))
{
eina_hash_free(data);
return NULL;
}
#endif
return data;
}

@ -221,7 +221,7 @@ struct Efreet_Menu_Desktop
unsigned char allocated:1; /**< If this desktop has been allocated */
};
static char *efreet_menu_prefix = NULL; /**< The $XDG_MENU_PREFIX env var */
static const char *efreet_menu_prefix = NULL; /**< The $XDG_MENU_PREFIX env var */
Eina_List *efreet_menu_kde_legacy_dirs = NULL; /**< The directories to use for KDELegacy entries */
static const char *efreet_tag_menu = NULL;
static char *efreet_menu_file = NULL; /**< A menu file set explicityl as default */
@ -580,7 +580,6 @@ efreet_menu_kde_legacy_init(void)
void
efreet_menu_shutdown(void)
{
IF_FREE(efreet_menu_prefix);
IF_FREE(efreet_menu_file);
IF_FREE_HASH(efreet_menu_handle_cbs);
@ -978,8 +977,10 @@ efreet_menu_dump(Efreet_Menu *menu, const char *indent)
* @return Returns the list of directories
* @brief Creates the list of directories based on the user
* dir, system dirs and given suffix.
*
* Needs EAPI because of helper binaries
*/
Eina_List *
EAPI Eina_List *
efreet_default_dirs_get(const char *user_dir, Eina_List *system_dirs,
const char *suffix)
{
@ -1063,13 +1064,10 @@ efreet_menu_internal_free(Efreet_Menu_Internal *internal)
static const char *
efreet_menu_prefix_get(void)
{
char *prefix;
if (efreet_menu_prefix) return efreet_menu_prefix;
prefix = getenv("XDG_MENU_PREFIX");
if (prefix) efreet_menu_prefix = strdup(prefix);
else efreet_menu_prefix = strdup("");
efreet_menu_prefix = getenv("XDG_MENU_PREFIX");
if (!efreet_menu_prefix) efreet_menu_prefix = "";
return efreet_menu_prefix;
}

@ -2,6 +2,8 @@
#ifndef EFREET_PRIVATE_H
#define EFREET_PRIVATE_H
#include <Eet.h>
/**
* @file efreet_private.h
* @brief Contains methods and defines that are private to the Efreet
@ -177,9 +179,9 @@ void efreet_icon_shutdown(void);
int efreet_menu_init(void);
void efreet_menu_shutdown(void);
Eina_List *efreet_default_dirs_get(const char *user_dir,
Eina_List *system_dirs,
const char *suffix);
EAPI Eina_List *efreet_default_dirs_get(const char *user_dir,
Eina_List *system_dirs,
const char *suffix);
int efreet_ini_init(void);
void efreet_ini_shutdown(void);
@ -187,16 +189,22 @@ void efreet_ini_shutdown(void);
int efreet_desktop_init(void);
void efreet_desktop_shutdown(void);
const char *efreet_home_dir_get(void);
EAPI const char *efreet_home_dir_get(void);
EAPI const char *efreet_lang_get(void);
EAPI const char *efreet_lang_country_get(void);
EAPI const char *efreet_lang_modifier_get(void);
const char *efreet_lang_get(void);
const char *efreet_lang_country_get(void);
const char *efreet_lang_modifier_get(void);
size_t efreet_array_cat(char *buffer, size_t size, const char *strs[]);
const char *efreet_desktop_environment_get(void);
EAPI Eet_Data_Descriptor *efreet_desktop_edd_init(void);
EAPI void efreet_desktop_edd_shutdown(Eet_Data_Descriptor *edd);
EAPI const char *efreet_util_cache_file(void);
EAPI const char *efreet_desktop_cache_file(void);
#define NON_EXISTING (void *)-1
/**

File diff suppressed because it is too large Load Diff

@ -2,22 +2,6 @@
#ifndef EFREET_UTILS_H
#define EFREET_UTILS_H
typedef enum _Efreet_Desktop_Change
{
EFREET_DESKTOP_CHANGE_ADD,
EFREET_DESKTOP_CHANGE_REMOVE,
EFREET_DESKTOP_CHANGE_UPDATE
} Efreet_Desktop_Change;
typedef struct _Efreet_Event_Desktop_Change Efreet_Event_Desktop_Change;
struct _Efreet_Event_Desktop_Change
{
Efreet_Desktop *current;
Efreet_Desktop *previous;
Efreet_Desktop_Change change;
};
EAPI int efreet_util_init(void);
EAPI int efreet_util_shutdown(void);
@ -41,7 +25,4 @@ EAPI Eina_List *efreet_util_desktop_category_list(const char *category);
EAPI Eina_List *efreet_util_menus_find(void);
EAPI extern int EFREET_EVENT_DESKTOP_LIST_CHANGE;
EAPI extern int EFREET_EVENT_DESKTOP_CHANGE;
#endif

@ -0,0 +1,43 @@
SUBDIRS = data compare
MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/src/lib \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)\" \
@EFREET_CFLAGS@
bin_PROGRAMS = efreet_test efreet_spec_test efreet_cache_test
efreet_test_DEPENDENCIES = $(top_builddir)/src/lib/libefreet.la \
$(top_builddir)/src/lib/libefreet_mime.la
efreet_test_LDADD = $(top_builddir)/src/lib/libefreet.la \
$(top_builddir)/src/lib/libefreet_mime.la \
@EFREET_LIBS@
efreet_test_SOURCES = \
ef_test.h \
ef_data_dirs.c \
ef_icon_theme.c \
ef_ini.c \
ef_utils.c \
ef_desktop.c \
ef_menu.c \
ef_mime.c \
main.c
if DEFAULT_VISIBILITY
efreet_test_SOURCES += \
ef_locale.c
endif
efreet_spec_test_LDADD = $(top_builddir)/src/lib/libefreet.la @EINA_LIBS@
efreet_spec_test_SOURCES = \
efreet_spec_test.c
efreet_cache_test_LDADD = $(top_builddir)/src/lib/libefreet.la @EFREET_LIBS@
efreet_cache_test_SOURCES = \
ef_cache.c

Before

Width:  |  Height:  |  Size: 648 B

After

Width:  |  Height:  |  Size: 648 B