From 97dfa9db2ec2f7f8039fcc318abd2a0993a78a8d Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Sat, 30 Jun 2012 19:28:49 +0000 Subject: [PATCH] enlightenment_filemanager - call EFM from another process. This is used to open a file manager window from another process. It will use DBus interface: org.enlightenment.FileManager.OpenDirectory(path) It returns immediately, but we could enhance the DBus interface and make it act like a real file manager process if that is needed. SVN revision: 73084 --- configure.ac | 8 + data/Makefile.am | 3 +- data/desktop/Makefile.am | 6 + .../desktop/enlightenment_filemanager.desktop | 14 ++ src/bin/Makefile.am | 7 +- src/bin/e_fm_cmdline.c | 144 ++++++++++++++++++ 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 data/desktop/Makefile.am create mode 100644 data/desktop/enlightenment_filemanager.desktop create mode 100644 src/bin/e_fm_cmdline.c diff --git a/configure.ac b/configure.ac index 61b2f2702..d90ec0f08 100644 --- a/configure.ac +++ b/configure.ac @@ -476,6 +476,13 @@ AC_MSG_WARN([EFM requirements : $efm_requires]) PKG_CHECK_MODULES(E_FM, [$efm_requires]) +PKG_CHECK_MODULES(E_FM_CMDLINE, [ + ecore >= 1.2.0 + ecore-file >= 1.2.0 + edbus >= 1.2.0 + dbus-1 +]) + PKG_CHECK_MODULES(E_FM_OP, [ ecore >= 1.2.0 ecore-file >= 1.2.0 @@ -964,6 +971,7 @@ src/preload/Makefile data/Makefile data/images/Makefile data/flags/Makefile +data/desktop/Makefile data/input_methods/Makefile data/themes/Makefile data/themes/images/Makefile diff --git a/data/Makefile.am b/data/Makefile.am index 782c2d9ef..ffc3ec062 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -8,4 +8,5 @@ input_methods \ etc \ icons \ backgrounds \ -flags +flags \ +desktop diff --git a/data/desktop/Makefile.am b/data/desktop/Makefile.am new file mode 100644 index 000000000..20a5004f4 --- /dev/null +++ b/data/desktop/Makefile.am @@ -0,0 +1,6 @@ +MAINTAINERCLEANFILES = Makefile.in +filesdir = $(datadir)/applications +files_DATA = \ + enlightenment_filemanager.desktop + +EXTRA_DIST = $(files_DATA) diff --git a/data/desktop/enlightenment_filemanager.desktop b/data/desktop/enlightenment_filemanager.desktop new file mode 100644 index 000000000..b1c613311 --- /dev/null +++ b/data/desktop/enlightenment_filemanager.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Application +Name=Enlightenment File Manager +Generic=File Manager +Comment=File Manager provided by Enlightenment +Exec=enlightenment_filemanager %U +Icon=system-file-manager +Categories=FileManager;Utility;Core;Enlightenment; +Terminal=false +StartupNotify=false +StartupWMClass=e_fm +OnlyShowIn=Enlightenment; +MimeType=x-directory/normal;inode/directory; diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 67c478ccf..0e2632b44 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -21,7 +21,8 @@ INCLUDES = \ bin_PROGRAMS = \ enlightenment \ enlightenment_imc \ -enlightenment_start +enlightenment_start \ +enlightenment_filemanager internal_bindir = $(libdir)/enlightenment/utils internal_bin_PROGRAMS = \ @@ -406,6 +407,10 @@ e_alert_main.c enlightenment_alert_LDADD = @E_ALERT_LIBS@ enlightenment_alert_CFLAGS = @E_ALERT_CFLAGS@ +enlightenment_filemanager_SOURCES = e_fm_cmdline.c +enlightenment_filemanager_LDADD = @E_FM_CMDLINE_LIBS@ +enlightenment_filemanager_CFLAGS = @E_FM_CMDLINE_CFLAGS@ + # HACK! why install-data-hook? install-exec-hook is run after bin_PROGRAMS # and before internal_bin_PROGRAMS are installed. install-data-hook is # run after both diff --git a/src/bin/e_fm_cmdline.c b/src/bin/e_fm_cmdline.c new file mode 100644 index 000000000..6b2909d15 --- /dev/null +++ b/src/bin/e_fm_cmdline.c @@ -0,0 +1,144 @@ +# ifdef HAVE_CONFIG_H +# include "config.h" +# endif + +#include +#include +#include + +static E_DBus_Connection *conn = NULL; +static int retval = EXIT_SUCCESS; +static int pending = 0; + +static void +fm_open_reply(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *err) +{ + if (dbus_error_is_set(err)) + { + retval = EXIT_FAILURE; + fprintf(stderr, "ERROR: %s: %s", err->name, err->message); + } + + pending--; + if (!pending) ecore_main_loop_quit(); +} + +static Eina_Bool +fm_error_quit_last(void *data __UNUSED__) +{ + if (!pending) ecore_main_loop_quit(); + return EINA_FALSE; +} + +static void +fm_open(const char *path) +{ + DBusMessage *msg; + Eina_Bool sent; + char *p = ecore_file_realpath(path); + + EINA_LOG_DBG("'%s' -> '%s'", path, p); + if ((!p) || (p[0] == '\0')) + { + fprintf(stderr, "ERROR: Could not get real path '%s'\n", path); + ecore_idler_add(fm_error_quit_last, NULL); + free(p); + return; + } + + msg = dbus_message_new_method_call + ("org.enlightenment.FileManager", + "/org/enlightenment/FileManager", + "org.enlightenment.FileManager", "OpenDirectory"); + if (!msg) + { + fputs("ERROR: Could not create DBus Message\n", stderr); + ecore_idler_add(fm_error_quit_last, NULL); + free(p); + return; + } + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &p, DBUS_TYPE_INVALID); + free(p); + + sent = !!e_dbus_message_send(conn, msg, fm_open_reply, -1, NULL); + dbus_message_unref(msg); + + if (!sent) + { + fputs("ERROR: Could not send DBus Message\n", stderr); + ecore_idler_add(fm_error_quit_last, NULL); + return; + } + + pending++; +} + +static const Ecore_Getopt options = { + "enlightenment_filemanager", + "%prog [options] [folder1] ... [folderN]", + PACKAGE_VERSION, + "(C) 2012 Gustavo Sverzut Barbieri and others", + "BSD 2-Clause", + "Opens the Enlightenment File Manager at a given folders.", + EINA_FALSE, + { + ECORE_GETOPT_VERSION('V', "version"), + ECORE_GETOPT_COPYRIGHT('C', "copyright"), + ECORE_GETOPT_LICENSE('L', "license"), + ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_SENTINEL + } +}; + +EAPI int +main(int argc, char *argv[]) +{ + Eina_Bool quit_option = EINA_FALSE; + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_NONE + }; + int args; + + args = ecore_getopt_parse(&options, values, argc, argv); + if (args < 0) + { + fputs("ERROR: Could not parse command line options.\n", stderr); + return EXIT_FAILURE; + } + + if (quit_option) return EXIT_SUCCESS; + + ecore_init(); + ecore_file_init(); + e_dbus_init(); + + conn = e_dbus_bus_get(DBUS_BUS_SESSION); + if (!conn) + { + fputs("ERROR: Could not DBus SESSION bus.\n", stderr); + retval = EXIT_FAILURE; + goto end; + } + + retval = EXIT_SUCCESS; + + if (args == argc) fm_open("."); + else + { + for (; args < argc; args++) + fm_open(argv[args]); + } + + ecore_main_loop_begin(); + + end: + e_dbus_shutdown(); + ecore_file_shutdown(); + ecore_shutdown(); + return retval; +}