diff options
author | António Fernandes <antoniof@gnome.org> | 2022-04-02 19:19:05 +0100 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-05-30 10:12:10 +0100 |
commit | df78c517516cec20892f2a108df47613153ddf5b (patch) | |
tree | e97afe8454492eb73a804c06a6abab5740676498 /src/nautilus-tag-manager.c | |
parent | 39e98edca46af9bb4e6e32147a20aa8d20f2c356 (diff) | |
download | nautilus-df78c517516cec20892f2a108df47613153ddf5b.tar.gz |
tag-manager: Use regular initialization
Somehow we have ended up in a situation where the singleton object
is not initialized on creation but instead when requires the
NautilusApplication code to pass a GCancellable instance in order to
complete the initialization.
The passed cancellable pointer is stored by the application object
in order to cancel it on finalization, but there is no other usage
for this cancellabled from outside of the NautilusTagManager code.
So, we can just cancel it in NautilusTagManager::finalize, such that
there is no need for NautilusApplication to pass or store it.
This way, we can move the initalization from ::set_cancellable()
into ::init instead.
Diffstat (limited to 'src/nautilus-tag-manager.c')
-rw-r--r-- | src/nautilus-tag-manager.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c index 32a9230ae..ec4205bba 100644 --- a/src/nautilus-tag-manager.c +++ b/src/nautilus-tag-manager.c @@ -300,8 +300,6 @@ nautilus_tag_manager_query_starred_files (NautilusTagManager *self, return; } - self->cancellable = cancellable; - tracker_sparql_statement_execute_async (self->query_starred_files, cancellable, on_get_starred_files_query_callback, @@ -533,6 +531,8 @@ nautilus_tag_manager_finalize (GObject *object) self); } + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); g_clear_object (&self->notifier); g_clear_object (&self->db); g_clear_object (&self->query_file_is_starred); @@ -647,15 +647,20 @@ setup_database (NautilusTagManager *self, return TRUE; } -/* Initialize the tag mananger. */ -void -nautilus_tag_manager_set_cancellable (NautilusTagManager *self, - GCancellable *cancellable) +static void +nautilus_tag_manager_init (NautilusTagManager *self) { g_autoptr (GError) error = NULL; - self->database_ok = setup_database (self, cancellable, &error); + self->starred_file_uris = g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify) g_free, + /* values are keys */ + NULL); + self->home = g_file_new_for_path (g_get_home_dir ()); + self->cancellable = g_cancellable_new (); + self->database_ok = setup_database (self, self->cancellable, &error); if (error) { g_warning ("Unable to initialize tag manager: %s", error->message); @@ -664,7 +669,7 @@ nautilus_tag_manager_set_cancellable (NautilusTagManager *self, self->notifier = tracker_sparql_connection_create_notifier (self->db); - nautilus_tag_manager_query_starred_files (self, cancellable); + nautilus_tag_manager_query_starred_files (self, self->cancellable); g_signal_connect (self->notifier, "events", @@ -672,26 +677,15 @@ nautilus_tag_manager_set_cancellable (NautilusTagManager *self, self); } -static void -nautilus_tag_manager_init (NautilusTagManager *self) -{ - self->starred_file_uris = g_hash_table_new_full (g_str_hash, - g_str_equal, - (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, +nautilus_tag_manager_can_star_contents (NautilusTagManager *self, 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); + return g_file_has_prefix (directory, self->home) || g_file_equal (directory, self->home); } static void |