feat(ui): allow downloading multiple mods in Modrinth at once
This commit is contained in:
parent
9c6727e27f
commit
512395e3f1
@ -34,6 +34,7 @@ ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance)
|
|||||||
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||||
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
|
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
|
||||||
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
|
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
|
||||||
|
connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModrinthPage::~ModrinthPage()
|
ModrinthPage::~ModrinthPage()
|
||||||
@ -61,7 +62,7 @@ bool ModrinthPage::shouldDisplay() const
|
|||||||
|
|
||||||
void ModrinthPage::openedImpl()
|
void ModrinthPage::openedImpl()
|
||||||
{
|
{
|
||||||
suggestCurrent();
|
updateSelectionButton();
|
||||||
triggerSearch();
|
triggerSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,10 +77,6 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
|
|
||||||
if(!first.isValid())
|
if(!first.isValid())
|
||||||
{
|
{
|
||||||
if(isOpened)
|
|
||||||
{
|
|
||||||
dialog->setSuggestedMod();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +94,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
if (!current.versionsLoaded)
|
if (!current.versionsLoaded)
|
||||||
{
|
{
|
||||||
qDebug() << "Loading Modrinth mod versions";
|
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());
|
auto netJob = new NetJob(QString("Modrinth::ModVersions(%1)").arg(current.name), APPLICATION->network());
|
||||||
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
|
std::shared_ptr<QByteArray> response = std::make_shared<QByteArray>();
|
||||||
QString addonId = current.addonId;
|
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));
|
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestCurrent();
|
updateSelectionButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -148,33 +150,47 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
|||||||
if(ui->versionSelectionBox->count() == 0){
|
if(ui->versionSelectionBox->count() == 0){
|
||||||
ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant(-1));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedVersion == -1)
|
ui->modSelectionButton->setEnabled(true);
|
||||||
{
|
auto& version = current.versions[selectedVersion];
|
||||||
dialog->setSuggestedMod();
|
if(!dialog->isModSelected(current.name, version.fileName)){
|
||||||
return;
|
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)
|
void ModrinthPage::onVersionSelectionChanged(QString data)
|
||||||
{
|
{
|
||||||
if(data.isNull() || data.isEmpty())
|
if (data.isNull() || data.isEmpty()){
|
||||||
{
|
|
||||||
selectedVersion = -1;
|
selectedVersion = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedVersion = ui->versionSelectionBox->currentData().toInt();
|
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();
|
||||||
}
|
}
|
||||||
|
@ -50,12 +50,13 @@ public:
|
|||||||
BaseInstance *m_instance;
|
BaseInstance *m_instance;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void suggestCurrent();
|
void updateSelectionButton();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void triggerSearch();
|
void triggerSearch();
|
||||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
void onVersionSelectionChanged(QString data);
|
void onVersionSelectionChanged(QString data);
|
||||||
|
void onModSelected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ModrinthPage *ui = nullptr;
|
Ui::ModrinthPage *ui = nullptr;
|
||||||
|
@ -1,90 +1,97 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>ModrinthPage</class>
|
<class>ModrinthPage</class>
|
||||||
<widget class="QWidget" name="ModrinthPage">
|
<widget class="QWidget" name="ModrinthPage">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>837</width>
|
<width>837</width>
|
||||||
<height>685</height>
|
<height>685</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="1" column="0">
|
<item row="1" column="2">
|
||||||
<widget class="QListView" name="packView">
|
<widget class="QTextBrowser" name="packDescription">
|
||||||
<property name="iconSize">
|
<property name="openExternalLinks">
|
||||||
<size>
|
<bool>true</bool>
|
||||||
<width>48</width>
|
</property>
|
||||||
<height>48</height>
|
<property name="openLinks">
|
||||||
</size>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="horizontalScrollBarPolicy">
|
</widget>
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
</item>
|
||||||
</property>
|
<item row="1" column="0">
|
||||||
<property name="alternatingRowColors">
|
<widget class="QListView" name="packView">
|
||||||
<bool>true</bool>
|
<property name="horizontalScrollBarPolicy">
|
||||||
</property>
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
</widget>
|
</property>
|
||||||
</item>
|
<property name="alternatingRowColors">
|
||||||
<item row="1" column="1">
|
<bool>true</bool>
|
||||||
<widget class="QTextBrowser" name="packDescription">
|
</property>
|
||||||
<property name="openExternalLinks">
|
<property name="iconSize">
|
||||||
<bool>true</bool>
|
<size>
|
||||||
</property>
|
<width>48</width>
|
||||||
<property name="openLinks">
|
<height>48</height>
|
||||||
<bool>true</bool>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</item>
|
||||||
<tabstops>
|
<item row="0" column="1">
|
||||||
<tabstop>searchEdit</tabstop>
|
<widget class="QPushButton" name="searchButton">
|
||||||
<tabstop>searchButton</tabstop>
|
<property name="text">
|
||||||
<tabstop>packView</tabstop>
|
<string>Search</string>
|
||||||
<tabstop>packDescription</tabstop>
|
</property>
|
||||||
<tabstop>sortByBox</tabstop>
|
</widget>
|
||||||
<tabstop>versionSelectionBox</tabstop>
|
</item>
|
||||||
</tabstops>
|
<item row="0" column="0">
|
||||||
<resources/>
|
<widget class="QLineEdit" name="searchEdit">
|
||||||
<connections/>
|
<property name="placeholderText">
|
||||||
|
<string>Search and filter ...</string>
|
||||||
|
</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>
|
||||||
|
<tabstop>searchEdit</tabstop>
|
||||||
|
<tabstop>searchButton</tabstop>
|
||||||
|
<tabstop>packView</tabstop>
|
||||||
|
<tabstop>packDescription</tabstop>
|
||||||
|
<tabstop>sortByBox</tabstop>
|
||||||
|
<tabstop>versionSelectionBox</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in New Issue
Block a user