diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/conversation.cc | 23 | ||||
-rw-r--r-- | src/gui/conversation.h | 10 | ||||
-rw-r--r-- | src/gui/debate.cc | 27 |
3 files changed, 20 insertions, 40 deletions
diff --git a/src/gui/conversation.cc b/src/gui/conversation.cc index ccb20b9a..cb0b82b8 100644 --- a/src/gui/conversation.cc +++ b/src/gui/conversation.cc @@ -234,7 +234,7 @@ namespace OpenAxiom { QString input = question()->text().trimmed(); if (empty_string(input)) return; - topic()->submit_query(input); + topic()->server()->input(input); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } @@ -271,13 +271,12 @@ namespace OpenAxiom { // Set a minimum preferred widget size, so no layout manager // messes with it. Indicate we can make use of more space. - Conversation::Conversation(Debate& parent) - : group(&parent), greatings(this), cur_ex(), cur_out(&greatings) { + Conversation::Conversation(Debate& parent, const Command& cmd) + : group(&parent), greatings(this), srv(cmd), cur_ex(), cur_out(&greatings) { setFont(monospace_font()); setBackgroundRole(QPalette::Base); greatings.setFont(font()); - oracle()->setProcessChannelMode(QProcess::MergedChannels); - connect(oracle(), SIGNAL(readyReadStandardOutput()), + connect(server(), SIGNAL(readyReadStandardOutput()), this, SLOT(read_reply())); // connect(oracle(), SIGNAL(readyReadStandardError()), // this, SLOT(read_reply())); @@ -286,8 +285,6 @@ namespace OpenAxiom { Conversation::~Conversation() { for (int i = children.size() -1 ; i >= 0; --i) delete children[i]; - if (oracle()->state() == QProcess::Running) - oracle()->terminate(); } QPoint Conversation::bottom_left() const { @@ -358,9 +355,9 @@ namespace OpenAxiom { }; static OracleOutput - read_output(QProcess& proc) { + read_output(Server* server) { OracleOutput output; - QStringList strs = QString::fromLocal8Bit(proc.readAll()).split('\n'); + QStringList strs = QString::fromLocal8Bit(server->readAll()).split('\n'); QStringList new_list; QRegExp rx("\\(\\d+\\)\\s->"); while (not strs.isEmpty()) { @@ -384,7 +381,7 @@ namespace OpenAxiom { void Conversation::read_reply() { - OracleOutput output = read_output(proc); + OracleOutput output = read_output(server()); if (empty(output)) return; if (not empty_string(output.result)) { @@ -407,10 +404,4 @@ namespace OpenAxiom { } } } - - void - Conversation::submit_query(const QString& s) { - oracle()->write(s.toAscii()); - oracle()->write("\n"); - } } diff --git a/src/gui/conversation.h b/src/gui/conversation.h index 2698c199..01847e6e 100644 --- a/src/gui/conversation.h +++ b/src/gui/conversation.h @@ -40,7 +40,7 @@ #include <QEvent> #include <QResizeEvent> #include <QPaintEvent> -#include <QProcess> +#include "server.h" namespace OpenAxiom { // A conversation is a set of exchanges. An exchange is a question @@ -154,7 +154,7 @@ namespace OpenAxiom { Q_OBJECT; typedef QWidget Base; public: - explicit Conversation(Debate&); + explicit Conversation(Debate&, const Command&); ~Conversation(); // Holds if this conversation just started. @@ -178,7 +178,7 @@ namespace OpenAxiom { QSize sizeHint() const; // Return a pointer to the oracle in this conversation. - QProcess* oracle() { return &proc; } + Server* server() { return &srv; } // Return a pointer to the current exchange, if any. Exchange* exchange() { return cur_ex; } @@ -186,8 +186,6 @@ namespace OpenAxiom { // Return the parent engine widget. Debate* debate() const { return group; } - void submit_query(const QString&); - public slots: // Return the topic following a given topic in this set of conversations Exchange* next(Exchange*); @@ -204,7 +202,7 @@ namespace OpenAxiom { Debate* group; Banner greatings; Children children; - QProcess proc; + Server srv; Exchange* cur_ex; OutputTextArea* cur_out; }; diff --git a/src/gui/debate.cc b/src/gui/debate.cc index 51a5eb69..deaed417 100644 --- a/src/gui/debate.cc +++ b/src/gui/debate.cc @@ -35,23 +35,8 @@ namespace OpenAxiom { - static void - start_interpreter(Conversation* conv, Command& cmd) { - QStringList args; - for (int i = 0; i < cmd.rt_args.size(); ++i) - args << cmd.rt_args[i]; - args << "--" << "--role=server"; - for (int i = 1; i < cmd.core.argc; ++i) - args << cmd.core.argv[i]; - conv->oracle()->start(make_path_for(cmd.root_dir, Driver::core), args); - // When invoked in a --role=server mode, OpenAxiom would - // wait to be pinged before displaying a prompt. This is - // an unfortunate result of a rather awkward hack. - conv->submit_query(""); - } - Debate::Debate(QTabWidget* parent, Command& cmd) - : QScrollArea(parent), conv(*this) { + : QScrollArea(parent), conv(*this, cmd) { setWidget(&conv); setViewportMargins(0, 0, 0, 0); viewport()->setAutoFillBackground(true); @@ -59,8 +44,14 @@ namespace OpenAxiom { setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); adjustSize(); - start_interpreter(exchanges(), cmd); - connect(conv.oracle(), + + exchanges()->server()->launch(); + // When invoked in a --role=server mode, OpenAxiom would + // wait to be pinged before displaying a prompt. This is + // an unfortunate result of a rather awkward hack. + exchanges()->server()->input(""); + + connect(exchanges()->server(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(done(int))); } |