NOISSUE rename QObjectPtr to shared_qobject_ptr, introduce unique_qobject_ptr, refactor MainWindow to match
This commit is contained in:
parent
9ad99ac481
commit
125abf5027
@ -21,8 +21,14 @@
|
|||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtCore/QUrl>
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
|
||||||
|
#include <QtGui/QDesktopServices>
|
||||||
|
#include <QtGui/QKeyEvent>
|
||||||
|
|
||||||
#include <QtWidgets/QAction>
|
#include <QtWidgets/QAction>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <QtWidgets/QButtonGroup>
|
#include <QtWidgets/QButtonGroup>
|
||||||
@ -32,8 +38,61 @@
|
|||||||
#include <QtWidgets/QStatusBar>
|
#include <QtWidgets/QStatusBar>
|
||||||
#include <QtWidgets/QToolBar>
|
#include <QtWidgets/QToolBar>
|
||||||
#include <QtWidgets/QWidget>
|
#include <QtWidgets/QWidget>
|
||||||
|
#include <QtWidgets/QMenu>
|
||||||
|
#include <QtWidgets/QMessageBox>
|
||||||
|
#include <QtWidgets/QInputDialog>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QtWidgets/QToolButton>
|
||||||
|
#include <QtWidgets/QWidgetAction>
|
||||||
|
#include <QtWidgets/QProgressDialog>
|
||||||
|
#include <QtWidgets/QShortcut>
|
||||||
|
|
||||||
class Ui_MainWindow
|
#include <BaseInstance.h>
|
||||||
|
#include <Env.h>
|
||||||
|
#include <InstanceList.h>
|
||||||
|
#include <MMCZip.h>
|
||||||
|
#include <auth/flows/AuthenticateTask.h>
|
||||||
|
#include <auth/flows/RefreshTask.h>
|
||||||
|
#include <icons/IconList.h>
|
||||||
|
#include <java/JavaUtils.h>
|
||||||
|
#include <java/JavaVersionList.h>
|
||||||
|
#include <launch/LaunchTask.h>
|
||||||
|
#include <minecraft/MinecraftVersionList.h>
|
||||||
|
#include <minecraft/LwjglVersionList.h>
|
||||||
|
#include <minecraft/SkinUtils.h>
|
||||||
|
#include <net/URLConstants.h>
|
||||||
|
#include <net/NetJob.h>
|
||||||
|
#include <net/CacheDownload.h>
|
||||||
|
#include <news/NewsChecker.h>
|
||||||
|
#include <notifications/NotificationChecker.h>
|
||||||
|
#include <resources/Resource.h>
|
||||||
|
#include <tools/BaseProfiler.h>
|
||||||
|
#include <updater/DownloadTask.h>
|
||||||
|
#include <updater/UpdateChecker.h>
|
||||||
|
|
||||||
|
#include "InstancePageProvider.h"
|
||||||
|
#include "InstanceProxyModel.h"
|
||||||
|
#include "JavaCommon.h"
|
||||||
|
#include "LaunchInteraction.h"
|
||||||
|
#include "SettingsUI.h"
|
||||||
|
#include "groupview/GroupView.h"
|
||||||
|
#include "groupview/InstanceDelegate.h"
|
||||||
|
#include "widgets/LabeledToolButton.h"
|
||||||
|
#include "widgets/ServerStatus.h"
|
||||||
|
#include "dialogs/NewInstanceDialog.h"
|
||||||
|
#include "dialogs/ProgressDialog.h"
|
||||||
|
#include "dialogs/AboutDialog.h"
|
||||||
|
#include "dialogs/VersionSelectDialog.h"
|
||||||
|
#include "dialogs/CustomMessageBox.h"
|
||||||
|
#include "dialogs/IconPickerDialog.h"
|
||||||
|
#include "dialogs/CopyInstanceDialog.h"
|
||||||
|
#include "dialogs/AccountSelectDialog.h"
|
||||||
|
#include "dialogs/UpdateDialog.h"
|
||||||
|
#include "dialogs/EditAccountDialog.h"
|
||||||
|
#include "dialogs/NotificationDialog.h"
|
||||||
|
#include "dialogs/ExportInstanceDialog.h"
|
||||||
|
|
||||||
|
class MainWindow::Ui
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QAction *actionAddInstance;
|
QAction *actionAddInstance;
|
||||||
@ -310,91 +369,15 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Ui {
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow::Ui)
|
||||||
class MainWindow: public Ui_MainWindow {};
|
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QInputDialog>
|
|
||||||
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QWidgetAction>
|
|
||||||
#include <QProgressDialog>
|
|
||||||
#include <QShortcut>
|
|
||||||
|
|
||||||
#include <MMCZip.h>
|
|
||||||
|
|
||||||
#include "groupview/GroupView.h"
|
|
||||||
#include "groupview/InstanceDelegate.h"
|
|
||||||
#include "InstanceProxyModel.h"
|
|
||||||
|
|
||||||
#include "widgets/LabeledToolButton.h"
|
|
||||||
#include "widgets/ServerStatus.h"
|
|
||||||
|
|
||||||
#include "dialogs/NewInstanceDialog.h"
|
|
||||||
#include "dialogs/ProgressDialog.h"
|
|
||||||
#include "dialogs/AboutDialog.h"
|
|
||||||
#include "dialogs/VersionSelectDialog.h"
|
|
||||||
#include "dialogs/CustomMessageBox.h"
|
|
||||||
#include "dialogs/IconPickerDialog.h"
|
|
||||||
#include "dialogs/CopyInstanceDialog.h"
|
|
||||||
#include "dialogs/AccountSelectDialog.h"
|
|
||||||
#include "dialogs/UpdateDialog.h"
|
|
||||||
#include "dialogs/EditAccountDialog.h"
|
|
||||||
#include "dialogs/NotificationDialog.h"
|
|
||||||
#include "dialogs/ExportInstanceDialog.h"
|
|
||||||
|
|
||||||
#include "InstanceList.h"
|
|
||||||
#include "minecraft/MinecraftVersionList.h"
|
|
||||||
#include "minecraft/LwjglVersionList.h"
|
|
||||||
#include "icons/IconList.h"
|
|
||||||
#include "java/JavaVersionList.h"
|
|
||||||
|
|
||||||
#include "auth/flows/AuthenticateTask.h"
|
|
||||||
#include "auth/flows/RefreshTask.h"
|
|
||||||
|
|
||||||
#include "updater/DownloadTask.h"
|
|
||||||
|
|
||||||
#include "news/NewsChecker.h"
|
|
||||||
|
|
||||||
#include "net/URLConstants.h"
|
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include "Env.h"
|
|
||||||
|
|
||||||
#include "BaseInstance.h"
|
|
||||||
#include "launch/LaunchTask.h"
|
|
||||||
#include "java/JavaUtils.h"
|
|
||||||
#include "JavaCommon.h"
|
|
||||||
#include "InstancePageProvider.h"
|
|
||||||
#include "LaunchInteraction.h"
|
|
||||||
#include "SettingsUI.h"
|
|
||||||
#include "minecraft/SkinUtils.h"
|
|
||||||
#include "resources/Resource.h"
|
|
||||||
|
|
||||||
#include <updater/UpdateChecker.h>
|
|
||||||
#include <notifications/NotificationChecker.h>
|
|
||||||
#include <net/CacheDownload.h>
|
|
||||||
|
|
||||||
#include "tools/BaseProfiler.h"
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
// initialize the news checker
|
QString winTitle = tr("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString());
|
||||||
m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL));
|
|
||||||
|
|
||||||
QString winTitle =
|
|
||||||
QString("MultiMC 5 - Version %1").arg(BuildConfig.printableVersionString());
|
|
||||||
if (!BuildConfig.BUILD_PLATFORM.isEmpty())
|
if (!BuildConfig.BUILD_PLATFORM.isEmpty())
|
||||||
winTitle += " on " + BuildConfig.BUILD_PLATFORM;
|
{
|
||||||
|
winTitle += tr(" on ") + BuildConfig.BUILD_PLATFORM;
|
||||||
|
}
|
||||||
setWindowTitle(winTitle);
|
setWindowTitle(winTitle);
|
||||||
|
|
||||||
// OSX magic.
|
// OSX magic.
|
||||||
@ -424,6 +407,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
// Add the news label to the news toolbar.
|
// Add the news label to the news toolbar.
|
||||||
{
|
{
|
||||||
|
m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL));
|
||||||
newsLabel = new QToolButton();
|
newsLabel = new QToolButton();
|
||||||
newsLabel->setIcon(MMC->getThemedIcon("news"));
|
newsLabel->setIcon(MMC->getThemedIcon("news"));
|
||||||
newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
@ -441,41 +425,21 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
view = new GroupView(ui->centralWidget);
|
view = new GroupView(ui->centralWidget);
|
||||||
|
|
||||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
// view->setCategoryDrawer(drawer);
|
view->setItemDelegate(new ListViewDelegate());
|
||||||
// view->setCollapsibleBlocks(true);
|
view->setFrameShape(QFrame::NoFrame);
|
||||||
// view->setViewMode(QListView::IconMode);
|
|
||||||
// view->setFlow(QListView::LeftToRight);
|
|
||||||
// view->setWordWrap(true);
|
|
||||||
// view->setMouseTracking(true);
|
|
||||||
// view->viewport()->setAttribute(Qt::WA_Hover);
|
|
||||||
auto delegate = new ListViewDelegate();
|
|
||||||
view->setItemDelegate(delegate);
|
|
||||||
// view->setSpacing(10);
|
|
||||||
// view->setUniformItemWidths(true);
|
|
||||||
|
|
||||||
// do not show ugly blue border on the mac
|
// do not show ugly blue border on the mac
|
||||||
view->setAttribute(Qt::WA_MacShowFocusRect, false);
|
view->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
view->installEventFilter(this);
|
view->installEventFilter(this);
|
||||||
|
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(view, &QWidget::customContextMenuRequested, this, &MainWindow::showInstanceContextMenu);
|
||||||
|
|
||||||
proxymodel = new InstanceProxyModel(this);
|
proxymodel = new InstanceProxyModel(this);
|
||||||
// proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole);
|
|
||||||
// proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole);
|
|
||||||
// proxymodel->setDynamicSortFilter ( true );
|
|
||||||
|
|
||||||
// FIXME: instList should be global-ish, or at least not tied to the main window...
|
|
||||||
// maybe the application itself?
|
|
||||||
proxymodel->setSourceModel(MMC->instances().get());
|
proxymodel->setSourceModel(MMC->instances().get());
|
||||||
proxymodel->sort(0);
|
proxymodel->sort(0);
|
||||||
view->setFrameShape(QFrame::NoFrame);
|
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
|
||||||
|
|
||||||
view->setModel(proxymodel);
|
view->setModel(proxymodel);
|
||||||
|
|
||||||
connect(proxymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), SLOT(instanceDataChanged(QModelIndex,QModelIndex)));
|
|
||||||
|
|
||||||
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
connect(view, SIGNAL(customContextMenuRequested(const QPoint &)), this,
|
|
||||||
SLOT(showInstanceContextMenu(const QPoint &)));
|
|
||||||
|
|
||||||
ui->horizontalLayout->addWidget(view);
|
ui->horizontalLayout->addWidget(view);
|
||||||
}
|
}
|
||||||
// The cat background
|
// The cat background
|
||||||
@ -486,19 +450,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
setCatBackground(cat_enable);
|
setCatBackground(cat_enable);
|
||||||
}
|
}
|
||||||
// start instance when double-clicked
|
// start instance when double-clicked
|
||||||
connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this,
|
connect(view, &GroupView::doubleClicked, this, &MainWindow::instanceActivated);
|
||||||
SLOT(instanceActivated(const QModelIndex &)));
|
|
||||||
// track the selection -- update the instance toolbar
|
// track the selection -- update the instance toolbar
|
||||||
connect(view->selectionModel(),
|
connect(view->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::instanceChanged);
|
||||||
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this,
|
|
||||||
SLOT(instanceChanged(const QModelIndex &, const QModelIndex &)));
|
|
||||||
|
|
||||||
// track icon changes and update the toolbar!
|
// track icon changes and update the toolbar!
|
||||||
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
connect(ENV.icons().get(), &IconList::iconUpdated, this, &MainWindow::iconUpdated);
|
||||||
|
|
||||||
// model reset -> selection is invalid. All the instance pointers are wrong.
|
// model reset -> selection is invalid. All the instance pointers are wrong.
|
||||||
// FIXME: stop using POINTERS everywhere
|
connect(MMC->instances().get(), &InstanceList::dataIsInvalid, this, &MainWindow::selectionBad);
|
||||||
connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad()));
|
|
||||||
|
|
||||||
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
||||||
m_statusRight = new ServerStatus(this);
|
m_statusRight = new ServerStatus(this);
|
||||||
@ -513,6 +474,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
accountMenu = new QMenu(this);
|
accountMenu = new QMenu(this);
|
||||||
manageAccountsAction = new QAction(tr("Manage Accounts"), this);
|
manageAccountsAction = new QAction(tr("Manage Accounts"), this);
|
||||||
manageAccountsAction->setCheckable(false);
|
manageAccountsAction->setCheckable(false);
|
||||||
|
manageAccountsAction->setIcon(MMC->getThemedIcon("accounts"));
|
||||||
connect(manageAccountsAction, SIGNAL(triggered(bool)), this,
|
connect(manageAccountsAction, SIGNAL(triggered(bool)), this,
|
||||||
SLOT(on_actionManageAccounts_triggered()));
|
SLOT(on_actionManageAccounts_triggered()));
|
||||||
|
|
||||||
@ -547,18 +509,19 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
for (int i = 0; i < accounts->count(); i++)
|
for (int i = 0; i < accounts->count(); i++)
|
||||||
{
|
{
|
||||||
auto account = accounts->at(i);
|
auto account = accounts->at(i);
|
||||||
if (account != nullptr)
|
if (!account)
|
||||||
{
|
{
|
||||||
|
qWarning() << "Null account at index" << i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (auto profile : account->profiles())
|
for (auto profile : account->profiles())
|
||||||
{
|
{
|
||||||
auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
|
auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
|
||||||
auto action = CacheDownload::make(
|
auto action = CacheDownload::make(QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
||||||
QUrl("https://" + URLConstants::SKINS_BASE + profile.id + ".png"), meta);
|
|
||||||
skin_dls.append(action);
|
skin_dls.append(action);
|
||||||
meta->stale = true;
|
meta->stale = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!skin_dls.isEmpty())
|
if (!skin_dls.isEmpty())
|
||||||
{
|
{
|
||||||
auto job = new NetJob("Startup player skins download");
|
auto job = new NetJob("Startup player skins download");
|
||||||
@ -620,8 +583,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
|
||||||
delete proxymodel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::skinJobFinished()
|
void MainWindow::skinJobFinished()
|
||||||
@ -760,14 +721,6 @@ void MainWindow::repopulateAccountsMenu()
|
|||||||
for (int i = 0; i < accounts->count(); i++)
|
for (int i = 0; i < accounts->count(); i++)
|
||||||
{
|
{
|
||||||
MojangAccountPtr account = accounts->at(i);
|
MojangAccountPtr account = accounts->at(i);
|
||||||
|
|
||||||
// Styling hack
|
|
||||||
/*
|
|
||||||
QAction *section = new QAction(account->username(), this);
|
|
||||||
section->setEnabled(false);
|
|
||||||
accountMenu->addAction(section);
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (auto profile : account->profiles())
|
for (auto profile : account->profiles())
|
||||||
{
|
{
|
||||||
QAction *action = new QAction(profile.name, this);
|
QAction *action = new QAction(profile.name, this);
|
||||||
@ -1459,16 +1412,19 @@ void MainWindow::on_mainToolBar_visibilityChanged(bool)
|
|||||||
|
|
||||||
void MainWindow::on_actionDeleteInstance_triggered()
|
void MainWindow::on_actionDeleteInstance_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (!m_selectedInstance)
|
||||||
{
|
{
|
||||||
auto response = CustomMessageBox::selectable(
|
return;
|
||||||
this, tr("CAREFUL!"), tr("About to delete: %1\nThis is permanent and will completely erase all data, even for tracked instances!\nAre you sure?").arg(m_selectedInstance->name()),
|
}
|
||||||
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No)->exec();
|
auto response = CustomMessageBox::selectable(this, tr("CAREFUL!"), tr("About to delete: %1\nThis is permanent and will completely erase "
|
||||||
|
"all data, even for tracked instances!\nAre you sure?")
|
||||||
|
.arg(m_selectedInstance->name()),
|
||||||
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No)
|
||||||
|
->exec();
|
||||||
if (response == QMessageBox::Yes)
|
if (response == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
m_selectedInstance->nuke();
|
m_selectedInstance->nuke();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExportInstance_triggered()
|
void MainWindow::on_actionExportInstance_triggered()
|
||||||
@ -1520,17 +1476,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
QApplication::exit();
|
QApplication::exit();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos)
|
|
||||||
{
|
|
||||||
QMenu *instContextMenu = new QMenu("Instance", this);
|
|
||||||
|
|
||||||
// Add the actions from the toolbar to the context menu.
|
|
||||||
instContextMenu->addActions(ui->instanceToolBar->actions());
|
|
||||||
|
|
||||||
instContextMenu->exec(view->mapToGlobal(pos));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void MainWindow::instanceActivated(QModelIndex index)
|
void MainWindow::instanceActivated(QModelIndex index)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -1561,7 +1507,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
|
|||||||
|
|
||||||
void MainWindow::launch(InstancePtr instance, bool online, BaseProfilerFactory* profiler)
|
void MainWindow::launch(InstancePtr instance, bool online, BaseProfilerFactory* profiler)
|
||||||
{
|
{
|
||||||
m_launchController = std::make_shared<LaunchController>();
|
m_launchController.reset(new LaunchController());
|
||||||
m_launchController->setInstance(instance);
|
m_launchController->setInstance(instance);
|
||||||
m_launchController->setOnline(online);
|
m_launchController->setOnline(online);
|
||||||
m_launchController->setParentWidget(this);
|
m_launchController->setParentWidget(this);
|
||||||
@ -1569,19 +1515,6 @@ void MainWindow::launch(InstancePtr instance, bool online, BaseProfilerFactory*
|
|||||||
m_launchController->launch();
|
m_launchController->launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void MainWindow::onGameUpdateError(QString error)
|
|
||||||
{
|
|
||||||
CustomMessageBox::selectable(this, tr("Error updating instance"), error,
|
|
||||||
QMessageBox::Warning)->show();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void MainWindow::taskStart()
|
|
||||||
{
|
|
||||||
// Nothing to do here yet.
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::taskEnd()
|
void MainWindow::taskEnd()
|
||||||
{
|
{
|
||||||
QObject *sender = QObject::sender();
|
QObject *sender = QObject::sender();
|
||||||
@ -1593,7 +1526,6 @@ void MainWindow::taskEnd()
|
|||||||
|
|
||||||
void MainWindow::startTask(Task *task)
|
void MainWindow::startTask(Task *task)
|
||||||
{
|
{
|
||||||
connect(task, SIGNAL(started()), SLOT(taskStart()));
|
|
||||||
connect(task, SIGNAL(succeeded()), SLOT(taskEnd()));
|
connect(task, SIGNAL(succeeded()), SLOT(taskEnd()));
|
||||||
connect(task, SIGNAL(failed(QString)), SLOT(taskEnd()));
|
connect(task, SIGNAL(failed(QString)), SLOT(taskEnd()));
|
||||||
task->start();
|
task->start();
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -33,32 +35,26 @@ class LabeledToolButton;
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
class MinecraftLauncher;
|
class MinecraftLauncher;
|
||||||
class BaseProfilerFactory;
|
class BaseProfilerFactory;
|
||||||
|
class GroupView;
|
||||||
namespace Ui
|
class ServerStatus;
|
||||||
{
|
|
||||||
class MainWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
class Ui;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
void closeEvent(QCloseEvent *event);
|
virtual bool eventFilter(QObject *obj, QEvent *ev) override;
|
||||||
|
virtual void closeEvent(QCloseEvent *event) override;
|
||||||
// Browser Dialog
|
|
||||||
void openWebPage(QUrl url);
|
|
||||||
|
|
||||||
void checkSetDefaultJava();
|
void checkSetDefaultJava();
|
||||||
void checkInstancePathForProblems();
|
void checkInstancePathForProblems();
|
||||||
|
|
||||||
private
|
private slots:
|
||||||
slots:
|
|
||||||
void setSelectedInstanceById(const QString &id);
|
|
||||||
|
|
||||||
void onCatToggled(bool);
|
void onCatToggled(bool);
|
||||||
|
|
||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
@ -101,8 +97,6 @@ slots:
|
|||||||
|
|
||||||
void on_mainToolBar_visibilityChanged(bool);
|
void on_mainToolBar_visibilityChanged(bool);
|
||||||
|
|
||||||
// void on_instanceView_customContextMenuRequested(const QPoint &pos);
|
|
||||||
|
|
||||||
void on_actionLaunchInstance_triggered();
|
void on_actionLaunchInstance_triggered();
|
||||||
|
|
||||||
void on_actionLaunchInstanceOffline_triggered();
|
void on_actionLaunchInstanceOffline_triggered();
|
||||||
@ -119,10 +113,11 @@ slots:
|
|||||||
|
|
||||||
void on_actionScreenshots_triggered();
|
void on_actionScreenshots_triggered();
|
||||||
|
|
||||||
void taskStart();
|
|
||||||
void taskEnd();
|
void taskEnd();
|
||||||
|
|
||||||
// called when an icon is changed in the icon model.
|
/**
|
||||||
|
* called when an icon is changed in the icon model.
|
||||||
|
*/
|
||||||
void iconUpdated(QString);
|
void iconUpdated(QString);
|
||||||
|
|
||||||
void showInstanceContextMenu(const QPoint &);
|
void showInstanceContextMenu(const QPoint &);
|
||||||
@ -130,8 +125,7 @@ slots:
|
|||||||
void updateToolsMenu();
|
void updateToolsMenu();
|
||||||
|
|
||||||
void skinJobFinished();
|
void skinJobFinished();
|
||||||
public
|
|
||||||
slots:
|
|
||||||
void instanceActivated(QModelIndex);
|
void instanceActivated(QModelIndex);
|
||||||
|
|
||||||
void instanceChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void instanceChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
@ -161,10 +155,10 @@ slots:
|
|||||||
*/
|
*/
|
||||||
void downloadUpdates(GoUpdate::Status status);
|
void downloadUpdates(GoUpdate::Status status);
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
bool eventFilter(QObject *obj, QEvent *ev);
|
|
||||||
void setCatBackground(bool enabled);
|
void setCatBackground(bool enabled);
|
||||||
void updateInstanceToolIcon(QString new_icon);
|
void updateInstanceToolIcon(QString new_icon);
|
||||||
|
void setSelectedInstanceById(const QString &id);
|
||||||
|
|
||||||
void waitForMinecraftVersions();
|
void waitForMinecraftVersions();
|
||||||
InstancePtr instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version);
|
InstancePtr instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version);
|
||||||
@ -172,28 +166,32 @@ protected:
|
|||||||
void finalizeInstance(InstancePtr inst);
|
void finalizeInstance(InstancePtr inst);
|
||||||
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
|
void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
|
||||||
|
|
||||||
|
/// open a web page in the default browser
|
||||||
|
void openWebPage(QUrl url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
std::unique_ptr<Ui> ui;
|
||||||
class GroupView *view;
|
|
||||||
|
// these are managed by Qt's memory management model!
|
||||||
|
GroupView *view;
|
||||||
InstanceProxyModel *proxymodel;
|
InstanceProxyModel *proxymodel;
|
||||||
NetJobPtr skin_download_job;
|
|
||||||
LabeledToolButton *renameButton;
|
LabeledToolButton *renameButton;
|
||||||
QToolButton *changeIconButton;
|
QToolButton *changeIconButton;
|
||||||
QToolButton *newsLabel;
|
QToolButton *newsLabel;
|
||||||
|
QLabel *m_statusLeft;
|
||||||
|
ServerStatus *m_statusRight;
|
||||||
|
QMenu *accountMenu;
|
||||||
|
QToolButton *accountMenuButton;
|
||||||
|
QAction *manageAccountsAction;
|
||||||
|
|
||||||
std::shared_ptr<NewsChecker> m_newsChecker;
|
unique_qobject_ptr<NetJob> skin_download_job;
|
||||||
std::shared_ptr<NotificationChecker> m_notificationChecker;
|
unique_qobject_ptr<NewsChecker> m_newsChecker;
|
||||||
std::shared_ptr<LaunchController> m_launchController;
|
unique_qobject_ptr<NotificationChecker> m_notificationChecker;
|
||||||
|
unique_qobject_ptr<LaunchController> m_launchController;
|
||||||
|
|
||||||
InstancePtr m_selectedInstance;
|
InstancePtr m_selectedInstance;
|
||||||
QString m_currentInstIcon;
|
QString m_currentInstIcon;
|
||||||
|
|
||||||
|
// managed by the application object
|
||||||
Task *m_versionLoadTask;
|
Task *m_versionLoadTask;
|
||||||
|
|
||||||
QLabel *m_statusLeft;
|
|
||||||
class ServerStatus *m_statusRight;
|
|
||||||
|
|
||||||
QMenu *accountMenu;
|
|
||||||
QToolButton *accountMenuButton;
|
|
||||||
QAction *manageAccountsAction;
|
|
||||||
};
|
};
|
||||||
|
@ -70,5 +70,5 @@ private:
|
|||||||
Ui::InstanceSettingsPage *ui;
|
Ui::InstanceSettingsPage *ui;
|
||||||
BaseInstance *m_instance;
|
BaseInstance *m_instance;
|
||||||
SettingsObjectPtr m_settings;
|
SettingsObjectPtr m_settings;
|
||||||
QObjectPtr<JavaCommon::TestCheck> checker;
|
unique_qobject_ptr<JavaCommon::TestCheck> checker;
|
||||||
};
|
};
|
||||||
|
@ -68,5 +68,5 @@ slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::JavaPage *ui;
|
Ui::JavaPage *ui;
|
||||||
QObjectPtr<JavaCommon::TestCheck> checker;
|
unique_qobject_ptr<JavaCommon::TestCheck> checker;
|
||||||
};
|
};
|
||||||
|
@ -210,6 +210,13 @@
|
|||||||
<file>32x32/noaccount.png</file>
|
<file>32x32/noaccount.png</file>
|
||||||
<file>48x48/noaccount.png</file>
|
<file>48x48/noaccount.png</file>
|
||||||
|
|
||||||
|
<!-- and the same again. TODO: make a nice accounts icon -->
|
||||||
|
<file alias="8x8/accounts.png">8x8/noaccount.png</file>
|
||||||
|
<file alias="16x16/accounts.png">16x16/noaccount.png</file>
|
||||||
|
<file alias="24x24/accounts.png">24x24/noaccount.png</file>
|
||||||
|
<file alias="32x32/accounts.png">32x32/noaccount.png</file>
|
||||||
|
<file alias="48x48/accounts.png">48x48/noaccount.png</file>
|
||||||
|
|
||||||
<!-- Log file, LGPL, http://www.iconarchive.com/show/crystal-clear-icons-by-everaldo/Mimetype-text-icon.html -->
|
<!-- Log file, LGPL, http://www.iconarchive.com/show/crystal-clear-icons-by-everaldo/Mimetype-text-icon.html -->
|
||||||
<file>16x16/log.png</file>
|
<file>16x16/log.png</file>
|
||||||
<file>24x24/log.png</file>
|
<file>24x24/log.png</file>
|
||||||
|
@ -1,26 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace details
|
||||||
|
{
|
||||||
|
struct DeleteQObjectLater
|
||||||
|
{
|
||||||
|
void operator()(QObject *obj) const
|
||||||
|
{
|
||||||
|
obj->deleteLater();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* A unique pointer class with unique pointer semantics intended for derivates of QObject
|
||||||
|
* Calls deleteLater() instead of destroying the contained object immediately
|
||||||
|
*/
|
||||||
|
template<typename T> using unique_qobject_ptr = std::unique_ptr<T, details::DeleteQObjectLater>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pointer class with the usual shared pointer semantics intended for derivates of QObject
|
* A shared pointer class with shared pointer semantics intended for derivates of QObject
|
||||||
* Calls deleteLater() instead of destroying the contained object immediately
|
* Calls deleteLater() instead of destroying the contained object immediately
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class QObjectPtr
|
class shared_qobject_ptr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QObjectPtr(){}
|
shared_qobject_ptr(){}
|
||||||
QObjectPtr(T * wrap)
|
shared_qobject_ptr(T * wrap)
|
||||||
{
|
{
|
||||||
reset(wrap);
|
reset(wrap);
|
||||||
}
|
}
|
||||||
QObjectPtr(const QObjectPtr<T>& other)
|
shared_qobject_ptr(const shared_qobject_ptr<T>& other)
|
||||||
{
|
{
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
}
|
}
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
QObjectPtr(const QObjectPtr<Derived> &other)
|
shared_qobject_ptr(const shared_qobject_ptr<Derived> &other)
|
||||||
{
|
{
|
||||||
m_ptr = other.unwrap();
|
m_ptr = other.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -424,7 +424,7 @@ void ForgeListLoadTask::listDownloaded()
|
|||||||
|
|
||||||
void ForgeListLoadTask::listFailed()
|
void ForgeListLoadTask::listFailed()
|
||||||
{
|
{
|
||||||
auto reply = listDownload->m_reply;
|
auto &reply = listDownload->m_reply;
|
||||||
if (reply)
|
if (reply)
|
||||||
{
|
{
|
||||||
qCritical() << "Getting forge version list failed: " << reply->errorString();
|
qCritical() << "Getting forge version list failed: " << reply->errorString();
|
||||||
@ -437,7 +437,7 @@ void ForgeListLoadTask::listFailed()
|
|||||||
|
|
||||||
void ForgeListLoadTask::gradleListFailed()
|
void ForgeListLoadTask::gradleListFailed()
|
||||||
{
|
{
|
||||||
auto reply = gradleListDownload->m_reply;
|
auto &reply = gradleListDownload->m_reply;
|
||||||
if (reply)
|
if (reply)
|
||||||
{
|
{
|
||||||
qCritical() << "Getting forge version list failed: " << reply->errorString();
|
qCritical() << "Getting forge version list failed: " << reply->errorString();
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// the network reply
|
/// the network reply
|
||||||
QObjectPtr<QNetworkReply> m_reply;
|
unique_qobject_ptr<QNetworkReply> m_reply;
|
||||||
|
|
||||||
/// the content of the content-type header
|
/// the content of the content-type header
|
||||||
QString m_content_type;
|
QString m_content_type;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
class NetJob;
|
class NetJob;
|
||||||
typedef QObjectPtr<NetJob> NetJobPtr;
|
typedef shared_qobject_ptr<NetJob> NetJobPtr;
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT NetJob : public Task
|
class MULTIMC_LOGIC_EXPORT NetJob : public Task
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user