2024-05-23 17:13:51 +08:00
|
|
|
#include "progressesdlg.h"
|
|
|
|
#include "gutil/qcore.h"
|
|
|
|
#include "gutil/qgui.h"
|
|
|
|
#include "gutil/qnetwork.h"
|
2024-08-07 18:18:37 +08:00
|
|
|
#include "main.h"
|
2024-05-23 17:13:51 +08:00
|
|
|
#include <QAction>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QHttpMultiPart>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
|
|
ProgressesDlg::ProgressesDlg(QWidget *parent) : QDialog(parent) {
|
|
|
|
resize(1280, 720);
|
|
|
|
setWindowFlag(Qt::WindowMaximizeButtonHint);
|
|
|
|
|
|
|
|
auto vBox = new VBox(this);
|
|
|
|
vBox->setContentsMargins(6, 0, 6, 0);
|
|
|
|
|
|
|
|
table = new TreeWidget;
|
|
|
|
table->addCol("#", "", 20);
|
|
|
|
table->addCol("id", "ID", 125);
|
|
|
|
table->addCol("ip", "IP", 95);
|
|
|
|
table->addCol("alias", tr("Alias"), 80);
|
|
|
|
table->addCol("progress", tr("Progress"), 100);
|
|
|
|
table->addCol("res", tr("State"), 200, QHeaderView::Stretch);
|
|
|
|
table->setDefs()->setHeaderAlignC();
|
|
|
|
table->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
vBox->addWidget(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgressesItem::sendProgress(const QString &id) {
|
|
|
|
QJsonObject json;
|
|
|
|
json.insert("_id", id);
|
|
|
|
json.insert("_type", id);
|
|
|
|
auto reply = NetReq("http://"+text("ip")+":2016/settings").timeout(30000).post(json);
|
|
|
|
ConnReply(reply, this) [=] {
|
|
|
|
if(treeWidget()==0) return;
|
|
|
|
JValue json;
|
|
|
|
auto err = errStrWithJson(reply, &json);
|
|
|
|
if(! err.isEmpty()) {
|
|
|
|
setRes(id+" "+tr("Error")+": "+err, Qt::red);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto progre = json["progress"].toInt();
|
|
|
|
if(progre >= 100) {
|
|
|
|
fdProgress->setValue(100);
|
|
|
|
setRes("FPGA "+tr("Install Success"), Qt::darkGreen);
|
|
|
|
} else if(progre == -1) {
|
|
|
|
fdProgress->setValue(100);
|
|
|
|
setRes(tr("Same version, needn't update"), Qt::darkGreen);
|
|
|
|
} else if(progre == -2) {
|
|
|
|
setRes(tr("Install Failed")+" (-2)", Qt::red);
|
|
|
|
} else {
|
|
|
|
fdProgress->setValue(progre);
|
|
|
|
wait(250);
|
|
|
|
sendProgress(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|