Skip to content

Commit

Permalink
DolphinQT: Create toggle for enabling/disabling time tracking
Browse files Browse the repository at this point in the history
Introduce a new "Enable Time Tracking" checkbox in the InterfacePane UI. The checkbox is dynamically enabled or disabled based on the emulation state, preventing changes while emulation is active.
  • Loading branch information
aminoa committed Jan 24, 2025
1 parent e3b6e6d commit fa549c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/Core/DolphinQt/Settings/InterfacePane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Core/AchievementManager.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/UISettings.h"
#include "Core/System.h"

#include "DolphinQt/Config/ConfigControls/ConfigBool.h"
#include "DolphinQt/Config/ConfigControls/ConfigChoice.h"
Expand All @@ -32,6 +33,7 @@
#include "DolphinQt/QtUtils/SignalBlocking.h"
#include "DolphinQt/Settings.h"

#include <Core/Core.h>
#include "UICommon/GameFile.h"

static ConfigStringChoice* MakeLanguageComboBox()
Expand Down Expand Up @@ -95,6 +97,10 @@ InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent)

connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&InterfacePane::UpdateShowDebuggingCheckbox);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&InterfacePane::OnEmulationStateChanged);

OnEmulationStateChanged(Core::GetState(Core::System::GetInstance()));
}

void InterfacePane::CreateLayout()
Expand Down Expand Up @@ -168,12 +174,15 @@ void InterfacePane::CreateUI()
new ConfigBool(tr("Hotkeys Require Window Focus"), Config::MAIN_FOCUSED_HOTKEYS);
m_checkbox_disable_screensaver =
new ConfigBool(tr("Inhibit Screensaver During Emulation"), Config::MAIN_DISABLE_SCREENSAVER);
m_checkbox_time_tracking =
new ConfigBool(tr("Enable Play Time Tracking"), Config::MAIN_TIME_TRACKING);

groupbox_layout->addWidget(m_checkbox_use_builtin_title_database);
groupbox_layout->addWidget(m_checkbox_use_covers);
groupbox_layout->addWidget(m_checkbox_show_debugging_ui);
groupbox_layout->addWidget(m_checkbox_focused_hotkeys);
groupbox_layout->addWidget(m_checkbox_disable_screensaver);
groupbox_layout->addWidget(m_checkbox_time_tracking);
}

void InterfacePane::CreateInGame()
Expand Down Expand Up @@ -313,6 +322,12 @@ void InterfacePane::OnLanguageChanged()
tr("You must restart Dolphin in order for the change to take effect."));
}

void InterfacePane::OnEmulationStateChanged(Core::State state)
{
const bool running = state != Core::State::Uninitialized;
m_checkbox_time_tracking->setEnabled(!running);
}

void InterfacePane::AddDescriptions()
{
static constexpr char TR_TITLE_DATABASE_DESCRIPTION[] = QT_TR_NOOP(
Expand Down Expand Up @@ -341,6 +356,10 @@ void InterfacePane::AddDescriptions()
static constexpr char TR_DISABLE_SCREENSAVER_DESCRIPTION[] =
QT_TR_NOOP("Disables your screensaver while running a game."
"<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>");
static constexpr char TR_TIME_TRACKING[] = QT_TR_NOOP(
"Tracks the time you spend playing games and shows it in the List View (as hours/minutes)."
"<br><br>This setting cannot be changed while emulation is active."
"<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>");
static constexpr char TR_CONFIRM_ON_STOP_DESCRIPTION[] =
QT_TR_NOOP("Prompts you to confirm that you want to end emulation when you press Stop."
"<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>");
Expand Down Expand Up @@ -394,6 +413,8 @@ void InterfacePane::AddDescriptions()

m_checkbox_disable_screensaver->SetDescription(tr(TR_DISABLE_SCREENSAVER_DESCRIPTION));

m_checkbox_time_tracking->SetDescription(tr(TR_TIME_TRACKING));

m_checkbox_confirm_on_stop->SetDescription(tr(TR_CONFIRM_ON_STOP_DESCRIPTION));

m_checkbox_use_panic_handlers->SetDescription(tr(TR_USE_PANIC_HANDLERS_DESCRIPTION));
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/DolphinQt/Settings/InterfacePane.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class QVBoxLayout;
class ToolTipCheckBox;
class ToolTipComboBox;

namespace Core
{
enum class State;
}

class InterfacePane final : public QWidget
{
Q_OBJECT
Expand All @@ -30,6 +35,8 @@ class InterfacePane final : public QWidget
void OnUserStyleChanged();
void OnLanguageChanged();

void OnEmulationStateChanged(Core::State state);

QVBoxLayout* m_main_layout;
ConfigStringChoice* m_combobox_language;

Expand All @@ -42,6 +49,7 @@ class InterfacePane final : public QWidget
ConfigBool* m_checkbox_focused_hotkeys;
ConfigBool* m_checkbox_use_covers;
ConfigBool* m_checkbox_disable_screensaver;
ConfigBool* m_checkbox_time_tracking;

ConfigBool* m_checkbox_confirm_on_stop;
ConfigBool* m_checkbox_use_panic_handlers;
Expand Down

0 comments on commit fa549c5

Please sign in to comment.