From 1ef58d23fd1f94c7ea3108c2eaf2c57940f120bb Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 30 Apr 2025 20:31:07 +0200 Subject: [PATCH] Implement read/write of serials in flotten-updater --- flotten-updater/devicesmodel.cpp | 35 +++++++++------------- flotten-updater/devicesmodel.h | 2 ++ flotten-updater/flottenupdatersettings.cpp | 10 +++++++ flotten-updater/flottenupdatersettings.h | 3 ++ flotten-updater/mainwindow.cpp | 11 +++++-- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/flotten-updater/devicesmodel.cpp b/flotten-updater/devicesmodel.cpp index fb94c5f..b07ec9c 100644 --- a/flotten-updater/devicesmodel.cpp +++ b/flotten-updater/devicesmodel.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "deviceconnection.h" #include "flottenupdatersettings.h" @@ -41,27 +42,7 @@ DevicesModel::DevicesModel(FlottenUpdaterSettings &settings, const QSslKey &key, m_cert{cert}, m_customColumns{settings.customColumns()} { - constexpr const char *serials[] { - "096850", "10000003", - "000010", "000011", "000012", "000013", "000014", "000015", "000016", "000017", "000018", "000019", "000020", "000021", "000022", "000023", "000024", "000025", "000026", "000027", "000028", "000029", - "000030", "000031", "000032", "000033", "000034", "000035", "000036", "000037", "000038", "000039", - "999900", "999901", "999902", "999903", "999904", "999905", "999906", "999907", "999908", "999909", - "999910", "999911", "999912", "999913", "999914", "00999915", "00999916", "00999917", "00999918", "00999919", - "999920", "00999921", "00999922", "999923", "00999924", "00999925", "999926", "999927", "999928", "999929", - "91000286", - "31416778", "31416779", "31416780", "31416781", "31416783", "31416784", "31416786", "31416787", "31416788", "31416789", "31416790", "31416791", "31416793", "31416794", "31416795", "31416796", "31416797", "31416798", "31416799", "31416800", "31416801", "31416802", "31416803", "31416804", "31416806", "31416807", "31416808", "31416809", "31416810", "31416811", "31416814", "31416815", "31416816", "31416817", "31416818", "31416819", - "91000001", "91000002", "91000003", "91000004", "91000005", "91000006", "91000007", "91000008", "91000009", "91000010", "91000011", "91000012", "91000013", "91000014", "91000015", "91000016", "91000017", "91000018", "91000019", "91000020", "91000021", "91000022", "91000023", "91000024", "91000025", "91000026", "91000027", "91000028", "91000029", "91000030", "91000031", "91000032", "91000033", "91000034", "91000035", "91000036", "91000037", "91000038", "91000039", "91000040", - "000043", "000044", "000047", "000050", "900001", "900103", "900104", "900105", "900107", "900108", "900113", "900117", "900118", "900123", "900126", "900127", - "91028339", "91028457", "91028482", "91028368", "91028336", "91028374", "91028371", "91028452", "91028481", "91028455", "91028334", "91028456", "91028351", "91028367", "91028346", "91028459", "91028366", "91028335", "91028483", "91028372", "91028337", "91028338", - "91008954", "91008978", "91008282", "91009008", "91008953", "91009000", "91009024", "91048840", "91048873", "91045590", "91045593", "91045586", "91048874", "91048879", "91048882", "91048878", "91048860", "91048865", "91048853", "91048864", "91048867", "91021261", "91021260", "91021379", "91021135", "91021266", "91021259", "91021374", "91021381", "91021258", "91021275", "91021380", "91021382", "91021377", "91021240", "91021371", "91021376", "91021255", "91021378", "91021383", "91021354", "91021195", "91021370", "91021278", "91021234", "91021256", "91021257", "91021360", "91021248", "91021363", "91021270", "91021267", "91021239", "91021193", "91021268", "91028339", "91028457", "91028482", "91028368", "91036167", "91028374", "91028371", "91028452", "91028481", "91028455", "91028334", "91028456", "91028351", "91028367", "91028346", "91028459", "91028366", "91028335", "91028483", "91028372", "91028337", "91028338", - "91100000", "91100001", "91100002", "91100003", "91100004", "91100005", "91100006", "91100007", "91100008", "91100009", "91100010", "91100011", "91100012", "91100013", "91100014", "91100015", "91100016", "91100017", "91100018", "91100019", "91100020", "91100021", "91100022", "91100023", "91100024", "91100025", "91100026", "91100027", "91100028", "91100029", "91100030", "91100031", - "402557", - "402558", - "402564", - "402567", - "402577", - }; - for (const auto &serial : serials) + for (const auto &serial : m_settings.serials()) { if (std::none_of(std::cbegin(m_devices), std::cend(m_devices), [&serial](auto &ptr){ return ptr->serial() == serial; @@ -392,6 +373,18 @@ void DevicesModel::removeCustomColumn(int section) m_settings.setCustomColumns(m_customColumns); } +QStringList DevicesModel::serials() const +{ + QStringList serials; + + serials.resize(m_devices.size()); + + std::transform(std::cbegin(m_devices), std::cend(m_devices), + std::begin(serials), [](const auto &device){ return device->serial(); }); + + return serials; +} + void DevicesModel::connectAll() { for (auto &device : m_devices) diff --git a/flotten-updater/devicesmodel.h b/flotten-updater/devicesmodel.h index bac8ab8..27426ee 100644 --- a/flotten-updater/devicesmodel.h +++ b/flotten-updater/devicesmodel.h @@ -37,6 +37,8 @@ public: bool customColumnRemovable(int section); void removeCustomColumn(int section); + QStringList serials() const; + public slots: void connectAll(); void disconnectAll(); diff --git a/flotten-updater/flottenupdatersettings.cpp b/flotten-updater/flottenupdatersettings.cpp index c1ff6b6..d575099 100644 --- a/flotten-updater/flottenupdatersettings.cpp +++ b/flotten-updater/flottenupdatersettings.cpp @@ -29,3 +29,13 @@ void FlottenUpdaterSettings::setCustomColumns(const QStringList &customColumns) { setValue("customColumns", customColumns); } + +QStringList FlottenUpdaterSettings::serials() const +{ + return value("serials").toStringList(); +} + +void FlottenUpdaterSettings::setSerials(const QStringList &serials) +{ + setValue("serials", serials); +} diff --git a/flotten-updater/flottenupdatersettings.h b/flotten-updater/flottenupdatersettings.h index 89c7fc8..64dc01d 100644 --- a/flotten-updater/flottenupdatersettings.h +++ b/flotten-updater/flottenupdatersettings.h @@ -17,4 +17,7 @@ public: QStringList customColumns() const; void setCustomColumns(const QStringList &customColumns); + + QStringList serials() const; + void setSerials(const QStringList &serials); }; diff --git a/flotten-updater/mainwindow.cpp b/flotten-updater/mainwindow.cpp index 2525e87..2e0c6f2 100644 --- a/flotten-updater/mainwindow.cpp +++ b/flotten-updater/mainwindow.cpp @@ -50,8 +50,8 @@ void MainWindow::doAdd() const auto serial = QInputDialog::getText(this, tr("Serial"), tr("Serial"), QLineEdit::Normal, {}, &ok); if (!ok) return; - m_model->addClient(serial); + m_settings.setSerials(m_model->serials()); } void MainWindow::doRemove() @@ -267,7 +267,7 @@ void MainWindow::removeRows(QModelIndexList &&indexes) ) != QMessageBox::Yes) return; - int failed{}; + int succeeded{}, failed{}; std::sort(indexes.begin(), indexes.end(), [](const QModelIndex &a, const QModelIndex &b) { @@ -275,12 +275,17 @@ void MainWindow::removeRows(QModelIndexList &&indexes) }); for (const QModelIndex &index : std::as_const(indexes)) - if (!m_model->removeRows(index.row(), 1, index.parent())) + if (m_model->removeRows(index.row(), 1, index.parent())) + succeeded++; + else { failed++; qWarning() << "removing row" << index.row() << "failed"; } + if (succeeded > 0) + m_settings.setSerials(m_model->serials()); + if (failed > 0) QMessageBox::warning(this, tr("Error while removing!"), tr("%0 rows could not be removed!").arg(failed)); }