[rhythmbox] button-bar: add ability to create buttons that trigger action signals



commit 48da5fbe8774c10e7e5e9e83dad3d5f88166d35c
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Mar 3 23:16:32 2013 +1000

    button-bar: add ability to create buttons that trigger action signals

 widgets/rb-button-bar.c |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/widgets/rb-button-bar.c b/widgets/rb-button-bar.c
index c9ffbef..fc4ec74 100644
--- a/widgets/rb-button-bar.c
+++ b/widgets/rb-button-bar.c
@@ -67,6 +67,14 @@ clear_button_bar (RBButtonBar *bar)
        bar->priv->position = 0;
 }
 
+static void
+signal_button_clicked_cb (GtkButton *button, RBButtonBar *bar)
+{
+       guint signal_id;
+       signal_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "rb-signal-bind-id"));
+       g_signal_emit (bar->priv->target, signal_id, 0);
+}
+
 static gboolean
 append_menu (RBButtonBar *bar, GMenuModel *menu, gboolean need_separator)
 {
@@ -111,9 +119,11 @@ append_menu (RBButtonBar *bar, GMenuModel *menu, gboolean need_separator)
                        const char *name;
                        GVariant *value;
                        char *str;
+                       guint signal_id;
                
-                       /* we can't do more than one of action and rb-property-bind,
-                        * so just do whichever turns up first in the iterator
+                       /* we can't do more than one of action and rb-property-bind
+                        * and rb-signal-bind, so just do whichever turns up first
+                        * in the iterator
                         */
                        iter = g_menu_model_iterate_item_attributes (menu, i);
                        while (g_menu_attribute_iter_get_next (iter, &name, &value)) {
@@ -133,6 +143,16 @@ append_menu (RBButtonBar *bar, GMenuModel *menu, gboolean need_separator)
                                                                G_BINDING_BIDIRECTIONAL | 
G_BINDING_SYNC_CREATE);
                                        g_free (str);
                                        break;
+                               } else if (g_str_equal (name, "rb-signal-bind")) {
+                                       button = gtk_button_new ();
+                                       g_variant_get (value, "s", &str, NULL);
+                                       signal_id = g_signal_lookup (str, G_OBJECT_TYPE (bar->priv->target));
+                                       if (signal_id != 0) {
+                                               g_object_set_data (G_OBJECT (button), "rb-signal-bind-id", 
GUINT_TO_POINTER (signal_id));
+                                               g_signal_connect (button, "clicked", G_CALLBACK 
(signal_button_clicked_cb), bar);
+                                       }
+                                       g_free (str);
+                                       break;
                                }
                        }
 


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