improve blocked mods dialog
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
178965676e
commit
2fc89d7e11
3 changed files with 128 additions and 65 deletions
|
@ -43,21 +43,18 @@
|
|||
#include <QTimer>
|
||||
|
||||
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()));
|
||||
connect(m_hashing_task.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);
|
||||
connect(m_hashingTask.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
|
||||
m_openMissingButton = ui->buttonBox->addButton(tr("Open Missing"), QDialogButtonBox::ActionRole);
|
||||
connect(m_openMissingButton, &QPushButton::clicked, this, [this]() { openAll(true); });
|
||||
|
||||
auto downloadFolderButton = ui->buttonBox->addButton(tr("Add Download Folder"), QDialogButtonBox::ActionRole);
|
||||
connect(downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
|
||||
connect(ui->openMissingButton, &QPushButton::clicked, this, [this]() { openAll(true); });
|
||||
connect(ui->downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
|
||||
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
|
||||
|
||||
|
@ -174,10 +171,12 @@ void BlockedModsDialog::update()
|
|||
|
||||
if (allModsMatched()) {
|
||||
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 {
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
@ -268,14 +267,14 @@ void BlockedModsDialog::addHashTask(QString path)
|
|||
/// @param path the path to the local file being hashed
|
||||
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;
|
||||
|
||||
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; });
|
||||
|
||||
m_hashing_task->addTask(hash_task);
|
||||
m_hashingTask->addTask(hash_task);
|
||||
}
|
||||
|
||||
/// @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
|
||||
void BlockedModsDialog::runHashTask()
|
||||
{
|
||||
if (!m_hashing_task->isRunning()) {
|
||||
m_rehash_pending = false;
|
||||
if (!m_hashingTask->isRunning()) {
|
||||
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";
|
||||
|
||||
auto path = m_pending_hash_paths.begin();
|
||||
while (path != m_pending_hash_paths.end()) {
|
||||
auto path = m_pendingHashPaths.begin();
|
||||
while (path != m_pendingHashPaths.end()) {
|
||||
buildHashTask(*path);
|
||||
path = m_pending_hash_paths.erase(path);
|
||||
path = m_pendingHashPaths.erase(path);
|
||||
}
|
||||
|
||||
m_hashing_task->start();
|
||||
m_hashingTask->start();
|
||||
}
|
||||
} else {
|
||||
qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task";
|
||||
qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pending_hash_paths;
|
||||
m_rehash_pending = true;
|
||||
qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pendingHashPaths;
|
||||
m_rehashPending = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BlockedModsDialog::hashTaskFinished()
|
||||
{
|
||||
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";
|
||||
runHashTask();
|
||||
}
|
||||
|
|
|
@ -70,11 +70,10 @@ class BlockedModsDialog : public QDialog {
|
|||
Ui::BlockedModsDialog* ui;
|
||||
QList<BlockedMod>& m_mods;
|
||||
QFileSystemWatcher m_watcher;
|
||||
shared_qobject_ptr<ConcurrentTask> m_hashing_task;
|
||||
QSet<QString> m_pending_hash_paths;
|
||||
bool m_rehash_pending;
|
||||
QPushButton* m_openMissingButton;
|
||||
QString m_hash_type;
|
||||
shared_qobject_ptr<ConcurrentTask> m_hashingTask;
|
||||
QSet<QString> m_pendingHashPaths;
|
||||
bool m_rehashPending;
|
||||
QString m_hashType;
|
||||
|
||||
void openAll(bool missingOnly);
|
||||
void addDownloadFolder();
|
||||
|
|
|
@ -6,20 +6,26 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>400</height>
|
||||
<width>800</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<width>700</width>
|
||||
<height>350</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">BlockedModsDialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,3,0,1,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelDescription">
|
||||
<property name="text">
|
||||
|
@ -36,47 +42,106 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="labelExplain">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>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.</p><p>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.</p></body></html></string>
|
||||
<string><html><head/><body><p>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.</p><p>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.</p><p><span style=" font-weight:600;">Click 'Open Missing' to open all the download links in the browser. </span></p></body></html></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBrowserModsListing">
|
||||
<property name="acceptRichText">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelWatched">
|
||||
<property name="text">
|
||||
<string>Watched Folders:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBrowserWatched">
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>12</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
<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>
|
||||
<widget class="QTextBrowser" name="textBrowserModsListing">
|
||||
<property name="acceptRichText">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="openMissingLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="openMissingButton">
|
||||
<property name="text">
|
||||
<string>Open Missing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QTextBrowser" name="textBrowserWatched">
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>12</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue