This commit is contained in:
Gangphon 2023-08-07 09:04:53 +08:00
parent 13ad4ec75f
commit 7fae3c0bd3
24 changed files with 2409 additions and 2503 deletions

View File

@ -11,6 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 5) {
CONFIG += c++17
CONFIG += lrelease
CONFIG += embed_translations
# CONFIG += console
# You can also make your code fail to compile if you use deprecated APIs.
@ -117,6 +118,7 @@ SOURCES += \
ffplayer.cpp \
globaldefine.cpp \
gutil/qgui.cpp \
gutil/qjson.cpp \
gutil/qnetwork.cpp \
main.cpp \
mainwindow.cpp \
@ -164,7 +166,6 @@ SOURCES += \
program/videosplitthread.cpp \
program/wplanitem.cpp \
program/wplanlist.cpp \
program/wprogrampublishitem.cpp \
HEADERS += \
base/changepasswordform.h \
@ -189,6 +190,7 @@ HEADERS += \
ffplayer.h \
globaldefine.h \
gutil/qgui.h \
gutil/qjson.h \
gutil/qnetwork.h \
mainwindow.h \
mguangyingpinwidget.h \
@ -235,7 +237,6 @@ HEADERS += \
program/videosplitthread.h \
program/wplanitem.h \
program/wplanlist.h \
program/wprogrampublishitem.h \
TRANSLATIONS += \
translations/app_zh_CN.ts \

View File

@ -1,4 +1,8 @@
Table {selection-background-color: #8ce;}
Table {selection-background-color: #0ae;}
QCheckBox::indicator, QTableWidget::indicator, QTreeWidget::indicator {
width: 1.15em; height: 1.15em;
}
QLineEdit,QComboBox,QAbstractSpinBox {
border: 1px solid #aaa;
@ -38,16 +42,6 @@ QAbstractSpinBox::down-arrow:pressed {
top: 1px;
}
QCheckBox::indicator, QTreeWidget::indicator {
border-image: url(:/res/CheckBoxUnchecked.png); width: 1em; height: 1em; margin-left: 0.25em;
}
QCheckBox::indicator:checked, QTreeWidget::indicator:checked {
border-image: url(:/res/CheckBoxChecked.png);
}
QCheckBox::indicator:disabled {
background-color: #666;
}
ExtendedGroupBox::indicator {
border-image: url(:/res/groupbox-unchecked.png);
}
@ -77,7 +71,7 @@ QMenu::item:selected {
}
QListWidget {
selection-background-color: #8ce;
selection-background-color: #0ae;
}
LoColorSelector {
@ -92,14 +86,10 @@ LoColorSelector {
QTreeWidget[ssType="topList"]::item {
border-right: 1px solid #ddd;
border-bottom: 1px solid #ddd;
height: 40px;
height: 38px;
}
QTreeWidget[ssType="topList"] QHeaderView::section {
border-top: 1px solid #aaa;
border-bottom: 1px solid #aaa;
border-left: 0;
border-right: 0;
height: 36px;
QTreeWidget[ssType="topList"]>QHeaderView::section {
height: 30px;
}
QTreeWidget[ssType="topList"]::item:hover {
background-color: #ddd;

View File

@ -148,12 +148,12 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
hBox->addWidget(labelWebServer);
fdWebServerAddr = new QComboBox;
fdWebServerAddr->addItem(tr("www.m2mled.net"));
fdWebServerAddr->addItem(tr("www.ledaips.com"));
fdWebServerAddr->addItem(tr("https://www.taxihub.cn:2340"));
fdWebServerAddr->addItem(tr("https://www.ledaips.com:2340"));
fdWebServerAddr->addItem(tr("https://www.36taxi.com:2340"));
fdWebServerAddr->addItem(tr("www.tlzxled.com"));
fdWebServerAddr->addItem("www.m2mled.net");
fdWebServerAddr->addItem("www.ledaips.com");
fdWebServerAddr->addItem("https://www.taxihub.cn:2340");
fdWebServerAddr->addItem("https://www.ledaips.com:2340");
fdWebServerAddr->addItem("https://www.36taxi.com:2340");
fdWebServerAddr->addItem("www.tlzxled.com");
fdWebServerAddr->setMinimumWidth(260);
fdWebServerAddr->setEditable(true);
hBox->addWidget(fdWebServerAddr);
@ -448,88 +448,71 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json{{"_type","DelPrograms"},{"_id","DelPrograms"},{"zVer","xixun1"}};
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("Clearing Program")+" ...");
waitingDlg->show();
auto card = gSelCards[0];
auto tcp = new QTcpSocket();
auto timer = new QTimer(tcp);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, tcp, [=] {
waitingDlg->close();
tcp->abort();
tcp->deleteLater();
QMessageBox::critical(this, tr("Tip"), tr("Clear Program")+" "+tr("Timeout"));
});
auto tcp = new TcpSocket;
connect(waitingDlg, &WaitingDlg::rejected, tcp, [=] {
timer->stop();
tcp->abort();
tcp->deleteLater();
});
connect(tcp, &QTcpSocket::connected, tcp, [=] {
timer->stop();
tcp->write("{\"_type\":\"DelPrograms\",\"_id\":\"DelPrograms\",\"zVer\":\"xixun1\"}");
timer->start(10000);
tcp->stopTimer();
tcp->write(JToBytes(json));
tcp->startTimer(10000);
});
connect(tcp, &QTcpSocket::readyRead, tcp, [=] {
timer->stop();
QByteArray resp = tcp->readAll();
tcp->stopTimer();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
QJsonDocument json = QJsonDocument::fromJson(resp, &parseErr);
if(parseErr.error != QJsonParseError::NoError) {
QString error;
auto json = JFrom(resp, &error);
if(! error.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), parseErr.errorString());
QMessageBox::critical(this, tr("Tip"), error);
} else if(! json["success"].toBool()) {
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), tr("Clear Program")+" "+tr("Failed"));
} else waitingDlg->success();
});
connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) {
timer->stop();
tcp->close();
tcp->deleteLater();
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), QString(socketErrKey(err))+" ("+QString::number(err)+") "+tcp->errorString());
});
tcp->connectToHost(card.ip, 3333);
timer->start(10000);
tcp->startTimer(10000);
} else {
foreach(auto card, gSelCards) {
auto tcp = new QTcpSocket();
auto timer = new QTimer(tcp);
timer->setSingleShot(true);
auto tcp = new TcpSocket;
auto cardId = card.id;
connect(timer, &QTimer::timeout, tcp, [tcp, cardId] {
tcp->abort();
tcp->deleteLater();
gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Timeout"));
connect(tcp, &QTcpSocket::connected, tcp, [=] {
tcp->stopTimer();
tcp->write(JToBytes(json));
tcp->startTimer(10000);
});
connect(tcp, &QTcpSocket::connected, tcp, [tcp, timer] {
timer->stop();
tcp->write("{\"_type\":\"DelPrograms\",\"_id\":\"DelPrograms\",\"zVer\":\"xixun1\"}");
timer->start(10000);
});
connect(tcp, &QTcpSocket::readyRead, tcp, [tcp, timer, cardId] {
timer->stop();
QByteArray resp = tcp->readAll();
connect(tcp, &QTcpSocket::readyRead, tcp, [=] {
tcp->stopTimer();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
QJsonDocument json = QJsonDocument::fromJson(resp, &parseErr);
if(parseErr.error != QJsonParseError::NoError) gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+parseErr.errorString());
QString error;
auto json = JFrom(resp, &error);
if(! error.isEmpty()) gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+error);
else if(! json["success"].toBool()) gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Failed"));
else gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Success"));
});
connect(tcp, &QTcpSocket::errorOccurred, tcp, [tcp, timer, cardId](QAbstractSocket::SocketError err) {
timer->stop();
connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) {
tcp->close();
tcp->deleteLater();
gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+QMetaEnum::fromType<QAbstractSocket::SocketError>().valueToKey(err)+" ("+QString::number(err)+") "+tcp->errorString());
gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+socketErrKey(err)+" ("+QString::number(err)+") "+tcp->errorString());
});
tcp->connectToHost(card.ip, 3333);
timer->start(10000);
tcp->startTimer(10000);
}
}
});
@ -544,87 +527,70 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
}
JObj json{{"_type","getPlayerState"},{"_id","getPlayerState"},{"zVer","xixun1"}};
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("Clearing Program")+" ...");
waitingDlg->show();
auto waitingDlg = new WaitingDlg(this, tr("Getting Player State")+" ...");
waitingDlg->showLater();
auto card = gSelCards[0];
auto tcp = new QTcpSocket();
auto timer = new QTimer(tcp);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, tcp, [=] {
waitingDlg->close();
tcp->abort();
tcp->deleteLater();
QMessageBox::critical(this, tr("Tip"), tr("Clear Program")+" "+tr("Timeout"));
});
auto tcp = new TcpSocket;
connect(waitingDlg, &WaitingDlg::rejected, tcp, [=] {
timer->stop();
tcp->abort();
tcp->deleteLater();
});
connect(tcp, &QTcpSocket::connected, tcp, [=] {
timer->stop();
tcp->stopTimer();
tcp->write(JToBytes(json));
timer->start(10000);
tcp->startTimer(10000);
});
connect(tcp, &QTcpSocket::readyRead, tcp, [=] {
timer->stop();
QByteArray resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
QJsonDocument json = QJsonDocument::fromJson(resp, &parseErr);
if(parseErr.error != QJsonParseError::NoError) {
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), parseErr.errorString());
} else if(! json["success"].toBool()) {
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), tr("Clear Program")+" "+tr("Failed"));
} else waitingDlg->success();
});
connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) {
timer->stop();
tcp->stopTimer();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
waitingDlg->close();
QMessageBox::critical(this, tr("Tip"), QString(socketErrKey(err))+" ("+QString::number(err)+") "+tcp->errorString());
QString error;
auto json = JFrom(resp, &error);
if(! error.isEmpty()) {
QMessageBox::critical(this, tr("Error"), error);
return;
}
QMessageBox::information(this, tr("Player State"), json["code"].toStr()+". "+json["des_en"].toStr()+"\n"+json["des"].toStr());
});
connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) {
tcp->close();
tcp->deleteLater();
waitingDlg->close();
QMessageBox::critical(this, tr("Error"), QString(socketErrKey(err))+" ("+QString::number(err)+") "+tcp->errorString());
});
tcp->connectToHost(card.ip, 3333);
timer->start(10000);
tcp->startTimer(10000);
} else {
foreach(auto card, gSelCards) {
auto tcp = new QTcpSocket();
auto timer = new QTimer(tcp);
timer->setSingleShot(true);
auto tcp = new TcpSocket;
auto cardId = card.id;
connect(timer, &QTimer::timeout, tcp, [tcp, cardId] {
tcp->abort();
tcp->deleteLater();
gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Timeout"));
});
connect(tcp, &QTcpSocket::connected, tcp, [tcp, json, timer] {
timer->stop();
connect(tcp, &QTcpSocket::connected, tcp, [=] {
tcp->stopTimer();
tcp->write(JToBytes(json));
timer->start(10000);
tcp->startTimer(10000);
});
connect(tcp, &QTcpSocket::readyRead, tcp, [tcp, timer, cardId] {
timer->stop();
QByteArray resp = tcp->readAll();
connect(tcp, &QTcpSocket::readyRead, tcp, [=] {
tcp->stopTimer();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
QJsonDocument json = QJsonDocument::fromJson(resp, &parseErr);
if(parseErr.error != QJsonParseError::NoError) gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+parseErr.errorString());
else if(! json["success"].toBool()) gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Failed"));
else gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+tr("Success"));
QString error;
auto json = JFrom(resp, &error);
if(! error.isEmpty()) {
gFdResInfo->append(cardId+" "+tr("Get Player State")+" "+error);
return;
}
gFdResInfo->append(cardId+" "+tr("Player State")+" "+json["code"].toStr()+". "+json["des_en"].toStr()+"\n"+json["des"].toStr());
});
connect(tcp, &QTcpSocket::errorOccurred, tcp, [tcp, timer, cardId](QAbstractSocket::SocketError err) {
timer->stop();
connect(tcp, &QTcpSocket::errorOccurred, tcp, [=](QAbstractSocket::SocketError err) {
tcp->close();
tcp->deleteLater();
gFdResInfo->append(cardId+" "+tr("Clear Program")+" "+QMetaEnum::fromType<QAbstractSocket::SocketError>().valueToKey(err)+" ("+QString::number(err)+") "+tcp->errorString());
gFdResInfo->append(cardId+" "+tr("Get Player State")+" "+socketErrKey(err)+" ("+QString::number(err)+") "+tcp->errorString());
});
tcp->connectToHost(card.ip, 3333);
timer->start(10000);
tcp->startTimer(10000);
}
}
});
@ -1519,7 +1485,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
});
connect(tcp, &QTcpSocket::readyRead, tcp, [=] {
timer->stop();
QByteArray resp = tcp->readAll();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
@ -1559,7 +1525,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
});
connect(tcp, &QTcpSocket::readyRead, tcp, [tcp, timer, cardId] {
timer->stop();
QByteArray resp = tcp->readAll();
auto resp = tcp->readAll();
tcp->close();
tcp->deleteLater();
QJsonParseError parseErr;
@ -2329,6 +2295,7 @@ void CtrlAdvancedPanel::transUi() {
btnGetLog->setText(tr("Check Log"));
btnSetBack->setText(tr("Set Wallpaper"));
btnClearProg->setText(tr("Clear Program"));
btnGetPlayerState->setText(tr("Get Player State"));
btnPlayerBackSet->setText(tr("Set player background"));
btnPlayerBackClear->setText(tr("Clear player background"));
@ -2407,7 +2374,7 @@ void PlayerBackSendThread::run() {
req.insert("zVer","xixun1");
auto resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'proStart'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'proStart'");
tcp.close();
return;
}
@ -2418,7 +2385,7 @@ void PlayerBackSendThread::run() {
req.insert("zVer","xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'imgFileStart'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'imgFileStart'");
tcp.close();
return;
}
@ -2438,13 +2405,13 @@ void PlayerBackSendThread::run() {
}
resNum = tcp.write(readed);
if(resNum == -1) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write file: "+file->fileName());
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write file: "+file->fileName());
tcp.close();
file->close();
return;
}
if(! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForWritten file: "+file->fileName());
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForWritten file: "+file->fileName());
tcp.close();
file->close();
return;
@ -2458,7 +2425,7 @@ void PlayerBackSendThread::run() {
req.insert("zVer","xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'fileEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'fileEnd'");
tcp.close();
return;
}
@ -2468,18 +2435,18 @@ void PlayerBackSendThread::run() {
req.insert("zVer","xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'proEnd'");
tcp.close();
return;
};
if(! tcp.waitForReadyRead()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForRead 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForRead 'proEnd'");
tcp.close();
return;
}
auto resp = tcp.readAll();
if(resp.isEmpty()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when read 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when read 'proEnd'");
tcp.close();
return;
}

View File

@ -364,7 +364,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
m_headerItem->setText(Upgrade_ONLINE, tr("Online"));
m_headerItem->setText(Upgrade_SCREEN_IP, tr("Screen IP"));
m_headerItem->setText(Upgrade_ENCRYPT, tr("Security"));
m_headerItem->setText(Upgrade_REMARK_NAME, tr("Remark Name"));
m_headerItem->setText(Upgrade_REMARK_NAME, tr("Alias"));
m_headerItem->setText(Upgrade_PROGRESS, tr("Progress"));
m_headerItem->setText(Upgrade_Remark, tr("State"));
m_headerItem->setText(Upgrade_XIXUNPLAYER_VERSION, tr("xixunplayer"));

View File

@ -362,7 +362,7 @@ void DevicePanel::transUi() {
m_headerItem->setText(DeviceTable_ID, tr("Screen ID"));
m_headerItem->setText(DeviceTable_IP, tr("Screen IP"));
m_headerItem->setText(DeviceTable_ScreenSize, tr("Screen Size"));
m_headerItem->setText(DeviceTable_Remark, tr("Remark Name"));
m_headerItem->setText(DeviceTable_Remark, tr("Alias"));
m_headerItem->setText(DeviceTable_Screenshot, tr("readback pic"));
m_headerItem->setText(DeviceTable_Brightness, tr("Screen Brightness"));
m_headerItem->setText(DeviceTable_Power, tr("Power Status"));

View File

@ -4,8 +4,7 @@
#include <QJsonDocument>
#include <QNetworkReply>
class LedCard {
public:
struct LedCard {
QString id;
QString ip;
int mWidth{0};

View File

@ -16,7 +16,7 @@ Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent)
noStretch = false;
} else horizontalHeader()->setSectionResizeMode(i, (QHeaderView::ResizeMode)it->resizeMode);
}
mFieldMap.insert(it->field, i++);
mFieldMap.emplace(it->field, i++);
}
}
@ -31,9 +31,14 @@ void Table::resizeSec() {
int colCnt = columnCount(), remainWidth = header->width(), stretchWidth = 0, secWidth;
QTableWidgetItem *item;
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc))) {
if((secWidth = item->data(0x99).toInt()) > 0) stretchWidth += secWidth;
else remainWidth -= header->sectionSize(cc);
}
if((secWidth = item->data(0x99).toInt()) > 0) stretchWidth += secWidth;
else remainWidth -= header->sectionSize(cc);
}
if(remainWidth<=0 || stretchWidth==0) return;
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc)) && (secWidth = item->data(0x99).toInt()) > 0) header->resizeSection(cc, secWidth * remainWidth / stretchWidth);
}
void Table::updateGeometries() {
QTableWidget::updateGeometries();
emit updGeos();
}

