#include "support/debug.h"
#include "support/filetools.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/Systemcall.h"
void toggleWarning(QString const &, QString const &, QString const &) {}
void error(QString const &, QString const &) {}
void information(QString const &, QString const &) {}
+ int prompt(docstring const &, docstring const &, int default_but, int,
+ docstring const &, docstring const &) { return default_but; }
};
int Systemcall::startscript(Starttype how, string const & what,
string const & path, bool process_events)
{
- lyxerr << "\nRunning: " << what << endl;
+ LYXERR(Debug::INFO,"Running: " << what);
string infile;
string outfile;
string errfile;
- QString cmd = QString::fromLocal8Bit(
+ QString const cmd = QString::fromLocal8Bit(
parsecmd(what, infile, outfile, errfile).c_str());
SystemcallPrivate d(infile, outfile, errfile);
void SystemcallPrivate::processEvents()
{
- if(process_events_) {
+ if (process_events_) {
QCoreApplication::processEvents(/*QEventLoop::ExcludeUserInputEvents*/);
}
}
}
+namespace {
+
+bool queryStopCommand(QString const & cmd)
+{
+ docstring text = bformat(_(
+ "The command\n%1$s\nhas not yet completed.\n\n"
+ "Do you want to stop it?"), qstring_to_ucs4(cmd));
+ return ProgressInterface::instance()->prompt(_("Stop command?"), text,
+ 1, 1, _("&Stop it"), _("Let it &run")) == 0;
+}
+
+}
+
+
bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int timeout)
{
if (!process_)
return false;
+ bool timedout = false;
process_events_ = process_events;
// Block GUI while waiting,
if (!process_events_) {
if (waitwhile == Starting)
return process_->waitForStarted(timeout);
- if (waitwhile == Running)
- return process_->waitForFinished(timeout);
+ if (waitwhile == Running) {
+ int bump = 2;
+ while (!timedout) {
+ if (process_->waitForFinished(timeout))
+ return true;
+ bool stop = queryStopCommand(cmd_);
+ // The command may have finished in the meantime
+ if (process_->state() == QProcess::NotRunning)
+ return true;
+ if (stop) {
+ timedout = true;
+ process_->kill();
+ } else {
+ timeout *= bump;
+ bump = 3;
+ }
+ }
+ }
return false;
}
return state != Error;
}
- // process events while waiting whith timeout
+ // process events while waiting with timeout
QTime timer;
timer.start();
- while (state == waitwhile && state != Error && timer.elapsed() < timeout) {
+ while (state == waitwhile && state != Error && !timedout) {
waitAndProcessEvents();
+ if (timer.elapsed() > timeout) {
+ bool stop = queryStopCommand(cmd_);
+ // The command may have finished in the meantime
+ if (process_->state() == QProcess::NotRunning)
+ break;
+ if (stop) {
+ timedout = true;
+ process_->kill();
+ } else
+ timeout *= 3;
+ }
}
- return (state != Error) && (timer.elapsed() < timeout);
+ return (state != Error) && !timedout;
}