pidgin: ddc321b4: Fix showing umlauts etc. on non-utf8 loc...

sadrul at pidgin.im sadrul at pidgin.im
Fri Nov 20 17:51:52 EST 2009


-----------------------------------------------------------------
Revision: ddc321b43c0fa9fd6f50cbe5e170c666c4647c2d
Ancestor: 253167f45b9ac9d02b9a70bc2a3469705175d008
Author: sadrul at pidgin.im
Date: 2009-11-20T21:45:44
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ddc321b43c0fa9fd6f50cbe5e170c666c4647c2d

Modified files:
        ChangeLog finch/libgnt/gntbox.c finch/libgnt/gntbutton.c
        finch/libgnt/gntcheckbox.c finch/libgnt/gntcombobox.c
        finch/libgnt/gntentry.c finch/libgnt/gntinternal.h
        finch/libgnt/gntlabel.c finch/libgnt/gntmain.c
        finch/libgnt/gntmenu.c finch/libgnt/gnttextview.c
        finch/libgnt/gnttree.c finch/libgnt/gntws.c

ChangeLog: 

Fix showing umlauts etc. on non-utf8 locales.

-------------- next part --------------
============================================================
--- ChangeLog	b93613ebaa316d10ba260ec5d9f94a2ab9b68f1e
+++ ChangeLog	5aa1e763049a83e5ad024a67635fd3276a7a7530
@@ -58,6 +58,7 @@ version 2.6.4 (??/??/20??):
 	* The TinyURL plugin now creates shorter URLs for long non-conversation
 	  URLs, e.g. URLs to open Inbox in Yahoo/MSN protocols, or the Yahoo
 	  Captcha when joining chat rooms.
+	* Fix displaying umlauts etc. in non-utf8 locale (fix in libgnt).
 
 	Pidgin:
 	* The userlist in a multiuser chat can be styled via gtkrc by using the
============================================================
--- finch/libgnt/gntbox.c	5e70754286c228776d9bac42e014f9eaf4964a82
+++ finch/libgnt/gntbox.c	773feab811cd702f8db5186b34cc3babd0254959
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "gntinternal.h"
 #include "gntbox.h"
 #include "gntstyle.h"
 #include "gntutils.h"
@@ -90,7 +91,7 @@ gnt_box_draw(GntWidget *widget)
 		else
 			wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TITLE_D));
 		mvwaddch(widget->window, 0, pos-1, ACS_RTEE | gnt_color_pair(GNT_COLOR_NORMAL));
-		mvwaddstr(widget->window, 0, pos, title);
+		mvwaddstr(widget->window, 0, pos, C_(title));
 		mvwaddch(widget->window, 0, right, ACS_LTEE | gnt_color_pair(GNT_COLOR_NORMAL));
 		g_free(title);
 	}
============================================================
--- finch/libgnt/gntbutton.c	be57de01c3fa867db8891d3ad40ef32fd1ed635a
+++ finch/libgnt/gntbutton.c	68de0381ebddff6a5bcdcff6f2b3ad556c9d1f0d
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "gntinternal.h"
 #include "gntbutton.h"
 #include "gntstyle.h"
 #include "gntutils.h"
@@ -48,7 +49,7 @@ gnt_button_draw(GntWidget *widget)
 		type = GNT_COLOR_NORMAL;
 
 	wbkgdset(widget->window, '\0' | gnt_color_pair(type));
-	mvwaddstr(widget->window, (small_button) ? 0 : 1, 2, button->priv->text);
+	mvwaddstr(widget->window, (small_button) ? 0 : 1, 2, C_(button->priv->text));
 	if (small_button) {
 		type = GNT_COLOR_HIGHLIGHT;
 		mvwchgat(widget->window, 0, 0, widget->priv.width, focus ? A_BOLD : A_REVERSE, type, NULL);
============================================================
--- finch/libgnt/gntcheckbox.c	a490038651a76e44b34ec3febed63df2164eb031
+++ finch/libgnt/gntcheckbox.c	e4061aeb639399aafe9b84a68d1320e803b9027f
@@ -51,7 +51,7 @@ gnt_check_box_draw(GntWidget *widget)
 	mvwaddch(widget->window, 0, 2, ']');
 
 	wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL));
