summaryrefslogtreecommitdiffstats
path: root/logic/resources/Resource.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-26 13:45:29 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-26 13:45:29 +0200
commit271ad9e4fdb4f003abd33b59ca9cadfb5bab9823 (patch)
treef006b597a61531345b810fb5ea28f45c850fd8a4 /logic/resources/Resource.cpp
parentcca670013463f0062cec950d9b9bb76f9150ed93 (diff)
downloadMultiMC-271ad9e4fdb4f003abd33b59ca9cadfb5bab9823.tar
MultiMC-271ad9e4fdb4f003abd33b59ca9cadfb5bab9823.tar.gz
MultiMC-271ad9e4fdb4f003abd33b59ca9cadfb5bab9823.tar.lz
MultiMC-271ad9e4fdb4f003abd33b59ca9cadfb5bab9823.tar.xz
MultiMC-271ad9e4fdb4f003abd33b59ca9cadfb5bab9823.zip
GH-1072 split resource system to UI and logic parts
Diffstat (limited to 'logic/resources/Resource.cpp')
-rw-r--r--logic/resources/Resource.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/logic/resources/Resource.cpp b/logic/resources/Resource.cpp
index 3cc6b648..e95675d7 100644
--- a/logic/resources/Resource.cpp
+++ b/logic/resources/Resource.cpp
@@ -2,38 +2,45 @@
#include <QDebug>
-#include "WebResourceHandler.h"
-#include "IconResourceHandler.h"
#include "ResourceObserver.h"
+#include "ResourceHandler.h"
// definition of static members of Resource
QMap<QString, std::function<std::shared_ptr<ResourceHandler>(const QString &)>> Resource::m_handlers;
QMap<QPair<int, int>, std::function<QVariant(QVariant)>> Resource::m_transfomers;
QMap<QString, std::weak_ptr<Resource>> Resource::m_resources;
+struct NullResourceResult {};
+Q_DECLARE_METATYPE(NullResourceResult)
+class NullResourceHandler : public ResourceHandler
+{
+public:
+ explicit NullResourceHandler()
+ {
+ setResult(QVariant::fromValue<NullResourceResult>(NullResourceResult()));
+ }
+};
+
Resource::Resource(const QString &resource)
: m_resource(resource)
{
- // register default handlers
- // QUESTION: move elsewhere?
- if (!m_handlers.contains("web"))
+ if (!resource.isEmpty())
{
- registerHandler<WebResourceHandler>("web");
+ // a valid resource identifier has the format <id>:<data>
+ Q_ASSERT(resource.contains(':'));
+ // "parse" the resource identifier into id and data
+ const QString resourceId = resource.left(resource.indexOf(':'));
+ const QString resourceData = resource.mid(resource.indexOf(':') + 1);
+
+ // create and set up the handler
+ Q_ASSERT(m_handlers.contains(resourceId));
+ m_handler = m_handlers.value(resourceId)(resourceData);
}
- if (!m_handlers.contains("icon"))
+ else
{
- registerHandler<IconResourceHandler>("icon");
+ m_handler = std::make_shared<NullResourceHandler>();
}
- // a valid resource identifier has the format <id>:<data>
- Q_ASSERT(resource.contains(':'));
- // "parse" the resource identifier into id and data
- const QString resourceId = resource.left(resource.indexOf(':'));
- const QString resourceData = resource.mid(resource.indexOf(':') + 1);
-
- // create and set up the handler
- Q_ASSERT(m_handlers.contains(resourceId));
- m_handler = m_handlers.value(resourceId)(resourceData);
Q_ASSERT(m_handler);
m_handler->init(m_handler);
m_handler->setResource(this);