2022-11-12 16:27:09 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 flow <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BaseInstance.h"
|
|
|
|
|
|
|
|
#include "modplatform/modrinth/ModrinthAPI.h"
|
|
|
|
#include "modplatform/modrinth/ModrinthPackManifest.h"
|
|
|
|
|
2022-11-12 15:19:05 +00:00
|
|
|
#include "modplatform/flame/FlameAPI.h"
|
|
|
|
#include "modplatform/flame/FlamePackIndex.h"
|
|
|
|
|
2023-01-03 16:58:27 +00:00
|
|
|
#include "net/NetJob.h"
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
#include "ui/pages/BasePage.h"
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ManagedPackPage;
|
|
|
|
}
|
|
|
|
|
2022-10-14 18:36:48 +01:00
|
|
|
class InstanceTask;
|
|
|
|
class InstanceWindow;
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
class ManagedPackPage : public QWidget, public BasePage {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline static ManagedPackPage* createPage(BaseInstance* inst, QWidget* parent = nullptr)
|
|
|
|
{
|
|
|
|
return ManagedPackPage::createPage(inst, inst->getManagedPackType(), parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ManagedPackPage* createPage(BaseInstance* inst, QString type, QWidget* parent = nullptr);
|
|
|
|
~ManagedPackPage() override;
|
|
|
|
|
|
|
|
[[nodiscard]] QString displayName() const override;
|
|
|
|
[[nodiscard]] QIcon icon() const override;
|
|
|
|
[[nodiscard]] QString helpPage() const override;
|
|
|
|
[[nodiscard]] QString id() const override { return "managed_pack"; }
|
|
|
|
[[nodiscard]] bool shouldDisplay() const override;
|
|
|
|
|
|
|
|
void openedImpl() override;
|
|
|
|
|
|
|
|
bool apply() override { return true; }
|
|
|
|
void retranslate() override;
|
|
|
|
|
|
|
|
/** Gets the necessary information about the managed pack, such as
|
|
|
|
* available versions*/
|
2022-11-12 16:27:09 +00:00
|
|
|
virtual void parseManagedPack(){};
|
2022-10-13 23:55:21 +01:00
|
|
|
|
|
|
|
/** URL of the managed pack.
|
|
|
|
* Not the version-specific one.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual QString url() const { return {}; };
|
|
|
|
|
2022-10-14 18:36:48 +01:00
|
|
|
void setInstanceWindow(InstanceWindow* window) { m_instance_window = window; }
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
public slots:
|
2022-11-11 20:44:16 +00:00
|
|
|
/** Gets the current version selection and update the UI, including the update button and the changelog.
|
2022-10-13 23:55:21 +01:00
|
|
|
*/
|
2022-11-11 20:44:16 +00:00
|
|
|
virtual void suggestVersion();
|
2022-10-13 23:55:21 +01:00
|
|
|
|
2022-11-12 16:27:09 +00:00
|
|
|
virtual void update(){};
|
2022-10-14 18:36:48 +01:00
|
|
|
|
2022-11-11 20:44:16 +00:00
|
|
|
protected slots:
|
|
|
|
/** Does the necessary UI changes for when something failed.
|
|
|
|
*
|
|
|
|
* This includes:
|
|
|
|
* - Setting an appropriate text on the version selector to indicate a fail;
|
|
|
|
* - Setting an appropriate text on the changelog text browser to indicate a fail;
|
|
|
|
* - Disable the update button.
|
|
|
|
*/
|
|
|
|
void setFailState();
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
protected:
|
2022-10-14 18:36:48 +01:00
|
|
|
ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr);
|
|
|
|
|
|
|
|
/** Run the InstanceTask, with a progress dialog and all.
|
|
|
|
* Similar to MainWindow::instanceFromInstanceTask
|
|
|
|
*
|
|
|
|
* Returns whether the task was successful.
|
|
|
|
*/
|
|
|
|
bool runUpdateTask(InstanceTask*);
|
2022-10-13 23:55:21 +01:00
|
|
|
|
|
|
|
protected:
|
2022-10-14 18:36:48 +01:00
|
|
|
InstanceWindow* m_instance_window = nullptr;
|
|
|
|
|
2022-10-13 23:55:21 +01:00
|
|
|
Ui::ManagedPackPage* ui;
|
|
|
|
BaseInstance* m_inst;
|
|
|
|
|
|
|
|
bool m_loaded = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Simple page for when we aren't a managed pack. */
|
|
|
|
class GenericManagedPackPage final : public ManagedPackPage {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-11-12 16:27:09 +00:00
|
|
|
GenericManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr)
|
|
|
|
: ManagedPackPage(inst, instance_window, parent)
|
|
|
|
{}
|
2022-10-13 23:55:21 +01:00
|
|
|
~GenericManagedPackPage() override = default;
|
2022-11-11 19:58:37 +00:00
|
|
|
|
|
|
|
// TODO: We may want to show this page with some useful info at some point.
|
|
|
|
[[nodiscard]] bool shouldDisplay() const override { return false; };
|
2022-10-13 23:55:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModrinthManagedPackPage final : public ManagedPackPage {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-10-14 18:36:48 +01:00
|
|
|
ModrinthManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr);
|
2022-10-13 23:55:21 +01:00
|
|
|
~ModrinthManagedPackPage() override = default;
|
|
|
|
|
|
|
|
void parseManagedPack() override;
|
|
|
|
[[nodiscard]] QString url() const override;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void suggestVersion() override;
|
2022-10-13 23:57:23 +01:00
|
|
|
|
2022-10-14 18:36:48 +01:00
|
|
|
void update() override;
|
|
|
|
|
2022-10-13 23:57:23 +01:00
|
|
|
private:
|
2022-11-18 18:48:16 +00:00
|
|
|
NetJob::Ptr m_fetch_job = nullptr;
|
|
|
|
|
2022-10-13 23:57:23 +01:00
|
|
|
Modrinth::Modpack m_pack;
|
|
|
|
ModrinthAPI m_api;
|
2022-10-13 23:55:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class FlameManagedPackPage final : public ManagedPackPage {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-10-14 18:36:48 +01:00
|
|
|
FlameManagedPackPage(BaseInstance* inst, InstanceWindow* instance_window, QWidget* parent = nullptr);
|
2022-10-13 23:55:21 +01:00
|
|
|
~FlameManagedPackPage() override = default;
|
|
|
|
|
|
|
|
void parseManagedPack() override;
|
|
|
|
[[nodiscard]] QString url() const override;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void suggestVersion() override;
|
2022-11-12 15:19:05 +00:00
|
|
|
|
2022-11-12 16:03:50 +00:00
|
|
|
void update() override;
|
|
|
|
|
2022-11-12 15:19:05 +00:00
|
|
|
private:
|
2022-11-18 18:48:16 +00:00
|
|
|
NetJob::Ptr m_fetch_job = nullptr;
|
|
|
|
|
2022-11-12 15:19:05 +00:00
|
|
|
Flame::IndexedPack m_pack;
|
|
|
|
FlameAPI m_api;
|
2022-10-13 23:55:21 +01:00
|
|
|
};
|