DolphinQt2: make Settings a singleton

With this, we can get signals when properties change.
This commit is contained in:
Michael Maltese 2017-05-31 00:17:39 -07:00
parent 95ef785b1f
commit 548522877a
15 changed files with 109 additions and 89 deletions

View file

@ -371,7 +371,7 @@ void ControllersWindow::OnWiimoteRefreshPressed()
void ControllersWindow::OnEmulationStateChanged(bool running) void ControllersWindow::OnEmulationStateChanged(bool running)
{ {
if (!Settings().IsWiiGameRunning() || NetPlay::IsNetPlayRunning()) if (!Settings::Instance().IsWiiGameRunning() || NetPlay::IsNetPlayRunning())
{ {
m_wiimote_sync->setEnabled(!running); m_wiimote_sync->setEnabled(!running);
m_wiimote_reset->setEnabled(!running); m_wiimote_reset->setEnabled(!running);
@ -383,7 +383,7 @@ void ControllersWindow::OnEmulationStateChanged(bool running)
m_wiimote_emu->setEnabled(!running); m_wiimote_emu->setEnabled(!running);
m_wiimote_passthrough->setEnabled(!running); m_wiimote_passthrough->setEnabled(!running);
if (!Settings().IsWiiGameRunning()) if (!Settings::Instance().IsWiiGameRunning())
{ {
m_wiimote_real_balance_board->setEnabled(!running); m_wiimote_real_balance_board->setEnabled(!running);
m_wiimote_continuous_scanning->setEnabled(!running); m_wiimote_continuous_scanning->setEnabled(!running);
@ -471,33 +471,35 @@ void ControllersWindow::UnimplementedButton()
void ControllersWindow::LoadSettings() void ControllersWindow::LoadSettings()
{ {
auto& settings = Settings::Instance();
for (size_t i = 0; i < m_wiimote_groups.size(); i++) for (size_t i = 0; i < m_wiimote_groups.size(); i++)
{ {
m_gc_controller_boxes[i]->setCurrentIndex(ToGCMenuIndex(Settings().GetSIDevice(i))); m_gc_controller_boxes[i]->setCurrentIndex(ToGCMenuIndex(settings.GetSIDevice(i)));
m_wiimote_boxes[i]->setCurrentIndex(ToWiimoteMenuIndex(g_wiimote_sources[i])); m_wiimote_boxes[i]->setCurrentIndex(ToWiimoteMenuIndex(g_wiimote_sources[i]));
} }
m_wiimote_real_balance_board->setChecked(g_wiimote_sources[WIIMOTE_BALANCE_BOARD] == m_wiimote_real_balance_board->setChecked(g_wiimote_sources[WIIMOTE_BALANCE_BOARD] ==
WIIMOTE_SRC_REAL); WIIMOTE_SRC_REAL);
m_wiimote_speaker_data->setChecked(Settings().IsWiimoteSpeakerEnabled()); m_wiimote_speaker_data->setChecked(settings.IsWiimoteSpeakerEnabled());
m_wiimote_continuous_scanning->setChecked(Settings().IsContinuousScanningEnabled()); m_wiimote_continuous_scanning->setChecked(settings.IsContinuousScanningEnabled());
m_advanced_bg_input->setChecked(Settings().IsBackgroundInputEnabled()); m_advanced_bg_input->setChecked(settings.IsBackgroundInputEnabled());
if (Settings().IsBluetoothPassthroughEnabled()) if (settings.IsBluetoothPassthroughEnabled())
m_wiimote_passthrough->setChecked(true); m_wiimote_passthrough->setChecked(true);
else else
m_wiimote_emu->setChecked(true); m_wiimote_emu->setChecked(true);
OnWiimoteModeChanged(Settings().IsBluetoothPassthroughEnabled()); OnWiimoteModeChanged(settings.IsBluetoothPassthroughEnabled());
} }
void ControllersWindow::SaveSettings() void ControllersWindow::SaveSettings()
{ {
Settings().SetWiimoteSpeakerEnabled(m_wiimote_speaker_data->isChecked()); auto& settings = Settings::Instance();
Settings().SetContinuousScanningEnabled(m_wiimote_continuous_scanning->isChecked()); settings.SetWiimoteSpeakerEnabled(m_wiimote_speaker_data->isChecked());
settings.SetContinuousScanningEnabled(m_wiimote_continuous_scanning->isChecked());
Settings().SetBluetoothPassthroughEnabled(m_wiimote_passthrough->isChecked()); settings.SetBluetoothPassthroughEnabled(m_wiimote_passthrough->isChecked());
Settings().SetBackgroundInputEnabled(m_advanced_bg_input->isChecked()); settings.SetBackgroundInputEnabled(m_advanced_bg_input->isChecked());
WiimoteReal::ChangeWiimoteSource(WIIMOTE_BALANCE_BOARD, WiimoteReal::ChangeWiimoteSource(WIIMOTE_BALANCE_BOARD,
m_wiimote_real_balance_board->isChecked() ? WIIMOTE_SRC_REAL : m_wiimote_real_balance_board->isChecked() ? WIIMOTE_SRC_REAL :
@ -515,8 +517,8 @@ void ControllersWindow::SaveSettings()
for (size_t i = 0; i < m_gc_groups.size(); i++) for (size_t i = 0; i < m_gc_groups.size(); i++)
{ {
const int index = m_gc_controller_boxes[i]->currentIndex(); const int index = m_gc_controller_boxes[i]->currentIndex();
Settings().SetSIDevice(i, FromGCMenuIndex(index)); settings.SetSIDevice(i, FromGCMenuIndex(index));
m_gc_buttons[i]->setEnabled(index != 0 && index != 6); m_gc_buttons[i]->setEnabled(index != 0 && index != 6);
} }
Settings().Save(); settings.Save();
} }

View file

@ -48,14 +48,14 @@ void GCPadWiiU::ConnectWidgets()
void GCPadWiiU::LoadSettings() void GCPadWiiU::LoadSettings()
{ {
m_rumble->setChecked(Settings().IsGCAdapterRumbleEnabled(GetPort())); m_rumble->setChecked(Settings::Instance().IsGCAdapterRumbleEnabled(GetPort()));
m_simulate_bongos->setChecked(Settings().IsGCAdapterSimulatingDKBongos(GetPort())); m_simulate_bongos->setChecked(Settings::Instance().IsGCAdapterSimulatingDKBongos(GetPort()));
} }
void GCPadWiiU::SaveSettings() void GCPadWiiU::SaveSettings()
{ {
Settings().SetGCAdapterRumbleEnabled(GetPort(), m_rumble->isChecked()); Settings::Instance().SetGCAdapterRumbleEnabled(GetPort(), m_rumble->isChecked());
Settings().SetGCAdapterSimulatingDKBongos(GetPort(), m_simulate_bongos->isChecked()); Settings::Instance().SetGCAdapterSimulatingDKBongos(GetPort(), m_simulate_bongos->isChecked());
} }
InputConfig* GCPadWiiU::GetConfig() InputConfig* GCPadWiiU::GetConfig()

View file

@ -126,8 +126,9 @@ void MappingWindow::ConnectWidgets()
void MappingWindow::OnDeleteProfilePressed() void MappingWindow::OnDeleteProfilePressed()
{ {
auto& settings = Settings::Instance();
const QString profile_name = m_profiles_combo->currentText(); const QString profile_name = m_profiles_combo->currentText();
if (!Settings().GetProfiles(m_config).contains(profile_name)) if (!settings.GetProfiles(m_config).contains(profile_name))
{ {
QMessageBox error; QMessageBox error;
error.setIcon(QMessageBox::Critical); error.setIcon(QMessageBox::Critical);
@ -153,7 +154,7 @@ void MappingWindow::OnDeleteProfilePressed()
QMessageBox result(this); QMessageBox result(this);
std::string profile_path = Settings().GetProfileINIPath(m_config, profile_name).toStdString(); std::string profile_path = settings.GetProfileINIPath(m_config, profile_name).toStdString();
File::CreateFullPath(profile_path); File::CreateFullPath(profile_path);
@ -170,7 +171,8 @@ void MappingWindow::OnLoadProfilePressed()
if (profile_name.isEmpty()) if (profile_name.isEmpty())
return; return;
std::string profile_path = Settings().GetProfileINIPath(m_config, profile_name).toStdString(); std::string profile_path =
Settings::Instance().GetProfileINIPath(m_config, profile_name).toStdString();
File::CreateFullPath(profile_path); File::CreateFullPath(profile_path);
@ -192,7 +194,8 @@ void MappingWindow::OnSaveProfilePressed()
if (profile_name.isEmpty()) if (profile_name.isEmpty())
return; return;
std::string profile_path = Settings().GetProfileINIPath(m_config, profile_name).toStdString(); std::string profile_path =
Settings::Instance().GetProfileINIPath(m_config, profile_name).toStdString();
File::CreateFullPath(profile_path); File::CreateFullPath(profile_path);
@ -297,7 +300,7 @@ void MappingWindow::ChangeMappingType(MappingWindow::Type type)
m_controller = m_config->GetController(GetPort()); m_controller = m_config->GetController(GetPort());
m_profiles_combo->addItem(QStringLiteral("")); m_profiles_combo->addItem(QStringLiteral(""));
for (const auto& item : Settings().GetProfiles(m_config)) for (const auto& item : Settings::Instance().GetProfiles(m_config))
m_profiles_combo->addItem(item); m_profiles_combo->addItem(item);
} }

View file

@ -38,12 +38,11 @@ void PathDialog::Browse()
QFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath()); QFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath());
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
Settings settings; QStringList game_folders = Settings::Instance().GetPaths();
QStringList game_folders = settings.GetPaths();
if (!game_folders.contains(dir)) if (!game_folders.contains(dir))
{ {
game_folders << dir; game_folders << dir;
settings.SetPaths(game_folders); Settings::Instance().SetPaths(game_folders);
m_path_list->addItem(dir); m_path_list->addItem(dir);
emit PathAdded(dir); emit PathAdded(dir);
} }
@ -59,7 +58,7 @@ void PathDialog::BrowseDefaultGame()
if (!file.isEmpty()) if (!file.isEmpty())
{ {
m_game_edit->setText(file); m_game_edit->setText(file);
Settings().SetDefaultGame(file); Settings::Instance().SetDefaultGame(file);
} }
} }
@ -69,7 +68,7 @@ void PathDialog::BrowseDVDRoot()
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
m_dvd_edit->setText(dir); m_dvd_edit->setText(dir);
Settings().SetDVDRoot(dir); Settings::Instance().SetDVDRoot(dir);
} }
} }
@ -80,7 +79,7 @@ void PathDialog::BrowseApploader()
if (!file.isEmpty()) if (!file.isEmpty())
{ {
m_app_edit->setText(file); m_app_edit->setText(file);
Settings().SetApploader(file); Settings::Instance().SetApploader(file);
} }
} }
@ -91,7 +90,7 @@ void PathDialog::BrowseWiiNAND()
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
m_nand_edit->setText(dir); m_nand_edit->setText(dir);
Settings().SetWiiNAND(dir); Settings::Instance().SetWiiNAND(dir);
} }
} }
@ -102,7 +101,7 @@ QGroupBox* PathDialog::MakeGameFolderBox()
QVBoxLayout* vlayout = new QVBoxLayout; QVBoxLayout* vlayout = new QVBoxLayout;
m_path_list = new QListWidget; m_path_list = new QListWidget;
m_path_list->insertItems(0, Settings().GetPaths()); m_path_list->insertItems(0, Settings::Instance().GetPaths());
m_path_list->setSpacing(1); m_path_list->setSpacing(1);
vlayout->addWidget(m_path_list); vlayout->addWidget(m_path_list);
@ -124,39 +123,40 @@ QGroupBox* PathDialog::MakeGameFolderBox()
QGridLayout* PathDialog::MakePathsLayout() QGridLayout* PathDialog::MakePathsLayout()
{ {
auto& settings = Settings::Instance();
QGridLayout* layout = new QGridLayout; QGridLayout* layout = new QGridLayout;
layout->setColumnStretch(1, 1); layout->setColumnStretch(1, 1);
m_game_edit = new QLineEdit(Settings().GetDefaultGame()); m_game_edit = new QLineEdit(settings.GetDefaultGame());
connect(m_game_edit, &QLineEdit::editingFinished, connect(m_game_edit, &QLineEdit::editingFinished,
[=] { Settings().SetDefaultGame(m_game_edit->text()); }); [=, &settings] { settings.SetDefaultGame(m_game_edit->text()); });
QPushButton* game_open = new QPushButton; QPushButton* game_open = new QPushButton;
connect(game_open, &QPushButton::clicked, this, &PathDialog::BrowseDefaultGame); connect(game_open, &QPushButton::clicked, this, &PathDialog::BrowseDefaultGame);
layout->addWidget(new QLabel(tr("Default Game")), 0, 0); layout->addWidget(new QLabel(tr("Default Game")), 0, 0);
layout->addWidget(m_game_edit, 0, 1); layout->addWidget(m_game_edit, 0, 1);
layout->addWidget(game_open, 0, 2); layout->addWidget(game_open, 0, 2);
m_dvd_edit = new QLineEdit(Settings().GetDVDRoot()); m_dvd_edit = new QLineEdit(settings.GetDVDRoot());
connect(m_dvd_edit, &QLineEdit::editingFinished, connect(m_dvd_edit, &QLineEdit::editingFinished,
[=] { Settings().SetDVDRoot(m_dvd_edit->text()); }); [=, &settings] { settings.SetDVDRoot(m_dvd_edit->text()); });
QPushButton* dvd_open = new QPushButton; QPushButton* dvd_open = new QPushButton;
connect(dvd_open, &QPushButton::clicked, this, &PathDialog::BrowseDVDRoot); connect(dvd_open, &QPushButton::clicked, this, &PathDialog::BrowseDVDRoot);
layout->addWidget(new QLabel(tr("DVD Root")), 1, 0); layout->addWidget(new QLabel(tr("DVD Root")), 1, 0);
layout->addWidget(m_dvd_edit, 1, 1); layout->addWidget(m_dvd_edit, 1, 1);
layout->addWidget(dvd_open, 1, 2); layout->addWidget(dvd_open, 1, 2);
m_app_edit = new QLineEdit(Settings().GetApploader()); m_app_edit = new QLineEdit(settings.GetApploader());
connect(m_app_edit, &QLineEdit::editingFinished, connect(m_app_edit, &QLineEdit::editingFinished,
[=] { Settings().SetApploader(m_app_edit->text()); }); [=, &settings] { settings.SetApploader(m_app_edit->text()); });
QPushButton* app_open = new QPushButton; QPushButton* app_open = new QPushButton;
connect(app_open, &QPushButton::clicked, this, &PathDialog::BrowseApploader); connect(app_open, &QPushButton::clicked, this, &PathDialog::BrowseApploader);
layout->addWidget(new QLabel(tr("Apploader")), 2, 0); layout->addWidget(new QLabel(tr("Apploader")), 2, 0);
layout->addWidget(m_app_edit, 2, 1); layout->addWidget(m_app_edit, 2, 1);
layout->addWidget(app_open, 2, 2); layout->addWidget(app_open, 2, 2);
m_nand_edit = new QLineEdit(Settings().GetWiiNAND()); m_nand_edit = new QLineEdit(settings.GetWiiNAND());
connect(m_nand_edit, &QLineEdit::editingFinished, connect(m_nand_edit, &QLineEdit::editingFinished,
[=] { Settings().SetWiiNAND(m_nand_edit->text()); }); [=, &settings] { settings.SetWiiNAND(m_nand_edit->text()); });
QPushButton* nand_open = new QPushButton; QPushButton* nand_open = new QPushButton;
connect(nand_open, &QPushButton::clicked, this, &PathDialog::BrowseWiiNAND); connect(nand_open, &QPushButton::clicked, this, &PathDialog::BrowseWiiNAND);
layout->addWidget(new QLabel(tr("Wii NAND Root")), 3, 0); layout->addWidget(new QLabel(tr("Wii NAND Root")), 3, 0);
@ -172,5 +172,5 @@ void PathDialog::RemovePath()
if (row < 0) if (row < 0)
return; return;
emit PathRemoved(m_path_list->takeItem(row)->text()); emit PathRemoved(m_path_list->takeItem(row)->text());
Settings().RemovePath(row); Settings::Instance().RemovePath(row);
} }

