[Xfce4-commits] <xfdesktop:jannis/port-to-gio> Port xfdesktop_file_icon_menu_properties() to GIO.

Jannis Pohlmann noreply at xfce.org
Mon Oct 18 14:50:01 CEST 2010


Updating branch refs/heads/jannis/port-to-gio
         to 748d1b51513b35a44f219d7c4215615fb9c42a30 (commit)
       from d89bf53413b592695b1b4827392dec6254023f9b (commit)

commit 748d1b51513b35a44f219d7c4215615fb9c42a30
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Oct 18 14:47:46 2010 +0200

    Port xfdesktop_file_icon_menu_properties() to GIO.
    
    Use the org.xfce.FileManager proxy to display the file properties dialog
    and move the code into xfdesktop-file-utils.{c,h} in the form of a new
    function called xfdesktop_file_utils_show_properties_dialog(). Display
    an error dialog when the service is unavailable.

 src/xfdesktop-file-icon-manager.c |   52 ++++---------------------------
 src/xfdesktop-file-utils.c        |   61 +++++++++++++++++++++++++++++++++++++
 src/xfdesktop-file-utils.h        |    3 ++
 3 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 7b062c8..726e01c 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -1068,58 +1068,20 @@ xfdesktop_file_icon_menu_properties(GtkWidget *widget,
 {
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     GList *selected;
-    DBusGConnection *conn;
     XfdesktopFileIcon *icon;
-    gboolean dbus_call_ok = FALSE;
+    GtkWidget *toplevel;
+    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);
     
-    conn = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
-    if(G_LIKELY(conn)) {
-        GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(fmanager->priv->icon_view));
-        gchar *display_name = gdk_screen_make_display_name(screen);
-        DBusGProxy *proxy;
-        const ThunarVfsInfo *info;
-        gchar *uri = NULL;
-
-        proxy = dbus_g_proxy_new_for_name(conn,
-                                          "org.xfce.Thunar",
-                                          "/org/xfce/FileManager",
-                                          "org.xfce.FileManager");
-
-        info = xfdesktop_file_icon_peek_info(icon);
-        if(info && info->path)
-            uri = thunar_vfs_path_dup_uri(info->path);
-
-        if(uri) {
-            dbus_call_ok = dbus_g_proxy_call(proxy, "DisplayFileProperties",
-                                             NULL,
-                                             G_TYPE_STRING, uri,
-                                             G_TYPE_STRING, display_name,
-                                             G_TYPE_INVALID,
-                                             G_TYPE_INVALID);
-            g_free(uri);
-        }
-
-        g_object_unref(G_OBJECT(proxy));
-        dbus_g_connection_unref(conn);
-    }
-
-    if(!dbus_call_ok) {
-        GtkWidget *parent;
-        parent = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
-
-        xfdesktop_file_properties_dialog_show(GTK_WINDOW(parent), icon,
-#ifdef HAVE_THUNARX
-                                              fmanager->priv->thunarx_properties_providers
-#else
-                                              NULL
-#endif
-                                              );
-    }
+    file = xfdesktop_file_icon_peek_file(icon);
+    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
+    
+    xfdesktop_file_utils_show_properties_dialog(file, fmanager->priv->gscreen, 
+                                                GTK_WINDOW(toplevel));
 }
 
 static void
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 924350f..4672bd1 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -531,6 +531,67 @@ xfdesktop_file_utils_rename_file(GFile *file,
     }
 }
 
+static void
+xfdesktop_file_utils_show_properties_dialog_cb(DBusGProxy *proxy,
+                                               GError *error,
+                                               gpointer user_data)
+{
+    GtkWindow *parent = user_data;
+
+    if(error) {
+        xfce_message_dialog(parent,
+                            _("File Properties Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The file properties dialog 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);
+    }
+}
+
+void
+xfdesktop_file_utils_show_properties_dialog(GFile *file,
+                                            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_file_properties_async(fileman_proxy,
+                                                                       uri, display_name, startup_id,
+                                                                       xfdesktop_file_utils_show_properties_dialog_cb,
+                                                                       parent))
+        {
+            xfce_message_dialog(parent,
+                                _("File Properties Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("The file properties dialog 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(startup_id);
+        g_free(uri);
+        g_free(display_name);
+    } else {
+        xfce_message_dialog(parent,
+                            _("File Properties Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The file properties dialog 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;
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index f8ca209..71e585b 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -83,6 +83,9 @@ void xfdesktop_file_utils_open_folder(GFile *file,
 void xfdesktop_file_utils_rename_file(GFile *file,
                                       GdkScreen *screen,
                                       GtkWindow *parent);
+void xfdesktop_file_utils_show_properties_dialog(GFile *file,
+                                                 GdkScreen *screen,
+                                                 GtkWindow *parent);
 
 
 gboolean xfdesktop_file_utils_dbus_init(void);



More information about the Xfce4-commits mailing list