Implement Add serials range button

This commit is contained in:
2025-04-30 20:57:18 +02:00
parent 1ef58d23fd
commit 0909bfb0e7
9 changed files with 336 additions and 48 deletions

View File

@ -80,6 +80,39 @@
<translation type="vanished">Zurück</translation>
</message>
</context>
<context>
<name>AddSerialsRangeDialog</name>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.ui" line="14"/>
<source>Add serials range</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.ui" line="22"/>
<source>From:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.ui" line="29"/>
<source>To:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.ui" line="36"/>
<source>Count:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.cpp" line="45"/>
<source>???</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/addserialsrangedialog.cpp" line="51"/>
<source>%0 serials</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ApiSettingsPage</name>
<message>
@ -1257,92 +1290,92 @@
<context>
<name>DevicesModel</name>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="291"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="272"/>
<source>Serial</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="292"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="273"/>
<source>WS Status</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="293"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="274"/>
<source>Status</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="294"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="275"/>
<source>Variant</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="295"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="276"/>
<source>IsGo</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="296"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="277"/>
<source>IsAustralien</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="297"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="278"/>
<source>ResetCard</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="298"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="279"/>
<source>ConnectedWifi</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="299"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="280"/>
<source>Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="300"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="281"/>
<source>Version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="301"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="282"/>
<source>IDF Version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="302"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="283"/>
<source>Update</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="303"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="284"/>
<source>Reboots</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="304"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="285"/>
<source>Uptime</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="305"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="286"/>
<source>Current Partition</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="306"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="287"/>
<source>Car state</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="307"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="288"/>
<source>Energy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/devicesmodel.cpp" line="308"/>
<location filename="../../flotten-updater/devicesmodel.cpp" line="289"/>
<source>Livedata</source>
<translation type="unfinished"></translation>
</message>
@ -1905,132 +1938,147 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="50"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="52"/>
<source>Serial</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="74"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="58"/>
<source>Error while adding serial!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="97"/>
<source>Error while adding!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="97"/>
<source>%0 rows could not be adding!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="104"/>
<source>%0 selected</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="81"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="111"/>
<source>Add new column...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="88"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="118"/>
<source>Remove column %0</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="96"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="126"/>
<source>Enter api key</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="96"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="126"/>
<source>Api key:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="127"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="157"/>
<source>Set update url...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="128"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="158"/>
<source>Start update...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="129"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="159"/>
<source>Reboot...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="130"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="160"/>
<source>Set chargectrl override...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="131"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="161"/>
<source>Set abitrary api key...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="132"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="162"/>
<source>Reset nvs key...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="133"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="163"/>
<source>Open app(s)...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="134"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="164"/>
<source>Remove...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="138"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="168"/>
<source>Enter update url...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="138"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="168"/>
<source>Update url:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="154"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="184"/>
<source>Select update release...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="156"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="186"/>
<source>Update release</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="173"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="203"/>
<source>Are you sure?</source>
<translation type="unfinished">Sind Sie sicher?</translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="173"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="203"/>
<source>Do you really want to reboot selected devices?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="240"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="270"/>
<source>Please input nvs key to be reset</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="240"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="270"/>
<source>Nvs key</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="265"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="295"/>
<source>Confirm deletion of devices</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="266"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="296"/>
<source>Do you really want to remove %0 devices?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="285"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="320"/>
<source>Error while removing!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../flotten-updater/mainwindow.cpp" line="285"/>
<location filename="../../flotten-updater/mainwindow.cpp" line="320"/>
<source>%0 rows could not be removed!</source>
<translation type="unfinished"></translation>
</message>

View File

@ -3,6 +3,9 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Quick WebSockets LinguistT
qt_standard_project_setup(REQUIRES 6.6 I18N_TRANSLATED_LANGUAGES de)
qt_add_executable(flotten-updater WIN32 MACOSX_BUNDLE
addserialsrangedialog.h
addserialsrangedialog.cpp
addserialsrangedialog.ui
deviceconnection.cpp
deviceconnection.h
devicesmodel.cpp

View File

@ -0,0 +1,61 @@
#include "addserialsrangedialog.h"
#include "ui_addserialsrangedialog.h"
AddSerialsRangeDialog::AddSerialsRangeDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::AddSerialsRangeDialog>()}
{
m_ui->setupUi(this);
connect(m_ui->spinBoxFrom, &QSpinBox::valueChanged,
this, &AddSerialsRangeDialog::updatePreview);
connect(m_ui->spinBoxTo, &QSpinBox::valueChanged,
this, &AddSerialsRangeDialog::updatePreview);
updatePreview();
}
AddSerialsRangeDialog::~AddSerialsRangeDialog() = default;
void AddSerialsRangeDialog::accept()
{
if (from() > to())
return;
QDialog::accept();
}
int AddSerialsRangeDialog::from() const
{
return m_ui->spinBoxFrom->value();
}
int AddSerialsRangeDialog::to() const
{
return m_ui->spinBoxTo->value();
}
void AddSerialsRangeDialog::updatePreview()
{
const auto from = this->from();
const auto to = this->to();
QString text;
QColor color;
if (from > to)
{
text = tr("???");
color = Qt::red;
}
else
{
const auto count = to - from + 1;
text = tr("%0 serials").arg(count);
color = count > 100 ? Qt::yellow : Qt::green;
}
m_ui->labelCountDisplay->setText(text);
QPalette palette = m_ui->labelCountDisplay->palette();
palette.setColor(m_ui->labelCountDisplay->backgroundRole(), color);
palette.setColor(m_ui->labelCountDisplay->foregroundRole(), color);
m_ui->labelCountDisplay->setPalette(palette);
}

View File

@ -0,0 +1,27 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class AddSerialsRangeDialog; }
class AddSerialsRangeDialog : public QDialog
{
Q_OBJECT
public:
explicit AddSerialsRangeDialog(QWidget *parent = nullptr);
~AddSerialsRangeDialog();
void accept() override;
int from() const;
int to() const;
private:
void updatePreview();
private:
const std::unique_ptr<Ui::AddSerialsRangeDialog> m_ui;
};

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddSerialsRangeDialog</class>
<widget class="QDialog" name="AddSerialsRangeDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>194</width>
<height>140</height>
</rect>
</property>
<property name="windowTitle">
<string>Add serials range</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelFrom">
<property name="text">
<string>From:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTo">
<property name="text">
<string>To:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelCount">
<property name="text">
<string>Count:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="labelCountDisplay"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBoxFrom">
<property name="maximum">
<number>2147483647</number>
</property>
<property name="value">
<number>999930</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxTo">
<property name="maximum">
<number>2147483647</number>
</property>
<property name="value">
<number>999940</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddSerialsRangeDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>96</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>96</x>
<y>69</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddSerialsRangeDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>96</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>96</x>
<y>69</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -321,8 +321,15 @@ bool DevicesModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
void DevicesModel::addClient(const QString &serial)
bool DevicesModel::addClient(const QString &serial)
{
if (std::any_of(std::cbegin(m_devices), std::cend(m_devices),
[&](const auto &device){ return device->serial() == serial; }))
{
qWarning() << "duplicate serial";
return false;
}
beginInsertRows({}, m_devices.size(), m_devices.size());
auto clientPtr = std::make_shared<DevicesConnection>(m_key, m_cert, serial, this);
@ -332,6 +339,8 @@ void DevicesModel::addClient(const QString &serial)
endInsertRows();
client->start();
return true;
}
std::shared_ptr<DevicesConnection> DevicesModel::getDevice(QModelIndex index)

View File

@ -28,7 +28,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
void addClient(const QString &serial);
bool addClient(const QString &serial);
std::shared_ptr<DevicesConnection> getDevice(QModelIndex index);
std::shared_ptr<const DevicesConnection> getDevice(QModelIndex index) const;

View File

@ -16,6 +16,7 @@
#include "devicesmodel.h"
#include "requestdialog.h"
#include "setarbitraryapikeydialog.h"
#include "addserialsrangedialog.h"
MainWindow::MainWindow(FlottenUpdaterSettings &settings, const QSslKey &key,
const QSslCertificate &cert, QWidget *parent) :
@ -35,6 +36,7 @@ MainWindow::MainWindow(FlottenUpdaterSettings &settings, const QSslKey &key,
connect(m_ui->pushButtonDisconnectAll, &QAbstractButton::pressed, m_model.get(), &DevicesModel::disconnectAll);
connect(m_ui->pushButtonAdd, &QAbstractButton::pressed, this, &MainWindow::doAdd);
connect(m_ui->pushButtonRemove, &QAbstractButton::pressed, this, &MainWindow::doRemove);
connect(m_ui->pushButtonAddRange, &QAbstractButton::pressed, this, &MainWindow::doAddRange);
connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::selectionChanged);
m_ui->treeView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->treeView->header(), &QTreeView::customContextMenuRequested, this, &MainWindow::headerContextMenuRequested);
@ -50,8 +52,10 @@ 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());
if (m_model->addClient(serial))
m_settings.setSerials(m_model->serials());
else
QMessageBox::warning(this, tr("Error while adding serial!"), tr("Error while adding serial!"));
}
void MainWindow::doRemove()
@ -67,6 +71,32 @@ void MainWindow::doRemove()
removeRows(std::move(selectedRows));
}
void MainWindow::doAddRange()
{
AddSerialsRangeDialog dialog{this};
if (dialog.exec() != QDialog::Accepted)
return;
int succeeded{}, failed{};
for (auto serial = dialog.from(); serial <= dialog.to(); serial++)
{
if (m_model->addClient(QString::number(serial)))
succeeded++;
else
{
qWarning() << "adding serial" << serial << "failed";
failed++;
}
}
if (succeeded > 0)
m_settings.setSerials(m_model->serials());
if (failed > 0)
QMessageBox::warning(this, tr("Error while adding!"), tr("%0 rows could not be adding!").arg(failed));
}
void MainWindow::selectionChanged()
{
auto count = m_ui->treeView->selectionModel()->selectedRows().count();

View File

@ -25,6 +25,7 @@ public:
private slots:
void doAdd();
void doRemove();
void doAddRange();
void selectionChanged();
void headerContextMenuRequested(const QPoint &pos);
void contextMenuRequested(const QPoint &pos);