Merge pull request #367 from TheKodeToad/linkjumping
fix https://github.com/PrismLauncher/PrismLauncher/issues/363
This commit is contained in:
commit
46a8e18841
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -131,6 +132,8 @@ QList<BasePage*> ModDownloadDialog::getPages()
|
|||||||
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
||||||
pages.append(FlameModPage::create(this, m_instance));
|
pages.append(FlameModPage::create(this, m_instance));
|
||||||
|
|
||||||
|
m_selectedPage = dynamic_cast<ModPage*>(pages[0]);
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,12 +181,22 @@ void ModDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* select
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* selected_page = dynamic_cast<ModPage*>(selected);
|
m_selectedPage = dynamic_cast<ModPage*>(selected);
|
||||||
if (!selected_page) {
|
if (!m_selectedPage) {
|
||||||
qCritical() << "Page '" << selected->displayName() << "' in ModDownloadDialog is not a ModPage!";
|
qCritical() << "Page '" << selected->displayName() << "' in ModDownloadDialog is not a ModPage!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same effect as having a global search bar
|
// Same effect as having a global search bar
|
||||||
selected_page->setSearchTerm(prev_page->getSearchTerm());
|
m_selectedPage->setSearchTerm(prev_page->getSearchTerm());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModDownloadDialog::selectPage(QString pageId)
|
||||||
|
{
|
||||||
|
return m_container->selectPage(pageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModPage* ModDownloadDialog::getSelectedPage()
|
||||||
|
{
|
||||||
|
return m_selectedPage;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -32,13 +33,14 @@ class ModDownloadDialog;
|
|||||||
|
|
||||||
class PageContainer;
|
class PageContainer;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
|
class ModPage;
|
||||||
class ModrinthModPage;
|
class ModrinthModPage;
|
||||||
|
|
||||||
class ModDownloadDialog final : public QDialog, public BasePageProvider
|
class ModDownloadDialog final : public QDialog, public BasePageProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance);
|
explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods, QWidget* parent, BaseInstance* instance);
|
||||||
~ModDownloadDialog() override = default;
|
~ModDownloadDialog() override = default;
|
||||||
|
|
||||||
@ -51,22 +53,26 @@ public:
|
|||||||
bool isModSelected(QString name) const;
|
bool isModSelected(QString name) const;
|
||||||
|
|
||||||
const QList<ModDownloadTask*> getTasks();
|
const QList<ModDownloadTask*> getTasks();
|
||||||
const std::shared_ptr<ModFolderModel> &mods;
|
const std::shared_ptr<ModFolderModel>& mods;
|
||||||
|
|
||||||
public slots:
|
bool selectPage(QString pageId);
|
||||||
|
ModPage* getSelectedPage();
|
||||||
|
|
||||||
|
public slots:
|
||||||
void confirm();
|
void confirm();
|
||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
void reject() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ModDownloadDialog *ui = nullptr;
|
Ui::ModDownloadDialog* ui = nullptr;
|
||||||
PageContainer * m_container = nullptr;
|
PageContainer* m_container = nullptr;
|
||||||
QDialogButtonBox * m_buttons = nullptr;
|
QDialogButtonBox* m_buttons = nullptr;
|
||||||
QVBoxLayout *m_verticalLayout = nullptr;
|
QVBoxLayout* m_verticalLayout = nullptr;
|
||||||
|
ModPage* m_selectedPage = nullptr;
|
||||||
|
|
||||||
QHash<QString, ModDownloadTask*> modTask;
|
QHash<QString, ModDownloadTask*> modTask;
|
||||||
BaseInstance *m_instance;
|
BaseInstance* m_instance;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -37,7 +38,9 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "ui_ModPage.h"
|
#include "ui_ModPage.h"
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <HoeDown.h>
|
#include <HoeDown.h>
|
||||||
@ -80,6 +83,8 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
|
|||||||
|
|
||||||
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
||||||
ui->packView->installEventFilter(this);
|
ui->packView->installEventFilter(this);
|
||||||
|
|
||||||
|
connect(ui->packDescription, &QTextBrowser::anchorClicked, this, &ModPage::openUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModPage::~ModPage()
|
ModPage::~ModPage()
|
||||||
@ -159,7 +164,7 @@ void ModPage::triggerSearch()
|
|||||||
auto changed = m_filter_widget->changed();
|
auto changed = m_filter_widget->changed();
|
||||||
m_filter = m_filter_widget->getFilter();
|
m_filter = m_filter_widget->getFilter();
|
||||||
|
|
||||||
if(changed){
|
if (changed) {
|
||||||
ui->packView->clearSelection();
|
ui->packView->clearSelection();
|
||||||
ui->packDescription->clear();
|
ui->packDescription->clear();
|
||||||
ui->versionSelectionBox->clear();
|
ui->versionSelectionBox->clear();
|
||||||
@ -241,6 +246,79 @@ void ModPage::onModSelected()
|
|||||||
ui->packView->adjustSize();
|
ui->packView->adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const QRegularExpression modrinth(QRegularExpression::anchoredPattern("(?:www\\.)?modrinth\\.com\\/mod\\/([^\\/]+)\\/?"));
|
||||||
|
static const QRegularExpression curseForge(QRegularExpression::anchoredPattern("(?:www\\.)?curseforge\\.com\\/minecraft\\/mc-mods\\/([^\\/]+)\\/?"));
|
||||||
|
static const QRegularExpression curseForgeOld(QRegularExpression::anchoredPattern("minecraft\\.curseforge\\.com\\/projects\\/([^\\/]+)\\/?"));
|
||||||
|
|
||||||
|
void ModPage::openUrl(const QUrl& url)
|
||||||
|
{
|
||||||
|
// do not allow other url schemes for security reasons
|
||||||
|
if (!(url.scheme() == "http" || url.scheme() == "https")) {
|
||||||
|
qWarning() << "Unsupported scheme" << url.scheme();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// detect mod URLs and search instead
|
||||||
|
|
||||||
|
const QString address = url.host() + url.path();
|
||||||
|
QRegularExpressionMatch match;
|
||||||
|
const char* page;
|
||||||
|
|
||||||
|
match = modrinth.match(address);
|
||||||
|
if (match.hasMatch())
|
||||||
|
page = "modrinth";
|
||||||
|
else if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
||||||
|
match = curseForge.match(address);
|
||||||
|
if (!match.hasMatch())
|
||||||
|
match = curseForgeOld.match(address);
|
||||||
|
|
||||||
|
if (match.hasMatch())
|
||||||
|
page = "curseforge";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
const QString slug = match.captured(1);
|
||||||
|
|
||||||
|
// ensure the user isn't opening the same mod
|
||||||
|
if (slug != current.slug) {
|
||||||
|
dialog->selectPage(page);
|
||||||
|
|
||||||
|
ModPage* newPage = dialog->getSelectedPage();
|
||||||
|
|
||||||
|
QLineEdit* searchEdit = newPage->ui->searchEdit;
|
||||||
|
ModPlatform::ListModel* model = newPage->listModel;
|
||||||
|
QListView* view = newPage->ui->packView;
|
||||||
|
|
||||||
|
auto jump = [url, slug, model, view] {
|
||||||
|
for (int row = 0; row < model->rowCount({}); row++) {
|
||||||
|
const QModelIndex index = model->index(row);
|
||||||
|
const auto pack = model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack>();
|
||||||
|
|
||||||
|
if (pack.slug == slug) {
|
||||||
|
view->setCurrentIndex(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The final fallback.
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
searchEdit->setText(slug);
|
||||||
|
newPage->triggerSearch();
|
||||||
|
|
||||||
|
if (model->activeJob())
|
||||||
|
connect(model->activeJob(), &Task::finished, jump);
|
||||||
|
else
|
||||||
|
jump();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// open in the user's web browser
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
/******** Make changes to the UI ********/
|
/******** Make changes to the UI ********/
|
||||||
|
|
||||||
@ -317,8 +395,7 @@ void ModPage::updateUi()
|
|||||||
text += "<br>" + tr(" by ") + authorStrs.join(", ");
|
text += "<br>" + tr(" by ") + authorStrs.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (current.extraDataLoaded) {
|
||||||
if(current.extraDataLoaded) {
|
|
||||||
if (!current.extraData.donate.isEmpty()) {
|
if (!current.extraData.donate.isEmpty()) {
|
||||||
text += "<br><br>" + tr("Donate information: ");
|
text += "<br><br>" + tr("Donate information: ");
|
||||||
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {
|
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {
|
||||||
|
@ -82,6 +82,7 @@ class ModPage : public QWidget, public BasePage {
|
|||||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
void onVersionSelectionChanged(QString data);
|
void onVersionSelectionChanged(QString data);
|
||||||
void onModSelected();
|
void onModSelected();
|
||||||
|
virtual void openUrl(const QUrl& url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ui::ModPage* ui = nullptr;
|
Ui::ModPage* ui = nullptr;
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<widget class="ProjectDescriptionPage" name="packDescription">
|
<widget class="ProjectDescriptionPage" name="packDescription">
|
||||||
<property name="openExternalLinks">
|
<property name="openExternalLinks">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="openLinks">
|
<property name="openLinks">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -78,3 +79,19 @@ bool FlameModPage::optedOut(ModPlatform::IndexedVersion& ver) const
|
|||||||
// other mod providers start loading before being selected, at least with
|
// other mod providers start loading before being selected, at least with
|
||||||
// my Qt, so we need to implement this in every derived class...
|
// my Qt, so we need to implement this in every derived class...
|
||||||
auto FlameModPage::shouldDisplay() const -> bool { return true; }
|
auto FlameModPage::shouldDisplay() const -> bool { return true; }
|
||||||
|
|
||||||
|
void FlameModPage::openUrl(const QUrl& url)
|
||||||
|
{
|
||||||
|
if (url.scheme().isEmpty()) {
|
||||||
|
QString query = url.query(QUrl::FullyDecoded);
|
||||||
|
|
||||||
|
if (query.startsWith("remoteUrl=")) {
|
||||||
|
// attempt to resolve url from warning page
|
||||||
|
query.remove(0, 10);
|
||||||
|
ModPage::openUrl({QUrl::fromPercentEncoding(query.toUtf8())}); // double decoding is necessary
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModPage::openUrl(url);
|
||||||
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -64,4 +65,6 @@ class FlameModPage : public ModPage {
|
|||||||
bool optedOut(ModPlatform::IndexedVersion& ver) const override;
|
bool optedOut(ModPlatform::IndexedVersion& ver) const override;
|
||||||
|
|
||||||
auto shouldDisplay() const -> bool override;
|
auto shouldDisplay() const -> bool override;
|
||||||
|
|
||||||
|
void openUrl(const QUrl& url) override;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user