[Xfce4-commits] <xfdesktop:danielm/port-to-gio> * src/xfdesktop-regular-file-icon.c: - Dropped Jobs stuff. Implemented copy, move, link and unlink functions using Thunar D-Bus API

Jannis Pohlmann noreply at xfce.org
Sun Aug 29 21:14:12 CEST 2010


Updating branch refs/heads/danielm/port-to-gio
         to f49510794894c1cfb51b880acbe16d8be485828b (commit)
       from b2f48a1cd61f62301d78b826f26d989c3af5b786 (commit)

commit f49510794894c1cfb51b880acbe16d8be485828b
Author: Daniel Morales <daniel at daniel.com.uy>
Date:   Tue Feb 23 23:03:03 2010 -0200

    * src/xfdesktop-regular-file-icon.c:
    	- Dropped Jobs stuff. Implemented copy, move, link and unlink
    	  functions using Thunar D-Bus API
    
    * TODO.gio:
    	- Updated

 TODO.gio                          |    9 --
 src/xfdesktop-regular-file-icon.c |  256 +++++++++++++++----------------------
 2 files changed, 102 insertions(+), 163 deletions(-)

diff --git a/TODO.gio b/TODO.gio
index 39e59f1..29dba69 100644
--- a/TODO.gio
+++ b/TODO.gio
@@ -1,20 +1,11 @@
 Port to GIO/gUDEV
 ========================
 
-- src/xfdesktop-file-icon.c:
-        -xfdesktop_file_icon_activated():
 - src/xfdesktop-regular-file-icon.c:
         - xfdesktop_regular_file_icon_do_drop_dest():
 
     * We have to implement a replacement for thunar_vfs_info_execute().
 
-- src/xfdesktop-job.[ch]: Implement
-- src/xfdesktop-file-jobs.[ch]: Implement
-    * Maybe we can take a look and see how THUNAR does it :)
-
-- src/xfdesktop-regular-file-icon.c:
-    * "ask" signal to jobs (currently commented until we implement Jobs)
-
 - GCancelable {
     * Maybe we can implement an GCancelable to use on:
         - xfdesktop_regular_file_icon_new
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index a0dbe25..5767bf2 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -45,12 +45,13 @@
 
 #include <libxfce4ui/libxfce4ui.h>
 
+#include <dbus/dbus-glib-lowlevel.h>
+
 #ifdef HAVE_THUNARX
 #include <thunarx/thunarx.h>
 #endif
 
-#include "xfdesktop-job.h"
-#include "xfdesktop-file-jobs.h"
+#include "xfdesktop-dbus-bindings-filemanager.h"
 #include "xfdesktop-file-utils.h"
 #include "xfdesktop-common.h"
 #include "xfdesktop-regular-file-icon.h"
@@ -91,9 +92,6 @@ static gboolean xfdesktop_regular_file_icon_delete_file(XfdesktopFileIcon *icon)
 static void xfdesktop_regular_file_icon_tfi_init(ThunarxFileInfoIface *iface);
 #endif
 
-static void xfdesktop_delete_file_finished(XfdesktopJob *job,
-                                           gpointer user_data);
-
 static inline void xfdesktop_regular_file_icon_invalidate_pixbuf(XfdesktopRegularFileIcon *icon);
 
 
@@ -317,62 +315,6 @@ xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
         return 0;
 }
 
-static void
-xfdesktop_regular_file_icon_drag_job_error(XfdesktopJob *job,
-                                           GError *error,
-                                           gpointer user_data)
-{
-    XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(user_data);
-    XfdesktopFileIcon *src_file_icon = g_object_get_data(G_OBJECT(job),
-                                                         "--xfdesktop-src-file-icon");
-    XfdesktopFileUtilsFileop fileop = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(job),
-                                                                        "--xfdesktop-file-icon-action"));
-
-    g_return_if_fail(file_icon);
-    
-    if(!src_file_icon)
-        return;
-    
-    xfdesktop_file_utils_handle_fileop_error(NULL,
-                                             src_file_icon,
-                                             file_icon, fileop,
-                                             error);
-}
-
-#if 0
-static XfdesktopJobResponse
-xfdesktop_regular_file_icon_interactive_job_ask(XfdesktopJob *job,
-                                                const gchar *message,
-                                                XfdesktopJobResponse choices,
-                                                gpointer user_data)
-{
-    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(user_data));
-    GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view);
-    return xfdesktop_file_utils_interactive_job_ask(GTK_WINDOW(toplevel),
-                                                    message, choices);
-}
-#endif
-
-static void
-xfdesktop_regular_file_icon_drag_job_finished(XfdesktopJob *job,
-                                              gpointer user_data)
-{
-    XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(user_data);
-    XfdesktopFileIcon *src_file_icon = g_object_get_data(G_OBJECT(job),
-                                                         "--xfdesktop-src-file-icon");
-    
-    if(!xfdesktop_file_icon_remove_active_job(file_icon, job))
-        g_critical("XfdesktopJob 0x%p not found in active jobs list", job);
-    
-    if(!xfdesktop_file_icon_remove_active_job(src_file_icon, job))
-        g_critical("XfdesktopJob 0x%p not found in active jobs list", job);
-    
-    g_object_unref(G_OBJECT(job));
-    
-    g_object_unref(G_OBJECT(src_file_icon));
-    g_object_unref(G_OBJECT(file_icon));
-}
-
 static gboolean
 xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
                                          XfdesktopIcon *src_icon,
