[gnome-initial-setup] assistant: Use a headerbar



commit 8637c7c1126535f5ac5433b445f24ca6cf4928e8
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jun 11 23:48:12 2013 -0400

    assistant: Use a headerbar
    
    This brings the layout much closer to the design.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702059

 gnome-initial-setup/gis-assistant.c        |   45 ++++++++++++++++++++--------
 gnome-initial-setup/gis-assistant.h        |    3 +-
 gnome-initial-setup/gis-center-container.c |   35 ++++------------------
 gnome-initial-setup/gis-center-container.h |    3 +-
 gnome-initial-setup/gis-driver.c           |   13 +-------
 5 files changed, 43 insertions(+), 56 deletions(-)
---
diff --git a/gnome-initial-setup/gis-assistant.c b/gnome-initial-setup/gis-assistant.c
index 8ea36c4..fe20571 100644
--- a/gnome-initial-setup/gis-assistant.c
+++ b/gnome-initial-setup/gis-assistant.c
@@ -58,6 +58,7 @@ struct _GisAssistantPrivate
   GtkWidget *action_area;
   GtkWidget *page_action_widget_area;
   GtkWidget *spinner;
+  GtkWidget *titlebar;
 
   GList *pages;
   GisPage *current_page;
@@ -250,6 +251,10 @@ update_navigation_buttons (GisAssistant *assistant)
 
       can_go_forward = gis_page_get_complete (page);
       gtk_widget_set_sensitive (priv->forward, can_go_forward);
+      if (can_go_forward)
+        gtk_style_context_add_class (gtk_widget_get_style_context (priv->forward), "suggested-action");
+      else
+        gtk_style_context_remove_class (gtk_widget_get_style_context (priv->forward), "suggested-action");
     }
 }
 
@@ -273,6 +278,15 @@ update_applying_state (GisAssistant *assistant)
 }
 
 static void
+update_titlebar (GisAssistant *assistant)
+{
+  GisAssistantPrivate *priv = gis_assistant_get_instance_private (assistant);
+
+  gtk_header_bar_set_title (GTK_HEADER_BAR (priv->titlebar),
+                            gis_assistant_get_title (assistant));
+}
+
+static void
 page_notify (GisPage      *page,
              GParamSpec   *pspec,
              GisAssistant *assistant)
@@ -351,7 +365,7 @@ do_cancel (GtkWidget    *button,
     gis_page_apply_cancel (priv->current_page);
 }
 
-gchar *
+const gchar *
 gis_assistant_get_title (GisAssistant *assistant)
 {
   GisAssistantPrivate *priv = gis_assistant_get_instance_private (assistant);
@@ -362,6 +376,13 @@ gis_assistant_get_title (GisAssistant *assistant)
 }
 
 GtkWidget *
+gis_assistant_get_titlebar (GisAssistant *assistant)
+{
+  GisAssistantPrivate *priv = gis_assistant_get_instance_private (assistant);
+  return priv->titlebar;
+}
+
+GtkWidget *
 _gis_assistant_get_frame (GisAssistant *assistant)
 {
   GisAssistantPrivate *priv = gis_assistant_get_instance_private (assistant);
@@ -380,6 +401,7 @@ _gis_assistant_current_page_changed (GisAssistant *assistant,
   priv->current_page = page;
   g_object_notify_by_pspec (G_OBJECT (assistant), obj_props[PROP_TITLE]);
 
+  update_titlebar (assistant);
   update_applying_state (assistant);
   update_action_widget (assistant);
   update_navigation_buttons (assistant);
@@ -415,9 +437,11 @@ static void
 gis_assistant_init (GisAssistant *assistant)
 {
   GisAssistantPrivate *priv = gis_assistant_get_instance_private (assistant);
-  GtkWidget *navigation;
   GtkWidget *widget;
 
+  priv->titlebar = gtk_header_bar_new ();
+  gtk_widget_show (priv->titlebar);
+
   priv->main_layout = gtk_box_new (GTK_ORIENTATION_VERTICAL, 20);
   gtk_box_pack_start (GTK_BOX (assistant), priv->main_layout, TRUE, TRUE, 0);
 
@@ -427,11 +451,6 @@ gis_assistant_init (GisAssistant *assistant)
 
   priv->page_action_widget_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
-  navigation = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  gtk_box_set_homogeneous (GTK_BOX (navigation), TRUE);
-  gtk_widget_set_halign (navigation, GTK_ALIGN_END);
-  gtk_widget_set_hexpand (navigation, TRUE);
-
   priv->forward = gtk_button_new ();
   gtk_button_set_image (GTK_BUTTON (priv->forward),
                         gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON));
@@ -448,16 +467,17 @@ gis_assistant_init (GisAssistant *assistant)
                         gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
   gtk_button_set_use_underline (GTK_BUTTON (priv->cancel), TRUE);
 
+  gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->titlebar), priv->cancel);
+  gtk_header_bar_pack_start (GTK_HEADER_BAR (priv->titlebar), priv->back);
+
   priv->spinner = gtk_spinner_new ();
   widget = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
   gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 0, 0, 12, 6);
