2023-01-23 14:03:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2023-05-02 22:49:54 +01:00
|
|
|
#include "ResourceDownloadTask.h"
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "modplatform/ModIndex.h"
|
|
|
|
#include "modplatform/ResourceAPI.h"
|
|
|
|
|
|
|
|
#include "ui/pages/BasePage.h"
|
2023-05-02 22:49:54 +01:00
|
|
|
#include "ui/pages/modplatform/ResourceModel.h"
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "ui/widgets/ProgressWidget.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ResourcePage;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BaseInstance;
|
2022-12-16 22:03:52 +00:00
|
|
|
|
|
|
|
namespace ResourceDownload {
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
class ResourceDownloadDialog;
|
2022-12-16 22:03:52 +00:00
|
|
|
class ResourceModel;
|
2022-11-25 12:23:46 +00:00
|
|
|
|
|
|
|
class ResourcePage : public QWidget, public BasePage {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-05-02 22:49:54 +01:00
|
|
|
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
2022-11-25 12:23:46 +00:00
|
|
|
~ResourcePage() override;
|
|
|
|
|
|
|
|
/* Affects what the user sees */
|
|
|
|
[[nodiscard]] auto displayName() const -> QString override = 0;
|
|
|
|
[[nodiscard]] auto icon() const -> QIcon override = 0;
|
|
|
|
[[nodiscard]] auto id() const -> QString override = 0;
|
|
|
|
[[nodiscard]] auto helpPage() const -> QString override = 0;
|
|
|
|
[[nodiscard]] bool shouldDisplay() const override = 0;
|
|
|
|
|
|
|
|
/* Used internally */
|
|
|
|
[[nodiscard]] virtual auto metaEntryBase() const -> QString = 0;
|
|
|
|
[[nodiscard]] virtual auto debugName() const -> QString = 0;
|
|
|
|
|
2022-12-30 19:59:35 +00:00
|
|
|
//: The plural version of 'resource'
|
|
|
|
[[nodiscard]] virtual inline QString resourcesString() const { return tr("resources"); }
|
|
|
|
//: The singular version of 'resources'
|
2022-11-25 12:23:46 +00:00
|
|
|
[[nodiscard]] virtual inline QString resourceString() const { return tr("resource"); }
|
|
|
|
|
|
|
|
/* Features this resource's page supports */
|
|
|
|
[[nodiscard]] virtual bool supportsFiltering() const = 0;
|
|
|
|
|
|
|
|
void retranslate() override;
|
|
|
|
void openedImpl() override;
|
|
|
|
auto eventFilter(QObject* watched, QEvent* event) -> bool override;
|
|
|
|
|
|
|
|
/** Get the current term in the search bar. */
|
|
|
|
[[nodiscard]] auto getSearchTerm() const -> QString;
|
|
|
|
/** Programatically set the term in the search bar. */
|
|
|
|
void setSearchTerm(QString);
|
|
|
|
|
2022-12-18 18:41:46 +00:00
|
|
|
[[nodiscard]] bool setCurrentPack(ModPlatform::IndexedPack);
|
2022-11-25 12:23:46 +00:00
|
|
|
[[nodiscard]] auto getCurrentPack() const -> ModPlatform::IndexedPack;
|
|
|
|
[[nodiscard]] auto getDialog() const -> const ResourceDownloadDialog* { return m_parent_dialog; }
|
2022-12-18 18:41:46 +00:00
|
|
|
[[nodiscard]] auto getModel() const -> ResourceModel* { return m_model; }
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
protected:
|
|
|
|
ResourcePage(ResourceDownloadDialog* parent, BaseInstance&);
|
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
void addSortings();
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
public slots:
|
|
|
|
virtual void updateUi();
|
|
|
|
virtual void updateSelectionButton();
|
|
|
|
virtual void updateVersionList();
|
|
|
|
|
2023-05-02 22:49:54 +01:00
|
|
|
void addResourceToDialog(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
2023-05-28 14:57:35 +01:00
|
|
|
void removeResourceFromDialog(ModPlatform::IndexedPack& pack);
|
2023-05-02 22:49:54 +01:00
|
|
|
virtual void removeResourceFromPage(const QString& name);
|
|
|
|
virtual void addResourceToPage(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&, const std::shared_ptr<ResourceFolderModel>);
|
|
|
|
|
|
|
|
QList<DownloadTaskPtr> selectedPacks() { return m_model->selectedPacks(); }
|
|
|
|
bool hasSelectedPacks() { return !(m_model->selectedPacks().isEmpty()); }
|
2022-11-25 12:23:46 +00:00
|
|
|
|
|
|
|
protected slots:
|
|
|
|
virtual void triggerSearch() {}
|
2023-04-21 22:47:51 +01:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
|
|
|
void onVersionSelectionChanged(QString data);
|
|
|
|
void onResourceSelected();
|
|
|
|
|
2022-12-18 20:03:39 +00:00
|
|
|
// NOTE: Can't use [[nodiscard]] here because of https://bugreports.qt.io/browse/QTBUG-58628 on Qt 5.12
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
/** Associates regex expressions to pages in the order they're given in the map. */
|
2022-12-18 20:03:39 +00:00
|
|
|
virtual QMap<QString, QString> urlHandlers() const = 0;
|
2022-11-25 12:23:46 +00:00
|
|
|
virtual void openUrl(const QUrl&);
|
|
|
|
|
|
|
|
/** Whether the version is opted out or not. Currently only makes sense in CF. */
|
|
|
|
virtual bool optedOut(ModPlatform::IndexedVersion& ver) const { return false; };
|
|
|
|
|
|
|
|
public:
|
|
|
|
BaseInstance& m_base_instance;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Ui::ResourcePage* m_ui;
|
|
|
|
|
|
|
|
ResourceDownloadDialog* m_parent_dialog = nullptr;
|
|
|
|
ResourceModel* m_model = nullptr;
|
|
|
|
|
|
|
|
int m_selected_version_index = -1;
|
|
|
|
|
|
|
|
ProgressWidget m_fetch_progress;
|
|
|
|
|
|
|
|
// Used to do instant searching with a delay to cache quick changes
|
|
|
|
QTimer m_search_timer;
|
|
|
|
};
|
2022-12-16 22:03:52 +00:00
|
|
|
|
|
|
|
} // namespace ResourceDownload
|