View file

@ -67,7 +67,7 @@ void SettingsWindow::MakeUnfinishedWarning()
void SettingsWindow::AddCategoryToList(const QString& title, const QString& icon) void SettingsWindow::AddCategoryToList(const QString& title, const QString& icon)
{ {
QString dir = Settings().GetThemeDir(); QString dir = Settings::Instance().GetThemeDir();
QListWidgetItem* button = new QListWidgetItem(); QListWidgetItem* button = new QListWidgetItem();
button->setIcon(QIcon(dir.append(icon))); button->setIcon(QIcon(dir.append(icon)));
button->setText(title); button->setText(title);

View file

@ -217,9 +217,9 @@ QString GameFile::GetBannerString(const QMap<DiscIO::Language, QString>& m) cons
bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC; bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC;
DiscIO::Language current_lang; DiscIO::Language current_lang;
if (wii) if (wii)
current_lang = Settings().GetWiiSystemLanguage(); current_lang = Settings::Instance().GetWiiSystemLanguage();
else else
current_lang = Settings().GetGCSystemLanguage(); current_lang = Settings::Instance().GetGCSystemLanguage();
if (m.contains(current_lang)) if (m.contains(current_lang))
return m[current_lang]; return m[current_lang];

View file

@ -50,7 +50,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
addWidget(m_table); addWidget(m_table);
addWidget(m_list); addWidget(m_list);
addWidget(m_empty); addWidget(m_empty);
m_prefer_table = Settings().GetPreferredView(); m_prefer_table = Settings::Instance().GetPreferredView();
ConsiderViewChange(); ConsiderViewChange();
} }
@ -70,15 +70,16 @@ void GameList::MakeTableView()
connect(m_table, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu); connect(m_table, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu);
m_table->setColumnHidden(GameListModel::COL_PLATFORM, !Settings().PlatformVisible()); auto& settings = Settings::Instance();
m_table->setColumnHidden(GameListModel::COL_ID, !Settings().IDVisible()); m_table->setColumnHidden(GameListModel::COL_PLATFORM, !settings.PlatformVisible());
m_table->setColumnHidden(GameListModel::COL_BANNER, !Settings().BannerVisible()); m_table->setColumnHidden(GameListModel::COL_ID, !settings.IDVisible());
m_table->setColumnHidden(GameListModel::COL_TITLE, !Settings().TitleVisible()); m_table->setColumnHidden(GameListModel::COL_BANNER, !settings.BannerVisible());
m_table->setColumnHidden(GameListModel::COL_DESCRIPTION, !Settings().DescriptionVisible()); m_table->setColumnHidden(GameListModel::COL_TITLE, !settings.TitleVisible());
m_table->setColumnHidden(GameListModel::COL_MAKER, !Settings().MakerVisible()); m_table->setColumnHidden(GameListModel::COL_DESCRIPTION, !settings.DescriptionVisible());
m_table->setColumnHidden(GameListModel::COL_SIZE, !Settings().SizeVisible()); m_table->setColumnHidden(GameListModel::COL_MAKER, !settings.MakerVisible());
m_table->setColumnHidden(GameListModel::COL_COUNTRY, !Settings().CountryVisible()); m_table->setColumnHidden(GameListModel::COL_SIZE, !settings.SizeVisible());
m_table->setColumnHidden(GameListModel::COL_RATING, !Settings().StateVisible()); m_table->setColumnHidden(GameListModel::COL_COUNTRY, !settings.CountryVisible());
m_table->setColumnHidden(GameListModel::COL_RATING, !settings.StateVisible());
QHeaderView* hor_header = m_table->horizontalHeader(); QHeaderView* hor_header = m_table->horizontalHeader();
hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::ResizeToContents); hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::ResizeToContents);
@ -284,7 +285,7 @@ void GameList::UninstallWAD()
void GameList::SetDefaultISO() void GameList::SetDefaultISO()
{ {
Settings().SetDefaultGame(GetSelectedGame()); Settings::Instance().SetDefaultGame(GetSelectedGame());
} }
void GameList::OpenContainingFolder() void GameList::OpenContainingFolder()
@ -364,7 +365,7 @@ QString GameList::GetSelectedGame() const
void GameList::SetPreferredView(bool table) void GameList::SetPreferredView(bool table)
{ {
m_prefer_table = table; m_prefer_table = table;
Settings().SetPreferredView(table); Settings::Instance().SetPreferredView(table);
ConsiderViewChange(); ConsiderViewChange();
} }