-  gtk_box_pack_start (GTK_BOX (navigation), widget, FALSE, FALSE, 0);
+  gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->titlebar), widget);
   gtk_container_add (GTK_CONTAINER (widget), priv->spinner);
   gtk_widget_show (widget);
 
-  gtk_box_pack_start (GTK_BOX (navigation), priv->cancel, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (navigation), priv->back, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (navigation), priv->forward, FALSE, FALSE, 0);
+  gtk_header_bar_pack_end (GTK_HEADER_BAR (priv->titlebar), priv->forward);
 
   g_signal_connect (priv->forward, "clicked", G_CALLBACK (go_forward), assistant);
   g_signal_connect (priv->back, "clicked", G_CALLBACK (go_backward), assistant);
@@ -467,8 +487,7 @@ gis_assistant_init (GisAssistant *assistant)
   gtk_widget_set_halign (priv->progress_indicator, GTK_ALIGN_CENTER);
 
   priv->action_area = gis_center_container_new (priv->page_action_widget_area,
-                                                priv->progress_indicator,
-                                                navigation);
+                                                priv->progress_indicator);
 
   gis_assistant_locale_changed (assistant);
   gtk_box_pack_start (GTK_BOX (priv->main_layout), priv->action_area, FALSE, TRUE, 0);
diff --git a/gnome-initial-setup/gis-assistant.h b/gnome-initial-setup/gis-assistant.h
index dd3c79a..ba4bdf3 100644
--- a/gnome-initial-setup/gis-assistant.h
+++ b/gnome-initial-setup/gis-assistant.h
@@ -67,7 +67,8 @@ void      gis_assistant_next_page         (GisAssistant *assistant);
 void      gis_assistant_previous_page     (GisAssistant *assistant);
 GisPage * gis_assistant_get_current_page  (GisAssistant *assistant);
 GList   * gis_assistant_get_all_pages     (GisAssistant *assistant);
-gchar *   gis_assistant_get_title         (GisAssistant *assistant);
+const gchar *gis_assistant_get_title      (GisAssistant *assistant);
+GtkWidget *gis_assistant_get_titlebar     (GisAssistant *assistant);
 
 void      gis_assistant_locale_changed    (GisAssistant *assistant);
 void      gis_assistant_save_data         (GisAssistant *assistant);
diff --git a/gnome-initial-setup/gis-center-container.c b/gnome-initial-setup/gis-center-container.c
index 1b4a0ef..0df4fe7 100644
--- a/gnome-initial-setup/gis-center-container.c
+++ b/gnome-initial-setup/gis-center-container.c
@@ -28,7 +28,6 @@ struct _GisCenterContainerPrivate
 {
   GtkWidget *left;
   GtkWidget *center;
-  GtkWidget *right;
 };
 typedef struct _GisCenterContainerPrivate GisCenterContainerPrivate;
 
