aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/pages/modplatform/ModPage.cpp
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2022-11-01 16:58:22 +0000
committerTheKodeToad <TheKodeToad@proton.me>2022-11-01 16:58:22 +0000
commit7f32c6464d84181fc8947f632da340a863dc53d6 (patch)
treeb9e0fa98bcaef118e0ca871dfe65ba57e322a5db /launcher/ui/pages/modplatform/ModPage.cpp
parent04b39294ba012721279ca9d009f99f75178fd57a (diff)
downloadPrismLauncher-7f32c6464d84181fc8947f632da340a863dc53d6.tar.gz
PrismLauncher-7f32c6464d84181fc8947f632da340a863dc53d6.tar.bz2
PrismLauncher-7f32c6464d84181fc8947f632da340a863dc53d6.zip
Initial better mod browser link implementation
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/ui/pages/modplatform/ModPage.cpp')
-rw-r--r--launcher/ui/pages/modplatform/ModPage.cpp63
1 files changed, 57 insertions, 6 deletions
diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp
index f2c1746f..7f62fff1 100644
--- a/launcher/ui/pages/modplatform/ModPage.cpp
+++ b/launcher/ui/pages/modplatform/ModPage.cpp
@@ -2,6 +2,7 @@
/*
* PolyMC - Minecraft Launcher
* 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
* it under the terms of the GNU General Public License as published by
@@ -37,6 +38,7 @@
#include "Application.h"
#include "ui_ModPage.h"
+#include <QDesktopServices>
#include <QKeyEvent>
#include <memory>
@@ -80,6 +82,8 @@ ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
ui->packView->installEventFilter(this);
+
+ connect(ui->packDescription, &QTextBrowser::anchorClicked, this, &ModPage::openUrl);
}
ModPage::~ModPage()
@@ -158,8 +162,8 @@ void ModPage::triggerSearch()
{
auto changed = m_filter_widget->changed();
m_filter = m_filter_widget->getFilter();
-
- if(changed){
+
+ if (changed) {
ui->packView->clearSelection();
ui->packDescription->clear();
ui->versionSelectionBox->clear();
@@ -241,6 +245,54 @@ void ModPage::onModSelected()
ui->packView->adjustSize();
}
+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
+ int prefixLength;
+ const char* page;
+
+ if ((url.host() == "modrinth.com" || url.host() == "www.modrinth.com")
+ && url.path().startsWith("/mod/")) {
+ prefixLength = 5;
+ page = "modrinth";
+ }
+ else if (APPLICATION->capabilities() & Application::SupportsFlame
+ && url.host() == "www.curseforge.com"
+ && url.path().toLower().startsWith("/minecraft/mc-mods/")) {
+ prefixLength = 19;
+ page = "curseforge";
+ }
+ else
+ prefixLength = 0;
+
+ if (prefixLength != 0) {
+ QString slug = url.path().mid(prefixLength);
+
+ // remove trailing slash(es)
+ while (slug.endsWith('/'))
+ slug.remove(slug.length() - 1, 1);
+
+ // ensure that the path doesn't contain any further slashes,
+ // and the user isn't opening the same mod; they probably
+ // intended to view in their web browser
+ if (!slug.isEmpty() && !slug.contains('/') && slug != current.slug) {
+ ui->searchEdit->setText(slug);
+ dialog->selectPage(page);
+ triggerSearch();
+ return;
+ }
+ }
+
+ // open in the user's web browser
+ QDesktopServices::openUrl(url);
+}
+
/******** Make changes to the UI ********/
@@ -270,8 +322,8 @@ void ModPage::updateModVersions(int prev_count)
if ((valid || m_filter->versions.empty()) && !optedOut(version))
ui->versionSelectionBox->addItem(version.version, QVariant(i));
}
- if (ui->versionSelectionBox->count() == 0 && prev_count != 0) {
- ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1));
+ if (ui->versionSelectionBox->count() == 0 && prev_count != 0) {
+ ui->versionSelectionBox->addItem(tr("No valid version found!"), QVariant(-1));
ui->modSelectionButton->setText(tr("Cannot select invalid version :("));
}
@@ -317,8 +369,7 @@ void ModPage::updateUi()
text += "<br>" + tr(" by ") + authorStrs.join(", ");
}
-
- if(current.extraDataLoaded) {
+ if (current.extraDataLoaded) {
if (!current.extraData.donate.isEmpty()) {
text += "<br><br>" + tr("Donate information: ");
auto donateToStr = [](ModPlatform::DonationData& donate) -> QString {