2019-09-27 00:09:09 -07:00
|
|
|
#include "common.h"
|
|
|
|
#include "quam/main_window.h"
|
|
|
|
#include "quam/pak.h"
|
|
|
|
|
2019-09-28 22:29:31 -07:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QErrorMessage>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
2019-09-27 00:09:09 -07:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow{parent},
|
2019-09-28 01:17:55 -07:00
|
|
|
Ui::MainWindow{},
|
2019-09-28 22:29:31 -07:00
|
|
|
m_directory{},
|
|
|
|
m_errors{new QErrorMessage{this}},
|
|
|
|
m_model{nullptr},
|
|
|
|
m_sorter{nullptr}
|
2019-09-27 00:09:09 -07:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2019-09-28 01:17:55 -07:00
|
|
|
|
2019-09-28 22:29:31 -07:00
|
|
|
actionClose->setShortcut(QKeySequence{QKeySequence::Close});
|
2019-09-28 03:54:04 -07:00
|
|
|
actionOpen->setShortcut(QKeySequence{QKeySequence::Open});
|
|
|
|
actionQuit->setShortcut(QKeySequence{QKeySequence::Quit});
|
|
|
|
|
2019-09-28 22:29:31 -07:00
|
|
|
tableView->sortByColumn(Pak::ColumnSize, Qt::AscendingOrder);
|
|
|
|
tableView->resizeColumnsToContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
2019-09-27 00:09:09 -07:00
|
|
|
}
|
|
|
|
|
2019-09-28 01:17:55 -07:00
|
|
|
void MainWindow::fileOpen() {
|
|
|
|
auto fileName =
|
|
|
|
QFileDialog::getOpenFileName(
|
|
|
|
this,
|
|
|
|
tr("Open Archive"),
|
|
|
|
QString{},
|
|
|
|
tr("Quake PACK file (*.pak);;"
|
2019-09-28 03:54:04 -07:00
|
|
|
"Quake WAD2 file (*.wad);;"
|
2019-09-28 01:17:55 -07:00
|
|
|
"All files (*)"));
|
|
|
|
|
|
|
|
if(!fileName.isEmpty()) {
|
|
|
|
try {
|
2019-09-28 22:29:31 -07:00
|
|
|
auto st = openReadBin(fileName.toStdString());
|
|
|
|
m_directory = readPak(st);
|
|
|
|
m_model = new PakDirModel{&m_directory, this};
|
|
|
|
m_sorter = new PakDirModelSorter{m_model};
|
|
|
|
m_sorter->setSourceModel(m_model);
|
|
|
|
tableView->setModel(m_sorter);
|
2019-09-28 01:17:55 -07:00
|
|
|
} catch(std::exception const &exc) {
|
2019-09-28 22:29:31 -07:00
|
|
|
m_errors->showMessage(tr(exc.what()));
|
2019-09-28 01:17:55 -07:00
|
|
|
}
|
|
|
|
}
|
2019-09-27 00:09:09 -07:00
|
|
|
}
|
|
|
|
|
2019-09-28 22:29:31 -07:00
|
|
|
void MainWindow::fileClose() {
|
|
|
|
tableView->setModel(nullptr);
|
|
|
|
delete m_sorter;
|
|
|
|
delete m_model;
|
|
|
|
m_directory = PakDir{};
|
|
|
|
}
|
|
|
|
|
2019-09-27 00:09:09 -07:00
|
|
|
// EOF
|