From e46aba9da584338db8d8a1a8a487bdcc6cf84343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 18 Mar 2017 02:22:36 +0100 Subject: NOISSUE sanitize loading and downloading of metadata files --- api/logic/meta/BaseEntity.h | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'api/logic/meta/BaseEntity.h') diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h index 7064e9d2..92a39272 100644 --- a/api/logic/meta/BaseEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -15,9 +15,9 @@ #pragma once -#include -#include #include +#include +#include "QObjectPtr.h" #include "multimc_logic_export.h" @@ -26,29 +26,48 @@ namespace Meta { class MULTIMC_LOGIC_EXPORT BaseEntity { +public: /* types */ + using Ptr = std::shared_ptr; + enum class LoadStatus + { + NotLoaded, + Local, + Remote + }; + enum class UpdateStatus + { + NotDone, + InProgress, + Failed, + Succeeded + }; + public: virtual ~BaseEntity(); - using Ptr = std::shared_ptr; - - virtual std::unique_ptr remoteUpdateTask() = 0; - virtual std::unique_ptr localUpdateTask() = 0; virtual void merge(const std::shared_ptr &other) = 0; virtual void parse(const QJsonObject &obj) = 0; virtual QString localFilename() const = 0; virtual QUrl url() const; - bool isComplete() const { return m_localLoaded || m_remoteLoaded; } + bool isLoaded() const + { + return m_loadStatus > LoadStatus::NotLoaded; + } + bool shouldStartRemoteUpdate() const + { + return m_updateStatus == UpdateStatus::NotDone; + } - bool isLocalLoaded() const { return m_localLoaded; } - bool isRemoteLoaded() const { return m_remoteLoaded; } + void load(); - void notifyLocalLoadComplete(); - void notifyRemoteLoadComplete(); +protected: /* methods */ + bool loadLocalFile(); private: - bool m_localLoaded = false; - bool m_remoteLoaded = false; + LoadStatus m_loadStatus = LoadStatus::NotLoaded; + UpdateStatus m_updateStatus = UpdateStatus::NotDone; + shared_qobject_ptr m_updateTask; }; } -- cgit v1.2.3