2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
#include "filetreewindow.h"
|
|
|
|
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QHBoxLayout>
|
2023-10-12 20:42:59 -04:00
|
|
|
#include <QLineEdit>
|
2023-04-09 15:32:09 -04:00
|
|
|
#include <QMenu>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QTreeWidget>
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 20:30:17 -04:00
|
|
|
FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent)
|
2023-10-10 18:02:13 -04:00
|
|
|
: QWidget(parent)
|
2023-10-12 20:42:59 -04:00
|
|
|
, m_gamePath(gamePath)
|
2023-10-10 18:02:13 -04:00
|
|
|
, data(data)
|
|
|
|
{
|
2023-10-12 20:42:59 -04:00
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2023-04-09 15:32:09 -04:00
|
|
|
setLayout(layout);
|
|
|
|
|
2023-10-12 20:42:59 -04:00
|
|
|
m_searchModel = new QSortFilterProxyModel();
|
|
|
|
m_searchModel->setRecursiveFilteringEnabled(true);
|
|
|
|
m_searchModel->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
|
|
|
|
|
|
|
auto searchLayout = new QHBoxLayout();
|
|
|
|
layout->addLayout(searchLayout);
|
|
|
|
|
|
|
|
auto searchEdit = new QLineEdit();
|
|
|
|
searchEdit->setPlaceholderText(QStringLiteral("Search..."));
|
|
|
|
searchEdit->setClearButtonEnabled(true);
|
|
|
|
connect(searchEdit, &QLineEdit::textChanged, this, [this](const QString &text) {
|
|
|
|
m_searchModel->setFilterRegularExpression(text);
|
|
|
|
});
|
|
|
|
searchLayout->addWidget(searchEdit);
|
|
|
|
|
|
|
|
m_unknownCheckbox = new QCheckBox();
|
|
|
|
m_unknownCheckbox->setToolTip(QStringLiteral("Show unknown files and folders."));
|
|
|
|
connect(m_unknownCheckbox, &QCheckBox::clicked, this, [this] {
|
|
|
|
refreshModel();
|
|
|
|
});
|
|
|
|
searchLayout->addWidget(m_unknownCheckbox);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
auto treeWidget = new QTreeView();
|
2023-10-12 20:42:59 -04:00
|
|
|
treeWidget->setModel(m_searchModel);
|
2023-10-12 19:04:19 -04:00
|
|
|
layout->addWidget(treeWidget);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
|
|
|
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
2023-10-10 18:02:13 -04:00
|
|
|
connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, [this, treeWidget](const QPoint &pos) {
|
2023-10-12 19:04:19 -04:00
|
|
|
auto index = treeWidget->indexAt(pos);
|
2023-04-09 15:32:09 -04:00
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
if (index.isValid()) {
|
|
|
|
auto path = m_fileModel->data(index, Qt::UserRole).toString();
|
2023-04-09 15:32:09 -04:00
|
|
|
|
|
|
|
auto menu = new QMenu();
|
|
|
|
|
2023-10-12 19:04:19 -04:00
|
|
|
auto extractAction = menu->addAction(QStringLiteral("Extract.."));
|
|
|
|
connect(extractAction, &QAction::triggered, this, [=] {
|
|
|
|
Q_EMIT extractFile(path);
|
|
|
|
});
|
|
|
|
|
2023-04-09 15:32:09 -04:00
|
|
|
menu->exec(treeWidget->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
});
|
2023-10-12 19:46:58 -04:00
|
|
|
|
|
|
|
connect(treeWidget, &QTreeView::clicked, [this, treeWidget](const QModelIndex &item) {
|
|
|
|
if (item.isValid()) {
|
2023-10-12 21:33:32 -04:00
|
|
|
auto path = m_searchModel->data(item, Qt::UserRole).toString();
|
2023-10-12 19:46:58 -04:00
|
|
|
Q_EMIT pathSelected(path);
|
|
|
|
}
|
|
|
|
});
|
2023-10-12 20:42:59 -04:00
|
|
|
|
|
|
|
refreshModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileTreeWindow::refreshModel()
|
|
|
|
{
|
|
|
|
// TODO: this should really be handled by the proxy
|
|
|
|
m_fileModel = new FileTreeModel(m_unknownCheckbox->isChecked(), m_gamePath, data);
|
|
|
|
m_searchModel->setSourceModel(m_fileModel);
|
2023-04-09 15:32:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_filetreewindow.cpp"
|