[devhelp/wip/stuff: 9/13] assistant: use G_DEFINE_TYPE_WITH_PRIVATE



commit 6c7aab36b60b0c58ccdb545a366518e29866ac42
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Thu Jul 25 11:17:10 2013 +0200

    assistant: use G_DEFINE_TYPE_WITH_PRIVATE

 src/dh-assistant.c |   60 ++++++++++++++++++++++-----------------------------
 1 files changed, 26 insertions(+), 34 deletions(-)
---
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index c6746fd..71dd376 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -34,15 +34,9 @@ typedef struct {
         GtkWidget     *main_box;
         GtkWidget     *view;
         DhSettings    *settings;
-} DhAssistantPriv;
+} DhAssistantPrivate;
 
-static void dh_assistant_class_init (DhAssistantClass *klass);
-static void dh_assistant_init       (DhAssistant      *assistant);
-
-G_DEFINE_TYPE (DhAssistant, dh_assistant, GTK_TYPE_APPLICATION_WINDOW);
-
-#define GET_PRIVATE(instance) G_TYPE_INSTANCE_GET_PRIVATE \
-  (instance, DH_TYPE_ASSISTANT, DhAssistantPriv)
+G_DEFINE_TYPE_WITH_PRIVATE (DhAssistant, dh_assistant, GTK_TYPE_APPLICATION_WINDOW);
 
 static gboolean
 assistant_key_press_event_cb (GtkWidget   *widget,
@@ -62,35 +56,33 @@ assistant_view_open_uri_cb (DhAssistantView *view,
                             const char      *uri,
                             DhAssistant     *assistant)
 {
-        DhAssistantPriv  *priv;
+        DhAssistantPrivate *priv;
         GtkWindow* window;
 
-        priv = GET_PRIVATE (assistant);
+        priv = dh_assistant_get_instance_private (assistant);
         window = dh_app_peek_first_window (priv->application);
         _dh_window_display_uri (DH_WINDOW (window), uri);
 }
 
 static gboolean
-window_configure_event_cb (GtkWidget *window,
+window_configure_event_cb (GtkWidget         *window,
                            GdkEventConfigure *event,
-                           gpointer user_data)
+                           DhAssistant       *assistant)
 {
-        DhAssistant *assistant;
-        DhAssistantPriv  *priv;
-
-        assistant = DH_ASSISTANT (user_data);
-        priv = GET_PRIVATE (assistant);
-        dh_util_window_settings_save (
-                GTK_WINDOW (assistant),
-                dh_settings_peek_assistant_settings (priv->settings), FALSE);
-       return FALSE;
+        DhAssistantPrivate *priv = dh_assistant_get_instance_private (assistant);
+
+        dh_util_window_settings_save (GTK_WINDOW (assistant),
+                                      dh_settings_peek_assistant_settings (priv->settings),
+                                      FALSE);
+        return FALSE;
 }
 
 static void
-dispose (GObject *object)
+dh_assistant_dispose (GObject *object)
 {
         DhAssistant *assistant = DH_ASSISTANT (object);
-        DhAssistantPriv *priv = GET_PRIVATE (assistant);
+        DhAssistantPrivate *priv = dh_assistant_get_instance_private (assistant);
+
         g_clear_object (&priv->application);
         g_clear_object (&priv->settings);
 
@@ -101,14 +93,14 @@ static void
 dh_assistant_class_init (DhAssistantClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
-        g_type_class_add_private (klass, sizeof (DhAssistantPriv));
-        object_class->dispose = dispose;
+
+        object_class->dispose = dh_assistant_dispose;
 }
 
 static void
 dh_assistant_init (DhAssistant *assistant)
 {
-        DhAssistantPriv *priv = GET_PRIVATE (assistant);
+        DhAssistantPrivate *priv = dh_assistant_get_instance_private (assistant);
 
         priv->settings = dh_settings_get ();
         priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -133,9 +125,9 @@ dh_assistant_init (DhAssistant *assistant)
                             priv->view, TRUE, TRUE, 0);
         gtk_widget_show (priv->view);
 
-        dh_util_window_settings_restore (
-                GTK_WINDOW (assistant),
-                dh_settings_peek_assistant_settings (priv->settings), FALSE);
+        dh_util_window_settings_restore (GTK_WINDOW (assistant),
+                                         dh_settings_peek_assistant_settings (priv->settings),
+                                         FALSE);
 
         g_signal_connect (GTK_WINDOW (assistant), "configure-event",
                           G_CALLBACK (window_configure_event_cb),
@@ -145,12 +137,12 @@ dh_assistant_init (DhAssistant *assistant)
 GtkWidget *
 dh_assistant_new (DhApp *application)
 {
-        GtkWidget       *assistant;
-        DhAssistantPriv *priv;
+        GtkWidget          *assistant;
+        DhAssistantPrivate *priv;
 
         assistant = g_object_new (DH_TYPE_ASSISTANT, NULL);
 
-        priv = GET_PRIVATE (assistant);
+        priv = dh_assistant_get_instance_private (DH_ASSISTANT (assistant));
         priv->application = g_object_ref (application);
 
         dh_assistant_view_set_book_manager (DH_ASSISTANT_VIEW (priv->view),
@@ -163,12 +155,12 @@ gboolean
 dh_assistant_search (DhAssistant *assistant,
                      const gchar *str)
 {
-        DhAssistantPriv *priv;
+        DhAssistantPrivate *priv;
 
         g_return_val_if_fail (DH_IS_ASSISTANT (assistant), FALSE);
         g_return_val_if_fail (str != NULL, FALSE);
 
-        priv = GET_PRIVATE (assistant);
+        priv = dh_assistant_get_instance_private (assistant);
 
         if (dh_assistant_view_search (DH_ASSISTANT_VIEW (priv->view), str)) {
                 gtk_widget_show (GTK_WIDGET (assistant));


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