From: gg Date: Thu, 15 Jan 2026 04:09:25 +0000 (-0500) Subject: move sync interval to node page; add more config keys X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=e93a5b89b69128407df6459d99c14315f7a7fb25;p=gamesguru%2Ffeather.git move sync interval to node page; add more config keys --- diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 85505557..e47963b8 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -187,21 +187,75 @@ void Settings::setupNetworkTab() { }); // Sync - QSpinBox *sbSyncInterval = new QSpinBox(this); - sbSyncInterval->setRange(1, 3600); - sbSyncInterval->setSuffix(" seconds"); - sbSyncInterval->setValue(conf()->get(Config::syncInterval).toInt()); - connect(sbSyncInterval, QOverload::of(&QSpinBox::valueChanged), [](int value){ - conf()->set(Config::syncInterval, value); - }); + QComboBox *comboSyncInterval = new QComboBox(this); + comboSyncInterval->setEditable(true); + + struct IntervalPreset { + QString label; + int seconds; + }; + + QList presets = { + {"30 seconds", 30}, + {"1 minute", 60}, + {"2 minutes", 120}, + {"5 minutes", 300}, + {"10 minutes", 600}, + {"15 minutes", 900}, + {"20 minutes", 1200}, + {"30 minutes", 1800}, + {"45 minutes", 2700}, + {"1 hour", 3600}, + {"1.5 hours", 5400}, + {"3 hours", 10800}, + {"5 hours", 18000}, + {"10 hours", 36000}, + {"1 day", 86400}, + {"1 week", 604800}, + {"1 month", 2592000} + }; + + for (const auto &preset : presets) { + comboSyncInterval->addItem(preset.label, preset.seconds); + } + + int currentInterval = conf()->get(Config::syncInterval).toInt(); + bool found = false; + for (int i = 0; i < comboSyncInterval->count(); ++i) { + if (comboSyncInterval->itemData(i).toInt() == currentInterval) { + comboSyncInterval->setCurrentIndex(i); + found = true; + break; + } + } + if (!found) { + comboSyncInterval->setCurrentText(QString("%1 seconds").arg(currentInterval)); + } + + auto updateConfig = [comboSyncInterval](const QString &text){ + int seconds = 0; + if (comboSyncInterval->currentIndex() != -1 && comboSyncInterval->currentText() == comboSyncInterval->itemText(comboSyncInterval->currentIndex())) { + seconds = comboSyncInterval->currentData().toInt(); + } else { + // Try to parse simple number as seconds + bool ok; + seconds = text.split(" ").first().toInt(&ok); + if (!ok) return; + } + if (seconds > 0) { + conf()->set(Config::syncInterval, seconds); + } + }; + + connect(comboSyncInterval, &QComboBox::currentTextChanged, updateConfig); QHBoxLayout *hLayoutSync = new QHBoxLayout(); hLayoutSync->addWidget(new QLabel("Time between syncs:", this)); - hLayoutSync->addWidget(sbSyncInterval); + hLayoutSync->addWidget(comboSyncInterval); hLayoutSync->addStretch(); - // Add to the same layout as offlineMode - if (auto *layout = qobject_cast(ui->checkBox_offlineMode->parentWidget()->layout())) { + // Add to Node tab + if (auto *layout = qobject_cast(ui->Node->layout())) { layout->addLayout(hLayoutSync); } } diff --git a/src/utils/config.cpp b/src/utils/config.cpp index e4657e5e..c7b93b94 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -84,6 +84,7 @@ static const QHash configStrings = { {Config::syncInterval, {QS("syncInterval"), 10}}, {Config::lastKnownNetworkHeight, {QS("lastKnownNetworkHeight"), 0}}, {Config::lastSyncTimestamp, {QS("lastSyncTimestamp"), 0}}, + {Config::lastPriceUpdateTimestamp, {QS("lastPriceUpdateTimestamp"), 0}}, // Transactions {Config::multiBroadcast, {QS("multiBroadcast"), true}}, diff --git a/src/utils/config.h b/src/utils/config.h index e2c9212a..a6040af8 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -149,6 +149,7 @@ public: syncInterval, lastKnownNetworkHeight, lastSyncTimestamp, + lastPriceUpdateTimestamp, }; enum PrivacyLevel { diff --git a/src/utils/prices.cpp b/src/utils/prices.cpp index d8ebf29f..635ed3af 100644 --- a/src/utils/prices.cpp +++ b/src/utils/prices.cpp @@ -12,6 +12,10 @@ Prices::Prices(QObject *parent) : QObject(parent) { + qint64 lastUpdate = conf()->get(Config::lastPriceUpdateTimestamp).toLongLong(); + if (lastUpdate > 0) { + this->lastUpdateTime = QDateTime::fromSecsSinceEpoch(lastUpdate); + } } void Prices::cryptoPricesReceived(const QJsonArray &data) { @@ -32,6 +36,7 @@ void Prices::cryptoPricesReceived(const QJsonArray &data) { } this->lastUpdateTime = QDateTime::currentDateTime(); + conf()->set(Config::lastPriceUpdateTimestamp, this->lastUpdateTime.toSecsSinceEpoch()); emit cryptoPricesUpdated(); }