From 010a5d80d6d5302de6c512d3ffd66d0db1785716 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 21 Feb 2021 11:12:16 +0100 Subject: Switch back to invalidating filter when receiving mod updates. --- src/mainwindow.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0fabd0dc..9f1ae7b6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2819,41 +2819,37 @@ void MainWindow::nxmUpdateInfoAvailable(QString gameName, QVariant userData, QVa } QVariantList resultList = resultData.toList(); - QFutureWatcher>>> *watcher = new QFutureWatcher>>>(); - QObject::connect(watcher, &QFutureWatcher>>::finished, this, &MainWindow::finishUpdateInfo); - QFuture>>> future = QtConcurrent::run([=]() -> std::pair>> { - return std::make_pair(gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true)); + auto* watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, watcher]() { + finishUpdateInfo(watcher->result()); + watcher->deleteLater(); + }); + auto future = QtConcurrent::run([=]() { + return NxmUpdateInfoData{ gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true) }; }); watcher->setFuture(future); + ui->modList->invalidateFilter(); } -void MainWindow::finishUpdateInfo() +void MainWindow::finishUpdateInfo(const NxmUpdateInfoData& data) { - QFutureWatcher>>> *watcher = static_cast>>> *>(sender()); - - QString game = watcher->result().first; - auto finalMods = watcher->result().second; - - if (finalMods.empty()) { - log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(game)); + if (data.finalMods.empty()) { + log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(data.game)); } std::set> organizedGames; - for (auto mod : finalMods) { + for (auto& mod : data.finalMods) { if (mod->canBeUpdated()) { organizedGames.insert(std::make_pair(mod->gameName().toLower(), mod->nexusId())); } - m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name())); } - if (!finalMods.empty() && organizedGames.empty()) + if (!data.finalMods.empty() && organizedGames.empty()) log::warn("{}", tr("All of your mods have been checked recently. We restrict update checks to help preserve your available API requests.")); - for (auto game : organizedGames) + for (const auto& game : organizedGames) { NexusInterface::instance().requestUpdates(game.second, this, QVariant(), game.first, QString()); - - disconnect(sender()); - delete sender(); + } } void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID) @@ -2928,13 +2924,15 @@ void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userD if (foundUpdate) { // Just get the standard data updates for endorsements and descriptions mod->setLastNexusUpdate(QDateTime::currentDateTimeUtc()); - m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name())); } else { // Scrape mod data here so we can use the mod version if no file update was located requiresInfo = true; } } + // invalidate the filter to display mods with an update + ui->modList->invalidateFilter(); + if (requiresInfo) NexusInterface::instance().requestModInfo(gameNameReal, modID, this, QVariant(), QString()); } -- cgit v1.3.1