2019-09-27 00:09:09 -07:00
|
|
|
#include "common.h"
|
|
|
|
#include "quam/main_window.h"
|
|
|
|
#include "quam/pak.h"
|
|
|
|
|
2019-09-28 01:17:55 -07:00
|
|
|
static void setListToDir(QListWidget &list, PakDir const &dir) {
|
|
|
|
list.clear();
|
|
|
|
for(auto const &kv : dir) {
|
|
|
|
auto const &name = kv.first;
|
|
|
|
auto const &node = kv.second;
|
|
|
|
auto var = QVariant::fromValue(node);
|
|
|
|
auto item = new QListWidgetItem{&list};
|
|
|
|
item->setText(QString::fromStdString(name));
|
|
|
|
item->setData(Qt::UserRole, var);
|
|
|
|
if(std::holds_alternative<PakDir>(node)) {
|
|
|
|
item->setIcon(QIcon::fromTheme("folder"));
|
|
|
|
} else {
|
|
|
|
item->setIcon(QIcon::fromTheme("text-x-generic"));
|
|
|
|
}
|
|
|
|
list.addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 00:09:09 -07:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow{parent},
|
2019-09-28 01:17:55 -07:00
|
|
|
Ui::MainWindow{},
|
|
|
|
m_errors{}
|
2019-09-27 00:09:09 -07:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2019-09-28 01:17:55 -07:00
|
|
|
|
|
|
|
actionOpen->setShortcut(QKeySequence(QKeySequence::Open));
|
|
|
|
actionQuit->setShortcut(QKeySequence(QKeySequence::Quit));
|
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);;"
|
|
|
|
"All files (*)"));
|
|
|
|
|
|
|
|
if(!fileName.isEmpty()) {
|
|
|
|
try {
|
|
|
|
auto st = openReadBin(fileName.toStdString());
|
|
|
|
auto pak = readPak(st);
|
|
|
|
setListToDir(*listWidget, pak);
|
|
|
|
} catch(std::exception const &exc) {
|
|
|
|
m_errors.showMessage(tr(exc.what()));
|
|
|
|
}
|
|
|
|
}
|
2019-09-27 00:09:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|