start to implement progress bar

This commit is contained in:
Gerhard Hoffmann 2025-04-11 12:28:53 +02:00
parent d1b3b81972
commit e12181dc5a

View File

@ -3,6 +3,7 @@
#include "worker.h"
#include "utils.h"
#include "utils_internal.h"
#include "log_line_entry.h"
#include "progress_event.h"
#include "update_dc_event.h"
#include "process/update_command.h"
@ -25,6 +26,42 @@
#define SYNCHRONIZE_REPOSITORY 6
#define UPDATE_DC 7
#define CHECK_ISMAS_CONNECT_PERCENT_START ( 1)
#define CHECK_ISMAS_CONNECT_PERCENT_END (10)
#define CHECK_UPDATE_REQUEST_PERCENT_START (10)
#define CHECK_UPDATE_REQUEST_PERCENT_END (20)
#define UPDATE_GIT_PERCENT_START (20)
#define UPDATE_GIT_PERCENT_END (21)
#define UPDATE_OPKG_NOACTION_PERCENT_START (21)
#define UPDATE_OPKG_NOACTION_PERCENT_END (25)
#define UPDATE_OPKG_PERCENT_START (25)
#define UPDATE_OPKG_PERCENT_END (40)
#define UPDATE_DOWNLOAD_JSON_START (40)
#define UPDATE_DOWNLOAD_JSON_END (49)
#define UPDATE_SYNC_START (49)
#define UPDATE_SYNC_END (50)
#define UPDATE_DOWNLOAD_DC_START (50)
#define UPDATE_DOWNLOAD_DC_END (100)
void MainWindow::onFileChanged(QString const& /*f*/) {
static int i = 30;
ui->updateProgress->setValue(++i);
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) << "YYYYYYYYYYYYYYYYYY file changed" << i;
// TODO: daten an ISMAS senden
}
QProgressBar *MainWindow::progressBar() {
return ui ? ui->updateProgress : nullptr;
}
MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent)
@ -32,10 +69,15 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
, m_worker(worker)
, m_width(60)
, m_progressRunning(false)
, m_updateStep(UpdateDcEvent::UpdateStep::NONE) {
, m_updateStep(UpdateDcEvent::UpdateStep::NONE)
, m_updateLog("/opt/app/tools/atbupdate/update.log") { // TODO: in ini-file eintragen
ui->setupUi(this);
if (!m_updateLog.open(QIODevice::ReadWrite | QIODevice::Unbuffered)) {
qCritical() << "ERROR can not open" << m_updateLog.fileName();
}
m_updateSteps.resize(8);
m_updateSteps[CHECK_BACKEND_CONNECTION] = "Check backend connection (ISMAS) ";
m_updateSteps[CHECK_UPDATE_REQUEST] = "Check update request ";
@ -274,6 +316,7 @@ void MainWindow::onShowTariffUpdate(QString) {
void MainWindow::onShowISMASConnectivity(QString status) {
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
QString stepResult;
QString s = m_updateSteps[CHECK_BACKEND_CONNECTION].trimmed();
bool const custRepoExists = internal::customerRepoExists();
@ -281,24 +324,46 @@ void MainWindow::onShowISMASConnectivity(QString status) {
if (status.contains(UpdateCommand::ISMAS_CONNECTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += " <font color='Green'>connected</font>";
stepResult = "ISMAS connected";
} else {
s += " <font color='Green'>connected&nbsp;(initial configuration)</font>";
stepResult = "ISMAS connected (initial configuration)";
}
} else
if (status.contains(UpdateCommand::NO_CUSTOMER_REPOSITORY, Qt::CaseInsensitive)) {
s += " <font color='Blue'>NOT CONNECTED</font>";
stepResult = "ISMAS not connected";
} else
if (status.contains(UpdateCommand::ISMAS_CONNECTION_IN_PROGRESS, Qt::CaseInsensitive)) {
s += " <font color='Green'>connecting</font>";
stepResult = "connecting ISMAS";
} else
if (status.contains(UpdateCommand::ISMAS_NOT_CONNECTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += " <font color='Red'>NOT CONNECTED. STOP</font>";
stepResult = "ISMAS not connected";
} else {
s += " <font color='Red'>not connected.&nbsp;(initial configuration)</font>";
stepResult = "ISMAS not connected (initial configuration)";
}
} else {
s += " <font color='Red'>UNKNOWN STATUS</font>";
stepResult = "unknown status";
}
struct LogLineEntry logLine =
initLogLineEntry(1, // receiver
QDateTime::currentDateTime().toString(Qt::ISODate).toUtf8().constData(),
_ISMAS_CONTINUE,
0, // eventState
CHECK_ISMAS_CONNECT_PERCENT_START,
ISMAS::RESULT_CODE::E_SUCCESS,
"show ISMAS connectivity", // step
stepResult.toUtf8().constData()); // stepResult
int w = 0;
if ((w = m_updateLog.write((char *)(&logLine), sizeof(logLine))) != sizeof(logLine)) {
qCritical() << __func__ << ":" << __LINE__ << "ERROR only" << w << "bytes written";
}
m_updateSteps[CHECK_BACKEND_CONNECTION] = s;
@ -307,6 +372,20 @@ void MainWindow::onShowISMASConnectivity(QString status) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
logLine =
initLogLineEntry(1, // receiver
QDateTime::currentDateTime().toString(Qt::ISODate).toUtf8().constData(),
_ISMAS_CONTINUE,
0, // eventState
CHECK_ISMAS_CONNECT_PERCENT_END,
ISMAS::RESULT_CODE::E_SUCCESS,
"show ISMAS connectivity", // step
stepResult.toUtf8().constData()); // stepResult
if ((w = m_updateLog.write((char *)(&logLine), sizeof(logLine))) != sizeof(logLine)) {
qCritical() << __func__ << ":" << __LINE__ << "ERROR only" << w << "bytes written";
}
}
void MainWindow::onShowCustRepoStatus(QString status) {
@ -458,6 +537,7 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
void MainWindow::onShowUpdateRequest(QString status) {
// qCritical() << __func__ << ":" << __LINE__ << "status" << status;
//ui->updateProgress->setValue(CHECK_UPDATE_REQUEST_PERCENT_START);
QString s = m_updateSteps[CHECK_UPDATE_REQUEST].trimmed();
bool const custRepoExists = internal::customerRepoExists();
@ -469,17 +549,20 @@ void MainWindow::onShowUpdateRequest(QString status) {
s += " <font color='Blue'>not requested&nbsp;(initial configuration)</font>";
}
} else
if (status.contains(UpdateCommand::UPDATE_REQUESTED, Qt::CaseInsensitive)) {
if (status.contains(internal::UPDATE_REQUESTED, Qt::CaseInsensitive)) {
if (custRepoExists) {
s += " <font color='Green'>requested</font>";
} else {
s += " <font color='Blue'>requested&nbsp;(initial configuration)</font>";
}
} else
if (status.contains(UpdateCommand::UPDATE_NOT_NECESSARY, Qt::CaseInsensitive)) {
if (status.contains(internal::UPDATE_INITIAL, Qt::CaseInsensitive)) {
s += " <font color='Green'>requested&nbsp;(initial configuration)</font>";
} else
if (status.contains(internal::UPDATE_NOT_NECESSARY, Qt::CaseInsensitive)) {
s += " <font color='Green'>not necessary</font>";
} else
if (status.contains(UpdateCommand::NO_CUSTOMER_REPOSITORY, Qt::CaseInsensitive)) {
if (status.contains(internal::NO_CUSTOMER_REPOSITORY, Qt::CaseInsensitive)) {
s += " <font color='Blue'>UNKNOWN (ISMAS not connected)</font>";
} else {
s += " <font color='Red'>UNKNOWN</font>";
@ -491,6 +574,7 @@ void MainWindow::onShowUpdateRequest(QString status) {
s += m_updateSteps[i] + "<br />";
}
ui->stepLabel->setText(s);
//ui->updateProgress->setValue(CHECK_UPDATE_REQUEST_PERCENT_END);
}
void MainWindow::onShowISMASChecks(QString) {