[nautilus/wip/csoriano/destktop-split2: 43/54] desktop: ensure desktop directory on application init



commit 9c8c9bdb8d3ce657a2cb9f554cbb24d0802fb552
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Mar 29 21:58:56 2016 +0200

    desktop: ensure desktop directory on application init
    
    Until now we were creating the desktop directory in a lazy way, like
    any other cached directory.
    
    However, we have the problem that at some point we have to dispatch
    between different types of files, when creating them for the cache.
    
    We cannot know when we will need to create the desktop directory for
    first time in order to discern between that type of directory, or the
    regular one.
    
    What we can do is ensure that we created the desktop directory before
    any other part of nautilus request it. In this way, we can create it
    on our subclasses of the desktop, and after that, nautilus will request
    the cache as a regular use, without the need to special case the
    desktop.
    
    For that, create the desktop directory when the desktop application
    starts, holding the reference so the cache doesn't release it, and then
    let nautilus work as expected.
    
    For that, in previous commits we moved the file dispatching to be inside
    the directory, so now any file creation happens inside the directory,
    and therefore we can control, when creating the desktop directory, what
    subclass will be called.

 libnautilus-private/nautilus-directory.c |   25 ++++++++++++++++++++-----
 libnautilus-private/nautilus-directory.h |    2 ++
 src/nautilus-desktop-application.c       |    8 ++++++++
 3 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c
index 653d0b7..baca1c7 100644
--- a/libnautilus-private/nautilus-directory.c
+++ b/libnautilus-private/nautilus-directory.c
@@ -34,8 +34,6 @@
 #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>
@@ -456,6 +454,25 @@ nautilus_directory_get_for_file (NautilusFile *file)
        return directory;
 }
 
+void
+nautilus_directory_add_to_cache (NautilusDirectory *directory)
+{
+       NautilusDirectory *existing_directory;
+       GFile *location;
+
+       location = nautilus_directory_get_location (directory);
+       existing_directory = nautilus_directory_get_existing (location);
+       if (existing_directory == NULL) {
+               /* Put it in the hash table. */
+               g_hash_table_insert (directories,
+                                    directory->details->location,
+                                    directory);
+       } else {
+               nautilus_directory_unref (existing_directory);
+       }
+}
+
+
 /* Returns a reffed NautilusFile object for this directory.
  */
 NautilusFile *
@@ -594,9 +611,7 @@ nautilus_directory_new (GFile *location)
 
        uri = g_file_get_uri (location);
 
-       if (eel_uri_is_desktop (uri)) {
-               type = NAUTILUS_TYPE_DESKTOP_DIRECTORY;
-       } else if (eel_uri_is_search (uri)) {
+       if (eel_uri_is_search (uri)) {
                type = NAUTILUS_TYPE_SEARCH_DIRECTORY;
        } else {
                type = NAUTILUS_TYPE_VFS_DIRECTORY;
diff --git a/libnautilus-private/nautilus-directory.h b/libnautilus-private/nautilus-directory.h
index f375f45..ecb5761 100644
--- a/libnautilus-private/nautilus-directory.h
+++ b/libnautilus-private/nautilus-directory.h
@@ -239,6 +239,8 @@ gboolean           nautilus_directory_is_editable              (NautilusDirector
 
 void               nautilus_directory_dump                     (NautilusDirectory         *directory);
 
+void               nautilus_directory_add_to_cache             (NautilusDirectory         *directory);
+
 NautilusFile *     nautilus_directory_new_file_from_filename   (NautilusDirectory *directory,
                                                                 const char        *filename,
                                                                 gboolean           self_owned);
diff --git a/src/nautilus-desktop-application.c b/src/nautilus-desktop-application.c
index 3f522ab..f2e1b96 100644
--- a/src/nautilus-desktop-application.c
+++ b/src/nautilus-desktop-application.c
@@ -20,6 +20,7 @@
 
 #include "nautilus-desktop-application.h"
 #include "nautilus-desktop-window.h"
+#include "nautilus-desktop-directory.h"
 
 #include "nautilus-freedesktop-generated.h"
 
@@ -28,6 +29,7 @@
 #include <gdk/gdkx.h>
 
 static NautilusFreedesktopFileManager1 *freedesktop_proxy = NULL;
+static NautilusDirectory *desktop_directory = NULL;
 
 struct _NautilusDesktopApplication
 {
@@ -235,6 +237,12 @@ nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
 static void
 nautilus_desktop_application_init (NautilusDesktopApplication *self)
 {
+  g_autoptr (GFile) desktop_location;
+
+  desktop_location = g_file_new_for_uri (EEL_DESKTOP_URI);
+  desktop_directory = g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY, "location", desktop_location, NULL);
+  nautilus_directory_add_to_cache (NAUTILUS_DIRECTORY (desktop_directory));
+  g_object_unref (desktop_location);
   g_print ("desktop application init\n");
 }
 


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