[buoh/cleanups: 10/31] Rewrite comic-manager to use G_DECLARE_DERIVABLE_TYPE
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [buoh/cleanups: 10/31] Rewrite comic-manager to use G_DECLARE_DERIVABLE_TYPE
- Date: Wed, 23 Jan 2019 11:20:19 +0000 (UTC)
commit a4356ad83cfed224b3e4cee1a0d5c24ce3b3965a
Author: Jan Tojnar <jtojnar gmail com>
Date: Tue Sep 25 02:07:07 2018 +0200
Rewrite comic-manager to use G_DECLARE_DERIVABLE_TYPE
src/buoh-comic-manager.c | 113 +++++++++++++++++++----------------------------
src/buoh-comic-manager.h | 19 +-------
2 files changed, 48 insertions(+), 84 deletions(-)
---
diff --git a/src/buoh-comic-manager.c b/src/buoh-comic-manager.c
index 636e09e..850557e 100644
--- a/src/buoh-comic-manager.c
+++ b/src/buoh-comic-manager.c
@@ -34,7 +34,7 @@ enum {
PROP_CURRENT
};
-struct _BuohComicManagerPrivate {
+typedef struct {
gchar *author;
gchar *title;
gchar *language;
@@ -42,7 +42,7 @@ struct _BuohComicManagerPrivate {
gchar *generic_uri;
GList *comic_list;
GList *current;
-};
+} BuohComicManagerPrivate;
static void buoh_comic_manager_init (BuohComicManager *comic_manager);
static void buoh_comic_manager_class_init (BuohComicManagerClass *klass);
@@ -61,15 +61,6 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (BuohComicManager, buoh_comic_manager, G_TYP
static void
buoh_comic_manager_init (BuohComicManager *comic_manager)
{
- comic_manager->priv = buoh_comic_manager_get_instance_private (comic_manager);
-
- comic_manager->priv->author = NULL;
- comic_manager->priv->title = NULL;
- comic_manager->priv->language = NULL;
- comic_manager->priv->id = NULL;
- comic_manager->priv->generic_uri = NULL;
- comic_manager->priv->current = NULL;
- comic_manager->priv->comic_list = NULL;
}
static void
@@ -138,38 +129,18 @@ static void
buoh_comic_manager_finalize (GObject *object)
{
BuohComicManager *comic_manager = BUOH_COMIC_MANAGER (object);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- if (comic_manager->priv->author) {
- g_free (comic_manager->priv->author);
- comic_manager->priv->author = NULL;
- }
-
- if (comic_manager->priv->title) {
- g_free (comic_manager->priv->title);
- comic_manager->priv->title = NULL;
- }
-
- if (comic_manager->priv->language) {
- g_free (comic_manager->priv->language);
- comic_manager->priv->language = NULL;
- }
+ g_clear_pointer (&priv->author, g_free);
+ g_clear_pointer (&priv->title, g_free);
+ g_clear_pointer (&priv->language, g_free);
+ g_clear_pointer (&priv->id, g_free);
+ g_clear_pointer (&priv->generic_uri, g_free);
- if (comic_manager->priv->id) {
- g_free (comic_manager->priv->id);
- comic_manager->priv->id = NULL;
- }
-
- if (comic_manager->priv->generic_uri) {
- g_free (comic_manager->priv->generic_uri);
- comic_manager->priv->generic_uri = NULL;
- }
-
- if (comic_manager->priv->comic_list) {
- g_list_foreach (comic_manager->priv->comic_list,
+ if (priv->comic_list) {
+ g_list_foreach (priv->comic_list,
(GFunc) g_object_unref, NULL);
- g_list_free (comic_manager->priv->comic_list);
-
- comic_manager->priv->comic_list = NULL;
+ g_clear_pointer (&priv->comic_list, g_list_free);
}
if (G_OBJECT_CLASS (buoh_comic_manager_parent_class)->finalize) {
@@ -208,39 +179,40 @@ buoh_comic_manager_set_property (GObject *object,
GParamSpec *pspec)
{
BuohComicManager *comic_manager = BUOH_COMIC_MANAGER (object);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
switch (prop_id) {
case PROP_TITLE:
- g_free (comic_manager->priv->title);
- comic_manager->priv->title = g_value_dup_string (value);
+ g_free (priv->title);
+ priv->title = g_value_dup_string (value);
break;
case PROP_AUTHOR:
- g_free (comic_manager->priv->author);
- comic_manager->priv->author = g_value_dup_string (value);
+ g_free (priv->author);
+ priv->author = g_value_dup_string (value);
break;
case PROP_LANGUAGE:
- g_free (comic_manager->priv->language);
- comic_manager->priv->language = g_value_dup_string (value);
+ g_free (priv->language);
+ priv->language = g_value_dup_string (value);
break;
case PROP_ID:
- g_free (comic_manager->priv->id);
- comic_manager->priv->id = g_value_dup_string (value);
+ g_free (priv->id);
+ priv->id = g_value_dup_string (value);
break;
case PROP_GENERIC_URI:
- g_free (comic_manager->priv->generic_uri);
- comic_manager->priv->generic_uri = g_value_dup_string (value);
+ g_free (priv->generic_uri);
+ priv->generic_uri = g_value_dup_string (value);
break;
case PROP_LIST:
- comic_manager->priv->comic_list = g_value_get_pointer (value);
+ priv->comic_list = g_value_get_pointer (value);
break;
case PROP_CURRENT:
- comic_manager->priv->current = g_value_get_pointer (value);
+ priv->current = g_value_get_pointer (value);
break;
default:
@@ -255,34 +227,35 @@ buoh_comic_manager_get_property (GObject *object,
GParamSpec *pspec)
{
BuohComicManager *comic_manager = BUOH_COMIC_MANAGER (object);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
switch (prop_id) {
case PROP_TITLE:
- g_value_set_string (value, comic_manager->priv->title);
+ g_value_set_string (value, priv->title);
break;
case PROP_AUTHOR:
- g_value_set_string (value, comic_manager->priv->author);
+ g_value_set_string (value, priv->author);
break;
case PROP_LANGUAGE:
- g_value_set_string (value, comic_manager->priv->language);
+ g_value_set_string (value, priv->language);
break;
case PROP_ID:
- g_value_set_string (value, comic_manager->priv->id);
+ g_value_set_string (value, priv->id);
break;
case PROP_GENERIC_URI:
- g_value_set_string (value, comic_manager->priv->generic_uri);
+ g_value_set_string (value, priv->generic_uri);
break;
case PROP_LIST:
- g_value_set_pointer (value, comic_manager->priv->comic_list);
+ g_value_set_pointer (value, priv->comic_list);
break;
case PROP_CURRENT:
- g_value_set_pointer (value, comic_manager->priv->current);
+ g_value_set_pointer (value, priv->current);
break;
default:
@@ -342,10 +315,11 @@ BuohComic *
buoh_comic_manager_get_current (BuohComicManager *comic_manager)
{
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), NULL);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- if (comic_manager->priv->current != NULL) {
+ if (priv->current != NULL) {
buoh_debug ("get_current");
- return comic_manager->priv->current->data;
+ return priv->current->data;
} else {
if (BUOH_COMIC_MANAGER_GET_CLASS (comic_manager)->get_last) {
return (BUOH_COMIC_MANAGER_GET_CLASS (comic_manager)->get_last) (comic_manager);
@@ -361,10 +335,11 @@ buoh_comic_manager_is_the_last (BuohComicManager *comic_manager)
GList *current;
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), FALSE);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- current = comic_manager->priv->current;
+ current = priv->current;
- return (current == g_list_last (comic_manager->priv->comic_list));
+ return (current == g_list_last (priv->comic_list));
}
gboolean
@@ -383,32 +358,36 @@ const gchar *
buoh_comic_manager_get_title (BuohComicManager *comic_manager)
{
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), NULL);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- return comic_manager->priv->title;
+ return priv->title;
}
const gchar *
buoh_comic_manager_get_author (BuohComicManager *comic_manager)
{
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), NULL);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- return comic_manager->priv->author;
+ return priv->author;
}
const gchar *
buoh_comic_manager_get_language (BuohComicManager *comic_manager)
{
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), NULL);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- return comic_manager->priv->language;
+ return priv->language;
}
const gchar *
buoh_comic_manager_get_id (BuohComicManager *comic_manager)
{
g_return_val_if_fail (BUOH_IS_COMIC_MANAGER (comic_manager), NULL);
+ BuohComicManagerPrivate *priv = buoh_comic_manager_get_instance_private (comic_manager);
- return comic_manager->priv->id;
+ return priv->id;
}
gint
diff --git a/src/buoh-comic-manager.h b/src/buoh-comic-manager.h
index 342ef96..c72e72b 100644
--- a/src/buoh-comic-manager.h
+++ b/src/buoh-comic-manager.h
@@ -24,23 +24,8 @@
G_BEGIN_DECLS
-typedef struct _BuohComicManager BuohComicManager;
-typedef struct _BuohComicManagerClass BuohComicManagerClass;
-typedef struct _BuohComicManagerPrivate BuohComicManagerPrivate;
-
-#define BUOH_TYPE_COMIC_MANAGER (buoh_comic_manager_get_type ())
-#define BUOH_COMIC_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), BUOH_TYPE_COMIC_MANAGER,
BuohComicManager))
-#define BUOH_COMIC_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), BUOH_TYPE_COMIC_MANAGER,
BuohComicManagerClass))
-#define BUOH_IS_COMIC_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), BUOH_TYPE_COMIC_MANAGER))
-#define BUOH_IS_COMIC_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BUOH_TYPE_COMIC_MANAGER))
-#define BUOH_COMIC_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), BUOH_TYPE_COMIC_MANAGER,
BuohComicManagerClass))
-
-
-struct _BuohComicManager {
- GObject parent;
-
- BuohComicManagerPrivate *priv;
-};
+#define BUOH_TYPE_COMIC_MANAGER buoh_comic_manager_get_type ()
+G_DECLARE_DERIVABLE_TYPE (BuohComicManager, buoh_comic_manager, BUOH, COMIC_MANAGER, GObject)
struct _BuohComicManagerClass {
GObjectClass parent_class;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]