+ gunichar shortcut = 0;
+
+ *position = 0;
+ *always_show = FALSE;
+
+ g_assert(strippedlabel != NULL);
+
+ if (label == NULL) {
+ *strippedlabel = NULL;
+ } else {
+ gchar *i;
+
+ *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
+ */
+
+ i = strchr(*strippedlabel, '_');
+ 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)) || *(i+1) == '_') {
+ /* Allow you to escape the first _ by putting __ */
+ if (*(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;
+
+ if (state->parent) {
+ if (obt_parse_attr_string(node, "label", &label)) {
+ GSList *acts = NULL;
+
+ for (node = node->children; node; node = node->next)
+ if (!xmlStrcasecmp(node->name, (const xmlChar*) "action")) {
+ ObActionsAct *a = actions_parse(node);
+ if (a)
+ acts = g_slist_append(acts, a);
+ }
+ menu_add_normal(state->parent, -1, label, acts, TRUE);
+ g_free(label);
+ }
+ }
+}
+
+static void parse_menu_separator(xmlNodePtr node, gpointer data)
+{
+ ObMenuParseState *state = data;
+
+ if (state->parent) {
+ gchar *label;
+
+ if (!obt_parse_attr_string(node, "label", &label))
+ label = NULL;
+
+ menu_add_separator(state->parent, -1, label);
+ g_free(label);
+ }