Merge lp:~indicator-applet-developers/indicator-applet/ubuntu into lp:~ubuntu-desktop/indicator-applet/ubuntu

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~indicator-applet-developers/indicator-applet/ubuntu
Merge into: lp:~ubuntu-desktop/indicator-applet/ubuntu
Diff against target: 342 lines (+235/-6)
4 files modified
configure.ac (+1/-1)
debian/changelog (+10/-0)
debian/control (+1/-1)
src/applet-main.c (+223/-4)
To merge this branch: bzr merge lp:~indicator-applet-developers/indicator-applet/ubuntu
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+17838@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

0.3.2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2010-01-08 14:52:07 +0000
3+++ configure.ac 2010-01-21 19:33:15 +0000
4@@ -4,7 +4,7 @@
5 AC_PREREQ(2.53)
6
7 AM_CONFIG_HEADER(config.h)
8-AM_INIT_AUTOMAKE(indicator-applet, 0.3.1)
9+AM_INIT_AUTOMAKE(indicator-applet, 0.3.2)
10
11 AM_MAINTAINER_MODE
12 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES])
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2010-01-11 15:48:56 +0000
16+++ debian/changelog 2010-01-21 19:33:15 +0000
17@@ -1,3 +1,13 @@
18+indicator-applet (0.3.2-0ubuntu1~ppa1) karmic; urgency=low
19+
20+ * Upstream release 0.3.2
21+ * Send debug information to a file
22+ * Adding support for sorting the indicators.
23+ * debian/control: Increasing libindicator required version to
24+ version 0.3.1 for the reordering functions.
25+
26+ -- Ted Gould <ted@ubuntu.com> Thu, 21 Jan 2010 13:31:03 -0600
27+
28 indicator-applet (0.3.1-0ubuntu3) lucid; urgency=low
29
30 * debian/control:
31
32=== modified file 'debian/control'
33--- debian/control 2010-01-11 15:48:56 +0000
34+++ debian/control 2010-01-21 19:33:15 +0000
35@@ -12,7 +12,7 @@
36 intltool,
37 libxml2-dev,
38 gtk-doc-tools,
39- libindicator-dev (>= 0.3.0)
40+ libindicator-dev (>= 0.3.1)
41 Standards-Version: 3.8.0
42 Homepage: https://launchpad.net/indicator-applet
43 Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-desktop/indicator-applet/ubuntu
44
45=== modified file 'src/applet-main.c'
46--- src/applet-main.c 2010-01-04 20:08:59 +0000
47+++ src/applet-main.c 2010-01-21 19:33:15 +0000
48@@ -20,12 +20,26 @@
49 with this program. If not, see <http://www.gnu.org/licenses/>.
50 */
51
52+#include <stdlib.h>
53 #include <config.h>
54 #include <panel-applet.h>
55
56 #include "libindicator/indicator-object.h"
57
58-#define ENTRY_DATA_NAME "indicator-custom-entry-data"
59+
60+static gchar * indicator_order[] = {
61+ "libapplication.so",
62+ "libmessaging.so",
63+ "libdatetime.so",
64+ "libme.so",
65+ "libsession.so",
66+ NULL
67+};
68+
69+#define MENU_DATA_INDICATOR_OBJECT "indicator-object"
70+#define MENU_DATA_INDICATOR_ENTRY "indicator-entry"
71+
72+#define IO_DATA_ORDER_NUMBER "indicator-order-number"
73
74 static gboolean applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data);
75
76@@ -60,8 +74,94 @@
77 #endif
78
79 /*************
80+ * log files
81+ * ***********/
82+#ifdef INDICATOR_APPLET
83+#define LOG_FILE_NAME "indicator-applet.log"
84+#endif
85+#ifdef INDICATOR_APPLET_SESSION
86+#define LOG_FILE_NAME "indicator-applet-session.log"
87+#endif
88+#ifdef INDICATOR_APPLET_COMPLETE
89+#define LOG_FILE_NAME "indicator-applet-complete.log"
90+#endif
91+GOutputStream * log_file = NULL;
92+
93+/*************
94 * init function
95 * ***********/
96+
97+static gint
98+name2order (const gchar * name) {
99+ int i;
100+
101+ for (i = 0; indicator_order[i] != NULL; i++) {
102+ if (g_strcmp0(name, indicator_order[i]) == 0) {
103+ return i;
104+ }
105+ }
106+
107+ return -1;
108+}
109+
110+typedef struct _incoming_position_t incoming_position_t;
111+struct _incoming_position_t {
112+ gint objposition;
113+ gint entryposition;
114+ gint menupos;
115+ gboolean found;
116+};
117+
118+/* This function helps by determining where in the menu list
119+ this new entry should be placed. It compares the objects
120+ that they're on, and then the individual entries. Each
121+ is progressively more expensive. */
122+static void
123+place_in_menu (GtkWidget * widget, gpointer user_data)
124+{
125+ incoming_position_t * position = (incoming_position_t *)user_data;
126+ if (position->found) {
127+ /* We've already been placed, just finish the foreach */
128+ return;
129+ }
130+
131+ IndicatorObject * io = INDICATOR_OBJECT(g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_OBJECT));
132+ g_assert(io != NULL);
133+
134+ gint objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
135+ /* We've already passed it, well, then this is where
136+ we should be be. Stop! */
137+ if (objposition > position->objposition) {
138+ position->found = TRUE;
139+ return;
140+ }
141+
142+ /* The objects don't match yet, keep looking */
143+ if (objposition < position->objposition) {
144+ position->menupos++;
145+ return;
146+ }
147+
148+ /* The objects are the same, let's start looking at entries. */
149+ IndicatorObjectEntry * entry = (IndicatorObjectEntry *)g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
150+ gint entryposition = indicator_object_get_location(io, entry);
151+
152+ if (entryposition > position->entryposition) {
153+ position->found = TRUE;
154+ return;
155+ }
156+
157+ if (entryposition < position->entryposition) {
158+ position->menupos++;
159+ return;
160+ }
161+
162+ /* We've got the same object and the same entry. Well,
163+ let's just put it right here then. */
164+ position->found = TRUE;
165+ return;
166+}
167+
168 static void
169 entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, GtkWidget * menu)
170 {
171@@ -83,10 +183,19 @@
172 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
173 }
174
175- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
176+ incoming_position_t position;
177+ position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
178+ position.entryposition = indicator_object_get_location(io, entry);
179+ position.menupos = 0;
180+ position.found = FALSE;
181+
182+ gtk_container_foreach(GTK_CONTAINER(menu), place_in_menu, &position);
183+
184+ gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, position.menupos);
185 gtk_widget_show(menuitem);
186
187- g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry);
188+ g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_ENTRY, entry);
189+ g_object_set_data(G_OBJECT(menuitem), MENU_DATA_INDICATOR_OBJECT, io);
190
191 return;
192 }
193@@ -94,7 +203,7 @@
194 static void
195 entry_removed_cb (GtkWidget * widget, gpointer userdata)
196 {
197- gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);
198+ gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
199
200 if (data != userdata) {
201 return;
202@@ -114,6 +223,58 @@
203 return;
204 }
205
206+static void
207+entry_moved_find_cb (GtkWidget * widget, gpointer userdata)
208+{
209+ gpointer * array = (gpointer *)userdata;
210+ if (array[1] != NULL) {
211+ return;
212+ }
213+
214+ gpointer data = g_object_get_data(G_OBJECT(widget), MENU_DATA_INDICATOR_ENTRY);
215+
216+ if (data != array[0]) {
217+ return;
218+ }
219+
220+ array[1] = widget;
221+ return;
222+}
223+
224+/* Gets called when an entry for an object was moved. */
225+static void
226+entry_moved (IndicatorObject * io, IndicatorObjectEntry * entry, gint old, gint new, gpointer user_data)
227+{
228+ GtkWidget * menu = GTK_WIDGET(user_data);
229+
230+ gpointer array[2];
231+ array[0] = entry;
232+ array[1] = NULL;
233+
234+ gtk_container_foreach(GTK_CONTAINER(user_data), entry_moved_find_cb, array);
235+ if (array[1] == NULL) {
236+ g_warning("Moving an entry that isn't in our menus.");
237+ return;
238+ }
239+
240+ GtkWidget * mi = GTK_WIDGET(array[1]);
241+ g_object_ref(G_OBJECT(mi));
242+ gtk_container_remove(GTK_CONTAINER(user_data), mi);
243+
244+ incoming_position_t position;
245+ position.objposition = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER));
246+ position.entryposition = indicator_object_get_location(io, entry);
247+ position.menupos = 0;
248+ position.found = FALSE;
249+
250+ gtk_container_foreach(GTK_CONTAINER(menu), place_in_menu, &position);
251+
252+ gtk_menu_shell_insert(GTK_MENU_SHELL(menu), mi, position.menupos);
253+ g_object_unref(G_OBJECT(mi));
254+
255+ return;
256+}
257+
258 static gboolean
259 load_module (const gchar * name, GtkWidget * menu)
260 {
261@@ -131,9 +292,13 @@
262 IndicatorObject * io = indicator_object_new_from_file(fullpath);
263 g_free(fullpath);
264
265+ /* Attach the 'name' to the object */
266+ g_object_set_data(G_OBJECT(io), IO_DATA_ORDER_NUMBER, GINT_TO_POINTER(name2order(name)));
267+
268 /* Connect to it's signals */
269 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu);
270 g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu);
271+ g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED, G_CALLBACK(entry_moved), menu);
272
273 /* Work on the entries */
274 GList * entries = indicator_object_get_entries(io);
275@@ -228,6 +393,58 @@
276 #endif
277 #define N_(x) x
278
279+static void
280+log_to_file_cb (GObject * source_obj, GAsyncResult * result, gpointer user_data)
281+{
282+ g_free(user_data);
283+ return;
284+}
285+
286+static void
287+log_to_file (const gchar * domain, GLogLevelFlags level, const gchar * message, gpointer data)
288+{
289+ if (log_file == NULL) {
290+ GError * error = NULL;
291+ gchar * filename = g_build_filename(g_get_user_cache_dir(), LOG_FILE_NAME, NULL);
292+ GFile * file = g_file_new_for_path(filename);
293+ g_free(filename);
294+
295+ if (!g_file_test(g_get_user_cache_dir(), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
296+ GFile * cachedir = g_file_new_for_path(g_get_user_cache_dir());
297+ g_file_make_directory_with_parents(cachedir, NULL, &error);
298+
299+ if (error != NULL) {
300+ g_error("Unable to make directory '%s' for log file: %s", g_get_user_cache_dir(), error->message);
301+ return;
302+ }
303+ }
304+
305+ g_file_delete(file, NULL, NULL);
306+
307+ GFileIOStream * io = g_file_create_readwrite(file,
308+ G_FILE_CREATE_REPLACE_DESTINATION, /* flags */
309+ NULL, /* cancelable */
310+ &error); /* error */
311+ if (error != NULL) {
312+ g_error("Unable to replace file: %s", error->message);
313+ return;
314+ }
315+
316+ log_file = g_io_stream_get_output_stream(G_IO_STREAM(io));
317+ }
318+
319+ gchar * outputstring = g_strdup_printf("%s\n", message);
320+ g_output_stream_write_async(log_file,
321+ outputstring, /* data */
322+ strlen(outputstring), /* length */
323+ G_PRIORITY_LOW, /* priority */
324+ NULL, /* cancelable */
325+ log_to_file_cb, /* callback */
326+ outputstring); /* data */
327+
328+ return;
329+}
330+
331 static gboolean
332 applet_fill_cb (PanelApplet * applet, const gchar * iid, gpointer data)
333 {
334@@ -272,6 +489,8 @@
335 #ifdef INDICATOR_APPLET_COMPLETE
336 g_set_application_name(_("Indicator Applet Complete"));
337 #endif
338+
339+ g_log_set_default_handler(log_to_file, NULL);
340 }
341
342 /* Set panel options */

Subscribers

People subscribed via source and target branches