@@ -380,6 +322,7 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
 {
     XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
     XfdesktopFileIcon *src_file_icon = XFDESKTOP_FILE_ICON(src_icon);
+    GError *error = NULL;
     
     DBG("entering");
     
@@ -393,7 +336,6 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
     if(xfdesktop_file_utils_is_executable(file_icon)) {
 #if 0
         GList *path_list = g_list_prepend(NULL, src_info->path);
-        GError *error = NULL;
         gboolean succeeded;
         
         succeeded = thunar_vfs_info_execute(file_icon->priv->info,
@@ -417,10 +359,16 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
 #endif
         return TRUE;
     } else {
-        XfdesktopJob *job = NULL;
-        gchar *name;
-        GFile *dest_path;
-        
+        DBusGProxy *thunar_proxy;
+        gchar     **filenames = NULL;
+        gboolean    result = TRUE;
+        GtkWidget  *icon_view, *toplevel;
+        GdkScreen  *gscreen;
+        GFile      *dest_path;
+        gchar      *display_name;
+        gchar      *dest_uri;
+        gchar      *name;
+
         if(xfdesktop_file_utils_is_root(src_file_icon))
             return FALSE;
         
@@ -435,65 +383,71 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
         if(!dest_path)
             return FALSE;
         
+        thunar_proxy = xfdesktop_file_utils_peek_thunar_proxy();
+        
+        /* only one file, but null terminated */
+        filenames = g_new(gchar *, 2);
+        filenames[0] = g_file_get_uri(file_icon->gfile);
+        filenames[1] = NULL;
+        
+        dest_uri = g_file_get_uri(dest_path);
+
+        icon_view = xfdesktop_icon_peek_icon_view(src_icon);
+        gscreen = gtk_widget_get_screen(icon_view);
+        display_name = gdk_screen_make_display_name(gscreen);
+
         switch(action) {
             case GDK_ACTION_MOVE:
                 DBG("doing move");
-                job = xfdesktop_file_jobs_move_file(src_file_icon->gfile, dest_path);
+                result = org_xfce_Thunar_move_into(thunar_proxy,
+                                                   (const gchar **)filenames,
+                                                   dest_uri,
+                                                   display_name,
+                                                   NULL,
+                                                   &error);
                 break;
             
             case GDK_ACTION_COPY:
                 DBG("doing copy");
-                job = xfdesktop_file_jobs_copy_file(src_file_icon->gfile, dest_path);
+                result = org_xfce_Thunar_copy_into(thunar_proxy,
+                                                   (const gchar **)filenames,
+                                                   dest_uri,
+                                                   display_name,
+                                                   NULL,
+                                                   &error);
                 break;
             
             case GDK_ACTION_LINK:
                 DBG("doing link");
-                job = xfdesktop_file_jobs_link_file(src_file_icon->gfile, dest_path);
+                result = org_xfce_Thunar_link_into(thunar_proxy,
+                                                   (const gchar **)filenames,
+                                                   dest_uri,
+                                                   display_name,
+                                                   NULL,
+                                                   &error);
                 break;
             
             default:
                 g_warning("Unsupported drag action: %d", action);
         }
+
+        if(!result && (error != NULL)) {
+            toplevel = gtk_widget_get_toplevel(icon_view);
+
+            xfdesktop_file_utils_handle_fileop_error(GTK_WINDOW(toplevel),
+                                                     src_file_icon,
+                                                     file_icon, action,
+                                                     error);
+            g_error_free(error);
+        }
         
+        g_strfreev(filenames); 
+        g_free(dest_uri);
+        g_free(display_name);
         g_object_unref(dest_path);
         
-        if(job) {
-            DBG("got job, action initiated");
-            
-            /* ensure they aren't destroyed until the job is finished */
-            g_object_ref(G_OBJECT(src_file_icon));
-            g_object_ref(G_OBJECT(file_icon));
-            
-            g_object_set_data(G_OBJECT(job), "--xfdesktop-file-icon-callback",
-                              G_CALLBACK(xfdesktop_regular_file_icon_drag_job_finished));
-            g_object_set_data(G_OBJECT(job), "--xfdesktop-file-icon-data", icon);
-            xfdesktop_file_icon_add_active_job(XFDESKTOP_FILE_ICON(file_icon),
-                                               job);
-            xfdesktop_file_icon_add_active_job(src_file_icon, job);
-            
-            g_object_set_data(G_OBJECT(job), "--xfdesktop-src-file-icon",
-                              src_icon);
-            g_object_set_data(G_OBJECT(job), "--xfdesktop-file-icon-action",
-                              GINT_TO_POINTER(action == GDK_ACTION_MOVE
-                                              ? XFDESKTOP_FILE_UTILS_FILEOP_MOVE
-                                              : (action == GDK_ACTION_COPY
-                                                 ? XFDESKTOP_FILE_UTILS_FILEOP_COPY
-                                                 : XFDESKTOP_FILE_UTILS_FILEOP_LINK)));
-            g_signal_connect(G_OBJECT(job), "error",
-                             G_CALLBACK(xfdesktop_regular_file_icon_drag_job_error),
-                             file_icon);
-#if 0
-            g_signal_connect(G_OBJECT(job), "ask",
-                             G_CALLBACK(xfdesktop_regular_file_icon_interactive_job_ask),
-                             file_icon);
-#endif
-            g_signal_connect(G_OBJECT(job), "finished",
-                             G_CALLBACK(xfdesktop_regular_file_icon_drag_job_finished),
-                             file_icon);
-            
-            return TRUE;
-        } else
-            return FALSE;
+        return result;
+        
     }
     
     return FALSE;
@@ -545,64 +499,58 @@ xfdesktop_regular_file_can_delete_file(XfdesktopFileIcon *icon)
     return xfdesktop_file_utils_can_delete(icon);
 }
 
-static void
-xfdesktop_delete_file_error(XfdesktopJob *job,
-                            GError *error,
-                            gpointer user_data)
-{
-    XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(user_data);
-    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
-    GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view);
-    gchar *primary = g_markup_printf_escaped("There was an error deleting \"%s\":",
-                                             g_file_info_get_display_name(icon->info));
-                                     
-    xfce_message_dialog(GTK_WINDOW(toplevel), _("Error"),
-                        GTK_STOCK_DIALOG_ERROR, primary,
-                        error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                        NULL);
-    
-    g_free(primary);
-}
-
-static void
-xfdesktop_delete_file_finished(XfdesktopJob *job,
-                               gpointer user_data)
-{
-    XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(user_data);
-    
-    if(!xfdesktop_file_icon_remove_active_job(XFDESKTOP_FILE_ICON(icon), job))
-        g_critical("XfdesktopJob 0x%p not found in active jobs list", job);
-    
-    g_object_unref(G_OBJECT(job));
-    g_object_unref(G_OBJECT(icon));
-}
-
 static gboolean
 xfdesktop_regular_file_icon_delete_file(XfdesktopFileIcon *icon)
 {
     XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
-    XfdesktopJob *job;
+    DBusGProxy        *thunar_proxy;
+    GdkScreen         *gscreen;
+    GtkWidget         *icon_view, *toplevel;
+    gboolean           result = TRUE;
+    GError            *error = NULL;
+    gchar            **filenames = NULL;
+    gchar             *display_name;
 
     g_return_val_if_fail(G_IS_FILE(file_icon->gfile), FALSE);
+    g_return_val_if_fail(G_IS_FILE_INFO(file_icon->info), FALSE);
 
-    job = xfdesktop_file_jobs_unlink_file(file_icon->gfile);
+    thunar_proxy = xfdesktop_file_utils_peek_thunar_proxy();
 
-    if(job) {
-        g_object_set_data(G_OBJECT(job), "--xfdesktop-file-icon-callback",
-                          G_CALLBACK(xfdesktop_delete_file_finished));
-        g_object_set_data(G_OBJECT(job), "--xfdesktop-file-icon-data", icon);
-        xfdesktop_file_icon_add_active_job(file_icon, job);
-        
-        g_signal_connect(G_OBJECT(job), "error",
-                         G_CALLBACK(xfdesktop_delete_file_error), icon);
-        g_signal_connect(G_OBJECT(job), "finished",
-                         G_CALLBACK(xfdesktop_delete_file_finished), icon);
-        
-        g_object_ref(G_OBJECT(icon));
+    /* only one file, but null terminated */
+    filenames = g_new(gchar *, 2);
+    filenames[0] = g_file_get_uri(file_icon->gfile);
+    filenames[1] = NULL;
+    
+    icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
+    gscreen = gtk_widget_get_screen(icon_view);
+    display_name = gdk_screen_make_display_name(gscreen);
+
+    /* delete the file using Thunar d-bus API */
+    result = org_xfce_Thunar_unlink_files(thunar_proxy,
+                                          (const gchar **)filenames,
+                                          display_name,
+                                          NULL,
+                                          &error);
+    
+    if(!result && (error != NULL)) {
+        gchar *primary = g_markup_printf_escaped("There was an error deleting \"%s\":",
+                                                 g_file_info_get_display_name(file_icon->info));
+
+        toplevel = gtk_widget_get_toplevel(icon_view);
+
+        xfce_message_dialog(GTK_WINDOW(toplevel), _("Error"),
+                            GTK_STOCK_DIALOG_ERROR, primary,
+                            error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
+                            NULL);
+
+        g_error_free(error);
+        g_free(primary);
     }
     
-    /* no real way to signal success or failure at this point */
-    return (job != NULL);
+    g_strfreev(filenames); 
+    g_free(display_name);
+ 
+    return result;
 }
 
 static gboolean



More information about the Xfce4-commits mailing list