|
| 1 | +#include "infowidget.h" |
| 2 | +#include "ui_infowidget.h" |
| 3 | +#include "clientmodel.h" |
| 4 | +#include "chainparams.h" |
| 5 | +#include <QPropertyAnimation> |
| 6 | +#include "overviewpage.h" |
| 7 | +#include <QMessageBox> |
| 8 | +#include <QDesktopServices> |
| 9 | +#include <QUrl> |
| 10 | +#include <QNetworkRequest> |
| 11 | +#include <QProcess> |
| 12 | +#include <QLatin1String> |
| 13 | +#include <QPixmapCache> |
| 14 | +#include "log/log.h" |
| 15 | +#include "qthyperlink.h" |
| 16 | +#include "walletmodel.h" |
| 17 | +#include <QNetworkAccessManager> |
| 18 | +#include <QNetworkRequest> |
| 19 | +#include <QNetworkReply> |
| 20 | +#include "json/cJSON.h" |
| 21 | +#include "intro.h" |
| 22 | +#include "updatedialog.h" |
| 23 | +QString version("V0.0.9"); |
| 24 | + |
| 25 | +bool isfullloaded =false; |
| 26 | +bool isfirstfullloaded = false; |
| 27 | +InfoWidget* InfoWidget::mm = NULL; |
| 28 | +InfoWidget::InfoWidget( QWidget *parent): |
| 29 | + QDialog(parent), |
| 30 | + m_walletModel(NULL), |
| 31 | + bestHeaderDate(QDateTime()), |
| 32 | + ui(new Ui::infowidget), |
| 33 | + m_userRequested(false) |
| 34 | +{ |
| 35 | + ui->setupUi(this); |
| 36 | + |
| 37 | + if(Intro::m_clienttype == "test") |
| 38 | + { |
| 39 | + ui->clickinfo->setText("<a href = http://exploertest.ipchainglobal.com/insight/feedback>http://exploertest.ipchainglobal.com/insight/feedback</a>"); |
| 40 | + ui->infolabel->setText("<a href = http://exploertest.ipchainglobal.com>http://exploertest.ipchainglobal.com </a>"); |
| 41 | + |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + ui->clickinfo->setText("<a href = http://exploer.ipchainglobal.com/insight/feedback>http://exploer.ipchainglobal.com/insight/feedback</a>"); |
| 46 | + ui->infolabel->setText("<a href = http://exploer.ipchainglobal.com >http://exploer.ipchainglobal.com </a>"); |
| 47 | + |
| 48 | + } |
| 49 | + connect(ui->clickinfo,SIGNAL(clicked(MyQTHyperLink*)),this,SLOT(openUrll())); |
| 50 | + QPalette pa; |
| 51 | + pa.setColor(QPalette::WindowText,Qt::red); |
| 52 | + ui->label_newversion->setPalette(pa); |
| 53 | + connect(ui->infolabel,SIGNAL(clicked(MyQTHyperLink*)),this,SLOT(openUrl1())); |
| 54 | + connect(ui->label_versionhtml,SIGNAL(clicked(MyQTHyperLink*)),this,SLOT(openUrlVersion())); |
| 55 | + connect(this,SIGNAL(updateclient(QString,QString,QString)),this,SLOT(updateclientSlot(QString,QString,QString)),Qt::QueuedConnection); |
| 56 | + m_versionhtml = getVersion(); |
| 57 | + QString strversionhtml = m_versionhtml; |
| 58 | + if(strversionhtml.isEmpty()){ |
| 59 | + ui->label_newversion->hide(); |
| 60 | + ui->label_versionhtml->hide(); |
| 61 | + } |
| 62 | + else{ |
| 63 | + QString html("<a href = "); |
| 64 | + html=html+strversionhtml+ ">" + strversionhtml + "</a>"; |
| 65 | + ui->label_versionhtml->setText(html); |
| 66 | + LOG_WRITE(LOG_INFO,"getVersion ",strversionhtml.toStdString().c_str()); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +InfoWidget::~InfoWidget() |
| 71 | +{ |
| 72 | + delete ui; |
| 73 | +} |
| 74 | + |
| 75 | +void InfoWidget::setClientModel(ClientModel *model) |
| 76 | +{ |
| 77 | + this->clientModel = model; |
| 78 | +} |
| 79 | + |
| 80 | +void InfoWidget::openUrll() |
| 81 | +{ |
| 82 | + |
| 83 | + if(Intro::m_clienttype == "test") |
| 84 | + { |
| 85 | + bool op =QDesktopServices::openUrl(QUrl(("http://exploertest.ipchainglobal.com/insight/feedback"))); |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + bool op =QDesktopServices::openUrl(QUrl(("http://exploer.ipchainglobal.com/insight/feedback"))); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +void InfoWidget::openUrl1() |
| 94 | +{ |
| 95 | + if(Intro::m_clienttype == "test") |
| 96 | + { |
| 97 | + bool op =QDesktopServices::openUrl(QUrl(("http://exploertest.ipchainglobal.com"))); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + bool op =QDesktopServices::openUrl(QUrl(("http://exploer.ipchainglobal.com"))); |
| 102 | + } |
| 103 | +} |
| 104 | +void InfoWidget::setKnownBestHeight(int count, const QDateTime& blockDate) |
| 105 | +{ |
| 106 | + if (count > bestHeaderHeight) { |
| 107 | + |
| 108 | + bestHeaderHeight = count; |
| 109 | + bestHeaderDate = blockDate; |
| 110 | + } |
| 111 | +} |
| 112 | +void InfoWidget::fresh(int count, const QDateTime& blockDate, double nVerificationProgress,bool head) |
| 113 | +{ |
| 114 | + if (head) |
| 115 | + { |
| 116 | + setKnownBestHeight(count, blockDate); |
| 117 | + } |
| 118 | + else |
| 119 | + { |
| 120 | + bool loadingfinish = tipUpdate(count, blockDate, nVerificationProgress); |
| 121 | + if(loadingfinish&&m_walletModel){ |
| 122 | + |
| 123 | + m_walletModel->setUpdataFinished(); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | +} |
| 129 | + |
| 130 | +bool InfoWidget::tipUpdate(int count, const QDateTime& blockDate, double nVerificationProgress) |
| 131 | +{ |
| 132 | + |
| 133 | + if(bestHeaderHeight != 0) |
| 134 | + { |
| 135 | + if(1 == count/bestHeaderHeight) |
| 136 | + { if(m_warnlabel_imagename != ":/res/png/loaded.png"){ |
| 137 | + |
| 138 | + QPixmapCache::clear(); |
| 139 | + |
| 140 | + QPixmapCache::setCacheLimit(1); |
| 141 | + QPixmap p; |
| 142 | + |
| 143 | + p.load(":/res/png/loaded.png"); |
| 144 | + ui->warnlabel->setPixmap(p); |
| 145 | + m_warnlabel_imagename = ":/res/png/loaded.png"; |
| 146 | + } |
| 147 | + } |
| 148 | + else |
| 149 | + { |
| 150 | + if(m_warnlabel_imagename != ":/res/png/loading.png"){ |
| 151 | + |
| 152 | + |
| 153 | + QPixmapCache::clear(); |
| 154 | + |
| 155 | + QPixmapCache::setCacheLimit(1); |
| 156 | + QPixmap p; |
| 157 | + |
| 158 | + p.load(":/res/png/loading.png"); |
| 159 | + ui->warnlabel->setPixmap(p); |
| 160 | + m_warnlabel_imagename = ":/res/png/loading.png"; |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + else |
| 165 | + { |
| 166 | + if(m_warnlabel_imagename != ":/res/png/loading.png"){ |
| 167 | + |
| 168 | + QPixmapCache::clear(); |
| 169 | + |
| 170 | + QPixmapCache::setCacheLimit(1); |
| 171 | + QPixmap p; |
| 172 | + |
| 173 | + p.load(":/res/png/loading.png"); |
| 174 | + ui->warnlabel->setPixmap(p); |
| 175 | + m_warnlabel_imagename = ":/res/png/loading.png"; |
| 176 | + } |
| 177 | + |
| 178 | + } |
| 179 | + |
| 180 | + |
| 181 | + ui->newestblockdate->setText(blockDate.toString(tr("yyyy-MM-dd hh:mm:ss "))); |
| 182 | + |
| 183 | + QString strBuffer,strBuffer1; |
| 184 | + strBuffer = blockDate.toString("yyyy-MM-dd hh:mm:ss"); |
| 185 | + QString tmp=blockDate.date().toString("yyyy-MM-dd hh:mm:ss"); |
| 186 | + |
| 187 | + |
| 188 | + strBuffer1 = blockDate.toString("yyyy-MM-dd hh:mm:ss"); |
| 189 | + bool hasBestHeader = bestHeaderHeight >= count; |
| 190 | + if (hasBestHeader && bestHeaderHeight != 0){//&& bestHeaderDate.isValid()) { |
| 191 | + ui->BlocksLeft->setText(QString::number(bestHeaderHeight - count)); |
| 192 | + QString percentnum = QString::number(((float)count/(float)bestHeaderHeight)*100,'f',2); |
| 193 | + ui->percent->setText(percentnum+"%"); |
| 194 | + |
| 195 | + std::string a ="100.00"; |
| 196 | + if("100.00" ==QString::number(((float)count/(float)bestHeaderHeight)*100,'f',2)) |
| 197 | + { |
| 198 | + isfullloaded = true; |
| 199 | + isfirstfullloaded = true; |
| 200 | + } |
| 201 | + else |
| 202 | + { |
| 203 | + isfullloaded = false; |
| 204 | + } |
| 205 | + if(percentnum == "100.00"){ |
| 206 | + return 1; |
| 207 | + } |
| 208 | + |
| 209 | + |
| 210 | + } else { |
| 211 | + ui->percent->setText(tr("loading")); |
| 212 | + ui->BlocksLeft->setText(tr("loading")); |
| 213 | + } |
| 214 | + return 0; |
| 215 | +} |
| 216 | + |
| 217 | + |
| 218 | +bool InfoWidget::getuserRequest() |
| 219 | +{ |
| 220 | + return m_userRequested; |
| 221 | + |
| 222 | +} |
| 223 | +void InfoWidget::setuserRequest(bool userRequested) |
| 224 | +{ |
| 225 | + m_userRequested = userRequested; |
| 226 | + |
| 227 | +} |
| 228 | +void InfoWidget::showHide(bool hide)//,bool userRequested) |
| 229 | +{ |
| 230 | + |
| 231 | + if(!hide) |
| 232 | + { |
| 233 | + setVisible(true); |
| 234 | + } |
| 235 | + else |
| 236 | + { |
| 237 | + setVisible(false); |
| 238 | + } |
| 239 | + |
| 240 | +} |
| 241 | + |
| 242 | +QString InfoWidget:: getVersion() |
| 243 | +{ |
| 244 | + QString url; |
| 245 | + if(Intro::m_clienttype == "test") |
| 246 | + { |
| 247 | + url = "http://exploertest.ipchainglobal.com:4000/getInfo"; |
| 248 | + }else |
| 249 | + { |
| 250 | + url = "http://exploer.ipchainglobal.com:4000/getInfo"; |
| 251 | + } |
| 252 | + QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
| 253 | + QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url))); |
| 254 | + QByteArray responseData; |
| 255 | + QEventLoop eventLoop; |
| 256 | + connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); |
| 257 | + eventLoop.exec(); |
| 258 | + responseData = reply->readAll(); |
| 259 | + delete manager; |
| 260 | + QString jsonstr = QString(responseData); |
| 261 | + std::string stdstrjson = jsonstr.toStdString(); |
| 262 | + LOG_WRITE(LOG_INFO,"getVersion ",stdstrjson.c_str()); |
| 263 | + cJSON*root=cJSON_Parse(stdstrjson.c_str()); |
| 264 | + if(root){ |
| 265 | + cJSON*itemversion=cJSON_GetObjectItem(root,"version"); |
| 266 | + if(itemversion){ |
| 267 | + |
| 268 | + cJSON*itemurl =cJSON_GetObjectItem(root,"url"); |
| 269 | + if(itemurl && QString::compare(QString(itemversion->valuestring),version)>0){ |
| 270 | + |
| 271 | + Q_EMIT(updateclient(cJSONGetStringObjectItem(root,"type"),\ |
| 272 | + cJSONGetStringObjectItem(root,"sugtext"),\ |
| 273 | + cJSONGetStringObjectItem(root,"url"))); |
| 274 | + return QString::fromStdString(itemurl->valuestring); |
| 275 | + } |
| 276 | + } |
| 277 | + } |
| 278 | + return QString(""); |
| 279 | +} |
| 280 | +QString InfoWidget::cJSONGetStringObjectItem(const cJSON* object,QString name) |
| 281 | +{ |
| 282 | + cJSON*item =cJSON_GetObjectItem(object,name.toStdString().c_str()); |
| 283 | + std::string text; |
| 284 | + if(item&&item->valuestring) |
| 285 | + text = item->valuestring; |
| 286 | + return QString::fromStdString(text); |
| 287 | +} |
| 288 | + |
| 289 | +void InfoWidget::openUrlVersion() |
| 290 | +{ |
| 291 | + bool back =QDesktopServices::openUrl(QUrl(m_versionhtml)); |
| 292 | + if(back) |
| 293 | + { |
| 294 | + LOG_WRITE(LOG_INFO,"openUrl true",m_versionhtml.toStdString().c_str()); |
| 295 | + }else{ |
| 296 | + LOG_WRITE(LOG_INFO,"openUrl false ",m_versionhtml.toStdString().c_str()); |
| 297 | + } |
| 298 | +} |
| 299 | +void InfoWidget::updateclientSlot(QString type,QString sugtext,QString url) |
| 300 | +{ |
| 301 | + LOG_WRITE(LOG_INFO,"InfoWidget::updateclientSlot ",\ |
| 302 | + type.toStdString().c_str(),sugtext.toStdString().c_str(),\ |
| 303 | + url.toStdString().c_str()); |
| 304 | + UpdateDialog updatedlg; |
| 305 | + updatedlg.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint); |
| 306 | + updatedlg.setinfo(type,sugtext,url); |
| 307 | + updatedlg.exec(); |
| 308 | +} |
0 commit comments