summaryrefslogtreecommitdiffstats
path: root/application/pages
diff options
context:
space:
mode:
authorJannis Lübke <werbung.janrupf@t-online.de>2018-08-02 00:52:31 +0200
committerPetr Mrázek <peterix@gmail.com>2018-08-02 00:52:31 +0200
commit6aada8adf7df5075d5838512670a0b2cc2bc12a1 (patch)
tree46460efee6d3f1bd66bc611e4ad4665362d36bf0 /application/pages
parent6cee50eac6c25796eb3642239385b0c58860cd58 (diff)
downloadMultiMC-6aada8adf7df5075d5838512670a0b2cc2bc12a1.tar
MultiMC-6aada8adf7df5075d5838512670a0b2cc2bc12a1.tar.gz
MultiMC-6aada8adf7df5075d5838512670a0b2cc2bc12a1.tar.lz
MultiMC-6aada8adf7df5075d5838512670a0b2cc2bc12a1.tar.xz
MultiMC-6aada8adf7df5075d5838512670a0b2cc2bc12a1.zip
NOISSUE FTB pack code implementation, cleaned up
Diffstat (limited to 'application/pages')
-rw-r--r--application/pages/modplatform/FTBPage.cpp203
-rw-r--r--application/pages/modplatform/FTBPage.h24
-rw-r--r--application/pages/modplatform/FTBPage.ui159
-rw-r--r--application/pages/modplatform/FtbListModel.cpp103
-rw-r--r--application/pages/modplatform/FtbListModel.h5
5 files changed, 364 insertions, 130 deletions
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp
index 1884bbfb..dca86efd 100644
--- a/application/pages/modplatform/FTBPage.cpp
+++ b/application/pages/modplatform/FTBPage.cpp
@@ -1,20 +1,23 @@
#include "FTBPage.h"
#include "ui_FTBPage.h"
+#include <QInputDialog>
+
#include "MultiMC.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)
{
- ftbFetchTask = new FtbPackFetchTask();
+ ftbFetchTask.reset(new FtbPackFetchTask());
+ ftbPrivatePacks.reset(new FtbPrivatePackManager());
ui->setupUi(this);
- ui->tabWidget->tabBar()->hide();
{
publicFilterModel = new FtbFilterModel(this);
@@ -49,29 +52,47 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
}
- ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
+ {
+ privateFilterModel = new FtbFilterModel(this);
+ privateListModel = new FtbListModel(this);
+ privateFilterModel->setSourceModel(privateListModel);
+
+ ui->privatePackList->setModel(privateFilterModel);
+ ui->privatePackList->setSortingEnabled(true);
+ ui->privatePackList->header()->hide();
+ ui->privatePackList->setIndentation(0);
+ ui->privatePackList->setIconSize(QSize(42, 42));
+
+ privateFilterModel->setSorting(publicFilterModel->getCurrentSorting());
+ }
+
+ 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->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->privatePackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPrivatePackSelectionChanged);
+
+ connect(ui->addPackBtn, &QPushButton::pressed, this, &FTBPage::onAddPackClicked);
+ connect(ui->removePackBtn, &QPushButton::pressed, this, &FTBPage::onRemovePackClicked);
- connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
+ connect(ui->tabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged);
- ui->modpackInfo->setOpenExternalLinks(true);
+ // 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();
- }
}
bool FTBPage::shouldDisplay() const
@@ -83,9 +104,15 @@ void FTBPage::openedImpl()
{
if(!initialized)
{
- connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully);
- connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed);
+ 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();
@@ -98,13 +125,37 @@ void FTBPage::suggestCurrent()
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);
+ 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](QString logo){
- dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
+ }
+ 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);
});
}
}
@@ -126,6 +177,24 @@ void FTBPage::ftbPackDataDownloadFailed(QString reason)
//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())
@@ -148,13 +217,25 @@ void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex now, QModelIndex prev
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();
+ ui->versionSelectionBox->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>");
+ 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++)
@@ -163,15 +244,25 @@ void FTBPage::onPackSelectionChanged(FtbModpack* pack)
{
currentAdded = true;
}
- ui->packVersionSelection->addItem(pack->oldVersions.at(i));
+ ui->versionSelectionBox->addItem(pack->oldVersions.at(i));
}
if(!currentAdded)
{
- ui->packVersionSelection->addItem(pack->currentVersion);
+ ui->versionSelectionBox->addItem(pack->currentVersion);
}
selected = *pack;
}
+ else
+ {
+ currentModpackInfo->setHtml("");
+ ui->versionSelectionBox->clear();
+ if(isOpened)
+ {
+ dialog->setSuggestedPack();
+ }
+ return;
+ }
suggestCurrent();
}
@@ -192,22 +283,31 @@ void FTBPage::onSortingSelectionChanged(QString data)
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)
+ if(tab == 1)
{
- currentModel = publicFilterModel;
- currentList = ui->publicPackList;
+ currentModel = thirdPartyFilterModel;
+ currentList = ui->thirdPartyPackList;
+ currentModpackInfo = ui->thirdPartyPackDescription;
+ }
+ else if(tab == 2)
+ {
+ currentModel = privateFilterModel;
+ currentList = ui->privatePackList;
+ currentModpackInfo = ui->privatePackDescription;
}
else
{
- currentModel = thirdPartyFilterModel;
- currentList = ui->thirdPartyPackList;
+ currentModel = publicFilterModel;
+ currentList = ui->publicPackList;
+ currentModpackInfo = ui->publicPackDescription;
}
+
+ currentList->selectionModel()->reset();
QModelIndex idx = currentList->currentIndex();
if(idx.isValid())
{
@@ -219,3 +319,46 @@ void FTBPage::onTabChanged(int tab)
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 46c14c30..6467decc 100644
--- a/application/pages/modplatform/FTBPage.h
+++ b/application/pages/modplatform/FTBPage.h
@@ -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,6 +34,9 @@ class FTBPage;
class FtbListModel;
class FtbFilterModel;
class NewInstanceDialog;
+class FtbPrivatePackListModel;
+class FtbPrivatePackFilterModel;
+class FtbPrivatePackManager;
class FTBPage : public QWidget, public BasePage
{
@@ -66,15 +72,26 @@ private slots:
void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
void ftbPackDataDownloadFailed(QString reason);
+ void ftbPrivatePackDataDownloadSuccessfully(FtbModpack pack);
+ void ftbPrivatePackDataDownloadFailed(QString reason, QString packCode);
+
void onSortingSelectionChanged(QString data);
void onVersionSelectionItemChanged(QString data);
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:
+ FtbFilterModel* currentModel = nullptr;
+ QTreeView* currentList = nullptr;
+ QTextBrowser* currentModpackInfo = nullptr;
+
bool initialized = false;
FtbModpack selected;
QString selectedVersion;
@@ -85,7 +102,12 @@ private:
FtbListModel *thirdPartyModel = nullptr;
FtbFilterModel *thirdPartyFilterModel = nullptr;
- FtbPackFetchTask *ftbFetchTask = nullptr;
+ FtbListModel *privateListModel = nullptr;
+ FtbFilterModel *privateFilterModel = nullptr;
+
+ unique_qobject_ptr<FtbPackFetchTask> ftbFetchTask;
+ std::unique_ptr<FtbPrivatePackManager> ftbPrivatePacks;
+
NewInstanceDialog* dialog = 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 0d0d4d5e..f4311afb 100644
--- a/application/pages/modplatform/FtbListModel.cpp
+++ b/application/pages/modplatform/FtbListModel.cpp
@@ -72,15 +72,17 @@ 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
@@ -96,15 +98,20 @@ int FtbListModel::columnCount(const QModelIndex &parent) const
QVariant FtbListModel::data(const QModelIndex &index, int role) const
{
int pos = index.row();
- if(pos >= modpacks.size() || pos < 0 || !index.isValid()) {
+ if(pos >= modpacks.size() || pos < 0 || !index.isValid())
+ {
return QString("INVALID INDEX %1").arg(pos);
}
FtbModpack pack = modpacks.at(pos);
- if(role == Qt::DisplayRole) {
+ if(role == Qt::DisplayRole)
+ {
return pack.name + "\n" + translatePackType(pack.type);
- } else if (role == Qt::ToolTipRole) {
- if(pack.description.length() > 100) {
+ }
+ 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("...");
@@ -112,23 +119,33 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const
}
return pack.description;
- } else if(role == Qt::DecorationRole) {
- if(m_logoMap.contains(pack.logo)) {
+ }
+ 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) {
+ }
+ else if(role == Qt::TextColorRole)
+ {
+ if(pack.broken)
+ {
//FIXME: Hardcoded color
return QColor(255, 0, 50);
- } else if(pack.bugged) {
+ }
+ else if(pack.bugged)
+ {
//FIXME: Hardcoded color
//bugged pack, currently only indicates bugged xml
return QColor(244, 229, 66);
}
- } else if(role == Qt::UserRole) {
+ }
+ else if(role == Qt::UserRole)
+ {
QVariant v;
v.setValue(pack);
return v;
@@ -144,11 +161,37 @@ void FtbListModel::fill(FtbModpackList 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);
}
+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);
@@ -164,7 +207,8 @@ void FtbListModel::logoFailed(QString logo)
void FtbListModel::requestLogo(QString file)
{
- if(m_loadingLogos.contains(file) || m_failedLogos.contains(file)) {
+ if(m_loadingLogos.contains(file) || m_failedLogos.contains(file))
+ {
return;
}
@@ -173,14 +217,17 @@ void FtbListModel::requestLogo(QString 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]{
+ QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]
+ {
emit logoLoaded(file, QIcon(fullPath));
- if(waitingCallbacks.contains(file)) {
+ if(waitingCallbacks.contains(file))
+ {
waitingCallbacks.value(file)(fullPath);
}
});
- QObject::connect(job, &NetJob::failed, this, [this, file]{
+ QObject::connect(job, &NetJob::failed, this, [this, file]
+ {
emit logoFailed(file);
});
@@ -191,9 +238,17 @@ void FtbListModel::requestLogo(QString file)
void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
{
- if(m_logoMap.contains(logo)) {
+ if(m_logoMap.contains(logo))
+ {
callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
- } else {
+ }
+ 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 c85c04fa..98301fd7 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>
@@ -60,8 +61,12 @@ public:
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 addPack(FtbModpack modpack);
+ void clear();
+ void remove(int row);
FtbModpack at(int row);
void getLogo(const QString &logo, LogoCallback callback);