GH-1053 split settings dialog creation to its own namespace
This commit is contained in:
		@@ -136,6 +136,10 @@ SET(MULTIMC_SOURCES
 | 
			
		||||
	ConsoleWindow.h
 | 
			
		||||
	ConsoleWindow.cpp
 | 
			
		||||
 | 
			
		||||
	# GUI - settings-specific wrappers for paged dialog
 | 
			
		||||
	SettingsUI.h
 | 
			
		||||
	SettingsUI.cpp
 | 
			
		||||
 | 
			
		||||
	# Processes
 | 
			
		||||
	LaunchController.h
 | 
			
		||||
	LaunchController.cpp
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#include "ConsoleWindow.h"
 | 
			
		||||
#include "BuildConfig.h"
 | 
			
		||||
#include "JavaCommon.h"
 | 
			
		||||
#include "SettingsUI.h"
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QInputDialog>
 | 
			
		||||
#include <tasks/Task.h>
 | 
			
		||||
@@ -45,7 +46,7 @@ void LaunchController::login()
 | 
			
		||||
		if (reply == QMessageBox::Yes)
 | 
			
		||||
		{
 | 
			
		||||
			// Open the account manager.
 | 
			
		||||
			//on_actionManageAccounts_triggered();
 | 
			
		||||
			SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else if (account.get() == nullptr)
 | 
			
		||||
 
 | 
			
		||||
@@ -350,15 +350,6 @@ namespace Ui {
 | 
			
		||||
#include "dialogs/NotificationDialog.h"
 | 
			
		||||
#include "dialogs/ExportInstanceDialog.h"
 | 
			
		||||
 | 
			
		||||
#include "pages/global/MultiMCPage.h"
 | 
			
		||||
#include "pages/global/ExternalToolsPage.h"
 | 
			
		||||
#include "pages/global/AccountListPage.h"
 | 
			
		||||
#include "pages/global/ProxyPage.h"
 | 
			
		||||
#include "pages/global/JavaPage.h"
 | 
			
		||||
#include "pages/global/MinecraftPage.h"
 | 
			
		||||
 | 
			
		||||
#include "pagedialog/PageDialog.h"
 | 
			
		||||
 | 
			
		||||
#include "InstanceList.h"
 | 
			
		||||
#include "minecraft/MinecraftVersionList.h"
 | 
			
		||||
#include "minecraft/LwjglVersionList.h"
 | 
			
		||||
@@ -382,6 +373,7 @@ namespace Ui {
 | 
			
		||||
#include "JavaCommon.h"
 | 
			
		||||
#include "InstancePageProvider.h"
 | 
			
		||||
#include "LaunchController.h"
 | 
			
		||||
#include "SettingsUI.h"
 | 
			
		||||
#include "minecraft/SkinUtils.h"
 | 
			
		||||
#include "resources/Resource.h"
 | 
			
		||||
 | 
			
		||||
@@ -541,17 +533,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
 | 
			
		||||
 | 
			
		||||
	ui->mainToolBar->addAction(accountMenuButtonAction);
 | 
			
		||||
 | 
			
		||||
	// set up global pages dialog
 | 
			
		||||
	{
 | 
			
		||||
		m_globalSettingsProvider = std::make_shared<GenericPageProvider>(tr("Settings"));
 | 
			
		||||
		m_globalSettingsProvider->addPage<MultiMCPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<MinecraftPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<JavaPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<ProxyPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<ExternalToolsPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<AccountListPage>();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Update the menu when the active account changes.
 | 
			
		||||
	// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
 | 
			
		||||
	// Template hell sucks...
 | 
			
		||||
@@ -1388,28 +1369,9 @@ void MainWindow::on_actionCheckUpdate_triggered()
 | 
			
		||||
	updater->checkForUpdate(MMC->settings()->get("UpdateChannel").toString(), true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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, open_page, parent);
 | 
			
		||||
		dlg.exec();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShowInstancePageDialog(InstancePtr instance, QWidget * parent, QString open_page = QString())
 | 
			
		||||
{
 | 
			
		||||
	auto provider = std::make_shared<InstancePageProvider>(instance);
 | 
			
		||||
	ShowPageDialog(provider, parent, open_page);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionSettings_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowPageDialog(m_globalSettingsProvider, this, "global-settings");
 | 
			
		||||
	SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), this, "global-settings");
 | 
			
		||||
	// FIXME: quick HACK to make this work. improve, optimize.
 | 
			
		||||
	proxymodel->invalidate();
 | 
			
		||||
	proxymodel->sort(0);
 | 
			
		||||
@@ -1419,28 +1381,28 @@ void MainWindow::on_actionSettings_triggered()
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionInstanceSettings_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowInstancePageDialog(m_selectedInstance, this, "settings");
 | 
			
		||||
	SettingsUI::ShowInstancePageDialog(m_selectedInstance, this, "settings");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionEditInstNotes_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowInstancePageDialog(m_selectedInstance, this, "notes");
 | 
			
		||||
	SettingsUI::ShowInstancePageDialog(m_selectedInstance, this, "notes");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionEditInstance_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowInstancePageDialog(m_selectedInstance, this);
 | 
			
		||||
	SettingsUI::ShowInstancePageDialog(m_selectedInstance, this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionScreenshots_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowInstancePageDialog(m_selectedInstance, this, "screenshots");
 | 
			
		||||
	SettingsUI::ShowInstancePageDialog(m_selectedInstance, this, "screenshots");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionManageAccounts_triggered()
 | 
			
		||||
{
 | 
			
		||||
	ShowPageDialog(m_globalSettingsProvider, this, "accounts");
 | 
			
		||||
	SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), this, "accounts");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::on_actionReportBug_triggered()
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,6 @@ class LabeledToolButton;
 | 
			
		||||
class QLabel;
 | 
			
		||||
class MinecraftLauncher;
 | 
			
		||||
class BaseProfilerFactory;
 | 
			
		||||
class GenericPageProvider;
 | 
			
		||||
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
@@ -180,7 +179,6 @@ private:
 | 
			
		||||
	QToolButton *changeIconButton;
 | 
			
		||||
	QToolButton *newsLabel;
 | 
			
		||||
 | 
			
		||||
	std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
 | 
			
		||||
	std::shared_ptr<NewsChecker> m_newsChecker;
 | 
			
		||||
	std::shared_ptr<NotificationChecker> m_notificationChecker;
 | 
			
		||||
	std::shared_ptr<LaunchController> m_launchController;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,12 @@
 | 
			
		||||
#include "MultiMC.h"
 | 
			
		||||
#include "BuildConfig.h"
 | 
			
		||||
#include "pages/BasePageProvider.h"
 | 
			
		||||
#include "pages/global/MultiMCPage.h"
 | 
			
		||||
#include "pages/global/MinecraftPage.h"
 | 
			
		||||
#include "pages/global/JavaPage.h"
 | 
			
		||||
#include "pages/global/ProxyPage.h"
 | 
			
		||||
#include "pages/global/ExternalToolsPage.h"
 | 
			
		||||
#include "pages/global/AccountListPage.h"
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
@@ -533,6 +540,18 @@ void MultiMC::initGlobalSettings(bool test_mode)
 | 
			
		||||
 | 
			
		||||
	// Jar mod nag dialog in version page
 | 
			
		||||
	m_settings->registerSetting("JarModNagSeen", false);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// Init page provider
 | 
			
		||||
	{
 | 
			
		||||
		m_globalSettingsProvider = std::make_shared<GenericPageProvider>(tr("Settings"));
 | 
			
		||||
		m_globalSettingsProvider->addPage<MultiMCPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<MinecraftPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<JavaPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<ProxyPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<ExternalToolsPage>();
 | 
			
		||||
		m_globalSettingsProvider->addPage<AccountListPage>();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<LWJGLVersionList> MultiMC::lwjgllist()
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
#include <updater/GoUpdate.h>
 | 
			
		||||
 | 
			
		||||
class GenericPageProvider;
 | 
			
		||||
class QFile;
 | 
			
		||||
class MinecraftVersionList;
 | 
			
		||||
class LWJGLVersionList;
 | 
			
		||||
@@ -54,6 +55,11 @@ public:
 | 
			
		||||
		return m_settings;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::shared_ptr<GenericPageProvider> globalSettingsPages()
 | 
			
		||||
	{
 | 
			
		||||
		return m_globalSettingsProvider;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	qint64 timeSinceStart() const
 | 
			
		||||
	{
 | 
			
		||||
		return startTime.msecsTo(QDateTime::currentDateTime());
 | 
			
		||||
@@ -163,6 +169,7 @@ private:
 | 
			
		||||
	std::shared_ptr<MinecraftVersionList> m_minecraftlist;
 | 
			
		||||
	std::shared_ptr<JavaVersionList> m_javalist;
 | 
			
		||||
	std::shared_ptr<TranslationDownloader> m_translationChecker;
 | 
			
		||||
	std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
 | 
			
		||||
 | 
			
		||||
	QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers;
 | 
			
		||||
	QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> m_tools;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								application/SettingsUI.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								application/SettingsUI.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#include "SettingsUI.h"
 | 
			
		||||
namespace SettingsUI
 | 
			
		||||
{
 | 
			
		||||
void ShowInstancePageDialog(InstancePtr instance, QWidget * parent, QString open_page)
 | 
			
		||||
{
 | 
			
		||||
	auto provider = std::make_shared<InstancePageProvider>(instance);
 | 
			
		||||
	ShowPageDialog(provider, parent, open_page);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								application/SettingsUI.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								application/SettingsUI.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#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, open_page, parent);
 | 
			
		||||
		dlg.exec();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShowInstancePageDialog(InstancePtr instance, QWidget * parent, QString open_page = QString());
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user