From c42e5fb2fec9b20fe6956d8798b85874b2eff73e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 26 Aug 2019 03:01:55 -0400 Subject: changed total speed and count to a list of the last 5 downloads existing servers now merged when retrieving the download links download manager doesn't store the servers any more, queries the settings every time --- src/mainwindow.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 79203d29..4c2594b8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5050,7 +5050,6 @@ void MainWindow::on_actionSettings_triggered() dlManager->setOutputDirectory(settings.getDownloadDirectory()); } } - dlManager->setServers(settings.getServers()); if ((settings.getModDirectory() != oldModDirectory) || (settings.displayForeign() != oldDisplayForeign)) { @@ -5904,20 +5903,32 @@ void MainWindow::nxmTrackedModsAvailable(QVariant userData, QVariant resultData, void MainWindow::nxmDownloadURLs(QString, int, int, QVariant, QVariant resultData, int) { - ServerList servers; + auto servers = m_OrganizerCore.settings().getServers(); for (const QVariant &var : resultData.toList()) { const QVariantMap map = var.toMap(); - ServerInfo server( - map["short_name"].toString(), - map["name"].toString().contains("Premium", Qt::CaseInsensitive), - QDate::currentDate(), - map["short_name"].toString().contains("CDN", Qt::CaseInsensitive) ? 1 : 0, - map["downloadCount"].toInt(), - map["downloadSpeed"].toDouble()); + const auto name = map["short_name"].toString(); + const auto isPremium = map["name"].toString().contains("Premium", Qt::CaseInsensitive); + const auto isCDN = map["short_name"].toString().contains("CDN", Qt::CaseInsensitive); - servers.add(std::move(server)); + bool found = false; + + for (auto& server : servers) { + if (server.name() == name) { + // already exists, update + server.setPremium(isPremium); + server.updateLastSeen(); + found = true; + break; + } + } + + if (!found) { + // new server + ServerInfo server(name, isPremium, QDate::currentDate(), isCDN ? 1 : 0, {}); + servers.add(std::move(server)); + } } m_OrganizerCore.settings().updateServers(servers); -- cgit v1.3.1