MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / ModFolderPage

Method ModFolderPage

launcher/ui/pages/instance/ModFolderPage.cpp:67–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65#include "ui/dialogs/ProgressDialog.h"
66
67ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel> mods, QWidget* parent)
68 : ExternalResourcesPage(inst, mods, parent), m_model(mods)
69{
70 // This is structured like that so that these changes
71 // do not affect the Resource pack and Shader pack tabs
72 {
73 ui->actionDownloadItem->setText(tr("Download mods"));
74 ui->actionDownloadItem->setToolTip(tr("Download mods from online mod platforms"));
75 ui->actionDownloadItem->setEnabled(true);
76 ui->actionAddItem->setText(tr("Add file"));
77 ui->actionAddItem->setToolTip(tr("Add a locally downloaded file"));
78
79 ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionDownloadItem);
80
81 connect(ui->actionDownloadItem, &QAction::triggered, this, &ModFolderPage::installMods);
82
83 ui->actionUpdateItem->setToolTip(tr("Try to check or update all selected mods (all mods if none are selected)"));
84 ui->actionsToolbar->insertActionAfter(ui->actionAddItem, ui->actionUpdateItem);
85 connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
86
87 connect(ui->actionDisableUpdates, &QAction::triggered, this, &ModFolderPage::disableUpdates);
88 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this] {
89 ui->actionDisableUpdates->setEnabled(ui->treeView->selectionModel()->hasSelection());
90 onDisableUpdatesChange();
91 });
92
93 auto check_allow_update = [this] {
94 return (!m_instance || !m_instance->isRunning()) &&
95 (ui->treeView->selectionModel()->hasSelection() || !m_model->empty());
96 };
97
98 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
99 ui->actionUpdateItem->setEnabled(check_allow_update());
100 });
101
102 connect(mods.get(), &ModFolderModel::rowsInserted, this, [this, check_allow_update] {
103 ui->actionUpdateItem->setEnabled(check_allow_update());
104 });
105
106 connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this, check_allow_update] {
107 ui->actionUpdateItem->setEnabled(check_allow_update());
108 });
109
110 connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] {
111 ui->actionUpdateItem->setEnabled(check_allow_update());
112
113 // Prevent a weird crash when trying to open the mods page twice in a session o.O
114 disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);
115 });
116
117 ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());
118 }
119}
120
121void ModFolderPage::runningStateChanged(bool running)
122{

Callers

nothing calls this directly

Calls 7

setEnabledMethod · 0.80
insertActionBeforeMethod · 0.80
insertActionAfterMethod · 0.80
setTextMethod · 0.45
isRunningMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected