From a570f01d973466f8787fdc9855f5a4122644263f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sun, 6 Feb 2022 00:37:24 +0600 Subject: [PATCH] Hard disk dialog improvements * Fix file field widget * Hard disk dialog is now identical to Win32 --- src/qt/qt_filefield.cpp | 5 +- src/qt/qt_filefield.hpp | 1 + src/qt/qt_harddiskdialog.cpp | 49 ++++--- src/qt/qt_harddiskdialog.hpp | 4 +- src/qt/qt_harddiskdialog.ui | 255 ++++++++++++++++++----------------- 5 files changed, 176 insertions(+), 138 deletions(-) diff --git a/src/qt/qt_filefield.cpp b/src/qt/qt_filefield.cpp index 2d7268d97..770a244e0 100644 --- a/src/qt/qt_filefield.cpp +++ b/src/qt/qt_filefield.cpp @@ -9,7 +9,10 @@ FileField::FileField(QWidget *parent) : { ui->setupUi(this); - connect(ui->label, &QLineEdit::editingFinished, this, [this] () { emit fileSelected(ui->label->text()); }); + connect(ui->label, &QLineEdit::editingFinished, this, [this] () { + fileName_ = ui->label->text(); + emit fileSelected(ui->label->text()); + }); } FileField::~FileField() diff --git a/src/qt/qt_filefield.hpp b/src/qt/qt_filefield.hpp index df68c1e02..00c4a5e12 100644 --- a/src/qt/qt_filefield.hpp +++ b/src/qt/qt_filefield.hpp @@ -22,6 +22,7 @@ public: QString selectedFilter() const { return selectedFilter_; } void setCreateFile(bool createFile) { createFile_ = createFile; } + bool createFile() { return createFile_; } signals: void fileSelected(const QString& fileName); diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index 288c4b0d8..2ed784a42 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -47,7 +47,6 @@ HarddiskDialog::HarddiskDialog(bool existing, QWidget *parent) : } else { setWindowTitle(tr("Add New Hard Disk")); ui->fileField->setCreateFile(true); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HarddiskDialog::onCreateNewFile); } auto* model = ui->comboBoxFormat->model(); @@ -248,6 +247,14 @@ static MVHDGeom create_drive_vhd_diff(const QString& fileName, const QString& pa } void HarddiskDialog::onCreateNewFile() { + + for (auto& curObject : children()) + { + if (qobject_cast(curObject)) qobject_cast(curObject)->setDisabled(true); + } + + ui->progressBar->setEnabled(true); + setResult(QDialog::Rejected); qint64 size = ui->lineEditSize->text().toUInt() << 20U; if (size > 0x1FFFFFFE00ll) { QMessageBox::critical(this, tr("Disk image too large"), tr("Disk images cannot be larger than 127 GB.")); @@ -323,18 +330,16 @@ void HarddiskDialog::onCreateNewFile() { } else if (img_format >= 3) { /* VHD file */ file.close(); - MVHDGeom _86box_geometry; + MVHDGeom _86box_geometry{}; int block_size = ui->comboBoxBlockSize->currentIndex() == 0 ? MVHD_BLOCK_LARGE : MVHD_BLOCK_SMALL; switch (img_format) { case 3: { - QProgressDialog progress(tr("86Box"), QString(), 0, 100, this); - connect(this, &HarddiskDialog::fileProgress, &progress, &QProgressDialog::setValue); - std::thread writer([&_86box_geometry, fileName, this] { + connect(this, &HarddiskDialog::fileProgress, this, [this] (int value) { ui->progressBar->setValue(value); QApplication::processEvents(); } ); + ui->progressBar->setVisible(true); + [&_86box_geometry, fileName, this] { _86box_geometry = create_drive_vhd_fixed(fileName, this, cylinders_, heads_, sectors_); - }); - progress.exec(); - writer.join(); + }(); } break; case 4: @@ -357,7 +362,14 @@ void HarddiskDialog::onCreateNewFile() { break; } - if (img_format != 5) { + if (_86box_geometry.cyl == 0 && + _86box_geometry.heads == 0 && + _86box_geometry.spt == 0) + { + QMessageBox::critical(this, tr("Unable to write file"), tr("Make sure the file is being saved to a writable directory.")); + return; + } + else if (img_format != 5) { QMessageBox::information(this, tr("Disk image created"), tr("Remember to partition and format the newly-created drive.")); } @@ -367,14 +379,15 @@ void HarddiskDialog::onCreateNewFile() { cylinders_ = _86box_geometry.cyl; heads_ = _86box_geometry.heads; sectors_ = _86box_geometry.spt; + setResult(QDialog::Accepted); return; } // formats 0, 1 and 2 - QProgressDialog progress(tr("86Box"), QString(), 0, 100, this); - connect(this, &HarddiskDialog::fileProgress, &progress, &QProgressDialog::setValue); - std::thread writer([size, &file, this] { + connect(this, &HarddiskDialog::fileProgress, this, [this] (int value) { ui->progressBar->setValue(value); QApplication::processEvents(); } ); + ui->progressBar->setVisible(true); + [size, &file, this] { QDataStream stream(&file); stream.setByteOrder(QDataStream::LittleEndian); @@ -393,11 +406,10 @@ void HarddiskDialog::onCreateNewFile() { } } emit fileProgress(100); - }); + }(); - progress.exec(); - writer.join(); QMessageBox::information(this, tr("Disk image created"), tr("Remember to partition and format the newly-created drive.")); + setResult(QDialog::Accepted); } static void adjust_vhd_geometry_for_86box(MVHDGeom *vhd_geometry) { @@ -718,3 +730,10 @@ void HarddiskDialog::on_comboBoxType_currentIndexChanged(int index) { checkAndAdjustHeads(); checkAndAdjustSectors(); } + +void HarddiskDialog::accept() +{ + if (ui->fileField->createFile()) onCreateNewFile(); + else setResult(QDialog::Accepted); + QDialog::done(result()); +} diff --git a/src/qt/qt_harddiskdialog.hpp b/src/qt/qt_harddiskdialog.hpp index e6ced50fb..321dc4708 100644 --- a/src/qt/qt_harddiskdialog.hpp +++ b/src/qt/qt_harddiskdialog.hpp @@ -25,6 +25,9 @@ public: signals: void fileProgress(int i); +public slots: + void accept() override; + private slots: void on_comboBoxType_currentIndexChanged(int index); void on_lineEditSectors_textEdited(const QString &arg1); @@ -35,7 +38,6 @@ private slots: void on_comboBoxFormat_currentIndexChanged(int index); void onCreateNewFile(); void onExistingFileSelected(const QString& fileName); - private: Ui::HarddiskDialog *ui; diff --git a/src/qt/qt_harddiskdialog.ui b/src/qt/qt_harddiskdialog.ui index b3b1c0f60..0d069ec17 100644 --- a/src/qt/qt_harddiskdialog.ui +++ b/src/qt/qt_harddiskdialog.ui @@ -6,18 +6,107 @@ 0 0 - 393 - 223 + 421 + 269 Dialog - - + + + + + - Heads: + Channel: + + + + + + + Sectors: + + + + + + + Type: + + + + + + + + 0 + 0 + + + + + 64 + 16777215 + + + + + + + + + 0 + 0 + + + + + 64 + 16777215 + + + + + + + + Size (MB): + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + Cylinders: @@ -40,75 +129,6 @@ - - - - - - - - - - File name: - - - - - - - - 0 - 0 - - - - - 64 - 16777215 - - - - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Cylinders: - - - - - - - Channel: - - - @@ -116,22 +136,16 @@ - - - - - 0 - 0 - - - - - 64 - 16777215 - + + + + Heads: + + + @@ -139,39 +153,11 @@ - - + + - - - - Sectors: - - - - - - - Block Size: - - - - - - - - - - Type: - - - - - - - Size (MB): - - + + @@ -192,8 +178,35 @@ - - + + + + + + + Block Size: + + + + + + + File name: + + + + + + + 0 + + + true + + + false + +