feat(ui): allow downloading multiple mods from CurseForge at once

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

View File

@ -35,6 +35,7 @@ FlameModPage::FlameModPage(ModDownloadDialog *dialog, BaseInstance *instance)
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameModPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameModPage::onVersionSelectionChanged);
connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected);
}
FlameModPage::~FlameModPage()
@ -62,7 +63,7 @@ bool FlameModPage::shouldDisplay() const
void FlameModPage::openedImpl()
{
suggestCurrent();
updateSelectionButton();
triggerSearch();
}
@ -77,10 +78,6 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if(!first.isValid())
{
if(isOpened)
{
dialog->setSuggestedMod();
}
return;
}
@ -112,6 +109,10 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if (!current.versionsLoaded)
{
qDebug() << "Loading flame mod versions";
ui->modSelectionButton->setText(tr("Loading versions..."));
ui->modSelectionButton->setEnabled(false);
auto netJob = new NetJob(QString("Flame::ModVersions(%1)").arg(current.name), APPLICATION->network());
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
int addonId = current.addonId;
@ -151,7 +152,7 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1));
}
suggestCurrent();
updateSelectionButton();
});
netJob->start();
}
@ -163,25 +164,26 @@ void FlameModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
if(ui->versionSelectionBox->count() == 0){
ui->versionSelectionBox->addItem(tr("No Valid Version found!"), QVariant(-1));
}
suggestCurrent();
updateSelectionButton();
}
}
void FlameModPage::suggestCurrent()
void FlameModPage::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 FlameModPage::onVersionSelectionChanged(QString data)
@ -192,5 +194,18 @@ void FlameModPage::onVersionSelectionChanged(QString data)
return;
}
selectedVersion = ui->versionSelectionBox->currentData().toInt();
suggestCurrent();
updateSelectionButton();
}
void FlameModPage::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::FlameModPage *ui = nullptr;

View File

@ -1,90 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FlameModPage</class>
<widget class="QWidget" name="FlameModPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>837</width>
<height>685</height>
</rect>
</property>
<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">
<widget class="QTextBrowser" name="packDescription">
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</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>
</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>
</layout>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="searchEdit">
<property name="placeholderText">
<string>Search and filter ...</string>
</property>
</widget>
</item>
<class>FlameModPage</class>
<widget class="QWidget" name="FlameModPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>837</width>
<height>685</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0,0,0" columnminimumwidth="0,0,0">
<item row="1" column="2">
<widget class="QComboBox" name="versionSelectionBox"/>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="sortByBox"/>
</item>
<item row="1" 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="2" column="2">
<widget class="QPushButton" name="modSelectionButton">
<property name="text">
<string>Select mod for download</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>searchEdit</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>packView</tabstop>
<tabstop>packDescription</tabstop>
<tabstop>sortByBox</tabstop>
<tabstop>versionSelectionBox</tabstop>
</tabstops>
<resources/>
<connections/>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="searchEdit">
<property name="placeholderText">
<string>Search and filter ...</string>
</property>
</widget>
</item>
<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="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextBrowser" name="packDescription">
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>searchEdit</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>packView</tabstop>
<tabstop>packDescription</tabstop>
<tabstop>sortByBox</tabstop>
<tabstop>versionSelectionBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>