efreet: Use dbus daemon

SVN revision: 78809
devs/devilhorns/wayland_egl
Sebastian Dransfeld 10 years ago
parent ac97a87b85
commit e94d0c6eb1
  1. 89
      legacy/efreet/src/bin/efreet_desktop_cache_create.c
  2. 97
      legacy/efreet/src/bin/efreet_icon_cache_create.c
  3. 3
      legacy/efreet/src/bin/efreetd.c
  4. 137
      legacy/efreet/src/bin/efreetd_cache.c
  5. 1
      legacy/efreet/src/bin/efreetd_cache.h
  6. 30
      legacy/efreet/src/bin/efreetd_dbus.c
  7. 2
      legacy/efreet/src/lib/efreet.c
  8. 508
      legacy/efreet/src/lib/efreet_cache.c
  9. 3
      legacy/efreet/src/lib/efreet_cache_private.h
  10. 109
      legacy/efreet/src/lib/efreet_desktop.c
  11. 102
      legacy/efreet/src/lib/efreet_icon.c
  12. 5
      legacy/efreet/src/lib/efreet_private.h

@ -36,12 +36,6 @@ static Eina_Hash *generic_name = NULL;
static Eina_Hash *comment = NULL;
static Eina_Hash *exec = NULL;
static int
strcmplen(const void *data1, const void *data2)
{
return strncmp(data1, data2, eina_stringshare_strlen(data1));
}
static int
cache_add(const char *path, const char *file_id, int priority __UNUSED__, int *changed)
{
@ -214,9 +208,8 @@ main(int argc, char **argv)
Efreet_Cache_Version version;
Eina_List *dirs = NULL;
Eina_List *systemdirs = NULL;
Efreet_Cache_Array_String *user_dirs = NULL;
Eina_List *extra_dirs = NULL;
Eina_List *store_dirs = NULL;
Eina_List *l = NULL;
int priority = 0;
char *dir = NULL;
char *path;
@ -272,12 +265,6 @@ main(int argc, char **argv)
if (!ecore_file_mkpath(file)) goto efreet_error;
efreet_setowner(file);
}
snprintf(file, sizeof(file), "%s/efreet/update", efreet_cache_home_get());
if (!ecore_file_exists(file))
{
if (!ecore_file_mkpath(file)) goto efreet_error;
efreet_setowner(file);
}
/* lock process, so that we only run one copy of this program */
lockfd = cache_lock_file();
@ -287,13 +274,6 @@ main(int argc, char **argv)
if (!edd) goto edd_error;
/* read user dirs from old cache */
ef = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_READ);
if (ef)
{
user_dirs = eet_data_read(ef, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS);
eet_close(ef);
}
ef = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ);
if (ef)
{
@ -349,61 +329,8 @@ main(int argc, char **argv)
systemdirs = eina_list_append(systemdirs, path);
}
if (user_dirs)
{
unsigned int j;
for (j = 0; j < user_dirs->array_count; j++)
{
if (eina_list_search_unsorted_list(systemdirs, strcmplen, user_dirs->array[j]))
continue;
if (!ecore_file_is_dir(user_dirs->array[j])) continue;
if (!cache_scan(user_dirs->array[j], NULL, priority, 0, &changed)) goto error;
store_dirs = eina_list_append(store_dirs, user_dirs->array[j]);
}
store_dirs = eina_list_sort(store_dirs, -1, EINA_COMPARE_CB(strcmp));
}
if (extra_dirs)
{
Eina_List *l;
EINA_LIST_FOREACH(extra_dirs, l, path)
{
if (eina_list_search_unsorted_list(systemdirs, strcmplen, path))
continue;
if (eina_list_search_unsorted_list(store_dirs, EINA_COMPARE_CB(strcmp), path))
continue;
if (!ecore_file_is_dir(path)) continue;
/* If we scan a passed dir, we must have changed */
changed = 1;
if (!cache_scan(path, NULL, priority, 0, &changed)) goto error;
store_dirs = eina_list_append(store_dirs, path);
}
store_dirs = eina_list_sort(store_dirs, -1, EINA_COMPARE_CB(strcmp));
}
if (user_dirs)
efreet_cache_array_string_free(user_dirs);
/* store user dirs */
if (store_dirs)
{
Eina_List *l;
user_dirs = NEW(Efreet_Cache_Array_String, 1);
user_dirs->array = NEW(char *, eina_list_count(store_dirs));
user_dirs->array_count = 0;
EINA_LIST_FOREACH(store_dirs, l, path)
user_dirs->array[user_dirs->array_count++] = path;
eet_data_write(ef, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS, user_dirs, 1);
IF_FREE(user_dirs->array);
free(user_dirs);
}
EINA_LIST_FOREACH(extra_dirs, l, path)
if (!cache_scan(path, NULL, priority, 0, &changed)) goto error;
/* store util */
#define STORE_HASH_ARRAY(_hash) \
@ -496,24 +423,16 @@ main(int argc, char **argv)
unlink(file);
}
/* touch update file */
snprintf(file, sizeof(file), "%s/efreet/update/desktop_data.update", efreet_cache_home_get());
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{
char c = 'n';
efreet_fsetowner(tmpfd);
if (changed) c = 'c';
if (write(tmpfd, &c, 1) != 1) perror("write");
close(tmpfd);
printf("%c\n", c);
}
EINA_LIST_FREE(systemdirs, dir)
eina_stringshare_del(dir);
eina_list_free(extra_dirs);
eina_list_free(store_dirs);
efreet_shutdown();
ecore_shutdown();
eet_shutdown();
@ -524,7 +443,6 @@ main(int argc, char **argv)
error:
IF_FREE(dir);
edd_error:
if (user_dirs) efreet_cache_array_string_free(user_dirs);
if (old_file_ids)
{
eina_hash_free(old_file_ids->hash);
@ -539,7 +457,6 @@ eet_error:
EINA_LIST_FREE(systemdirs, dir)
eina_stringshare_del(dir);
eina_list_free(extra_dirs);
eina_list_free(store_dirs);
eina_log_domain_unregister(_efreet_desktop_cache_log_dom);
eina_shutdown();
eina_error:

@ -694,77 +694,6 @@ icon_theme_free(Efreet_Cache_Icon_Theme *theme)
free(theme);
}
/**
* @internal
* @return EINA_TRUE if data adds new
*/
static Eina_Bool
add_data(Eet_File *ef, Eina_Array *data, const char *key)
{
Efreet_Cache_Array_String *add;
unsigned int i, j;
Eina_Bool added = EINA_FALSE;
add = eet_data_read(ef, efreet_array_string_edd(), key);
if (!add) return EINA_TRUE;
/* loop once to check added */
for (i = 0; i < data->count; i++)
{
int found = 0;
for (j = 0; j < add->array_count; ++j)
{
if (!strcmp(add->array[j], data->data[i]))
{
found = 1;
break;
}
}
if (!found)
{
added = EINA_TRUE;
break;
}
}
/* loop again to add all data */
for (i = 0; i < add->array_count; i++)
{
int found = 0;
for (j = 0; j < data->count; ++j)
{
if (!strcmp(add->array[i], data->data[j]))
{
found = 1;
break;
}
}
if (!found)
eina_array_push(data, add->array[i]);
}
IF_FREE(add->array);
free(add);
return added;
}
static void
save_data(Eet_File *ef, Eina_Array *data, const char *key)
{
Efreet_Cache_Array_String *save;
unsigned int i;
if (!data || !data->count) return;
save = NEW(Efreet_Cache_Array_String, 1);
save->array = NEW(char *, data->count);
save->array_count = 0;
for (i = 0; i < data->count; ++i)
save->array[save->array_count++] = data->data[i];
eet_data_write(ef, efreet_array_string_edd(), key, save, 1);
IF_FREE(save->array);
free(save);
}
int
main(int argc, char **argv)
{
@ -790,7 +719,6 @@ main(int argc, char **argv)
Eina_Bool changed = EINA_FALSE;
Eina_Bool flush = EINA_FALSE;
int lockfd = -1;
int tmpfd = -1;
char **keys;
int num, i;
@ -822,6 +750,7 @@ main(int argc, char **argv)
printf(" -v Verbose mode\n");
printf(" -e .ext1 .ext2 Extensions\n");
printf(" -d dir1 dir2 Extra dirs\n");
printf(" -f Flush\n");
exit(0);
}
else if (!strcmp(argv[i], "-e"))
@ -834,6 +763,8 @@ main(int argc, char **argv)
while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
eina_array_push(extra_dirs, argv[++i]);
}
else if (!strcmp(argv[i], "-d"))
flush = EINA_TRUE;
}
if (!eet_init()) return -1;
@ -852,12 +783,6 @@ main(int argc, char **argv)
if (!ecore_file_mkpath(file)) return -1;
efreet_setowner(file);
}
snprintf(file, sizeof(file), "%s/efreet/update", efreet_cache_home_get());
if (!ecore_file_exists(file))
{
if (!ecore_file_mkpath(file)) return -1;
efreet_setowner(file);
}
/* lock process, so that we only run one copy of this program */
lockfd = cache_lock_file();
@ -894,10 +819,6 @@ main(int argc, char **argv)
theme_version->major = EFREET_ICON_CACHE_MAJOR;
theme_version->minor = EFREET_ICON_CACHE_MINOR;
if (add_data(theme_ef, exts, EFREET_CACHE_ICON_EXTENSIONS))
flush = EINA_TRUE;
if (add_data(theme_ef, extra_dirs, EFREET_CACHE_ICON_EXTRA_DIRS))
flush = EINA_TRUE;
if (flush)
changed = EINA_TRUE;
@ -1004,7 +925,7 @@ main(int argc, char **argv)
INF("generated: '%s' %i (%i)",
theme->theme.name.internal,
changed,
theme->changed,
eina_hash_population(icons));
icons_it = eina_hash_iterator_tuple_new(icons);
@ -1017,6 +938,7 @@ main(int argc, char **argv)
}
eina_hash_free(themes);
eina_hash_free(icons);
changed = EINA_TRUE;
}
eet_data_write(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION, icon_version, 1);
@ -1110,24 +1032,15 @@ main(int argc, char **argv)
/* save data */
eet_data_write(theme_ef, efreet_version_edd(), EFREET_CACHE_VERSION, theme_version, 1);
save_data(theme_ef, exts, EFREET_CACHE_ICON_EXTENSIONS);
save_data(theme_ef, extra_dirs, EFREET_CACHE_ICON_EXTRA_DIRS);
eet_close(theme_ef);
efreet_setowner(efreet_icon_theme_cache_file());
free(theme_version);
/* touch update file */
snprintf(file, sizeof(file), "%s/efreet/update/icon_data.update", efreet_cache_home_get());
tmpfd = open(file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (tmpfd >= 0)
{
char c = 'n';
efreet_fsetowner(tmpfd);
if (changed) c = 'c';
if (write(tmpfd, &c, 1) != 1) perror("write");
close(tmpfd);
printf("%c\n", c);
}

@ -45,7 +45,8 @@ dbus_error:
ecore_file_error:
ecore_shutdown();
ecore_error:
eina_log_domain_unregister(efreetd_log_dom);
if (efreetd_log_dom >= 0)
eina_log_domain_unregister(efreetd_log_dom);
efreetd_log_dom = -1;
eina_shutdown();
return 1;

@ -12,6 +12,7 @@
#include "Efreet.h"
#define EFREET_MODULE_LOG_DOM efreetd_log_dom
#include "efreet_private.h"
#include "efreetd_cache.h"
static Eina_Hash *change_monitors = NULL;
@ -22,9 +23,11 @@ static Ecore_Exe *desktop_cache_exe = NULL;
static Ecore_Timer *icon_cache_timer = NULL;
static Ecore_Timer *desktop_cache_timer = NULL;
static Eina_List *desktop_system_dirs = NULL;
static Eina_List *desktop_extra_dirs = NULL;
static Eina_List *icon_extra_dirs = NULL;
static Eina_List *icon_extra_exts = NULL;
static Eina_List *icon_exts = NULL;
static Eina_Bool icon_flush = EINA_FALSE;
static void desktop_changes_monitor_add(const char *path);
@ -37,6 +40,8 @@ icon_cache_update_cache_cb(void *data __UNUSED__)
icon_cache_timer = NULL;
if ((!icon_flush) && (!icon_exts)) return ECORE_CALLBACK_CANCEL;
/* TODO: Queue if already running */
prio = ecore_exe_run_priority_get();
ecore_exe_run_priority_set(19);
@ -53,29 +58,35 @@ icon_cache_update_cache_cb(void *data __UNUSED__)
eina_strlcat(file, p, sizeof(file));
}
}
if (icon_extra_exts)
if (icon_exts)
{
Eina_List *ll;
char *p;
eina_strlcat(file, " -e", sizeof(file));
EINA_LIST_FOREACH(icon_extra_exts, ll, p)
EINA_LIST_FOREACH(icon_exts, ll, p)
{
eina_strlcat(file, " ", sizeof(file));
eina_strlcat(file, p, sizeof(file));
}
}
icon_cache_exe = ecore_exe_run(file, NULL);
if (icon_flush)
eina_strlcat(file, " -f", sizeof(file));
icon_flush = EINA_FALSE;
icon_cache_exe =
ecore_exe_pipe_run(file, ECORE_EXE_PIPE_READ|ECORE_EXE_PIPE_READ_LINE_BUFFERED, NULL);
ecore_exe_run_priority_set(prio);
return ECORE_CALLBACK_CANCEL;
}
static void
cache_icon_update(void)
cache_icon_update(Eina_Bool flush)
{
if (icon_cache_timer)
ecore_timer_del(icon_cache_timer);
if (flush)
icon_flush = flush;
icon_cache_timer = ecore_timer_add(0.2, icon_cache_update_cache_cb, NULL);
}
@ -104,20 +115,13 @@ desktop_cache_update_cache_cb(void *data __UNUSED__)
}
}
INF("Run desktop cache creation: %s", file);
desktop_cache_exe = ecore_exe_run(file, NULL);
desktop_cache_exe =
ecore_exe_pipe_run(file, ECORE_EXE_PIPE_READ|ECORE_EXE_PIPE_READ_LINE_BUFFERED, NULL);
ecore_exe_run_priority_set(prio);
return ECORE_CALLBACK_CANCEL;
}
static void
cache_desktop_update(void)
{
if (desktop_cache_timer)
ecore_timer_del(desktop_cache_timer);
desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL);
}
static Eina_Bool
cache_exe_data_cb(void *data __UNUSED__, int type __UNUSED__, void *event)
{
@ -139,6 +143,7 @@ cache_exe_data_cb(void *data __UNUSED__, int type __UNUSED__, void *event)
if ((ev->lines) && (*ev->lines->line == 'c'))
update = EINA_TRUE;
send_signal_icon_cache_update(update);
}
return ECORE_CALLBACK_RENEW;
@ -178,12 +183,12 @@ icon_changes_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
case ECORE_FILE_EVENT_CLOSED:
case ECORE_FILE_EVENT_DELETED_DIRECTORY:
case ECORE_FILE_EVENT_CREATED_DIRECTORY:
cache_icon_update();
cache_icon_update(EINA_FALSE);
break;
case ECORE_FILE_EVENT_DELETED_SELF:
eina_hash_del_by_key(change_monitors, path);
cache_icon_update();
cache_icon_update(EINA_FALSE);
break;
}
}
@ -193,23 +198,26 @@ icon_changes_monitor_add(const char *path)
{
Eina_Iterator *it;
Eina_File_Direct_Info *info;
Ecore_File_Monitor *mon;
if (!ecore_file_is_dir(path)) return;
if (eina_hash_find(change_monitors, path)) return;
eina_hash_add(change_monitors, path,
ecore_file_monitor_add(path,
icon_changes_cb,
NULL));
mon = ecore_file_monitor_add(path,
icon_changes_cb,
NULL);
if (mon)
eina_hash_add(change_monitors, path, mon);
it = eina_file_stat_ls(path);
if (!it) return;
EINA_ITERATOR_FOREACH(it, info)
{
if (info->type != EINA_FILE_DIR) continue;
eina_hash_add(change_monitors, info->path,
ecore_file_monitor_add(info->path,
icon_changes_cb,
NULL));
mon = ecore_file_monitor_add(info->path,
icon_changes_cb,
NULL);
if (mon)
eina_hash_add(change_monitors, info->path, mon);
}
eina_iterator_free(it);
}
@ -286,11 +294,14 @@ desktop_changes_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
static void
desktop_changes_monitor_add(const char *path)
{
Ecore_File_Monitor *mon;
if (eina_hash_find(change_monitors, path)) return;
eina_hash_add(change_monitors, path,
ecore_file_monitor_add(path,
desktop_changes_cb,
NULL));
mon = ecore_file_monitor_add(path,
desktop_changes_cb,
NULL);
if (mon)
eina_hash_add(change_monitors, path, mon);
}
static void
@ -314,17 +325,13 @@ desktop_changes_listen_recursive(const char *path)
static void
desktop_changes_listen(void)
{
Eina_List *dirs, *l;
Eina_List *l;
const char *path;
dirs = efreet_default_dirs_get(efreet_data_home_get(),
efreet_data_dirs_get(), "applications");
EINA_LIST_FREE(dirs, path)
EINA_LIST_FOREACH(desktop_system_dirs, l, path)
{
if (ecore_file_is_dir(path))
desktop_changes_listen_recursive(path);
eina_stringshare_del(path);
}
EINA_LIST_FOREACH(desktop_extra_dirs, l, path)
@ -332,7 +339,7 @@ desktop_changes_listen(void)
}
static void
fill_extra(const char *file, Eina_List **l)
fill_list(const char *file, Eina_List **l)
{
Eina_File *f = NULL;
Eina_Iterator *it = NULL;
@ -349,7 +356,6 @@ fill_extra(const char *file, Eina_List **l)
const char *end;
end = line->end - 1;
*l = eina_list_append(*l, eina_stringshare_add_length(line->start, end - line->start));
printf("fill: %s\n", (const char *)(*l)->data);
}
eina_iterator_free(it);
error:
@ -357,15 +363,15 @@ error:
}
static void
read_extra(void)
read_lists(void)
{
fill_extra("extra_desktop.dirs", &desktop_extra_dirs);
fill_extra("extra_icon.dirs", &icon_extra_dirs);
fill_extra("extra_icon.exts", &icon_extra_exts);
fill_list("extra_desktop.dirs", &desktop_extra_dirs);
fill_list("extra_icon.dirs", &icon_extra_dirs);
fill_list("icon.exts", &icon_exts);
}
static void
save_extra(const char *file, Eina_List *l)
save_list(const char *file, Eina_List *l)
{
FILE *f;
char buf[PATH_MAX];
@ -373,13 +379,19 @@ save_extra(const char *file, Eina_List *l)
const char *path;
snprintf(buf, sizeof(buf), "%s/efreet/%s", efreet_cache_home_get(), file);
f = fopen("wb", buf);
f = fopen(buf, "wb");
if (!f) return;
EINA_LIST_FOREACH(l, ll, path)
fprintf(f, "%s\n", path);
fclose(f);
}
static int
strcmplen(const void *data1, const void *data2)
{
return strncmp(data1, data2, eina_stringshare_strlen(data1));
}
/* external */
void
cache_desktop_dir_add(const char *dir)
@ -388,10 +400,11 @@ cache_desktop_dir_add(const char *dir)
san = eina_file_path_sanitize(dir);
if (!san) return;
if (!eina_list_search_unsorted_list(desktop_extra_dirs, EINA_COMPARE_CB(strcmp), san))
if ((!eina_list_search_unsorted_list(desktop_system_dirs, strcmplen, san)) &&
(!eina_list_search_unsorted_list(desktop_extra_dirs, EINA_COMPARE_CB(strcmp), san)))
{
desktop_extra_dirs = eina_list_append(desktop_extra_dirs, eina_stringshare_add(san));
save_extra("extra_desktop.dirs", desktop_extra_dirs);
save_list("extra_desktop.dirs", desktop_extra_dirs);
cache_desktop_update();
}
free(san);
@ -407,8 +420,8 @@ cache_icon_dir_add(const char *dir)
if (!eina_list_search_unsorted_list(icon_extra_dirs, EINA_COMPARE_CB(strcmp), san))
{
icon_extra_dirs = eina_list_append(icon_extra_dirs, eina_stringshare_add(san));
save_extra("extra_icon.dirs", icon_extra_dirs);
cache_icon_update();
save_list("extra_icon.dirs", icon_extra_dirs);
cache_icon_update(EINA_TRUE);
}
free(san);
}
@ -416,14 +429,22 @@ cache_icon_dir_add(const char *dir)
void
cache_icon_ext_add(const char *ext)
{
if (!eina_list_search_unsorted_list(icon_extra_exts, EINA_COMPARE_CB(strcmp), ext))
if (!eina_list_search_unsorted_list(icon_exts, EINA_COMPARE_CB(strcmp), ext))
{
icon_extra_exts = eina_list_append(icon_extra_exts, eina_stringshare_add(ext));
save_extra("extra_icon.exts", icon_extra_exts);
cache_icon_update();
icon_exts = eina_list_append(icon_exts, eina_stringshare_add(ext));
save_list("icon.exts", icon_exts);
cache_icon_update(EINA_TRUE);
}
}
void
cache_desktop_update(void)
{
if (desktop_cache_timer)
ecore_timer_del(desktop_cache_timer);
desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL);
}
Eina_Bool
cache_init(void)
{
@ -437,14 +458,14 @@ cache_init(void)
}
cache_exe_del_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
cache_exe_del_cb, NULL);
cache_exe_del_cb, NULL);
if (!cache_exe_del_handler)
{
ERR("Failed to add exe del handler\n");
goto error;
}
cache_exe_data_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
cache_exe_data_cb, NULL);
cache_exe_data_cb, NULL);
if (!cache_exe_data_handler)
{
ERR("Failed to add exe del handler\n");
@ -456,10 +477,13 @@ cache_init(void)
efreet_cache_update = 0;
if (!efreet_init()) goto error;
read_extra();
read_lists();
/* TODO: Should check if system dirs has changed and handles extra_dirs */
desktop_system_dirs = efreet_default_dirs_get(efreet_data_home_get(),
efreet_data_dirs_get(), "applications");
icon_changes_listen();
desktop_changes_listen();
cache_icon_update();
cache_icon_update(EINA_FALSE);
cache_desktop_update();
return EINA_TRUE;
@ -485,11 +509,14 @@ cache_shutdown(void)
if (change_monitors)
eina_hash_free(change_monitors);
change_monitors = NULL;
EINA_LIST_FREE(desktop_system_dirs, data)
eina_stringshare_del(data);
EINA_LIST_FREE(desktop_extra_dirs, data)
eina_stringshare_del(data);
EINA_LIST_FREE(icon_extra_dirs, data)
eina_stringshare_del(data);
EINA_LIST_FREE(icon_extra_exts, data)
EINA_LIST_FREE(icon_exts, data)
eina_stringshare_del(data);
return EINA_TRUE;
}

