Mercurial > hg > octave-lyh
changeset 13353:9562e5252fa6
Removed piped terminal windows.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 07 Apr 2011 11:15:19 +0200 |
parents | 5329898fbe05 |
children | ffe3534fcffd |
files | gui//Quint.pro gui//client.cpp gui//client.h gui//clientmanager.cpp gui//clientmanager.h gui//mainwindow.cpp gui//octaveterminal.cpp gui//octaveterminal.h gui//terminal.cpp gui//terminalhighlighter.cpp gui//terminalhighlighter.h |
diffstat | 11 files changed, 5 insertions(+), 658 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//Quint.pro +++ b/gui//Quint.pro @@ -12,18 +12,10 @@ SOURCES += main.cpp\ mainwindow.cpp \ - octaveterminal.cpp \ - clientmanager.cpp \ - client.cpp \ - terminalhighlighter.cpp \ - terminal.cpp + terminal.cpp -HEADERS += mainwindow.h \ - octaveterminal.h \ - clientmanager.h \ - client.h \ - terminalhighlighter.h \ - terminal.h +HEADERS += mainwindow.h \ + terminal.h LIBS += ../Quint/qtermwidget/libqtermwidget.a
deleted file mode 100644 --- a/gui//client.cpp +++ /dev/null @@ -1,51 +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 <http://www.gnu.org/licenses/>. - */ - -#include "client.h" - -Client::Client(QString command) - : QObject(), - m_command(command) { - m_thread.start(); - moveToThread(&m_thread); - - m_process.start(m_command, QProcess::ReadWrite); - connect(&m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(handleProcessFinished(int,QProcess::ExitStatus))); - connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(reemitDataAvailable())); - connect(&m_process, SIGNAL(readyReadStandardError()), this, SLOT(reemitErrorAvailable())); -} - -QMutex *Client::accessMutex() { - return &m_access; -} - -void Client::send(QString content) { - m_process.write(content.toLocal8Bit()); -} - -void Client::reemitDataAvailable() { - emit dataAvailable(m_process.readAllStandardOutput()); -} - -void Client::reemitErrorAvailable() { - emit errorAvailable(m_process.readAllStandardError()); -} - -void Client::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { - m_process.start(m_command, QProcess::ReadWrite); -}
deleted file mode 100644 --- a/gui//client.h +++ /dev/null @@ -1,131 +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 <http://www.gnu.org/licenses/>. - */ - -#ifndef CLIENT_H -#define CLIENT_H - -#include "clientmanager.h" -#include <QProcess> -#include <QObject> -#include <QThread> -#include <QMutex> - -/** - * \class Client - * - * A client is a representation of another external unit Quint is communicating with. - * Usually this will be the octave process. A client is launched by providing a command - * that will be executed. It will handle the process itself. - */ -class Client : public QObject { - Q_OBJECT - friend class ClientManager; - -public: - QMutex *accessMutex(); - -public slots: - void send(QString content); - -signals: - void dataAvailable(QString data); - void errorAvailable(QString error); - void lostConnection(); - -protected: - /** Clients may only be created by the client manager. */ - Client(QString command); - -private slots: - void reemitDataAvailable(); - void reemitErrorAvailable(); - void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); - -private: - QString m_command; - QProcess m_process; - QThread m_thread; - QMutex m_access; -}; - -/** - * \class PendingRequest - * - * The PendingRequest class helps to communicate with clients. It automatically locks - * the client until the PendingRequest is deleted. As soon as the request is being - * answered, it will send out the answered()-Signal. It buffers all input and delivers - * it by offering the fetchData() and fetchError()-methods. A request is considered - * as answered, when the termination string is found in the buffer. - */ -class PendingRequest : public QObject { - Q_OBJECT -public: - PendingRequest(Client *client) - : QObject(), - m_client(client), - m_dataBuffer(""), - m_errorBuffer("") { - client->accessMutex()->lock(); - connect(client, SIGNAL(dataAvailable(QString)), this, SLOT(receiveData(QString))); - connect(client, SIGNAL(errorAvailable(QString)), this, SLOT(receiveError(QString))); - } - - virtual ~PendingRequest() { - m_client->accessMutex()->unlock(); - } - - QString fetchData() { - QString content = m_dataBuffer, m_dataBuffer = ""; - return content; - } - - QString fetchError() { - QString content = m_errorBuffer, m_errorBuffer = ""; - return content; - } - - void query(QString request, QRegExp terminator = QRegExp("(\r\n | \n\r | \n)+")) { - m_terminator = terminator; - QMetaObject::invokeMethod(m_client, "send", Q_ARG(QString, request)); - } - -signals: - void answered(); - -private slots: - void receiveData(QString data) { - m_dataBuffer += data; - if(m_terminator.indexIn(m_dataBuffer) != -1) - emit answered(); - } - - void receiveError(QString error) { - m_errorBuffer += error; - if(m_terminator.indexIn(m_dataBuffer) != -1) - emit answered(); - } - -private: - Client *m_client; - QString m_dataBuffer; - QString m_errorBuffer; - QString m_request; - QRegExp m_terminator; -}; - -#endif // CLIENT_H
deleted file mode 100644 --- a/gui//clientmanager.cpp +++ /dev/null @@ -1,34 +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 <http://www.gnu.org/licenses/>. - */ - -#include "clientmanager.h" - -ClientManager ClientManager::m_clientManager; - -ClientManager::ClientManager() { -} - -ClientManager& ClientManager::clientManager() { - return ClientManager::m_clientManager; -} - -Client *ClientManager::startProcess(QString command) { - Client *client = new Client(command); - m_activeClients.push_back(client); - return client; -}
deleted file mode 100644 --- a/gui//clientmanager.h +++ /dev/null @@ -1,46 +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 <http://www.gnu.org/licenses/>. - */ - -#ifndef CLIENTMANAGER_H -#define CLIENTMANAGER_H - -#include <QList> -#include <QObject> -#include "client.h" - -/** - * \class ClientManager - * - * The client manager is a singleton that keeps track of all current clients. - */ -class Client; -class ClientManager : public QObject { - Q_OBJECT -public: - static ClientManager& clientManager(); - - /** Factory function to produce new clients. */ - Client *startProcess(QString command); - -private: - ClientManager(); - static ClientManager m_clientManager; - QList<Client*> m_activeClients; -}; - -#endif // CLIENTMANAGER_H
--- a/gui//mainwindow.cpp +++ b/gui//mainwindow.cpp @@ -33,7 +33,7 @@ //addOctaveTerminal(); loadWebPage("Online Manual", "http://www.gnu.org/software/octave/doc/interpreter/"); addTerminalWindow(); - + addTerminalWindow(); m_mdiArea->setViewMode(QMdiArea::SubWindowView); showMaximized(); }
deleted file mode 100644 --- a/gui//octaveterminal.cpp +++ /dev/null @@ -1,93 +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 <http://www.gnu.org/licenses/>. - */ - -#include "octaveterminal.h" -#include <QVBoxLayout> -#include <QPushButton> - -OctaveTerminal::OctaveTerminal(QWidget *parent) : - QMdiSubWindow(parent), - m_client(0) { - setWindowTitle("Octave Terminal"); - - setWidget(new QWidget(this)); - m_mainToolBar = new QToolBar(widget()); - m_octaveOutput = new QTextBrowser(widget()); - m_commandLine = new TerminalCommandLine(widget()); - - QVBoxLayout *layout = new QVBoxLayout(); - layout->addWidget(m_mainToolBar); - layout->addWidget(m_octaveOutput); - layout->addWidget(m_commandLine); - widget()->setLayout(layout); - - QPushButton *showEnvironmentButton = new QPushButton("Show Environment (who)"); - m_mainToolBar->addWidget(showEnvironmentButton); - - m_octaveOutput->setFontFamily("Monospace"); - m_octaveOutput->setReadOnly(true); - - blockUserInput(); - connect(m_commandLine, SIGNAL(claimCommand(QString)), this, SLOT(sendCommand(QString))); - connect(showEnvironmentButton, SIGNAL(clicked()), this, SLOT(showEnvironment())); - - m_terminalHighlighter = new TerminalHighlighter(m_octaveOutput->document()); -} - -void OctaveTerminal::sendCommand(QString command) { - m_octaveOutput->append(">" + command); - addRequest(command + "\n"); -} - -void OctaveTerminal::blockUserInput() { - m_commandLine->setEnabled(false); -} - -void OctaveTerminal::allowUserInput() { - m_commandLine->setEnabled(true); - m_commandLine->setFocus(); -} - -void OctaveTerminal::assignClient(Client *client) { - m_client = client; - allowUserInput(); - - // Sends an empty command to make the welcome message show up. - addRequest("\n"); -} - -void OctaveTerminal::showEnvironment() { - addRequest("who\n"); -} - - -void OctaveTerminal::addRequest(QString command) { - blockUserInput(); - m_pendingRequest = new PendingRequest(m_client); - connect(m_pendingRequest, SIGNAL(answered()), this, SLOT(handleAnsweredRequest())); - m_pendingRequest->query(command, QRegExp("octave:[0-9]+>")); -} - -void OctaveTerminal::handleAnsweredRequest() { - allowUserInput(); - QString data = m_pendingRequest->fetchData(); - QString error = m_pendingRequest->fetchError(); - m_octaveOutput->append(data); - m_octaveOutput->append(error); - delete m_pendingRequest; -}
deleted file mode 100644 --- a/gui//octaveterminal.h +++ /dev/null @@ -1,161 +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 <http://www.gnu.org/licenses/>. - */ - -#ifndef OCTAVETERMINAL_H -#define OCTAVETERMINAL_H - -#include <QMdiSubWindow> -#include <QLineEdit> -#include <QTextBrowser> -#include <QAction> -#include <QMenuBar> -#include <QMenu> -#include <QToolBar> -#include <QKeyEvent> -#include <QFocusEvent> -#include <QQueue> - -#include "client.h" -#include "terminalhighlighter.h" - -/** - * \class TerminalCommandLine - * - * Extends the QLineEdit by a history function. - */ -class TerminalCommandLine : public QLineEdit { - Q_OBJECT -public: - TerminalCommandLine(QWidget *parent = 0) - : QLineEdit(parent), - m_commandHistoryIndex(0) { - } - -signals: - void claimCommand(QString command); - -protected: - void focusOutEvent(QFocusEvent *focusEvent) { - setFocus(); - } - - bool event(QEvent *event) - { - if (event->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast<QKeyEvent *>(event); - if (ke->key() == Qt::Key_Tab) { - emit claimCommand("\t"); - return true; - } - } - - return QWidget::event(event); - } - - void keyPressEvent(QKeyEvent *keyEvent) { - QString command; - switch(keyEvent->key()) { - case Qt::Key_Return: - command = text(); - emit claimCommand(command); - m_commandHistory.append(command); - m_commandHistoryIndex = m_commandHistory.size(); - m_currentlyEditedCommand = ""; - setText(""); - break; - - case Qt::Key_Up: - if(!m_commandHistory.empty()) - { - if(m_commandHistoryIndex == m_commandHistory.size()) - m_currentlyEditedCommand = text(); - - m_commandHistoryIndex--; - if(m_commandHistoryIndex < 0) - m_commandHistoryIndex = m_commandHistory.size(); - - if(m_commandHistoryIndex == m_commandHistory.size()) - setText(m_currentlyEditedCommand); - else - setText(m_commandHistory.at(m_commandHistoryIndex)); - } - break; - - case Qt::Key_Down: - if(!m_commandHistory.empty()) - { - if(m_commandHistoryIndex == m_commandHistory.size()) - m_currentlyEditedCommand = text(); - - m_commandHistoryIndex++; - if(m_commandHistoryIndex > m_commandHistory.size()) - m_commandHistoryIndex = 0; - - if(m_commandHistoryIndex == m_commandHistory.size()) - setText(m_currentlyEditedCommand); - else - setText(m_commandHistory.at(m_commandHistoryIndex)); - } - break; - - default: - QLineEdit::keyPressEvent(keyEvent); - break; - } - } - -private: - QList<QString> m_commandHistory; - QString m_currentlyEditedCommand; - int m_commandHistoryIndex; -}; - -/** - * \class OctaveTerminal - * - * Provides a complete OctaveTerminal. Unless there is no octave client assigned to - * this terminal it will be not functional. - */ -class OctaveTerminal : public QMdiSubWindow { - Q_OBJECT -public: - explicit OctaveTerminal(QWidget *parent = 0); - -signals: - -public slots: - void sendCommand(QString command); - void blockUserInput(); - void allowUserInput(); - - void assignClient(Client* client); - void showEnvironment(); - void handleAnsweredRequest(); - -private: - void addRequest(QString command); - - QToolBar *m_mainToolBar; - QTextBrowser *m_octaveOutput; - TerminalCommandLine *m_commandLine; - Client *m_client; - TerminalHighlighter *m_terminalHighlighter; - PendingRequest *m_pendingRequest; -}; - -#endif // OCTAVETERMINAL_H
--- a/gui//terminal.cpp +++ b/gui//terminal.cpp @@ -18,5 +18,6 @@ m_terminalWidget->setShellProgram(programName); m_terminalWidget->startShellProgram(); setFocus(); + connect(m_terminalWidget, SIGNAL(finished()), this, SLOT(launchTerminal())); }
deleted file mode 100644 --- a/gui//terminalhighlighter.cpp +++ /dev/null @@ -1,76 +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 <http://www.gnu.org/licenses/>. - */ - -#include "terminalhighlighter.h" -#include <QtGui> - -TerminalHighlighter::TerminalHighlighter(QTextDocument *parent) - : QSyntaxHighlighter(parent) -{ - HighlightingRule rule; - - keywordFormat.setForeground(Qt::darkRed); - QStringList keywordPatterns; - keywordPatterns << "\\bOctave\\b" << "\\bGNU\\b"; - - foreach(const QString &pattern, keywordPatterns) { - rule.pattern = QRegExp(pattern); - rule.format = keywordFormat; - highlightingRules.append(rule); - } - - promptFormat.setForeground(Qt::darkGreen); - rule.pattern = QRegExp("\\boctave:[0-9]+>"); - rule.format = promptFormat; - highlightingRules.append(rule); - - errorFormat.setForeground(Qt::red); - errorFormat.setFontWeight(QFont::Bold); - rule.pattern = QRegExp("\\berror:"); - rule.format = errorFormat; - highlightingRules.append(rule); - - numberFormat.setForeground(Qt::darkGreen); - numberFormat.setFontWeight(QFont::Bold); - rule.pattern = QRegExp("\\b[0-9\\.]+[i]?\\b"); - rule.format = numberFormat; - highlightingRules.append(rule); - - urlFormat.setForeground(Qt::darkBlue); - rule.pattern = QRegExp("\\bhttp://[^\\s]+\\b"); - rule.format = urlFormat; - highlightingRules.append(rule); - - quotationFormat.setForeground(Qt::darkGreen); - rule.pattern = QRegExp("\".*\""); - rule.format = quotationFormat; - highlightingRules.append(rule); -} - -void TerminalHighlighter::highlightBlock(const QString &text) -{ - foreach(const HighlightingRule &rule, highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); - while(index >= 0) { - int length = expression.matchedLength(); - setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); - } - } -}
deleted file mode 100644 --- a/gui//terminalhighlighter.h +++ /dev/null @@ -1,54 +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 <http://www.gnu.org/licenses/>. - */ - -#ifndef TERMINALHIGHLIGHTER_H -#define TERMINALHIGHLIGHTER_H - -#include <QSyntaxHighlighter> - -/** - * \class TerminalHighlighter - * - * Subclass Qt's QSyntaxHighlighter-class to provide syntac highlighting. - */ -class QTextDocument; -class TerminalHighlighter : public QSyntaxHighlighter { - Q_OBJECT - -public: - TerminalHighlighter(QTextDocument *parent = 0); - -protected: - void highlightBlock(const QString &text); - -private: - struct HighlightingRule { - QRegExp pattern; - QTextCharFormat format; - }; - QVector<HighlightingRule> highlightingRules; - - QTextCharFormat keywordFormat; - QTextCharFormat quotationFormat; - QTextCharFormat numberFormat; - QTextCharFormat urlFormat; - QTextCharFormat errorFormat; - QTextCharFormat promptFormat; -}; - -#endif // TERMINALHIGHLIGHTER_H