Populate text-edit with run-time info from update-process.
This commit is contained in:
parent
eb7d77692b
commit
b3f4a4086b
106
mainwindow.cpp
106
mainwindow.cpp
@ -1,63 +1,97 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "worker.h"
|
#include "worker.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
, m_worker(worker) {
|
, m_worker(worker)
|
||||||
|
, m_width(52) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(ui->start, SIGNAL(clicked()), m_worker, SLOT(update()));
|
ui->updateProgress->setRange(1, 100);
|
||||||
connect(ui->exit, SIGNAL(clicked()), qApp, SLOT(quit()));
|
ui->updateProgress->reset();
|
||||||
|
|
||||||
int w = 52;
|
m_startTimer = new QTimer(this);
|
||||||
|
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
||||||
|
m_startTimer->setSingleShot(true);
|
||||||
|
m_startTimer->start(5 * 1000);
|
||||||
|
|
||||||
|
m_exitTimer = new QTimer(this);
|
||||||
|
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
|
||||||
|
m_exitTimer->setSingleShot(true);
|
||||||
|
m_exitTimer->start(1800 * 1000);
|
||||||
|
|
||||||
|
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
|
||||||
|
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
|
||||||
|
connect(ui->start, SIGNAL(clicked()), m_worker, SLOT(update()));
|
||||||
|
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit()));
|
||||||
|
connect(m_worker, SIGNAL(stopStartTimer()), this, SLOT(onStopStartTimer()));
|
||||||
|
connect(m_worker, SIGNAL(restartExitTimer()), this, SLOT(onRestartExitTimer()));
|
||||||
|
connect(m_worker, SIGNAL(appendText(QString, QString)), this, SLOT(onAppendText(QString, QString)));
|
||||||
|
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
|
||||||
|
connect(m_worker, SIGNAL(setProgress(quint8)), this, SLOT(onSetProgress(quint8)));
|
||||||
|
|
||||||
QStringList lst;
|
QStringList lst;
|
||||||
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
|
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||||
lst << QString("Start: ") + start.leftJustified(w-10);
|
lst << QString("Start: ") + start.leftJustified(m_width-10);
|
||||||
lst << QString("").leftJustified(w-3, '=');
|
lst << QString("").leftJustified(m_width-3, '=');
|
||||||
lst << QString("Machine number : %1 ").arg(996).leftJustified(w-3);
|
lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3);
|
||||||
lst << QString("Customer number : %1 ").arg(281).leftJustified(w-3);
|
lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3);
|
||||||
lst << QString("Zone number : %1 (%2)").arg(1).arg("yellow").leftJustified(w-3);
|
lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3);
|
||||||
lst << QString("").leftJustified(w-3, '=');
|
lst << QString("").leftJustified(m_width-3, '=');
|
||||||
lst << QString("Backend connected ").leftJustified(w-10) + " [ ok]";
|
|
||||||
lst << QString("Update trigger set ").leftJustified(w-10) + " [ ok]";
|
|
||||||
// lst << QString("Found ISMAS machine number : %1 ").arg(996).leftJustified(w-10) + " [done]";
|
|
||||||
// lst << QString("Found ISMAS customer number: %1 ").arg(281).leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("Prepare customer environment ").leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("Found %1 files to update ").arg(5).leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("(") + QString("%1").arg(1).rightJustified(2, ' ') + QString(")")
|
|
||||||
+ (QString(" Update ") + "DC2C_print01.json ").leftJustified(w-14) + " [done]";
|
|
||||||
lst << QString("(") + QString("%1").arg(2).rightJustified(2, ' ') + QString(")")
|
|
||||||
+ (QString(" Update ") + "DC2C_print01.json ").leftJustified(w-14) + " [done]";
|
|
||||||
lst << QString("(") + QString("%1").arg(3).rightJustified(2, ' ') + QString(")")
|
|
||||||
+ QString(" Update opkg pakets ").leftJustified(w-14) + " [done]";
|
|
||||||
lst << QString("(") + QString("%1").arg(4).rightJustified(2, ' ') + QString(")")
|
|
||||||
+ QString(" Update device controller %1 ").arg("04.38").leftJustified(w-14) + " [done]";
|
|
||||||
lst << QString("Sync customer environment with filesystem ").leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("(") + QString("%1").arg(5).rightJustified(2, ' ') + QString(")")
|
|
||||||
+ (QString(" Update ") + "tariff01.json ").leftJustified(w-14) + " [done]";
|
|
||||||
lst << QString("Send ISMAS notification ").leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("Save log file %1.log").arg(start).leftJustified(w-10) + " [done]";
|
|
||||||
lst << QString("").leftJustified(w-3, '=');
|
|
||||||
lst << QString("").leftJustified(w-13) + " [SUCCESS]";
|
|
||||||
|
|
||||||
ui->updateStatus->setText(lst.join('\n'));
|
ui->updateStatus->setText(lst.join('\n'));
|
||||||
ui->updateStatus->setEnabled(true);
|
ui->updateStatus->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
delete m_startTimer;
|
||||||
|
delete m_exitTimer;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onStopStartTimer() {
|
||||||
void MainWindow::onStartClicked() {
|
m_startTimer->stop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onExitClicked() {
|
void MainWindow::onRestartExitTimer() {
|
||||||
|
m_exitTimer->stop();
|
||||||
|
m_exitTimer->start(5 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onQuit() {
|
||||||
|
if (!m_worker->updateProcessRunning()) {
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onSetProgress(quint8 v) {
|
||||||
|
qCritical() << "SET VAL" << v;
|
||||||
|
ui->updateProgress->setValue(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onAppendText(QString text, QString suffix) {
|
||||||
|
QString editText = ui->updateStatus->toPlainText();
|
||||||
|
QStringList lines = editText.split('\n');
|
||||||
|
for (int i=0; i<lines.size(); ++i) {
|
||||||
|
qCritical() << lines.at(i);
|
||||||
|
}
|
||||||
|
if (!suffix.contains("[SUCCESS]")) {
|
||||||
|
editText += text.leftJustified(m_width-9) + suffix;
|
||||||
|
ui->updateStatus->setPlainText(editText);
|
||||||
|
} else {
|
||||||
|
editText += QString("\n").leftJustified(m_width-3, '=');
|
||||||
|
editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]";
|
||||||
|
}
|
||||||
|
ui->updateStatus->setText(editText);
|
||||||
|
ui->updateStatus->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onShowErrorMessage(QString title, QString text) {
|
||||||
|
QMessageBox::critical(this, title, text, QMessageBox::Ok);
|
||||||
}
|
}
|
||||||
|
17
mainwindow.h
17
mainwindow.h
@ -2,12 +2,14 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class Worker;
|
#include "worker.h"
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -15,12 +17,21 @@ public:
|
|||||||
MainWindow(Worker *worker, QWidget *parent = nullptr);
|
MainWindow(Worker *worker, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onAppendText(QString, QString);
|
||||||
|
void onShowErrorMessage(QString, QString);
|
||||||
|
void onSetProgress(quint8);
|
||||||
|
void onStopStartTimer();
|
||||||
|
void onRestartExitTimer();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onStartClicked();
|
void onQuit();
|
||||||
void onExitClicked();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Worker *m_worker;
|
Worker *m_worker;
|
||||||
|
int m_width;
|
||||||
|
QTimer *m_startTimer;
|
||||||
|
QTimer *m_exitTimer;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user