+ if (label == NULL) {
+ *strippedlabel = NULL;
+ } else {
+ gchar *i;
+ gboolean escape;
+
+ *strippedlabel = g_strdup(label);
+
+ /* if allow_shortcut is false, then you can't use the '_', instead you
+ have to just use the first valid character
+ */
+
+ /* allow __ to escape an underscore */
+ i = *strippedlabel;
+ do {
+ escape = FALSE;
+ i = strchr(i, '_');
+ if (i && *(i+1) == '_') {
+ gchar *j;
+
+ /* remove the escape '_' from the string */
+ for (j = i; *j != '\0'; ++j)
+ *j = *(j+1);
+
+ ++i;
+ escape = TRUE;
+ }
+ } while (escape);
+
+ if (allow_shortcut && i != NULL) {
+ /* there is an underscore in the string */
+
+ /* you have to use a printable ascii character for shortcuts
+ don't allow space either, so you can have like "a _ b"
+ */
+ if (VALID_SHORTCUT(*(i+1))) {
+ shortcut = g_unichar_tolower(g_utf8_get_char(i+1));
+ *position = i - *strippedlabel;
+ *always_show = TRUE;
+
+ /* remove the '_' from the string */
+ for (; *i != '\0'; ++i)
+ *i = *(i+1);
+ } else if (*(i+1) == '\0') {
+ /* no default shortcut if the '_' is the last character
+ (eg. "Exit_") for menu entries that you don't want
+ to be executed by mistake
+ */
+ *i = '\0';
+ }
+ } else {
+ /* there is no underscore, so find the first valid character to use
+ instead */
+
+ for (i = *strippedlabel; *i != '\0'; ++i)
+ if (VALID_SHORTCUT(*i)) {
+ *position = i - *strippedlabel;
+ shortcut = g_unichar_tolower(g_utf8_get_char(i));
+ break;
+ }
+ }
+ }
+ return shortcut;
+}
+
+static void parse_menu_item(xmlNodePtr node, gpointer data)
+{
+ ObMenuParseState *state = data;
+ gchar *label;
+ gchar *icon;
+ ObMenuEntry *e;
+
+ if (state->parent) {
+ /* Don't try to extract "icon" attribute if icons in user-defined
+ menus are not enabled. */
+
+ if (obt_xml_attr_string_unstripped(node, "label", &label)) {
+ xmlNodePtr c;
+ GSList *acts = NULL;
+
+ c = obt_xml_find_node(node->children, "action");
+ while (c) {
+ ObActionsAct *action = actions_parse(c);
+ if (action)
+ acts = g_slist_append(acts, action);
+ c = obt_xml_find_node(c->next, "action");
+ }
+ e = menu_add_normal(state->parent, -1, label, acts, TRUE);
+
+ if (config_menu_show_icons &&
+ obt_xml_attr_string(node, "icon", &icon))
+ {
+ e->data.normal.icon = RrImageNewFromName(ob_rr_icons, icon);
+
+ if (e->data.normal.icon)
+ e->data.normal.icon_alpha = 0xff;
+
+ g_free(icon);
+ }
+ g_free(label);
+ }
+ }