X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FSystemcall.cpp;h=ca804096603eb81b7f35732fe6bac5e6ac8820ab;hb=12554c93d81f75f87c34040fd7737048d3518d6d;hp=4273983bd2c458229a529e13424cb86f22bc8e4c;hpb=29627f1680755510f116b36efd951b518234a878;p=lyx.git diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 4273983bd2..ca80409660 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -15,6 +15,7 @@ #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" @@ -72,6 +73,8 @@ public: 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; } }; @@ -237,12 +240,12 @@ string const parsecmd(string const & incmd, string & infile, string & outfile, 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); @@ -358,7 +361,7 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path) void SystemcallPrivate::processEvents() { - if(process_events_) { + if (process_events_) { QCoreApplication::processEvents(/*QEventLoop::ExcludeUserInputEvents*/); } } @@ -371,11 +374,26 @@ void SystemcallPrivate::waitAndProcessEvents() } +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, @@ -383,8 +401,24 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time 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; } @@ -396,13 +430,24 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time 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; }