From 332d689b8c79f388ee44c6d57ce12b09191ed104 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 2 Aug 2023 15:47:19 +0200 Subject: [PATCH] Add worker-object to be able to update for the worker. --- update.cpp | 44 +++++++++++++++++++++++++++++++++----------- update.h | 11 ++++------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/update.cpp b/update.cpp index e626b78..15b002f 100644 --- a/update.cpp +++ b/update.cpp @@ -1,4 +1,5 @@ #include "update.h" +#include "worker.h" #include #include @@ -25,9 +26,9 @@ #define UPDATE_OPKG (1) #define UPDATE_DC (1) #define UPDATE_PRINTER_TEMPLATES (1) -#define UPDATE_CASH_TEMPLATE (0) -#define UPDATE_CONF_TEMPLATE (0) -#define UPDATE_DEVICE_TEMPLATE (0) +#define UPDATE_CASH_TEMPLATE (1) +#define UPDATE_CONF_TEMPLATE (1) +#define UPDATE_DEVICE_TEMPLATE (1) static const QMap baudrateMap = { {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, @@ -75,6 +76,7 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) { } Update::Update(hwinf *hw, + Worker *worker, QString customerRepository, QString customerNrStr, QString branchName, @@ -85,6 +87,7 @@ Update::Update(hwinf *hw, char const *baudrate) : QObject(parent) , m_hw(hw) + , m_worker(worker) , m_serialInterface(serialInterface) , m_baudrate(baudrate) , m_customerRepository(customerRepository) @@ -510,7 +513,7 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) { disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError())); } -bool Update::doUpdate(QStringList const &filesToWorkOn) { +bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { // // ACHTUNG !!! @@ -542,7 +545,6 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) { bool res = false; QString fToWorkOn = (*it).trimmed(); - if (fToWorkOn.contains("dc2c", Qt::CaseInsensitive) && fToWorkOn.endsWith(".bin", Qt::CaseInsensitive)) { @@ -582,6 +584,10 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) { if ((res = updateBinary(fToWorkOn.toStdString().c_str())) == true) { qCritical() << "downloaded binary" << fToWorkOn; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } m_hw->dc_autoRequest(true); // turn auto-request setting on @@ -607,6 +613,10 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) { } else { if ((res = updatePrinterTemplate(templateIdx, fToWorkOn))) { qInfo() << "downloaded printer template"<< fToWorkOn; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } } #endif @@ -614,24 +624,36 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) { && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; #if UPDATE_CASH_TEMPLATE == 1 - if ((res = updateCashConf(name))) { - qInfo() << "downloaded cash template"<< name; + if ((res = updateCashConf(fToWorkOn))) { + qInfo() << "downloaded cash template"<< fToWorkOn; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } #endif } else if (fToWorkOn.contains("DC2C_conf", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; #if UPDATE_CONF_TEMPLATE == 1 - if ((res= updateConfig(name))) { - qInfo() << "downloaded config template"<< name; + if ((res= updateConfig(fToWorkOn))) { + qInfo() << "downloaded config template"<< fToWorkOn; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } #endif } else if (fToWorkOn.contains("DC2C_device", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; #if UPDATE_DEVICE_TEMPLATE == 1 - if ((res = updateDeviceConf(name))) { - qInfo() << "downloaded device template"<< name; + if ((res = updateDeviceConf(fToWorkOn))) { + qInfo() << "downloaded device template"<< fToWorkOn; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } #endif } else { diff --git a/update.h b/update.h index c612313..24c7d6f 100644 --- a/update.h +++ b/update.h @@ -9,7 +9,6 @@ #include #include "plugins/interfaces.h" -#include "apism/apism_client.h" #ifdef PTU5 #define SERIAL_PORT "ttymxc2" @@ -17,15 +16,12 @@ #define SERIAL_PORT "ttyUSB0" #endif -class Update; - -// TODO: check hardware compatibility -// TODO: opkg commandos - +class Worker; class Update : public QObject { Q_OBJECT hwinf *m_hw; + Worker *m_worker; char const *m_serialInterface; char const *m_baudrate; QString m_customerRepository; @@ -44,6 +40,7 @@ public: explicit Update(hwinf *hw, + Worker *worker, QString customerRepository, QString customerNrStr, QString branchName, @@ -53,7 +50,7 @@ public: char const *serialInterface = SERIAL_PORT, char const *baudrate = "115200"); virtual ~Update() override; - bool doUpdate(QStringList const &linesToWorkOn); + bool doUpdate(int &displayIndex, QStringList const &linesToWorkOn); //QString customerId() { return m_customerId; } //QString const customerId() const { return m_customerId; }