[seahorse/wip/nielsdg/cleanup-pgp-more: 3/6] pgp: Photo: Use G_DECLARE_DERIVABLE_TYPE
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/wip/nielsdg/cleanup-pgp-more: 3/6] pgp: Photo: Use G_DECLARE_DERIVABLE_TYPE
- Date: Tue, 29 Jan 2019 13:00:49 +0000 (UTC)
commit 41816438326b30226cee9cc16c0c31e0c9d63089
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Jan 29 09:32:53 2019 +0100
pgp: Photo: Use G_DECLARE_DERIVABLE_TYPE
pgp/seahorse-pgp-photo.c | 62 ++++++++++++++++++++++--------------------------
pgp/seahorse-pgp-photo.h | 19 +++------------
2 files changed, 31 insertions(+), 50 deletions(-)
---
diff --git a/pgp/seahorse-pgp-photo.c b/pgp/seahorse-pgp-photo.c
index 2d3e3a3d..4935473a 100644
--- a/pgp/seahorse-pgp-photo.c
+++ b/pgp/seahorse-pgp-photo.c
@@ -30,20 +30,15 @@ enum {
PROP_PIXBUF
};
-G_DEFINE_TYPE (SeahorsePgpPhoto, seahorse_pgp_photo, G_TYPE_OBJECT);
+typedef struct _SeahorsePgpPhotoPrivate {
+ GdkPixbuf *pixbuf;
+} SeahorsePgpPhotoPrivate;
-struct _SeahorsePgpPhotoPrivate {
- GdkPixbuf *pixbuf;
-};
-
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
+G_DEFINE_TYPE_WITH_PRIVATE (SeahorsePgpPhoto, seahorse_pgp_photo, G_TYPE_OBJECT);
static void
seahorse_pgp_photo_init (SeahorsePgpPhoto *self)
{
- self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_PGP_TYPE_PHOTO, SeahorsePgpPhotoPrivate);
}
static void
@@ -51,7 +46,7 @@ seahorse_pgp_photo_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
SeahorsePgpPhoto *self = SEAHORSE_PGP_PHOTO (object);
-
+
switch (prop_id) {
case PROP_PIXBUF:
g_value_set_object (value, seahorse_pgp_photo_get_pixbuf (self));
@@ -60,8 +55,8 @@ seahorse_pgp_photo_get_property (GObject *object, guint prop_id,
}
static void
-seahorse_pgp_photo_set_property (GObject *object, guint prop_id, const GValue *value,
- GParamSpec *pspec)
+seahorse_pgp_photo_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
{
SeahorsePgpPhoto *self = SEAHORSE_PGP_PHOTO (object);
@@ -76,37 +71,30 @@ static void
seahorse_pgp_photo_finalize (GObject *gobject)
{
SeahorsePgpPhoto *self = SEAHORSE_PGP_PHOTO (gobject);
+ SeahorsePgpPhotoPrivate *priv =
+ seahorse_pgp_photo_get_instance_private (self);
+
+ g_clear_object (&priv->pixbuf);
- if (self->pv->pixbuf)
- g_object_unref (self->pv->pixbuf);
- self->pv->pixbuf = NULL;
-
G_OBJECT_CLASS (seahorse_pgp_photo_parent_class)->finalize (gobject);
}
static void
seahorse_pgp_photo_class_init (SeahorsePgpPhotoClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- seahorse_pgp_photo_parent_class = g_type_class_peek_parent (klass);
- g_type_class_add_private (klass, sizeof (SeahorsePgpPhotoPrivate));
-
gobject_class->finalize = seahorse_pgp_photo_finalize;
gobject_class->set_property = seahorse_pgp_photo_set_property;
gobject_class->get_property = seahorse_pgp_photo_get_property;
-
+
g_object_class_install_property (gobject_class, PROP_PIXBUF,
g_param_spec_object ("pixbuf", "Pixbuf", "Photo Pixbuf",
GDK_TYPE_PIXBUF, G_PARAM_READWRITE));
}
-/* -----------------------------------------------------------------------------
- * PUBLIC
- */
-
-SeahorsePgpPhoto*
-seahorse_pgp_photo_new (GdkPixbuf *pixbuf)
+SeahorsePgpPhoto*
+seahorse_pgp_photo_new (GdkPixbuf *pixbuf)
{
return g_object_new (SEAHORSE_PGP_TYPE_PHOTO, "pixbuf", pixbuf, NULL);
}
@@ -114,20 +102,26 @@ seahorse_pgp_photo_new (GdkPixbuf *pixbuf)
GdkPixbuf*
seahorse_pgp_photo_get_pixbuf (SeahorsePgpPhoto *self)
{
+ SeahorsePgpPhotoPrivate *priv;
+
g_return_val_if_fail (SEAHORSE_PGP_IS_PHOTO (self), NULL);
- return self->pv->pixbuf;
+
+ priv = seahorse_pgp_photo_get_instance_private (self);
+ return priv->pixbuf;
}
void
seahorse_pgp_photo_set_pixbuf (SeahorsePgpPhoto *self, GdkPixbuf* pixbuf)
{
+ SeahorsePgpPhotoPrivate *priv;
+
g_return_if_fail (SEAHORSE_PGP_IS_PHOTO (self));
- if (self->pv->pixbuf)
- g_object_unref (self->pv->pixbuf);
- self->pv->pixbuf = pixbuf;
- if (self->pv->pixbuf)
- g_object_ref (self->pv->pixbuf);
-
+ priv = seahorse_pgp_photo_get_instance_private (self);
+ g_clear_object (&priv->pixbuf);
+ priv->pixbuf = pixbuf;
+ if (priv->pixbuf)
+ g_object_ref (priv->pixbuf);
+
g_object_notify (G_OBJECT (self), "pixbuf");
}
diff --git a/pgp/seahorse-pgp-photo.h b/pgp/seahorse-pgp-photo.h
index 513fa9da..4a9e8dc6 100644
--- a/pgp/seahorse-pgp-photo.h
+++ b/pgp/seahorse-pgp-photo.h
@@ -23,27 +23,14 @@
#include <gtk/gtk.h>
#define SEAHORSE_PGP_TYPE_PHOTO (seahorse_pgp_photo_get_type ())
-#define SEAHORSE_PGP_PHOTO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_PGP_TYPE_PHOTO,
SeahorsePgpPhoto))
-#define SEAHORSE_PGP_PHOTO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_PGP_TYPE_PHOTO,
SeahorsePgpPhotoClass))
-#define SEAHORSE_PGP_IS_PHOTO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SEAHORSE_PGP_TYPE_PHOTO))
-#define SEAHORSE_PGP_IS_PHOTO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SEAHORSE_PGP_TYPE_PHOTO))
-#define SEAHORSE_PGP_PHOTO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SEAHORSE_PGP_TYPE_PHOTO,
SeahorsePgpPhotoClass))
-
-typedef struct _SeahorsePgpPhoto SeahorsePgpPhoto;
-typedef struct _SeahorsePgpPhotoClass SeahorsePgpPhotoClass;
-typedef struct _SeahorsePgpPhotoPrivate SeahorsePgpPhotoPrivate;
-
-struct _SeahorsePgpPhoto {
- GObject parent;
- SeahorsePgpPhotoPrivate *pv;
-};
+G_DECLARE_DERIVABLE_TYPE (SeahorsePgpPhoto, seahorse_pgp_photo,
+ SEAHORSE_PGP, PHOTO,
+ GObject);
struct _SeahorsePgpPhotoClass {
GObjectClass parent_class;
};
-GType seahorse_pgp_photo_get_type (void);
-
SeahorsePgpPhoto* seahorse_pgp_photo_new (GdkPixbuf *pixbuf);
GdkPixbuf* seahorse_pgp_photo_get_pixbuf (SeahorsePgpPhoto *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]