From: gg Date: Thu, 15 Jan 2026 03:16:18 +0000 (-0500) Subject: tooltip simplifications/methods X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=577e41621e504fea0c14c5a4b116e7bad64583e1;p=gamesguru%2Ffeather.git tooltip simplifications/methods --- diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 15ac104d..a1820b36 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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 &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); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 37c86090..f161ff05 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -208,6 +208,7 @@ private: void userActivity(); void checkUserActivity(); void updateStatusToolTip(); + void updateSyncStatusToolTip(); void lockWallet(); void unlockWallet(const QString &password); void closeQDialogChildren(QObject *object); diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 81e85fae..85505557 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -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::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(ui->checkBox_offlineMode->parentWidget()->layout())) { + layout->addLayout(hLayoutSync); + } } void Settings::setupStorageTab() { diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index f28424ac..9dc59e5a 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -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; diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 099ded2b..c37cc5d7 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -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; diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 1ddb0284..e4657e5e 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -81,6 +81,7 @@ static const QHash 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}}, diff --git a/src/utils/config.h b/src/utils/config.h index 05aa2038..e2c9212a 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -146,6 +146,7 @@ public: // Sync & data saver syncPaused, syncPausedAlsoDisconnectWebSocket, + syncInterval, lastKnownNetworkHeight, lastSyncTimestamp, };