diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/common/conversion.cc synaptic-0.32/common/conversion.cc --- synaptic-0.32.orig/common/conversion.cc 1970-01-01 03:00:00 +0300 +++ synaptic-0.32/common/conversion.cc 2003-01-21 15:13:17 +0300 @@ -0,0 +1,94 @@ +/* -*- mode: cpp; mode: fold -*- + * + * conversion.cc + * + * Copyright (c) 2003 Sviatoslav Sviridov + * + * Author: Sviatoslav Sviridov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id$ + */ + +#include "conversion.h" + +#include + +#include +#include + +using namespace std; + +IConv::IConv(const char *tocode, const char *fromcode): + /*inbuf(0), inbuflen(0),*/ + outbuf(0), outbuflen(0), gbuf(0) +{ + //type = UseIConv; + type = UseGConv; + if (fromcode == NULL) + fromcode = nl_langinfo(CODESET); + if (tocode!=NULL && fromcode!=NULL) + cd = iconv_open(tocode, fromcode); + else + cd = (iconv_t)-1; +} + +IConv::~IConv() +{ + iconv_close(cd); + delete outbuf; + g_free(gbuf); +} + +const char *IConv::i_convert(const char *frombuf, size_t len) +{ + if (frombuf==NULL || len<=0) + return NULL; + if (cd == (iconv_t)-1) + return frombuf; + + if (outbuflen < 3*len+1) { + delete outbuf; + outbuf = new char[3*len+1]; + if (outbuf!=NULL) + outbuflen = 3*len+1; + else outbuflen = 0; + } + char *inptr = (char *) frombuf; + char *outptr = outbuf; + size_t inleft = len; + size_t outleft = outbuflen - 1; + + size_t res = iconv(cd, &inptr, &inleft, &outptr, &outleft); + if (res != (size_t) -1) { + *outptr = 0; + return outbuf; + } else + return frombuf; +} + +const char *IConv::g_convert(const char *frombuf, size_t len) +{ + gsize br = 0; + gsize bw = 0; + + g_free(gbuf); + + gbuf = g_locale_to_utf8(frombuf, len, &br, &bw, NULL); + + return gbuf; +} diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/common/conversion.h synaptic-0.32/common/conversion.h --- synaptic-0.32.orig/common/conversion.h 1970-01-01 03:00:00 +0300 +++ synaptic-0.32/common/conversion.h 2003-01-21 15:13:18 +0300 @@ -0,0 +1,60 @@ +/* -*- mode: cpp; mode: fold -*- + * + * conversion.h + * + * Copyright (c) 2003 Sviatoslav Sviridov + * + * Author: Sviatoslav Sviridov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id$ + */ + +#ifndef CONVERSION_H +#define CONVERSION_H + +#include +#include "config.h" +#include +#include + +class IConv +{ + enum ConvType {UseIConv, UseGConv}; + + protected: + ConvType type; + iconv_t cd; + + char *outbuf; + size_t outbuflen; + + gchar *gbuf; + public: + IConv(const char *tocode, const char *fromcode = NULL); + ~IConv(); + + void i_reset() { iconv(cd, NULL, NULL, NULL, NULL); }; + const char *i_convert(const char *frombuf, size_t len); + const char *g_convert(const char *frombuf, size_t len); + + const char *convert(const char *frombuf, size_t len) + { return type == UseIConv ? i_convert(frombuf, len) : g_convert(frombuf, len); }; + +}; + +#endif // CONVERSION_H diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/common/Makefile.am synaptic-0.32/common/Makefile.am --- synaptic-0.32.orig/common/Makefile.am 2002-08-20 02:33:00 +0400 +++ synaptic-0.32/common/Makefile.am 2003-01-21 14:28:11 +0300 @@ -2,7 +2,7 @@ noinst_LIBRARIES = libraptor.a -INCLUDES = -I/usr/include/apt-pkg @RPM_HDRS@ @DEB_HDRS@ +INCLUDES = -I/usr/include/apt-pkg @RPM_HDRS@ @DEB_HDRS@ @PACKAGE_CFLAGS@ libraptor_a_SOURCES =\ i18n.h\ @@ -27,8 +27,10 @@ raptoptions.cc \ rsources.cc \ rsources.h \ - raptoptions.h - + raptoptions.h \ + conversion.h \ + conversion.cc + # rrepositoryfile.h\ # rrepositoryfile.cc diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/configure.in synaptic-0.32/configure.in --- synaptic-0.32.orig/configure.in 2003-01-20 13:22:59 +0300 +++ synaptic-0.32/configure.in 2003-01-21 14:17:36 +0300 @@ -33,7 +33,7 @@ ) dnl Checks for gtk -pkg_modules="gtk+-2.0 >= 2.0.0, libglade-2.0 >= 2.0.0, pango >= 1.0.0" +pkg_modules="gtk+-2.0 >= 2.0.0, libglade-2.0 >= 2.0.0, pango >= 1.0.0, glib-2.0" PKG_CHECK_MODULES(PACKAGE, [$pkg_modules]) AC_SUBST(PACKAGE_CFLAGS) AC_SUBST(PACKAGE_LIBS) @@ -105,7 +105,7 @@ dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(unistd.h libintl.h) +AC_CHECK_HEADERS(unistd.h libintl.h iconv.h) AC_LANG_CPLUSPLUS AC_CHECK_HEADER(apt-pkg/configuration.h) @@ -122,7 +122,7 @@ dnl Checks for library functions. AC_FUNC_STRCOLL -AC_CHECK_FUNCS(regcomp strdup) +AC_CHECK_FUNCS(regcomp strdup iconv) AC_ARG_WITH(pkg-hold, [--with-pkg-hold build with experimental package "hold" feature], diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/gtk/rgmainwindow.cc synaptic-0.32/gtk/rgmainwindow.cc --- synaptic-0.32.orig/gtk/rgmainwindow.cc 2003-01-21 12:45:03 +0300 +++ synaptic-0.32/gtk/rgmainwindow.cc 2003-01-21 13:27:42 +0300 @@ -68,7 +68,7 @@ #include "rginstallprogress.h" #include "rgdummyinstallprogress.h" #include "rgzvtinstallprogress.h" - +#include "conversion.h" // icons and pixmaps @@ -873,11 +873,11 @@ if (_showUpdateInfo && elem->updateImportance() == RPackage::ISecurity) - gtk_clist_set_pixtext(GTK_CLIST(_table), row, 4, str, 4, + gtk_clist_set_pixtext(GTK_CLIST(_table), row, 4, _iconv.convert(str,strlen(str)), 4, StatusPixmaps[8], StatusMasks[8]); else - gtk_clist_set_text(GTK_CLIST(_table), row, 4, str); + gtk_clist_set_text(GTK_CLIST(_table), row, 4, _iconv.convert(str,strlen(str))); row++; } @@ -1217,7 +1217,8 @@ // name/summary gtk_label_set_text(GTK_LABEL(_nameL), (char*)pkg->name()); - gtk_label_set_text(GTK_LABEL(_summL), (char*)pkg->summary().c_str()); + //gtk_label_set_text(GTK_LABEL(_summL), (char*)pkg->summary().c_str()); + gtk_label_set_text(GTK_LABEL(_summL), _iconv.convert(pkg->summary().c_str(),pkg->summary().size())); // package info @@ -1297,7 +1298,8 @@ } // description - gtk_text_buffer_set_text(_textBuffer, pkg->description(), -1); + //gtk_text_buffer_set_text(_textBuffer, pkg->description(), -1); + gtk_text_buffer_set_text(_textBuffer, _iconv.convert(pkg->description(), strlen(pkg->description())), -1); updateDynPackageInfo(pkg); setStatusText(); } @@ -1487,7 +1489,7 @@ RGMainWindow::RGMainWindow(RPackageLister *packLister) - : RGWindow("main", false, true), _lister(packLister) + : RGWindow("main", false, true), _lister(packLister), _iconv("UTF8") { #if !defined(DEBUGUI) || defined(HAVE_RPM) //_showUpdateInfo = true; // xxx conectiva only, for now diff -urN --exclude-from=synaptic.excludes synaptic-0.32.orig/gtk/rgmainwindow.h synaptic-0.32/gtk/rgmainwindow.h --- synaptic-0.32.orig/gtk/rgmainwindow.h 2003-01-21 12:45:04 +0300 +++ synaptic-0.32/gtk/rgmainwindow.h 2003-01-21 13:27:42 +0300 @@ -35,6 +35,7 @@ #include #include "rgwindow.h" +#include "conversion.h" class RGSourcesWindow; class RGConfigWindow; @@ -242,7 +243,8 @@ static void closeFilterManagerAction(void *self, RGFilterManagerWindow *win); // RPackageObserver virtual void notifyChange(RPackage *pkg); - + + IConv _iconv; public: RGMainWindow(RPackageLister *packLister); virtual ~RGMainWindow() {};