[nautilus/wip/antoniof/new-list-view-continuation: 1/19] tag-manager: Use regular initialization
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view-continuation: 1/19] tag-manager: Use regular initialization
- Date: Sat, 9 Apr 2022 16:57:42 +0000 (UTC)
commit e04a4623e0852737ac29df0e4029936876b85b12
Author: António Fernandes <antoniof gnome org>
Date: Sat Apr 2 19:19:05 2022 +0100
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.
src/nautilus-application.c | 8 --------
src/nautilus-tag-manager.c | 37 +++++++++++++++----------------------
src/nautilus-tag-manager.h | 3 ---
3 files changed, 15 insertions(+), 33 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 06255587d..2b9880b84 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -84,7 +84,6 @@ typedef struct
NautilusFileUndoManager *undo_manager;
NautilusTagManager *tag_manager;
- GCancellable *tag_manager_cancellable;
guint previewer_selection_id;
} NautilusApplicationPrivate;
@@ -587,9 +586,6 @@ nautilus_application_finalize (GObject *object)
g_clear_object (&priv->tag_manager);
- g_cancellable_cancel (priv->tag_manager_cancellable);
- g_clear_object (&priv->tag_manager_cancellable);
-
G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
}
@@ -1101,11 +1097,7 @@ nautilus_application_init (NautilusApplication *self)
NULL);
priv->undo_manager = nautilus_file_undo_manager_new ();
-
- priv->tag_manager_cancellable = g_cancellable_new ();
priv->tag_manager = nautilus_tag_manager_get ();
- nautilus_tag_manager_set_cancellable (priv->tag_manager,
- priv->tag_manager_cancellable);
g_application_add_main_option_entries (G_APPLICATION (self), options);
diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c
index 32a9230ae..b3a7e4278 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
@@ -713,7 +707,6 @@ update_moved_uris_callback (GObject *object,
else
{
g_autolist (NautilusFile) updated_files = NULL;
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
for (guint i = 0; i < new_uris->len; i++)
{
diff --git a/src/nautilus-tag-manager.h b/src/nautilus-tag-manager.h
index 1ba8a48dd..e2f1d6747 100644
--- a/src/nautilus-tag-manager.h
+++ b/src/nautilus-tag-manager.h
@@ -30,9 +30,6 @@ G_DECLARE_FINAL_TYPE (NautilusTagManager, nautilus_tag_manager, NAUTILUS, TAG_MA
NautilusTagManager* nautilus_tag_manager_get (void);
-void nautilus_tag_manager_set_cancellable (NautilusTagManager *tag_manager,
- GCancellable *cancellable);
-
GList* nautilus_tag_manager_get_starred_files (NautilusTagManager *self);
void nautilus_tag_manager_star_files (NautilusTagManager *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]