[seahorse/wip/nielsdg/remove-more-deprecated: 6/8] ObjectModel: Don't use g_type_class_add_private)
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/wip/nielsdg/remove-more-deprecated: 6/8] ObjectModel: Don't use g_type_class_add_private)
- Date: Tue, 19 Feb 2019 05:43:28 +0000 (UTC)
commit 44ec1f85ef7f708f36e3f44f8a46027de93f3911
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Feb 19 06:21:51 2019 +0100
ObjectModel: Don't use g_type_class_add_private)
It's been deprecated a while now in favor of `G_ADD_PRIVATE ()`
libseahorse/seahorse-object-model.c | 228 +++++++++++++++++-------------------
libseahorse/seahorse-object-model.h | 48 ++------
2 files changed, 115 insertions(+), 161 deletions(-)
---
diff --git a/libseahorse/seahorse-object-model.c b/libseahorse/seahorse-object-model.c
index 655c8ee4..a8f5ee72 100644
--- a/libseahorse/seahorse-object-model.c
+++ b/libseahorse/seahorse-object-model.c
@@ -16,7 +16,7 @@
* along with this program; if not, see
* <http://www.gnu.org/licenses/>.
*/
-
+
#include "config.h"
#include <string.h>
@@ -25,6 +25,13 @@
#include "seahorse-object-model.h"
#include "seahorse-marshal.h"
+/**
+ * SeahorseObjectModel:
+ *
+ * A GtkTreeModel that can assign certain rows as
+ * 'key rows' which are updated when a key is updated.
+ */
+
enum {
PROP_0,
PROP_DATA_COLUMN,
@@ -37,46 +44,43 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-typedef struct _SeahorseObjectModelPrivate {
+struct _SeahorseObjectModel {
+ GtkTreeStore parent;
GHashTable *rows;
gint data_column;
-} SeahorseObjectModelPrivate;
+};
G_DEFINE_TYPE (SeahorseObjectModel, seahorse_object_model, GTK_TYPE_TREE_STORE);
-#define SEAHORSE_OBJECT_MODEL_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SEAHORSE_TYPE_OBJECT_MODEL, SeahorseObjectModelPrivate))
-
/* Internal data stored at 0 in the tree store in order to keep track
* of the location, key-store and key.
*/
typedef struct {
- SeahorseObjectModel *self;
- GPtrArray *refs; /* GtkTreeRowReference pointers */
- GObject *object; /* The key we're dealing with */
- gpointer binding;
+ SeahorseObjectModel *self;
+ GPtrArray *refs; /* GtkTreeRowReference pointers */
+ GObject *object; /* The key we're dealing with */
+ gpointer binding;
} SeahorseObjectRow;
/* -----------------------------------------------------------------------------
- * INTERNAL
+ * INTERNAL
*/
static void
key_notify (GObject *object,
SeahorseObjectModel *self)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
SeahorseObjectRow *skrow;
GtkTreeIter iter;
GtkTreePath *path;
guint i;
- skrow = g_hash_table_lookup (pv->rows, object);
+ skrow = g_hash_table_lookup (self->rows, object);
if (!skrow)
return;
-
+
for (i = 0; i < skrow->refs->len; i++) {
-
+
path = gtk_tree_row_reference_get_path (g_ptr_array_index (skrow->refs, i));
if (path) {
gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
@@ -89,13 +93,13 @@ key_notify (GObject *object,
static void
key_destroyed (gpointer data, GObject *was)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (data);
- SeahorseObjectRow *skrow = g_hash_table_lookup (pv->rows, was);
- if (skrow) {
- skrow->object = NULL;
- skrow->binding = NULL;
- g_hash_table_remove (pv->rows, was);
- }
+ SeahorseObjectModel *self = SEAHORSE_OBJECT_MODEL (data);
+ SeahorseObjectRow *skrow = g_hash_table_lookup (self->rows, was);
+ if (skrow) {
+ skrow->object = NULL;
+ skrow->binding = NULL;
+ g_hash_table_remove (self->rows, was);
+ }
}
@@ -112,7 +116,7 @@ key_row_new (SeahorseObjectModel *self,
GObject *object)
{
SeahorseObjectRow *skrow;
-
+
g_assert (SEAHORSE_IS_OBJECT_MODEL (self));
g_assert (G_IS_OBJECT (object));
@@ -121,9 +125,9 @@ key_row_new (SeahorseObjectModel *self,
skrow->self = self;
skrow->object = object;
skrow->binding = seahorse_bind_objects (NULL, object, (SeahorseTransfer)key_notify, self);
-
+
g_object_weak_ref (G_OBJECT (object), key_destroyed, self);
-
+
return skrow;
}
@@ -131,60 +135,57 @@ static void
key_row_free (SeahorseObjectRow *skrow)
{
SeahorseObjectModel *self = skrow->self;
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
GtkTreeRowReference *ref;
GtkTreePath *path;
GtkTreeIter iter;
guint i;
-
- g_return_if_fail (pv->data_column != -1);
-
+
+ g_return_if_fail (self->data_column != -1);
+
for (i = 0; i < skrow->refs->len; i++) {
-
+
ref = (GtkTreeRowReference*)g_ptr_array_index (skrow->refs, i);
if (ref) {
path = gtk_tree_row_reference_get_path (ref);
if (path) {
gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
- gtk_tree_store_set (GTK_TREE_STORE (self), &iter,
- pv->data_column, NULL, -1);
+ gtk_tree_store_set (GTK_TREE_STORE (self), &iter,
+ self->data_column, NULL, -1);
gtk_tree_path_free (path);
}
gtk_tree_row_reference_free (ref);
}
-
+
}
-
+
if (skrow->binding)
- seahorse_bind_disconnect (skrow->binding);
+ seahorse_bind_disconnect (skrow->binding);
if (skrow->object)
- g_object_weak_unref (G_OBJECT (skrow->object), key_destroyed, skrow->self);
+ g_object_weak_unref (G_OBJECT (skrow->object), key_destroyed, skrow->self);
g_ptr_array_free (skrow->refs, TRUE);
g_free (skrow);
}
static void
-row_inserted (SeahorseObjectModel *self, GtkTreePath *path, GtkTreeIter *iter,
+row_inserted (SeahorseObjectModel *self, GtkTreePath *path, GtkTreeIter *iter,
gpointer user_data)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
- g_return_if_fail (pv->data_column != -1);
+ g_return_if_fail (self->data_column != -1);
/* XXX: The following line causes problems with GtkTreeModelFilter */
- /* gtk_tree_store_set (GTK_TREE_STORE (self), iter, pv->data_column, NULL, -1); */
+ /* gtk_tree_store_set (GTK_TREE_STORE (self), iter, self->data_column, NULL, -1); */
}
/* -----------------------------------------------------------------------------
- * OBJECT
+ * OBJECT
*/
static void
seahorse_object_model_init (SeahorseObjectModel *self)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
- pv->rows = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ self->rows = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, (GDestroyNotify)key_row_free);
- pv->data_column = -1;
+ self->data_column = -1;
g_signal_connect (self, "row-inserted", G_CALLBACK (row_inserted), NULL);
}
@@ -193,12 +194,11 @@ seahorse_object_model_set_property (GObject *gobject, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
SeahorseObjectModel *self = SEAHORSE_OBJECT_MODEL (gobject);
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
switch (prop_id) {
case PROP_DATA_COLUMN:
- g_assert (pv->data_column == -1);
- pv->data_column = g_value_get_uint (value);
+ g_assert (self->data_column == -1);
+ self->data_column = g_value_get_uint (value);
break;
}
}
@@ -208,11 +208,10 @@ seahorse_object_model_get_property (GObject *gobject, guint prop_id,
GValue *value, GParamSpec *pspec)
{
SeahorseObjectModel *self = SEAHORSE_OBJECT_MODEL (gobject);
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
switch (prop_id) {
case PROP_DATA_COLUMN:
- g_value_set_uint (value, pv->data_column);
+ g_value_set_uint (value, self->data_column);
break;
}
}
@@ -221,10 +220,9 @@ static void
seahorse_object_model_dispose (GObject *gobject)
{
SeahorseObjectModel *self = SEAHORSE_OBJECT_MODEL (gobject);
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
-
+
/* Release all our pointers and stuff */
- g_hash_table_foreach_remove (pv->rows, (GHRFunc)remove_each, self);
+ g_hash_table_foreach_remove (self->rows, (GHRFunc)remove_each, self);
G_OBJECT_CLASS (seahorse_object_model_parent_class)->dispose (gobject);
}
@@ -232,52 +230,47 @@ static void
seahorse_object_model_finalize (GObject *gobject)
{
SeahorseObjectModel *self = SEAHORSE_OBJECT_MODEL (gobject);
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
- if (pv->rows)
- g_hash_table_destroy (pv->rows);
- pv->rows = NULL;
-
+ if (self->rows)
+ g_hash_table_destroy (self->rows);
+ self->rows = NULL;
+
G_OBJECT_CLASS (seahorse_object_model_parent_class)->finalize (gobject);
}
static void
seahorse_object_model_class_init (SeahorseObjectModelClass *klass)
{
- GObjectClass *gobject_class;
-
- seahorse_object_model_parent_class = g_type_class_peek_parent (klass);
- gobject_class = G_OBJECT_CLASS (klass);
-
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
gobject_class->dispose = seahorse_object_model_dispose;
gobject_class->finalize = seahorse_object_model_finalize;
gobject_class->set_property = seahorse_object_model_set_property;
gobject_class->get_property = seahorse_object_model_get_property;
-
+
g_object_class_install_property (gobject_class, PROP_DATA_COLUMN,
g_param_spec_uint ("data-column", "Column data is stored", "Column where internal data is stored",
0, ~0, 0, G_PARAM_READWRITE | G_PARAM_READWRITE));
- signals[UPDATE_ROW] = g_signal_new ("update-row", SEAHORSE_TYPE_OBJECT_MODEL,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (SeahorseObjectModelClass, update_row),
- NULL, NULL, seahorse_marshal_VOID__OBJECT_POINTER, G_TYPE_NONE, 2, SEAHORSE_TYPE_OBJECT,
G_TYPE_POINTER);
-
- g_type_class_add_private (klass, sizeof (SeahorseObjectModelPrivate));
+ signals[UPDATE_ROW] = g_signal_new ("update-row", SEAHORSE_TYPE_OBJECT_MODEL,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ seahorse_marshal_VOID__OBJECT_POINTER,
+ G_TYPE_NONE, 2, SEAHORSE_TYPE_OBJECT, G_TYPE_POINTER);
}
/* -----------------------------------------------------------------------------
- * PUBLIC
+ * PUBLIC
*/
-SeahorseObjectModel*
+SeahorseObjectModel*
seahorse_object_model_new (gint n_columns, GType *types)
{
SeahorseObjectModel *model;
-
+
model = g_object_new (SEAHORSE_TYPE_OBJECT_MODEL, NULL);
seahorse_object_model_set_column_types (model, n_columns, types);
-
+
return model;
}
@@ -285,18 +278,17 @@ void
seahorse_object_model_set_column_types (SeahorseObjectModel *self, gint n_columns,
GType *types)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
GType *itypes;
-
+
g_return_if_fail (SEAHORSE_IS_OBJECT_MODEL (self));
itypes = g_new0(GType, n_columns + 1);
memcpy (itypes, types, n_columns * sizeof (GType));
itypes[n_columns] = G_TYPE_POINTER;
- pv->data_column = n_columns;
+ self->data_column = n_columns;
gtk_tree_store_set_column_types (GTK_TREE_STORE (self), n_columns + 1, itypes);
-
+
g_free (itypes);
}
@@ -305,65 +297,64 @@ seahorse_object_model_set_row_object (SeahorseObjectModel *self,
GtkTreeIter *iter,
GObject *object)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
SeahorseObjectRow *skrow;
GtkTreePath *path;
GtkTreePath *ipath;
guint i;
-
+
g_return_if_fail (SEAHORSE_IS_OBJECT_MODEL (self));
g_return_if_fail (G_IS_OBJECT (object) || object == NULL);
- g_return_if_fail (pv->data_column >= 0);
-
+ g_return_if_fail (self->data_column >= 0);
+
/* Add the row/key association */
if (object) {
-
+
/* Do we already have a row for this key? */
- skrow = (SeahorseObjectRow*)g_hash_table_lookup (pv->rows, object);
+ skrow = (SeahorseObjectRow*)g_hash_table_lookup (self->rows, object);
if (!skrow) {
skrow = key_row_new (self, object);
/* Put it in our row cache */
- g_hash_table_replace (pv->rows, object, skrow);
+ g_hash_table_replace (self->rows, object, skrow);
}
-
+
path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), iter);
g_ptr_array_add (skrow->refs, gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path));
gtk_tree_path_free (path);
-
+
/* Remove the row/key association */
} else {
-
- gtk_tree_model_get (GTK_TREE_MODEL (self), iter, pv->data_column, &skrow, -1);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self), iter, self->data_column, &skrow, -1);
if (skrow) {
-
+
ipath = gtk_tree_model_get_path (GTK_TREE_MODEL (self), iter);
g_return_if_fail (ipath != NULL);
-
+
for (i = 0; i < skrow->refs->len; i++) {
-
+
path = gtk_tree_row_reference_get_path (g_ptr_array_index (skrow->refs, i));
-
+
/* Check if they're the same or invalid, remove */
if (!path || gtk_tree_path_compare (path, ipath) == 0) {
gtk_tree_row_reference_free (g_ptr_array_index (skrow->refs, i));
g_ptr_array_remove_index_fast (skrow->refs, i);
i--;
}
-
+
if (path)
gtk_tree_path_free (path);
}
-
+
/* If we no longer have rows associated with this key, then remove */
if (skrow->refs->len == 0)
- g_hash_table_remove (pv->rows, skrow->object);
+ g_hash_table_remove (self->rows, skrow->object);
}
}
-
- gtk_tree_store_set (GTK_TREE_STORE (self), iter,
- pv->data_column, object ? skrow : NULL, -1);
-
+
+ gtk_tree_store_set (GTK_TREE_STORE (self), iter,
+ self->data_column, object ? skrow : NULL, -1);
+
if (object)
key_notify (object, self);
}
@@ -371,13 +362,12 @@ seahorse_object_model_set_row_object (SeahorseObjectModel *self,
GObject *
seahorse_object_model_get_row_key (SeahorseObjectModel *self, GtkTreeIter *iter)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
SeahorseObjectRow *skrow;
-
+
g_return_val_if_fail (SEAHORSE_IS_OBJECT_MODEL (self), NULL);
- g_return_val_if_fail (pv->data_column >= 0, NULL);
-
- gtk_tree_model_get (GTK_TREE_MODEL (self), iter, pv->data_column, &skrow, -1);
+ g_return_val_if_fail (self->data_column >= 0, NULL);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self), iter, self->data_column, &skrow, -1);
if (!skrow)
return NULL;
g_assert (G_IS_OBJECT (skrow->object));
@@ -388,22 +378,21 @@ void
seahorse_object_model_remove_rows_for_object (SeahorseObjectModel *self,
GObject *object)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
SeahorseObjectRow *skrow;
GtkTreeIter iter;
GtkTreePath *path;
guint i;
-
+
g_return_if_fail (SEAHORSE_IS_OBJECT_MODEL (self));
g_return_if_fail (G_IS_OBJECT (object));
- g_return_if_fail (pv->data_column >= 0);
-
- skrow = (SeahorseObjectRow*)g_hash_table_lookup (pv->rows, object);
- if (!skrow)
+ g_return_if_fail (self->data_column >= 0);
+
+ skrow = (SeahorseObjectRow*)g_hash_table_lookup (self->rows, object);
+ if (!skrow)
return;
-
+
for (i = 0; i < skrow->refs->len; i++) {
-
+
path = gtk_tree_row_reference_get_path (g_ptr_array_index (skrow->refs, i));
if (path) {
gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
@@ -411,31 +400,30 @@ seahorse_object_model_remove_rows_for_object (SeahorseObjectModel *self,
gtk_tree_path_free (path);
}
}
-
+
/* We no longer have rows associated with this key, then remove */
- g_hash_table_remove (pv->rows, object);
+ g_hash_table_remove (self->rows, object);
}
GList*
seahorse_object_model_get_rows_for_object (SeahorseObjectModel *self,
GObject *object)
{
- SeahorseObjectModelPrivate *pv = SEAHORSE_OBJECT_MODEL_GET_PRIVATE (self);
GList *rows = NULL;
SeahorseObjectRow *skrow;
GtkTreeIter *iter;
GtkTreePath *path;
guint i;
-
+
g_return_val_if_fail (SEAHORSE_IS_OBJECT_MODEL (self), NULL);
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
- skrow = (SeahorseObjectRow*)g_hash_table_lookup (pv->rows, object);
- if (!skrow)
+ skrow = (SeahorseObjectRow*)g_hash_table_lookup (self->rows, object);
+ if (!skrow)
return NULL;
-
+
for (i = 0; i < skrow->refs->len; i++) {
-
+
path = gtk_tree_row_reference_get_path (g_ptr_array_index (skrow->refs, i));
if (path) {
iter = g_new0(GtkTreeIter, 1);
@@ -444,7 +432,7 @@ seahorse_object_model_get_rows_for_object (SeahorseObjectModel *self,
gtk_tree_path_free (path);
}
}
-
+
return rows;
}
diff --git a/libseahorse/seahorse-object-model.h b/libseahorse/seahorse-object-model.h
index 9a7d3fa1..aa56c31a 100644
--- a/libseahorse/seahorse-object-model.h
+++ b/libseahorse/seahorse-object-model.h
@@ -16,54 +16,22 @@
* along with this program; if not, see
* <http://www.gnu.org/licenses/>.
*/
-
-#ifndef __SEAHORSE_OBJECT_MODEL_H__
-#define __SEAHORSE_OBJECT_MODEL_H__
+
+#pragma once
#include <gtk/gtk.h>
#include "seahorse-common.h"
-#define SEAHORSE_TYPE_OBJECT_MODEL (seahorse_object_model_get_type ())
-#define SEAHORSE_OBJECT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
SEAHORSE_TYPE_OBJECT_MODEL, SeahorseObjectModel))
-#define SEAHORSE_OBJECT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
SEAHORSE_TYPE_OBJECT_MODEL, SeahorseObjectModelClass))
-#define SEAHORSE_IS_OBJECT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
SEAHORSE_TYPE_OBJECT_MODEL))
-#define SEAHORSE_IS_OBJECT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
SEAHORSE_TYPE_OBJECT_MODEL))
-#define SEAHORSE_OBJECT_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
SEAHORSE_TYPE_OBJECT_MODEL, SeahorseObjectModelClass))
-
-typedef struct _SeahorseObjectModel SeahorseObjectModel;
-typedef struct _SeahorseObjectModelClass SeahorseObjectModelClass;
-
-/**
- * SeahorseObjectModel:
- * @parent: The parent #GtkTreeStore
- *
- * A GtkTreeModel that can assign certain rows as
- * 'key rows' which are updated when a key is updated.
- *
- * Signals:
- * update-row: A request to update a row
- */
-
-struct _SeahorseObjectModel {
- GtkTreeStore parent;
-};
-
-struct _SeahorseObjectModelClass {
- GtkTreeStoreClass parent_class;
-
- /* A key was added to this view */
- void (*update_row) (SeahorseObjectModel *self,
- GObject *object,
- GtkTreeIter *iter);
-};
-
-GType seahorse_object_model_get_type (void);
+#define SEAHORSE_TYPE_OBJECT_MODEL (seahorse_object_model_get_type ())
+G_DECLARE_FINAL_TYPE (SeahorseObjectModel, seahorse_object_model,
+ SEAHORSE, OBJECT_MODEL,
+ GtkTreeStore)
SeahorseObjectModel* seahorse_object_model_new (gint n_columns,
GType *types);
-void seahorse_object_model_set_column_types (SeahorseObjectModel *self,
+void seahorse_object_model_set_column_types (SeahorseObjectModel *self,
gint n_columns,
GType *types);
@@ -81,5 +49,3 @@ void seahorse_object_model_remove_rows_for_object (SeahorseObjec
GObject *object);
void seahorse_object_model_free_rows (GList *rows);
-
-#endif /* __SEAHORSE_OBJECT_MODEL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]