[nautilus/use-tracked-dirs-for-star] files-view: Use tracked directories for star



commit 82aff15226a27aae751403ab5146893b89cc1ede
Author: Carlos Soriano <csoriano redhat com>
Date:   Tue Jan 29 16:24:43 2019 +0100

    files-view: Use tracked directories for star
    
    We were using the xdg directories to check whether we can star a file
    or not, since the star feature only works on directories that are
    tracked by tracker.
    
    Tracker is usually shipped in distributions tracking the
    xdg-directories, so we check that as a stop gap solution for 3.30
    since we didn't have time to actually query what directories tracker
    is tracking and match that.
    
    This work makes it so that we show the star action on tracked
    directories.

 build-aux/flatpak/org.gnome.Nautilus.json |  31 ++++++++-
 src/meson.build                           |   4 +-
 src/nautilus-files-view.c                 |   9 +--
 src/nautilus-global-preferences.c         |   2 +
 src/nautilus-global-preferences.h         |   1 +
 src/nautilus-list-view.c                  |  13 ++--
 src/nautilus-tracker-utilities.c          | 112 ++++++++++++++++++++++++++++++
 src/nautilus-tracker-utilities.h          |  26 +++++++
 8 files changed, 185 insertions(+), 13 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Nautilus.json b/build-aux/flatpak/org.gnome.Nautilus.json
index ef359d4f4..e7a18a6d1 100644
--- a/build-aux/flatpak/org.gnome.Nautilus.json
+++ b/build-aux/flatpak/org.gnome.Nautilus.json
@@ -16,6 +16,7 @@
         "--socket=wayland",
         "--talk-name=org.gnome.OnlineAccounts",
         "--talk-name=org.freedesktop.Tracker1",
+        "--talk-name=org.freedesktop.Tracker1.Miner.Extract",
         "--filesystem=host",
         "--talk-name=org.gtk.vfs",
         "--talk-name=org.gtk.vfs.*",
@@ -84,6 +85,34 @@
                 }
             ]
         },
+        {
+            "name": "tracker-miners",
+            "buildsystem": "meson",
+            "cleanup": [ "/etc",
+                         "/lib",
+                         "/libexec",
+                         "/share/dbus-1/services/org.freedesktop.Tracker1.Miner.Extract.service",
+                         "/share/dbus-1/services/org.freedesktop.Tracker1.Writeback.service",
+                         "/share/tracker/miners/org.freedesktop.Tracker1.Miner.Applications.service",
+                         "/share/tracker/miners/org.freedesktop.Tracker1.Miner.Extract.service",
+                         "/share/tracker/miners/org.freedesktop.Tracker1.Miner.RSS.service",
+                         "/share/tracker-miners",
+                         "/share/glib-2.0/schemas/org.freedesktop.Tracker.Extract.gschema.xml",
+                         "/share/glib-2.0/schemas/org.freedesktop.Tracker.Writeback.gschema.xml" ],
+            "config-opts": [ "-Dextract=false",
+                             "-Dgeneric_media_extractor=none",
+                             "-Dminer_apps=false",
+                             "-Dminer_fs=true",
+                             "-Dminer_rss=false",
+                             "-Dsystemd_user_services=no",
+                             "-Dwriteback=false" ],
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "https://gitlab.gnome.org/GNOME/tracker-miners.git";
+                }
+            ]
+        },
         {
             "name" : "gnome-autoar",
             "sources" : [
@@ -110,4 +139,4 @@
             ]
         }
     ]
