Merge lp:~ted/indicator-applet/dynamic-allocation into lp:indicator-applet/0.4

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-applet/dynamic-allocation
Merge into: lp:indicator-applet/0.4
Diff against target: 112 lines (+61/-18)
1 file modified
src/applet-main.c (+61/-18)
To merge this branch: bzr merge lp:~ted/indicator-applet/dynamic-allocation
Reviewer Review Type Date Requested Status
David Barth Approve
Review via email: mp+15230@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

This patch makes it so that the indicator applet can respond to entries being added and removed.

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, 2009-11-25 at 03:35 +0000, Ted Gould wrote:
>
> + 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);
> + }

I'd be tempted to have a helper function for this idiom, though its
right on the lower bound of being useful for that.

Is this something that can be tested?

 review; approve

Revision history for this message
David Barth (dbarth) :
review: Approve
Revision history for this message
Ted Gould (ted) wrote :

On Wed, 2009-11-25 at 05:36 +0000, Robert Collins wrote:
> On Wed, 2009-11-25 at 03:35 +0000, Ted Gould wrote:
> >
> > + 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);
> > + }
>
> I'd be tempted to have a helper function for this idiom, though its
> right on the lower bound of being useful for that.

The problem is that C doesn't have an easy to use "foreach" type
construct. So you end up building datatypes to make it reasonable,
which doesn't make the code any shorter :(

> Is this something that can be tested?

Not really. We'd need a Bonobo test harness. I'm not up for writing
one, especially with Bonobo being deprecated.

  --Ted

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, 2009-11-25 at 21:27 +0000, Ted Gould wrote:
> + if (entry->image != NULL) {
> > > + gtk_box_pack_start(GTK_BOX(hbox),
> > > GTK_WIDGET(entry->image), FALSE, FALSE, 0);

re: datatypes - you have those, don't you? (GTK_WIDGET, GTK_BOX, ..) Or
does GTK_WIDGET barf on NULL ? (in which case
GTK_WIDGET_NULL(entry->image);)

-Rob

Revision history for this message
Ted Gould (ted) wrote :

On Wed, 2009-11-25 at 21:51 +0000, Robert Collins wrote:
> On Wed, 2009-11-25 at 21:27 +0000, Ted Gould wrote:
> > + if (entry->image != NULL) {
> > > > + gtk_box_pack_start(GTK_BOX(hbox),
> > > > GTK_WIDGET(entry->image), FALSE, FALSE, 0);
>
> re: datatypes - you have those, don't you? (GTK_WIDGET, GTK_BOX, ..) Or
> does GTK_WIDGET barf on NULL ? (in which case
> GTK_WIDGET_NULL(entry->image);)

I don't believe that GTK_WIDGET will barf. I believe it just returns
NULL. Which (I haven't looked, but I'm pretty confident in) will cause
gtk_box_pack_start() to throw a warning/error. Which we can't catch and
not print because, well, it's C :)

  --Ted

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, 2009-11-25 at 21:57 +0000, Ted Gould wrote:
>
>
> I don't believe that GTK_WIDGET will barf. I believe it just returns
> NULL. Which (I haven't looked, but I'm pretty confident in) will
> cause
> gtk_box_pack_start() to throw a warning/error. Which we can't catch
> and
> not print because, well, it's C :)

I know :)

The helper I had in mind was:

void
foo(GtkWidget *widget ....) {
if (NULL == widget)
   return;
....
}

Note that I'm not asking you to do this, as I mentioned its just
something I'd consider doing.

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/applet-main.c'
2--- src/applet-main.c 2009-11-04 20:11:04 +0000
3+++ src/applet-main.c 2009-11-25 03:35:21 +0000
4@@ -25,6 +25,8 @@
5
6 #include "libindicator/indicator-object.h"
7
8+#define ENTRY_DATA_NAME "indicator-custom-entry-data"
9+
10 static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);
11
12
13@@ -46,6 +48,58 @@
14 /*************
15 * init function
16 * ***********/
17+static void
18+entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menu)
19+{
20+ g_debug("Signal: Entry Added");
21+
22+ GtkWidget * menuitem = gtk_menu_item_new();
23+ GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
24+
25+ if (entry->image != NULL) {
26+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
27+ }
28+ if (entry->label != NULL) {
29+ gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
30+ }
31+ gtk_container_add(GTK_CONTAINER(menuitem), hbox);
32+ gtk_widget_show(hbox);
33+
34+ if (entry->menu != NULL) {
35+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
36+ }
37+
38+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
39+ gtk_widget_show(menuitem);
40+
41+ g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry);
42+
43+ return;
44+}
45+
46+static void
47+entry_removed_cb (GtkWidget * widget, gpointer userdata)
48+{
49+ gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);
50+
51+ if (data != userdata) {
52+ return;
53+ }
54+
55+ gtk_widget_destroy(widget);
56+ return;
57+}
58+
59+static void
60+entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
61+{
62+ g_debug("Signal: Entry Removed");
63+
64+ gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
65+
66+ return;
67+}
68+
69 static gboolean
70 load_module (const gchar * name, GtkWidget * menu)
71 {
72@@ -58,33 +112,22 @@
73
74 g_debug("Loading Module: %s", name);
75
76+ /* Build the object for the module */
77 gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
78 IndicatorObject * io = indicator_object_new_from_file(fullpath);
79 g_free(fullpath);
80
81+ /* Connect to it's signals */
82+ g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu);
83+ g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu);
84+
85+ /* Work on the entries */
86 GList * entries = indicator_object_get_entries(io);
87 GList * entry = NULL;
88
89 for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
90 IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
91-
92- GtkWidget * menuitem = gtk_menu_item_new();
93- GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
94- if (entrydata->image != NULL) {
95- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->image), FALSE, FALSE, 0);
96- }
97- if (entrydata->label != NULL) {
98- gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
99- }
100- gtk_container_add(GTK_CONTAINER(menuitem), hbox);
101- gtk_widget_show(hbox);
102-
103- if (entrydata->menu != NULL) {
104- gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
105- }
106-
107- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
108- gtk_widget_show(menuitem);
109+ entry_added(io, entrydata, menu);
110 }
111
112 g_list_free(entries);

Subscribers

People subscribed via source and target branches

to status/vote changes: