mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-04 07:40:10 +01:00
191 lines
5.3 KiB
C++
191 lines
5.3 KiB
C++
#include "pkg_install_dialog.h"
|
|
#include "game_compatibility.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QPushButton>
|
|
#include <QFileInfo>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QToolButton>
|
|
|
|
enum Roles
|
|
{
|
|
FullPathRole = Qt::UserRole + 0,
|
|
BaseDisplayRole = Qt::UserRole + 1,
|
|
ChangelogRole = Qt::UserRole + 2,
|
|
TitleRole = Qt::UserRole + 3,
|
|
TitleIdRole = Qt::UserRole + 4,
|
|
VersionRole = Qt::UserRole + 5,
|
|
};
|
|
|
|
pkg_install_dialog::pkg_install_dialog(const QStringList& paths, game_compatibility* compat, QWidget* parent)
|
|
: QDialog(parent)
|
|
{
|
|
m_dir_list = new QListWidget(this);
|
|
|
|
class numbered_widget_item final : public QListWidgetItem
|
|
{
|
|
public:
|
|
explicit numbered_widget_item(const QString& text, QListWidget* listview = nullptr, int type = QListWidgetItem::Type)
|
|
: QListWidgetItem(text, listview, type)
|
|
{
|
|
}
|
|
|
|
QVariant data(int role) const override
|
|
{
|
|
QVariant result;
|
|
switch (role)
|
|
{
|
|
case Qt::DisplayRole:
|
|
result = QStringLiteral("%1. %2").arg(listWidget()->row(this) + 1).arg(data(Roles::BaseDisplayRole).toString());
|
|
break;
|
|
case Roles::BaseDisplayRole:
|
|
result = QListWidgetItem::data(Qt::DisplayRole);
|
|
break;
|
|
default:
|
|
result = QListWidgetItem::data(role);
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool operator<(const QListWidgetItem& other) const override
|
|
{
|
|
return data(Roles::BaseDisplayRole).toString() < other.data(Roles::BaseDisplayRole).toString();
|
|
}
|
|
};
|
|
|
|
for (const QString& path : paths)
|
|
{
|
|
const compat::package_info info = game_compatibility::GetPkgInfo(path, compat);
|
|
|
|
QString tooltip;
|
|
QString version = info.version;
|
|
|
|
if (info.changelog.isEmpty())
|
|
{
|
|
tooltip = tr("No info");
|
|
}
|
|
else
|
|
{
|
|
tooltip = tr("Changelog:\n\n%0").arg(info.changelog);
|
|
}
|
|
|
|
if (!version.isEmpty())
|
|
{
|
|
version = tr("v.%0").arg(info.version);
|
|
}
|
|
|
|
const QString text = tr("%0 (%1 %2)").arg(info.title).arg(info.title_id).arg(version);
|
|
|
|
QListWidgetItem* item = new numbered_widget_item(text, m_dir_list);
|
|
item->setData(Roles::FullPathRole, info.path);
|
|
item->setData(Roles::ChangelogRole, info.changelog);
|
|
item->setData(Roles::TitleRole, info.title);
|
|
item->setData(Roles::TitleIdRole, info.title_id);
|
|
item->setData(Roles::VersionRole, info.version);
|
|
item->setToolTip(tooltip);
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
item->setCheckState(Qt::Checked);
|
|
}
|
|
|
|
m_dir_list->sortItems();
|
|
m_dir_list->setCurrentRow(0);
|
|
m_dir_list->setMinimumWidth((m_dir_list->sizeHintForColumn(0) * 125) / 100);
|
|
|
|
// Create buttons
|
|
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
|
buttons->button(QDialogButtonBox::Ok)->setText(tr("Install"));
|
|
buttons->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
connect(buttons, &QDialogButtonBox::clicked, this, [this, buttons](QAbstractButton* button)
|
|
{
|
|
if (button == buttons->button(QDialogButtonBox::Ok))
|
|
{
|
|
accept();
|
|
}
|
|
else if (button == buttons->button(QDialogButtonBox::Cancel))
|
|
{
|
|
reject();
|
|
}
|
|
});
|
|
|
|
connect(m_dir_list, &QListWidget::itemChanged, this, [this, buttons](QListWidgetItem*)
|
|
{
|
|
bool any_checked = false;
|
|
for (int i = 0; i < m_dir_list->count(); i++)
|
|
{
|
|
if (m_dir_list->item(i)->checkState() == Qt::Checked)
|
|
{
|
|
any_checked = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
buttons->button(QDialogButtonBox::Ok)->setEnabled(any_checked);
|
|
});
|
|
|
|
QToolButton* move_up = new QToolButton;
|
|
move_up->setArrowType(Qt::UpArrow);
|
|
move_up->setToolTip(tr("Move selected item up"));
|
|
connect(move_up, &QToolButton::clicked, this, [this]() { MoveItem(-1); });
|
|
|
|
QToolButton* move_down = new QToolButton;
|
|
move_down->setArrowType(Qt::DownArrow);
|
|
move_down->setToolTip(tr("Move selected item down"));
|
|
connect(move_down, &QToolButton::clicked, this, [this]() { MoveItem(1); });
|
|
|
|
QHBoxLayout* hbox = new QHBoxLayout;
|
|
hbox->addStretch();
|
|
hbox->addWidget(move_up);
|
|
hbox->addWidget(move_down);
|
|
|
|
QLabel* description = new QLabel(tr("You are about to install multiple packages.\nReorder and/or exclude them if needed, then click \"Install\" to proceed."));
|
|
|
|
QVBoxLayout* vbox = new QVBoxLayout;
|
|
vbox->addWidget(description);
|
|
vbox->addLayout(hbox);
|
|
vbox->addWidget(m_dir_list);
|
|
vbox->addWidget(buttons);
|
|
|
|
setLayout(vbox);
|
|
setWindowTitle(tr("Batch PKG Installation"));
|
|
setObjectName("pkg_install_dialog");
|
|
}
|
|
|
|
void pkg_install_dialog::MoveItem(int offset)
|
|
{
|
|
const int src_index = m_dir_list->currentRow();
|
|
const int dest_index = src_index + offset;
|
|
|
|
if (src_index >= 0 && src_index < m_dir_list->count() &&
|
|
dest_index >= 0 && dest_index < m_dir_list->count())
|
|
{
|
|
QListWidgetItem* item = m_dir_list->takeItem(src_index);
|
|
m_dir_list->insertItem(dest_index, item);
|
|
m_dir_list->setCurrentItem(item);
|
|
}
|
|
}
|
|
|
|
std::vector<compat::package_info> pkg_install_dialog::GetPathsToInstall() const
|
|
{
|
|
std::vector<compat::package_info> result;
|
|
|
|
for (int i = 0; i < m_dir_list->count(); i++)
|
|
{
|
|
const QListWidgetItem* item = m_dir_list->item(i);
|
|
if (item && item->checkState() == Qt::Checked)
|
|
{
|
|
compat::package_info info;
|
|
info.path = item->data(Roles::FullPathRole).toString();
|
|
info.title = item->data(Roles::TitleRole).toString();
|
|
info.title_id = item->data(Roles::TitleIdRole).toString();
|
|
info.changelog = item->data(Roles::ChangelogRole).toString();
|
|
info.version = item->data(Roles::VersionRole).toString();
|
|
result.push_back(info);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|