feat: change task container in ModDownloadDialog to a QHash
Previously, we used a unique_ptr to a ModDownloadTask to keep track of the selected mod to download when we accepted the dialog. In order to allow multiple mods to be selected at once for download, this has been changed to a QHash where the key is the mods name (since it doesn't seem right to allow for multiple versions of the same mod to be downloaded at once), and the value is a pointer to the corresponding ModDownloadTask.
This commit is contained in:
parent
613b351f13
commit
9c6727e27f
@ -10,6 +10,7 @@ class ModDownloadTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr<ModFolderModel> mods);
|
||||
const QString& getFilename() const { return filename; }
|
||||
|
||||
public slots:
|
||||
bool abort() override;
|
||||
|
@ -52,6 +52,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods
|
||||
HelpButton->setDefault(false);
|
||||
HelpButton->setAutoDefault(false);
|
||||
connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setWindowTitle("Download mods");
|
||||
@ -83,16 +84,38 @@ QList<BasePage *> ModDownloadDialog::getPages()
|
||||
};
|
||||
}
|
||||
|
||||
void ModDownloadDialog::setSuggestedMod(const QString& name, ModDownloadTask* task)
|
||||
void ModDownloadDialog::addSelectedMod(const QString& name, ModDownloadTask* task)
|
||||
{
|
||||
modTask.reset(task);
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(task);
|
||||
if(modTask.contains(name))
|
||||
delete modTask.find(name).value();
|
||||
|
||||
if(task)
|
||||
modTask.insert(name, task);
|
||||
else
|
||||
modTask.remove(name);
|
||||
|
||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(!modTask.isEmpty());
|
||||
}
|
||||
|
||||
void ModDownloadDialog::removeSelectedMod(const QString &name)
|
||||
{
|
||||
if(modTask.contains(name))
|
||||
delete modTask.find(name).value();
|
||||
modTask.remove(name);
|
||||
}
|
||||
|
||||
bool ModDownloadDialog::isModSelected(const QString &name, const QString& filename) const
|
||||
{
|
||||
// FIXME: Is there a way to check for versions without checking the filename
|
||||
// as a heuristic, other than adding such info to ModDownloadTask itself?
|
||||
auto iter = modTask.find(name);
|
||||
return iter != modTask.end() && (iter.value()->getFilename() == filename);
|
||||
}
|
||||
|
||||
ModDownloadDialog::~ModDownloadDialog()
|
||||
{
|
||||
}
|
||||
|
||||
ModDownloadTask *ModDownloadDialog::getTask() {
|
||||
return modTask.release();
|
||||
const QList<ModDownloadTask*> ModDownloadDialog::getTasks() {
|
||||
return modTask.values();
|
||||
}
|
||||
|
@ -29,9 +29,11 @@ public:
|
||||
QString dialogTitle() override;
|
||||
QList<BasePage *> getPages() override;
|
||||
|
||||
void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
||||
void addSelectedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
|
||||
void removeSelectedMod(const QString & name = QString());
|
||||
bool isModSelected(const QString & name, const QString & filename) const;
|
||||
|
||||
ModDownloadTask * getTask();
|
||||
const QList<ModDownloadTask*> getTasks();
|
||||
const std::shared_ptr<ModFolderModel> &mods;
|
||||
|
||||
public slots:
|
||||
@ -49,6 +51,6 @@ private:
|
||||
|
||||
ModrinthPage *modrinthPage = nullptr;
|
||||
FlameModPage *flameModPage = nullptr;
|
||||
std::unique_ptr<ModDownloadTask> modTask;
|
||||
QHash<QString, ModDownloadTask*> modTask;
|
||||
BaseInstance *m_instance;
|
||||
};
|
||||
|
@ -365,8 +365,7 @@ void ModFolderPage::on_actionInstall_mods_triggered()
|
||||
}
|
||||
ModDownloadDialog mdownload(m_mods, this, m_inst);
|
||||
if(mdownload.exec()) {
|
||||
ModDownloadTask *task = mdownload.getTask();
|
||||
if (task) {
|
||||
for(auto task : mdownload.getTasks()){
|
||||
connect(task, &Task::failed, [this, task](QString reason) {
|
||||
task->deleteLater();
|
||||
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
|
||||
|
Loading…
Reference in New Issue
Block a user