[qrvthtool] SelectDeviceDialog.cpp: Mask the device serial number here, too.

Add ConfigStore as a constructor parameter. QRvtHToolWindow's
ConfigStore object must be passed here.

Listen for the option change, even though it shouldn't be possible
for the option to change while the dialog is open.

QRvtHToolWindow::on_actionOpenDevice_triggered():
- Pass the ConfigStore to SelectDeviceDialog.
- Also pass `this` as parent to ensure that the user realizes the
  window is modal. On KDE, this dims the main window. Previously,
  the main window wouldn't be dimmed, but it wouldn't be usable
  while SelectDeviceDialog was open.
This commit is contained in:
David Korth 2025-06-16 22:36:04 -04:00
parent 54b78ac69d
commit 1d0f8e86ef
4 changed files with 67 additions and 10 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018-2022 David Korth <gerbilsoft@gerbilsoft.com> -->
<!-- Copyright 2018-2025 David Korth <gerbilsoft@gerbilsoft.com> -->
<component type="desktop-application">
<id>com.gerbilsoft.qrvthtool</id>
@ -38,6 +38,7 @@
<icon type="local" width="16" height="16">/usr/share/icons/hicolor/16x16/apps/qrvthtool.png</icon>
<content_rating type="oars-1.1"/>
<releases>
<release version="2.0" date="2025-06-16"/>
<release version="1.1.1" date="2018-09-17"/>
<release version="1.1" date="2018-09-17"/>
<release version="1.0" date="2018-06-07"/>

View File

@ -1120,7 +1120,8 @@ void QRvtHToolWindow::on_actionOpenDiskImage_triggered(void)
void QRvtHToolWindow::on_actionOpenDevice_triggered(void)
{
// Prompt the user to select a device.
SelectDeviceDialog *const selectDeviceDialog = new SelectDeviceDialog();
Q_D(QRvtHToolWindow);
SelectDeviceDialog *const selectDeviceDialog = new SelectDeviceDialog(d->cfg, this);
selectDeviceDialog->setObjectName(QStringLiteral("selectDeviceDialog"));
int ret = selectDeviceDialog->exec();
if (ret == QDialog::Accepted) {

View File

@ -32,13 +32,16 @@
#include <QPushButton>
#include <QMetaMethod>
// Configuration
#include "config/ConfigStore.hpp"
/** SelectDeviceDialogPrivate **/
#include "ui_SelectDeviceDialog.h"
class SelectDeviceDialogPrivate
{
public:
explicit SelectDeviceDialogPrivate(SelectDeviceDialog *q);
explicit SelectDeviceDialogPrivate(ConfigStore *cfg, SelectDeviceDialog *q);
~SelectDeviceDialogPrivate();
protected:
@ -50,6 +53,9 @@ private:
public:
Ui::SelectDeviceDialog ui;
// Configuration
ConfigStore *const cfg;
// RVT-H Reader icon
QIcon rvthReaderIcon;
@ -95,8 +101,9 @@ public:
const RvtH_QueryEntry *entry, RvtH_Listen_State_e state, void *userdata);
};
SelectDeviceDialogPrivate::SelectDeviceDialogPrivate(SelectDeviceDialog *q)
SelectDeviceDialogPrivate::SelectDeviceDialogPrivate(ConfigStore *cfg, SelectDeviceDialog *q)
: q_ptr(q)
, cfg(cfg)
, sel_device(nullptr)
, listener(nullptr)
#ifdef _WIN32
@ -108,6 +115,10 @@ SelectDeviceDialogPrivate::SelectDeviceDialogPrivate(SelectDeviceDialog *q)
// Set the window icon.
q->setWindowIcon(rvthReaderIcon);
// Configuration signals
cfg->registerChangeNotification(QLatin1String("maskDeviceSerialNumbers"),
q, SLOT(maskDeviceSerialNumbers_cfg_slot(QVariant)));
}
SelectDeviceDialogPrivate::~SelectDeviceDialogPrivate()
@ -128,10 +139,32 @@ SelectDeviceDialogPrivate::~SelectDeviceDialogPrivate()
*/
void SelectDeviceDialogPrivate::addDevice(const DeviceQueryData &queryData)
{
const bool mask = cfg->get(QLatin1String("maskDeviceSerialNumbers")).toBool();
// Create the string.
QString text = queryData.device_name + QChar(L'\n') +
queryData.usb_serial + QChar(L'\n') +
formatSize(static_cast<off64_t>(queryData.size));
QString text = queryData.device_name + QChar(L'\n');
if (mask) {
// Mask the last 5 digits.
// TODO: qsizetype?
QString qs_full_serial = queryData.usb_serial;
const int size = static_cast<int>(qs_full_serial.size());
if (size > 5) {
for (int i = size - 5; i < size; i++) {
qs_full_serial[i] = QChar(L'x');
}
} else {
// Mask the entire thing?
qs_full_serial = QString(size, QChar(L'x'));
}
text += qs_full_serial;
} else {
// Show the full serial number.
text += queryData.usb_serial;
}
text += QChar(L'\n');
text += formatSize(static_cast<off64_t>(queryData.size));
// Create the QListWidgetItem.
// TODO: Verify that QListWidget takes ownership.
@ -251,12 +284,12 @@ void SelectDeviceDialogPrivate::rvth_listener_callback(
/** SelectDeviceDialog **/
SelectDeviceDialog::SelectDeviceDialog(QWidget *parent)
SelectDeviceDialog::SelectDeviceDialog(ConfigStore *cfg, QWidget *parent)
: super(parent,
Qt::WindowSystemMenuHint |
Qt::WindowTitleHint |
Qt::WindowCloseButtonHint)
, d_ptr(new SelectDeviceDialogPrivate(this))
, d_ptr(new SelectDeviceDialogPrivate(cfg, this))
{
Q_D(SelectDeviceDialog);
d->ui.setupUi(this);
@ -534,3 +567,13 @@ void SelectDeviceDialog::deviceStateChanged(const DeviceQueryData &queryData, Rv
break;
}
}
/**
* "Mask Device Serial Numbers" option was changed by the configuration.
* @param mask If true, mask device serial numbers.
*/
void SelectDeviceDialog::maskDeviceSerialNumbers_cfg_slot(const QVariant &mask)
{
Q_D(SelectDeviceDialog);
d->refreshDeviceList();
}

View File

@ -14,6 +14,9 @@
#include "librvth/query.h"
Q_DECLARE_METATYPE(RvtH_Listen_State_e)
// Configuration
class ConfigStore;
/**
* Convert a TCHAR string to QString.
* @param str TCHAR string
@ -77,7 +80,7 @@ Q_OBJECT
typedef QDialog super;
public:
explicit SelectDeviceDialog(QWidget *parent = nullptr);
explicit SelectDeviceDialog(ConfigStore *cfg, QWidget *parent = nullptr);
virtual ~SelectDeviceDialog();
protected:
@ -149,4 +152,13 @@ protected slots:
* @param state Device state
*/
void deviceStateChanged(const DeviceQueryData &queryData, RvtH_Listen_State_e state);
protected slots:
/** Configuration slots **/
/**
* "Mask Device Serial Numbers" option was changed by the configuration.
* @param mask If true, mask device serial numbers.
*/
void maskDeviceSerialNumbers_cfg_slot(const QVariant &mask);
};