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.

Seems that at the time when the frontend folder was introduced
it wasn't clear that the toolkits also provide non-gui functionality.

Peter

Index: src/LaTeX.cpp
===================================================================
--- src/LaTeX.cpp       (revision 21078)
+++ src/LaTeX.cpp       (working copy)
@@ -427,9 +427,14 @@
 int LaTeX::startscript()
 {
        // onlyFilename() is needed for cygwin
-       string tmp = cmd + ' '
+       /*
+    string tmp0 = cmd + ' '
                     + quoteName(onlyFilename(file.toFilesystemEncoding()))
                     + " > " + os::nulldev();
+    */
+    string tmp = cmd + ' ' 
+             + "-max-print-line=200 "
+                    + quoteName((file.toFilesystemEncoding()));
        Systemcall one;
        return one.startscript(Systemcall::Wait, tmp);
 }
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 21078)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -28,6 +28,7 @@
 class QDropEvent;
 class QMenu;
 class QToolBar;
+class QTextEdit;
 
 namespace lyx {
 namespace frontend {
@@ -90,6 +91,8 @@
 
        QMenu* createPopupMenu();
 
+    static QTextEdit* progressWidget();
+
 Q_SIGNALS:
        void closing(int);
 
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp       (revision 21078)
+++ src/frontends/qt4/GuiView.cpp       (working copy)
@@ -22,6 +22,7 @@
 #include "GuiToolbar.h"
 #include "GuiToolbars.h"
 #include "qt_helpers.h"
+#include "CoreSystemProcess.h"
 
 #include "frontends/Application.h"
 #include "frontends/Dialogs.h"
@@ -32,6 +33,8 @@
 #include "support/convert.h"
 #include "support/lstrings.h"
 #include "support/os.h"
+#include "support/SystemCall.h"
+#include "support/systemprocess.h"
 
 #include "Buffer.h"
 #include "BufferParams.h"
@@ -65,6 +68,9 @@
 #include <QStatusBar>
 #include <QToolBar>
 #include <QUrl>
+#include <QDockWidget>
+#include <QTextEdit>
+#include <QVBoxLayout>
 
 #include <boost/current_function.hpp>
 
@@ -134,6 +140,7 @@
        TabWorkArea * tab_widget_;
        QStackedWidget * stack_widget_;
        BackgroundWidget * bg_widget_;
+    static QTextEdit * process_view_;
        /// view's menubar
        GuiMenubar * menubar_;
        /// view's toolbars
@@ -205,8 +212,8 @@
 
 
 unsigned int GuiViewBase::GuiViewPrivate::lastIconSize = 0;
+QTextEdit * GuiViewBase::GuiViewPrivate::process_view_ = 0;
 
-
 GuiViewBase::GuiViewBase(int id)
        : QMainWindow(), LyXView(id), quitting_by_menu_(false),
          d(*new GuiViewPrivate)
@@ -244,6 +251,19 @@
 
        // For Drag&Drop.
        setAcceptDrops(true);
+
+    // add progress view
+    d.process_view_ = new QTextEdit;
+    QVBoxLayout* vl = new QVBoxLayout;
+    vl->addWidget(d.process_view_);
+    QWidget* content = new QWidget;
+    content->setLayout(vl);
+    vl->setMargin(0);
+    QDockWidget *dock_widget = new QDockWidget(tr("Progress"), this);
+    dock_widget->setWidget(content);
+    addDockWidget(Qt::BottomDockWidgetArea, dock_widget);
+    lyx::support::Systemcall::registerProcessCreator(
+        &lyx::support::SystemProcess::creator<CoreSystemProcess>);
 }
 
 
@@ -255,6 +275,12 @@
 }
 
 
+QTextEdit* GuiViewBase::progressWidget()
+{
+    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 <QTextEdit>
+#include <QProcess>
+
+#include <string>
+
+
+namespace lyx {
+namespace frontend {
+
+
+class CoreSystemProcess : public QObject, public lyx::support::SystemProcess
+{
+       Q_OBJECT
+
+public:
+       CoreSystemProcess();
+
+    int start(const std::string& cmd, bool waitForFinished);
+
+public Q_SLOTS:
+       void newProcessOutput();
+    void processStarted();
+    void processError(QProcess::ProcessError);
+    void processFinished(int, QProcess::ExitStatus);
+       
+private:
+    QProcess process;
+    QTextEdit* view;
+};
+
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUIVIEW_H

Property changes on: src/frontends/qt4/CoreSystemProcess.h
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Index: src/frontends/qt4/CoreSystemProcess.cpp
===================================================================
--- src/frontends/qt4/CoreSystemProcess.cpp     (revision 0)
+++ src/frontends/qt4/CoreSystemProcess.cpp     (revision 0)
@@ -0,0 +1,97 @@
+/**
+ * \file GuiView.cpp
+ * 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.
+ */
+
+#include <config.h>
+
+#include "CoreSystemProcess.h"
+#include "GuiView.h"
+
+#include <QString>
+#include <QApplication>
+
+namespace lyx {
+namespace frontend {
+       
+
+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 {
+        // wait some seconds until the process has started
+        process.waitForStarted(10 * 1000);
+        if (process.state() != QProcess::Running) {
+            process.kill();
+            // TODO this needs more testing
+            deleteLater();
+            return -1;
+        }
+        return 0;
+    }
+}
+
+
+
+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();
+}
+
+       
+void CoreSystemProcess::processStarted()
+{
+       view->append("LaTex started\n");
+    QApplication::processEvents();
+}
+
+
+void CoreSystemProcess::processError(QProcess::ProcessError)
+{
+       view->append("LaTex error\n");
+    QApplication::processEvents();
+}
+
+
+void CoreSystemProcess::processFinished(int, QProcess::ExitStatus)
+{
+    deleteLater();
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "CoreSystemProcess_moc.cpp"

Property changes on: src/frontends/qt4/CoreSystemProcess.cpp
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

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())
+    {
+           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());
+    }
+    else
+    {
+        // process object must delete itself when 
+        // the process has finished 
+        SystemProcess* process = processCreator();
+        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;
+
 } // namespace support
 } // namespace lyx
Index: src/support/Systemcall.h
===================================================================
--- src/support/Systemcall.h    (revision 21078)
+++ src/support/Systemcall.h    (working copy)
@@ -12,11 +12,15 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef SYSTEMCALL_H
-#define SYSTEMCALL_H
+#ifndef LYX_SUPPORT_SYSTEMCALL_H
+#define LYX_SUPPORT_SYSTEMCALL_H
 
 #include <string>
 
+#include "support/SystemProcess.h"
+
+#include <boost/function.hpp>
+
 namespace lyx {
 namespace support {
 
@@ -43,6 +47,12 @@
         *  by spaces.
         */
        int startscript(Starttype how, std::string const & what);
+
+    static
+    void registerProcessCreator(const boost::function<SystemProcess*()>&);
+
+private:
+    static boost::function<SystemProcess*()> processCreator;
 };
 
 } // namespace support
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;
+    }
+
+    // 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()) {

Reply via email to