From ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 11 Mar 2017 01:39:45 +0100 Subject: NOISSUE Wonko is the new Meta And then Wonko was the Meta. --- application/pages/global/MetadataPage.cpp | 242 ++++++++++++++++++++++++++++ application/pages/global/MetadataPage.h | 57 +++++++ application/pages/global/MetadataPage.ui | 252 ++++++++++++++++++++++++++++++ application/pages/global/WonkoPage.cpp | 240 ---------------------------- application/pages/global/WonkoPage.h | 57 ------- application/pages/global/WonkoPage.ui | 252 ------------------------------ 6 files changed, 551 insertions(+), 549 deletions(-) create mode 100644 application/pages/global/MetadataPage.cpp create mode 100644 application/pages/global/MetadataPage.h create mode 100644 application/pages/global/MetadataPage.ui delete mode 100644 application/pages/global/WonkoPage.cpp delete mode 100644 application/pages/global/WonkoPage.h delete mode 100644 application/pages/global/WonkoPage.ui (limited to 'application/pages') diff --git a/application/pages/global/MetadataPage.cpp b/application/pages/global/MetadataPage.cpp new file mode 100644 index 00000000..4e355997 --- /dev/null +++ b/application/pages/global/MetadataPage.cpp @@ -0,0 +1,242 @@ +/* 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 "MetadataPage.h" +#include "ui_MetadataPage.h" + +#include +#include +#include + +#include "dialogs/ProgressDialog.h" +#include "VersionProxyModel.h" + +#include "meta/Index.h" +#include "meta/VersionList.h" +#include "meta/Version.h" +#include "Env.h" +#include "MultiMC.h" + +using namespace Meta; + +static QString formatRequires(const VersionPtr &version) +{ + QStringList lines; + for (const Reference &ref : version->requires()) + { + const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->getList(ref.uid())->humanReadable() : ref.uid(); + if (ref.version().isEmpty()) + { + lines.append(readable); + } + else + { + lines.append(QString("%1 (%2)").arg(readable, ref.version())); + } + } + return lines.join('\n'); +} + +MetadataPage::MetadataPage(QWidget *parent) : + QWidget(parent), + ui(new Ui::MetadataPage) +{ + ui->setupUi(this); + ui->tabWidget->tabBar()->hide(); + + m_fileProxy = new QSortFilterProxyModel(this); + m_fileProxy->setSortRole(Qt::DisplayRole); + m_fileProxy->setSortCaseSensitivity(Qt::CaseInsensitive); + m_fileProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_fileProxy->setFilterRole(Qt::DisplayRole); + m_fileProxy->setFilterKeyColumn(0); + m_fileProxy->sort(0); + m_fileProxy->setSourceModel(ENV.metadataIndex().get()); + ui->indexView->setModel(m_fileProxy); + + m_filterProxy = new QSortFilterProxyModel(this); + m_filterProxy->setSortRole(VersionList::SortRole); + m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_filterProxy->setFilterRole(Qt::DisplayRole); + m_filterProxy->setFilterKeyColumn(0); + m_filterProxy->sort(0, Qt::DescendingOrder); + ui->versionsView->setModel(m_filterProxy); + + m_versionProxy = new VersionProxyModel(this); + m_filterProxy->setSourceModel(m_versionProxy); + + connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateCurrentVersionList); + connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateVersion); + connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &MetadataPage::versionListDataChanged); + + updateCurrentVersionList(QModelIndex()); + updateVersion(); +} + +MetadataPage::~MetadataPage() +{ + delete ui; +} + +QIcon MetadataPage::icon() const +{ + return MMC->getThemedIcon("looney"); +} + +void MetadataPage::on_refreshIndexBtn_clicked() +{ + ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); +} +void MetadataPage::on_refreshFileBtn_clicked() +{ + VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value(); + if (!list) + { + return; + } + ProgressDialog(this).execWithTask(list->remoteUpdateTask()); +} +void MetadataPage::on_refreshVersionBtn_clicked() +{ + VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value(); + if (!version) + { + return; + } + ProgressDialog(this).execWithTask(version->remoteUpdateTask()); +} + +void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) +{ + if (search.isEmpty()) + { + m_fileProxy->setFilterFixedString(QString()); + } + else + { + QStringList parts = search.split(' '); + std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape); + m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); + } +} +void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) +{ + if (search.isEmpty()) + { + m_filterProxy->setFilterFixedString(QString()); + } + else + { + QStringList parts = search.split(' '); + std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape); + m_filterProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); + } +} + +void MetadataPage::updateCurrentVersionList(const QModelIndex &index) +{ + if (index.isValid()) + { + VersionListPtr list = index.data(Index::ListPtrRole).value(); + ui->versionsBox->setEnabled(true); + ui->refreshFileBtn->setEnabled(true); + ui->fileUidLabel->setEnabled(true); + ui->fileUid->setText(list->uid()); + ui->fileNameLabel->setEnabled(true); + ui->fileName->setText(list->name()); + m_versionProxy->setSourceModel(list.get()); + ui->refreshFileBtn->setText(tr("Refresh %1").arg(list->humanReadable())); + + if (!list->isLocalLoaded()) + { + std::unique_ptr task = list->localUpdateTask(); + connect(task.get(), &Task::finished, this, [this, list]() + { + if (list->count() == 0 && !list->isRemoteLoaded()) + { + ProgressDialog(this).execWithTask(list->remoteUpdateTask()); + } + }); + ProgressDialog(this).execWithTask(task); + } + } + else + { + ui->versionsBox->setEnabled(false); + ui->refreshFileBtn->setEnabled(false); + ui->fileUidLabel->setEnabled(false); + ui->fileUid->clear(); + ui->fileNameLabel->setEnabled(false); + ui->fileName->clear(); + m_versionProxy->setSourceModel(nullptr); + ui->refreshFileBtn->setText(tr("Refresh ___")); + } +} + +void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) +{ + if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex())) + { + updateVersion(); + } +} + +void MetadataPage::updateVersion() +{ + VersionPtr version = std::dynamic_pointer_cast( + ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value()); + if (version) + { + ui->refreshVersionBtn->setEnabled(true); + ui->versionVersionLabel->setEnabled(true); + ui->versionVersion->setText(version->version()); + ui->versionTimeLabel->setEnabled(true); + ui->versionTime->setText(version->time().toString("yyyy-MM-dd HH:mm")); + ui->versionTypeLabel->setEnabled(true); + ui->versionType->setText(version->type()); + ui->versionRequiresLabel->setEnabled(true); + ui->versionRequires->setText(formatRequires(version)); + ui->refreshVersionBtn->setText(tr("Refresh %1").arg(version->version())); + } + else + { + ui->refreshVersionBtn->setEnabled(false); + ui->versionVersionLabel->setEnabled(false); + ui->versionVersion->clear(); + ui->versionTimeLabel->setEnabled(false); + ui->versionTime->clear(); + ui->versionTypeLabel->setEnabled(false); + ui->versionType->clear(); + ui->versionRequiresLabel->setEnabled(false); + ui->versionRequires->clear(); + ui->refreshVersionBtn->setText(tr("Refresh ___")); + } +} + +void MetadataPage::opened() +{ + if (!ENV.metadataIndex()->isLocalLoaded()) + { + std::unique_ptr task = ENV.metadataIndex()->localUpdateTask(); + connect(task.get(), &Task::finished, this, [this]() + { + if (!ENV.metadataIndex()->isRemoteLoaded()) + { + ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); + } + }); + ProgressDialog(this).execWithTask(task); + } +} diff --git a/application/pages/global/MetadataPage.h b/application/pages/global/MetadataPage.h new file mode 100644 index 00000000..f75b4952 --- /dev/null +++ b/application/pages/global/MetadataPage.h @@ -0,0 +1,57 @@ +/* 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 + +#include "pages/BasePage.h" + +namespace Ui { +class MetadataPage; +} + +class QSortFilterProxyModel; +class VersionProxyModel; + +class MetadataPage : public QWidget, public BasePage +{ + Q_OBJECT +public: + explicit MetadataPage(QWidget *parent = 0); + ~MetadataPage(); + + QString id() const override { return "metadata-global"; } + QString displayName() const override { return tr("Metadata"); } + QIcon icon() const override; + void opened() override; + +private slots: + void on_refreshIndexBtn_clicked(); + void on_refreshFileBtn_clicked(); + void on_refreshVersionBtn_clicked(); + void on_fileSearchEdit_textChanged(const QString &search); + void on_versionSearchEdit_textChanged(const QString &search); + void updateCurrentVersionList(const QModelIndex &index); + void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br); + +private: + Ui::MetadataPage *ui; + QSortFilterProxyModel *m_fileProxy; + QSortFilterProxyModel *m_filterProxy; + VersionProxyModel *m_versionProxy; + + void updateVersion(); +}; diff --git a/application/pages/global/MetadataPage.ui b/application/pages/global/MetadataPage.ui new file mode 100644 index 00000000..0bd33f32 --- /dev/null +++ b/application/pages/global/MetadataPage.ui @@ -0,0 +1,252 @@ + + + MetadataPage + + + + 0 + 0 + 640 + 480 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + Tab 1 + + + + + + Versions + + + + + + Search... + + + true + + + + + + + true + + + false + + + + + + + + + Refresh ___ + + + + + + + + + + + Version: + + + + + + + + + + + + + + Time: + + + + + + + + + + + + + + Type: + + + + + + + + + + + + + + Dependencies: + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Resources + + + + + + Search... + + + true + + + + + + + true + + + false + + + + + + + + + Refresh ___ + + + + + + + + + + + UID: + + + + + + + + + + + + + + Name: + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Refresh Index + + + + + + + + + + + + diff --git a/application/pages/global/WonkoPage.cpp b/application/pages/global/WonkoPage.cpp deleted file mode 100644 index 1a72b18d..00000000 --- a/application/pages/global/WonkoPage.cpp +++ /dev/null @@ -1,240 +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 "WonkoPage.h" -#include "ui_WonkoPage.h" - -#include -#include -#include - -#include "dialogs/ProgressDialog.h" -#include "VersionProxyModel.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersionList.h" -#include "wonko/WonkoVersion.h" -#include "Env.h" -#include "MultiMC.h" - -static QString formatRequires(const WonkoVersionPtr &version) -{ - QStringList lines; - for (const WonkoReference &ref : version->requires()) - { - const QString readable = ENV.wonkoIndex()->hasUid(ref.uid()) ? ENV.wonkoIndex()->getList(ref.uid())->humanReadable() : ref.uid(); - if (ref.version().isEmpty()) - { - lines.append(readable); - } - else - { - lines.append(QString("%1 (%2)").arg(readable, ref.version())); - } - } - return lines.join('\n'); -} - -WonkoPage::WonkoPage(QWidget *parent) : - QWidget(parent), - ui(new Ui::WonkoPage) -{ - ui->setupUi(this); - ui->tabWidget->tabBar()->hide(); - - m_fileProxy = new QSortFilterProxyModel(this); - m_fileProxy->setSortRole(Qt::DisplayRole); - m_fileProxy->setSortCaseSensitivity(Qt::CaseInsensitive); - m_fileProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); - m_fileProxy->setFilterRole(Qt::DisplayRole); - m_fileProxy->setFilterKeyColumn(0); - m_fileProxy->sort(0); - m_fileProxy->setSourceModel(ENV.wonkoIndex().get()); - ui->indexView->setModel(m_fileProxy); - - m_filterProxy = new QSortFilterProxyModel(this); - m_filterProxy->setSortRole(WonkoVersionList::SortRole); - m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); - m_filterProxy->setFilterRole(Qt::DisplayRole); - m_filterProxy->setFilterKeyColumn(0); - m_filterProxy->sort(0, Qt::DescendingOrder); - ui->versionsView->setModel(m_filterProxy); - - m_versionProxy = new VersionProxyModel(this); - m_filterProxy->setSourceModel(m_versionProxy); - - connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateCurrentVersionList); - connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateVersion); - connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &WonkoPage::versionListDataChanged); - - updateCurrentVersionList(QModelIndex()); - updateVersion(); -} - -WonkoPage::~WonkoPage() -{ - delete ui; -} - -QIcon WonkoPage::icon() const -{ - return MMC->getThemedIcon("looney"); -} - -void WonkoPage::on_refreshIndexBtn_clicked() -{ - ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); -} -void WonkoPage::on_refreshFileBtn_clicked() -{ - WonkoVersionListPtr list = ui->indexView->currentIndex().data(WonkoIndex::ListPtrRole).value(); - if (!list) - { - return; - } - ProgressDialog(this).execWithTask(list->remoteUpdateTask()); -} -void WonkoPage::on_refreshVersionBtn_clicked() -{ - WonkoVersionPtr version = ui->versionsView->currentIndex().data(WonkoVersionList::WonkoVersionPtrRole).value(); - if (!version) - { - return; - } - ProgressDialog(this).execWithTask(version->remoteUpdateTask()); -} - -void WonkoPage::on_fileSearchEdit_textChanged(const QString &search) -{ - if (search.isEmpty()) - { - m_fileProxy->setFilterFixedString(QString()); - } - else - { - QStringList parts = search.split(' '); - std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape); - m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); - } -} -void WonkoPage::on_versionSearchEdit_textChanged(const QString &search) -{ - if (search.isEmpty()) - { - m_filterProxy->setFilterFixedString(QString()); - } - else - { - QStringList parts = search.split(' '); - std::transform(parts.begin(), parts.end(), parts.begin(), &QRegularExpression::escape); - m_filterProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); - } -} - -void WonkoPage::updateCurrentVersionList(const QModelIndex &index) -{ - if (index.isValid()) - { - WonkoVersionListPtr list = index.data(WonkoIndex::ListPtrRole).value(); - ui->versionsBox->setEnabled(true); - ui->refreshFileBtn->setEnabled(true); - ui->fileUidLabel->setEnabled(true); - ui->fileUid->setText(list->uid()); - ui->fileNameLabel->setEnabled(true); - ui->fileName->setText(list->name()); - m_versionProxy->setSourceModel(list.get()); - ui->refreshFileBtn->setText(tr("Refresh %1").arg(list->humanReadable())); - - if (!list->isLocalLoaded()) - { - std::unique_ptr task = list->localUpdateTask(); - connect(task.get(), &Task::finished, this, [this, list]() - { - if (list->count() == 0 && !list->isRemoteLoaded()) - { - ProgressDialog(this).execWithTask(list->remoteUpdateTask()); - } - }); - ProgressDialog(this).execWithTask(task); - } - } - else - { - ui->versionsBox->setEnabled(false); - ui->refreshFileBtn->setEnabled(false); - ui->fileUidLabel->setEnabled(false); - ui->fileUid->clear(); - ui->fileNameLabel->setEnabled(false); - ui->fileName->clear(); - m_versionProxy->setSourceModel(nullptr); - ui->refreshFileBtn->setText(tr("Refresh ___")); - } -} - -void WonkoPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) -{ - if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex())) - { - updateVersion(); - } -} - -void WonkoPage::updateVersion() -{ - WonkoVersionPtr version = std::dynamic_pointer_cast( - ui->versionsView->currentIndex().data(WonkoVersionList::VersionPointerRole).value()); - if (version) - { - ui->refreshVersionBtn->setEnabled(true); - ui->versionVersionLabel->setEnabled(true); - ui->versionVersion->setText(version->version()); - ui->versionTimeLabel->setEnabled(true); - ui->versionTime->setText(version->time().toString("yyyy-MM-dd HH:mm")); - ui->versionTypeLabel->setEnabled(true); - ui->versionType->setText(version->type()); - ui->versionRequiresLabel->setEnabled(true); - ui->versionRequires->setText(formatRequires(version)); - ui->refreshVersionBtn->setText(tr("Refresh %1").arg(version->version())); - } - else - { - ui->refreshVersionBtn->setEnabled(false); - ui->versionVersionLabel->setEnabled(false); - ui->versionVersion->clear(); - ui->versionTimeLabel->setEnabled(false); - ui->versionTime->clear(); - ui->versionTypeLabel->setEnabled(false); - ui->versionType->clear(); - ui->versionRequiresLabel->setEnabled(false); - ui->versionRequires->clear(); - ui->refreshVersionBtn->setText(tr("Refresh ___")); - } -} - -void WonkoPage::opened() -{ - if (!ENV.wonkoIndex()->isLocalLoaded()) - { - std::unique_ptr task = ENV.wonkoIndex()->localUpdateTask(); - connect(task.get(), &Task::finished, this, [this]() - { - if (!ENV.wonkoIndex()->isRemoteLoaded()) - { - ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); - } - }); - ProgressDialog(this).execWithTask(task); - } -} diff --git a/application/pages/global/WonkoPage.h b/application/pages/global/WonkoPage.h deleted file mode 100644 index 1d576c15..00000000 --- a/application/pages/global/WonkoPage.h +++ /dev/null @@ -1,57 +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 - -#include "pages/BasePage.h" - -namespace Ui { -class WonkoPage; -} - -class QSortFilterProxyModel; -class VersionProxyModel; - -class WonkoPage : public QWidget, public BasePage -{ - Q_OBJECT -public: - explicit WonkoPage(QWidget *parent = 0); - ~WonkoPage(); - - QString id() const override { return "wonko-global"; } - QString displayName() const override { return tr("Wonko"); } - QIcon icon() const override; - void opened() override; - -private slots: - void on_refreshIndexBtn_clicked(); - void on_refreshFileBtn_clicked(); - void on_refreshVersionBtn_clicked(); - void on_fileSearchEdit_textChanged(const QString &search); - void on_versionSearchEdit_textChanged(const QString &search); - void updateCurrentVersionList(const QModelIndex &index); - void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br); - -private: - Ui::WonkoPage *ui; - QSortFilterProxyModel *m_fileProxy; - QSortFilterProxyModel *m_filterProxy; - VersionProxyModel *m_versionProxy; - - void updateVersion(); -}; diff --git a/application/pages/global/WonkoPage.ui b/application/pages/global/WonkoPage.ui deleted file mode 100644 index 2d14ceca..00000000 --- a/application/pages/global/WonkoPage.ui +++ /dev/null @@ -1,252 +0,0 @@ - - - WonkoPage - - - - 0 - 0 - 640 - 480 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - Tab 1 - - - - - - Versions - - - - - - Search... - - - true - - - - - - - true - - - false - - - - - - - - - Refresh ___ - - - - - - - - - - - Version: - - - - - - - - - - - - - - Time: - - - - - - - - - - - - - - Type: - - - - - - - - - - - - - - Dependencies: - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Resources - - - - - - Search... - - - true - - - - - - - true - - - false - - - - - - - - - Refresh ___ - - - - - - - - - - - UID: - - - - - - - - - - - - - - Name: - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Refresh Index - - - - - - - - - - - - -- cgit v1.2.3