[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kcoreaddons] src/lib/io: map OnlyStd{out, err}Channel to Forwarded{Error, Output}Channel
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2014-03-09 12:38:13
Message-ID: E1WMczd-0006Qz-9s () scm ! kde ! org
[Download RAW message or body]

Git commit 1fed7e861f73a6ecbed79be4625afa52a5eaaf3b by Oswald Buddenhagen.
Committed on 09/03/2014 at 12:32.
Pushed by ossi into branch 'master'.

map OnlyStd{out,err}Channel to Forwarded{Error,Output}Channel

QProcess supports these modes since qt 5.2.

the next step would be removing the OutputChannelMode enum alltogether,
but that is SIC and may require adjustments all over the place, so i'm
not going to do that.

M  +2    -91   src/lib/io/kprocess.cpp
M  +3    -5    src/lib/io/kprocess.h
M  +0    -5    src/lib/io/kprocess_p.h

http://commits.kde.org/kcoreaddons/1fed7e861f73a6ecbed79be4625afa52a5eaaf3b

diff --git a/src/lib/io/kprocess.cpp b/src/lib/io/kprocess.cpp
index b3acbbf..75081a1 100644
--- a/src/lib/io/kprocess.cpp
+++ b/src/lib/io/kprocess.cpp
@@ -30,77 +30,6 @@
 
 #include <qfile.h>
 
-#ifdef Q_OS_WIN
-# include <windows.h>
-#else
-# include <unistd.h>
-# include <errno.h>
-#endif
-
-#ifndef Q_OS_WIN
-# define STD_OUTPUT_HANDLE 1
-# define STD_ERROR_HANDLE 2
-#endif
-
-#ifdef _WIN32_WCE
-#include <stdio.h>
-#endif
-
-void KProcessPrivate::writeAll(const QByteArray &buf, int fd)
-{
-#ifdef Q_OS_WIN
-#ifndef _WIN32_WCE
-    HANDLE h = GetStdHandle(fd);
-    if (h) {
-        DWORD wr;
-        WriteFile(h, buf.data(), buf.size(), &wr, 0);
-    }
-#else
-    fwrite(buf.data(), 1, buf.size(), (FILE *)fd);
-#endif
-#else
-    int off = 0;
-    do {
-        int ret = QT_WRITE(fd, buf.data() + off, buf.size() - off);
-        if (ret < 0) {
-            if (errno != EINTR) {
-                return;
-            }
-        } else {
-            off += ret;
-        }
-    } while (off < buf.size());
-#endif
-}
-
-void KProcessPrivate::forwardStd(KProcess::ProcessChannel good, int fd)
-{
-    Q_Q(KProcess);
-
-    QProcess::ProcessChannel oc = q->readChannel();
-    q->setReadChannel(good);
-    writeAll(q->readAll(), fd);
-    q->setReadChannel(oc);
-}
-
-void KProcessPrivate::_k_forwardStdout()
-{
-#ifndef _WIN32_WCE
-    forwardStd(KProcess::StandardOutput, STD_OUTPUT_HANDLE);
-#else
-    forwardStd(KProcess::StandardOutput, (int)stdout);
-#endif
-}
-
-void KProcessPrivate::_k_forwardStderr()
-{
-#ifndef _WIN32_WCE
-    forwardStd(KProcess::StandardError, STD_ERROR_HANDLE);
-#else
-    forwardStd(KProcess::StandardError, (int)stderr);
-#endif
-}
-
 /////////////////////////////
 // public member functions //
 /////////////////////////////
@@ -128,30 +57,12 @@ KProcess::~KProcess()
 
 void KProcess::setOutputChannelMode(OutputChannelMode mode)
 {
-    Q_D(KProcess);
-
-    d->outputChannelMode = mode;
-    disconnect(this, SIGNAL(readyReadStandardOutput()));
-    disconnect(this, SIGNAL(readyReadStandardError()));
-    switch (mode) {
-    case OnlyStdoutChannel:
-        connect(this, SIGNAL(readyReadStandardError()), SLOT(_k_forwardStderr()));
-        break;
-    case OnlyStderrChannel:
-        connect(this, SIGNAL(readyReadStandardOutput()), SLOT(_k_forwardStdout()));
-        break;
-    default:
-        QProcess::setProcessChannelMode((ProcessChannelMode)mode);
-        return;
-    }
-    QProcess::setProcessChannelMode(QProcess::SeparateChannels);
+    QProcess::setProcessChannelMode((ProcessChannelMode)mode);
 }
 
 KProcess::OutputChannelMode KProcess::outputChannelMode() const
 {
-    Q_D(const KProcess);
-
-    return d->outputChannelMode;
+    return (OutputChannelMode)QProcess::processChannelMode();
 }
 
 void KProcess::setNextOpenMode(QIODevice::OpenMode mode)
diff --git a/src/lib/io/kprocess.h b/src/lib/io/kprocess.h
index 2fb7988..d57061c 100644
--- a/src/lib/io/kprocess.h
+++ b/src/lib/io/kprocess.h
@@ -61,9 +61,10 @@ public:
         ForwardedChannels = QProcess::ForwardedChannels,
         /**< Both standard output and standard error are forwarded
              to the parent process' respective channel */
-        OnlyStdoutChannel,
+        OnlyStdoutChannel = QProcess::ForwardedErrorChannel,
         /**< Only standard output is handled; standard error is forwarded */
-        OnlyStderrChannel  /**< Only standard error is handled; standard output is forwarded */
+        OnlyStderrChannel = QProcess::ForwardedOutputChannel
+        /**< Only standard error is handled; standard output is forwarded */
     };
 
     /**
@@ -332,9 +333,6 @@ private:
     using QProcess::readChannelMode;
     using QProcess::setProcessChannelMode;
     using QProcess::processChannelMode;
-
-    Q_PRIVATE_SLOT(d_func(), void _k_forwardStdout())
-    Q_PRIVATE_SLOT(d_func(), void _k_forwardStderr())
 };
 
 #endif
diff --git a/src/lib/io/kprocess_p.h b/src/lib/io/kprocess_p.h
index 59a6f9e..70fe91f 100644
--- a/src/lib/io/kprocess_p.h
+++ b/src/lib/io/kprocess_p.h
@@ -32,14 +32,9 @@ protected:
         openMode(QIODevice::ReadWrite)
     {
     }
-    void writeAll(const QByteArray &buf, int fd);
-    void forwardStd(KProcess::ProcessChannel good, int fd);
-    void _k_forwardStdout();
-    void _k_forwardStderr();
 
     QString prog;
     QStringList args;
-    KProcess::OutputChannelMode outputChannelMode;
     QIODevice::OpenMode openMode;
 
     KProcess *q_ptr;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic