2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
13 #include <QTextStream>
21 using namespace boost
;
23 Engine::Engine(const QString
& path
, const QStringList
& arguments
)
25 , m_arguments(arguments
) {
26 connect(&m_engine
, SIGNAL(readyRead()), this, SLOT(processInput()));
27 connect(&m_engine
, SIGNAL(finished(int, QProcess::ExitStatus
)),
28 this, SIGNAL(lostConnection()));
33 void Engine::start() {
34 if (!m_workPath
.isNull())
35 m_engine
.setWorkingDirectory(m_workPath
);
36 m_engine
.start(m_path
, m_arguments
);
40 void Engine::sendCommand(const QString
& command
, bool echo
) {
41 QTextStream
os(&m_engine
);
42 os
<< command
<< "\n";
43 if (echo
&& m_console
)
44 m_console
->echo(command
);
46 std::cout
<< "> " << command
<< std::endl
;
50 void Engine::processInput() {
51 // process only full lines
52 while (m_engine
.canReadLine()) {
53 QString line
= m_engine
.readLine();
54 line
.remove("\n").remove("\r");
56 std::cout
<< "< " << line
<< std::endl
;
59 m_console
->displayText(line
+ "\n", 0);
60 emit
receivedCommand(line
);
64 void Engine::textNotify(const QString
& text
) {
65 sendCommand(text
, false);
69 void Engine::setNotifier(const shared_ptr
<EngineNotifier
>& notifier
) {
70 m_notifier
= notifier
;
73 void Engine::setConsole(const shared_ptr
<Console
>& console
) {