From 298b5979eaad32574d18e1bec6d70b846e4cf79c Mon Sep 17 00:00:00 2001 From: Deewens Date: Sun, 3 Sep 2023 19:13:16 +0200 Subject: [PATCH 1/6] Add a button to "Query Info" of every download in the list --- src/downloadmanager.cpp | 20 ++++++++++++++++++++ src/downloadmanager.h | 5 +++++ src/downloadstab.cpp | 10 +++++++++- src/downloadstab.h | 7 +++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 730803f6d..88f1d121b 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -440,6 +440,26 @@ void DownloadManager::refreshList() } } +void DownloadManager::queryDownloadListInfo() +{ + TimeThis tt("DownloadManager::queryDownloadListInfos()"); + + startDisableDirWatcher(); + + log::info("Retrieving infos from every download (if possible)..."); + + // Just go through all active downloads to query infos + for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { + if (isInfoIncomplete(i)) { + queryInfoMd5(i); + } + } + + log::info("Files infos have been retrived successfully!"); + + endDisableDirWatcher(); +} + bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, int fileID, const ModRepositoryFileInfo* fileInfo) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 1e7a626ee..549ac29ae 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -402,6 +402,11 @@ class DownloadManager : public QObject */ void refreshList(); + /** + * @brief Query infos for every download in the list + */ + void queryDownloadListInfo(); + public: // IDownloadManager interface: int startDownloadURLs(const QStringList& urls); int startDownloadNexusFile(int modID, int fileID); diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index bf3ea9ad0..d7aa74372 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -5,7 +5,7 @@ #include "ui_mainwindow.h" DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) - : m_core(core), ui{mwui->btnRefreshDownloads, mwui->downloadView, + : m_core(core), ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, mwui->showHiddenBox, mwui->downloadFilterEdit} { DownloadList* sourceModel = new DownloadList(m_core, ui.list); @@ -26,6 +26,9 @@ DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) connect(ui.refresh, &QPushButton::clicked, [&] { refresh(); }); + connect(ui.queryInfos, &QPushButton::clicked, [&] { + queryInfos(); + }); connect(ui.list, SIGNAL(installDownload(int)), &m_core, SLOT(installDownload(int))); connect(ui.list, SIGNAL(queryInfo(int)), m_core.downloadManager(), SLOT(queryInfo(int))); @@ -80,6 +83,11 @@ void DownloadsTab::refresh() m_core.downloadManager()->refreshList(); } +void DownloadsTab::queryInfos() +{ + m_core.downloadManager()->queryDownloadListInfo(); +} + void DownloadsTab::resumeDownload(int downloadIndex) { m_core.loggedInAction(ui.list, [this, downloadIndex] { diff --git a/src/downloadstab.h b/src/downloadstab.h index f0b85d918..1676ec761 100644 --- a/src/downloadstab.h +++ b/src/downloadstab.h @@ -23,6 +23,7 @@ class DownloadsTab : public QObject struct DownloadsTabUi { QPushButton* refresh; + QPushButton* queryInfos; DownloadListView* list; QCheckBox* showHidden; QLineEdit* filter; @@ -33,6 +34,12 @@ class DownloadsTab : public QObject MOBase::FilterWidget m_filter; void refresh(); + + /** + * @brief Handle click on the "Query infos" button + **/ + void queryInfos(); + void resumeDownload(int downloadIndex); }; From 22559a0e1d5dfb732f4c833266a7a48b6daa7521 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Sat, 27 Jul 2024 08:13:01 -0400 Subject: [PATCH 2/6] Update mainwindow.ui Added button to pr Update mainwindow.ui Update mainwindow.ui Added button to pr --- src/mainwindow.ui | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index c2ce37b32..227486cf0 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1326,6 +1326,26 @@ + + + + + 0 + 0 + + + + Qt::ContextMenuPolicy::DefaultContextMenu + + + Query Metadata + + + + :/MO/gui/resources/system-search.png:/MO/gui/resources/system-search.png + + + From 7c0dcf0e1426b138473f9510532e44fa25087b9f Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Sat, 27 Jul 2024 21:47:37 -0400 Subject: [PATCH 3/6] Fix linter Fixed clang formatting on downloadstab.cpp --- src/downloadstab.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index d7aa74372..25dfa8e48 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -5,8 +5,9 @@ #include "ui_mainwindow.h" DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) - : m_core(core), ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, - mwui->showHiddenBox, mwui->downloadFilterEdit} + : m_core(core), + ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, + mwui->showHiddenBox, mwui->downloadFilterEdit} { DownloadList* sourceModel = new DownloadList(m_core, ui.list); @@ -27,7 +28,7 @@ DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) refresh(); }); connect(ui.queryInfos, &QPushButton::clicked, [&] { - queryInfos(); + queryInfos(); }); connect(ui.list, SIGNAL(installDownload(int)), &m_core, SLOT(installDownload(int))); connect(ui.list, SIGNAL(queryInfo(int)), m_core.downloadManager(), @@ -83,7 +84,7 @@ void DownloadsTab::refresh() m_core.downloadManager()->refreshList(); } -void DownloadsTab::queryInfos() +void DownloadsTab::queryInfos() { m_core.downloadManager()->queryDownloadListInfo(); } From 5d117c121018c72a65109651f8c62810e58739b3 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 11:32:30 -0400 Subject: [PATCH 4/6] Add warning message for dialog box --- src/downloadmanager.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 88f1d121b..af1ed9e4d 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -444,20 +444,38 @@ void DownloadManager::queryDownloadListInfo() { TimeThis tt("DownloadManager::queryDownloadListInfos()"); - startDisableDirWatcher(); - log::info("Retrieving infos from every download (if possible)..."); + int incompleteInfos = 0; + // Just go through all active downloads to query infos for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { if (isInfoIncomplete(i)) { - queryInfoMd5(i); + incompleteInfos++; } } - log::info("Files infos have been retrived successfully!"); + // Warn the user if the number of incomplete infos is over 5 + if (incompleteInfos > 5) { + QString message = tr("There %1 incomplete download meta files.\n\n" + "Do you want to fetch metadata for all incomplete downloads?\n" + "API uses will be consumed, and Mod Organizer may stutter."); + message = message.arg(incompleteInfos); + if (QMessageBox::question(m_ParentWidget, tr("Incomplete Download Infos"), message, + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + // Fetch metadata for incomplete download infos + startDisableDirWatcher(); + for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { + if (isInfoIncomplete(i)) { + queryInfoMd5(i); + } + } + endDisableDirWatcher(); + } + return; + } - endDisableDirWatcher(); + log::info("Files infos have been retrieved successfully!"); } bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, From 63866278cf3961ceb97b119c64f1e69a2442cbc7 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 11:57:32 -0400 Subject: [PATCH 5/6] Fix oversight in new dialog box The new dialog box hijacked the function and skipped the fetch if there were less than 5 files. Now directly runs if there are 5 files or less, and shows the dialog if there are more than 5\ --- src/downloadmanager.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index af1ed9e4d..2dd3ea9c8 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -455,8 +455,18 @@ void DownloadManager::queryDownloadListInfo() } } - // Warn the user if the number of incomplete infos is over 5 - if (incompleteInfos > 5) { + if (incompleteInfos <= 5) { + // Fetch metadata for incomplete download infos + startDisableDirWatcher(); + for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { + if (isInfoIncomplete(i)) { + queryInfoMd5(i); + } + } + endDisableDirWatcher(); + } else { + + // Warn the user if the number of incomplete infos is over 5 QString message = tr("There %1 incomplete download meta files.\n\n" "Do you want to fetch metadata for all incomplete downloads?\n" "API uses will be consumed, and Mod Organizer may stutter."); From 4f52ef8d75f39e28b3bf81d17e39d93ed7afb6c9 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 12:03:55 -0400 Subject: [PATCH 6/6] Grammar fixes in dialog box and logs --- src/downloadmanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 2dd3ea9c8..2ac531ec5 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -444,7 +444,7 @@ void DownloadManager::queryDownloadListInfo() { TimeThis tt("DownloadManager::queryDownloadListInfos()"); - log::info("Retrieving infos from every download (if possible)..."); + log::info("Retrieving data from every download (if possible)..."); int incompleteInfos = 0; @@ -467,8 +467,8 @@ void DownloadManager::queryDownloadListInfo() } else { // Warn the user if the number of incomplete infos is over 5 - QString message = tr("There %1 incomplete download meta files.\n\n" - "Do you want to fetch metadata for all incomplete downloads?\n" + QString message = tr("There are %1 incomplete download meta files.\n\n" + "Do you want to fetch all incomplete metadata?\n" "API uses will be consumed, and Mod Organizer may stutter."); message = message.arg(incompleteInfos); if (QMessageBox::question(m_ParentWidget, tr("Incomplete Download Infos"), message, @@ -485,7 +485,7 @@ void DownloadManager::queryDownloadListInfo() return; } - log::info("Files infos have been retrieved successfully!"); + log::info("Metadata has been retrieved successfully!"); } bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID,