2015-12-20 23:36:39 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-05-09 16:49:10 +00:00
|
|
|
#include <QDir>
|
2017-07-06 00:35:47 +00:00
|
|
|
#include <QSettings>
|
2015-12-20 23:36:39 +00:00
|
|
|
#include <QSize>
|
|
|
|
|
2017-06-21 08:26:06 +00:00
|
|
|
#include "AudioCommon/AudioCommon.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "Common/FileSearch.h"
|
2015-12-20 23:36:39 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2015-12-20 23:36:39 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2017-08-01 10:55:21 +00:00
|
|
|
#include "DolphinQt2/GameList/GameListModel.h"
|
2015-12-20 23:36:39 +00:00
|
|
|
#include "DolphinQt2/Settings.h"
|
2017-05-20 15:53:17 +00:00
|
|
|
#include "InputCommon/InputConfig.h"
|
2015-12-20 23:36:39 +00:00
|
|
|
|
2017-07-06 00:35:47 +00:00
|
|
|
Settings::Settings() = default;
|
2015-12-20 23:36:39 +00:00
|
|
|
|
2017-05-31 07:17:39 +00:00
|
|
|
Settings& Settings::Instance()
|
|
|
|
{
|
|
|
|
static Settings settings;
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2017-05-31 23:15:48 +00:00
|
|
|
void Settings::SetThemeName(const QString& theme_name)
|
|
|
|
{
|
|
|
|
SConfig::GetInstance().theme_name = theme_name.toStdString();
|
|
|
|
emit ThemeChanged();
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
QString Settings::GetProfilesDir() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(File::GetUserPath(D_CONFIG_IDX) + "Profiles/");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Settings::GetProfileINIPath(const InputConfig* config, const QString& name) const
|
|
|
|
{
|
|
|
|
return GetProfilesDir() + QString::fromStdString(config->GetProfileName()) + QDir::separator() +
|
|
|
|
name + QStringLiteral(".ini");
|
|
|
|
}
|
|
|
|
|
2015-12-20 23:36:39 +00:00
|
|
|
QStringList Settings::GetPaths() const
|
|
|
|
{
|
2017-06-22 22:11:53 +00:00
|
|
|
QStringList list;
|
|
|
|
for (const auto& path : SConfig::GetInstance().m_ISOFolder)
|
|
|
|
list << QString::fromStdString(path);
|
|
|
|
return list;
|
2017-05-31 07:42:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
void Settings::AddPath(const QString& qpath)
|
2015-12-20 23:36:39 +00:00
|
|
|
{
|
2017-06-22 22:11:53 +00:00
|
|
|
std::string path = qpath.toStdString();
|
2015-12-20 23:36:39 +00:00
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
std::vector<std::string>& paths = SConfig::GetInstance().m_ISOFolder;
|
|
|
|
if (std::find(paths.begin(), paths.end(), path) != paths.end())
|
2017-05-31 07:42:15 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
paths.emplace_back(path);
|
|
|
|
emit PathAdded(qpath);
|
2017-05-04 04:19:51 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
void Settings::RemovePath(const QString& qpath)
|
2017-05-04 04:19:51 +00:00
|
|
|
{
|
2017-06-22 22:11:53 +00:00
|
|
|
std::string path = qpath.toStdString();
|
|
|
|
std::vector<std::string>& paths = SConfig::GetInstance().m_ISOFolder;
|
2017-05-04 04:19:51 +00:00
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
auto new_end = std::remove(paths.begin(), paths.end(), path);
|
|
|
|
if (new_end == paths.end())
|
|
|
|
return;
|
2015-12-20 23:36:39 +00:00
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
paths.erase(new_end, paths.end());
|
|
|
|
emit PathRemoved(qpath);
|
2015-12-20 23:36:39 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 10:29:39 +00:00
|
|
|
bool Settings::GetPreferredView() const
|
|
|
|
{
|
2017-07-06 00:35:47 +00:00
|
|
|
return QSettings().value(QStringLiteral("PreferredView"), true).toBool();
|
2016-01-01 10:29:39 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 08:28:53 +00:00
|
|
|
void Settings::SetPreferredView(bool list)
|
2016-01-01 10:29:39 +00:00
|
|
|
{
|
2017-08-05 08:28:53 +00:00
|
|
|
QSettings().setValue(QStringLiteral("PreferredView"), list);
|
2015-12-20 23:36:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 01:56:40 +00:00
|
|
|
int Settings::GetStateSlot() const
|
|
|
|
{
|
2017-07-06 00:35:47 +00:00
|
|
|
return QSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt();
|
2016-02-15 01:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::SetStateSlot(int slot)
|
|
|
|
{
|
2017-07-06 00:35:47 +00:00
|
|
|
QSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot);
|
2015-12-20 23:36:39 +00:00
|
|
|
}
|
2017-05-08 17:03:59 +00:00
|
|
|
|
2017-06-01 06:49:06 +00:00
|
|
|
void Settings::SetHideCursor(bool hide_cursor)
|
|
|
|
{
|
|
|
|
SConfig::GetInstance().bHideCursor = hide_cursor;
|
|
|
|
emit HideCursorChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Settings::GetHideCursor() const
|
|
|
|
{
|
|
|
|
return SConfig::GetInstance().bHideCursor;
|
|
|
|
}
|
|
|
|
|
2017-06-21 08:26:06 +00: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());
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:53:17 +00:00
|
|
|
QVector<QString> Settings::GetProfiles(const InputConfig* config) const
|
|
|
|
{
|
|
|
|
const std::string path = GetProfilesDir().toStdString() + config->GetProfileName();
|
|
|
|
QVector<QString> vec;
|
|
|
|
|
2017-06-21 04:24:26 +00:00
|
|
|
for (const auto& file : Common::DoFileSearch({path}, {".ini"}))
|
2017-05-20 15:53:17 +00:00
|
|
|
{
|
|
|
|
std::string basename;
|
|
|
|
SplitPath(file, nullptr, &basename, nullptr);
|
|
|
|
vec.push_back(QString::fromStdString(basename));
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
2017-07-04 13:21:33 +00:00
|
|
|
|
|
|
|
bool Settings::IsLogVisible() const
|
|
|
|
{
|
2017-06-25 17:40:01 +00:00
|
|
|
return QSettings().value(QStringLiteral("logging/logvisible")).toBool();
|
2017-07-04 13:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::SetLogVisible(bool visible)
|
|
|
|
{
|
|
|
|
if (IsLogVisible() != visible)
|
|
|
|
{
|
2017-06-25 17:40:01 +00:00
|
|
|
QSettings().setValue(QStringLiteral("logging/logvisible"), visible);
|
2017-07-04 13:21:33 +00:00
|
|
|
emit LogVisibilityChanged(visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Settings::IsLogConfigVisible() const
|
|
|
|
{
|
2017-06-25 17:40:01 +00:00
|
|
|
return QSettings().value(QStringLiteral("logging/logconfigvisible")).toBool();
|
2017-07-04 13:21:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::SetLogConfigVisible(bool visible)
|
|
|
|
{
|
|
|
|
if (IsLogConfigVisible() != visible)
|
|
|
|
{
|
2017-06-25 17:40:01 +00:00
|
|
|
QSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible);
|
2017-07-04 13:21:33 +00:00
|
|
|
emit LogConfigVisibilityChanged(visible);
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 10:55:21 +00: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);
|
|
|
|
}
|