[Xfce4-commits] <xfdesktop:master> Port xfdesktop_file_utils_open_folder() to GIO.

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


Updating branch refs/heads/master
         to 0e69dd78810a40c63f05dbe0cf44aecb10bb58e8 (commit)
       from 38ee8e3098fbe579f56abe98f2b91ba80c9844be (commit)

commit 0e69dd78810a40c63f05dbe0cf44aecb10bb58e8
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Oct 18 12:52:00 2010 +0200

    Port xfdesktop_file_utils_open_folder() to GIO.
    
    Thunar will be so heavily important for xfdesktop that we will no longer
    implement fallbacks for when it is not present. Instead, simply display
    an error dialog to the user.

 src/xfdesktop-file-icon-manager.c |   21 ++++++------
 src/xfdesktop-file-icon.c         |    7 ++--
 src/xfdesktop-file-utils.c        |   64 +++++++++++++++++++-----------------
 src/xfdesktop-file-utils.h        |    2 +-
 4 files changed, 49 insertions(+), 45 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 079aafc..be874af 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -52,7 +52,7 @@
 #define PATH_MAX 4096
 #endif
 
-#include <glib-object.h>
+#include <gio/gio.h>
 #include <gdk/gdkkeysyms.h>
 
 #ifdef HAVE_THUNARX
@@ -942,7 +942,7 @@ xfdesktop_file_icon_menu_open_folder(GtkWidget *widget,
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     XfdesktopFileIcon *icon;
     GList *selected;
-    const ThunarVfsInfo *info;
+    GFile *file;
     GtkWidget *toplevel;
     
     selected = xfdesktop_icon_view_get_selected_items(fmanager->priv->icon_view);
@@ -950,13 +950,11 @@ xfdesktop_file_icon_menu_open_folder(GtkWidget *widget,
     icon = XFDESKTOP_FILE_ICON(selected->data);
     g_list_free(selected);
     
-    info = xfdesktop_file_icon_peek_info(icon);
-    if(!info)
-        return;
+    file = xfdesktop_file_icon_peek_file(icon);
     
     toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
-    xfdesktop_file_utils_open_folder(info, fmanager->priv->gscreen,
+    xfdesktop_file_utils_open_folder(file, fmanager->priv->gscreen,
                                      GTK_WINDOW(toplevel));
 }
 
@@ -966,16 +964,16 @@ xfdesktop_file_icon_menu_open_desktop(GtkWidget *widget,
 {
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     XfdesktopFileIcon *icon = fmanager->priv->desktop_icon;
-    const ThunarVfsInfo *info;
+    GFile *file;
     GtkWidget *toplevel;
     
-    info = xfdesktop_file_icon_peek_info(icon);
-    if(!info)
+    file = xfdesktop_file_icon_peek_file(icon);
+    if(!file)
         return;
     
     toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
-    xfdesktop_file_utils_open_folder(info, fmanager->priv->gscreen,
+    xfdesktop_file_utils_open_folder(file, fmanager->priv->gscreen,
                                      GTK_WINDOW(toplevel));
 }
 
@@ -987,7 +985,8 @@ xfdesktop_file_icon_manager_display_chooser_error(XfdesktopFileIconManager *fman
     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 present (such as that supplied by Thunar)."),
+                        _("This feature requires a file manager service to "
+                          "be present (such as the one supplied by Thunar)."),
                         GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
 }
 
diff --git a/src/xfdesktop-file-icon.c b/src/xfdesktop-file-icon.c
index d79f32c..cc01713 100644
--- a/src/xfdesktop-file-icon.c
+++ b/src/xfdesktop-file-icon.c
@@ -23,7 +23,7 @@
 #include <config.h>
 #endif
 
-#include <glib-object.h>
+#include <gio/gio.h>
 
 #include <libxfce4ui/libxfce4ui.h>
 
@@ -101,12 +101,13 @@ xfdesktop_file_icon_activated(XfdesktopIcon *icon)
 {
     XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
     const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(file_icon);
+    GFile *file = xfdesktop_file_icon_peek_file(file_icon);
     GtkWidget *icon_view, *toplevel;
     GdkScreen *gscreen;
     gboolean success = FALSE;
     
     TRACE("entering");
-    
+
     if(!info)
         return FALSE;
     
@@ -115,7 +116,7 @@ xfdesktop_file_icon_activated(XfdesktopIcon *icon)
     gscreen = gtk_widget_get_screen(icon_view);
     
     if(info->type == THUNAR_VFS_FILE_TYPE_DIRECTORY) {
-        xfdesktop_file_utils_open_folder(info, gscreen, GTK_WINDOW(toplevel));
+        xfdesktop_file_utils_open_folder(file, gscreen, GTK_WINDOW(toplevel));
         success = TRUE;
     } else {
         if(info->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE) {
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 62ef42b..f08437d 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -400,69 +400,73 @@ xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
     return ret;
 }
 
-typedef struct
-{
-    const ThunarVfsInfo *info;
-    GdkScreen *screen;
-    GtkWindow *parent;
-} XfdesktopDisplayFolderData;
-
 static void
 xfdesktop_file_utils_display_folder_cb(DBusGProxy *proxy,
                                        GError *error,
                                        gpointer user_data)
 {
-    XfdesktopDisplayFolderData *dfdata = user_data;
-    
-    g_return_if_fail(dfdata);
+    GtkWindow *parent = user_data;
+
+    g_return_if_fail(GTK_IS_WINDOW(parent));
     
-    xfdesktop_file_utils_set_window_cursor(dfdata->parent, GDK_LEFT_PTR);
+    xfdesktop_file_utils_set_window_cursor(parent, GDK_LEFT_PTR);
     
     if(error) {
-        xfdesktop_file_utils_launch_fallback(dfdata->info, dfdata->screen,
-                                             dfdata->parent);
+        xfce_message_dialog(parent,
+                            _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The folder 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);
     }
-    
-    g_free(user_data);
 }
 
 void
-xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
+xfdesktop_file_utils_open_folder(GFile *file,
                                  GdkScreen *screen,
                                  GtkWindow *parent)
 {
     DBusGProxy *fileman_proxy;
     
-    g_return_if_fail(info && (screen || parent));
+    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) {
-        XfdesktopDisplayFolderData *dfdata = g_new(XfdesktopDisplayFolderData, 1);
-        gchar *uri = thunar_vfs_path_dup_uri(info->path);
+        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());
         
-        dfdata->info = info;
-        dfdata->screen = screen;
-        dfdata->parent = parent;
         if(!xfdesktop_file_manager_proxy_display_folder_async(fileman_proxy,
                                                               uri, display_name, startup_id,
-                                                              xfdesktop_file_utils_display_folder_cb,
-                                                              dfdata))
+                                                              parent ? xfdesktop_file_utils_display_folder_cb : NULL,
+                                                              parent))
         {
-            xfdesktop_file_utils_launch_fallback(info, screen, parent);
-            g_free(dfdata);
-        } else
-            xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
+            xfce_message_dialog(parent,
+                                _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("The folder 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
-        xfdesktop_file_utils_launch_fallback(info, screen, parent);
+    } else {
+        xfce_message_dialog(parent,
+                            _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The folder 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);
+    }
 }
 
 
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index 1bb8f74..beb7cdd 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -77,7 +77,7 @@ gboolean xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
                                               GdkScreen *screen,
                                               GtkWindow *parent);
 
-void xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
+void xfdesktop_file_utils_open_folder(GFile *file,
                                       GdkScreen *screen,
                                       GtkWindow *parent);
 



More information about the Xfce4-commits mailing list