From kde-commits Sun Mar 09 12:38:13 2014 From: Oswald Buddenhagen Date: Sun, 09 Mar 2014 12:38:13 +0000 To: kde-commits Subject: [kcoreaddons] src/lib/io: map OnlyStd{out, err}Channel to Forwarded{Error, Output}Channel Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=139436870229070 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 = -#ifdef Q_OS_WIN -# include -#else -# include -# include -#endif - -#ifndef Q_OS_WIN -# define STD_OUTPUT_HANDLE 1 -# define STD_ERROR_HANDLE 2 -#endif - -#ifdef _WIN32_WCE -#include -#endif - -void KProcessPrivate::writeAll(const QByteArray &buf, int fd) -{ -#ifdef Q_OS_WIN -#ifndef _WIN32_WCE - HANDLE h =3D 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 =3D 0; - do { - int ret =3D QT_WRITE(fd, buf.data() + off, buf.size() - off); - if (ret < 0) { - if (errno !=3D EINTR) { - return; - } - } else { - off +=3D ret; - } - } while (off < buf.size()); -#endif -} - -void KProcessPrivate::forwardStd(KProcess::ProcessChannel good, int fd) -{ - Q_Q(KProcess); - - QProcess::ProcessChannel oc =3D 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 =3D mode; - disconnect(this, SIGNAL(readyReadStandardOutput())); - disconnect(this, SIGNAL(readyReadStandardError())); - switch (mode) { - case OnlyStdoutChannel: - connect(this, SIGNAL(readyReadStandardError()), SLOT(_k_forwardStd= err())); - break; - case OnlyStderrChannel: - connect(this, SIGNAL(readyReadStandardOutput()), SLOT(_k_forwardSt= dout())); - 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 =3D QProcess::ForwardedChannels, /**< Both standard output and standard error are forwarded to the parent process' respective channel */ - OnlyStdoutChannel, + OnlyStdoutChannel =3D QProcess::ForwardedErrorChannel, /**< Only standard output is handled; standard error is forwarded = */ - OnlyStderrChannel /**< Only standard error is handled; standard o= utput is forwarded */ + OnlyStderrChannel =3D 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;