-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottombar.cpp
124 lines (87 loc) · 3.54 KB
/
bottombar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "bottombar.h"
#include "ui_bottombar.h"
#include "consoledialog.h"
#include "blockchain.h"
#include "debug_log.h"
#include "commontip.h"
#include "rpcthread.h"
#include "commondialog.h"
#include <QPainter>
#include <QTimer>
#include <QMovie>
#include <QMouseEvent>
BottomBar::BottomBar(QWidget *parent) :
QWidget(parent),
ui(new Ui::BottomBar)
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
ui->setupUi(this);
ui->networkLabel->setPixmap(QPixmap(":/pic/cplpic/network.png"));
ui->syncLabel->setStyleSheet("color:rgb(112,104,103)");
ui->nodeNumLabel->setStyleSheet("color:rgb(112,104,103)");
connect(Blockchain::getInstance(), SIGNAL(jsonDataUpdated(QString)),this, SLOT(jsonDataUpdated(QString)));
jsonDataUpdated("id_info");
setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Background, QColor(229,229,227));
setPalette(palette);
timer = new QTimer(this);
timer->start(5000);
connect(timer,SIGNAL(timeout()),this,SLOT(updateNumOfConnections()));
updateNumOfConnections();
connectionTip = new CommonTip;
DLOG_QT_WALLET_FUNCTION_END;
}
BottomBar::~BottomBar()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
delete ui;
DLOG_QT_WALLET_FUNCTION_END;
}
void BottomBar::updateNumOfConnections()
{
// DLOG_QT_WALLET_FUNCTION_BEGIN;
QString result = Blockchain::getInstance()->jsonDataValue("id_info");
if( result.isEmpty()) return;
int pos = result.indexOf("\"network_num_connections\"") + 26;
QString num = result.mid( pos, result.indexOf("," , pos) - pos);
ui->nodeNumLabel->setText(num + tr(" peers"));
// DLOG_QT_WALLET_FUNCTION_END;
}
void BottomBar::retranslator()
{
ui->retranslateUi(this);
}
void BottomBar::jsonDataUpdated(QString id)
{
if( id == "id_info")
{
Blockchain::getInstance()->parseBalance();
QString result = Blockchain::getInstance()->jsonDataValue( id);
if( result.isEmpty() ) return;
int pos = result.indexOf( "\"blockchain_head_block_age\":") + 28;
QString seconds = result.mid( pos, result.indexOf("\"blockchain_head_block_timestamp\":") - pos - 1);
int pos2 = result.indexOf( "\"blockchain_head_block_num\":") + 28;
QString num = result.mid( pos2, result.indexOf("\"blockchain_head_block_age\":") - pos2 - 1);
if( seconds.toInt() < 0) seconds = "0";
// int numToSync = seconds.toInt()/ 10;
ui->syncLabel->setText( tr("Local block height: ") + num );
Blockchain::getInstance()->currentBlockHeight = num.toInt();
int pos3 = result.indexOf( "\"wallet_scan_progress\":") + 23;
QString scanProgress = result.mid( pos3, result.indexOf(",\"wallet_block_production_enabled\":") - pos3);
scanProgress.remove('\"');
double scanPercent = scanProgress.toDouble();
if( Blockchain::getInstance()->needToScan && scanPercent > 0.99999)
{
Blockchain::getInstance()->postRPC( toJsonFormat( "id_scan", "scan", QStringList() << "0"));
Blockchain::getInstance()->needToScan = false;
}
return;
}
}
void BottomBar::refresh()
{
Blockchain::getInstance()->postRPC( toJsonFormat( "id_info", "info", QStringList() << ""));
Blockchain::getInstance()->postRPC( toJsonFormat( "id_blockchain_list_assets", "blockchain_list_assets", QStringList() << ""));
// Fry::getInstance()->postRPC( toJsonFormat( "id_balance", "balance", QStringList() << ""));
}