]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
tooltip simplifications/methods
authorgg <chown_tee@proton.me>
Thu, 15 Jan 2026 03:16:18 +0000 (22:16 -0500)
committergg <chown_tee@proton.me>
Thu, 15 Jan 2026 03:16:18 +0000 (22:16 -0500)
src/MainWindow.cpp
src/MainWindow.h
src/SettingsDialog.cpp
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h
src/utils/config.cpp
src/utils/config.h

index 15ac104d9d032fef8fef336efd822786e9f9f4b8..a1820b367f9f47977d2ef172955e601c1690af92 100644 (file)
@@ -129,6 +129,12 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa
 
     conf()->set(Config::firstRun, false);
 
+    connect(conf(), &Config::changed, this, [this](Config::ConfigKey key){
+        if (key == Config::syncInterval && m_wallet) {
+            m_wallet->setRefreshInterval(conf()->get(Config::syncInterval).toInt());
+        }
+    });
+
     this->onWalletOpened();
 
     connect(&appData()->prices, &Prices::fiatPricesUpdated, this, &MainWindow::updateBalance);
@@ -724,6 +730,14 @@ void MainWindow::onWalletOpened() {
 
     m_wallet->setRingDatabase(Utils::ringDatabasePath());
 
+    // Load persisted sync state
+    qint64 lastSync = conf()->get(Config::lastSyncTimestamp).toLongLong();
+    if (lastSync > 0) {
+        m_lastSyncStatusUpdate = QDateTime::fromSecsSinceEpoch(lastSync);
+    }
+
+    m_wallet->setRefreshInterval(conf()->get(Config::syncInterval).toInt());
+
     m_wallet->updateBalance();
     if (m_wallet->isHwBacked()) {
         m_statusBtnHwDevice->show();
@@ -839,13 +853,71 @@ void MainWindow::updateStatusToolTip() {
         toolTip += QString("\nWallet synced: %1").arg(Utils::timeAgo(m_wallet->lastSyncTime()));
     }
     m_statusLabelBalance->setToolTip(toolTip);
+
+    this->updateSyncStatusToolTip();
+}
+
+void MainWindow::updateSyncStatusToolTip() {
+    if (!m_wallet) return;
+
+    quint64 walletHeight = m_wallet->blockChainHeight();
+    quint64 targetHeight = m_wallet->daemonBlockChainTargetHeight();
+
+    // Fall back to persisted network height if current is 0
+    if (targetHeight == 0) {
+        targetHeight = conf()->get(Config::lastKnownNetworkHeight).toULongLong();
+    }
+
+    // Determine blocks behind
+    quint64 blocksBehindActual = Utils::blocksBehind(walletHeight, targetHeight);
+    quint64 blocksBehindEstimated = 0;
+
+    // Use lastSyncTime, then m_lastSyncStatusUpdate, then persisted timestamp
+    QDateTime lastSync = m_wallet->lastSyncTime().isValid()
+        ? m_wallet->lastSyncTime()
+        : m_lastSyncStatusUpdate;
+
+    if (!lastSync.isValid()) {
+        qint64 persistedTimestamp = conf()->get(Config::lastSyncTimestamp).toLongLong();
+        if (persistedTimestamp > 0) {
+            lastSync = QDateTime::fromSecsSinceEpoch(persistedTimestamp);
+        }
+    }
+
+    if (lastSync.isValid()) {
+        qint64 secsSinceSync = lastSync.secsTo(QDateTime::currentDateTime());
+        blocksBehindEstimated = secsSinceSync / 120; // ~2 min per block
+    }
+
+    quint64 blocksBehind = std::max(blocksBehindActual, blocksBehindEstimated);
+
+    // Build Tooltip
+    QString tooltip;
+    if (targetHeight > 0) {
+        tooltip = tr("Wallet Height: %1 | Network Tip: %2")
+            .arg(QLocale().toString(walletHeight))
+            .arg(QLocale().toString(targetHeight));
+    } else {
+        tooltip = tr("Wallet Height: %1").arg(QLocale().toString(walletHeight));
+    }
+
+    if (lastSync.isValid()) {
+        tooltip += tr("\nLast synchronized: %1").arg(Utils::timeAgo(lastSync));
+    }
+
+    if (blocksBehind > 0) {
+        tooltip += tr("\n~%1 blocks behind").arg(QLocale().toString(blocksBehind));
+    }
+
+    // qDebug() << "Setting Status Tooltip:" << tooltip;
+    m_statusLabelStatus->setToolTip(tooltip);
 }
 
 void MainWindow::setStatusText(const QString &text, bool override, int timeout) {
 
     if (override) {
         m_statusOverrideActive = true;
-        qDebug() << "STATUS (override):" << text;
+        // qDebug() << "STATUS (override):" << text;
         m_statusLabelStatus->setText(text);
         QTimer::singleShot(timeout, [this]{
             m_statusOverrideActive = false;
@@ -857,7 +929,7 @@ void MainWindow::setStatusText(const QString &text, bool override, int timeout)
     m_statusText = text;
 
     if (!m_statusOverrideActive && !m_constructingTransaction) {
-        qDebug() << "STATUS:" << text; // adding this since the label has complex handlers now
+        // qDebug() << "STATUS:" << text;
         m_statusLabelStatus->setText(text);
     }
 }
@@ -957,12 +1029,13 @@ void MainWindow::onMultiBroadcast(const QMap<QString, QString> &txHexMap) {
 }
 
 void MainWindow::onSyncStatus(quint64 height, quint64 target, bool daemonSync) {
-    qDebug() << "onSyncStatus: Height" << height << "Target" << target << "DaemonSync" << daemonSync;
+    // qDebug() << "onSyncStatus: Height" << height << "Target" << target << "DaemonSync" << daemonSync;
 
     quint64 blocksBehind = Utils::blocksBehind(height, target);
-    m_lastSyncStatusUpdate = QDateTime::currentDateTime();
 
     if (height >= (target - 1) && target > 0) {
+        m_lastSyncStatusUpdate = QDateTime::currentDateTime();
+
         this->updateNetStats();
         this->setStatusText(QString("Synchronized (%1)").arg(QLocale().toString(height)));
 
@@ -975,19 +1048,7 @@ void MainWindow::onSyncStatus(quint64 height, quint64 target, bool daemonSync) {
         this->setStatusText(tr("%1 sync: %2 blocks behind").arg(type, blocksStr));
     }
 
-    // Update tooltip with consistent format
-    QString tooltip = tr("Wallet Height: %1 | Network Tip: %2")
-        .arg(QLocale().toString(height))
-        .arg(QLocale().toString(target));
-
-    tooltip += tr("\nLast updated: %1").arg(Utils::timeAgo(m_lastSyncStatusUpdate));
-
-    if (blocksBehind > 0) {
-        tooltip += tr("\n~%1 blocks behind").arg(QLocale().toString(blocksBehind));
-    }
-
-    qDebug() << "Setting Status Tooltip:" << tooltip;
-    m_statusLabelStatus->setToolTip(tooltip);
+    this->updateSyncStatusToolTip();
 }
 
 void MainWindow::onConnectionStatusChanged(int status)
@@ -1050,48 +1111,7 @@ void MainWindow::onConnectionStatusChanged(int status)
 
     this->setStatusText(statusStr);
 
-    // Update tooltip with wallet/network heights and time since last sync
-    if (m_wallet) {
-        quint64 walletHeight = m_wallet->blockChainHeight();
-        quint64 targetHeight = m_wallet->daemonBlockChainTargetHeight();
-
-        // Fall back to persisted network height if current is 0
-        if (targetHeight == 0) {
-            targetHeight = conf()->get(Config::lastKnownNetworkHeight).toULongLong();
-        }
-
-        QString tooltip;
-        if (targetHeight > 0) {
-            tooltip = tr("Wallet Height: %1 | Network Tip: %2")
-                .arg(QLocale().toString(walletHeight))
-                .arg(QLocale().toString(targetHeight));
-        } else {
-            tooltip = tr("Wallet Height: %1").arg(QLocale().toString(walletHeight));
-        }
-
-        // Use lastSyncTime, then m_lastSyncStatusUpdate, then persisted timestamp
-        QDateTime lastSync = m_wallet->lastSyncTime().isValid()
-            ? m_wallet->lastSyncTime()
-            : m_lastSyncStatusUpdate;
-
-        // Fall back to persisted timestamp if still invalid
-        if (!lastSync.isValid()) {
-            qint64 persistedTimestamp = conf()->get(Config::lastSyncTimestamp).toLongLong();
-            if (persistedTimestamp > 0) {
-                lastSync = QDateTime::fromSecsSinceEpoch(persistedTimestamp);
-            }
-        }
-
-        if (lastSync.isValid()) {
-            qint64 secsSinceSync = lastSync.secsTo(QDateTime::currentDateTime());
-            quint64 blocksBehind = secsSinceSync / 120; // ~2 min per block
-            tooltip += tr("\nLast updated: %1").arg(Utils::timeAgo(lastSync));
-            if (blocksBehind > 0) {
-                tooltip += tr("\n~%1 blocks behind").arg(QLocale().toString(blocksBehind));
-            }
-        }
-        m_statusLabelStatus->setToolTip(tooltip);
-    }
+    this->updateSyncStatusToolTip();
 
     if (m_wallet) {
         quint64 walletHeight = m_wallet->blockChainHeight();
@@ -1105,9 +1125,7 @@ void MainWindow::onConnectionStatusChanged(int status)
                     .arg(QLocale::system().toString(targetHeight));
         }
     }
-
     m_statusBtnConnectionStatusIndicator->setToolTip(statusStr);
-
     m_statusBtnConnectionStatusIndicator->setIcon(icon);
 }
 
index 37c86090fb27c8e3d323e211a20f1ca57d2992a8..f161ff058418d69b6c1ded312b9a1760806cd667 100644 (file)
@@ -208,6 +208,7 @@ private:
     void userActivity();
     void checkUserActivity();
     void updateStatusToolTip();
+    void updateSyncStatusToolTip();
     void lockWallet();
     void unlockWallet(const QString &password);
     void closeQDialogChildren(QObject *object);
index 81e85fae679409ce392df8f070a19f43c716ac61..8550555769476dccc0606e8a15c6d56e35fe3472 100644 (file)
@@ -186,13 +186,24 @@ void Settings::setupNetworkTab() {
         this->enableWebsocket(checked);
     });
 
-    // Overview
-    ui->checkBox_offlineMode->setChecked(conf()->get(Config::offlineMode).toBool());
-    connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){
-        conf()->set(Config::offlineMode, checked);
-        emit offlineMode(checked);
-        this->enableWebsocket(!checked);
-    });
+    // 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);
+    });
+
+    QHBoxLayout *hLayoutSync = new QHBoxLayout();
+    hLayoutSync->addWidget(new QLabel("Time between syncs:", this));
+    hLayoutSync->addWidget(sbSyncInterval);
+    hLayoutSync->addStretch();
+
+    // Add to the same layout as offlineMode
+    if (auto *layout = qobject_cast<QVBoxLayout*>(ui->checkBox_offlineMode->parentWidget()->layout())) {
+        layout->addLayout(hLayoutSync);
+    }
 }
 
 void Settings::setupStorageTab() {
index f28424ac657b391ab62e23c1dd4133ce82a45429..9dc59e5a55afb1cd26c99367aa4341eafe5f5b6c 100644 (file)
@@ -494,7 +494,6 @@ void Wallet::startRefreshThread()
     const auto future = m_scheduler.run([this] {
         // Beware! This code does not run in the GUI thread.
 
-        constexpr const std::chrono::seconds refreshInterval{10};
         constexpr const std::chrono::milliseconds intervalResolution{100};
 
         auto last = std::chrono::steady_clock::now();
@@ -504,7 +503,7 @@ void Wallet::startRefreshThread()
             {
                 const auto now = std::chrono::steady_clock::now();
                 const auto elapsed = now - last;
-                if (elapsed >= refreshInterval || m_refreshNow)
+                if (elapsed >= std::chrono::seconds(m_refreshInterval) || m_refreshNow)
                 {
                     m_refreshNow = false;
 
@@ -608,6 +607,11 @@ QDateTime Wallet::lastSyncTime() const {
     return m_lastSyncTime;
 }
 
+void Wallet::setRefreshInterval(int seconds) {
+    if (seconds < 1) seconds = 1;
+    m_refreshInterval = seconds;
+}
+
 void Wallet::skipToTip() {
     if (!m_wallet2)
         return;
index 099ded2bca8b6cbc98047606842235cec672bfb4..c37cc5d7d37db949f48a08c17136f8350b5f5485 100644 (file)
@@ -139,6 +139,7 @@ public:
     bool viewOnly() const;
 
     QDateTime lastSyncTime() const;
+    void setRefreshInterval(int seconds);
 
     //! return true if deterministic keys
     bool isDeterministic() const;
@@ -519,6 +520,8 @@ private:
     Coins *m_coins;
     CoinsModel *m_coinsModel;
 
+    int m_refreshInterval = 10;
+
     QMutex m_asyncMutex;
     QString m_daemonUsername;
     QString m_daemonPassword;
index 1ddb02840575147849b1bdd017010a3f4d24dcf0..e4657e5e0e561b550bb46376b460366335c45597 100644 (file)
@@ -81,6 +81,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
         {Config::offlineMode, {QS("offlineMode"), false}},
         {Config::syncPaused, {QS("syncPaused"), false}},
         {Config::syncPausedAlsoDisconnectWebSocket, {QS("syncPausedAlsoDisconnectWebSocket"), false}},
+        {Config::syncInterval, {QS("syncInterval"), 10}},
         {Config::lastKnownNetworkHeight, {QS("lastKnownNetworkHeight"), 0}},
         {Config::lastSyncTimestamp, {QS("lastSyncTimestamp"), 0}},
 
index 05aa2038c99edcbe41bbd11cdf50baa8ec12e45a..e2c9212a0fbbed262085cda0dd1c8eda75fcd233 100644 (file)
@@ -146,6 +146,7 @@ public:
         // Sync & data saver
         syncPaused,
         syncPausedAlsoDisconnectWebSocket,
+        syncInterval,
         lastKnownNetworkHeight,
         lastSyncTimestamp,
     };