[Xfce4-commits] <xfdesktop:master> Port xfdesktop_file_icon_menu_rename() to GIO. Use Thunar's D-Bus API.

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


Updating branch refs/heads/master
         to deee7fdba7c7bafad6f37bfce253f6fe17dab6e3 (commit)
       from 4f6cfd96879543e666df4d9e2ac46b8fff5f1445 (commit)

commit deee7fdba7c7bafad6f37bfce253f6fe17dab6e3
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Oct 18 14:19:13 2010 +0200

    Port xfdesktop_file_icon_menu_rename() to GIO. Use Thunar's D-Bus API.
    
    As a wrapper for the D-Bus call, a new method called
    xfdesktop_file_utils_rename_file() has been added which asynchronously
    calls the Thunar service.

 src/xfdesktop-file-icon-manager.c   |   40 +++-------------------
 src/xfdesktop-file-manager-dbus.xml |   15 ++++++++
 src/xfdesktop-file-utils.c          |   62 +++++++++++++++++++++++++++++++++++
 src/xfdesktop-file-utils.h          |    3 ++
 4 files changed, 86 insertions(+), 34 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 5c8c3c3..7b062c8 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -610,47 +610,19 @@ xfdesktop_file_icon_menu_rename(GtkWidget *widget,
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
     XfdesktopFileIcon *icon;
     GList *selected;
-    const ThunarVfsInfo *info;
-    GtkWidget *dlg, *entry = NULL, *toplevel;
-    GdkPixbuf *pix;
-    gchar *title;
-    gint w, h;
+    GFile *file;
+    GtkWidget *toplevel;
     
     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);
-    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
-    info = xfdesktop_file_icon_peek_info(icon);
-    
-    /* make sure the icon doesn't get destroyed while the dialog is open */
-    g_object_ref(G_OBJECT(icon));
-    
-    title = g_strdup_printf(_("Rename \"%s\""), info->display_name);
-    gtk_icon_size_lookup(GTK_ICON_SIZE_DIALOG, &w, &h);
-    pix = xfdesktop_icon_peek_pixbuf(XFDESKTOP_ICON(icon), w);
-    
-    dlg = xfdesktop_file_icon_create_entry_dialog(title,
-                                                  GTK_WINDOW(toplevel),
-                                                  pix,
-                                                  _("Enter the new name:"),
-                                                  info->display_name,
-                                                  _("Rename"),
-                                                  &entry);
-    g_free(title);
-    
-    if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dlg))) {
-        gchar *new_name;
-        
-        new_name = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
-        xfdesktop_file_icon_rename_file(icon, new_name);
-        
-        g_free(new_name);
-    }
+    file = xfdesktop_file_icon_peek_file(icon);
+    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
-    gtk_widget_destroy(dlg);
-    g_object_unref(G_OBJECT(icon));
+    xfdesktop_file_utils_rename_file(file, fmanager->priv->gscreen, 
+                                     GTK_WINDOW(toplevel));
 }
 
 enum
diff --git a/src/xfdesktop-file-manager-dbus.xml b/src/xfdesktop-file-manager-dbus.xml
index 76b00b4..349b49e 100644
--- a/src/xfdesktop-file-manager-dbus.xml
+++ b/src/xfdesktop-file-manager-dbus.xml
@@ -271,6 +271,21 @@
       <arg direction="in" name="display" type="s" />
       <arg direction="in" name="startup_id" type="s" />
     </method>
+
+    <!--
+      RenameFile (uri : STRING, display : STRING, startup_id : STRING) : VOID
+
+      uri        : a URI to rename. This may be either a file:-URI or an absolute path.
+      display    : the screen on which to launch the filenames or ""
+                   to use the default screen of the file manager.
+      startup_id : the DESKTOP_STARTUP_ID environment variable for properly
+                   handling startup notification and focus stealing.
+    -->
+    <method name="RenameFile">
+      <arg direction="in" name="filename" type="s" />
+      <arg direction="in" name="display" type="s" />
+      <arg direction="in" name="startup_id" type="s" />
+    </method>
   </interface>
 </node>
 
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index f08437d..924350f 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -469,6 +469,68 @@ xfdesktop_file_utils_open_folder(GFile *file,
     }
 }
 
+static void
+xfdesktop_file_utils_rename_file_cb(DBusGProxy *proxy,
+                                    GError *error,
+                                    gpointer user_data)
+{
+    GtkWindow *parent = user_data;
+
+    if(error) {
+        xfce_message_dialog(parent,
+                            _("Rename Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The file could not be renamed"),
+                            _("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_rename_file(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_rename_file_async(fileman_proxy,
+                                                           uri, display_name, startup_id,
+                                                           xfdesktop_file_utils_rename_file_cb,
+                                                           parent))
+        {
+            xfce_message_dialog(parent,
+                                _("Rename Error"), GTK_STOCK_DIALOG_ERROR,
+                                _("The file could not be renamed"),
+                                _("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,
+                            _("Rename Error"), GTK_STOCK_DIALOG_ERROR,
+                            _("The file could not be renamed"),
+                            _("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 beb7cdd..f8ca209 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -80,6 +80,9 @@ gboolean xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
 void xfdesktop_file_utils_open_folder(GFile *file,
                                       GdkScreen *screen,
                                       GtkWindow *parent);
+void xfdesktop_file_utils_rename_file(GFile *file,
+                                      GdkScreen *screen,
+                                      GtkWindow *parent);
 
 
 gboolean xfdesktop_file_utils_dbus_init(void);



More information about the Xfce4-commits mailing list