[nautilus/fix-starring-non-indexed-files-in-a-lol-way] files-view: Show starring only for indexed (by default) files



commit b0a62ac9e4ca6f9110270adad980a695d891c6c3
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Feb 8 20:54:44 2018 +0100

    files-view: Show starring only for indexed (by default) files
    
    Currently the star menu item is shown for every file in the system,
    however when a file is not indexed by tracker this operation fails.
    
    We cannot set Tracker to index the file and wait for Tracker to index
    it, since that happens in an idle and Tracker doesn't queue the
    operation of starring.
    
    There is no easy solution for this, so for now we will show the star
    menu item for indexed (by default) locations, which are the XDG folders,
    otherwise we will hide the item.
    
    A better solution needs to be researched for 3.30, but this will do for
    now.
    
    Related https://gitlab.gnome.org/GNOME/nautilus/issues/243

 eel/eel-vfs-extensions.c  | 32 ++++++++++++++++++++++++++++++++
 eel/eel-vfs-extensions.h  |  1 +
 src/nautilus-files-view.c | 17 +++++++++++++++--
 3 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 54ccd7f98..94160f8fb 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -67,6 +67,38 @@ eel_uri_is_other_locations (const char *uri)
     return g_str_has_prefix (uri, "other-locations:");
 }
 
+gboolean
+eel_uri_is_in_xdg_dirs (const gchar *uri)
+{
+    GUserDirectory dir;
+    g_autoptr (GFile) location = NULL;
+    gboolean has_prefix = FALSE;
+
+    location = g_file_new_for_uri (uri);
+    for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
+    {
+        g_autoptr (GFile) xdg_dir_location = NULL;
+        const gchar *path;
+
+        path = g_get_user_special_dir (dir);
+        if (path == NULL)
+        {
+            continue;
+        }
+
+        xdg_dir_location = g_file_new_for_path (path);
+        has_prefix = g_file_has_prefix (location, xdg_dir_location) ||
+                     g_file_equal (location, xdg_dir_location);
+
+        if (has_prefix)
+        {
+            break;
+        }
+    }
+
+    return has_prefix;
+}
+
 char *
 eel_filename_get_extension_offset (const char *filename)
 {
diff --git a/eel/eel-vfs-extensions.h b/eel/eel-vfs-extensions.h
index 69aa51088..1881edc31 100644
--- a/eel/eel-vfs-extensions.h
+++ b/eel/eel-vfs-extensions.h
@@ -39,6 +39,7 @@ gboolean           eel_uri_is_trash                      (const char           *
 gboolean           eel_uri_is_search                     (const char           *uri);
 gboolean           eel_uri_is_other_locations            (const char           *uri);
 gboolean           eel_uri_is_recent                     (const char           *uri);
+gboolean           eel_uri_is_in_xdg_dirs                (const char           *uri);
 
 char *             eel_filename_strip_extension          (const char           *filename);
 void               eel_filename_get_rename_region        (const char           *filename,
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 7937bed31..83fe02fae 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -7692,8 +7692,21 @@ real_update_actions_state (NautilusFilesView *view)
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
                                  !nautilus_files_view_is_empty (view));
 
-    show_star = (selection != NULL);
-    show_unstar = (selection != NULL);
+
+    GFile *current_location;
+    gboolean current_directory_in_xdg_folders = FALSE;
+
+    /* FIXME: We are assuming tracker indexes XDG folders and ignore the search
+     * setting. This should be fixed in a better way for Nautilus 3.30.
+     * See https://gitlab.gnome.org/GNOME/nautilus/issues/243
+     */
+    current_location = nautilus_file_get_location (nautilus_files_view_get_directory_as_file (view));
+    current_directory_in_xdg_folders = eel_uri_is_in_xdg_dirs (g_file_get_uri (current_location));
+
+    show_star = (selection != NULL) &&
+                (current_directory_in_xdg_folders || selection_contains_starred);
+    show_unstar = (selection != NULL) &&
+                  (current_directory_in_xdg_folders || selection_contains_starred);
     for (l = selection; l != NULL; l = l->next)
     {
         file = NAUTILUS_FILE (l->data);


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