Commit c3efdd2a authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

strip newlines, tabs and adjacent spaces from string values. Added a naive

2002-02-25  Sven Neumann  <sven@gimp.org>

	* app/gui/tips-parser.[ch]: strip newlines, tabs and adjacent spaces
	from string values. Added a naive locale match algorithm. We'll see
	how well it works in real life...

	* app/gui/tips-dialog.c: call gimp_tips_from_file() with current
	locale. Let GTK+ do the line breaks, assorted cosmetic changes.

	* tips/de.po: stripped newlines from translation.
parent 619c9a94
2002-02-25 Sven Neumann <sven@gimp.org>
* app/gui/tips-parser.[ch]: strip newlines, tabs and adjacent spaces
from string values. Added a naive locale match algorithm. We'll see
how well it works in real life...
* app/gui/tips-dialog.c: call gimp_tips_from_file() with current
locale. Let GTK+ do the line breaks, assorted cosmetic changes.
* tips/de.po: stripped newlines from translation.
2002-02-25 Michael Natterer <mitch@gimp.org>
* app/vectors/Makefile.am
......
......@@ -49,11 +49,13 @@ static void tips_toggle_update (GtkWidget *widget,
static GtkWidget *tips_dialog = NULL;
static GtkWidget *tips_label = NULL;
static GList *tips = NULL;
static gint tips_count = 0;
static gint old_show_tips = 0;
static GtkWidget *tips_dialog = NULL;
static GtkWidget *welcome_label = NULL;
static GtkWidget *thetip_label = NULL;
static GList *tips = NULL;
static GList *current_tip = NULL;
static gint tips_count = 0;
static gint old_show_tips = 0;
GtkWidget *
......@@ -75,12 +77,15 @@ tips_dialog_create (void)
filename = g_build_filename (gimp_data_directory (), "tips",
"gimp-tips.xml", NULL);
tips = gimp_tips_from_file (filename, NULL, &error);
tips = gimp_tips_from_file (filename,
setlocale (LC_MESSAGES, NULL),
&error);
g_free (filename);
if (error)
{
tips = g_list_prepend (NULL, gimp_tip_new (NULL, error->message));
tips = g_list_prepend (tips, gimp_tip_new (NULL, error->message));
g_error_free (error);
}
}
......@@ -90,6 +95,8 @@ tips_dialog_create (void)
if (gimprc.last_tip >= tips_count || gimprc.last_tip < 0)
gimprc.last_tip = 0;
current_tip = g_list_nth (tips, gimprc.last_tip);
if (tips_dialog)
return tips_dialog;
......@@ -116,24 +123,37 @@ tips_dialog_create (void)
gtk_container_add (GTK_CONTAINER (tips_dialog), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 5);
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
tip = g_list_nth_data (tips, gimprc.last_tip);
tips_label = gtk_label_new (tip->thetip);
vbox2 = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
gtk_widget_show (vbox2);
tip = (GimpTip *) current_tip->data;
welcome_label = gtk_label_new (tip->welcome);
gtk_label_set_justify (GTK_LABEL (welcome_label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (welcome_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (welcome_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), welcome_label, FALSE, FALSE, 0);
if (tip->welcome)
gtk_widget_show (welcome_label);
gtk_label_set_justify (GTK_LABEL (tips_label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (tips_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), tips_label, TRUE, TRUE, 3);
gtk_widget_show (tips_label);
thetip_label = gtk_label_new (tip->thetip);
gtk_label_set_justify (GTK_LABEL (thetip_label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (thetip_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (thetip_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), thetip_label, TRUE, TRUE, 0);
gtk_widget_show (thetip_label);
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
gtk_widget_show (vbox2);
filename = g_build_filename (gimp_data_directory(),
filename = g_build_filename (gimp_data_directory (),
"images", "wilber-tips.png", NULL);
wilber = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
......@@ -154,7 +174,8 @@ tips_dialog_create (void)
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
button = gtk_check_button_new_with_label (_("Show tip next time GIMP starts"));
button =
gtk_check_button_new_with_mnemonic (_("Show tip next time GIMP starts"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), gimprc.show_tips);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
......@@ -185,7 +206,7 @@ tips_dialog_create (void)
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
button = gtk_button_new_with_label (_("Previous Tip"));
button = gtk_button_new_with_mnemonic (_("_Previous Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_widget_set_sensitive (button, (tips_count > 1));
gtk_container_add (GTK_CONTAINER (bbox), button);
......@@ -195,7 +216,7 @@ tips_dialog_create (void)
G_CALLBACK (tips_show_previous),
NULL);
button = gtk_button_new_with_label (_("Next Tip"));
button = gtk_button_new_with_mnemonic (_("_Next Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_widget_set_sensitive (button, (tips_count > 1));
gtk_container_add (GTK_CONTAINER (bbox), button);
......@@ -222,10 +243,12 @@ tips_dialog_destroy (GtkWidget *widget,
tips_dialog = NULL;
current_tip = NULL;
gimp_tips_free (tips);
tips = NULL;
/* the last-shown-tip is now saved in sessionrc */
gimprc.last_tip = g_list_position (tips, current_tip);
if (gimprc.show_tips != old_show_tips)
{
......@@ -239,35 +262,35 @@ tips_dialog_destroy (GtkWidget *widget,
}
static void
tips_show_previous (GtkWidget *widget,
gpointer data)
tips_set_labels (GimpTip *tip)
{
GimpTip *tip;
g_return_if_fail (tip != NULL);
gimprc.last_tip--;
if (gimprc.last_tip < 0)
gimprc.last_tip = tips_count - 1;
if (tip->welcome)
gtk_widget_show (welcome_label);
else
gtk_widget_hide (welcome_label);
gtk_label_set_text (GTK_LABEL (welcome_label), tip->welcome);
gtk_label_set_text (GTK_LABEL (thetip_label), tip->thetip);
}
tip = g_list_nth_data (tips, gimprc.last_tip);
static void
tips_show_previous (GtkWidget *widget,
gpointer data)
{
current_tip = current_tip->prev ? current_tip->prev : g_list_last (tips);
gtk_label_set_text (GTK_LABEL (tips_label), tip->thetip);
tips_set_labels (current_tip->data);
}
static void
tips_show_next (GtkWidget *widget,
gpointer data)
{
GimpTip *tip;
gimprc.last_tip++;
if (gimprc.last_tip >= tips_count)
gimprc.last_tip = 0;
tip = g_list_nth_data (tips, gimprc.last_tip);
current_tip = current_tip->next ? current_tip->next : tips;
gtk_label_set_text (GTK_LABEL (tips_label), tip->thetip);
tips_set_labels (current_tip->data);
}
static void
......
......@@ -43,23 +43,23 @@ typedef enum
typedef enum
{
TIPS_LANG_NONE,
TIPS_LANG_MATCH,
TIPS_LANG_MISMATCH,
} TipsParserLangState;
TIPS_LOCALE_NONE,
TIPS_LOCALE_MATCH,
TIPS_LOCALE_MISMATCH,
} TipsParserLocaleState;
typedef struct _TipsParser TipsParser;
struct _TipsParser
{
TipsParserState state;
TipsParserState last_known_state;
const gchar *lang;
TipsParserLangState lang_state;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
TipsParserState state;
TipsParserState last_known_state;
const gchar *locale;
TipsParserLocaleState locale_state;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
};
......@@ -82,13 +82,13 @@ static void tips_parser_error (GMarkupParseContext *context,
GError *error,
gpointer user_data);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_lang (TipsParser *parser,
const gchar **names,
const gchar **values);
static void tips_parser_set_by_lang (TipsParser *parser,
gchar **dest);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values);
static void tips_parser_set_by_locale (TipsParser *parser,
gchar **dest);
static const GMarkupParser markup_parser =
......@@ -126,7 +126,7 @@ gimp_tip_free (GimpTip *tip)
GList *
gimp_tips_from_file (const gchar *filename,
const gchar *language,
const gchar *locale,
GError **error)
{
GMarkupParseContext *context;
......@@ -151,8 +151,8 @@ gimp_tips_from_file (const gchar *filename,
}
parser = g_new0 (TipsParser, 1);
parser->lang = language;
parser->value = g_string_new (NULL);
parser->locale = locale;
parser->value = g_string_new (NULL);
context = g_markup_parse_context_new (&markup_parser, 0, parser, NULL);
......@@ -202,7 +202,6 @@ gimp_tips_free (GList *tips)
g_list_free (tips);
}
static void
tips_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
......@@ -236,12 +235,12 @@ tips_parser_start_element (GMarkupParseContext *context,
if (strcmp (element_name, "welcome") == 0)
{
parser->state = TIPS_IN_WELCOME;
tips_parser_parse_lang (parser, attribute_names, attribute_values);
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else if (strcmp (element_name, "thetip") == 0)
{
parser->state = TIPS_IN_THETIP;
tips_parser_parse_lang (parser, attribute_names, attribute_values);
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else
tips_parser_start_unknown (parser);
......@@ -280,12 +279,12 @@ tips_parser_end_element (GMarkupParseContext *context,
break;
case TIPS_IN_WELCOME:
tips_parser_set_by_lang (parser, &parser->current_tip->welcome);
tips_parser_set_by_locale (parser, &parser->current_tip->welcome);
parser->state = TIPS_IN_TIP;
break;
case TIPS_IN_THETIP:
tips_parser_set_by_lang (parser, &parser->current_tip->thetip);
tips_parser_set_by_locale (parser, &parser->current_tip->thetip);
parser->state = TIPS_IN_TIP;
break;
......@@ -311,8 +310,20 @@ tips_parser_characters (GMarkupParseContext *context,
{
case TIPS_IN_WELCOME:
case TIPS_IN_THETIP:
if (parser->lang_state != TIPS_LANG_MISMATCH)
g_string_append (parser->value, text);
if (parser->locale_state != TIPS_LOCALE_MISMATCH)
{
gint i;
/* strip tabs, newlines and adjacent whitespace */
for (i = 0; i < text_len; i++)
{
if (text[i] != ' ' && text[i] != '\t' && text[i] != '\n')
g_string_append_c (parser->value, text[i]);
else if (parser->value->len > 0 &&
parser->value->str[parser->value->len - 1] != ' ')
g_string_append_c (parser->value, ' ');
}
}
break;
default:
break;
......@@ -349,19 +360,21 @@ tips_parser_end_unknown (TipsParser *parser)
}
static void
tips_parser_parse_lang (TipsParser *parser,
const gchar **names,
const gchar **values)
tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values)
{
parser->lang_state = TIPS_LANG_NONE;
parser->locale_state = TIPS_LOCALE_NONE;
while (*names && *values)
{
if (strcmp (*names, "xml:lang") == 0 && **values)
{
parser->lang_state = ((parser->lang &&
strcmp (*values, parser->lang) == 0) ?
TIPS_LANG_MATCH : TIPS_LANG_MISMATCH);
parser->locale_state = ((parser->locale &&
(strcmp (*values, parser->locale) == 0 ||
strncmp (*values, parser->locale, 2) == 0))
? TIPS_LOCALE_MATCH
: TIPS_LOCALE_MISMATCH);
}
names++;
......@@ -370,13 +383,13 @@ tips_parser_parse_lang (TipsParser *parser,
}
static void
tips_parser_set_by_lang (TipsParser *parser,
gchar **dest)
tips_parser_set_by_locale (TipsParser *parser,
gchar **dest)
{
switch (parser->lang_state)
switch (parser->locale_state)
{
case TIPS_LANG_NONE:
if (!parser->lang)
case TIPS_LOCALE_NONE:
if (!parser->locale)
{
g_free (*dest);
*dest = g_strdup (parser->value->str);
......@@ -387,12 +400,12 @@ tips_parser_set_by_lang (TipsParser *parser,
}
break;
case TIPS_LANG_MATCH:
case TIPS_LOCALE_MATCH:
g_free (*dest);
*dest = g_strdup (parser->value->str);
break;
case TIPS_LANG_MISMATCH:
case TIPS_LOCALE_MISMATCH:
break;
}
}
......@@ -37,7 +37,7 @@ GimpTip * gimp_tip_new (const gchar *welcome,
void gimp_tip_free (GimpTip *tip);
GList * gimp_tips_from_file (const gchar *filename,
const gchar *language,
const gchar *locale,
GError **error);
void gimp_tips_free (GList *tips);
......
......@@ -49,11 +49,13 @@ static void tips_toggle_update (GtkWidget *widget,
static GtkWidget *tips_dialog = NULL;
static GtkWidget *tips_label = NULL;
static GList *tips = NULL;
static gint tips_count = 0;
static gint old_show_tips = 0;
static GtkWidget *tips_dialog = NULL;
static GtkWidget *welcome_label = NULL;
static GtkWidget *thetip_label = NULL;
static GList *tips = NULL;
static GList *current_tip = NULL;
static gint tips_count = 0;
static gint old_show_tips = 0;
GtkWidget *
......@@ -75,12 +77,15 @@ tips_dialog_create (void)
filename = g_build_filename (gimp_data_directory (), "tips",
"gimp-tips.xml", NULL);
tips = gimp_tips_from_file (filename, NULL, &error);
tips = gimp_tips_from_file (filename,
setlocale (LC_MESSAGES, NULL),
&error);
g_free (filename);
if (error)
{
tips = g_list_prepend (NULL, gimp_tip_new (NULL, error->message));
tips = g_list_prepend (tips, gimp_tip_new (NULL, error->message));
g_error_free (error);
}
}
......@@ -90,6 +95,8 @@ tips_dialog_create (void)
if (gimprc.last_tip >= tips_count || gimprc.last_tip < 0)
gimprc.last_tip = 0;
current_tip = g_list_nth (tips, gimprc.last_tip);
if (tips_dialog)
return tips_dialog;
......@@ -116,24 +123,37 @@ tips_dialog_create (void)
gtk_container_add (GTK_CONTAINER (tips_dialog), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 5);
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
tip = g_list_nth_data (tips, gimprc.last_tip);
tips_label = gtk_label_new (tip->thetip);
vbox2 = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
gtk_widget_show (vbox2);
tip = (GimpTip *) current_tip->data;
welcome_label = gtk_label_new (tip->welcome);
gtk_label_set_justify (GTK_LABEL (welcome_label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (welcome_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (welcome_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), welcome_label, FALSE, FALSE, 0);
if (tip->welcome)
gtk_widget_show (welcome_label);
gtk_label_set_justify (GTK_LABEL (tips_label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (tips_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), tips_label, TRUE, TRUE, 3);
gtk_widget_show (tips_label);
thetip_label = gtk_label_new (tip->thetip);
gtk_label_set_justify (GTK_LABEL (thetip_label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (thetip_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (thetip_label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), thetip_label, TRUE, TRUE, 0);
gtk_widget_show (thetip_label);
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
gtk_widget_show (vbox2);
filename = g_build_filename (gimp_data_directory(),
filename = g_build_filename (gimp_data_directory (),
"images", "wilber-tips.png", NULL);
wilber = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
......@@ -154,7 +174,8 @@ tips_dialog_create (void)
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
button = gtk_check_button_new_with_label (_("Show tip next time GIMP starts"));
button =
gtk_check_button_new_with_mnemonic (_("Show tip next time GIMP starts"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), gimprc.show_tips);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
......@@ -185,7 +206,7 @@ tips_dialog_create (void)
gtk_box_pack_end (GTK_BOX (hbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
button = gtk_button_new_with_label (_("Previous Tip"));
button = gtk_button_new_with_mnemonic (_("_Previous Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_widget_set_sensitive (button, (tips_count > 1));
gtk_container_add (GTK_CONTAINER (bbox), button);
......@@ -195,7 +216,7 @@ tips_dialog_create (void)
G_CALLBACK (tips_show_previous),
NULL);
button = gtk_button_new_with_label (_("Next Tip"));
button = gtk_button_new_with_mnemonic (_("_Next Tip"));
GTK_WIDGET_UNSET_FLAGS (button, GTK_RECEIVES_DEFAULT);
gtk_widget_set_sensitive (button, (tips_count > 1));
gtk_container_add (GTK_CONTAINER (bbox), button);
......@@ -222,10 +243,12 @@ tips_dialog_destroy (GtkWidget *widget,
tips_dialog = NULL;
current_tip = NULL;
gimp_tips_free (tips);
tips = NULL;
/* the last-shown-tip is now saved in sessionrc */
gimprc.last_tip = g_list_position (tips, current_tip);
if (gimprc.show_tips != old_show_tips)
{
......@@ -239,35 +262,35 @@ tips_dialog_destroy (GtkWidget *widget,
}
static void
tips_show_previous (GtkWidget *widget,
gpointer data)
tips_set_labels (GimpTip *tip)
{
GimpTip *tip;
g_return_if_fail (tip != NULL);
gimprc.last_tip--;
if (gimprc.last_tip < 0)
gimprc.last_tip = tips_count - 1;
if (tip->welcome)
gtk_widget_show (welcome_label);
else
gtk_widget_hide (welcome_label);
gtk_label_set_text (GTK_LABEL (welcome_label), tip->welcome);
gtk_label_set_text (GTK_LABEL (thetip_label), tip->thetip);
}
tip = g_list_nth_data (tips, gimprc.last_tip);
static void
tips_show_previous (GtkWidget *widget,
gpointer data)
{
current_tip = current_tip->prev ? current_tip->prev : g_list_last (tips);
gtk_label_set_text (GTK_LABEL (tips_label), tip->thetip);
tips_set_labels (current_tip->data);
}
static void
tips_show_next (GtkWidget *widget,
gpointer data)
{
GimpTip *tip;
gimprc.last_tip++;
if (gimprc.last_tip >= tips_count)
gimprc.last_tip = 0;
tip = g_list_nth_data (tips, gimprc.last_tip);
current_tip = current_tip->next ? current_tip->next : tips;
gtk_label_set_text (GTK_LABEL (tips_label), tip->thetip);
tips_set_labels (current_tip->data);
}
static void
......
......@@ -43,23 +43,23 @@ typedef enum
typedef enum
{
TIPS_LANG_NONE,
TIPS_LANG_MATCH,
TIPS_LANG_MISMATCH,
} TipsParserLangState;
TIPS_LOCALE_NONE,
TIPS_LOCALE_MATCH,
TIPS_LOCALE_MISMATCH,
} TipsParserLocaleState;
typedef struct _TipsParser TipsParser;
struct _TipsParser
{
TipsParserState state;
TipsParserState last_known_state;
const gchar *lang;
TipsParserLangState lang_state;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
TipsParserState state;
TipsParserState last_known_state;
const gchar *locale;
TipsParserLocaleState locale_state;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
};
......@@ -82,13 +82,13 @@ static void tips_parser_error (GMarkupParseContext *context,
GError *error,
gpointer user_data);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_lang (TipsParser *parser,
const gchar **names,
const gchar **values);
static void tips_parser_set_by_lang (TipsParser *parser,
gchar **dest);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values);
static void tips_parser_set_by_locale (TipsParser *parser,
gchar **dest);
static const GMarkupParser markup_parser =
......@@ -126,7 +126,7 @@ gimp_tip_free (GimpTip *tip)
GList *
gimp_tips_from_file (const gchar *filename,
const gchar *language,
const gchar *locale,
GError **error)
{
GMarkupParseContext *context;
......@@ -151,8 +151,8 @@ gimp_tips_from_file (const gchar *filename,
}
parser = g_new0 (TipsParser, 1);
parser->lang = language;
parser->value = g_string_new (NULL);
parser->locale = locale;
parser->value = g_string_new (NULL);
context = g_markup_parse_context_new (&markup_parser, 0, parser, NULL);
......@@ -202,7 +202,6 @@ gimp_tips_free (GList *tips)
g_list_free (tips);
}
static void
tips_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
......@@ -236,12 +235,12 @@ tips_parser_start_element (GMarkupParseContext *context,
if (strcmp (element_name, "welcome") == 0)
{
parser->state = TIPS_IN_WELCOME;
tips_parser_parse_lang (parser, attribute_names, attribute_values);
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else if (strcmp (element_name, "thetip") == 0)
{
parser->state = TIPS_IN_THETIP;
tips_parser_parse_lang (parser, attribute_names, attribute_values);
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else
tips_parser_start_unknown (parser);
......@@ -280,12 +279,12 @@ tips_parser_end_element (GMarkupParseContext *context,
break;
case TIPS_IN_WELCOME:
tips_parser_set_by_lang (parser, &parser->current_tip->welcome);
tips_parser_set_by_locale (parser, &parser->current_tip->welcome);
parser->state = TIPS_IN_TIP;
break;
case TIPS_IN_THETIP:
tips_parser_set_by_lang (parser, &parser->current_tip->thetip);
tips_parser_set_by_locale (parser, &parser->current_tip->thetip);
parser->state = TIPS_IN_TIP;
break;
......@@ -311,8 +310,20 @@ tips_parser_characters (GMarkupParseContext *context,
{
case TIPS_IN_WELCOME:
case TIPS_IN_THETIP:
if (parser->lang_state != TIPS_LANG_MISMATCH)
g_string_append (parser->value, text);
if (parser->locale_state != TIPS_LOCALE_MISMATCH)
{
gint i;
/* strip tabs, newlines and adjacent whitespace */
for (i = 0; i < text_len; i++)
{
if (text[i] != ' ' && text[i] != '\t' && text[i] != '\n')
g_string_append_c (parser->value, text[i]);
else if (parser->value->len > 0 &&
parser->value->str[parser->value->len - 1] != ' ')
g_string_append_c (parser->value, ' ');
}
}
break;
default:
break;
......@@ -349,19 +360,21 @@ tips_parser_end_unknown (TipsParser *parser)
}
static void
tips_parser_parse_lang (TipsParser *parser,
const gchar **names,
const gchar **values)
tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values)
{
parser->lang_state = TIPS_LANG_NONE;