open-axiom repository from github
// Copyright (C) 2011-2013, Gabriel Dos Reis.1// All rights reserved.2// Written by Gabriel Dos Reis.3//4// Redistribution and use in source and binary forms, with or without5// modification, are permitted provided that the following conditions are6// met:7//8// - Redistributions of source code must retain the above copyright9// notice, this list of conditions and the following disclaimer.10//11// - Redistributions in binary form must reproduce the above copyright12// notice, this list of conditions and the following disclaimer in13// the documentation and/or other materials provided with the14// distribution.15//16// - Neither the name of OpenAxiom. nor the names of its contributors17// may be used to endorse or promote products derived from this18// software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER24// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.3132#include <QMenuBar>33#include <QAction>34#include <QApplication>35#include <QMessageBox>36#include <QScrollBar>3738#include "debate.h"39#include "main-window.h"4041namespace OpenAxiom {42void43MainWindow::display_error(const std::string& s) {44QMessageBox::critical(this, tr("System error"), QString(s.c_str()));45}4647void48MainWindow::read_databases() {49}505152static void connect_server_io(MainWindow* win, Debate* debate) {53QObject::connect(win->server(), SIGNAL(readyReadStandardError()),54win, SLOT(display_error()));55QObject::connect(win->server(), SIGNAL(readyReadStandardOutput()),56debate->exchanges(), SLOT(read_reply()));57}585960MainWindow::MainWindow(int argc, char* argv[])61: srv(argc, argv), tabs(this) {62setCentralWidget(&tabs);63setWindowTitle("OpenAxiom");64auto debate = new Debate(this);65tabs.addTab(debate, "Interpreter");66auto s = debate->widget()->frameSize();67s.rwidth() += debate->verticalScrollBar()->width();68s.rheight() += debate->horizontalScrollBar()->width();69resize(s);70QMenu* file = menuBar()->addMenu(tr("&File"));71QAction* action = new QAction(tr("Quit"), this);72file->addAction(action);73action->setShortcut(tr("Ctrl+Q"));74connect(action, SIGNAL(triggered()), this, SLOT(close()));7576connect_server_io(this, debate);77server()->launch();78// When invoked in a --role=server mode, OpenAxiom would79// wait to be pinged before displaying a prompt. This is80// an unfortunate result of a rather awkward hack.81server()->input("");82read_databases();83}8485MainWindow::~MainWindow() {86}8788void MainWindow::done(int s, QProcess::ExitStatus) {89// For the time being, shut done the whole application90// if the interpreter quits. FIXME.91QApplication::exit(s);92}9394void MainWindow::display_error() {95auto s = server()->readAllStandardError();96QMessageBox::critical(this, tr("System error"), QString(s));97}98}99100101