#include <QTime>
#include <QThread>
#include <QCoreApplication>
-
+#include <QDebug>
#define USE_QPROCESS
-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;
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());
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.
}
+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)
}
-
SystemcallPrivate::~SystemcallPrivate()
{
flush();
}
}
+
void SystemcallPrivate::stdOut()
{
if (proc_ && showout_) {
}
}
}
+ processEvents();
}
}
}
}
+ 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;
}
}
-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_)
return message;
}
+
int SystemcallPrivate::exitCode()
{
if (!proc_)
killProcess(proc_);
}
+
void SystemcallPrivate::killProcess(QProcess * p)
{
if (p) {