[Xfce4-commits] <xfdesktop:master> Use async functions when working with the dbus filemanager (9105)

Eric Koegel noreply at xfce.org
Tue Aug 27 02:42:01 CEST 2013


Updating branch refs/heads/master
         to 7dd08719051b5adff0ac4af483d94bf153e6d921 (commit)
       from 30ef6b2772c76899b3580e99ed754a8c5f18ca1c (commit)

commit 7dd08719051b5adff0ac4af483d94bf153e6d921
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Aug 26 20:27:57 2013 +0300

    Use async functions when working with the dbus filemanager (9105)
    
    This fixes the context menu not getting hidden when doing a rename,
    additionally it removes some redundant code and hopefully makes some
    operations a bit faster since it doesn't wait on it to complete.

 src/xfdesktop-file-utils.c |  186 ++++++++++++++------------------------------
 1 file changed, 60 insertions(+), 126 deletions(-)

diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index ed721d9..28e4706 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -715,6 +715,21 @@ xfdesktop_file_utils_open_folder(GFile *file,
     g_free(uri);
 }
 
+static void
+xfdesktop_file_utils_async_cb(DBusGProxy *proxy, GError *error, gpointer userdata)
+{
+    GtkWindow *parent = GTK_WINDOW(userdata);
+
+    if(error != NULL) {
+        xfce_message_dialog(parent,
+                            _("Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The requested operation could not be completed"),
+                            error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
+                            NULL);
+        g_error_free(error);
+    }
+}
+
 void
 xfdesktop_file_utils_rename_file(GFile *file,
                                  GdkScreen *screen,
@@ -730,25 +745,16 @@ xfdesktop_file_utils_rename_file(GFile *file,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *uri = g_file_get_uri(file);
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_rename_file(fileman_proxy,
-                                                     uri, display_name, startup_id,
-                                                     &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Rename Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The file could not be renamed"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_rename_file_async(fileman_proxy,
+                                                       uri, display_name, startup_id,
+                                                       (xfdesktop_file_manager_proxy_rename_file_reply)xfdesktop_file_utils_async_cb,
+                                                       parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -780,7 +786,6 @@ xfdesktop_file_utils_unlink_files(GList *files,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         guint nfiles = g_list_length(files);
         gchar **uris = g_new0(gchar *, nfiles+1);
         gchar *display_name = gdk_screen_make_display_name(screen);
@@ -795,19 +800,11 @@ xfdesktop_file_utils_unlink_files(GList *files,
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_unlink_files(fileman_proxy,
-                                                      NULL, (const gchar **)uris,
-                                                      display_name, startup_id,
-                                                      &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Delete Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The selected files could not be deleted"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_unlink_files_async(fileman_proxy,
+                                                        NULL, (const gchar **)uris,
+                                                        display_name, startup_id,
+                                                        (xfdesktop_file_manager_proxy_unlink_files_reply)xfdesktop_file_utils_async_cb,
+                                                        parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -839,7 +836,6 @@ xfdesktop_file_utils_trash_files(GList *files,
 
     trash_proxy = xfdesktop_file_utils_peek_trash_proxy();
     if(trash_proxy) {
-        GError *error = NULL;
         guint nfiles = g_list_length(files);
         gchar **uris = g_new0(gchar *, nfiles+1);
         gchar *display_name = gdk_screen_make_display_name(screen);
@@ -854,19 +850,11 @@ xfdesktop_file_utils_trash_files(GList *files,
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_trash_proxy_move_to_trash(trash_proxy,
-                                                (const gchar **)uris,
-                                                display_name, startup_id,
-                                                &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Trash Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The selected files could not be moved to the trash"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_trash_proxy_move_to_trash_async(trash_proxy,
+                                                  (const gchar **)uris,
+                                                  display_name, startup_id,
+                                                  (xfdesktop_trash_proxy_move_to_trash_reply)xfdesktop_file_utils_async_cb,
+                                                  parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -896,24 +884,15 @@ xfdesktop_file_utils_empty_trash(GdkScreen *screen,
 
     trash_proxy = xfdesktop_file_utils_peek_trash_proxy();
     if(trash_proxy) {
-        GError *error = NULL;
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_trash_proxy_empty_trash(trash_proxy,
-                                              display_name, startup_id,
-                                              &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Trash Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("Could not empty the trash"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_trash_proxy_empty_trash_async(trash_proxy,
+                                                display_name, startup_id,
+                                                (xfdesktop_trash_proxy_empty_trash_reply)xfdesktop_file_utils_async_cb,
+                                                parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -945,27 +924,18 @@ xfdesktop_file_utils_create_file(GFile *parent_folder,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *parent_directory = g_file_get_uri(parent_folder);
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_create_file(fileman_proxy,
-                                                     parent_directory,
-                                                     content_type, display_name,
-                                                     startup_id,
-                                                     &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Create File Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("Could not create a new file"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_create_file_async(fileman_proxy,
+                                                       parent_directory,
+                                                       content_type, display_name,
+                                                       startup_id,
+                                                       (xfdesktop_file_manager_proxy_create_file_reply)xfdesktop_file_utils_async_cb,
+                                                       parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -999,7 +969,6 @@ xfdesktop_file_utils_create_file_from_template(GFile *parent_folder,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *parent_directory = g_file_get_uri(parent_folder);
         gchar *template_uri = g_file_get_uri(template_file);
         gchar *display_name = gdk_screen_make_display_name(screen);
@@ -1007,21 +976,13 @@ xfdesktop_file_utils_create_file_from_template(GFile *parent_folder,
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_create_file_from_template(fileman_proxy,
-                                                                   parent_directory,
-                                                                   template_uri,
-                                                                   display_name,
-                                                                   startup_id,
-                                                                   &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Create Document Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("Could not create a new document from the template"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_create_file_from_template_async(fileman_proxy,
+                                                                     parent_directory,
+                                                                     template_uri,
+                                                                     display_name,
+                                                                     startup_id,
+                                                                     (xfdesktop_file_manager_proxy_create_file_from_template_reply)xfdesktop_file_utils_async_cb,
+                                                                     parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -1053,25 +1014,16 @@ xfdesktop_file_utils_show_properties_dialog(GFile *file,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *uri = g_file_get_uri(file);
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_display_file_properties(fileman_proxy,
-                                                                 uri, display_name, startup_id,
-                                                                 &error))
-        {
-            xfce_message_dialog(parent,
-                                _("File Properties Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The file properties dialog could not be opened"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_display_file_properties_async(fileman_proxy,
+                                                                   uri, display_name, startup_id,
+                                                                   (xfdesktop_file_manager_proxy_display_file_properties_reply)xfdesktop_file_utils_async_cb,
+                                                                   parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -1103,25 +1055,16 @@ xfdesktop_file_utils_launch(GFile *file,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *uri = g_file_get_uri(file);
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_launch(fileman_proxy,
-                                                uri, display_name, startup_id,
-                                                &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The file could not be opened"),
-                                error->message,
-                                GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_launch_async(fileman_proxy,
+                                                  uri, display_name, startup_id,
+                                                  (xfdesktop_file_manager_proxy_launch_reply)xfdesktop_file_utils_async_cb,
+                                                  parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 
@@ -1239,27 +1182,18 @@ xfdesktop_file_utils_display_chooser_dialog(GFile *file,
 
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
-        GError *error = NULL;
         gchar *uri = g_file_get_uri(file);
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
 
-        if(!xfdesktop_file_manager_proxy_display_chooser_dialog(fileman_proxy,
-                                                                uri, open,
-                                                                display_name,
-                                                                startup_id,
-                                                                &error))
-        {
-            xfce_message_dialog(parent,
-                                _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
-                                _("The application chooser could not be opened"),
-                                error->message, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
-                                NULL);
-
-            g_error_free(error);
-        }
+        xfdesktop_file_manager_proxy_display_chooser_dialog_async(fileman_proxy,
+                                                                  uri, open,
+                                                                  display_name,
+                                                                  startup_id,
+                                                                  (xfdesktop_file_manager_proxy_display_chooser_dialog_reply)xfdesktop_file_utils_async_cb,
+                                                                  parent);
 
         xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
 


More information about the Xfce4-commits mailing list