# HG changeset patch # User Jacob Dawid # Date 1302463643 -7200 # Node ID 6bdfa6012e77b1ff7a39171e615e3c2a16faff5a # Parent f31614496d866ac13fde44bf12aca58f609003c7 Removed concept of multiple terminals. diff -r f31614496d86 -r 6bdfa6012e77 gui//Quint.pro --- a/gui//Quint.pro Sat Apr 09 21:11:54 2011 +0200 +++ b/gui//Quint.pro Sun Apr 10 21:27:23 2011 +0200 @@ -35,11 +35,11 @@ src/Session.cpp \ src/ShellCommand.cpp \ src/QTerminalWidget.cpp \ - src/TerminalMdiSubWindow.cpp \ src/MainWindow.cpp \ src/Quint.cpp \ src/OctaveLink.cpp \ - src/ProcessInfo.cpp + src/ProcessInfo.cpp \ + src/OctaveTerminal.cpp HEADERS += \ src/TerminalCharacterDecoder.h \ @@ -69,13 +69,13 @@ src/Session.h \ src/ShellCommand.h \ src/QTerminalWidget.h \ - src/TerminalMdiSubWindow.h \ src/MainWindow.h \ src/OctaveLink.h \ src/konsole_export.h \ src/ProcessInfo.h \ src/kpty_export.h \ - src/kdecore_export.h + src/kdecore_export.h \ + src/OctaveTerminal.h INCFLAGS = -g3 $$system(mkoctfile -p INCFLAGS) LFLAGS = $$system(mkoctfile -p LFLAGS) \ @@ -83,4 +83,3 @@ $$system(mkoctfile -p LIBS) LIBS += $$LFLAGS -loctave -loctinterp -lreadline -lutil QMAKE_CXXFLAGS += $$INCFLAGS - diff -r f31614496d86 -r 6bdfa6012e77 gui//src/MainWindow.cpp --- a/gui//src/MainWindow.cpp Sat Apr 09 21:11:54 2011 +0200 +++ b/gui//src/MainWindow.cpp Sun Apr 10 21:27:23 2011 +0200 @@ -22,43 +22,20 @@ #include #include "MainWindow.h" -#include "TerminalMdiSubWindow.h" +#include "OctaveTerminal.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { constructWindow(); - - loadWebPage("Online Manual", "http://www.gnu.org/software/octave/doc/interpreter/"); showMaximized(); } MainWindow::~MainWindow() { } -void MainWindow::addTerminalWindow() { - TerminalMdiSubWindow *terminal = new TerminalMdiSubWindow(this); - m_mdiArea->addSubWindow(terminal); - terminal->show(); -} - -void MainWindow::loadWebPage(QString title, QString url) { - - QWebView *webView = new QWebView(); - webView->setWindowTitle(title); - webView->load(QUrl(url)); - m_mdiArea->addSubWindow(webView); +void MainWindow::constructWindow() { + m_octaveTerminal = new OctaveTerminal(this); + setWindowTitle("Quint"); + setCentralWidget(m_octaveTerminal); } - -void MainWindow::constructWindow() { - m_mdiArea = new QMdiArea(); - setWindowTitle("Quint"); - setCentralWidget(m_mdiArea); - - QMenu *viewsMenu = menuBar()->addMenu("Views"); - QAction *addOctaveTerminalAction = viewsMenu->addAction("Add Octave Terminal"); - - m_mdiArea->setViewMode(QMdiArea::SubWindowView); - - connect(addOctaveTerminalAction, SIGNAL(triggered()), this, SLOT(addTerminalWindow())); -} diff -r f31614496d86 -r 6bdfa6012e77 gui//src/MainWindow.h --- a/gui//src/MainWindow.h Sat Apr 09 21:11:54 2011 +0200 +++ b/gui//src/MainWindow.h Sun Apr 10 21:27:23 2011 +0200 @@ -20,8 +20,7 @@ #define MAINWINDOW_H #include -#include - +#include "OctaveTerminal.h" /** * \class MainWindow @@ -36,13 +35,9 @@ ~MainWindow(); public slots: - void addTerminalWindow(); - void loadWebPage(QString title, QString url); - private: void constructWindow(); - - QMdiArea *m_mdiArea; + OctaveTerminal *m_octaveTerminal; }; #endif // MAINWINDOW_H diff -r f31614496d86 -r 6bdfa6012e77 gui//src/OctaveTerminal.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui//src/OctaveTerminal.cpp Sun Apr 10 21:27:23 2011 +0200 @@ -0,0 +1,177 @@ +/* Quint - A graphical user interface for Octave + * Copyright (C) 2011 Jacob Dawid + * jacob.dawid@googlemail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "OctaveTerminal.h" +#include +#include +#include +#include + +OctaveTerminal::OctaveTerminal(QWidget *parent) + : QWidget(parent), + m_terminalWidget(0), + isRunning(true) { + constructWindow(); + establishOctaveLink(); +} + +OctaveTerminal::~OctaveTerminal() { + delete m_octaveLink; + isRunning = false; +} + +void OctaveTerminal::setStatus(QString message) { + m_statusBar->showMessage(message, 1000); +} + +void OctaveTerminal::establishOctaveLink() { + QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Establishing Octave link.."))); + m_octaveLink = new OctaveLink(); + pthread_create(&m_octaveThread, 0, OctaveTerminal::octaveMainWrapper, this); + pthread_create(&m_octaveCallbackThread, 0, OctaveTerminal::octaveCallback, this); + command_editor::add_event_hook(server_rl_event_hook_function); + + int fdm, fds; + if(openpty(&fdm, &fds, 0, 0, 0) < 0) { + assert(0); + } + dup2 (fds, 0); + dup2 (fds, 1); + dup2 (fds, 2); + m_terminalWidget->openTeletype(fdm); +} + +void OctaveTerminal::constructWindow() { + QVBoxLayout *vBoxLayout = new QVBoxLayout(); + + QWidget *hWidget = new QWidget(); + QHBoxLayout *hBoxLayout = new QHBoxLayout(); + + m_terminalWidget = new QTerminalWidget(0, hWidget); + m_terminalWidget->setScrollBarPosition(QTerminalWidget::ScrollBarRight); + m_terminalWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QWidget *hvWidget = new QWidget(); + QVBoxLayout *hvBoxLayout = new QVBoxLayout(); + m_variableView = new QTreeView(hWidget); + m_commandHistoryView = new QListView(hWidget); + m_commandHistoryView->setModel(new QStringListModel()); + hvWidget->setMaximumWidth(300); + hvBoxLayout->addWidget(new QLabel("Variables", hWidget)); + hvBoxLayout->addWidget(m_variableView); + hvBoxLayout->addWidget(new QLabel("Command History", hWidget)); + hvBoxLayout->addWidget(m_commandHistoryView); + hvBoxLayout->setMargin(1); + hvWidget->setLayout(hvBoxLayout); + + hBoxLayout->addWidget(m_terminalWidget); + hBoxLayout->addWidget(hvWidget); + hBoxLayout->setMargin(2); + hWidget->setLayout(hBoxLayout); + + m_statusBar = new QStatusBar(); + + vBoxLayout->addWidget(hWidget); + vBoxLayout->addWidget(m_statusBar); + vBoxLayout->setMargin(2); + setLayout(vBoxLayout); +} + +void OctaveTerminal::updateHistory(string_vector historyEntries) { + QStringListModel * model = dynamic_cast(m_commandHistoryView->model()); + if(!model) + return; + QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating history.."))); + QStringList stringList = model->stringList(); + for(size_t i = 0; i < historyEntries.length(); i++) { + QString command(historyEntries[i].c_str()); + if(!command.startsWith("#")) + stringList.push_front(QString("%1: ").arg(stringList.size() + 1) + command); + } + model->setStringList(stringList); +} + +void OctaveTerminal::updateVariables(std::vector variables) { + QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating variables.."))); + // TODO: Update variable view. +} + +void* OctaveTerminal::octaveMainWrapper(void *widget) { + //MainWindow *mainWindow = (MainWindow*)ptr; + + int argc = 3; + const char* argv[] = {"octave", "--interactive", "--line-editing"}; + octave_main(argc, (char**)argv,1); + switch_to_buffer(create_buffer(get_input_from_stdin())); + main_loop(); + clean_up_and_exit(0); + return 0; +} + +void* OctaveTerminal::octaveCallback(void *widget) { + OctaveTerminal* terminalWindow = (OctaveTerminal*)widget; + + while(terminalWindow->isRunning) { + + // Get a full variable list. + std::vector variables = oct_octave_server.variableInfoList(); + if(variables.size()) + terminalWindow->updateVariables(variables); + + // Check whether any requested variables have been returned. + std::vector reqVars = oct_octave_server.requestedVariables(); + for(std::vector::iterator it = reqVars.begin(); + it != reqVars.end(); it++ ) { + // TODO: Process requested variables. + } + + // Collect history list. + string_vector historyList = oct_octave_server.getHistoryList(); + if(historyList.length()) { + terminalWindow->updateHistory(historyList); + } + + // Put a marker in each buffer at the proper location. + int status = 0; + std::vector breakPoints = oct_octave_server.breakPointList(status); + if(status==0) { + //MEditor::GetInstance()->process_breakpoint_list (bps); + } + + // Find out if a breakpoint is hit + static bool lineNumber = -1; + bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); + if((status==0) && hitBreakPoint) { + std::vector hit_breakpoint = oct_octave_server.reachedBreakpoint(); + + if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); + lineNumber = hit_breakpoint[0].lineNumber; + } + } + else if((status==0) && lineNumber>0) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + lineNumber = -1; + } + + usleep(100000); + } + + return 0; +} diff -r f31614496d86 -r 6bdfa6012e77 gui//src/OctaveTerminal.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui//src/OctaveTerminal.h Sun Apr 10 21:27:23 2011 +0200 @@ -0,0 +1,100 @@ +/* Quint - A graphical user interface for Octave + * Copyright (C) 2011 Jacob Dawid + * jacob.dawid@googlemail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TERMINALMDISUBWINDOW_H +#define TERMINALMDISUBWINDOW_H + +#include +#include +#include +#include +#include "QTerminalWidget.h" +#include "OctaveLink.h" + +// Octave includes +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#undef PACKAGE_URL +#include "octave/config.h" + +#include "octave/debug.h" +#include "octave/octave.h" +#include "octave/symtab.h" +#include "octave/parse.h" +#include "octave/unwind-prot.h" +#include "octave/toplev.h" +#include "octave/load-path.h" +#include "octave/error.h" +#include "octave/quit.h" +#include "octave/variables.h" +#include "octave/sighandlers.h" +#include "octave/sysdep.h" +#include "octave/str-vec.h" +#include "octave/cmd-hist.h" +#include "octave/cmd-edit.h" +#include "octave/oct-env.h" +#include "octave/symtab.h" +#include "cmd-edit.h" + +typedef struct yy_buffer_state *YY_BUFFER_STATE; +extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); +extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); +extern OCTINTERP_API FILE *get_input_from_stdin (void); + +// System +#include +#include +#include +#include +#include +#include +#include +#include "pty.h" + +class OctaveTerminal : public QWidget { + Q_OBJECT +public: + static void* octaveMainWrapper(void *widget); + static void* octaveCallback(void *widget); + + void updateHistory(string_vector historyEntries); + void updateVariables(std::vector variables); + OctaveTerminal(QWidget *parent = 0); + ~OctaveTerminal(); + +public slots: + void setStatus(QString message); + +private: + void establishOctaveLink(); + void constructWindow(); + QTerminalWidget *m_terminalWidget; + QTreeView *m_variableView; + QListView *m_commandHistoryView; + QStatusBar *m_statusBar; + OctaveLink *m_octaveLink; + + // Threads for running octave and managing the data interaction. + pthread_t m_octaveThread; + pthread_t m_octaveCallbackThread; + bool isRunning; +}; +#endif // TERMINALMDISUBWINDOW_H diff -r f31614496d86 -r 6bdfa6012e77 gui//src/TerminalMdiSubWindow.cpp --- a/gui//src/TerminalMdiSubWindow.cpp Sat Apr 09 21:11:54 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -/* Quint - A graphical user interface for Octave - * Copyright (C) 2011 Jacob Dawid - * jacob.dawid@googlemail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "TerminalMdiSubWindow.h" -#include -#include -#include -#include - -TerminalMdiSubWindow::TerminalMdiSubWindow(QWidget *parent) - : QMdiSubWindow(parent), - m_terminalWidget(0), - isRunning(true) { - constructWindow(); - establishOctaveLink(); -} - -TerminalMdiSubWindow::~TerminalMdiSubWindow() { - delete m_octaveLink; - isRunning = false; -} - -void TerminalMdiSubWindow::setStatus(QString message) { - m_statusBar->showMessage(message, 1000); -} - -void TerminalMdiSubWindow::establishOctaveLink() { - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Establishing Octave link.."))); - m_octaveLink = new OctaveLink(); - pthread_create(&m_octaveThread, 0, TerminalMdiSubWindow::octaveMainWrapper, this); - pthread_create(&m_octaveCallbackThread, 0, TerminalMdiSubWindow::octaveCallback, this); - command_editor::add_event_hook(server_rl_event_hook_function); - - int fdm, fds; - if(openpty(&fdm, &fds, 0, 0, 0) < 0) { - assert(0); - } - dup2 (fds, 0); - dup2 (fds, 1); - dup2 (fds, 2); - m_terminalWidget->openTeletype(fdm); -} - -void TerminalMdiSubWindow::constructWindow() { - setWindowTitle("Octave Session"); - resize(900, 600); - setWidget(new QWidget(this)); - - QVBoxLayout *vBoxLayout = new QVBoxLayout(); - - QWidget *hWidget = new QWidget(); - QHBoxLayout *hBoxLayout = new QHBoxLayout(); - - m_terminalWidget = new QTerminalWidget(0, hWidget); - m_terminalWidget->setScrollBarPosition(QTerminalWidget::ScrollBarRight); - m_terminalWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QWidget *hvWidget = new QWidget(); - QVBoxLayout *hvBoxLayout = new QVBoxLayout(); - m_variableView = new QTreeView(hWidget); - m_commandHistoryView = new QListView(hWidget); - m_commandHistoryView->setModel(new QStringListModel()); - hvWidget->setMaximumWidth(300); - hvBoxLayout->addWidget(new QLabel("Variables", hWidget)); - hvBoxLayout->addWidget(m_variableView); - hvBoxLayout->addWidget(new QLabel("Command History", hWidget)); - hvBoxLayout->addWidget(m_commandHistoryView); - hvBoxLayout->setMargin(1); - hvWidget->setLayout(hvBoxLayout); - - hBoxLayout->addWidget(m_terminalWidget); - hBoxLayout->addWidget(hvWidget); - hBoxLayout->setMargin(2); - hWidget->setLayout(hBoxLayout); - - m_statusBar = new QStatusBar(); - - vBoxLayout->addWidget(hWidget); - vBoxLayout->addWidget(m_statusBar); - vBoxLayout->setMargin(2); - widget()->setLayout(vBoxLayout); -} - -void TerminalMdiSubWindow::updateHistory(string_vector historyEntries) { - QStringListModel * model = dynamic_cast(m_commandHistoryView->model()); - if(!model) - return; - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating history.."))); - QStringList stringList = model->stringList(); - for(size_t i = 0; i < historyEntries.length(); i++) { - QString command(historyEntries[i].c_str()); - if(!command.startsWith("#")) - stringList.push_front(QString("%1: ").arg(stringList.size() + 1) + command); - } - model->setStringList(stringList); -} - -void TerminalMdiSubWindow::updateVariables(std::vector variables) { - QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Updating variables.."))); - // TODO: Update variable view. -} - -void* TerminalMdiSubWindow::octaveMainWrapper(void *widget) { - //MainWindow *mainWindow = (MainWindow*)ptr; - - int argc = 3; - const char* argv[] = {"octave", "--interactive", "--line-editing"}; - octave_main(argc, (char**)argv,1); - switch_to_buffer(create_buffer(get_input_from_stdin())); - main_loop(); - clean_up_and_exit(0); - return 0; -} - -void* TerminalMdiSubWindow::octaveCallback(void *widget) { - TerminalMdiSubWindow* terminalWindow = (TerminalMdiSubWindow*)widget; - - while(terminalWindow->isRunning) { - - // Get a full variable list. - std::vector variables = oct_octave_server.variableInfoList(); - if(variables.size()) - terminalWindow->updateVariables(variables); - - // Check whether any requested variables have been returned. - std::vector reqVars = oct_octave_server.requestedVariables(); - for(std::vector::iterator it = reqVars.begin(); - it != reqVars.end(); it++ ) { - // TODO: Process requested variables. - } - - // Collect history list. - string_vector historyList = oct_octave_server.getHistoryList(); - if(historyList.length()) { - terminalWindow->updateHistory(historyList); - } - - // Put a marker in each buffer at the proper location. - int status = 0; - std::vector breakPoints = oct_octave_server.breakPointList(status); - if(status==0) { - //MEditor::GetInstance()->process_breakpoint_list (bps); - } - - // Find out if a breakpoint is hit - static bool lineNumber = -1; - bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); - if((status==0) && hitBreakPoint) { - std::vector hit_breakpoint = oct_octave_server.reachedBreakpoint(); - - if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); - lineNumber = hit_breakpoint[0].lineNumber; - } - } - else if((status==0) && lineNumber>0) { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - lineNumber = -1; - } - - usleep(100000); - } - - return 0; -} diff -r f31614496d86 -r 6bdfa6012e77 gui//src/TerminalMdiSubWindow.h --- a/gui//src/TerminalMdiSubWindow.h Sat Apr 09 21:11:54 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/* Quint - A graphical user interface for Octave - * Copyright (C) 2011 Jacob Dawid - * jacob.dawid@googlemail.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef TERMINALMDISUBWINDOW_H -#define TERMINALMDISUBWINDOW_H - -#include -#include -#include -#include -#include "QTerminalWidget.h" -#include "OctaveLink.h" - -// Octave includes -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#undef PACKAGE_URL -#include "octave/config.h" - -#include "octave/debug.h" -#include "octave/octave.h" -#include "octave/symtab.h" -#include "octave/parse.h" -#include "octave/unwind-prot.h" -#include "octave/toplev.h" -#include "octave/load-path.h" -#include "octave/error.h" -#include "octave/quit.h" -#include "octave/variables.h" -#include "octave/sighandlers.h" -#include "octave/sysdep.h" -#include "octave/str-vec.h" -#include "octave/cmd-hist.h" -#include "octave/cmd-edit.h" -#include "octave/oct-env.h" -#include "octave/symtab.h" -#include "cmd-edit.h" - -typedef struct yy_buffer_state *YY_BUFFER_STATE; -extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); -extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); -extern OCTINTERP_API FILE *get_input_from_stdin (void); - -// System -#include -#include -#include -#include -#include -#include -#include -#include "pty.h" - -class TerminalMdiSubWindow : public QMdiSubWindow { - Q_OBJECT -public: - static void* octaveMainWrapper(void *widget); - static void* octaveCallback(void *widget); - - void updateHistory(string_vector historyEntries); - void updateVariables(std::vector variables); - TerminalMdiSubWindow(QWidget *parent = 0); - ~TerminalMdiSubWindow(); - -public slots: - void setStatus(QString message); - -private: - void establishOctaveLink(); - void constructWindow(); - QTerminalWidget *m_terminalWidget; - QTreeView *m_variableView; - QListView *m_commandHistoryView; - QStatusBar *m_statusBar; - OctaveLink *m_octaveLink; - - // Threads for running octave and managing the data interaction. - pthread_t m_octaveThread; - pthread_t m_octaveCallbackThread; - bool isRunning; -}; -#endif // TERMINALMDISUBWINDOW_H