-	mvwaddstr(widget->window, 0, 4, (GNT_BUTTON(cb)->priv->text));
+	mvwaddstr(widget->window, 0, 4, C_(GNT_BUTTON(cb)->priv->text));
 	wmove(widget->window, 0, 1);
 
 	GNTDEBUG;
============================================================
--- finch/libgnt/gntcombobox.c	b9b7a42f1f149ca8d54907aa0173bdfc841014a0
+++ finch/libgnt/gntcombobox.c	6ea4ab3db35c312f0ea8039b41886a2d6c995951
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "gntinternal.h"
 #include "gntbox.h"
 #include "gntcombobox.h"
 #include "gnttree.h"
@@ -90,7 +91,7 @@ gnt_combo_box_draw(GntWidget *widget)
 	s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len);
 	*s = '\0';
 
-	mvwaddstr(widget->window, 1, 1, text);
+	mvwaddstr(widget->window, 1, 1, C_(text));
 	whline(widget->window, ' ' | gnt_color_pair(type), widget->priv.width - 4 - len);
 	mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL));
 	mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL));
============================================================
--- finch/libgnt/gntentry.c	684dcf564690db94d19643dbc35bc2eb24bd139e
+++ finch/libgnt/gntentry.c	aab15984d2897e625531f155b67623568e1446bc
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <string.h>
 
+#include "gntinternal.h"
 #include "gntbox.h"
 #include "gntentry.h"
 #include "gntmarshal.h"
@@ -284,7 +285,7 @@ gnt_entry_draw(GntWidget *widget)
 				g_utf8_pointer_to_offset(entry->scroll, entry->end));
 	}
 	else
-		mvwprintw(widget->window, 0, 0, "%s", entry->scroll);
+		mvwprintw(widget->window, 0, 0, "%s", C_(entry->scroll));
 
 	stop = gnt_util_onscreen_width(entry->scroll, entry->end);
 	if (stop < widget->priv.width)
============================================================
--- finch/libgnt/gntinternal.h	363f9df88c6ab973ad7b619e6010e4a5ff50b0d5
+++ finch/libgnt/gntinternal.h	05baa71b9741ebe3fe9715212ca5ec4f5fe7b955
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
+#include <glib.h>
 #undef G_LOG_DOMAIN
 #define G_LOG_DOMAIN "Gnt"
 
@@ -31,3 +32,6 @@
 # define gnt_warning g_warning
 #endif
 
+extern int gnt_need_conversation_to_locale;
+extern const char *C_(const char *x);
+
============================================================
--- finch/libgnt/gntlabel.c	bb612cbba2c334e0c19a8ac3089b84ef3a8baa14
+++ finch/libgnt/gntlabel.c	f527d8e67302ca42aa54ca932fd2d79a63615a10
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "gntinternal.h"
 #include "gntlabel.h"
 #include "gntutils.h"
 
@@ -53,7 +54,7 @@ gnt_label_draw(GntWidget *widget)
 	chtype flag = gnt_text_format_flag_to_chtype(label->flags);
 
 	wbkgdset(widget->window, '\0' | flag);
-	mvwaddstr(widget->window, 0, 0, label->text);
+	mvwaddstr(widget->window, 0, 0, C_(label->text));
 
 	GNTDEBUG;
 }
============================================================
--- finch/libgnt/gntmain.c	d61a9bb0e859f8155fb9ad4ba64372c9bc6d6042
+++ finch/libgnt/gntmain.c	c68dc315a89db3e9fe6caff990e17bc20153a7fd
@@ -82,6 +82,8 @@ static GntClipboard *clipboard;
 static GntWM *wm;
 static GntClipboard *clipboard;
 
+int gnt_need_conversation_to_locale;
+
 #define HOLDING_ESCAPE  (escape_stuff.timer != 0)
 
 static struct {
@@ -465,10 +467,12 @@ void gnt_init()
 #ifdef NO_WIDECHAR
 	ascii_only = TRUE;
 #else
-	if (locale && (strstr(locale, "UTF") || strstr(locale, "utf")))
+	if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) {
 		ascii_only = FALSE;
-	else
+	} else {
 		ascii_only = TRUE;
+		gnt_need_conversation_to_locale = TRUE;
+	}
 #endif
 
 	initscr();
@@ -731,3 +735,24 @@ gboolean gnt_is_refugee()
 #endif
 }
 
