[gnome-control-center] shell: Make the main app window a subclass of GtkApplicationWindow



commit 408ae4a87c3d3ebb36d2589bb3960a59ce54c27e
Author: William Jon McCann <jmccann redhat com>
Date:   Sun Feb 17 00:30:43 2013 -0500

    shell: Make the main app window a subclass of GtkApplicationWindow
    
    This allows for better encapsulation of window logic. In order to
    do this CcShell was made an interface instead of an abstract base
    class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692174

 shell/cc-application.c       |    6 +-
 shell/cc-shell.c             |  154 +++++++------------------------
 shell/cc-shell.h             |   54 ++---------
 shell/gnome-control-center.c |  204 +++++++++++++++++++++++-------------------
 shell/gnome-control-center.h |    9 +-
 5 files changed, 165 insertions(+), 262 deletions(-)
---
diff --git a/shell/cc-application.c b/shell/cc-application.c
index cbd05f6..08d8401 100644
--- a/shell/cc-application.c
+++ b/shell/cc-application.c
@@ -166,7 +166,7 @@ cc_application_command_line (GApplication *application,
 
   cc_shell_log_set_debug (verbose);
 
-  gnome_control_center_show (self->priv->window, GTK_APPLICATION (application));
+  gnome_control_center_show (self->priv->window);
 
   if (search_str)
     {
@@ -222,7 +222,7 @@ cc_application_quit (GSimpleAction *simple,
 {
   CcApplication *self = CC_APPLICATION (user_data);
 
-  g_clear_object (&self->priv->window);
+  gtk_widget_destroy (GTK_WIDGET (self->priv->window));
 }
 
 
@@ -281,7 +281,7 @@ cc_application_startup (GApplication *application)
   gtk_application_add_accelerator (GTK_APPLICATION (application),
                                    "F1", "app.help", NULL);
 
-  self->priv->window = gnome_control_center_new ();
+  self->priv->window = gnome_control_center_new (GTK_APPLICATION (application));
 }
 
 static GObject *
diff --git a/shell/cc-shell.c b/shell/cc-shell.c
index eb97a3a..86c0215 100644
--- a/shell/cc-shell.c
+++ b/shell/cc-shell.c
@@ -21,9 +21,9 @@
 
 /**
  * SECTION:cc-shell
- * @short_description: Abstract class representing the Control Center shell
+ * @short_description: Interface representing the Control Center shell
  *
- * CcShell is an abstract class that represents an instance of a control
+ * CcShell is an interface that represents an instance of a control
  * center shell. It provides access to some of the properties of the shell
  * that panels will need to read or change. When a panel is created it has an
  * instance of CcShell available that represents the current shell.
@@ -33,93 +33,17 @@
 #include "cc-shell.h"
 #include "cc-panel.h"
 
-G_DEFINE_ABSTRACT_TYPE (CcShell, cc_shell, G_TYPE_OBJECT)
-
-#define SHELL_PRIVATE(o) \
-  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL, CcShellPrivate))
-
-struct _CcShellPrivate
-{
-  CcPanel *active_panel;
-};
-
-enum
-{
-  PROP_ACTIVE_PANEL = 1
-};
-
-
-static void
-cc_shell_get_property (GObject    *object,
-                       guint       property_id,
-                       GValue     *value,
-                       GParamSpec *pspec)
-{
-  CcShell *shell = CC_SHELL (object);
-
-  switch (property_id)
-    {
-    case PROP_ACTIVE_PANEL:
-      g_value_set_object (value, shell->priv->active_panel);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-    }
-}
-
-static void
-cc_shell_set_property (GObject      *object,
-                       guint         property_id,
-                       const GValue *value,
-                       GParamSpec   *pspec)
-{
-  CcShell *shell = CC_SHELL (object);
-
-  switch (property_id)
-    {
-    case PROP_ACTIVE_PANEL:
-      cc_shell_set_active_panel (shell, g_value_get_object (value));
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-    }
-}
-
-static void
-cc_shell_dispose (GObject *object)
-{
-  /* remove and unref the active shell */
-  cc_shell_set_active_panel (CC_SHELL (object), NULL);
-
-  G_OBJECT_CLASS (cc_shell_parent_class)->dispose (object);
-}
-
-static void
-cc_shell_class_init (CcShellClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GParamSpec *pspec;
-
-  g_type_class_add_private (klass, sizeof (CcShellPrivate));
-
-  object_class->get_property = cc_shell_get_property;
-  object_class->set_property = cc_shell_set_property;
-  object_class->dispose = cc_shell_dispose;
-
-  pspec = g_param_spec_object ("active-panel",
-                               "active panel",
-                               "The currently active Panel",
-                               CC_TYPE_PANEL,
-                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (object_class, PROP_ACTIVE_PANEL, pspec);
-}
+G_DEFINE_INTERFACE (CcShell, cc_shell, GTK_TYPE_WIDGET)
 
 static void
-cc_shell_init (CcShell *self)
+cc_shell_default_init (CcShellInterface *iface)
 {
-  self->priv = SHELL_PRIVATE (self);
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("active-panel",
+                                                            "active panel",
+                                                            "The currently active Panel",
+                                                            CC_TYPE_PANEL,
+                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 /**
@@ -130,12 +54,16 @@ cc_shell_init (CcShell *self)
  *
  * Returns: a #CcPanel or NULL if no panel is active
  */
-CcPanel*
+CcPanel *
 cc_shell_get_active_panel (CcShell *shell)
 {
+  CcPanel *panel = NULL;
+
   g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
 
-  return shell->priv->active_panel;
+  g_object_get (shell, "active-panel", &panel, NULL);
+
+  return panel;
 }
 
 /**
@@ -155,18 +83,7 @@ cc_shell_set_active_panel (CcShell *shell,
   g_return_if_fail (CC_IS_SHELL (shell));
   g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
 
-  if (panel != shell->priv->active_panel)
-    {
-      /* remove the old panel */
-      g_clear_object (&shell->priv->active_panel);
-
-      /* set the new panel */
-      if (panel)
-        {
-          shell->priv->active_panel = g_object_ref (panel);
-        }
-      g_object_notify (G_OBJECT (shell), "active-panel");
-    }
+  g_object_set (shell, "active-panel", panel, NULL);
 }
 
 /**
@@ -185,23 +102,22 @@ cc_shell_set_active_panel_from_id (CcShell      *shell,
                                    const gchar **argv,
                                    GError      **error)
 {
-  CcShellClass *class;
+  CcShellInterface *iface;
 
   g_return_val_if_fail (CC_IS_SHELL (shell), FALSE);
 
+  iface = CC_SHELL_GET_IFACE (shell);
 
-  class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
-
-  if (!class->set_active_panel_from_id)
+  if (!iface->set_active_panel_from_id)
     {
-      g_warning ("Object of type \"%s\" does not implement required virtual"
-                 " function \"set_active_panel_from_id\",",
+      g_warning ("Object of type \"%s\" does not implement required interface"
+                 " method \"set_active_panel_from_id\",",
                  G_OBJECT_TYPE_NAME (shell));
       return FALSE;
     }
   else
     {
-      return class->set_active_panel_from_id (shell, id, argv, error);
+      return iface->set_active_panel_from_id (shell, id, argv, error);
     }
 }
 
@@ -216,19 +132,19 @@ cc_shell_set_active_panel_from_id (CcShell      *shell,
 GtkWidget *
 cc_shell_get_toplevel (CcShell *shell)
 {
-  CcShellClass *klass;
+  CcShellInterface *iface;
 
   g_return_val_if_fail (CC_IS_SHELL (shell), NULL);
 
-  klass = CC_SHELL_GET_CLASS (shell);
+  iface = CC_SHELL_GET_IFACE (shell);
 
-  if (klass->get_toplevel)
+  if (iface->get_toplevel)
     {
-        return klass->get_toplevel (shell);
+        return iface->get_toplevel (shell);
     }
 
-  g_warning ("Object of type \"%s\" does not implement required virtual"
-             " function \"get_toplevel\",",
+  g_warning ("Object of type \"%s\" does not implement required interface"
+             " method \"get_toplevel\",",
              G_OBJECT_TYPE_NAME (shell));
 
   return NULL;
@@ -237,20 +153,20 @@ cc_shell_get_toplevel (CcShell *shell)
 void
 cc_shell_embed_widget_in_header (CcShell *shell, GtkWidget *widget)
 {
-  CcShellClass *class;
+  CcShellInterface *iface;
 
   g_return_if_fail (CC_IS_SHELL (shell));
 
-  class = (CcShellClass *) G_OBJECT_GET_CLASS (shell);
+  iface = CC_SHELL_GET_IFACE (shell);
 
-  if (!class->embed_widget_in_header)
+  if (!iface->embed_widget_in_header)
     {
-      g_warning ("Object of type \"%s\" does not implement required virtual"
-                 " function \"embed_widget_in_header\",",
+      g_warning ("Object of type \"%s\" does not implement required interface"
+                 " method \"embed_widget_in_header\",",
                  G_OBJECT_TYPE_NAME (shell));
     }
   else
     {
-      class->embed_widget_in_header (shell, widget);
+      iface->embed_widget_in_header (shell, widget);
     }
 }
diff --git a/shell/cc-shell.h b/shell/cc-shell.h
index a879e53..01f101a 100644
--- a/shell/cc-shell.h
+++ b/shell/cc-shell.h
@@ -26,64 +26,30 @@
 
 G_BEGIN_DECLS
 
-#define CC_TYPE_SHELL cc_shell_get_type()
-
-#define CC_SHELL(obj) \
-  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-  CC_TYPE_SHELL, CcShell))
-
-#define CC_SHELL_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_CAST ((klass), \
-  CC_TYPE_SHELL, CcShellClass))
-
-#define CC_IS_SHELL(obj) \
-  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
-  CC_TYPE_SHELL))
-
-#define CC_IS_SHELL_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
-  CC_TYPE_SHELL))
-
-#define CC_SHELL_GET_CLASS(obj) \
-  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-  CC_TYPE_SHELL, CcShellClass))
-
+#define CC_TYPE_SHELL (cc_shell_get_type())
+#define CC_SHELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_SHELL, CcShell))
+#define CC_IS_SHELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_SHELL))
+#define CC_SHELL_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CC_TYPE_SHELL, CcShellInterface))
 
 #define CC_SHELL_PANEL_EXTENSION_POINT "control-center-1"
 
 typedef struct _CcShell CcShell;
-typedef struct _CcShellClass CcShellClass;
-typedef struct _CcShellPrivate CcShellPrivate;
+typedef struct _CcShellInterface CcShellInterface;
 
 /* cc-panel.h requires CcShell, so make sure they are defined first */
 #include "cc-panel.h"
 
 /**
- * CcShell:
- *
- * The contents of this struct are private should not be accessed directly.
- */
-struct _CcShell
-{
-  /*< private >*/
-  GObject parent;
-
-  CcShellPrivate *priv;
-};
-
-/**
- * CcShellClass:
+ * CcShellInterface:
  * @set_active_panel_from_id: virtual function to set the active panel from an
  *                            id string
  *
  */
-struct _CcShellClass
+struct _CcShellInterface
 {
-  /*< private >*/
-  GObjectClass parent_class;
+  GTypeInterface g_iface;
 
-  /*< public >*/
-  /* vfuncs */
+  /* methods */
   gboolean    (*set_active_panel_from_id) (CcShell      *shell,
                                            const gchar  *id,
                                            const gchar **argv,
@@ -95,7 +61,7 @@ struct _CcShellClass
 
 GType           cc_shell_get_type                 (void) G_GNUC_CONST;
 
-CcPanel*        cc_shell_get_active_panel         (CcShell      *shell);
+CcPanel *       cc_shell_get_active_panel         (CcShell      *shell);
 void            cc_shell_set_active_panel         (CcShell      *shell,
                                                    CcPanel      *panel);
 gboolean        cc_shell_set_active_panel_from_id (CcShell      *shell,
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index a37959a..70867ea 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -39,7 +39,10 @@
 #include "cc-panel-loader.h"
 #include "cc-util.h"
 
-G_DEFINE_TYPE (GnomeControlCenter, gnome_control_center, CC_TYPE_SHELL)
+static void     cc_shell_iface_init         (CcShellInterface      *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GnomeControlCenter, gnome_control_center, GTK_TYPE_APPLICATION_WINDOW,
+                         G_IMPLEMENT_INTERFACE (CC_TYPE_SHELL, cc_shell_iface_init))
 
 #define CONTROL_CENTER_PRIVATE(o) \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_CONTROL_CENTER, GnomeControlCenterPrivate))
@@ -55,6 +58,9 @@ G_DEFINE_TYPE (GnomeControlCenter, gnome_control_center, CC_TYPE_SHELL)
 
 #define MIN_ICON_VIEW_HEIGHT 300
 
+#define DEFAULT_WINDOW_TITLE N_("Settings")
+#define DEFAULT_WINDOW_ICON_NAME "preferences-desktop"
+
 typedef enum {
        SMALL_SCREEN_UNSET,
        SMALL_SCREEN_TRUE,
@@ -71,7 +77,6 @@ struct _GnomeControlCenterPrivate
   GtkWidget  *current_panel_box;
   GtkWidget  *current_panel;
   char       *current_panel_id;
-  GtkWidget  *window;
   GtkWidget  *search_entry;
   GtkWidget  *lock_button;
   GPtrArray  *custom_widgets;
@@ -82,13 +87,18 @@ struct _GnomeControlCenterPrivate
   GtkWidget *search_view;
   gchar *filter_string;
 
-  gchar *default_window_title;
-  gchar *default_window_icon;
+  CcPanel *active_panel;
 
   int monitor_num;
   CcSmallScreen small_screen;
 };
 
+enum
+{
+  PROP_0,
+  PROP_ACTIVE_PANEL
+};
+
 /* Notebook helpers */
 static GtkWidget *
 notebook_get_selected_page (GtkWidget *notebook)
@@ -169,21 +179,21 @@ get_icon_name_from_g_icon (GIcon *gicon)
 }
 
 static gboolean
-activate_panel (GnomeControlCenter *shell,
+activate_panel (GnomeControlCenter *self,
                 const gchar        *id,
                const gchar       **argv,
                 const gchar        *name,
                 GIcon              *gicon)
 {
-  GnomeControlCenterPrivate *priv = shell->priv;
+  GnomeControlCenterPrivate *priv = self->priv;
   GtkWidget *box;
   const gchar *icon_name;
 
   if (!id)
     return FALSE;
 
-  priv->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (shell), id, argv));
-  cc_shell_set_active_panel (CC_SHELL (shell), CC_PANEL (priv->current_panel));
+  priv->current_panel = GTK_WIDGET (cc_panel_loader_load_by_name (CC_SHELL (self), id, argv));
+  cc_shell_set_active_panel (CC_SHELL (self), CC_PANEL (priv->current_panel));
   gtk_widget_show (priv->current_panel);
 
   gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button),
@@ -202,10 +212,11 @@ activate_panel (GnomeControlCenter *shell,
 
   /* set the title of the window */
   icon_name = get_icon_name_from_g_icon (gicon);
-  gtk_window_set_role (GTK_WINDOW (priv->window), id);
-  gtk_window_set_title (GTK_WINDOW (priv->window), name);
+
+  gtk_window_set_role (GTK_WINDOW (self), id);
+  gtk_window_set_title (GTK_WINDOW (self), name);
   gtk_window_set_default_icon_name (icon_name);
-  gtk_window_set_icon_name (GTK_WINDOW (priv->window), icon_name);
+  gtk_window_set_icon_name (GTK_WINDOW (self), icon_name);
 
   priv->current_panel_box = box;
 
@@ -230,9 +241,9 @@ _shell_remove_all_custom_widgets (GnomeControlCenterPrivate *priv)
 }
 
 static void
-shell_show_overview_page (GnomeControlCenter *center)
+shell_show_overview_page (GnomeControlCenter *self)
 {
-  GnomeControlCenterPrivate *priv = center->priv;
+  GnomeControlCenterPrivate *priv = self->priv;
 
   notebook_select_page (priv->notebook, priv->scrolled_window);
 
@@ -251,13 +262,12 @@ shell_show_overview_page (GnomeControlCenter *center)
   gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button), NULL);
 
   /* reset window title and icon */
-  gtk_window_set_role (GTK_WINDOW (priv->window), NULL);
-  gtk_window_set_title (GTK_WINDOW (priv->window), priv->default_window_title);
-  gtk_window_set_default_icon_name (priv->default_window_icon);
-  gtk_window_set_icon_name (GTK_WINDOW (priv->window),
-                            priv->default_window_icon);
+  gtk_window_set_role (GTK_WINDOW (self), NULL);
+  gtk_window_set_title (GTK_WINDOW (self), _(DEFAULT_WINDOW_TITLE));
+  gtk_window_set_default_icon_name (DEFAULT_WINDOW_ICON_NAME);
+  gtk_window_set_icon_name (GTK_WINDOW (self), DEFAULT_WINDOW_ICON_NAME);
 
-  cc_shell_set_active_panel (CC_SHELL (center), NULL);
+  cc_shell_set_active_panel (CC_SHELL (self), NULL);
 
   /* clear any custom widgets */
   _shell_remove_all_custom_widgets (priv);
@@ -895,10 +905,11 @@ home_button_clicked_cb (GtkButton *button,
 }
 
 static void
-notebook_page_notify_cb (GtkNotebook              *notebook,
-                        GParamSpec               *spec,
-                         GnomeControlCenterPrivate *priv)
+notebook_page_notify_cb (GtkNotebook        *notebook,
+                        GParamSpec         *spec,
+                         GnomeControlCenter *self)
 {
+  GnomeControlCenterPrivate *priv = self->priv;
   int nat_height;
   GtkWidget *child;
 
@@ -923,10 +934,10 @@ notebook_page_notify_cb (GtkNotebook              *notebook,
       gtk_widget_hide (W (priv->builder, "search-entry"));
       /* set the scrolled window small so that it doesn't force
          the window to be larger than this panel */
-      gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->window),
+      gtk_widget_get_preferred_height_for_width (GTK_WIDGET (self),
                                                  FIXED_WIDTH, NULL, &nat_height);
       gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (priv->scrolled_window), 
MIN_ICON_VIEW_HEIGHT);
-      gtk_window_resize (GTK_WINDOW (priv->window),
+      gtk_window_resize (GTK_WINDOW (self),
                          FIXED_WIDTH,
                          nat_height);
     }
@@ -1037,7 +1048,7 @@ _shell_set_active_panel_from_id (CcShell      *shell,
 static GtkWidget *
 _shell_get_toplevel (CcShell *shell)
 {
-  return GNOME_CONTROL_CENTER (shell)->priv->window;
+  return GTK_WIDGET (shell);
 }
 
 /* GObject Implementation */
@@ -1047,21 +1058,52 @@ gnome_control_center_get_property (GObject    *object,
                                    GValue     *value,
                                    GParamSpec *pspec)
 {
+  GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
+
   switch (property_id)
     {
+    case PROP_ACTIVE_PANEL:
+      g_value_set_object (value, priv->active_panel);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
 static void
+set_active_panel (GnomeControlCenter *shell,
+                  CcPanel *panel)
+{
+  g_return_if_fail (CC_IS_SHELL (shell));
+  g_return_if_fail (panel == NULL || CC_IS_PANEL (panel));
+
+  if (panel != shell->priv->active_panel)
+    {
+      /* remove the old panel */
+      g_clear_object (&shell->priv->active_panel);
+
+      /* set the new panel */
+      if (panel)
+        {
+          shell->priv->active_panel = g_object_ref (panel);
+        }
+      g_object_notify (G_OBJECT (shell), "active-panel");
+    }
+}
+
+static void
 gnome_control_center_set_property (GObject      *object,
                                    guint         property_id,
                                    const GValue *value,
                                    GParamSpec   *pspec)
 {
+  GnomeControlCenter *shell = GNOME_CONTROL_CENTER (object);
+
   switch (property_id)
     {
+    case PROP_ACTIVE_PANEL:
+      set_active_panel (shell, g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -1079,16 +1121,6 @@ gnome_control_center_dispose (GObject *object)
       g_ptr_array_unref (priv->custom_widgets);
       priv->custom_widgets = NULL;
     }
-  if (priv->window)
-    {
-      gtk_widget_destroy (priv->window);
-      priv->window = NULL;
-
-      /* destroying the window will destroy its children */
-      priv->notebook = NULL;
-      priv->search_entry = NULL;
-      priv->search_view = NULL;
-    }
 
   if (priv->builder)
     {
@@ -1123,26 +1155,21 @@ gnome_control_center_finalize (GObject *object)
       priv->filter_string = NULL;
     }
 
-  if (priv->default_window_title)
-    {
-      g_free (priv->default_window_title);
-      priv->default_window_title = NULL;
-    }
-
-  if (priv->default_window_icon)
-    {
-      g_free (priv->default_window_icon);
-      priv->default_window_icon = NULL;
-    }
-
   G_OBJECT_CLASS (gnome_control_center_parent_class)->finalize (object);
 }
 
 static void
+cc_shell_iface_init (CcShellInterface *iface)
+{
+  iface->set_active_panel_from_id = _shell_set_active_panel_from_id;
+  iface->embed_widget_in_header = _shell_embed_widget_in_header;
+  iface->get_toplevel = _shell_get_toplevel;
+}
+
+static void
 gnome_control_center_class_init (GnomeControlCenterClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  CcShellClass *shell_class = CC_SHELL_CLASS (klass);
 
   g_type_class_add_private (klass, sizeof (GnomeControlCenterPrivate));
 
@@ -1151,9 +1178,7 @@ gnome_control_center_class_init (GnomeControlCenterClass *klass)
   object_class->dispose = gnome_control_center_dispose;
   object_class->finalize = gnome_control_center_finalize;
 
-  shell_class->set_active_panel_from_id = _shell_set_active_panel_from_id;
-  shell_class->embed_widget_in_header = _shell_embed_widget_in_header;
-  shell_class->get_toplevel = _shell_get_toplevel;
+  g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel");
 }
 
 static gboolean
@@ -1190,7 +1215,7 @@ window_key_press_event (GtkWidget          *win,
             break;
           case GDK_KEY_Q:
           case GDK_KEY_q:
-            g_object_unref (self);
+            gtk_widget_destroy (GTK_WIDGET (self));
             retval = TRUE;
             break;
           case GDK_KEY_W:
@@ -1219,7 +1244,7 @@ get_monitor_height (GnomeControlCenter *self)
 
   /* We cannot use workarea here, as this wouldn't
    * be updated when we read it after a monitors-changed signal */
-  screen = gtk_widget_get_screen (self->priv->window);
+  screen = gtk_widget_get_screen (GTK_WIDGET (self));
   gdk_screen_get_monitor_geometry (screen, self->priv->monitor_num, &rect);
 
   return rect.height;
@@ -1234,7 +1259,7 @@ update_monitor_number (GnomeControlCenter *self)
   GdkWindow *window;
   int monitor;
 
-  widget = self->priv->window;
+  widget = GTK_WIDGET (self);
 
   window = gtk_widget_get_window (widget);
   screen = gtk_widget_get_screen (widget);
@@ -1266,23 +1291,23 @@ update_small_screen_settings (GnomeControlCenter *self)
 
   if (small == SMALL_SCREEN_TRUE)
     {
-      gtk_window_set_resizable (GTK_WINDOW (self->priv->window), TRUE);
+      gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
 
       if (self->priv->small_screen != small)
-        gtk_window_maximize (GTK_WINDOW (self->priv->window));
+        gtk_window_maximize (GTK_WINDOW (self));
     }
   else
     {
       if (self->priv->small_screen != small)
-        gtk_window_unmaximize (GTK_WINDOW (self->priv->window));
+        gtk_window_unmaximize (GTK_WINDOW (self));
 
-      gtk_window_set_resizable (GTK_WINDOW (self->priv->window), FALSE);
+      gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
     }
 
   self->priv->small_screen = small;
 
   /* And update the minimum sizes */
-  notebook_page_notify_cb (GTK_NOTEBOOK (self->priv->notebook), NULL, self->priv);
+  notebook_page_notify_cb (GTK_NOTEBOOK (self->priv->notebook), NULL, self);
 }
 
 static gboolean
@@ -1302,9 +1327,9 @@ application_set_cb (GObject    *object,
   /* update small screen settings now - to avoid visible resizing, we want
    * to do it before showing the window, and GtkApplicationWindow cannot be
    * realized unless its application property has been set */
-  if (gtk_window_get_application (GTK_WINDOW (self->priv->window)))
+  if (gtk_window_get_application (GTK_WINDOW (self)))
     {
-      gtk_widget_realize (self->priv->window);
+      gtk_widget_realize (GTK_WIDGET (self));
       update_small_screen_settings (self);
     }
 }
@@ -1330,7 +1355,7 @@ gdk_window_set_cb (GObject    *object,
   if (!GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
     return;
 
-  window = gtk_widget_get_window (GTK_WIDGET (self->priv->window));
+  window = gtk_widget_get_window (GTK_WIDGET (self));
 
   if (!window)
     return;
@@ -1347,17 +1372,10 @@ gnome_control_center_init (GnomeControlCenter *self)
   GnomeControlCenterPrivate *priv;
   GdkScreen *screen;
   GtkWidget *frame;
+  GtkWidget *box;
 
   priv = self->priv = CONTROL_CENTER_PRIVATE (self);
 
-#ifdef HAVE_CHEESE
-  if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
-    {
-      g_critical ("Clutter-GTK init failed");
-      return;
-    }
-#endif /* HAVE_CHEESE */
-
   priv->monitor_num = -1;
   self->priv->small_screen = SMALL_SCREEN_UNSET;
 
@@ -1372,17 +1390,18 @@ gnome_control_center_init (GnomeControlCenter *self)
       return;
     }
 
+  box = W(priv->builder, "vbox1");
+  gtk_widget_reparent (box, GTK_WIDGET (self));
+
   /* connect various signals */
-  priv->window = W (priv->builder, "main-window");
-  gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (priv->window), TRUE);
-  screen = gtk_widget_get_screen (priv->window);
+  screen = gtk_widget_get_screen (GTK_WIDGET (self));
   g_signal_connect (screen, "monitors-changed", G_CALLBACK (monitors_changed_cb), self);
-  g_signal_connect (priv->window, "configure-event", G_CALLBACK (main_window_configure_cb), self);
-  g_signal_connect (priv->window, "notify::application", G_CALLBACK (application_set_cb), self);
-  g_signal_connect_swapped (priv->window, "delete-event", G_CALLBACK (g_object_unref), self);
-  g_signal_connect_after (priv->window, "key_press_event",
+
+  g_signal_connect (self, "configure-event", G_CALLBACK (main_window_configure_cb), self);
+  g_signal_connect (self, "notify::application", G_CALLBACK (application_set_cb), self);
+  g_signal_connect_after (self, "key_press_event",
                           G_CALLBACK (window_key_press_event), self);
-  g_signal_connect (priv->window, "notify::window", G_CALLBACK (gdk_window_set_cb), self);
+  g_signal_connect (self, "notify::window", G_CALLBACK (gdk_window_set_cb), self);
 
   priv->notebook = W (priv->builder, "notebook");
 
@@ -1392,7 +1411,7 @@ gnome_control_center_init (GnomeControlCenter *self)
   gtk_widget_set_size_request (priv->scrolled_window, FIXED_WIDTH, -1);
   priv->main_vbox = W (priv->builder, "main-vbox");
   g_signal_connect (priv->notebook, "notify::page",
-                    G_CALLBACK (notebook_page_notify_cb), priv);
+                    G_CALLBACK (notebook_page_notify_cb), self);
 
   /* Set the alignment for the home button */
   frame = W(priv->builder, "home-aspect-frame");
@@ -1413,29 +1432,32 @@ gnome_control_center_init (GnomeControlCenter *self)
 
   setup_lock (self);
 
-  /* store default window title and name */
-  priv->default_window_title = g_strdup (gtk_window_get_title (GTK_WINDOW (priv->window)));
-  priv->default_window_icon = g_strdup (gtk_window_get_icon_name (GTK_WINDOW (priv->window)));
-
-  notebook_page_notify_cb (GTK_NOTEBOOK (priv->notebook), NULL, priv);
+  notebook_page_notify_cb (GTK_NOTEBOOK (priv->notebook), NULL, self);
 }
 
 GnomeControlCenter *
-gnome_control_center_new (void)
+gnome_control_center_new (GtkApplication *application)
 {
-  return g_object_new (GNOME_TYPE_CONTROL_CENTER, NULL);
+  g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
+
+  return g_object_new (GNOME_TYPE_CONTROL_CENTER,
+                       "application", application,
+                       "hide-titlebar-when-maximized", TRUE,
+                       "resizable", TRUE,
+                       "title", DEFAULT_WINDOW_TITLE,
+                       "icon-name", DEFAULT_WINDOW_ICON_NAME,
+                       "window-position", GTK_WIN_POS_CENTER,
+                       NULL);
 }
 
 void
 gnome_control_center_present (GnomeControlCenter *center)
 {
-  gtk_window_present (GTK_WINDOW (center->priv->window));
+  gtk_window_present (GTK_WINDOW (center));
 }
 
 void
-gnome_control_center_show (GnomeControlCenter *center,
-                          GtkApplication     *app)
+gnome_control_center_show (GnomeControlCenter *center)
 {
-  gtk_window_set_application (GTK_WINDOW (center->priv->window), app);
-  gtk_widget_show (gtk_bin_get_child (GTK_BIN (center->priv->window)));
+  gtk_widget_show (GTK_WIDGET (center));
 }
diff --git a/shell/gnome-control-center.h b/shell/gnome-control-center.h
index c3e1e23..63ca623 100644
--- a/shell/gnome-control-center.h
+++ b/shell/gnome-control-center.h
@@ -54,23 +54,22 @@ typedef struct _GnomeControlCenterPrivate GnomeControlCenterPrivate;
 
 struct _GnomeControlCenter
 {
-  CcShell parent;
-
+  GtkApplicationWindow parent;
   GnomeControlCenterPrivate *priv;
 };
 
 struct _GnomeControlCenterClass
 {
-  CcShellClass parent_class;
+  GtkApplicationWindowClass parent_class;
 };
 
 GType gnome_control_center_get_type (void) G_GNUC_CONST;
 
-GnomeControlCenter *gnome_control_center_new (void);
+GnomeControlCenter *gnome_control_center_new (GtkApplication *application);
 
 void gnome_control_center_present (GnomeControlCenter *center);
 
-void gnome_control_center_show (GnomeControlCenter *center, GtkApplication *app);
+void gnome_control_center_show (GnomeControlCenter *center);
 
 void gnome_control_center_set_overview_page (GnomeControlCenter *center);
 


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