diff --git a/legacy/efreet/.gitignore b/legacy/efreet/.gitignore index 99c665b57e..9e19f3ead3 100644 --- a/legacy/efreet/.gitignore +++ b/legacy/efreet/.gitignore @@ -40,12 +40,14 @@ m4/lt~obsolete.m4 /missing src/bin/efreet_desktop_cache_create src/bin/efreet_icon_cache_create +src/bin/efreetd src/tests/compare/efreet_alloc src/tests/compare/efreet_menu_alloc src/tests/efreet_cache_test src/tests/efreet_icon_cache_dump src/tests/efreet_spec_test src/tests/efreet_test +src/tests/efreet_user_dir /m4/codeset.m4 /m4/gettext.m4 /m4/glibc21.m4 @@ -150,3 +152,4 @@ src/tests/efreet_test /po/*.gmo /po/stamp-po /stamp-h1 +/org.enlightenment.Efreet.service diff --git a/legacy/efreet/Makefile.am b/legacy/efreet/Makefile.am index a1590158cf..858b0bb0e6 100644 --- a/legacy/efreet/Makefile.am +++ b/legacy/efreet/Makefile.am @@ -76,6 +76,9 @@ endif pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = efreet.pc efreet-mime.pc efreet-trash.pc +servicedir = $(dbusservicedir) +service_DATA = org.enlightenment.Efreet.service + EXTRA_DIST = \ AUTHORS \ COPYING \ diff --git a/legacy/efreet/configure.ac b/legacy/efreet/configure.ac index 07c56a0909..fb11f00ecd 100644 --- a/legacy/efreet/configure.ac +++ b/legacy/efreet/configure.ac @@ -166,11 +166,33 @@ AC_SUBST(EFL_EFREET_BUILD) AC_SUBST(EFL_EFREET_MIME_BUILD) AC_SUBST(EFL_EFREET_TRASH_BUILD) +service="" +have_efreetd="" +dbusservicedir="" +PKG_CHECK_MODULES(EFREETD, [ + eina >= 1.7.99 + ecore >= 1.7.99 + ecore-file >= 1.7.99 + edbus2 >= 1.7.99 +], [ + have_efreetd="yes" + service="org.enlightenment.Efreet.service" + requirement_efreet="edbus2 ${requirement_efreet}" + dbusservicedir=${datadir}/dbus-1/services + AC_ARG_WITH([dbus-services], + AC_HELP_STRING([--with-dbus-services=DBUS_SERVICES], [specify a directory to store dbus service files.]), + [ dbusservicedir=$withval ] + ) + + ], [ + have_efreetd="no" +]) +AM_CONDITIONAL([HAVE_EFREETD], [test "x${have_efreetd}" = "xyes"]) + requirement_efreet="ecore-file >= 1.6.99 ecore >= 1.6.99 eet >= 1.6.99 eina >= 1.6.99 ${requirement_efreet}" PKG_CHECK_MODULES(EFREET, [${requirement_efreet}]) PKG_CHECK_MODULES(EINA, [eina >= 1.6.99]) - ### Checks for header files AC_CHECK_HEADERS([netinet/in.h arpa/inet.h]) @@ -234,6 +256,7 @@ if test "x$enable_coverage" = "xyes" ; then fi AC_SUBST(requirement_efreet) +AC_SUBST(dbusservicedir) AC_OUTPUT([ efreet.spec @@ -251,6 +274,7 @@ src/tests/data/Makefile src/tests/data/sub/Makefile src/tests/compare/Makefile $po_makefile_in +$service ]) @@ -270,6 +294,10 @@ echo " Specification compliance:" echo " Strict.............: ${enable_strict_spec}" echo " Sloppy.............: ${enable_sloppy_spec}" echo +if test "x$have_efreetd" = "xyes"; then + echo " DBus services dir....: ${dbusservicedir}" + echo +fi echo " Tests................: ${enable_tests}" echo " Coverage.............: ${enable_coverage}" echo diff --git a/legacy/efreet/org.enlightenment.Efreet.service.in b/legacy/efreet/org.enlightenment.Efreet.service.in new file mode 100644 index 0000000000..94eedc87e3 --- /dev/null +++ b/legacy/efreet/org.enlightenment.Efreet.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.enlightenment.Efreet +Exec=@prefix@/bin/efreetd diff --git a/legacy/efreet/src/bin/Makefile.am b/legacy/efreet/src/bin/Makefile.am index 3040a20bac..e77fd6c4a8 100644 --- a/legacy/efreet/src/bin/Makefile.am +++ b/legacy/efreet/src/bin/Makefile.am @@ -27,3 +27,20 @@ $(top_builddir)/src/lib/libefreet.la \ efreet_icon_cache_create_SOURCES = \ efreet_icon_cache_create.c + +if HAVE_EFREETD +bin_PROGRAMS = \ +efreetd + +efreetd_LDADD = \ +$(top_builddir)/src/lib/libefreet.la \ +@EFREETD_LIBS@ + +efreetd_SOURCES = \ +efreetd.c \ +efreetd_dbus.h \ +efreetd_dbus.c \ +efreetd_cache.h \ +efreetd_cache.c +endif + diff --git a/legacy/efreet/src/bin/efreet_desktop_cache_create.c b/legacy/efreet/src/bin/efreet_desktop_cache_create.c index 3b77f8282a..2c8e330a4a 100644 --- a/legacy/efreet/src/bin/efreet_desktop_cache_create.c +++ b/legacy/efreet/src/bin/efreet_desktop_cache_create.c @@ -507,6 +507,7 @@ main(int argc, char **argv) if (changed) c = 'c'; if (write(tmpfd, &c, 1) != 1) perror("write"); close(tmpfd); + printf("%c\n", c); } EINA_LIST_FREE(systemdirs, dir) diff --git a/legacy/efreet/src/bin/efreet_icon_cache_create.c b/legacy/efreet/src/bin/efreet_icon_cache_create.c index e24364b6d5..0eb34b779b 100644 --- a/legacy/efreet/src/bin/efreet_icon_cache_create.c +++ b/legacy/efreet/src/bin/efreet_icon_cache_create.c @@ -1128,6 +1128,7 @@ main(int argc, char **argv) if (changed) c = 'c'; if (write(tmpfd, &c, 1) != 1) perror("write"); close(tmpfd); + printf("%c\n", c); } INF("done"); diff --git a/legacy/efreet/src/bin/efreetd.c b/legacy/efreet/src/bin/efreetd.c new file mode 100644 index 0000000000..a905664f3d --- /dev/null +++ b/legacy/efreet/src/bin/efreetd.c @@ -0,0 +1,47 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "efreetd.h" +#include "efreetd_dbus.h" +#include "efreetd_cache.h" + +int efreetd_log_dom = -1; + +int +main(void) +{ + if (!eina_init()) return 1; + efreetd_log_dom = eina_log_domain_register("efreetd", EFREETD_DEFAULT_LOG_COLOR); + if (efreetd_log_dom < 0) + { + EINA_LOG_ERR("Efreet: Could not create a log domain for efreetd."); + goto ecore_error; + } + if (!ecore_init()) goto ecore_error; + + if (!dbus_init()) goto dbus_error; + if (!cache_init()) goto cache_error; + + ecore_main_loop_begin(); + + cache_shutdown(); + dbus_shutdown(); + ecore_shutdown(); + eina_log_domain_unregister(efreetd_log_dom); + efreetd_log_dom = -1; + eina_shutdown(); + return 0; + +cache_error: + dbus_shutdown(); +dbus_error: + ecore_shutdown(); +ecore_error: + eina_log_domain_unregister(efreetd_log_dom); + efreetd_log_dom = -1; + eina_shutdown(); + return 1; +} diff --git a/legacy/efreet/src/bin/efreetd.h b/legacy/efreet/src/bin/efreetd.h new file mode 100644 index 0000000000..67097de4a5 --- /dev/null +++ b/legacy/efreet/src/bin/efreetd.h @@ -0,0 +1,32 @@ +#ifndef __EFREETD_H +#define __EFREETD_H + +#ifdef EFREETD_DEFAULT_LOG_COLOR +#undef EFREETD_DEFAULT_LOG_COLOR +#endif +#define EFREETD_DEFAULT_LOG_COLOR "\033[36m" + +extern int efreetd_log_dom; + +#ifdef CRITICAL +#undef CRITICAL +#endif +#define CRITICAL(...) EINA_LOG_DOM_CRIT(efreetd_log_dom, __VA_ARGS__) +#ifdef ERR +#undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(efreetd_log_dom, __VA_ARGS__) +#ifdef DBG +#undef DBG +#endif +#define DBG(...) EINA_LOG_DOM_DBG(efreetd_log_dom, __VA_ARGS__) +#ifdef INF +#undef INF +#endif +#define INF(...) EINA_LOG_DOM_INFO(efreetd_log_dom, __VA_ARGS__) +#ifdef WRN +#undef WRN +#endif +#define WRN(...) EINA_LOG_DOM_WARN(efreetd_log_dom, __VA_ARGS__) + +#endif diff --git a/legacy/efreet/src/bin/efreetd_cache.c b/legacy/efreet/src/bin/efreetd_cache.c new file mode 100644 index 0000000000..a3a47eeaf7 --- /dev/null +++ b/legacy/efreet/src/bin/efreetd_cache.c @@ -0,0 +1,495 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include + +#include "efreetd.h" +#include "efreetd_dbus.h" + +#include "Efreet.h" +#define EFREET_MODULE_LOG_DOM efreetd_log_dom +#include "efreet_private.h" + +static Eina_Hash *change_monitors = NULL; + +static Ecore_Event_Handler *cache_exe_del_handler = NULL; +static Ecore_Event_Handler *cache_exe_data_handler = NULL; +static Ecore_Exe *icon_cache_exe = NULL; +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_extra_dirs = NULL; +static Eina_List *icon_extra_dirs = NULL; +static Eina_List *icon_extra_exts = NULL; + +static void desktop_changes_monitor_add(const char *path); + +/* internal */ +static Eina_Bool +icon_cache_update_cache_cb(void *data __UNUSED__) +{ + char file[PATH_MAX]; + int prio; + + icon_cache_timer = NULL; + + /* TODO: Queue if already running */ + prio = ecore_exe_run_priority_get(); + ecore_exe_run_priority_set(19); + eina_strlcpy(file, PACKAGE_LIB_DIR "/efreet/efreet_icon_cache_create", sizeof(file)); + if (icon_extra_dirs) + { + Eina_List *ll; + char *p; + + eina_strlcat(file, " -d", sizeof(file)); + EINA_LIST_FOREACH(icon_extra_dirs, ll, p) + { + eina_strlcat(file, " ", sizeof(file)); + eina_strlcat(file, p, sizeof(file)); + } + } + if (icon_extra_exts) + { + Eina_List *ll; + char *p; + + eina_strlcat(file, " -e", sizeof(file)); + EINA_LIST_FOREACH(icon_extra_exts, ll, p) + { + eina_strlcat(file, " ", sizeof(file)); + eina_strlcat(file, p, sizeof(file)); + } + } + icon_cache_exe = ecore_exe_run(file, NULL); + ecore_exe_run_priority_set(prio); + + return ECORE_CALLBACK_CANCEL; +} + +static void +cache_icon_update(void) +{ + if (icon_cache_timer) + ecore_timer_del(icon_cache_timer); + icon_cache_timer = ecore_timer_add(0.2, icon_cache_update_cache_cb, NULL); +} + +static Eina_Bool +desktop_cache_update_cache_cb(void *data __UNUSED__) +{ + char file[PATH_MAX]; + int prio; + + desktop_cache_timer = NULL; + + /* TODO: Queue if already running */ + 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)); + if (desktop_extra_dirs) + { + Eina_List *ll; + const char *str; + + eina_strlcat(file, " -d", sizeof(file)); + EINA_LIST_FOREACH(desktop_extra_dirs, ll, str) + { + eina_strlcat(file, " ", sizeof(file)); + eina_strlcat(file, str, sizeof(file)); + } + } + INF("Run desktop cache creation: %s", file); + desktop_cache_exe = ecore_exe_run(file, 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) +{ + Ecore_Exe_Event_Data *ev; + + ev = event; + if (ev->exe == desktop_cache_exe) + { + Eina_Bool update = EINA_FALSE; + + if ((ev->lines) && (*ev->lines->line == 'c')) + update = EINA_TRUE; + + send_signal_desktop_cache_update(update); + } + else if (ev->exe == icon_cache_exe) + { + Eina_Bool update = EINA_FALSE; + + if ((ev->lines) && (*ev->lines->line == 'c')) + update = EINA_TRUE; + send_signal_icon_cache_update(update); + } + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool +cache_exe_del_cb(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + Ecore_Exe_Event_Del *ev; + + ev = event; + if (ev->exe == desktop_cache_exe) + { + desktop_cache_exe = NULL; + } + else if (ev->exe == icon_cache_exe) + { + icon_cache_exe = NULL; + } + return ECORE_CALLBACK_RENEW; +} + +static void +icon_changes_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__, + Ecore_File_Event event, const char *path) +{ + /* TODO: If we get a stale symlink, we need to rerun cache creation */ + switch (event) + { + case ECORE_FILE_EVENT_NONE: + /* noop */ + break; + + case ECORE_FILE_EVENT_CREATED_FILE: + case ECORE_FILE_EVENT_DELETED_FILE: + case ECORE_FILE_EVENT_MODIFIED: + case ECORE_FILE_EVENT_CLOSED: + case ECORE_FILE_EVENT_DELETED_DIRECTORY: + case ECORE_FILE_EVENT_CREATED_DIRECTORY: + cache_icon_update(); + break; + + case ECORE_FILE_EVENT_DELETED_SELF: + eina_hash_del_by_key(change_monitors, path); + cache_icon_update(); + break; + } +} + +static void +icon_changes_monitor_add(const char *path) +{ + Eina_Iterator *it; + Eina_File_Direct_Info *info; + + 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)); + + 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)); + } + eina_iterator_free(it); +} + +static void +icon_changes_listen(void) +{ + Eina_List *l; + Eina_List *xdg_dirs; + char buf[PATH_MAX]; + const char *dir; + + icon_changes_monitor_add(efreet_icon_deprecated_user_dir_get()); + icon_changes_monitor_add(efreet_icon_user_dir_get()); + EINA_LIST_FOREACH(icon_extra_dirs, l, dir) + icon_changes_monitor_add(dir); + + xdg_dirs = efreet_data_dirs_get(); + EINA_LIST_FOREACH(xdg_dirs, l, dir) + { + snprintf(buf, sizeof(buf), "%s/icons", dir); + icon_changes_monitor_add(buf); + } + +#ifndef STRICT_SPEC + EINA_LIST_FOREACH(xdg_dirs, l, dir) + { + snprintf(buf, sizeof(buf), "%s/pixmaps", dir); + icon_changes_monitor_add(buf); + } +#endif + + icon_changes_monitor_add("/usr/share/pixmaps"); +} + +static void +desktop_changes_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__, + Ecore_File_Event event, const char *path) +{ + const char *ext; + + /* TODO: If we get a stale symlink, we need to rerun cache creation */ + /* TODO: Check for desktop*.cache, as this will be created when app is installed */ + /* TODO: Do efreet_cache_icon_update() when app is installed, as it has the same + * symlink problem */ + switch (event) + { + case ECORE_FILE_EVENT_NONE: + /* noop */ + break; + + case ECORE_FILE_EVENT_CREATED_FILE: + case ECORE_FILE_EVENT_DELETED_FILE: + case ECORE_FILE_EVENT_MODIFIED: + case ECORE_FILE_EVENT_CLOSED: + ext = strrchr(path, '.'); + if (ext && (!strcmp(ext, ".desktop") || !strcmp(ext, ".directory"))) + cache_desktop_update(); + break; + + case ECORE_FILE_EVENT_DELETED_SELF: + case ECORE_FILE_EVENT_DELETED_DIRECTORY: + eina_hash_del_by_key(change_monitors, path); + cache_desktop_update(); + break; + + case ECORE_FILE_EVENT_CREATED_DIRECTORY: + desktop_changes_monitor_add(path); + cache_desktop_update(); + break; + } +} + +static void +desktop_changes_monitor_add(const char *path) +{ + if (eina_hash_find(change_monitors, path)) return; + eina_hash_add(change_monitors, path, + ecore_file_monitor_add(path, + desktop_changes_cb, + NULL)); +} + +static void +desktop_changes_listen_recursive(const char *path) +{ + Eina_Iterator *it; + Eina_File_Direct_Info *info; + + desktop_changes_monitor_add(path); + + it = eina_file_stat_ls(path); + if (!it) return; + EINA_ITERATOR_FOREACH(it, info) + { + if (info->type != EINA_FILE_DIR) continue; + desktop_changes_listen_recursive(info->path); + } + eina_iterator_free(it); +} + +static void +desktop_changes_listen(void) +{ + Eina_List *dirs, *l; + const char *path; + + dirs = efreet_default_dirs_get(efreet_data_home_get(), + efreet_data_dirs_get(), "applications"); + + EINA_LIST_FREE(dirs, path) + { + if (ecore_file_is_dir(path)) + desktop_changes_listen_recursive(path); + eina_stringshare_del(path); + } + + EINA_LIST_FOREACH(desktop_extra_dirs, l, path) + desktop_changes_monitor_add(path); +} + +static void +fill_extra(const char *file, Eina_List **l) +{ + Eina_File *f = NULL; + Eina_Iterator *it = NULL; + Eina_File_Line *line = NULL; + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/efreet/%s", efreet_cache_home_get(), file); + f = eina_file_open(buf, EINA_FALSE); + if (!f) return; + it = eina_file_map_lines(f); + if (!it) goto error; + EINA_ITERATOR_FOREACH(it, line) + { + 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: + eina_file_close(f); +} + +static void +read_extra(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); +} + +static void +save_extra(const char *file, Eina_List *l) +{ + FILE *f; + char buf[PATH_MAX]; + Eina_List *ll; + const char *path; + + snprintf(buf, sizeof(buf), "%s/efreet/%s", efreet_cache_home_get(), file); + f = fopen("wb", buf); + if (!f) return; + EINA_LIST_FOREACH(l, ll, path) + fprintf(f, "%s\n", path); + fclose(f); +} + +/* external */ +void +cache_desktop_dir_add(const char *dir) +{ + char *san; + + san = eina_file_path_sanitize(dir); + if (!san) return; + if (!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); + cache_desktop_update(); + } + free(san); +} + +void +cache_icon_dir_add(const char *dir) +{ + char *san; + + san = eina_file_path_sanitize(dir); + if (!san) return; + 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(); + } + free(san); +} + +void +cache_icon_ext_add(const char *ext) +{ + if (!eina_list_search_unsorted_list(icon_extra_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(); + } +} + +Eina_Bool +cache_init(void) +{ + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/efreet", efreet_cache_home_get()); + if (!ecore_file_mkpath(buf)) + { + ERR("Failed to create directory '%s'\n", buf); + goto error; + } + + cache_exe_del_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, + 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); + if (!cache_exe_data_handler) + { + ERR("Failed to add exe del handler\n"); + goto error; + } + + change_monitors = eina_hash_string_superfast_new(EINA_FREE_CB(ecore_file_monitor_del)); + + efreet_cache_update = 0; + if (!efreet_init()) goto error; + + read_extra(); + icon_changes_listen(); + desktop_changes_listen(); + cache_icon_update(); + cache_desktop_update(); + + return EINA_TRUE; +error: + if (cache_exe_del_handler) ecore_event_handler_del(cache_exe_del_handler); + cache_exe_del_handler = NULL; + if (cache_exe_data_handler) ecore_event_handler_del(cache_exe_data_handler); + cache_exe_data_handler = NULL; + return EINA_FALSE; +} + +Eina_Bool +cache_shutdown(void) +{ + const char *data; + + efreet_shutdown(); + + if (cache_exe_del_handler) ecore_event_handler_del(cache_exe_del_handler); + cache_exe_del_handler = NULL; + if (cache_exe_data_handler) ecore_event_handler_del(cache_exe_data_handler); + cache_exe_data_handler = NULL; + + if (change_monitors) + eina_hash_free(change_monitors); + 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_stringshare_del(data); + return EINA_TRUE; +} diff --git a/legacy/efreet/src/bin/efreetd_cache.h b/legacy/efreet/src/bin/efreetd_cache.h new file mode 100644 index 0000000000..cfcadda50b --- /dev/null +++ b/legacy/efreet/src/bin/efreetd_cache.h @@ -0,0 +1,11 @@ +#ifndef __EFREETD_CACHE_H +#define __EFREETD_CACHE_H + +void cache_desktop_dir_add(const char *dir); +void cache_icon_dir_add(const char *dir); +void cache_icon_ext_add(const char *ext); + +Eina_Bool cache_init(void); +Eina_Bool cache_shutdown(void); + +#endif diff --git a/legacy/efreet/src/bin/efreetd_dbus.c b/legacy/efreet/src/bin/efreetd_dbus.c new file mode 100644 index 0000000000..1bac51875d --- /dev/null +++ b/legacy/efreet/src/bin/efreetd_dbus.c @@ -0,0 +1,184 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "efreetd.h" +#include "efreetd_cache.h" + +#define BUS "org.enlightenment" +#define PATH "/org/enlightenment" +#define INTERFACE "org.enlightenment.Efreet" + +/* internal */ +enum +{ + EFREET_SIGNAL_ICON_CACHE_UPDATE = 0, + EFREET_SIGNAL_DESKTOP_CACHE_UPDATE +}; + +static EDBus_Connection *conn; +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."); + return NULL; + } + + while (edbus_message_iter_get_and_next(array, 's', &dir)) + { + cache_desktop_dir_add(dir); + } + + return NULL; +} + +static EDBus_Message * +add_icon_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *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."); + return NULL; + } + + while (edbus_message_iter_get_and_next(array, 's', &dir)) + { + cache_icon_dir_add(dir); + } + + 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."); + return NULL; + } + + while (edbus_message_iter_get_and_next(array, 's', &ext)) + { + cache_icon_ext_add(ext); + } + + return NULL; +} + +static const EDBus_Signal signals[] = { + [EFREET_SIGNAL_ICON_CACHE_UPDATE] = {"IconCacheUpdate", EDBUS_ARGS({ "b", "update" }), 0}, + [EFREET_SIGNAL_DESKTOP_CACHE_UPDATE] = {"DesktopCacheUpdate", EDBUS_ARGS({ "b", "update" }), 0}, + { NULL, NULL, 0 } +}; + +static const EDBus_Method methods[] = { + { + "Ping", NULL, NULL, + ping, 0 + }, + { + "AddDesktopDirs", NULL, EDBUS_ARGS({"as", "dirs"}), + add_desktop_dirs, EDBUS_METHOD_FLAG_NOREPLY + }, + { + "AddIconDirs", NULL, EDBUS_ARGS({"as", "dirs"}), + add_icon_dirs, EDBUS_METHOD_FLAG_NOREPLY + }, + { + "AddIconExts", NULL, EDBUS_ARGS({"as", "exts"}), + add_icon_exts, EDBUS_METHOD_FLAG_NOREPLY + }, + { NULL, NULL, NULL, NULL, 0 } +}; + +static void +on_name_request(void *data __UNUSED__, const EDBus_Message *msg, EDBus_Pending *pending __UNUSED__) +{ + unsigned int flag; + + if (edbus_message_error_get(msg, NULL, NULL)) + { + ERR("error on on_name_request"); + return; + } + + if (!edbus_message_arguments_get(msg, "u", &flag)) + { + ERR("error getting arguments on on_name_request"); + return; + } + + if (!(flag & EDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)) + { + ERR("error name already in use"); + return; + } + + iface = edbus_service_interface_register(conn, PATH, INTERFACE, methods, + signals); +} + +/* external */ +void +send_signal_icon_cache_update(Eina_Bool update) +{ + edbus_service_signal_emit(iface, EFREET_SIGNAL_ICON_CACHE_UPDATE, update); +} + +void +send_signal_desktop_cache_update(Eina_Bool update) +{ + edbus_service_signal_emit(iface, EFREET_SIGNAL_DESKTOP_CACHE_UPDATE, update); +} + +Eina_Bool +dbus_init(void) +{ + if (!edbus_init()) return EINA_FALSE; + + conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION); + if (!conn) goto conn_error; + + edbus_name_request(conn, BUS, EDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE, + on_name_request, NULL); + + return EINA_TRUE; +conn_error: + edbus_shutdown(); + return EINA_FALSE; +} + +Eina_Bool +dbus_shutdown(void) +{ + edbus_connection_unref(conn); + edbus_shutdown(); + return EINA_TRUE; + +} diff --git a/legacy/efreet/src/bin/efreetd_dbus.h b/legacy/efreet/src/bin/efreetd_dbus.h new file mode 100644 index 0000000000..9e9fd70700 --- /dev/null +++ b/legacy/efreet/src/bin/efreetd_dbus.h @@ -0,0 +1,10 @@ +#ifndef __EFREETD_DBUS_H +#define __EFREETD_DBUS_H + +void send_signal_icon_cache_update(Eina_Bool update); +void send_signal_desktop_cache_update(Eina_Bool update); + +Eina_Bool dbus_init(void); +Eina_Bool dbus_shutdown(void); + +#endif diff --git a/legacy/efreet/src/lib/efreet_copy.h b/legacy/efreet/src/lib/efreet_copy.h new file mode 100644 index 0000000000..ccffa00bea --- /dev/null +++ b/legacy/efreet/src/lib/efreet_copy.h @@ -0,0 +1,10 @@ +#ifndef __EFREET_COPY_H +#define __EFREET_COPY_H + +/* functions copied from lib to reduce include size */ + +const char *efreet_icon_deprecated_user_dir_get(void); +const char *efreet_icon_user_dir_get(void); + +#endif +