View File

@ -2,12 +2,12 @@
#define QGUI_H
#include <QComboBox>
#include <QStackedLayout>
#include <QSplitter>
#include <QListWidget>
#include <QTableWidget>
#include <QHeaderView>
#include <QLabel>
#include <QListWidget>
#include <QSplitter>
#include <QStackedLayout>
#include <QTableWidget>
#include <QTextEdit>
#define MainMust \
@ -155,10 +155,6 @@ public:
Table() {}
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0);
inline auto setNoEdit() {
setEditTriggers(QAbstractItemView::NoEditTriggers);
return this;
}
inline auto setDefs() {
setSelectionBehavior(QTableWidget::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
@ -291,13 +287,15 @@ public:
setCellWidget(row, col, widget);
}
std::map<QString, int> mFieldMap;
public Q_SLOTS:
inline void clearRows() {setRowCount(0);}
signals:
void updGeos();
protected:
void resizeEvent(QResizeEvent *event) override;
void updateGeometries() override;
void resizeSec();
QMap<QString,int> mFieldMap;
bool noStretch{true};
};

View File

@ -94,13 +94,23 @@ public:
if(type==Array) return *(JArray*) data;
return JArray();
}
const JValue operator[](const QString &key) const {
return type==Obj ? (*(JObj*) data)[key] : JValue();
}
const JValue operator[](int i) const {
return type==Array ? (*(JArray*) data)[i] : JValue();
}
private:
JValue(const void *) = delete; // avoid implicit conversions from char * to bool
};
class JParser {
public:
JParser(QTextStream &in) : in(in) {}
JParser(QTextStream &in) : in(in) {
#if(QT_VERSION_MAJOR < 6)
in.setCodec("UTF-8");
#endif
}
inline JValue read() {
skipSpace();
@ -144,7 +154,11 @@ inline JValue JFrom(QIODevice *device, QString *err = 0) {
class JOut {
public:
JOut(QTextStream &out, QString indent = "") : out(out), indent(indent) {}
JOut(QTextStream &out, QString indent = "") : out(out), indent(indent) {
#if(QT_VERSION_MAJOR < 6)
out.setCodec("UTF-8");
#endif
}
void write(const JValue &obj);
void writeStr(const QString &str);

View File

@ -71,13 +71,12 @@ bool TcpSocket::connAndExec(int msecs, QEventLoop *loop) {
connect(this, &QTcpSocket::errorOccurred, loop, [loop] {
loop->exit(1);
});
if(msecs > 0) {
connect(this, &TcpSocket::timeout, loop, &QEventLoop::exit);
if(timerId!=0) killTimer(timerId);
timerId = startTimer(msecs);
if(timerId) {
killTimer(timerId);
timerId = 0;
}
if(msecs > 0) startTimer(msecs);
auto res = loop->exec();
timerStop();
if(res==5) setSocketError(SocketTimeoutError);
stopTimer();
return res==0;
}

View File

@ -5,6 +5,7 @@
#include <QJsonDocument>
#include <QEventLoop>
#include <QTimerEvent>
#include <QCoreApplication>
extern const char *const FormBoundary;
@ -101,30 +102,45 @@ const char* socketErrKey(int value);
class TcpSocket : public QTcpSocket {
Q_OBJECT
public:
explicit TcpSocket(QObject *parent = nullptr) : QTcpSocket{parent} {};
using QTcpSocket::QTcpSocket;
~TcpSocket() {
if(timerId!=0) killTimer(timerId);
if(timerId) killTimer(timerId);
};
void abort() {
stopTimer();
QTcpSocket::abort();
}
void close() override {
stopTimer();
QTcpSocket::close();
}
bool waitForConnected(int msecs = 30000) override;
bool waitForDisconnected(int msecs = 30000) override;
bool waitForBytesWritten(int msecs = 30000) override;
bool waitForReadyRead(int msecs = 30000) override;
protected:
void timerEvent(QTimerEvent *e) override {
if(e->timerId()!=timerId) return;
killTimer(timerId);
timerId = 0;
emit timeout(5);
};
bool connAndExec(int msecs, QEventLoop *loop);
inline void timerStop() {
void startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer) {
if(timerId) killTimer(timerId);
timerId = QTcpSocket::startTimer(interval, timerType);
}
void stopTimer() {
if(timerId==0) return;
killTimer(timerId);
timerId = 0;
}
int timerId = 0;
signals:
void timeout(int);
int timerId{0};
protected:
void timerEvent(QTimerEvent *e) override {
if(e->timerId()!=timerId) QTcpSocket::timerEvent(e);
else {
abort();
setSocketError(SocketTimeoutError);
setErrorString(QCoreApplication::translate("QAbstractSocket", "Socket operation timed out"));
emit errorOccurred(QAbstractSocket::SocketTimeoutError);
}
};
bool connAndExec(int msecs, QEventLoop *loop);
};
#endif // QNETWORK_H

View File

@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
QApplication::setOrganizationDomain("www.ledok.cn");
QApplication::setApplicationName("LedOK Express");
QApplication a(argc, argv);
a.setStyle(QStyleFactory::create("Fusion"));
QApplication::setStyle(QStyleFactory::create("Fusion"));
QFile file(":/css.css");
if(file.exists() && file.open(QFile::ReadOnly)) {
a.setStyleSheet(css = file.readAll());

View File

@ -214,7 +214,7 @@ ProgPanel::ProgPanel(QWidget *parent) : QWidget(parent) {
connect(txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &)));
mProgTree = new LoQTreeWidget();
mProgTree->setIndentation(10);
mProgTree->setIndentation(6);
mProgTree->setSortingEnabled(true);
m_headerItem = new QTreeWidgetItem();
for(int i=1; i<ENUM_PROGRAMLISTHEADERITEM_END; i++) m_headerItem->setTextAlignment(i, Qt::AlignCenter);
@ -223,7 +223,7 @@ ProgPanel::ProgPanel(QWidget *parent) : QWidget(parent) {
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, Qt::DisplayRole, tr("Resolution"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, Qt::DisplayRole, tr("File Size"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, Qt::DisplayRole, tr("Last Modify"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, Qt::DisplayRole, tr("Usb playback"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, Qt::DisplayRole, tr("USB Update"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SEND, Qt::DisplayRole, tr("Publish"));
mProgTree->setHeaderItem(m_headerItem);
mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_CHECK, QHeaderView::Fixed);
@ -308,7 +308,7 @@ void ProgPanel::transUi() {
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, tr("Resolution"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, tr("File Size"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, tr("Last Modify"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, 0, tr("Usb playback"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, 0, tr("USB Update"));
m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SEND, 0, tr("Publish"));
bnNew->setText(tr("New"));
bnEdit->setText(tr("Edit"));
@ -317,7 +317,6 @@ void ProgPanel::transUi() {
bnExport->setText(tr("Export"));
bnSend->setText(tr("Send"));
btnPlay->setText(tr("Play")+"/"+tr("Stop"));
for(int i=0;i<m_pwPorgramItemList.count();i++) m_pwPorgramItemList.at(i)->refreshLable();
}
void ProgPanel::onEditClicked(bool){

View File

@ -74,7 +74,6 @@ QPushButton:hover {
});
m_bnExport = new QPushButton();
m_bnExport->setCursor(QCursor(Qt::PointingHandCursor));
m_bnExport->setToolTip(QObject::tr("ExportButtonTip"));
m_bnExport->setStyleSheet(R"rrr(
QPushButton {
border-radius: 4px;
@ -87,7 +86,7 @@ QPushButton:hover{background-color: #cccccc;}
mTree->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, m_bnExport);
QObject::connect(m_bnExport, &QPushButton::clicked, mTree, [this] {
QDialog dlg(mTree);
dlg.setWindowTitle(QObject::tr("Usb upgrade program"));
dlg.setWindowTitle(QObject::tr("USB Update Program"));
#ifdef Q_OS_WIN
dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
#endif
@ -140,7 +139,6 @@ QPushButton:hover{background-color: #cccccc;}
m_bnSend = new QPushButton();
m_bnSend->setCursor(QCursor(Qt::PointingHandCursor));
m_bnSend->setToolTip(QObject::tr("SendButtonTip"));
m_bnSend->setStyleSheet(R"rrr(
QPushButton{
border-radius: 4px;
@ -164,10 +162,6 @@ QPushButton:hover{background-color: #cccccc;}
dlg.exec();
});
}
void ProgItem::refreshLable() {
m_bnExport->setToolTip(QObject::tr("ExportButtonTip"));
m_bnSend->setToolTip(QObject::tr("SendButtonTip"));
}
void ProgItem::save() {
QDir dRoot(mProgDir);

View File

@ -18,7 +18,6 @@ public:
void save();
void del();
void refreshLable();
QString mName;
int mWidth;

View File

@ -1,14 +1,17 @@
#include "sendprogramdialog.h"
#include "cfg.h"
#include "wprogrampublishitem.h"
#include "sendprogthread.h"
#include "gutil/qgui.h"
#include "deviceitem.h"
#include "devicepanel.h"
#include "gutil/qnetwork.h"
#include "base/waitingdlg.h"
#include <QAction>
#include <QLineEdit>
#include <QHeaderView>
#include <QDialogButtonBox>
#include "deviceitem.h"
#include "devicepanel.h"
#include <QInputDialog>
#include <QMessageBox>
#include <QProgressBar>
SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialog(parent), mProgName(progName) {
#ifdef Q_OS_WIN
@ -18,6 +21,7 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo
resize(1024, 700);
auto vBox = new VBox(this);
vBox->setContentsMargins(6,0,6,9);
auto hBox = new HBox(vBox);
label = new QLabel(tr("success info"));
@ -25,96 +29,107 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo
hBox->addStretch();
auto pushButtonRefresh = new QPushButton(tr("Refresh"));
pushButtonRefresh->setProperty("ssType", "progManageTool");
connect(pushButtonRefresh, SIGNAL(clicked()),this, SLOT(onRefresh()));
hBox->addWidget(pushButtonRefresh);
auto btnRefresh = new QPushButton(tr("Refresh"));
btnRefresh->setProperty("ssType", "progManageTool");
connect(btnRefresh, &QPushButton::clicked, this, &SendProgramDialog::refresh);
hBox->addWidget(btnRefresh);
auto txtSearch = new QLineEdit();
auto txtSearch = new QLineEdit;
txtSearch->setFixedWidth(150);
txtSearch->setClearButtonEnabled(true);
txtSearch->setStyleSheet("QLineEdit{border: 2px solid #aaaaaa; padding: 2px;}");
txtSearch->setStyleSheet("QLineEdit{border: 2px solid #aaa; padding: 2px;}");
txtSearch->addAction(new QAction(QIcon(":/res/program/bnSearch.png"), QString()), QLineEdit::LeadingPosition);
connect(txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &)));
connect(txtSearch, &QLineEdit::textEdited, this, [=](const QString &text) {
auto cnt = table->rowCount();
for(int rr=0; rr<cnt; rr++) table->setRowHidden(rr, !(text.isEmpty() || table->text(rr, "id").contains(text) || table->text(rr, "ip").contains(text) || table->text(rr, "alias").contains(text) || table->text(rr, "size").contains(text)));
});
hBox->addWidget(txtSearch);
table = new Table{
{"id", "ID", 140},
{"online", tr("Online"), 40},
{"ip", "IP", 100},
{"size", tr("Screen Size"), 80},
{"alias", tr("Alias"), 120},
{"encrypt", tr("Security"), 40},
{"progress", tr("Progress"), 120},
{"remarks", tr("Remarks"), QHeaderView::Stretch}
};
table->setDefs();
auto colId = table->mFieldMap["id"];
table->sortItems(colId);
table->setSelectionMode(Table::NoSelection);
table->setStyle(new ViewItemStyle);
vBox->addWidget(table);
wDevicePublishList = new LoQTreeWidget();
wDevicePublishList->setProperty("ssType", "topList");
m_headerItem = new QTreeWidgetItem();
m_headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
for(int i=1; i<ENUM_DEVICE_PUBLISH_HEADE_END; i++) m_headerItem->setTextAlignment(i, Qt::AlignCenter);
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_CHECK, 0, "");
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 0, tr("Screen ID"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, 0, tr("Online"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 0, tr("Screen IP"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, 0, tr("Screen Size"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT,0,tr("Security"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, tr("Remark Name"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, 0, tr("Progress"));
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("Remarks"));
wDevicePublishList->setHeaderItem(m_headerItem);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_CHECK, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, QHeaderView::Fixed);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, QHeaderView::Interactive);
wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, QHeaderView::Stretch);
wDevicePublishList->header()->setStretchLastSection(false);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_CHECK, 52);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 130);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 130);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, 88);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, 50);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, 52);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 160);
wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, 120);
vBox->addWidget(wDevicePublishList);
fdCheckAll = new QCheckBox(table);
connect(fdCheckAll, &QCheckBox::stateChanged, this, [=](int state) {
if(state==Qt::PartiallyChecked) return;
int cnt = table->rowCount();
for(int i=0; i<cnt; i++) table->itemValid(i, colId)->setCheckState((Qt::CheckState) state);
});
connect(table, &Table::updGeos, this, [=] {
fdCheckAll->move(table->verticalHeader()->size().width() + 8, 2);
});
auto cellClicked = [=](int row, int column) {
if(column!=colId) return;
auto item = table->itemValid(row, colId);
auto state = item->checkState()==Qt::Checked ? Qt::Unchecked : Qt::Checked;
item->setCheckState(state);
int cnt = table->rowCount();
fdCheckAll->blockSignals(true);
for(int i=0; i<cnt; i++) if(table->itemValid(i, colId)->checkState()!=state) {
fdCheckAll->setCheckState(Qt::PartiallyChecked);
goto end;
}
fdCheckAll->setCheckState(state);
end:fdCheckAll->blockSignals(false);
};
connect(table, &Table::cellClicked, table, cellClicked);
connect(table, &Table::cellEntered, table, cellClicked);
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
btnBox->button(QDialogButtonBox::Ok)->setText(tr("Publish"));
connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(btnBox, &QDialogButtonBox::accepted, this, [this] {
connect(btnBox, &QDialogButtonBox::accepted, this, [=] {
if(mWaitCnt > 0) return;
int cnt = wDevicePublishList->topLevelItemCount();
int cnt = table->rowCount();
int sentCnt{0};
for(int i=0; i<cnt; i++) {
auto item = wDevicePublishList->topLevelItem(i);
if(item->checkState(0) != Qt::Checked) continue;
auto row = static_cast<wProgramPublishItem*>(item);
if(row->mIsSending) continue;
if(row->mLedCard.hasPassword && row->mLedCard.isLocked) {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("This screen is encrypted"));
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
auto fdId = table->itemValid(i, colId);
if(fdId->checkState()!=Qt::Checked) continue;
if(fdId->data(isSending).toBool()) continue;
auto btnUnlock = (QPushButton*) table->cellWidget(i, "encrypt");
auto fdRemarks = table->itemValid(i, "remarks");
if(btnUnlock && btnUnlock->property("isLocked").toBool()) {
fdRemarks->setText(tr("This screen is encrypted"));
fdRemarks->setForeground(Qt::red);
continue;
}
row->fdProgress->setValue(0);
auto fdProgress = (QProgressBar*) table->cellWidget(i, "progress");
fdProgress->setValue(0);
if(sentCnt>=5) {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, " 等待中 ...");
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::black);
fdRemarks->setText(" "+tr("Waiting")+" ...");
fdRemarks->setForeground(Qt::black);
mWaitCnt++;
continue;
}
row->mIsSending = true;
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "");
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard.ip, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = false;
fdId->setData(isSending, true);
fdRemarks->setText("");
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(i, "ip"), 3333);
connect(sendProg, &SendProgThread::emErr, fdProgress, [=](QString strTip) {
fdId->setData(isSending, false);
if(strTip=="OK") {
row->setCheckState(0, Qt::Unchecked);
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "OK");
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::darkGreen);
fdId->setCheckState(Qt::Unchecked);
fdRemarks->setText("OK");
fdRemarks->setForeground(Qt::darkGreen);
} else {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, strTip);
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
fdRemarks->setText(strTip);
fdRemarks->setForeground(Qt::red);
}
sendNext();
});
connect(sendProg, &SendProgThread::emProgress, row->fdProgress, &QProgressBar::setValue);
connect(sendProg, &SendProgThread::emProgress, fdProgress, &QProgressBar::setValue);
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
sendProg->start();
sentCnt++;
@ -122,147 +137,133 @@ SendProgramDialog::SendProgramDialog(QString progName, QWidget *parent) : QDialo
});
vBox->addWidget(btnBox);
onRefresh();
refresh();
auto timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &SendProgramDialog::onRefresh);
connect(timer, &QTimer::timeout, this, &SendProgramDialog::refresh);
timer->start(60000);
}
void SendProgramDialog::addRow(LedCard card) {
int cnt = table->rowCount();
for(int rr=0; rr<cnt; rr++) if(table->text(rr, "id") == card.id) {
updRow(rr, card);
return;
}
table->setSortingEnabled(false);
table->setRowCount(cnt+1);
auto item = table->setText(cnt, "id", card.id);
item->setCheckState(Qt::Unchecked);
item->setFlags(Qt::ItemIsEnabled);
auto fdOnline = new QLabel;
fdOnline->setAlignment(Qt::AlignCenter);
table->setCellWidget(cnt, "online", fdOnline);
auto fdProgress = new QProgressBar;
fdProgress->setAlignment(Qt::AlignCenter);
fdProgress->setStyleSheet("QProgressBar {margin-top: 6px; margin-bottom: 6px;}");
table->setCellWidget(cnt, "progress", fdProgress);
updRow(cnt, card);
table->setSortingEnabled(true);
}
void SendProgramDialog::updRow(int row, LedCard card) {
table->setText(row, "alias", card.alias);
table->setText(row, "ip", card.ip);
table->setText(row, "size", QString("%1 x %2").arg(card.mWidth).arg(card.mHeight))->setTextAlignment(Qt::AlignCenter);
((QLabel*) table->cellWidget(row, "online"))->setPixmap(QPixmap(card.isOnline ? ":/res/O_Online.png" : ":/res/O_Offline.png"));
if(! card.hasPassword) table->setCellWidget(row, "encrypt", 0);
else {
auto btnUnlock = (QPushButton*) table->cellWidget(row, "encrypt");
if(btnUnlock==0) {
btnUnlock = new QPushButton;
btnUnlock->setMaximumHeight(40);
btnUnlock->setProperty("isLocked", card.isLocked);
table->setCellWidget(row, "encrypt", btnUnlock);
connect(btnUnlock, &QPushButton::clicked, btnUnlock, [=] {
if(! btnUnlock->property("isLocked").toBool()) 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(60000).post(json);
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, btnUnlock, [=] {
QJsonDocument json;
QString 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();
btnUnlock->setProperty("isLocked", false);
btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
auto item = findItem(card.id);
if(item) {
item->mCard.isLocked = false;
item->btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
}
});
});
}
btnUnlock->setIcon(QIcon(card.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png")); //已验证显示绿色 没验证蓝色
}
}
void SendProgramDialog::closeEvent(QCloseEvent *) {
emit stopAllThd();
}
void SendProgramDialog::sendNext() {
if(mWaitCnt <= 0) return;
int cnt = wDevicePublishList->topLevelItemCount();
int cnt = table->rowCount();
for(int i=0; i<cnt; i++) {
auto item = wDevicePublishList->topLevelItem(i);
if(item->checkState(0) != Qt::Checked) continue;
auto row = static_cast<wProgramPublishItem*>(item);
if(row->mIsSending) continue;
if(row->mLedCard.hasPassword && row->mLedCard.isLocked) continue;
if(! row->data(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0).toString().startsWith(" ")) continue;
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "");
row->fdProgress->setValue(0);
row->mIsSending = true;
auto fdId = table->itemValid(i, "id");
if(fdId->checkState()!=Qt::Checked) continue;
if(fdId->data(isSending).toBool()) continue;
auto btnUnlock = (QPushButton*) table->cellWidget(i, "encrypt");
if(btnUnlock && btnUnlock->property("isLocked").toBool()) continue;
auto fdRemarks = table->itemValid(i, "remarks");
if(! fdRemarks->text().startsWith(" ")) continue;
fdRemarks->setText("");
auto fdProgress = (QProgressBar*) table->cellWidget(i, "progress");
fdProgress->setValue(0);
fdId->setData(isSending, true);
mWaitCnt--;
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", row->mLedCard.ip, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = false;
auto sendProg = new SendProgThread(programsDir()+"/"+mProgName+"_tmp", table->text(i, "ip"), 3333);
connect(sendProg, &SendProgThread::emErr, fdProgress, [=](QString strTip) {
fdId->setData(isSending, false);
if(strTip=="OK") {
row->setCheckState(0, Qt::Unchecked);
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "OK");
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::darkGreen);
fdId->setCheckState(Qt::Unchecked);
fdRemarks->setText("OK");
fdRemarks->setForeground(Qt::darkGreen);
} else {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, strTip);
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
fdRemarks->setText(strTip);
fdRemarks->setForeground(Qt::red);
}
sendNext();
});
connect(sendProg, &SendProgThread::emProgress, row->fdProgress, &QProgressBar::setValue);
connect(sendProg, &SendProgThread::emProgress, fdProgress, &QProgressBar::setValue);
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
sendProg->start();
return;
}
}
void SendProgramDialog::onRefresh() {
void SendProgramDialog::refresh() {
int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; i++) onAddLedCard(static_cast<DeviceItem*>(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard);
label->setText(tr("All")+":"+QString::number(cnt));
}
void SendProgramDialog::onAddLedCard(LedCard p) {
int iExistFlg=0;
int cnt = wDevicePublishList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->mLedCard.id;
if(strTempCardId == p.id) {
iExistFlg=1;
static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->SetItemParam(p);
break;
}
}
if(iExistFlg==0) new wProgramPublishItem(p, wDevicePublishList, mProgName, programsDir());
}
void SendProgramDialog::FilterProgram(const QString &strtemp)
{
if (strtemp.isEmpty()) //显示全部
{
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false);
}
}
else
{
QList<QTreeWidgetItem*> resultList = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID); //搜索结果
if (resultList.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
if (resultList.contains(topItem))
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
QList<QTreeWidgetItem*> resultList6 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME); //搜索结果
if (resultList6.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
if (resultList6.contains(topItem))
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
//QMessageBox::warning(this, "Export", "FilterProgram");
QList<QTreeWidgetItem*> resultList1 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE); //搜索结果
if (resultList1.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
if (resultList1.contains(topItem))
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
QList<QTreeWidgetItem*> resultList2 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP); //搜索结果
if (resultList2.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
if (resultList2.contains(topItem))
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
}
}
}
}
for(int i=0; i<cnt; i++) addRow(static_cast<DeviceItem*>(gDevicePanel->mDeviceTable->topLevelItem(i))->mCard);
label->setText(tr("All")+": "+QString::number(cnt));
}

