From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- lib/util/blockingkprocess.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 lib/util/blockingkprocess.cpp (limited to 'lib/util/blockingkprocess.cpp') diff --git a/lib/util/blockingkprocess.cpp b/lib/util/blockingkprocess.cpp new file mode 100644 index 00000000..f0d6e6c3 --- /dev/null +++ b/lib/util/blockingkprocess.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** +* Copyright (C) 2006 by Andras Mantia * +* amantia@kde.org * +* * +* 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. * +* * +***************************************************************************/ + +#include "blockingkprocess.h" + +#include +#include + +BlockingKProcess::BlockingKProcess(QObject *parent, const char *name) + : KProcess(parent, name) +{ + m_stdOut = ""; + m_stdErr = ""; + m_timeoutValue = 60; + m_timer = 0L; + + connect(this, SIGNAL(receivedStdout(KProcess *, char *, int)), + this, SLOT(slotReceivedStdOut(KProcess *, char *, int))); + connect(this, SIGNAL(receivedStderr(KProcess *, char *, int)), + this, SLOT(slotReceivedStdErr(KProcess *, char *, int))); + connect(this, SIGNAL(processExited(KProcess *)), + this, SLOT(slotProcessExited(KProcess *))); +} + +BlockingKProcess::BlockingKProcess() + : KProcess() +{ + m_stdOut = ""; + m_stdErr = ""; + m_timeoutValue = 60; + m_timer = 0L; + connect(this, SIGNAL(receivedStdout(KProcess *, char *, int)), + this, SLOT(slotReceivedStdOut(KProcess *, char *, int))); + connect(this, SIGNAL(receivedStderr(KProcess *, char *, int)), + this, SLOT(slotReceivedStdErr(KProcess *, char *, int))); + connect(this, SIGNAL(processExited(KProcess *)), + this, SLOT(slotProcessExited(KProcess *))); +} + + +BlockingKProcess::~BlockingKProcess() +{ +} +bool BlockingKProcess::start(RunMode runmode, Communication comm) +{ + if (KProcess::start(runmode, comm)) + { + m_timeout = false; + m_timer = new QTimer(); + connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeOut())); + m_timer->start(m_timeoutValue*1000, true); + enter_loop(); + delete m_timer; + m_timer = 0L; + return !m_timeout; + } else + return false; +} + + +void BlockingKProcess::slotReceivedStdOut(KProcess *, char *buffer, int buflen) +{ + m_stdOut += QString::fromLatin1(buffer, buflen); +} + +void BlockingKProcess::slotReceivedStdErr(KProcess *, char *buffer, int buflen) +{ + m_stdErr += QString::fromLatin1(buffer, buflen); +} + +void BlockingKProcess::slotProcessExited(KProcess *) +{ + qApp->exit_loop(); +} + +void BlockingKProcess::slotTimeOut() +{ + m_timeout = true; + kill(); + qApp->exit_loop(); +} + + +void qt_enter_modal( QWidget *widget ); +void qt_leave_modal( QWidget *widget ); + +void BlockingKProcess::enter_loop() +{ + QWidget dummy(0,0,WType_Dialog | WShowModal); + dummy.setFocusPolicy( QWidget::NoFocus ); + qt_enter_modal(&dummy); + qApp->enter_loop(); + qt_leave_modal(&dummy); +} + + +#include "blockingkprocess.moc" -- cgit v1.2.1