[Xfce4-commits] <xfdesktop:master> Port application chooser code to GIO and refactor it a bit.

Jannis Pohlmann noreply at xfce.org
Tue Nov 2 01:14:23 CET 2010


Updating branch refs/heads/master
         to d9d109f8806f296fe612e571461584d577250877 (commit)
       from c79ff7333fb100326b6482bd21eed18db7ed8a31 (commit)

commit d9d109f8806f296fe612e571461584d577250877
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Oct 21 21:45:10 2010 +0200

    Port application chooser code to GIO and refactor it a bit.
    
    Also, properly set the cursor to watch/normal before and after
    D-Bus method calls.

 src/xfdesktop-file-icon-manager.c |   62 +++--------------------
 src/xfdesktop-file-utils.c        |  101 +++++++++++++++++++++++++++++++++++-
 src/xfdesktop-file-utils.h        |    4 ++
 3 files changed, 110 insertions(+), 57 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 17a6057..1db9a76 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -960,73 +960,27 @@ xfdesktop_file_icon_menu_open_desktop(GtkWidget *widget,
 }
 
 static void
-xfdesktop_file_icon_manager_display_chooser_error(XfdesktopFileIconManager *fmanager)
-{
-    GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
-    
-    xfce_message_dialog(GTK_WINDOW(toplevel),
-                        _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
-                        _("The application chooser could not be opened."),
-                        _("This feature requires a file manager service to "
-                          "be present (such as the one supplied by Thunar)."),
-                        GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
-}
-
-static void
-xfdesktop_file_icon_manager_display_chooser_cb(DBusGProxy *proxy,
-                                               GError *error,
-                                               gpointer user_data)
-{
-    XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
-    GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
-    
-    xfdesktop_file_utils_set_window_cursor(GTK_WINDOW(toplevel), GDK_LEFT_PTR);
-    if(error)
-        xfdesktop_file_icon_manager_display_chooser_error(fmanager);
-}
-
-static void
 xfdesktop_file_icon_menu_other_app(GtkWidget *widget,
                                    gpointer user_data)
 {
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     XfdesktopFileIcon *icon;
+    GtkWidget *toplevel;
     GList *selected;
-    const ThunarVfsInfo *info;
-    DBusGProxy *fileman_proxy;
+    GFile *file;
     
     selected = xfdesktop_icon_view_get_selected_items(fmanager->priv->icon_view);
     g_return_if_fail(g_list_length(selected) == 1);
     icon = XFDESKTOP_FILE_ICON(selected->data);
     g_list_free(selected);
     
-    info = xfdesktop_file_icon_peek_info(icon);
-    if(!info)
-        return;
-    
-    fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
-    if(fileman_proxy) {
-        gchar *uri = thunar_vfs_path_dup_uri(info->path);
-        gchar *display_name = gdk_screen_make_display_name(fmanager->priv->gscreen);
-        gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
-        
-        if(!xfdesktop_file_manager_proxy_display_chooser_dialog_async(fileman_proxy,
-                                                                      uri, TRUE,
-                                                                      display_name, startup_id,
-                                                                      xfdesktop_file_icon_manager_display_chooser_cb,
-                                                                      fmanager))
-        {
-            xfdesktop_file_icon_manager_display_chooser_error(fmanager);
-        } else {
-            GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
-            xfdesktop_file_utils_set_window_cursor(GTK_WINDOW(toplevel),
-                                                   GDK_WATCH);
-        }
+    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
 
-        g_free(startup_id);
-        g_free(uri);
-        g_free(display_name);
-    }
+    file = xfdesktop_file_icon_peek_file(icon);
+
+    xfdesktop_file_utils_display_chooser_dialog(file, TRUE, 
+                                                fmanager->priv->gscreen, 
+                                                GTK_WINDOW(toplevel));
 }
 
 static void
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 3f60161..b3579e9 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -546,7 +546,8 @@ xfdesktop_file_utils_display_folder_cb(DBusGProxy *proxy,
 
     g_return_if_fail(GTK_IS_WINDOW(parent));
     
-    xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+    if(parent)
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
     
     if(error) {
         xfce_message_dialog(parent,
@@ -612,6 +613,9 @@ xfdesktop_file_utils_rename_file_cb(DBusGProxy *proxy,
 {
     GtkWindow *parent = user_data;
 
+    if(parent)
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+    
     if(error) {
         xfce_message_dialog(parent,
                             _("Rename Error"), GTK_STOCK_DIALOG_ERROR,
@@ -651,6 +655,9 @@ xfdesktop_file_utils_rename_file(GFile *file,
                                 _("This feature requires a file manager service to "
                                   "be present (such as the one supplied by Thunar)."),
                                 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        } else {
+            if(parent)
+              xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
         }
         
         g_free(startup_id);
@@ -673,6 +680,9 @@ xfdesktop_file_utils_create_file_cb(DBusGProxy *proxy,
 {
     GtkWindow *parent = user_data;
 
+    if(parent)
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+    
     if(error) {
         xfce_message_dialog(parent,
                             _("Create File Error"), GTK_STOCK_DIALOG_ERROR,
@@ -715,6 +725,9 @@ xfdesktop_file_utils_create_file(GFile *parent_folder,
                                 _("This feature requires a file manager service to "
                                   "be present (such as the one supplied by Thunar)."),
                                 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        } else {
+            if(parent)
+              xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
         }
         
         g_free(startup_id);
@@ -737,6 +750,9 @@ xfdesktop_file_utils_show_properties_dialog_cb(DBusGProxy *proxy,
 {
     GtkWindow *parent = user_data;
 
+    if(parent)
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+    
     if(error) {
         xfce_message_dialog(parent,
                             _("File Properties Error"), GTK_STOCK_DIALOG_ERROR,
@@ -776,6 +792,9 @@ xfdesktop_file_utils_show_properties_dialog(GFile *file,
                                 _("This feature requires a file manager service to "
                                   "be present (such as the one supplied by Thunar)."),
                                 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        } else {
+            if(parent)
+              xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
         }
         
         g_free(startup_id);
@@ -798,6 +817,9 @@ xfdesktop_file_utils_launch_cb(DBusGProxy *proxy,
 {
     GtkWindow *parent = user_data;
 
+    if(parent)
+        xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+    
     if(error) {
         xfce_message_dialog(parent,
                             _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
@@ -826,8 +848,6 @@ xfdesktop_file_utils_launch(GFile *file,
         gchar *display_name = gdk_screen_make_display_name(screen);
         gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
 
-        g_debug ("launching %s", uri);
-        
         if(!xfdesktop_file_manager_proxy_launch_async(fileman_proxy,
                                                       uri, display_name, startup_id,
                                                       xfdesktop_file_utils_launch_cb,
@@ -839,7 +859,11 @@ xfdesktop_file_utils_launch(GFile *file,
                                 _("This feature requires a file manager service to "
                                   "be present (such as the one supplied by Thunar)."),
                                 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        } else {
+            if(parent)
+              xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
         }
+
         
         g_free(startup_id);
         g_free(uri);
@@ -854,6 +878,77 @@ xfdesktop_file_utils_launch(GFile *file,
     }
 }
 
+static void
+xfdesktop_file_utils_display_chooser_dialog_cb(DBusGProxy *proxy,
+                                               GError *error,
+                                               gpointer user_data)
+{
+    GtkWindow *parent = user_data;
+
+    if(parent)
+      xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
+
+    if(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);
+    }
+}
+
+void
+xfdesktop_file_utils_display_chooser_dialog(GFile *file,
+                                            gboolean open,
+                                            GdkScreen *screen,
+                                            GtkWindow *parent)
+{
+    DBusGProxy *fileman_proxy;
+    
+    g_return_if_fail(G_IS_FILE(file));
+    g_return_if_fail(GDK_IS_SCREEN(screen) || GTK_IS_WINDOW(parent));
+    
+    if(!screen)
+        screen = gtk_widget_get_screen(GTK_WIDGET(parent));
+    
+    fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
+    if(fileman_proxy) {
+        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());
+
+        if(!xfdesktop_file_manager_proxy_display_chooser_dialog_async(fileman_proxy,
+                                                                      uri, open,
+                                                                      display_name, 
+                                                                      startup_id,
+                                                                      xfdesktop_file_utils_display_chooser_dialog_cb,
+                                                                      parent))
+        {
+            xfce_message_dialog(parent,
+                                _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("The application chooser could not be opened"),
+                                _("This feature requires a file manager service to "
+                                  "be present (such as the one supplied by Thunar)."),
+                                GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+        } else {
+            if(parent)
+              xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
+        }
+
+        
+        g_free(startup_id);
+        g_free(uri);
+        g_free(display_name);
+    } else {
+        xfce_message_dialog(parent,
+                            _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The application chooser could not be opened"),
+                            _("This feature requires a file manager service to "
+                              "be present (such as the one supplied by Thunar)."),
+                            GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+    }
+}
+
 static gint dbus_ref_cnt = 0;
 static DBusGConnection *dbus_gconn = NULL;
 static DBusGProxy *dbus_trash_proxy = NULL;
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index 5d31a5b..fc87177 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -100,6 +100,10 @@ void xfdesktop_file_utils_show_properties_dialog(GFile *file,
 void xfdesktop_file_utils_launch(GFile *file,
                                  GdkScreen *screen,
                                  GtkWindow *parent);
+void xfdesktop_file_utils_display_chooser_dialog(GFile *file,
+                                                 gboolean open,
+                                                 GdkScreen *screen,
+                                                 GtkWindow *parent);
 
 
 gboolean xfdesktop_file_utils_dbus_init(void);



More information about the Xfce4-commits mailing list