app/widgets/gimplanguagestore.[ch] actually populate the language store.

2008-02-08  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimplanguagestore.[ch]
	* app/widgets/gimplanguagestore-parser.c: actually populate the
	language store. Still work in progress...

	* app/widgets/gimptexteditor.c: added a combo-box for language
	selection. Not functional yet; just something to play with.

svn path=/trunk/; revision=24833
This commit is contained in:
Sven Neumann 2008-02-08 13:50:34 +00:00 committed by Sven Neumann
parent 5bcb542896
commit 904abbfd11
5 changed files with 82 additions and 6 deletions

View file

@ -1,3 +1,12 @@
2008-02-08 Sven Neumann <sven@gimp.org>
* app/widgets/gimplanguagestore.[ch]
* app/widgets/gimplanguagestore-parser.c: actually populate the
language store. Still work in progress...
* app/widgets/gimptexteditor.c: added a combo-box for language
selection. Not functional yet; just something to play with.
2008-02-08 Sven Neumann <sven@gimp.org>
* app/widgets/gimplanguagestore-parser.c: implemented the parser.

View file

@ -32,6 +32,8 @@
#include "gimplanguagestore.h"
#include "gimplanguagestore-parser.h"
#include "gimp-intl.h"
typedef enum
{
@ -46,10 +48,7 @@ typedef struct
IsoCodesParserState state;
IsoCodesParserState last_known_state;
gint unknown_depth;
GString *value;
GimpLanguageStore *store;
gchar *language;
gchar *code;
} IsoCodesParser;
@ -91,7 +90,9 @@ gimp_language_store_populate (GimpLanguageStore *store,
g_return_val_if_fail (GIMP_IS_LANGUAGE_STORE (store), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
parser.value = g_string_new (NULL);
bindtextdomain ("iso_639", ISO_CODES_LOCALEDIR);
parser.store = g_object_ref (store);
xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
@ -99,9 +100,10 @@ gimp_language_store_populate (GimpLanguageStore *store,
success = gimp_xml_parser_parse_file (xml_parser, filename, error);
gimp_xml_parser_free (xml_parser);
g_free (filename);
g_string_free (parser.value, TRUE);
gimp_xml_parser_free (xml_parser);
g_object_unref (parser.store);
return success;
#endif
@ -131,6 +133,28 @@ iso_codes_parser_entry (IsoCodesParser *parser,
names++;
values++;
}
if (lang && *lang && code && *code)
{
const gchar *semicolon;
lang = dgettext ("iso_639", lang);
/* there might be several language names; use the first one */
semicolon = strchr (lang, ';');
if (semicolon)
{
gchar *first = g_strndup (lang, semicolon - lang);
gimp_language_store_add (parser->store, first, code);
g_free (first);
}
else
{
gimp_language_store_add (parser->store, lang, code);
}
}
}
static void

View file

@ -70,6 +70,8 @@ gimp_language_store_init (GimpLanguageStore *store)
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
G_N_ELEMENTS (column_types), column_types);
gimp_language_store_populate (store, NULL);
}
static void
@ -119,3 +121,20 @@ gimp_language_store_new (gboolean translations)
"translations", translations,
NULL);
}
void
gimp_language_store_add (GimpLanguageStore *store,
const gchar *lang,
const gchar *code)
{
GtkTreeIter iter;
g_return_if_fail (GIMP_IS_LANGUAGE_STORE (store));
g_return_if_fail (lang != NULL && code != NULL);
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_LANGUAGE_STORE_LANGUAGE, lang,
GIMP_LANGUAGE_STORE_ISO_639_1, code,
-1);
}

View file

@ -56,6 +56,9 @@ struct _GimpLanguageStore
GType gimp_language_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_language_store_new (gboolean translations);
void gimp_language_store_add (GimpLanguageStore *store,
const gchar *lang,
const gchar *code);
#endif /* __GIMP_LANGUAGE_STORE_H__ */

View file

@ -31,6 +31,7 @@
#include "gimphelp-ids.h"
#include "gimpmenufactory.h"
#include "gimplanguagestore.h"
#include "gimptexteditor.h"
#include "gimpuimanager.h"
@ -168,6 +169,26 @@ gimp_text_editor_new (const gchar *title,
gtk_widget_show (toolbar);
}
{
GtkListStore *store;
GtkWidget *combo;
GtkCellRenderer *cell;
store = gimp_language_store_new (FALSE);
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
g_object_unref (store);
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
"text", GIMP_LANGUAGE_STORE_LANGUAGE,
NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (editor)->vbox),
combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
}
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,