dolphin/Source/Core/DolphinQt2/Settings.cpp

419 lines
9.1 KiB
C++
Raw Normal View History

// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
2017-05-09 18:49:10 +02:00
#include <QDir>
#include <QSettings>
#include <QSize>
2017-06-21 10:26:06 +02:00
#include "AudioCommon/AudioCommon.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
2017-05-20 17:53:17 +02:00
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
2017-08-01 12:55:21 +02:00
#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/QtUtils/QueueOnObject.h"
#include "DolphinQt2/Settings.h"
2017-05-20 17:53:17 +02:00
#include "InputCommon/InputConfig.h"
Settings::Settings()
{
qRegisterMetaType<Core::State>();
Core::SetOnStateChangedCallback([this](Core::State new_state) {
QueueOnObject(this, [this, new_state] { emit EmulationStateChanged(new_state); });
});
Config::AddConfigChangedCallback(
[this] { QueueOnObject(this, [this] { emit ConfigChanged(); }); });
}
Settings& Settings::Instance()
{
static Settings settings;
return settings;
}
QSettings& Settings::GetQSettings()
{
static QSettings settings(
QStringLiteral("%1/Qt.ini").arg(QString::fromStdString(File::GetUserPath(D_CONFIG_IDX))),
QSettings::IniFormat);
return settings;
}
void Settings::SetThemeName(const QString& theme_name)
{
SConfig::GetInstance().theme_name = theme_name.toStdString();
emit ThemeChanged();
}
QStringList Settings::GetPaths() const
{
QStringList list;
for (const auto& path : SConfig::GetInstance().m_ISOFolder)
list << QString::fromStdString(path);
return list;
}
void Settings::AddPath(const QString& qpath)
{
std::string path = qpath.toStdString();
std::vector<std::string>& paths = SConfig::GetInstance().m_ISOFolder;
if (std::find(paths.begin(), paths.end(), path) != paths.end())
return;
paths.emplace_back(path);
emit PathAdded(qpath);
}
void Settings::RemovePath(const QString& qpath)
{
std::string path = qpath.toStdString();
std::vector<std::string>& paths = SConfig::GetInstance().m_ISOFolder;
auto new_end = std::remove(paths.begin(), paths.end(), path);
if (new_end == paths.end())
return;
paths.erase(new_end, paths.end());
emit PathRemoved(qpath);
}
void Settings::ReloadPath(const QString& qpath)
{
emit PathReloadRequested(qpath);
}
QString Settings::GetDefaultGame() const
{
return QString::fromStdString(SConfig::GetInstance().m_strDefaultISO);
}
void Settings::SetDefaultGame(QString path)
{
if (GetDefaultGame() != path)
{
SConfig::GetInstance().m_strDefaultISO = path.toStdString();
emit DefaultGameChanged(path);
}
}
bool Settings::GetPreferredView() const
{
return GetQSettings().value(QStringLiteral("PreferredView"), true).toBool();
}
void Settings::SetPreferredView(bool list)
{
GetQSettings().setValue(QStringLiteral("PreferredView"), list);
}
int Settings::GetStateSlot() const
{
return GetQSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt();
}
void Settings::SetStateSlot(int slot)
{
GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot);
}
2017-05-08 19:03:59 +02:00
2017-06-01 08:49:06 +02:00
void Settings::SetHideCursor(bool hide_cursor)
{
SConfig::GetInstance().bHideCursor = hide_cursor;
emit HideCursorChanged();
}
bool Settings::GetHideCursor() const
{
return SConfig::GetInstance().bHideCursor;
}
2018-04-22 10:56:15 +02:00
void Settings::SetKeepWindowOnTop(bool top)
{
if (IsKeepWindowOnTopEnabled() == top)
return;
SConfig::GetInstance().bKeepWindowOnTop = top;
emit KeepWindowOnTopChanged(top);
}
bool Settings::IsKeepWindowOnTopEnabled() const
{
return SConfig::GetInstance().bKeepWindowOnTop;
}
2017-06-21 10:26:06 +02:00
int Settings::GetVolume() const
{
return SConfig::GetInstance().m_Volume;
}
void Settings::SetVolume(int volume)
{
if (GetVolume() != volume)
{
SConfig::GetInstance().m_Volume = volume;
emit VolumeChanged(volume);
}
}
void Settings::IncreaseVolume(int volume)
{
AudioCommon::IncreaseVolume(volume);
emit VolumeChanged(GetVolume());
}
void Settings::DecreaseVolume(int volume)
{
AudioCommon::DecreaseVolume(volume);
emit VolumeChanged(GetVolume());
}
bool Settings::IsLogVisible() const
{
return GetQSettings().value(QStringLiteral("logging/logvisible")).toBool();
}
void Settings::SetLogVisible(bool visible)
{
if (IsLogVisible() != visible)
{
GetQSettings().setValue(QStringLiteral("logging/logvisible"), visible);
emit LogVisibilityChanged(visible);
}
}
bool Settings::IsLogConfigVisible() const
{
return GetQSettings().value(QStringLiteral("logging/logconfigvisible")).toBool();
}
void Settings::SetLogConfigVisible(bool visible)
{
if (IsLogConfigVisible() != visible)
{
GetQSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible);
emit LogConfigVisibilityChanged(visible);
}
}
2017-08-01 12:55:21 +02:00
GameListModel* Settings::GetGameListModel() const
{
static GameListModel* model = new GameListModel;
return model;
}
NetPlayClient* Settings::GetNetPlayClient()
{
return m_client.get();
}
void Settings::ResetNetPlayClient(NetPlayClient* client)
{
m_client.reset(client);
}
NetPlayServer* Settings::GetNetPlayServer()
{
return m_server.get();
}
void Settings::ResetNetPlayServer(NetPlayServer* server)
{
m_server.reset(server);
}
2017-08-30 21:00:59 +02:00
bool Settings::GetCheatsEnabled() const
{
return SConfig::GetInstance().bEnableCheats;
}
void Settings::SetCheatsEnabled(bool enabled)
{
if (SConfig::GetInstance().bEnableCheats != enabled)
{
SConfig::GetInstance().bEnableCheats = enabled;
emit EnableCheatsChanged(enabled);
}
}
2017-09-19 14:14:45 +02:00
void Settings::SetDebugModeEnabled(bool enabled)
{
if (IsDebugModeEnabled() != enabled)
{
SConfig::GetInstance().bEnableDebugging = enabled;
emit DebugModeToggled(enabled);
}
if (enabled)
SetCodeVisible(true);
2017-09-19 14:14:45 +02:00
}
bool Settings::IsDebugModeEnabled() const
{
return SConfig::GetInstance().bEnableDebugging;
}
void Settings::SetRegistersVisible(bool enabled)
{
if (IsRegistersVisible() != enabled)
{
GetQSettings().setValue(QStringLiteral("debugger/showregisters"), enabled);
emit RegistersVisibilityChanged(enabled);
}
}
bool Settings::IsRegistersVisible() const
{
return GetQSettings().value(QStringLiteral("debugger/showregisters")).toBool();
}
2017-09-27 08:53:05 +02:00
void Settings::SetWatchVisible(bool enabled)
{
if (IsWatchVisible() != enabled)
{
GetQSettings().setValue(QStringLiteral("debugger/showwatch"), enabled);
2017-09-27 08:53:05 +02:00
emit WatchVisibilityChanged(enabled);
}
}
bool Settings::IsWatchVisible() const
{
return GetQSettings().value(QStringLiteral("debugger/showwatch")).toBool();
2017-09-27 08:53:05 +02:00
}
void Settings::SetBreakpointsVisible(bool enabled)
{
if (IsBreakpointsVisible() != enabled)
{
GetQSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled);
emit BreakpointsVisibilityChanged(enabled);
}
}
bool Settings::IsBreakpointsVisible() const
{
return GetQSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool();
}
bool Settings::IsControllerStateNeeded() const
{
return m_controller_state_needed;
}
void Settings::SetControllerStateNeeded(bool needed)
{
m_controller_state_needed = needed;
}
2018-02-14 23:25:01 +01:00
void Settings::SetCodeVisible(bool enabled)
{
if (IsCodeVisible() != enabled)
{
GetQSettings().setValue(QStringLiteral("debugger/showcode"), enabled);
2018-02-14 23:25:01 +01:00
emit CodeVisibilityChanged(enabled);
}
}
bool Settings::IsCodeVisible() const
{
return GetQSettings().value(QStringLiteral("debugger/showcode")).toBool();
2018-02-14 23:25:01 +01:00
}
2018-03-16 12:39:53 +01:00
void Settings::SetMemoryVisible(bool enabled)
{
if (IsMemoryVisible() == enabled)
return;
QSettings().setValue(QStringLiteral("debugger/showmemory"), enabled);
emit MemoryVisibilityChanged(enabled);
}
bool Settings::IsMemoryVisible() const
{
return QSettings().value(QStringLiteral("debugger/showmemory")).toBool();
}
2018-02-14 23:25:01 +01:00
void Settings::SetDebugFont(QFont font)
{
if (GetDebugFont() != font)
{
GetQSettings().setValue(QStringLiteral("debugger/font"), font);
2018-02-14 23:25:01 +01:00
emit DebugFontChanged(font);
}
}
QFont Settings::GetDebugFont() const
{
QFont default_font = QFont(QStringLiteral("Monospace"));
default_font.setStyleHint(QFont::TypeWriter);
return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
2018-02-14 23:25:01 +01:00
}
2018-03-22 12:20:15 +01:00
void Settings::SetAutoUpdateTrack(const QString& mode)
{
if (mode == GetAutoUpdateTrack())
return;
SConfig::GetInstance().m_auto_update_track = mode.toStdString();
emit AutoUpdateTrackChanged(mode);
}
QString Settings::GetAutoUpdateTrack() const
{
return QString::fromStdString(SConfig::GetInstance().m_auto_update_track);
}
void Settings::SetAnalyticsEnabled(bool enabled)
{
if (enabled == IsAnalyticsEnabled())
return;
SConfig::GetInstance().m_analytics_enabled = enabled;
emit AnalyticsToggled(enabled);
}
bool Settings::IsAnalyticsEnabled() const
{
return SConfig::GetInstance().m_analytics_enabled;
}
2018-04-19 11:32:00 +02:00
void Settings::SetToolBarVisible(bool visible)
{
if (IsToolBarVisible() == visible)
return;
GetQSettings().setValue(QStringLiteral("toolbar/visible"), visible);
emit ToolBarVisibilityChanged(visible);
}
bool Settings::IsToolBarVisible() const
{
return GetQSettings().value(QStringLiteral("toolbar/visible")).toBool();
}
void Settings::SetWidgetsLocked(bool locked)
{
if (AreWidgetsLocked() == locked)
return;
GetQSettings().setValue(QStringLiteral("widgets/locked"), locked);
emit WidgetLockChanged(locked);
}
bool Settings::AreWidgetsLocked() const
{
return GetQSettings().value(QStringLiteral("widgets/locked"), true).toBool();
}