[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#449554: konqueror: Recode manual pages to UTF-8



tags 449554 patch
user ubuntu-devel@lists.ubuntu.com
usertags 449554 origin-ubuntu ubuntu-patch hardy
thanks

The attached patch uses a new facility provided by man-db 2.5.1 to
recode manual pages to UTF-8 while reading them. This allows the man kio
slave's rendering code to work regardless of the source encoding of the
manual page, without it having to have lots of logic duplicated from
man-db to figure this out.

This facility is specific to man-db, and so at present not suitable for
upstream (without some kind of run-time logic to figure out whether the
facility is available).

See also:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=440420
  https://bugs.launchpad.net/ubuntu/+source/kdebase/+bug/44548

Thanks,

-- 
Colin Watson                                       [cjwatson@debian.org]
diff -Nru kdebase-3.5.8.dfsg.1.orig/debian/control.in kdebase-3.5.8.dfsg.1/debian/control.in
--- kdebase-3.5.8.dfsg.1.orig/debian/control.in	2008-02-11 10:45:39.000000000 +0000
+++ kdebase-3.5.8.dfsg.1/debian/control.in	2008-02-11 10:52:06.000000000 +0000
@@ -174,7 +174,7 @@
 Package: kdebase-kio-plugins
 Section: kde
 Architecture: any
-Depends: ${shlibs:Depends}, libsasl2-modules, psmisc, kdeeject
+Depends: ${shlibs:Depends}, libsasl2-modules, psmisc, kdeeject, man-db (>= 2.5.1-1)
 Recommends: hal, pmount, kamera, kdemultimedia-kio-plugins
 Suggests: khelpcenter, mtools
 Conflicts: kdebase-libs (<< 4:3.0.0)
diff -Nru kdebase-3.5.8.dfsg.1.orig/debian/patches/71_kio_man_utf8.diff kdebase-3.5.8.dfsg.1/debian/patches/71_kio_man_utf8.diff
--- kdebase-3.5.8.dfsg.1.orig/debian/patches/71_kio_man_utf8.diff	1970-01-01 01:00:00.000000000 +0100
+++ kdebase-3.5.8.dfsg.1/debian/patches/71_kio_man_utf8.diff	2008-02-11 10:44:54.000000000 +0000
@@ -0,0 +1,64 @@
+diff -Nur -x '*.orig' -x '*~' kdebase-3.5.8/kioslave/man/kio_man.cpp kdebase-3.5.8.new/kioslave/man/kio_man.cpp
+--- kdebase-3.5.8/kioslave/man/kio_man.cpp	2007-10-08 10:51:22.000000000 +0100
++++ kdebase-3.5.8.new/kioslave/man/kio_man.cpp	2008-01-31 09:04:58.000000000 +0000
+@@ -517,6 +517,11 @@
+   myStdStream += QString::fromLocal8Bit(s, len);
+ }
+ 
++void MANProtocol::slotGetStdOutputUtf8(KProcess* /* p */, char *s, int len)
++{
++  myStdStream += QString::fromUtf8(s, len);
++}
++
+ char *MANProtocol::readManPage(const char *_filename)
+ {
+     QCString filename = _filename;
+@@ -564,24 +569,20 @@
+         }
+         lastdir = filename.left(filename.findRev('/'));
+     
+-        QIODevice *fd= KFilterDev::deviceForFile(filename);
+-    
+-        if ( !fd || !fd->open(IO_ReadOnly))
+-        {
+-           delete fd;
+-           return 0;
+-        }
+-        QByteArray array(fd->readAll());
+-        kdDebug(7107) << "read " << array.size() << endl;
+-        fd->close();
+-        delete fd;
+-        
+-        if (array.isEmpty())
+-            return 0;
+-    
+-        const int len = array.size();
++        myStdStream = QString::null;
++        KProcess proc;
++        /* TODO: detect availability of 'man --recode' so that this can go
++         * upstream */
++        proc << "man" << "--recode" << "UTF-8" << filename;
++
++        QApplication::connect(&proc, SIGNAL(receivedStdout (KProcess *, char *, int)),
++                              this, SLOT(slotGetStdOutputUtf8(KProcess *, char *, int)));
++        proc.start(KProcess::Block, KProcess::All);
++
++        const QCString cstr=myStdStream.utf8();
++        const int len = cstr.size()-1;
+         buf = new char[len + 4];
+-        qmemmove(buf + 1, array.data(), len);
++        qmemmove(buf + 1, cstr.data(), len);
+         buf[0]=buf[len]='\n'; // Start and end with a end of line
+         buf[len+1]=buf[len+2]='\0'; // Two NUL characters at end
+     }
+diff -Nur -x '*.orig' -x '*~' kdebase-3.5.8/kioslave/man/kio_man.h kdebase-3.5.8.new/kioslave/man/kio_man.h
+--- kdebase-3.5.8/kioslave/man/kio_man.h	2005-10-10 16:04:01.000000000 +0100
++++ kdebase-3.5.8.new/kioslave/man/kio_man.h	2008-01-31 12:44:49.000000000 +0000
+@@ -61,6 +61,7 @@
+ 
+ private slots:
+   void slotGetStdOutput(KProcess*, char*, int);
++  void slotGetStdOutputUtf8(KProcess*, char*, int);
+     
+ private:
+     void checkManPaths();

Reply to: