2023-04-18 14:14:46 +08:00
|
|
|
#include "sendprogramdialog.h"
|
|
|
|
#include "cfg.h"
|
2023-05-11 11:47:00 +08:00
|
|
|
#include "sendprogthread.h"
|
2023-08-07 09:04:53 +08:00
|
|
|
#include "deviceitem.h"
|
|
|
|
#include "devicepanel.h"
|
|
|
|
#include "gutil/qnetwork.h"
|
2023-09-19 11:49:20 +08:00
|
|
|
#include "gutil/qwaitingdlg.h"
|
2023-04-18 14:14:46 +08:00
|
|
|
#include <QAction>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QHeaderView>
|
2023-05-05 17:22:54 +08:00
|
|
|
#include <QDialogButtonBox>
|
2023-08-07 09:04:53 +08:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QProgressBar>
|
2023-04-18 14:14:46 +08:00
|
|
|
|
|
|
|
SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialog(parent), mProgName(progName) {
|
2023-05-15 16:06:10 +08:00
|
|
|
#ifdef Q_OS_WIN
|
2023-04-18 14:14:46 +08:00
|
|
|
setWindowFlag(Qt::WindowMaximizeButtonHint);
|
2023-05-05 17:22:54 +08:00
|
|
|
#endif
|
2023-04-18 14:14:46 +08:00
|
|
|
setWindowTitle(tr("Publish")+" "+mProgName);
|
2023-09-19 11:49:20 +08:00
|
|
|
resize(1024, 720);
|
2023-05-05 17:22:54 +08:00
|
|
|
|
|
|
|
auto vBox = new VBox(this);
|
2023-09-19 11:49:20 +08:00
|
|
|
vBox->setContentsMargins(6,0,6,0);
|
2023-05-05 17:22:54 +08:00
|
|
|
auto hBox = new HBox(vBox);
|
2023-04-18 14:14:46 +08:00
|
|
|
|
|
|
|
label = new QLabel(tr("success info"));
|
|
|
|
hBox->addWidget(label);
|
2023-09-19 11:49:20 +08:00
|
|
|
hBox->addSpacing(20);
|
2023-04-18 14:14:46 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
auto btnPublish = new QPushButton(tr("Publish"));
|
|
|
|
connect(btnPublish, &QPushButton::clicked, this, [=] {
|
2023-04-18 14:14:46 +08:00
|
|
|
if(mWaitCnt > 0) return;
|
2023-09-19 11:49:20 +08:00
|
|
|
int cnt = table->topLevelItemCount();
|
|
|
|
int sentCnt = 0;
|
|
|
|
SendProgramItem *item;
|
|
|
|
auto remarks = "remarks"**table;
|
|
|
|
for(int rr=0; rr<cnt; rr++) if(! (item = (SendProgramItem*) table->topLevelItem(rr))->isHidden() && item->checkState("id") == Qt::Checked && ! item->isSending) {
|
|
|
|
if(item->btnUnlock && item->isLocked) {
|
|
|
|
item->setResult(tr("This screen is encrypted"), Qt::red);
|
2023-04-18 14:14:46 +08:00
|
|
|
continue;
|
|
|
|
}
|
2023-09-19 11:49:20 +08:00
|
|
|
item->fdProgress->setValue(0);
|
|
|
|
if(sentCnt>=gSendBatch) {
|
|
|
|
item->setText(remarks, " "+tr("Waiting")+" ...");
|
|
|
|
item->setForeground(remarks, Qt::black);
|
2023-04-18 14:14:46 +08:00
|
|
|
mWaitCnt++;
|
|
|
|
continue;
|
|
|
|
}
|
2023-09-19 11:49:20 +08:00
|
|
|
item->isSending = true;
|
|
|
|
item->setText(remarks, "");
|
|
|
|
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", item->text("ip"), 3333);
|
|
|
|
connect(sendProg, &SendProgThread::emErr, item->fdProgress, [=](QString strTip) {
|
|
|
|
item->isSending = false;
|
2023-04-18 14:14:46 +08:00
|
|
|
if(strTip=="OK") {
|
2023-09-19 11:49:20 +08:00
|
|
|
item->setCheckState("id", Qt::Unchecked);
|
|
|
|
item->setText(remarks, "OK");
|
|
|
|
item->setForeground(remarks, Qt::darkGreen);
|
2023-04-18 14:14:46 +08:00
|
|
|
} else {
|
2023-09-19 11:49:20 +08:00
|
|
|
item->setText(remarks, strTip);
|
|
|
|
item->setForeground(remarks, Qt::red);
|
2023-04-18 14:14:46 +08:00
|
|
|
}
|
|
|
|
sendNext();
|
|
|
|
});
|
2023-09-19 11:49:20 +08:00
|
|
|
connect(sendProg, &SendProgThread::emProgress, item->fdProgress, &QProgressBar::setValue);
|
2023-04-18 14:14:46 +08:00
|
|
|
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
|
|
|
|
sendProg->start();
|
|
|
|
sentCnt++;
|
|
|
|
}
|
|
|
|
});
|
2023-09-19 11:49:20 +08:00
|
|
|
hBox->addWidget(btnPublish);
|
2023-04-18 14:14:46 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
hBox->addStretch();
|
2023-08-07 09:04:53 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
auto btnRefresh = new QPushButton(tr("Refresh"));
|
|
|
|
connect(btnRefresh, &QPushButton::clicked, this, [=] {
|
|
|
|
int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
|
|
|
|
for(int i=0; i<cnt; i++) {
|
|
|
|
auto card = ((DeviceItem*)gDevicePanel->mDeviceTable->topLevelItem(i))->mCard;
|
|
|
|
int cnt = table->topLevelItemCount();
|
|
|
|
SendProgramItem *item;
|
|
|
|
for(int rr=0; rr<cnt; rr++) if((item = (SendProgramItem*) table->topLevelItem(rr))->text("id") == card.id) goto end;
|
|
|
|
item = new SendProgramItem(table);
|
|
|
|
item->setFlags(item->flags() & ~Qt::ItemIsUserCheckable);
|
|
|
|
item->setCheckState("id", Qt::Unchecked);
|
|
|
|
item->setText("id", card.id);
|
|
|
|
{
|
|
|
|
item->fdOnline = new QLabel;
|
|
|
|
item->fdOnline->setScaledContents(true);
|
|
|
|
item->fdOnline->setFixedSize(24, 24);
|
|
|
|
auto wgt = new QWidget;
|
|
|
|
auto hhh = new HBox(wgt);
|
|
|
|
hhh->setContentsMargins(0,0,0,0);
|
|
|
|
hhh->addWidget(item->fdOnline);
|
|
|
|
item->setCellWidget("online", wgt);
|
|
|
|
}
|
|
|
|
item->fdProgress = new QProgressBar;
|
|
|
|
item->fdProgress->setAlignment(Qt::AlignCenter);
|
|
|
|
item->fdProgress->setStyleSheet("QProgressBar {margin-top: 6px; margin-bottom: 6px;}");
|
|
|
|
item->setCellWidget("progress", item->fdProgress);
|
|
|
|
end:
|
|
|
|
item->setText("ip", card.ip);
|
|
|
|
item->setText("alias", card.alias);
|
|
|
|
item->setText("size", QString("%1 x %2").arg(card.mWidth).arg(card.mHeight));
|
|
|
|
item->fdOnline->setPixmap({card.isOnline ? ":/res/online.png" : ":/res/offline.png"});
|
|
|
|
if(! card.hasPassword) {
|
|
|
|
item->isLocked = false;
|
|
|
|
item->setCellWidget("encrypt", item->btnUnlock = 0);
|
|
|
|
} else {
|
|
|
|
item->isLocked = card.isLocked;
|
|
|
|
if(item->btnUnlock==0) {
|
|
|
|
item->btnUnlock = new QPushButton;
|
|
|
|
item->btnUnlock->setMaximumHeight(36);
|
|
|
|
item->setCellWidget("encrypt", item->btnUnlock);
|
|
|
|
connect(item->btnUnlock, &QPushButton::clicked, item->btnUnlock, [=] {
|
|
|
|
if(! item->isLocked) return;
|
|
|
|
bool ok;
|
|
|
|
auto pwd = QInputDialog::getText(this, tr("Input password"), tr("Input password"), QLineEdit::Password, QString(), &ok);
|
|
|
|
if(! ok) return;
|
|
|
|
QJsonObject json;
|
|
|
|
json.insert("_id", "VerifyPassword");
|
|
|
|
json.insert("_type", "VerifyPassword");
|
|
|
|
json.insert("pwd", pwd);
|
|
|
|
auto waitingDlg = new WaitingDlg(this, tr("VerifyPassword")+" ...");
|
|
|
|
waitingDlg->show();
|
|
|
|
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(30000).post(json);
|
|
|
|
waitingDlg->connAbort(reply);
|
|
|
|
connect(reply, &QNetworkReply::finished, item->btnUnlock, [=] {
|
|
|
|
QJsonDocument json;
|
|
|
|
auto err = checkReplyForJson(reply, &json);
|
|
|
|
if(! err.isEmpty()) {
|
|
|
|
waitingDlg->close();
|
|
|
|
QMessageBox::critical(this, QObject::tr("Error"), err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(! json["result"].toBool()) {
|
|
|
|
waitingDlg->close();
|
|
|
|
QMessageBox::warning(this, tr("Tip Info"), tr("password is wrong"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
waitingDlg->success();
|
|
|
|
item->isLocked = false;
|
|
|
|
item->btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
|
|
|
|
auto item = findItem(card.id);
|
|
|
|
if(item) {
|
|
|
|
item->mCard.isLocked = false;
|
|
|
|
item->btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
item->btnUnlock->setIcon(QIcon(card.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png")); //已验证显示绿色 没验证蓝色
|
|
|
|
}
|
|
|
|
}
|
|
|
|
label->setText(tr("All")+": "+QString::number(cnt));
|
|
|
|
});
|
|
|
|
hBox->addWidget(btnRefresh);
|
2023-08-07 09:04:53 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
auto txtSearch = new QLineEdit;
|
|
|
|
txtSearch->setFixedWidth(150);
|
|
|
|
txtSearch->setClearButtonEnabled(true);
|
|
|
|
txtSearch->setStyleSheet("QLineEdit{border: 2px solid #aaa; padding: 2px;}");
|
|
|
|
txtSearch->addAction(new QAction(QIcon(":/res/program/bnSearch.png"), QString()), QLineEdit::LeadingPosition);
|
|
|
|
connect(txtSearch, &QLineEdit::textEdited, this, [=](const QString &text) {
|
|
|
|
auto cnt = table->topLevelItemCount();
|
|
|
|
for(int rr=0; rr<cnt; rr++) {
|
|
|
|
auto item = table->item(rr);
|
|
|
|
item->setHidden(! (text.isEmpty() || item->text("id").contains(text) || item->text("ip").contains(text) || item->text("alias").contains(text) || item->text("size").contains(text)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
hBox->addWidget(txtSearch);
|
2023-08-07 09:04:53 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
table = new LoQTreeWidget;
|
|
|
|
table->addCol("#", "", 20);
|
|
|
|
table->addCol("id", "ID", 130).margin(4);
|
|
|
|
table->addCol("online", tr("Online"), 40);
|
|
|
|
table->addCol("ip", "IP", 100);
|
|
|
|
table->addCol("size", tr("Screen Size"), 80).alignC(),
|
|
|
|
table->addCol("alias", tr("Alias"), 120);
|
|
|
|
table->addCol("encrypt", tr("Security"), 40);
|
|
|
|
table->addCol("progress", tr("Progress"), 120);
|
|
|
|
table->addCol("remarks", tr("Remarks"), QHeaderView::Stretch);
|
|
|
|
table->setDefs()->setHeaderAlignC();
|
|
|
|
table->addFd();
|
|
|
|
table->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
table->setSortingEnabled(true);
|
|
|
|
vBox->addWidget(table);
|
2023-08-07 09:04:53 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
auto sortField = gDevicePanel->mDeviceTable->sortField();
|
|
|
|
if(sortField=="id" || sortField=="ip" || sortField=="alias") table->sortItems(sortField, gDevicePanel->mDeviceTable->header()->sortIndicatorOrder());
|
|
|
|
else table->sortItems("id");
|
2023-08-07 09:04:53 +08:00
|
|
|
|
2023-09-19 11:49:20 +08:00
|
|
|
emit btnRefresh->clicked();
|
2023-08-07 09:04:53 +08:00
|
|
|
}
|
|
|
|
|
2023-04-18 14:14:46 +08:00
|
|
|
void SendProgramDialog::closeEvent(QCloseEvent *) {
|
|
|
|
emit stopAllThd();
|
|
|
|
}
|
|
|
|
void SendProgramDialog::sendNext() {
|
|
|
|
if(mWaitCnt <= 0) return;
|
2023-09-19 11:49:20 +08:00
|
|
|
int cnt = table->topLevelItemCount();
|
|
|
|
SendProgramItem *item;
|
|
|
|
auto remarks = "remarks"**table;
|
|
|
|
for(int rr=0; rr<cnt; rr++) if(! (item = (SendProgramItem*) table->item(rr))->isHidden() && item->checkState("id") == Qt::Checked && ! item->isSending && ! item->isLocked && item->text(remarks).startsWith(" ")) {
|
|
|
|
item->setText(remarks, "");
|
|
|
|
item->fdProgress->setValue(0);
|
|
|
|
item->isSending = true;
|
2023-04-18 14:14:46 +08:00
|
|
|
mWaitCnt--;
|
2023-09-19 11:49:20 +08:00
|
|
|
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", item->text("ip"), 3333);
|
|
|
|
connect(sendProg, &SendProgThread::emErr, item->fdProgress, [=](QString strTip) {
|
|
|
|
item->isSending = false;
|
2023-04-18 14:14:46 +08:00
|
|
|
if(strTip=="OK") {
|
2023-09-19 11:49:20 +08:00
|
|
|
item->setCheckState("id", Qt::Unchecked);
|
|
|
|
item->setText(remarks, "OK");
|
|
|
|
item->setForeground(remarks, Qt::darkGreen);
|
2023-04-18 14:14:46 +08:00
|
|
|
} else {
|
2023-09-19 11:49:20 +08:00
|
|
|
item->setText(remarks, strTip);
|
|
|
|
item->setForeground(remarks, Qt::red);
|
2023-04-18 14:14:46 +08:00
|
|
|
}
|
|
|
|
sendNext();
|
|
|
|
});
|
2023-09-19 11:49:20 +08:00
|
|
|
connect(sendProg, &SendProgThread::emProgress, item->fdProgress, &QProgressBar::setValue);
|
2023-04-18 14:14:46 +08:00
|
|
|
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
|
|
|
|
sendProg->start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|