NOISSUE feature complete setup wizard
This commit is contained in:
@ -1,7 +1,23 @@
|
||||
// Licensed under the Apache-2.0 license. See README.md for details.
|
||||
|
||||
#include "ProgressWidget.h"
|
||||
|
||||
/*
|
||||
textBrowser->setHtml(QApplication::translate("JavaWizardPage",
|
||||
"<html><body>"
|
||||
"<p>MultiMC sends anonymous usage statistics on every start of the application. This helps us decide what platforms and issues to focus on.</p>"
|
||||
"<p>The data is processed by Google Analytics, see their <a href=\"https://support.google.com/analytics/answer/6004245?hl=en\">article on the matter</a>.</p>"
|
||||
"<p>The following data is collected:</p>"
|
||||
"<ul><li>A random unique ID of the MultiMC installation.<br />It is stored in the application settings (multimc.cfg).</li>"
|
||||
"<li>Anonymized IP address.<br />Last octet is set to 0 by Google and not stored.</li>"
|
||||
"<li>MultiMC version.</li>"
|
||||
"<li>Operating system name, version and architecture.</li>"
|
||||
"<li>CPU architecture (kernel architecture on linux).</li>"
|
||||
"<li>Size of system memory.</li>"
|
||||
"<li>Java version, architecture and memory settings.</li></ul>"
|
||||
"<p>The analytics will activate on next start, unless you disable them in the settings.</p>"
|
||||
"<p>If we change the tracked information, analytics won't be active for the first run and you will see this page again.</p></body></html>", Q_NULLPTR));
|
||||
checkBox->setText(QApplication::translate("JavaWizardPage", "Enable Analytics", Q_NULLPTR));
|
||||
*/
|
||||
#include <QProgressBar>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
181
application/widgets/VersionSelectWidget.cpp
Normal file
181
application/widgets/VersionSelectWidget.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
#include "VersionSelectWidget.h"
|
||||
#include <QProgressBar>
|
||||
#include <QVBoxLayout>
|
||||
#include "VersionListView.h"
|
||||
#include <QHeaderView>
|
||||
#include <VersionProxyModel.h>
|
||||
#include <dialogs/CustomMessageBox.h>
|
||||
|
||||
VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent)
|
||||
: QWidget(parent), m_vlist(vlist)
|
||||
{
|
||||
setObjectName(QStringLiteral("VersionSelectWidget"));
|
||||
verticalLayout = new QVBoxLayout(this);
|
||||
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
|
||||
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_proxyModel = new VersionProxyModel(this);
|
||||
m_proxyModel->setSourceModel(vlist);
|
||||
|
||||
listView = new VersionListView(this);
|
||||
listView->setObjectName(QStringLiteral("listView"));
|
||||
listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
listView->setAlternatingRowColors(true);
|
||||
listView->setRootIsDecorated(false);
|
||||
listView->setItemsExpandable(false);
|
||||
listView->setWordWrap(true);
|
||||
listView->header()->setCascadingSectionResizes(true);
|
||||
listView->header()->setStretchLastSection(false);
|
||||
listView->setModel(m_proxyModel);
|
||||
listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
verticalLayout->addWidget(listView);
|
||||
|
||||
sneakyProgressBar = new QProgressBar(this);
|
||||
sneakyProgressBar->setObjectName(QStringLiteral("sneakyProgressBar"));
|
||||
sneakyProgressBar->setFormat(QStringLiteral("%p%"));
|
||||
verticalLayout->addWidget(sneakyProgressBar);
|
||||
sneakyProgressBar->setHidden(true);
|
||||
connect(listView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &VersionSelectWidget::currentRowChanged);
|
||||
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setEmptyString(QString emptyString)
|
||||
{
|
||||
listView->setEmptyString(emptyString);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setEmptyErrorString(QString emptyErrorString)
|
||||
{
|
||||
listView->setEmptyErrorString(emptyErrorString);
|
||||
}
|
||||
|
||||
VersionSelectWidget::~VersionSelectWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setResizeOn(int column)
|
||||
{
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents);
|
||||
resizeOnColumn = column;
|
||||
listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::initialize()
|
||||
{
|
||||
if (!m_vlist->isLoaded())
|
||||
{
|
||||
loadList();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_proxyModel->rowCount() == 0)
|
||||
{
|
||||
listView->setEmptyMode(VersionListView::String);
|
||||
}
|
||||
preselect();
|
||||
}
|
||||
}
|
||||
|
||||
void VersionSelectWidget::closeEvent(QCloseEvent * event)
|
||||
{
|
||||
if(loadTask)
|
||||
{
|
||||
loadTask->abort();
|
||||
loadTask->deleteLater();
|
||||
loadTask = nullptr;
|
||||
}
|
||||
QWidget::closeEvent(event);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::loadList()
|
||||
{
|
||||
if(loadTask)
|
||||
{
|
||||
return;
|
||||
}
|
||||
loadTask = m_vlist->getLoadTask();
|
||||
if (!loadTask)
|
||||
{
|
||||
return;
|
||||
}
|
||||
connect(loadTask, &Task::finished, this, &VersionSelectWidget::onTaskFinished);
|
||||
connect(loadTask, &Task::progress, this, &VersionSelectWidget::changeProgress);
|
||||
loadTask->start();
|
||||
sneakyProgressBar->setHidden(false);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::onTaskFinished()
|
||||
{
|
||||
if (!loadTask->successful())
|
||||
{
|
||||
CustomMessageBox::selectable(this, tr("Error"),
|
||||
tr("List update failed:\n%1").arg(loadTask->failReason()),
|
||||
QMessageBox::Warning)->show();
|
||||
if (m_proxyModel->rowCount() == 0)
|
||||
{
|
||||
listView->setEmptyMode(VersionListView::ErrorString);
|
||||
}
|
||||
}
|
||||
else if (m_proxyModel->rowCount() == 0)
|
||||
{
|
||||
listView->setEmptyMode(VersionListView::String);
|
||||
}
|
||||
sneakyProgressBar->setHidden(true);
|
||||
loadTask->deleteLater();
|
||||
loadTask = nullptr;
|
||||
preselect();
|
||||
}
|
||||
|
||||
void VersionSelectWidget::changeProgress(qint64 current, qint64 total)
|
||||
{
|
||||
sneakyProgressBar->setMaximum(total);
|
||||
sneakyProgressBar->setValue(current);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::currentRowChanged(const QModelIndex& current, const QModelIndex&)
|
||||
{
|
||||
auto variant = m_proxyModel->data(current, BaseVersionList::VersionPointerRole);
|
||||
emit selectedVersionChanged(variant.value<BaseVersionPtr>());
|
||||
}
|
||||
|
||||
void VersionSelectWidget::preselect()
|
||||
{
|
||||
if(preselectedAlready)
|
||||
return;
|
||||
preselectedAlready = true;
|
||||
selectRecommended();
|
||||
}
|
||||
|
||||
void VersionSelectWidget::selectRecommended()
|
||||
{
|
||||
auto idx = m_proxyModel->getRecommended();
|
||||
if(idx.isValid())
|
||||
{
|
||||
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||
}
|
||||
}
|
||||
|
||||
bool VersionSelectWidget::hasVersions() const
|
||||
{
|
||||
return m_proxyModel->rowCount(QModelIndex()) != 0;
|
||||
}
|
||||
|
||||
BaseVersionPtr VersionSelectWidget::selectedVersion() const
|
||||
{
|
||||
auto currentIndex = listView->selectionModel()->currentIndex();
|
||||
auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole);
|
||||
return variant.value<BaseVersionPtr>();
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter)
|
||||
{
|
||||
m_proxyModel->setFilter(role, filter, true);
|
||||
}
|
||||
|
||||
void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
|
||||
{
|
||||
m_proxyModel->setFilter(role, filter, false);
|
||||
}
|
76
application/widgets/VersionSelectWidget.h
Normal file
76
application/widgets/VersionSelectWidget.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* Copyright 2013-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 <QWidget>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "BaseVersionList.h"
|
||||
|
||||
class VersionProxyModel;
|
||||
class VersionListView;
|
||||
class QVBoxLayout;
|
||||
class QProgressBar;
|
||||
|
||||
class VersionSelectWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VersionSelectWidget(BaseVersionList *vlist, QWidget *parent = 0);
|
||||
~VersionSelectWidget();
|
||||
|
||||
//! loads the list if needed.
|
||||
void initialize();
|
||||
|
||||
//! Starts a task that loads the list.
|
||||
void loadList();
|
||||
|
||||
bool hasVersions() const;
|
||||
BaseVersionPtr selectedVersion() const;
|
||||
void selectRecommended();
|
||||
|
||||
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||
void setEmptyString(QString emptyString);
|
||||
void setEmptyErrorString(QString emptyErrorString);
|
||||
void setResizeOn(int column);
|
||||
void setUseLatest(const bool useLatest);
|
||||
|
||||
signals:
|
||||
void selectedVersionChanged(BaseVersionPtr version);
|
||||
|
||||
protected:
|
||||
virtual void closeEvent ( QCloseEvent* );
|
||||
|
||||
private slots:
|
||||
void onTaskFinished();
|
||||
void changeProgress(qint64 current, qint64 total);
|
||||
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &);
|
||||
|
||||
private:
|
||||
void preselect();
|
||||
|
||||
private:
|
||||
BaseVersionList *m_vlist = nullptr;
|
||||
VersionProxyModel *m_proxyModel = nullptr;
|
||||
int resizeOnColumn = 0;
|
||||
Task * loadTask = nullptr;
|
||||
bool preselectedAlready = false;
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout = nullptr;
|
||||
VersionListView *listView = nullptr;
|
||||
QProgressBar *sneakyProgressBar = nullptr;
|
||||
};
|
Reference in New Issue
Block a user