From c06074065460e63cf78ef1c5b7eb819fa6a86430 Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Sun, 13 Jan 2019 18:19:49 -0300 Subject: [PATCH] Add support for org.freedesktop.FileManager1 (Bug #12414) --- .gitignore | 2 +- Makefile.am | 4 +- org.freedesktop.FileManager1.service.in | 4 + thunar/Makefile.am | 6 + thunar/thunar-application.c | 28 ++- thunar/thunar-dbus-freedesktop-interfaces.xml | 36 ++++ thunar/thunar-dbus-service.c | 183 +++++++++++++++++- 7 files changed, 246 insertions(+), 17 deletions(-) create mode 100644 org.freedesktop.FileManager1.service.in create mode 100644 thunar/thunar-dbus-freedesktop-interfaces.xml diff --git a/.gitignore b/.gitignore index 4a0624281..9fbb0a34c 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,7 @@ tests/data/.*.swp thunar/*.loT thunar/.*.swp thunar/thunar +thunar/thunar-dbus-freedesktop-interfaces.[ch] thunar/thunar-dbus-service-infos.[ch] thunar/thunar-fallback-icon.c thunar/thunar-thumbnail-cache-proxy.[ch] @@ -117,7 +118,6 @@ thunar/core.* thunar/*.core thunar/thunar-*-ui.h thunar/stamp-thunar-*.* -thunar/thunar-dbus-service-infos.h thunarx/.*.swp thunarx/*.pc thunarx/*.gir diff --git a/Makefile.am b/Makefile.am index 94c8f3eb4..bd2a6e96d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,7 +79,9 @@ appdata_DATA = $(appdata_in_files:.xml.in=.xml) appdata_in_files = org.xfce.thunar.appdata.xml.in servicedir = $(datadir)/dbus-1/services -service_in_files = org.xfce.FileManager.service.in org.xfce.Thunar.service.in +service_in_files = org.xfce.FileManager.service.in \ + org.xfce.Thunar.service.in \ + org.freedesktop.FileManager1.service.in service_DATA = $(service_in_files:.service.in=.service) systemd_userdir = $(prefix)/lib/systemd/user diff --git a/org.freedesktop.FileManager1.service.in b/org.freedesktop.FileManager1.service.in new file mode 100644 index 000000000..e0b3fade4 --- /dev/null +++ b/org.freedesktop.FileManager1.service.in @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.freedesktop.FileManager1 +Exec=@bindir@/Thunar --gapplication-service +SystemdService=thunar.service diff --git a/thunar/Makefile.am b/thunar/Makefile.am index cd747267e..a92ae7476 100644 --- a/thunar/Makefile.am +++ b/thunar/Makefile.am @@ -30,6 +30,8 @@ thunar_built_sources = \ thunar-shortcuts-pane-ui.h \ thunar-renamer-dialog-ui.h \ thunar-standard-view-ui.h \ + thunar-dbus-freedesktop-interfaces.h \ + thunar-dbus-freedesktop-interfaces.c \ thunar-dbus-service-infos.h \ thunar-dbus-service-infos.c \ thunar-thumbnailer-proxy.c \ @@ -289,6 +291,9 @@ DISTCLEANFILES += \ BUILT_SOURCES = \ $(thunar_built_sources) +thunar-dbus-freedesktop-interfaces.h thunar-dbus-freedesktop-interfaces.c: $(srcdir)/thunar-dbus-freedesktop-interfaces.xml Makefile + $(AM_V_GEN) gdbus-codegen --c-namespace Thunar --generate-c-code=thunar-dbus-freedesktop-interfaces $(srcdir)/thunar-dbus-freedesktop-interfaces.xml + thunar-dbus-service-infos.h thunar-dbus-service-infos.c: $(srcdir)/thunar-dbus-service-infos.xml Makefile $(AM_V_GEN) gdbus-codegen --c-namespace Thunar --generate-c-code=thunar-dbus-service-infos $(srcdir)/thunar-dbus-service-infos.xml @@ -356,6 +361,7 @@ endif EXTRA_DIST = \ thunar-abstract-icon-view-ui.xml \ + thunar-dbus-freedesktop-interfaces.xml \ thunar-dbus-service-infos.xml \ thunar-details-view-ui.xml \ thunar-launcher-ui.xml \ diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c index 71a1594c3..4e27360b7 100644 --- a/thunar/thunar-application.c +++ b/thunar/thunar-application.c @@ -208,7 +208,8 @@ struct _ThunarApplication GList *files_to_launch; - guint dbus_owner_id; + guint dbus_owner_id_xfce; + guint dbus_owner_id_fdo; }; @@ -324,14 +325,23 @@ thunar_application_dbus_init (ThunarApplication *application) if (geteuid() == 0) return; - application->dbus_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, - "org.xfce.FileManager", - G_BUS_NAME_OWNER_FLAGS_NONE, - thunar_application_dbus_acquired_cb, - thunar_application_name_acquired_cb, - thunar_application_dbus_name_lost_cb, - application, - NULL); + application->dbus_owner_id_xfce = g_bus_own_name (G_BUS_TYPE_SESSION, + "org.xfce.FileManager", + G_BUS_NAME_OWNER_FLAGS_NONE, + thunar_application_dbus_acquired_cb, + thunar_application_name_acquired_cb, + thunar_application_dbus_name_lost_cb, + application, + NULL); + + application->dbus_owner_id_fdo = g_bus_own_name (G_BUS_TYPE_SESSION, + "org.freedesktop.FileManager1", + G_BUS_NAME_OWNER_FLAGS_NONE, + thunar_application_dbus_acquired_cb, + thunar_application_name_acquired_cb, + thunar_application_dbus_name_lost_cb, + application, + NULL); } diff --git a/thunar/thunar-dbus-freedesktop-interfaces.xml b/thunar/thunar-dbus-freedesktop-interfaces.xml new file mode 100644 index 000000000..598afb7bc --- /dev/null +++ b/thunar/thunar-dbus-freedesktop-interfaces.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c index 66c104b73..2d27642dd 100644 --- a/thunar/thunar-dbus-service.c +++ b/thunar/thunar-dbus-service.c @@ -47,6 +47,7 @@ /* include generate dbus infos */ +#include #include @@ -220,6 +221,21 @@ static gboolean thunar_dbus_service_terminate (ThunarDBusThuna GDBusMethodInvocation *invocation, ThunarDBusService *dbus_service); +static gboolean thunar_dbus_freedesktop_show_folders (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service); +static gboolean thunar_dbus_freedesktop_show_items (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service); +static gboolean thunar_dbus_freedesktop_show_item_properties (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service); struct _ThunarDBusServiceClass @@ -231,9 +247,10 @@ struct _ThunarDBusService { GObject __parent__; - ThunarDBusFileManager *file_manager; - ThunarDBusTrash *trash; - ThunarDBusThunar *thunar; + ThunarDBusFileManager *file_manager; + ThunarDBusTrash *trash; + ThunarDBusThunar *thunar; + ThunarOrgFreedesktopFileManager1 *file_manager_fdo; ThunarFile *trash_bin; }; @@ -281,9 +298,10 @@ static void connect_signals_multiple (gpointer object, static void thunar_dbus_service_init (ThunarDBusService *dbus_service) { - dbus_service->file_manager = thunar_dbus_file_manager_skeleton_new (); - dbus_service->trash = thunar_dbus_trash_skeleton_new (); - dbus_service->thunar = thunar_dbus_thunar_skeleton_new (); + dbus_service->file_manager = thunar_dbus_file_manager_skeleton_new (); + dbus_service->trash = thunar_dbus_trash_skeleton_new (); + dbus_service->thunar = thunar_dbus_thunar_skeleton_new (); + dbus_service->file_manager_fdo = thunar_org_freedesktop_file_manager1_skeleton_new (); connect_signals_multiple (dbus_service->file_manager, dbus_service, "handle-display-chooser-dialog", thunar_dbus_service_display_chooser_dialog, @@ -315,6 +333,12 @@ thunar_dbus_service_init (ThunarDBusService *dbus_service) "handle-bulk-rename", thunar_dbus_service_bulk_rename, "handle-terminate", thunar_dbus_service_terminate, NULL); + + connect_signals_multiple (dbus_service->file_manager_fdo, dbus_service, + "handle-show-folders", thunar_dbus_freedesktop_show_folders, + "handle-show-items", thunar_dbus_freedesktop_show_items, + "handle-show-item-properties", thunar_dbus_freedesktop_show_item_properties, + NULL); } @@ -327,6 +351,7 @@ thunar_dbus_service_finalize (GObject *object) g_object_unref (dbus_service->file_manager); g_object_unref (dbus_service->trash); g_object_unref (dbus_service->thunar); + g_object_unref (dbus_service->file_manager_fdo); if (dbus_service->trash_bin) g_object_unref (dbus_service->trash_bin); @@ -1475,6 +1500,145 @@ thunar_dbus_service_terminate (ThunarDBusThunar *object, +static gboolean +thunar_dbus_freedesktop_show_folders (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service) +{ + ThunarApplication *application; + GdkScreen *screen; + gint n; + GFile *file; + ThunarFile *thunar_file; + + screen = gdk_screen_get_default (); + application = thunar_application_get (); + + for (n = 0; uris[n] != NULL; ++n) + { + file = g_file_new_for_uri (uris[n]); + thunar_file = thunar_file_get (file, NULL); + + g_object_unref (G_OBJECT (file)); + if (thunar_file == NULL) + continue; + + if (thunar_file_is_directory (thunar_file)) + thunar_application_open_window (application, thunar_file, screen, + startup_id, FALSE); + + g_object_unref (G_OBJECT (thunar_file)); + } + + g_object_unref (G_OBJECT (application)); + + thunar_org_freedesktop_file_manager1_complete_show_folders (object, invocation); + + return TRUE; +} + + + +static gboolean +thunar_dbus_freedesktop_show_items (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service) +{ + ThunarApplication *application; + GtkWidget *window; + GdkScreen *screen; + gint n; + GFile *file; + ThunarFile *thunar_folder, *thunar_file = NULL; + + screen = gdk_screen_get_default (); + application = thunar_application_get (); + + for (n = 0; uris[n] != NULL; ++n) + { + file = g_file_new_for_uri (uris[n]); + thunar_folder = thunar_file_get (file, NULL); + + g_object_unref (G_OBJECT (file)); + if (thunar_folder == NULL) + continue; + + if (G_LIKELY (thunar_file_has_parent (thunar_folder))) + { + thunar_file = thunar_folder; + thunar_folder = thunar_file_get_parent (thunar_folder, NULL); + } + + window = thunar_application_open_window (application, thunar_folder, + screen, startup_id, FALSE); + + if (G_LIKELY (thunar_file != NULL)) + { + thunar_window_scroll_to_file (THUNAR_WINDOW (window), thunar_file, + TRUE, TRUE, 0.5f, 0.5f); + g_object_unref (G_OBJECT (thunar_file)); + } + + g_object_unref (G_OBJECT (thunar_folder)); + } + + g_object_unref (G_OBJECT (application)); + + thunar_org_freedesktop_file_manager1_complete_show_items (object, invocation); + return TRUE; +} + + + +static gboolean +thunar_dbus_freedesktop_show_item_properties (ThunarOrgFreedesktopFileManager1 *object, + GDBusMethodInvocation *invocation, + gchar **uris, + const gchar *startup_id, + ThunarDBusService *dbus_service) +{ + ThunarApplication *application; + GdkScreen *screen; + gint n; + GFile *file; + GtkWidget *dialog; + ThunarFile *thunar_file; + + screen = gdk_screen_get_default (); + application = thunar_application_get (); + + for (n = 0; uris[n] != NULL; ++n) + { + file = g_file_new_for_uri (uris[n]); + thunar_file = thunar_file_get (file, NULL); + + g_object_unref (G_OBJECT (file)); + if (thunar_file == NULL) + continue; + + dialog = thunar_properties_dialog_new (NULL); + gtk_window_set_screen (GTK_WINDOW (dialog), screen); + gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id); + thunar_properties_dialog_set_file (THUNAR_PROPERTIES_DIALOG (dialog), + thunar_file); + gtk_window_present (GTK_WINDOW (dialog)); + thunar_application_take_window (application, GTK_WINDOW (dialog)); + + g_object_unref (G_OBJECT (thunar_file)); + } + + g_object_unref (G_OBJECT (application)); + + thunar_org_freedesktop_file_manager1_complete_show_item_properties (object, invocation); + return TRUE; +} + + + gboolean thunar_dbus_service_export_on_connection (ThunarDBusService *service, GDBusConnection *connection, GError **error) @@ -1497,6 +1661,12 @@ gboolean thunar_dbus_service_export_on_connection (ThunarDBusService *service, error)) goto fail; + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (service->file_manager_fdo), + connection, + "/org/freedesktop/FileManager1", + error)) + goto fail; + return TRUE; fail: @@ -1504,5 +1674,6 @@ gboolean thunar_dbus_service_export_on_connection (ThunarDBusService *service, g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (service->file_manager), connection); g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (service->trash), connection); g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (service->thunar), connection); + g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (service->file_manager_fdo), connection); return FALSE; }