[gnome-initial-setup/wip/bin-fanciness: 2/2] Turn GisPage into a GtkBin subclass



commit c6192f84b2db0b51ee990374d5898daabdc37b15
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Nov 8 15:54:05 2012 -0500

    Turn GisPage into a GtkBin subclass
    
    This ties the page directly to the widget, which actually triggers
    our dispose handlers when we destroy the widget.

 gnome-initial-setup/gis-assistant-clutter.c        |   12 +++--
 gnome-initial-setup/gis-assistant-gtk.c            |   14 +++--
 gnome-initial-setup/gis-assistant-private.h        |    2 +-
 gnome-initial-setup/gis-assistant.c                |   54 ++++++--------------
 gnome-initial-setup/gis-assistant.h                |   29 ++---------
 gnome-initial-setup/gis-page.c                     |    3 +-
 gnome-initial-setup/gis-page.h                     |    5 +-
 .../pages/account/gis-account-page.c               |    2 +-
 gnome-initial-setup/pages/eulas/gis-eula-pages.c   |    2 +-
 gnome-initial-setup/pages/goa/gis-goa-page.c       |    2 +-
 .../pages/language/gis-language-page.c             |    2 +-
 .../pages/location/gis-location-page.c             |    2 +-
 .../pages/network/gis-network-page.c               |    2 +-
 .../pages/summary/gis-summary-page.c               |   12 ++--
 14 files changed, 52 insertions(+), 91 deletions(-)
---
diff --git a/gnome-initial-setup/gis-assistant-clutter.c b/gnome-initial-setup/gis-assistant-clutter.c
index e037626..c954634 100644
--- a/gnome-initial-setup/gis-assistant-clutter.c
+++ b/gnome-initial-setup/gis-assistant-clutter.c
@@ -46,22 +46,24 @@ current_page_changed (CcNotebook   *notebook,
                       GisAssistant *assistant)
 {
   GtkWidget *page = cc_notebook_get_selected_page (notebook);
-  _gis_assistant_current_page_changed (assistant, page);
+  _gis_assistant_current_page_changed (assistant, GIS_PAGE (page));
 }
 
 static void
-gis_assistant_clutter_switch_to (GisAssistant *assistant, GtkWidget *widget)
+gis_assistant_clutter_switch_to (GisAssistant *assistant, GisPage *page)
 {
   GisAssistantClutterPrivate *priv = GIS_ASSISTANT_CLUTTER (assistant)->priv;
-  cc_notebook_select_page (CC_NOTEBOOK (priv->notebook), widget, TRUE);
+  cc_notebook_select_page (CC_NOTEBOOK (priv->notebook), GTK_WIDGET (page), TRUE);
 }
 
 static void
 gis_assistant_clutter_add_page (GisAssistant *assistant,
-                                GtkWidget    *page)
+                                GisPage      *page)
 {
   GisAssistantClutterPrivate *priv = GIS_ASSISTANT_CLUTTER (assistant)->priv;
-  cc_notebook_add_page (CC_NOTEBOOK (priv->notebook), page);
+  cc_notebook_add_page (CC_NOTEBOOK (priv->notebook), GTK_WIDGET (page));
+
+  gtk_widget_show (GTK_WIDGET (page));
 }
 
 static void
diff --git a/gnome-initial-setup/gis-assistant-gtk.c b/gnome-initial-setup/gis-assistant-gtk.c
index 29cbdca..0d6025d 100644
--- a/gnome-initial-setup/gis-assistant-gtk.c
+++ b/gnome-initial-setup/gis-assistant-gtk.c
@@ -45,24 +45,28 @@ current_page_changed (GtkNotebook  *notebook,
                       gint          new_page_num,
                       GisAssistant *assistant)
 {
-  _gis_assistant_current_page_changed (assistant, new_page);
+  _gis_assistant_current_page_changed (assistant, GIS_PAGE (new_page));
 }
 
 static void
 gis_assistant_gtk_switch_to (GisAssistant *assistant,
-                             GtkWidget    *widget)
+                             GisPage      *page)
 {
   GisAssistantGtkPrivate *priv = GIS_ASSISTANT_GTK (assistant)->priv;
-  gint page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), widget);
+  gint page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
+                                         GTK_WIDGET (page));
   gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page_num);
 }
 
 static void
 gis_assistant_gtk_add_page (GisAssistant *assistant,
-                            GtkWidget    *widget)
+                            GisPage      *page)
 {
   GisAssistantGtkPrivate *priv = GIS_ASSISTANT_GTK (assistant)->priv;
-  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), widget, NULL);
+  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+                            GTK_WIDGET (page), NULL);
+
+  gtk_widget_show (GTK_WIDGET (page));
 }
 
 static void
