summaryrefslogtreecommitdiffstats
path: root/application/pages/modplatform
diff options
context:
space:
mode:
Diffstat (limited to 'application/pages/modplatform')
-rw-r--r--application/pages/modplatform/FTBPage.cpp434
-rw-r--r--application/pages/modplatform/FTBPage.h104
-rw-r--r--application/pages/modplatform/FTBPage.ui159
-rw-r--r--application/pages/modplatform/FtbListModel.cpp275
-rw-r--r--application/pages/modplatform/FtbListModel.h68
-rw-r--r--application/pages/modplatform/ImportPage.cpp161
-rw-r--r--application/pages/modplatform/ImportPage.h56
-rw-r--r--application/pages/modplatform/TechnicPage.cpp13
-rw-r--r--application/pages/modplatform/TechnicPage.h50
-rw-r--r--application/pages/modplatform/TwitchPage.cpp47
-rw-r--r--application/pages/modplatform/TwitchPage.h58
-rw-r--r--application/pages/modplatform/TwitchPage.ui33
-rw-r--r--application/pages/modplatform/VanillaPage.cpp94
-rw-r--r--application/pages/modplatform/VanillaPage.h64
-rw-r--r--application/pages/modplatform/VanillaPage.ui20
15 files changed, 979 insertions, 657 deletions
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp
index f438fce7..dca86efd 100644
--- a/application/pages/modplatform/FTBPage.cpp
+++ b/application/pages/modplatform/FTBPage.cpp
@@ -1,222 +1,364 @@
#include "FTBPage.h"
#include "ui_FTBPage.h"
+#include <QInputDialog>
+
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/NewInstanceDialog.h"
#include "modplatform/ftb/FtbPackFetchTask.h"
#include "modplatform/ftb/FtbPackInstallTask.h"
+#include "modplatform/ftb/FtbPrivatePackManager.h"
#include "FtbListModel.h"
FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
+ : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage)
{
- ftbFetchTask = new FtbPackFetchTask();
+ ftbFetchTask.reset(new FtbPackFetchTask());
+ ftbPrivatePacks.reset(new FtbPrivatePackManager());
+
+ ui->setupUi(this);
+
+ {
+ publicFilterModel = new FtbFilterModel(this);
+ publicListModel = new FtbListModel(this);
+ publicFilterModel->setSourceModel(publicListModel);
+
+ ui->publicPackList->setModel(publicFilterModel);
+ ui->publicPackList->setSortingEnabled(true);
+ ui->publicPackList->header()->hide();
+ ui->publicPackList->setIndentation(0);
+ ui->publicPackList->setIconSize(QSize(42, 42));
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
+ for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
+ {
+ ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
+ }
- {
- publicFilterModel = new FtbFilterModel(this);
- publicListModel = new FtbListModel(this);
- publicFilterModel->setSourceModel(publicListModel);
+ ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
+ }
- ui->publicPackList->setModel(publicFilterModel);
- ui->publicPackList->setSortingEnabled(true);
- ui->publicPackList->header()->hide();
- ui->publicPackList->setIndentation(0);
- ui->publicPackList->setIconSize(QSize(42, 42));
+ {
+ thirdPartyFilterModel = new FtbFilterModel(this);
+ thirdPartyModel = new FtbListModel(this);
+ thirdPartyFilterModel->setSourceModel(thirdPartyModel);
- for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++)
- {
- ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i));
- }
+ ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
+ ui->thirdPartyPackList->setSortingEnabled(true);
+ ui->thirdPartyPackList->header()->hide();
+ ui->thirdPartyPackList->setIndentation(0);
+ ui->thirdPartyPackList->setIconSize(QSize(42, 42));
- ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting());
- }
+ thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
+ }
- {
- thirdPartyFilterModel = new FtbFilterModel(this);
- thirdPartyModel = new FtbListModel(this);
- thirdPartyFilterModel->setSourceModel(thirdPartyModel);
+ {
+ privateFilterModel = new FtbFilterModel(this);
+ privateListModel = new FtbListModel(this);
+ privateFilterModel->setSourceModel(privateListModel);
- ui->thirdPartyPackList->setModel(thirdPartyFilterModel);
- ui->thirdPartyPackList->setSortingEnabled(true);
- ui->thirdPartyPackList->header()->hide();
- ui->thirdPartyPackList->setIndentation(0);
- ui->thirdPartyPackList->setIconSize(QSize(42, 42));
+ ui->privatePackList->setModel(privateFilterModel);
+ ui->privatePackList->setSortingEnabled(true);
+ ui->privatePackList->header()->hide();
+ ui->privatePackList->setIndentation(0);
+ ui->privatePackList->setIconSize(QSize(42, 42));
- thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
- }
+ privateFilterModel->setSorting(publicFilterModel->getCurrentSorting());
+ }
- ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
+ ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
- connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
- connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
+ connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
+ connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
- connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
- connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
+ connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged);
+ connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged);
+ connect(ui->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPrivatePackSelectionChanged);
- connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
+ connect(ui->addPackBtn, &QPushButton::pressed, this, &FTBPage::onAddPackClicked);
+ connect(ui->removePackBtn, &QPushButton::pressed, this, &FTBPage::onRemovePackClicked);
- ui->modpackInfo->setOpenExternalLinks(true);
+ connect(ui->tabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
- ui->publicPackList->selectionModel()->reset();
- ui->thirdPartyPackList->selectionModel()->reset();
+ // ui->modpackInfo->setOpenExternalLinks(true);
+
+ ui->publicPackList->selectionModel()->reset();
+ ui->thirdPartyPackList->selectionModel()->reset();
+ ui->privatePackList->selectionModel()->reset();
+
+ onTabChanged(ui->tabWidget->currentIndex());
}
FTBPage::~FTBPage()
{
- delete ui;
- if(ftbFetchTask) {
- ftbFetchTask->deleteLater();
- }
+ delete ui;
}
bool FTBPage::shouldDisplay() const
{
- return true;
+ return true;
}
void FTBPage::openedImpl()
{
- if(!initialized)
- {
- connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
- connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
- ftbFetchTask->fetch();
- initialized = true;
- }
- suggestCurrent();
+ if(!initialized)
+ {
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
+
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFinished, this, &FTBPage::ftbPrivatePackDataDownloadSuccessfully);
+ connect(ftbFetchTask.get(), &FtbPackFetchTask::privateFileDownloadFailed, this, &FTBPage::ftbPrivatePackDataDownloadFailed);
+
+ ftbFetchTask->fetch();
+ ftbPrivatePacks->load();
+ ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().toList());
+ initialized = true;
+ }
+ suggestCurrent();
}
void FTBPage::suggestCurrent()
{
- if(isOpened)
- {
- if(!selected.broken)
- {
- dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
- if(selected.type == FtbPackType::Public) {
- publicListModel->getLogo(selected.logo, [this](QString logo){
- dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
- });
- } else if (selected.type == FtbPackType::ThirdParty) {
- thirdPartyModel->getLogo(selected.logo, [this](QString logo){
- dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
- });
- }
- }
- else
- {
- dialog->setSuggestedPack();
- }
- }
+ if(isOpened)
+ {
+ if(!selected.broken)
+ {
+ dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
+ QString editedLogoName;
+ if(selected.logo.toLower().startsWith("ftb"))
+ {
+ editedLogoName = selected.logo;
+ }
+ else
+ {
+ editedLogoName = "ftb_" + selected.logo;
+ }
+
+ editedLogoName = editedLogoName.left(editedLogoName.lastIndexOf(".png"));
+
+ if(selected.type == FtbPackType::Public)
+ {
+ publicListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ else if (selected.type == FtbPackType::ThirdParty)
+ {
+ thirdPartyModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ else if (selected.type == FtbPackType::Private)
+ {
+ privateListModel->getLogo(selected.logo, [this, editedLogoName](QString logo)
+ {
+ dialog->setSuggestedIconFromFile(logo, editedLogoName);
+ });
+ }
+ }
+ else
+ {
+ dialog->setSuggestedPack();
+ }
+ }
}
void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks)
{
- publicListModel->fill(publicPacks);
- thirdPartyModel->fill(thirdPartyPacks);
+ publicListModel->fill(publicPacks);
+ thirdPartyModel->fill(thirdPartyPacks);
}
void FTBPage::ftbPackDataDownloadFailed(QString reason)
{
- //TODO: Display the error
+ //TODO: Display the error
+}
+
+void FTBPage::ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack)
+{
+ privateListModel->addPack(pack);
+}
+
+void FTBPage::ftbPrivatePackDataDownloadFailed(QString reason, QString packCode)
+{
+ auto reply = QMessageBox::question(
+ this,
+ tr("FTB private packs"),
+ tr("Failed to download pack information for code %1.\nShould it be removed now?").arg(packCode)
+ );
+ if(reply == QMessageBox::Yes)
+ {
+ ftbPrivatePacks->remove(packCode);
+ }
}
void FTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
- if(!now.isValid())
- {
- onPackSelectionChanged();
- return;
- }
- FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&selectedPack);
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = publicFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
}
void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev)
{
- if(!now.isValid())
- {
- onPackSelectionChanged();
- return;
- }
- FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&selectedPack);
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = thirdPartyFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
+}
+
+void FTBPage::onPrivatePackSelectionChanged(QModelIndex now, QModelIndex prev)
+{
+ if(!now.isValid())
+ {
+ onPackSelectionChanged();
+ return;
+ }
+ FtbModpack selectedPack = privateFilterModel->data(now, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&selectedPack);
}
void FTBPage::onPackSelectionChanged(FtbModpack* pack)
{
- ui->packVersionSelection->clear();
- if(pack)
- {
- ui->modpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" + "<br>Minecraft " + pack->mcVersion + "<br>"
- "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>") + "</li></ul>");
- bool currentAdded = false;
-
- for(int i = 0; i < pack->oldVersions.size(); i++)
- {
- if(pack->currentVersion == pack->oldVersions.at(i))
- {
- currentAdded = true;
- }
- ui->packVersionSelection->addItem(pack->oldVersions.at(i));
- }
-
- if(!currentAdded)
- {
- ui->packVersionSelection->addItem(pack->currentVersion);
- }
- selected = *pack;
- }
- suggestCurrent();
+ ui->versionSelectionBox->clear();
+ if(pack)
+ {
+ currentModpackInfo->setHtml("Pack by <b>" + pack->author + "</b>" +
+ "<br>Minecraft " + pack->mcVersion + "<br>" + "<br>" + pack->description + "<ul><li>" + pack->mods.replace(";", "</li><li>")
+ + "</li></ul>");
+ bool currentAdded = false;
+
+ for(int i = 0; i < pack->oldVersions.size(); i++)
+ {
+ if(pack->currentVersion == pack->oldVersions.at(i))
+ {
+ currentAdded = true;
+ }
+ ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
+ }
+
+ if(!currentAdded)
+ {
+ ui->versionSelectionBox->addItem(pack->currentVersion);
+ }
+ selected = *pack;
+ }
+ else
+ {
+ currentModpackInfo->setHtml("");
+ ui->versionSelectionBox->clear();
+ if(isOpened)
+ {
+ dialog->setSuggestedPack();
+ }
+ return;
+ }
+ suggestCurrent();
}
void FTBPage::onVersionSelectionItemChanged(QString data)
{
- if(data.isNull() || data.isEmpty())
- {
- selectedVersion = "";
- return;
- }
+ if(data.isNull() || data.isEmpty())
+ {
+ selectedVersion = "";
+ return;
+ }
- selectedVersion = data;
- suggestCurrent();
+ selectedVersion = data;
+ suggestCurrent();
}
void FTBPage::onSortingSelectionChanged(QString data)
{
- FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
- publicFilterModel->setSorting(toSet);
- thirdPartyFilterModel->setSorting(toSet);
+ FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data);
+ publicFilterModel->setSorting(toSet);
+ thirdPartyFilterModel->setSorting(toSet);
+ privateFilterModel->setSorting(toSet);
}
void FTBPage::onTabChanged(int tab)
{
- FtbFilterModel* currentModel = nullptr;
- QTreeView* currentList = nullptr;
- if (tab == 0)
- {
- currentModel = publicFilterModel;
- currentList = ui->publicPackList;
- }
- else
- {
- currentModel = thirdPartyFilterModel;
- currentList = ui->thirdPartyPackList;
- }
- QModelIndex idx = currentList->currentIndex();
- if(idx.isValid())
- {
- auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
- onPackSelectionChanged(&pack);
- }
- else
- {
- onPackSelectionChanged();
- }
+ if(tab == 1)
+ {
+ currentModel = thirdPartyFilterModel;
+ currentList = ui->thirdPartyPackList;
+ currentModpackInfo = ui->thirdPartyPackDescription;
+ }
+ else if(tab == 2)
+ {
+ currentModel = privateFilterModel;
+ currentList = ui->privatePackList;
+ currentModpackInfo = ui->privatePackDescription;
+ }
+ else
+ {
+ currentModel = publicFilterModel;
+ currentList = ui->publicPackList;
+ currentModpackInfo = ui->publicPackDescription;
+ }
+
+ currentList->selectionModel()->reset();
+ QModelIndex idx = currentList->currentIndex();
+ if(idx.isValid())
+ {
+ auto pack = currentModel->data(idx, Qt::UserRole).value<FtbModpack>();
+ onPackSelectionChanged(&pack);
+ }
+ else
+ {
+ onPackSelectionChanged();
+ }
+}
+
+void FTBPage::onAddPackClicked()
+{
+ bool ok;
+ QString text = QInputDialog::getText(
+ this,
+ tr("Add FTB pack"),
+ tr("Enter pack code:"),
+ QLineEdit::Normal,
+ QString(),
+ &ok
+ );
+ if(ok && !text.isEmpty())
+ {
+ ftbPrivatePacks->add(text);
+ ftbFetchTask->fetchPrivate({text});
+ }
+}
+
+void FTBPage::onRemovePackClicked()
+{
+ auto index = ui->privatePackList->currentIndex();
+ if(!index.isValid())
+ {
+ return;
+ }
+ auto row = index.row();
+ FtbModpack pack = privateListModel->at(row);
+ auto answer = QMessageBox::question(
+ this,
+ tr("Remove pack"),
+ tr("Are you sure you want to remove pack %1?").arg(pack.name),
+ QMessageBox::Yes | QMessageBox::No
+ );
+ if(answer != QMessageBox::Yes)
+ {
+ return;
+ }
+
+ ftbPrivatePacks->remove(pack.packCode);
+ privateListModel->remove(row);
+ onPackSelectionChanged();
}
diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h
index 00c5e9c5..215252ee 100644
--- a/application/pages/modplatform/FTBPage.h
+++ b/application/pages/modplatform/FTBPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,15 @@
#pragma once
#include <QWidget>
+#include <QTreeView>
+#include <QTextBrowser>
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
#include "modplatform/ftb/PackHelpers.h"
#include "modplatform/ftb/FtbPackFetchTask.h"
+#include "QObjectPtr.h"
namespace Ui
{
@@ -31,62 +34,81 @@ class FTBPage;
class FtbListModel;
class FtbFilterModel;
class NewInstanceDialog;
+class FtbPrivatePackListModel;
+class FtbPrivatePackFilterModel;
+class FtbPrivatePackManager;
class FTBPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0);
- virtual ~FTBPage();
- QString displayName() const override
- {
- return tr("FTB Legacy");
- }
- QIcon icon() const override
- {
- return MMC->getThemedIcon("ftb_logo");
- }
- QString id() const override
- {
- return "ftb";
- }
- QString helpPage() const override
- {
- return "FTB-platform";
- }
- bool shouldDisplay() const override;
- void openedImpl() override;
+ explicit FTBPage(NewInstanceDialog * dialog, QWidget *parent = 0);
+ virtual ~FTBPage();
+ QString displayName() const override
+ {
+ return tr("FTB Legacy");
+ }
+ QIcon icon() const override
+ {
+ return MMC->getThemedIcon("ftb_logo");
+ }
+ QString id() const override
+ {
+ return "ftb";
+ }
+ QString helpPage() const override
+ {
+ return "FTB-platform";
+ }
+ bool shouldDisplay() const override;
+ void openedImpl() override;
private:
- void suggestCurrent();
- void onPackSelectionChanged(FtbModpack *pack = nullptr);
+ void suggestCurrent();
+ void onPackSelectionChanged(FtbModpack *pack = nullptr);
private slots:
- void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
- void ftbPackDataDownloadFailed(QString reason);
+ void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
+ void ftbPackDataDownloadFailed(QString reason);
- void onSortingSelectionChanged(QString data);
- void onVersionSelectionItemChanged(QString data);
+ void ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack);
+ void ftbPrivatePackDataDownloadFailed(QString reason, QString packCode);
- void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
- void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onSortingSelectionChanged(QString data);
+ void onVersionSelectionItemChanged(QString data);
- void onTabChanged(int tab);
+ void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second);
+ void onPrivatePackSelectionChanged(QModelIndex first, QModelIndex second);
+
+ void onTabChanged(int tab);
+
+ void onAddPackClicked();
+ void onRemovePackClicked();
private:
- bool initialized = false;
- FtbModpack selected;
- QString selectedVersion;
+ FtbFilterModel* currentModel = nullptr;
+ QTreeView* currentList = nullptr;
+ QTextBrowser* currentModpackInfo = nullptr;
+
+ bool initialized = false;
+ FtbModpack selected;
+ QString selectedVersion;
+
+ FtbListModel* publicListModel = nullptr;
+ FtbFilterModel* publicFilterModel = nullptr;
+
+ FtbListModel *thirdPartyModel = nullptr;
+ FtbFilterModel *thirdPartyFilterModel = nullptr;
- FtbListModel* publicListModel = nullptr;
- FtbFilterModel* publicFilterModel = nullptr;
+ FtbListModel *privateListModel = nullptr;
+ FtbFilterModel *privateFilterModel = nullptr;
- FtbListModel *thirdPartyModel = nullptr;
- FtbFilterModel *thirdPartyFilterModel = nullptr;
+ unique_qobject_ptr<FtbPackFetchTask> ftbFetchTask;
+ std::unique_ptr<FtbPrivatePackManager> ftbPrivatePacks;
- FtbPackFetchTask *ftbFetchTask = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ NewInstanceDialog* dialog = nullptr;
- Ui::FTBPage *ui = nullptr;
+ Ui::FTBPage *ui = nullptr;
};
diff --git a/application/pages/modplatform/FTBPage.ui b/application/pages/modplatform/FTBPage.ui
index cb085af2..e5ed78cb 100644
--- a/application/pages/modplatform/FTBPage.ui
+++ b/application/pages/modplatform/FTBPage.ui
@@ -11,18 +11,6 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
@@ -30,86 +18,107 @@
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
- <string notr="true"/>
+ <string>Public</string>
</attribute>
- <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
- <item row="1" column="2" colspan="2">
- <widget class="QTextBrowser" name="modpackInfo">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QTreeView" name="publicPackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="2">
- <widget class="QLabel" name="selectedVersionLabel">
- <property name="text">
- <string>Version selected:</string>
+ <item row="0" column="1">
+ <widget class="QTextBrowser" name="publicPackDescription"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>3rd Party</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="1">
+ <widget class="QTextBrowser" name="thirdPartyPackDescription"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTreeView" name="thirdPartyPackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
- <property name="alignment">
- <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_3">
+ <attribute name="title">
+ <string>Private</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QTreeView" name="privatePackList">
+ <property name="maximumSize">
+ <size>
+ <width>250</width>
+ <height>16777215</height>
+ </size>
</property>
</widget>
</item>
- <item row="2" column="3">
- <widget class="QComboBox" name="packVersionSelection"/>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="addPackBtn">
+ <property name="text">
+ <string>Add pack</string>
+ </property>
+ </widget>
</item>
<item row="2" column="0">
- <widget class="QComboBox" name="sortByBox"/>
- </item>
- <item row="0" column="0" rowspan="2">
- <widget class="QTabWidget" name="ftbTabWidget">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="tabShape">
- <enum>QTabWidget::Rounded</enum>
- </property>
- <property name="currentIndex">
- <number>0</number>
+ <widget class="QPushButton" name="removePackBtn">
+ <property name="text">
+ <string>Remove selected pack</string>
</property>
- <widget class="QWidget" name="tab_2">
- <attribute name="title">
- <string>Public Packs</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QTreeView" name="publicPackList">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QWidget" name="tab_3">
- <attribute name="title">
- <string>3rd Party Packs</string>
- </attribute>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QTreeView" name="thirdPartyPackList">
- <property name="verticalScrollBarPolicy">
- <enum>Qt::ScrollBarAsNeeded</enum>
- </property>
- <property name="horizontalScrollBarPolicy">
- <enum>Qt::ScrollBarAlwaysOff</enum>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
</widget>
</item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QTextBrowser" name="privatePackDescription"/>
+ </item>
</layout>
</widget>
</widget>
</item>
+ <item>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="0" column="1">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Version selected:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QComboBox" name="versionSelectionBox"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QComboBox" name="sortByBox">
+ <property name="minimumSize">
+ <size>
+ <width>265</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/application/pages/modplatform/FtbListModel.cpp b/application/pages/modplatform/FtbListModel.cpp
index c14907c6..51aec890 100644
--- a/application/pages/modplatform/FtbListModel.cpp
+++ b/application/pages/modplatform/FtbListModel.cpp
@@ -10,56 +10,58 @@
#include <RWStorage.h>
#include <Env.h>
+#include "net/URLConstants.h"
+
FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
{
- currentSorting = Sorting::ByGameVersion;
- sortings.insert(tr("Sort by name"), Sorting::ByName);
- sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
+ currentSorting = Sorting::ByGameVersion;
+ sortings.insert(tr("Sort by name"), Sorting::ByName);
+ sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
}
bool FtbFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
- FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
- FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
+ FtbModpack leftPack = sourceModel()->data(left, Qt::UserRole).value<FtbModpack>();
+ FtbModpack rightPack = sourceModel()->data(right, Qt::UserRole).value<FtbModpack>();
- if(currentSorting == Sorting::ByGameVersion) {
- Version lv(leftPack.mcVersion);
- Version rv(rightPack.mcVersion);
- return lv < rv;
+ if(currentSorting == Sorting::ByGameVersion) {
+ Version lv(leftPack.mcVersion);
+ Version rv(rightPack.mcVersion);
+ return lv < rv;
- } else if(currentSorting == Sorting::ByName) {
- return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
- }
+ } else if(currentSorting == Sorting::ByName) {
+ return Strings::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
+ }
- //UHM, some inavlid value set?!
- qWarning() << "Invalid sorting set!";
- return true;
+ //UHM, some inavlid value set?!
+ qWarning() << "Invalid sorting set!";
+ return true;
}
bool FtbFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
- return true;
+ return true;
}
const QMap<QString, FtbFilterModel::Sorting> FtbFilterModel::getAvailableSortings()
{
- return sortings;
+ return sortings;
}
QString FtbFilterModel::translateCurrentSorting()
{
- return sortings.key(currentSorting);
+ return sortings.key(currentSorting);
}
void FtbFilterModel::setSorting(Sorting s)
{
- currentSorting = s;
- invalidate();
+ currentSorting = s;
+ invalidate();
}
FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting()
{
- return currentSorting;
+ return currentSorting;
}
FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent)
@@ -72,128 +74,183 @@ FtbListModel::~FtbListModel()
QString FtbListModel::translatePackType(FtbPackType type) const
{
- if(type == FtbPackType::Public) {
- return tr("Public Modpack");
- } else if(type == FtbPackType::ThirdParty) {
- return tr("Third Party Modpack");
- } else if(type == FtbPackType::Private) {
- return tr("Private Modpack");
- } else {
- return tr("Unknown Type");
- }
+ switch(type)
+ {
+ case FtbPackType::Public:
+ return tr("Public Modpack");
+ case FtbPackType::ThirdParty:
+ return tr("Third Party Modpack");
+ case FtbPackType::Private:
+ return tr("Private Modpack");
+ }
+ qWarning() << "Unknown FTB modpack type:" << int(type);
+ return QString();
}
int FtbListModel::rowCount(const QModelIndex &parent) const
{
- return modpacks.size();
+ return modpacks.size();
}
int FtbListModel::columnCount(const QModelIndex &parent) const
{
- return 1;
+ return 1;
}
QVariant FtbListModel::data(const QModelIndex &index, int role) const
{
- int pos = index.row();
- if(pos >= modpacks.size() || pos < 0 || !index.isValid()) {
- return QString("INVALID INDEX %1").arg(pos);
- }
-
- FtbModpack pack = modpacks.at(pos);
- if(role == Qt::DisplayRole) {
- return pack.name + "\n" + translatePackType(pack.type);
- } else if (role == Qt::ToolTipRole) {
- if(pack.description.length() > 100) {
- //some magic to prevent to long tooltips and replace html linebreaks
- QString edit = pack.description.left(97);
- edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
- return edit;
-
- }
- return pack.description;
- } else if(role == Qt::DecorationRole) {
- if(m_logoMap.contains(pack.logo)) {
- return (m_logoMap.value(pack.logo));
- }
- QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
- ((FtbListModel *)this)->requestLogo(pack.logo);
- return icon;
- } else if(role == Qt::TextColorRole) {
- if(pack.broken) {
- //FIXME: Hardcoded color
- return QColor(255, 0, 50);
- } else if(pack.bugged) {
- //FIXME: Hardcoded color
- //bugged pack, currently only indicates bugged xml
- return QColor(244, 229, 66);
- }
- } else if(role == Qt::UserRole) {
- QVariant v;
- v.setValue(pack);
- return v;
- }
-
- return QVariant();
+ int pos = index.row();
+ if(pos >= modpacks.size() || pos < 0 || !index.isValid())
+ {
+ return QString("INVALID INDEX %1").arg(pos);
+ }
+
+ FtbModpack pack = modpacks.at(pos);
+ if(role == Qt::DisplayRole)
+ {
+ return pack.name + "\n" + translatePackType(pack.type);
+ }
+ else if (role == Qt::ToolTipRole)
+ {
+ if(pack.description.length() > 100)
+ {
+ //some magic to prevent to long tooltips and replace html linebreaks
+ QString edit = pack.description.left(97);
+ edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
+ return edit;
+
+ }
+ return pack.description;
+ }
+ else if(role == Qt::DecorationRole)
+ {
+ if(m_logoMap.contains(pack.logo))
+ {
+ return (m_logoMap.value(pack.logo));
+ }
+ QIcon icon = MMC->getThemedIcon("screenshot-placeholder");
+ ((FtbListModel *)this)->requestLogo(pack.logo);
+ return icon;
+ }
+ else if(role == Qt::TextColorRole)
+ {
+ if(pack.broken)
+ {
+ //FIXME: Hardcoded color
+ return QColor(255, 0, 50);
+ }
+ else if(pack.bugged)
+ {
+ //FIXME: Hardcoded color
+ //bugged pack, currently only indicates bugged xml
+ return QColor(244, 229, 66);
+ }
+ }
+ else if(role == Qt::UserRole)
+ {
+ QVariant v;
+ v.setValue(pack);
+ return v;
+ }
+
+ return QVariant();
}
void FtbListModel::fill(FtbModpackList modpacks)
{
- beginResetModel();
- this->modpacks = modpacks;
- endResetModel();
+ beginResetModel();
+ this->modpacks = modpacks;
+ endResetModel();
+}
+
+void FtbListModel::addPack(FtbModpack modpack)
+{
+ beginResetModel();
+ this->modpacks.append(modpack);
+ endResetModel();
+}
+
+void FtbListModel::clear()
+{
+ beginResetModel();
+ modpacks.clear();
+ endResetModel();
}
FtbModpack FtbListModel::at(int row)
{
- return modpacks.at(row);
+ return modpacks.at(row);
+}
+
+void FtbListModel::remove(int row)
+{
+ if(row < 0 || row >= modpacks.size())
+ {
+ qWarning() << "Attempt to remove FTB modpacks with invalid row" << row;
+ return;
+ }
+ beginRemoveRows(QModelIndex(), row, row);
+ modpacks.removeAt(row);
+ endRemoveRows();
}
void FtbListModel::logoLoaded(QString logo, QIcon out)
{
- m_loadingLogos.removeAll(logo);
- m_logoMap.insert(logo, out);
- emit dataChanged(createIndex(0, 0), createIndex(1, 0));
+ m_loadingLogos.removeAll(logo);
+ m_logoMap.insert(logo, out);
+ emit dataChanged(createIndex(0, 0), createIndex(1, 0));
}
void FtbListModel::logoFailed(QString logo)
{
- m_failedLogos.append(logo);
- m_loadingLogos.removeAll(logo);
+ m_failedLogos.append(logo);
+ m_loadingLogos.removeAll(logo);
}
void FtbListModel::requestLogo(QString file)
{
- if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
- return;
- }
-
- MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
- NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
- job->addNetAction(Net::Download::makeCached(QUrl(QString("https://ftb.cursecdn.com/FTB2/static/%1").arg(file)), entry));
-
- auto fullPath = entry->getFullPath();
- QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
- emit logoLoaded(file, QIcon(fullPath));
- if(waitingCallbacks.contains(file)) {
- waitingCallbacks.value(file)(fullPath);
- }
- });
-
- QObject::connect(job, &NetJob::failed, this, [this, file]{
- emit logoFailed(file);
- });
-
- job->start();
-
- m_loadingLogos.append(file);
+ if(m_loadingLogos.contains(file) || m_failedLogos.contains(file))
+ {
+ return;
+ }
+
+ MetaEntryPtr entry = ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0)));
+ NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file));
+ job->addNetAction(Net::Download::makeCached(QUrl(QString(URLConstants::FTB_CDN_BASE_URL + "static/%1").arg(file)), entry));
+
+ auto fullPath = entry->getFullPath();
+ QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]
+ {
+ emit logoLoaded(file, QIcon(fullPath));
+ if(waitingCallbacks.contains(file))
+ {
+ waitingCallbacks.value(file)(fullPath);
+ }
+ });
+
+ QObject::connect(job, &NetJob::failed, this, [this, file]
+ {
+ emit logoFailed(file);
+ });
+
+ job->start();
+
+ m_loadingLogos.append(file);
}
void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
{
- if(m_logoMap.contains(logo)) {
- callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
- } else {
- requestLogo(logo);
- }
+ if(m_logoMap.contains(logo))
+ {
+ callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ }
+ else
+ {
+ requestLogo(logo);
+ }
+}
+
+Qt::ItemFlags FtbListModel::flags(const QModelIndex &index) const
+{
+ return QAbstractListModel::flags(index);
}
diff --git a/application/pages/modplatform/FtbListModel.h b/application/pages/modplatform/FtbListModel.h
index d3a82b73..34749b24 100644
--- a/application/pages/modplatform/FtbListModel.h
+++ b/application/pages/modplatform/FtbListModel.h
@@ -7,6 +7,7 @@
#include <QSortFilterProxyModel>
#include <QThreadPool>
#include <QIcon>
+#include <QStyledItemDelegate>
#include <functional>
@@ -15,54 +16,59 @@ typedef std::function<void(QString)> LogoCallback;
class FtbFilterModel : public QSortFilterProxyModel
{
+ Q_OBJECT
public:
- FtbFilterModel(QObject* parent = Q_NULLPTR);
- enum Sorting {
- ByName,
- ByGameVersion
- };
- const QMap<QString, Sorting> getAvailableSortings();
- QString translateCurrentSorting();
- void setSorting(Sorting sorting);
- Sorting getCurrentSorting();
+ FtbFilterModel(QObject* parent = Q_NULLPTR);
+ enum Sorting {
+ ByName,
+ ByGameVersion
+ };
+ const QMap<QString, Sorting> getAvailableSortings();
+ QString translateCurrentSorting();
+ void setSorting(Sorting sorting);
+ Sorting getCurrentSorting();
protected:
- bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
- bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
- QMap<QString, Sorting> sortings;
- Sorting currentSorting;
+ QMap<QString, Sorting> sortings;
+ Sorting currentSorting;
};
class FtbListModel : public QAbstractListModel
{
- Q_OBJECT
+ Q_OBJECT
private:
- FtbModpackList modpacks;
- QStringList m_failedLogos;
- QStringList m_loadingLogos;
- FtbLogoMap m_logoMap;
- QMap<QString, LogoCallback> waitingCallbacks;
+ FtbModpackList modpacks;
+ QStringList m_failedLogos;
+ QStringList m_loadingLogos;
+ FtbLogoMap m_logoMap;
+ QMap<QString, LogoCallback> waitingCallbacks;
- void requestLogo(QString file);
- QString translatePackType(FtbPackType type) const;
+ void requestLogo(QString file);
+ QString translatePackType(FtbPackType type) const;
private slots:
- void logoFailed(QString logo);
- void logoLoaded(QString logo, QIcon out);
+ void logoFailed(QString logo);
+ void logoLoaded(QString logo, QIcon out);
public:
- FtbListModel(QObject *parent);
- ~FtbListModel();
- int rowCount(const QModelIndex &parent) const override;
- int columnCount(const QModelIndex &parent) const override;
- QVariant data(const QModelIndex &index, int role) const override;
+ FtbListModel(QObject *parent);
+ ~FtbListModel();
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
- void fill(FtbModpackList modpacks);
+ void fill(FtbModpackList modpacks);
+ void addPack(FtbModpack modpack);
+ void clear();
+ void remove(int row);
- FtbModpack at(int row);
- void getLogo(const QString &logo, LogoCallback callback);
+ FtbModpack at(int row);
+ void getLogo(const QString &logo, LogoCallback callback);
};
diff --git a/application/pages/modplatform/ImportPage.cpp b/application/pages/modplatform/ImportPage.cpp
index 75a51245..af243511 100644
--- a/application/pages/modplatform/ImportPage.cpp
+++ b/application/pages/modplatform/ImportPage.cpp
@@ -2,11 +2,9 @@
#include "ui_ImportPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
#include <QFileDialog>
+#include <QValidator>
#include <InstanceImportTask.h>
#include <QTabBar>
#include <QValidator>
@@ -14,114 +12,119 @@
class UrlValidator : public QValidator
{
public:
- using QValidator::QValidator;
+ using QValidator::QValidator;
- State validate(QString &in, int &pos) const
- {
- const QUrl url(in);
- if (url.isValid() && !url.isRelative() && !url.isEmpty())
- {
- return Acceptable;
- }
- else if (QFile::exists(in))
- {
- return Acceptable;
- }
- else
- {
- return Intermediate;
- }
- }
+ State validate(QString &in, int &pos) const
+ {
+ const QUrl url(in);
+ if (url.isValid() && !url.isRelative() && !url.isEmpty())
+ {
+ return Acceptable;
+ }
+ else if (QFile::exists(in))
+ {
+ return Acceptable;
+ }
+ else
+ {
+ return Intermediate;
+ }
+ }
};
ImportPage::ImportPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
+ : QWidget(parent), ui(new Ui::ImportPage), dialog(dialog)
{
- ui->setupUi(this);
- ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
- connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
+ ui->setupUi(this);
+ ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
+ connect(ui->modpackEdit, &QLineEdit::textChanged, this, &ImportPage::updateState);
}
ImportPage::~ImportPage()
{
- delete ui;
+ delete ui;
}
bool ImportPage::shouldDisplay() const
{
- return true;
+ return true;
}
void ImportPage::openedImpl()
{
- updateState();
+ updateState();
}
void ImportPage::updateState()
{
- if(!isOpened)
- {
- return;
- }
- if(ui->modpackEdit->hasAcceptableInput())
- {
- QString input = ui->modpackEdit->text();
- auto url = QUrl::fromUserInput(input);
- if(url.isLocalFile())
- {
- // FIXME: actually do some validation of what's inside here... this is fake AF
- QFileInfo fi(input);
- if(fi.exists() && fi.suffix() == "zip")
- {
- QFileInfo fi(url.fileName());
- dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
- }
- }
- else
- {
- // hook, line and sinker.
- QFileInfo fi(url.fileName());
- dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
- }
- }
- else
- {
- dialog->setSuggestedPack();
- }
+ if(!isOpened)
+ {
+ return;
+ }
+ if(ui->modpackEdit->hasAcceptableInput())
+ {
+ QString input = ui->modpackEdit->text();
+ auto url = QUrl::fromUserInput(input);
+ if(url.isLocalFile())
+ {
+ // FIXME: actually do some validation of what's inside here... this is fake AF
+ QFileInfo fi(input);
+ if(fi.exists() && fi.suffix() == "zip")
+ {
+ QFileInfo fi(url.fileName());
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
+ }
+ }
+ else
+ {
+ if(input.endsWith("?client=y")) {
+ input.chop(9);
+ input.append("/file");
+ url = QUrl::fromUserInput(input);
+ }
+ // hook, line and sinker.
+ QFileInfo fi(url.fileName());
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(url));
+ }
+ }
+ else
+ {
+ dialog->setSuggestedPack();
+ }
}
void ImportPage::setUrl(const QString& url)
{
- ui->modpackEdit->setText(url);
- updateState();
+ ui->modpackEdit->setText(url);
+ updateState();
}
void ImportPage::on_modpackBtn_clicked()
{
- const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)"));
- if (url.isValid())
- {
- if (url.isLocalFile())
- {
- ui->modpackEdit->setText(url.toLocalFile());
- }
- else
- {
- ui->modpackEdit->setText(url.toString());
- }
- }
+ const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Choose modpack"), modpackUrl(), tr("Zip (*.zip)"));
+ if (url.isValid())
+ {
+ if (url.isLocalFile())
+ {
+ ui->modpackEdit->setText(url.toLocalFile());
+ }
+ else
+ {
+ ui->modpackEdit->setText(url.toString());
+ }
+ }
}
QUrl ImportPage::modpackUrl() const
{
- const QUrl url(ui->modpackEdit->text());
- if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
- {
- return url;
- }
- else
- {
- return QUrl::fromLocalFile(ui->modpackEdit->text());
- }
+ const QUrl url(ui->modpackEdit->text());
+ if (url.isValid() && !url.isRelative() && !url.host().isEmpty())
+ {
+ return url;
+ }
+ else
+ {
+ return QUrl::fromLocalFile(ui->modpackEdit->text());
+ }
}
diff --git a/application/pages/modplatform/ImportPage.h b/application/pages/modplatform/ImportPage.h
index 8f62e6b1..3afb0045 100644
--- a/application/pages/modplatform/ImportPage.h
+++ b/application/pages/modplatform/ImportPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,41 +30,41 @@ class NewInstanceDialog;
class ImportPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0);
- virtual ~ImportPage();
- virtual QString displayName() const override
- {
- return tr("Import from zip");
- }
- virtual QIcon icon() const override
- {
- return MMC->getThemedIcon("viewfolder");
- }
- virtual QString id() const override
- {
- return "import";
- }
- virtual QString helpPage() const override
- {
- return "Zip-import";
- }
- virtual bool shouldDisplay() const override;
+ explicit ImportPage(NewInstanceDialog* dialog, QWidget *parent = 0);
+ virtual ~ImportPage();
+ virtual QString displayName() const override
+ {
+ return tr("Import from zip");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("viewfolder");
+ }
+ virtual QString id() const override
+ {
+ return "import";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Zip-import";
+ }
+ virtual bool shouldDisplay() const override;
- void setUrl(const QString & url);
- void openedImpl() override;
+ void setUrl(const QString & url);
+ void openedImpl() override;
private slots:
- void on_modpackBtn_clicked();
- void updateState();
+ void on_modpackBtn_clicked();
+ void updateState();
private:
- QUrl modpackUrl() const;
+ QUrl modpackUrl() const;
private:
- Ui::ImportPage *ui = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ Ui::ImportPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
};
diff --git a/application/pages/modplatform/TechnicPage.cpp b/application/pages/modplatform/TechnicPage.cpp
index c0f4faa5..2f95bec8 100644
--- a/application/pages/modplatform/TechnicPage.cpp
+++ b/application/pages/modplatform/TechnicPage.cpp
@@ -2,28 +2,25 @@
#include "ui_TechnicPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
+ : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
}
TechnicPage::~TechnicPage()
{
- delete ui;
+ delete ui;
}
bool TechnicPage::shouldDisplay() const
{
- return true;
+ return true;
}
void TechnicPage::openedImpl()
{
- dialog->setSuggestedPack();
+ dialog->setSuggestedPack();
}
diff --git a/application/pages/modplatform/TechnicPage.h b/application/pages/modplatform/TechnicPage.h
index 5b0f16a6..cc82ddf3 100644
--- a/application/pages/modplatform/TechnicPage.h
+++ b/application/pages/modplatform/TechnicPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,32 +30,32 @@ class NewInstanceDialog;
class TechnicPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0);
- virtual ~TechnicPage();
- virtual QString displayName() const override
- {
- return tr("Technic");
- }
- virtual QIcon icon() const override
- {
- return MMC->getThemedIcon("technic");
- }
- virtual QString id() const override
- {
- return "technic";
- }
- virtual QString helpPage() const override
- {
- return "Technic-platform";
- }
- virtual bool shouldDisplay() const override;
-
- void openedImpl() override;
+ explicit TechnicPage(NewInstanceDialog* dialog, QWidget *parent = 0);
+ virtual ~TechnicPage();
+ virtual QString displayName() const override
+ {
+ return tr("Technic");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("technic");
+ }
+ virtual QString id() const override
+ {
+ return "technic";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Technic-platform";
+ }
+ virtual bool shouldDisplay() const override;
+
+ void openedImpl() override;
private:
- Ui::TechnicPage *ui = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ Ui::TechnicPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
};
diff --git a/application/pages/modplatform/TwitchPage.cpp b/application/pages/modplatform/TwitchPage.cpp
index 42aa46be..ea0f9267 100644
--- a/application/pages/modplatform/TwitchPage.cpp
+++ b/application/pages/modplatform/TwitchPage.cpp
@@ -2,28 +2,59 @@
#include "ui_TwitchPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/NewInstanceDialog.h"
+#include <InstanceImportTask.h>
TwitchPage::TwitchPage(NewInstanceDialog* dialog, QWidget *parent)
- : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
+ : QWidget(parent), ui(new Ui::TwitchPage), dialog(dialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
+ connect(ui->checkButton, &QPushButton::clicked, this, &TwitchPage::triggerCheck);
}
TwitchPage::~TwitchPage()
{
- delete ui;
+ delete ui;
}
bool TwitchPage::shouldDisplay() const
{
- return false;
+ return true;
}
void TwitchPage::openedImpl()
{
- dialog->setSuggestedPack();
+ dialog->setSuggestedPack();
+}
+
+void TwitchPage::triggerCheck(bool)
+{
+ if(m_modIdResolver) {
+ return;
+ }
+ auto task = new Flame::UrlResolvingTask(ui->lineEdit->text());
+ connect(task, &Task::finished, this, &TwitchPage::checkDone);
+ m_modIdResolver.reset(task);
+ task->start();
+}
+
+void TwitchPage::setUrl(const QString& url)
+{
+ ui->lineEdit->setText(url);
+ triggerCheck(true);
+}
+
+void TwitchPage::checkDone()
+{
+ auto result = m_modIdResolver->getResults();
+ auto formatted = QString("Project %1, File %2").arg(result.projectId).arg(result.fileId);
+ if(result.resolved && result.type == Flame::File::Type::Modpack) {
+ ui->twitchLabel->setText(formatted);
+ QFileInfo fi(result.fileName);
+ dialog->setSuggestedPack(fi.completeBaseName(), new InstanceImportTask(result.url));
+ } else {
+ ui->twitchLabel->setPixmap(QPixmap(QString::fromUtf8(":/assets/deadglitch")));
+ dialog->setSuggestedPack();
+ }
+ m_modIdResolver.reset();
}
diff --git a/application/pages/modplatform/TwitchPage.h b/application/pages/modplatform/TwitchPage.h
index 8e072917..600913cd 100644
--- a/application/pages/modplatform/TwitchPage.h
+++ b/application/pages/modplatform/TwitchPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
#include "pages/BasePage.h"
#include <MultiMC.h>
#include "tasks/Task.h"
+#include "modplatform/flame/UrlResolvingTask.h"
namespace Ui
{
@@ -30,32 +31,39 @@ class NewInstanceDialog;
class TwitchPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
- virtual ~TwitchPage();
- virtual QString displayName() const override
- {
- return tr("Twitch");
- }
- virtual QIcon icon() const override
- {
- return MMC->getThemedIcon("twitch");
- }
- virtual QString id() const override
- {
- return "twitch";
- }
- virtual QString helpPage() const override
- {
- return "Twitch-platform";
- }
- virtual bool shouldDisplay() const override;
-
- void openedImpl() override;
+ explicit TwitchPage(NewInstanceDialog* dialog, QWidget *parent = 0);
+ virtual ~TwitchPage();
+ virtual QString displayName() const override
+ {
+ return tr("Twitch URL");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("twitch");
+ }
+ virtual QString id() const override
+ {
+ return "twitch";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Twitch-platform";
+ }
+ virtual bool shouldDisplay() const override;
+
+ void openedImpl() override;
+
+ void setUrl(const QString & url);
+
+private slots:
+ void triggerCheck(bool checked);
+ void checkDone();
private:
- Ui::TwitchPage *ui = nullptr;
- NewInstanceDialog* dialog = nullptr;
+ Ui::TwitchPage *ui = nullptr;
+ NewInstanceDialog* dialog = nullptr;
+ shared_qobject_ptr<Flame::UrlResolvingTask> m_modIdResolver;
};
diff --git a/application/pages/modplatform/TwitchPage.ui b/application/pages/modplatform/TwitchPage.ui
index 0930f541..0db2484d 100644
--- a/application/pages/modplatform/TwitchPage.ui
+++ b/application/pages/modplatform/TwitchPage.ui
@@ -10,9 +10,25 @@
<height>405</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="label_3">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Twitch URL:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="3">
+ <widget class="QLabel" name="twitchLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="font">
<font>
<pointsize>40</pointsize>
@@ -26,8 +42,19 @@
</property>
</widget>
</item>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="checkButton">
+ <property name="text">
+ <string>Check</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
+ <tabstops>
+ <tabstop>lineEdit</tabstop>
+ <tabstop>checkButton</tabstop>
+ </tabstops>
<resources>
<include location="../../resources/assets/assets.qrc"/>
</resources>
diff --git a/application/pages/modplatform/VanillaPage.cpp b/application/pages/modplatform/VanillaPage.cpp
index c355fccb..17535f1e 100644
--- a/application/pages/modplatform/VanillaPage.cpp
+++ b/application/pages/modplatform/VanillaPage.cpp
@@ -2,9 +2,6 @@
#include "ui_VanillaPage.h"
#include "MultiMC.h"
-#include "FolderInstanceProvider.h"
-#include "dialogs/CustomMessageBox.h"
-#include "dialogs/ProgressDialog.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
@@ -15,81 +12,84 @@
#include <QTabBar>
VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent)
- : QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
+ : QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage)
{
- ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
- connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion);
- filterChanged();
- connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
- connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
- connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
- connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
- connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
- connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
+ ui->setupUi(this);
+ ui->tabWidget->tabBar()->hide();
+ connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &VanillaPage::setSelectedVersion);
+ filterChanged();
+ connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->betaFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->oldSnapshotFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->experimentsFilter, &QCheckBox::stateChanged, this, &VanillaPage::filterChanged);
+ connect(ui->refreshBtn, &QPushButton::clicked, this, &VanillaPage::refresh);
}
void VanillaPage::openedImpl()
{
- if(!initialized)
- {
- auto vlist = ENV.metadataIndex()->get("net.minecraft");
- ui->versionList->initialize(vlist.get());
- initialized = true;
- }
- else
- {
- suggestCurrent();
- }
+ if(!initialized)
+ {
+ auto vlist = ENV.metadataIndex()->get("net.minecraft");
+ ui->versionList->initialize(vlist.get());
+ initialized = true;
+ }
+ else
+ {
+ suggestCurrent();
+ }
}
void VanillaPage::refresh()
{
- ui->versionList->loadList();
+ ui->versionList->loadList();
}
void VanillaPage::filterChanged()
{
- QStringList out;
- if(ui->alphaFilter->isChecked())
- out << "(old_alpha)";
- if(ui->betaFilter->isChecked())
- out << "(old_beta)";
- if(ui->snapshotFilter->isChecked())
- out << "(snapshot)";
- if(ui->oldSnapshotFilter->isChecked())
- out << "(old_snapshot)";
- if(ui->releaseFilter->isChecked())
- out << "(release)";
- auto regexp = out.join('|');
- ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
+ QStringList out;
+ if(ui->alphaFilter->isChecked())
+ out << "(old_alpha)";
+ if(ui->betaFilter->isChecked())
+ out << "(old_beta)";
+ if(ui->snapshotFilter->isChecked())
+ out << "(snapshot)";
+ if(ui->oldSnapshotFilter->isChecked())
+ out << "(old_snapshot)";
+ if(ui->releaseFilter->isChecked())
+ out << "(release)";
+ if(ui->experimentsFilter->isChecked())
+ out << "(experiment)";
+ auto regexp = out.join('|');
+ ui->versionList->setFilter(BaseVersionList::TypeRole, new RegexpFilter(regexp, false));
}
VanillaPage::~VanillaPage()
{
- delete ui;
+ delete ui;
}
bool VanillaPage::shouldDisplay() const
{
- return true;
+ return true;
}
BaseVersionPtr VanillaPage::selectedVersion() const
{
- return m_selectedVersion;
+ return m_selectedVersion;
}
void VanillaPage::suggestCurrent()
{
- if(m_selectedVersion && isOpened)
- {
- dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
- }
+ if(m_selectedVersion && isOpened)
+ {
+ dialog->setSuggestedPack(m_selectedVersion->descriptor(), new InstanceCreationTask(m_selectedVersion));
+ }
}
void VanillaPage::setSelectedVersion(BaseVersionPtr version)
{
- m_selectedVersion = version;
- suggestCurrent();
+ m_selectedVersion = version;
+ suggestCurrent();
}
diff --git a/application/pages/modplatform/VanillaPage.h b/application/pages/modplatform/VanillaPage.h
index 91c65edf..cc77733c 100644
--- a/application/pages/modplatform/VanillaPage.h
+++ b/application/pages/modplatform/VanillaPage.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2018 MultiMC Contributors
+/* Copyright 2013-2019 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,46 +30,46 @@ class NewInstanceDialog;
class VanillaPage : public QWidget, public BasePage
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0);
- virtual ~VanillaPage();
- virtual QString displayName() const override
- {
- return tr("Vanilla");
- }
- virtual QIcon icon() const override
- {
- return MMC->getThemedIcon("minecraft");
- }
- virtual QString id() const override
- {
- return "vanilla";
- }
- virtual QString helpPage() const override
- {
- return "Vanilla-platform";
- }
- virtual bool shouldDisplay() const override;
- void openedImpl() override;
+ explicit VanillaPage(NewInstanceDialog *dialog, QWidget *parent = 0);
+ virtual ~VanillaPage();
+ virtual QString displayName() const override
+ {
+ return tr("Vanilla");
+ }
+ virtual QIcon icon() const override
+ {
+ return MMC->getThemedIcon("minecraft");
+ }
+ virtual QString id() const override
+ {
+ return "vanilla";
+ }
+ virtual QString helpPage() const override
+ {
+ return "Vanilla-platform";
+ }
+ virtual bool shouldDisplay() const override;
+ void openedImpl() override;
- BaseVersionPtr selectedVersion() const;
+ BaseVersionPtr selectedVersion() const;
public slots:
- void setSelectedVersion(BaseVersionPtr version);
+ void setSelectedVersion(BaseVersionPtr version);
private slots:
- void filterChanged();
+ void filterChanged();
private:
- void refresh();
- void suggestCurrent();
+ void refresh();
+ void suggestCurrent();
private:
- bool initialized = false;
- NewInstanceDialog *dialog = nullptr;
- Ui::VanillaPage *ui = nullptr;
- bool m_versionSetByUser = false;
- BaseVersionPtr m_selectedVersion;
+ bool initialized = false;
+ NewInstanceDialog *dialog = nullptr;
+ Ui::VanillaPage *ui = nullptr;
+ bool m_versionSetByUser = false;
+ BaseVersionPtr m_selectedVersion;
};
diff --git a/application/pages/modplatform/VanillaPage.ui b/application/pages/modplatform/VanillaPage.ui
index ae9cab47..47effc86 100644
--- a/application/pages/modplatform/VanillaPage.ui
+++ b/application/pages/modplatform/VanillaPage.ui
@@ -99,6 +99,16 @@
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="experimentsFilter">
+ <property name="text">
+ <string>Experiments</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -144,6 +154,16 @@
<container>1</container>
</customwidget>
</customwidgets>
+ <tabstops>
+ <tabstop>tabWidget</tabstop>
+ <tabstop>releaseFilter</tabstop>
+ <tabstop>snapshotFilter</tabstop>
+ <tabstop>oldSnapshotFilter</tabstop>
+ <tabstop>betaFilter</tabstop>
+ <tabstop>alphaFilter</tabstop>
+ <tabstop>experimentsFilter</tabstop>
+ <tabstop>refreshBtn</tabstop>
+ </tabstops>
<resources/>
<connections/>
</ui>