[nautilus/wip/antoniof/new-list-view-continuation: 12/32] tag-manager: Stop getting full references
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/new-list-view-continuation: 12/32] tag-manager: Stop getting full references
- Date: Thu, 21 Apr 2022 09:57:38 +0000 (UTC)
commit a571f01936da494a3c1a2852b36552c516ddca95
Author: António Fernandes <antoniof gnome org>
Date: Sun Apr 3 00:29:52 2022 +0100
tag-manager: Stop getting full references
It's really annoying having to setup a local autocleanup variable in
every function we want to use the NautilusTagManager API.
Use a NautilusUndoManager-like API instead, with new() returning a
reference and get() not.
src/nautilus-application.c | 2 +-
src/nautilus-file-changes-queue.c | 3 +--
src/nautilus-file-undo-operations.c | 10 ++++------
src/nautilus-file.c | 7 ++++---
src/nautilus-files-view.c | 11 ++++-------
src/nautilus-list-view-private.h | 1 -
src/nautilus-list-view.c | 17 ++++++++---------
src/nautilus-starred-directory.c | 17 +++++++----------
src/nautilus-tag-manager.c | 24 +++++++++++++++---------
src/nautilus-tag-manager.h | 1 +
10 files changed, 45 insertions(+), 48 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 2b9880b84..9d4e2959d 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1097,7 +1097,7 @@ nautilus_application_init (NautilusApplication *self)
NULL);
priv->undo_manager = nautilus_file_undo_manager_new ();
- priv->tag_manager = nautilus_tag_manager_get ();
+ priv->tag_manager = nautilus_tag_manager_new ();
g_application_add_main_option_entries (G_APPLICATION (self), options);
diff --git a/src/nautilus-file-changes-queue.c b/src/nautilus-file-changes-queue.c
index 859e0c0da..547327117 100644
--- a/src/nautilus-file-changes-queue.c
+++ b/src/nautilus-file-changes-queue.c
@@ -206,7 +206,6 @@ pairs_list_free (GList *pairs)
void
nautilus_file_changes_consume_changes (gboolean consume_all)
{
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
NautilusFileChange *change;
GList *additions, *changes, *deletions, *moves;
GFilePair *pair;
@@ -322,7 +321,7 @@ nautilus_file_changes_consume_changes (gboolean consume_all)
case CHANGE_FILE_MOVED:
{
- nautilus_tag_manager_update_moved_uris (tag_manager,
+ nautilus_tag_manager_update_moved_uris (nautilus_tag_manager_get (),
change->from,
change->to);
diff --git a/src/nautilus-file-undo-operations.c b/src/nautilus-file-undo-operations.c
index 64f9ce76c..7fc6ecd2d 100644
--- a/src/nautilus-file-undo-operations.c
+++ b/src/nautilus-file-undo-operations.c
@@ -1437,11 +1437,10 @@ starred_redo_func (NautilusFileUndoInfo *info,
NautilusFileOperationsDBusData *dbus_data)
{
NautilusFileUndoInfoStarred *self = NAUTILUS_FILE_UNDO_INFO_STARRED (info);
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
if (self->starred)
{
- nautilus_tag_manager_star_files (tag_manager,
+ nautilus_tag_manager_star_files (nautilus_tag_manager_get (),
G_OBJECT (info),
self->files,
on_undo_starred_tags_updated,
@@ -1449,7 +1448,7 @@ starred_redo_func (NautilusFileUndoInfo *info,
}
else
{
- nautilus_tag_manager_unstar_files (tag_manager,
+ nautilus_tag_manager_unstar_files (nautilus_tag_manager_get (),
G_OBJECT (info),
self->files,
on_undo_starred_tags_updated,
@@ -1463,11 +1462,10 @@ starred_undo_func (NautilusFileUndoInfo *info,
NautilusFileOperationsDBusData *dbus_data)
{
NautilusFileUndoInfoStarred *self = NAUTILUS_FILE_UNDO_INFO_STARRED (info);
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
if (self->starred)
{
- nautilus_tag_manager_unstar_files (tag_manager,
+ nautilus_tag_manager_unstar_files (nautilus_tag_manager_get (),
G_OBJECT (info),
self->files,
on_undo_starred_tags_updated,
@@ -1475,7 +1473,7 @@ starred_undo_func (NautilusFileUndoInfo *info,
}
else
{
- nautilus_tag_manager_star_files (tag_manager,
+ nautilus_tag_manager_star_files (nautilus_tag_manager_get (),
G_OBJECT (info),
self->files,
on_undo_starred_tags_updated,
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 727181421..e8734f453 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -1863,7 +1863,6 @@ rename_get_info_callback (GObject *source_object,
new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
if (new_info != NULL)
{
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
g_autoptr (GFile) old_location = NULL;
g_autoptr (GFile) new_location = NULL;
@@ -1891,7 +1890,9 @@ rename_get_info_callback (GObject *source_object,
new_uri = g_file_get_uri (new_location);
nautilus_directory_moved (old_uri, new_uri);
- nautilus_tag_manager_update_moved_uris (tag_manager, old_location, new_location);
+ nautilus_tag_manager_update_moved_uris (nautilus_tag_manager_get (),
+ old_location,
+ new_location);
g_free (new_uri);
g_free (old_uri);
@@ -3505,7 +3506,7 @@ static int
compare_by_starred (NautilusFile *file_1,
NautilusFile *file_2)
{
- g_autoptr (NautilusTagManager) tag_manager = nautilus_tag_manager_get ();
+ NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
g_autofree gchar *uri_1 = NULL;
g_autofree gchar *uri_2 = NULL;
gboolean file_1_is_starred;
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 9b677abce..e423c943c 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -273,7 +273,6 @@ typedef struct
GCancellable *clipboard_cancellable;
GCancellable *starred_cancellable;
- NautilusTagManager *tag_manager;
gulong name_accepted_handler_id;
gulong cancelled_handler_id;
@@ -1644,7 +1643,7 @@ action_star (GSimpleAction *action,
priv = nautilus_files_view_get_instance_private (view);
selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- nautilus_tag_manager_star_files (priv->tag_manager,
+ nautilus_tag_manager_star_files (nautilus_tag_manager_get (),
G_OBJECT (view),
selection,
NULL,
@@ -1664,7 +1663,7 @@ action_unstar (GSimpleAction *action,
priv = nautilus_files_view_get_instance_private (view);
selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- nautilus_tag_manager_unstar_files (priv->tag_manager,
+ nautilus_tag_manager_unstar_files (nautilus_tag_manager_get (),
G_OBJECT (view),
selection,
NULL,
@@ -3343,7 +3342,6 @@ nautilus_files_view_finalize (GObject *object)
g_cancellable_cancel (priv->starred_cancellable);
g_clear_object (&priv->starred_cancellable);
- g_clear_object (&priv->tag_manager);
G_OBJECT_CLASS (nautilus_files_view_parent_class)->finalize (object);
}
@@ -7797,7 +7795,7 @@ 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);
- can_star_current_directory = nautilus_tag_manager_can_star_contents (priv->tag_manager,
current_location);
+ can_star_current_directory = nautilus_tag_manager_can_star_contents (nautilus_tag_manager_get (),
current_location);
show_star = (selection != NULL) &&
(can_star_current_directory || selection_contains_starred);
@@ -7815,7 +7813,7 @@ real_update_actions_state (NautilusFilesView *view)
break;
}
- if (nautilus_tag_manager_file_is_starred (priv->tag_manager, uri))
+ if (nautilus_tag_manager_file_is_starred (nautilus_tag_manager_get (), uri))
{
show_star = FALSE;
}
@@ -9708,7 +9706,6 @@ nautilus_files_view_init (NautilusFilesView *view)
nautilus_application_set_accelerators (app, "view.popup-menu", popup_menu_accels);
priv->starred_cancellable = g_cancellable_new ();
- priv->tag_manager = nautilus_tag_manager_get ();
priv->rename_file_controller = nautilus_rename_file_popover_controller_new ();
diff --git a/src/nautilus-list-view-private.h b/src/nautilus-list-view-private.h
index 2c83860cc..4c0e3e1c8 100644
--- a/src/nautilus-list-view-private.h
+++ b/src/nautilus-list-view-private.h
@@ -75,7 +75,6 @@ struct NautilusListViewDetails {
GRegex *regex;
- NautilusTagManager *tag_manager;
GCancellable *starred_cancellable;
};
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index a3ad6946c..9bd0adb3a 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -408,6 +408,7 @@ on_star_cell_renderer_clicked (GtkTreePath *path,
NautilusFile *file;
g_autofree gchar *uri = NULL;
GList *selection;
+ NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
list_model = list_view->details->model;
@@ -422,9 +423,9 @@ on_star_cell_renderer_clicked (GtkTreePath *path,
uri = nautilus_file_get_uri (file);
selection = g_list_prepend (NULL, file);
- if (nautilus_tag_manager_file_is_starred (list_view->details->tag_manager, uri))
+ if (nautilus_tag_manager_file_is_starred (tag_manager, uri))
{
- nautilus_tag_manager_unstar_files (list_view->details->tag_manager,
+ nautilus_tag_manager_unstar_files (tag_manager,
G_OBJECT (list_view),
selection,
NULL,
@@ -432,7 +433,7 @@ on_star_cell_renderer_clicked (GtkTreePath *path,
}
else
{
- nautilus_tag_manager_star_files (list_view->details->tag_manager,
+ nautilus_tag_manager_star_files (tag_manager,
G_OBJECT (list_view),
selection,
NULL,
@@ -1593,7 +1594,7 @@ starred_cell_data_func (GtkTreeViewColumn *column,
uri = nautilus_file_get_uri (file);
- if (nautilus_tag_manager_file_is_starred (view->details->tag_manager, uri))
+ if (nautilus_tag_manager_file_is_starred (nautilus_tag_manager_get (), uri))
{
g_object_set (renderer,
"icon-name", "starred-symbolic",
@@ -2356,7 +2357,7 @@ get_visible_columns (NautilusListView *list_view)
uri = nautilus_file_get_uri (file);
location = g_file_new_for_uri (uri);
- can_star_current_directory = nautilus_tag_manager_can_star_contents (list_view->details->tag_manager,
+ can_star_current_directory = nautilus_tag_manager_can_star_contents (nautilus_tag_manager_get (),
location);
is_starred = eel_uri_is_starred (uri);
@@ -3527,10 +3528,9 @@ nautilus_list_view_finalize (GObject *object)
g_cancellable_cancel (list_view->details->starred_cancellable);
g_clear_object (&list_view->details->starred_cancellable);
- g_signal_handlers_disconnect_by_func (list_view->details->tag_manager,
+ g_signal_handlers_disconnect_by_func (nautilus_tag_manager_get (),
on_starred_files_changed,
list_view);
- g_clear_object (&list_view->details->tag_manager);
g_free (list_view->details);
@@ -3944,10 +3944,9 @@ nautilus_list_view_init (NautilusListView *list_view)
list_view->details->regex = g_regex_new ("\\R+", 0, G_REGEX_MATCH_NEWLINE_ANY, NULL);
- list_view->details->tag_manager = nautilus_tag_manager_get ();
list_view->details->starred_cancellable = g_cancellable_new ();
- g_signal_connect (list_view->details->tag_manager,
+ g_signal_connect (nautilus_tag_manager_get (),
"starred-changed",
(GCallback) on_starred_files_changed,
list_view);
diff --git a/src/nautilus-starred-directory.c b/src/nautilus-starred-directory.c
index fd41418a4..4c26a0ead 100644
--- a/src/nautilus-starred-directory.c
+++ b/src/nautilus-starred-directory.c
@@ -26,7 +26,6 @@ struct _NautilusFavoriteDirectory
{
NautilusDirectory parent_slot;
- NautilusTagManager *tag_manager;
GList *files;
GList *monitor_list;
@@ -96,6 +95,7 @@ disconnect_and_unmonitor_file (NautilusFile *file,
static void
nautilus_starred_directory_update_files (NautilusFavoriteDirectory *self)
{
+ NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
GList *l;
GList *tmp_l;
GList *new_starred_files;
@@ -120,7 +120,7 @@ nautilus_starred_directory_update_files (NautilusFavoriteDirectory *self)
g_hash_table_add (uri_table, nautilus_file_get_uri (NAUTILUS_FILE (l->data)));
}
- new_starred_files = nautilus_tag_manager_get_starred_files (self->tag_manager);
+ new_starred_files = nautilus_tag_manager_get_starred_files (tag_manager);
for (l = new_starred_files; l != NULL; l = l->next)
{
@@ -147,7 +147,7 @@ nautilus_starred_directory_update_files (NautilusFavoriteDirectory *self)
{
uri = nautilus_file_get_uri (NAUTILUS_FILE (l->data));
- if (!nautilus_tag_manager_file_is_starred (self->tag_manager, uri))
+ if (!nautilus_tag_manager_file_is_starred (tag_manager, uri))
{
files_removed = g_list_prepend (files_removed,
nautilus_file_ref (NAUTILUS_FILE (l->data)));
@@ -217,7 +217,7 @@ real_contains_file (NautilusDirectory *directory,
uri = nautilus_file_get_uri (file);
- return nautilus_tag_manager_file_is_starred (self->tag_manager, uri);
+ return nautilus_tag_manager_file_is_starred (nautilus_tag_manager_get (), uri);
}
static gboolean
@@ -451,7 +451,7 @@ nautilus_starred_directory_set_files (NautilusFavoriteDirectory *self)
file_list = NULL;
- starred_files = nautilus_tag_manager_get_starred_files (self->tag_manager);
+ starred_files = nautilus_tag_manager_get_starred_files (nautilus_tag_manager_get ());
for (l = starred_files; l != NULL; l = l->next)
{
@@ -495,11 +495,10 @@ nautilus_starred_directory_finalize (GObject *object)
self = NAUTILUS_STARRED_DIRECTORY (object);
- g_signal_handlers_disconnect_by_func (self->tag_manager,
+ g_signal_handlers_disconnect_by_func (nautilus_tag_manager_get (),
on_starred_files_changed,
self);
- g_object_unref (self->tag_manager);
nautilus_file_list_free (self->files);
G_OBJECT_CLASS (nautilus_starred_directory_parent_class)->finalize (object);
@@ -568,9 +567,7 @@ nautilus_starred_directory_new ()
static void
nautilus_starred_directory_init (NautilusFavoriteDirectory *self)
{
- self->tag_manager = nautilus_tag_manager_get ();
-
- g_signal_connect (self->tag_manager,
+ g_signal_connect (nautilus_tag_manager_get (),
"starred-changed",
(GCallback) on_starred_files_changed,
self);
diff --git a/src/nautilus-tag-manager.c b/src/nautilus-tag-manager.c
index b3a7e4278..22aed9011 100644
--- a/src/nautilus-tag-manager.c
+++ b/src/nautilus-tag-manager.c
@@ -49,6 +49,8 @@ struct _NautilusTagManager
G_DEFINE_TYPE (NautilusTagManager, nautilus_tag_manager, G_TYPE_OBJECT);
+static NautilusTagManager *tag_manager = NULL;
+
typedef struct
{
NautilusTagManager *tag_manager;
@@ -566,20 +568,13 @@ nautilus_tag_manager_class_init (NautilusTagManagerClass *klass)
}
/**
- * nautilus_tag_manager_get:
- *
- * Gets a reference to the tag manager.
- *
- * If used to initialize a struct field, make sure to release on finalization.
- * If used to initialize a local variable, make sure to use g_autoptr().
+ * nautilus_tag_manager_new:
*
* Returns: (transfer full): the #NautilusTagManager singleton object.
*/
NautilusTagManager *
-nautilus_tag_manager_get (void)
+nautilus_tag_manager_new (void)
{
- static NautilusTagManager *tag_manager = NULL;
-
if (tag_manager != NULL)
{
return g_object_ref (tag_manager);
@@ -591,6 +586,17 @@ nautilus_tag_manager_get (void)
return tag_manager;
}
+/**
+ * nautilus_tag_manager_get:
+ *
+ * Returns: (transfer none): the #NautilusTagManager singleton object.
+ */
+NautilusTagManager *
+nautilus_tag_manager_get (void)
+{
+ return tag_manager;
+}
+
static gboolean
setup_database (NautilusTagManager *self,
GCancellable *cancellable,
diff --git a/src/nautilus-tag-manager.h b/src/nautilus-tag-manager.h
index e2f1d6747..24ef72459 100644
--- a/src/nautilus-tag-manager.h
+++ b/src/nautilus-tag-manager.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (NautilusTagManager, nautilus_tag_manager, NAUTILUS, TAG_MANAGER, GObject);
+NautilusTagManager* nautilus_tag_manager_new (void);
NautilusTagManager* nautilus_tag_manager_get (void);
GList* nautilus_tag_manager_get_starred_files (NautilusTagManager *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]