From c3ff652ff8c612054fa102234677c74fcd19a51c Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Fri, 22 Mar 2019 17:33:10 -0500 Subject: Only change to the update filter if mods are being checked for update or mods have updates available --- src/mainwindow.cpp | 24 ++++++++++++++++++------ src/modinfo.cpp | 18 ++++++++++++++++-- src/modinfo.h | 12 +++++++++++- 3 files changed, 45 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 669820be..8fe786ba 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4075,28 +4075,40 @@ void MainWindow::saveArchiveList() void MainWindow::checkModsForUpdates() { - statusBar()->show(); + bool checkingModsForUpdate = false; if (NexusInterface::instance(&m_PluginContainer)->getAccessManager()->validated()) { - ModInfo::checkAllForUpdate(&m_PluginContainer, this); + checkingModsForUpdate = ModInfo::checkAllForUpdate(&m_PluginContainer, this); NexusInterface::instance(&m_PluginContainer)->requestEndorsementInfo(this, QVariant(), QString()); NexusInterface::instance(&m_PluginContainer)->requestTrackingInfo(this, QVariant(), QString()); } else { QString apiKey; if (m_OrganizerCore.settings().getNexusApiKey(apiKey)) { m_OrganizerCore.doAfterLogin([this] () { this->checkModsForUpdates(); }); + statusBar()->show(); NexusInterface::instance(&m_PluginContainer)->getAccessManager()->apiCheck(apiKey); } else { qWarning("You are not currently authenticated with Nexus. Please do so under Settings -> Nexus."); } } - m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)); - for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) { - if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { - ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i)); + bool updatesAvailable = false; + for (auto mod : m_OrganizerCore.modList()->allMods()) { + ModInfo::Ptr modInfo = ModInfo::getByName(mod); + if (modInfo->updateAvailable()) { + updatesAvailable = true; break; } } + + if (updatesAvailable || checkingModsForUpdate) { + m_ModListSortProxy->setCategoryFilter(boost::assign::list_of(CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)); + for (int i = 0; i < ui->categoriesList->topLevelItemCount(); ++i) { + if (ui->categoriesList->topLevelItem(i)->data(0, Qt::UserRole) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { + ui->categoriesList->setCurrentItem(ui->categoriesList->topLevelItem(i)); + break; + } + } + } } void MainWindow::changeVersioningScheme() { diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 0afd92e6..28e9b8f2 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -166,6 +166,14 @@ std::vector ModInfo::getByModID(QString game, int modID) } +ModInfo::Ptr ModInfo::getByName(const QString &name) +{ + QMutexLocker locker(&s_Mutex); + + return s_Collection[ModInfo::getIndex(name)]; +} + + bool ModInfo::removeMod(unsigned int index) { QMutexLocker locker(&s_Mutex); @@ -285,8 +293,10 @@ ModInfo::ModInfo(PluginContainer *pluginContainer) } -void ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiver) +bool ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiver) { + bool updatesAvailable = true; + QDateTime earliest = QDateTime::currentDateTimeUtc(); QDateTime latest; std::set games; @@ -308,8 +318,10 @@ void ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *recei } } - if (organizedGames.empty()) + if (organizedGames.empty()) { qWarning("All of your mods have been checked recently. We restrict update checks to help preserve your available API requests."); + updatesAvailable = false; + } for (auto game : organizedGames) { NexusInterface::instance(pluginContainer)->requestUpdates(game.second, receiver, QVariant(), game.first, QString()); @@ -327,6 +339,8 @@ void ModInfo::checkAllForUpdate(PluginContainer *pluginContainer, QObject *recei for (auto gameName : games) NexusInterface::instance(pluginContainer)->requestUpdateInfo(gameName, NexusInterface::UpdatePeriod::DAY, receiver, QVariant(false), QString()); } + + return updatesAvailable; } std::set> ModInfo::filteredMods(QString gameName, QVariantList updateData, bool addOldMods, bool markUpdated) diff --git a/src/modinfo.h b/src/modinfo.h index 81f59b61..f1d816fe 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -167,6 +167,15 @@ public: **/ static std::vector getByModID(QString game, int modID); + /** + * @brief retrieve a ModInfo object based on its name + * + * @param name the name to look up + * @return a reference counting pointer to the mod info + * @note since the pointer is reference counter, the pointer remains valid even if the collection is refreshed in a different thread + **/ + static ModInfo::Ptr getByName(const QString &name); + /** * @brief remove a mod by index * @@ -199,8 +208,9 @@ public: /** * @brief query nexus information for every mod and update the "newest version" information + * @return true if any mods are checked for update **/ - static void checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiver); + static bool checkAllForUpdate(PluginContainer *pluginContainer, QObject *receiver); static std::set> filteredMods(QString gameName, QVariantList updateData, bool addOldMods = false, bool markUpdated = false); -- cgit v1.3.1