Skip to content

Commit

Permalink
Add support for org.freedesktop.FileManager1 (Bug #12414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Miranda committed Jan 13, 2019
1 parent 5e282b5 commit c060740
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions org.freedesktop.FileManager1.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.FileManager1
Exec=@bindir@/Thunar --gapplication-service
SystemdService=thunar.service
6 changes: 6 additions & 0 deletions thunar/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
28 changes: 19 additions & 9 deletions thunar/thunar-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ struct _ThunarApplication

GList *files_to_launch;

guint dbus_owner_id;
guint dbus_owner_id_xfce;
guint dbus_owner_id_fdo;
};


Expand Down Expand Up @@ -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);
}


Expand Down
36 changes: 36 additions & 0 deletions thunar/thunar-dbus-freedesktop-interfaces.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2019 Andre Miranda <andreldm@xfce.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
-->

<node name="/org/freedesktop/FileManager1">
<interface name="org.freedesktop.FileManager1">
<method name="ShowFolders">
<arg direction="in" name="URIs" type="as"/>
<arg direction="in" name="StartupId" type="s"/>
</method>
<method name="ShowItems">
<arg direction="in" name="URIs" type="as"/>
<arg direction="in" name="StartupId" type="s"/>
</method>
<method name="ShowItemProperties">
<arg direction="in" name="URIs" type="as"/>
<arg direction="in" name="StartupId" type="s"/>
</method>
</interface>
</node>
183 changes: 177 additions & 6 deletions thunar/thunar-dbus-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@


/* include generate dbus infos */
#include <thunar/thunar-dbus-freedesktop-interfaces.h>
#include <thunar/thunar-dbus-service-infos.h>


Expand Down Expand Up @@ -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
Expand All @@ -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;
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}


Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -1497,12 +1661,19 @@ 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:
/* export either all or nothing */
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;
}

0 comments on commit c060740

Please sign in to comment.