improve blocked mods dialog

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-02-01 20:06:22 +02:00
parent 178965676e
commit 2fc89d7e11
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
3 changed files with 128 additions and 65 deletions

View file

@ -43,21 +43,18 @@
#include <QTimer> #include <QTimer>
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods, QString hash_type) BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods, QString hash_type)
: QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods), m_hash_type(hash_type) : QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods), m_hashType(hash_type)
{ {
m_hashing_task = shared_qobject_ptr<ConcurrentTask>( m_hashingTask = shared_qobject_ptr<ConcurrentTask>(
new ConcurrentTask("MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt())); new ConcurrentTask("MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
connect(m_hashing_task.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished); connect(m_hashingTask.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);
ui->setupUi(this); ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel")); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK")); ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
m_openMissingButton = ui->buttonBox->addButton(tr("Open Missing"), QDialogButtonBox::ActionRole); connect(ui->openMissingButton, &QPushButton::clicked, this, [this]() { openAll(true); });
connect(m_openMissingButton, &QPushButton::clicked, this, [this]() { openAll(true); }); connect(ui->downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
auto downloadFolderButton = ui->buttonBox->addButton(tr("Add Download Folder"), QDialogButtonBox::ActionRole);
connect(downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged); connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
@ -174,10 +171,12 @@ void BlockedModsDialog::update()
if (allModsMatched()) { if (allModsMatched()) {
ui->labelModsFound->setText("<span style=\"color:green\">✔</span>" + tr("All mods found")); ui->labelModsFound->setText("<span style=\"color:green\">✔</span>" + tr("All mods found"));
m_openMissingButton->setDisabled(true); ui->openMissingButton->setDisabled(true);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
} else { } else {
ui->labelModsFound->setText(tr("Please download the missing mods.")); ui->labelModsFound->setText(tr("Please download the missing mods."));
m_openMissingButton->setDisabled(false); ui->openMissingButton->setDisabled(false);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Skip"));
} }
} }
@ -260,7 +259,7 @@ void BlockedModsDialog::scanPath(QString path, bool start_task)
void BlockedModsDialog::addHashTask(QString path) void BlockedModsDialog::addHashTask(QString path)
{ {
qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set."; qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set.";
m_pending_hash_paths.insert(path); m_pendingHashPaths.insert(path);
} }
/// @brief add a hashing task for the file located at path and connect it to check that hash against /// @brief add a hashing task for the file located at path and connect it to check that hash against
@ -268,14 +267,14 @@ void BlockedModsDialog::addHashTask(QString path)
/// @param path the path to the local file being hashed /// @param path the path to the local file being hashed
void BlockedModsDialog::buildHashTask(QString path) void BlockedModsDialog::buildHashTask(QString path)
{ {
auto hash_task = Hashing::createHasher(path, m_hash_type); auto hash_task = Hashing::createHasher(path, m_hashType);
qDebug() << "[Blocked Mods Dialog] Creating Hash task for path: " << path; qDebug() << "[Blocked Mods Dialog] Creating Hash task for path: " << path;
connect(hash_task.get(), &Task::succeeded, this, [this, hash_task, path] { checkMatchHash(hash_task->getResult(), path); }); connect(hash_task.get(), &Task::succeeded, this, [this, hash_task, path] { checkMatchHash(hash_task->getResult(), path); });
connect(hash_task.get(), &Task::failed, this, [path] { qDebug() << "Failed to hash path: " << path; }); connect(hash_task.get(), &Task::failed, this, [path] { qDebug() << "Failed to hash path: " << path; });
m_hashing_task->addTask(hash_task); m_hashingTask->addTask(hash_task);
} }
/// @brief check if the computed hash for the provided path matches a blocked /// @brief check if the computed hash for the provided path matches a blocked
@ -406,31 +405,31 @@ void BlockedModsDialog::validateMatchedMods()
/// @brief run hash task or mark a pending run if it is already running /// @brief run hash task or mark a pending run if it is already running
void BlockedModsDialog::runHashTask() void BlockedModsDialog::runHashTask()
{ {
if (!m_hashing_task->isRunning()) { if (!m_hashingTask->isRunning()) {
m_rehash_pending = false; m_rehashPending = false;
if (!m_pending_hash_paths.isEmpty()) { if (!m_pendingHashPaths.isEmpty()) {
qDebug() << "[Blocked Mods Dialog] there are pending hash tasks, building and running tasks"; qDebug() << "[Blocked Mods Dialog] there are pending hash tasks, building and running tasks";
auto path = m_pending_hash_paths.begin(); auto path = m_pendingHashPaths.begin();
while (path != m_pending_hash_paths.end()) { while (path != m_pendingHashPaths.end()) {
buildHashTask(*path); buildHashTask(*path);
path = m_pending_hash_paths.erase(path); path = m_pendingHashPaths.erase(path);
} }
m_hashing_task->start(); m_hashingTask->start();
} }
} else { } else {
qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task"; qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task";
qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pending_hash_paths; qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pendingHashPaths;
m_rehash_pending = true; m_rehashPending = true;
} }
} }
void BlockedModsDialog::hashTaskFinished() void BlockedModsDialog::hashTaskFinished()
{ {
qDebug() << "[Blocked Mods Dialog] All hash tasks finished"; qDebug() << "[Blocked Mods Dialog] All hash tasks finished";
if (m_rehash_pending) { if (m_rehashPending) {
qDebug() << "[Blocked Mods Dialog] task finished with a rehash pending, rerunning"; qDebug() << "[Blocked Mods Dialog] task finished with a rehash pending, rerunning";
runHashTask(); runHashTask();
} }

View file

@ -70,11 +70,10 @@ class BlockedModsDialog : public QDialog {
Ui::BlockedModsDialog* ui; Ui::BlockedModsDialog* ui;
QList<BlockedMod>& m_mods; QList<BlockedMod>& m_mods;
QFileSystemWatcher m_watcher; QFileSystemWatcher m_watcher;
shared_qobject_ptr<ConcurrentTask> m_hashing_task; shared_qobject_ptr<ConcurrentTask> m_hashingTask;
QSet<QString> m_pending_hash_paths; QSet<QString> m_pendingHashPaths;
bool m_rehash_pending; bool m_rehashPending;
QPushButton* m_openMissingButton; QString m_hashType;
QString m_hash_type;
void openAll(bool missingOnly); void openAll(bool missingOnly);
void addDownloadFolder(); void addDownloadFolder();

View file

@ -6,20 +6,26 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>800</width>
<height>400</height> <height>500</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>700</width>
<height>350</height> <height>350</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">BlockedModsDialog</string> <string notr="true">BlockedModsDialog</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,3,0,1,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item> <item>
<widget class="QLabel" name="labelDescription"> <widget class="QLabel" name="labelDescription">
<property name="text"> <property name="text">
@ -36,16 +42,23 @@
<item> <item>
<widget class="QLabel" name="labelExplain"> <widget class="QLabel" name="labelExplain">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Your configured global mods folder and default downloads folder are automatically checked for the downloaded mods and they will be copied to the instance if found.&lt;/p&gt;&lt;p&gt;Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch if you did not download the mods to a default location.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Your configured global mods folder and default downloads folder are automatically checked for the downloaded mods and they will be copied to the instance if found.&lt;/p&gt;&lt;p&gt;Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch if you did not download the mods to a default location.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Click 'Open Missing' to open all the download links in the browser. &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Blocked Mods</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTextBrowser" name="textBrowserModsListing"> <widget class="QTextBrowser" name="textBrowserModsListing">
<property name="acceptRichText"> <property name="acceptRichText">
@ -57,12 +70,36 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="labelWatched"> <layout class="QHBoxLayout" name="openMissingLayout">
<item>
<widget class="QPushButton" name="openMissingButton">
<property name="text"> <property name="text">
<string>Watched Folders:</string> <string>Open Missing</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="openMissingSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Watched Folders</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QTextBrowser" name="textBrowserWatched"> <widget class="QTextBrowser" name="textBrowserWatched">
<property name="baseSize"> <property name="baseSize">
@ -79,6 +116,34 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="downloadFolderLayout">
<item>
<widget class="QPushButton" name="downloadFolderButton">
<property name="text">
<string>Add Download Folder</string>
</property>
</widget>
</item>
<item>
<spacer name="downloadFolderSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="bottomBoxH"> <layout class="QHBoxLayout" name="bottomBoxH">
<item> <item>