aboutsummaryrefslogtreecommitdiff
path: root/src/im-menu-item.c
diff options
context:
space:
mode:
authorAllan LeSage <allanlesage@gmail.com>2012-03-27 15:31:28 -0500
committerAllan LeSage <allanlesage@gmail.com>2012-03-27 15:31:28 -0500
commitc9f1e2838a8da6eefb875fee2e3b43a8a04efb80 (patch)
tree2bfd914a9100a79c80b666297f5cbe4c9bd9b69e /src/im-menu-item.c
parent5996de39f38da7d605a999100a6c4a571ad6b66e (diff)
parent0e5b8f77b3320b12f497153b7a781272aacac00a (diff)
downloadayatana-indicator-messages-c9f1e2838a8da6eefb875fee2e3b43a8a04efb80.tar.gz
ayatana-indicator-messages-c9f1e2838a8da6eefb875fee2e3b43a8a04efb80.tar.bz2
ayatana-indicator-messages-c9f1e2838a8da6eefb875fee2e3b43a8a04efb80.zip
Merge of prior fixes for TDD tooling.
Diffstat (limited to 'src/im-menu-item.c')
-rw-r--r--src/im-menu-item.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/im-menu-item.c b/src/im-menu-item.c
index e7c0177..f07fff9 100644
--- a/src/im-menu-item.c
+++ b/src/im-menu-item.c
@@ -288,11 +288,47 @@ time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL
return;
}
+/* Returns a newly allocated string which is 'str' with all occurences of
+ * consecutive whitespace collapsed into single space character. */
+static gchar *
+collapse_whitespace (const gchar *str)
+{
+ GString *result;
+ gboolean in_space = FALSE;
+
+ if (!str)
+ return NULL;
+
+ result = g_string_sized_new (strlen (str));
+
+ while (*str) {
+ gunichar c = g_utf8_get_char_validated (str, -1);
+
+ if (c < 0)
+ break;
+
+ if (!g_unichar_isspace (c)) {
+ g_string_append_unichar (result, c);
+ in_space = FALSE;
+ }
+ else if (!in_space) {
+ g_string_append_c (result, ' ');
+ in_space = TRUE;
+ }
+
+ str = g_utf8_next_char (str);
+ }
+
+ return g_string_free (result, FALSE);
+}
+
/* Callback from libindicate that is for getting the sender information
on a particular indicator. */
static void
sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, const gchar * propertydata, gpointer data)
{
+ gchar *label;
+
g_debug("Got Sender Information: %s", propertydata);
ImMenuItem * self = IM_MENU_ITEM(data);
@@ -310,7 +346,9 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat
return;
}
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_LABEL, propertydata);
+ label = collapse_whitespace (propertydata);
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_LABEL, label);
+ g_free (label);
return;
}