diff options
-rw-r--r-- | src/nautilus-files-view.c | 8 | ||||
-rw-r--r-- | src/nautilus-list-view.c | 7 | ||||
-rw-r--r-- | src/nautilus-tag-manager.c | 13 | ||||
-rw-r--r-- | src/nautilus-tag-manager.h | 3 | ||||
-rw-r--r-- | src/nautilus-tracker-utilities.c | 133 | ||||
-rw-r--r-- | src/nautilus-tracker-utilities.h | 2 |
6 files changed, 24 insertions, 142 deletions
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index 2d8439283..b22bd8408 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -7450,7 +7450,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_tracked; + gboolean can_star_current_directory; gboolean show_star; gboolean show_unstar; gchar *uri; @@ -7784,12 +7784,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_tracked = nautilus_tracker_directory_is_tracked (current_location); + can_star_current_directory = nautilus_tag_manager_can_star_contents (priv->tag_manager, current_location); show_star = (selection != NULL) && - (current_directory_tracked || selection_contains_starred); + (can_star_current_directory || selection_contains_starred); show_unstar = (selection != NULL) && - (current_directory_tracked || selection_contains_starred); + (can_star_current_directory || selection_contains_starred); for (l = selection; l != NULL; l = l->next) { NautilusFile *file; diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c index 2ac0890e5..e30fb6389 100644 --- a/src/nautilus-list-view.c +++ b/src/nautilus-list-view.c @@ -2494,14 +2494,15 @@ get_visible_columns (NautilusListView *list_view) GPtrArray *res; GList *l; g_autofree gchar *uri = NULL; - gboolean in_tracked_dir; + gboolean can_star_current_directory; gboolean is_starred; file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view)); uri = nautilus_file_get_uri (file); location = g_file_new_for_uri (uri); - in_tracked_dir = nautilus_tracker_directory_is_tracked (location); + can_star_current_directory = nautilus_tag_manager_can_star_contents (list_view->details->tag_manager, + location); is_starred = eel_uri_is_starred (uri); visible_columns = nautilus_file_get_metadata_list (file, @@ -2515,7 +2516,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_tracked_dir || is_starred))) + (g_strcmp0 (l->data, "starred") == 0 && (can_star_current_directory || is_starred))) { g_ptr_array_add (res, l->data); } diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c index 2606d0d02..f41b3ec8f 100644 --- a/src/nautilus-tag-manager.c +++ b/src/nautilus-tag-manager.c @@ -41,6 +41,7 @@ struct _NautilusTagManager TrackerSparqlStatement *query_file_is_starred; GHashTable *starred_file_uris; + GFile *home; GCancellable *cancellable; }; @@ -676,4 +677,16 @@ nautilus_tag_manager_init (NautilusTagManager *self) (GDestroyNotify) g_free, /* values are keys */ NULL); + self->home = g_file_new_for_path (g_get_home_dir ()); +} + +gboolean +nautilus_tag_manager_can_star_contents (NautilusTagManager *tag_manager, + GFile *directory) +{ + /* We only allow files to be starred inside the home directory for now. + * This avoids the starred files database growing too big. + * See https://gitlab.gnome.org/GNOME/nautilus/-/merge_requests/553#note_903108 + */ + return g_file_has_prefix (directory, tag_manager->home) || g_file_equal (directory, tag_manager->home); } diff --git a/src/nautilus-tag-manager.h b/src/nautilus-tag-manager.h index acac9301a..c0d793adc 100644 --- a/src/nautilus-tag-manager.h +++ b/src/nautilus-tag-manager.h @@ -51,4 +51,7 @@ void nautilus_tag_manager_unstar_files (NautilusTagManager gboolean nautilus_tag_manager_file_is_starred (NautilusTagManager *self, const gchar *file_uri); +gboolean nautilus_tag_manager_can_star_contents (NautilusTagManager *self, + GFile *directory); + G_END_DECLS diff --git a/src/nautilus-tracker-utilities.c b/src/nautilus-tracker-utilities.c index 4c408942e..6230a5043 100644 --- a/src/nautilus-tracker-utilities.c +++ b/src/nautilus-tracker-utilities.c @@ -143,136 +143,3 @@ nautilus_tracker_get_miner_fs_busname (GError **error) return tracker_miner_fs_busname; } - -static GFile * -location_from_tracker_dir (const gchar *value) -{ - const gchar *special_dir; - g_autoptr (GFile) home = NULL; - GFile *location; - - home = g_file_new_for_path (g_get_home_dir ()); - - if (g_strcmp0 (value, "$HOME") == 0) - { - return g_steal_pointer (&home); - } - - special_dir = NULL; - if (g_strcmp0 (value, "&DESKTOP") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); - } - else if (g_strcmp0 (value, "&DOCUMENTS") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); - } - else if (g_strcmp0 (value, "&DOWNLOAD") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD); - } - else if (g_strcmp0 (value, "&MUSIC") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC); - } - else if (g_strcmp0 (value, "&PICTURES") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES); - } - else if (g_strcmp0 (value, "&PUBLIC_SHARE") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE); - } - else if (g_strcmp0 (value, "&TEMPLATES") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES); - } - else if (g_strcmp0 (value, "&VIDEOS") == 0) - { - special_dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS); - } - - if (special_dir != NULL) - { - location = g_file_new_for_commandline_arg (special_dir); - - /* Ignore XDG directories set to $HOME, like the miner does */ - if (g_file_equal (location, home)) - { - g_clear_object (&location); - } - } - else - { - location = g_file_new_for_commandline_arg (value); - } - - return location; -} - -static GList * -get_tracker_locations (const gchar *key) -{ - g_auto (GStrv) locations = NULL; - GList *list = NULL; - gint idx; - GFile *location; - - locations = g_settings_get_strv (tracker_preferences, key); - - for (idx = 0; locations[idx] != NULL; idx++) - { - location = location_from_tracker_dir (locations[idx]); - if (location != NULL) - { - list = g_list_prepend (list, location); - } - } - - return list; -} - -/** - * nautilus_tracker_directory_is_tracked: - * @directory: a #GFile representing a directory - * - * This function reads the "index-recursive-directories" and - * "index-single-directories" keys from the org.freedesktop.tracker.miner.files - * schema, and assumes the listed directories (and their descendants for the - * former key) are tracked. - * - * Exception: XDG user dirs set to $HOME are ignored. - * - * FIXME: Tracker's files miner's logic is actually a lot more complex, - * including configurable ignore patterns, but we are overlooking that. - * - * Returns: $TRUE if the @directory is, in principle, tracked. $FALSE otherwise. - */ -gboolean -nautilus_tracker_directory_is_tracked (GFile *directory) -{ - g_autolist (GFile) recursive_locations = NULL; - g_autolist (GFile) single_locations = NULL; - GList *l; - - recursive_locations = get_tracker_locations (TRACKER_KEY_RECURSIVE_DIRECTORIES); - for (l = recursive_locations; l != NULL; l = l->next) - { - if (g_file_equal (directory, G_FILE (l->data)) || - g_file_has_prefix (directory, G_FILE (l->data))) - { - return TRUE; - } - } - - single_locations = get_tracker_locations (TRACKER_KEY_SINGLE_DIRECTORIES); - for (l = single_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 index d4b2eba0c..f541655e2 100644 --- a/src/nautilus-tracker-utilities.h +++ b/src/nautilus-tracker-utilities.h @@ -26,5 +26,3 @@ TrackerSparqlConnection * nautilus_tracker_get_miner_fs_connection (GError **error); const gchar * nautilus_tracker_get_miner_fs_busname (GError **error); - -gboolean nautilus_tracker_directory_is_tracked (GFile *directory); |