From 47e37635f50c09b4f9a9ee7699e3120bab3e4088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 10 Apr 2016 04:29:29 +0200 Subject: NOISSUE split GUI stuff from logic library --- libraries/logic/resources/ResourceHandler.h | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 libraries/logic/resources/ResourceHandler.h (limited to 'libraries/logic/resources/ResourceHandler.h') diff --git a/libraries/logic/resources/ResourceHandler.h b/libraries/logic/resources/ResourceHandler.h new file mode 100644 index 00000000..f09d8904 --- /dev/null +++ b/libraries/logic/resources/ResourceHandler.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +#include "multimc_logic_export.h" + +class Resource; + +/** Base class for things that can retrieve a resource. + * + * Subclass, provide a constructor that takes a single QString as argument, and + * call Resource::registerHandler(""), where is the + * prefix of the resource ("web", "icon", etc.) + */ +class MULTIMC_LOGIC_EXPORT ResourceHandler +{ +public: + virtual ~ResourceHandler() {} + + void setResource(Resource *resource) { m_resource = resource; } + /// reimplement this if you need to do something after you have been put in a shared pointer + // we do this instead of inheriting from std::enable_shared_from_this + virtual void init(std::shared_ptr&) {} + + QVariant result() const { return m_result; } + +protected: // use these methods to notify the resource of changes + void setResult(const QVariant &result); + void setFailure(const QString &reason); + void setProgress(const int progress); + +private: + QVariant m_result; + Resource *m_resource = nullptr; +}; -- cgit v1.2.3