View File

@ -1,33 +1,51 @@
#ifndef SENDPROGRAMDIALOG_H
#define SENDPROGRAMDIALOG_H
#include <QDialog>
#include <QLabel>
#include "base/loqtreewidget.h"
#include "globaldefine.h"
#include "gutil/qgui.h"
#include <QDialog>
#include <QCheckBox>
#include <QProxyStyle>
#include <QApplication>
class SendProgramDialog : public QDialog {
Q_OBJECT
public:
explicit SendProgramDialog(QString, QWidget *parent = nullptr);
protected:
void closeEvent(QCloseEvent *event) override;
signals:
void stopAllThd();
protected slots:
void onRefresh();
void FilterProgram(const QString &strtemp);
private:
void refresh();
protected:
void closeEvent(QCloseEvent *event) override;
void sendNext();
void onAddLedCard(LedCard);
void addRow(LedCard);
void updRow(int, LedCard);
LoQTreeWidget *wDevicePublishList;
Table *table;
QCheckBox *fdCheckAll;
int mWaitCnt{0};
QLabel *label;
QTreeWidgetItem *m_headerItem = nullptr;
QString mProgName;
QString m_strUrl;
enum {isSending = Qt::UserRole};
};
class ViewItemStyle : public QProxyStyle {
public:
ViewItemStyle() : QProxyStyle(QApplication::style()) {}
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override {
auto res = QProxyStyle::subElementRect(element, option, widget);
if(option && option->type==QStyleOption::SO_ViewItem && ((QStyleOptionViewItem*)option)->features & QStyleOptionViewItem::HasCheckIndicator && ((QStyleOptionViewItem*)option)->index.internalId()==0) res.setLeft(res.x() + 6);
return res;
}
int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override {
auto res = QProxyStyle::pixelMetric(metric, option, widget);
if(metric==PM_FocusFrameHMargin && option && option->type==QStyleOption::SO_ViewItem && ((QStyleOptionViewItem*)option)->features & QStyleOptionViewItem::HasCheckIndicator) res += 4;
return res;
}
};
#endif // SENDPROGRAMDIALOG_H

