From c809f482d57a96ff0c4f9cee526f3cafc6110f54 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Sun, 5 Feb 2023 12:12:37 -0500 Subject: [PATCH] qt: Fixes to the process for selecting an existing hdd image --- src/qt/qt_filefield.cpp | 2 +- src/qt/qt_filefield.hpp | 2 +- src/qt/qt_harddiskdialog.cpp | 76 +++++++++++++++++++----------------- src/qt/qt_harddiskdialog.hpp | 2 +- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/qt/qt_filefield.cpp b/src/qt/qt_filefield.cpp index 9bdb6cd7f..b6db5e611 100644 --- a/src/qt/qt_filefield.cpp +++ b/src/qt/qt_filefield.cpp @@ -29,7 +29,7 @@ FileField::FileField(QWidget *parent) connect(ui->label, &QLineEdit::editingFinished, this, [this]() { fileName_ = ui->label->text(); - emit fileSelected(ui->label->text()); + emit fileSelected(ui->label->text(), true); }); this->setFixedWidth(this->sizeHint().width() + ui->pushButton->sizeHint().width()); } diff --git a/src/qt/qt_filefield.hpp b/src/qt/qt_filefield.hpp index 8520e3e57..ee011a38b 100644 --- a/src/qt/qt_filefield.hpp +++ b/src/qt/qt_filefield.hpp @@ -24,7 +24,7 @@ public: bool createFile() { return createFile_; } signals: - void fileSelected(const QString &fileName); + void fileSelected(const QString &fileName, bool precheck = false); private slots: void on_pushButton_clicked(); diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index 943b13dc0..e8ccccd6f 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -51,6 +51,40 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) { ui->setupUi(this); + auto *model = ui->comboBoxFormat->model(); + model->insertRows(0, 6); + model->setData(model->index(0, 0), tr("Raw image (.img)")); + model->setData(model->index(1, 0), tr("HDI image (.hdi)")); + model->setData(model->index(2, 0), tr("HDX image (.hdx)")); + model->setData(model->index(3, 0), tr("Fixed-size VHD (.vhd)")); + model->setData(model->index(4, 0), tr("Dynamic-size VHD (.vhd)")); + model->setData(model->index(5, 0), tr("Differencing VHD (.vhd)")); + + model = ui->comboBoxBlockSize->model(); + model->insertRows(0, 2); + model->setData(model->index(0, 0), tr("Large blocks (2 MB)")); + model->setData(model->index(1, 0), tr("Small blocks (512 KB)")); + + ui->comboBoxBlockSize->hide(); + ui->labelBlockSize->hide(); + + Harddrives::populateBuses(ui->comboBoxBus->model()); + ui->comboBoxBus->setCurrentIndex(3); + + model = ui->comboBoxType->model(); + for (int i = 0; i < 127; i++) { + uint64_t size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2]; + uint32_t size_mb = size >> 11LL; + // QString text = QString("%1 MiB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]); + QString text = QString::asprintf(tr("%u MB (CHS: %i, %i, %i)").toUtf8().constData(), (size_mb), (hdd_table[i][0]), (hdd_table[i][1]), (hdd_table[i][2])); + Models::AddEntry(model, text, i); + } + Models::AddEntry(model, tr("Custom..."), 127); + Models::AddEntry(model, tr("Custom (large)..."), 128); + + ui->lineEditSize->setValidator(new QIntValidator()); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + if (existing) { ui->fileField->setFilter(tr("Hard disk images") % util::DlgFilter({ "hd?", "im?", "vhd" }) % tr("All files") % util::DlgFilter({ "*" }, true)); @@ -85,40 +119,6 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); }); } - - auto *model = ui->comboBoxFormat->model(); - model->insertRows(0, 6); - model->setData(model->index(0, 0), tr("Raw image (.img)")); - model->setData(model->index(1, 0), tr("HDI image (.hdi)")); - model->setData(model->index(2, 0), tr("HDX image (.hdx)")); - model->setData(model->index(3, 0), tr("Fixed-size VHD (.vhd)")); - model->setData(model->index(4, 0), tr("Dynamic-size VHD (.vhd)")); - model->setData(model->index(5, 0), tr("Differencing VHD (.vhd)")); - - model = ui->comboBoxBlockSize->model(); - model->insertRows(0, 2); - model->setData(model->index(0, 0), tr("Large blocks (2 MB)")); - model->setData(model->index(1, 0), tr("Small blocks (512 KB)")); - - ui->comboBoxBlockSize->hide(); - ui->labelBlockSize->hide(); - - Harddrives::populateBuses(ui->comboBoxBus->model()); - ui->comboBoxBus->setCurrentIndex(3); - - model = ui->comboBoxType->model(); - for (int i = 0; i < 127; i++) { - uint64_t size = ((uint64_t) hdd_table[i][0]) * hdd_table[i][1] * hdd_table[i][2]; - uint32_t size_mb = size >> 11LL; - // QString text = QString("%1 MiB (CHS: %2, %3, %4)").arg(size_mb).arg(hdd_table[i][0]).arg(hdd_table[i][1]).arg(hdd_table[i][2]); - QString text = QString::asprintf(tr("%u MB (CHS: %i, %i, %i)").toUtf8().constData(), (size_mb), (hdd_table[i][0]), (hdd_table[i][1]), (hdd_table[i][2])); - Models::AddEntry(model, text, i); - } - Models::AddEntry(model, tr("Custom..."), 127); - Models::AddEntry(model, tr("Custom (large)..."), 128); - - ui->lineEditSize->setValidator(new QIntValidator()); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } HarddiskDialog::~HarddiskDialog() @@ -499,7 +499,7 @@ HarddiskDialog::recalcSelection() } void -HarddiskDialog::onExistingFileSelected(const QString &fileName) +HarddiskDialog::onExistingFileSelected(const QString &fileName, bool precheck) { // TODO : Over to non-existing file selected /* @@ -531,7 +531,11 @@ HarddiskDialog::onExistingFileSelected(const QString &fileName) ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { - QMessageBox::critical(this, tr("Unable to read file"), tr("Make sure the file exists and is readable.")); + // No message box during precheck (performed when the file input loses focus and this function is called) + // If precheck is false, the file has been chosen from a file dialog and the alert should display. + if(!precheck) { + QMessageBox::critical(this, tr("Unable to read file"), tr("Make sure the file exists and is readable.")); + } return; } QByteArray fileNameUtf8 = fileName.toUtf8(); diff --git a/src/qt/qt_harddiskdialog.hpp b/src/qt/qt_harddiskdialog.hpp index a630bd8e2..0d5fa13bc 100644 --- a/src/qt/qt_harddiskdialog.hpp +++ b/src/qt/qt_harddiskdialog.hpp @@ -37,7 +37,7 @@ private slots: void on_comboBoxBus_currentIndexChanged(int index); void on_comboBoxFormat_currentIndexChanged(int index); void onCreateNewFile(); - void onExistingFileSelected(const QString &fileName); + void onExistingFileSelected(const QString &fileName, bool precheck); private: Ui::HarddiskDialog *ui;