[gdl] Notify the switcher when the name/icon of the GdlDockItem changes



commit 19b1241ed8e2367eb214c90ac90e9908fb678c31
Author: Johannes Schmid <jhs gnome org>
Date:   Sat Apr 24 14:17:29 2010 +0200

    Notify the switcher when the name/icon of the GdlDockItem changes
    
    This is used to update the button accordingly (bgo #516738)

 gdl/gdl-switcher.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 6 deletions(-)
---
diff --git a/gdl/gdl-switcher.c b/gdl/gdl-switcher.c
index 5399bb3..74f954f 100644
--- a/gdl/gdl-switcher.c
+++ b/gdl/gdl-switcher.c
@@ -51,7 +51,8 @@ static void gdl_switcher_add_button  (GdlSwitcher *switcher,
                                       const gchar *label,
                                       const gchar *tooltips,
                                       const gchar *stock_id,
-                                      gint switcher_id);
+                                      gint switcher_id,
+                                      GtkWidget *page);
 /* static void gdl_switcher_remove_button (GdlSwitcher *switcher, gint switcher_id); */
 static void gdl_switcher_select_page (GdlSwitcher *switcher, gint switcher_id);
 static void gdl_switcher_select_button (GdlSwitcher *switcher, gint switcher_id);
@@ -71,6 +72,7 @@ typedef struct {
     GtkWidget *icon;
     GtkWidget *arrow;
     GtkWidget *hbox;
+    GtkWidget *page;
     int id;
 } Button;
 
@@ -97,9 +99,36 @@ GDL_CLASS_BOILERPLATE (GdlSwitcher, gdl_switcher, GtkNotebook, GTK_TYPE_NOTEBOOK
 
 /* Utility functions.  */
 
+static void
+gdl_switcher_long_name_changed (GObject* object,
+                                GParamSpec* spec,
+                                gpointer user_data)
+{
+    Button* button = user_data;
+    gchar* label;
+
+    g_object_get (object, "long-name", &label, NULL);
+    gtk_label_set_text (GTK_LABEL (button->label), label);
+    g_free (label);
+}
+
+static void
+gdl_switcher_stock_id_changed (GObject* object,
+                               GParamSpec* spec,
+                               gpointer user_data)
+{
+    Button* button = user_data;
+    gchar* id;
+
+    g_object_get (object, "stock-id", &id, NULL);
+    gtk_image_set_from_stock (GTK_IMAGE(button->icon), id, GTK_ICON_SIZE_MENU);
+    g_free (id);
+}
+
+
 static Button *
 button_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
-            GtkWidget *arrow, GtkWidget *hbox, int id)
+            GtkWidget *arrow, GtkWidget *hbox, int id, GtkWidget *page)
 {
     Button *button = g_new (Button, 1);
 
@@ -109,7 +138,13 @@ button_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
     button->arrow = arrow;
     button->hbox = hbox;
     button->id = id;
+    button->page = page;
 
+    g_signal_connect (page, "notify::long-name", G_CALLBACK (gdl_switcher_long_name_changed), 
+                      button);
+    g_signal_connect (page, "notify::stock-id", G_CALLBACK (gdl_switcher_stock_id_changed), 
+                      button);
+    
     g_object_ref (button_widget);
     g_object_ref (label);
     g_object_ref (icon);
@@ -122,6 +157,13 @@ button_new (GtkWidget *button_widget, GtkWidget *label, GtkWidget *icon,
 static void
 button_free (Button *button)
 {
+    g_signal_handlers_disconnect_by_func (button->page,
+                                          gdl_switcher_long_name_changed,
+                                          button);
+    g_signal_handlers_disconnect_by_func (button->page,
+                                          gdl_switcher_stock_id_changed,
+                                          button);    
+    
     g_object_unref (button->button_widget);
     g_object_unref (button->label);
     g_object_unref (button->icon);
@@ -629,7 +671,7 @@ gdl_switcher_page_added_cb (GtkNotebook *nb, GtkWidget *page,
     switcher_id = gdl_switcher_get_page_id (page);
     
     gdl_switcher_add_button (GDL_SWITCHER (switcher), NULL, NULL, NULL,
-                             switcher_id);
+                             switcher_id, page);
     gdl_switcher_select_button (GDL_SWITCHER (switcher), switcher_id);
 }
 
@@ -739,7 +781,7 @@ gdl_switcher_new (void)
 void
 gdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
                          const gchar *tooltips, const gchar *stock_id,
-                         gint switcher_id)
+                         gint switcher_id, GtkWidget* page)
 {
     GtkWidget *event_box;
     GtkWidget *button_widget;
@@ -799,7 +841,7 @@ gdl_switcher_add_button (GdlSwitcher *switcher, const gchar *label,
         g_slist_append (switcher->priv->buttons,
                         button_new (button_widget, label_widget,
                                     icon_widget,
-                                    arrow, hbox, switcher_id));
+                                    arrow, hbox, switcher_id, page));
     
     gtk_widget_set_parent (button_widget, GTK_WIDGET (switcher));
     gtk_widget_queue_resize (GTK_WIDGET (switcher));
@@ -833,6 +875,7 @@ gdl_switcher_select_button (GdlSwitcher *switcher, gint switcher_id)
     /* Select the notebook page associated with this button */
     gdl_switcher_select_page (switcher, switcher_id);
 }
+   
 
 gint
 gdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
@@ -851,12 +894,14 @@ gdl_switcher_insert_page (GdlSwitcher *switcher, GtkWidget *page,
         gtk_widget_show (tab_widget);
     }
     switcher_id = gdl_switcher_get_page_id (page);
-    gdl_switcher_add_button (switcher, label, tooltips, stock_id, switcher_id);
+    gdl_switcher_add_button (switcher, label, tooltips, stock_id, switcher_id, page);
+    
     ret_position = gtk_notebook_insert_page (GTK_NOTEBOOK (switcher), page,
                                              tab_widget, position);
     g_signal_handlers_unblock_by_func (switcher,
                                        gdl_switcher_page_added_cb,
                                        switcher);
+    
     return ret_position;
 }
 



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