X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FSystemcall.cpp;h=69692aaa529f7e62fe31b794532f427c368084d3;hb=11020c50f1e8bd71e7546c82d9ef7b2ec8ff4afb;hp=abb96bc9e54833ab8ca8ab8f68e8c7678831e635;hpb=1eb72710eb853c969a8fbea0b0303cfd3e819fbc;p=lyx.git diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index abb96bc9e5..69692aaa52 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -28,7 +28,7 @@ #include #include #include - +#include #define USE_QPROCESS @@ -99,16 +99,15 @@ string const parsecmd(string const & cmd, string & outfile) -int Systemcall::startscript(Starttype how, string const & what) +int Systemcall::startscript(Starttype how, string const & what, bool process_events) { string outfile; QString cmd = toqstr(parsecmd(what, outfile)); SystemcallPrivate d(outfile); - bool processEvents = false; d.startProcess(cmd); - if (!d.waitWhile(SystemcallPrivate::Starting, processEvents, 3000)) { + if (!d.waitWhile(SystemcallPrivate::Starting, process_events, 3000)) { LYXERR0("QProcess " << cmd << " did not start!"); LYXERR0("error " << d.errorMessage()); return 10; @@ -120,7 +119,7 @@ int Systemcall::startscript(Starttype how, string const & what) return 0; } - if (!d.waitWhile(SystemcallPrivate::Running, processEvents, 180000)) { + if (!d.waitWhile(SystemcallPrivate::Running, process_events, 180000)) { LYXERR0("QProcess " << cmd << " did not finished!"); LYXERR0("error " << d.errorMessage()); LYXERR0("status " << d.exitStatusMessage()); @@ -138,8 +137,8 @@ int Systemcall::startscript(Starttype how, string const & what) SystemcallPrivate::SystemcallPrivate(const std::string& of) : - proc_(new QProcess), outindex_(0), - errindex_(0), showout_(false), showerr_(false), outfile(of) + proc_(new QProcess), outindex_(0), errindex_(0), + outfile(of), showout_(false), showerr_(false), process_events(false) { if (!outfile.empty()) { // Check whether we have to simply throw away the output. @@ -168,21 +167,32 @@ void SystemcallPrivate::startProcess(const QString& cmd) } +void SystemcallPrivate::processEvents() +{ + if(process_events) { + //static int count = 0; qDebug() << count++ << ": waitAndProcessEvents"; + QCoreApplication::processEvents(QEventLoop::AllEvents); + } +} + + void SystemcallPrivate::waitAndProcessEvents() { Sleep::millisec(100); - QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + processEvents(); } -bool SystemcallPrivate::waitWhile(State waitwhile, bool processEvents, int timeout) +bool SystemcallPrivate::waitWhile(State waitwhile, bool proc_events, int timeout) { if (!proc_) return false; + process_events = proc_events; + // Block GUI while waiting, // relay on QProcess' wait functions - if (!processEvents) { + if (!process_events) { if (waitwhile == Starting) return proc_->waitForStarted(timeout); if (waitwhile == Running) @@ -208,7 +218,6 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool processEvents, int timeo } - SystemcallPrivate::~SystemcallPrivate() { flush(); @@ -245,6 +254,7 @@ void SystemcallPrivate::flush() } } + void SystemcallPrivate::stdOut() { if (proc_ && showout_) { @@ -259,6 +269,7 @@ void SystemcallPrivate::stdOut() } } } + processEvents(); } @@ -276,10 +287,25 @@ void SystemcallPrivate::stdErr() } } } + processEvents(); +} + + +void SystemcallPrivate::processStarted() +{ + state = Running; + // why do we get two started signals? + //disconnect(proc_, SIGNAL(started()), this, SLOT(processStarted())); +} + + +void SystemcallPrivate::processFinished(int, QProcess::ExitStatus) +{ + state = Finished; } -void SystemcallPrivate::processError(QProcess::ProcessError err) +void SystemcallPrivate::processError(QProcess::ProcessError) { state = Error; } @@ -319,20 +345,6 @@ QString SystemcallPrivate::errorMessage() const } -void SystemcallPrivate::processStarted() -{ - state = Running; - // why do we get two started signals? - //disconnect(proc_, SIGNAL(started()), this, SLOT(processStarted())); -} - - -void SystemcallPrivate::processFinished(int, QProcess::ExitStatus status) -{ - state = Finished; -} - - QString SystemcallPrivate::exitStatusMessage() const { if (!proc_) @@ -353,6 +365,7 @@ QString SystemcallPrivate::exitStatusMessage() const return message; } + int SystemcallPrivate::exitCode() { if (!proc_) @@ -375,6 +388,7 @@ void SystemcallPrivate::killProcess() killProcess(proc_); } + void SystemcallPrivate::killProcess(QProcess * p) { if (p) {