diff options
| author | Petr Mrázek <peterix@gmail.com> | 2017-03-11 01:39:45 +0100 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2017-04-07 00:20:01 +0200 |
| commit | ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c (patch) | |
| tree | 0dfb9713e99f5d89d75e05e2ceb4b1378a2aa6b3 /api/logic/wonko | |
| parent | 1fbe03f982f130bf675b7f94dd9c06aee62da54f (diff) | |
| download | PrismLauncher-ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c.tar.gz PrismLauncher-ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c.tar.bz2 PrismLauncher-ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c.zip | |
NOISSUE Wonko is the new Meta
And then Wonko was the Meta.
Diffstat (limited to 'api/logic/wonko')
21 files changed, 0 insertions, 1814 deletions
diff --git a/api/logic/wonko/BaseWonkoEntity.cpp b/api/logic/wonko/BaseWonkoEntity.cpp deleted file mode 100644 index e6a0e41e..00000000 --- a/api/logic/wonko/BaseWonkoEntity.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright 2015-2017 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 "BaseWonkoEntity.h" - -#include "Json.h" -#include "WonkoUtil.h" - -BaseWonkoEntity::~BaseWonkoEntity() -{ -} - -void BaseWonkoEntity::store() const -{ - Json::write(serialized(), Wonko::localWonkoDir().absoluteFilePath(localFilename())); -} - -void BaseWonkoEntity::notifyLocalLoadComplete() -{ - m_localLoaded = true; - store(); -} -void BaseWonkoEntity::notifyRemoteLoadComplete() -{ - m_remoteLoaded = true; - store(); -} diff --git a/api/logic/wonko/BaseWonkoEntity.h b/api/logic/wonko/BaseWonkoEntity.h deleted file mode 100644 index c6e8c832..00000000 --- a/api/logic/wonko/BaseWonkoEntity.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2015-2017 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> -#include <memory> - -#include "multimc_logic_export.h" - -class Task; - -class MULTIMC_LOGIC_EXPORT BaseWonkoEntity -{ -public: - virtual ~BaseWonkoEntity(); - - using Ptr = std::shared_ptr<BaseWonkoEntity>; - - virtual std::unique_ptr<Task> remoteUpdateTask() = 0; - virtual std::unique_ptr<Task> localUpdateTask() = 0; - virtual void merge(const std::shared_ptr<BaseWonkoEntity> &other) = 0; - - void store() const; - virtual QString localFilename() const = 0; - virtual QJsonObject serialized() const = 0; - - bool isComplete() const { return m_localLoaded || m_remoteLoaded; } - - bool isLocalLoaded() const { return m_localLoaded; } - bool isRemoteLoaded() const { return m_remoteLoaded; } - - void notifyLocalLoadComplete(); - void notifyRemoteLoadComplete(); - -private: - bool m_localLoaded = false; - bool m_remoteLoaded = false; -}; diff --git a/api/logic/wonko/WonkoIndex.cpp b/api/logic/wonko/WonkoIndex.cpp deleted file mode 100644 index f6ad201a..00000000 --- a/api/logic/wonko/WonkoIndex.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2015-2017 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 "WonkoIndex.h" - -#include "WonkoVersionList.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" - -WonkoIndex::WonkoIndex(QObject *parent) - : QAbstractListModel(parent) -{ -} -WonkoIndex::WonkoIndex(const QVector<WonkoVersionListPtr> &lists, QObject *parent) - : QAbstractListModel(parent), m_lists(lists) -{ - for (int i = 0; i < m_lists.size(); ++i) - { - m_uids.insert(m_lists.at(i)->uid(), m_lists.at(i)); - connectVersionList(i, m_lists.at(i)); - } -} - -QVariant WonkoIndex::data(const QModelIndex &index, int role) const -{ - if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size()) - { - return QVariant(); - } - - WonkoVersionListPtr list = m_lists.at(index.row()); - switch (role) - { - case Qt::DisplayRole: - switch (index.column()) - { - case 0: return list->humanReadable(); - default: break; - } - case UidRole: return list->uid(); - case NameRole: return list->name(); - case ListPtrRole: return QVariant::fromValue(list); - } - return QVariant(); -} -int WonkoIndex::rowCount(const QModelIndex &parent) const -{ - return m_lists.size(); -} -int WonkoIndex::columnCount(const QModelIndex &parent) const -{ - return 1; -} -QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) - { - return tr("Name"); - } - else - { - return QVariant(); - } -} - -std::unique_ptr<Task> WonkoIndex::remoteUpdateTask() -{ - return std::unique_ptr<WonkoIndexRemoteLoadTask>(new WonkoIndexRemoteLoadTask(this, this)); -} -std::unique_ptr<Task> WonkoIndex::localUpdateTask() -{ - return std::unique_ptr<WonkoIndexLocalLoadTask>(new WonkoIndexLocalLoadTask(this, this)); -} - -QJsonObject WonkoIndex::serialized() const -{ - return WonkoFormat::serializeIndex(this); -} - -bool WonkoIndex::hasUid(const QString &uid) const -{ - return m_uids.contains(uid); -} -WonkoVersionListPtr WonkoIndex::getList(const QString &uid) const -{ - return m_uids.value(uid, nullptr); -} -WonkoVersionListPtr WonkoIndex::getListGuaranteed(const QString &uid) const -{ - return m_uids.value(uid, std::make_shared<WonkoVersionList>(uid)); -} - -void WonkoIndex::merge(const Ptr &other) -{ - const QVector<WonkoVersionListPtr> lists = std::dynamic_pointer_cast<WonkoIndex>(other)->m_lists; - // initial load, no need to merge - if (m_lists.isEmpty()) - { - beginResetModel(); - m_lists = lists; - for (int i = 0; i < lists.size(); ++i) - { - m_uids.insert(lists.at(i)->uid(), lists.at(i)); - connectVersionList(i, lists.at(i)); - } - endResetModel(); - } - else - { - for (const WonkoVersionListPtr &list : lists) - { - if (m_uids.contains(list->uid())) - { - m_uids[list->uid()]->merge(list); - } - else - { - beginInsertRows(QModelIndex(), m_lists.size(), m_lists.size()); - connectVersionList(m_lists.size(), list); - m_lists.append(list); - m_uids.insert(list->uid(), list); - endInsertRows(); - } - } - } -} - -void WonkoIndex::connectVersionList(const int row, const WonkoVersionListPtr &list) -{ - connect(list.get(), &WonkoVersionList::nameChanged, this, [this, row]() - { - emit dataChanged(index(row), index(row), QVector<int>() << Qt::DisplayRole); - }); -} diff --git a/api/logic/wonko/WonkoIndex.h b/api/logic/wonko/WonkoIndex.h deleted file mode 100644 index fe07c3ef..00000000 --- a/api/logic/wonko/WonkoIndex.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2015-2017 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 <memory> - -#include "BaseWonkoEntity.h" - -#include "multimc_logic_export.h" - -class Task; -using WonkoVersionListPtr = std::shared_ptr<class WonkoVersionList>; - -class MULTIMC_LOGIC_EXPORT WonkoIndex : public QAbstractListModel, public BaseWonkoEntity -{ - Q_OBJECT -public: - explicit WonkoIndex(QObject *parent = nullptr); - explicit WonkoIndex(const QVector<WonkoVersionListPtr> &lists, QObject *parent = nullptr); - - enum - { - UidRole = Qt::UserRole, - NameRole, - ListPtrRole - }; - - QVariant data(const QModelIndex &index, int role) const override; - int rowCount(const QModelIndex &parent) const override; - int columnCount(const QModelIndex &parent) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - - std::unique_ptr<Task> remoteUpdateTask() override; - std::unique_ptr<Task> localUpdateTask() override; - - QString localFilename() const override { return "index.json"; } - QJsonObject serialized() const override; - - // queries - bool hasUid(const QString &uid) const; - WonkoVersionListPtr getList(const QString &uid) const; - WonkoVersionListPtr getListGuaranteed(const QString &uid) const; - - QVector<WonkoVersionListPtr> lists() const { return m_lists; } - -public: // for usage by parsers only - void merge(const BaseWonkoEntity::Ptr &other); - -private: - QVector<WonkoVersionListPtr> m_lists; - QHash<QString, WonkoVersionListPtr> m_uids; - - void connectVersionList(const int row, const WonkoVersionListPtr &list); -}; diff --git a/api/logic/wonko/WonkoIndex_test.cpp b/api/logic/wonko/WonkoIndex_test.cpp deleted file mode 100644 index d7b92f21..00000000 --- a/api/logic/wonko/WonkoIndex_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include <QTest> -#include "TestUtil.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" - -class WonkoIndexTest : public QObject -{ - Q_OBJECT -private -slots: - void test_isProvidedByEnv() - { - QVERIFY(ENV.wonkoIndex()); - QCOMPARE(ENV.wonkoIndex(), ENV.wonkoIndex()); - } - - void test_providesTasks() - { - QVERIFY(ENV.wonkoIndex()->localUpdateTask() != nullptr); - QVERIFY(ENV.wonkoIndex()->remoteUpdateTask() != nullptr); - } - - void test_hasUid_and_getList() - { - WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")}); - QVERIFY(windex.hasUid("list1")); - QVERIFY(!windex.hasUid("asdf")); - QVERIFY(windex.getList("list2") != nullptr); - QCOMPARE(windex.getList("list2")->uid(), QString("list2")); - QVERIFY(windex.getList("adsf") == nullptr); - } - - void test_merge() - { - WonkoIndex windex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")}); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list1"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list3")}))); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list4"), std::make_shared<WonkoVersionList>("list2"), std::make_shared<WonkoVersionList>("list5")}))); - QCOMPARE(windex.lists().size(), 5); - windex.merge(std::shared_ptr<WonkoIndex>(new WonkoIndex({std::make_shared<WonkoVersionList>("list6")}))); - QCOMPARE(windex.lists().size(), 6); - } -}; - -QTEST_GUILESS_MAIN(WonkoIndexTest) - -#include "WonkoIndex_test.moc" diff --git a/api/logic/wonko/WonkoReference.cpp b/api/logic/wonko/WonkoReference.cpp deleted file mode 100644 index 7193e56e..00000000 --- a/api/logic/wonko/WonkoReference.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2015-2017 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 "WonkoReference.h" - -WonkoReference::WonkoReference(const QString &uid) - : m_uid(uid) -{ -} - -QString WonkoReference::uid() const -{ - return m_uid; -} - -QString WonkoReference::version() const -{ - return m_version; -} -void WonkoReference::setVersion(const QString &version) -{ - m_version = version; -} - -bool WonkoReference::operator==(const WonkoReference &other) const -{ - return m_uid == other.m_uid && m_version == other.m_version; -} -bool WonkoReference::operator!=(const WonkoReference &other) const -{ - return m_uid != other.m_uid || m_version != other.m_version; -} diff --git a/api/logic/wonko/WonkoReference.h b/api/logic/wonko/WonkoReference.h deleted file mode 100644 index ba7427b3..00000000 --- a/api/logic/wonko/WonkoReference.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2015-2017 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 <QString> -#include <QMetaType> - -#include "multimc_logic_export.h" - -class MULTIMC_LOGIC_EXPORT WonkoReference -{ -public: - WonkoReference() {} - explicit WonkoReference(const QString &uid); - - QString uid() const; - - QString version() const; - void setVersion(const QString &version); - - bool operator==(const WonkoReference &other) const; - bool operator!=(const WonkoReference &other) const; - -private: - QString m_uid; - QString m_version; -}; -Q_DECLARE_METATYPE(WonkoReference) diff --git a/api/logic/wonko/WonkoUtil.cpp b/api/logic/wonko/WonkoUtil.cpp deleted file mode 100644 index 3b8049c4..00000000 --- a/api/logic/wonko/WonkoUtil.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2015-2017 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 "WonkoUtil.h" - -#include <QUrl> -#include <QDir> - -#include "Env.h" - -namespace Wonko -{ -QUrl rootUrl() -{ - return ENV.wonkoRootUrl(); -} -QUrl indexUrl() -{ - return rootUrl().resolved(QStringLiteral("index.json")); -} -QUrl versionListUrl(const QString &uid) -{ - return rootUrl().resolved(uid + ".json"); -} -QUrl versionUrl(const QString &uid, const QString &version) -{ - return rootUrl().resolved(uid + "/" + version + ".json"); -} - -QDir localWonkoDir() -{ - return QDir("wonko"); -} - -} diff --git a/api/logic/wonko/WonkoUtil.h b/api/logic/wonko/WonkoUtil.h deleted file mode 100644 index fb58ba1f..00000000 --- a/api/logic/wonko/WonkoUtil.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2015-2017 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 "multimc_logic_export.h" - -class QUrl; -class QString; -class QDir; - -namespace Wonko -{ -MULTIMC_LOGIC_EXPORT QUrl rootUrl(); -MULTIMC_LOGIC_EXPORT QUrl indexUrl(); -MULTIMC_LOGIC_EXPORT QUrl versionListUrl(const QString &uid); -MULTIMC_LOGIC_EXPORT QUrl versionUrl(const QString &uid, const QString &version); -MULTIMC_LOGIC_EXPORT QDir localWonkoDir(); -} diff --git a/api/logic/wonko/WonkoVersion.cpp b/api/logic/wonko/WonkoVersion.cpp deleted file mode 100644 index f5a063be..00000000 --- a/api/logic/wonko/WonkoVersion.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright 2015-2017 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 "WonkoVersion.h" - -#include <QDateTime> - -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" - -WonkoVersion::WonkoVersion(const QString &uid, const QString &version) - : BaseVersion(), m_uid(uid), m_version(version) -{ -} - -QString WonkoVersion::descriptor() -{ - return m_version; -} -QString WonkoVersion::name() -{ - return m_version; -} -QString WonkoVersion::typeString() const -{ - return m_type; -} - -QDateTime WonkoVersion::time() const -{ - return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); -} - -std::unique_ptr<Task> WonkoVersion::remoteUpdateTask() -{ - return std::unique_ptr<WonkoVersionRemoteLoadTask>(new WonkoVersionRemoteLoadTask(this, this)); -} -std::unique_ptr<Task> WonkoVersion::localUpdateTask() -{ - return std::unique_ptr<WonkoVersionLocalLoadTask>(new WonkoVersionLocalLoadTask(this, this)); -} - -void WonkoVersion::merge(const std::shared_ptr<BaseWonkoEntity> &other) -{ - WonkoVersionPtr version = std::dynamic_pointer_cast<WonkoVersion>(other); - if (m_type != version->m_type) - { - setType(version->m_type); - } - if (m_time != version->m_time) - { - setTime(version->m_time); - } - if (m_requires != version->m_requires) - { - setRequires(version->m_requires); - } - - setData(version->m_data); -} - -QString WonkoVersion::localFilename() const -{ - return m_uid + '/' + m_version + ".json"; -} -QJsonObject WonkoVersion::serialized() const -{ - return WonkoFormat::serializeVersion(this); -} - -void WonkoVersion::setType(const QString &type) -{ - m_type = type; - emit typeChanged(); -} -void WonkoVersion::setTime(const qint64 time) -{ - m_time = time; - emit timeChanged(); -} -void WonkoVersion::setRequires(const QVector<WonkoReference> &requires) -{ - m_requires = requires; - emit requiresChanged(); -} -void WonkoVersion::setData(const VersionFilePtr &data) -{ - m_data = data; -} diff --git a/api/logic/wonko/WonkoVersion.h b/api/logic/wonko/WonkoVersion.h deleted file mode 100644 index 397ff14e..00000000 --- a/api/logic/wonko/WonkoVersion.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright 2015-2017 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 "BaseVersion.h" -#include "BaseWonkoEntity.h" - -#include <QVector> -#include <QStringList> -#include <QJsonObject> -#include <memory> - -#include "minecraft/VersionFile.h" -#include "WonkoReference.h" - -#include "multimc_logic_export.h" - -using WonkoVersionPtr = std::shared_ptr<class WonkoVersion>; - -class MULTIMC_LOGIC_EXPORT WonkoVersion : public QObject, public BaseVersion, public BaseWonkoEntity -{ - Q_OBJECT - Q_PROPERTY(QString uid READ uid CONSTANT) - Q_PROPERTY(QString version READ version CONSTANT) - Q_PROPERTY(QString type READ type NOTIFY typeChanged) - Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) - Q_PROPERTY(QVector<WonkoReference> requires READ requires NOTIFY requiresChanged) -public: - explicit WonkoVersion(const QString &uid, const QString &version); - - QString descriptor() override; - QString name() override; - QString typeString() const override; - - QString uid() const { return m_uid; } - QString version() const { return m_version; } - QString type() const { return m_type; } - QDateTime time() const; - qint64 rawTime() const { return m_time; } - QVector<WonkoReference> requires() const { return m_requires; } - VersionFilePtr data() const { return m_data; } - - std::unique_ptr<Task> remoteUpdateTask() override; - std::unique_ptr<Task> localUpdateTask() override; - void merge(const std::shared_ptr<BaseWonkoEntity> &other) override; - - QString localFilename() const override; - QJsonObject serialized() const override; - -public: // for usage by format parsers only - void setType(const QString &type); - void setTime(const qint64 time); - void setRequires(const QVector<WonkoReference> &requires); - void setData(const VersionFilePtr &data); - -signals: - void typeChanged(); - void timeChanged(); - void requiresChanged(); - -private: - QString m_uid; - QString m_version; - QString m_type; - qint64 m_time; - QVector<WonkoReference> m_requires; - VersionFilePtr m_data; -}; - -Q_DECLARE_METATYPE(WonkoVersionPtr) diff --git a/api/logic/wonko/WonkoVersionList.cpp b/api/logic/wonko/WonkoVersionList.cpp deleted file mode 100644 index 191e00f9..00000000 --- a/api/logic/wonko/WonkoVersionList.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* Copyright 2015-2017 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 "WonkoVersionList.h" - -#include <QDateTime> - -#include "WonkoVersion.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "format/WonkoFormat.h" -#include "WonkoReference.h" - -class WVLLoadTask : public Task -{ - Q_OBJECT -public: - explicit WVLLoadTask(WonkoVersionList *list, QObject *parent = nullptr) - : Task(parent), m_list(list) - { - } - - bool canAbort() const override - { - return !m_currentTask || m_currentTask->canAbort(); - } - bool abort() override - { - return m_currentTask->abort(); - } - -private: - void executeTask() override - { - if (!m_list->isLocalLoaded()) - { - m_currentTask = m_list->localUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::next); - } - else - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - } - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::failed, this, &WVLLoadTask::emitFailed); - m_currentTask->start(); - } - - void next() - { - m_currentTask = m_list->remoteUpdateTask(); - connect(m_currentTask.get(), &Task::status, this, &WVLLoadTask::setStatus); - connect(m_currentTask.get(), &Task::progress, this, &WVLLoadTask::setProgress); - connect(m_currentTask.get(), &Task::succeeded, this, &WVLLoadTask::emitSucceeded); - m_currentTask->start(); - } - - WonkoVersionList *m_list; - std::unique_ptr<Task> m_currentTask; -}; - -WonkoVersionList::WonkoVersionList(const QString &uid, QObject *parent) - : BaseVersionList(parent), m_uid(uid) -{ - setObjectName("Wonko version list: " + uid); -} - -Task *WonkoVersionList::getLoadTask() -{ - return new WVLLoadTask(this); -} - -bool WonkoVersionList::isLoaded() -{ - return isLocalLoaded() && isRemoteLoaded(); -} - -const BaseVersionPtr WonkoVersionList::at(int i) const -{ - return m_versions.at(i); -} -int WonkoVersionList::count() const -{ - return m_versions.size(); -} - -void WonkoVersionList::sortVersions() -{ - beginResetModel(); - std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b) - { - return *a.get() < *b.get(); - }); - endResetModel(); -} - -QVariant WonkoVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() < 0 || index.row() >= m_versions.size() || index.parent().isValid()) - { - return QVariant(); - } - - WonkoVersionPtr version = m_versions.at(index.row()); - - switch (role) - { - case VersionPointerRole: return QVariant::fromValue(std::dynamic_pointer_cast<BaseVersion>(version)); - case VersionRole: - case VersionIdRole: - return version->version(); - case ParentGameVersionRole: - { - const auto end = version->requires().end(); - const auto it = std::find_if(version->requires().begin(), end, - [](const WonkoReference &ref) { return ref.uid() == "net.minecraft"; }); - if (it != end) - { - return (*it).version(); - } - return QVariant(); - } - case TypeRole: return version->type(); - - case UidRole: return version->uid(); - case TimeRole: return version->time(); - case RequiresRole: return QVariant::fromValue(version->requires()); - case SortRole: return version->rawTime(); - case WonkoVersionPtrRole: return QVariant::fromValue(version); - case RecommendedRole: return version == getRecommended(); - case LatestRole: return version == getLatestStable(); - default: return QVariant(); - } -} - -BaseVersionList::RoleList WonkoVersionList::providesRoles() const -{ - return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, - TypeRole, UidRole, TimeRole, RequiresRole, SortRole, - RecommendedRole, LatestRole, WonkoVersionPtrRole}; -} - -QHash<int, QByteArray> WonkoVersionList::roleNames() const -{ - QHash<int, QByteArray> roles = B |
