feat(ui): allow downloading multiple mods in Modrinth at once

This commit is contained in:
flow 2022-02-21 21:34:53 -03:00
parent 9c6727e27f
commit 512395e3f1
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
3 changed files with 130 additions and 106 deletions

View File

@ -34,6 +34,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance)
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected);
}
ModrinthPage::~ModrinthPage()
@ -61,7 +62,7 @@ bool ModrinthPage::shouldDisplay() const
void ModrinthPage::openedImpl()
{
suggestCurrent();
updateSelectionButton();
triggerSearch();
}
@ -76,10 +77,6 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if(!first.isValid())
{
if(isOpened)
{
dialog->setSuggestedMod();
}
return;
}
@ -97,6 +94,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if (!current.versionsLoaded)
{
qDebug() << "Loading Modrinth mod versions";
ui->modSelectionButton->setText(tr("Loading versions..."));
ui->modSelectionButton->setEnabled(false);
auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network());
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
QString addonId = current.addonId;
@ -136,8 +137,9 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1));
}
suggestCurrent();
updateSelectionButton();
});
netJob->start();
}
else
@ -148,33 +150,47 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if(ui->versionSelectionBox->count() == 0){
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1));
}
suggestCurrent();
updateSelectionButton();
}
}
void ModrinthPage::suggestCurrent()
void ModrinthPage::updateSelectionButton()
{
if(!isOpened)
{
if(!isOpened || selectedVersion < 0){
ui->modSelectionButton->setEnabled(false);
return;
}
if (selectedVersion == -1)
{
dialog->setSuggestedMod();
return;
ui->modSelectionButton->setEnabled(true);
auto& version = current.versions[selectedVersion];
if(!dialog->isModSelected(current.name, version.fileName)){
ui->modSelectionButton->setText(tr("Select mod for download"));
}
else{
ui->modSelectionButton->setText(tr("Deselect mod for download"));
}
auto version = current.versions[selectedVersion];
dialog->setSuggestedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods));
}
void ModrinthPage::onVersionSelectionChanged(QString data)
{
if(data.isNull() || data.isEmpty())
{
if (data.isNull() || data.isEmpty()){
selectedVersion = -1;
return;
}
selectedVersion = ui->versionSelectionBox->currentData().toInt();
suggestCurrent();
updateSelectionButton();
}
void ModrinthPage::onModSelected()
{
auto& version = current.versions[selectedVersion];
if (dialog->isModSelected(current.name, version.fileName)){
dialog->removeSelectedMod(current.name);
}
else{
dialog->addSelectedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName , dialog->mods));
}
updateSelectionButton();
}

View File

@ -50,12 +50,13 @@ public:
BaseInstance *m_instance;
private:
void suggestCurrent();
void updateSelectionButton();
private slots:
void triggerSearch();
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data);
void onModSelected();
private:
Ui::ModrinthPage *ui = nullptr;

View File

@ -13,23 +13,7 @@
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QListView" name="packView">
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="2">
<widget class="QTextBrowser" name="packDescription">
<property name="openExternalLinks">
<bool>true</bool>
@ -39,26 +23,22 @@
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0" columnminimumwidth="0,0,0">
<item row="0" column="2">
<widget class="QComboBox" name="versionSelectionBox"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Version selected:</string>
<item row="1" column="0">
<widget class="QListView" name="packView">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="sortByBox"/>
</item>
</layout>
</item>
<item row="0" column="1">
@ -75,6 +55,33 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0,0">
<item row="0" column="2">
<widget class="QComboBox" name="versionSelectionBox"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Version selected:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="sortByBox"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="modSelectionButton">
<property name="text">
<string>Select mod for download</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>