On Sat, Oct 20, 2007 at 01:09:20PM +0200, Peter Kümmel wrote: > Here an idea how to add a latex output widget > to the GUI (atm not fully integrated). > > With this as starting point it should be possible to > create a progress bar and a button to kill the latex job. > > It uses QProcess which is in principle not a GUI element, > but because I don't wanna call moc in support I've added > it to qt4. > > In the long run also support should have toolkit sub folders > as frontends has: > > |--frontends > |--qt4 (links against QtGui, QtCore,...) > |--gtk > > |--support > |--qt4 (links against QtCore/Xml/Network only) > |--gtk > n |--boost (?) > > then we don't have to reinvent the wheel in support.
As far as I can tell using QtCore in support/*.cpp is acceptable nowadays, so just use QProcess and be done. We can think about a split in support as soon as we have a non-Qt frontend _and_ do not want to link against Qt anymore. No need to be pro-active here. [We currently do somethign weird for alerts, though...] > +QTextEdit* GuiViewBase::progressWidget() const? > +{ > + return GuiViewPrivate::process_view_; > +} > + > + > void GuiViewBase::close() > { > quitting_by_menu_ = true; > Index: src/frontends/qt4/CoreSystemProcess.h > =================================================================== > --- src/frontends/qt4/CoreSystemProcess.h (revision 0) > +++ src/frontends/qt4/CoreSystemProcess.h (revision 0) > @@ -0,0 +1,51 @@ > +// -*- C++ -*- > +/** > + * \file GuiView.h > + * This file is part of LyX, the document processor. > + * Licence details can be found in the file COPYING. > + * > + * \author Peter K?mmel > + * > + * Full author contact details are available in file CREDITS. > + */ > + > +#ifndef CORE_PROCESS_VIEW_H > +#define CORE_PROCESS_VIEW_H > + > +#include <support/systemprocess.h> #include "..." > +namespace lyx { > +namespace frontend { > + > + > +class CoreSystemProcess : public QObject, public lyx::support::SystemProcess No need for 'lyx::' if you are inside the namespace > Property changes on: src/frontends/qt4/CoreSystemProcess.h > ___________________________________________________________________ > Name: svn:executable > + * ? > Name: svn:eol-style > +CoreSystemProcess::CoreSystemProcess() : view (0) > +{ > + view = GuiViewBase::progressWidget(); > + if (view) { > + connect(&process, SIGNAL(readyRead()), this, > SLOT(newProcessOutput())); > + connect(&process, SIGNAL(started()), this, SLOT(processStarted())); > + connect(&process, SIGNAL(error(QProcess::ProcessError)), this, > SLOT(processError(QProcess::ProcessError))); > + connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), > + this, SLOT(processFinished(int, QProcess::ExitStatus))); > > + } > +} > + > + > +int CoreSystemProcess::start(const std::string& cmd, bool waitForFinished) > +{ > + if (view) { > + view->clear(); > + view->append("starting LaTex with command"); > + view->append(cmd.c_str()); > + } > + > + process.setReadChannel(QProcess::StandardOutput); > + process.start(cmd.c_str(), QStringList(), QIODevice::ReadOnly); > + if (waitForFinished) { > + // no timeout > + process.waitForFinished(-1); > + return process.exitCode(); > + } else { No need for 'else' after 'return' > +void CoreSystemProcess::newProcessOutput() > +{ > + const QString output = > QString::fromLocal8Bit(process.readAllStandardOutput()); > + // parse output for page number, etc., could be used for a progress bar > + view->append(output); > + QApplication::processEvents(); > +} Have you checked QApplication::processEvents() is needed? > +void CoreSystemProcess::processStarted() > +{ > + view->append("LaTex started\n"); > + QApplication::processEvents(); > +} There's also something wrong with spacing in the last four functions. > > Index: src/support/Systemcall.cpp > =================================================================== > --- src/support/Systemcall.cpp (revision 21078) > +++ src/support/Systemcall.cpp (working copy) > @@ -32,19 +32,40 @@ > { > string command = what; > > - if (how == DontWait) { > - switch (os::shell()) { > - case os::UNIX: > - command += " &"; > - break; > - case os::CMD_EXE: > - command = "start /min " + command; > - break; > - } > - } > + if (processCreator.empty()) > + { Brace on line with 'if'. > + if (how == DontWait) { > + switch (os::shell()) { > + case os::UNIX: > + command += " &"; > + break; > + case os::CMD_EXE: > + command = "start /min " + command; > + break; > + } > + } > + return ::system(command.c_str()); > + } If we use QProcess, why not for synchronous executiom, too? Calling 'system' is a mess when it comes to proper quoting of arguments, expecially on WIndows. > + else > + { Brace. > + // process object must delete itself when > + // the process has finished > + SystemProcess* process = processCreator(); Space before *. > + if (how == Wait) { > + return process->start(command, true); > + } else { > + return process->start(command, false); > + } > + } > +} > > - return ::system(command.c_str()); > + > +void Systemcall::registerProcessCreator(const > boost::function<SystemProcess*()>& func) > +{ > + processCreator = func; > } > > +boost::function<SystemProcess*()> Systemcall::processCreator; > + Why do why need boost::function? > Index: src/support/SystemProcess.h > =================================================================== > --- src/support/SystemProcess.h (revision 0) > +++ src/support/SystemProcess.h (revision 0) > @@ -0,0 +1,43 @@ > +// -*- C++ -*- > +/** > + * \file GuiView.h > + * This file is part of LyX, the document processor. > + * Licence details can be found in the file COPYING. > + * > + * \author Peter K?mmel > + * > + * Full author contact details are available in file CREDITS. > + */ > + > +#ifndef LYX_SUPPORT_SYSTEMPROCESS_H > +#define LYX_SUPPORT_SYSTEMPROCESS_H > + > + > +namespace lyx { > +namespace support { > + > + > +class SystemProcess > +{ > +public: > + virtual ~SystemProcess(){} > + > + // creator template > + template<class T> > + static SystemProcess* creator() { > + return new T; > + } Hm? > + > + // waitForFinished == true: returns the exit code of the process > + // waitForFinished == false: returns 0 if the process could bestarted > + virtual int start(const std::string& cmd, bool waitForFinished) = 0; > + > +protected: > + SystemProcess(){} > +}; > + > + > +} // namespace support > +} // namespace lyx > + > +#endif // LYX_SUPPORT_PROCESS_H > > Property changes on: src/support/SystemProcess.h > ___________________________________________________________________ > Name: svn:executable > + * > Name: svn:eol-style > + native > > Index: src/Buffer.cpp > =================================================================== > --- src/Buffer.cpp (revision 21078) > +++ src/Buffer.cpp (working copy) > @@ -1094,8 +1094,7 @@ > if (output_preamble) { > if (!runparams.nice) { > // code for usual, NOT nice-latex-file > - os << "\\batchmode\n"; // changed > - // from \nonstopmode > + os << "\\nonstopmode\n"; > texrow().newline(); > } > if (!original_path.empty()) {