diff options
author | Brian Tarricone <brian@tarricone.org> | 2006-08-23 23:22:38 +0000 |
---|---|---|
committer | Brian Tarricone <brian@tarricone.org> | 2006-08-23 23:22:38 +0000 |
commit | 196233b063e83be7eb926f1d18fac10d0b9396e2 (patch) | |
tree | 0deeb0299a870e7c2e8c46712758b89a1b5a2769 | |
parent | 81b8e61665bd3878900272d636f2beea4bf2daae (diff) | |
download | xfdesktop-196233b063e83be7eb926f1d18fac10d0b9396e2.tar.gz |
* add dep on dbus >= 0.34 if thunar-vfs is enabled
* use DBusGProxy for trash-related functions
(Old svn revision: 22862)
-rw-r--r-- | configure.ac.in | 5 | ||||
-rw-r--r-- | src/Makefile.am | 30 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/xfdesktop-dbus-bindings-filemanager.xml | 100 | ||||
-rw-r--r-- | src/xfdesktop-dbus-bindings-trash.xml | 99 | ||||
-rw-r--r-- | src/xfdesktop-special-file-icon.c | 191 |
6 files changed, 385 insertions, 45 deletions
diff --git a/configure.ac.in b/configure.ac.in index 401dfa1e..f3924f89 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -56,6 +56,11 @@ XDT_CHECK_OPTIONAL_PACKAGE([THUNAR_VFS], [thunar-vfs-1], [0.3.2], [thunar-vfs], [Disable the use Thunar's VFS layer to show the desktop folder (default=enabled)])) AM_CONDITIONAL([HAVE_THUNAR_VFS], [test "x$THUNAR_VFS_FOUND" = "xyes"]) +dnl file icons requires dbus as well +if test "x$THUNAR_VFS_FOUND" = "xyes"; then + XDT_CHECK_PACKAGE([DBUS], [dbus-glib-1], [0.34]) +fi + XDT_CHECK_OPTIONAL_PACKAGE([THUNARX], [thunarx-1], [0.3.2], [thunarx], AC_HELP_STRING([--disable-thunarx], [Disable the use of Thunar's extension mechanism to add external features to the desktop icon implementation (default=enabled)])) diff --git a/src/Makefile.am b/src/Makefile.am index f3d6963e..6cdd90b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,8 @@ desktop_icon_sources = \ desktop_file_icon_sources = \ xfdesktop-clipboard-manager.c \ xfdesktop-clipboard-manager.h \ + xfdesktop-dbus-bindings-filemanager.h \ + xfdesktop-dbus-bindings-trash.h \ xfdesktop-file-icon.c \ xfdesktop-file-icon.h \ xfdesktop-file-icon-manager.c \ @@ -54,7 +56,6 @@ xfdesktop_CFLAGS = \ -DDATADIR=\"$(datadir)\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ -DXFCEMODDIR=\"$(libdir)/xfce4/modules\" \ - -DEXO_API_SUBJECT_TO_CHANGE \ $(LIBX11_CFLAGS) \ $(GMODULE_CFLAGS) \ $(LIBXFCEGUI4_CFLAGS) \ @@ -83,14 +84,37 @@ if HAVE_THUNAR_VFS endif xfdesktop_CFLAGS += \ + -DEXO_API_SUBJECT_TO_CHANGE \ + -DDBUS_API_SUBJECT_TO_CHANGE \ $(LIBEXO_CFLAGS) \ $(THUNAR_VFS_CFLAGS) \ - $(THUNARX_CFLAGS) + $(THUNARX_CFLAGS) \ + $(DBUS_CFLAGS) xfdesktop_LDADD += \ $(LIBEXO_LIBS) \ $(THUNAR_VFS_LIBS) \ - $(THUNARX_LIBS) + $(THUNARX_LIBS) \ + $(DBUS_LIBS) + +if HAVE_THUNAR_VFS +if MAINTAINER_MODE + +BUILT_SOURCES = \ + xfdesktop-dbus-bindings-filemanager.h \ + xfdesktop-dbus-bindings-trash.h +DISTCLEANFILES = \ + xfdesktop-dbus-bindings-filemanager.h \ + xfdesktop-dbus-bindings-trash.h + +xfdesktop-dbus-bindings-filemanager.h: $(srcdir)/xfdesktop-dbus-bindings-filemanager.xml Makefile + dbus-binding-tool --mode=glib-client $(srcdir)/xfdesktop-dbus-bindings-filemanager.xml > xfdesktop-dbus-bindings-filemanager.h + +xfdesktop-dbus-bindings-trash.h: $(srcdir)/xfdesktop-dbus-bindings-trash.xml Makefile + dbus-binding-tool --mode=glib-client $(srcdir)/xfdesktop-dbus-bindings-trash.xml > xfdesktop-dbus-bindings-trash.h + +endif +endif endif @@ -49,6 +49,10 @@ #include <libxfce4mcs/mcs-client.h> #include <libxfcegui4/libxfcegui4.h> +#ifdef HAVE_THUNAR_VFS +#include <dbus/dbus-glib.h> +#endif + #include "main.h" #include "xfdesktop-common.h" #include "xfce-backdrop.h" @@ -243,6 +247,7 @@ main(int argc, char **argv) #if defined(ENABLE_DESKTOP_ICONS) && defined(HAVE_THUNAR_VFS) g_thread_init(NULL); + dbus_g_thread_init(); #endif gtk_init(&argc, &argv); diff --git a/src/xfdesktop-dbus-bindings-filemanager.xml b/src/xfdesktop-dbus-bindings-filemanager.xml new file mode 100644 index 00000000..b76fa743 --- /dev/null +++ b/src/xfdesktop-dbus-bindings-filemanager.xml @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + $Id: thunar-dbus-service-infos.xml 22583 2006-07-30 22:49:35Z benny $ + + Copyright (c) 2006 Benedikt Meurer <benny@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 +--> + +<!-- + NB: modified by Brian Tarricone <bjt23@cornell.edu> to remove methods + that xfdesktop does not use. This means that this file does not + necessarily define the full org.xfce.FileManager interface and should + not be used as a reference for implementation. +--> + +<node name="/org/xfce/FileManager"> + <!-- + org.xfce.FileManager + + The generic Xfce File Manager interface, implemented by all Xfce + File Managers. + --> + <interface name="org.xfce.FileManager"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="thunar_dbus_service" /> + + <!-- + DisplayChooserDialog (uri : STRING, open : BOOLEAN, display : STRING) : VOID + + uri : either a file:-URI or an absolute path. + open : TRUE to let the user open the file identified by the + uri after choosing an application, FALSE to only update + the mime database. + display : the screen on which to display the chooser dialog or + "" to use the default screen of the file manager. + + Displays the chooser dialog, which lets the user select an application + to handle the file identified by the uri (and all other files of the + same mime type). If open is TRUE the user will also be able to open + the file after choosing an application. + --> + <method name="DisplayChooserDialog"> + <arg direction="in" name="uri" type="s" /> + <arg direction="in" name="open" type="b" /> + <arg direction="in" name="display" type="s" /> + </method> + + + <!-- + DisplayFolder (uri : STRING, display : STRING) : VOID + + uri : either a file:-URI or an absolute path. + display : the screen on which to display the folder or "" + to use the default screen of the file manager. + --> + <method name="DisplayFolder"> + <arg direction="in" name="uri" type="s" /> + <arg direction="in" name="display" type="s" /> + </method> + + + <!-- + DisplayFileProperties (uri : STRING, display : STRING) : VOID + + uri : either a file:-URI or an absolute path. + display : the screen on which to display the file properties + or "" to use the default screen of the file manager. + --> + <method name="DisplayFileProperties"> + <arg direction="in" name="uri" type="s" /> + <arg direction="in" name="display" type="s" /> + </method> + + + <!-- + Launch (uri : STRING, display : STRING) : VOID + + uri : either a file:-URI or an absolute path. + display : the screen on which to launch the file or "" + to use the default screen of the file manager. + --> + <method name="Launch"> + <arg direction="in" name="uri" type="s" /> + <arg direction="in" name="display" type="s" /> + </method> + </interface> +</node> diff --git a/src/xfdesktop-dbus-bindings-trash.xml b/src/xfdesktop-dbus-bindings-trash.xml new file mode 100644 index 00000000..589cf699 --- /dev/null +++ b/src/xfdesktop-dbus-bindings-trash.xml @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + $Id: thunar-dbus-service-infos.xml 22583 2006-07-30 22:49:35Z benny $ + + Copyright (c) 2006 Benedikt Meurer <benny@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/xfce/FileManager"> + <!-- + org.xfce.Trash + + The generic Xfce Trash Bin interface, implemented by all Xfce File + Managers that support a trash bin. + --> + <interface name="org.xfce.Trash"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="thunar_dbus_service" /> + + <!-- + DisplayTrash (display : STRING) : VOID + + display : the screen on which to display the trash folder + contents or "" to use the default screen of the + file manager. + + Opens a new file manager window showing the trash folder + contents. + --> + <method name="DisplayTrash"> + <arg direction="in" name="display" type="s" /> + </method> + + <!-- + EmptyTrash (display : STRING) : VOID + + display : the screen on which to display the confirmation of + the operation and the progress status or "" to use + the default screen of the file manager. + + Tells the file manager to empty the trash bin. + --> + <method name="EmptyTrash"> + <arg direction="in" name="display" type="s" /> + </method> + + <!-- + MoveToTrash (uris : ARRAY OF STRING, display : STRING) : VOID + + filenames : an array of file:-URIs or absolute paths for the files + that should be moved to the trash can. + display : the screen on which to display the progress dialog + and possible error messages and confirmation dialogs + or "" to use the default screen of the file manager. + + Tells the file manager to move all files specified by the filenames + to the trash bin. + --> + <method name="MoveToTrash"> + <arg direction="in" name="filenames" type="as" /> + <arg direction="in" name="display" type="s" /> + </method> + + <!-- + QueryTrash () : BOOLEAN + + Determines whether the trash bin contains atleast one + item. + + Returns: TRUE if the trash bin is not empty, FALSE otherwise. + --> + <method name="QueryTrash"> + <arg direction="out" name="full" type="b" /> + </method> + + <!-- + TrashChanged (full : BOOLEAN) + + full : TRUE if the trash now contains atleast one item. + + This signal is emitted by the file manager whenever the state + of the trash bin changes. + --> + <signal name="TrashChanged" /> + </interface> +</node> diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c index c64c0de6..249af4bf 100644 --- a/src/xfdesktop-special-file-icon.c +++ b/src/xfdesktop-special-file-icon.c @@ -43,11 +43,14 @@ #ifdef HAVE_THUNARX #include <thunarx/thunarx.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-lowlevel.h> #endif #include "xfdesktop-file-utils.h" #include "xfdesktop-icon.h" #include "xfdesktop-file-icon.h" +#include "xfdesktop-dbus-bindings-trash.h" #include "xfdesktop-special-file-icon.h" struct _XfdesktopSpecialFileIconPrivate @@ -58,6 +61,10 @@ struct _XfdesktopSpecialFileIconPrivate gint cur_pix_size; ThunarVfsInfo *info; GdkScreen *gscreen; + + /* only needed for trash */ + DBusGProxy *dbus_proxy; + gboolean trash_full; }; static void xfdesktop_special_file_icon_finalize(GObject *obj); @@ -415,32 +422,68 @@ xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon) } static void +xfdesktop_special_file_icon_trash_handle_error(GdkScreen *gscreen, + const gchar *method, + const gchar *message) +{ + GtkWidget *dlg = xfce_message_dialog_new(NULL, _("Trash Error"), + GTK_STOCK_DIALOG_WARNING, + _("Unable to contact the Xfce Trash service."), + _("Make sure you have a file manager installed that supports the Xfce Trash service, such as Thunar."), + GTK_STOCK_CLOSE, + GTK_RESPONSE_ACCEPT, NULL); + gtk_window_set_screen(GTK_WINDOW(dlg), gscreen); + gtk_dialog_run(GTK_DIALOG(dlg)); + gtk_widget_destroy(dlg); + + g_warning("org.xfce.Trash.%s failed: %s", method ? method : "??", + message ? message : "??"); +} + +static void +xfdesktop_special_file_icon_trash_open_cb(DBusGProxy *proxy, + GError *error, + gpointer user_data) +{ + if(error) { + xfdesktop_special_file_icon_trash_handle_error(GDK_SCREEN(user_data), + "DisplayTrash", + error->message); + } +} + +static void +xfdesktop_special_file_icon_trash_empty_cb(DBusGProxy *proxy, + GError *error, + gpointer user_data) +{ + if(error) { + xfdesktop_special_file_icon_trash_handle_error(GDK_SCREEN(user_data), + "EmptyTrash", + error->message); + } +} + +static void xfdesktop_special_file_icon_trash_open(GtkWidget *w, gpointer user_data) { XfdesktopSpecialFileIcon *file_icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data); - gchar *display_name, *commandline; - gint status = 0; - gboolean ret; - - display_name = gdk_screen_make_display_name(file_icon->priv->gscreen); - commandline = g_strdup_printf("dbus-send --print-reply --dest=org.xfce.FileManager " - "/org/xfce/FileManager org.xfce.Trash.DisplayTrash " - "string:\"%s\"", display_name); - - ret = (g_spawn_command_line_sync(commandline, NULL, NULL, &status, NULL) - && status == 0); - - if(!ret) { - xfce_message_dialog(NULL, _("Launch Error"), GTK_STOCK_DIALOG_ERROR, - _("Unable to open the trash."), - _("Viewing the contents of the trash requires a file manager that supports the Xfce trash service, such as Thunar."), - GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); + if(G_LIKELY(file_icon->priv->dbus_proxy)) { + gchar *display_name = gdk_screen_make_display_name(file_icon->priv->gscreen); + + if(!org_xfce_Trash_display_trash_async(file_icon->priv->dbus_proxy, + display_name, + xfdesktop_special_file_icon_trash_open_cb, + file_icon->priv->gscreen)) + { + xfdesktop_special_file_icon_trash_handle_error(file_icon->priv->gscreen, + "DisplayTrash", + NULL); + } + g_free(display_name); } - - g_free(display_name); - g_free(commandline); } static void @@ -448,28 +491,21 @@ xfdesktop_special_file_icon_trash_empty(GtkWidget *w, gpointer user_data) { XfdesktopSpecialFileIcon *file_icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data); - gchar *display_name, *commandline; - gint status = 0; - gboolean ret; - - display_name = gdk_screen_make_display_name(file_icon->priv->gscreen); - commandline = g_strdup_printf("dbus-send --print-reply --dest=org.xfce.FileManager " - "/org/xfce/FileManager org.xfce.Trash.EmptyTrash " - "string:\"%s\"", display_name); - - ret = (g_spawn_command_line_sync(commandline, NULL, NULL, &status, NULL) - && status == 0); - - if(!ret) { - xfce_message_dialog(NULL, _("Launch Error"), GTK_STOCK_DIALOG_ERROR, - _("Unable to empty the trash."), - _("Emptying the trash requires a file manager that supports the Xfce trash service, such as Thunar."), - GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); + if(G_LIKELY(file_icon->priv->dbus_proxy)) { + gchar *display_name = gdk_screen_make_display_name(file_icon->priv->gscreen); + + if(!org_xfce_Trash_empty_trash_async(file_icon->priv->dbus_proxy, + display_name, + xfdesktop_special_file_icon_trash_empty_cb, + file_icon->priv->gscreen)) + { + xfdesktop_special_file_icon_trash_handle_error(file_icon->priv->gscreen, + "EmptyTrash", + NULL); + } + g_free(display_name); } - - g_free(display_name); - g_free(commandline); } static GtkWidget * @@ -499,8 +535,12 @@ xfdesktop_special_file_icon_get_popup_menu(XfdesktopIcon *icon) mi = gtk_image_menu_item_new_with_mnemonic(_("_Empty Trash")); gtk_widget_show(mi); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); - g_signal_connect(G_OBJECT(mi), "activate", - G_CALLBACK(xfdesktop_special_file_icon_trash_empty), icon); + if(special_file_icon->priv->trash_full) { + g_signal_connect(G_OBJECT(mi), "activate", + G_CALLBACK(xfdesktop_special_file_icon_trash_empty), + icon); + } else + gtk_widget_set_sensitive(mi, FALSE); return menu; } @@ -514,6 +554,32 @@ xfdesktop_special_file_icon_peek_info(XfdesktopFileIcon *icon) } +static void +xfdesktop_special_file_icon_trash_changed_cb(DBusGProxy *proxy, + gboolean trash_full, + gpointer user_data) +{ + XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data); + TRACE("entering (%p, %d, %p)", proxy, trash_full, user_data); + special_file_icon->priv->trash_full = trash_full; +} + +static void +xfdesktop_special_file_icon_query_trash_cb(DBusGProxy *proxy, + gboolean trash_full, + GError *error, + gpointer user_data) +{ + XfdesktopSpecialFileIcon *icon = XFDESKTOP_SPECIAL_FILE_ICON(user_data); + + if(error) { + xfdesktop_special_file_icon_trash_handle_error(icon->priv->gscreen, + "QueryTrash", + error->message); + } else + icon->priv->trash_full = trash_full; +} + /* public API */ @@ -551,6 +617,47 @@ xfdesktop_special_file_icon_new(XfdesktopSpecialFileIconType type, return NULL; } + if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == type) { + DBusGConnection *dgconn = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + + if(G_LIKELY(dgconn)) { + /* dbus's default is brain-dead */ + DBusConnection *dconn = dbus_g_connection_get_connection(dgconn); + dbus_connection_set_exit_on_disconnect(dconn, FALSE); + + special_file_icon->priv->dbus_proxy = dbus_g_proxy_new_for_name(dgconn, + "org.xfce.FileManager", + "/org/xfce/FileManager", + "org.xfce.Trash"); + + dbus_g_proxy_add_signal(special_file_icon->priv->dbus_proxy, + "TrashChanged", G_TYPE_BOOLEAN, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal(special_file_icon->priv->dbus_proxy, + "TrashChanged", + G_CALLBACK(xfdesktop_special_file_icon_trash_changed_cb), + special_file_icon, NULL); + + if(!org_xfce_Trash_query_trash_async(special_file_icon->priv->dbus_proxy, + xfdesktop_special_file_icon_query_trash_cb, + special_file_icon)) + { + xfdesktop_special_file_icon_trash_handle_error(special_file_icon->priv->gscreen, + "QueryTrash", + NULL); + } + + /* the DBusGProxy (actually, its associated DBusGProxyManager) holds + * a reference to the DBusGConnection during its lifetime, so we + * don't have to hold a ref. */ + dbus_g_connection_unref(dgconn); + } else { + /* we might as well just bail here */ + g_object_unref(G_OBJECT(special_file_icon)); + return NULL; + } + } + g_signal_connect_swapped(G_OBJECT(gtk_icon_theme_get_for_screen(screen)), "changed", G_CALLBACK(xfdesktop_special_file_icon_invalidate_pixbuf), |