[libgepub/wip/cosimoc/api-rework: 2/13] widget: simplify code



commit 99aeb3dab9e3c65e09c9731710077f54a59f216c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jun 18 11:58:41 2016 -0700

    widget: simplify code

 libgepub/gepub-widget.c |   22 +++++-----------------
 libgepub/gepub-widget.h |    2 +-
 2 files changed, 6 insertions(+), 18 deletions(-)
---
diff --git a/libgepub/gepub-widget.c b/libgepub/gepub-widget.c
index 729ffa6..eff8237 100644
--- a/libgepub/gepub-widget.c
+++ b/libgepub/gepub-widget.c
@@ -72,10 +72,7 @@ gepub_widget_finalize (GObject *object)
 {
     GepubWidget *widget = GEPUB_WIDGET (object);
 
-    if (widget->doc) {
-        g_object_unref (widget->doc);
-        widget->doc = NULL;
-    }
+    g_clear_object (&widget->doc);
 
     G_OBJECT_CLASS (gepub_widget_parent_class)->finalize (object);
 }
@@ -108,20 +105,14 @@ gepub_widget_class_init (GepubWidgetClass *klass)
 
 /**
  * gepub_widget_new:
- * @path: the epub doc path
- * @error: location to store a #GError, or %NULL
  *
  * Returns: (transfer full): the new GepubWidget created
  */
 GtkWidget *
-gepub_widget_new (const gchar *path)
+gepub_widget_new (void)
 {
-    GepubWidget *widget = g_object_new (GEPUB_TYPE_WIDGET,
-                                        NULL);
-
-    widget->doc = NULL;
-
-    return GTK_WIDGET (widget);
+  return g_object_new (GEPUB_TYPE_WIDGET,
+                       NULL);
 }
 
 /**
@@ -146,10 +137,7 @@ gepub_widget_get_doc (GepubWidget *widget)
 void
 gepub_widget_load_epub (GepubWidget *widget, const gchar *path)
 {
-    if (widget->doc) {
-        g_object_unref (widget->doc);
-        widget->doc = NULL;
-    }
+    g_clear_object (&widget->doc);
 
     widget->doc = gepub_doc_new (path);
     gepub_widget_reload (widget);
diff --git a/libgepub/gepub-widget.h b/libgepub/gepub-widget.h
index dc1bf0d..93aaad1 100644
--- a/libgepub/gepub-widget.h
+++ b/libgepub/gepub-widget.h
@@ -40,7 +40,7 @@ typedef struct _GepubWidgetClass GepubWidgetClass;
 
 GType             gepub_widget_get_type                        (void) G_GNUC_CONST;
 
-GtkWidget        *gepub_widget_new                             ();
+GtkWidget        *gepub_widget_new                             (void);
 GepubDoc         *gepub_widget_get_doc                         (GepubWidget *widget);
 void              gepub_widget_load_epub                       (GepubWidget *widget, const gchar *path);
 void              gepub_widget_reload                          (GepubWidget *widget);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]