qt/LedOK/deviceitem.cpp

99 lines
3.8 KiB
C++
Raw Normal View History

2023-05-25 10:00:00 +08:00
#include "deviceitem.h"
2023-10-23 11:44:22 +08:00
#include "devicepanel.h"
2023-05-15 16:06:10 +08:00
#include "globaldefine.h"
2023-10-23 11:44:22 +08:00
#include "gutil/qwaitingdlg.h"
2023-05-11 11:47:00 +08:00
#include "gutil/qgui.h"
2023-05-15 16:06:10 +08:00
#include "gutil/qnetwork.h"
2022-08-25 18:37:24 +08:00
#include <QMessageBox>
2023-05-11 11:47:00 +08:00
#include <QPainter>
2022-08-25 18:37:24 +08:00
#include <QInputDialog>
2023-10-23 11:44:22 +08:00
DeviceItem::DeviceItem(LoQTreeWidget *parent) : TreeWidgetItem(parent) {
setFlags(flags() & ~Qt::ItemIsUserCheckable);
setCheckState("check", Qt::Unchecked);
auto ft = treeWidget()->font();
ft.setPixelSize(14);
for(int i=2; i<treeWidget()->columnCount()-2; i++) setFont(i, ft);
2022-08-25 18:37:24 +08:00
2023-10-23 11:44:22 +08:00
auto btnGetCapture = new QPushButton;
btnGetCapture->setCursor(QCursor(Qt::PointingHandCursor));
btnGetCapture->setIcon(QIcon(":/res/deviceReadbackPic.png"));
btnGetCapture->setIconSize({28, 28});
QObject::connect(btnGetCapture, &QPushButton::clicked, btnGetCapture, [=] {
2024-06-25 09:37:41 +08:00
JObj json;
2023-05-11 11:47:00 +08:00
json.insert("_id", "GetScreenshotFull");
json.insert("_type", "GetScreenshotFull");
2023-10-23 11:44:22 +08:00
auto waitingDlg = new WaitingDlg(btnGetCapture, DevicePanel::tr("Getting ")+DevicePanel::tr("Screenshot")+" ...");
2023-05-11 11:47:00 +08:00
waitingDlg->show();
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(120000).post(json);
2023-10-23 11:44:22 +08:00
ConnReply(reply, waitingDlg) [=] {
2023-05-11 11:47:00 +08:00
waitingDlg->close();
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) {
2023-10-23 11:44:22 +08:00
QMessageBox::critical(treeWidget(), DevicePanel::tr("Error"), err);
2023-05-11 11:47:00 +08:00
return;
}
ImgDlg dlg(QByteArray::fromBase64(json["data"].toString().toLatin1()), treeWidget());
dlg.exec();
});
});
2023-10-23 11:44:22 +08:00
setCellWidget("screenshot", btnGetCapture);
2022-08-25 18:37:24 +08:00
2023-10-23 11:44:22 +08:00
fdOnline = new QLabel;
fdOnline->setPixmap({":/res/online.png"});
fdOnline->setScaledContents(true);
fdOnline->setFixedSize(24, 24);
auto wgt = new QWidget;
auto hhh = new HBox(wgt);
hhh->setContentsMargins(0,0,0,0);
hhh->addWidget(fdOnline);
setCellWidget("online", wgt);
2022-08-25 18:37:24 +08:00
2023-05-11 11:47:00 +08:00
btnUnlock = new QPushButton;
btnUnlock->setMaximumHeight(40);
2023-10-23 11:44:22 +08:00
QObject::connect(btnUnlock, &QPushButton::clicked, btnUnlock, [this] {
2023-05-15 16:06:10 +08:00
if(! mCard.isLocked) return;
2023-05-11 11:47:00 +08:00
bool ok;
2023-10-23 11:44:22 +08:00
auto pwd = QInputDialog::getText(treeWidget(), DevicePanel::tr("Input password"), DevicePanel::tr("Input password"), QLineEdit::Password, QString(), &ok);
2023-05-11 11:47:00 +08:00
if(! ok) return;
2024-06-25 09:37:41 +08:00
JObj json;
2023-05-11 11:47:00 +08:00
json.insert("_id", "VerifyPassword");
json.insert("_type", "VerifyPassword");
json.insert("pwd", pwd);
2023-10-23 11:44:22 +08:00
auto waitingDlg = new WaitingDlg(btnUnlock, DevicePanel::tr("VerifyPassword")+" ...");
2023-05-11 11:47:00 +08:00
waitingDlg->show();
2023-05-15 16:06:10 +08:00
auto reply = NetReq("http://"+mCard.ip+":2016/settings").timeout(60000).post(json);
2023-10-23 11:44:22 +08:00
ConnReply(reply, waitingDlg) [=] {
2023-05-11 11:47:00 +08:00
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) {
waitingDlg->close();
2023-10-23 11:44:22 +08:00
QMessageBox::critical(treeWidget(), DevicePanel::tr("Error"), err);
2023-05-11 11:47:00 +08:00
return;
}
if(! json["result"].toBool()) {
waitingDlg->close();
2023-10-23 11:44:22 +08:00
QMessageBox::critical(treeWidget(), DevicePanel::tr("Tip Info"), DevicePanel::tr("password is wrong"));
2023-05-11 11:47:00 +08:00
return;
}
waitingDlg->success();
2023-05-15 16:06:10 +08:00
mCard.isLocked = false;
2023-08-01 11:42:41 +08:00
btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
2023-05-11 11:47:00 +08:00
});
});
2023-10-23 11:44:22 +08:00
wgt = new QWidget;
hhh = new HBox(wgt);
hhh->setContentsMargins(0,0,0,0);
hhh->addWidget(btnUnlock);
setCellWidget("password", wgt);
2022-08-25 18:37:24 +08:00
}
2023-05-15 16:06:10 +08:00
void DeviceItem::init() {
2023-10-23 11:44:22 +08:00
setText("id", mCard.id);
setText("ip", mCard.ip);
setText("screenSize", QString("%1 x %2").arg(mCard.mWidth).arg(mCard.mHeight));
2023-08-01 11:42:41 +08:00
if(mCard.hasPassword) btnUnlock->setIcon(QIcon(mCard.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png"));
2023-05-15 16:06:10 +08:00
else btnUnlock->hide();
2022-08-25 18:37:24 +08:00
}