summaryrefslogtreecommitdiffstats
path: root/api/logic/resources/ResourceHandler.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-10 15:53:05 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-01 00:00:14 +0200
commitb6d455a02bd338e9dc0faa09d4d8177ecd8d569a (patch)
tree41982bca1ede50049f2f8c7109dd18edeefde6d0 /api/logic/resources/ResourceHandler.h
parent47e37635f50c09b4f9a9ee7699e3120bab3e4088 (diff)
downloadMultiMC-b6d455a02bd338e9dc0faa09d4d8177ecd8d569a.tar
MultiMC-b6d455a02bd338e9dc0faa09d4d8177ecd8d569a.tar.gz
MultiMC-b6d455a02bd338e9dc0faa09d4d8177ecd8d569a.tar.lz
MultiMC-b6d455a02bd338e9dc0faa09d4d8177ecd8d569a.tar.xz
MultiMC-b6d455a02bd338e9dc0faa09d4d8177ecd8d569a.zip
NOISSUE reorganize and document libraries
Diffstat (limited to 'api/logic/resources/ResourceHandler.h')
-rw-r--r--api/logic/resources/ResourceHandler.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/api/logic/resources/ResourceHandler.h b/api/logic/resources/ResourceHandler.h
new file mode 100644
index 00000000..f09d8904
--- /dev/null
+++ b/api/logic/resources/ResourceHandler.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <QVariant>
+#include <memory>
+
+#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<MyResourceHandler>("<id>"), where <id> 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<ResourceHandler>&) {}
+
+ 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;
+};