[WIP] Implementing file loading through LoadDialog
MODIFY
src/loaddialog.cpp
src/loaddialog.cpp
@@ -54,13 +54,13 @@ LoadDialog::LoadDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::LoadDial
void LoadDialog::inputTypeChanged() {
auto* button = m_fileTypeButtons->checkedButton();
if (button == m_ui->assemblyRadioButton) {
- m_currentFileType = FileType::Assembly;
+ m_fileType = FileType::Assembly;
updateAssemblyPageState();
} else if (button == m_ui->binaryRadioButton) {
- m_currentFileType = FileType::FlatBinary;
+ m_fileType = FileType::FlatBinary;
updateBinaryPageState();
} else if (button == m_ui->elfRadioButton) {
- m_currentFileType = FileType::Executable;
+ m_fileType = FileType::Executable;
updateELFPageState();
}
validateCurrentFile();
@@ -68,19 +68,21 @@ void LoadDialog::inputTypeChanged() {
void LoadDialog::openFileButtonTriggered() {
QString title;
- QString filter = "*";
- switch (m_currentFileType) {
+ QString filter;
+ switch (m_fileType) {
case FileType::Assembly: {
title = "Open assembly file";
- filter = "Assembly file (*.s *.as *.asm)";
+ filter = "Assembly files [*.s, *.as, *.asm] (*.s *.as *.asm);; All files (*.*)";
break;
}
case FileType::FlatBinary: {
title = "Open binary file";
+ filter = "All files (*.*)";
break;
}
case FileType::Executable: {
title = "Open executable (ELF) file";
+ filter = "All files (*.*)";
break;
}
}
@@ -117,7 +119,7 @@ bool LoadDialog::validateELFFile(const QFile& file) {
}
bool LoadDialog::fileTypeValidate(const QFile& file) {
- switch (m_currentFileType) {
+ switch (m_fileType) {
case FileType::Assembly:
return validateAssemblyFile(file);
case FileType::FlatBinary:
@@ -143,12 +145,12 @@ void LoadDialog::loadFileError(const QString& filename) {
}
void LoadDialog::accept() {
- switch (m_currentFileType) {
- case FileType::Assembly:
- case FileType::FlatBinary:
- case FileType::Executable:
- break;
- }
+ // It is assumed that the currently selected file will always be valid for the currently selected type, if the
+ // accept button is enabled. No further validation is performed.
+ m_params.filepath = m_ui->filePath->text();
+ m_params.type = m_fileType;
+ m_params.binaryLoadAt = m_ui->binaryLoadAt->text().toUInt(nullptr, 16);
+ m_params.binaryEntryPoint = m_ui->binaryEntryPoint->text().toUInt(nullptr, 16);
QDialog::accept();
}

MODIFY
src/loaddialog.h
src/loaddialog.h
@@ -12,6 +12,13 @@ namespace Ui {
class LoadDialog;
}
+struct LoadFileParams {
+ QString filepath;
+ FileType type;
+ uint32_t binaryEntryPoint;
+ uint32_t binaryLoadAt;
+};
+
class LoadDialog : public QDialog {
Q_OBJECT
@@ -20,6 +27,7 @@ public:
~LoadDialog();
void accept() override;
+ const LoadFileParams& getParams() const { return m_params; }
private slots:
void validateCurrentFile();
@@ -40,9 +48,11 @@ private:
void paletteValidate(QWidget* w, bool valid);
- FileType m_currentFileType;
+ FileType m_fileType;
+ LoadFileParams m_params;
+
Ui::LoadDialog* m_ui;
QButtonGroup* m_fileTypeButtons = nullptr;
-};
+}; // namespace Ripes
} // namespace Ripes

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -159,8 +159,42 @@ void MainWindow::exit() {
void MainWindow::loadFileTriggered() {
LoadDialog diag;
- diag.exec();
+ if (!diag.exec())
+ return;
+
+ const auto& fileParams = diag.getParams();
+
+ switch (fileParams.type) {
+ case FileType::Assembly:
+ loadAssemblyFile(fileParams);
+ break;
+ case FileType::FlatBinary:
+ loadFlatBinaryFile(fileParams);
+ break;
+ case FileType::Executable:
+ loadElfFile(fileParams);
+ break;
}
+}
+
+void MainWindow::loadFlatBinaryFile(const LoadFileParams& params) {}
+
+void MainWindow::loadAssemblyFile(const LoadFileParams& params) {
+ // ... load file
+ QFile file(params.filepath);
+ m_editTab->setInputMode(true);
+ Parser::getParser()->clear();
+ m_editTab->clear();
+ m_processorTab->restart();
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ m_editTab->setAssemblyText(file.readAll());
+ file.close();
+ }
+ m_currentFile = params.filepath;
+ m_editTab->setDisassemblerText();
+}
+
+void MainWindow::loadElfFile(const LoadFileParams& params) {}
void MainWindow::loadBinaryFile(QString filename) {
m_editTab->setInputMode(false);
@@ -307,5 +341,5 @@ void MainWindow::newProgramTriggered() {
}
m_currentFile.clear();
m_editTab->newProgram();
-}
+} // namespace Ripes
} // namespace Ripes

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -18,6 +18,7 @@ class EditTab;
class MemoryTab;
class ProcessorTab;
class ProcessorHandler;
+struct LoadFileParams;
class MainWindow : public QMainWindow {
Q_OBJECT
@@ -51,6 +52,10 @@ signals:
void updateMemoryTab();
private:
+ void loadFlatBinaryFile(const LoadFileParams&);
+ void loadAssemblyFile(const LoadFileParams&);
+ void loadElfFile(const LoadFileParams&);
+
void loadFile(const QString& filename, FileType type);
void setupMenus();

[WIP] Implementing file loading through LoadDialog