+const char *C_(const char *x)
+{
+	static char *c = NULL;
+	if (gnt_need_conversation_to_locale) {
+		GError *error = NULL;
+		g_free(c);
+		c = g_locale_from_utf8(x, -1, NULL, NULL, &error);
+		if (c == NULL || error) {
+			char *store = c;
+			c = NULL;
+			gnt_warning("Error: %s\n", error ? error->message : "(unknown)");
+			g_error_free(error);
+			error = NULL;
+			g_free(c);
+			c = store;
+		}
+		return c ? c : x;
+	} else
+		return x;
+}
+
============================================================
--- finch/libgnt/gntmenu.c	5991a201f76da038410c07dbce48bc06991264e5
+++ finch/libgnt/gntmenu.c	9f97768c994c84f8e018237202a834a1d199b6d6
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "gntinternal.h"
 #include "gntmenu.h"
 #include "gntmenuitemcheck.h"
 
@@ -92,7 +93,7 @@ gnt_menu_draw(GntWidget *widget)
 			item->priv.x = getcurx(widget->window) + widget->priv.x;
 			item->priv.y = getcury(widget->window) + widget->priv.y + 1;
 			wbkgdset(widget->window, type);
-			wprintw(widget->window, " %s   ", item->text);
+			wprintw(widget->window, " %s   ", C_(item->text));
 		}
 	} else {
 		org_draw(widget);
============================================================
--- finch/libgnt/gnttextview.c	a5621d9b3331ebb9c5dec9d863b239549db19a31
+++ finch/libgnt/gnttextview.c	96936723d96661f1aab7605c0f3accc04ec14c9a
@@ -118,7 +118,7 @@ gnt_text_view_draw(GntWidget *widget)
 			if (select_start && select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
 				fl |= A_REVERSE;
 				wattrset(widget->window, fl);
-				wprintw(widget->window, "%s", (view->string->str + seg->start));
+				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
 			} else if (select_start && select_end &&
 				((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) ||
 				(select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) {
@@ -132,13 +132,13 @@ gnt_text_view_draw(GntWidget *widget)
 						fl = seg->flags;
 					str = g_strndup(cur, last - cur);
 					wattrset(widget->window, fl);
-					waddstr(widget->window, str);
+					waddstr(widget->window, C_(str));
 					g_free(str);
 					cur = g_utf8_next_char(cur);
 				}
 			} else {
 				wattrset(widget->window, fl);
-				wprintw(widget->window, "%s", (view->string->str + seg->start));
+				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
 			}
 			*end = back;
 		}
============================================================
--- finch/libgnt/gnttree.c	04e5815e0f58358bc23f36e45b0d6b7d42e4c95c
+++ finch/libgnt/gnttree.c	cf84b9a2bf3e25dddcf98f887da5be719f57c33d
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "gntinternal.h"
 #include "gntmarshal.h"
 #include "gntstyle.h"
 #include "gnttree.h"
@@ -549,7 +550,7 @@ redraw_tree(GntTree *tree)
 		}
 
 		wbkgdset(widget->window, '\0' | attr);
-		mvwaddstr(widget->window, i, pos, str);
+		mvwaddstr(widget->window, i, pos, C_(str));
 		whline(widget->window, ' ', scrcol - wr);
 		tree->bottom = row;
 		g_free(str);
============================================================
--- finch/libgnt/gntws.c	84bcc551bd267c5ad6b59303a366762524150b6a
+++ finch/libgnt/gntws.c	07a062e4a689caccf0729f06b3379ee009d81d3c
@@ -1,5 +1,6 @@
 #include <gmodule.h>
 
+#include "gntinternal.h"
 #include "gntbox.h"
 #include "gntwidget.h"
 #include "gntwindow.h"
@@ -73,7 +74,7 @@ gnt_ws_draw_taskbar(GntWS *ws, gboolean 
 		else
 			mvwhline(taskbar, 0, width * i, ' ' | gnt_color_pair(color), getmaxx(stdscr) - width * i);
 		title = GNT_BOX(w)->title;
-		mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>");
+		mvwprintw(taskbar, 0, width * i, "%s", title ? C_(title) : "<gnt>");
 		if (i)
 			mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | gnt_color_pair(GNT_COLOR_NORMAL));
 	}


More information about the Commits mailing list