[Xfce4-commits] <xfce4-indicator-plugin:master> Add entry_{added, removed} signal handlers

Mark Trompell noreply at xfce.org
Mon Feb 21 23:00:01 CET 2011


Updating branch refs/heads/master
         to 16d8daa8bc6e695eaf5032c122c9a4d41ba079bd (commit)
       from 5fd54ab20467bdd2f44dc5c9c1455eb3a99278c2 (commit)

commit 16d8daa8bc6e695eaf5032c122c9a4d41ba079bd
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Mon Feb 21 22:51:31 2011 +0100

    Add entry_{added,removed} signal handlers

 panel-plugin/indicator.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index b769297..1c66999 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -308,6 +308,50 @@ indicator_construct (XfcePanelPlugin *plugin)
 }
 
 
+static void
+entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
+{
+  GtkWidget * menuitem = gtk_menu_item_new();
+  GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
+
+  if (entry->image != NULL)
+    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
+
+  if (entry->label != NULL)
+    gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
+
+  gtk_container_add(GTK_CONTAINER(menuitem), hbox);
+  gtk_widget_show(hbox);
+
+  if (entry->menu != NULL)
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
+
+  gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem);
+  gtk_widget_show(menuitem);
+
+  g_object_set_data(G_OBJECT(menuitem), "indicator-custom-entry-data", entry);
+}
+
+
+static void
+entry_removed_cb (GtkWidget * widget, gpointer userdata)
+{
+  gpointer data = g_object_get_data(G_OBJECT(widget), "indicator-custom-entry-data");
+
+  if (data != userdata)
+    return;
+
+  gtk_widget_destroy(widget);
+}
+
+
+static void
+entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
+{
+  gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
+}
+
+
 static gboolean
 load_module (const gchar * name, GtkWidget * menu)
 {
@@ -323,6 +367,11 @@ load_module (const gchar * name, GtkWidget * menu)
 	IndicatorObject * io = indicator_object_new_from_file(fullpath);
 	g_free(fullpath);
 
+    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
+                     G_CALLBACK(entry_added), menu);
+    g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
+                     G_CALLBACK(entry_removed), menu);
+
 	GList * entries = indicator_object_get_entries(io);
 	GList * entry = NULL;
 



More information about the Xfce4-commits mailing list