diff --git a/src/qrvthtool/resources/xdg/com.gerbilsoft.qrvthtool.metainfo.xml b/src/qrvthtool/resources/xdg/com.gerbilsoft.qrvthtool.metainfo.xml index 363e098..9c81f54 100644 --- a/src/qrvthtool/resources/xdg/com.gerbilsoft.qrvthtool.metainfo.xml +++ b/src/qrvthtool/resources/xdg/com.gerbilsoft.qrvthtool.metainfo.xml @@ -1,5 +1,5 @@ - + com.gerbilsoft.qrvthtool @@ -38,6 +38,7 @@ /usr/share/icons/hicolor/16x16/apps/qrvthtool.png + diff --git a/src/qrvthtool/windows/QRvtHToolWindow.cpp b/src/qrvthtool/windows/QRvtHToolWindow.cpp index 7b42e1f..530e8bc 100644 --- a/src/qrvthtool/windows/QRvtHToolWindow.cpp +++ b/src/qrvthtool/windows/QRvtHToolWindow.cpp @@ -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) { diff --git a/src/qrvthtool/windows/SelectDeviceDialog.cpp b/src/qrvthtool/windows/SelectDeviceDialog.cpp index 9477873..c524480 100644 --- a/src/qrvthtool/windows/SelectDeviceDialog.cpp +++ b/src/qrvthtool/windows/SelectDeviceDialog.cpp @@ -32,13 +32,16 @@ #include #include +// 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(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(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(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(); +} diff --git a/src/qrvthtool/windows/SelectDeviceDialog.hpp b/src/qrvthtool/windows/SelectDeviceDialog.hpp index c405b55..0fda68d 100644 --- a/src/qrvthtool/windows/SelectDeviceDialog.hpp +++ b/src/qrvthtool/windows/SelectDeviceDialog.hpp @@ -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); };