6 #include <Ecore_File.h>
7 #include <Ecore_Getopt.h>
11 static E_DBus_Connection *conn = NULL;
12 static int retval = EXIT_SUCCESS;
13 static int pending = 0;
16 fm_open_reply(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *err)
18 if (dbus_error_is_set(err))
20 retval = EXIT_FAILURE;
21 fprintf(stderr, "ERROR: %s: %s", err->name, err->message);
25 if (!pending) ecore_main_loop_quit();
29 fm_error_quit_last(void *data __UNUSED__)
31 if (!pending) ecore_main_loop_quit();
36 fm_open(const char *path)
48 if (!getcwd(buf, sizeof(buf)))
51 "ERROR: Could not get current working directory: %s\n",
53 ecore_idler_add(fm_error_quit_last, NULL);
56 if (strcmp(path, ".") == 0)
61 snprintf(tmp, sizeof(tmp), "%s/%s", buf, path);
66 EINA_LOG_DBG("'%s' -> '%s'", path, p);
67 if ((!p) || (p[0] == '\0'))
69 fprintf(stderr, "ERROR: Could not get path '%s'\n", path);
70 ecore_idler_add(fm_error_quit_last, NULL);
75 if (ecore_file_is_dir(p))
76 method = "OpenDirectory";
80 msg = dbus_message_new_method_call
81 ("org.enlightenment.FileManager",
82 "/org/enlightenment/FileManager",
83 "org.enlightenment.FileManager", method);
86 fputs("ERROR: Could not create DBus Message\n", stderr);
87 ecore_idler_add(fm_error_quit_last, NULL);
92 dbus_message_append_args(msg, DBUS_TYPE_STRING, &p, DBUS_TYPE_INVALID);
95 sent = !!e_dbus_message_send(conn, msg, fm_open_reply, -1, NULL);
96 dbus_message_unref(msg);
100 fputs("ERROR: Could not send DBus Message\n", stderr);
101 ecore_idler_add(fm_error_quit_last, NULL);
108 static const Ecore_Getopt options = {
109 "enlightenment_filemanager",
110 "%prog [options] [file-or-folder1] ... [file-or-folderN]",
112 "(C) 2012 Gustavo Sverzut Barbieri and others",
114 "Opens the Enlightenment File Manager at a given folders.",
117 ECORE_GETOPT_VERSION('V', "version"),
118 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
119 ECORE_GETOPT_LICENSE('L', "license"),
120 ECORE_GETOPT_HELP('h', "help"),
121 ECORE_GETOPT_SENTINEL
126 main(int argc, char *argv[])
128 Eina_Bool quit_option = EINA_FALSE;
129 Ecore_Getopt_Value values[] = {
130 ECORE_GETOPT_VALUE_BOOL(quit_option),
131 ECORE_GETOPT_VALUE_BOOL(quit_option),
132 ECORE_GETOPT_VALUE_BOOL(quit_option),
133 ECORE_GETOPT_VALUE_BOOL(quit_option),
134 ECORE_GETOPT_VALUE_NONE
138 args = ecore_getopt_parse(&options, values, argc, argv);
141 fputs("ERROR: Could not parse command line options.\n", stderr);
145 if (quit_option) return EXIT_SUCCESS;
151 conn = e_dbus_bus_get(DBUS_BUS_SESSION);
154 fputs("ERROR: Could not DBus SESSION bus.\n", stderr);
155 retval = EXIT_FAILURE;
159 retval = EXIT_SUCCESS;
161 if (args == argc) fm_open(".");
164 for (; args < argc; args++)
168 ecore_main_loop_begin();
172 ecore_file_shutdown();