diff --git a/gnome-initial-setup/gis-assistant-private.h b/gnome-initial-setup/gis-assistant-private.h
index 370a48f..2250c9f 100644
--- a/gnome-initial-setup/gis-assistant-private.h
+++ b/gnome-initial-setup/gis-assistant-private.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
 GtkWidget *_gis_assistant_get_frame (GisAssistant *assistant);
 
 void _gis_assistant_current_page_changed (GisAssistant *assistant,
-                                          GtkWidget    *page);
+                                          GisPage      *page);
 
 G_END_DECLS
 
diff --git a/gnome-initial-setup/gis-assistant.c b/gnome-initial-setup/gis-assistant.c
index c48443f..da95640 100644
--- a/gnome-initial-setup/gis-assistant.c
+++ b/gnome-initial-setup/gis-assistant.c
@@ -27,8 +27,6 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#include "gis-page.h"
-
 #include "gis-assistant.h"
 #include "gis-assistant-private.h"
 
@@ -66,15 +64,14 @@ struct _GisAssistantPrivate
 
 struct _GisAssistantPagePrivate
 {
-  GisAssistant *assistant;
   GList *link;
 };
 
 static void
-widget_destroyed (GtkWidget *widget,
-                  GisPage   *page)
+widget_destroyed (GtkWidget    *widget,
+                  GisAssistant *assistant)
 {
-  GisAssistant *assistant = page->assistant_priv->assistant;
+  GisPage *page = GIS_PAGE (widget);
   GisAssistantPrivate *priv = assistant->priv;
 
   priv->pages = g_list_delete_link (priv->pages, page->assistant_priv->link);
@@ -86,9 +83,9 @@ widget_destroyed (GtkWidget *widget,
 }
 
 static void
-gis_assistant_switch_to (GisAssistant *assistant, GtkWidget *widget)
+gis_assistant_switch_to (GisAssistant *assistant, GisPage *page)
 {
-  GIS_ASSISTANT_GET_CLASS (assistant)->switch_to (assistant, widget);
+  GIS_ASSISTANT_GET_CLASS (assistant)->switch_to (assistant, page);
 }
 
 void
@@ -96,12 +93,12 @@ gis_assistant_next_page (GisAssistant *assistant)
 {
   GisAssistantPrivate *priv = assistant->priv;
   g_signal_emit (assistant, signals[NEXT_PAGE], 0,
-                 priv->current_page->widget);
+                 priv->current_page);
 }
 
 static void
 gis_assistant_real_next_page (GisAssistant *assistant,
-                              GtkWidget    *widget)
+                              GisPage      *page)
 {
   GisAssistantPrivate *priv = assistant->priv;
   GisPage *next_page;
@@ -109,7 +106,7 @@ gis_assistant_real_next_page (GisAssistant *assistant,
   g_return_if_fail (priv->current_page != NULL);
 
   next_page = GIS_PAGE (priv->current_page->assistant_priv->link->next->data);
-  gis_assistant_switch_to (assistant, next_page->widget);
+  gis_assistant_switch_to (assistant, next_page);
 }
 
 void
@@ -121,7 +118,7 @@ gis_assistant_previous_page (GisAssistant *assistant)
   g_return_if_fail (priv->current_page != NULL);
 
   prev_page = GIS_PAGE (priv->current_page->assistant_priv->link->prev->data);
-  gis_assistant_switch_to (assistant, prev_page->widget);
+  gis_assistant_switch_to (assistant, prev_page);
 }
 
 static void
