Merge lp:~larsu/indicator-messages/fix-770486 into lp:indicator-messages/0.3

Proposed by Lars Karlitski on 2012-03-08
Status: Merged
Approved by: Charles Kerr on 2012-03-08
Approved revision: 253
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~larsu/indicator-messages/fix-770486
Merge into: lp:indicator-messages/0.3
Diff against target: 62 lines (+39/-1)
1 file modified
src/im-menu-item.c (+39/-1)
To merge this branch: bzr merge lp:~larsu/indicator-messages/fix-770486
Reviewer Review Type Date Requested Status
Charles Kerr (community) 2012-03-08 Approve on 2012-03-08
Review via email: mp+96643@code.launchpad.net

Description of the change

Fixes bug #770486.

Text has already vertically been centered for a while now. This patch also collapses all whitespace so that multi-line items don't occur anymore.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

Very clean!

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 2012-02-03 18:43:39 +0000
3+++ src/im-menu-item.c 2012-03-08 18:46:21 +0000
4@@ -288,11 +288,47 @@
5 return;
6 }
7
8+/* Returns a newly allocated string which is 'str' with all occurences of
9+ * consecutive whitespace collapsed into single space character. */
10+static gchar *
11+collapse_whitespace (const gchar *str)
12+{
13+ GString *result;
14+ gboolean in_space = FALSE;
15+
16+ if (!str)
17+ return NULL;
18+
19+ result = g_string_sized_new (strlen (str));
20+
21+ while (*str) {
22+ gunichar c = g_utf8_get_char_validated (str, -1);
23+
24+ if (c < 0)
25+ break;
26+
27+ if (!g_unichar_isspace (c)) {
28+ g_string_append_unichar (result, c);
29+ in_space = FALSE;
30+ }
31+ else if (!in_space) {
32+ g_string_append_c (result, ' ');
33+ in_space = TRUE;
34+ }
35+
36+ str = g_utf8_next_char (str);
37+ }
38+
39+ return g_string_free (result, FALSE);
40+}
41+
42 /* Callback from libindicate that is for getting the sender information
43 on a particular indicator. */
44 static void
45 sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
46 {
47+ gchar *label;
48+
49 g_debug("Got Sender Information: %s", propertydata);
50 ImMenuItem * self = IM_MENU_ITEM(data);
51
52@@ -310,7 +346,9 @@
53 return;
54 }
55
56- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_LABEL, propertydata);
57+ label = collapse_whitespace (propertydata);
58+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_LABEL, label);
59+ g_free (label);
60
61 return;
62 }

Subscribers

People subscribed via source and target branches