]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
move sync interval to node page; add more config keys
authorgg <chown_tee@proton.me>
Thu, 15 Jan 2026 04:09:25 +0000 (23:09 -0500)
committergg <chown_tee@proton.me>
Thu, 15 Jan 2026 04:09:25 +0000 (23:09 -0500)
src/SettingsDialog.cpp
src/utils/config.cpp
src/utils/config.h
src/utils/prices.cpp

index 8550555769476dccc0606e8a15c6d56e35fe3472..e47963b8ece9278e0082e1ff374ef27875d44a9b 100644 (file)
@@ -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<int>::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<IntervalPreset> 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<QVBoxLayout*>(ui->checkBox_offlineMode->parentWidget()->layout())) {
+    // Add to Node tab
+    if (auto *layout = qobject_cast<QVBoxLayout*>(ui->Node->layout())) {
         layout->addLayout(hLayoutSync);
     }
 }
index e4657e5e0e561b550bb46376b460366335c45597..c7b93b9466bf254d5d1050b4845b699e5dfa6c04 100644 (file)
@@ -84,6 +84,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> 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}},
index e2c9212a0fbbed262085cda0dd1c8eda75fcd233..a6040af8ec0971aaf61889addd049a96754518be 100644 (file)
@@ -149,6 +149,7 @@ public:
         syncInterval,
         lastKnownNetworkHeight,
         lastSyncTimestamp,
+        lastPriceUpdateTimestamp,
     };
 
     enum PrivacyLevel {
index d8ebf29f02f4694098e03bd0b9a3bd5ac0758a54..635ed3af4b5c1ce5000f39647a78ad479c2bed95 100644 (file)
 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();
 }