2017-01-08 03:58:05 +00:00
|
|
|
/* Copyright 2015-2017 MultiMC Contributors
|
2016-04-06 22:09:30 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
#include "PackagesPage.h"
|
|
|
|
#include "ui_PackagesPage.h"
|
2016-04-06 22:09:30 +01:00
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
|
|
|
|
#include "dialogs/ProgressDialog.h"
|
|
|
|
#include "VersionProxyModel.h"
|
|
|
|
|
2017-03-11 00:39:45 +00:00
|
|
|
#include "meta/Index.h"
|
|
|
|
#include "meta/VersionList.h"
|
|
|
|
#include "meta/Version.h"
|
2016-04-06 22:09:30 +01:00
|
|
|
#include "Env.h"
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2017-03-11 00:39:45 +00:00
|
|
|
using namespace Meta;
|
|
|
|
|
|
|
|
static QString formatRequires(const VersionPtr &version)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
QStringList lines;
|
2017-03-11 00:39:45 +00:00
|
|
|
for (const Reference &ref : version->requires())
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-17 00:48:54 +00:00
|
|
|
const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->get(ref.uid())->humanReadable() : ref.uid();
|
2016-04-06 22:09:30 +01:00
|
|
|
if (ref.version().isEmpty())
|
|
|
|
{
|
|
|
|
lines.append(readable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lines.append(QString("%1 (%2)").arg(readable, ref.version()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines.join('\n');
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
PackagesPage::PackagesPage(QWidget *parent) :
|
2016-04-06 22:09:30 +01:00
|
|
|
QWidget(parent),
|
2017-03-12 15:00:06 +00:00
|
|
|
ui(new Ui::PackagesPage)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
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);
|
2017-03-11 00:39:45 +00:00
|
|
|
m_fileProxy->setSourceModel(ENV.metadataIndex().get());
|
2016-04-06 22:09:30 +01:00
|
|
|
ui->indexView->setModel(m_fileProxy);
|
|
|
|
|
|
|
|
m_filterProxy = new QSortFilterProxyModel(this);
|
2017-03-11 00:39:45 +00:00
|
|
|
m_filterProxy->setSortRole(VersionList::SortRole);
|
2016-04-06 22:09:30 +01:00
|
|
|
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);
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList);
|
|
|
|
connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion);
|
|
|
|
connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged);
|
2016-04-06 22:09:30 +01:00
|
|
|
|
|
|
|
updateCurrentVersionList(QModelIndex());
|
|
|
|
updateVersion();
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
PackagesPage::~PackagesPage()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
QIcon PackagesPage::icon() const
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-12 15:00:06 +00:00
|
|
|
return MMC->getThemedIcon("packages");
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::on_refreshIndexBtn_clicked()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-18 01:22:36 +00:00
|
|
|
ENV.metadataIndex()->load();
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::on_refreshFileBtn_clicked()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-11 00:39:45 +00:00
|
|
|
VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value<VersionListPtr>();
|
2016-04-06 22:09:30 +01:00
|
|
|
if (!list)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 01:22:36 +00:00
|
|
|
list->load();
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::on_refreshVersionBtn_clicked()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-11 00:39:45 +00:00
|
|
|
VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value<VersionPtr>();
|
2016-04-06 22:09:30 +01:00
|
|
|
if (!version)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 01:22:36 +00:00
|
|
|
version->load();
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::on_fileSearchEdit_textChanged(const QString &search)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
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(".*") + ".*");
|
|
|
|
}
|
|
|
|
}
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::on_versionSearchEdit_textChanged(const QString &search)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
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(".*") + ".*");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::updateCurrentVersionList(const QModelIndex &index)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
if (index.isValid())
|
|
|
|
{
|
2017-03-11 00:39:45 +00:00
|
|
|
VersionListPtr list = index.data(Index::ListPtrRole).value<VersionListPtr>();
|
2016-04-06 22:09:30 +01:00
|
|
|
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()));
|
2017-03-18 01:22:36 +00:00
|
|
|
list->load();
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
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);
|
2017-03-12 15:00:06 +00:00
|
|
|
ui->refreshFileBtn->setText(tr("Refresh"));
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br)
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
|
|
|
if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex()))
|
|
|
|
{
|
|
|
|
updateVersion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::updateVersion()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-11 00:39:45 +00:00
|
|
|
VersionPtr version = std::dynamic_pointer_cast<Version>(
|
|
|
|
ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value<BaseVersionPtr>());
|
2016-04-06 22:09:30 +01:00
|
|
|
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();
|
2017-03-12 15:00:06 +00:00
|
|
|
ui->refreshVersionBtn->setText(tr("Refresh"));
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-12 15:00:06 +00:00
|
|
|
void PackagesPage::opened()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2017-03-18 01:22:36 +00:00
|
|
|
ENV.metadataIndex()->load();
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|