Settings.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. // Copyright 2015 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DolphinQt/Settings.h"
  4. #include <atomic>
  5. #include <memory>
  6. #include <QApplication>
  7. #include <QColor>
  8. #include <QDir>
  9. #include <QFile>
  10. #include <QFileInfo>
  11. #include <QFontDatabase>
  12. #include <QPalette>
  13. #include <QRadioButton>
  14. #include <QSize>
  15. #include <QStyle>
  16. #include <QStyleHints>
  17. #include <QWidget>
  18. #include "AudioCommon/AudioCommon.h"
  19. #include "Common/Config/Config.h"
  20. #include "Common/Contains.h"
  21. #include "Common/FileUtil.h"
  22. #include "Common/StringUtil.h"
  23. #include "Core/AchievementManager.h"
  24. #include "Core/Config/GraphicsSettings.h"
  25. #include "Core/Config/MainSettings.h"
  26. #include "Core/ConfigManager.h"
  27. #include "Core/Core.h"
  28. #include "Core/IOS/IOS.h"
  29. #include "Core/NetPlayClient.h"
  30. #include "Core/NetPlayServer.h"
  31. #include "Core/System.h"
  32. #include "DolphinQt/Host.h"
  33. #include "DolphinQt/QtUtils/QueueOnObject.h"
  34. #include "InputCommon/ControllerInterface/ControllerInterface.h"
  35. #include "InputCommon/InputConfig.h"
  36. #include "VideoCommon/NetPlayChatUI.h"
  37. #include "VideoCommon/NetPlayGolfUI.h"
  38. static std::unique_ptr<QPalette> s_default_palette;
  39. Settings::Settings()
  40. {
  41. qRegisterMetaType<Core::State>();
  42. Core::AddOnStateChangedCallback([this](Core::State new_state) {
  43. QueueOnObject(this, [this, new_state] {
  44. // Avoid signal spam while continuously frame stepping. Will still send a signal for the first
  45. // and last framestep.
  46. if (!m_continuously_frame_stepping)
  47. emit EmulationStateChanged(new_state);
  48. });
  49. });
  50. Config::AddConfigChangedCallback([this] {
  51. static std::atomic<bool> do_once{true};
  52. if (do_once.exchange(false))
  53. {
  54. // Calling ConfigChanged() with a "delay" can have risks, for example, if from
  55. // code we change some configs that result in Qt greying out some setting, we could
  56. // end up editing that setting before its greyed out, sending out an event,
  57. // which might not be expected or handled by the code, potentially crashing.
  58. // The only safe option would be to wait on the Qt thread to have finished executing this.
  59. QueueOnObject(this, [this] {
  60. do_once = true;
  61. emit ConfigChanged();
  62. });
  63. }
  64. });
  65. m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] {
  66. if (Core::IsHostThread())
  67. {
  68. emit DevicesChanged();
  69. }
  70. else
  71. {
  72. // Any device shared_ptr in the host thread needs to be released immediately as otherwise
  73. // they'd continue living until the queued event has run, but some devices can't be recreated
  74. // until they are destroyed.
  75. // This is safe from any thread. Devices will be refreshed and re-acquired and in
  76. // DevicesChanged(). Calling it without queueing shouldn't cause any deadlocks but is slow.
  77. emit ReleaseDevices();
  78. QueueOnObject(this, [this] { emit DevicesChanged(); });
  79. }
  80. });
  81. }
  82. Settings::~Settings() = default;
  83. void Settings::UnregisterDevicesChangedCallback()
  84. {
  85. g_controller_interface.UnregisterDevicesChangedCallback(m_hotplug_callback_handle);
  86. }
  87. Settings& Settings::Instance()
  88. {
  89. static Settings settings;
  90. return settings;
  91. }
  92. QSettings& Settings::GetQSettings()
  93. {
  94. static QSettings settings(
  95. QStringLiteral("%1/Qt.ini").arg(QString::fromStdString(File::GetUserPath(D_CONFIG_IDX))),
  96. QSettings::IniFormat);
  97. return settings;
  98. }
  99. void Settings::TriggerThemeChanged()
  100. {
  101. emit ThemeChanged();
  102. }
  103. QString Settings::GetUserStyleName() const
  104. {
  105. if (GetQSettings().contains(QStringLiteral("userstyle/name")))
  106. return GetQSettings().value(QStringLiteral("userstyle/name")).toString();
  107. // Migration code for the old way of storing this setting
  108. return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName();
  109. }
  110. void Settings::SetUserStyleName(const QString& stylesheet_name)
  111. {
  112. GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name);
  113. }
  114. void Settings::InitDefaultPalette()
  115. {
  116. s_default_palette = std::make_unique<QPalette>(qApp->palette());
  117. }
  118. bool Settings::IsSystemDark()
  119. {
  120. #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
  121. return (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark);
  122. #else
  123. return false;
  124. #endif
  125. }
  126. bool Settings::IsThemeDark()
  127. {
  128. return qApp->palette().color(QPalette::Base).valueF() < 0.5;
  129. }
  130. // Calling this before the main window has been created breaks the style of some widgets.
  131. void Settings::ApplyStyle()
  132. {
  133. const StyleType style_type = GetStyleType();
  134. const QString stylesheet_name = GetUserStyleName();
  135. QString stylesheet_contents;
  136. // If we haven't found one, we continue with an empty (default) style
  137. if (!stylesheet_name.isEmpty() && style_type == StyleType::User)
  138. {
  139. // Load custom user stylesheet
  140. QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX)));
  141. QFile stylesheet(directory.filePath(stylesheet_name));
  142. if (stylesheet.open(QFile::ReadOnly))
  143. stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
  144. }
  145. #ifdef _WIN32
  146. if (stylesheet_contents.isEmpty())
  147. {
  148. // No theme selected or found. Usually we would just fallthrough and set an empty stylesheet
  149. // which would select Qt's default theme, but unlike other OSes we don't automatically get a
  150. // default dark theme on Windows when the user has selected dark mode in the Windows settings.
  151. // So manually check if the user wants dark mode and, if yes, load our embedded dark theme.
  152. if (style_type == StyleType::Dark || (style_type != StyleType::Light && IsSystemDark()))
  153. {
  154. QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss"));
  155. if (file.open(QFile::ReadOnly))
  156. stylesheet_contents = QString::fromUtf8(file.readAll().data());
  157. QPalette palette = qApp->style()->standardPalette();
  158. palette.setColor(QPalette::Window, QColor(32, 32, 32));
  159. palette.setColor(QPalette::WindowText, QColor(220, 220, 220));
  160. palette.setColor(QPalette::Base, QColor(32, 32, 32));
  161. palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48));
  162. palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126));
  163. palette.setColor(QPalette::Text, QColor(220, 220, 220));
  164. palette.setColor(QPalette::Button, QColor(48, 48, 48));
  165. palette.setColor(QPalette::ButtonText, QColor(220, 220, 220));
  166. palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
  167. palette.setColor(QPalette::Highlight, QColor(0, 120, 215));
  168. palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
  169. palette.setColor(QPalette::Link, QColor(100, 160, 220));
  170. palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220));
  171. qApp->setPalette(palette);
  172. }
  173. else
  174. {
  175. // reset any palette changes that may exist from a previously set dark mode
  176. if (s_default_palette)
  177. qApp->setPalette(*s_default_palette);
  178. }
  179. }
  180. #endif
  181. // Define tooltips style if not already defined
  182. if (!stylesheet_contents.contains(QStringLiteral("QToolTip"), Qt::CaseSensitive))
  183. {
  184. const QPalette& palette = qApp->palette();
  185. QColor window_color;
  186. QColor text_color;
  187. QColor unused_text_emphasis_color;
  188. QColor border_color;
  189. GetToolTipStyle(window_color, text_color, unused_text_emphasis_color, border_color, palette,
  190. palette);
  191. const auto tooltip_stylesheet =
  192. QStringLiteral("QToolTip { background-color: #%1; color: #%2; padding: 8px; "
  193. "border: 1px; border-style: solid; border-color: #%3; }")
  194. .arg(window_color.rgba(), 0, 16)
  195. .arg(text_color.rgba(), 0, 16)
  196. .arg(border_color.rgba(), 0, 16);
  197. stylesheet_contents.append(QStringLiteral("%1").arg(tooltip_stylesheet));
  198. }
  199. qApp->setStyleSheet(stylesheet_contents);
  200. }
  201. Settings::StyleType Settings::GetStyleType() const
  202. {
  203. if (GetQSettings().contains(QStringLiteral("userstyle/styletype")))
  204. {
  205. bool ok = false;
  206. const int type_int = GetQSettings().value(QStringLiteral("userstyle/styletype")).toInt(&ok);
  207. if (ok && type_int >= static_cast<int>(StyleType::MinValue) &&
  208. type_int <= static_cast<int>(StyleType::MaxValue))
  209. {
  210. return static_cast<StyleType>(type_int);
  211. }
  212. }
  213. // if the style type is unset or invalid, try the old enabled flag instead
  214. const bool enabled = GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool();
  215. return enabled ? StyleType::User : StyleType::System;
  216. }
  217. void Settings::SetStyleType(StyleType type)
  218. {
  219. GetQSettings().setValue(QStringLiteral("userstyle/styletype"), static_cast<int>(type));
  220. // also set the old setting so that the config is correctly intepreted by older Dolphin builds
  221. GetQSettings().setValue(QStringLiteral("userstyle/enabled"), type == StyleType::User);
  222. }
  223. void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color,
  224. QColor& emphasis_text_color, QColor& border_color,
  225. const QPalette& palette, const QPalette& high_contrast_palette) const
  226. {
  227. const auto theme_window_color = palette.color(QPalette::Base);
  228. const auto theme_window_hsv = theme_window_color.toHsv();
  229. const auto brightness = theme_window_hsv.value();
  230. const bool brightness_over_threshold = brightness > 128;
  231. const QColor emphasis_text_color_1 = Qt::yellow;
  232. const QColor emphasis_text_color_2 = QColor(QStringLiteral("#0090ff")); // ~light blue
  233. if (Config::Get(Config::MAIN_USE_HIGH_CONTRAST_TOOLTIPS))
  234. {
  235. window_color = brightness_over_threshold ? QColor(72, 72, 72) : Qt::white;
  236. text_color = brightness_over_threshold ? Qt::white : Qt::black;
  237. emphasis_text_color = brightness_over_threshold ? emphasis_text_color_1 : emphasis_text_color_2;
  238. border_color = high_contrast_palette.color(QPalette::Window).darker(160);
  239. }
  240. else
  241. {
  242. window_color = palette.color(QPalette::Window);
  243. text_color = palette.color(QPalette::Text);
  244. emphasis_text_color = brightness_over_threshold ? emphasis_text_color_2 : emphasis_text_color_1;
  245. border_color = palette.color(QPalette::Text);
  246. }
  247. }
  248. QStringList Settings::GetPaths() const
  249. {
  250. QStringList list;
  251. for (const auto& path : Config::GetIsoPaths())
  252. list << QString::fromStdString(path);
  253. return list;
  254. }
  255. void Settings::AddPath(const QString& qpath)
  256. {
  257. std::string path = qpath.toStdString();
  258. std::vector<std::string> paths = Config::GetIsoPaths();
  259. if (Common::Contains(paths, path))
  260. return;
  261. paths.emplace_back(path);
  262. Config::SetIsoPaths(paths);
  263. emit PathAdded(qpath);
  264. }
  265. void Settings::RemovePath(const QString& qpath)
  266. {
  267. std::string path = qpath.toStdString();
  268. std::vector<std::string> paths = Config::GetIsoPaths();
  269. if (std::erase(paths, path) == 0)
  270. return;
  271. Config::SetIsoPaths(paths);
  272. emit PathRemoved(qpath);
  273. }
  274. void Settings::RefreshGameList()
  275. {
  276. emit GameListRefreshRequested();
  277. }
  278. void Settings::NotifyRefreshGameListStarted()
  279. {
  280. emit GameListRefreshStarted();
  281. }
  282. void Settings::NotifyRefreshGameListComplete()
  283. {
  284. emit GameListRefreshCompleted();
  285. }
  286. void Settings::NotifyMetadataRefreshComplete()
  287. {
  288. emit MetadataRefreshCompleted();
  289. }
  290. void Settings::ReloadTitleDB()
  291. {
  292. emit TitleDBReloadRequested();
  293. }
  294. bool Settings::IsAutoRefreshEnabled() const
  295. {
  296. return GetQSettings().value(QStringLiteral("gamelist/autorefresh"), true).toBool();
  297. }
  298. void Settings::SetAutoRefreshEnabled(bool enabled)
  299. {
  300. if (IsAutoRefreshEnabled() == enabled)
  301. return;
  302. GetQSettings().setValue(QStringLiteral("gamelist/autorefresh"), enabled);
  303. emit AutoRefreshToggled(enabled);
  304. }
  305. QString Settings::GetDefaultGame() const
  306. {
  307. return QString::fromStdString(Config::Get(Config::MAIN_DEFAULT_ISO));
  308. }
  309. void Settings::SetDefaultGame(QString path)
  310. {
  311. if (GetDefaultGame() != path)
  312. {
  313. Config::SetBase(Config::MAIN_DEFAULT_ISO, path.toStdString());
  314. emit DefaultGameChanged(path);
  315. }
  316. }
  317. bool Settings::GetPreferredView() const
  318. {
  319. return GetQSettings().value(QStringLiteral("PreferredView"), true).toBool();
  320. }
  321. void Settings::SetPreferredView(bool list)
  322. {
  323. GetQSettings().setValue(QStringLiteral("PreferredView"), list);
  324. }
  325. int Settings::GetStateSlot() const
  326. {
  327. return GetQSettings().value(QStringLiteral("Emulation/StateSlot"), 1).toInt();
  328. }
  329. void Settings::SetStateSlot(int slot)
  330. {
  331. GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot);
  332. }
  333. Config::ShowCursor Settings::GetCursorVisibility() const
  334. {
  335. return Config::Get(Config::MAIN_SHOW_CURSOR);
  336. }
  337. bool Settings::GetLockCursor() const
  338. {
  339. return Config::Get(Config::MAIN_LOCK_CURSOR);
  340. }
  341. void Settings::SetKeepWindowOnTop(bool top)
  342. {
  343. if (IsKeepWindowOnTopEnabled() == top)
  344. return;
  345. emit KeepWindowOnTopChanged(top);
  346. }
  347. bool Settings::IsKeepWindowOnTopEnabled() const
  348. {
  349. return Config::Get(Config::MAIN_KEEP_WINDOW_ON_TOP);
  350. }
  351. bool Settings::GetGraphicModsEnabled() const
  352. {
  353. return Config::Get(Config::GFX_MODS_ENABLE);
  354. }
  355. void Settings::SetGraphicModsEnabled(bool enabled)
  356. {
  357. if (GetGraphicModsEnabled() == enabled)
  358. {
  359. return;
  360. }
  361. Config::SetBaseOrCurrent(Config::GFX_MODS_ENABLE, enabled);
  362. emit EnableGfxModsChanged(enabled);
  363. }
  364. int Settings::GetVolume() const
  365. {
  366. return Config::Get(Config::MAIN_AUDIO_VOLUME);
  367. }
  368. void Settings::SetVolume(int volume)
  369. {
  370. if (GetVolume() != volume)
  371. {
  372. Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, volume);
  373. emit VolumeChanged(volume);
  374. }
  375. }
  376. void Settings::IncreaseVolume(int volume)
  377. {
  378. AudioCommon::IncreaseVolume(Core::System::GetInstance(), volume);
  379. emit VolumeChanged(GetVolume());
  380. }
  381. void Settings::DecreaseVolume(int volume)
  382. {
  383. AudioCommon::DecreaseVolume(Core::System::GetInstance(), volume);
  384. emit VolumeChanged(GetVolume());
  385. }
  386. bool Settings::IsLogVisible() const
  387. {
  388. return GetQSettings().value(QStringLiteral("logging/logvisible")).toBool();
  389. }
  390. void Settings::SetLogVisible(bool visible)
  391. {
  392. if (IsLogVisible() != visible)
  393. {
  394. GetQSettings().setValue(QStringLiteral("logging/logvisible"), visible);
  395. emit LogVisibilityChanged(visible);
  396. }
  397. }
  398. bool Settings::IsLogConfigVisible() const
  399. {
  400. return GetQSettings().value(QStringLiteral("logging/logconfigvisible")).toBool();
  401. }
  402. void Settings::SetLogConfigVisible(bool visible)
  403. {
  404. if (IsLogConfigVisible() != visible)
  405. {
  406. GetQSettings().setValue(QStringLiteral("logging/logconfigvisible"), visible);
  407. emit LogConfigVisibilityChanged(visible);
  408. }
  409. }
  410. std::shared_ptr<NetPlay::NetPlayClient> Settings::GetNetPlayClient()
  411. {
  412. return m_client;
  413. }
  414. void Settings::ResetNetPlayClient(NetPlay::NetPlayClient* client)
  415. {
  416. m_client.reset(client);
  417. g_netplay_chat_ui.reset();
  418. g_netplay_golf_ui.reset();
  419. }
  420. std::shared_ptr<NetPlay::NetPlayServer> Settings::GetNetPlayServer()
  421. {
  422. return m_server;
  423. }
  424. void Settings::ResetNetPlayServer(NetPlay::NetPlayServer* server)
  425. {
  426. m_server.reset(server);
  427. }
  428. bool Settings::GetCheatsEnabled() const
  429. {
  430. return Config::Get(Config::MAIN_ENABLE_CHEATS);
  431. }
  432. void Settings::SetDebugModeEnabled(bool enabled)
  433. {
  434. if (AchievementManager::GetInstance().IsHardcoreModeActive())
  435. enabled = false;
  436. if (IsDebugModeEnabled() != enabled)
  437. {
  438. Config::SetBaseOrCurrent(Config::MAIN_ENABLE_DEBUGGING, enabled);
  439. emit DebugModeToggled(enabled);
  440. if (enabled)
  441. SetCodeVisible(true);
  442. }
  443. }
  444. bool Settings::IsDebugModeEnabled() const
  445. {
  446. return Config::Get(Config::MAIN_ENABLE_DEBUGGING);
  447. }
  448. void Settings::SetRegistersVisible(bool enabled)
  449. {
  450. if (IsRegistersVisible() != enabled)
  451. {
  452. GetQSettings().setValue(QStringLiteral("debugger/showregisters"), enabled);
  453. emit RegistersVisibilityChanged(enabled);
  454. }
  455. }
  456. bool Settings::IsThreadsVisible() const
  457. {
  458. return GetQSettings().value(QStringLiteral("debugger/showthreads")).toBool();
  459. }
  460. void Settings::SetThreadsVisible(bool enabled)
  461. {
  462. if (IsThreadsVisible() == enabled)
  463. return;
  464. GetQSettings().setValue(QStringLiteral("debugger/showthreads"), enabled);
  465. emit ThreadsVisibilityChanged(enabled);
  466. }
  467. bool Settings::IsRegistersVisible() const
  468. {
  469. return GetQSettings().value(QStringLiteral("debugger/showregisters")).toBool();
  470. }
  471. void Settings::SetWatchVisible(bool enabled)
  472. {
  473. if (IsWatchVisible() != enabled)
  474. {
  475. GetQSettings().setValue(QStringLiteral("debugger/showwatch"), enabled);
  476. emit WatchVisibilityChanged(enabled);
  477. }
  478. }
  479. bool Settings::IsWatchVisible() const
  480. {
  481. return GetQSettings().value(QStringLiteral("debugger/showwatch")).toBool();
  482. }
  483. void Settings::SetBreakpointsVisible(bool enabled)
  484. {
  485. if (IsBreakpointsVisible() != enabled)
  486. {
  487. GetQSettings().setValue(QStringLiteral("debugger/showbreakpoints"), enabled);
  488. emit BreakpointsVisibilityChanged(enabled);
  489. }
  490. }
  491. bool Settings::IsBreakpointsVisible() const
  492. {
  493. return GetQSettings().value(QStringLiteral("debugger/showbreakpoints")).toBool();
  494. }
  495. void Settings::SetCodeVisible(bool enabled)
  496. {
  497. if (IsCodeVisible() != enabled)
  498. {
  499. GetQSettings().setValue(QStringLiteral("debugger/showcode"), enabled);
  500. emit CodeVisibilityChanged(enabled);
  501. }
  502. }
  503. bool Settings::IsCodeVisible() const
  504. {
  505. return GetQSettings().value(QStringLiteral("debugger/showcode")).toBool();
  506. }
  507. void Settings::SetMemoryVisible(bool enabled)
  508. {
  509. if (IsMemoryVisible() == enabled)
  510. return;
  511. GetQSettings().setValue(QStringLiteral("debugger/showmemory"), enabled);
  512. emit MemoryVisibilityChanged(enabled);
  513. }
  514. bool Settings::IsMemoryVisible() const
  515. {
  516. return GetQSettings().value(QStringLiteral("debugger/showmemory")).toBool();
  517. }
  518. void Settings::SetNetworkVisible(bool enabled)
  519. {
  520. if (IsNetworkVisible() == enabled)
  521. return;
  522. GetQSettings().setValue(QStringLiteral("debugger/shownetwork"), enabled);
  523. emit NetworkVisibilityChanged(enabled);
  524. }
  525. bool Settings::IsNetworkVisible() const
  526. {
  527. return GetQSettings().value(QStringLiteral("debugger/shownetwork")).toBool();
  528. }
  529. void Settings::SetJITVisible(bool enabled)
  530. {
  531. if (IsJITVisible() == enabled)
  532. return;
  533. GetQSettings().setValue(QStringLiteral("debugger/showjit"), enabled);
  534. emit JITVisibilityChanged(enabled);
  535. }
  536. bool Settings::IsJITVisible() const
  537. {
  538. return GetQSettings().value(QStringLiteral("debugger/showjit")).toBool();
  539. }
  540. void Settings::SetAssemblerVisible(bool enabled)
  541. {
  542. if (IsAssemblerVisible() == enabled)
  543. return;
  544. GetQSettings().setValue(QStringLiteral("debugger/showassembler"), enabled);
  545. emit AssemblerVisibilityChanged(enabled);
  546. }
  547. bool Settings::IsAssemblerVisible() const
  548. {
  549. return GetQSettings().value(QStringLiteral("debugger/showassembler")).toBool();
  550. }
  551. void Settings::RefreshWidgetVisibility()
  552. {
  553. emit DebugModeToggled(IsDebugModeEnabled());
  554. emit LogVisibilityChanged(IsLogVisible());
  555. emit LogConfigVisibilityChanged(IsLogConfigVisible());
  556. }
  557. void Settings::SetDebugFont(QFont font)
  558. {
  559. if (GetDebugFont() != font)
  560. {
  561. GetQSettings().setValue(QStringLiteral("debugger/font"), font);
  562. emit DebugFontChanged(font);
  563. }
  564. }
  565. QFont Settings::GetDebugFont() const
  566. {
  567. QFont default_font = QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
  568. default_font.setPointSizeF(9.0);
  569. return GetQSettings().value(QStringLiteral("debugger/font"), default_font).value<QFont>();
  570. }
  571. void Settings::SetAutoUpdateTrack(const QString& mode)
  572. {
  573. if (mode == GetAutoUpdateTrack())
  574. return;
  575. Config::SetBase(Config::MAIN_AUTOUPDATE_UPDATE_TRACK, mode.toStdString());
  576. emit AutoUpdateTrackChanged(mode);
  577. }
  578. QString Settings::GetAutoUpdateTrack() const
  579. {
  580. return QString::fromStdString(Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK));
  581. }
  582. void Settings::SetFallbackRegion(const DiscIO::Region& region)
  583. {
  584. if (region == GetFallbackRegion())
  585. return;
  586. Config::SetBase(Config::MAIN_FALLBACK_REGION, region);
  587. emit FallbackRegionChanged(region);
  588. }
  589. DiscIO::Region Settings::GetFallbackRegion() const
  590. {
  591. return Config::Get(Config::MAIN_FALLBACK_REGION);
  592. }
  593. void Settings::SetAnalyticsEnabled(bool enabled)
  594. {
  595. if (enabled == IsAnalyticsEnabled())
  596. return;
  597. Config::SetBase(Config::MAIN_ANALYTICS_ENABLED, enabled);
  598. emit AnalyticsToggled(enabled);
  599. }
  600. bool Settings::IsAnalyticsEnabled() const
  601. {
  602. return Config::Get(Config::MAIN_ANALYTICS_ENABLED);
  603. }
  604. void Settings::SetToolBarVisible(bool visible)
  605. {
  606. if (IsToolBarVisible() == visible)
  607. return;
  608. GetQSettings().setValue(QStringLiteral("toolbar/visible"), visible);
  609. emit ToolBarVisibilityChanged(visible);
  610. }
  611. bool Settings::IsToolBarVisible() const
  612. {
  613. return GetQSettings().value(QStringLiteral("toolbar/visible"), true).toBool();
  614. }
  615. void Settings::SetWidgetsLocked(bool locked)
  616. {
  617. if (AreWidgetsLocked() == locked)
  618. return;
  619. GetQSettings().setValue(QStringLiteral("widgets/locked"), locked);
  620. emit WidgetLockChanged(locked);
  621. }
  622. bool Settings::AreWidgetsLocked() const
  623. {
  624. return GetQSettings().value(QStringLiteral("widgets/locked"), true).toBool();
  625. }
  626. bool Settings::IsBatchModeEnabled() const
  627. {
  628. return m_batch;
  629. }
  630. void Settings::SetBatchModeEnabled(bool batch)
  631. {
  632. m_batch = batch;
  633. }
  634. bool Settings::IsSDCardInserted() const
  635. {
  636. return Config::Get(Config::MAIN_WII_SD_CARD);
  637. }
  638. void Settings::SetSDCardInserted(bool inserted)
  639. {
  640. if (IsSDCardInserted() != inserted)
  641. {
  642. Config::SetBaseOrCurrent(Config::MAIN_WII_SD_CARD, inserted);
  643. emit SDCardInsertionChanged(inserted);
  644. }
  645. }
  646. bool Settings::IsUSBKeyboardConnected() const
  647. {
  648. return Config::Get(Config::MAIN_WII_KEYBOARD);
  649. }
  650. void Settings::SetUSBKeyboardConnected(bool connected)
  651. {
  652. if (IsUSBKeyboardConnected() != connected)
  653. {
  654. Config::SetBaseOrCurrent(Config::MAIN_WII_KEYBOARD, connected);
  655. emit USBKeyboardConnectionChanged(connected);
  656. }
  657. }
  658. void Settings::SetIsContinuouslyFrameStepping(bool is_stepping)
  659. {
  660. m_continuously_frame_stepping = is_stepping;
  661. }
  662. bool Settings::GetIsContinuouslyFrameStepping() const
  663. {
  664. return m_continuously_frame_stepping;
  665. }