diff options
author | Janrupf <werbung.janrupf@t-online.de> | 2018-04-01 20:24:28 +0200 |
---|---|---|
committer | Janrupf <werbung.janrupf@t-online.de> | 2018-04-02 23:02:33 +0200 |
commit | bbd523acb8bf846d27a7859d1d79f28ea92de245 (patch) | |
tree | b8cb693f9558b99e27f730840ca1764da08495d2 /application | |
parent | 67d2f283da3bf9538e6a31de3759cd959010b36c (diff) | |
download | MultiMC-bbd523acb8bf846d27a7859d1d79f28ea92de245.tar MultiMC-bbd523acb8bf846d27a7859d1d79f28ea92de245.tar.gz MultiMC-bbd523acb8bf846d27a7859d1d79f28ea92de245.tar.lz MultiMC-bbd523acb8bf846d27a7859d1d79f28ea92de245.tar.xz MultiMC-bbd523acb8bf846d27a7859d1d79f28ea92de245.zip |
NOISSUE Added FTB Pack logos to chooser and fixed some missing includes
Diffstat (limited to 'application')
-rw-r--r-- | application/FtbListModel.cpp | 91 | ||||
-rw-r--r-- | application/FtbListModel.h | 23 | ||||
-rw-r--r-- | application/MainWindow.h | 1 | ||||
-rw-r--r-- | application/pages/modplatform/FTBPage.cpp | 81 | ||||
-rw-r--r-- | application/pages/modplatform/FTBPage.h | 24 | ||||
-rw-r--r-- | application/pages/modplatform/FTBPage.ui | 79 |
6 files changed, 240 insertions, 59 deletions
diff --git a/application/FtbListModel.cpp b/application/FtbListModel.cpp index d79bcac0..d8c18ee5 100644 --- a/application/FtbListModel.cpp +++ b/application/FtbListModel.cpp @@ -5,12 +5,16 @@ #include <Version.h> #include <QtMath> +#include <QLabel> + +#include <RWStorage.h> +#include <Env.h> FtbFilterModel::FtbFilterModel(QObject *parent) : QSortFilterProxyModel(parent) { currentSorting = Sorting::ByGameVersion; - sortings.insert("Sort by name", Sorting::ByName); - sortings.insert("Sort by game version", 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 @@ -42,6 +46,11 @@ const QMap<QString, FtbFilterModel::Sorting> FtbFilterModel::getAvailableSorting return sortings; } +QString FtbFilterModel::translateCurrentSorting() +{ + return sortings.key(currentSorting); +} + void FtbFilterModel::setSorting(Sorting s) { currentSorting = s; @@ -55,6 +64,27 @@ FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting() FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent) { + m_logoPool = new QThreadPool(this); + m_logoPool->setMaxThreadCount(4); +} + +FtbListModel::~FtbListModel() +{ + m_logoPool->waitForDone(500); + m_logoPool->deleteLater(); +} + +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"); + } } int FtbListModel::rowCount(const QModelIndex &parent) const @@ -70,14 +100,13 @@ int FtbListModel::columnCount(const QModelIndex &parent) const QVariant FtbListModel::data(const QModelIndex &index, int role) const { int pos = index.row(); - if(modpacks.size() <= pos || pos < 0) { + if(modpacks.size() <= pos || pos < 0 || !index.isValid()) { return QString("INVALID INDEX %1").arg(pos); } FtbModpack pack = modpacks.at(pos); - if(role == Qt::DisplayRole) { - return pack.name; + 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 @@ -88,7 +117,12 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const } return pack.description; } else if(role == Qt::DecorationRole) { - //TODO: Add pack logos or something... but they have a weird size. This needs some design hacks + if(m_logoMap.contains(pack.logo)) { + return (m_logoMap.value(pack.logo)); + } + QPixmap pixmap = MMC->getThemedIcon("screenshot-placeholder").pixmap(QSize(42, 42)); + ((FtbListModel *)this)->requestLogo(pack.logo); + return pixmap; } else if(role == Qt::TextColorRole) { if(pack.broken) { //FIXME: Hardcoded color @@ -103,6 +137,7 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const v.setValue(pack); return v; } + return QVariant(); } @@ -117,3 +152,47 @@ FtbModpack FtbListModel::at(int row) { return modpacks.at(row); } + +void FtbListModel::logoLoaded(QString logo, QPixmap out) +{ + m_loadingLogos.removeAll(logo); + m_logoMap.insert(logo, out); + emit dataChanged(createIndex(0, 0), createIndex(modpacks.size(), 0)); +} + +void FtbListModel::logoFailed(QString 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)); + 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)); + + QString *_file = new QString(file); + MetaEntry *_entry = entry.get(); + + QObject::connect(job, &NetJob::finished, this, [this, _file, _entry]{ + QPixmap pixmap; + pixmap.load(_entry->getFullPath()); + pixmap = pixmap.scaled(QSize(42, 42)); + emit logoLoaded(*_file, pixmap); + }); + + QObject::connect(job, &NetJob::failed, this, [this, _file]{ + emit logoFailed(*_file); + }); + + job->start(); + + m_loadingLogos.append(file); +} + +#include "FtbListModel.moc" diff --git a/application/FtbListModel.h b/application/FtbListModel.h index 41fc3ccd..747c65bd 100644 --- a/application/FtbListModel.h +++ b/application/FtbListModel.h @@ -3,6 +3,13 @@ #include <QAbstractListModel> #include <QSortFilterProxyModel> #include <modplatform/ftb/PackHelpers.h> +#include <QThreadPool> + +#include <RWStorage.h> + +#include <QPixmap> + +typedef QMap<QString, QPixmap> FtbLogoMap; class FtbFilterModel : public QSortFilterProxyModel { @@ -13,8 +20,9 @@ public: ByGameVersion }; const QMap<QString, Sorting> getAvailableSortings(); - Sorting getCurrentSorting(); + QString translateCurrentSorting(); void setSorting(Sorting sorting); + Sorting getCurrentSorting(); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -31,9 +39,22 @@ class FtbListModel : public QAbstractListModel Q_OBJECT private: FtbModpackList modpacks; + QThreadPool *m_logoPool; + QStringList m_failedLogos; + QStringList m_loadingLogos; + FtbLogoMap m_logoMap; + + void requestLogo(QString file); + QString translatePackType(FtbPackType type) const; + + +private slots: + void logoFailed(QString logo); + void logoLoaded(QString logo, QPixmap 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; diff --git a/application/MainWindow.h b/application/MainWindow.h index 609df4ca..8f756412 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -25,7 +25,6 @@ #include "minecraft/auth/MojangAccount.h" #include "net/NetJob.h" #include "updater/GoUpdate.h" -#include <modplatform/ftb/FtbPackDownloader.h> class LaunchController; class NewsChecker; diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index 26b1e30b..3b808799 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -5,41 +5,53 @@ #include "FolderInstanceProvider.h" #include "dialogs/CustomMessageBox.h" #include "dialogs/NewInstanceDialog.h" -#include "modplatform/ftb/FtbPackDownloader.h" +#include "modplatform/ftb/FtbPackFetchTask.h" #include "modplatform/ftb/FtbPackInstallTask.h" #include <FtbListModel.h> FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) : QWidget(parent), dialog(dialog), ui(new Ui::FTBPage) { + ftbFetchTask = new FtbPackFetchTask(); + ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - ftbPackDownloader = new FtbPackDownloader(); - connect(ftbPackDownloader, &FtbPackDownloader::ready, this, &FTBPage::ftbPackDataDownloadSuccessfully); - connect(ftbPackDownloader, &FtbPackDownloader::packFetchFailed, this, &FTBPage::ftbPackDataDownloadFailed); + { + publicFilterModel = new FtbFilterModel(this); + publicListModel = new FtbListModel(this); + publicFilterModel->setSourceModel(publicListModel); - filterModel = new FtbFilterModel(this); - listModel = new FtbListModel(this); - filterModel->setSourceModel(listModel); + ui->publicPackList->setModel(publicFilterModel); + ui->publicPackList->setSortingEnabled(true); + ui->publicPackList->header()->hide(); + ui->publicPackList->setIndentation(0); - ui->packList->setModel(filterModel); - ui->packList->setSortingEnabled(true); - ui->packList->header()->hide(); - ui->packList->setIndentation(0); + for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i)); + } - filterModel->setSorting(FtbFilterModel::Sorting::ByName); + ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting()); + } - for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) { - ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); + thirdPartyFilterModel = new FtbFilterModel(this); + thirdPartyModel = new FtbListModel(this); + thirdPartyFilterModel->setSourceModel(thirdPartyModel); + + ui->thirdPartyPackList->setModel(thirdPartyFilterModel); + ui->thirdPartyPackList->setSortingEnabled(true); + ui->thirdPartyPackList->header()->hide(); + ui->thirdPartyPackList->setIndentation(0); + thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting()); } - ui->sortByBox->setCurrentText(filterModel->getAvailableSortings().key(filterModel->getCurrentSorting())); - connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged); connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged); - connect(ui->packList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPackSelectionChanged); + + connect(ui->publicPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onPublicPackSelectionChanged); + connect(ui->thirdPartyPackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &FTBPage::onThirdPartyPackSelectionChanged); ui->modpackInfo->setOpenExternalLinks(true); } @@ -47,9 +59,8 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) FTBPage::~FTBPage() { delete ui; - if(ftbPackDownloader) - { - ftbPackDownloader->deleteLater(); + if(ftbFetchTask) { + ftbFetchTask->deleteLater(); } } @@ -62,7 +73,9 @@ void FTBPage::openedImpl() { if(!initialized) { - ftbPackDownloader->fetchModpacks(false); + connect(ftbFetchTask, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully); + connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed); + ftbFetchTask->fetch(); initialized = true; } suggestCurrent(); @@ -83,25 +96,31 @@ void FTBPage::suggestCurrent() } } -FtbPackDownloader *FTBPage::getFtbPackDownloader() +void FTBPage::ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks) +{ + publicListModel->fill(publicPacks); + thirdPartyModel->fill(thirdPartyPacks); +} + +void FTBPage::ftbPackDataDownloadFailed(QString reason) { - return ftbPackDownloader; + //TODO: Display the error } -void FTBPage::ftbPackDataDownloadSuccessfully() +void FTBPage::onPublicPackSelectionChanged(QModelIndex first, QModelIndex second) { - listModel->fill(ftbPackDownloader->getModpacks()); + onPackSelectionChanged(first, second, publicFilterModel); } -void FTBPage::ftbPackDataDownloadFailed() +void FTBPage::onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second) { - qDebug() << "Stuff went missing while grabbing FTB pack list or something..."; + onPackSelectionChanged(first, second, thirdPartyFilterModel); } -void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev) +void FTBPage::onPackSelectionChanged(QModelIndex now, QModelIndex prev, FtbFilterModel *model) { ui->packVersionSelection->clear(); - FtbModpack selectedPack = filterModel->data(now, Qt::UserRole).value<FtbModpack>(); + FtbModpack selectedPack = model->data(now, Qt::UserRole).value<FtbModpack>(); ui->modpackInfo->setHtml("Pack by <b>" + selectedPack.author + "</b>" + "<br>Minecraft " + selectedPack.mcVersion + "<br>" "<br>" + selectedPack.description + "<ul><li>" + selectedPack.mods.replace(";", "</li><li>") + "</li></ul>"); @@ -149,5 +168,7 @@ QString FTBPage::getSelectedVersion() void FTBPage::onSortingSelectionChanged(QString data) { - filterModel->setSorting(filterModel->getAvailableSortings().value(data)); + FtbFilterModel::Sorting toSet = publicFilterModel->getAvailableSortings().value(data); + publicFilterModel->setSorting(toSet); + thirdPartyFilterModel->setSorting(toSet); } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index f7d6ca8b..ba8dd299 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -21,6 +21,7 @@ #include <MultiMC.h> #include "tasks/Task.h" #include "modplatform/ftb/PackHelpers.h" +#include "modplatform/ftb/FtbPackFetchTask.h" namespace Ui { @@ -29,7 +30,6 @@ class FTBPage; class FtbListModel; class FtbFilterModel; -class FtbPackDownloader; class NewInstanceDialog; class FTBPage : public QWidget, public BasePage @@ -58,28 +58,36 @@ public: bool shouldDisplay() const override; void openedImpl() override; - FtbPackDownloader* getFtbPackDownloader(); FtbModpack getSelectedModpack(); QString getSelectedVersion(); private: void suggestCurrent(); + void onPackSelectionChanged(QModelIndex first, QModelIndex second, FtbFilterModel *model); private slots: - void ftbPackDataDownloadSuccessfully(); - void ftbPackDataDownloadFailed(); + void ftbPackDataDownloadSuccessfully(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks); + void ftbPackDataDownloadFailed(QString reason); + void onSortingSelectionChanged(QString data); void onVersionSelectionItemChanged(QString data); - void onPackSelectionChanged(QModelIndex first, QModelIndex second); + + void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second); + void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second); private: bool initialized = false; - FtbPackDownloader* ftbPackDownloader = nullptr; FtbModpack selectedPack; FtbModpack selected; QString selectedVersion; - FtbListModel* listModel = nullptr; - FtbFilterModel* filterModel = nullptr; + + FtbListModel* publicListModel = nullptr; + FtbFilterModel* publicFilterModel = nullptr; + + FtbListModel *thirdPartyModel = nullptr; + FtbFilterModel *thirdPartyFilterModel = nullptr; + + FtbPackFetchTask *ftbFetchTask; NewInstanceDialog* dialog = nullptr; Ui::FTBPage *ui = nullptr; diff --git a/application/pages/modplatform/FTBPage.ui b/application/pages/modplatform/FTBPage.ui index a64c9606..ee91f1f5 100644 --- a/application/pages/modplatform/FTBPage.ui +++ b/application/pages/modplatform/FTBPage.ui @@ -10,7 +10,7 @@ <height>602</height> </rect> </property> - <layout class="QVBoxLayout" name="verticalLayout"> + <layout class="QGridLayout" name="gridLayout_2"> <property name="leftMargin"> <number>0</number> </property> @@ -23,7 +23,7 @@ <property name="bottomMargin"> <number>0</number> </property> - <item> + <item row="0" column="0"> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> <number>0</number> @@ -32,17 +32,15 @@ <attribute name="title"> <string notr="true"/> </attribute> - <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,4,4"> - <item row="0" column="0" colspan="2"> - <widget class="QTreeView" name="packList"/> - </item> - <item row="0" column="2" colspan="2"> - <widget class="QTextBrowser" name="modpackInfo"/> - </item> - <item row="1" column="3"> - <widget class="QComboBox" name="packVersionSelection"/> + <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> + </property> + </widget> </item> - <item row="1" column="2"> + <item row="2" column="2"> <widget class="QLabel" name="selectedVersionLabel"> <property name="text"> <string>Version selected:</string> @@ -52,9 +50,64 @@ </property> </widget> </item> - <item row="1" column="0" colspan="2"> + <item row="2" column="3"> + <widget class="QComboBox" name="packVersionSelection"/> + </item> + <item row="2" column="0"> <widget class="QComboBox" name="sortByBox"/> </item> + <item row="0" column="0" rowspan="2"> + <widget class="QTabWidget" name="tabWidget_2"> + <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> + </property> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>Public Packs</string> + </attribute> + <widget class="QTreeView" name="publicPackList"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>221</width> + <height>491</height> + </rect> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOn</enum> + </property> + </widget> + </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>3rd Party Packs</string> + </attribute> + <widget class="QTreeView" name="thirdPartyPackList"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>221</width> + <height>491</height> + </rect> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOn</enum> + </property> + </widget> + </widget> + </widget> + </item> </layout> </widget> </widget> |