qt/LedOK/wProgramManager/sendprogramdialog.cpp

274 lines
14 KiB
C++
Raw Normal View History

2022-01-04 18:11:48 +08:00
#include "sendprogramdialog.h"
2022-09-28 18:21:57 +08:00
#include "tools.h"
2022-01-04 18:11:48 +08:00
#include <QAction>
2022-08-25 18:37:24 +08:00
#include <QLineEdit>
#include <QHeaderView>
#include <QVBoxLayout>
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
SendProgramDialog::SendProgramDialog(QWidget *parent, QString strProgramName, QString strProgramPath) : QWidget(parent, Qt::Window) {
setWindowModality(Qt::ApplicationModal);
setAttribute(Qt::WA_DeleteOnClose);
resize(1024, 700);
setWindowTitle(tr("Publish")+" "+strProgramName);
auto vBox = new QVBoxLayout(this);
auto hBox = new QHBoxLayout();
label = new QLabel(tr("success info"));
hBox->addWidget(label);
hBox->addStretch();
auto pushButtonRefresh = new QPushButton(tr("Refresh"));
pushButtonRefresh->setProperty("ssType", "progManageTool");
connect(pushButtonRefresh, SIGNAL(clicked()),this, SLOT(onRefresh()));
hBox->addWidget(pushButtonRefresh);
auto txtSearch = new QLineEdit();
txtSearch->setFixedWidth(150);
txtSearch->setClearButtonEnabled(true);
txtSearch->setStyleSheet("QLineEdit{border: 2px solid #aaaaaa; padding: 2px;}");
txtSearch->addAction(new QAction(QIcon(":/res/ProgramManager/bnSearch.png"), QString()), QLineEdit::LeadingPosition);
connect(txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &)));
hBox->addWidget(txtSearch);
vBox->addLayout(hBox);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
wDevicePublishList = new LoQTreeWidget();
wDevicePublishList->setProperty("ssType", "topList");
2022-01-04 18:11:48 +08:00
m_headerItem = new QTreeWidgetItem();
m_headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
2022-08-25 18:37:24 +08:00
for(int i=1; i<ENUM_DEVICE_PUBLISH_HEADE_END; i++) m_headerItem->setTextAlignment(i, Qt::AlignCenter);
2022-01-04 18:11:48 +08:00
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_PROGRESS, 0, tr("Progress"));
2022-08-25 18:37:24 +08:00
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, tr("Remark Name"));
2022-01-04 18:11:48 +08:00
m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("Remarks"));
2022-08-25 18:37:24 +08:00
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);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
hBox = new QHBoxLayout();
hBox->addStretch();
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto btnPublish = new QPushButton(tr("Publish"));
connect(btnPublish, &QPushButton::clicked, this, [this] {
if(mWaitCnt > 0) return;
int cnt = wDevicePublishList->topLevelItemCount();
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->bPassword && row->mLedCard->m_bLockStatus) {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, tr("This screen is encrypted"));
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
continue;
}
row->fdProgress->setValue(0);
if(sentCnt>=5) {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, " 等待中 ...");
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::black);
mWaitCnt++;
continue;
}
row->mIsSending = true;
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, "");
auto sendProg = new SendProgThread(m_strProgramPath+"/"+m_strProgramName+"_tmp", row->mLedCard->m_strCardIp, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = 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);
} else {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, strTip);
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
}
sendNext();
});
connect(sendProg, &SendProgThread::emProgress, row->fdProgress, &QProgressBar::setValue);
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
sendProg->start();
sentCnt++;
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
});
btnPublish->setProperty("ssType", "progManageTool");
hBox->addWidget(btnPublish);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto btnCancel = new QPushButton(tr("Cancel"));
connect(btnCancel, &QPushButton::clicked, this, &QWidget::close);
btnCancel->setProperty("ssType", "progManageTool");
hBox->addWidget(btnCancel);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
vBox->addLayout(hBox);
m_strProgramName = strProgramName;
m_strProgramPath = strProgramPath;
onRefresh();
auto timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &SendProgramDialog::onRefresh);
timer->start(60000);
2022-01-04 18:11:48 +08:00
}
2022-09-26 18:10:47 +08:00
void SendProgramDialog::closeEvent(QCloseEvent *) {
2022-08-25 18:37:24 +08:00
emit stopAllThd();
}
void SendProgramDialog::sendNext() {
if(mWaitCnt <= 0) return;
int cnt = wDevicePublishList->topLevelItemCount();
2022-01-04 18:11:48 +08:00
for(int i=0; i<cnt; i++) {
2022-08-25 18:37:24 +08:00
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->bPassword && row->mLedCard->m_bLockStatus) 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;
mWaitCnt--;
auto sendProg = new SendProgThread(m_strProgramPath+"/"+m_strProgramName+"_tmp", row->mLedCard->m_strCardIp, 3333);
connect(sendProg, &SendProgThread::emErr, row, [this, row](QString strTip) {
row->mIsSending = 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);
} else {
row->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 0, strTip);
row->setForeground(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, Qt::red);
}
sendNext();
});
connect(sendProg, &SendProgThread::emProgress, row->fdProgress, &QProgressBar::setValue);
connect(this, &SendProgramDialog::stopAllThd, sendProg, &SendProgThread::stop);
sendProg->start();
return;
2022-01-04 18:11:48 +08:00
}
}
2022-08-25 18:37:24 +08:00
void SendProgramDialog::onRefresh() {
2022-09-28 18:21:57 +08:00
int iCount = gDevicePanel->LedCardList.count();
for(int i=0; i<iCount; i++) onAddLedCard(gDevicePanel->LedCardList.at(i));
2022-08-25 18:37:24 +08:00
label->setText(tr("All")+":"+QString::number(iCount));
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
void SendProgramDialog::onAddLedCard(LedCard *p) {
2022-01-04 18:11:48 +08:00
int iExistFlg=0;
2022-08-25 18:37:24 +08:00
int cnt = wDevicePublishList->topLevelItemCount();
2022-01-04 18:11:48 +08:00
for(int i=0; i<cnt; i++) {
2022-08-25 18:37:24 +08:00
QString strTempCardId=static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->mLedCard->m_strCardId;
2022-01-04 18:11:48 +08:00
if(strTempCardId == p->m_strCardId) {
iExistFlg=1;
2022-08-25 18:37:24 +08:00
static_cast<wProgramPublishItem*>(wDevicePublishList->topLevelItem(i))->SetItemParam(p);
2022-01-04 18:11:48 +08:00
break;
}
}
2022-08-25 18:37:24 +08:00
if(iExistFlg==0) new wProgramPublishItem(p, wDevicePublishList, this, m_strProgramName, m_strProgramPath);
2022-01-04 18:11:48 +08:00
}
void SendProgramDialog::FilterProgram(const QString &strtemp)
{
if (strtemp.isEmpty()) //显示全部
{
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false);
2022-01-04 18:11:48 +08:00
}
}
else
{
2022-08-25 18:37:24 +08:00
QList<QTreeWidgetItem*> resultList = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID); //搜索结果
2022-01-04 18:11:48 +08:00
if (resultList.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
2022-01-04 18:11:48 +08:00
if (resultList.contains(topItem))
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
2022-01-04 18:11:48 +08:00
else
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
2022-01-04 18:11:48 +08:00
}
}
else {
2022-08-25 18:37:24 +08:00
QList<QTreeWidgetItem*> resultList6 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME); //搜索结果
2022-01-04 18:11:48 +08:00
if (resultList6.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
2022-01-04 18:11:48 +08:00
if (resultList6.contains(topItem))
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
2022-01-04 18:11:48 +08:00
else
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
2022-01-04 18:11:48 +08:00
}
}
else {
//QMessageBox::warning(this, "Export", "FilterProgram");
2022-08-25 18:37:24 +08:00
QList<QTreeWidgetItem*> resultList1 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_SIZE); //搜索结果
2022-01-04 18:11:48 +08:00
if (resultList1.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
2022-01-04 18:11:48 +08:00
if (resultList1.contains(topItem))
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
2022-01-04 18:11:48 +08:00
else
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
2022-01-04 18:11:48 +08:00
}
}
else {
2022-08-25 18:37:24 +08:00
QList<QTreeWidgetItem*> resultList2 = wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP); //搜索结果
2022-01-04 18:11:48 +08:00
if (resultList2.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
2022-01-04 18:11:48 +08:00
if (resultList2.contains(topItem))
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),false); //显示匹配的结果
2022-01-04 18:11:48 +08:00
else
2022-08-25 18:37:24 +08:00
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
2022-01-04 18:11:48 +08:00
}
}
else {
2022-08-25 18:37:24 +08:00
for (int i = 0; i< wDevicePublishList->topLevelItemCount(); ++i)
2022-01-04 18:11:48 +08:00
{
2022-08-25 18:37:24 +08:00
QTreeWidgetItem* topItem = wDevicePublishList->topLevelItem(i);
wDevicePublishList->setRowHidden(i,wDevicePublishList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
2022-01-04 18:11:48 +08:00
}
}
}
}
}
}
}