[nautilus/wip/csoriano/destktop-split2: 42/54] desktop-directory: override creation of files



commit 85867ab6c852aa355714f67cb6d2f7f8949be392
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Mar 29 21:57:59 2016 +0200

    desktop-directory: override creation of files
    
    So we use inheritance instead of special casing, making possible
    to remove the desktop dependency for the creation of the desktop
    files.

 libnautilus-private/nautilus-desktop-directory.c |   26 ++++++++++++++++++++++
 libnautilus-private/nautilus-directory.c         |   11 +--------
 2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/libnautilus-private/nautilus-desktop-directory.c 
b/libnautilus-private/nautilus-desktop-directory.c
index d390221..41c6cd2 100644
--- a/libnautilus-private/nautilus-desktop-directory.c
+++ b/libnautilus-private/nautilus-desktop-directory.c
@@ -24,6 +24,7 @@
 
 #include <config.h>
 #include "nautilus-desktop-directory.h"
+#include "nautilus-desktop-directory-file.h"
 
 #include "nautilus-directory-private.h"
 #include "nautilus-file.h"
@@ -485,6 +486,30 @@ update_desktop_directory (NautilusDesktopDirectory *desktop)
        desktop->details->real_directory = real_directory;
 }
 
+static NautilusFile *
+real_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 (self_owned) {
+               file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE, NULL));
+       } else {
+               g_critical ("Accessing desktop uris directly is not supported.");
+
+               return NULL;
+       }
+
+       nautilus_file_set_directory (file, directory);
+
+       return file;
+}
+
 static void
 desktop_directory_changed_callback (gpointer data)
 {
@@ -523,6 +548,7 @@ nautilus_desktop_directory_class_init (NautilusDesktopDirectoryClass *class)
        directory_class->force_reload = desktop_force_reload;
        directory_class->are_all_files_seen = desktop_are_all_files_seen;
        directory_class->is_not_empty = desktop_is_not_empty;
+       directory_class->new_file_from_filename = real_new_file_from_filename;
        /* Override get_file_list so that we can return the list of files
         * in NautilusDesktopDirectory->details->real_directory,
         * in addition to the list of standard desktop icons on the desktop.
diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c
index 97be864..653d0b7 100644
--- a/libnautilus-private/nautilus-directory.c
+++ b/libnautilus-private/nautilus-directory.c
@@ -569,16 +569,7 @@ real_new_file_from_filename (NautilusDirectory *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 (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
                if (self_owned) {
                        file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE, NULL));
                } else {


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