NOISSUE add option to open global settings from instance settings

This should hopefully giude people towards using the right thing.
This commit is contained in:
Petr Mrázek 2019-06-01 12:28:53 +02:00
parent 59e1ed3d87
commit 932160818e
10 changed files with 55 additions and 53 deletions

View File

@ -64,9 +64,6 @@ SET(MULTIMC_SOURCES
themes/SystemTheme.cpp
themes/SystemTheme.h
# GUI - settings-specific wrappers for paged dialog
SettingsUI.h
# Processes
LaunchController.h
LaunchController.cpp

View File

@ -9,7 +9,6 @@
#include "InstanceWindow.h"
#include "BuildConfig.h"
#include "JavaCommon.h"
#include "SettingsUI.h"
#include <QLineEdit>
#include <QInputDialog>
#include <tasks/Task.h>
@ -53,7 +52,7 @@ void LaunchController::login()
if (reply == QMessageBox::Yes)
{
// Open the account manager.
SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts");
MMC->ShowGlobalSettings(m_parentWidget, "accounts");
}
}
else if (account.get() == nullptr)

View File

@ -70,7 +70,6 @@
#include "InstanceProxyModel.h"
#include "JavaCommon.h"
#include "LaunchController.h"
#include "SettingsUI.h"
#include "groupview/GroupView.h"
#include "groupview/InstanceDelegate.h"
#include "widgets/LabeledToolButton.h"
@ -703,6 +702,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
// model reset -> selection is invalid. All the instance pointers are wrong.
connect(MMC->instances().get(), &InstanceList::dataIsInvalid, this, &MainWindow::selectionBad);
// When the global settings page closes, we want to know about it and update our state
connect(MMC, &MultiMC::globalSettingsClosed, this, &MainWindow::globalSettingsClosed);
m_statusLeft = new QLabel(tr("No instance selected"), this);
m_statusRight = new ServerStatus(this);
statusBar()->addPermanentWidget(m_statusLeft, 1);
@ -1572,7 +1574,11 @@ void MainWindow::checkForUpdates()
void MainWindow::on_actionSettings_triggered()
{
SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), this, "global-settings");
MMC->ShowGlobalSettings(this, "global-settings");
}
void MainWindow::globalSettingsClosed()
{
// FIXME: quick HACK to make this work. improve, optimize.
MMC->instances()->loadList();
proxymodel->invalidate();
@ -1608,7 +1614,7 @@ void MainWindow::on_actionScreenshots_triggered()
void MainWindow::on_actionManageAccounts_triggered()
{
SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), this, "accounts");
MMC->ShowGlobalSettings(this, "accounts");
}
void MainWindow::on_actionReportBug_triggered()

View File

@ -181,6 +181,8 @@ private slots:
void konamiTriggered();
void globalSettingsClosed();
private:
void addInstance(QString url = QString());
void activateInstance(InstancePtr instance);

View File

@ -66,6 +66,8 @@
#include <ganalytics.h>
#include <sys.h>
#include "pagedialog/PageDialog.h"
#if defined Q_OS_WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -1088,6 +1090,20 @@ void MultiMC::controllerFailed(const QString& error)
}
}
void MultiMC::ShowGlobalSettings(class QWidget* parent, QString open_page)
{
if(!m_globalSettingsProvider) {
return;
}
emit globalSettingsAboutToOpen();
{
SettingsObject::Lock lock(MMC->settings());
PageDialog dlg(m_globalSettingsProvider.get(), open_page, parent);
dlg.exec();
}
emit globalSettingsClosed();
}
MainWindow* MultiMC::showMainWindow(bool minimized)
{
if(m_mainWindow)

View File

@ -65,11 +65,6 @@ public:
return m_settings;
}
std::shared_ptr<GenericPageProvider> globalSettingsPages() const
{
return m_globalSettingsProvider;
}
qint64 timeSinceStart() const
{
return startTime.msecsTo(QDateTime::currentDateTime());
@ -146,8 +141,12 @@ public:
void updateIsRunning(bool running);
bool updatesAreAllowed();
void ShowGlobalSettings(class QWidget * parent, QString open_page = QString());
signals:
void updateAllowedChanged(bool status);
void globalSettingsAboutToOpen();
void globalSettingsClosed();
public slots:
bool launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);

View File

@ -1,26 +0,0 @@
#pragma once
#include "pages/BasePageProvider.h"
#include "MultiMC.h"
#include "pagedialog/PageDialog.h"
#include "InstancePageProvider.h"
#include <settings/SettingsObject.h>
#include <BaseInstance.h>
/*
* FIXME: this is a fragment. find a better place for it.
*/
namespace SettingsUI
{
template <typename T>
void ShowPageDialog(T raw_provider, QWidget * parent, QString open_page = QString())
{
auto provider = std::dynamic_pointer_cast<BasePageProvider>(raw_provider);
if(!provider)
return;
{
SettingsObject::Lock lock(MMC->settings());
PageDialog dlg(provider.get(), open_page, parent);
dlg.exec();
}
}
}

View File

@ -21,6 +21,9 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
ui->setupUi(this);
auto sysMB = Sys::getSystemRam() / Sys::megabyte;
ui->maxMemSpinBox->setMaximum(sysMB);
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
connect(MMC, &MultiMC::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
connect(MMC, &MultiMC::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
loadSettings();
}
@ -34,6 +37,11 @@ InstanceSettingsPage::~InstanceSettingsPage()
delete ui;
}
void InstanceSettingsPage::globalSettingsButtonClicked(bool)
{
MMC->ShowGlobalSettings(this, "global-settings");
}
bool InstanceSettingsPage::apply()
{
applySettings();

View File

@ -66,6 +66,8 @@ private slots:
void checkerFinished();
void globalSettingsButtonClicked(bool checked);
private:
Ui::InstanceSettingsPage *ui;
BaseInstance *m_instance;

View File

@ -6,23 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>522</height>
<width>738</width>
<height>804</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
<item>
<widget class="QCommandLinkButton" name="openGlobalJavaSettingsButton">
<property name="text">
<string>Open Global Settings</string>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
<property name="description">
<string>The settings here are overrides for global settings.</string>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="settingsTabs">
<property name="tabShape">
@ -367,6 +365,7 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>openGlobalJavaSettingsButton</tabstop>
<tabstop>settingsTabs</tabstop>
<tabstop>javaSettingsGroupBox</tabstop>
<tabstop>javaPathTextBox</tabstop>