@ -4,6 +4,7 @@
void cache_desktop_dir_add(const char *dir);
void cache_icon_dir_add(const char *dir);
void cache_icon_ext_add(const char *ext);
void cache_desktop_update(void);
Eina_Bool cache_init(void);
Eina_Bool cache_shutdown(void);

@ -7,8 +7,8 @@
#include "efreetd.h"
#include "efreetd_cache.h"
#define BUS "org.enlightenment"
#define PATH "/org/enlightenment"
#define BUS "org.enlightenment.Efreet"
#define PATH "/org/enlightenment/Efreet"
#define INTERFACE "org.enlightenment.Efreet"
/* internal */
@ -24,17 +24,15 @@ static EDBus_Service_Interface *iface;
static EDBus_Message *
ping(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
{
printf("ping\n");
return edbus_message_method_return_new(message);
}
static EDBus_Message *
add_desktop_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
{
EDBus_Message_Iter *array = NULL;
const char *dir;
printf("Add desktop dirs\n");
if (!edbus_message_arguments_get(message, "as", &array))
{
ERR("Error getting arguments.");
@ -55,7 +53,6 @@ add_icon_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message
EDBus_Message_Iter *array = NULL;
const char *dir;
printf("Add icon dirs\n");
if (!edbus_message_arguments_get(message, "as", &array))
{
ERR("Error getting arguments.");
@ -70,13 +67,19 @@ add_icon_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message
return NULL;
}
static EDBus_Message *
build_desktop_cache(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message __UNUSED__)
{
cache_desktop_update();
return NULL;
}
static EDBus_Message *
add_icon_exts(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
{
EDBus_Message_Iter *array = NULL;
const char *ext;
printf("Add icon exts\n");
if (!edbus_message_arguments_get(message, "as", &array))
{
ERR("Error getting arguments.");
@ -98,26 +101,31 @@ static const EDBus_Signal signals[] = {
};
static const EDBus_Method methods[] = {
/* TODO: Register / Unregister */
{
"Ping", NULL, NULL,
ping, 0
},
{
"AddDesktopDirs", NULL, EDBUS_ARGS({"as", "dirs"}),
"AddDesktopDirs", EDBUS_ARGS({"as", "dirs"}), NULL,
add_desktop_dirs, EDBUS_METHOD_FLAG_NOREPLY
},
{
"AddIconDirs", NULL, EDBUS_ARGS({"as", "dirs"}),
"BuildDesktopCache", NULL, NULL,
build_desktop_cache, EDBUS_METHOD_FLAG_NOREPLY
},
{
"AddIconDirs", EDBUS_ARGS({"as", "dirs"}), NULL,
add_icon_dirs, EDBUS_METHOD_FLAG_NOREPLY
},
{
"AddIconExts", NULL, EDBUS_ARGS({"as", "exts"}),
"AddIconExts", EDBUS_ARGS({"as", "exts"}), NULL,
add_icon_exts, EDBUS_METHOD_FLAG_NOREPLY
},
{ NULL, NULL, NULL, NULL, 0 }
};
const static EDBus_Service_Interface_Desc desc = {
static const EDBus_Service_Interface_Desc desc = {
INTERFACE, methods, signals
};

@ -187,7 +187,7 @@ efreet_lang_reset(void)
efreet_dirs_reset();
efreet_cache_desktop_close();
efreet_cache_desktop_update();
efreet_cache_desktop_build();
}
/**

@ -15,6 +15,7 @@
#include <Eet.h>
#include <Ecore.h>
#include <Ecore_File.h>
#include <EDBus.h>
/* define macros and variable for using the eina logging system */
#define EFREET_MODULE_LOG_DOM _efreet_cache_log_dom
@ -34,6 +35,13 @@ struct _Efreet_Old_Cache
Eet_File *ef;
};
/* TODO: Common define location with daemon */
#define BUS "org.enlightenment.Efreet"
#define PATH "/org/enlightenment/Efreet"
#define INTERFACE "org.enlightenment.Efreet"
static EDBus_Connection *conn = NULL;
static EDBus_Proxy *proxy = NULL;
/**
* Data for cache files
*/
@ -65,20 +73,9 @@ static Eet_Data_Descriptor *array_string_edd = NULL;
static Eet_Data_Descriptor *hash_string_edd = NULL;
static Eina_Hash *desktops = NULL;
static Eina_List *desktop_dirs_add = NULL;
static Eet_File *desktop_cache = NULL;
static const char *desktop_cache_file = NULL;
static Ecore_File_Monitor *cache_monitor = NULL;
static Ecore_Event_Handler *cache_exe_handler = NULL;
static Ecore_Timer *icon_cache_timer = NULL;
static Ecore_Exe *icon_cache_exe = NULL;
static int icon_cache_exe_lock = -1;
static Ecore_Timer *desktop_cache_timer = NULL;
static Ecore_Exe *desktop_cache_exe = NULL;
static int desktop_cache_exe_lock = -1;
static Eina_List *old_desktop_caches = NULL;
static const char *util_cache_file = NULL;
@ -96,14 +93,10 @@ static void efreet_cache_icon_theme_free(Efreet_Icon_Theme *theme);
static Eina_Bool efreet_cache_check(Eet_File **ef, const char *path, int major);
static void *efreet_cache_close(Eet_File *ef);
static Eina_Bool cache_exe_cb(void *data, int type, void *event);
static Eina_Bool cache_check_change(const char *path);
static void cache_update_cb(void *data, Ecore_File_Monitor *em,
Ecore_File_Event event, const char *path);
static void on_send_ping(void *data, const EDBus_Message *msg, EDBus_Pending *pending);
static void desktop_cache_update(void *context, const EDBus_Message *msg);
static void icon_cache_update(void *context, const EDBus_Message *msg);
static Eina_Bool desktop_cache_update_cache_cb(void *data);
static Eina_Bool icon_cache_update_cache_cb(void *data);
static void desktop_cache_update_free(void *data, void *ev);
static void icon_cache_update_free(void *data, void *ev);
static void *hash_array_string_add(void *hash, const char *key, void *data);
@ -128,50 +121,26 @@ efreet_cache_init(void)
fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
desktops = eina_hash_string_superfast_new(NULL);
edbus_init();
if (efreet_cache_update)
{
char buf[PATH_MAX];
EDBus_Object *obj;
snprintf(buf, sizeof(buf), "%s/efreet", efreet_cache_home_get());
if (!ecore_file_exists(buf))
{
if (!ecore_file_mkpath(buf))
{
ERR("Failed to create directory '%s'", buf);
goto error;
}
efreet_setowner(buf);
}
snprintf(buf, sizeof(buf), "%s/efreet/update", efreet_cache_home_get());
if (!ecore_file_exists(buf))
{
if (!ecore_file_mkpath(buf))
{
ERR("Failed to create directory '%s'", buf);
goto error;
}
efreet_setowner(buf);
}
conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
if (!conn) goto error;
cache_exe_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
cache_exe_cb, NULL);
if (!cache_exe_handler)
{
ERR("Failed to add exe del handler");
goto error;
}
obj = edbus_object_get(conn, BUS, PATH);
proxy = edbus_proxy_get(obj, INTERFACE);
edbus_proxy_signal_handler_add(proxy, "IconCacheUpdate", icon_cache_update, NULL);
edbus_proxy_signal_handler_add(proxy, "DesktopCacheUpdate", desktop_cache_update, NULL);
cache_monitor = ecore_file_monitor_add(buf,
cache_update_cb,
NULL);
if (!cache_monitor)
{
ERR("Failed to set up ecore file monitor for '%s'", buf);
goto error;
}
edbus_proxy_call(proxy, "Ping", on_send_ping, NULL, -1, "");
efreet_cache_icon_update();
efreet_cache_desktop_update();
/*
* TODO: Needed?
edbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
conn, EINA_TRUE);
*/
}
return 1;
@ -185,10 +154,6 @@ error:
if (desktops) eina_hash_free(desktops);
desktops = NULL;
if (cache_exe_handler) ecore_event_handler_del(cache_exe_handler);
cache_exe_handler = NULL;
if (cache_monitor) ecore_file_monitor_del(cache_monitor);
cache_monitor = NULL;
efreet_cache_edd_shutdown();
return 0;
}
@ -197,7 +162,6 @@ void
efreet_cache_shutdown(void)
{
Efreet_Old_Cache *d;
void *data;
IF_RELEASE(theme_name);
@ -209,34 +173,11 @@ efreet_cache_shutdown(void)
IF_FREE_HASH(fallbacks);
IF_FREE_HASH_CB(desktops, EINA_FREE_CB(efreet_cache_desktop_free));
EINA_LIST_FREE(desktop_dirs_add, data)
eina_stringshare_del(data);
desktop_cache = efreet_cache_close(desktop_cache);
IF_RELEASE(desktop_cache_file);
if (cache_exe_handler) ecore_event_handler_del(cache_exe_handler);
cache_exe_handler = NULL;
if (cache_monitor) ecore_file_monitor_del(cache_monitor);
cache_monitor = NULL;
efreet_cache_edd_shutdown();
if (desktop_cache_timer)
{
ecore_timer_del(desktop_cache_timer);
desktop_cache_timer = NULL;
}
IF_RELEASE(icon_theme_cache_file);
if (icon_cache_exe_lock > 0)
{
close(icon_cache_exe_lock);
icon_cache_exe_lock = -1;
}
if (desktop_cache_exe_lock > 0)
{
close(desktop_cache_exe_lock);
desktop_cache_exe_lock = -1;
}
if (old_desktop_caches)
ERR("This application has not properly closed all its desktop references!");
@ -264,6 +205,14 @@ efreet_cache_shutdown(void)
eina_log_domain_unregister(_efreet_cache_log_dom);
_efreet_cache_log_dom = -1;
/*
* TODO: Needed??
edbus_name_owner_changed_callback_del(conn, BUS, on_name_owner_changed, conn);
*/
if (conn) edbus_connection_unref(conn);
edbus_shutdown();
}
/*
@ -910,52 +859,56 @@ efreet_cache_desktop_free(Efreet_Desktop *desktop)
void
efreet_cache_desktop_add(Efreet_Desktop *desktop)
{
char buf[PATH_MAX];
char *dir;
Efreet_Cache_Array_String *arr;
EDBus_Message *msg;
EDBus_Message_Iter *iter, *array_of_string;
/*
* Read file from disk, save path in cache so it will be included in next
* cache update
*/
strncpy(buf, desktop->orig_path, PATH_MAX);
buf[PATH_MAX - 1] = '\0';
dir = dirname(buf);
arr = efreet_cache_desktop_dirs();
if (arr)
{
unsigned int i;
for (i = 0; i < arr->array_count; i++)
{
/* Check if we already have this dir in cache */
if (!strcmp(dir, arr->array[i]))
return;
}
efreet_cache_array_string_free(arr);
}
if (!eina_list_search_unsorted_list(desktop_dirs_add, EINA_COMPARE_CB(strcmp), dir))
desktop_dirs_add = eina_list_append(desktop_dirs_add, eina_stringshare_add(dir));
efreet_cache_desktop_update();
if (!efreet_cache_update) return;
/* TODO: Chunk updates */
msg = edbus_proxy_method_call_new(proxy, "AddDesktopDirs");
iter = edbus_message_iter_get(msg);
array_of_string = edbus_message_iter_container_new(iter, 'a',"s");
edbus_message_iter_basic_append(array_of_string, 's', desktop->orig_path);
edbus_message_iter_container_close(iter, array_of_string);
edbus_proxy_send(proxy, msg, NULL, NULL, -1);
edbus_message_unref(msg);
}
Efreet_Cache_Array_String *
efreet_cache_desktop_dirs(void)
void
efreet_cache_icon_exts_add(Eina_List *exts)
{
if (!efreet_cache_check(&desktop_cache, efreet_desktop_cache_file(), EFREET_DESKTOP_CACHE_MAJOR)) return NULL;
EDBus_Message *msg;
EDBus_Message_Iter *iter, *array_of_string;
Eina_List *l;
const char *ext;
return eet_data_read(desktop_cache, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS);
if (!efreet_cache_update) return;
msg = edbus_proxy_method_call_new(proxy, "AddIconExts");
iter = edbus_message_iter_get(msg);
array_of_string = edbus_message_iter_container_new(iter, 'a',"s");
EINA_LIST_FOREACH(exts, l, ext)
edbus_message_iter_basic_append(array_of_string, 's', ext);
edbus_message_iter_container_close(iter, array_of_string);
edbus_proxy_send(proxy, msg, NULL, NULL, -1);
edbus_message_unref(msg);
}
void
efreet_cache_desktop_update(void)
efreet_cache_icon_dirs_add(Eina_List *dirs)
{
if (!efreet_cache_update) return;
EDBus_Message *msg;
EDBus_Message_Iter *iter, *array_of_string;
Eina_List *l;
const char *dir;
if (desktop_cache_timer)
ecore_timer_del(desktop_cache_timer);
desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL);
if (!efreet_cache_update) return;
msg = edbus_proxy_method_call_new(proxy, "AddIconDirs");
iter = edbus_message_iter_get(msg);
array_of_string = edbus_message_iter_container_new(iter, 'a',"s");
EINA_LIST_FOREACH(dirs, l, dir)
edbus_message_iter_basic_append(array_of_string, 's', dir);
edbus_message_iter_container_close(iter, array_of_string);
edbus_proxy_send(proxy, msg, NULL, NULL, -1);
edbus_message_unref(msg);
}
void
@ -995,13 +948,10 @@ efreet_cache_desktop_close(void)
}
void
efreet_cache_icon_update(void)
efreet_cache_desktop_build(void)
{
if (!efreet_cache_update) return;
if (icon_cache_timer)
ecore_timer_del(icon_cache_timer);
icon_cache_timer = ecore_timer_add(0.2, icon_cache_update_cache_cb, NULL);
edbus_proxy_call(proxy, "BuildDesktopCache", NULL, NULL, -1, "");
}
static Eina_Bool
@ -1095,283 +1045,91 @@ efreet_cache_util_names(const char *key)
return util_cache_names;
}
static Eina_Bool
cache_exe_cb(void *data __UNUSED__, int type __UNUSED__, void *event)
static void
on_send_ping(void *data __UNUSED__, const EDBus_Message *msg, EDBus_Pending *pending __UNUSED__)
{
Ecore_Exe_Event_Del *ev;
const char *errname, *errmsg;
ev = event;
if (ev->exe == desktop_cache_exe)
if (edbus_message_error_get(msg, &errname, &errmsg))
{
if (desktop_cache_exe_lock > 0)
{
close(desktop_cache_exe_lock);
desktop_cache_exe_lock = -1;
}
desktop_cache_exe = NULL;
}
else if (ev->exe == icon_cache_exe)
{
if (icon_cache_exe_lock > 0)
{
close(icon_cache_exe_lock);
icon_cache_exe_lock = -1;
}
icon_cache_exe = NULL;
ERR("%s %s", errname, errmsg);
return;
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
cache_check_change(const char *path)
{
const char *data;
Eina_Bool changed = EINA_TRUE;
Eina_File *f;
f = eina_file_open(path, EINA_FALSE);
if (!f) return EINA_TRUE;
if (eina_file_size_get(f) < 1) return EINA_TRUE;
data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
if (*data == 'n') changed = EINA_FALSE;
eina_file_close(f);
return changed;
}
static void
cache_update_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
Ecore_File_Event event, const char *path)
desktop_cache_update(void *context __UNUSED__, const EDBus_Message *msg)
{
const char *file;
Efreet_Event_Cache_Update *ev = NULL;
Efreet_Old_Cache *d = NULL;
Eina_List *l = NULL;
if (event != ECORE_FILE_EVENT_CLOSED)
return;
Eina_Bool update;
file = ecore_file_file_get(path);
if (!file) return;
if (!strcmp(file, "desktop_data.update"))
if (edbus_message_arguments_get(msg, "b", &update))
{
if (cache_check_change(path))
if (update)
{
ev = NEW(Efreet_Event_Cache_Update, 1);
if (!ev) goto error;
Efreet_Event_Cache_Update *ev = NULL;
efreet_cache_desktop_close();
ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_UPDATE, ev, desktop_cache_update_free, d);
}
ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
/* TODO: Check if desktop_dirs_add exists, and rebuild cache if */
}
else if (!strcmp(file, "icon_data.update"))
{
if (cache_check_change(path))
{
ev = NEW(Efreet_Event_Cache_Update, 1);
if (!ev) goto error;
IF_RELEASE(theme_name);
/* Save all old caches */
d = NEW(Efreet_Old_Cache, 1);
if (!d) goto error;
d->hash = themes;
d->ef = icon_theme_cache;
l = eina_list_append(l, d);
d = NEW(Efreet_Old_Cache, 1);
if (!d) goto error;
d->hash = icons;
d->ef = icon_cache;
l = eina_list_append(l, d);
d = NEW(Efreet_Old_Cache, 1);
if (!d) goto error;
d->hash = fallbacks;
d->ef = fallback_cache;
l = eina_list_append(l, d);
/* Create new empty caches */
themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
icon_theme_cache = NULL;
icon_cache = NULL;
fallback_cache = NULL;
/* Send event */
ecore_event_add(EFREET_EVENT_ICON_CACHE_UPDATE, ev, icon_cache_update_free, l);
if (ev)
ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_UPDATE, ev, NULL, NULL);
}
/* TODO: Need to send this event always */
ecore_event_add(EFREET_EVENT_DESKTOP_CACHE_BUILD, NULL, NULL, NULL);
}
return;
error:
IF_FREE(ev);
IF_FREE(d);
EINA_LIST_FREE(l, d)
free(d);
}
static Eina_Bool
desktop_cache_update_cache_cb(void *data __UNUSED__)
static void
icon_cache_update(void *context __UNUSED__, const EDBus_Message *msg)
{
char file[PATH_MAX];
struct flock fl;
int prio;
desktop_cache_timer = NULL;
/* TODO: Retry update cache later */
if (desktop_cache_exe_lock > 0) return ECORE_CALLBACK_CANCEL;
snprintf(file, sizeof(file), "%s/efreet/desktop_exec.lock", efreet_cache_home_get());
desktop_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (desktop_cache_exe_lock < 0) goto error;
efreet_fsetowner(desktop_cache_exe_lock);
memset(&fl, 0, sizeof(struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
if (fcntl(desktop_cache_exe_lock, F_SETLK, &fl) < 0) goto error;
prio = ecore_exe_run_priority_get();
ecore_exe_run_priority_set(19);
eina_strlcpy(file, PACKAGE_LIB_DIR "/efreet/efreet_desktop_cache_create", sizeof(file));