[nautilus/wip/csoriano/destktop-split2: 47/54] desktop-icon-file, file: move rename handling to subclass



commit 9c1ffe2c06a101bcc53fc0893547b98f73524637
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Mar 30 14:36:30 2016 +0200

    desktop-icon-file, file: move rename handling to subclass
    
    Now that we can override the vfuncs needed for special casing the
    desktop icon files, move all that handling to the subclass.

 libnautilus-private/nautilus-desktop-icon-file.c |   83 ++++++++++++++++++++++
 libnautilus-private/nautilus-file.c              |   41 +----------
 2 files changed, 84 insertions(+), 40 deletions(-)
---
diff --git a/libnautilus-private/nautilus-desktop-icon-file.c 
b/libnautilus-private/nautilus-desktop-icon-file.c
index b869593..94cbb64 100644
--- a/libnautilus-private/nautilus-desktop-icon-file.c
+++ b/libnautilus-private/nautilus-desktop-icon-file.c
@@ -32,6 +32,8 @@
 #include "nautilus-file-private.h"
 #include "nautilus-file-utilities.h"
 #include "nautilus-file-operations.h"
+#include "nautilus-link.h"
+#include "nautilus-file-undo-manager.h"
 #include <eel/eel-glib-extensions.h>
 #include "nautilus-desktop-directory.h"
 #include <glib/gi18n.h>
@@ -344,6 +346,85 @@ nautilus_desktop_icon_file_eject (NautilusFile                   *file,
 }
 
 static void
+real_rename (NautilusFile                  *file,
+             const char                    *new_name,
+             NautilusFileOperationCallback  callback,
+             gpointer                       callback_data)
+{
+       NautilusDesktopLink *link;
+       char *old_name;
+       gboolean success;
+       GError *error;
+
+       g_return_if_fail (NAUTILUS_IS_FILE (file));
+       g_return_if_fail (new_name != NULL);
+       g_return_if_fail (callback != NULL);
+
+       /* Can't rename a file that's already gone.
+        * We need to check this here because there may be a new
+        * file with the same name.
+        */
+       if (nautilus_file_is_gone (file)) {
+               /* Claim that something changed even if the rename
+                * failed. This makes it easier for some clients who
+                * see the "reverting" to the old name as "changing
+                * back".
+                */
+               nautilus_file_changed (file);
+               error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                                    _("File not found"));
+               (* callback) (file, NULL, error, callback_data);
+               g_error_free (error);
+               return;
+       }
+
+       link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+       old_name = nautilus_file_get_display_name (file);
+
+       if ((old_name != NULL && strcmp (new_name, old_name) == 0)) {
+               success = TRUE;
+       } else {
+               success = (link != NULL && nautilus_desktop_link_rename (link, new_name));
+       }
+
+       if (success) {
+               (* callback) (file, NULL, NULL, callback_data);
+       } else {
+               error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+                                    _("Unable to rename desktop icon"));
+               (* callback) (file, NULL, error, callback_data);
+               g_error_free (error);
+       }
+
+       g_free (old_name);
+       g_object_unref (link);
+
+       return;
+}
+
+static gboolean
+real_can_rename (NautilusFile *file)
+{
+        NautilusDesktopLink *link;
+        gboolean can_rename;
+
+        can_rename = NAUTILUS_FILE_CLASS (nautilus_desktop_icon_file_parent_class)->can_rename (file);
+
+        if (!can_rename)
+                return FALSE;
+
+        link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+
+        /* Certain types of links can't be renamed */
+        if (link != NULL) {
+                can_rename = nautilus_desktop_link_can_rename (link);
+                g_object_unref (link);
+        }
+
+        return can_rename;
+}
+
+static void
 nautilus_desktop_icon_file_set_metadata (NautilusFile           *file,
                                         const char             *key,
                                         const char             *value)
@@ -383,6 +464,8 @@ nautilus_desktop_icon_file_class_init (NautilusDesktopIconFileClass *klass)
        file_class->set_metadata_as_list = nautilus_desktop_icon_file_set_metadata_as_list;
        file_class->unmount = nautilus_desktop_icon_file_unmount;
        file_class->eject = nautilus_desktop_icon_file_eject;
+        file_class->can_rename = real_can_rename;
+        file_class->rename = real_rename;
 
        g_type_class_add_private (object_class, sizeof(NautilusDesktopIconFileDetails));
 }
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 6736d37..81a1644 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -1518,18 +1518,6 @@ real_can_rename (NautilusFile *file)
        
        can_rename = TRUE;
 
-       /* Certain types of links can't be renamed */
-       if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
-               NautilusDesktopLink *link;
-
-               link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
-
-               if (link != NULL) {
-                       can_rename = nautilus_desktop_link_can_rename (link);
-                       g_object_unref (link);
-               }
-       }
-
        if (!can_rename) {
                return FALSE;
        }
@@ -1865,8 +1853,7 @@ real_rename (NautilusFile                  *file,
         * (1) rename returns an error if new & old are same.
         * (2) We don't want to send file-changed signal if nothing changed.
         */
-       if (!NAUTILUS_IS_DESKTOP_ICON_FILE (file) &&
-           !is_renameable_desktop_file &&
+       if (!is_renameable_desktop_file &&
            name_is (file, new_name)) {
                (* callback) (file, NULL, NULL, callback_data);
                return;
@@ -1890,32 +1877,6 @@ real_rename (NautilusFile                  *file,
                return;
        }
 
-       if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
-               NautilusDesktopLink *link;
-
-               link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
-               old_name = nautilus_file_get_display_name (file);
-
-               if ((old_name != NULL && strcmp (new_name, old_name) == 0)) {
-                       success = TRUE;
-               } else {
-                       success = (link != NULL && nautilus_desktop_link_rename (link, new_name));
-               }
-
-               if (success) {
-                       (* callback) (file, NULL, NULL, callback_data);
-               } else {
-                       error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                                            _("Unable to rename desktop icon"));
-                       (* callback) (file, NULL, error, callback_data);
-                       g_error_free (error);
-               }
-
-               g_free (old_name);
-               g_object_unref (link);
-               return;
-       }
-       
        if (is_renameable_desktop_file) {
                /* Don't actually change the name if the new name is the same.
                 * This helps for the vfolder method where this can happen and


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]