Generate unique id for <key id="...">.
This commit is contained in:
		@ -65,6 +65,7 @@ struct _ParseCallbackData {
 | 
				
			|||||||
    EekOrientation orientation;
 | 
					    EekOrientation orientation;
 | 
				
			||||||
    GSList *points;
 | 
					    GSList *points;
 | 
				
			||||||
    GSList *symbols;
 | 
					    GSList *symbols;
 | 
				
			||||||
 | 
					    guint keyval;
 | 
				
			||||||
    gint groups, levels;
 | 
					    gint groups, levels;
 | 
				
			||||||
    EekOutline outline;
 | 
					    EekOutline outline;
 | 
				
			||||||
    gchar *oref;
 | 
					    gchar *oref;
 | 
				
			||||||
@ -159,6 +160,7 @@ start_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
    const gchar **names = attribute_names;
 | 
					    const gchar **names = attribute_names;
 | 
				
			||||||
    const gchar **values = attribute_values;
 | 
					    const gchar **values = attribute_values;
 | 
				
			||||||
    gint column = -1, row = -1, groups = -1, levels = -1;
 | 
					    gint column = -1, row = -1, groups = -1, levels = -1;
 | 
				
			||||||
 | 
					    guint keyval = EEK_INVALID_KEYSYM;
 | 
				
			||||||
    gchar *name = NULL, *id = NULL, *version = NULL;
 | 
					    gchar *name = NULL, *id = NULL, *version = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    validate (element_name, data->element_stack, error);
 | 
					    validate (element_name, data->element_stack, error);
 | 
				
			||||||
@ -170,10 +172,12 @@ start_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
            column = strtol (*values, NULL, 10);
 | 
					            column = strtol (*values, NULL, 10);
 | 
				
			||||||
        else if (g_strcmp0 (*names, "row") == 0)
 | 
					        else if (g_strcmp0 (*names, "row") == 0)
 | 
				
			||||||
            row = strtol (*values, NULL, 10);
 | 
					            row = strtol (*values, NULL, 10);
 | 
				
			||||||
        else if (g_strcmp0 (*names, "name") == 0)
 | 
					 | 
				
			||||||
            name = g_strdup (*values);
 | 
					 | 
				
			||||||
        else if (g_strcmp0 (*names, "id") == 0)
 | 
					        else if (g_strcmp0 (*names, "id") == 0)
 | 
				
			||||||
            id = g_strdup (*values);
 | 
					            id = g_strdup (*values);
 | 
				
			||||||
 | 
					        else if (g_strcmp0 (*names, "name") == 0)
 | 
				
			||||||
 | 
					            name = g_strdup (*values);
 | 
				
			||||||
 | 
					        else if (g_strcmp0 (*names, "keyval") == 0)
 | 
				
			||||||
 | 
					            keyval = strtoul (*values, NULL, 10);
 | 
				
			||||||
        else if (g_strcmp0 (*names, "version") == 0)
 | 
					        else if (g_strcmp0 (*names, "version") == 0)
 | 
				
			||||||
            version = g_strdup (*values);
 | 
					            version = g_strdup (*values);
 | 
				
			||||||
        else if (g_strcmp0 (*names, "groups") == 0)
 | 
					        else if (g_strcmp0 (*names, "groups") == 0)
 | 
				
			||||||
@ -188,24 +192,25 @@ start_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
        data->keyboard = g_object_new (EEK_TYPE_KEYBOARD,
 | 
					        data->keyboard = g_object_new (EEK_TYPE_KEYBOARD,
 | 
				
			||||||
                                       "layout", data->layout,
 | 
					                                       "layout", data->layout,
 | 
				
			||||||
                                       NULL);
 | 
					                                       NULL);
 | 
				
			||||||
        if (name)
 | 
					        if (id)
 | 
				
			||||||
            eek_element_set_name (EEK_ELEMENT(data->keyboard), name);
 | 
					            eek_element_set_name (EEK_ELEMENT(data->keyboard), id);
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "section") == 0) {
 | 
					    if (g_strcmp0 (element_name, "section") == 0) {
 | 
				
			||||||
        data->section = eek_keyboard_create_section (data->keyboard);
 | 
					        data->section = eek_keyboard_create_section (data->keyboard);
 | 
				
			||||||
        if (name)
 | 
					        if (id)
 | 
				
			||||||
            eek_element_set_name (EEK_ELEMENT(data->section), name);
 | 
					            eek_element_set_name (EEK_ELEMENT(data->section), id);
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "key") == 0) {
 | 
					    if (g_strcmp0 (element_name, "key") == 0) {
 | 
				
			||||||
        data->key = eek_section_create_key (data->section, column, row);
 | 
					        data->key = eek_section_create_key (data->section, column, row);
 | 
				
			||||||
        if (name)
 | 
					        if (id) {
 | 
				
			||||||
            eek_element_set_name (EEK_ELEMENT(data->key), name);
 | 
					            eek_element_set_name (EEK_ELEMENT(data->key), id);
 | 
				
			||||||
        if (id && g_str_has_prefix (id, "key"))
 | 
					            if (g_str_has_prefix (id, "keycode"))
 | 
				
			||||||
            eek_key_set_keycode (data->key, strtoul (id + 3, NULL, 10));
 | 
					                eek_key_set_keycode (data->key, strtoul (id + 7, NULL, 10));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -216,6 +221,9 @@ start_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (g_strcmp0 (element_name, "keysym") == 0)
 | 
				
			||||||
 | 
					        data->keyval = keyval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "outline") == 0) {
 | 
					    if (g_strcmp0 (element_name, "outline") == 0) {
 | 
				
			||||||
        data->oref = g_strdup (id);
 | 
					        data->oref = g_strdup (id);
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
@ -357,8 +365,8 @@ end_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "columns") == 0) {
 | 
					    if (g_strcmp0 (element_name, "angle") == 0) {
 | 
				
			||||||
        data->num_columns = strtol (text, NULL, 10);
 | 
					        eek_section_set_angle (data->section, strtol (text, NULL, 10));
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -367,6 +375,11 @@ end_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (g_strcmp0 (element_name, "columns") == 0) {
 | 
				
			||||||
 | 
					        data->num_columns = strtol (text, NULL, 10);
 | 
				
			||||||
 | 
					        goto out;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "row") == 0) {
 | 
					    if (g_strcmp0 (element_name, "row") == 0) {
 | 
				
			||||||
        eek_section_add_row (data->section,
 | 
					        eek_section_add_row (data->section,
 | 
				
			||||||
                             data->num_columns,
 | 
					                             data->num_columns,
 | 
				
			||||||
@ -377,10 +390,13 @@ end_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "keysym") == 0) {
 | 
					    if (g_strcmp0 (element_name, "keysym") == 0) {
 | 
				
			||||||
        gchar *name = g_strdup (text);
 | 
					        EekKeysym *keysym;
 | 
				
			||||||
        data->symbols = g_slist_prepend (data->symbols,
 | 
					
 | 
				
			||||||
                                         eek_keysym_new_from_name (name));
 | 
					        if (data->keyval != EEK_INVALID_KEYSYM)
 | 
				
			||||||
        g_free (name);
 | 
					            keysym = eek_keysym_new (data->keyval);
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            keysym = eek_keysym_new_from_name (text);
 | 
				
			||||||
 | 
					        data->symbols = g_slist_prepend (data->symbols, keysym);
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -519,7 +535,8 @@ eek_xml_layout_real_create_keyboard (EekLayout *self,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_element_get_bounds (EEK_ELEMENT(data.keyboard), &bounds);
 | 
					    eek_element_get_bounds (EEK_ELEMENT(data.keyboard), &bounds);
 | 
				
			||||||
    scale = initial_width < initial_height ? initial_width / bounds.width : 
 | 
					    scale = initial_width * bounds.height < initial_height * bounds.width ?
 | 
				
			||||||
 | 
					        initial_width / bounds.width :
 | 
				
			||||||
        initial_height / bounds.height;
 | 
					        initial_height / bounds.height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_hash_table_iter_init (&iter, data.oref_outline_hash);
 | 
					    g_hash_table_iter_init (&iter, data.oref_outline_hash);
 | 
				
			||||||
 | 
				
			|||||||
@ -55,6 +55,7 @@ struct _OutputCallbackData {
 | 
				
			|||||||
    GString *output;
 | 
					    GString *output;
 | 
				
			||||||
    gint indent;
 | 
					    gint indent;
 | 
				
			||||||
    GArray *outline_array;
 | 
					    GArray *outline_array;
 | 
				
			||||||
 | 
					    gint key_serial;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
typedef struct _OutputCallbackData OutputCallbackData;
 | 
					typedef struct _OutputCallbackData OutputCallbackData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -78,20 +79,34 @@ output_key_callback (EekElement *element, gpointer user_data)
 | 
				
			|||||||
    gint i, num_symbols;
 | 
					    gint i, num_symbols;
 | 
				
			||||||
    EekSymbolMatrix *matrix;
 | 
					    EekSymbolMatrix *matrix;
 | 
				
			||||||
    gint column, row;
 | 
					    gint column, row;
 | 
				
			||||||
    guint keycode = eek_key_get_keycode (EEK_KEY(element));
 | 
					    guint keycode;
 | 
				
			||||||
 | 
					    gchar *id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    keycode = eek_key_get_keycode (EEK_KEY(element));
 | 
				
			||||||
 | 
					    if (keycode == EEK_INVALID_KEYCODE)
 | 
				
			||||||
 | 
					        id = g_strdup_printf ("key%d", data->key_serial);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        id = g_strdup_printf ("keycode%d", keycode);
 | 
				
			||||||
 | 
					    data->key_serial++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_key_get_index (EEK_KEY(element), &column, &row);
 | 
					    eek_key_get_index (EEK_KEY(element), &column, &row);
 | 
				
			||||||
    g_string_append_indent (data->output, data->indent);
 | 
					    g_string_append_indent (data->output, data->indent);
 | 
				
			||||||
    if (eek_element_get_name (element))
 | 
					    if (eek_element_get_name (element))
 | 
				
			||||||
        g_string_markup_printf (data->output,
 | 
					        g_string_markup_printf (data->output,
 | 
				
			||||||
                                "<key id=\"key%u\" column=\"%d\" row=\"%d\" "
 | 
					                                "<key id=\"%s\" name=\"%s\" "
 | 
				
			||||||
                                "name=\"%s\">\n",
 | 
					                                "column=\"%d\" row=\"%d\">\n",
 | 
				
			||||||
                                keycode, column, row,
 | 
					                                id,
 | 
				
			||||||
                                eek_element_get_name (element));
 | 
					                                eek_element_get_name (element),
 | 
				
			||||||
 | 
					                                column,
 | 
				
			||||||
 | 
					                                row);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        g_string_markup_printf (data->output,
 | 
					        g_string_markup_printf (data->output,
 | 
				
			||||||
                                "<key id=\"key%d\" column=\"%d\" row=\"%d\">\n",
 | 
					                                "<key id=\"%s\" "
 | 
				
			||||||
                                keycode, column, row);
 | 
					                                "column=\"%d\" row=\"%d\">\n",
 | 
				
			||||||
 | 
					                                id,
 | 
				
			||||||
 | 
					                                column,
 | 
				
			||||||
 | 
					                                row);
 | 
				
			||||||
 | 
					    g_free (id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_element_get_bounds (element, &bounds);
 | 
					    eek_element_get_bounds (element, &bounds);
 | 
				
			||||||
    g_string_append_indent (data->output, data->indent + 1);
 | 
					    g_string_append_indent (data->output, data->indent + 1);
 | 
				
			||||||
@ -121,15 +136,27 @@ output_key_callback (EekElement *element, gpointer user_data)
 | 
				
			|||||||
                                matrix->num_groups, matrix->num_levels);
 | 
					                                matrix->num_groups, matrix->num_levels);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < num_symbols; i++) {
 | 
					        for (i = 0; i < num_symbols; i++) {
 | 
				
			||||||
 | 
					            EekSymbol *symbol = matrix->data[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            g_string_append_indent (data->output, data->indent + 2);
 | 
					            g_string_append_indent (data->output, data->indent + 2);
 | 
				
			||||||
            if (EEK_IS_KEYSYM(matrix->data[i]))
 | 
					            if (EEK_IS_KEYSYM(symbol)) {
 | 
				
			||||||
                g_string_markup_printf (data->output,
 | 
					                guint xkeysym = eek_keysym_get_xkeysym (EEK_KEYSYM(symbol));
 | 
				
			||||||
                                        "<keysym>%s</keysym>\n",
 | 
					
 | 
				
			||||||
                                        eek_symbol_get_name (matrix->data[i]));
 | 
					                if (xkeysym != EEK_INVALID_KEYSYM)
 | 
				
			||||||
 | 
					                    g_string_markup_printf
 | 
				
			||||||
 | 
					                        (data->output,
 | 
				
			||||||
 | 
					                         "<keysym keyval=\"%u\">%s</keysym>\n",
 | 
				
			||||||
 | 
					                         xkeysym,
 | 
				
			||||||
 | 
					                         eek_symbol_get_name (symbol));
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                    g_string_markup_printf (data->output,
 | 
				
			||||||
 | 
					                                            "<keysym>%s</keysym>\n",
 | 
				
			||||||
 | 
					                                            eek_symbol_get_name (symbol));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                g_string_markup_printf (data->output,
 | 
					                g_string_markup_printf (data->output,
 | 
				
			||||||
                                        "<symbol>%s</symbol>\n",
 | 
					                                        "<symbol>%s</symbol>\n",
 | 
				
			||||||
                                        eek_symbol_get_name (matrix->data[i]));
 | 
					                                        eek_symbol_get_name (symbol));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        g_string_append_indent (data->output, data->indent + 1);
 | 
					        g_string_append_indent (data->output, data->indent + 1);
 | 
				
			||||||
        g_string_markup_printf (data->output, "</symbols>\n");
 | 
					        g_string_markup_printf (data->output, "</symbols>\n");
 | 
				
			||||||
@ -202,10 +229,15 @@ eek_keyboard_output (EekKeyboard *keyboard, GString *output, gint indent)
 | 
				
			|||||||
    g_assert (EEK_IS_KEYBOARD(keyboard));
 | 
					    g_assert (EEK_IS_KEYBOARD(keyboard));
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
    g_string_append_indent (output, indent);
 | 
					    g_string_append_indent (output, indent);
 | 
				
			||||||
    g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
 | 
					    if (eek_element_get_name (EEK_ELEMENT(keyboard)))
 | 
				
			||||||
                            "<keyboard version=\""
 | 
					        g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
 | 
				
			||||||
                            EEK_XML_SCHEMA_VERSION
 | 
					                                "<keyboard version=\"%s\" id=\"%s\">\n",
 | 
				
			||||||
                            "\">\n");
 | 
					                                EEK_XML_SCHEMA_VERSION,
 | 
				
			||||||
 | 
					                                eek_element_get_name (EEK_ELEMENT(keyboard)));
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
 | 
				
			||||||
 | 
					                                "<keyboard version=\"%s\">\n",
 | 
				
			||||||
 | 
					                                EEK_XML_SCHEMA_VERSION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
 | 
					    eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
 | 
				
			||||||
    g_string_append_indent (output, indent + 1);
 | 
					    g_string_append_indent (output, indent + 1);
 | 
				
			||||||
@ -214,6 +246,7 @@ eek_keyboard_output (EekKeyboard *keyboard, GString *output, gint indent)
 | 
				
			|||||||
    data.output = output;
 | 
					    data.output = output;
 | 
				
			||||||
    data.indent = indent;
 | 
					    data.indent = indent;
 | 
				
			||||||
    data.outline_array = g_array_new (FALSE, FALSE, sizeof (gpointer));
 | 
					    data.outline_array = g_array_new (FALSE, FALSE, sizeof (gpointer));
 | 
				
			||||||
 | 
					    data.key_serial = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data.indent++;
 | 
					    data.indent++;
 | 
				
			||||||
    eek_container_foreach_child (EEK_CONTAINER(keyboard),
 | 
					    eek_container_foreach_child (EEK_CONTAINER(keyboard),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user