2022-12-17 06:14:21 +05:30
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
2022-12-19 01:33:39 +05:30
|
|
|
#include <QHash>
|
2022-11-25 17:53:46 +05:30
|
|
|
#include <QLayout>
|
|
|
|
|
2022-12-19 00:11:46 +05:30
|
|
|
#include "QObjectPtr.h"
|
|
|
|
#include "modplatform/ModIndex.h"
|
2022-11-25 17:53:46 +05:30
|
|
|
#include "ui/pages/BasePageProvider.h"
|
|
|
|
|
2022-12-17 06:14:21 +05:30
|
|
|
class BaseInstance;
|
|
|
|
class ModFolderModel;
|
2022-11-25 17:53:46 +05:30
|
|
|
class PageContainer;
|
|
|
|
class QVBoxLayout;
|
|
|
|
class QDialogButtonBox;
|
2022-12-17 06:14:21 +05:30
|
|
|
class ResourceDownloadTask;
|
|
|
|
class ResourceFolderModel;
|
2022-11-25 17:53:46 +05:30
|
|
|
|
2022-12-17 03:33:52 +05:30
|
|
|
namespace ResourceDownload {
|
|
|
|
|
|
|
|
class ResourcePage;
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-12-19 00:11:46 +05:30
|
|
|
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model);
|
|
|
|
|
|
|
|
void initializeContainer();
|
|
|
|
void connectButtons();
|
|
|
|
|
|
|
|
//: String that gets appended to the download dialog title ("Download " + resourcesString())
|
|
|
|
[[nodiscard]] virtual QString resourceString() const { return tr("resources"); }
|
|
|
|
|
|
|
|
QString dialogTitle() override { return tr("Download %1").arg(resourceString()); };
|
|
|
|
|
|
|
|
bool selectPage(QString pageId);
|
|
|
|
ResourcePage* getSelectedPage();
|
|
|
|
|
2022-12-19 00:11:46 +05:30
|
|
|
void addResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&, bool is_indexed = false);
|
|
|
|
void removeResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
2022-11-25 17:53:46 +05:30
|
|
|
|
2022-12-19 00:11:46 +05:30
|
|
|
const QList<DownloadTaskPtr> getTasks();
|
2022-11-25 17:53:46 +05:30
|
|
|
[[nodiscard]] const std::shared_ptr<ResourceFolderModel> getBaseModel() const { return m_base_model; }
|
|
|
|
|
2022-12-17 06:14:21 +05:30
|
|
|
public slots:
|
|
|
|
void accept() override;
|
|
|
|
void reject() override;
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
protected slots:
|
|
|
|
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
|
|
|
|
|
|
|
virtual void confirm();
|
|
|
|
|
2022-12-17 06:14:21 +05:30
|
|
|
protected:
|
|
|
|
[[nodiscard]] virtual QString geometrySaveKey() const { return ""; }
|
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
protected:
|
|
|
|
const std::shared_ptr<ResourceFolderModel> m_base_model;
|
|
|
|
|
|
|
|
PageContainer* m_container = nullptr;
|
|
|
|
ResourcePage* m_selectedPage = nullptr;
|
|
|
|
|
|
|
|
QDialogButtonBox m_buttons;
|
|
|
|
QVBoxLayout m_vertical_layout;
|
|
|
|
|
2022-12-19 00:11:46 +05:30
|
|
|
QHash<QString, DownloadTaskPtr> m_selected;
|
2022-11-25 17:53:46 +05:30
|
|
|
};
|
2022-12-17 03:33:52 +05:30
|
|
|
|
2022-12-17 06:14:21 +05:30
|
|
|
|
|
|
|
|
|
|
|
class ModDownloadDialog final : public ResourceDownloadDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance);
|
|
|
|
~ModDownloadDialog() override = default;
|
|
|
|
|
|
|
|
//: String that gets appended to the mod download dialog title ("Download " + resourcesString())
|
|
|
|
[[nodiscard]] QString resourceString() const override { return tr("mods"); }
|
|
|
|
[[nodiscard]] QString geometrySaveKey() const override { return "ModDownloadGeometry"; }
|
|
|
|
|
|
|
|
QList<BasePage*> getPages() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
};
|
|
|
|
|
2022-12-17 03:33:52 +05:30
|
|
|
} // namespace ResourceDownload
|