2022-01-14 23:05:02 +00:00
|
|
|
#include "QBootablesView.h"
|
2022-01-16 14:54:21 +00:00
|
|
|
#include "ui_bootableview.h"
|
2022-01-13 23:58:16 +00:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
|
|
|
#include "CoverUtils.h"
|
|
|
|
#include "ui_shared/BootablesProcesses.h"
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
QBootablesView::QBootablesView(QWidget* parent)
|
2022-01-16 14:54:21 +00:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::QBootablesView)
|
2022-01-13 23:58:16 +00:00
|
|
|
|
2022-01-16 14:54:21 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->listView->setStyleSheet("QListView{ background:QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #4baaf3, stop: 1 #0A0A0A); }");
|
2022-01-14 00:13:17 +00:00
|
|
|
|
2022-01-13 23:58:16 +00:00
|
|
|
// used as workaround to avoid direct ui access from a thread
|
|
|
|
connect(this, SIGNAL(AsyncUpdateCoverDisplay()), this, SLOT(UpdateCoverDisplay()));
|
|
|
|
connect(this, SIGNAL(AsyncResetModel(bool)), this, SLOT(resetModel(bool)));
|
|
|
|
|
2022-01-16 14:54:21 +00:00
|
|
|
ui->listView->setContextMenuPolicy(Qt::ActionsContextMenu);
|
2022-01-13 23:58:16 +00:00
|
|
|
|
2022-01-16 14:54:21 +00:00
|
|
|
ui->listView->setItemDelegate(new BootImageItemDelegate);
|
2022-01-13 23:58:16 +00:00
|
|
|
|
|
|
|
m_bootables = BootablesDb::CClient::GetInstance().GetBootables(BootablesDb::CClient::SORT_METHOD::SORT_METHOD_RECENT);
|
|
|
|
|
|
|
|
CoverUtils::PopulatePlaceholderCover();
|
|
|
|
AsyncPopulateCache();
|
|
|
|
|
|
|
|
auto model = new BootableModel(this, m_bootables);
|
2022-01-16 14:54:21 +00:00
|
|
|
ui->listView->setModel(model);
|
2022-01-13 23:58:16 +00:00
|
|
|
|
2022-01-16 14:54:21 +00:00
|
|
|
connect(ui->listView, &QAbstractItemView::doubleClicked, this, &QBootablesView::DoubleClicked);
|
2022-01-13 23:58:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
QBootablesView::~QBootablesView()
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
|
|
|
if(m_coverLoader.joinable())
|
|
|
|
m_coverLoader.join();
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
void QBootablesView::AddAction(std::string name, Callback callback)
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
|
|
|
auto action = new QAction(name.c_str(), this);
|
2022-01-16 14:54:21 +00:00
|
|
|
auto listViewBoundCallback = [listView = ui->listView, callback](bool val) {
|
|
|
|
callback(listView, val);
|
|
|
|
};
|
|
|
|
connect(action, &QAction::triggered, listViewBoundCallback);
|
|
|
|
ui->listView->addAction(action);
|
2022-01-13 23:58:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
void QBootablesView::AddBootAction(Callback callback)
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
|
|
|
auto action = new QAction("Boot", this);
|
2022-01-16 14:54:21 +00:00
|
|
|
auto listViewBoundCallback = [listView = ui->listView, callback](bool val) {
|
|
|
|
callback(listView, val);
|
|
|
|
};
|
|
|
|
connect(action, &QAction::triggered, listViewBoundCallback);
|
|
|
|
ui->listView->addAction(action);
|
2022-01-13 23:58:16 +00:00
|
|
|
m_bootCallback = callback;
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
void QBootablesView::DoubleClicked(const QModelIndex&)
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
|
|
|
// we assume, selection will change on click, thus we can ignore the index
|
2022-01-16 14:54:21 +00:00
|
|
|
m_bootCallback(ui->listView, true);
|
2022-01-13 23:58:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
void QBootablesView::AsyncPopulateCache()
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
|
|
|
if(!m_threadRunning)
|
|
|
|
{
|
|
|
|
if(m_coverLoader.joinable())
|
|
|
|
m_coverLoader.join();
|
|
|
|
|
|
|
|
m_threadRunning = true;
|
|
|
|
m_coverLoader = std::thread([&] {
|
|
|
|
CoverUtils::PopulateCache(m_bootables);
|
|
|
|
|
|
|
|
AsyncUpdateCoverDisplay();
|
|
|
|
m_threadRunning = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:05:02 +00:00
|
|
|
void QBootablesView::resizeEvent(QResizeEvent* ev)
|
2022-01-13 23:58:16 +00:00
|
|
|
{
|
2022-01-16 14:54:21 +00:00
|
|
|
static_cast<BootableModel*>(ui->listView->model())->SetWidth(size().width() - style()->pixelMetric(QStyle::PM_ScrollBarExtent) - 5);
|
|
|
|
QWidget::resizeEvent(ev);
|
2022-01-13 23:58:16 +00:00
|
|
|
}
|