enlightenment/src/modules/fileman/e_mod_dbus.c

331 lines
8.6 KiB
C
Raw Normal View History

#include "e_mod_main.h"
static const char E_FILEMAN_BUS_NAME[] = "org.enlightenment.FileManager";
static const char E_FILEMAN_INTERFACE[] = "org.enlightenment.FileManager";
static const char E_FILEMAN_ERROR[] = "org.enlightenment.FileManager.Error";
static const char E_FILEMAN_PATH[] = "/org/enlightenment/FileManager";
typedef struct _E_Fileman_DBus_Daemon E_Fileman_DBus_Daemon;
struct _E_Fileman_DBus_Daemon
{
2013-04-23 08:08:29 -07:00
Eldbus_Connection *conn;
Eldbus_Service_Interface *iface;
};
2013-04-23 08:08:29 -07:00
static Eldbus_Message * _e_fileman_dbus_daemon_open_directory_cb(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
static Eldbus_Message *_e_fileman_dbus_daemon_open_file_cb(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
_e_fileman_dbus_daemon_error(const Eldbus_Message *msg,
const char *error_msg)
{
2013-04-23 08:08:29 -07:00
return eldbus_message_error_new(msg, E_FILEMAN_ERROR, error_msg);
}
2013-04-23 08:08:29 -07:00
static const Eldbus_Method methods[] = {
{ "OpenDirectory", ELDBUS_ARGS({"s", "directory"}), NULL,
_e_fileman_dbus_daemon_open_directory_cb },
2013-04-23 08:08:29 -07:00
{ "OpenFile", ELDBUS_ARGS({"s", "file"}), NULL,
_e_fileman_dbus_daemon_open_file_cb },
{ }
};
2013-04-23 08:08:29 -07:00
static const Eldbus_Service_Interface_Desc desc = {
E_FILEMAN_INTERFACE, methods
};
static void
_e_fileman_dbus_daemon_object_init(E_Fileman_DBus_Daemon *d)
{
2013-04-23 08:08:29 -07:00
d->iface = eldbus_service_interface_register(d->conn, E_FILEMAN_PATH, &desc);
if (!d->iface)
{
fprintf(stderr, "ERROR: cannot add object to %s\n", E_FILEMAN_PATH);
return;
}
}
static void
_e_fileman_dbus_daemon_free(E_Fileman_DBus_Daemon *d)
{
if (d->iface)
2013-04-23 08:08:29 -07:00
eldbus_service_object_unregister(d->iface);
if (d->conn)
2013-04-23 08:08:29 -07:00
eldbus_connection_unref(d->conn);
free(d);
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message *
_e_fileman_dbus_daemon_open_directory_cb(const Eldbus_Service_Interface *iface __UNUSED__,
const Eldbus_Message *msg)
{
const char *directory = NULL, *p;
char *dev, *to_free = NULL;
E_Zone *zone;
2013-04-23 08:08:29 -07:00
if (!eldbus_message_arguments_get(msg, "s", &directory))
{
fprintf(stderr, "Error: getting arguments of OpenDirectory call.\n");
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(msg);
}
if ((!directory) || (directory[0] == '\0'))
return _e_fileman_dbus_daemon_error(msg, "no directory provided.");
zone = e_util_zone_current_get(e_manager_current_get());
if (!zone)
return _e_fileman_dbus_daemon_error(msg, "could not find a zone.");
if (strstr(directory, "://"))
{
Efreet_Uri *uri = efreet_uri_decode(directory);
directory = NULL;
if (uri)
{
if ((uri->protocol) && (strcmp(uri->protocol, "file") == 0))
directory = to_free = strdup(uri->path);
efreet_uri_free(uri);
}
if (!directory)
return _e_fileman_dbus_daemon_error(msg, "unsupported protocol");
}
p = strchr(directory, '/');
if (p)
{
int len = p - directory + 1;
dev = malloc(len + 1);
if (!dev)
{
free(to_free);
return _e_fileman_dbus_daemon_error(msg,
"could not allocate memory.");
}
memcpy(dev, directory, len);
dev[len] = '\0';
if ((dev[0] != '/') && (dev[0] != '~'))
dev[len - 1] = '\0'; /* remove trailing '/' */
directory += p - directory;
}
else
{
dev = strdup(directory);
directory = "/";
}
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
e_fwin_new(zone->comp, dev, directory);
free(dev);
free(to_free);
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(msg);
}
static Eina_Bool
_mime_shell_script_check(const char *mime)
{
static const struct sh_script_map {
const char *str;
size_t len;
} options[] = {
#define O(x) {x, sizeof(x) - 1}
O("application/x-sh"),
O("application/x-shellscript"),
O("text/x-sh"),
#undef O
{NULL, 0}
};
const struct sh_script_map *itr;
size_t mimelen = strlen(mime);
for (itr = options; itr->str != NULL; itr++)
if ((mimelen == itr->len) && (memcmp(mime, itr->str, mimelen) == 0))
return EINA_TRUE;
return EINA_FALSE;
}
2013-04-23 08:08:29 -07:00
static Eldbus_Message*
_e_fileman_dbus_daemon_open_file_cb(const Eldbus_Service_Interface *iface __UNUSED__,
const Eldbus_Message *msg)
{
Eina_List *handlers;
const char *param_file = NULL, *mime, *errmsg = "unknow error";
char *real_file, *to_free = NULL;
E_Zone *zone;
2013-04-23 08:08:29 -07:00
if (!eldbus_message_arguments_get(msg, "s", &param_file))
{
fprintf(stderr, "ERROR: getting arguments of OpenFile call.\n");
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(msg);
}
if ((!param_file) || (param_file[0] == '\0'))
return _e_fileman_dbus_daemon_error(msg, "no file provided.");
zone = e_util_zone_current_get(e_manager_current_get());
if (!zone)
return _e_fileman_dbus_daemon_error(msg, "could not find a zone.");
if (!strstr(param_file, "://"))
{
real_file = ecore_file_realpath(param_file);
if (!real_file)
{
errmsg = "couldn't get realpath for file.";
goto error;
}
}
else
{
Efreet_Uri *uri = efreet_uri_decode(param_file);
real_file = NULL;
if (uri)
{
if ((uri->protocol) && (strcmp(uri->protocol, "file") == 0))
{
real_file = ecore_file_realpath(uri->path);
param_file = to_free = strdup(uri->path);
}
efreet_uri_free(uri);
}
if (!real_file)
{
errmsg = "unsupported protocol";
goto error;
}
}
mime = efreet_mime_type_get(real_file);
if (!mime)
{
errmsg = "couldn't find mime-type";
goto error;
}
if (strcmp(mime, "application/x-desktop") == 0)
{
Efreet_Desktop *desktop = efreet_desktop_new(real_file);
if (!desktop)
{
errmsg = "couldn't open desktop file";
goto error;
}
e_exec(zone, desktop, NULL, NULL, NULL);
efreet_desktop_free(desktop);
goto end;
}
else if ((strcmp(mime, "application/x-executable") == 0) ||
ecore_file_can_exec(param_file))
{
e_exec(zone, NULL, param_file, NULL, NULL);
goto end;
}
else if (_mime_shell_script_check(mime))
{
Eina_Strbuf *b = eina_strbuf_new();
const char *shell = getenv("SHELL");
if (!shell)
{
uid_t uid = getuid();
struct passwd *pw = getpwuid(uid);
if (pw) shell = pw->pw_shell;
}
if (!shell) shell = "/bin/sh";
eina_strbuf_append_printf(b, "%s %s %s",
e_config->exebuf_term_cmd,
shell,
param_file);
e_exec(zone, NULL, eina_strbuf_string_get(b), NULL, NULL);
eina_strbuf_free(b);
goto end;
}
handlers = efreet_util_desktop_mime_list(mime);
if (!handlers)
{
errmsg = "no handlers for given file";
goto end;
}
else
{
Efreet_Desktop *desktop = handlers->data;
Eina_List *files = eina_list_append(NULL, param_file);
e_exec(zone, desktop, NULL, files, NULL);
eina_list_free(files);
EINA_LIST_FREE(handlers, desktop)
efreet_desktop_free(desktop);
}
end:
free(real_file);
free(to_free);
2013-04-23 08:08:29 -07:00
return eldbus_message_method_return_new(msg);
error:
free(real_file);
free(to_free);
return _e_fileman_dbus_daemon_error(msg, errmsg);
}
static E_Fileman_DBus_Daemon *
_e_fileman_dbus_daemon_new(void)
{
E_Fileman_DBus_Daemon *d;
d = calloc(1, sizeof(E_Fileman_DBus_Daemon));
if (!d)
{
perror("ERROR: FILEMAN: cannot allocate fileman dbus daemon memory.");
return NULL;
}
2013-04-23 08:08:29 -07:00
d->conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
if (!d->conn)
goto error;
_e_fileman_dbus_daemon_object_init(d);
2013-04-23 08:08:29 -07:00
eldbus_name_request(d->conn, E_FILEMAN_BUS_NAME,
ELDBUS_NAME_REQUEST_FLAG_REPLACE_EXISTING, NULL, NULL);
return d;
error:
fprintf(stderr, "ERROR: FILEMAN: failed to create daemon at %p\n", d);
_e_fileman_dbus_daemon_free(d);
return NULL;
}
static E_Fileman_DBus_Daemon *_daemon = NULL;
void
e_fileman_dbus_init(void)
{
if (_daemon)
return;
2013-04-23 08:08:29 -07:00
eldbus_init();
_daemon = _e_fileman_dbus_daemon_new();
}
void
e_fileman_dbus_shutdown(void)
{
if (!_daemon)
return;
_e_fileman_dbus_daemon_free(_daemon);
_daemon = NULL;
2013-04-23 08:08:29 -07:00
eldbus_shutdown();
}