changeset 18872:85b155a574a3

libgnt.localize Start working towards non-utf8 locale support.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 11 Aug 2007 04:18:14 +0000
parents 2e41a68009ba
children 7066896f6628
files finch/libgnt/gntbutton.c finch/libgnt/gntcheckbox.c finch/libgnt/gntentry.c finch/libgnt/gntlabel.c finch/libgnt/gntmain.c finch/libgnt/gnttextview.c finch/libgnt/gnttree.c finch/libgnt/gntutils.c finch/libgnt/gntutils.h
diffstat 9 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntbutton.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntbutton.c	Sat Aug 11 04:18:14 2007 +0000
@@ -162,6 +162,7 @@
 	GntWidget *widget = g_object_new(GNT_TYPE_BUTTON, NULL);
 	GntButton *button = GNT_BUTTON(widget);
 
+	text = gnt_util_localize_string(text);
 	button->priv->text = gnt_util_onscreen_fit_string(text, -1);
 	gnt_widget_set_take_focus(widget, TRUE);
 
--- a/finch/libgnt/gntcheckbox.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntcheckbox.c	Sat Aug 11 04:18:14 2007 +0000
@@ -21,6 +21,7 @@
  */
 
 #include "gntcheckbox.h"
+#include "gntutils.h"
 
 enum
 {
@@ -154,6 +155,7 @@
 {
 	GntWidget *widget = g_object_new(GNT_TYPE_CHECK_BOX, NULL);
 
+	text = gnt_util_localize_string(text);
 	GNT_BUTTON(widget)->priv->text = g_strdup(text);
 	gnt_widget_set_take_focus(widget, TRUE);
 
--- a/finch/libgnt/gntentry.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntentry.c	Sat Aug 11 04:18:14 2007 +0000
@@ -830,6 +830,7 @@
 
 	g_free(entry->start);
 
+	text = gnt_util_localize_string(text);
 	if (text && text[0])
 	{
 		len = strlen(text);
--- a/finch/libgnt/gntlabel.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntlabel.c	Sat Aug 11 04:18:14 2007 +0000
@@ -134,6 +134,7 @@
 void gnt_label_set_text(GntLabel *label, const char *text)
 {
 	g_free(label->text);
+	text = gnt_util_localize_string(text);
 	label->text = gnt_util_onscreen_fit_string(text, -1);
 
 	if (GNT_WIDGET(label)->window)
--- a/finch/libgnt/gntmain.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntmain.c	Sat Aug 11 04:18:14 2007 +0000
@@ -222,7 +222,7 @@
 {
 	char keys[256];
 	int rd;
-	char *k;
+	char *k, *utf8;
 
 	if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD)
 		return FALSE;
@@ -251,7 +251,8 @@
 
 	if (HOLDING_ESCAPE)
 		keys[0] = '\033';
-	k = keys;
+	utf8 = g_locale_to_utf8(keys, rd, NULL, NULL, NULL);
+	k = utf8 ? utf8 : keys;
 	while (rd) {
 		char back;
 		int p;
@@ -278,6 +279,7 @@
 	}
 end:
 	gnt_wm_set_event_stack(wm, FALSE);
+	g_free(utf8);
 	return TRUE;
 }
 
--- a/finch/libgnt/gnttextview.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gnttextview.c	Sat Aug 11 04:18:14 2007 +0000
@@ -376,6 +376,7 @@
 	view->string->len = 0;
 	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);
 
+	g_object_set_data(G_OBJECT(view), "resizing", GINT_TO_POINTER(TRUE));
 	for (; back; back = back->prev) {
 		line = back->data;
 		if (back->next && !line->soft) {
@@ -394,6 +395,7 @@
 		free_text_line(line, NULL);
 	}
 	g_list_free(list);
+	g_object_set_data(G_OBJECT(view), "resizing", GINT_TO_POINTER(FALSE));
 
 	list = view->list = g_list_first(view->list);
 	/* Go back to the line that was in view before resizing started */
@@ -507,6 +509,8 @@
 	if (text == NULL || *text == '\0')
 		return;
 
+	if (!g_object_get_data(G_OBJECT(view), "resizing"))
+		text = gnt_util_localize_string(text);
 	fl = gnt_text_format_flag_to_chtype(flags);
 
 	len = view->string->len;
@@ -701,6 +705,7 @@
 	GList *list, *next, *iter, *inext;
 	const int text_length = text ? strlen(text) : 0;
 	int count = 0;
+	text = gnt_util_localize_string(text);
 	for (list = view->tags; list; list = next) {
 		GntTextTag *tag = list->data;
 		next = list->next;
--- a/finch/libgnt/gnttree.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gnttree.c	Sat Aug 11 04:18:14 2007 +0000
@@ -1486,6 +1486,7 @@
 
 	g_return_if_fail(colno < tree->ncol);
 	
+	text = gnt_util_localize_string(text);
 	row = g_hash_table_lookup(tree->hash, key);
 	if (row)
 	{
@@ -1625,7 +1626,9 @@
 			col->text = iter->data;
 			col->isbinary = TRUE;
 		} else {
-			col->text = g_strdup(iter->data ? iter->data : "");
+			const char *text = iter->data;
+			text = gnt_util_localize_string(text);
+			col->text = g_strdup(text ? text : "");
 			col->isbinary = FALSE;
 		}
 
@@ -1667,6 +1670,7 @@
 void gnt_tree_set_column_title(GntTree *tree, int index, const char *title)
 {
 	g_free(tree->columns[index].title);
+	title = gnt_util_localize_string(title);
 	tree->columns[index].title = g_strdup(title);
 }
 
@@ -1679,6 +1683,7 @@
 	for (i = 0; i < tree->ncol; i++)
 	{
 		const char *title = va_arg(args, const char *);
+		title = gnt_util_localize_string(title);
 		tree->columns[i].title = g_strdup(title);
 	}
 	va_end(args);
--- a/finch/libgnt/gntutils.c	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntutils.c	Sat Aug 11 04:18:14 2007 +0000
@@ -409,3 +409,14 @@
 	g_signal_connect_swapped(G_OBJECT(button), "destroy", G_CALLBACK(free_trigger_button), tb);
 }
 
+const char *gnt_util_localize_string(const char *string)
+{
+	static char *loc = NULL;
+
+	g_free(loc);
+
+	loc = string ? g_locale_from_utf8(string, -1, NULL, NULL, NULL) : NULL;
+
+	return loc ? loc : string;
+}
+
--- a/finch/libgnt/gntutils.h	Sat Aug 11 04:17:15 2007 +0000
+++ b/finch/libgnt/gntutils.h	Sat Aug 11 04:18:14 2007 +0000
@@ -139,3 +139,10 @@
  */
 void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button);
 
+/**
+ * Return a string safe to print.
+ *
+ * @param string   The UTF-8 string.
+ */
+const char *gnt_util_localize_string(const char *string);
+