View file

@ -28,7 +28,7 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
m_loader_thread.start(); m_loader_thread.start();
for (QString dir : Settings().GetPaths()) for (QString dir : Settings::Instance().GetPaths())
AddDirectory(dir); AddDirectory(dir);
} }

View file

@ -34,8 +34,9 @@ int main(int argc, char* argv[])
QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock, QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,
&app, &Core::HostDispatchJobs); &app, &Core::HostDispatchJobs);
auto& settings = Settings::Instance();
int retval = 0; int retval = 0;
if (Settings().IsInDevelopmentWarningEnabled()) if (settings.IsInDevelopmentWarningEnabled())
{ {
InDevelopmentWarning warning_box; InDevelopmentWarning warning_box;
retval = warning_box.exec() == QDialog::Rejected; retval = warning_box.exec() == QDialog::Rejected;
@ -48,7 +49,7 @@ int main(int argc, char* argv[])
win.show(); win.show();
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS
if (!Settings().HasAskedForAnalyticsPermission()) if (!settings.HasAskedForAnalyticsPermission())
{ {
QMessageBox analytics_prompt(&win); QMessageBox analytics_prompt(&win);
@ -69,9 +70,9 @@ int main(int argc, char* argv[])
const int answer = analytics_prompt.exec(); const int answer = analytics_prompt.exec();
Settings().SetAskedForAnalyticsPermission(true); settings.SetAskedForAnalyticsPermission(true);
Settings().SetAnalyticsEnabled(answer == QMessageBox::Yes); settings.SetAnalyticsEnabled(answer == QMessageBox::Yes);
Settings().Save(); settings.Save();
DolphinAnalytics::Instance()->ReloadConfig(); DolphinAnalytics::Instance()->ReloadConfig();
} }

View file

@ -206,7 +206,7 @@ void MainWindow::Play()
} }
else else
{ {
QString default_path = Settings().GetDefaultGame(); QString default_path = Settings::Instance().GetDefaultGame();
if (!default_path.isEmpty() && QFile::exists(default_path)) if (!default_path.isEmpty() && QFile::exists(default_path))
{ {
StartGame(default_path); StartGame(default_path);
@ -228,7 +228,7 @@ void MainWindow::Pause()
bool MainWindow::Stop() bool MainWindow::Stop()
{ {
bool stop = true; bool stop = true;
if (Settings().GetConfirmStop()) if (Settings::Instance().GetConfirmStop())
{ {
// We could pause the game here and resume it if they say no. // We could pause the game here and resume it if they say no.
QMessageBox::StandardButton confirm; QMessageBox::StandardButton confirm;
@ -313,7 +313,7 @@ void MainWindow::StartGame(const QString& path)
void MainWindow::ShowRenderWidget() void MainWindow::ShowRenderWidget()
{ {
Settings settings; auto& settings = Settings::Instance();
if (settings.GetRenderToMain()) if (settings.GetRenderToMain())
{ {
// If we're rendering to main, add it to the stack and update our title when necessary. // If we're rendering to main, add it to the stack and update our title when necessary.
@ -432,6 +432,6 @@ void MainWindow::StateSaveOldest()
void MainWindow::SetStateSlot(int slot) void MainWindow::SetStateSlot(int slot)
{ {
Settings().SetStateSlot(slot); Settings::Instance().SetStateSlot(slot);
m_state_slot = slot; m_state_slot = slot;
} }

View file

@ -140,7 +140,7 @@ void MenuBar::AddStateSlotMenu(QMenu* emu_menu)
QAction* action = m_state_slot_menu->addAction(QStringLiteral("")); QAction* action = m_state_slot_menu->addAction(QStringLiteral(""));
action->setCheckable(true); action->setCheckable(true);
action->setActionGroup(m_state_slots); action->setActionGroup(m_state_slots);
if (Settings().GetStateSlot() == i) if (Settings::Instance().GetStateSlot() == i)
action->setChecked(true); action->setChecked(true);
connect(action, &QAction::triggered, this, [=]() { emit SetStateSlot(i); }); connect(action, &QAction::triggered, this, [=]() { emit SetStateSlot(i); });
@ -203,7 +203,7 @@ void MenuBar::AddGameListTypeSection(QMenu* view_menu)
list_group->addAction(table_view); list_group->addAction(table_view);
list_group->addAction(list_view); list_group->addAction(list_view);
bool prefer_table = Settings().GetPreferredView(); bool prefer_table = Settings::Instance().GetPreferredView();
table_view->setChecked(prefer_table); table_view->setChecked(prefer_table);
list_view->setChecked(!prefer_table); list_view->setChecked(!prefer_table);
@ -213,15 +213,16 @@ void MenuBar::AddGameListTypeSection(QMenu* view_menu)
void MenuBar::AddTableColumnsMenu(QMenu* view_menu) void MenuBar::AddTableColumnsMenu(QMenu* view_menu)
{ {
static const QMap<QString, bool*> columns{{tr("Platform"), &Settings().PlatformVisible()}, auto& settings = Settings::Instance();
{tr("ID"), &Settings().IDVisible()}, static const QMap<QString, bool*> columns{{tr("Platform"), &settings.PlatformVisible()},
{tr("Banner"), &Settings().BannerVisible()}, {tr("ID"), &settings.IDVisible()},
{tr("Title"), &Settings().TitleVisible()}, {tr("Banner"), &settings.BannerVisible()},
{tr("Description"), &Settings().DescriptionVisible()}, {tr("Title"), &settings.TitleVisible()},
{tr("Maker"), &Settings().MakerVisible()}, {tr("Description"), &settings.DescriptionVisible()},
{tr("Size"), &Settings().SizeVisible()}, {tr("Maker"), &settings.MakerVisible()},
{tr("Country"), &Settings().CountryVisible()}, {tr("Size"), &settings.SizeVisible()},
{tr("Quality"), &Settings().StateVisible()}}; {tr("Country"), &settings.CountryVisible()},
{tr("Quality"), &settings.StateVisible()}};
QActionGroup* column_group = new QActionGroup(this); QActionGroup* column_group = new QActionGroup(this);
QMenu* cols_menu = view_menu->addMenu(tr("Table Columns")); QMenu* cols_menu = view_menu->addMenu(tr("Table Columns"));
@ -235,7 +236,7 @@ void MenuBar::AddTableColumnsMenu(QMenu* view_menu)
action->setChecked(*config); action->setChecked(*config);
connect(action, &QAction::toggled, [this, config, key](bool value) { connect(action, &QAction::toggled, [this, config, key](bool value) {
*config = value; *config = value;
Settings().Save(); Settings::Instance().Save();
emit ColumnVisibilityToggled(key, value); emit ColumnVisibilityToggled(key, value);
}); });
} }

View file

@ -47,22 +47,22 @@ QPixmap Resources::GetPixmap(const QString& name, const QString& dir)
QIcon Resources::GetScaledIcon(const std::string& name) QIcon Resources::GetScaledIcon(const std::string& name)
{ {
return GetIcon(QString::fromStdString(name), Settings().GetResourcesDir()); return GetIcon(QString::fromStdString(name), Settings::Instance().GetResourcesDir());
} }
QIcon Resources::GetScaledThemeIcon(const std::string& name) QIcon Resources::GetScaledThemeIcon(const std::string& name)
{ {
return GetIcon(QString::fromStdString(name), Settings().GetThemeDir()); return GetIcon(QString::fromStdString(name), Settings::Instance().GetThemeDir());
} }
QPixmap Resources::GetScaledPixmap(const std::string& name) QPixmap Resources::GetScaledPixmap(const std::string& name)
{ {
return GetPixmap(QString::fromStdString(name), Settings().GetResourcesDir()); return GetPixmap(QString::fromStdString(name), Settings::Instance().GetResourcesDir());
} }
QPixmap Resources::GetScaledThemePixmap(const std::string& name) QPixmap Resources::GetScaledThemePixmap(const std::string& name)
{ {
return GetPixmap(QString::fromStdString(name), Settings().GetThemeDir()); return GetPixmap(QString::fromStdString(name), Settings::Instance().GetThemeDir());
} }
void Resources::Init() void Resources::Init()

View file

@ -17,10 +17,16 @@ static QString GetSettingsPath()
return QString::fromStdString(File::GetUserPath(D_CONFIG_IDX)) + QStringLiteral("/UI.ini"); return QString::fromStdString(File::GetUserPath(D_CONFIG_IDX)) + QStringLiteral("/UI.ini");
} }
Settings::Settings(QObject* parent) : QSettings(GetSettingsPath(), QSettings::IniFormat, parent) Settings::Settings() : QSettings(GetSettingsPath(), QSettings::IniFormat)
{ {
} }
Settings& Settings::Instance()
{
static Settings settings;
return settings;
}
QString Settings::GetThemeDir() const QString Settings::GetThemeDir() const
{ {
return QString::fromStdString(File::GetThemeDir(SConfig::GetInstance().theme_name)); return QString::fromStdString(File::GetThemeDir(SConfig::GetInstance().theme_name));

View file

@ -7,6 +7,7 @@
#include <QSettings> #include <QSettings>
#include <QVector> #include <QVector>
#include "Common/NonCopyable.h"
#include "Core/HW/SI/SI.h" #include "Core/HW/SI/SI.h"
namespace DiscIO namespace DiscIO
@ -17,12 +18,12 @@ enum class Language;
class InputConfig; class InputConfig;
// UI settings to be stored in the config directory. // UI settings to be stored in the config directory.
class Settings final : public QSettings class Settings final : public QSettings, NonCopyable
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Settings(QObject* parent = nullptr); static Settings& Instance();
// UI // UI
QString GetThemeDir() const; QString GetThemeDir() const;
@ -105,4 +106,7 @@ public:
void SetGCAdapterSimulatingDKBongos(int port, bool enabled); void SetGCAdapterSimulatingDKBongos(int port, bool enabled);
void Save(); void Save();
private:
Settings();
}; };

View file

@ -140,11 +140,12 @@ void GeneralPane::CreateAdvanced()
void GeneralPane::LoadConfig() void GeneralPane::LoadConfig()
{ {
m_checkbox_force_ntsc->setChecked(Settings().GetForceNTSCJ()); auto& settings = Settings::Instance();
m_checkbox_enable_analytics->setChecked(Settings().GetAnalyticsEnabled()); m_checkbox_force_ntsc->setChecked(settings.GetForceNTSCJ());
m_checkbox_enable_analytics->setChecked(settings.GetAnalyticsEnabled());
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
m_checkbox_cheats->setChecked(SConfig::GetInstance().bEnableCheats); m_checkbox_cheats->setChecked(SConfig::GetInstance().bEnableCheats);
int selection = qRound(Settings().GetEmulationSpeed() * 10); int selection = qRound(settings.GetEmulationSpeed() * 10);
if (selection < m_combobox_speedlimit->count()) if (selection < m_combobox_speedlimit->count())
m_combobox_speedlimit->setCurrentIndex(selection); m_combobox_speedlimit->setCurrentIndex(selection);
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
@ -170,8 +171,9 @@ void GeneralPane::LoadConfig()
void GeneralPane::OnSaveConfig() void GeneralPane::OnSaveConfig()
{ {
Settings().SetForceNTSCJ(m_checkbox_force_ntsc->isChecked()); auto& settings = Settings::Instance();
Settings().SetAnalyticsEnabled(m_checkbox_enable_analytics->isChecked()); settings.SetForceNTSCJ(m_checkbox_force_ntsc->isChecked());
settings.SetAnalyticsEnabled(m_checkbox_enable_analytics->isChecked());
SConfig::GetInstance().bCPUThread = m_checkbox_dualcore->isChecked(); SConfig::GetInstance().bCPUThread = m_checkbox_dualcore->isChecked();
SConfig::GetInstance().bEnableCheats = m_checkbox_cheats->isChecked(); SConfig::GetInstance().bEnableCheats = m_checkbox_cheats->isChecked();
SConfig::GetInstance().m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f; SConfig::GetInstance().m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f;