@@ -61,10 +60,6 @@ gis_center_container_get_preferred_width (GtkWidget *widget,
   sum_min = sum_min + child_min;
   sum_nat = sum_nat + child_nat + SPACING;
 
-  gtk_widget_get_preferred_width (priv->right, &child_min, &child_nat);
-  sum_min = sum_min + child_min;
-  sum_nat = sum_nat + child_nat + SPACING;
-
   if (minimum_size)
     *minimum_size = sum_min;
   if (natural_size)
@@ -89,10 +84,6 @@ gis_center_container_get_preferred_height (GtkWidget *widget,
   max_min = MAX (max_min, child_min);
   max_nat = MAX (max_nat, child_nat);
 
-  gtk_widget_get_preferred_height (priv->right, &child_min, &child_nat);
-  max_min = MAX (max_min, child_min);
-  max_nat = MAX (max_nat, child_nat);
-
   if (minimum_size)
     *minimum_size = max_min;
   if (natural_size)
@@ -106,7 +97,7 @@ gis_center_container_size_allocate (GtkWidget     *widget,
   GisCenterContainer *center = GIS_CENTER_CONTAINER (widget);
   GisCenterContainerPrivate *priv = gis_center_container_get_instance_private (center);
   GtkAllocation child_allocation;
-  gint max_side;
+  gint left_side;
 
   gtk_widget_set_allocation (widget, allocation);
 
@@ -114,23 +105,14 @@ gis_center_container_size_allocate (GtkWidget     *widget,
   child_allocation.height = allocation->height;
 
   /* XXX -- fix minimum allocations */
-  {
-    gint left_side, right_side;
-    gtk_widget_get_preferred_width (priv->left, NULL, &left_side);
-    gtk_widget_get_preferred_width (priv->right, NULL, &right_side);
-    max_side = MAX (left_side, right_side);
-  }
-
-  child_allocation.width = max_side;
+  gtk_widget_get_preferred_width (priv->left, NULL, &left_side);
 
   child_allocation.x = allocation->x;
+  child_allocation.width = left_side;
   gtk_widget_size_allocate (priv->left, &child_allocation);
 
-  child_allocation.x = allocation->x + allocation->width - max_side;
-  gtk_widget_size_allocate (priv->right, &child_allocation);
-
-  child_allocation.x = allocation->x + max_side + SPACING;
-  child_allocation.width = allocation->width - max_side * 2 - SPACING * 2;
+  child_allocation.x = allocation->x + left_side + SPACING;
+  child_allocation.width = allocation->width - left_side * 2 - SPACING * 2;
   gtk_widget_size_allocate (priv->center, &child_allocation);
 }
 
@@ -151,7 +133,6 @@ gis_center_container_forall (GtkContainer *container,
 
   callback (priv->left, callback_data);
   callback (priv->center, callback_data);
-  callback (priv->right, callback_data);
 }
 
 static void
@@ -171,8 +152,7 @@ gis_center_container_class_init (GisCenterContainerClass *class)
 
 GtkWidget *
 gis_center_container_new (GtkWidget *left,
-                          GtkWidget *center,
-                          GtkWidget *right)
+                          GtkWidget *center)
 {
   GisCenterContainer *container = g_object_new (GIS_TYPE_CENTER_CONTAINER, NULL);
   GisCenterContainerPrivate *priv = gis_center_container_get_instance_private (container);
@@ -183,9 +163,6 @@ gis_center_container_new (GtkWidget *left,
   priv->center = center;
   gtk_widget_set_parent (center, GTK_WIDGET (container));
 
-  priv->right = right;
-  gtk_widget_set_parent (right, GTK_WIDGET (container));
-
   return GTK_WIDGET (container);
 }
 
diff --git a/gnome-initial-setup/gis-center-container.h b/gnome-initial-setup/gis-center-container.h
index 68c36f5..ddc5834 100644
--- a/gnome-initial-setup/gis-center-container.h
+++ b/gnome-initial-setup/gis-center-container.h
@@ -52,8 +52,7 @@ struct _GisCenterContainerClass
 GType gis_center_container_get_type (void);
 
 GtkWidget * gis_center_container_new (GtkWidget *left,
-                                      GtkWidget *center,
-                                      GtkWidget *right);
+                                      GtkWidget *center);
 
 G_END_DECLS
 
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index da6d07f..dd1758f 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -92,15 +92,6 @@ gis_driver_finalize (GObject *object)
 }
 
 static void
-title_changed_cb (GisAssistant *assistant,
-                  GParamSpec   *gparam,
-                  GisDriver    *driver)
-{
-  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
-  gtk_window_set_title (priv->main_window, gis_assistant_get_title (assistant));
-}
-
-static void
 prepare_main_window (GisDriver *driver)
 {
   GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
@@ -115,8 +106,8 @@ prepare_main_window (GisDriver *driver)
                                  &size_hints,
                                  GDK_HINT_MIN_SIZE | GDK_HINT_WIN_GRAVITY);
 
-  g_signal_connect (priv->assistant, "notify::title",
-                    G_CALLBACK (title_changed_cb), driver);
+  gtk_window_set_titlebar (priv->main_window,
+                           gis_assistant_get_titlebar (priv->assistant));
 }
 
 static gboolean


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