refactor(RD): move success callbacks from ModModel to ResourceModel
While implementing the resource pack downloader in another branch, I noticed that most of the code in the success callback was identical in both cases, safe for a few minute differences in strings. So, this tries to make it easier to share this piece of code. However, it still leaves the possibility of extending the methods in ResourceModel to accomodate for cases where this similarity may not hold. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
@ -57,13 +57,13 @@ class ResourceModel : public QAbstractListModel {
|
||||
void setSearchTerm(QString term) { m_search_term = term; }
|
||||
|
||||
virtual ResourceAPI::SearchArgs createSearchArguments() = 0;
|
||||
virtual ResourceAPI::SearchCallbacks createSearchCallbacks() = 0;
|
||||
virtual ResourceAPI::SearchCallbacks createSearchCallbacks() { return {}; }
|
||||
|
||||
virtual ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) = 0;
|
||||
virtual ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(QModelIndex&) = 0;
|
||||
virtual ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(QModelIndex&) { return {}; }
|
||||
|
||||
virtual ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) = 0;
|
||||
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(QModelIndex&) = 0;
|
||||
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(QModelIndex&) { return {}; }
|
||||
|
||||
/** Requests the API for more entries. */
|
||||
virtual void search();
|
||||
@ -86,6 +86,22 @@ class ResourceModel : public QAbstractListModel {
|
||||
|
||||
[[nodiscard]] auto getCurrentSortingMethodByIndex() const -> std::optional<ResourceAPI::SortingMethod>;
|
||||
|
||||
/** Converts a JSON document to a common array format.
|
||||
*
|
||||
* This is needed so that different providers, with different JSON structures, can be parsed
|
||||
* uniformally. You NEED to re-implement this if you intend on using the default callbacks.
|
||||
*/
|
||||
[[nodiscard]] virtual auto documentToArray(QJsonDocument&) const -> QJsonArray;
|
||||
|
||||
/** Functions to load data into a pack.
|
||||
*
|
||||
* Those are needed for the same reason as ddocumentToArray, and NEED to be re-implemented in the same way.
|
||||
*/
|
||||
|
||||
virtual void loadIndexedPack(ModPlatform::IndexedPack&, QJsonObject&);
|
||||
virtual void loadExtraPackInfo(ModPlatform::IndexedPack&, QJsonObject&);
|
||||
virtual void loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArray&);
|
||||
|
||||
protected:
|
||||
const BaseInstance& m_base_instance;
|
||||
|
||||
@ -114,9 +130,14 @@ class ResourceModel : public QAbstractListModel {
|
||||
|
||||
private:
|
||||
/* Default search request callbacks */
|
||||
void searchRequestSucceeded(QJsonDocument&);
|
||||
void searchRequestFailed(QString reason, int network_error_code);
|
||||
void searchRequestAborted();
|
||||
|
||||
void versionRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
|
||||
|
||||
void infoRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
|
||||
|
||||
signals:
|
||||
void versionListUpdated();
|
||||
void projectInfoUpdated();
|
||||
|
Reference in New Issue
Block a user