aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui/dialogs')
-rw-r--r--launcher/ui/dialogs/ExportPackDialog.cpp (renamed from launcher/ui/dialogs/ExportMrPackDialog.cpp)63
-rw-r--r--launcher/ui/dialogs/ExportPackDialog.h (renamed from launcher/ui/dialogs/ExportMrPackDialog.h)14
-rw-r--r--launcher/ui/dialogs/ExportPackDialog.ui (renamed from launcher/ui/dialogs/ExportMrPackDialog.ui)15
-rw-r--r--launcher/ui/dialogs/ProgressDialog.cpp48
-rw-r--r--launcher/ui/dialogs/ProgressDialog.h2
-rw-r--r--launcher/ui/dialogs/ResourceDownloadDialog.cpp9
6 files changed, 100 insertions, 51 deletions
diff --git a/launcher/ui/dialogs/ExportMrPackDialog.cpp b/launcher/ui/dialogs/ExportPackDialog.cpp
index b302f7ba..2abe2805 100644
--- a/launcher/ui/dialogs/ExportMrPackDialog.cpp
+++ b/launcher/ui/dialogs/ExportPackDialog.cpp
@@ -16,11 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "ExportMrPackDialog.h"
+#include "ExportPackDialog.h"
#include "minecraft/mod/ModFolderModel.h"
+#include "modplatform/ModIndex.h"
+#include "modplatform/flame/FlamePackExportTask.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/ProgressDialog.h"
-#include "ui_ExportMrPackDialog.h"
+#include "ui_ExportPackDialog.h"
#include <QFileDialog>
#include <QFileSystemModel>
@@ -32,17 +34,24 @@
#include "MMCZip.h"
#include "modplatform/modrinth/ModrinthPackExportTask.h"
-ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
- : QDialog(parent), instance(instance), ui(new Ui::ExportMrPackDialog)
+ExportPackDialog::ExportPackDialog(InstancePtr instance, QWidget* parent, ModPlatform::ResourceProvider provider)
+ : QDialog(parent), instance(instance), ui(new Ui::ExportPackDialog), m_provider(provider)
{
ui->setupUi(this);
ui->name->setText(instance->name());
- ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]);
+ if (m_provider == ModPlatform::ResourceProvider::MODRINTH) {
+ ui->summary->setText(instance->notes().split(QRegularExpression("\\r?\\n"))[0]);
+ setWindowTitle("Export Modrinth Pack");
+ } else {
+ setWindowTitle("Export CurseForge Pack");
+ ui->version->setText("");
+ ui->summaryLabel->setText("Author");
+ }
// ensure a valid pack is generated
// the name and version fields mustn't be empty
- connect(ui->name, &QLineEdit::textEdited, this, &ExportMrPackDialog::validate);
- connect(ui->version, &QLineEdit::textEdited, this, &ExportMrPackDialog::validate);
+ connect(ui->name, &QLineEdit::textEdited, this, &ExportPackDialog::validate);
+ connect(ui->version, &QLineEdit::textEdited, this, &ExportPackDialog::validate);
// the instance name can technically be empty
validate();
@@ -66,6 +75,7 @@ ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
if (mcInstance) {
+ mcInstance->loaderModList()->update();
const QDir index = mcInstance->loaderModList()->indexDir();
if (index.exists())
proxy->blockedPaths().insert(root.relativeFilePath(index.absolutePath()));
@@ -83,43 +93,54 @@ ExportMrPackDialog::ExportMrPackDialog(InstancePtr instance, QWidget* parent)
headerView->setSectionResizeMode(0, QHeaderView::Stretch);
}
-ExportMrPackDialog::~ExportMrPackDialog()
+ExportPackDialog::~ExportPackDialog()
{
delete ui;
}
-void ExportMrPackDialog::done(int result)
+void ExportPackDialog::done(int result)
{
if (result == Accepted) {
const QString filename = FS::RemoveInvalidFilenameChars(ui->name->text());
- const QString output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
- FS::PathCombine(QDir::homePath(), filename + ".mrpack"),
- "Modrinth pack (*.mrpack *.zip)", nullptr);
+ QString output;
+ if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
+ output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
+ FS::PathCombine(QDir::homePath(), filename + ".mrpack"), "Modrinth pack (*.mrpack *.zip)",
+ nullptr);
+ else
+ output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(ui->name->text()),
+ FS::PathCombine(QDir::homePath(), filename + ".zip"), "CurseForge pack (*.zip)", nullptr);
if (output.isEmpty())
return;
-
- ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
- std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
-
- connect(&task, &Task::failed,
+ Task* task;
+ if (m_provider == ModPlatform::ResourceProvider::MODRINTH)
+ task = new ModrinthPackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
+ std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
+ else
+ task = new FlamePackExportTask(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
+ std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1));
+
+ connect(task, &Task::failed,
[this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
- connect(&task, &Task::aborted, [this] {
+ connect(task, &Task::aborted, [this] {
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)
->show();
});
+ connect(task, &Task::finished, [task] { task->deleteLater(); });
ProgressDialog progress(this);
progress.setSkipButton(true, tr("Abort"));
- if (progress.execWithTask(&task) != QDialog::Accepted)
+ if (progress.execWithTask(task) != QDialog::Accepted)
return;
}
QDialog::done(result);
}
-void ExportMrPackDialog::validate()
+void ExportPackDialog::validate()
{
- const bool invalid = ui->name->text().isEmpty() || ui->version->text().isEmpty();
+ const bool invalid =
+ ui->name->text().isEmpty() || ((m_provider == ModPlatform::ResourceProvider::MODRINTH) && ui->version->text().isEmpty());
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(invalid);
}
diff --git a/launcher/ui/dialogs/ExportMrPackDialog.h b/launcher/ui/dialogs/ExportPackDialog.h
index 1c70c4ae..830c24d2 100644
--- a/launcher/ui/dialogs/ExportMrPackDialog.h
+++ b/launcher/ui/dialogs/ExportPackDialog.h
@@ -22,24 +22,28 @@
#include "BaseInstance.h"
#include "FastFileIconProvider.h"
#include "FileIgnoreProxy.h"
+#include "modplatform/ModIndex.h"
namespace Ui {
-class ExportMrPackDialog;
+class ExportPackDialog;
}
-class ExportMrPackDialog : public QDialog {
+class ExportPackDialog : public QDialog {
Q_OBJECT
public:
- explicit ExportMrPackDialog(InstancePtr instance, QWidget* parent = nullptr);
- ~ExportMrPackDialog();
+ explicit ExportPackDialog(InstancePtr instance,
+ QWidget* parent = nullptr,
+ ModPlatform::ResourceProvider provider = ModPlatform::ResourceProvider::MODRINTH);
+ ~ExportPackDialog();
void done(int result) override;
void validate();
private:
const InstancePtr instance;
- Ui::ExportMrPackDialog* ui;
+ Ui::ExportPackDialog* ui;
FileIgnoreProxy* proxy;
FastFileIconProvider icons;
+ const ModPlatform::ResourceProvider m_provider;
};
diff --git a/launcher/ui/dialogs/ExportMrPackDialog.ui b/launcher/ui/dialogs/ExportPackDialog.ui
index 9a789737..3976e28f 100644
--- a/launcher/ui/dialogs/ExportMrPackDialog.ui
+++ b/launcher/ui/dialogs/ExportPackDialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>ExportMrPackDialog</class>
- <widget class="QDialog" name="ExportMrPackDialog">
+ <class>ExportPackDialog</class>
+ <widget class="QDialog" name="ExportPackDialog">
<property name="geometry">
<rect>
<x>0</x>
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>Export Modrinth Pack</string>
+ <string>Export Pack</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
@@ -24,7 +24,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
- <widget class="QLabel" name="versionLabel">
+ <widget class="QLabel" name="summaryLabel">
<property name="text">
<string>Summary</string>
</property>
@@ -41,7 +41,7 @@
</widget>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="summaryLabel">
+ <widget class="QLabel" name="versionLabel">
<property name="text">
<string>Version</string>
</property>
@@ -57,6 +57,7 @@
</property>
</widget>
</item>
+
</layout>
</widget>
</item>
@@ -103,7 +104,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
- <receiver>ExportMrPackDialog</receiver>
+ <receiver>ExportPackDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -119,7 +120,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
- <receiver>ExportMrPackDialog</receiver>
+ <receiver>ExportPackDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
diff --git a/launcher/ui/dialogs/ProgressDialog.cpp b/launcher/ui/dialogs/ProgressDialog.cpp
index 246a0fd4..4243e291 100644
--- a/launcher/ui/dialogs/ProgressDialog.cpp
+++ b/launcher/ui/dialogs/ProgressDialog.cpp
@@ -34,6 +34,7 @@
*/
#include "ProgressDialog.h"
+#include <QPoint>
#include "ui_ProgressDialog.h"
#include <limits>
@@ -66,8 +67,9 @@ ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Pr
ui->taskProgressScrollArea->setHidden(true);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
- setSkipButton(false);
changeProgress(0, 100);
+ updateSize(true);
+ setSkipButton(false);
}
void ProgressDialog::setSkipButton(bool present, QString label)
@@ -93,25 +95,39 @@ ProgressDialog::~ProgressDialog()
delete ui;
}
-void ProgressDialog::updateSize()
+void ProgressDialog::updateSize(bool recenterParent)
{
QSize lastSize = this->size();
- QSize qSize = QSize(480, minimumSizeHint().height());
-
- // if the current window is too small
- if ((lastSize != qSize) && (lastSize.height() < qSize.height()))
+ QPoint lastPos = this->pos();
+ int minHeight = ui->globalStatusDetailsLabel->minimumSize().height() + (ui->verticalLayout->spacing() * 2);
+ minHeight += ui->globalProgressBar->minimumSize().height() + ui->verticalLayout->spacing();
+ if (!ui->taskProgressScrollArea->isHidden())
+ minHeight += ui->taskProgressScrollArea->minimumSizeHint().height() + ui->verticalLayout->spacing();
+ if (ui->skipButton->isVisible())
+ minHeight += ui->skipButton->height() + ui->verticalLayout->spacing();
+ minHeight = std::max(minHeight, 60);
+ QSize minSize = QSize(480, minHeight);
+
+ setMinimumSize(minSize);
+ adjustSize();
+
+ QSize newSize = this->size();
+ // if the current window is a different size
+ auto parent = this->parentWidget();
+ if (recenterParent && parent) {
+ auto newX = std::max(0, parent->x() + ((parent->width() - newSize.width()) / 2));
+ auto newY = std::max(0, parent->y() + ((parent->height() - newSize.height()) / 2));
+ this->move(newX, newY);
+ }
+ else if (lastSize != newSize)
{
- resize(qSize);
-
- // keep the dialog in the center after a resize
- this->move(
- this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
- this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
- );
+ // center on old position after resize
+ QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative
+ auto newX = std::max(0, lastPos.x() + (sizeDiff.width() / 2));
+ auto newY = std::max(0, lastPos.y() + (sizeDiff.height() / 2));
+ this->move(newX, newY);
}
- setMinimumSize(qSize);
-
}
int ProgressDialog::execWithTask(Task* task)
@@ -201,7 +217,9 @@ void ProgressDialog::onTaskSucceeded()
void ProgressDialog::changeStatus(const QString& status)
{
ui->globalStatusLabel->setText(task->getStatus());
+ ui->globalStatusLabel->adjustSize();
ui->globalStatusDetailsLabel->setText(task->getDetails());
+ ui->globalStatusDetailsLabel->adjustSize();
updateSize();
}
diff --git a/launcher/ui/dialogs/ProgressDialog.h b/launcher/ui/dialogs/ProgressDialog.h
index fc9a0fbc..f062be08 100644
--- a/launcher/ui/dialogs/ProgressDialog.h
+++ b/launcher/ui/dialogs/ProgressDialog.h
@@ -62,7 +62,7 @@ public:
explicit ProgressDialog(QWidget *parent = 0);
~ProgressDialog();
- void updateSize();
+ void updateSize(bool recenterParent = false);
int execWithTask(Task* task);
int execWithTask(std::unique_ptr<Task> &&task);
diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.cpp b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
index 283f35bc..c243ce28 100644
--- a/launcher/ui/dialogs/ResourceDownloadDialog.cpp
+++ b/launcher/ui/dialogs/ResourceDownloadDialog.cpp
@@ -43,6 +43,8 @@
#include "ui/pages/modplatform/flame/FlameResourcePages.h"
#include "ui/pages/modplatform/modrinth/ModrinthResourcePages.h"
+#include "modplatform/flame/FlameAPI.h"
+#include "modplatform/modrinth/ModrinthAPI.h"
#include "ui/widgets/PageContainer.h"
namespace ResourceDownload {
@@ -277,8 +279,11 @@ QList<BasePage*> ModDownloadDialog::getPages()
{
QList<BasePage*> pages;
- pages.append(ModrinthModPage::create(this, *m_instance));
- if (APPLICATION->capabilities() & Application::SupportsFlame)
+ auto loaders = static_cast<MinecraftInstance*>(m_instance)->getPackProfile()->getModLoaders().value();
+
+ if (ModrinthAPI::validateModLoaders(loaders))
+ pages.append(ModrinthModPage::create(this, *m_instance));
+ if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders))
pages.append(FlameModPage::create(this, *m_instance));
return pages;