ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00632
[Branch ~indicator-applet-developers/indicator-applet/applet] Rev 334: Start handling the addition and removal of entries in the applet.
Merge authors:
Ted Gould (ted)
Ted Gould (ted)
Related merge proposals:
https://code.launchpad.net/~ted/indicator-applet/dynamic-allocation/+merge/15230
proposed by: Ted Gould (ted)
review: Approve - David Barth (dbarth)
------------------------------------------------------------
revno: 334 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: applet
timestamp: Wed 2009-11-25 15:26:04 -0600
message:
Start handling the addition and removal of entries in the applet.
modified:
src/applet-main.c
--
lp:indicator-applet
https://code.launchpad.net/~indicator-applet-developers/indicator-applet/applet
Your team ayatana-commits is subscribed to branch lp:indicator-applet.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-applet/applet/+edit-subscription.
=== modified file 'src/applet-main.c'
--- src/applet-main.c 2009-11-04 20:11:04 +0000
+++ src/applet-main.c 2009-11-24 23:15:22 +0000
@@ -25,6 +25,8 @@
#include "libindicator/indicator-object.h"
+#define ENTRY_DATA_NAME "indicator-custom-entry-data"
+
static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);
@@ -46,6 +48,58 @@
/*************
* init function
* ***********/
+static void
+entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menu)
+{
+ g_debug("Signal: Entry Added");
+
+ 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(menu), menuitem);
+ gtk_widget_show(menuitem);
+
+ g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry);
+
+ return;
+}
+
+static void
+entry_removed_cb (GtkWidget * widget, gpointer userdata)
+{
+ gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);
+
+ if (data != userdata) {
+ return;
+ }
+
+ gtk_widget_destroy(widget);
+ return;
+}
+
+static void
+entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
+{
+ g_debug("Signal: Entry Removed");
+
+ gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
+
+ return;
+}
+
static gboolean
load_module (const gchar * name, GtkWidget * menu)
{
@@ -58,33 +112,22 @@
g_debug("Loading Module: %s", name);
+ /* Build the object for the module */
gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
IndicatorObject * io = indicator_object_new_from_file(fullpath);
g_free(fullpath);
+ /* Connect to it's signals */
+ 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);
+
+ /* Work on the entries */
GList * entries = indicator_object_get_entries(io);
GList * entry = NULL;
for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
-
- GtkWidget * menuitem = gtk_menu_item_new();
- GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
- if (entrydata->image != NULL) {
- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->image), FALSE, FALSE, 0);
- }
- if (entrydata->label != NULL) {
- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
- }
- gtk_container_add(GTK_CONTAINER(menuitem), hbox);
- gtk_widget_show(hbox);
-
- if (entrydata->menu != NULL) {
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
- }
-
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- gtk_widget_show(menuitem);
+ entry_added(io, entrydata, menu);
}
g_list_free(entries);