[gtk/prop-list: 22/32] Turn GtkRecentInfo into an object
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 22/32] Turn GtkRecentInfo into an object
- Date: Sat, 21 Dec 2019 05:29:04 +0000 (UTC)
commit 1ea2dac0065ee1a494d3b93546dd0f970e889b99
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 18 23:20:38 2019 -0500
Turn GtkRecentInfo into an object
This is in preparation to eventually using
a list model of recent infos.
docs/reference/gtk/gtk4-sections.txt | 2 --
gtk/gtk-autocleanups.h | 1 -
gtk/gtkfilechooserwidget.c | 2 +-
gtk/gtkrecentmanager.c | 69 +++++++++++-------------------------
gtk/gtkrecentmanager.h | 13 ++-----
testsuite/gtk/recentmanager.c | 2 +-
6 files changed, 26 insertions(+), 63 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 42d8e9d3ea..2cb2811923 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -2594,8 +2594,6 @@ gtk_recent_manager_move_item
gtk_recent_manager_get_items
gtk_recent_manager_purge_items
<SUBSECTION>
-gtk_recent_info_ref
-gtk_recent_info_unref
gtk_recent_info_get_uri
gtk_recent_info_get_display_name
gtk_recent_info_get_description
diff --git a/gtk/gtk-autocleanups.h b/gtk/gtk-autocleanups.h
index 7eb7e359d5..1b18fd5dde 100644
--- a/gtk/gtk-autocleanups.h
+++ b/gtk/gtk-autocleanups.h
@@ -169,7 +169,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkViewport, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkVolumeButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkPaperSize, gtk_paper_size_free)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentInfo, gtk_recent_info_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSelectionData, gtk_selection_data_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTextIter, gtk_text_iter_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreeIter, gtk_tree_iter_free)
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 7ac3e20889..86668c8861 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -7542,7 +7542,7 @@ recent_start_loading (GtkFileChooserWidget *impl)
g_list_free_full (folders, g_object_unref);
}
- g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
+ g_list_free_full (items, (GDestroyNotify) g_object_unref);
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->browse_files_tree_view),
GTK_TREE_MODEL (priv->recent_model));
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index c4238d079a..20a99c3131 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -139,6 +139,8 @@ typedef struct
*/
struct _GtkRecentInfo
{
+ GObject parent_instance;
+
gchar *uri;
gchar *display_name;
@@ -158,8 +160,11 @@ struct _GtkRecentInfo
int n_groups;
gboolean is_private;
+};
- gint ref_count;
+struct _GtkRecentInfoClass
+{
+ GObjectClass parent_class;
};
struct _GtkRecentManagerPrivate
@@ -222,7 +227,6 @@ static void purge_recent_items_list (GtkRecentManager *manag
GError **error);
static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
-static void gtk_recent_info_free (GtkRecentInfo *recent_info);
static guint signal_changed = 0;
@@ -1473,9 +1477,12 @@ gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
* GtkRecentInfo *
*****************/
-G_DEFINE_BOXED_TYPE (GtkRecentInfo, gtk_recent_info,
- gtk_recent_info_ref,
- gtk_recent_info_unref)
+G_DEFINE_TYPE (GtkRecentInfo, gtk_recent_info, G_TYPE_OBJECT)
+
+static void
+gtk_recent_info_init (GtkRecentInfo *info)
+{
+}
static GtkRecentInfo *
gtk_recent_info_new (const gchar *uri)
@@ -1484,7 +1491,8 @@ gtk_recent_info_new (const gchar *uri)
g_assert (uri != NULL);
- info = g_new0 (GtkRecentInfo, 1);
+ info = g_object_new (GTK_TYPE_RECENT_INFO, NULL);
+
info->uri = g_strdup (uri);
info->applications = NULL;
@@ -1492,19 +1500,15 @@ gtk_recent_info_new (const gchar *uri)
info->groups = NULL;
- info->ref_count = 1;
-
return info;
}
static void
-gtk_recent_info_free (GtkRecentInfo *recent_info)
+gtk_recent_info_finalize (GObject *object)
{
+ GtkRecentInfo *recent_info = GTK_RECENT_INFO (object);
int i;
- if (!recent_info)
- return;
-
g_free (recent_info->uri);
g_free (recent_info->display_name);
g_free (recent_info->description);
@@ -1527,46 +1531,15 @@ gtk_recent_info_free (GtkRecentInfo *recent_info)
g_free (recent_info->groups);
- g_free (recent_info);
+ G_OBJECT_CLASS (gtk_recent_info_parent_class)->finalize (object);
}
-/**
- * gtk_recent_info_ref:
- * @info: a #GtkRecentInfo
- *
- * Increases the reference count of @recent_info by one.
- *
- * Returns: the recent info object with its reference count
- * increased by one
- */
-GtkRecentInfo *
-gtk_recent_info_ref (GtkRecentInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
- g_return_val_if_fail (info->ref_count > 0, NULL);
-
- info->ref_count += 1;
-
- return info;
-}
-
-/**
- * gtk_recent_info_unref:
- * @info: a #GtkRecentInfo
- *
- * Decreases the reference count of @info by one. If the reference
- * count reaches zero, @info is deallocated, and the memory freed.
- */
-void
-gtk_recent_info_unref (GtkRecentInfo *info)
+static void
+gtk_recent_info_class_init (GtkRecentInfoClass *class)
{
- g_return_if_fail (info != NULL);
- g_return_if_fail (info->ref_count > 0);
-
- info->ref_count -= 1;
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
- if (info->ref_count == 0)
- gtk_recent_info_free (info);
+ object_class->finalize = gtk_recent_info_finalize;
}
/**
diff --git a/gtk/gtkrecentmanager.h b/gtk/gtkrecentmanager.h
index cd82c6b9f5..400d48721c 100644
--- a/gtk/gtkrecentmanager.h
+++ b/gtk/gtkrecentmanager.h
@@ -32,6 +32,9 @@ G_BEGIN_DECLS
#define GTK_TYPE_RECENT_INFO (gtk_recent_info_get_type ())
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkRecentInfo, gtk_recent_info, GTK, RECENT_INFO, GObject)
+
#define GTK_TYPE_RECENT_MANAGER (gtk_recent_manager_get_type ())
#define GTK_RECENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_TYPE_RECENT_MANAGER, GtkRecentManager))
#define GTK_IS_RECENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_MANAGER))
@@ -39,7 +42,6 @@ G_BEGIN_DECLS
#define GTK_IS_RECENT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_MANAGER))
#define GTK_RECENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_MANAGER,
GtkRecentManagerClass))
-typedef struct _GtkRecentInfo GtkRecentInfo;
typedef struct _GtkRecentData GtkRecentData;
typedef struct _GtkRecentManager GtkRecentManager;
typedef struct _GtkRecentManagerClass GtkRecentManagerClass;
@@ -189,15 +191,6 @@ GDK_AVAILABLE_IN_ALL
gint gtk_recent_manager_purge_items (GtkRecentManager *manager,
GError **error);
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_info_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkRecentInfo * gtk_recent_info_ref (GtkRecentInfo *info);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_info_unref (GtkRecentInfo *info);
-
GDK_AVAILABLE_IN_ALL
const gchar * gtk_recent_info_get_uri (GtkRecentInfo *info);
GDK_AVAILABLE_IN_ALL
diff --git a/testsuite/gtk/recentmanager.c b/testsuite/gtk/recentmanager.c
index e8acfac77f..3af46caefc 100644
--- a/testsuite/gtk/recentmanager.c
+++ b/testsuite/gtk/recentmanager.c
@@ -247,7 +247,7 @@ recent_manager_lookup_item (void)
g_assert (gtk_recent_info_has_application (info, "testrecentchooser"));
- gtk_recent_info_unref (info);
+ g_object_unref (info);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]