feat:unlocked versions page

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-07-09 22:47:38 +03:00
parent 67d473aab7
commit 159f14c076
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 139 additions and 231 deletions

View File

@ -40,14 +40,13 @@
#include "Application.h" #include "Application.h"
#include <QMessageBox> #include <QAbstractItemModel>
#include <QLabel>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QLabel>
#include <QAbstractItemModel>
#include <QMessageBox>
#include <QListView> #include <QListView>
#include <QMenu>
#include <QMessageBox>
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
@ -55,28 +54,26 @@
#include "ui_VersionPage.h" #include "ui_VersionPage.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/VersionSelectDialog.h"
#include "ui/dialogs/NewComponentDialog.h" #include "ui/dialogs/NewComponentDialog.h"
#include "ui/dialogs/ProgressDialog.h" #include "ui/dialogs/ProgressDialog.h"
#include "ui/dialogs/VersionSelectDialog.h"
#include "ui/GuiUtil.h" #include "ui/GuiUtil.h"
#include "DesktopServices.h"
#include "Exception.h"
#include "Version.h"
#include "icons/IconList.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "minecraft/auth/AccountList.h" #include "minecraft/auth/AccountList.h"
#include "minecraft/mod/Mod.h" #include "minecraft/mod/Mod.h"
#include "icons/IconList.h"
#include "Exception.h"
#include "Version.h"
#include "DesktopServices.h"
#include "meta/Index.h" #include "meta/Index.h"
#include "meta/VersionList.h" #include "meta/VersionList.h"
class IconProxy : public QIdentityProxyModel class IconProxy : public QIdentityProxyModel {
{
Q_OBJECT Q_OBJECT
public: public:
IconProxy(QWidget* parentWidget) : QIdentityProxyModel(parentWidget) IconProxy(QWidget* parentWidget) : QIdentityProxyModel(parentWidget)
{ {
connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone); connect(parentWidget, &QObject::destroyed, this, &IconProxy::widgetGone);
@ -87,17 +84,12 @@ public:
{ {
QVariant var = QIdentityProxyModel::data(proxyIndex, role); QVariant var = QIdentityProxyModel::data(proxyIndex, role);
int column = proxyIndex.column(); int column = proxyIndex.column();
if(column == 0 && role == Qt::DecorationRole && m_parentWidget) if (column == 0 && role == Qt::DecorationRole && m_parentWidget) {
{ if (!var.isNull()) {
if(!var.isNull())
{
auto string = var.toString(); auto string = var.toString();
if(string == "warning") if (string == "warning") {
{
return APPLICATION->getThemedIcon("status-yellow"); return APPLICATION->getThemedIcon("status-yellow");
} } else if (string == "error") {
else if(string == "error")
{
return APPLICATION->getThemedIcon("status-bad"); return APPLICATION->getThemedIcon("status-bad");
} }
} }
@ -106,10 +98,7 @@ public:
return var; return var;
} }
private slots: private slots:
void widgetGone() void widgetGone() { m_parentWidget = nullptr; }
{
m_parentWidget = nullptr;
}
private: private:
QWidget* m_parentWidget = nullptr; QWidget* m_parentWidget = nullptr;
@ -151,8 +140,7 @@ QMenu * VersionPage::createPopupMenu()
return filteredMenu; return filteredMenu;
} }
VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) VersionPage::VersionPage(MinecraftInstance* inst, QWidget* parent) : QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)
: QMainWindow(parent), ui(new Ui::VersionPage), m_inst(inst)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -182,10 +170,8 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent); connect(smodel, &QItemSelectionModel::currentChanged, this, &VersionPage::packageCurrent);
connect(m_profile.get(), &PackProfile::minecraftChanged, this, &VersionPage::updateVersionControls); connect(m_profile.get(), &PackProfile::minecraftChanged, this, &VersionPage::updateVersionControls);
controlsEnabled = !m_inst->isRunning();
updateVersionControls(); updateVersionControls();
preselect(0); preselect(0);
connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus);
connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu); connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu);
connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged); connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged);
} }
@ -204,16 +190,14 @@ void VersionPage::showContextMenu(const QPoint& pos)
void VersionPage::packageCurrent(const QModelIndex& current, const QModelIndex& previous) void VersionPage::packageCurrent(const QModelIndex& current, const QModelIndex& previous)
{ {
if (!current.isValid()) if (!current.isValid()) {
{
ui->frame->clear(); ui->frame->clear();
return; return;
} }
int row = current.row(); int row = current.row();
auto patch = m_profile->getComponent(row); auto patch = m_profile->getComponent(row);
auto severity = patch->getProblemSeverity(); auto severity = patch->getProblemSeverity();
switch(severity) switch (severity) {
{
case ProblemSeverity::Warning: case ProblemSeverity::Warning:
ui->frame->setName(tr("%1 possibly has issues.").arg(patch->getName())); ui->frame->setName(tr("%1 possibly has issues.").arg(patch->getName()));
break; break;
@ -228,14 +212,10 @@ void VersionPage::packageCurrent(const QModelIndex &current, const QModelIndex &
auto& problems = patch->getProblems(); auto& problems = patch->getProblems();
QString problemOut; QString problemOut;
for (auto &problem: problems) for (auto& problem : problems) {
{ if (problem.m_severity == ProblemSeverity::Error) {
if(problem.m_severity == ProblemSeverity::Error)
{
problemOut += tr("Error: "); problemOut += tr("Error: ");
} } else if (problem.m_severity == ProblemSeverity::Warning) {
else if(problem.m_severity == ProblemSeverity::Warning)
{
problemOut += tr("Warning: "); problemOut += tr("Warning: ");
} }
problemOut += problem.m_description; problemOut += problem.m_description;
@ -244,29 +224,21 @@ void VersionPage::packageCurrent(const QModelIndex &current, const QModelIndex &
ui->frame->setDescription(problemOut); ui->frame->setDescription(problemOut);
} }
void VersionPage::updateRunningStatus(bool running)
{
if(controlsEnabled == running) {
controlsEnabled = !running;
updateVersionControls();
}
}
void VersionPage::updateVersionControls() void VersionPage::updateVersionControls()
{ {
// FIXME: this is a dirty hack // FIXME: this is a dirty hack
auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft")); auto minecraftVersion = Version(m_profile->getComponentVersion("net.minecraft"));
ui->actionInstall_Forge->setEnabled(controlsEnabled); ui->actionInstall_Forge->setEnabled(true);
bool supportsFabric = minecraftVersion >= Version("1.14"); bool supportsFabric = minecraftVersion >= Version("1.14");
ui->actionInstall_Fabric->setEnabled(controlsEnabled && supportsFabric); ui->actionInstall_Fabric->setEnabled(supportsFabric);
bool supportsQuilt = minecraftVersion >= Version("1.14"); bool supportsQuilt = minecraftVersion >= Version("1.14");
ui->actionInstall_Quilt->setEnabled(controlsEnabled && supportsQuilt); ui->actionInstall_Quilt->setEnabled(supportsQuilt);
bool supportsLiteLoader = minecraftVersion <= Version("1.12.2"); bool supportsLiteLoader = minecraftVersion <= Version("1.12.2");
ui->actionInstall_LiteLoader->setEnabled(controlsEnabled && supportsLiteLoader); ui->actionInstall_LiteLoader->setEnabled(supportsLiteLoader);
updateButtons(); updateButtons();
} }
@ -276,39 +248,32 @@ void VersionPage::updateButtons(int row)
if (row == -1) if (row == -1)
row = currentRow(); row = currentRow();
auto patch = m_profile->getComponent(row); auto patch = m_profile->getComponent(row);
ui->actionRemove->setEnabled(controlsEnabled && patch && patch->isRemovable()); ui->actionRemove->setEnabled(patch && patch->isRemovable());
ui->actionMove_down->setEnabled(controlsEnabled && patch && patch->isMoveable()); ui->actionMove_down->setEnabled(patch && patch->isMoveable());
ui->actionMove_up->setEnabled(controlsEnabled && patch && patch->isMoveable()); ui->actionMove_up->setEnabled(patch && patch->isMoveable());
ui->actionChange_version->setEnabled(controlsEnabled && patch && patch->isVersionChangeable()); ui->actionChange_version->setEnabled(patch && patch->isVersionChangeable());
ui->actionEdit->setEnabled(controlsEnabled && patch && patch->isCustom()); ui->actionEdit->setEnabled(patch && patch->isCustom());
ui->actionCustomize->setEnabled(controlsEnabled && patch && patch->isCustomizable()); ui->actionCustomize->setEnabled(patch && patch->isCustomizable());
ui->actionRevert->setEnabled(controlsEnabled && patch && patch->isRevertible()); ui->actionRevert->setEnabled(patch && patch->isRevertible());
ui->actionDownload_All->setEnabled(controlsEnabled); ui->actionDownload_All->setEnabled(true);
ui->actionAdd_Empty->setEnabled(controlsEnabled); ui->actionAdd_Empty->setEnabled(true);
ui->actionImport_Components->setEnabled(controlsEnabled); ui->actionImport_Components->setEnabled(true);
ui->actionReload->setEnabled(controlsEnabled); ui->actionReload->setEnabled(true);
ui->actionReplace_Minecraft_jar->setEnabled(controlsEnabled); ui->actionReplace_Minecraft_jar->setEnabled(true);
ui->actionAdd_to_Minecraft_jar->setEnabled(controlsEnabled); ui->actionAdd_to_Minecraft_jar->setEnabled(true);
ui->actionAdd_Agents->setEnabled(controlsEnabled); ui->actionAdd_Agents->setEnabled(true);
} }
bool VersionPage::reloadPackProfile() bool VersionPage::reloadPackProfile()
{ {
try try {
{
m_profile->reload(Net::Mode::Online); m_profile->reload(Net::Mode::Online);
return true; return true;
} } catch (const Exception& e) {
catch (const Exception &e)
{
QMessageBox::critical(this, tr("Error"), e.cause()); QMessageBox::critical(this, tr("Error"), e.cause());
return false; return false;
} } catch (...) {
catch (...) QMessageBox::critical(this, tr("Error"), tr("Couldn't load the instance profile."));
{
QMessageBox::critical(
this, tr("Error"),
tr("Couldn't load the instance profile."));
return false; return false;
} }
} }
@ -321,14 +286,12 @@ void VersionPage::on_actionReload_triggered()
void VersionPage::on_actionRemove_triggered() void VersionPage::on_actionRemove_triggered()
{ {
if (!ui->packageView->currentIndex().isValid()) if (!ui->packageView->currentIndex().isValid()) {
{
return; return;
} }
int index = ui->packageView->currentIndex().row(); int index = ui->packageView->currentIndex().row();
auto component = m_profile->getComponent(index); auto component = m_profile->getComponent(index);
if (component->isCustom()) if (component->isCustom()) {
{
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"), auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"),
tr("You are about to remove \"%1\".\n" tr("You are about to remove \"%1\".\n"
"This is permanent and will completely remove the custom component.\n\n" "This is permanent and will completely remove the custom component.\n\n"
@ -341,8 +304,7 @@ void VersionPage::on_actionRemove_triggered()
return; return;
} }
// FIXME: use actual model, not reloading. // FIXME: use actual model, not reloading.
if (!m_profile->remove(index)) if (!m_profile->remove(index)) {
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
} }
updateButtons(); updateButtons();
@ -352,17 +314,16 @@ void VersionPage::on_actionRemove_triggered()
void VersionPage::on_actionInstall_mods_triggered() void VersionPage::on_actionInstall_mods_triggered()
{ {
if(m_container) if (m_container) {
{
m_container->selectPage("mods"); m_container->selectPage("mods");
} }
} }
void VersionPage::on_actionAdd_to_Minecraft_jar_triggered() void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()
{ {
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"),
if(!list.empty()) APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
{ if (!list.empty()) {
m_profile->installJarMods(list); m_profile->installJarMods(list);
} }
updateButtons(); updateButtons();
@ -370,9 +331,9 @@ void VersionPage::on_actionAdd_to_Minecraft_jar_triggered()
void VersionPage::on_actionReplace_Minecraft_jar_triggered() void VersionPage::on_actionReplace_Minecraft_jar_triggered()
{ {
auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget()); auto jarPath = GuiUtil::BrowseForFile("jar", tr("Select jar"), tr("Minecraft.jar replacement (*.jar)"),
if(!jarPath.isEmpty()) APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
{ if (!jarPath.isEmpty()) {
m_profile->installCustomJar(jarPath); m_profile->installCustomJar(jarPath);
} }
updateButtons(); updateButtons();
@ -406,12 +367,9 @@ void VersionPage::on_actionAdd_Agents_triggered()
void VersionPage::on_actionMove_up_triggered() void VersionPage::on_actionMove_up_triggered()
{ {
try try {
{
m_profile->move(currentRow(), PackProfile::MoveUp); m_profile->move(currentRow(), PackProfile::MoveUp);
} } catch (const Exception& e) {
catch (const Exception &e)
{
QMessageBox::critical(this, tr("Error"), e.cause()); QMessageBox::critical(this, tr("Error"), e.cause());
} }
updateButtons(); updateButtons();
@ -419,12 +377,9 @@ void VersionPage::on_actionMove_up_triggered()
void VersionPage::on_actionMove_down_triggered() void VersionPage::on_actionMove_down_triggered()
{ {
try try {
{
m_profile->move(currentRow(), PackProfile::MoveDown); m_profile->move(currentRow(), PackProfile::MoveDown);
} } catch (const Exception& e) {
catch (const Exception &e)
{
QMessageBox::critical(this, tr("Error"), e.cause()); QMessageBox::critical(this, tr("Error"), e.cause());
} }
updateButtons(); updateButtons();
@ -433,39 +388,32 @@ void VersionPage::on_actionMove_down_triggered()
void VersionPage::on_actionChange_version_triggered() void VersionPage::on_actionChange_version_triggered()
{ {
auto versionRow = currentRow(); auto versionRow = currentRow();
if(versionRow == -1) if (versionRow == -1) {
{
return; return;
} }
auto patch = m_profile->getComponent(versionRow); auto patch = m_profile->getComponent(versionRow);
auto name = patch->getName(); auto name = patch->getName();
auto list = patch->getVersionList(); auto list = patch->getVersionList();
if(!list) if (!list) {
{
return; return;
} }
auto uid = list->uid(); auto uid = list->uid();
// FIXME: this is a horrible HACK. Get version filtering information from the actual metadata... // FIXME: this is a horrible HACK. Get version filtering information from the actual metadata...
if(uid == "net.minecraftforge") if (uid == "net.minecraftforge") {
{
on_actionInstall_Forge_triggered(); on_actionInstall_Forge_triggered();
return; return;
} } else if (uid == "com.mumfrey.liteloader") {
else if (uid == "com.mumfrey.liteloader")
{
on_actionInstall_LiteLoader_triggered(); on_actionInstall_LiteLoader_triggered();
return; return;
} }
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this); VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") {
{
vselect.setEmptyString(tr("No intermediary mappings versions are currently available.")); vselect.setEmptyString(tr("No intermediary mappings versions are currently available."));
vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!"));
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
} }
auto currentVersion = patch->getVersion(); auto currentVersion = patch->getVersion();
if(!currentVersion.isEmpty()) if (!currentVersion.isEmpty()) {
{
vselect.setCurrentVersion(currentVersion); vselect.setCurrentVersion(currentVersion);
} }
if (!vselect.exec() || !vselect.selectedVersion()) if (!vselect.exec() || !vselect.selectedVersion())
@ -473,8 +421,7 @@ void VersionPage::on_actionChange_version_triggered()
qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor(); qDebug() << "Change" << uid << "to" << vselect.selectedVersion()->descriptor();
bool important = false; bool important = false;
if(uid == "net.minecraft") if (uid == "net.minecraft") {
{
important = true; important = true;
} }
m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important); m_profile->setComponentVersion(uid, vselect.selectedVersion()->descriptor(), important);
@ -484,19 +431,17 @@ void VersionPage::on_actionChange_version_triggered()
void VersionPage::on_actionDownload_All_triggered() void VersionPage::on_actionDownload_All_triggered()
{ {
if (!APPLICATION->accounts()->anyAccountIsValid()) if (!APPLICATION->accounts()->anyAccountIsValid()) {
{ CustomMessageBox::selectable(this, tr("Error"),
CustomMessageBox::selectable(
this, tr("Error"),
tr("Cannot download Minecraft or update instances unless you have at least " tr("Cannot download Minecraft or update instances unless you have at least "
"one account added.\nPlease add your Mojang or Minecraft account."), "one account added.\nPlease add your Mojang or Minecraft account."),
QMessageBox::Warning)->show(); QMessageBox::Warning)
->show();
return; return;
} }
auto updateTask = m_inst->createUpdateTask(Net::Mode::Online); auto updateTask = m_inst->createUpdateTask(Net::Mode::Online);
if (!updateTask) if (!updateTask) {
{
return; return;
} }
ProgressDialog tDialog(this); ProgressDialog tDialog(this);
@ -510,23 +455,21 @@ void VersionPage::on_actionDownload_All_triggered()
void VersionPage::on_actionInstall_Forge_triggered() void VersionPage::on_actionInstall_Forge_triggered()
{ {
auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge"); auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge");
if(!vlist) if (!vlist) {
{
return; return;
} }
VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this); VersionSelectDialog vselect(vlist.get(), tr("Select Forge version"), this);
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") +
m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
auto currentVersion = m_profile->getComponentVersion("net.minecraftforge"); auto currentVersion = m_profile->getComponentVersion("net.minecraftforge");
if(!currentVersion.isEmpty()) if (!currentVersion.isEmpty()) {
{
vselect.setCurrentVersion(currentVersion); vselect.setCurrentVersion(currentVersion);
} }
if (vselect.exec() && vselect.selectedVersion()) if (vselect.exec() && vselect.selectedVersion()) {
{
auto vsn = vselect.selectedVersion(); auto vsn = vselect.selectedVersion();
m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor()); m_profile->setComponentVersion("net.minecraftforge", vsn->descriptor());
m_profile->resolve(Net::Mode::Online); m_profile->resolve(Net::Mode::Online);
@ -539,8 +482,7 @@ void VersionPage::on_actionInstall_Forge_triggered()
void VersionPage::on_actionInstall_Fabric_triggered() void VersionPage::on_actionInstall_Fabric_triggered()
{ {
auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader"); auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader");
if(!vlist) if (!vlist) {
{
return; return;
} }
VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this); VersionSelectDialog vselect(vlist.get(), tr("Select Fabric Loader version"), this);
@ -548,13 +490,11 @@ void VersionPage::on_actionInstall_Fabric_triggered()
vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the Fabric Loader version lists!"));
auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader"); auto currentVersion = m_profile->getComponentVersion("net.fabricmc.fabric-loader");
if(!currentVersion.isEmpty()) if (!currentVersion.isEmpty()) {
{
vselect.setCurrentVersion(currentVersion); vselect.setCurrentVersion(currentVersion);
} }
if (vselect.exec() && vselect.selectedVersion()) if (vselect.exec() && vselect.selectedVersion()) {
{
auto vsn = vselect.selectedVersion(); auto vsn = vselect.selectedVersion();
m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor()); m_profile->setComponentVersion("net.fabricmc.fabric-loader", vsn->descriptor());
m_profile->resolve(Net::Mode::Online); m_profile->resolve(Net::Mode::Online);
@ -566,8 +506,7 @@ void VersionPage::on_actionInstall_Fabric_triggered()
void VersionPage::on_actionInstall_Quilt_triggered() void VersionPage::on_actionInstall_Quilt_triggered()
{ {
auto vlist = APPLICATION->metadataIndex()->get("org.quiltmc.quilt-loader"); auto vlist = APPLICATION->metadataIndex()->get("org.quiltmc.quilt-loader");
if(!vlist) if (!vlist) {
{
return; return;
} }
VersionSelectDialog vselect(vlist.get(), tr("Select Quilt Loader version"), this); VersionSelectDialog vselect(vlist.get(), tr("Select Quilt Loader version"), this);
@ -575,13 +514,11 @@ void VersionPage::on_actionInstall_Quilt_triggered()
vselect.setEmptyErrorString(tr("Couldn't load or download the Quilt Loader version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the Quilt Loader version lists!"));
auto currentVersion = m_profile->getComponentVersion("org.quiltmc.quilt-loader"); auto currentVersion = m_profile->getComponentVersion("org.quiltmc.quilt-loader");
if(!currentVersion.isEmpty()) if (!currentVersion.isEmpty()) {
{
vselect.setCurrentVersion(currentVersion); vselect.setCurrentVersion(currentVersion);
} }
if (vselect.exec() && vselect.selectedVersion()) if (vselect.exec() && vselect.selectedVersion()) {
{
auto vsn = vselect.selectedVersion(); auto vsn = vselect.selectedVersion();
m_profile->setComponentVersion("org.quiltmc.quilt-loader", vsn->descriptor()); m_profile->setComponentVersion("org.quiltmc.quilt-loader", vsn->descriptor());
m_profile->resolve(Net::Mode::Online); m_profile->resolve(Net::Mode::Online);
@ -594,14 +531,12 @@ void VersionPage::on_actionAdd_Empty_triggered()
{ {
NewComponentDialog compdialog(QString(), QString(), this); NewComponentDialog compdialog(QString(), QString(), this);
QStringList blacklist; QStringList blacklist;
for(int i = 0; i < m_profile->rowCount(); i++) for (int i = 0; i < m_profile->rowCount(); i++) {
{
auto comp = m_profile->getComponent(i); auto comp = m_profile->getComponent(i);
blacklist.push_back(comp->getID()); blacklist.push_back(comp->getID());
} }
compdialog.setBlacklist(blacklist); compdialog.setBlacklist(blacklist);
if (compdialog.exec()) if (compdialog.exec()) {
{
qDebug() << "name:" << compdialog.name(); qDebug() << "name:" << compdialog.name();
qDebug() << "uid:" << compdialog.uid(); qDebug() << "uid:" << compdialog.uid();
m_profile->installEmpty(compdialog.uid(), compdialog.name()); m_profile->installEmpty(compdialog.uid(), compdialog.name());
@ -611,23 +546,21 @@ void VersionPage::on_actionAdd_Empty_triggered()
void VersionPage::on_actionInstall_LiteLoader_triggered() void VersionPage::on_actionInstall_LiteLoader_triggered()
{ {
auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader"); auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader");
if(!vlist) if (!vlist) {
{
return; return;
} }
VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this); VersionSelectDialog vselect(vlist.get(), tr("Select LiteLoader version"), this);
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft")); vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft")); vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader"); auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader");
if(!currentVersion.isEmpty()) if (!currentVersion.isEmpty()) {
{
vselect.setCurrentVersion(currentVersion); vselect.setCurrentVersion(currentVersion);
} }
if (vselect.exec() && vselect.selectedVersion()) if (vselect.exec() && vselect.selectedVersion()) {
{
auto vsn = vselect.selectedVersion(); auto vsn = vselect.selectedVersion();
m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor()); m_profile->setComponentVersion("com.mumfrey.liteloader", vsn->descriptor());
m_profile->resolve(Net::Mode::Online); m_profile->resolve(Net::Mode::Online);
@ -655,16 +588,13 @@ void VersionPage::versionCurrent(const QModelIndex &current, const QModelIndex &
void VersionPage::preselect(int row) void VersionPage::preselect(int row)
{ {
if(row < 0) if (row < 0) {
{
row = 0; row = 0;
} }
if(row >= m_profile->rowCount(QModelIndex())) if (row >= m_profile->rowCount(QModelIndex())) {
{
row = m_profile->rowCount(QModelIndex()) - 1; row = m_profile->rowCount(QModelIndex()) - 1;
} }
if(row < 0) if (row < 0) {
{
return; return;
} }
auto model_index = m_profile->index(row); auto model_index = m_profile->index(row);
@ -680,8 +610,7 @@ void VersionPage::onGameUpdateError(QString error)
ComponentPtr VersionPage::current() ComponentPtr VersionPage::current()
{ {
auto row = currentRow(); auto row = currentRow();
if(row < 0) if (row < 0) {
{
return nullptr; return nullptr;
} }
return m_profile->getComponent(row); return m_profile->getComponent(row);
@ -689,8 +618,7 @@ ComponentPtr VersionPage::current()
int VersionPage::currentRow() int VersionPage::currentRow()
{ {
if (ui->packageView->selectionModel()->selectedRows().isEmpty()) if (ui->packageView->selectionModel()->selectedRows().isEmpty()) {
{
return -1; return -1;
} }
return ui->packageView->selectionModel()->selectedRows().first().row(); return ui->packageView->selectionModel()->selectedRows().first().row();
@ -699,18 +627,15 @@ int VersionPage::currentRow()
void VersionPage::on_actionCustomize_triggered() void VersionPage::on_actionCustomize_triggered()
{ {
auto version = currentRow(); auto version = currentRow();
if(version == -1) if (version == -1) {
{
return; return;
} }
auto patch = m_profile->getComponent(version); auto patch = m_profile->getComponent(version);
if(!patch->getVersionFile()) if (!patch->getVersionFile()) {
{
// TODO: wait for the update task to finish here... // TODO: wait for the update task to finish here...
return; return;
} }
if(!m_profile->customize(version)) if (!m_profile->customize(version)) {
{
// TODO: some error box here // TODO: some error box here
} }
updateButtons(); updateButtons();
@ -720,13 +645,11 @@ void VersionPage::on_actionCustomize_triggered()
void VersionPage::on_actionEdit_triggered() void VersionPage::on_actionEdit_triggered()
{ {
auto version = current(); auto version = current();
if(!version) if (!version) {
{
return; return;
} }
auto filename = version->getFilename(); auto filename = version->getFilename();
if(!QFileInfo::exists(filename)) if (!QFileInfo::exists(filename)) {
{
qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!"; qWarning() << "file" << filename << "can't be opened for editing, doesn't exist!";
return; return;
} }
@ -736,8 +659,7 @@ void VersionPage::on_actionEdit_triggered()
void VersionPage::on_actionRevert_triggered() void VersionPage::on_actionRevert_triggered()
{ {
auto version = currentRow(); auto version = currentRow();
if(version == -1) if (version == -1) {
{
return; return;
} }
auto component = m_profile->getComponent(version); auto component = m_profile->getComponent(version);
@ -753,8 +675,7 @@ void VersionPage::on_actionRevert_triggered()
if (response != QMessageBox::Yes) if (response != QMessageBox::Yes)
return; return;
if(!m_profile->revertToBase(version)) if (!m_profile->revertToBase(version)) {
{
// TODO: some error box here // TODO: some error box here
} }
updateButtons(); updateButtons();

View File

@ -46,31 +46,20 @@
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "ui/pages/BasePage.h" #include "ui/pages/BasePage.h"
namespace Ui namespace Ui {
{
class VersionPage; class VersionPage;
} }
class VersionPage : public QMainWindow, public BasePage class VersionPage : public QMainWindow, public BasePage {
{
Q_OBJECT Q_OBJECT
public: public:
explicit VersionPage(MinecraftInstance* inst, QWidget* parent = 0); explicit VersionPage(MinecraftInstance* inst, QWidget* parent = 0);
virtual ~VersionPage(); virtual ~VersionPage();
virtual QString displayName() const override virtual QString displayName() const override { return tr("Version"); }
{
return tr("Version");
}
virtual QIcon icon() const override; virtual QIcon icon() const override;
virtual QString id() const override virtual QString id() const override { return "version"; }
{ virtual QString helpPage() const override { return "Instance-Version"; }
return "version";
}
virtual QString helpPage() const override
{
return "Instance-Version";
}
virtual bool shouldDisplay() const override; virtual bool shouldDisplay() const override;
void retranslate() override; void retranslate() override;
@ -122,7 +111,6 @@ private:
std::shared_ptr<PackProfile> m_profile; std::shared_ptr<PackProfile> m_profile;
MinecraftInstance* m_inst; MinecraftInstance* m_inst;
int currentIdx = 0; int currentIdx = 0;
bool controlsEnabled = false;
std::shared_ptr<Setting> m_wide_bar_setting = nullptr; std::shared_ptr<Setting> m_wide_bar_setting = nullptr;
@ -130,7 +118,6 @@ public slots:
void versionCurrent(const QModelIndex& current, const QModelIndex& previous); void versionCurrent(const QModelIndex& current, const QModelIndex& previous);
private slots: private slots:
void updateRunningStatus(bool running);
void onGameUpdateError(QString error); void onGameUpdateError(QString error);
void packageCurrent(const QModelIndex& current, const QModelIndex& previous); void packageCurrent(const QModelIndex& current, const QModelIndex& previous);
void showContextMenu(const QPoint& pos); void showContextMenu(const QPoint& pos);