Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 152546 - Recode man output into UTF-8 encoding in kio_man (By Sergey A. Sukiyazov <corwin@altlinux.ru>)
Summary: Recode man output into UTF-8 encoding in kio_man (By Sergey A. Sukiyazov <cor...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] KDE (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo KDE team
URL: https://bugs.kde.org/show_bug.cgi?id=...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-23 05:40 UTC by Alexander I. Moskalenko
Modified: 2007-04-29 17:36 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Forces kioproc to use codec for current locale instead of ISO-8859-1 (kdelibs-3.1.2-fix-kprocio-def-codec.patch,916 bytes, patch)
2006-11-29 00:41 UTC, Sergey A. Sukiyazov
Details | Diff
orrects UTF-8 charset name to charset name current locale in Content-Type builded HTML document (kdelibs-3.4.0-ALT-fix-kdoctools-mime-charset.patch,1.14 KB, patch)
2006-11-29 00:42 UTC, Sergey A. Sukiyazov
Details | Diff
copy of man_recode patch (kdebase-3.5.0-man_recode.patch,2.39 KB, patch)
2006-11-29 00:42 UTC, Sergey A. Sukiyazov
Details | Diff
Patch to document changes in kio_man.cpp (kdebase-kioslaves-3.5.6-doc-man_recode.patch,777 bytes, patch)
2007-02-12 09:43 UTC, Peter Volkov (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander I. Moskalenko 2006-10-23 05:40:23 UTC
Recode man output from current locale encoding (or from .charset file in manpages directory, or value MAN_ICONV_INPUT_CHARSET environment variable) 
into UTF-8 encoding for correct representation by konqueror 


diff -Naur kdebase-3.5.0-orig/kioslave/man/kio_man.cpp kdebase-3.5.0/kioslave/man/kio_man.cpp
--- kdebase-3.5.0-orig/kioslave/man/kio_man.cpp	2005-10-10 19:04:01 +0400
+++ kdebase-3.5.0/kioslave/man/kio_man.cpp	2006-01-01 19:49:28 +0300
@@ -30,6 +30,8 @@
 #include <qptrlist.h>
 #include <qmap.h>
 #include <qregexp.h>
+#include <qtextcodec.h>
+#include <qfileinfo.h>
 
 #include <kdebug.h>
 #include <kinstance.h>
@@ -566,6 +568,51 @@
         
         if (array.isEmpty())
             return 0;
+
+        //-------- Make locale encoded manpage text ---------------------------------
+        QTextCodec  *loc_codec = QTextCodec::codecForLocale();
+        if (loc_codec) {
+            QTextCodec  *man_codec = 0;
+
+            // Try .charmap file in manpage dir 
+            QFileInfo   fi(QFile::decodeName(_filename));
+            QFile       file(fi.dirPath(true).replace(QRegExp("/man\\w$"),"/.charset"));
+
+            if ( file.open( IO_ReadOnly ) ) {
+                QTextStream stream( &file );
+                QString     man_charmap;
+
+                man_charmap = stream.readLine(); // line of text excluding '\n'
+                file.close();
+                if (!man_charmap.isEmpty()) {
+                    man_codec = QTextCodec::codecForName(man_charmap.latin1());
+                }
+            }
+
+            // Can't find .charmap file or its empty. Try environment 
+            // variable
+            if(!man_codec) {
+                char *env = getenv("MAN_ICONV_INPUT_CHARSET");
+                if(env && *env)
+                    man_codec = QTextCodec::codecForName(env);
+            }
+    
+            // No manpage charmap specified, use UTF-8 as default
+            //if(!man_codec)
+            //    man_codec = QTextCodec::codecForMib(106);
+
+            if(man_codec) {
+                if (loc_codec->mibEnum()!=man_codec->mibEnum()) {
+                    // Locale has difer charmap than manpage
+                    QString unicode;
+
+                    kdDebug(7107) << "recode  " << man_codec->name() << " to " << loc_codec->name()  << endl;
+                    unicode = man_codec->toUnicode(array);
+                    array   = loc_codec->fromUnicode(unicode);
+                }
+            }
+        }
+        //--------------------------------------------------------------------------
     
         const int len = array.size();
         buf = new char[len + 4];
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2006-10-23 08:06:38 UTC
Don't restrict bugs without any reason. Just leave the checkboxes alone, please.
Comment 2 Charlie Shepherd (RETIRED) gentoo-dev 2006-11-24 17:21:16 UTC
Please take this upstream...
Comment 3 Diego Elio Pettenò (RETIRED) gentoo-dev 2006-11-25 00:32:35 UTC
Sorry, I was supposed to look into this.
Comment 4 Sergey A. Sukiyazov 2006-11-29 00:41:37 UTC
Created attachment 102964 [details, diff]
Forces kioproc to use codec for current locale instead of ISO-8859-1
Comment 5 Sergey A. Sukiyazov 2006-11-29 00:42:19 UTC
Created attachment 102965 [details, diff]
orrects  UTF-8 
charset name to  charset name current locale in Content-Type builded HTML document
Comment 6 Sergey A. Sukiyazov 2006-11-29 00:42:52 UTC
Created attachment 102966 [details, diff]
copy of man_recode patch
Comment 7 Sergey A. Sukiyazov 2006-11-29 00:44:52 UTC
I author of this patch. Sorry for long delay... Too many work.


Some patches on kdelibs also are necessary to you. See attachements. The first patch forces kioproc to use codec 
for current locale instead of ISO-8859-1 (kdelibs-3.1.2-fix-kprocio-def-codec.patch). The second patch corrects  UTF-8 
charset name to  charset name current locale in Content-Type builded HTML document (kdelibs-3.4.0-ALT-fix-kdoctools-mime-charset.patch).

And copy of man_recode patch (kdebase-3.5.0-man_recode.patch)


Comment 8 Peter Volkov (RETIRED) gentoo-dev 2007-02-12 09:43:46 UTC
Created attachment 109936 [details, diff]
Patch to document changes in kio_man.cpp

Small documentation update to reflect changes done by this patches.

BTW. This patches are applied in Altlinux Sisyphus (unstable branch of Altlinux):
http://sisyphus.ru/srpm/kdelibs/patches

* kdelibs-3.4.0-ALT-fix-kdoctools-mime-charset.patch
* kdelibs-3.1.2-fix-kprocio-def-codec.patch

and
http://sisyphus.ru/srpm/kdebase/patches

* kdebase-3.5.0-man_recode.patch

I've tested them and these patches work here. Really useful :) Thank you, Sergey.
Comment 9 Carsten Lohrke (RETIRED) gentoo-dev 2007-04-25 09:11:15 UTC
I'm not fine to include such a patch for this minor functionality, especially since I'm quite sure your patch won't be accepted upstream, as long as it implies adding recode as another dependency to KDE. Please sort this out upstream.
Comment 10 Sergey A. Sukiyazov 2007-04-29 17:36:12 UTC
KDE upstream bugzilla link https://bugs.kde.org/show_bug.cgi?id=141340