599 lines
25 KiB
C++
599 lines
25 KiB
C++
#include "devicepanel.h"
|
||
#include "globaldefine.h"
|
||
#include "gutil/qgui.h"
|
||
#include "gutil/qnetwork.h"
|
||
#include "deviceitem.h"
|
||
#include "device/ctrlbrightpanel.h"
|
||
#include "device/ctrlpowerpanel.h"
|
||
#include "device/ctrlnetworkpanel.h"
|
||
#include "device/ctrlverifyclockpanel.h"
|
||
#include "device/ctrlhdmipanel.h"
|
||
#include "device/ctrlvolumepanel.h"
|
||
#include "device/ctrlpwdpanel.h"
|
||
#include "device/ctrladvancedpanel.h"
|
||
#include "device/ctrltestpanel.h"
|
||
#include <QAction>
|
||
#include <QNetworkDatagram>
|
||
#include <QNetworkInterface>
|
||
#include <QMessageBox>
|
||
#include <QJsonArray>
|
||
#include <QStyledItemDelegate>
|
||
#include <QToolButton>
|
||
#include <QPainter>
|
||
|
||
DevicePanel *gDevicePanel;
|
||
QTextEdit *gFdResInfo;
|
||
|
||
void setCard(LedCard &card, const QString &addr, const QJsonDocument &json) {
|
||
if(! addr.isEmpty()) card.ip = addr;
|
||
else {
|
||
card.ip = json["newIp"].toString();
|
||
if(card.ip.isEmpty()) card.ip = json["ip"].toString();
|
||
}
|
||
if(card.mWidth==0) card.mWidth = json["width"].toInt();
|
||
if(card.mHeight==0) card.mHeight = json["height"].toInt();
|
||
card.androidVersion = json["androidVersion"].toString();
|
||
}
|
||
DevicePanel::DevicePanel(QSettings &settings, QWidget *parent) : QWidget(parent) {
|
||
gDevicePanel = this;
|
||
setAutoFillBackground(true);
|
||
QPalette pal;
|
||
pal.setBrush(QPalette::Window, QColor(0xeeeeee));
|
||
setPalette(pal);
|
||
|
||
auto vBox = new VBox(this);
|
||
vBox->setContentsMargins(0, 0, 0, 0);
|
||
vBox->setSpacing(0);
|
||
|
||
auto hBox = new HBox(vBox);
|
||
hBox->setContentsMargins(6, 2, 6, 2);
|
||
hBox->setSpacing(2);
|
||
|
||
auto label = new QLabel();
|
||
label->setPixmap({":/res/DeviceNum_All.png"});
|
||
label->setScaledContents(true);
|
||
label->setFixedSize(33, 24);
|
||
hBox->addWidget(label);
|
||
|
||
label_3 = new QLabel(tr("All"));
|
||
hBox->addWidget(label_3);
|
||
|
||
nDeviceNum = new QLabel;
|
||
nDeviceNum->setFixedSize(40, 20);
|
||
hBox->addWidget(nDeviceNum);
|
||
|
||
auto fdSearch = new QLineEdit;
|
||
fdSearch->setClearButtonEnabled(true);
|
||
fdSearch->setFixedSize(220, 30);
|
||
fdSearch->addAction(new QAction(QIcon(":/res/program/bnSearch.png"), QString()), QLineEdit::LeadingPosition);
|
||
fdSearch->setStyleSheet("border: 1px solid #aaaaaa;");
|
||
connect(fdSearch, &QLineEdit::textChanged, this, [=](const QString &text) {
|
||
auto cnt = mDeviceTable->topLevelItemCount();
|
||
int sel = 0, unsel = 0;
|
||
for(int i=0; i<cnt; i++) {
|
||
auto item = mDeviceTable->item(i);
|
||
item->setHidden(! (text.isEmpty() || item->text("id").contains(text) || item->text("alias").contains(text) || item->text("ip").contains(text)));
|
||
if(item->isHidden()) item->setCheckState("check", Qt::Unchecked);
|
||
else (item->checkState("check")==Qt::Checked ? sel : unsel)++;
|
||
mDeviceTable->fdCheckAll->blockSignals(true);
|
||
mDeviceTable->fdCheckAll->setCheckState(sel==0 ? Qt::Unchecked : unsel ? Qt::PartiallyChecked : Qt::Checked);
|
||
mDeviceTable->fdCheckAll->blockSignals(false);
|
||
emit mDeviceTable->selChanged();
|
||
}
|
||
});
|
||
hBox->addWidget(fdSearch);
|
||
|
||
hBox->addSpacing(10);
|
||
|
||
fdCardNumInfo = new QLabel(tr("Current Screen")+": "+tr("none"));
|
||
fdCardNumInfo->setStyleSheet("QLabel{color: #15f;}");
|
||
fdCardNumInfo->hide();
|
||
hBox->addWidget(fdCardNumInfo);
|
||
|
||
hBox->addStretch();
|
||
|
||
auto areaFlash = new QWidget();
|
||
areaFlash->setFixedSize(100, 34);
|
||
|
||
bnSpecifyIP = new QComboBox(areaFlash);
|
||
bnSpecifyIP->addItem(tr("Specify IP"));
|
||
bnSpecifyIP->setGeometry(0, 0, areaFlash->width(), areaFlash->height());
|
||
bnSpecifyIP->setItemDelegate(new QStyledItemDelegate);
|
||
connect(bnSpecifyIP, &QComboBox::textActivated, this, [this] {
|
||
mUdpTimer.stop();
|
||
specifyIPDlg->exec();
|
||
mUdpTimer.start(30000);
|
||
});
|
||
bnSpecifyIP->setStyleSheet(R"rrr(
|
||
QComboBox {
|
||
border: none;
|
||
border-radius: 5px;
|
||
background-color: #19c;
|
||
}
|
||
QComboBox:hover {background-color: #08b;}
|
||
QComboBox::drop-down {width: 25px;}
|
||
QComboBox::down-arrow {image: url(:/res/FlashArrow.png);}
|
||
QComboBox QAbstractItemView::item {
|
||
height: 28px;
|
||
color: #fff;
|
||
}
|
||
QComboBox QAbstractItemView::item:selected {background-color: #09c;}
|
||
)rrr");
|
||
|
||
btnRefresh = new QPushButton(tr("Refresh"), areaFlash);
|
||
btnRefresh->setGeometry(0, 0, 75, areaFlash->height());
|
||
connect(btnRefresh, &QPushButton::clicked, this, [this] {
|
||
mDeviceTable->clear();
|
||
mDeviceTable->fdCheckAll->setCheckState(Qt::Unchecked);
|
||
nDeviceNum->setText("0");
|
||
sendGetInfo();
|
||
});
|
||
btnRefresh->setStyleSheet(R"rrr(
|
||
QPushButton {
|
||
border-radius: 5px;
|
||
background-color: #19c;
|
||
color: #fff;
|
||
}
|
||
QPushButton:hover {background-color: #08b;}
|
||
)rrr");
|
||
|
||
hBox->addWidget(areaFlash);
|
||
|
||
mHBox = new HBox(vBox);
|
||
|
||
auto table = new LoQTreeWidget;
|
||
table->addCol("#", "", 20);
|
||
table->addCol("check", "", 28).margin(2);
|
||
table->addCol("id", "ID", 130, QHeaderView::Stretch).alignC();
|
||
table->addCol("online", "", 40);
|
||
table->addCol("ip", "IP", 130, QHeaderView::Stretch).alignC();
|
||
table->addCol("screenSize", "", 100, QHeaderView::Stretch).alignC();
|
||
table->addCol("alias", "", 130, QHeaderView::Stretch).alignC();
|
||
table->addCol("brightness", "", 80).alignC();
|
||
table->addCol("power", "", 80).alignC();
|
||
table->addCol("password", "", 72);
|
||
table->addCol("info", "", 72);
|
||
table->addCol("screenshot", "", 72);
|
||
table->setDefs()->setHeaderAlignC();
|
||
table->addFd();
|
||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||
table->minRowHeight = 36;
|
||
table->setSortingEnabled(true);
|
||
|
||
table->hideColumn("check");
|
||
table->fdCheckAll->hide();
|
||
table->sortItems("id", Qt::AscendingOrder);
|
||
connect(table, &LoQTreeWidget::selChanged, table, [=] {
|
||
gSelCards.clear();
|
||
int cnt = table->topLevelItemCount();
|
||
for(int i=0; i<cnt; i++) if(table->item(i)->checkState("check") == Qt::Checked) gSelCards.append(static_cast<DeviceItem*>(table->topLevelItem(i))->mCard);
|
||
emit sigSelectedDeviceList();
|
||
});
|
||
mHBox->addWidget(mDeviceTable = table);
|
||
|
||
connect(&mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo);
|
||
connect(&mUdpSocket, &QUdpSocket::readyRead, this, [this] {
|
||
while(mUdpSocket.hasPendingDatagrams()) {
|
||
auto gram = mUdpSocket.receiveDatagram();
|
||
auto data = gram.data();
|
||
if(data.isEmpty()) continue;
|
||
auto senderAddress = gram.senderAddress();
|
||
bool ok = true;
|
||
if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok));
|
||
auto addr = ok ? senderAddress.toString() : "";
|
||
DeviceItem *item;
|
||
if(data.startsWith("{\"")) {
|
||
QJsonParseError error;
|
||
QJsonDocument json = QJsonDocument::fromJson(gram.data(), &error);
|
||
if(error.error != QJsonParseError::NoError) {
|
||
qDebug()<<"DeviceItem OnProHttpResponse 解析json文件错误!";
|
||
continue;
|
||
}
|
||
auto cardId = json["cardId"].toString();
|
||
int cnt = mDeviceTable->topLevelItemCount();
|
||
for(int i=0; i<cnt; i++) if((item = (DeviceItem *)mDeviceTable->topLevelItem(i))->mCard.id==cardId) {
|
||
item->mCard.isOnline = true;
|
||
setCard(item->mCard, addr, json);
|
||
item->init();
|
||
goto end;
|
||
}
|
||
item = new DeviceItem(mDeviceTable);
|
||
item->mCard.id = cardId;
|
||
setCard(item->mCard, addr, json);
|
||
} else {
|
||
auto bytes = gram.data();
|
||
auto packet = (UDPPacket *)bytes.data();
|
||
int cnt = mDeviceTable->topLevelItemCount();
|
||
for(int i=0; i<cnt; i++) if((item = (DeviceItem *)mDeviceTable->topLevelItem(i))->mCard.id==packet->serialCode) {
|
||
item->mCard.isOnline = true;
|
||
item->mCard.ip = addr;
|
||
item->init();
|
||
goto end;
|
||
}
|
||
item = new DeviceItem(mDeviceTable);
|
||
item->mCard.id = packet->serialCode;
|
||
item->mCard.ip = addr;
|
||
}
|
||
item->init();
|
||
{
|
||
auto btn = new QPushButton;
|
||
btn->setCursor(QCursor(Qt::PointingHandCursor));
|
||
btn->setIcon(QIcon(":/res/info.png"));
|
||
btn->setIconSize({26, 26});
|
||
item->setCellWidget("info", btn);
|
||
connect(btn, &QPushButton::clicked, btn, [=] {
|
||
QString msgpre;
|
||
msgpre.append(tr("Current Brightness")).append(": ").append(QString::number(item->mCard.bright)).append("%").append("\n");
|
||
msgpre.append(tr("Brightness Level")).append(": ").append(QString::number(item->mCard.BrightnessLevel)).append("\n");
|
||
msgpre.append(tr("Android OS Resolution")).append(": ").append(item->mCard.ScreenResolution).append("\n");
|
||
msgpre.append(tr("Android Version")).append(": ").append(item->mCard.androidVersion).append("\n");
|
||
msgpre.append(tr("FPGA Version")).append(": ").append(item->mCard.HardVersion).append("\n");
|
||
msgpre.append(tr("Firmware Version")).append(": ").append(item->mCard.FirmwareVersion).append("\n");
|
||
msgpre.append("IMEI: ").append(item->mCard.IMEI).append("\n");
|
||
QMessageBox msgBox(QMessageBox::Information, item->mCard.id+" "+tr("Detail Info"), msgpre + tr("Player Version")+": "+tr("Getting")+" ...");
|
||
QJsonObject json;
|
||
json.insert("_id", "CheckSoftVersions");
|
||
json.insert("_type", "CheckSoftVersions");
|
||
auto card = item->mCard;
|
||
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, &msgBox) [=, &msgBox] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) {
|
||
msgBox.setText(msgpre + tr("Player Version")+": "+err);
|
||
return;
|
||
}
|
||
auto apps = json["apps"].toArray();
|
||
foreach(QJsonValue value, apps) {
|
||
QJsonObject app = value.toObject();
|
||
if(app["packageName"].toString().contains("xixunplayer")) {
|
||
msgBox.setText(msgpre + tr("Player Version")+": "+app["versionName"].toString());
|
||
return;
|
||
}
|
||
}
|
||
msgBox.setText(msgpre + tr("Player Version")+":");
|
||
});
|
||
msgBox.exec();
|
||
});
|
||
}
|
||
init(item);
|
||
nDeviceNum->setText(QString::number(mDeviceTable->topLevelItemCount()));
|
||
{
|
||
QJsonObject json;
|
||
json.insert("_id", "SyncTime");
|
||
json.insert("_type", "SyncTime");
|
||
json.insert("time", QDateTime::currentDateTime().toMSecsSinceEpoch());
|
||
auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(60000).post(json);
|
||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||
}
|
||
end:;
|
||
}
|
||
});
|
||
|
||
specifyIPDlg = new QDialog(this);
|
||
specifyIPDlg->setWindowTitle(tr("Specify IP"));
|
||
|
||
vBox = new VBox(specifyIPDlg);
|
||
vBox->addStretch();
|
||
|
||
label = new QLabel(tr("Specify IP list"));
|
||
label->setAlignment(Qt::AlignCenter);
|
||
vBox->addWidget(label);
|
||
|
||
fdIP = new QTextEdit;
|
||
auto ipstr = settings.value("SpecifyIP").toString();
|
||
if(! ipstr.isEmpty()) fdIP->setText(ipstr);
|
||
fdIP->setPlaceholderText("192.168.1.1\n192.168.1.2\n ...");
|
||
fdIP->setMinimumWidth(160);
|
||
vBox->addWidget(fdIP);
|
||
|
||
hBox = new HBox(vBox);
|
||
hBox->addStretch();
|
||
|
||
auto bnSearch = new QPushButton(tr("Search"));
|
||
connect(bnSearch, &QPushButton::clicked, fdIP, [this] {
|
||
QString ipsStr = fdIP->toPlainText();
|
||
if(ipsStr.isEmpty()) {
|
||
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
|
||
return;
|
||
}
|
||
auto ips = ipsStr.split("\n", Qt::SkipEmptyParts);
|
||
if(ips.isEmpty()) {
|
||
QMessageBox::warning(this, tr("Attention"), tr("Please input IP address!"));
|
||
return;
|
||
}
|
||
QByteArray data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
|
||
foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "Specify IP write Failed." << ip;
|
||
specifyIPDlg->accept();
|
||
});
|
||
hBox->addWidget(bnSearch);
|
||
|
||
auto btnCancel = new QPushButton(tr("Cancel"));
|
||
connect(btnCancel, &QPushButton::clicked, specifyIPDlg, &QDialog::reject);
|
||
hBox->addWidget(btnCancel);
|
||
hBox->addStretch();
|
||
|
||
transUi();
|
||
|
||
sendGetInfo();
|
||
mUdpTimer.start(30000);
|
||
}
|
||
|
||
DevicePanel::~DevicePanel() {
|
||
mUdpSocket.close();
|
||
mUdpTimer.stop();
|
||
}
|
||
|
||
void DevicePanel::sendGetInfo() {
|
||
auto data = QJsonDocument(QJsonObject{{"action", "getInfo"}}).toJson(QJsonDocument::Compact);
|
||
uchar ccc[]{0x7E, 0x7E, 0x7E, 0x90, 0x42, 0x72, 0x6F, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x21,
|
||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x9F};
|
||
if(mUdpSocket.writeDatagram(data, QHostAddress("255.255.255.255"), 22222) != data.length()) qDebug() << "getInfo write to 255.255.255.255 failed";
|
||
if(mUdpSocket.writeDatagram((char *)ccc, sizeof(ccc), QHostAddress("255.255.255.255"), 31296) != sizeof(ccc)) qDebug() << "getInfo write to 255.255.255.255 failed";
|
||
auto networkinterfaces = QNetworkInterface::allInterfaces();
|
||
foreach(auto face, networkinterfaces) {
|
||
auto flags = face.flags();
|
||
bool can = (flags & QNetworkInterface::IsRunning) && (flags & QNetworkInterface::CanBroadcast) && ! (flags & QNetworkInterface::IsLoopBack);
|
||
if(! can) continue;
|
||
auto addrEntries = face.addressEntries();
|
||
foreach(QNetworkAddressEntry addrEntry, addrEntries) {
|
||
auto ip = addrEntry.ip();
|
||
if(ip.protocol()!=QAbstractSocket::IPv4Protocol) continue;
|
||
auto broadcast = addrEntry.broadcast();
|
||
if(mUdpSocket.writeDatagram(data, broadcast, 22222) != data.length()) qDebug() << "getInfo write failed." << ip.toString() << "->" << broadcast.toString();
|
||
}
|
||
}
|
||
auto ipstr = fdIP->toPlainText();
|
||
if(! ipstr.isEmpty()) {
|
||
auto ips = ipstr.split("\n", Qt::SkipEmptyParts);
|
||
foreach(auto ip, ips) if(mUdpSocket.writeDatagram(data, QHostAddress(ip), 22222) != data.length()) qDebug() << "getInfo specify IP write failed." << ip;
|
||
}
|
||
}
|
||
|
||
void DevicePanel::changeEvent(QEvent *event) {
|
||
QWidget::changeEvent(event);
|
||
if(event->type() == QEvent::LanguageChange) transUi();
|
||
}
|
||
void DevicePanel::transUi() {
|
||
btnRefresh->setText(tr("Refresh"));
|
||
bnSpecifyIP->setItemText(0,tr("Specify IP"));
|
||
label_3->setText(tr("All"));
|
||
|
||
mDeviceTable->setHeaderText("online", tr("Online"));
|
||
mDeviceTable->setHeaderText("id", tr("Screen ID"));
|
||
mDeviceTable->setHeaderText("screenSize", tr("Screen Size"));
|
||
mDeviceTable->setHeaderText("alias", tr("Alias"));
|
||
mDeviceTable->setHeaderText("brightness", tr("Screen Brightness"));
|
||
mDeviceTable->setHeaderText("power", tr("Power Status"));
|
||
mDeviceTable->setHeaderText("password", tr("Security"));
|
||
mDeviceTable->setHeaderText("info", tr("More Info"));
|
||
mDeviceTable->setHeaderText("screenshot", tr("Screenshot"));
|
||
|
||
auto cnt = mDeviceTable->topLevelItemCount();
|
||
for(int i=0; i<cnt; i++) {
|
||
auto item = (DeviceItem*) mDeviceTable->item(i);
|
||
item->setText("power", item->mCard.isScreenOn ? tr("On") : tr("Off"));
|
||
}
|
||
transCtrl();
|
||
}
|
||
void DevicePanel::transCtrl() {
|
||
if(mDeviceCtrlPanel) {
|
||
mBtnGrp->button(Setting_Bright)->setText(tr("Brightness Adj."));
|
||
mBtnGrp->button(Setting_PowerControl)->setText(tr("Power Control"));
|
||
mBtnGrp->button(Setting_NetCfg)->setText(tr("Net Config"));
|
||
mBtnGrp->button(Setting_VerifyClock)->setText(tr("Time Sync"));
|
||
mBtnGrp->button(Setting_HDMI)->setText(tr("Video source"));
|
||
mBtnGrp->button(Setting_Encrypt)->setText(tr("Password"));
|
||
mBtnGrp->button(Setting_Advanced)->setText(tr("Advanced"));
|
||
mBtnGrp->button(Setting_Volume)->setText(tr("Volume Adj."));
|
||
mBtnGrp->button(Setting_Test)->setText(tr("Test"));
|
||
|
||
if(gSelCards.count() < 1) fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
|
||
else if(gSelCards.count()==1) fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
|
||
else fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
|
||
btnClear->setText(tr("Clear"));
|
||
}
|
||
}
|
||
void DevicePanel::newCtrl() {
|
||
mHBox->addWidget(mDeviceCtrlPanel = new QWidget);
|
||
auto vBox = new QVBoxLayout(mDeviceCtrlPanel);
|
||
vBox->setContentsMargins(0,0,0,0);
|
||
vBox->setSpacing(0);
|
||
|
||
auto hBox = new QHBoxLayout;
|
||
hBox->setSpacing(2);
|
||
|
||
mBtnGrp = new QButtonGroup(mDeviceCtrlPanel);
|
||
for(int i=0; i<Setting_End; i++) {
|
||
auto btn = new QToolButton;
|
||
auto policy = btn->sizePolicy();
|
||
policy.setHorizontalPolicy(QSizePolicy::Preferred);
|
||
btn->setSizePolicy(policy);
|
||
btn->setIconSize(QSize(48, 48));
|
||
btn->setCheckable(true);
|
||
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
btn->setProperty("ss", "CtrlTab");
|
||
hBox->addWidget(btn);
|
||
mBtnGrp->addButton(btn, i);
|
||
}
|
||
mBtnGrp->button(Setting_Bright)->setIcon(QIcon(":/res/bnBrightnessAdjustMent_s.png"));
|
||
mBtnGrp->button(Setting_PowerControl)->setIcon(QIcon(":/res/bnPowerControl_s.png"));
|
||
mBtnGrp->button(Setting_NetCfg)->setIcon(QIcon(":/res/bnNetConfig_s.png"));
|
||
mBtnGrp->button(Setting_VerifyClock)->setIcon(QIcon(":/res/bnVerifyClock_s.png"));
|
||
mBtnGrp->button(Setting_Encrypt)->setIcon(QIcon(":/res/encrypt.png"));
|
||
mBtnGrp->button(Setting_HDMI)->setIcon(QIcon(":/res/Hdmi.png"));
|
||
mBtnGrp->button(Setting_Volume)->setIcon(QIcon(":/res/volume.png"));
|
||
mBtnGrp->button(Setting_Advanced)->setIcon(QIcon(":/res/AdvParam.png"));
|
||
mBtnGrp->button(Setting_Test)->setIcon(QIcon(":/res/test.png"));
|
||
|
||
connect(mBtnGrp, &QButtonGroup::idToggled, this, [this](int index, bool checked) {
|
||
if(!checked || index==curIndex) return;
|
||
curIndex = index;
|
||
if(wgts[index]==0) {
|
||
if(index==Setting_Bright) wgts[index] = new CtrlBrightPanel;
|
||
else if(index==Setting_PowerControl) wgts[index] = new CtrlPowerPanel;
|
||
else if(index==Setting_NetCfg) wgts[index] = new CtrlNetworkPanel;
|
||
else if(index==Setting_VerifyClock) wgts[index] = new CtrlVerifyClockPanel;
|
||
else if(index==Setting_Encrypt) wgts[index] = new CtrlPwdPanel;
|
||
else if(index==Setting_HDMI) wgts[index] = new CtrlHdmiPanel;
|
||
else if(index==Setting_Volume) wgts[index] = new CtrlVolumePanel;
|
||
else if(index==Setting_Advanced) wgts[index] = new CtrlAdvancedPanel;
|
||
else if(index==Setting_Test) wgts[index] = new CtrlTestPanel;
|
||
}
|
||
scrollArea->takeWidget();
|
||
scrollArea->setWidget(wgts[index]);
|
||
wgts[index]->setFocus();
|
||
});
|
||
vBox->addLayout(hBox);
|
||
|
||
auto line = new QFrame;
|
||
line->setFrameShape(QFrame::HLine);
|
||
line->setFrameShadow(QFrame::Sunken);
|
||
vBox->addWidget(line);
|
||
|
||
hBox = new QHBoxLayout;
|
||
|
||
scrollArea = new QScrollArea;
|
||
scrollArea->setWidgetResizable(true);
|
||
hBox->addWidget(scrollArea);
|
||
|
||
auto vBox2 = new QVBoxLayout();
|
||
|
||
fdInfo = new QTextEdit();
|
||
gFdResInfo = fdInfo;
|
||
fdInfo->setReadOnly(true);
|
||
fdInfo->setMaximumWidth(360);
|
||
vBox2->addWidget(fdInfo);
|
||
|
||
btnClear = new QPushButton(tr("Clear"));
|
||
btnClear->setMinimumHeight(30);
|
||
btnClear->setProperty("ssType", "progManageTool");
|
||
connect(btnClear, &QPushButton::clicked, fdInfo, &QTextEdit::clear);
|
||
vBox2->addWidget(btnClear);
|
||
|
||
hBox->addLayout(vBox2);
|
||
|
||
vBox->addLayout(hBox);
|
||
|
||
fdInfo->hide();
|
||
btnClear->hide();
|
||
|
||
connect(this, &DevicePanel::sigSelectedDeviceList, fdInfo, [this] {
|
||
if(gSelCards.count() < 2) {
|
||
if(gSelCards.count()==1) fdCardNumInfo->setText(tr("Current Screen")+": "+gSelCards[0].id);
|
||
else fdCardNumInfo->setText(tr("Current Screen")+": "+tr("none"));
|
||
fdInfo->hide();
|
||
btnClear->hide();
|
||
} else {
|
||
fdCardNumInfo->setText(tr("Multi screen operation")+". "+tr("selected num")+": "+QString::number(gSelCards.count()));
|
||
fdInfo->clear();
|
||
fdInfo->show();
|
||
btnClear->show();
|
||
}
|
||
});
|
||
|
||
mBtnGrp->button(0)->setChecked(true);
|
||
|
||
transCtrl();
|
||
}
|
||
|
||
void DevicePanel::init(DeviceItem *item) {
|
||
QJsonObject json;
|
||
json.insert("_id", "GetBuildInformation");
|
||
json.insert("_type", "GetBuildInformation");
|
||
auto reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.BrightnessLevel = json["BrightnessLevel"].toInt();
|
||
item->mCard.FirmwareVersion = json["FirmwareVersion"].toString();
|
||
item->mCard.HardVersion = json["HardVersion"].toString();
|
||
item->mCard.ScreenResolution = json["ScreenResolution"].toString();
|
||
item->mCard.IMEI = json["IMEI"].toString();
|
||
auto androidVersion = json["AndroidVersion"].toString();
|
||
if(! androidVersion.isEmpty()) item->mCard.androidVersion = androidVersion;
|
||
});
|
||
|
||
if(item->mCard.mWidth==0 || item->mCard.mHeight==0) {
|
||
json = QJsonObject();
|
||
json.insert("_id", "GetScreenSize");
|
||
json.insert("_type", "GetScreenSize");
|
||
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.mWidth = json["width"].toInt();
|
||
item->mCard.mHeight = json["height"].toInt();
|
||
item->setText("screenSize", QString("%1 x %2").arg(item->mCard.mWidth).arg(item->mCard.mHeight));
|
||
});
|
||
}
|
||
|
||
json = QJsonObject();
|
||
json.insert("_id", "GetBrightness");
|
||
json.insert("_type", "GetBrightness");
|
||
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.bright = json["brightnessPercentage"].toInt(-1);
|
||
if(item->mCard.bright==-1) item->mCard.bright = qRound(json["brightness"].toInt() * 100.0 / item->mCard.BrightnessLevel);
|
||
item->setText("brightness", QString::number(item->mCard.bright)+"%");
|
||
});
|
||
json = QJsonObject();
|
||
json.insert("_id", "IsScreenOn");
|
||
json.insert("_type", "IsScreenOn");
|
||
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.isScreenOn = json["on"].toBool();
|
||
item->setForeground("power"**mDeviceTable, item->mCard.isScreenOn ? Qt::green : Qt::red);
|
||
item->setText("power", item->mCard.isScreenOn ? tr("On") : tr("Off"));
|
||
});
|
||
json = QJsonObject();
|
||
json.insert("_id", "GetCardAlias");
|
||
json.insert("_type", "GetCardAlias");
|
||
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.alias = QString::fromUtf8(QByteArray::fromBase64(json["alias"].toString().toLatin1()));
|
||
item->setText("alias", item->mCard.alias);
|
||
});
|
||
|
||
json = QJsonObject();
|
||
json.insert("_id", "HasControllerPassword");
|
||
json.insert("_type", "HasControllerPassword");
|
||
reply = NetReq("http://"+item->mCard.ip+":2016/settings").timeout(120000).post(json);
|
||
ConnReply(reply, item->fdOnline) [=] {
|
||
QJsonDocument json;
|
||
QString err = checkReplyForJson(reply, &json);
|
||
if(! err.isEmpty()) return;
|
||
item->mCard.hasPassword = json["result"].toBool();
|
||
if(item->mCard.hasPassword) {//加过密
|
||
item->btnUnlock->show();
|
||
item->btnUnlock->setIcon(QIcon(item->mCard.isLocked ? ":/res/Lock.png" : ":/res/UnLock.png"));
|
||
} else item->btnUnlock->hide();
|
||
});
|
||
}
|
||
|
||
ImgDlg::ImgDlg(const QByteArray &data, QWidget *parent) : QDialog(parent) {
|
||
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
|
||
setWindowTitle(tr("Screenshot"));
|
||
mImg.loadFromData(data);
|
||
auto www = mImg.width();
|
||
auto hhh = mImg.height();
|
||
if(www <= 1600 && hhh <= 900) resize(www, hhh);
|
||
else if(www > hhh) resize(900 * www / hhh, 900);
|
||
else resize(1600, 1600 * hhh / www);
|
||
}
|
||
void ImgDlg::paintEvent(QPaintEvent *) {
|
||
QPainter painter(this);
|
||
painter.drawImage(rect(), mImg);
|
||
}
|