Skip to content

Commit 24f72e9

Browse files
committed
Merge #8371: [Qt] Add out-of-sync modal info layer
08827df [Qt] modalinfolayer: removed unused comments, renamed signal, code style overhaul (Jonas Schnelli) d8b062e [Qt] only update "amount of blocks left" when the header chain is in-sync (Jonas Schnelli) e3245b4 [Qt] add out-of-sync modal info layer (Jonas Schnelli) e47052f [Qt] ClientModel add method to get the height of the header chain (Jonas Schnelli) a001f18 [Qt] Always pass the numBlocksChanged signal for headers tip changed (Jonas Schnelli) bd44a04 [Qt] make Out-Of-Sync warning icon clickable (Jonas Schnelli) 0904c3c [Refactor] refactor function that forms human readable text out of a timeoffset (Jonas Schnelli)
2 parents d2e4655 + 08827df commit 24f72e9

17 files changed

+708
-29
lines changed

src/Makefile.qt.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ QT_FORMS_UI = \
9696
qt/forms/editaddressdialog.ui \
9797
qt/forms/helpmessagedialog.ui \
9898
qt/forms/intro.ui \
99+
qt/forms/modaloverlay.ui \
99100
qt/forms/openuridialog.ui \
100101
qt/forms/optionsdialog.ui \
101102
qt/forms/overviewpage.ui \
@@ -125,6 +126,7 @@ QT_MOC_CPP = \
125126
qt/moc_intro.cpp \
126127
qt/moc_macdockiconhandler.cpp \
127128
qt/moc_macnotificationhandler.cpp \
129+
qt/moc_modaloverlay.cpp \
128130
qt/moc_notificator.cpp \
129131
qt/moc_openuridialog.cpp \
130132
qt/moc_optionsdialog.cpp \
@@ -192,6 +194,7 @@ BITCOIN_QT_H = \
192194
qt/intro.h \
193195
qt/macdockiconhandler.h \
194196
qt/macnotificationhandler.h \
197+
qt/modaloverlay.h \
195198
qt/networkstyle.h \
196199
qt/notificator.h \
197200
qt/openuridialog.h \
@@ -292,6 +295,7 @@ BITCOIN_QT_CPP = \
292295
qt/csvmodelwriter.cpp \
293296
qt/guiutil.cpp \
294297
qt/intro.cpp \
298+
qt/modaloverlay.cpp \
295299
qt/networkstyle.cpp \
296300
qt/notificator.cpp \
297301
qt/optionsdialog.cpp \

src/qt/bitcoingui.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clientmodel.h"
1313
#include "guiconstants.h"
1414
#include "guiutil.h"
15+
#include "modaloverlay.h"
1516
#include "networkstyle.h"
1617
#include "notificator.h"
1718
#include "openuridialog.h"
@@ -115,6 +116,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
115116
notificator(0),
116117
rpcConsole(0),
117118
helpMessageDialog(0),
119+
modalOverlay(0),
118120
prevBlocks(0),
119121
spinnerFrame(0),
120122
platformStyle(_platformStyle)
@@ -239,6 +241,12 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *
239241

240242
// Subscribe to notifications from core
241243
subscribeToCoreSignals();
244+
245+
modalOverlay = new ModalOverlay(this->centralWidget());
246+
#ifdef ENABLE_WALLET
247+
if(enableWallet)
248+
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
249+
#endif
242250
}
243251

