Merge lp:~ted/indicator-messages/lift-and-separate into lp:indicator-messages/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-messages/lift-and-separate
Merge into: lp:indicator-messages/0.5
Diff against target: None lines
To merge this branch: bzr merge lp:~ted/indicator-messages/lift-and-separate
Reviewer Review Type Date Requested Status
David Barth Approve
Neil J. Patel (community) Approve
Review via email: mp+11493@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

Adding separators between the entries. Really needs the dbusmenu patch to make it work well.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Works perfectly with the reorder branch. Approved.

review: Approve
Revision history for this message
David Barth (dbarth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/im-menu-item.c'
2--- src/im-menu-item.c 2009-09-09 01:18:34 +0000
3+++ src/im-menu-item.c 2009-09-09 15:03:33 +0000
4@@ -125,12 +125,21 @@
5 g_debug("Building new IM Menu Item");
6 ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
7
8+ /* Set the variables to NULL, but they should be
9+ configured further down the line. */
10 priv->listener = NULL;
11 priv->server = NULL;
12 priv->indicator = NULL;
13
14+ /* A sane default, but look below */
15 priv->seconds = 0;
16
17+ /* Set the seconds to be the time when the item was
18+ created incase we're not given a better time. */
19+ GTimeVal current_time;
20+ g_get_current_time(&current_time);
21+ priv->seconds = current_time.tv_sec;
22+
23 return;
24 }
25
26
27=== modified file 'src/messages-service.c'
28--- src/messages-service.c 2009-09-05 03:06:42 +0000
29+++ src/messages-service.c 2009-09-09 19:51:19 +0000
30@@ -26,6 +26,7 @@
31 #include <libindicate/listener.h>
32 #include <gio/gio.h>
33
34+#include <libdbusmenu-glib/client.h>
35 #include <libdbusmenu-glib/server.h>
36
37 #include "im-menu-item.h"
38@@ -71,6 +72,7 @@
39 struct _serverList_t {
40 IndicateListenerServer * server;
41 AppMenuItem * menuitem;
42+ DbusmenuMenuitem * separator;
43 gboolean attention;
44 guint count;
45 GList * imList;
46@@ -154,6 +156,7 @@
47 typedef struct _launcherList_t launcherList_t;
48 struct _launcherList_t {
49 LauncherMenuItem * menuitem;
50+ DbusmenuMenuitem * separator;
51 GList * appdiritems;
52 };
53
54@@ -287,6 +290,7 @@
55 launcherList_t * item = (launcherList_t *)launcher->data;
56 if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) {
57 launcher_menu_item_set_eclipsed(item->menuitem, TRUE);
58+ dbusmenu_menuitem_property_set(item->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
59 }
60 }
61
62@@ -333,6 +337,7 @@
63 }
64 if (serveritem == NULL) {
65 launcher_menu_item_set_eclipsed(li->menuitem, FALSE);
66+ dbusmenu_menuitem_property_set(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "true");
67 }
68 }
69 }
70@@ -477,6 +482,10 @@
71 sl_item->attention = FALSE;
72 sl_item->count = 0;
73
74+ /* Build a separator */
75+ sl_item->separator = dbusmenu_menuitem_new();
76+ dbusmenu_menuitem_property_set(sl_item->separator, "type", DBUSMENU_CLIENT_TYPES_SEPARATOR);
77+
78 /* Incase we got an indicator first */
79 GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal);
80 if (alreadythere != NULL) {
81@@ -494,8 +503,11 @@
82 g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), sl_item);
83 g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell);
84
85+ /* Put our new menu item in, with the separator behind it.
86+ resort_menu will take care of whether it should be hidden
87+ or not. */
88 dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem));
89- /* Should be prepend ^ */
90+ dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(sl_item->separator));
91
92 resort_menu(menushell);
93 check_hidden();
94@@ -576,14 +588,19 @@
95 return;
96 }
97
98+/* Run when a server is removed from the indicator bus. It figures
99+ out if we have it somewhere, and if so then we dump it out and
100+ clean up all of it's entries. */
101 static void
102 server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data)
103 {
104+ /* Look for the server */
105 g_debug("Removing server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server));
106- serverList_t slt;
107+ serverList_t slt = {0};
108 slt.server = server;
109 GList * lookup = g_list_find_custom(serverList, &slt, serverList_equal);
110
111+ /* If we don't have it, exit */
112 if (lookup == NULL) {
113 g_debug("\tUnable to find server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server));
114 return;
115@@ -591,21 +608,32 @@
116
117 serverList_t * sltp = (serverList_t *)lookup->data;
118
119- remove_eclipses(sltp->menuitem);
120-
121+ /* Removing indicators from this server */
122 while (sltp->imList) {
123 imList_t * imitem = (imList_t *)sltp->imList->data;
124 indicator_removed(listener, server, imitem->indicator, data);
125 }
126
127+ /* Remove from the server list */
128 serverList = g_list_remove(serverList, sltp);
129
130+ /* Remove launchers this could be eclipsing */
131+ remove_eclipses(sltp->menuitem);
132+
133+ /* If there is a menu item, let's get rid of it. */
134 if (sltp->menuitem != NULL) {
135 dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(sltp->menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
136 dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->menuitem));
137 g_object_unref(G_OBJECT(sltp->menuitem));
138 }
139
140+ /* If there is a separator, let's get rid of it. */
141+ if (sltp->separator != NULL) {
142+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(sltp->separator), DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
143+ dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->separator));
144+ g_object_unref(G_OBJECT(sltp->separator));
145+ }
146+
147 if (sltp->attention) {
148 /* Check to see if this was the server causing the menu item to
149 be lit up. */
150@@ -664,25 +692,44 @@
151 return;
152 }
153
154+/* This function takes care of putting the menu in the right order.
155+ It basically it rebuilds the order by looking through all the
156+ applications and launchers and puts them in the right place. The
157+ menu functions will handle the cases where they don't move so this
158+ is a good way to ensure everything is right. */
159 static void
160 resort_menu (DbusmenuMenuitem * menushell)
161 {
162 guint position = 0;
163 GList * serverentry;
164 GList * launcherentry = launcherList;
165+ DbusmenuMenuitem * last_separator = NULL;
166
167 g_debug("Reordering Menu:");
168
169 for (serverentry = serverList; serverentry != NULL; serverentry = serverentry->next) {
170 serverList_t * si = (serverList_t *)serverentry->data;
171
172+ /* Looking to see if there are any launchers we need to insert
173+ into the menu structure. We put as many as we need to. */
174 if (launcherentry != NULL) {
175 launcherList_t * li = (launcherList_t *)launcherentry->data;
176 while (launcherentry != NULL && g_strcmp0(launcher_menu_item_get_name(li->menuitem), app_menu_item_get_name(si->menuitem)) < 0) {
177+ /* Putting the launcher item in */
178 g_debug("\tMoving launcher '%s' to position %d", launcher_menu_item_get_name(li->menuitem), position);
179 dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->menuitem), position);
180-
181- position++;
182+ position++;
183+
184+ /* Putting the launcher separator in */
185+ g_debug("\tMoving launcher separator to position %d", position);
186+ dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->separator), position);
187+ if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
188+ /* Only clear the visiblity if we're not eclipsed */
189+ dbusmenu_menuitem_property_set(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "true");
190+ last_separator = li->separator;
191+ }
192+ position++;
193+
194 launcherentry = launcherentry->next;
195 if (launcherentry != NULL) {
196 li = (launcherList_t *)launcherentry->data;
197@@ -690,12 +737,15 @@
198 }
199 }
200
201+ /* Putting the app menu item in */
202 if (si->menuitem != NULL) {
203 g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position);
204 dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->menuitem), position);
205 position++;
206 }
207
208+ /* Putting all the indicators that are related to this application
209+ after it. */
210 GList * imentry;
211 for (imentry = si->imList; imentry != NULL; imentry = imentry->next) {
212 imList_t * imi = (imList_t *)imentry->data;
213@@ -706,17 +756,45 @@
214 position++;
215 }
216 }
217+
218+ /* Lastly putting the separator in */
219+ if (si->separator != NULL) {
220+ g_debug("\tMoving app %s separator to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position);
221+ dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->separator), position);
222+ dbusmenu_menuitem_property_set(si->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "true");
223+ position++;
224+ last_separator = si->separator;
225+ }
226 }
227
228+ /* Put any leftover launchers in at the end of the list. */
229 while (launcherentry != NULL) {
230 launcherList_t * li = (launcherList_t *)launcherentry->data;
231+
232+ /* Putting the launcher in */
233 g_debug("\tMoving launcher '%s' to position %d", launcher_menu_item_get_name(li->menuitem), position);
234 dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->menuitem), position);
235-
236- position++;
237+ position++;
238+
239+ /* Putting the launcher separator in */
240+ g_debug("\tMoving launcher separator to position %d", position);
241+ dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->separator), position);
242+ if (!launcher_menu_item_get_eclipsed(li->menuitem)) {
243+ /* Only clear the visiblity if we're not eclipsed */
244+ dbusmenu_menuitem_property_set(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "true");
245+ last_separator = li->separator;
246+ }
247+ position++;
248+
249 launcherentry = launcherentry->next;
250 }
251
252+ if (last_separator != NULL) {
253+ dbusmenu_menuitem_property_set(last_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
254+ } else {
255+ g_warning("No last separator on resort");
256+ }
257+
258 return;
259 }
260
261@@ -745,7 +823,7 @@
262 /* Looking for a server entry to attach this indicator
263 to. If we can't find one then we have to build one
264 and attach the indicator to it. */
265- serverList_t sl_item_local;
266+ serverList_t sl_item_local = {0};
267 serverList_t * sl_item = NULL;
268 sl_item_local.server = server;
269 GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal);
270@@ -759,6 +837,7 @@
271 sl_item->imList = NULL;
272 sl_item->attention = FALSE;
273 sl_item->count = 0;
274+ sl_item->separator = NULL;
275
276 serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort);
277 } else {
278@@ -813,7 +892,7 @@
279 gboolean removed = FALSE;
280
281 /* Find the server that was related to this item */
282- serverList_t sl_item_local;
283+ serverList_t sl_item_local = {0};
284 serverList_t * sl_item = NULL;
285 sl_item_local.server = server;
286 GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal);
287@@ -824,7 +903,7 @@
288 sl_item = (serverList_t *)serverentry->data;
289
290 /* Look in the IM Hash Table */
291- imList_t listData;
292+ imList_t listData = {0};
293 listData.server = server;
294 listData.indicator = indicator;
295
296@@ -928,6 +1007,7 @@
297
298 if (!g_strcmp0(aidesktop, lidesktop)) {
299 launcher_menu_item_set_eclipsed(ll->menuitem, TRUE);
300+ dbusmenu_menuitem_property_set(ll->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
301 break;
302 }
303 }
304@@ -952,6 +1032,7 @@
305
306 if (!g_strcmp0(aidesktop, lidesktop)) {
307 launcher_menu_item_set_eclipsed(ll->menuitem, FALSE);
308+ dbusmenu_menuitem_property_set(ll->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "true");
309 break;
310 }
311 }
312@@ -1052,15 +1133,21 @@
313 g_free(trimdesktop);
314 ll->appdiritems = g_list_append(NULL, path);
315
316+ /* Build a separator */
317+ ll->separator = dbusmenu_menuitem_new();
318+ dbusmenu_menuitem_property_set(ll->separator, "type", DBUSMENU_CLIENT_TYPES_SEPARATOR);
319+
320 /* Add it to the list */
321 launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort);
322
323 /* Add it to the menu */
324 dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem));
325+ dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->separator));
326 resort_menu(root_menuitem);
327
328 if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) {
329 launcher_menu_item_set_eclipsed(ll->menuitem, TRUE);
330+ dbusmenu_menuitem_property_set(ll->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
331 }
332 } else {
333 /* If so add ourselves */

Subscribers

People subscribed via source and target branches

to all changes: