aboutsummaryrefslogtreecommitdiff
path: root/api/logic
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/logic
parentaa4842a91d35481264ae5a7c0ac17ea43610b600 (diff)
downloadPrismLauncher-1be7d573326570d63e55e36235537ed2b1831ae1.tar.gz
PrismLauncher-1be7d573326570d63e55e36235537ed2b1831ae1.tar.bz2
PrismLauncher-1be7d573326570d63e55e36235537ed2b1831ae1.zip
NOISSUE re/move some dead code and unused build system parts
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/AbstractCommonModel.cpp133
-rw-r--r--api/logic/AbstractCommonModel.h462
-rw-r--r--api/logic/BaseConfigObject.cpp103
-rw-r--r--api/logic/BaseConfigObject.h50
-rw-r--r--api/logic/CMakeLists.txt15
-rw-r--r--api/logic/TypeMagic.h37
-rw-r--r--api/logic/resources/Resource.cpp155
-rw-r--r--api/logic/resources/Resource.h132
-rw-r--r--api/logic/resources/ResourceHandler.cpp28
-rw-r--r--api/logic/resources/ResourceHandler.h36
-rw-r--r--api/logic/resources/ResourceObserver.cpp55
-rw-r--r--api/logic/resources/ResourceObserver.h73
-rw-r--r--api/logic/resources/ResourceProxyModel.cpp89
-rw-r--r--api/logic/resources/ResourceProxyModel.h39
14 files changed, 0 insertions, 1407 deletions
diff --git a/api/logic/AbstractCommonModel.cpp b/api/logic/AbstractCommonModel.cpp
deleted file mode 100644
index 71d75829..00000000
--- a/api/logic/AbstractCommonModel.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Copyright 2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "AbstractCommonModel.h"
-
-BaseAbstractCommonModel::BaseAbstractCommonModel(const Qt::Orientation orientation, QObject *parent)
- : QAbstractListModel(parent), m_orientation(orientation)
-{
-}
-
-int BaseAbstractCommonModel::rowCount(const QModelIndex &parent) const
-{
- return m_orientation == Qt::Horizontal ? entryCount() : size();
-}
-int BaseAbstractCommonModel::columnCount(const QModelIndex &parent) const
-{
- return m_orientation == Qt::Horizontal ? size() : entryCount();
-}
-QVariant BaseAbstractCommonModel::data(const QModelIndex &index, int role) const
-{
- if (!hasIndex(index.row(), index.column(), index.parent()))
- {
- return QVariant();
- }
- const int i = m_orientation == Qt::Horizontal ? index.column() : index.row();
- const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column();
- return formatData(i, role, get(i, entry, role));
-}
-QVariant BaseAbstractCommonModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (orientation != m_orientation && role == Qt::DisplayRole)
- {
- return entryTitle(section);
- }
- else
- {
- return QVariant();
- }
-}
-bool BaseAbstractCommonModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- const int i = m_orientation == Qt::Horizontal ? index.column() : index.row();
- const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column();
- const bool result = set(i, entry, role, sanetizeData(i, role, value));
- if (result)
- {
- emit dataChanged(index, index, QVector<int>() << role);
- }
- return result;
-}
-Qt::ItemFlags BaseAbstractCommonModel::flags(const QModelIndex &index) const
-{
- if (!hasIndex(index.row(), index.column(), index.parent()))
- {
- return Qt::NoItemFlags;
- }
-
- const int entry = m_orientation == Qt::Horizontal ? index.row() : index.column();
- if (canSet(entry))
- {
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
- }
- else
- {
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
- }
-}
-
-void BaseAbstractCommonModel::notifyAboutToAddObject(const int at)
-{
- if (m_orientation == Qt::Horizontal)
- {
- beginInsertColumns(QModelIndex(), at, at);
- }
- else
- {
- beginInsertRows(QModelIndex(), at, at);
- }
-}
-void BaseAbstractCommonModel::notifyObjectAdded()
-{
- if (m_orientation == Qt::Horizontal)
- {
- endInsertColumns();
- }
- else
- {
- endInsertRows();
- }
-}
-void BaseAbstractCommonModel::notifyAboutToRemoveObject(const int at)
-{
- if (m_orientation == Qt::Horizontal)
- {
- beginRemoveColumns(QModelIndex(), at, at);
- }
- else
- {
- beginRemoveRows(QModelIndex(), at, at);
- }
-}
-void BaseAbstractCommonModel::notifyObjectRemoved()
-{
- if (m_orientation == Qt::Horizontal)
- {
- endRemoveColumns();
- }
- else
- {
- endRemoveRows();
- }
-}
-
-void BaseAbstractCommonModel::notifyBeginReset()
-{
- beginResetModel();
-}
-void BaseAbstractCommonModel::notifyEndReset()
-{
- endResetModel();
-}
diff --git a/api/logic/AbstractCommonModel.h b/api/logic/AbstractCommonModel.h
deleted file mode 100644
index 31b86a23..00000000
--- a/api/logic/AbstractCommonModel.h
+++ /dev/null
@@ -1,462 +0,0 @@
-/* Copyright 2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <QAbstractListModel>
-#include <type_traits>
-#include <functional>
-#include <memory>
-
-class BaseAbstractCommonModel : public QAbstractListModel
-{
- Q_OBJECT
-public:
- explicit BaseAbstractCommonModel(const Qt::Orientation orientation, QObject *parent = nullptr);
-
- // begin QAbstractItemModel interface
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
- QVariant data(const QModelIndex &index, int role) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
- bool setData(const QModelIndex &index, const QVariant &value, int role) override;
- Qt::ItemFlags flags(const QModelIndex &index) const override;
- // end QAbstractItemModel interface
-
- virtual int size() const = 0;
- virtual int entryCount() const = 0;
-
- virtual QVariant formatData(const int index, int role, const QVariant &data) const { return data; }
- virtual QVariant sanetizeData(const int index, int role, const QVariant &data) const { return data; }
-
-protected:
- virtual QVariant get(const int index, const int entry, const int role) const = 0;
- virtual bool set(const int index, const int entry, const int role, const QVariant &value) = 0;
- virtual bool canSet(const int entry) const = 0;
- virtual QString entryTitle(const int entry) const = 0;
-
- void notifyAboutToAddObject(const int at);
- void notifyObjectAdded();
- void notifyAboutToRemoveObject(const int at);
- void notifyObjectRemoved();
- void notifyBeginReset();
- void notifyEndReset();
-
- const Qt::Orientation m_orientation;
-};
-
-template<typename Object>
-class AbstractCommonModel : public BaseAbstractCommonModel
-{
-public:
- explicit AbstractCommonModel(const Qt::Orientation orientation)
- : BaseAbstractCommonModel(orientation) {}
- virtual ~AbstractCommonModel() {}
-
- int size() const override { return m_objects.size(); }
- int entryCount() const override { return m_entries.size(); }
-
- void append(const Object &object)
- {
- notifyAboutToAddObject(size());
- m_objects.append(object);
- notifyObjectAdded();
- }
- void prepend(const Object &object)
- {
- notifyAboutToAddObject(0);
- m_objects.prepend(object);
- notifyObjectAdded();
- }
- void insert(const Object &object, const int index)
- {
- if (index >= size())
- {
- prepend(object);
- }
- else if (index <= 0)
- {
- append(object);
- }
- else
- {
- notifyAboutToAddObject(index);
- m_objects.insert(index, object);
- notifyObjectAdded();
- }
- }
- void remove(const int index)
- {
- notifyAboutToRemoveObject(index);
- m_objects.removeAt(index);
- notifyObjectRemoved();
- }
- Object get(const int index) const
- {
- return m_objects.at(index);
- }
-
-private:
- friend class CommonModel;
- QVariant get(const int index, const int entry, const int role) const override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(role))
- {
- return QVariant();
- }
- return m_entries[entry].second.value(role)->get(m_objects.at(index));
- }
- bool set(const int index, const int entry, const int role, const QVariant &value) override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(role))
- {
- return false;
- }
- IEntry *e = m_entries[entry].second.value(role);
- if (!e->canSet())
- {
- return false;
- }
- e->set(m_objects[index], value);
- return true;
- }
- bool canSet(const int entry) const override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(Qt::EditRole))
- {
- return false;
- }
- IEntry *e = m_entries[entry].second.value(Qt::EditRole);
- return e->canSet();
- }
-
- QString entryTitle(const int entry) const override
- {
- return m_entries.at(entry).first;
- }
-
-private:
- struct IEntry
- {
- virtual ~IEntry() {}
- virtual void set(Object &object, const QVariant &value) = 0;
- virtual QVariant get(const Object &object) const = 0;
- virtual bool canSet() const = 0;
- };
- template<typename T>
- struct VariableEntry : public IEntry
- {
- typedef T (Object::*Member);
-
- explicit VariableEntry(Member member)
- : m_member(member) {}
-
- void set(Object &object, const QVariant &value) override
- {
- object.*m_member = value.value<T>();
- }
- QVariant get(const Object &object) const override
- {
- return QVariant::fromValue<T>(object.*m_member);
- }
- bool canSet() const override { return true; }
-
- private:
- Member m_member;
- };
- template<typename T>
- struct FunctionEntry : public IEntry
- {
- typedef T (Object::*Getter)() const;
- typedef void (Object::*Setter)(T);
-
- explicit FunctionEntry(Getter getter, Setter setter)
- : m_getter(m_getter), m_setter(m_setter) {}
-
- void set(Object &object, const QVariant &value) override
- {
- object.*m_setter(value.value<T>());
- }
- QVariant get(const Object &object) const override
- {
- return QVariant::fromValue<T>(object.*m_getter());
- }
- bool canSet() const override { return !!m_setter; }
-
- private:
- Getter m_getter;
- Setter m_setter;
- };
-
- QList<Object> m_objects;
- QVector<QPair<QString, QMap<int, IEntry *>>> m_entries;
-
- void addEntryInternal(IEntry *e, const int entry, const int role)
- {
- if (m_entries.size() <= entry)
- {
- m_entries.resize(entry + 1);
- }
- m_entries[entry].second.insert(role, e);
- }
-
-protected:
- template<typename Getter, typename Setter>
- typename std::enable_if<std::is_member_function_pointer<Getter>::value && std::is_member_function_pointer<Getter>::value, void>::type
- addEntry(Getter getter, Setter setter, const int entry, const int role)
- {
- addEntryInternal(new FunctionEntry<typename std::result_of<Getter>::type>(getter, setter), entry, role);
- }
- template<typename Getter>
- typename std::enable_if<std::is_member_function_pointer<Getter>::value, void>::type
- addEntry(Getter getter, const int entry, const int role)
- {
- addEntryInternal(new FunctionEntry<typename std::result_of<Getter>::type>(getter, nullptr), entry, role);
- }
- template<typename T>
- typename std::enable_if<!std::is_member_function_pointer<T (Object::*)>::value, void>::type
- addEntry(T (Object::*member), const int entry, const int role)
- {
- addEntryInternal(new VariableEntry<T>(member), entry, role);
- }
-
- void setEntryTitle(const int entry, const QString &title)
- {
- m_entries[entry].first = title;
- }
-};
-template<typename Object>
-class AbstractCommonModel<Object *> : public BaseAbstractCommonModel
-{
-public:
- explicit AbstractCommonModel(const Qt::Orientation orientation)
- : BaseAbstractCommonModel(orientation) {}
- virtual ~AbstractCommonModel()
- {
- qDeleteAll(m_objects);
- }
-
- int size() const override { return m_objects.size(); }
- int entryCount() const override { return m_entries.size(); }
-
- void append(Object *object)
- {
- notifyAboutToAddObject(size());
- m_objects.append(object);
- notifyObjectAdded();
- }
- void prepend(Object *object)
- {
- notifyAboutToAddObject(0);
- m_objects.prepend(object);
- notifyObjectAdded();
- }
- void insert(Object *object, const int index)
- {
- if (index >= size())
- {
- prepend(object);
- }
- else if (index <= 0)
- {
- append(object);
- }
- else
- {
- notifyAboutToAddObject(index);
- m_objects.insert(index, object);
- notifyObjectAdded();
- }
- }
- void remove(const int index)
- {
- notifyAboutToRemoveObject(index);
- m_objects.removeAt(index);
- notifyObjectRemoved();
- }
- Object *get(const int index) const
- {
- return m_objects.at(index);
- }
- int find(Object * const obj) const
- {
- return m_objects.indexOf(obj);
- }
-
- QList<Object *> getAll() const
- {
- return m_objects;
- }
-
-private:
- friend class CommonModel;
- QVariant get(const int index, const int entry, const int role) const override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(role))
- {
- return QVariant();
- }
- return m_entries[entry].second.value(role)->get(m_objects.at(index));
- }
- bool set(const int index, const int entry, const int role, const QVariant &value) override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(role))
- {
- return false;
- }
- IEntry *e = m_entries[entry].second.value(role);
- if (!e->canSet())
- {
- return false;
- }
- e->set(m_objects[index], value);
- return true;
- }
- bool canSet(const int entry) const override
- {
- if (m_entries.size() < entry || !m_entries[entry].second.contains(Qt::EditRole))
- {
- return false;
- }
- IEntry *e = m_entries[entry].second.value(Qt::EditRole);
- return e->canSet();
- }
-
- QString entryTitle(const int entry) const override
- {
- return m_entries.at(entry).first;
- }
-
-private:
- struct IEntry
- {
- virtual ~IEntry() {}
- virtual void set(Object *object, const QVariant &value) = 0;
- virtual QVariant get(Object *object) const = 0;
- virtual bool canSet() const = 0;
- };
- template<typename T>
- struct VariableEntry : public IEntry
- {
- typedef T (Object::*Member);
-
- explicit VariableEntry(Member member)
- : m_member(member) {}
-
- void set(Object *object, const QVariant &value) override
- {
- object->*m_member = value.value<T>();
- }
- QVariant get(Object *object) const override
- {
- return QVariant::fromValue<T>(object->*m_member);
- }
- bool canSet() const override { return true; }
-
- private:
- Member m_member;
- };
- template<typename T>
- struct FunctionEntry : public IEntry
- {
- typedef T (Object::*Getter)() const;
- typedef void (Object::*Setter)(T);
-
- explicit FunctionEntry(Getter getter, Setter setter)
- : m_getter(getter), m_setter(setter) {}
-
- void set(Object *object, const QVariant &value) override
- {
- (object->*m_setter)(value.value<T>());
- }
- QVariant get(Object *object) const override
- {
- return QVariant::fromValue<T>((object->*m_getter)());
- }
- bool canSet() const override { return !!m_setter; }
-
- private:
- Getter m_getter;
- Setter m_setter;
- };
- template<typename T>
- struct LambdaEntry : public IEntry
- {
- using Getter = std::function<T(Object *)>;
-
- explicit LambdaEntry(Getter getter)
- : m_getter(getter) {}
-
- void set(Object *object, const QVariant &value) override {}
- QVariant get(Object *object) const override
- {
- return QVariant::fromValue<T>(m_getter(object));
- }
- bool canSet() const override { return false; }
-
- private:
- Getter m_getter;
- };
-
- QList<Object *> m_objects;
- QVector<QPair<QString, QMap<int, IEntry *>>> m_entries;
-
- void addEntryInternal(IEntry *e, const int entry, const int role)
- {
- if (m_entries.size() <= entry)
- {
- m_entries.resize(entry + 1);
- }
- m_entries[entry].second.insert(role, e);
- }
-
-protected:
- template<typename Getter, typename Setter>
- typename std::enable_if<std::is_member_function_pointer<Getter>::value && std::is_member_function_pointer<Getter>::value, void>::type
- addEntry(const int entry, const int role, Getter getter, Setter setter)
- {
- addEntryInternal(new FunctionEntry<typename std::result_of<Getter>::type>(getter, setter), entry, role);
- }
- template<typename T>
- typename std::enable_if<std::is_member_function_pointer<typename FunctionEntry<T>::Getter>::value, void>::type
- addEntry(const int entry, const int role, typename FunctionEntry<T>::Getter getter)
- {
- addEntryInternal(new FunctionEntry<T>(getter, nullptr), entry, role);
- }
- template<typename T>
- typename std::enable_if<!std::is_member_function_pointer<T (Object::*)>::value, void>::type
- addEntry(const int entry, const int role, T (Object::*member))
- {
- addEntryInternal(new VariableEntry<T>(member), entry, role);
- }
- template<typename T>
- void addEntry(const int entry, const int role, typename LambdaEntry<T>::Getter lambda)
- {
- addEntryInternal(new LambdaEntry<T>(lambda), entry, role);
- }
-
- void setEntryTitle(const int entry, const QString &title)
- {
- m_entries[entry].first = title;
- }
-
- void setAll(const QList<Object *> objects)
- {
- notifyBeginReset();
- qDeleteAll(m_objects);
- m_objects = objects;
- notifyEndReset();
- }
-};
diff --git a/api/logic/BaseConfigObject.cpp b/api/logic/BaseConfigObject.cpp
deleted file mode 100644
index 3040ac2e..00000000
--- a/api/logic/BaseConfigObject.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Copyright 2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "BaseConfigObject.h"
-
-#include <QTimer>
-#include <QFile>
-#include <QCoreApplication>
-#include <QDebug>
-
-#include "Exception.h"
-#include "FileSystem.h"
-
-BaseConfigObject::BaseConfigObject(const QString &filename)
- : m_filename(filename)
-{
- m_saveTimer = new QTimer;
- m_saveTimer->setSingleShot(true);
- // cppcheck-suppress pureVirtualCall
- QObject::connect(m_saveTimer, &QTimer::timeout, [this](){saveNow();});
- setSaveTimeout(250);
-
- m_initialReadTimer = new QTimer;
- m_initialReadTimer->setSingleShot(true);
- QObject::connect(m_initialReadTimer, &QTimer::timeout, [this]()
- {
- loadNow();
- m_initialReadTimer->deleteLater();
- m_initialReadTimer = 0;
- });
- m_initialReadTimer->start(0);
-
- // cppcheck-suppress pureVirtualCall
- m_appQuitConnection = QObject::connect(qApp, &QCoreApplication::aboutToQuit, [this](){saveNow();});
-}
-BaseConfigObject::~BaseConfigObject()
-{
- delete m_saveTimer;
- if (m_initialReadTimer)
- {
- delete m_initialReadTimer;
- }
- QObject::disconnect(m_appQuitConnection);
-}
-
-void BaseConfigObject::setSaveTimeout(int msec)
-{
- m_saveTimer->setInterval(msec);
-}
-
-void BaseConfigObject::scheduleSave()
-{
- m_saveTimer->stop();
- m_saveTimer->start();
-}
-void BaseConfigObject::saveNow()
-{
- if (m_saveTimer->isActive())
- {
- m_saveTimer->stop();
- }
- if (m_disableSaving)
- {
- return;
- }
-
- try
- {
- FS::write(m_filename, doSave());
- }
- catch (Exception & e)
- {
- qCritical() << e.cause();
- }
-}
-void BaseConfigObject::loadNow()
-{
- if (m_saveTimer->isActive())
- {
- saveNow();
- }
-
- try
- {
- doLoad(FS::read(m_filename));
- }
- catch (Exception & e)
- {
- qWarning() << "Error loading" << m_filename << ":" << e.cause();
- }
-}
diff --git a/api/logic/BaseConfigObject.h b/api/logic/BaseConfigObject.h
deleted file mode 100644
index 1c96b3d1..00000000
--- a/api/logic/BaseConfigObject.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright 2015 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <QObject>
-
-class QTimer;
-
-class BaseConfigObject
-{
-public:
- void setSaveTimeout(int msec);
-
-protected:
- explicit BaseConfigObject(const QString &filename);
- virtual ~BaseConfigObject();
-
- // cppcheck-suppress pureVirtualCall
- virtual QByteArray doSave() const = 0;
- virtual void doLoad(const QByteArray &data) = 0;
-
- void setSavingDisabled(bool savingDisabled) { m_disableSaving = savingDisabled; }
-
- QString fileName() const { return m_filename; }
-
-public:
- void scheduleSave();
- void saveNow();
- void loadNow();
-
-private:
- QTimer *m_saveTimer;
- QTimer *m_initialReadTimer;
- QString m_filename;
- QMetaObject::Connection m_appQuitConnection;
- bool m_disableSaving = false;
-};
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
diff --git a/api/logic/TypeMagic.h b/api/logic/TypeMagic.h
deleted file mode 100644
index fa9d12a9..00000000
--- a/api/logic/TypeMagic.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-namespace TypeMagic
-{
-/** "Cleans" the given type T by stripping references (&) and cv-qualifiers (const, volatile) from it
- * const int => int
- * QString & => QString
- * const unsigned long long & => unsigned long long
- *
- * Usage:
- * using Cleaned = Detail::CleanType<const int>;
- * static_assert(std::is_same<Cleaned, int>, "Cleaned == int");
- */
-// the order of remove_cv and remove_reference matters!
-template <typename T>
-using CleanType = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
-
-/// For functors (structs with operator()), including lambdas, which in **most** cases are functors
-/// "Calls" Function<Ret(*)(Arg)> or Function<Ret(C::*)(Arg)>
-template <typename T> struct Function : public Function<decltype(&T::operator())> {};
-/// For function pointers (&function), including static members (&Class::member)
-template <typename Ret, typename Arg> struct Function<Ret(*)(Arg)> : public Function<Ret(Arg)> {};
-/// Default specialization used by others.
-template <typename Ret, typename Arg> struct Function<Ret(Arg)>
-{
- using ReturnType = Ret;
- using Argument = Arg;
-};
-/// For member functions. Also used by the lambda overload if the lambda captures [this]
-template <class C, typename Ret, typename Arg> struct Function<Ret(C::*)(Arg)> : public Function<Ret(Arg)> {};
-template <class C, typename Ret, typename Arg> struct Function<Ret(C::*)(Arg) const> : public Function<Ret(Arg)> {};
-/// Overload for references
-template <typename F> struct Function<F&> : public Function<F> {};
-/// Overload for rvalues
-template <typename F> struct Function<F&&> : public Function<F> {};
-// for more info: https://functionalcpp.wordpress.com/2013/08/05/function-traits/
-}
diff --git a/api/logic/resources/Resource.cpp b/api/logic/resources/Resource.cpp
deleted file mode 100644
index e95675d7..00000000
--- a/api/logic/resources/Resource.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-#include "Resource.h"
-
-#include <QDebug>
-
-#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)
-{
- if (!resource.isEmpty())
- {
- // 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);
- }
- else
- {
- m_handler = std::make_shared<NullResourceHandler>();
- }
-
- Q_ASSERT(m_handler);
- m_handler->init(m_handler);
- m_handler->setResource(this);
-}
-Resource::~Resource()
-{
- qDeleteAll(m_observers);
-}
-
-Resource::Ptr Resource::create(const QString &resource, Ptr placeholder)
-{
- const QString storageId = storageIdentifier(resource, placeholder);
-
- // do we already have a resource? even if m_resources contains it it might not be valid any longer (weak_ptr)
- Resource::Ptr ptr = m_resources.contains(storageId)
- ? m_resources.value(storageId).lock()
- : nullptr;
- // did we have one? and is it still valid?
- if (!ptr)
- {
- /* We don't want Resource to have a public constructor, but std::make_shared needs it,
- * so we create a subclass of Resource here that exposes the constructor as public.
- * The alternative would be making the allocator for std::make_shared a friend, but it
- * differs between different STL implementations, so that would be a pain.
- */
- struct ConstructableResource : public Resource
- {
- explicit ConstructableResource(const QString &resource)
- : Resource(resource) {}
- };
- ptr = std::make_shared<ConstructableResource>(resource);
- ptr->m_placeholder = placeholder;
- m_resources.insert(storageId, ptr);
- }
- return ptr;
-}
-
-Resource::Ptr Resource::applyTo(ResourceObserver *observer)
-{
- m_observers.append(observer);
- observer->setSource(shared_from_this()); // give the observer a shared_ptr for us so we don't get deleted
- observer->resourceUpdated(); // ask the observer to poll us immediently, we might already have data
- return shared_from_this(); // allow chaining
-}
-Resource::Ptr Resource::applyTo(QObject *target, const char *property)
-{
- // the cast to ResourceObserver* is required to ensure the right overload gets choosen,
- // since QObjectResourceObserver also inherits from QObject
- return applyTo(static_cast<ResourceObserver *>(new QObjectResourceObserver(target, property)));
-}
-
-QVariant Resource::getResourceInternal(const int typeId) const
-{
- // no result (yet), but a placeholder? delegate to the placeholder.
- if (m_handler->result().isNull() && m_placeholder)
- {
- return m_placeholder->getResourceInternal(typeId);
- }
- const QVariant variant = m_handler->result();
- const auto typePair = qMakePair(int(variant.type()), typeId);
-
- // do we have an explicit transformer? use it.
- if (m_transfomers.contains(typePair))
- {
- return m_transfomers.value(typePair)(variant);
- }
- else
- {
- // we do not have an explicit transformer, so we just pass the QVariant, which will automatically
- // transform some types for us (different numbers to each other etc.)
- return variant;
- }
-}
-
-void Resource::reportResult()
-{
- for (ResourceObserver *observer : m_observers)
- {
- observer->resourceUpdated();
- }
-}
-void Resource::reportFailure(const QString &reason)
-{
- for (ResourceObserver *observer : m_observers)
- {
- observer->setFailure(reason);
- }
-}
-void Resource::reportProgress(const int progress)
-{
- for (ResourceObserver *observer : m_observers)
- {
- observer->setProgress(progress);
- }
-}
-
-void Resource::notifyObserverDeleted(ResourceObserver *observer)
-{
- m_observers.removeAll(observer);
-}
-
-QString Resource::storageIdentifier(const QString &id, Resource::Ptr placeholder)
-{
- if (placeholder)
- {
- return id + '#' + storageIdentifier(placeholder->m_resource, placeholder->m_placeholder);
- }
- else
- {
- return id;
- }
-}
diff --git a/api/logic/resources/Resource.h b/api/logic/resources/Resource.h
deleted file mode 100644
index 63e97b88..00000000
--- a/api/logic/resources/Resource.h
+++ /dev/null
@@ -1,132 +0,0 @@
-#pragma onc