diff options
author | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2023-10-29 13:50:55 +0000 |
---|---|---|
committer | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2024-01-24 04:26:55 +0000 |
commit | e4915fb7d2077584a11a15141bc81d28ed2b0125 (patch) | |
tree | 1783055dc2e98eaf9099e8e7b194b55f8f607747 /src/yuzu/configuration | |
parent | a560b9f5a26bdc49814930a0bec91d0ad6545942 (diff) |
Rework time service to fix time passing offline.
Diffstat (limited to 'src/yuzu/configuration')
-rw-r--r-- | src/yuzu/configuration/configure_ringcon.cpp | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 57 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_system.h | 6 | ||||
-rw-r--r-- | src/yuzu/configuration/shared_translation.cpp | 4 |
4 files changed, 63 insertions, 6 deletions
diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp index 3a7f6101d..9fd094ab6 100644 --- a/src/yuzu/configuration/configure_ringcon.cpp +++ b/src/yuzu/configuration/configure_ringcon.cpp @@ -494,4 +494,4 @@ QString ConfigureRingController::AnalogToText(const Common::ParamPackage& param, } return QObject::tr("[unknown]"); -}
\ No newline at end of file +} diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index b0b84f967..e193b5f95 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -12,9 +12,10 @@ #include <QGraphicsItem> #include <QLineEdit> #include <QMessageBox> +#include <QSpinBox> + #include "common/settings.h" #include "core/core.h" -#include "core/hle/service/time/time_manager.h" #include "ui_configure_system.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_system.h" @@ -49,6 +50,11 @@ ConfigureSystem::ConfigureSystem(Core::System& system_, : Tab(group_, parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_} { ui->setupUi(this); + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + const auto current_time_s = + std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); + previous_time = current_time_s + Settings::values.custom_rtc_offset.GetValue(); + Setup(builder); const auto locale_check = [this]() { @@ -64,13 +70,28 @@ ConfigureSystem::ConfigureSystem(Core::System& system_, } }; + const auto update_date_offset = [this]() { + if (!checkbox_rtc->isChecked()) { + return; + } + auto offset = date_rtc_offset->value(); + offset += date_rtc->dateTime().toSecsSinceEpoch() - previous_time; + previous_time = date_rtc->dateTime().toSecsSinceEpoch(); + date_rtc_offset->setValue(offset); + }; + const auto update_rtc_date = [this]() { UpdateRtcTime(); }; + connect(combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check); connect(combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check); + connect(checkbox_rtc, qOverload<int>(&QCheckBox::stateChanged), this, update_rtc_date); + connect(date_rtc_offset, qOverload<int>(&QSpinBox::valueChanged), this, update_rtc_date); + connect(date_rtc, &QDateTimeEdit::dateTimeChanged, this, update_date_offset); ui->label_warn_invalid_locale->setVisible(false); locale_check(); SetConfiguration(); + UpdateRtcTime(); } ConfigureSystem::~ConfigureSystem() = default; @@ -120,14 +141,28 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { continue; } + // Keep track of the region_index (and language_index) combobox to validate the selected + // settings if (setting->Id() == Settings::values.region_index.Id()) { - // Keep track of the region_index (and language_index) combobox to validate the selected - // settings combo_region = widget->combobox; - } else if (setting->Id() == Settings::values.language_index.Id()) { + } + + if (setting->Id() == Settings::values.language_index.Id()) { combo_language = widget->combobox; } + if (setting->Id() == Settings::values.custom_rtc.Id()) { + checkbox_rtc = widget->checkbox; + } + + if (setting->Id() == Settings::values.custom_rtc.Id()) { + date_rtc = widget->date_time_edit; + } + + if (setting->Id() == Settings::values.custom_rtc_offset.Id()) { + date_rtc_offset = widget->spinbox; + } + switch (setting->GetCategory()) { case Settings::Category::Core: core_hold.emplace(setting->Id(), widget); @@ -147,6 +182,19 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { } } +void ConfigureSystem::UpdateRtcTime() { + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + previous_time = std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); + date_rtc_offset->setEnabled(checkbox_rtc->isChecked()); + + if (checkbox_rtc->isChecked()) { + previous_time += date_rtc_offset->value(); + } + + const auto date = QDateTime::fromSecsSinceEpoch(previous_time); + date_rtc->setDateTime(date); +} + void ConfigureSystem::SetConfiguration() {} void ConfigureSystem::ApplyConfiguration() { @@ -154,4 +202,5 @@ void ConfigureSystem::ApplyConfiguration() { for (const auto& func : apply_funcs) { func(powered_on); } + UpdateRtcTime(); } diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index eab99a48a..4334211f9 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -43,6 +43,8 @@ private: void Setup(const ConfigurationShared::Builder& builder); + void UpdateRtcTime(); + std::vector<std::function<void(bool)>> apply_funcs{}; std::unique_ptr<Ui::ConfigureSystem> ui; @@ -52,4 +54,8 @@ private: QComboBox* combo_region; QComboBox* combo_language; + QCheckBox* checkbox_rtc; + QDateTimeEdit* date_rtc; + QSpinBox* date_rtc_offset; + u64 previous_time; }; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 922eb1b1a..ed9c7d859 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -143,8 +143,10 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) { INSERT(Settings, rng_seed, tr("RNG Seed"), QStringLiteral()); INSERT(Settings, rng_seed_enabled, QStringLiteral(), QStringLiteral()); INSERT(Settings, device_name, tr("Device Name"), QStringLiteral()); - INSERT(Settings, custom_rtc, tr("Custom RTC"), QStringLiteral()); + INSERT(Settings, custom_rtc, tr("Custom RTC Date:"), QStringLiteral()); INSERT(Settings, custom_rtc_enabled, QStringLiteral(), QStringLiteral()); + INSERT(Settings, custom_rtc_offset, QStringLiteral(" "), + QStringLiteral("The number of seconds from the current unix time")); INSERT(Settings, language_index, tr("Language:"), tr("Note: this can be overridden when region setting is auto-select")); INSERT(Settings, region_index, tr("Region:"), QStringLiteral()); |