mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
Reimplement View Homepage
I removed it for some reason, but now it's back for all pages! Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -141,16 +141,14 @@ auto Mod::version() const -> QString
|
||||
return details().version;
|
||||
}
|
||||
|
||||
auto Mod::homeurl() const -> QString
|
||||
auto Mod::homepage() const -> QString
|
||||
{
|
||||
return details().homeurl;
|
||||
}
|
||||
QString metaUrl = Resource::homepage();
|
||||
|
||||
auto Mod::metaurl() const -> QString
|
||||
{
|
||||
if (metadata() == nullptr)
|
||||
return homeurl();
|
||||
return ModPlatform::getMetaURL(metadata()->provider, metadata()->project_id);
|
||||
if (metaUrl.isEmpty())
|
||||
return details().homeurl;
|
||||
else
|
||||
return metaUrl;
|
||||
}
|
||||
|
||||
auto Mod::loaders() const -> QString
|
||||
|
@ -61,12 +61,11 @@ class Mod : public Resource {
|
||||
auto details() const -> const ModDetails&;
|
||||
auto name() const -> QString override;
|
||||
auto version() const -> QString;
|
||||
auto homeurl() const -> QString;
|
||||
auto homepage() const -> QString override;
|
||||
auto description() const -> QString;
|
||||
auto authors() const -> QStringList;
|
||||
auto licenses() const -> const QList<ModLicense>&;
|
||||
auto issueTracker() const -> QString;
|
||||
auto metaurl() const -> QString;
|
||||
auto side() const -> QString;
|
||||
auto loaders() const -> QString;
|
||||
auto mcVersions() const -> QString;
|
||||
|
@ -95,6 +95,14 @@ auto Resource::provider() const -> QString
|
||||
return tr("Unknown");
|
||||
}
|
||||
|
||||
auto Resource::homepage() const -> QString
|
||||
{
|
||||
if (metadata())
|
||||
return ModPlatform::getMetaURL(metadata()->provider, metadata()->project_id);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void Resource::setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
|
||||
{
|
||||
if (status() == ResourceStatus::NO_METADATA)
|
||||
|
@ -100,6 +100,7 @@ class Resource : public QObject {
|
||||
[[nodiscard]] auto metadata() -> std::shared_ptr<Metadata::ModStruct> { return m_metadata; }
|
||||
[[nodiscard]] auto metadata() const -> std::shared_ptr<const Metadata::ModStruct> { return m_metadata; }
|
||||
[[nodiscard]] auto provider() const -> QString;
|
||||
[[nodiscard]] virtual auto homepage() const -> QString;
|
||||
|
||||
void setStatus(ResourceStatus status) { m_status = status; }
|
||||
void setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata);
|
||||
|
@ -28,7 +28,7 @@ QString toHTML(QList<Mod*> mods, OptionalData extraData)
|
||||
auto meta = mod->metadata();
|
||||
auto modName = mod->name().toHtmlEscaped();
|
||||
if (extraData & Url) {
|
||||
auto url = mod->metaurl().toHtmlEscaped();
|
||||
auto url = mod->homepage().toHtmlEscaped();
|
||||
if (!url.isEmpty())
|
||||
modName = QString("<a href=\"%1\">%2</a>").arg(url, modName);
|
||||
}
|
||||
@ -65,7 +65,7 @@ QString toMarkdown(QList<Mod*> mods, OptionalData extraData)
|
||||
auto meta = mod->metadata();
|
||||
auto modName = toMarkdownEscaped(mod->name());
|
||||
if (extraData & Url) {
|
||||
auto url = mod->metaurl();
|
||||
auto url = mod->homepage();
|
||||
if (!url.isEmpty())
|
||||
modName = QString("[%1](%2)").arg(modName, url);
|
||||
}
|
||||
@ -95,7 +95,7 @@ QString toPlainTXT(QList<Mod*> mods, OptionalData extraData)
|
||||
|
||||
auto line = modName;
|
||||
if (extraData & Url) {
|
||||
auto url = mod->metaurl();
|
||||
auto url = mod->homepage();
|
||||
if (!url.isEmpty())
|
||||
line += QString(" (%1)").arg(url);
|
||||
}
|
||||
@ -124,7 +124,7 @@ QString toJSON(QList<Mod*> mods, OptionalData extraData)
|
||||
QJsonObject line;
|
||||
line["name"] = modName;
|
||||
if (extraData & Url) {
|
||||
auto url = mod->metaurl();
|
||||
auto url = mod->homepage();
|
||||
if (!url.isEmpty())
|
||||
line["url"] = url;
|
||||
}
|
||||
@ -156,7 +156,7 @@ QString toCSV(QList<Mod*> mods, OptionalData extraData)
|
||||
|
||||
data << modName;
|
||||
if (extraData & Url)
|
||||
data << mod->metaurl();
|
||||
data << mod->homepage();
|
||||
if (extraData & Version) {
|
||||
auto ver = mod->version();
|
||||
if (ver.isEmpty() && meta != nullptr)
|
||||
@ -203,7 +203,7 @@ QString exportToModList(QList<Mod*> mods, QString lineTemplate)
|
||||
for (auto mod : mods) {
|
||||
auto meta = mod->metadata();
|
||||
auto modName = mod->name();
|
||||
auto url = mod->metaurl();
|
||||
auto url = mod->homepage();
|
||||
auto ver = mod->version();
|
||||
if (ver.isEmpty() && meta != nullptr)
|
||||
ver = meta->version().toString();
|
||||
|
@ -74,6 +74,7 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
||||
connect(ui->actionRemoveItem, &QAction::triggered, this, &ExternalResourcesPage::removeItem);
|
||||
connect(ui->actionEnableItem, &QAction::triggered, this, &ExternalResourcesPage::enableItem);
|
||||
connect(ui->actionDisableItem, &QAction::triggered, this, &ExternalResourcesPage::disableItem);
|
||||
connect(ui->actionViewHomepage, &QAction::triggered, this, &ExternalResourcesPage::viewHomepage);
|
||||
connect(ui->actionViewConfigs, &QAction::triggered, this, &ExternalResourcesPage::viewConfigs);
|
||||
connect(ui->actionViewFolder, &QAction::triggered, this, &ExternalResourcesPage::viewFolder);
|
||||
|
||||
@ -301,6 +302,27 @@ void ExternalResourcesPage::disableItem()
|
||||
m_model->setResourceEnabled(selection.indexes(), EnableAction::DISABLE);
|
||||
}
|
||||
|
||||
void ExternalResourcesPage::viewHomepage()
|
||||
{
|
||||
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
|
||||
bool openedAny = false;
|
||||
for (auto resource : m_model->selectedResources(selection)) {
|
||||
auto url = resource->homepage();
|
||||
if (!url.isEmpty()) {
|
||||
DesktopServices::openUrl(url);
|
||||
openedAny = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: just disable button
|
||||
// just doing this for now to prevent race conditions which may be worse with implementation changes
|
||||
if (!openedAny) {
|
||||
CustomMessageBox::selectable(this, tr("No homepages found"), tr("None of the selected resources had an available homepage."),
|
||||
QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Ok)
|
||||
->exec();
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalResourcesPage::viewConfigs()
|
||||
{
|
||||
DesktopServices::openPath(m_instance->instanceConfigFolder(), true);
|
||||
@ -314,16 +336,18 @@ void ExternalResourcesPage::viewFolder()
|
||||
void ExternalResourcesPage::updateActions()
|
||||
{
|
||||
const bool hasSelection = ui->treeView->selectionModel()->hasSelection();
|
||||
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
|
||||
|
||||
ui->actionUpdateItem->setEnabled(!m_model->empty());
|
||||
ui->actionResetItemMetadata->setEnabled(hasSelection);
|
||||
|
||||
const QModelIndexList rows = ui->treeView->selectionModel()->selectedRows();
|
||||
ui->actionChangeVersion->setEnabled(rows.count() == 1 && m_model->at(m_filterModel->mapToSource(rows[0]).row()).metadata() != nullptr);
|
||||
|
||||
ui->actionRemoveItem->setEnabled(hasSelection);
|
||||
ui->actionEnableItem->setEnabled(hasSelection);
|
||||
ui->actionDisableItem->setEnabled(hasSelection);
|
||||
|
||||
ui->actionViewHomepage->setEnabled(hasSelection);
|
||||
ui->actionExportMetadata->setEnabled(!m_model->empty());
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,8 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
|
||||
virtual void enableItem();
|
||||
virtual void disableItem();
|
||||
|
||||
virtual void viewHomepage();
|
||||
|
||||
virtual void viewFolder();
|
||||
virtual void viewConfigs();
|
||||
|
||||
|
@ -90,6 +90,8 @@
|
||||
<addaction name="actionRemoveItem"/>
|
||||
<addaction name="actionEnableItem"/>
|
||||
<addaction name="actionDisableItem"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionViewHomepage"/>
|
||||
<addaction name="actionViewConfigs"/>
|
||||
<addaction name="actionViewFolder"/>
|
||||
</widget>
|
||||
@ -213,6 +215,17 @@
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionViewHomepage">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>View Homepage</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>View the homepages of all selected items.</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -107,11 +107,11 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
||||
connect(ui->actionChangeVersion, &QAction::triggered, this, &ModFolderPage::changeModVersion);
|
||||
ui->actionsToolbar->insertActionAfter(ui->actionUpdateItem, ui->actionChangeVersion);
|
||||
|
||||
ui->actionViewHomepage->setToolTip(tr("View the homepages of all selected mods."));
|
||||
|
||||
ui->actionExportMetadata->setToolTip(tr("Export mod's metadata to text."));
|
||||
connect(ui->actionExportMetadata, &QAction::triggered, this, &ModFolderPage::exportModMetadata);
|
||||
ui->actionsToolbar->insertActionAfter(ui->actionDisableItem, ui->actionExportMetadata);
|
||||
|
||||
ui->actionsToolbar->insertSeparator(ui->actionExportMetadata);
|
||||
ui->actionsToolbar->insertActionAfter(ui->actionViewHomepage, ui->actionExportMetadata);
|
||||
}
|
||||
|
||||
bool ModFolderPage::shouldDisplay() const
|
||||
|
@ -74,6 +74,7 @@ TexturePackPage::TexturePackPage(MinecraftInstance* instance, std::shared_ptr<Te
|
||||
connect(ui->actionChangeVersion, &QAction::triggered, this, &TexturePackPage::changeTexturePackVersion);
|
||||
ui->actionsToolbar->insertActionAfter(ui->actionUpdateItem, ui->actionChangeVersion);
|
||||
|
||||
ui->actionViewHomepage->setToolTip(tr("View the homepages of all selected texture packs."));
|
||||
}
|
||||
|
||||
void TexturePackPage::updateFrame(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
|
||||
|
@ -84,7 +84,7 @@ void InfoFrame::updateWithMod(Mod const& m)
|
||||
|
||||
QString text = "";
|
||||
QString name = "";
|
||||
QString link = m.metaurl();
|
||||
QString link = m.homepage();
|
||||
if (m.name().isEmpty())
|
||||
name = m.internal_id();
|
||||
else
|
||||
@ -93,7 +93,7 @@ void InfoFrame::updateWithMod(Mod const& m)
|
||||
if (link.isEmpty())
|
||||
text = name;
|
||||
else {
|
||||
text = "<a href=\"" + link + "\">" + name + "</a>";
|
||||
text = "<a href=\"" + QUrl(link).toEncoded() + "\">" + name + "</a>";
|
||||
}
|
||||
if (!m.authors().isEmpty())
|
||||
text += " by " + m.authors().join(", ");
|
||||
@ -145,6 +145,12 @@ void InfoFrame::updateWithMod(Mod const& m)
|
||||
|
||||
void InfoFrame::updateWithResource(const Resource& resource)
|
||||
{
|
||||
const QString homepage = resource.homepage();
|
||||
|
||||
if (!homepage.isEmpty()) {
|
||||
|
||||
}
|
||||
|
||||
setName(resource.name());
|
||||
setImage();
|
||||
}
|
||||
@ -209,14 +215,28 @@ QString InfoFrame::renderColorCodes(QString input)
|
||||
|
||||
void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
|
||||
{
|
||||
setName(renderColorCodes(resource_pack.name()));
|
||||
QString name = renderColorCodes(resource_pack.name());
|
||||
|
||||
const QString homepage = resource_pack.homepage();
|
||||
if (!homepage.isEmpty()) {
|
||||
name = "<a href=\"" + homepage + "\">" + name + "</a>";
|
||||
}
|
||||
|
||||
setName(name);
|
||||
setDescription(renderColorCodes(resource_pack.description()));
|
||||
setImage(resource_pack.image({ 64, 64 }));
|
||||
}
|
||||
|
||||
void InfoFrame::updateWithTexturePack(TexturePack& texture_pack)
|
||||
{
|
||||
setName(renderColorCodes(texture_pack.name()));
|
||||
QString name = renderColorCodes(texture_pack.name());
|
||||
|
||||
const QString homepage = texture_pack.homepage();
|
||||
if (!homepage.isEmpty()) {
|
||||
name = "<a href=\"" + homepage + "\">" + name + "</a>";
|
||||
}
|
||||
|
||||
setName(name);
|
||||
setDescription(renderColorCodes(texture_pack.description()));
|
||||
setImage(texture_pack.image({ 64, 64 }));
|
||||
}
|
||||
|
Reference in New Issue
Block a user