-}
\ No newline at end of file
+}
diff --git a/src/meson.build b/src/meson.build
index a87c51414..5aea6d251 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -267,7 +267,9 @@ libnautilus_sources = [
   'nautilus-starred-directory.c',
   'nautilus-starred-directory.h',
   'nautilus-enums.h',
-  'nautilus-types.h'
+  'nautilus-types.h',
+  'nautilus-tracker-utilities.c',
+  'nautilus-tracker-utilities.h'
 ]
 
 nautilus_deps = [
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 20a5c03d2..591d87b52 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -88,6 +88,7 @@
 #include "nautilus-view.h"
 #include "nautilus-view-icon-controller.h"
 #include "nautilus-window.h"
+#include "nautilus-tracker-utilities.h"
 
 /* Minimum starting update inverval */
 #define UPDATE_INTERVAL_MIN 100
@@ -7302,7 +7303,7 @@ real_update_actions_state (NautilusFilesView *view)
     GDriveStartStopType start_stop_type;
     g_autoptr (GFile) current_location = NULL;
     g_autofree gchar *current_uri = NULL;
-    gboolean current_directory_in_xdg_folders;
+    gboolean current_directory_tracked;
     gboolean show_star;
     gboolean show_unstar;
     gchar *uri;
@@ -7638,12 +7639,12 @@ real_update_actions_state (NautilusFilesView *view)
      */
     current_location = nautilus_file_get_location (nautilus_files_view_get_directory_as_file (view));
     current_uri = g_file_get_uri (current_location);
-    current_directory_in_xdg_folders = eel_uri_is_in_xdg_dirs (current_uri);
+    current_directory_tracked = nautilus_tracker_directory_is_tracked (current_location);
 
     show_star = (selection != NULL) &&
-                (current_directory_in_xdg_folders || selection_contains_starred);
+                (current_directory_tracked || selection_contains_starred);
     show_unstar = (selection != NULL) &&
-                  (current_directory_in_xdg_folders || selection_contains_starred);
+                  (current_directory_tracked || selection_contains_starred);
     for (l = selection; l != NULL; l = l->next)
     {
         NautilusFile *file;
diff --git a/src/nautilus-global-preferences.c b/src/nautilus-global-preferences.c
index 8fc9baadf..0e7e011b6 100644
--- a/src/nautilus-global-preferences.c
+++ b/src/nautilus-global-preferences.c
@@ -41,6 +41,7 @@ GSettings *gtk_filechooser_preferences;
 GSettings *gnome_lockdown_preferences;
 GSettings *gnome_background_preferences;
 GSettings *gnome_interface_preferences;
+GSettings *tracker_preferences;
 
 void
 nautilus_global_preferences_init (void)
@@ -65,4 +66,5 @@ nautilus_global_preferences_init (void)
     gnome_lockdown_preferences = g_settings_new ("org.gnome.desktop.lockdown");
     gnome_background_preferences = g_settings_new ("org.gnome.desktop.background");
     gnome_interface_preferences = g_settings_new ("org.gnome.desktop.interface");
+    tracker_preferences = g_settings_new ("org.freedesktop.Tracker.Miner.Files");
 }
diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h
index 87a79e706..e7e497e3e 100644
--- a/src/nautilus-global-preferences.h
+++ b/src/nautilus-global-preferences.h
@@ -164,5 +164,6 @@ extern GSettings *gtk_filechooser_preferences;
 extern GSettings *gnome_lockdown_preferences;
 extern GSettings *gnome_background_preferences;
 extern GSettings *gnome_interface_preferences;
+extern GSettings *tracker_preferences;
 
 G_END_DECLS
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 100c7c474..e8a00f27c 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -54,6 +54,7 @@
 #include "nautilus-tree-view-drag-dest.h"
 #include "nautilus-ui-utilities.h"
 #include "nautilus-view.h"
+#include "nautilus-tracker-utilities.h"
 
 struct SelectionForeachData
 {
@@ -2465,20 +2466,18 @@ get_visible_columns (NautilusListView *list_view)
 {
     NautilusFile *file;
     g_autoptr (GList) visible_columns = NULL;
+    g_autoptr (GFile) location = NULL;
     GPtrArray *res;
     GList *l;
     g_autofree gchar *uri = NULL;
-    gboolean in_xdg_dirs;
+    gboolean in_tracked_dir;
     gboolean is_starred;
 
     file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
     uri = nautilus_file_get_uri (file);
 
-    /* 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
-     */
-    in_xdg_dirs = eel_uri_is_in_xdg_dirs (uri);
+    location = g_file_new_for_uri (uri);
+    in_tracked_dir = nautilus_tracker_directory_is_tracked (location);
     is_starred = eel_uri_is_starred (uri);
 
     visible_columns = nautilus_file_get_metadata_list (file,
@@ -2492,7 +2491,7 @@ get_visible_columns (NautilusListView *list_view)
     for (l = visible_columns; l != NULL; l = l->next)
     {
         if (g_strcmp0 (l->data, "starred") != 0 ||
-            (g_strcmp0 (l->data, "starred") == 0 && (in_xdg_dirs || is_starred)))
+            (g_strcmp0 (l->data, "starred") == 0 && (in_tracked_dir || is_starred)))
         {
             g_ptr_array_add (res, l->data);
         }
diff --git a/src/nautilus-tracker-utilities.c b/src/nautilus-tracker-utilities.c
new file mode 100644
index 000000000..2e9af932d
--- /dev/null
+++ b/src/nautilus-tracker-utilities.c
@@ -0,0 +1,112 @@
+/* nautilus-tracker-utilities.c
+ *
+ * Copyright 2019 Carlos Soriano <csoriano redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "nautilus-tracker-utilities.h"
+#include "nautilus-global-preferences.h"
+
+#define TRACKER_KEY_RECURSIVE_DIRECTORIES "index-recursive-directories"
+
+static const gchar *
+path_from_tracker_dir (const gchar *value)
+{
+    const gchar *path;
+
+    if (g_strcmp0 (value, "&DESKTOP") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+    }
+    else if (g_strcmp0 (value, "&DOCUMENTS") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
+    }
+    else if (g_strcmp0 (value, "&DOWNLOAD") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
+    }
+    else if (g_strcmp0 (value, "&MUSIC") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
+    }
+    else if (g_strcmp0 (value, "&PICTURES") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
+    }
+    else if (g_strcmp0 (value, "&PUBLIC_SHARE") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
+    }
+    else if (g_strcmp0 (value, "&TEMPLATES") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES);
+    }
+    else if (g_strcmp0 (value, "&VIDEOS") == 0)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
+    }
+    else if (g_strcmp0 (value, "$HOME") == 0)
+    {
+        path = g_get_home_dir ();
+    }
+    else
+    {
+        path = value;
+    }
+
+    return path;
+}
+
+static GList *
+get_tracker_locations (void)
+{
+    g_auto (GStrv) locations = NULL;
+    GList *list = NULL;
+    gint idx;
+    GFile *location;
+    const gchar *path;
+
+    locations = g_settings_get_strv (tracker_preferences, TRACKER_KEY_RECURSIVE_DIRECTORIES);
+
+    for (idx = 0; locations[idx] != NULL; idx++)
+    {
+        path = path_from_tracker_dir (locations[idx]);
+        location = g_file_new_for_commandline_arg (path);
+        list = g_list_prepend (list, location);
+    }
+
+    return list;
+}
+
+gboolean
+nautilus_tracker_directory_is_tracked (GFile *directory)
+{
+    g_autolist (GFile) locations = NULL;
+    GList *l;
+
+    locations = get_tracker_locations ();
+    for (l = locations; l != NULL; l = l->next)
+    {
+        if (g_file_equal (directory, G_FILE (l->data)))
+        {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
diff --git a/src/nautilus-tracker-utilities.h b/src/nautilus-tracker-utilities.h
new file mode 100644
index 000000000..f509c3005
--- /dev/null
+++ b/src/nautilus-tracker-utilities.h
@@ -0,0 +1,26 @@
+/* nautilus-tracker-utilities.h
+ *
+ * Copyright 2019 Carlos Soriano <csoriano redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+
+#pragma once
+
+#include <gio/gio.h>
+
+gboolean nautilus_tracker_directory_is_tracked (GFile *directory);


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