Skip to content

Commit 2b61d22

Browse files
committed
qml: Put BlockClock into an Error state if init fails
Co-authored-by: thebagmaster <thebagmaster>
1 parent 67150ef commit 2b61d22

File tree

8 files changed

+55
-8
lines changed

8 files changed

+55
-8
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ QML_RES_ICONS = \
327327
qml/res/icons/caret-right.png \
328328
qml/res/icons/check.png \
329329
qml/res/icons/cross.png \
330+
qml/res/icons/error.png \
330331
qml/res/icons/export.png \
331332
qml/res/icons/gear.png \
332333
qml/res/icons/info.png \

src/qml/bitcoin_qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<file alias="caret-right">res/icons/caret-right.png</file>
7575
<file alias="check">res/icons/check.png</file>
7676
<file alias="cross">res/icons/cross.png</file>
77+
<file alias="error">res/icons/error.png</file>
7778
<file alias="export">res/icons/export.png</file>
7879
<file alias="gear">res/icons/gear.png</file>
7980
<file alias="info">res/icons/info.png</file>

src/qml/components/BlockClock.qml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Item {
3030
property var syncState: formatRemainingSyncTime(nodeModel.remainingSyncTime)
3131
property string syncTime: syncState.text
3232
property bool estimating: syncState.estimating
33+
property bool faulted: nodeModel.faulted
3334

3435
activeFocusOnTab: true
3536

@@ -47,7 +48,7 @@ Item {
4748
penWidth: dial.width / 50
4849
timeRatioList: chainModel.timeRatioList
4950
verificationProgress: nodeModel.verificationProgress
50-
paused: root.paused
51+
paused: root.paused || root.faulted
5152
connected: root.connected
5253
synced: nodeModel.verificationProgress > 0.999
5354
backgroundColor: Theme.color.neutral2
@@ -140,7 +141,7 @@ Item {
140141
maxNumOutboundPeers: nodeModel.maxNumOutboundPeers
141142
indicatorDimensions: dial.width * (3/200)
142143
indicatorSpacing: dial.width / 40
143-
paused: root.paused
144+
paused: root.paused || root.faulted
144145
}
145146

146147
NetworkIndicator {
@@ -152,10 +153,13 @@ Item {
152153

153154
MouseArea {
154155
anchors.fill: dial
155-
cursorShape: Qt.PointingHandCursor
156+
cursorShape: root.faulted ? Qt.ArrowCursor : Qt.PointingHandCursor
157+
enabled: !root.faulted
156158
onClicked: {
157-
root.paused = !root.paused
158-
nodeModel.pause = root.paused
159+
if (!root.faulted) {
160+
root.paused = !root.paused
161+
nodeModel.pause = root.paused
162+
}
159163
}
160164
FocusBorder {
161165
visible: root.activeFocus
@@ -171,6 +175,7 @@ Item {
171175
subText: root.syncTime
172176
}
173177
},
178+
174179
State {
175180
name: "BLOCKCLOCK"; when: synced && !paused && connected
176181
PropertyChanges {
@@ -182,7 +187,7 @@ Item {
182187
},
183188

184189
State {
185-
name: "PAUSE"; when: paused
190+
name: "PAUSE"; when: paused && !faulted
186191
PropertyChanges {
187192
target: root
188193
header: "Paused"
@@ -200,6 +205,20 @@ Item {
200205
}
201206
},
202207

208+
State {
209+
name: "ERROR"; when: faulted
210+
PropertyChanges {
211+
target: root
212+
header: "Error"
213+
headerSize: dial.width * (3/25)
214+
}
215+
PropertyChanges {
216+
target: bitcoinIcon
217+
anchors.bottomMargin: dial.width / 40
218+
icon.source: "image://images/error"
219+
}
220+
},
221+
203222
State {
204223
name: "CONNECTING"; when: !paused && !connected
205224
PropertyChanges {
@@ -220,6 +239,7 @@ Item {
220239
}
221240
]
222241

242+
223243
function formatProgressPercentage(progress) {
224244
if (progress >= 1) {
225245
return Math.round(progress) + "%"

src/qml/imageprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize
8282
return QIcon(":/icons/cross").pixmap(requested_size);
8383
}
8484

85+
if (id == "error") {
86+
*size = requested_size;
87+
return QIcon(":/icons/error").pixmap(requested_size);
88+
}
89+
8590
if (id == "export") {
8691
*size = requested_size;
8792
return QIcon(":/icons/export").pixmap(requested_size);

src/qml/models/nodemodel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <QDateTime>
1616
#include <QMetaObject>
1717
#include <QTimerEvent>
18+
#include <QString>
1819

1920
NodeModel::NodeModel(interfaces::Node& node)
2021
: m_node{node}
@@ -93,6 +94,14 @@ void NodeModel::setPause(bool new_pause)
9394
}
9495
}
9596

97+
void NodeModel::setErrorState(bool faulted)
98+
{
99+
if (m_faulted != faulted) {
100+
m_faulted = faulted;
101+
Q_EMIT errorStateChanged(faulted);
102+
}
103+
}
104+
96105
void NodeModel::startNodeInitializionThread()
97106
{
98107
Q_EMIT requestedInitialize();
@@ -103,9 +112,11 @@ void NodeModel::requestShutdown()
103112
Q_EMIT requestedShutdown();
104113
}
105114

106-
void NodeModel::initializeResult([[maybe_unused]] bool success, interfaces::BlockAndHeaderTipInfo tip_info)
115+
void NodeModel::initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
107116
{
108-
// TODO: Handle the `success` parameter,
117+
if (!success) {
118+
setErrorState(true);
119+
}
109120
setBlockTipHeight(tip_info.block_height);
110121
setVerificationProgress(tip_info.verification_progress);
111122

src/qml/models/nodemodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class NodeModel : public QObject
3333
Q_PROPERTY(int remainingSyncTime READ remainingSyncTime NOTIFY remainingSyncTimeChanged)
3434
Q_PROPERTY(double verificationProgress READ verificationProgress NOTIFY verificationProgressChanged)
3535
Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged)
36+
Q_PROPERTY(bool faulted READ errorState WRITE setErrorState NOTIFY errorStateChanged)
3637

3738
public:
3839
explicit NodeModel(interfaces::Node& node);
@@ -49,6 +50,8 @@ class NodeModel : public QObject
4950
void setVerificationProgress(double new_progress);
5051
bool pause() const { return m_pause; }
5152
void setPause(bool new_pause);
53+
bool errorState() const { return m_faulted; }
54+
void setErrorState(bool new_error);
5255

5356
Q_INVOKABLE float getTotalBytesReceived() const { return (float)m_node.getTotalBytesRecv(); }
5457
Q_INVOKABLE float getTotalBytesSent() const { return (float)m_node.getTotalBytesSent(); }
@@ -70,6 +73,7 @@ public Q_SLOTS:
7073
void requestedShutdown();
7174
void verificationProgressChanged();
7275
void pauseChanged(bool new_pause);
76+
void errorStateChanged(bool new_error_state);
7377

7478
void setTimeRatioList(int new_time);
7579
void setTimeRatioListInitial();
@@ -85,6 +89,7 @@ public Q_SLOTS:
8589
int m_remaining_sync_time{0};
8690
double m_verification_progress{0.0};
8791
bool m_pause{false};
92+
bool m_faulted{false};
8893

8994
int m_shutdown_polling_timer_id{0};
9095

src/qml/res/icons/error.png

3.41 KB
Loading

src/qml/res/src/error.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)