Added visit mod's page
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
3b9d822d72
commit
f724059b88
@ -154,6 +154,17 @@
|
|||||||
<string>Try to check or update all selected resources (all resources if none are selected)</string>
|
<string>Try to check or update all selected resources (all resources if none are selected)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionVisitItemPage">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Visit on mod's page</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Go to mods home page</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
@ -59,6 +60,7 @@
|
|||||||
#include "minecraft/mod/Mod.h"
|
#include "minecraft/mod/Mod.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
|
||||||
|
#include "modplatform/ModIndex.h"
|
||||||
#include "modplatform/ResourceAPI.h"
|
#include "modplatform/ResourceAPI.h"
|
||||||
|
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
@ -85,22 +87,29 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
|||||||
ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);
|
ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);
|
||||||
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
||||||
|
|
||||||
|
ui->actionVisitItemPage->setToolTip(tr("Go to mods home page"));
|
||||||
|
ui->actionsToolbar->insertActionAfter(ui->actionViewFolder, ui->actionVisitItemPage);
|
||||||
|
connect(ui->actionVisitItemPage, &QAction::triggered, this, &ModFolderPage::visitModPages);
|
||||||
|
|
||||||
auto check_allow_update = [this] {
|
auto check_allow_update = [this] {
|
||||||
return (!m_instance || !m_instance->isRunning()) &&
|
return (!m_instance || !m_instance->isRunning()) && (ui->treeView->selectionModel()->hasSelection() || !m_model->empty());
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
|
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
ui->actionUpdateItem->setEnabled(check_allow_update());
|
||||||
|
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
|
||||||
|
auto mods_list = m_model->selectedMods(selection);
|
||||||
|
auto enableView = std::any_of(mods_list.cbegin(), mods_list.cend(),
|
||||||
|
[](Mod* v) { return v->metadata() != nullptr || v->homeurl().size() != 0; });
|
||||||
|
ui->actionVisitItemPage->setEnabled(enableView);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::rowsInserted, this, [this, check_allow_update] {
|
connect(mods.get(), &ModFolderModel::rowsInserted, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this, check_allow_update] {
|
connect(mods.get(), &ModFolderModel::rowsRemoved, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] {
|
connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] {
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
ui->actionUpdateItem->setEnabled(check_allow_update());
|
||||||
@ -140,7 +149,7 @@ bool ModFolderPage::onSelectionChanged(const QModelIndex& current, const QModelI
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModFolderPage::removeItems(const QItemSelection &selection)
|
void ModFolderPage::removeItems(const QItemSelection& selection)
|
||||||
{
|
{
|
||||||
m_model->deleteMods(selection.indexes());
|
m_model->deleteMods(selection.indexes());
|
||||||
}
|
}
|
||||||
@ -214,8 +223,7 @@ void ModFolderPage::updateMods()
|
|||||||
message = tr("All selected mods are up-to-date! :)");
|
message = tr("All selected mods are up-to-date! :)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CustomMessageBox::selectable(this, tr("Update checker"), message)
|
CustomMessageBox::selectable(this, tr("Update checker"), message)->exec();
|
||||||
->exec();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,3 +290,21 @@ bool NilModFolderPage::shouldDisplay() const
|
|||||||
{
|
{
|
||||||
return m_model->dir().exists();
|
return m_model->dir().exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModFolderPage::visitModPages()
|
||||||
|
{
|
||||||
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
|
||||||
|
for (auto mod : m_model->selectedMods(selection))
|
||||||
|
if (auto meta = mod->metadata(); meta != nullptr) {
|
||||||
|
auto slug = meta->slug.remove(".pw.toml");
|
||||||
|
switch (meta->provider) {
|
||||||
|
case ModPlatform::ResourceProvider::MODRINTH:
|
||||||
|
DesktopServices::openUrl(QString("https://modrinth.com/mod/%1").arg(slug));
|
||||||
|
break;
|
||||||
|
case ModPlatform::ResourceProvider::FLAME:
|
||||||
|
DesktopServices::openUrl(QString("https://www.curseforge.com/minecraft/mc-mods/%1").arg(slug));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (mod->homeurl().size() != 0)
|
||||||
|
DesktopServices::openUrl(mod->homeurl());
|
||||||
|
}
|
@ -64,6 +64,7 @@ class ModFolderPage : public ExternalResourcesPage {
|
|||||||
|
|
||||||
void installMods();
|
void installMods();
|
||||||
void updateMods();
|
void updateMods();
|
||||||
|
void visitModPages();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<ModFolderModel> m_model;
|
std::shared_ptr<ModFolderModel> m_model;
|
||||||
|
Loading…
Reference in New Issue
Block a user