diff --git a/slsDetectorGui/forms/form_tab_messages.ui b/slsDetectorGui/forms/form_tab_messages.ui
index d352bce00..9ef5a0081 100755
--- a/slsDetectorGui/forms/form_tab_messages.ui
+++ b/slsDetectorGui/forms/form_tab_messages.ui
@@ -127,9 +127,9 @@
- btnSave
- btnClear
dispCommand
+ btnClear
+ btnSave
diff --git a/slsDetectorGui/include/qTabMessages.h b/slsDetectorGui/include/qTabMessages.h
index e70598def..aaa7f86f8 100755
--- a/slsDetectorGui/include/qTabMessages.h
+++ b/slsDetectorGui/include/qTabMessages.h
@@ -3,6 +3,8 @@
#include "ui_form_tab_messages.h"
#include "qDebugStream.h"
+class QProcess;
+
class qTabMessages:public QWidget, private Ui::TabMessagesObject {
Q_OBJECT
@@ -21,5 +23,9 @@ private:
void SetupWidgetWindow();
void Initialization();
void PrintNextLine();
+ void AppendOutput();
+ void AppendError();
+
+ QProcess* process;
};
diff --git a/slsDetectorGui/src/qTabMessages.cpp b/slsDetectorGui/src/qTabMessages.cpp
index 6fc620d68..2524aa3a6 100755
--- a/slsDetectorGui/src/qTabMessages.cpp
+++ b/slsDetectorGui/src/qTabMessages.cpp
@@ -17,14 +17,17 @@ qTabMessages::qTabMessages(QWidget *parent) : QWidget(parent) {
FILE_LOG(logDEBUG) << "Messages ready";
}
-qTabMessages::~qTabMessages() {}
-
-void qTabMessages::Refresh() {
- dispCommand->clear();
+qTabMessages::~qTabMessages() {
+ process->close();
+ if (process)
+ delete process;
}
void qTabMessages::SetupWidgetWindow() {
+ process = new QProcess;
+ process->setWorkingDirectory(QDir::cleanPath(QDir::currentPath()));
PrintNextLine();
+
qDebugStream(std::cout, this);
qDebugStream(std::cerr, this);
@@ -34,31 +37,51 @@ void qTabMessages::SetupWidgetWindow() {
void qTabMessages::Initialization() {
connect(btnSave, SIGNAL(clicked()), this, SLOT(SaveLog()));
connect(btnClear, SIGNAL(clicked()), this, SLOT(ClearLog()));
- connect(dispCommand, SIGNAL(editingFinished()), this, SLOT(ExecuteCommand()));
+ connect(dispCommand, SIGNAL(returnPressed()), this, SLOT(ExecuteCommand()));
+ //connect(process, SIGNAL(readAllStandardError()), this, SLOT(AppendError()));
+ //connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(AppendOutput()));
}
void qTabMessages::ExecuteCommand() {
- QString command = dispCommand->text();
- dispLog->append(command);
+ QStringList param = dispCommand->text().split(" ");
dispCommand->clear();
+ // appending command to log without newline
+ dispLog->moveCursor (QTextCursor::End);
+ dispLog->insertHtml(QString("") + param.join(" ") + QString(""));
+
+ QString command = param.at(0);
+ param.removeFirst();
+ FILE_LOG(logINFO) << "Executing Command:[" << command.toAscii().constData() << "] with Arguments:[" << param.join(" ").toAscii().constData() << "]";
- // take 1st string as program
- QStringList arguments;
-
- QProcess *myProcess = new QProcess(this);
- myProcess->start(command, arguments);
-
- // print readall
- QByteArray result = myProcess.readAll();
-
- PrintNextLine();
+ process->setProcessChannelMode(QProcess::MergedChannels);
+ process->start(command, param);
+ if(!process->waitForFinished()) {
+ AppendError();
+ } else {
+ AppendOutput();
+ }
}
void qTabMessages::PrintNextLine() {
- QString path = QDir::cleanPath(QDir::currentPath());
- dispLog->append(QString("\n") + path + QString("$"));
+ dispLog->append(QString("") + QDir::current().dirName() + QString("$ ") + QString(""));
}
+void qTabMessages::AppendOutput() {
+ QByteArray result = process->readAll();
+ result.replace("\n", "
");
+ dispLog->append(QString("") + result + QString(""));
+ FILE_LOG(logDEBUG) << "Command executed successfully";
+ PrintNextLine();
+}
+
+void qTabMessages::AppendError() {
+ dispLog->append(QString("") + process->errorString() + QString(""));
+ FILE_LOG(logERROR) << "Error executing command";
+ PrintNextLine();
+}
+
+
+
void qTabMessages::customEvent(QEvent *e) {
if (e->type() == (STREAMEVENT)) {
QString temp = ((qStreamEvent *)e)->getString();
@@ -67,29 +90,35 @@ void qTabMessages::customEvent(QEvent *e) {
}
void qTabMessages::SaveLog() {
- QString fName = QString(""); //FIXME:current directory?
- fName = fName + "/LogFile.txt";
+ QString fName = QDir::cleanPath(QDir::currentPath()) + "/LogFile.txt";
fName = QFileDialog::getSaveFileName(this, tr("Save Snapshot "),
fName, tr("Text files (*.txt);;All Files(*)"));
if (!fName.isEmpty()) {
QFile outfile;
outfile.setFileName(fName);
- if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { //Append
+ if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&outfile);
out << dispLog->toPlainText() << endl;
- qDefs::Message(qDefs::INFORMATION, std::string("The Log has been successfully saved to "
- "") +
- fName.toAscii().constData(),
- "qTabMessages::SaveLog");
+ std::string mess = std::string("The Log has been successfully saved to ") + fName.toAscii().constData();
+ qDefs::Message(qDefs::INFORMATION, mess, "TabMessages::SaveLog");
+ FILE_LOG(logINFO) << mess;
} else {
- FILE_LOG(logWARNING) << "Attempt to save log file failed.";
+ FILE_LOG(logWARNING) << "Attempt to save log file failed: " << fName.toAscii().constData();
qDefs::Message(qDefs::WARNING, "Attempt to save log file failed.", "qTabMessages::SaveLog");
}
}
+ dispCommand->setFocus();
}
void qTabMessages::ClearLog() {
dispLog->clear();
FILE_LOG(logINFO) << "Log Cleared";
+ PrintNextLine();
+ dispCommand->setFocus();
+}
+
+void qTabMessages::Refresh() {
+ dispCommand->clear();
+ dispCommand->setFocus();
}