@@ -161,7 +158,7 @@ update_navigation_buttons (GisAssistant *assistant)
 
 static void
 gis_assistant_prepare (GisAssistant *assistant,
-                       GtkWidget    *widget)
+                       GisPage      *page)
 {
   update_navigation_buttons (assistant);
 }
@@ -190,14 +187,13 @@ gis_assistant_add_page (GisAssistant *assistant,
   g_return_if_fail (page->assistant_priv == NULL);
 
   page->assistant_priv = g_slice_new0 (GisAssistantPagePrivate);
-  page->assistant_priv->assistant = assistant;
   priv->pages = g_list_append (priv->pages, page);
   link = page->assistant_priv->link = g_list_last (priv->pages);
 
-  g_signal_connect (page->widget, "destroy", G_CALLBACK (widget_destroyed), page);
+  g_signal_connect (page, "destroy", G_CALLBACK (widget_destroyed), assistant);
   g_signal_connect (page, "notify", G_CALLBACK (page_notify), assistant);
 
-  GIS_ASSISTANT_GET_CLASS (assistant)->add_page (assistant, page->widget);
+  GIS_ASSISTANT_GET_CLASS (assistant)->add_page (assistant, page);
 
   if (priv->current_page->assistant_priv->link == link->prev)
     update_navigation_buttons (assistant);
@@ -253,34 +249,16 @@ _gis_assistant_get_frame (GisAssistant *assistant)
   return assistant->priv->frame;
 }
 
-static GisPage *
-find_page_for_widget (GisAssistant *assistant,
-                      GtkWidget    *widget)
-{
-  GisAssistantPrivate *priv = assistant->priv;
-  GList *l;
-
-  for (l = priv->pages; l != NULL; l = l->next)
-    {
-      GisPage *page = GIS_PAGE (l->data);
-      if (page->widget == widget)
-        return page;
-    }
-
-  return NULL;
-}
-
 void
 _gis_assistant_current_page_changed (GisAssistant *assistant,
-                                     GtkWidget    *widget)
+                                     GisPage      *page)
 {
   GisAssistantPrivate *priv = assistant->priv;
-  GisPage *page = find_page_for_widget (assistant, widget);
 
   if (priv->current_page != page) {
     priv->current_page = page;
     g_object_notify_by_pspec (G_OBJECT (assistant), obj_props[PROP_TITLE]);
-    g_signal_emit (assistant, signals[PREPARE], 0, page->widget);
+    g_signal_emit (assistant, signals[PREPARE], 0, page);
   }
 }
 
@@ -377,7 +355,7 @@ gis_assistant_class_init (GisAssistantClass *klass)
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GisAssistantClass, next_page),
                   NULL, NULL, NULL,
