Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass Metadata Parsing #2079

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,54 @@ void DownloadManager::refreshList()
}
}

void DownloadManager::queryDownloadListInfo()
{
TimeThis tt("DownloadManager::queryDownloadListInfos()");

log::info("Retrieving data 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)) {
incompleteInfos++;
}
}

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 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,
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;
}

log::info("Metadata has been retrieved successfully!");
}

bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID,
int fileID, const ModRepositoryFileInfo* fileInfo)
{
Expand Down
5 changes: 5 additions & 0 deletions src/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/downloadstab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "ui_mainwindow.h"

DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui)
: m_core(core), ui{mwui->btnRefreshDownloads, 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);

Expand All @@ -26,6 +27,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)));
Expand Down Expand Up @@ -80,6 +84,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] {
Expand Down
7 changes: 7 additions & 0 deletions src/downloadstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DownloadsTab : public QObject
struct DownloadsTabUi
{
QPushButton* refresh;
QPushButton* queryInfos;
DownloadListView* list;
QCheckBox* showHidden;
QLineEdit* filter;
Expand All @@ -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);
};

Expand Down
20 changes: 20 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,26 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnQueryDownloadsInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::ContextMenuPolicy::DefaultContextMenu</enum>
</property>
<property name="text">
<string>Query Metadata</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/MO/gui/resources/system-search.png</normaloff>:/MO/gui/resources/system-search.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down