mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
Merge pull request #2989 from Trial97/what
add extra protection against empty download link
This commit is contained in:
@ -39,6 +39,7 @@
|
||||
|
||||
#include "ResourcePage.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui_ResourcePage.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
@ -54,7 +55,7 @@
|
||||
namespace ResourceDownload {
|
||||
|
||||
ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_instance)
|
||||
: QWidget(parent), m_base_instance(base_instance), m_ui(new Ui::ResourcePage), m_parent_dialog(parent), m_fetch_progress(this, false)
|
||||
: QWidget(parent), m_baseInstance(base_instance), m_ui(new Ui::ResourcePage), m_parentDialog(parent), m_fetchProgress(this, false)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@ -63,18 +64,18 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
|
||||
m_ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||
|
||||
m_search_timer.setTimerType(Qt::TimerType::CoarseTimer);
|
||||
m_search_timer.setSingleShot(true);
|
||||
m_searchTimer.setTimerType(Qt::TimerType::CoarseTimer);
|
||||
m_searchTimer.setSingleShot(true);
|
||||
|
||||
connect(&m_search_timer, &QTimer::timeout, this, &ResourcePage::triggerSearch);
|
||||
connect(&m_searchTimer, &QTimer::timeout, this, &ResourcePage::triggerSearch);
|
||||
|
||||
// hide progress bar to prevent weird artifact
|
||||
m_fetch_progress.hide();
|
||||
m_fetch_progress.hideIfInactive(true);
|
||||
m_fetch_progress.setFixedHeight(24);
|
||||
m_fetch_progress.progressFormat("");
|
||||
m_fetchProgress.hide();
|
||||
m_fetchProgress.hideIfInactive(true);
|
||||
m_fetchProgress.setFixedHeight(24);
|
||||
m_fetchProgress.progressFormat("");
|
||||
|
||||
m_ui->verticalLayout->insertWidget(1, &m_fetch_progress);
|
||||
m_ui->verticalLayout->insertWidget(1, &m_fetchProgress);
|
||||
|
||||
m_ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
||||
m_ui->packView->installEventFilter(this);
|
||||
@ -120,10 +121,10 @@ auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
} else {
|
||||
if (m_search_timer.isActive())
|
||||
m_search_timer.stop();
|
||||
if (m_searchTimer.isActive())
|
||||
m_searchTimer.stop();
|
||||
|
||||
m_search_timer.start(350);
|
||||
m_searchTimer.start(350);
|
||||
}
|
||||
} else if (watched == m_ui->packView) {
|
||||
if (keyEvent->key() == Qt::Key_Return) {
|
||||
@ -247,7 +248,7 @@ void ResourcePage::updateUi()
|
||||
|
||||
void ResourcePage::updateSelectionButton()
|
||||
{
|
||||
if (!isOpened || m_selected_version_index < 0) {
|
||||
if (!isOpened || m_selectedVersionIndex < 0) {
|
||||
m_ui->resourceSelectionButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
@ -257,7 +258,7 @@ void ResourcePage::updateSelectionButton()
|
||||
if (current_pack->versionsLoaded && current_pack->versions.empty()) {
|
||||
m_ui->resourceSelectionButton->setEnabled(false);
|
||||
qWarning() << tr("No version available for the selected pack");
|
||||
} else if (!current_pack->isVersionSelected(m_selected_version_index))
|
||||
} else if (!current_pack->isVersionSelected(m_selectedVersionIndex))
|
||||
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
|
||||
else
|
||||
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
|
||||
@ -326,18 +327,18 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
||||
|
||||
void ResourcePage::onVersionSelectionChanged(int index)
|
||||
{
|
||||
m_selected_version_index = index;
|
||||
m_selectedVersionIndex = m_ui->versionSelectionBox->itemData(index).toInt();
|
||||
updateSelectionButton();
|
||||
}
|
||||
|
||||
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack::Ptr pack, ModPlatform::IndexedVersion& version)
|
||||
{
|
||||
m_parent_dialog->addResource(pack, version);
|
||||
m_parentDialog->addResource(pack, version);
|
||||
}
|
||||
|
||||
void ResourcePage::removeResourceFromDialog(const QString& pack_name)
|
||||
{
|
||||
m_parent_dialog->removeResource(pack_name);
|
||||
m_parentDialog->removeResource(pack_name);
|
||||
}
|
||||
|
||||
void ResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
||||
@ -354,14 +355,15 @@ void ResourcePage::removeResourceFromPage(const QString& name)
|
||||
|
||||
void ResourcePage::onResourceSelected()
|
||||
{
|
||||
if (m_selected_version_index < 0)
|
||||
if (m_selectedVersionIndex < 0)
|
||||
return;
|
||||
|
||||
auto current_pack = getCurrentPack();
|
||||
if (!current_pack || !current_pack->versionsLoaded)
|
||||
if (!current_pack || !current_pack->versionsLoaded || current_pack->versions.size() < m_selectedVersionIndex)
|
||||
return;
|
||||
|
||||
auto& version = current_pack->versions[m_selected_version_index];
|
||||
auto& version = current_pack->versions[m_selectedVersionIndex];
|
||||
Q_ASSERT(!version.downloadUrl.isNull());
|
||||
if (version.is_currently_selected)
|
||||
removeResourceFromDialog(current_pack->name);
|
||||
else
|
||||
@ -400,14 +402,14 @@ void ResourcePage::openUrl(const QUrl& url)
|
||||
}
|
||||
}
|
||||
|
||||
if (!page.isNull() && !m_do_not_jump_to_mod) {
|
||||
if (!page.isNull() && !m_doNotJumpToMod) {
|
||||
const QString slug = match.captured(1);
|
||||
|
||||
// ensure the user isn't opening the same mod
|
||||
if (auto current_pack = getCurrentPack(); current_pack && slug != current_pack->slug) {
|
||||
m_parent_dialog->selectPage(page);
|
||||
m_parentDialog->selectPage(page);
|
||||
|
||||
auto newPage = m_parent_dialog->selectedPage();
|
||||
auto newPage = m_parentDialog->selectedPage();
|
||||
|
||||
QLineEdit* searchEdit = newPage->m_ui->searchEdit;
|
||||
auto model = newPage->m_model;
|
||||
@ -451,7 +453,7 @@ void ResourcePage::openProject(QVariant projectID)
|
||||
m_ui->resourceFilterButton->hide();
|
||||
m_ui->packView->hide();
|
||||
m_ui->resourceSelectionButton->hide();
|
||||
m_do_not_jump_to_mod = true;
|
||||
m_doNotJumpToMod = true;
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
|
||||
@ -469,17 +471,19 @@ void ResourcePage::openProject(QVariant projectID)
|
||||
|
||||
connect(okBtn, &QPushButton::clicked, this, [this] {
|
||||
onResourceSelected();
|
||||
m_parent_dialog->accept();
|
||||
m_parentDialog->accept();
|
||||
});
|
||||
|
||||
connect(cancelBtn, &QPushButton::clicked, m_parent_dialog, &ResourceDownloadDialog::reject);
|
||||
connect(cancelBtn, &QPushButton::clicked, m_parentDialog, &ResourceDownloadDialog::reject);
|
||||
m_ui->gridLayout_4->addWidget(buttonBox, 1, 2);
|
||||
|
||||
auto jump = [this, okBtn] {
|
||||
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
[this, okBtn](int index) { okBtn->setEnabled(m_ui->versionSelectionBox->itemData(index).toInt() >= 0); });
|
||||
|
||||
auto jump = [this] {
|
||||
for (int row = 0; row < m_model->rowCount({}); row++) {
|
||||
const QModelIndex index = m_model->index(row);
|
||||
m_ui->packView->setCurrentIndex(index);
|
||||
okBtn->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
m_ui->packDescription->setText(tr("The resource was not found"));
|
||||
|
Reference in New Issue
Block a user