diff options
| author | Petr Mrázek <peterix@gmail.com> | 2018-07-15 14:51:05 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2018-07-15 14:51:05 +0200 |
| commit | bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9 (patch) | |
| tree | e6497e304b7b9368367565fbc7c06efab1124b1c /application/pages/modplatform | |
| parent | 03280cc62e75f8073f8d3d9e9e3952acf21fa77d (diff) | |
| download | PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.gz PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.tar.bz2 PrismLauncher-bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9.zip | |
NOISSUE tabs -> spaces
Diffstat (limited to 'application/pages/modplatform')
| -rw-r--r-- | application/pages/modplatform/FTBPage.cpp | 292 | ||||
| -rw-r--r-- | application/pages/modplatform/FTBPage.h | 80 | ||||
| -rw-r--r-- | application/pages/modplatform/FtbListModel.cpp | 208 | ||||
| -rw-r--r-- | application/pages/modplatform/FtbListModel.h | 62 | ||||
| -rw-r--r-- | application/pages/modplatform/ImportPage.cpp | 152 | ||||
| -rw-r--r-- | application/pages/modplatform/ImportPage.h | 54 | ||||
| -rw-r--r-- | application/pages/modplatform/TechnicPage.cpp | 10 | ||||
| -rw-r--r-- | application/pages/modplatform/TechnicPage.h | 48 | ||||
| -rw-r--r-- | application/pages/modplatform/TwitchPage.cpp | 10 | ||||
| -rw-r--r-- | application/pages/modplatform/TwitchPage.h | 48 | ||||
| -rw-r--r-- | application/pages/modplatform/VanillaPage.cpp | 88 | ||||
| -rw-r--r-- | application/pages/modplatform/VanillaPage.h | 62 |
12 files changed, 557 insertions, 557 deletions
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index f438fce7..ae4dd92e 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -10,213 +10,213 @@ #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 = new FtbPackFetchTask(); - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); - { - publicFilterModel = new FtbFilterModel(this); - publicListModel = new FtbListModel(this); - publicFilterModel->setSourceModel(publicListModel); + { + 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->publicPackList->setModel(publicFilterModel); + ui->publicPackList->setSortingEnabled(true); + ui->publicPackList->header()->hide(); + ui->publicPackList->setIndentation(0); + ui->publicPackList->setIconSize(QSize(42, 42)); - for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) - { - ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i)); - } + for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(publicFilterModel->getAvailableSortings().keys().at(i)); + } - ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting()); - } + ui->sortByBox->setCurrentText(publicFilterModel->translateCurrentSorting()); + } - { - thirdPartyFilterModel = new FtbFilterModel(this); - thirdPartyModel = new FtbListModel(this); - thirdPartyFilterModel->setSourceModel(thirdPartyModel); + { + 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); - ui->thirdPartyPackList->setIconSize(QSize(42, 42)); + ui->thirdPartyPackList->setModel(thirdPartyFilterModel); + ui->thirdPartyPackList->setSortingEnabled(true); + ui->thirdPartyPackList->header()->hide(); + ui->thirdPartyPackList->setIndentation(0); + ui->thirdPartyPackList->setIconSize(QSize(42, 42)); - thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting()); - } + thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting()); + } - ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300); + ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->packVersionSelection->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->packVersionSelection, &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->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged); + connect(ui->ftbTabWidget, &QTabWidget::currentChanged, this, &FTBPage::onTabChanged); - ui->modpackInfo->setOpenExternalLinks(true); + ui->modpackInfo->setOpenExternalLinks(true); - ui->publicPackList->selectionModel()->reset(); - ui->thirdPartyPackList->selectionModel()->reset(); + ui->publicPackList->selectionModel()->reset(); + ui->thirdPartyPackList->selectionModel()->reset(); } FTBPage::~FTBPage() { - delete ui; - if(ftbFetchTask) { - ftbFetchTask->deleteLater(); - } + delete ui; + if(ftbFetchTask) { + ftbFetchTask->deleteLater(); + } } 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, &FtbPackFetchTask::finished, this, &FTBPage::ftbPackDataDownloadSuccessfully); + connect(ftbFetchTask, &FtbPackFetchTask::failed, this, &FTBPage::ftbPackDataDownloadFailed); + ftbFetchTask->fetch(); + 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)); + 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(); + } + } } 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::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::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->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(); } void FTBPage::onVersionSelectionItemChanged(QString data) { - if(data.isNull() || data.isEmpty()) - { - selectedVersion = ""; - return; - } - - selectedVersion = data; - suggestCurrent(); + if(data.isNull() || data.isEmpty()) + { + selectedVersion = ""; + return; + } + + 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); } 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(); - } + 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(); + } } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index 00c5e9c5..46c14c30 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -34,59 +34,59 @@ class NewInstanceDialog; 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 onSortingSelectionChanged(QString data); + void onVersionSelectionItemChanged(QString data); - void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second); - void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second); + void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second); + void onThirdPartyPackSelectionChanged(QModelIndex first, QModelIndex second); - void onTabChanged(int tab); + void onTabChanged(int tab); private: - bool initialized = false; - FtbModpack selected; - QString selectedVersion; + bool initialized = false; + FtbModpack selected; + QString selectedVersion; - FtbListModel* publicListModel = nullptr; - FtbFilterModel* publicFilterModel = nullptr; + FtbListModel* publicListModel = nullptr; + FtbFilterModel* publicFilterModel = nullptr; - FtbListModel *thirdPartyModel = nullptr; - FtbFilterModel *thirdPartyFilterModel = nullptr; + FtbListModel *thirdPartyModel = nullptr; + FtbFilterModel *thirdPartyFilterModel = nullptr; - FtbPackFetchTask *ftbFetchTask = nullptr; - NewInstanceDialog* dialog = nullptr; + FtbPackFetchTask *ftbFetchTask = nullptr; + NewInstanceDialog* dialog = nullptr; - Ui::FTBPage *ui = nullptr; + Ui::FTBPage *ui = nullptr; }; diff --git a/application/pages/modplatform/FtbListModel.cpp b/application/pages/modplatform/FtbListModel.cpp index c14907c6..0d0d4d5e 100644 --- a/application/pages/modplatform/FtbListModel.cpp +++ b/application/pages/modplatform/FtbListModel.cpp @@ -12,54 +12,54 @@ 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 +72,128 @@ 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"); - } + 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 { - 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(); } FtbModpack FtbListModel::at(int row) { - return modpacks.at(row); + return modpacks.at(row); } 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; - } + 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)); + 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); - } - }); + 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); - }); + QObject::connect(job, &NetJob::failed, this, [this, file]{ + emit logoFailed(file); + }); - job->start(); + job->start(); - m_loadingLogos.append(file); + 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); + } } diff --git a/application/pages/modplatform/FtbListModel.h b/application/pages/modplatform/FtbListModel.h index d3a82b73..c85c04fa 100644 --- a/application/pages/modplatform/FtbListModel.h +++ b/application/pages/modplatform/FtbListModel.h @@ -16,53 +16,53 @@ typedef std::function<void(QString)> LogoCallback; class FtbFilterModel : public QSortFilterProxyModel { 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; - void fill(FtbModpackList modpacks); + void fill(FtbModpackList modpacks); - 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 f00c4811..5e476195 100644 --- a/application/pages/modplatform/ImportPage.cpp +++ b/application/pages/modplatform/ImportPage.cpp @@ -13,114 +13,114 @@ 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() &&am |