244252
BitcoinGUI::~BitcoinGUI()
@@ -489,6 +497,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
489497
// initialize the disable state of the tray icon with the current value in the model.
490498
setTrayIconVisible(optionsModel->getHideTrayIcon());
491499
}
500+
501+
modalOverlay->setKnownBestHeight(clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(clientModel->getHeaderTipTime()));
492502
} else {
493503
// Disable possibility to show main window via action
494504
toggleHideAction->setEnabled(false);
@@ -703,7 +713,17 @@ void BitcoinGUI::setNumConnections(int count)
703713

704714
void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
705715
{
706-
if(!clientModel)
716+
if (modalOverlay)
717+
{
718+
if (header) {
719+
/* use clientmodels getHeaderTipHeight and getHeaderTipTime because the NotifyHeaderTip signal does not fire when updating the best header */
720+
modalOverlay->setKnownBestHeight(clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(clientModel->getHeaderTipTime()));
721+
}
722+
else {
723+
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
724+
}
725+
}
726+
if (!clientModel)
707727
return;
708728

709729
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbelled text)
@@ -752,38 +772,18 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
752772

753773
#ifdef ENABLE_WALLET
754774
if(walletFrame)
775+
{
755776
walletFrame->showOutOfSyncWarning(false);
777+
modalOverlay->showHide(true, true);
778+
}
756779
#endif // ENABLE_WALLET
757780

758781
progressBarLabel->setVisible(false);
759782
progressBar->setVisible(false);
760783
}
761784
else
762785
{
763-
// Represent time from last generated block in human readable text
764-
QString timeBehindText;
765-
const int HOUR_IN_SECONDS = 60*60;
766-
const int DAY_IN_SECONDS = 24*60*60;
767-
const int WEEK_IN_SECONDS = 7*24*60*60;
768-
const int YEAR_IN_SECONDS = 31556952; // Average length of year in Gregorian calendar
769-
if(secs < 2*DAY_IN_SECONDS)
770-
{
771-
timeBehindText = tr("%n hour(s)","",secs/HOUR_IN_SECONDS);
772-
}
773-
else if(secs < 2*WEEK_IN_SECONDS)
774-
{
775-
timeBehindText = tr("%n day(s)","",secs/DAY_IN_SECONDS);
776-
}
777-
else if(secs < YEAR_IN_SECONDS)
778-
{
779-
timeBehindText = tr("%n week(s)","",secs/WEEK_IN_SECONDS);
780-
}
781-
else
782-
{
783-
qint64 years = secs / YEAR_IN_SECONDS;
784-
qint64 remainder = secs % YEAR_IN_SECONDS;
785-
timeBehindText = tr("%1 and %2").arg(tr("%n year(s)", "", years)).arg(tr("%n week(s)","", remainder/WEEK_IN_SECONDS));
786-
}
786+
QString timeBehindText = GUIUtil::formateNiceTimeOffset(secs);
787787

788788
progressBarLabel->setVisible(true);
789789
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
@@ -803,7 +803,10 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
803803

804804
#ifdef ENABLE_WALLET
805805
if(walletFrame)
806+
{
806807
walletFrame->showOutOfSyncWarning(true);
808+
modalOverlay->showHide();
809+
}
807810
#endif // ENABLE_WALLET
808811

809812
tooltip += QString("<br>");
@@ -1099,6 +1102,12 @@ void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
10991102
}
11001103
}
11011104

1105+
void BitcoinGUI::showModalOverlay()
1106+
{
1107+
if (modalOverlay)
1108+
modalOverlay->showHide(false, true);
1109+
}
1110+
11021111
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
11031112
{
11041113
bool modal = (style & CClientUIInterface::MODAL);

src/qt/bitcoingui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UnitDisplayStatusBarControl;
2929
class WalletFrame;
3030
class WalletModel;
3131
class HelpMessageDialog;
32+
class ModalOverlay;
3233

3334
class CWallet;
3435

@@ -118,6 +119,7 @@ class BitcoinGUI : public QMainWindow
118119
Notificator *notificator;
119120
RPCConsole *rpcConsole;
120121
HelpMessageDialog *helpMessageDialog;
122+
ModalOverlay *modalOverlay;
121123

122124
/** Keep track of previous number of blocks, to detect progress */
123125
int prevBlocks;
@@ -229,6 +231,8 @@ private Q_SLOTS:
229231

230232
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
231233
void setTrayIconVisible(bool);
234+
235+
void showModalOverlay();
232236
};
233237

234238
class UnitDisplayStatusBarControl : public QLabel

src/qt/clientmodel.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ int ClientModel::getNumBlocks() const
7070
return chainActive.Height();
7171
}
7272

73+
int ClientModel::getHeaderTipHeight() const
74+
{
75+
LOCK(cs_main);
76+
if (!pindexBestHeader)
77+
return 0;
78+
return pindexBestHeader->nHeight;
79+
}
80+
81+
int64_t ClientModel::getHeaderTipTime() const
82+
{
83+
LOCK(cs_main);
84+
if (!pindexBestHeader)
85+
return 0;
86+
return pindexBestHeader->GetBlockTime();
87+
}
88+
7389
quint64 ClientModel::getTotalBytesRecv() const
7490
{
7591
if(!g_connman)
@@ -240,7 +256,7 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
240256
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
241257

242258
// if we are in-sync, update the UI regardless of last update time
243-
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
259+
if (fHeader || !initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
244260
//pass a async signal to the UI thread
245261
QMetaObject::invokeMethod(clientmodel, "numBlocksChanged", Qt::QueuedConnection,
246262
Q_ARG(int, pIndex->nHeight),

src/qt/clientmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class ClientModel : public QObject
5151
//! Return number of connections, default is in- and outbound (total)
5252
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
5353
int getNumBlocks() const;
54-
54+
int getHeaderTipHeight() const;
55+
int64_t getHeaderTipTime() const;
5556
//! Return number of transactions in the mempool
5657
long getMempoolSize() const;
5758
//! Return the dynamic memory usage of the mempool

0 commit comments

Comments
 (0)