3 * \file SystemcallPrivate.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "SystemcallPrivate.h"
16 #include "Systemcall.h"
17 #include "ProgressInterface.h"
20 #include "qstring_helpers.h"
27 // TODO should we move qt_ to qstring_helpers?
29 QString const qt_(char const * str)
31 return toqstr(_(str));
36 SystemcallPrivate::SystemcallPrivate()
38 ProgressInterface* progress = Systemcall::progress();
40 connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(newProcessOutput()));
41 connect(&process, SIGNAL(started()), this, SLOT(processStarted()));
42 connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
43 connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)),
44 this, SLOT(processFinished(int, QProcess::ExitStatus)));
49 int SystemcallPrivate::start(const std::string& cmd, bool waitForFinished)
51 ProgressInterface* progress = Systemcall::progress();
53 progress->clearMessages();
54 progress->appendMessage(qt_("Starting LaTex with command "));
55 progress->appendMessage(cmd.c_str());
58 process.setReadChannel(QProcess::StandardOutput);
59 process.start(cmd.c_str(), QStringList(), QIODevice::ReadOnly);
60 // wait some seconds until the process has started
61 process.waitForStarted(10 * 1000);
62 if (waitForFinished) {
63 // with waitForFinished(-1); we only get one signal per run
64 while (process.state() == QProcess::Running)
65 process.waitForFinished(500);
66 return process.exitCode();
68 if (process.state() != QProcess::Running) {
70 // TODO this needs more testing
78 void SystemcallPrivate::newProcessOutput()
80 ProgressInterface* progress = Systemcall::progress();
82 const QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
83 progress->appendMessage(output);
88 void SystemcallPrivate::processStarted()
90 ProgressInterface* progress = Systemcall::progress();
92 progress->appendMessage(qt_("LaTex started\n"));
97 void SystemcallPrivate::processError(QProcess::ProcessError)
99 ProgressInterface* progress = Systemcall::progress();
101 progress->appendMessage(qt_("LaTex error\n"));
106 void SystemcallPrivate::processFinished(int, QProcess::ExitStatus)
112 } // namespace support
115 #include "SystemcallPrivate_moc.cpp"