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
=== modified file 'src/applet-main.c'
--- src/applet-main.c 2009-11-04 20:11:04 +0000
+++ src/applet-main.c 2009-11-25 03:35:21 +0000
@@ -25,6 +25,8 @@
2525
26#include "libindicator/indicator-object.h"26#include "libindicator/indicator-object.h"
2727
28#define ENTRY_DATA_NAME "indicator-custom-entry-data"
29
28static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);30static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);
2931
3032
@@ -46,6 +48,58 @@
46/*************48/*************
47 * init function49 * init function
48 * ***********/50 * ***********/
51static void
52entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menu)
53{
54 g_debug("Signal: Entry Added");
55
56 GtkWidget * menuitem = gtk_menu_item_new();
57 GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
58
59 if (entry->image != NULL) {
60 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
61 }
62 if (entry->label != NULL) {
63 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
64 }
65 gtk_container_add(GTK_CONTAINER(menuitem), hbox);
66 gtk_widget_show(hbox);
67
68 if (entry->menu != NULL) {
69 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
70 }
71
72 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
73 gtk_widget_show(menuitem);
74
75 g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry);
76
77 return;
78}
79
80static void
81entry_removed_cb (GtkWidget * widget, gpointer userdata)
82{
83 gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);
84
85 if (data != userdata) {
86 return;
87 }
88
89 gtk_widget_destroy(widget);
90 return;
91}
92
93static void
94entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
95{
96 g_debug("Signal: Entry Removed");
97
98 gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);
99
100 return;
101}
102
49static gboolean103static gboolean
50load_module (const gchar * name, GtkWidget * menu)104load_module (const gchar * name, GtkWidget * menu)
51{105{
@@ -58,33 +112,22 @@
58112
59 g_debug("Loading Module: %s", name);113 g_debug("Loading Module: %s", name);
60114
115 /* Build the object for the module */
61 gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);116 gchar * fullpath = g_build_filename(INDICATOR_DIR, name, NULL);
62 IndicatorObject * io = indicator_object_new_from_file(fullpath);117 IndicatorObject * io = indicator_object_new_from_file(fullpath);
63 g_free(fullpath);118 g_free(fullpath);
64119
120 /* Connect to it's signals */
121 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu);
122 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu);
123
124 /* Work on the entries */
65 GList * entries = indicator_object_get_entries(io);125 GList * entries = indicator_object_get_entries(io);
66 GList * entry = NULL;126 GList * entry = NULL;
67127
68 for (entry = entries; entry != NULL; entry = g_list_next(entry)) {128 for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
69 IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;129 IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
70130 entry_added(io, entrydata, menu);
71 GtkWidget * menuitem = gtk_menu_item_new();
72 GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
73 if (entrydata->image != NULL) {
74 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->image), FALSE, FALSE, 0);
75 }
76 if (entrydata->label != NULL) {
77 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entrydata->label), FALSE, FALSE, 0);
78 }
79 gtk_container_add(GTK_CONTAINER(menuitem), hbox);
80 gtk_widget_show(hbox);
81
82 if (entrydata->menu != NULL) {
83 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entrydata->menu));
84 }
85
86 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
87 gtk_widget_show(menuitem);
88 }131 }
89132
90 g_list_free(entries);133 g_list_free(entries);

Subscribers

People subscribed via source and target branches

to status/vote changes: