[nautilus/wip/csoriano/destktop-split2: 31/60] file, directory: move file creation dispatching to directory



commit c6b101705ffd0a90c94a08ddeda709f9981b8640
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Mar 29 21:30:12 2016 +0200

    file, directory: move file creation dispatching to directory
    
    It's the directory who owns the files, and we were actually creating
    new files from nautilus directories in nautilus-file.
    
    We can move that code to nautilus directory.
    
    In this way, we will able to handle files of a specific scheme better,
    like the desktop, in future patches.

 libnautilus-private/nautilus-directory.c |   39 ++++++++++++++++++++++++++++++
 libnautilus-private/nautilus-directory.h |    3 ++
 libnautilus-private/nautilus-file.c      |   26 +-------------------
 3 files changed, 43 insertions(+), 25 deletions(-)
---
diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c
index 201ab23..a79fe30 100644
--- a/libnautilus-private/nautilus-directory.c
+++ b/libnautilus-private/nautilus-directory.c
@@ -27,11 +27,14 @@
 #include "nautilus-file-private.h"
 #include "nautilus-file-utilities.h"
 #include "nautilus-search-directory.h"
+#include "nautilus-search-directory-file.h"
+#include "nautilus-vfs-file.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-lib-self-check-functions.h"
 #include "nautilus-metadata.h"
 #include "nautilus-profile.h"
 #include "nautilus-desktop-directory.h"
+#include "nautilus-desktop-directory-file.h"
 #include "nautilus-vfs-directory.h"
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-string.h>
@@ -539,6 +542,42 @@ nautilus_directory_get_location (NautilusDirectory  *directory)
        return g_object_ref (directory->details->location);
 }
 
+NautilusFile *
+nautilus_directory_new_file_from_filename (NautilusDirectory *directory,
+                                           const char        *filename,
+                                           gboolean           self_owned)
+{
+       NautilusFile *file;
+
+       g_assert (NAUTILUS_IS_DIRECTORY (directory));
+       g_assert (filename != NULL);
+       g_assert (filename[0] != '\0');
+
+       if (NAUTILUS_IS_DESKTOP_DIRECTORY (directory)) {
+         g_print ("DIRECTORY FILE\n");
+               if (self_owned) {
+                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE, NULL));
+               } else {
+                       /* This doesn't normally happen, unless the user somehow types in a uri
+                        * that references a file like this. (See #349840) */
+                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+               }
+       } else if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
+               if (self_owned) {
+                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE, NULL));
+               } else {
+                       /* This doesn't normally happen, unless the user somehow types in a uri
+                        * that references a file like this. (See #349840) */
+                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+               }
+       } else {
+               file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+       }
+       nautilus_file_set_directory (file, directory);
+
+       return file;
+}
+
 static NautilusDirectory *
 nautilus_directory_new (GFile *location)
 {
diff --git a/libnautilus-private/nautilus-directory.h b/libnautilus-private/nautilus-directory.h
index dd467a2..46a253c 100644
--- a/libnautilus-private/nautilus-directory.h
+++ b/libnautilus-private/nautilus-directory.h
@@ -232,5 +232,8 @@ gboolean           nautilus_directory_is_editable              (NautilusDirector
 
 void               nautilus_directory_dump                     (NautilusDirectory         *directory);
 
+NautilusFile *     nautilus_directory_new_file_from_filename   (NautilusDirectory *directory,
+                                                                const char        *filename,
+                                                                gboolean           self_owned);
 
 #endif /* NAUTILUS_DIRECTORY_H */
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index d8dd2ea..d11f4b2 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -25,8 +25,6 @@
 #include "nautilus-directory-notify.h"
 #include "nautilus-directory-private.h"
 #include "nautilus-signaller.h"
-#include "nautilus-desktop-directory.h"
-#include "nautilus-desktop-directory-file.h"
 #include "nautilus-desktop-icon-file.h"
 #include "nautilus-file-attributes.h"
 #include "nautilus-file-private.h"
@@ -37,8 +35,6 @@
 #include "nautilus-link.h"
 #include "nautilus-metadata.h"
 #include "nautilus-module.h"
-#include "nautilus-search-directory.h"
-#include "nautilus-search-directory-file.h"
 #include "nautilus-thumbnails.h"
 #include "nautilus-ui-utilities.h"
 #include "nautilus-video-mime-types.h"
@@ -533,27 +529,7 @@ nautilus_file_new_from_filename (NautilusDirectory *directory,
        g_assert (filename != NULL);
        g_assert (filename[0] != '\0');
 
-       if (NAUTILUS_IS_DESKTOP_DIRECTORY (directory)) {
-               if (self_owned) {
-                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE, NULL));
-               } else {
-                       /* This doesn't normally happen, unless the user somehow types in a uri
-                        * that references a file like this. (See #349840) */
-                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
-               }
-       } else if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
-               if (self_owned) {
-                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE, NULL));
-               } else {
-                       /* This doesn't normally happen, unless the user somehow types in a uri
-                        * that references a file like this. (See #349840) */
-                       file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
-               }
-       } else {
-               file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
-       }
-       nautilus_file_set_directory (file, directory);
-
+       file = nautilus_directory_new_file_from_filename (directory, filename, self_owned);
        file->details->name = eel_ref_str_new (filename);
 
 #ifdef NAUTILUS_FILE_DEBUG_REF


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