-                  G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
+                  G_TYPE_NONE, 1, GIS_TYPE_PAGE);
 
   /**
    * GisAssistant::prepare:
@@ -396,6 +374,6 @@ gis_assistant_class_init (GisAssistantClass *klass)
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GisAssistantClass, prepare),
                   NULL, NULL, NULL,
-                  G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
+                  G_TYPE_NONE, 1, GIS_TYPE_PAGE);
 
 }
diff --git a/gnome-initial-setup/gis-assistant.h b/gnome-initial-setup/gis-assistant.h
index 55cfdaa..747d7ef 100644
--- a/gnome-initial-setup/gis-assistant.h
+++ b/gnome-initial-setup/gis-assistant.h
@@ -24,8 +24,6 @@
 #ifndef __GIS_ASSISTANT_H__
 #define __GIS_ASSISTANT_H__
 
-#include <glib-object.h>
-
 #include "gis-page.h"
 
 G_BEGIN_DECLS
@@ -52,11 +50,11 @@ struct _GisAssistantClass
 {
   GtkBoxClass parent_class;
 
-  void (* prepare) (GisAssistant *assistant, GtkWidget *page);
-  void (* next_page) (GisAssistant *assistant, GtkWidget *page);
+  void (* prepare) (GisAssistant *assistant, GisPage *page);
+  void (* next_page) (GisAssistant *assistant, GisPage *page);
 
-  void (* switch_to) (GisAssistant *assistant, GtkWidget *page);
-  void (* add_page) (GisAssistant *assistant, GtkWidget *page);
+  void (* switch_to) (GisAssistant *assistant, GisPage *page);
+  void (* add_page) (GisAssistant *assistant, GisPage *page);
 };
 
 GType gis_assistant_get_type (void);
@@ -67,27 +65,8 @@ void      gis_assistant_add_page          (GisAssistant *assistant,
 void      gis_assistant_next_page         (GisAssistant *assistant);
 void      gis_assistant_previous_page     (GisAssistant *assistant);
 void      gis_assistant_destroy_all_pages (GisAssistant *assistant);
-
-void      gis_assistant_set_page_complete (GisAssistant *assistant,
-                                           GtkWidget    *page,
-                                           gboolean      complete);
-gboolean  gis_assistant_get_page_complete (GisAssistant *assistant,
-                                           GtkWidget    *page);
-
-void      gis_assistant_set_page_title    (GisAssistant *assistant,
-                                           GtkWidget    *page,
-                                           gchar        *title);
-gchar *   gis_assistant_get_page_title    (GisAssistant *assistant,
-                                           GtkWidget    *page);
 gchar *   gis_assistant_get_title         (GisAssistant *assistant);
 
-void      gis_assistant_set_use_arrow_buttons (GisAssistant *assistant,
-                                               GtkWidget    *page,
-                                               gboolean      use_arrow_buttons);
-
-gboolean  gis_assistant_get_use_arrow_buttons (GisAssistant *assistant,
-                                               GtkWidget    *page);
-
 G_END_DECLS
 
 #endif /* __GIS_ASSISTANT_H__ */
diff --git a/gnome-initial-setup/gis-page.c b/gnome-initial-setup/gis-page.c
index 3202bd6..d01135f 100644
--- a/gnome-initial-setup/gis-page.c
+++ b/gnome-initial-setup/gis-page.c
@@ -27,7 +27,7 @@
 
 #include "gis-page.h"
 
-G_DEFINE_ABSTRACT_TYPE (GisPage, gis_page, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (GisPage, gis_page, GTK_TYPE_BIN);
 
 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GIS_TYPE_PAGE, GisPagePrivate))
 
@@ -123,7 +123,6 @@ gis_page_dispose (GObject *object)
 
   g_clear_object (&page->driver);
   g_clear_object (&page->builder);
-  g_clear_object (&page->widget);
 
   G_OBJECT_CLASS (gis_page_parent_class)->dispose (object);
 }
