55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
#include "common.h"
|
|
#include "quam/main_window.h"
|
|
#include "quam/pak.h"
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
QMainWindow{parent},
|
|
Ui::MainWindow{},
|
|
m_errors{}
|
|
{
|
|
setupUi(this);
|
|
|
|
actionOpen->setShortcut(QKeySequence(QKeySequence::Open));
|
|
actionQuit->setShortcut(QKeySequence(QKeySequence::Quit));
|
|
}
|
|
|
|
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()));
|
|
}
|
|
}
|
|
}
|
|
|
|
// EOF
|