FaceAccess/Linguist/setUi/settingUiDevMng.cpp

2898 lines
113 KiB
C++
Raw Normal View History

2024-07-11 11:27:12 +08:00
#include "settingUiDevMng.h"
#include <QDebug>
#include <QDateTime>
#include <QCoreApplication>
#include "UiConfig.h"
#include "rw_zlog.h"
int settingUiDevMng::m_pageIndex = 0;
settingUiDevMng::settingUiDevMng(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("界面显示IP"), "", myListWidget::enPropertySwitch),
SetOpn(tr("界面显示ID及版本号"), "", myListWidget::enPropertySwitch),
SetOpn(tr("音量控制"), "xx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("亮度控制"), "xx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("进入屏保时间(秒)"), "xx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("熄屏等待时间(秒)"), "xx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("时间设置"), "", myListWidget::enPropertyMoreArrow),
//SetOpn(tr("网络设置"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("蓝牙"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("动态底库"), "", myListWidget::enPropertySwitch),
SetOpn(tr("通行密码"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("禁用工程页面"), "", myListWidget::enPropertySwitch),
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMng()";
#if 0//蓝牙功能暂时隐藏
controlListWidgetItemShow(false, DEV_MNG_BLUETOOTH);
#endif
}
settingUiDevMng::~settingUiDevMng()
{
qDebug() << "~settingUiDevMng()";
}
void settingUiDevMng::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
reset();
}
void settingUiDevMng::reset()
{
if(nullptr == m_backstageIf){
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case DEV_MNG_SHOW_IP:
case DEV_MNG_SHOW_ID_VER:
{
bool switch_option = false;
if(DEV_MNG_SHOW_IP == i){
switch_option = m_backstageIf->getIpShowSw();
}else if(DEV_MNG_SHOW_ID_VER == i){
switch_option = m_backstageIf->getShowIdAndVerSw();
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_SET_VOLUMN:qDebug() << "DEV_MNG_SET_VOLUMN";
str = QString::number(m_backstageIf->getVolume());
break;
case DEV_MNG_SET_BRIGHTNESS:qDebug() << "DEV_MNG_SET_BRIGHTNESS";
str = QString::number(m_backstageIf->getLcdBrightness());
break;
#if 0
case DEV_MNG_SCREENSAVER:
case DEV_MNG_SCREENOFF:
{
int standbyTime = m_backstageIf->getStandbyTime();
if(0 == standbyTime){
str = tr("永不");
}
else{
str = QString::number(standbyTime);
if(DEV_MNG_SCREENOFF == i){
int screenoffTime = m_backstageIf->getCloseScreenTime();
str = (0 == screenoffTime ? tr("永不") : QString::number(screenoffTime));
}
}
}
break;
#else
case DEV_MNG_SCREENSAVER:qDebug() << "DEV_MNG_SCREENSAVER";
{
int standbyTime = m_backstageIf->getStandbyTime();
str = (0 == standbyTime ? tr("永不") : QString::number(standbyTime));
}
break;
case DEV_MNG_SCREENOFF:qDebug() << "DEV_MNG_SCREENOFF";
{
int screenoffTime = m_backstageIf->getCloseScreenTime();
str = (0 == screenoffTime ? tr("永不") : QString::number(screenoffTime));
}
break;
#endif
case DEV_MNG_SET_TIME:qDebug() << "DEV_MNG_SET_TIME";
break;
#if 0
case DEV_MNG_SET_NETWORK:
break;
#endif
case DEV_MNG_PASSWORD:qDebug() << "DEV_MNG_PASSWORD";
if(UiConfig::GetInstance()->isTpAvailable()){
int pwdType = 0;
std::string pwd;
if(0 == m_backstageIf->getDevPwd(pwdType, pwd)){
//qDebug() << "password type:" << pwdType << ", password:" << QString(pwd.c_str());
str = pwd.empty() ? tr("(未设置)") : pwd.c_str();
}
}
else{
qDebug() << "has no TP, hide password";
controlListWidgetItemShow(false, DEV_MNG_PASSWORD);
}
break;
case DEV_MNG_BLUETOOTH:qDebug() << "DEV_MNG_BLUETOOTH";
{
qDebug() << "get bt switch";
bool btSwitch = false;
m_backstageIf->getBtSwitch(btSwitch);
str = btSwitch ? tr("已开启") : tr("已关闭");
qDebug() << "bt switch:" << btSwitch;
}
break;
case DEV_MNG_OPEN_DYNAMICFEATURE:
{
bool switch_option = m_backstageIf->getDynamicFeatureSw();
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_DEV_SETTING_DISABLE:
wdt->updateIcon(m_backstageIf->getDisableDevSettingSw() ? ":/res/image/on.png" : ":/res/image/off.png");
break;
default:
break;
}
wdt->updateLabel(str);
}
}
void settingUiDevMng::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case DEV_MNG_SHOW_IP:
case DEV_MNG_DEV_SETTING_DISABLE:
case DEV_MNG_SHOW_ID_VER:
{
bool setting_value = false;
if(DEV_MNG_SHOW_IP == row){
setting_value = static_cast<bool>(m_backstageIf->getIpShowSw());
}else if(DEV_MNG_DEV_SETTING_DISABLE == row){
setting_value = static_cast<bool>(m_backstageIf->getDisableDevSettingSw());
}else if(DEV_MNG_SHOW_ID_VER == row){
setting_value = static_cast<bool>(m_backstageIf->getShowIdAndVerSw());
}
setting_value = static_cast<bool>(!setting_value);
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
if(DEV_MNG_SHOW_IP == row){
m_backstageIf->setIpShowSw(setting_value);
}else if(DEV_MNG_DEV_SETTING_DISABLE == row){
do{
if(setting_value){
QuestionDialog dlg(tr("打开此开关后,设备将无法进入工程页面,\n是否确认打开?"), parent()->parent());
if(QDialog::Accepted != dlg.exec()){
wdt->updateIcon(":/res/image/off.png");
break;
}
}
m_backstageIf->setDisableDevSettingSw(setting_value);
}while(0);
}else if(DEV_MNG_SHOW_ID_VER == row){
m_backstageIf->setShowIdAndVerSw(setting_value);
}
}
break;
case DEV_MNG_SET_VOLUMN:
case DEV_MNG_SET_BRIGHTNESS:
case DEV_MNG_SCREENSAVER:
case DEV_MNG_SCREENOFF:
{
int currentValue = 10;
int min = 0;
int max = 100;
QString tip("this is a line of prompt text");
#ifndef DEBUG_MODE
if(DEV_MNG_SET_VOLUMN == row){
currentValue = m_backstageIf->getVolume();
min = 0;
max = 100;
tip.clear();
}
else if(DEV_MNG_SET_BRIGHTNESS == row){
currentValue = m_backstageIf->getLcdBrightness();
min = 0;
max = 100;
tip.clear();
}
else if(DEV_MNG_SCREENSAVER == row){
currentValue = m_backstageIf->getStandbyTime();
min = 0;
max = 60;
tip = tr("设置为0时永不进入待机");
}
else if(DEV_MNG_SCREENOFF == row){
currentValue = m_backstageIf->getCloseScreenTime();
min = 0;
max = 60;
tip = tr("设置为0时永不进入熄屏"); //设置为0或者不进入待机时永不进入熄屏
}
#endif
SliderDialog dlg(currentValue, min, max, tip, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString str("valueSet");
int valueSet = dlg.getValueSet();
#ifndef DEBUG_MODE
if(DEV_MNG_SET_VOLUMN == row){
m_backstageIf->setVolume(valueSet);
str = QString::number(valueSet);
}
else if(DEV_MNG_SET_BRIGHTNESS == row){
m_backstageIf->setLcdBrightness(valueSet);
str = QString::number(valueSet);
}
#if 0
else if(DEV_MNG_SCREENSAVER == row){
m_backstageIf->setStandbyTime(valueSet);
myListWidget* wdtScreenOff = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_SCREENOFF)));
if(0 == valueSet){
str = tr("永不");
if(wdtScreenOff != nullptr){
wdtScreenOff->updateLabel(str);
}
}
else{
str = QString::number(valueSet);
int screenoffTime = m_backstageIf->getCloseScreenTime();
if(wdtScreenOff != nullptr){
wdtScreenOff->updateLabel(0 == screenoffTime ? tr("永不") : QString::number(screenoffTime));
}
}
}
else if(DEV_MNG_SCREENOFF == row){
m_backstageIf->setCloseScreenTime(valueSet);
str = (0 == m_backstageIf->getStandbyTime() || 0 == valueSet ? tr("永不") : QString::number(valueSet));
}
#else
else if(DEV_MNG_SCREENSAVER == row){
m_backstageIf->setStandbyTime(valueSet);
str = (0 == valueSet ? tr("永不") : QString::number(valueSet));
}
else if(DEV_MNG_SCREENOFF == row){
m_backstageIf->setCloseScreenTime(valueSet);
str = (0 == valueSet ? tr("永不") : QString::number(valueSet));
}
#endif
#endif
wdt->updateLabel(str);
}
}
break;
case DEV_MNG_SET_TIME:
emit signalShowPage(settingUiDevMngTime::m_pageIndex);
break;
#if 0
case DEV_MNG_SET_NETWORK:
emit signalShowPage(settingUiDevMngNetwork::m_pageIndex);
break;
#endif
case DEV_MNG_BLUETOOTH:
emit signalShowPage(settingUiDevMngBt::m_pageIndex);
break;
case DEV_MNG_OPEN_DYNAMICFEATURE:
{
bool setting_value = !(m_backstageIf->getDynamicFeatureSw());
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
m_backstageIf->setDynamicFeatureSw(setting_value);
}
break;
case DEV_MNG_PASSWORD:
{
int pwdType = 0;
std::string pwd;
if(0 == m_backstageIf->getDevPwd(pwdType, pwd)){
if(1 == pwdType){ //设备本地配置密码
bool settingFailed = true;
do{
LineEditInputDialog dlg(config[DEV_MNG_PASSWORD].m_sOpn, parent()->parent());
if(dlg.exec() == QDialog::Accepted){
const QString strInput = dlg.getRow(0);
do{
if(strInput.length()){
if(strInput.length() < 4 || strInput.length() > 10){
break;
}
bool isDigi = false;
strInput.toInt(&isDigi);
if(!isDigi){
break;
}
}
if(0 == m_backstageIf->setLocalDevPwd(strInput.toStdString())){
wdt->updateLabel(strInput.isEmpty() ? tr("(未设置)") : strInput);
settingFailed = false;
}
}while(0);
}
else {
settingFailed = false;
}
if(settingFailed){
InfoDialog(tr("密码为4-10位数字设置有误请重新输入"), parent()->parent()).exec();
}
}while(settingFailed);
}
else if(2 == pwdType){ //平台配置密码
InfoDialog(tr("平台下发的通行密码,如需修改请前往平台操作"), parent()->parent()).exec();
}
}
}
break;
default:
break;
}
}
int settingUiDevMngTime::m_pageIndex = 0;
settingUiDevMngTime::settingUiDevMngTime(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("NTP获取时间"), "", myListWidget::enPropertySwitch),
SetOpn(tr("NTP服务器"), "xxxxxxxxxxxxxxxxxxxxxxx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("校时间隔(小时)"), "x", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("时区"), "UTC+8亚洲/北京/xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("手动设置"), "xxxx-xx-xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1))
}, parent), m_msgDlg(nullptr)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngTime()";
}
settingUiDevMngTime::~settingUiDevMngTime()
{
qDebug() << "~settingUiDevMngTime()";
}
void settingUiDevMngTime::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
reset();
}
void settingUiDevMngTime::reset()
{
if(nullptr == m_backstageIf){
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
const int iBufSize = 256;
char buf[iBufSize] = {'\0'};
switch(i)
{
case DEV_MNG_TIME_NTP_SW:
{
bool switch_option = false;
if(DEV_MNG_TIME_NTP_SW == i){
switch_option = m_backstageIf->getNtpServerSw();
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_TIME_NTP_SERVER:
{
if(0 == m_backstageIf->getNtpServerAddr(buf, iBufSize)){
str = buf;
}
/*
str += ":";
int port = m_backstageIf->getNtpServerPort();
if(port >= 0){
str += QString::number(port);
}
*/
}
break;
case DEV_MNG_TIME_NTP_INTERVAL:
str = QString::number(m_backstageIf->getNtpCheckInterval());
break;
case DEV_MNG_TIME_NTP_TIME_ZONE:
if(0 == m_backstageIf->getNtpTimeZone(buf, iBufSize)){
for(int j = 0; j < TimeZoneSet.length(); j++){
if(TimeZoneSet[j] == buf){
str = TimeZone[j];
break;
}
}
}
break;
case DEV_MNG_TIME_MANUAL:
str = QDateTime::currentDateTime().toString("yyyy-MM-dd"); // hh:mm
break;
default:
break;
}
wdt->updateLabel(str);
}
if(m_backstageIf->getNtpServerSw()){
controlListWidgetItemShow(false, DEV_MNG_TIME_MANUAL);
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_SERVER);
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_INTERVAL);
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_TIME_ZONE);
}
else{
controlListWidgetItemShow(true, DEV_MNG_TIME_MANUAL);
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_SERVER);
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_INTERVAL);
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_TIME_ZONE);
}
}
void settingUiDevMngTime::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case DEV_MNG_TIME_NTP_SW:
{
bool setting_value = false;
#ifndef DEBUG_MODE
if(DEV_MNG_TIME_NTP_SW == row){
setting_value = static_cast<bool>(m_backstageIf->getNtpServerSw());
}
#endif
setting_value = static_cast<bool>(!setting_value);
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
#ifndef DEBUG_MODE
if(DEV_MNG_TIME_NTP_SW == row){
m_backstageIf->setNtpServerSw(setting_value);
if(setting_value){
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_SERVER);
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_INTERVAL);
controlListWidgetItemShow(true, DEV_MNG_TIME_NTP_TIME_ZONE);
controlListWidgetItemShow(false, DEV_MNG_TIME_MANUAL);
}
else{
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_SERVER);
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_INTERVAL);
controlListWidgetItemShow(false, DEV_MNG_TIME_NTP_TIME_ZONE);
controlListWidgetItemShow(true, DEV_MNG_TIME_MANUAL);
}
ntpTimeCorrect();
}
#endif
}
break;
case DEV_MNG_TIME_NTP_SERVER:
case DEV_MNG_TIME_NTP_INTERVAL:
{
bool settingFailed = true;
do{
QStringList strs;
if(DEV_MNG_TIME_NTP_SERVER == row){
strs << config[row].m_sOpn;
}
else if(DEV_MNG_TIME_NTP_INTERVAL == row){
strs << config[row].m_sOpn;
}
LineEditInputDialog dlg(strs, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString str;
do{
if(DEV_MNG_TIME_NTP_SERVER == row){
/*
bool isDigi = false;
int valueSet = dlg.getRow(1).toInt(&isDigi);
if(isDigi){
if(valueSet < 0 || valueSet > 65535){
break;
}
}
*/
if("" == dlg.getRow(0)){
break;
}
#ifndef DEBUG_MODE
if(m_backstageIf){
m_backstageIf->setNtpServerAddr(const_cast<char*>(dlg.getRow(0).toStdString().c_str()));
//m_backstageIf->setNtpServerPort(valueSet);
str = dlg.getRow(0);// + ":" + dlg.getRow(1);
wdt->updateLabel(str);
ntpTimeCorrect();
}
#endif
}
else if(DEV_MNG_TIME_NTP_INTERVAL == row){
bool isDigi = false;
int valueSet = dlg.getRow(0).toInt(&isDigi);
if(!isDigi || (valueSet < 0 || valueSet > 1000000)){
break;
}
#ifndef DEBUG_MODE
if(m_backstageIf){
m_backstageIf->setNtpCheckInterval(valueSet);
str = QString::number(valueSet);
wdt->updateLabel(str);
ntpTimeCorrect();
}
#endif
}
settingFailed = false;
}while(0);
}
else {
settingFailed = false;
}
if(settingFailed)
{
InfoDialog(tr("设置有误,请重新输入!"), parent()->parent()).exec();
}
}while(settingFailed);
}
break;
case DEV_MNG_TIME_NTP_TIME_ZONE:
{
int choosed = 0;
const QVector<QString>& opts = TimeZone;
if(DEV_MNG_TIME_NTP_TIME_ZONE == row){
#ifndef DEBUG_MODE
const int iBufSize = 256;
char buf[iBufSize] = {'\0'};
if(0 == m_backstageIf->getNtpTimeZone(buf, iBufSize)){
for(int i = 0; i < TimeZoneSet.length(); i++){
if(TimeZoneSet[i] == buf){
choosed = i;
break;
}
}
}
#endif
}
ItemChooseDialog dlg(opts, choosed, parent()->parent());
if(QDialog::Accepted == dlg.exec())
{
int newChoosed = dlg.getChoosedIndex();
if(newChoosed != choosed){
qDebug() << "newChoosed:" << newChoosed;
if(DEV_MNG_TIME_NTP_TIME_ZONE == row){
#ifndef DEBUG_MODE
m_backstageIf->setNtpTimeZone(const_cast<char*>(TimeZoneSet[newChoosed].toStdString().c_str()));
ntpTimeCorrect();
#endif
wdt->updateLabel(opts[newChoosed]);
}
}
}
}
break;
case DEV_MNG_TIME_MANUAL:
{
DateTimeDialog dateTimeDlg(QDateTime::currentDateTime(), parent()->parent());
if(dateTimeDlg.exec() == QDialog::Accepted)
{
m_backstageIf->setDateTime(dateTimeDlg.getValueSet().toString("yyyy-MM-dd hh:mm").toStdString().c_str());
wdt->updateLabel(dateTimeDlg.getValueSet().toString("yyyy-MM-dd"));
}
}
break;
default:
break;
}
}
void settingUiDevMngTime::ntpTimeCorrect()
{
QTimer::singleShot(1000, this, SLOT(slotShowProcessing()));
if(m_backstageIf->getNtpServerSw()){
if(nullptr == m_msgDlg){
m_msgDlg = new MsgDialog(tr("处理中,请稍候..."), parent()->parent());
m_msgDlg->exec();
}
}
}
void settingUiDevMngTime::slotShowProcessing()
{
int ret = m_backstageIf->ntpTimeCorrect();
if(m_msgDlg){
delete m_msgDlg;
m_msgDlg = nullptr;
}
if(0 != ret){
InfoDialog(tr("NTP校时失败请检查"), parent()->parent()).exec();
}
}
int settingUiDevMngNetwork::m_pageIndex = 0;
settingUiDevMngNetwork::settingUiDevMngNetwork(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("有线网络"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("无线网络"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("4G网络"), "", myListWidget::enPropertyMoreArrow)
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngNetwork()";
}
settingUiDevMngNetwork::~settingUiDevMngNetwork()
{
qDebug() << "~settingUiDevMngNetwork()";
}
void settingUiDevMngNetwork::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
}
void settingUiDevMngNetwork::reset()
{
if(nullptr == m_backstageIf){
return;
}
if(UiConfig::GetInstance()->isFuncNotSupport(FuncWifi)){
controlListWidgetItemShow(false, DEV_MNG_NETWORK_WIFI);
}
stNet4G netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNet4G));
if(0 != m_backstageIf->getNet4GCfg(netCfg)){
InfoDialog(tr("获取4G网络配置失败请重试"), parent()->parent()).exec();
return;
}
controlListWidgetItemShow(netCfg.available, DEV_MNG_NETWORK_4G);
}
void settingUiDevMngNetwork::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case DEV_MNG_NETWORK_WIRE:
emit signalShowPage(settingUiDevMngNetWire::m_pageIndex);
break;
case DEV_MNG_NETWORK_WIFI:
emit signalShowPage(settingUiDevMngNetWifi::m_pageIndex);
break;
case DEV_MNG_NETWORK_4G:
emit signalShowPage(settingUiDevMngNet4G::m_pageIndex);
break;
default:
break;
}
}
int settingUiDevMngNetWire::m_pageIndex = 0;
settingUiDevMngNetWire::settingUiDevMngNetWire(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("启用有线网络"), "", myListWidget::enPropertySwitch),
SetOpn(tr("DHCP"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("手动配置"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("设备IP"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyIndent1),
SetOpn(tr("子网掩码"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyIndent1),
SetOpn(tr("设备网关"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyIndent1),
SetOpn(tr("DNS服务器"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyIndent1)
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngNetWire()";
}
settingUiDevMngNetWire::~settingUiDevMngNetWire()
{
qDebug() << "~settingUiDevMngNetWire()";
}
void settingUiDevMngNetWire::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
//reset();
}
void settingUiDevMngNetWire::reset()
{
stNetWire netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWire));
if(0 != m_backstageIf->getNetWireCfg(netCfg)){
InfoDialog(tr("获取有线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i){
case DEV_MNG_NET_WIRE_SW:
case DEV_MNG_NET_WIRE_DHCP:
{
bool switch_option = false;
if(DEV_MNG_NET_WIRE_SW == i){
switch_option = netCfg.cfg.enable;
}
else if(DEV_MNG_NET_WIRE_DHCP == i){
switch_option = netCfg.cfg.type;
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_NET_WIRE_MAN_CFG:
break;
case DEV_MNG_NET_WIRE_IP:
str = netCfg.cfg.ip;
break;
case DEV_MNG_NET_WIRE_MASK:
str = netCfg.cfg.mask;
break;
case DEV_MNG_NET_WIRE_GW:
str = netCfg.cfg.gw;
break;
case DEV_MNG_NET_WIRE_DNS:
str = netCfg.cfg.dns;
break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_DHCP);
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_MAN_CFG);
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_IP);
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_MASK);
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_GW);
controlListWidgetItemShow(netCfg.cfg.enable, DEV_MNG_NET_WIRE_DNS);
if(netCfg.cfg.enable){
controlListWidgetItemShow(!netCfg.cfg.type, DEV_MNG_NET_WIRE_MAN_CFG);
}
}
bool settingUiDevMngNetWire::setStaticNetworkPara(const stNetWire& curNetCfg)
{
stNetWire netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWire));
netCfg.cfg.enable = true;
netCfg.cfg.type = 0;
bool ret = false;
bool settingFailed = true;
do{
QList<QString> strs;
strs << config[DEV_MNG_NET_WIRE_IP].m_sOpn
<< config[DEV_MNG_NET_WIRE_MASK].m_sOpn
<< config[DEV_MNG_NET_WIRE_GW].m_sOpn
<< config[DEV_MNG_NET_WIRE_DNS].m_sOpn;
IpInputBarDialog dlg(strs, {true, true, false, false}, {false, true, false, false}, parent()->parent());
#if 0
dlg.fillRow(0, curNetCfg.cfg.ip);
dlg.fillRow(1, curNetCfg.cfg.mask);
dlg.fillRow(2, curNetCfg.cfg.gw);
dlg.fillRow(3, curNetCfg.cfg.dns);
#endif
if (dlg.exec() == QDialog::Accepted) {
strcpy(netCfg.cfg.ip, dlg.getRow(0).toStdString().c_str());
strcpy(netCfg.cfg.mask, dlg.getRow(1).toStdString().c_str());
strcpy(netCfg.cfg.gw, dlg.getRow(2).toStdString().c_str());
strcpy(netCfg.cfg.dns, dlg.getRow(3).toStdString().c_str());
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if (0 == m_backstageIf->setNetWireCfg(netCfg)) {
settingFailed = false;
auto wdgIp = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_IP)));
if (wdgIp != nullptr) {
wdgIp->updateLabel(netCfg.cfg.ip);
}
auto wdgMask = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_MASK)));
if (wdgMask != nullptr) {
wdgMask->updateLabel(netCfg.cfg.mask);
}
auto wdgGw = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_GW)));
if (wdgGw != nullptr) {
wdgGw->updateLabel(netCfg.cfg.gw);
}
auto wdgDns = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_DNS)));
if (wdgDns != nullptr) {
wdgDns->updateLabel(netCfg.cfg.dns);
}
ret = true;
} else {
InfoDialog(tr("设置有线网络失败,请重试!"), parent()->parent()).exec();
}
} else {
settingFailed = false;
}
}while(settingFailed);
return ret;
}
void settingUiDevMngNetWire::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
stNetWire netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWire));
#ifndef DEBUG_MODE
if(0 == m_backstageIf->getNetWireCfg(netCfg)){
#endif
switch(row){
case DEV_MNG_NET_WIRE_SW:
case DEV_MNG_NET_WIRE_DHCP:
{
bool setting_value = false;
QString que;
if(DEV_MNG_NET_WIRE_SW == row){
setting_value = netCfg.cfg.enable;
que = (setting_value ? tr("您确定要禁用有线网络吗?") : tr("您确定要启用有线网络吗?"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
setting_value = static_cast<bool>(!setting_value);
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWireEnable(setting_value)){
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
controlListWidgetItemShow(setting_value, DEV_MNG_NET_WIRE_DHCP);
controlListWidgetItemShow(setting_value ? 0 == netCfg.cfg.type : false, DEV_MNG_NET_WIRE_MAN_CFG);
controlListWidgetItemShow(setting_value, DEV_MNG_NET_WIRE_IP);
controlListWidgetItemShow(setting_value, DEV_MNG_NET_WIRE_MASK);
controlListWidgetItemShow(setting_value, DEV_MNG_NET_WIRE_GW);
controlListWidgetItemShow(setting_value, DEV_MNG_NET_WIRE_DNS);
}
else {
InfoDialog(tr("设置有线网络失败,请重试!"), parent()->parent()).exec();
}
}
else if(DEV_MNG_NET_WIRE_DHCP == row){
setting_value = static_cast<bool>(netCfg.cfg.type);
que = (setting_value ? tr("您确定要禁用DHCP吗") : tr("您确定要启用DHCP吗"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
if(setting_value){ //is dhcp now, need to input static network config
if(!setStaticNetworkPara(netCfg)){
break;
}
}
setting_value = static_cast<bool>(!setting_value);
int ret = 0;
if(setting_value){ //switch from static to dhcp
netCfg.cfg.type = static_cast<int>(setting_value);
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
ret = m_backstageIf->setNetWireCfg(netCfg);
if(0 == ret){ //refresh
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
myListWidget* wdgIp = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_IP)));
if(wdgIp != nullptr){
wdgIp->updateLabel("");
}
myListWidget* wdgMask = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_MASK)));
if(wdgMask != nullptr){
wdgMask->updateLabel("");
}
myListWidget* wdgGw = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_GW)));
if(wdgGw != nullptr){
wdgGw->updateLabel("");
}
myListWidget* wdgDns = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIRE_DNS)));
if(wdgDns != nullptr){
wdgDns->updateLabel("");
}
}
else {
InfoDialog(tr("设置有线网络失败,请重试!"), parent()->parent()).exec();
}
}
else {
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
}
if(0 == ret){
controlListWidgetItemShow(!setting_value, DEV_MNG_NET_WIRE_MAN_CFG);
}
}
}
break;
case DEV_MNG_NET_WIRE_MAN_CFG:
setStaticNetworkPara(netCfg);
break;
default:
break;
}
#ifndef DEBUG_MODE
}
#endif
}
int settingUiDevMngNetWifi::m_pageIndex = 0;
settingUiDevMngNetWifi::settingUiDevMngNetWifi(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("启用"), "", myListWidget::enPropertySwitch),
SetOpn(tr("AP模式"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertySwitch | myListWidget::enPropertyIndent1)),
SetOpn(tr("其它网络"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("重新搜索"), "", myListWidget::enPropertyIndent1),
SetOpn(tr("热点密码"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngNetWifi()";
}
settingUiDevMngNetWifi::~settingUiDevMngNetWifi()
{
qDebug() << "~settingUiDevMngNetWifi()";
}
void settingUiDevMngNetWifi::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
//reset();
}
void settingUiDevMngNetWifi::reset()
{
if(nullptr == m_backstageIf){
return;
}
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case DEV_MNG_NET_WIFI_SW:
case DEV_MNG_NET_AP_SW:
{
bool switch_option = false;
if(DEV_MNG_NET_WIFI_SW == i){
switch_option = netCfg.cfg.enable;
}else if(DEV_MNG_NET_AP_SW == i){
switch_option = netCfg.enableAp;
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_NET_WIFI_ASSIGN:
break;
case DEV_MNG_NET_WIFI_SEARCH:
break;
case DEV_MNG_NET_AP_PWD:
str = netCfg.apPwd;
break;
default:
break;
}
wdt->updateLabel(str);
}
if(netCfg.cfg.enable){
if(!netCfg.enableAp){
wifiSearch();
}
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_ASSIGN);
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_SEARCH);
controlListWidgetItemShow(netCfg.enableAp, DEV_MNG_NET_AP_PWD);
}else{
clearSsidList();
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_ASSIGN);
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_SEARCH);
controlListWidgetItemShow(false, DEV_MNG_NET_AP_SW);
controlListWidgetItemShow(false, DEV_MNG_NET_AP_PWD);
}
#if 0 //test
for(int i=0; i<30; i++)
{
QListWidgetItem* pItem = new QListWidgetItem(m_listWidget);
QWidget* wifiListwidget = nullptr;
if(i < 29){
wifiListwidget = new WifiListWidget(QString("ssid") + QString::number(i), i % 2, 100, m_listWidget);
}
else {
wifiListwidget = new myListWidget(SetOpn(), m_listWidget);
}
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->setItemWidget(pItem, wifiListwidget);
m_listWidget->setStyleSheet("QListWidget::item{border-top: 1px solid #DFDDEB;}");
}
#endif
}
void settingUiDevMngNetWifi::slotUpdateConnectionStatus(QString ssid, bool connected)
{
qDebug() << "slotUpdateConnectionStatus";
for(int i=m_ssidPosIndex; i<m_listWidget->count(); i++){
WifiListWidget* wifi = dynamic_cast<WifiListWidget*>(m_listWidget->itemWidget(m_listWidget->item(i)));
if(wifi == nullptr){
qDebug() << "get WifiListWidget failed!";
break;
}
if(wifi->getSsid() == ssid){
qDebug() << "wifi->getSsid():" << wifi->getSsid();
if(connected){
wifi->updateStatus(connected);
}
else {
wifi->clearStatus();
}
}
}
}
void settingUiDevMngNetWifi::wifiSearch()
{
clearSsidList();
//slotShowSsidList();
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(m_backstageIf){
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
//return; //TODO
}
const int ssidListSize = 64;
stAccPoint ssidList[ssidListSize];
MsgDialog msgdlg(tr("搜索中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
bool isTargetSsidFindable = false;
//bool isSearchRetNotNuLL = false;
int ret = m_backstageIf->getSsidList(ssidList, ssidListSize);
if (ret > 0) {
for(int i=0; i<ret; i++)
{
qDebug() << "ssidList" << i << "ssidDis:" << QString(ssidList[i].ssid)
<< ", connected: " << ssidList[i].isConnected;
QListWidgetItem* pItem = new QListWidgetItem(m_listWidget);
auto wifiListwidget =
new WifiListWidget(ssidList[i].ssid, ssidList[i].isConnected, ssidList[i].isEncrypt, ssidList[i].sigLev,
QString(ssidList[i].ssid) == netCfg.ssid, m_listWidget);
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->setItemWidget(pItem, wifiListwidget);
//m_listWidget->setStyleSheet("QListWidget::item{border-top: 1px solid #DFDDEB;}");
if(QString(ssidList[i].ssid) == netCfg.ssid){
isTargetSsidFindable = true;
if (netCfg.isConnected) ((WifiListWidget *)wifiListwidget)->updateStatus(netCfg.isConnected);
}
}
}
if(!isTargetSsidFindable && netCfg.isConnected){ //if target ssid is not findable but connected, show it
QListWidgetItem* pItem = new QListWidgetItem();
QWidget* wifiListwidget = new WifiListWidget(netCfg.ssid, netCfg.isConnected, "none" != QString(netCfg.encType), -1, true, m_listWidget);
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->setItemWidget(pItem, wifiListwidget);
//m_listWidget->setStyleSheet("QListWidget::item{border-top: 1px solid #DFDDEB;}");
m_listWidget->insertItem(m_ssidPosIndex, pItem);
}
}
}
//void settingUiDevMngNetWifi::showSsidList()
//{
//}
void settingUiDevMngNetWifi::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
return;
}
int row = m_listWidget->currentRow();
switch(row){
case DEV_MNG_NET_WIFI_SW:
case DEV_MNG_NET_AP_SW:
{
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
qDebug() << "get myListWidget failed!";
return;
}
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
if(DEV_MNG_NET_WIFI_SW == row){
bool setting_value = netCfg.cfg.enable;
QString que = (setting_value ? tr("您确定要禁用无线网络吗?") : tr("您确定要启用无线网络吗?"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
setting_value = static_cast<bool>(!setting_value);
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWifiEnable(setting_value)){
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
if(setting_value){
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_ASSIGN);
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_SEARCH);
controlListWidgetItemShow(netCfg.enableAp, DEV_MNG_NET_AP_SW);
controlListWidgetItemShow(netCfg.enableAp, DEV_MNG_NET_AP_PWD);
if(!netCfg.enableAp){
wifiSearch();
}
}else {
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_ASSIGN);
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_SEARCH);
controlListWidgetItemShow(false, DEV_MNG_NET_AP_SW);
controlListWidgetItemShow(false, DEV_MNG_NET_AP_PWD);
clearSsidList();
}
}else {
InfoDialog(tr("设置无线网络失败,请重试!"), parent()->parent()).exec();
}
}else if(DEV_MNG_NET_AP_SW == row){
bool setting_value = netCfg.enableAp;
QString que = (setting_value ? tr("您确定要关闭AP模式吗") : tr("您确定要启用AP模式吗"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
setting_value = static_cast<bool>(!setting_value);
if(setting_value && strlen(netCfg.apPwd) == 0){
do{
LineEditInputDialog dlg(tr("热点密码"), parent()->parent());
if(dlg.exec() == QDialog::Accepted){
const QString strInput = dlg.getRow(0);
if(strInput.length() >= 8 && strInput.length() <= 16){
snprintf(netCfg.apPwd, sizeof(netCfg.apPwd), strInput.toStdString().c_str());
break;
}else{
InfoDialog(tr("密码长度为8-16位字符"), parent()->parent()).exec();
}
}else{
return;
}
}while(true);
}
netCfg.enableAp = setting_value;
netCfg.isAPCfg = true;
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
if(netCfg.enableAp){
clearSsidList();
}
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_ASSIGN);
controlListWidgetItemShow(!netCfg.enableAp, DEV_MNG_NET_WIFI_SEARCH);
auto wdgIp = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_AP_PWD)));
if (wdgIp != nullptr) {
wdgIp->updateLabel(netCfg.apPwd);
}
controlListWidgetItemShow(netCfg.enableAp, DEV_MNG_NET_AP_PWD);
InfoDialog(tr("设置成功!"), parent()->parent()).exec();
}else {
InfoDialog(tr("设置失败,请重试!"), parent()->parent()).exec();
}
}
}
break;
case DEV_MNG_NET_WIFI_ASSIGN:
{
WifiAccPointDialog accPointDlg(parent()->parent());
//accPointDlg.fillRow(0, "RW-5F"); //TODO debug
//accPointDlg.fillRow(1, "RW@sz=B103#");
if(accPointDlg.exec() == QDialog::Accepted)
{
#ifndef DEBUG_MODE
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
netCfg.cfg.type = 1;
snprintf(netCfg.ssid, sizeof (netCfg.ssid), accPointDlg.getRow(0).toStdString().c_str());
snprintf(netCfg.encType, sizeof (netCfg.encType), accPointDlg.getEncType().toStdString().c_str());
snprintf(netCfg.pwd, sizeof (netCfg.pwd), accPointDlg.getRow(1).toStdString().c_str());
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
//InfoDialog(tr("设置成功!"), parent()->parent()).exec();
bool updateSsidList = false;
do{
stNetWire netWireCfg;
memset(reinterpret_cast<char*>(&netWireCfg), 0, sizeof(stNetWire));
if(0 != m_backstageIf->getNetWireCfg(netWireCfg)){
break;
}
if(!netWireCfg.cfg.enable){
updateSsidList = true;
break;
}
QuestionDialog dlg(tr("无线网络连接成功,是否禁用有线网络?"), parent()->parent());
if(QDialog::Accepted == dlg.exec()){
if(0 == m_backstageIf->setNetWireEnable(false)){
updateSsidList = true;
}else{
InfoDialog(tr("禁用有线网络失败,请重试!"), parent()->parent()).exec();
}
}
}while(0);
if(updateSsidList){
clearSsidList();
QListWidgetItem* pItem = new QListWidgetItem(m_listWidget);
QWidget* wifiListwidget = new WifiListWidget(netCfg.ssid, true, "none" != QString(netCfg.encType), -1, true, m_listWidget);
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->setItemWidget(pItem, wifiListwidget);
}
}else {
InfoDialog(tr("设置无线网络失败,请重试!"), parent()->parent()).exec();
}
#endif
}
}
break;
case DEV_MNG_NET_WIFI_SEARCH:
wifiSearch();
break;
case DEV_MNG_NET_AP_PWD:{
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
do{
LineEditInputDialog dlg(tr("热点密码"), parent()->parent());
if(dlg.exec() == QDialog::Accepted){
const QString strInput = dlg.getRow(0);
if(strInput.length() >= 8 && strInput.length() <= 16){
snprintf(netCfg.apPwd, sizeof(netCfg.apPwd), strInput.toStdString().c_str());
break;
}else{
InfoDialog(tr("密码长度为8-16位字符"), parent()->parent()).exec();
}
}else{
return;
}
}while(true);
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
auto wdgIp = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_AP_PWD)));
if (wdgIp != nullptr) {
wdgIp->updateLabel(netCfg.apPwd);
}
InfoDialog(tr("设置成功!"), parent()->parent()).exec();
}else {
InfoDialog(tr("设置失败,请重试!"), parent()->parent()).exec();
}
}break;
default:
if(row >= m_ssidPosIndex && row < m_listWidget->count()){
WifiListWidget* wifiWdt = dynamic_cast<WifiListWidget*>(m_listWidget->itemWidget(item));
if(wifiWdt == nullptr){
qDebug() << "get WifiListWidget failed!";
return;
}
if(wifiWdt->isConnected() || wifiWdt->isTargetNet()){
emit signalShowPage(settingUiDevMngNetWifiAccPoint::m_pageIndex, wifiWdt->getSsid());
}
else {
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(wifiWdt->getLockStatus()){
PasswordDialog pwd_check(wifiWdt->getSsid(), tr("请输入密码"), UiConfig::NO_OPERATION_OVERTIME_RETURN * 1000, parent()->parent()); //TODO, "RW@sz=B103#"
int ret = pwd_check.exec();
if(QDialog::Accepted == ret){
if(m_backstageIf){
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
netCfg.cfg.type = 1;
snprintf(netCfg.encType, sizeof (netCfg.encType), "wpa");
snprintf(netCfg.ssid, sizeof (netCfg.ssid), wifiWdt->getSsid().toStdString().c_str());
snprintf(netCfg.pwd, sizeof (netCfg.pwd), pwd_check.getPwd().toStdString().c_str());
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
//InfoDialog(tr("连接成功!"), parent()->parent()).exec();
bool updateConnectionFlag = false;
do{
stNetWire netWireCfg;
memset(reinterpret_cast<char*>(&netWireCfg), 0, sizeof(stNetWire));
if(0 != m_backstageIf->getNetWireCfg(netWireCfg)){
break;
}
if(!netWireCfg.cfg.enable){
updateConnectionFlag = true;
break;
}
QuestionDialog dlg(tr("无线网络连接成功,是否禁用有线网络?"), parent()->parent());
if(QDialog::Accepted == dlg.exec()){
if(0 == m_backstageIf->setNetWireEnable(false)){
updateConnectionFlag = true;
}
else{
InfoDialog(tr("禁用有线网络失败,请重试!"), parent()->parent()).exec();
}
}
}
while(0);
if(updateConnectionFlag){
//clean connected wifi flag
for (int i = m_ssidPosIndex; i < m_listWidget->count(); i++) {
WifiListWidget* wifi = dynamic_cast<WifiListWidget*>(m_listWidget->itemWidget(m_listWidget->item(i)));
if(wifi == nullptr){
qDebug() << "get WifiListWidget failed!";
break;
}
if(wifi->isConnected() || wifi->isTargetNet()){
wifi->clearStatus();
}
}
wifiWdt->updateStatus(true);
}
}
else {
InfoDialog(tr("连接无线网络失败,请重试!"), parent()->parent()).exec();
}
}
}
}
else {
netCfg.cfg.enable = true;
netCfg.cfg.type = 1;
snprintf(netCfg.ssid, sizeof (netCfg.ssid), wifiWdt->getSsid().toStdString().c_str());
snprintf(netCfg.encType, sizeof (netCfg.encType), "none");
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
InfoDialog(tr("连接成功!"), parent()->parent()).exec();
}
else {
InfoDialog(tr("连接无线网络失败,请重试!"), parent()->parent()).exec();
}
}
}
}
break;
}
}
//void settingUiDevMngNetWifi::slotShowSsidList()
//{
//showSsidList();
//}
void settingUiDevMngNetWifi::clearSsidList()
{
int itemQty = m_listWidget->count();
qDebug() << "clearSsidList itemQty:" << itemQty;
for(int i=0; i<itemQty - m_ssidPosIndex; i++){
QListWidgetItem* pItem = m_listWidget->takeItem(m_ssidPosIndex);
delete pItem;
}
}
int settingUiDevMngNetWifiAccPoint::m_pageIndex = 0;
settingUiDevMngNetWifiAccPoint::settingUiDevMngNetWifiAccPoint(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("连接此网络"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("忽略此网络"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("自动获取"), "", myListWidget::enPropertySwitch),
SetOpn(tr("手动配置"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("设备IP"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyNull),
SetOpn(tr("子网掩码"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyNull),
SetOpn(tr("设备网关"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyNull),
SetOpn(tr("DNS服务器"), "xxx.xxx.xxx.xxx", myListWidget::enPropertyNull)
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngNetWifiAccPoint()";
}
settingUiDevMngNetWifiAccPoint::~settingUiDevMngNetWifiAccPoint()
{
qDebug() << "~settingUiDevMngNetWifiAccPoint()";
}
void settingUiDevMngNetWifiAccPoint::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
//reset();
}
void settingUiDevMngNetWifiAccPoint::reset()
{
if(nullptr == m_backstageIf){
return;
}
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case DEV_MNG_NET_WIFI_AP_CONNECT:
break;
case DEV_MNG_NET_WIFI_AP_FORGET:
break;
case DEV_MNG_NET_WIFI_AP_DHCP:
{
bool switch_option = false;
if(DEV_MNG_NET_WIFI_AP_DHCP == i){
switch_option = netCfg.cfg.type;
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_NET_WIFI_AP_MAN_CFG:
break;
case DEV_MNG_NET_WIFI_AP_IP:
str = netCfg.cfg.ip;
break;
case DEV_MNG_NET_WIFI_AP_MASK:
str = netCfg.cfg.mask;
break;
case DEV_MNG_NET_WIFI_AP_GW:
str = netCfg.cfg.gw;
break;
case DEV_MNG_NET_WIFI_AP_DNS:
str = netCfg.cfg.dns;
break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(!netCfg.isConnected, DEV_MNG_NET_WIFI_AP_CONNECT);
controlListWidgetItemShow(!netCfg.cfg.type, DEV_MNG_NET_WIFI_AP_MAN_CFG);
}
bool settingUiDevMngNetWifiAccPoint::setStaticNetworkPara(const stNetWifi& curNetCfg)
{
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
#if 1
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return false;
}
#else
netCfg.cfg.enable = true;
#endif
netCfg.cfg.type = 0;
bool ret = false;
bool settingFailed = true;
do{
QStringList strs;
strs << config[DEV_MNG_NET_WIFI_AP_IP].m_sOpn
<< config[DEV_MNG_NET_WIFI_AP_MASK].m_sOpn
<< config[DEV_MNG_NET_WIFI_AP_GW].m_sOpn
<< config[DEV_MNG_NET_WIFI_AP_DNS].m_sOpn;
IpInputBarDialog dlg(strs, {true, true, false, false}, {false, true, false, false}, parent()->parent());
#if 0
dlg.fillRow(0, curNetCfg.cfg.ip);
dlg.fillRow(1, curNetCfg.cfg.mask);
dlg.fillRow(2, curNetCfg.cfg.gw);
dlg.fillRow(3, curNetCfg.cfg.dns);
#endif
if (dlg.exec() == QDialog::Accepted) {
#if 0
int i = 0;
for(i=0; i<4; i++){
if(i <= 1 && "" == dlg.getRow(i)){
InfoDialog(0 == i ? tr("IP设置不能为空") : tr("子网掩码设置不能为空!"), parent()->parent()).exec();
break;
}
}
#endif
strcpy(netCfg.cfg.ip, dlg.getRow(0).toStdString().c_str());
strcpy(netCfg.cfg.mask, dlg.getRow(1).toStdString().c_str());
strcpy(netCfg.cfg.gw, dlg.getRow(2).toStdString().c_str());
strcpy(netCfg.cfg.dns, dlg.getRow(3).toStdString().c_str());
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if (0 == m_backstageIf->setNetWifiCfg(netCfg)) {
settingFailed = false;
auto wdgIp = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_IP)));
if (wdgIp != nullptr) {
wdgIp->updateLabel(netCfg.cfg.ip);
}
auto wdgMask =
dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_MASK)));
if (wdgMask != nullptr) {
wdgMask->updateLabel(netCfg.cfg.mask);
}
auto wdgGw = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_GW)));
if (wdgGw != nullptr) {
wdgGw->updateLabel(netCfg.cfg.gw);
}
auto wdgDns = dynamic_cast<myListWidget *>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_DNS)));
if (wdgDns != nullptr) {
wdgDns->updateLabel(netCfg.cfg.dns);
}
ret = true;
} else {
InfoDialog(tr("设置无线网络失败,请重试!"), parent()->parent()).exec();
}
} else {
settingFailed = false;
}
}while(settingFailed);
return ret;
}
void settingUiDevMngNetWifiAccPoint::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
stNetWifi netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNetWifi));
#ifndef DEBUG_MODE
if(0 != m_backstageIf->getNetWifiCfg(netCfg)){
InfoDialog(tr("获取无线网络配置失败,请重试!"), parent()->parent()).exec();
return;
}
#endif
switch(row){
case DEV_MNG_NET_WIFI_AP_CONNECT:
{
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNetWifiCfg(netCfg)){
stNetWire netWireCfg;
memset(reinterpret_cast<char*>(&netWireCfg), 0, sizeof(stNetWire));
if(0 != m_backstageIf->getNetWireCfg(netWireCfg)){
break;
}
if(!netWireCfg.cfg.enable){
emit signalUpdateConnectionStatus(netCfg.ssid, true);
break;
}
QuestionDialog dlg(tr("无线网络连接成功,是否禁用有线网络?"), parent()->parent());
if(QDialog::Accepted == dlg.exec()){
if(0 == m_backstageIf->setNetWireEnable(false)){
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_AP_CONNECT);
emit signalUpdateConnectionStatus(netCfg.ssid, true);
}
else{
InfoDialog(tr("禁用有线网络失败,请重试!"), parent()->parent()).exec();
}
}
}
else {
InfoDialog(tr("连接无线网络失败,请重试!"), parent()->parent()).exec();
}
}
break;
case DEV_MNG_NET_WIFI_AP_FORGET:
{
#ifndef DEBUG_MODE
QuestionDialog dlg(tr("您确定要忽略此网络吗?"), parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->claerNetWifiCfg()){
//InfoDialog(tr("设置成功!"), parent()->parent()).exec();
emit signalUpdateConnectionStatus(netCfg.ssid, false);
emit signalReturn();
}
else {
InfoDialog(tr("设置无线网络失败,请重试!"), parent()->parent()).exec();
}
#endif
}
break;
case DEV_MNG_NET_WIFI_AP_DHCP:
{
bool setting_value = false;
QString que;
#ifndef DEBUG_MODE
if(DEV_MNG_NET_WIFI_AP_DHCP == row){
setting_value = static_cast<bool>(netCfg.cfg.type);
que = (setting_value ? tr("您确定要关闭自动获取吗?") : tr("您确定要打开自动获取吗?"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
if(setting_value){ //is dhcp now, need to input static network config
if(!setStaticNetworkPara(netCfg)){
break;
}
}
}
#endif
setting_value = static_cast<bool>(!setting_value);
#ifndef DEBUG_MODE
if(DEV_MNG_NET_WIFI_AP_DHCP == row){
int ret = 0;
if(setting_value){ //switch from static to dhcp
netCfg.cfg.type = static_cast<int>(setting_value);
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
ret = m_backstageIf->setNetWifiCfg(netCfg);
if(0 == ret){ //refresh
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
myListWidget* wdgIp = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_IP)));
if(wdgIp != nullptr){
wdgIp->updateLabel("");
}
myListWidget* wdgMask = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_MASK)));
if(wdgMask != nullptr){
wdgMask->updateLabel("");
}
myListWidget* wdgGw = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_GW)));
if(wdgGw != nullptr){
wdgGw->updateLabel("");
}
myListWidget* wdgDns = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_WIFI_AP_DNS)));
if(wdgDns != nullptr){
wdgDns->updateLabel("");
}
}
else {
InfoDialog(tr("设置无线网络失败,请重试!"), parent()->parent()).exec();
}
}
else {
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
}
if(0 == ret){
if(setting_value){
controlListWidgetItemShow(false, DEV_MNG_NET_WIFI_AP_MAN_CFG);
}
else {
controlListWidgetItemShow(true, DEV_MNG_NET_WIFI_AP_MAN_CFG);
}
}
}
#endif
}
break;
case DEV_MNG_NET_WIFI_AP_MAN_CFG:
setStaticNetworkPara(netCfg);
break;
default:
break;
}
}
int settingUiDevMngNet4G::m_pageIndex = 0;
settingUiDevMngNet4G::settingUiDevMngNet4G(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("启用"), "", myListWidget::enPropertySwitch),
SetOpn(tr("SIM卡信息"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("重启4G网络"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1 | myListWidget::enPropertyRedWord))
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngNet4G()";
}
settingUiDevMngNet4G::~settingUiDevMngNet4G()
{
qDebug() << "~settingUiDevMngNet4G()";
}
void settingUiDevMngNet4G::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
//reset();
}
void settingUiDevMngNet4G::reset()
{
if(nullptr == m_backstageIf){
return;
}
stNet4G netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNet4G));
if(0 != m_backstageIf->getNet4GCfg(netCfg)){
InfoDialog(tr("获取4G网络配置失败请重试"), parent()->parent()).exec();
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case DEV_MNG_NET_4G_SW:
{
bool switch_option = false;
if(DEV_MNG_NET_4G_SW == i){
switch_option = netCfg.enable;
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case DEV_MNG_NET_4G_PROVIDER:
if(netCfg.provider < net4GProvider.size()){
str = net4GProvider[netCfg.provider];
}
break;
case DEV_MNG_NET_4G_REBOOT:
break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(netCfg.enable, DEV_MNG_NET_4G_PROVIDER);
controlListWidgetItemShow(netCfg.enable, DEV_MNG_NET_4G_REBOOT);
}
void settingUiDevMngNet4G::slotItemClicked(QListWidgetItem* item)
{
if(nullptr == m_backstageIf){
#ifndef DEBUG_MODE
return;
#endif
}
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
stNet4G netCfg;
memset(reinterpret_cast<char*>(&netCfg), 0, sizeof(stNet4G));
if(0 != m_backstageIf->getNet4GCfg(netCfg)){
InfoDialog(tr("获取4G网络配置失败请重试"), parent()->parent()).exec();
return;
}
switch(row){
case DEV_MNG_NET_4G_SW:
{
bool setting_value = false;
QString que;
if(DEV_MNG_NET_4G_SW == row){
setting_value = netCfg.enable;
que = (setting_value ? tr("您确定要禁用4G网络吗") : tr("您确定要启用4G网络吗"));
QuestionDialog dlg(que, parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
setting_value = static_cast<bool>(!setting_value);
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->setNet4GEnable(setting_value)){
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
controlListWidgetItemShow(setting_value, DEV_MNG_NET_4G_PROVIDER);
controlListWidgetItemShow(setting_value, DEV_MNG_NET_4G_REBOOT);
if(setting_value){
if(0 == m_backstageIf->getNet4GCfg(netCfg)){
myListWidget* wdtProvider = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(DEV_MNG_NET_4G_PROVIDER)));
if(nullptr == wdtProvider){
return;
}
QString provider;
if(netCfg.provider < net4GProvider.size()){
provider = net4GProvider[netCfg.provider];
}
wdtProvider->updateLabel(provider);
}
else{
InfoDialog(tr("获取4G网络配置失败请重试"), parent()->parent()).exec();
return;
}
}
}
else {
InfoDialog(tr("设置4G网络失败请重试"), parent()->parent()).exec();
}
}
}
break;
case DEV_MNG_NET_4G_PROVIDER:
break;
case DEV_MNG_NET_4G_REBOOT:
{
#ifndef DEBUG_MODE
QuestionDialog dlg(tr("您确定要重启4G网络吗"), parent()->parent());
if(QDialog::Accepted != dlg.exec()){
break;
}
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
if(0 == m_backstageIf->reboot4G()){
InfoDialog(tr("重启成功!"), parent()->parent()).exec();
}
else {
InfoDialog(tr("重启4G网络失败请重试"), parent()->parent()).exec();
}
#endif
}
break;
default:
break;
}
}
int settingUiDevMngBt::m_pageIndex = 0;
settingUiDevMngBt::settingUiDevMngBt(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("启用"), "", myListWidget::enPropertySwitch),
SetOpn(tr("蓝牙音箱"), "bt speaker", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("蓝牙门锁"), "bt lock", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1))
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngBt()";
}
void settingUiDevMngBt::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
}
void settingUiDevMngBt::reset()
{
BluetoothStat_t bluetoothStat;
m_backstageIf->getBtAllInfo(bluetoothStat);
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case DEV_MNG_BT_ENABLE:
wdt->updateIcon(bluetoothStat.isEnable ? ":/res/image/on.png" : ":/res/image/off.png");
break;
case DEV_MNG_BT_SPK:
break;
case DEV_MNG_BT_LOCK:
break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(bluetoothStat.isEnable, DEV_MNG_BT_SPK);
controlListWidgetItemShow(bluetoothStat.isEnable, DEV_MNG_BT_LOCK);
}
void settingUiDevMngBt::slotItemClicked(QListWidgetItem* item)
{
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
switch(row){
case DEV_MNG_BT_ENABLE:
{
MsgDialog msgdlg0(tr("处理中,请稍候..."), parent()->parent());
msgdlg0.show();
QCoreApplication::processEvents();
BluetoothStat_t bluetoothStat;
m_backstageIf->getBtAllInfo(bluetoothStat);
bool setting_value = bluetoothStat.isEnable;
setting_value = static_cast<bool>(!setting_value);
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
m_backstageIf->btSetSwitch(setting_value);
controlListWidgetItemShow(setting_value, DEV_MNG_BT_SPK);
controlListWidgetItemShow(setting_value, DEV_MNG_BT_LOCK);
}
break;
case DEV_MNG_BT_SPK:
emit signalShowPage(settingUiDevMngBtSpk::m_pageIndex);
break;
case DEV_MNG_BT_LOCK:
emit signalShowPage(settingUiDevMngBtLock::m_pageIndex);
break;
default:
break;
}
}
int settingUiDevMngBtSpk::m_pageIndex = 0;
settingUiDevMngBtSpk::settingUiDevMngBtSpk(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
//SetOpn(tr("启用"), "", myListWidget::enPropertySwitch),
SetOpn(tr("设备名称"), "Bluetooth-cai", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow)),
SetOpn(tr("已配对设备"), "", myListWidget::enPropertyNull),
SetOpn(tr("可用设备"), "", myListWidget::enPropertyNull)
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngBtSpk()";
m_pairedItemCnt = 0;
m_availdItemCnt = 0;
m_btDevName = "Bluetooth";
m_btIsEnable = false;
QListWidgetItem* pItem;
myListWidget* wdt;
pItem = m_listWidget->item(DEV_MNG_BULETOOTH_AVAILABLE_DEV);
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(":/res/image/refresh_large.png", 40, 40);
}
settingUiDevMngBtSpk::~settingUiDevMngBtSpk()
{
qDebug() << "~settingUiDevMngBtSpk()";
}
void settingUiDevMngBtSpk::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
}
void settingUiDevMngBtSpk::reset()
{
if(nullptr == m_backstageIf){
return;
}
BluetoothStat_t bluetoothStat;
m_backstageIf->getBtAllInfo(bluetoothStat);
m_btDevName = bluetoothStat.devName;
m_btIsEnable = bluetoothStat.isEnable;
//m_btPairedList = bluetoothStat.pairedDev;
//m_btAvailList = bluetoothStat.availableDev;
//bool isBluetoothEnable = m_backstageIf->getParamBluetoothEnable();
QListWidgetItem* pItem;
myListWidget* wdt;
#if 0
pItem = m_listWidget->item(DEV_MNG_BULETOOTH_ENABLE);
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(m_btIsEnable ? ":/res/image/on.png" : ":/res/image/off.png");
#endif
//set name text
pItem = m_listWidget->item(DEV_MNG_BULETOOTH_DEVNAME);
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateLabel(QString::fromStdString(m_btDevName));
if(1) //m_btIsEnable
{
//1.show fixed item
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_DEVNAME);
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_HISTORY_DEV);
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt);
//2.reset item
resetPaireItem(bluetoothStat.pairedDev);
QCoreApplication::processEvents();//提前处理ui
//下面的操作耗时,增加提示
MsgDialog msgdlg(tr("搜索中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
// list<BluetoothDev_t> btAvailList;
// m_backstageIf->btScan(btAvailList);
resetAvailItem(bluetoothStat.availableDev/*btAvailList*/);
}else
{
//1.clear item
clearPaireItem();
clearAvailItem();
//2.hide fixed item
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_DEVNAME);
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_HISTORY_DEV);
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt);
}
}
void settingUiDevMngBtSpk::clearPaireItem()
{
for(int i=0; i<m_pairedItemCnt; i++)
{
#if 0
QListWidgetItem* pItem2 = m_listWidget->item(DEV_MNG_BULETOOTH_HISTORY_DEV + 1);
BtListWidget *wdt = dynamic_cast<BtListWidget*>(m_listWidget->itemWidget(pItem2));
BluetoothDev_t btDev;
wdt->getDevInfo(btDev);
LOGD("m_pairedItemCnt=%d: %s, %s, %d", m_pairedItemCnt, btDev.id.c_str(), btDev.name.c_str(), btDev.devStat);
#endif
QListWidgetItem* pItem = m_listWidget->takeItem(DEV_MNG_BULETOOTH_HISTORY_DEV + 1);
delete pItem;
}
m_pairedItemCnt = 0;
}
void settingUiDevMngBtSpk::clearAvailItem()
{
for(int i=0; i<m_availdItemCnt; i++)
{
QListWidgetItem* pItem = m_listWidget->takeItem(DEV_MNG_BULETOOTH_AVAILABLE_DEV + 1 + m_pairedItemCnt);
delete pItem;
}
m_availdItemCnt = 0;
}
void settingUiDevMngBtSpk::addPairedItem(BluetoothDev_t &btDev)
{
QListWidgetItem* pItem = new QListWidgetItem();
BtListWidget* btListwidget = new BtListWidget(btDev/*, true*/);
connect(btListwidget, SIGNAL(signalClickSet(BluetoothDev_t)), this, SLOT(slotBtDevSet(BluetoothDev_t)));
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->insertItem(m_pairedItemCnt + DEV_MNG_BULETOOTH_HISTORY_DEV + 1, pItem);
m_listWidget->setItemWidget(pItem, btListwidget);
m_pairedItemCnt++;
LOGD("m_pairedItemCnt=%d: %s, %s, %d", m_pairedItemCnt, btDev.id.c_str(), btDev.name.c_str(), btDev.devStat);
}
void settingUiDevMngBtSpk::addPairedItem(BtListWidget *pBtListWidget)
{
QListWidgetItem* pItem = new QListWidgetItem();
connect(pBtListWidget, SIGNAL(signalClickSet(BluetoothDev_t)), this, SLOT(slotBtDevSet(BluetoothDev_t)));
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->insertItem(m_pairedItemCnt + DEV_MNG_BULETOOTH_HISTORY_DEV + 1, pItem);
m_listWidget->setItemWidget(pItem, pBtListWidget);
m_pairedItemCnt++;
}
void settingUiDevMngBtSpk::addPairedItem(list<BluetoothDev_t> &btDevList)
{
for(auto it = btDevList.begin(); it!=btDevList.end(); it++)
{
addPairedItem(*it);
}
}
void settingUiDevMngBtSpk::addAvailItem(BluetoothDev_t &btDev)
{
QListWidgetItem* pItem = new QListWidgetItem();
BtListWidget* btListwidget = new BtListWidget(btDev/*, false*/);
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->insertItem(m_availdItemCnt + DEV_MNG_BULETOOTH_AVAILABLE_DEV + 1 + m_pairedItemCnt, pItem);
m_listWidget->setItemWidget(pItem, btListwidget);
m_availdItemCnt++;
//LOGD("m_availdItemCnt=%d: %s, %s, %d", m_availdItemCnt, btDev.id.c_str(), btDev.name.c_str(), btDev.devStat);
}
void settingUiDevMngBtSpk::addAvailItem(BtListWidget *pBtListWidget)
{
QListWidgetItem* pItem = new QListWidgetItem();
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->insertItem(m_availdItemCnt + DEV_MNG_BULETOOTH_AVAILABLE_DEV + 1 + m_pairedItemCnt, pItem);
m_listWidget->setItemWidget(pItem, pBtListWidget);
m_availdItemCnt++;
}
void settingUiDevMngBtSpk::addAvailItem(list<BluetoothDev_t> &btDevList)
{
for(auto it = btDevList.begin(); it!=btDevList.end(); it++)
{
addAvailItem(*it);
}
}
int settingUiDevMngBtSpk::deletePairedItem(int row)
{
if(row > DEV_MNG_BULETOOTH_HISTORY_DEV &&
row <= DEV_MNG_BULETOOTH_HISTORY_DEV + m_pairedItemCnt)
{
QListWidgetItem* pItem = m_listWidget->takeItem(row);
delete pItem;
m_pairedItemCnt--;
return 0;
}else
{
return -1;
}
}
int settingUiDevMngBtSpk::deleteAvaidItem(int row)
{
if(row > DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt &&
row <= DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt + m_availdItemCnt)
{
QListWidgetItem* pItem = m_listWidget->takeItem(row);
delete pItem;
m_availdItemCnt--;
return 0;
}else
{
return -1;
}
}
void settingUiDevMngBtSpk::resetPaireItem(list<BluetoothDev_t> &btDevList)
{
//1.clear old item
clearPaireItem();
//2.add item
addPairedItem(btDevList);
}
void settingUiDevMngBtSpk::resetAvailItem(list<BluetoothDev_t> &btDevList)
{
//1.clear old item
clearAvailItem();
//2.add item
addAvailItem(btDevList);
}
void settingUiDevMngBtSpk::slotItemClicked(QListWidgetItem * item)
{
if(nullptr == m_backstageIf){
return;
}
int row = m_listWidget->currentRow();
LOGD("slotItemClicked: row=%d", row);
#if 0
if(row == DEV_MNG_BULETOOTH_ENABLE)
{
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
m_btIsEnable = !m_btIsEnable;
wdt->updateIcon(m_btIsEnable ? ":/res/image/on.png" : ":/res/image/off.png");
//下面的操作耗时,增加提示
MsgDialog msgdlg0(tr("处理中,请稍候..."), parent()->parent());
msgdlg0.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
m_backstageIf->btSetSwitch(m_btIsEnable);
if(m_btIsEnable)
{
//1.get bt info
BluetoothStat_t bluetoothStat;
m_backstageIf->getBtAllInfo(bluetoothStat);
m_btDevName = bluetoothStat.devName;
//2.set name text
QListWidgetItem* pItem_name = m_listWidget->item(DEV_MNG_BULETOOTH_DEVNAME);;
myListWidget* pWidget_name = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem_name));
pWidget_name->updateLabel(QString::fromStdString(m_btDevName));
//3.show fixed item
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_DEVNAME);
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_HISTORY_DEV);
controlListWidgetItemShow(true, DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt);
//4.reset item
resetPaireItem(bluetoothStat.pairedDev);
QCoreApplication::processEvents();//提前处理ui
//下面的操作耗时,增加提示
MsgDialog msgdlg1(tr("搜索中,请稍候..."), parent()->parent());
msgdlg1.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
// list<BluetoothDev_t> btAvailList;
// m_backstageIf->btScan(btAvailList);
resetAvailItem(bluetoothStat.availableDev);
}else
{
//1.clear item
clearPaireItem();
clearAvailItem();
//2.show fixed item
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_DEVNAME);
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_HISTORY_DEV);
controlListWidgetItemShow(false, DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt);
}
}else
#endif
if(row == DEV_MNG_BULETOOTH_DEVNAME)
{
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
//QString itemName = config[DEV_MNG_BULETOOTH_DEVNAME].m_sOpn;
QString itemName = "设备名称";
LineEditInputDialog dlg(itemName, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString setStr = dlg.getRow(0);
if(setStr.isEmpty())
{
InfoDialog(tr("设置有误,请重新输入!"), parent()->parent()).exec();
}else
{
wdt->updateLabel(setStr);
m_backstageIf->btSetName(setStr.toStdString());
}
}
}else if(row > DEV_MNG_BULETOOTH_HISTORY_DEV &&
row <= DEV_MNG_BULETOOTH_HISTORY_DEV + m_pairedItemCnt)
{
LOGD("click paired item");
BtListWidget* btListWidget = dynamic_cast<BtListWidget*>(m_listWidget->itemWidget(item));
if(btListWidget == nullptr){
return;
}
BluetoothDev_t btDev;
btListWidget->getDevInfo(btDev);
if(btDev.devStat == BlueToothDevStat_connected){
QString showText = tr("此操作将会断开您与以下设备的连接:<br>") + QString::fromStdString(btDev.name);
QuestionDialog dlg(showText, parent()->parent(), tr("确定"));
if(QDialog::Accepted == dlg.exec()){
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
//断开连接
m_backstageIf->btDisConnect(btDev.id);
//更改item状态为已配对
btDev.devStat = BlueToothDevStat_paired;
btListWidget->updateDev(btDev);
}
}else if(btDev.devStat == BlueToothDevStat_paired){
QString showText = tr("要与以下设备连接:<br>") + QString::fromStdString(btDev.name);
QuestionDialog dlg(showText, parent()->parent(), tr("连接"));
if(QDialog::Accepted == dlg.exec()){
//更改该item的状态为连接中...
btDev.devStat = BlueToothDevStat_connecting;
btListWidget->updateDev(btDev);
QCoreApplication::processEvents();//提前处理ui
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
//蓝牙连接
if(0 == m_backstageIf->btConnect(btDev.id))
{
//更改item状态为已连接
btDev.devStat = BlueToothDevStat_connected;
btListWidget->updateDev(btDev);
}else
{
//更改item状态为已匹配
btDev.devStat = BlueToothDevStat_paired;
btListWidget->updateDev(btDev);
//连接失败提示框
InfoDialog(tr("蓝牙连接失败,请重试!"), parent()->parent()).exec();
}
//蓝牙连接接口调用完,可能会导致其他已连接的蓝牙状态发生变化,所以这里重新获取已配对蓝牙列表
list<BluetoothDev_t> pairedDev;
m_backstageIf->getBtPairedDev(pairedDev);
resetPaireItem(pairedDev);
}
}
}else if(row == DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt)
{
//搜索刷新
LOGD("click refresh");
MsgDialog msgdlg(tr("搜索中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
list<BluetoothDev_t> btAvailList;
m_backstageIf->getBtAvailDev(btAvailList);
//m_backstageIf->btScan(btAvailList);
resetAvailItem(btAvailList);
}else if(row > DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt &&
row <= DEV_MNG_BULETOOTH_AVAILABLE_DEV + m_pairedItemCnt + m_availdItemCnt)
{
LOGD("click availd item");
BtListWidget* btListWidget = dynamic_cast<BtListWidget*>(m_listWidget->itemWidget(item));
if(btListWidget == nullptr){
return;
}
BluetoothDev_t btDev;
btListWidget->getDevInfo(btDev);
if(btDev.devStat == BlueToothDevStat_idle)
{
QString showText = tr("要与以下设备配对:<br>") + QString::fromStdString(btDev.name);
QuestionDialog dlg(showText, parent()->parent(), tr("配对"));
if(QDialog::Accepted == dlg.exec()){
//配对
//更改该item的状态为匹配中...
btDev.devStat = BlueToothDevStat_pairing;
btListWidget->updateDev(btDev);
QCoreApplication::processEvents();//提前处理ui
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
if(0 == m_backstageIf->btPaire(btDev.id))
{//success
//删除该item
deleteAvaidItem(row);
//在已配对设备添加一个连接中的item
btDev.devStat = BlueToothDevStat_connecting;
BtListWidget* newBtListwidget = new BtListWidget(btDev);
addPairedItem(newBtListwidget);
QCoreApplication::processEvents();//处理qt事件刷新ui
//蓝牙连接
if(0 == m_backstageIf->btConnect(btDev.id))
{
//更改item状态为已连接
btDev.devStat = BlueToothDevStat_connected;
newBtListwidget->updateDev(btDev);
}else
{
//更改item状态为已匹配
btDev.devStat = BlueToothDevStat_paired;
newBtListwidget->updateDev(btDev);
//连接失败提示框
InfoDialog(tr("蓝牙连接失败,请重试!"), parent()->parent()).exec();
}
//蓝牙连接接口调用完,可能会导致其他已连接的蓝牙状态发生变化,所以这里重新获取已配对蓝牙列表
list<BluetoothDev_t> pairedDev;
m_backstageIf->getBtPairedDev(pairedDev);
resetPaireItem(pairedDev);
}else
{//failed
//更改item状态为空闲
btDev.devStat = BlueToothDevStat_idle;
btListWidget->updateDev(btDev);
//配对失败提示框
InfoDialog(tr("蓝牙配对失败,请重试!"), parent()->parent()).exec();
}
}
}
}
}
void settingUiDevMngBtSpk::slotBtDevSet(BluetoothDev_t btDevInfo)
{
LOGD("slotBtDevSet");
emit signalClickSet(btDevInfo);
emit signalShowPage(settingUiDevMngBtSpkAccPoint::m_pageIndex, QString::fromStdString(btDevInfo.name));
}
int settingUiDevMngBtSpkAccPoint::m_pageIndex = 0;
settingUiDevMngBtSpkAccPoint::settingUiDevMngBtSpkAccPoint(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("重命名"), "xxx", myListWidget::enPropertyMoreArrow),
SetOpn(tr("取消配对"), "", myListWidget::enPropertyNull),
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngBtSpkAccPoint()";
}
settingUiDevMngBtSpkAccPoint::~settingUiDevMngBtSpkAccPoint()
{
}
void settingUiDevMngBtSpkAccPoint::setBackstageUiinterface(BackstageInterfaceForUi *interface)
{
m_backstageIf = interface;
//reset();
}
void settingUiDevMngBtSpkAccPoint::reset()
{
}
void settingUiDevMngBtSpkAccPoint::slotItemClicked(QListWidgetItem *item)
{
if(nullptr == m_backstageIf){
return;
}
int row = m_listWidget->currentRow();
LOGD("slotItemClicked: row=%d", row);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case DEV_MNG_BULETOOTH_ACCPOINTE_RENAME:
{
QString itemName = config[row].m_sOpn;
LineEditInputDialog dlg(itemName, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString setStr = dlg.getRow(0);
if(setStr.isEmpty())
{
InfoDialog(tr("设置有误,请重新输入!"), parent()->parent()).exec();
}else
{
wdt->updateLabel(setStr);
//重命名
m_backstageIf->btRenameDev(m_btDev.id, setStr.toStdString());
}
}
}
break;
case DEV_MNG_BULETOOTH_ACCPOINTE_CANCLE:
{
QuestionDialog dlg(tr("您确定要取消此设备的配对"), parent()->parent());
if(QDialog::Accepted == dlg.exec()){
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();//处理qt事件刷新ui
//取消配对
m_backstageIf->btDisPaire(m_btDev.id);
//回退页面
emit signalReturn();
}
}
break;
default:
break;
}
}
void settingUiDevMngBtSpkAccPoint::setAccPointInfo(const BluetoothDev_t &rBlueDev)
{
m_btDev = rBlueDev;
QListWidgetItem* pItem;
myListWidget* wdt;
pItem = m_listWidget->item(DEV_MNG_BULETOOTH_ACCPOINTE_RENAME);
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
wdt->updateLabel(QString::fromStdString(m_btDev.name));
}
int settingUiDevMngBtLock::m_pageIndex = 0;
settingUiDevMngBtLock::settingUiDevMngBtLock(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("启用"), "", myListWidget::enPropertySwitch),
SetOpn(tr("添加蓝牙门锁"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1))
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngBtLock()";
QListWidgetItem* pItem = m_listWidget->item(DEV_MNG_BT_LOCK_ADD);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(":/res/image/add3.png", 40, 40);
}
void settingUiDevMngBtLock::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
}
void settingUiDevMngBtLock::reset()
{
BtDoorLock cfg;
m_backstageIf->getBtLockCfg(cfg);
qDebug() << "cfg.qty:" << cfg.qty;
QListWidgetItem* pItem = m_listWidget->item(DEV_MNG_BT_LOCK_ENABLE);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(cfg.isEnable ? ":/res/image/on.png" : ":/res/image/off.png");
if(cfg.isEnable){
showBtLockList(cfg);
}
else{
clearBtLockList();
controlListWidgetItemShow(false, DEV_MNG_BT_LOCK_ADD);
}
}
void settingUiDevMngBtLock::slotItemClicked(QListWidgetItem* item)
{
BtDoorLock cfg;
m_backstageIf->getBtLockCfg(cfg);
qDebug() << "enable:" << cfg.isEnable;
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
switch(row){
case DEV_MNG_BT_LOCK_ENABLE:
{
MsgDialog msgdlg(tr("处理中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
cfg.isEnable = static_cast<bool>(!cfg.isEnable);
qDebug() << "now enable:" << cfg.isEnable;
wdt->updateIcon(cfg.isEnable ? ":/res/image/on.png" : ":/res/image/off.png");
controlListWidgetItemShow(cfg.isEnable, DEV_MNG_BT_LOCK_ADD);
if(0 == m_backstageIf->setBtLockCfg(cfg)){
if(cfg.isEnable){
showBtLockList(cfg);
}
else{
clearBtLockList();
}
}
}
break;
case DEV_MNG_BT_LOCK_ADD:
{
bool settingFailed = true;
QString posiInput;
QString macInput;
do{
QList<QString> strs;
strs << tr("厂商名称") << tr("房间名") << tr("MAC地址");
LineEditInputDialog dlg(strs, parent()->parent());
dlg.fillRow(0, "博雅讯", true);
dlg.fillRow(1, posiInput);
dlg.fillRow(2, macInput);
if(dlg.exec() == QDialog::Accepted){
posiInput = dlg.getRow(1);
macInput = dlg.getRow(2).toUpper();
qDebug() << "mac:" << macInput;
do{
if(posiInput.isEmpty()){
InfoDialog(tr("房间名不能为空!"), parent()->parent()).exec();
break;
}else if(posiInput.length() > 32){
InfoDialog(tr("房间名请控制在32个字符以内"), parent()->parent()).exec();
break;
}
bool macConflict = false;
for(int i=0; i<cfg.qty; i++){
if(macInput == cfg.mac.at(i).c_str()){
InfoDialog(tr("mac地址重复请检查"), parent()->parent()).exec();
macConflict = true;
break;
}
}
if(macConflict){
break;
}
cfg.manufacturer.push_back(1);
cfg.position.push_back(posiInput.toStdString());
cfg.mac.push_back(macInput.toStdString());
cfg.qty++;
if(0 == m_backstageIf->setBtLockCfg(cfg)){
addBtLock(posiInput);
controlListWidgetItemShow(cfg.qty < 5, DEV_MNG_BT_LOCK_ADD);
settingFailed = false;
}
}while(0);
}
else {
settingFailed = false;
}
}while(settingFailed);
}
break;
default:
if(row >= DEV_MNG_BT_LOCK_BUTT && row < (m_listWidget->count())){
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
emit signalShowPage(settingUiDevMngBtLockAccPoint::m_pageIndex, wdt->getOptionLabel());
emit signalCurrentLock(QString(cfg.mac.at(row - DEV_MNG_BT_LOCK_BUTT).c_str()));
}
break;
}
}
void settingUiDevMngBtLock::slotRefresh()
{
reset();
}
void settingUiDevMngBtLock::clearBtLockList()
{
int itemQty = m_listWidget->count();
qDebug() << "clearBtLockList itemQty:" << itemQty;
for(int i=0; i<itemQty - DEV_MNG_BT_LOCK_BUTT; i++){
QListWidgetItem* pItem = m_listWidget->takeItem(DEV_MNG_BT_LOCK_BUTT);
delete pItem;
}
}
void settingUiDevMngBtLock::addBtLock(const QString& position)
{
QListWidgetItem* pItem = new QListWidgetItem(m_listWidget);
myListWidget* lockWidget = new myListWidget(myListWidget::SetOpnCfg(position, "",
static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)), m_listWidget);
lockWidget->setLeftIcon(":/res/image/bt_lock.png", 40, 40);
pItem->setSizeHint(QSize(UiConfig::GetInstance()->getUiHeight() / 12, UiConfig::GetInstance()->getUiHeight() / 12));
m_listWidget->setItemWidget(pItem, lockWidget);
}
void settingUiDevMngBtLock::showBtLockList(const BtDoorLock& cfg)
{
clearBtLockList();
for(int i=0; i<cfg.qty; i++){
addBtLock(cfg.position.at(i).c_str());
}
controlListWidgetItemShow(cfg.qty < 5, DEV_MNG_BT_LOCK_ADD);
}
int settingUiDevMngBtLockAccPoint::m_pageIndex = 0;
settingUiDevMngBtLockAccPoint::settingUiDevMngBtLockAccPoint(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("门锁信息"), "", myListWidget::enPropertyMoreArrow),
SetOpn(tr("电量(0-100)"), "", myListWidget::enPropertyNull),
SetOpn(tr("删除门锁"), "", myListWidget::enPropertyRedWord)
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiDevMngBluetoothAccPoint()";
QListWidgetItem* pItem = m_listWidget->item(DEV_MNG_BT_LOCK_BATTERY);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(":/res/image/refresh_large.png", 40, 40);
pItem = m_listWidget->item(DEV_MNG_BT_LOCK_DELETE);
wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateIcon(":/res/image/del.png", 40, 40);
}
void settingUiDevMngBtLockAccPoint::setBackstageUiinterface(BackstageInterfaceForUi *interface)
{
m_backstageIf = interface;
}
void settingUiDevMngBtLockAccPoint::reset()
{
}
void settingUiDevMngBtLockAccPoint::slotItemClicked(QListWidgetItem *item)
{
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
BtDoorLock cfg;
m_backstageIf->getBtLockCfg(cfg);
switch(row){
case DEV_MNG_BT_LOCK_INFO:
{
bool settingFailed = true;
QString posiFillStr = m_position;
QString macFillStr = m_mac;
do{
QList<QString> strs;
strs << tr("产商名称") << tr("房间名") << tr("MAC地址");
LineEditInputDialog dlg(strs, parent()->parent());
dlg.fillRow(0, "博雅讯", true);
dlg.fillRow(1, posiFillStr);
dlg.fillRow(2, macFillStr);
if(dlg.exec() == QDialog::Accepted){
const QString posiInput = dlg.getRow(1);
const QString macInput = dlg.getRow(2).toUpper();
do{
posiFillStr = posiInput;
macFillStr = macInput;
qDebug() << "mac:" << macInput;
if(posiInput.isEmpty()){
InfoDialog(tr("房间名不能为空!"), parent()->parent()).exec();
break;
}else if(posiInput.length() > 32){
InfoDialog(tr("房间名请控制在32个字符以内"), parent()->parent()).exec();
break;
}
bool macConflict = false;
for(int i=0; i<cfg.qty; i++){
if(m_mac != macInput && macInput == cfg.mac.at(i).c_str()){
QString tip(tr("mac地址与"));
tip += cfg.position.at(i).c_str();
tip += tr("重复,请检查!");
InfoDialog(tip, parent()->parent()).exec();
macConflict = true;
break;
}
}
if(macConflict){
break;
}
for(int i=0; i<cfg.qty; i++){
if(m_mac == cfg.mac.at(i).c_str()){
cfg.manufacturer[i] = 1;
cfg.position[i] = posiInput.toStdString();
cfg.mac[i] = macInput.toStdString();
break;
}
}
if(0 == m_backstageIf->setBtLockCfg(cfg)){
m_manufacturer = 0;
m_position = posiInput;
m_mac = macInput;
emit signalUpdataTitle(m_position);
settingFailed = false;
}
}while(0);
}
else {
settingFailed = false;
}
}while(settingFailed);
}
break;
case DEV_MNG_BT_LOCK_BATTERY:
getRemainingBatPwr();
break;
case DEV_MNG_BT_LOCK_DELETE:
{
QuestionDialog dlg(tr("您确定要删除此门锁吗?"), parent()->parent(), tr("删除"));
if(QDialog::Accepted == dlg.exec()){
for(int i=0; i<cfg.qty; i++){
qDebug() << "i:" << i;
if(m_mac == cfg.mac.at(i).c_str()){
qDebug() << "cur mac:" << cfg.mac.at(i).c_str();
cfg.manufacturer.erase(cfg.manufacturer.begin() + i);
cfg.position.erase(cfg.position.begin() + i);
cfg.mac.erase(cfg.mac.begin() + i);
cfg.qty--;
break;
}
}
qDebug() << "save cfg, qty:" << cfg.qty;
if(0 == m_backstageIf->setBtLockCfg(cfg)){
emit signalRefresh();
}
}
}
break;
default:
break;
}
}
void settingUiDevMngBtLockAccPoint::slotCurrentLock(const QString& lock)
{
qDebug() << "lock mac:" << lock;
BtDoorLock cfg;
m_backstageIf->getBtLockCfg(cfg);
for(int i=0; i<cfg.qty; i++){
if(lock == cfg.mac.at(i).c_str()){
m_manufacturer = cfg.manufacturer.at(i);
m_position = cfg.position.at(i).c_str();
m_mac = cfg.mac.at(i).c_str();
break;
}
}
getRemainingBatPwr();
}
void settingUiDevMngBtLockAccPoint::getRemainingBatPwr()
{
MsgDialog msgdlg(tr("电量获取中,请稍候..."), parent()->parent());
msgdlg.show();
QCoreApplication::processEvents();
int pwr = m_backstageIf->getBtLockRemainingBatPwr(m_mac.toStdString());
QListWidgetItem* pItem = m_listWidget->item(DEV_MNG_BT_LOCK_BATTERY);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
wdt->updateLabel(pwr >= 0 ? QString::number(pwr) : tr("(未知)"));
}