View File

@ -22,7 +22,7 @@ void SendProgThread::run() {
TcpSocket tcp;
tcp.connectToHost(ip, port);
if(! tcp.waitForConnected()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForConnected");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForConnected");
tcp.close();
return;
}
@ -45,18 +45,18 @@ void SendProgThread::run() {
auto requ = QJsonDocument(req).toJson(QJsonDocument::Compact);
auto resNum = tcp.write(requ);
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'consult'. size"+QString::number(requ.size()));
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'consult'. size"+QString::number(requ.size()));
tcp.close();
return;
}
if(! tcp.waitForReadyRead()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForRead 'consult'. size"+QString::number(requ.size()));
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForRead 'consult'. size"+QString::number(requ.size()));
tcp.close();
return;
}
auto resp = tcp.readAll();
if(resp.isEmpty()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when read 'consult'. size"+QString::number(requ.size()));
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when read 'consult'. size"+QString::number(requ.size()));
tcp.close();
return;
}
@ -68,13 +68,13 @@ void SendProgThread::run() {
QJsonDocument res = QJsonDocument::fromJson(resp, &parseErr);
for(int i=2; parseErr.error == QJsonParseError::UnterminatedString && i < 10; i++) {
if(! tcp.waitForReadyRead()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForRead 'consult' "+QString::number(i));
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForRead 'consult' "+QString::number(i));
tcp.close();
return;
}
auto resp2 = tcp.readAll();
if(resp2.isEmpty()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when read 'consult' "+QString::number(i));
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when read 'consult' "+QString::number(i));
tcp.close();
return;
}
@ -111,7 +111,7 @@ void SendProgThread::run() {
req.insert("zVer","xixun1");
auto resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'proStart'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'proStart'");
tcp.close();
return;
}
@ -132,7 +132,7 @@ void SendProgThread::run() {
req.insert("zVer","xixun1");
auto resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'fileStart'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'fileStart'");
tcp.close();
return;
}
@ -157,13 +157,13 @@ void SendProgThread::run() {
};
resNum = tcp.write(readed);
if(resNum == -1) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write file: "+file->fileName());
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write file: "+file->fileName());
tcp.close();
file->close();
return;
}
if(! tcp.waitForBytesWritten(60000)) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForWritten file: "+file->fileName());
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForWritten file: "+file->fileName());
tcp.close();
file->close();
return;
@ -188,7 +188,7 @@ void SendProgThread::run() {
req.insert("zVer", "xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'fileEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'fileEnd'");
tcp.close();
return;
}
@ -204,18 +204,18 @@ void SendProgThread::run() {
req.insert("zVer","xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when write 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'proEnd'");
tcp.close();
return;
};
if(! tcp.waitForReadyRead()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when waitForRead 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForRead 'proEnd'");
tcp.close();
return;
}
auto resp = tcp.readAll();
if(resp.isEmpty()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") when read 'proEnd'");
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when read 'proEnd'");
tcp.close();
return;
}

