]> git.lyx.org Git - lyx.git/commitdiff
more cleanup without behavior changes
authorPeter Kümmel <syntheticpp@gmx.net>
Fri, 4 Dec 2009 10:11:06 +0000 (10:11 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Fri, 4 Dec 2009 10:11:06 +0000 (10:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32324 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Systemcall.cpp
src/support/SystemcallPrivate.h

index 499994b34c57ef4f11c023b9c511b24699f1087e..054be5f949e529cec1c8c667eeb8e427e46f91be 100644 (file)
@@ -48,17 +48,6 @@ using namespace std;
 namespace lyx {
 namespace support {
 
-static void killProcess(QProcess * p)
-{
-       p->disconnect();
-       p->closeReadChannel(QProcess::StandardOutput);
-       p->closeReadChannel(QProcess::StandardError);
-       p->close();
-       delete p;
-}
-
-
-
 
 
 // Reuse of instance
@@ -114,19 +103,10 @@ int Systemcall::startscript(Starttype how, string const & what)
 {
        string outfile;
        QString cmd = toqstr(parsecmd(what, outfile));
-       QProcess * process = new QProcess;
-       SystemcallPrivate d(process);
-       if (!outfile.empty()) {
-               // Check whether we have to simply throw away the output.
-               if (outfile != os::nulldev())
-                       process->setStandardOutputFile(toqstr(outfile));
-       } else if (os::is_terminal(os::STDOUT))
-               d.showout();
-       if (os::is_terminal(os::STDERR))
-               d.showerr();
-       
+       SystemcallPrivate d(outfile);
 
        bool processEvents = false;
+
        d.startProcess(cmd);
        if (!d.waitWhile(SystemcallPrivate::Starting, processEvents, 3000)) {
                LYXERR0("QProcess " << cmd << " did not start!");
@@ -146,36 +126,37 @@ int Systemcall::startscript(Starttype how, string const & what)
                return 20;
        }
 
-       int const exit_code = process->exitCode();
+       int const exit_code = d.exitCode();
        if (exit_code) {
                LYXERR0("QProcess " << cmd << " finished!");
                LYXERR0("error " << exit_code << ": " << d.errorMessage()); 
        }
 
-       // If the output has been redirected, we write it all at once.
-       // Even if we are not running in a terminal, the output could go
-       // to some log file, for example ~/.xsession-errors on *nix.
-       if (!os::is_terminal(os::STDOUT) && outfile.empty())
-               cout << fromqstr(QString::fromLocal8Bit(
-                           process->readAllStandardOutput().data()));
-       if (!os::is_terminal(os::STDERR))
-               cerr << fromqstr(QString::fromLocal8Bit(
-                           process->readAllStandardError().data()));
-
-       killProcess(process);
+       d.flush();
+       d.killProcess();
 
        return exit_code;
 }
 
 
-SystemcallPrivate::SystemcallPrivate(QProcess * proc) : proc_(proc), outindex_(0), 
-                               errindex_(0), showout_(false), showerr_(false)
+SystemcallPrivate::SystemcallPrivate(const std::string& of) : 
+                               proc_(new QProcess), outindex_(0), 
+                               errindex_(0), showout_(false), showerr_(false), outfile(of)
 {
-       connect(proc, SIGNAL(readyReadStandardOutput()), SLOT(stdOut()));
-       connect(proc, SIGNAL(readyReadStandardError()), SLOT(stdErr()));
-       connect(proc, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
-       connect(proc, SIGNAL(started()), this, SLOT(processStarted()));
-       connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(processFinished(int, QProcess::ExitStatus)));
+       if (!outfile.empty()) {
+               // Check whether we have to simply throw away the output.
+               if (outfile != os::nulldev())
+                       proc_->setStandardOutputFile(toqstr(outfile));
+       } else if (os::is_terminal(os::STDOUT))
+               showout();
+       if (os::is_terminal(os::STDERR))
+               showerr();
+
+       connect(proc_, SIGNAL(readyReadStandardOutput()), SLOT(stdOut()));
+       connect(proc_, SIGNAL(readyReadStandardError()), SLOT(stdErr()));
+       connect(proc_, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
+       connect(proc_, SIGNAL(started()), this, SLOT(processStarted()));
+       connect(proc_, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(processFinished(int, QProcess::ExitStatus)));
 }
 
 
@@ -224,6 +205,7 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool processEvents, int timeo
 }
 
 
+
 SystemcallPrivate::~SystemcallPrivate()
 {
        if (outindex_) {
@@ -241,6 +223,19 @@ SystemcallPrivate::~SystemcallPrivate()
 }
 
 
+void SystemcallPrivate::flush()
+{
+       // If the output has been redirected, we write it all at once.
+       // Even if we are not running in a terminal, the output could go
+       // to some log file, for example ~/.xsession-errors on *nix.
+       if (!os::is_terminal(os::STDOUT) && outfile.empty())
+               cout << fromqstr(QString::fromLocal8Bit(
+                           proc_->readAllStandardOutput().data()));
+       if (!os::is_terminal(os::STDERR))
+               cerr << fromqstr(QString::fromLocal8Bit(
+                           proc_->readAllStandardError().data()));
+}
+
 void SystemcallPrivate::stdOut()
 {
        if (showout_) {
@@ -343,6 +338,27 @@ QString SystemcallPrivate::exitStatusMessage() const
        return message;
 }
 
+int SystemcallPrivate::exitCode()
+{
+       return proc_->exitCode();
+}
+
+
+void SystemcallPrivate::killProcess()
+{
+       killProcess(proc_);
+}
+
+void SystemcallPrivate::killProcess(QProcess * p)
+{
+       p->disconnect();
+       p->closeReadChannel(QProcess::StandardOutput);
+       p->closeReadChannel(QProcess::StandardError);
+       p->close();
+       delete p;
+}
+
+
 
 #include "moc_SystemcallPrivate.cpp"
 #endif
index 5e00f9846c337d7ebb167be75c4abe3e4fb8917f..a7c25639006c4a5317c8d1a4a9b17e4d9b4c5f54 100644 (file)
@@ -30,7 +30,7 @@ class SystemcallPrivate : public QObject
 {
        Q_OBJECT
 public:
-       SystemcallPrivate(QProcess * proc);
+       SystemcallPrivate(const std::string& outfile);
        ~SystemcallPrivate();
 
        /// Should the standard output be displayed?
@@ -50,10 +50,14 @@ public:
        bool waitWhile(State, bool processEvents, int timeout = -1);
        void startProcess(const QString& cmd);
        
+       int exitCode();
+
        QString errorMessage() const;
        QString exitStatusMessage() const;
 
-
+       void flush();
+       void killProcess();
+       static void killProcess(QProcess * p);
 
 private:
        /// Pointer to the process to monitor.
@@ -62,6 +66,8 @@ private:
        size_t outindex_;
        /// Index to the standard error buffer.
        size_t errindex_;
+       ///
+       std::string outfile;
        /// Size of buffers.
        static size_t const bufsize_ = 200;
        /// Standard output buffer.