summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-04-10 17:01:24 +0200
committerPetr Mrázek <peterix@gmail.com>2016-05-01 00:00:24 +0200
commit1be7d573326570d63e55e36235537ed2b1831ae1 (patch)
treeba7037671cde8688e87e69acb753df80ec4cd4f9 /api
parentaa4842a91d35481264ae5a7c0ac17ea43610b600 (diff)
downloadMultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.gz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.lz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.tar.xz
MultiMC-1be7d573326570d63e55e36235537ed2b1831ae1.zip
NOISSUE re/move some dead code and unused build system parts
Diffstat (limited to 'api')
-rw-r--r--api/dead/README.md3
-rw-r--r--api/dead/src/AbstractCommonModel.cpp (renamed from api/logic/AbstractCommonModel.cpp)0
-rw-r--r--api/dead/src/AbstractCommonModel.h (renamed from api/logic/AbstractCommonModel.h)0
-rw-r--r--api/dead/src/BaseConfigObject.cpp (renamed from api/logic/BaseConfigObject.cpp)0
-rw-r--r--api/dead/src/BaseConfigObject.h (renamed from api/logic/BaseConfigObject.h)0
-rw-r--r--api/dead/src/TypeMagic.h (renamed from api/logic/TypeMagic.h)0
-rw-r--r--api/dead/src/handlers/IconResourceHandler.cpp37
-rw-r--r--api/dead/src/handlers/IconResourceHandler.h23
-rw-r--r--api/dead/src/handlers/WebResourceHandler.cpp68
-rw-r--r--api/dead/src/handlers/WebResourceHandler.h23
-rw-r--r--api/dead/src/resources/Resource.cpp (renamed from api/logic/resources/Resource.cpp)0
-rw-r--r--api/dead/src/resources/Resource.h (renamed from api/logic/resources/Resource.h)0
-rw-r--r--api/dead/src/resources/ResourceHandler.cpp (renamed from api/logic/resources/ResourceHandler.cpp)0
-rw-r--r--api/dead/src/resources/ResourceHandler.h (renamed from api/logic/resources/ResourceHandler.h)0
-rw-r--r--api/dead/src/resources/ResourceObserver.cpp (renamed from api/logic/resources/ResourceObserver.cpp)0
-rw-r--r--api/dead/src/resources/ResourceObserver.h (renamed from api/logic/resources/ResourceObserver.h)0
-rw-r--r--api/dead/src/resources/ResourceProxyModel.cpp (renamed from api/logic/resources/ResourceProxyModel.cpp)0
-rw-r--r--api/dead/src/resources/ResourceProxyModel.h (renamed from api/logic/resources/ResourceProxyModel.h)0
-rw-r--r--api/dead/test/tst_Resource.cpp116
-rw-r--r--api/logic/CMakeLists.txt15
20 files changed, 270 insertions, 15 deletions
diff --git a/api/dead/README.md b/api/dead/README.md
new file mode 100644
index 00000000..520b18d3
--- /dev/null
+++ b/api/dead/README.md
@@ -0,0 +1,3 @@
+This stuff is dead code I collected from the repository that still looks like it might be useful for something.
+
+Moved on 10. April 2016 - if it hasn't been moved or used in a while, delete this.
diff --git a/api/logic/AbstractCommonModel.cpp b/api/dead/src/AbstractCommonModel.cpp
index 71d75829..71d75829 100644
--- a/api/logic/AbstractCommonModel.cpp
+++ b/api/dead/src/AbstractCommonModel.cpp
diff --git a/api/logic/AbstractCommonModel.h b/api/dead/src/AbstractCommonModel.h
index 31b86a23..31b86a23 100644
--- a/api/logic/AbstractCommonModel.h
+++ b/api/dead/src/AbstractCommonModel.h
diff --git a/api/logic/BaseConfigObject.cpp b/api/dead/src/BaseConfigObject.cpp
index 3040ac2e..3040ac2e 100644
--- a/api/logic/BaseConfigObject.cpp
+++ b/api/dead/src/BaseConfigObject.cpp
diff --git a/api/logic/BaseConfigObject.h b/api/dead/src/BaseConfigObject.h
index 1c96b3d1..1c96b3d1 100644
--- a/api/logic/BaseConfigObject.h
+++ b/api/dead/src/BaseConfigObject.h
diff --git a/api/logic/TypeMagic.h b/api/dead/src/TypeMagic.h
index fa9d12a9..fa9d12a9 100644
--- a/api/logic/TypeMagic.h
+++ b/api/dead/src/TypeMagic.h
diff --git a/api/dead/src/handlers/IconResourceHandler.cpp b/api/dead/src/handlers/IconResourceHandler.cpp
new file mode 100644
index 00000000..b03553fd
--- /dev/null
+++ b/api/dead/src/handlers/IconResourceHandler.cpp
@@ -0,0 +1,37 @@
+#include "IconResourceHandler.h"
+#include <xdgicon.h>
+
+#include <QDir>
+#include <QDebug>
+
+QList<std::weak_ptr<IconResourceHandler>> IconResourceHandler::m_iconHandlers;
+
+IconResourceHandler::IconResourceHandler(const QString &key)
+ : m_key(key)
+{
+}
+
+void IconResourceHandler::setTheme(const QString &theme)
+{
+ // notify everyone
+ for (auto handler : m_iconHandlers)
+ {
+ std::shared_ptr<IconResourceHandler> ptr = handler.lock();
+ if (ptr)
+ {
+ ptr->setResult(ptr->get());
+ }
+ }
+}
+
+void IconResourceHandler::init(std::shared_ptr<ResourceHandler> &ptr)
+{
+ m_iconHandlers.append(std::dynamic_pointer_cast<IconResourceHandler>(ptr));
+ // we always have a result, so lets report it now!
+ setResult(get());
+}
+
+QVariant IconResourceHandler::get() const
+{
+ return XdgIcon::fromTheme(m_key);
+}
diff --git a/api/dead/src/handlers/IconResourceHandler.h b/api/dead/src/handlers/IconResourceHandler.h
new file mode 100644
index 00000000..0cc4de4f
--- /dev/null
+++ b/api/dead/src/handlers/IconResourceHandler.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <memory>
+#include <resources/ResourceHandler.h>
+
+class IconResourceHandler : public ResourceHandler
+{
+public:
+ explicit IconResourceHandler(const QString &key);
+
+ /// Sets the current theme and notifies all IconResourceHandlers of the change
+ static void setTheme(const QString &theme);
+
+private:
+ // we need to keep track of all IconResourceHandlers so that we can update them if the theme changes
+ void init(std::shared_ptr<ResourceHandler> &ptr) override;
+ static QList<std::weak_ptr<IconResourceHandler>> m_iconHandlers;
+
+ QString m_key;
+
+ // the workhorse, returns QVariantMap (filename => size) for m_key/m_theme
+ QVariant get() const;
+};
diff --git a/api/dead/src/handlers/WebResourceHandler.cpp b/api/dead/src/handlers/WebResourceHandler.cpp
new file mode 100644
index 00000000..757b870a
--- /dev/null
+++ b/api/dead/src/handlers/WebResourceHandler.cpp
@@ -0,0 +1,68 @@
+#include "WebResourceHandler.h"
+
+#include "net/CacheDownload.h"
+#include "net/HttpMetaCache.h"
+#include "net/NetJob.h"
+#include "FileSystem.h"
+#include "Env.h"
+
+//FIXME: wrong. needs to be done elsewhere.
+QMap<QString, NetJob *> WebResourceHandler::m_activeDownloads;
+
+WebResourceHandler::WebResourceHandler(const QString &url)
+ : QObject(), m_url(url)
+{
+ MetaEntryPtr entry = ENV.metacache()->resolveEntry("icons", url);
+ if (!entry->isStale())
+ {
+ setResultFromFile(entry->getFullPath());
+ }
+ else if (m_activeDownloads.contains(url))
+ {
+ NetJob *job = m_activeDownloads.value(url);
+ connect(job, &NetJob::succeeded, this, &WebResourceHandler::succeeded);
+ connect(job, &NetJob::failed, this, [job, this]() {setFailure(job->failReason());});
+ connect(job, &NetJob::progress, this, &WebResourceHandler::progress);
+ }
+ else
+ {
+ NetJob *job = new NetJob("Icon download");
+ job->addNetAction(CacheDownload::make(QUrl(url), entry));
+ connect(job, &NetJob::succeeded, this, &WebResourceHandler::succeeded);
+ connect(job, &NetJob::failed, this, [job, this]() {setFailure(job->failReason());});
+ connect(job, &NetJob::progress, this, &WebResourceHandler::progress);
+ connect(job, &NetJob::finished, job, [job](){m_activeDownloads.remove(m_activeDownloads.key(job));job->deleteLater();});
+ m_activeDownloads.insert(url, job);
+ job->start();
+ }
+}
+
+void WebResourceHandler::succeeded()
+{
+ MetaEntryPtr entry = ENV.metacache()->resolveEntry("icons", m_url);
+ setResultFromFile(entry->getFullPath());
+ m_activeDownloads.remove(m_activeDownloads.key(qobject_cast<NetJob *>(sender())));
+}
+void WebResourceHandler::progress(qint64 current, qint64 total)
+{
+ if (total == 0)
+ {
+ setProgress(101);
+ }
+ else
+ {
+ setProgress(current / total);
+ }
+}
+
+void WebResourceHandler::setResultFromFile(const QString &file)
+{
+ try
+ {
+ setResult(FS::read(file));
+ }
+ catch (Exception &e)
+ {
+ setFailure(e.cause());
+ }
+}
diff --git a/api/dead/src/handlers/WebResourceHandler.h b/api/dead/src/handlers/WebResourceHandler.h
new file mode 100644
index 00000000..54bef6a1
--- /dev/null
+++ b/api/dead/src/handlers/WebResourceHandler.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <QObject>
+#include <resources/ResourceHandler.h>
+
+class NetJob;
+
+class WebResourceHandler : public QObject, public ResourceHandler
+{
+public:
+ explicit WebResourceHandler(const QString &url);
+
+private slots:
+ void succeeded();
+ void progress(qint64 current, qint64 total);
+
+private:
+ static QMap<QString, NetJob *> m_activeDownloads;
+
+ QString m_url;
+
+ void setResultFromFile(const QString &file);
+};
diff --git a/api/logic/resources/Resource.cpp b/api/dead/src/resources/Resource.cpp
index e95675d7..e95675d7 100644
--- a/api/logic/resources/Resource.cpp
+++ b/api/dead/src/resources/Resource.cpp
diff --git a/api/logic/resources/Resource.h b/api/dead/src/resources/Resource.h
index 63e97b88..63e97b88 100644
--- a/api/logic/resources/Resource.h
+++ b/api/dead/src/resources/Resource.h
diff --git a/api/logic/resources/ResourceHandler.cpp b/api/dead/src/resources/ResourceHandler.cpp
index 46a4422c..46a4422c 100644
--- a/api/logic/resources/ResourceHandler.cpp
+++ b/api/dead/src/resources/ResourceHandler.cpp
diff --git a/api/logic/resources/ResourceHandler.h b/api/dead/src/resources/ResourceHandler.h
index f09d8904..f09d8904 100644
--- a/api/logic/resources/ResourceHandler.h
+++ b/api/dead/src/resources/ResourceHandler.h
diff --git a/api/logic/resources/ResourceObserver.cpp b/api/dead/src/resources/ResourceObserver.cpp
index 4f168fd2..4f168fd2 100644
--- a/api/logic/resources/ResourceObserver.cpp
+++ b/api/dead/src/resources/ResourceObserver.cpp
diff --git a/api/logic/resources/ResourceObserver.h b/api/dead/src/resources/ResourceObserver.h
index c42e41ba..c42e41ba 100644
--- a/api/logic/resources/ResourceObserver.h
+++ b/api/dead/src/resources/ResourceObserver.h
diff --git a/api/logic/resources/ResourceProxyModel.cpp b/api/dead/src/resources/ResourceProxyModel.cpp
index f026d9a9..f026d9a9 100644
--- a/api/logic/resources/ResourceProxyModel.cpp
+++ b/api/dead/src/resources/ResourceProxyModel.cpp
diff --git a/api/logic/resources/ResourceProxyModel.h b/api/dead/src/resources/ResourceProxyModel.h
index 98a3dbd1..98a3dbd1 100644
--- a/api/logic/resources/ResourceProxyModel.h
+++ b/api/dead/src/resources/ResourceProxyModel.h
diff --git a/api/dead/test/tst_Resource.cpp b/api/dead/test/tst_Resource.cpp
new file mode 100644
index 00000000..4bf41a03
--- /dev/null
+++ b/api/dead/test/tst_Resource.cpp
@@ -0,0 +1,116 @@
+#include <QTest>
+#include "TestUtil.h"
+
+#include "resources/Resource.h"
+#include "resources/ResourceHandler.h"
+#include "resources/ResourceObserver.h"
+
+class DummyStringResourceHandler : public ResourceHandler
+{
+public:
+ explicit DummyStringResourceHandler(const QString &key)
+ : m_key(key) {}
+
+ void init(std::shared_ptr<ResourceHandler> &) override
+ {
+ setResult(m_key);
+ }
+
+ QString m_key;
+};
+class DummyObserver : public ResourceObserver
+{
+public:
+ void resourceUpdated() override
+ {
+ values += get<QString>();
+ }
+
+ QStringList values;
+};
+class DummyObserverObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString property MEMBER property)
+
+public:
+ explicit DummyObserverObject(QObject *parent = nullptr) : QObject(parent) {}
+
+ QString property;
+};
+
+class ResourceTest : public QObject
+{
+ Q_OBJECT
+ private
+ slots:
+ void initTestCase()
+ {
+ Resource::registerHandler<DummyStringResourceHandler>("dummy");
+ }
+ void cleanupTestCase()
+ {
+ }
+
+ void test_Then()
+ {
+ QString val;
+ Resource::create("dummy:test_Then")
+ ->then([&val](const QString &key) { val = key; });
+ QCOMPARE(val, QStringLiteral("test_Then"));
+ }
+ void test_Object()
+ {
+ DummyObserver *observer = new DummyObserver;
+ Resource::create("dummy:test_Object")->applyTo(observer);
+ QCOMPARE(observer->values, QStringList() << "test_Object");
+ }
+ void test_QObjectProperty()
+ {
+ DummyObserverObject *object = new DummyObserverObject;
+ Resource::create("dummy:test_QObjectProperty")->applyTo(object);
+ QCOMPARE(object->property, QStringLiteral("test_QObjectProperty"));
+ }
+
+ void test_DontRequestPlaceholder()
+ {
+ // since dummy:asdf immediently gives a value we should not get the placeholder
+ Resource::create("dummy:asdf", Resource::create("dummy:fdsa"))
+ ->then([](const QString &key) { QCOMPARE(key, QStringLiteral("asdf")); });
+ }
+
+ void test_MergedResources()
+ {
+ auto r1 = Resource::create("dummy:asdf");
+ auto r2 = Resource::create("dummy:asdf");
+ auto r3 = Resource::create("dummy:fdsa");
+ auto r4 = Resource::create("dummy:asdf");
+
+ QCOMPARE(r1, r2);
+ QCOMPARE(r1, r4);
+ QVERIFY(r1 != r3);
+ QVERIFY(r2 != r3);
+ QVERIFY(r4 != r3);
+ }
+
+ void test_MergedResourceWithPlaceholder()
+ {
+ auto p1 = Resource::create("dummy:placeA");
+ auto p2 = Resource::create("dummy:placeB");
+
+ auto r1 = Resource::create("dummy:asdf");
+ auto r2 = Resource::create("dummy:asdf", p1);
+ auto r3 = Resource::create("dummy:asdf", p2);
+ auto r4 = Resource::create("dummy:asdf", p1);
+
+ QCOMPARE(r2, r4);
+ QVERIFY(r1 != r2);
+ QVERIFY(r1 != r3);
+ QVERIFY(r1 != r4);
+ QVERIFY(r2 != r3);
+ }
+};
+
+QTEST_GUILESS_MAIN(ResourceTest)
+
+#include "tst_Resource.moc"
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index 317627d5..a7013c9d 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -16,11 +16,6 @@ set(LOGIC_SOURCES
MMCZip.cpp
MMCStrings.h
MMCStrings.cpp
- BaseConfigObject.h
- BaseConfigObject.cpp
- AbstractCommonModel.h
- AbstractCommonModel.cpp
- TypeMagic.h
# Prefix tree where node names are strings between separators
SeparatorPrefixTree.h
@@ -47,16 +42,6 @@ set(LOGIC_SOURCES
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
QObjectPtr.h
- # Resources
- resources/Resource.cpp
- resources/Resource.h
- resources/ResourceHandler.cpp
- resources/ResourceHandler.h
- resources/ResourceObserver.cpp
- resources/ResourceObserver.h
- resources/ResourceProxyModel.h
- resources/ResourceProxyModel.cpp
-
# Path matchers
pathmatcher/FSTreeMatcher.h
pathmatcher/IPathMatcher.h