View File

@ -1,89 +0,0 @@
#include "wprogrampublishitem.h"
#include "gutil/qgui.h"
#include "base/waitingdlg.h"
#include "gutil/qnetwork.h"
#include "deviceitem.h"
#include <QMessageBox>
#include <QJsonObject>
#include <QJsonDocument>
#include <QProgressBar>
#include "globaldefine.h"
#include <QInputDialog>
#include <QMetaEnum>
wProgramPublishItem::wProgramPublishItem(LedCard pLedCard, LoQTreeWidget *parent, QString strProgramName, QString strProgramPath) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
m_strProgramName = strProgramName;
m_strProgramPath = strProgramPath;
mLedCard = pLedCard;
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
setCheckState(0, Qt::Unchecked);
m_parent->addTopLevelItem(this);
m_ImageOnline = new QLabel();
m_ImageOnline->setAlignment(Qt::AlignCenter);
m_parent->setItemWidget(this, ENUM_DEVICE_PUBLISH_HEADE_ONLINE, m_ImageOnline);
for(int i=1; i<ENUM_DEVICE_PUBLISH_HEADE_REMARKS; i++) setTextAlignment(i, Qt::AlignCenter);
fdProgress = new QProgressBar();
fdProgress->setStyleSheet("margin-top: 8px; margin-bottom: 8px;");
m_parent->setItemWidget(this, ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, fdProgress);
fdProgress->setAlignment(Qt::AlignCenter);
btnUnlock = new QPushButton;
btnUnlock->setMaximumHeight(40);
auto wgt = new QWidget;
auto vBox = new VBox(wgt);
vBox->setContentsMargins(0,0,0,0);
vBox->addWidget(btnUnlock);
m_parent->setItemWidget(this, ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, wgt);
connect(btnUnlock, &QPushButton::clicked, this, [this] {
if(! mLedCard.isLocked) return;
bool ok;
auto pwd = QInputDialog::getText(treeWidget(), 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(treeWidget(), tr("VerifyPassword")+" ...");
waitingDlg->show();
auto reply = NetReq("http://"+mLedCard.ip+":2016/settings").timeout(60000).post(json);
waitingDlg->connAbort(reply);
connect(reply, &QNetworkReply::finished, this, [=] {
QJsonDocument json;
QString err = checkReplyForJson(reply, &json);
if(! err.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(m_parent, QObject::tr("Error"), err);
return;
}
if(! json["result"].toBool()) {
waitingDlg->close();
QMessageBox::warning(treeWidget(), tr("Tip Info"), tr("password is wrong"));
return;
}
waitingDlg->success();
mLedCard.isLocked = false;
btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
auto item = findItem(mLedCard.id);
if(item) {
item->mCard.isLocked = false;
item->btnUnlock->setIcon(QIcon(":/res/UnLock.png"));
}
});
});
SetItemParam(mLedCard);
}
void wProgramPublishItem::SetItemParam(LedCard card) {
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 0, card.id);
setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, card.alias);
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 0, card.ip);
setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE, 0, QString("%1 x %2").arg(card.mWidth).arg(card.mHeight));
m_ImageOnline->setPixmap(QPixmap(mLedCard.isOnline ? ":/res/O_Online.png" : ":/res/O_Offline.png"));
if(! card.hasPassword) btnUnlock->hide();
else {
if(! btnUnlock->isVisible()) btnUnlock->show();
btnUnlock->setIcon(QIcon(card.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png")); //如果已经验证通过密码显示绿色图标 没有验证显示蓝色锁图标
}
}

View File

@ -1,45 +0,0 @@
#ifndef WPROGRAMPUBLISHITEM_H
#define WPROGRAMPUBLISHITEM_H
#include <QDateTime>
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel>
#include <QProgressBar>
#include <QPushButton>
#include "base/loqtreewidget.h"
#include "globaldefine.h"
class wProgramPublishItem : public QObject, public QTreeWidgetItem {
Q_OBJECT
public:
explicit wProgramPublishItem(LedCard pLedCard, LoQTreeWidget *parent = nullptr, QString strProgramName="",QString strProgramPath="");
void SetItemParam(LedCard p);
LedCard mLedCard;
QProgressBar *fdProgress{nullptr};
bool mIsSending{false};
private:
QString m_strProgramName="";
QString m_strProgramPath="";
QLabel *m_ImageOnline=nullptr;
LoQTreeWidget *m_parent = nullptr;
QPushButton *btnUnlock = nullptr;//
};
enum ENUM_DEVICE_PUBLISH_HEADERITEM {
ENUM_DEVICE_PUBLISH_HEADE_CHECK=0,
ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID,
ENUM_DEVICE_PUBLISH_HEADE_ONLINE,
ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP,
ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE,
ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT,
ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME,
ENUM_DEVICE_PUBLISH_HEADE_PROGRESS,
ENUM_DEVICE_PUBLISH_HEADE_REMARKS,
ENUM_DEVICE_PUBLISH_HEADE_END,
};
#endif // WPROGRAMPUBLISHITEM_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff