Hard disk dialog improvements

* Fix file field widget
* Hard disk dialog is now identical to Win32
This commit is contained in:
Cacodemon345
2022-02-06 00:37:24 +06:00
parent 6ffa0a9640
commit a570f01d97
5 changed files with 176 additions and 138 deletions

View File

@@ -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()

View File

@@ -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);

View File

@@ -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<QWidget*>(curObject)) qobject_cast<QWidget*>(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());
}

View File

@@ -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;

View File

@@ -6,18 +6,107 @@
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>223</height>
<width>421</width>
<height>269</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="2">
<widget class="QLabel" name="label_4">
<item row="0" column="1" colspan="5">
<widget class="FileField" name="fileField" native="true"/>
</item>
<item row="5" column="4">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Heads:</string>
<string>Channel:</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Sectors:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditCylinders">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEditSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size (MB):</string>
</property>
</widget>
</item>
<item row="5" column="5">
<widget class="QComboBox" name="comboBoxChannel"/>
</item>
<item row="11" column="0" colspan="6">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="9" column="0" colspan="6">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Cylinders:</string>
</property>
</widget>
</item>
@@ -40,75 +129,6 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxFormat"/>
</item>
<item row="5" column="5">
<widget class="QComboBox" name="comboBoxChannel"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditCylinders">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="8" column="0" colspan="6">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxBlockSize"/>
</item>
<item row="9" column="0" colspan="6">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Cylinders:</string>
</property>
</widget>
</item>
<item row="5" column="4">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Channel:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelFormat">
<property name="text">
@@ -116,22 +136,16 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEditSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
<item row="3" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Heads:</string>
</property>
</widget>
</item>
<item row="4" column="3" colspan="3">
<widget class="QComboBox" name="comboBoxType"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
@@ -139,39 +153,11 @@
</property>
</widget>
</item>
<item row="5" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxBus"/>
<item row="6" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxFormat"/>
</item>
<item row="3" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Sectors:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelBlockSize">
<property name="text">
<string>Block Size:</string>
</property>
</widget>
</item>
<item row="4" column="3" colspan="3">
<widget class="QComboBox" name="comboBoxType"/>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size (MB):</string>
</property>
</widget>
<item row="7" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxBlockSize"/>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="lineEditHeads">
@@ -192,8 +178,35 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="5">
<widget class="FileField" name="fileField" native="true"/>
<item row="5" column="1" colspan="3">
<widget class="QComboBox" name="comboBoxBus"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelBlockSize">
<property name="text">
<string>Block Size:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="6">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="visible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>