aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk/parser.c
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-03-09 08:26:36 -0500
committerMichael Terry <mike@mterry.name>2011-03-09 08:26:36 -0500
commit415011b666e92ec899b2c53c80708fdfc1d90322 (patch)
tree3219f62b52799c19bf254f29881ca95ca526bf94 /libdbusmenu-gtk/parser.c
parent3ff07dc2e4582f3f6ef7fcbb57122a8a0a22caa6 (diff)
downloadlibdbusmenu-415011b666e92ec899b2c53c80708fdfc1d90322.tar.gz
libdbusmenu-415011b666e92ec899b2c53c80708fdfc1d90322.tar.bz2
libdbusmenu-415011b666e92ec899b2c53c80708fdfc1d90322.zip
sanitize label text to strip pango markup
Diffstat (limited to 'libdbusmenu-gtk/parser.c')
-rw-r--r--libdbusmenu-gtk/parser.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index 71df266..2d42de5 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -340,6 +340,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse)
return;
}
+static gchar *
+sanitize_label_text (const gchar * label)
+{
+ /* Label contains underscores, which we like, and pango markup,
+ which we don't. */
+ gchar * sanitized = NULL;
+ GError * error = NULL;
+ if (pango_parse_markup (label, -1, 0, NULL, &sanitized, NULL, &error)) {
+ return sanitized;
+ }
+ else {
+ g_warning ("Could not parse '%s': %s", label, error->message);
+ g_error_free (error);
+ return g_strdup (label);
+ }
+}
+
/* Turn a widget into a dbusmenu item depending on the type of GTK
object that it is. */
static DbusmenuMenuitem *
@@ -423,9 +440,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget)
{
// Sometimes, an app will directly find and modify the label
// (like empathy), so watch the label especially for that.
- dbusmenu_menuitem_property_set (mi,
- "label",
- gtk_label_get_label (GTK_LABEL (label)));
+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label)));
+ dbusmenu_menuitem_property_set (mi, "label", text);
+ g_free (text);
pdata->label = label;
g_signal_connect (G_OBJECT (label),
@@ -668,9 +685,11 @@ label_notify_cb (GtkWidget *widget,
if (pspec->name == g_intern_static_string ("label"))
{
+ gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget)));
dbusmenu_menuitem_property_set (child,
DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_label_get_label (GTK_LABEL (widget)));
+ text);
+ g_free (text);
}
}
@@ -724,9 +743,11 @@ action_notify_cb (GtkAction *action,
}
else if (pspec->name == g_intern_static_string ("label"))
{
+ gchar * text = sanitize_label_text (gtk_action_get_label (action));
dbusmenu_menuitem_property_set (mi,
DBUSMENU_MENUITEM_PROP_LABEL,
- gtk_action_get_label (action));
+ text);
+ g_free (text);
}
}