A few steps towards better disk image handling. The flux file 'open' button

works now.
This commit is contained in:
David Given
2024-01-20 00:03:49 +01:00
parent 7f2913e8da
commit 61e83d5eba
5 changed files with 103 additions and 27 deletions

View File

@@ -6,6 +6,7 @@
#include "driveConfigurationForm.h"
#include "fluxConfigurationForm.h"
#include <QStandardItemModel>
#include <range/v3/all.hpp>
static const char* DRIVE = "drive/";
static const char* SELECTED_DRIVE = "drive/drive";
@@ -96,6 +97,33 @@ public:
&QLineEdit::editingFinished,
this,
&ConfigurationForm::updateSavedState);
connect(openButton,
&QPushButton::clicked,
[this]()
{
std::string formats = Config::getFluxFormats() |
ranges::views::transform(
[](const FluxConstructor& f)
{
return f.glob;
}) |
ranges::views::filter(
[](const std::string& s)
{
return !s.empty();
}) |
ranges::views::intersperse(" ") |
ranges::views::join |
ranges::to<std::string>();
QFileDialog dialogue(_dci->container());
dialogue.setFileMode(QFileDialog::ExistingFile);
dialogue.setNameFilter(QString::fromStdString("Flux files (" + formats + ")"));
QStringList fileNames;
if (dialogue.exec())
filenameEdit->setText(dialogue.selectedFiles().first());
});
}
void updateSavedState() const override

View File

@@ -33,7 +33,7 @@
<widget class="QLineEdit" name="filenameEdit"/>
</item>
<item>
<widget class="QToolButton" name="toolButton_7">
<widget class="QToolButton" name="openButton">
<property name="text">
<string>Open</string>
</property>
@@ -111,6 +111,9 @@
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>

View File

@@ -1,6 +1,7 @@
#include "lib/globals.h"
#include "lib/config.h"
#include "lib/readerwriter.h"
#include "lib/utils.h"
#include "globals.h"
#include "mainwindow.h"
#include "drivecomponent.h"
@@ -12,6 +13,14 @@ class MainWindowImpl : public MainWindow
{
W_OBJECT(MainWindowImpl)
private:
enum State
{
STATE_IDLE,
STATE_READING,
STATE_WRITING
};
public:
MainWindowImpl()
{
@@ -31,14 +40,20 @@ public:
_progressWidget->setAlignment(Qt::AlignRight);
statusbar->addPermanentWidget(_progressWidget);
auto* stopWidget = new QToolButton();
stopWidget->setText("Stop");
statusbar->addPermanentWidget(stopWidget);
_stopWidget = new QToolButton();
_stopWidget->setText("Stop");
statusbar->addPermanentWidget(_stopWidget);
connect(readDiskButton,
&QAbstractButton::clicked,
this,
&MainWindowImpl::readDisk);
connect(_stopWidget,
&QPushButton::clicked,
this,
&MainWindowImpl::emergencyStop);
setState(STATE_IDLE);
}
public:
@@ -61,24 +76,24 @@ public:
{
_fluxComponent->setDiskData(m.disk);
_imageComponent->setDiskData(m.disk);
_currentDisk = m.disk;
},
/* Large-scale operation start. */
[this](const BeginOperationLogMessage& m)
{
setProgressBar(0);
_progressWidget->setValue(0);
},
/* Large-scale operation end. */
[this](const EndOperationLogMessage& m)
{
finishedWithProgressBar();
},
/* Large-scale operation progress. */
[this](const OperationProgressLogMessage& m)
{
setProgressBar(m.progress);
_progressWidget->setValue(m.progress);
}},
*message);
@@ -87,18 +102,6 @@ public:
logViewerEdit->ensureCursorVisible();
}
void setProgressBar(int progress) override
{
_progressWidget->setEnabled(true);
_progressWidget->setValue(progress);
}
void finishedWithProgressBar() override
{
_progressWidget->setEnabled(false);
_progressWidget->setValue(0);
}
void collectConfig() override
{
try
@@ -113,9 +116,7 @@ public:
}
catch (...)
{
std::exception_ptr p = std::current_exception();
std::clog << (p ? p.__cxa_exception_type()->name() : "null")
<< std::endl;
log("Mysterious uncaught exception!");
}
}
@@ -126,22 +127,65 @@ private:
return;
collectConfig();
safeRunOnWorkerThread(
::emergencyStop = false;
setState(STATE_READING);
runThen(
[this]()
{
auto& fluxSource = globalConfig().getFluxSource();
auto& decoder = globalConfig().getDecoder();
auto diskflux = readDiskCommand(*fluxSource, *decoder);
},
[this]()
{
setState(STATE_IDLE);
});
}
W_SLOT(readDisk)
private:
void emergencyStop()
{
::emergencyStop = true;
}
W_SLOT(emergencyStop)
void setState(int state)
{
_stopWidget->setEnabled(state != STATE_IDLE);
_progressWidget->setEnabled(state != STATE_IDLE);
diskOperationsGroup->setEnabled(state == STATE_IDLE);
memoryOperationsGroup->setEnabled(state == STATE_IDLE);
driveWindow->setEnabled(state == STATE_IDLE);
formatWindow->setEnabled(state == STATE_IDLE);
_state = state;
}
W_SLOT(setState)
private:
void runThen(
std::function<void()> workCb, std::function<void()> completionCb)
{
QFutureWatcher<void>* watcher = new QFutureWatcher<void>(this);
watcher->setFuture(safeRunOnWorkerThread(workCb));
connect(watcher, &QFutureWatcher<void>::finished, completionCb);
connect(watcher,
&QFutureWatcher<void>::finished,
watcher,
&QFutureWatcher<void>::deleteLater);
}
private:
DriveComponent* _driveComponent;
FormatComponent* _formatComponent;
FluxComponent* _fluxComponent;
ImageComponent* _imageComponent;
QAbstractButton* _stopWidget;
QProgressBar* _progressWidget;
std::shared_ptr<const DiskFlux> _currentDisk;
int _state;
};
W_OBJECT_IMPL(MainWindowImpl)

View File

@@ -10,7 +10,5 @@ public:
public:
virtual void logMessage(std::shared_ptr<const AnyLogMessage> message) = 0;
virtual void setProgressBar(int progress) = 0;
virtual void finishedWithProgressBar() = 0;
virtual void collectConfig() = 0;
};

View File

@@ -65,7 +65,7 @@
</spacer>
</item>
<item row="6" column="3">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="memoryOperationsGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
@@ -134,7 +134,10 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="diskOperationsGroup">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>