diff --git a/gnome-initial-setup/gis-page.h b/gnome-initial-setup/gis-page.h
index 8db99f5..211fc46 100644
--- a/gnome-initial-setup/gis-page.h
+++ b/gnome-initial-setup/gis-page.h
@@ -42,11 +42,10 @@ typedef struct _GisAssistantPagePrivate GisAssistantPagePrivate;
 
 struct _GisPage
 {
-  GObject parent;
+  GtkBin parent;
 
   GisDriver *driver;
   GtkBuilder *builder;
-  GtkWidget *widget;
 
   GisPagePrivate *priv;
   GisAssistantPagePrivate *assistant_priv;
@@ -54,7 +53,7 @@ struct _GisPage
 
 struct _GisPageClass
 {
-  GObjectClass parent_class;
+  GtkBinClass parent_class;
   char *page_id;
 
   GtkBuilder * (*get_builder) (GisPage *page);
diff --git a/gnome-initial-setup/pages/account/gis-account-page.c b/gnome-initial-setup/pages/account/gis-account-page.c
index 3b9a867..2dd5d12 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -1000,7 +1000,7 @@ gis_account_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_account_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("account-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("account-page"));
 
   priv->realmd_watch = g_bus_watch_name (G_BUS_TYPE_SYSTEM, "org.freedesktop.realmd",
                                          G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
diff --git a/gnome-initial-setup/pages/eulas/gis-eula-pages.c b/gnome-initial-setup/pages/eulas/gis-eula-pages.c
index eae1853..650735d 100644
--- a/gnome-initial-setup/pages/eulas/gis-eula-pages.c
+++ b/gnome-initial-setup/pages/eulas/gis-eula-pages.c
@@ -243,7 +243,7 @@ gis_eula_page_constructed (GObject *object)
   gtk_widget_set_vexpand (scrolled_window, TRUE);
   gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
   gtk_container_add (GTK_CONTAINER (vbox), scrolled_window);
-  GIS_PAGE (page)->widget = vbox;
+  gtk_container_add (GTK_CONTAINER (page), vbox);
 
   priv->text_view = text_view;
   priv->scrolled_window = scrolled_window;
diff --git a/gnome-initial-setup/pages/goa/gis-goa-page.c b/gnome-initial-setup/pages/goa/gis-goa-page.c
index 249288b..2f9e9c9 100644
--- a/gnome-initial-setup/pages/goa/gis-goa-page.c
+++ b/gnome-initial-setup/pages/goa/gis-goa-page.c
@@ -303,7 +303,7 @@ gis_goa_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_goa_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("goa-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("goa-page"));
 
   priv->goa_client = goa_client_new_sync (NULL, &error);
 
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c b/gnome-initial-setup/pages/language/gis-language-page.c
index 9cce748..1818f0f 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -268,7 +268,7 @@ gis_language_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_language_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("language-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("language-page"));
 
   liststore = gtk_list_store_new (NUM_COLS,
                                   G_TYPE_STRING,
diff --git a/gnome-initial-setup/pages/location/gis-location-page.c b/gnome-initial-setup/pages/location/gis-location-page.c
index 0161ea9..b66069a 100644
--- a/gnome-initial-setup/pages/location/gis-location-page.c
+++ b/gnome-initial-setup/pages/location/gis-location-page.c
@@ -271,7 +271,7 @@ gis_location_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_location_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("location-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("location-page"));
 
   frame = WID("location-map-frame");
 
diff --git a/gnome-initial-setup/pages/network/gis-network-page.c b/gnome-initial-setup/pages/network/gis-network-page.c
index e87a4fd..acae439 100644
--- a/gnome-initial-setup/pages/network/gis-network-page.c
+++ b/gnome-initial-setup/pages/network/gis-network-page.c
@@ -631,7 +631,7 @@ gis_network_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_network_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("network-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("network-page"));
 
   col = OBJ(GtkTreeViewColumn*, "network-list-column");
 
diff --git a/gnome-initial-setup/pages/summary/gis-summary-page.c b/gnome-initial-setup/pages/summary/gis-summary-page.c
index 09ee1df..9fb2c58 100644
--- a/gnome-initial-setup/pages/summary/gis-summary-page.c
+++ b/gnome-initial-setup/pages/summary/gis-summary-page.c
@@ -290,13 +290,13 @@ tour_cb (GtkButton *button, GisSummaryPage *page)
 
 static void
 prepare_cb (GisAssistant   *assistant,
-            GtkWidget      *widget,
-            GisSummaryPage *page)
+            GisPage        *which_page,
+            GisSummaryPage *this_page)
 {
-  if (GIS_PAGE (page)->widget == widget)
+  if (GIS_PAGE (which_page) == GIS_PAGE (this_page))
     {
-      GisSummaryPagePrivate *priv = page->priv;
-      gis_driver_get_user_permissions (GIS_PAGE (page)->driver,
+      GisSummaryPagePrivate *priv = this_page->priv;
+      gis_driver_get_user_permissions (GIS_PAGE (this_page)->driver,
                                        &priv->user_account,
                                        &priv->user_password);
     }
@@ -340,7 +340,7 @@ gis_summary_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_summary_page_parent_class)->constructed (object);
 
-  GIS_PAGE (page)->widget = WID ("summary-page");
+  gtk_container_add (GTK_CONTAINER (page), WID ("summary-page"));
 
   g_signal_connect (assistant, "prepare", G_CALLBACK (prepare_cb), page);
 



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