2022-01-04 18:11:48 +08:00
# include " mainwindow.h "
2023-04-18 14:14:46 +08:00
# include "gutil/qgui.h"
2024-08-07 18:18:37 +08:00
# include "main.h"
2023-08-01 11:42:41 +08:00
# include "devicepanel.h"
# include "gutil/qnetwork.h"
2023-04-18 14:14:46 +08:00
# include "device/upgradeapkdialog.h"
2025-12-30 17:22:43 +08:00
# include "gutil/qwaitingdlg.h"
2022-08-25 18:37:24 +08:00
# include <QColorDialog>
# include <QDesktopServices>
# include <QMenu>
# include <QMessageBox>
2022-01-04 18:11:48 +08:00
# include <QProcess>
2022-08-25 18:37:24 +08:00
# include <QSettings>
2022-09-28 18:21:57 +08:00
# include <QButtonGroup>
2022-09-30 18:08:39 +08:00
# include <QHeaderView>
2023-04-19 14:42:06 +08:00
# include <QStandardPaths>
2023-05-18 18:24:40 +08:00
# include <QDialogButtonBox>
2023-08-01 11:42:41 +08:00
# include <QToolButton>
2023-09-19 11:49:20 +08:00
# include <QDir>
# include <QCoreApplication>
2024-08-07 18:18:37 +08:00
# include <QOpenGLWidget>
2022-08-25 18:37:24 +08:00
2025-12-30 17:22:43 +08:00
# include <QNetworkConfigurationManager>
# include <Windows.h>
# include <WLANAPI.h>
# include <QDebug>
2022-09-06 23:40:02 +08:00
extern QPoint gPlayPos ;
2022-08-25 18:37:24 +08:00
2024-08-07 18:18:37 +08:00
QString gApkHome ;
2025-05-06 18:28:05 +08:00
int gProgWidth = 512 , gProgHeight = 256 ;
2024-08-07 18:18:37 +08:00
bool gVideoCompress = false ;
bool gVideoTranscoding = false ;
bool gTextAntialiasing = false ;
bool gWidthSplit = false ;
int gSendBatch = 5 ;
bool gHideDetect = false ;
bool gShowIP = true ;
bool gShowAlias = false ;
bool gShowLora = false ;
Tick * gTick ;
2022-08-25 18:37:24 +08:00
class ImgBtn : public QToolButton {
public :
ImgBtn ( ) {
auto policy = sizePolicy ( ) ;
policy . setHorizontalPolicy ( QSizePolicy : : Preferred ) ;
setSizePolicy ( policy ) ;
connect ( this , & QToolButton : : toggled , this , [ this ] ( bool checked ) {
setIcon ( icons [ checked ? 1 : 0 ] ) ;
} ) ;
}
void setIcons ( const QIcon & unchecked , const QIcon & checked ) {
setIcon ( unchecked ) ;
icons [ 0 ] = unchecked ;
icons [ 1 ] = checked ;
}
protected :
2023-04-19 14:42:06 +08:00
# if(QT_VERSION_MAJOR > 5)
void enterEvent ( QEnterEvent * ) override {
# else
2022-08-25 18:37:24 +08:00
void enterEvent ( QEvent * ) override {
2023-04-19 14:42:06 +08:00
# endif
2022-08-25 18:37:24 +08:00
if ( this - > isChecked ( ) ) return ;
setIcon ( icons [ 1 ] ) ;
}
void leaveEvent ( QEvent * ) override {
if ( this - > isChecked ( ) ) return ;
setIcon ( icons [ 0 ] ) ;
}
QIcon icons [ 2 ] ;
} ;
MainWindow : : MainWindow ( QWidget * parent ) : BaseWin ( parent ) {
2023-04-18 14:14:46 +08:00
setAttribute ( Qt : : WA_AlwaysShowToolTips ) ;
2023-08-01 11:42:41 +08:00
auto ft = font ( ) ;
ft . setPixelSize ( 14 ) ;
setFont ( ft ) ;
auto menuLang = new QMenu ;
2024-06-06 21:55:36 +08:00
langGrp = new QActionGroup ( menuLang ) ;
connect ( menuLang , & QMenu : : triggered , this , [ this ] ( QAction * action ) {
auto lanName = action - > objectName ( ) ;
2025-12-30 17:22:43 +08:00
qInfo ( ) < < " load QT Translator " < < lanName < < qtTranslator . load ( " qt_ " + lanName , QApplication : : applicationDirPath ( ) + " /translations " ) ;
qInfo ( ) < < " load APP Translator " < < lanName < < appTranslator . load ( " app_ " + lanName , " :/i18n " ) ;
2024-06-06 21:55:36 +08:00
} ) ;
QSettings settings ;
2024-06-20 10:44:08 +08:00
auto langName = settings . value ( " Language " ) . toString ( ) ;
2024-06-06 21:55:36 +08:00
QAction * actLan = 0 ;
# ifdef leyide
auto actTW = new QAction ( " 中文繁体 " ) ;
actTW - > setCheckable ( true ) ;
actTW - > setObjectName ( " zh_TW " ) ;
menuLang - > addAction ( actTW ) ;
langGrp - > addAction ( actTW ) ;
auto actEn = new QAction ( " English " ) ;
actEn - > setCheckable ( true ) ;
actEn - > setObjectName ( " en " ) ;
menuLang - > addAction ( actEn ) ;
langGrp - > addAction ( actEn ) ;
if ( ! langName . isEmpty ( ) ) {
if ( langName . endsWith ( " TW " ) ) actLan = actTW ;
else if ( langName . startsWith ( " en " ) ) actLan = actEn ;
}
if ( actLan = = 0 ) {
langName = QLocale ( ) . name ( ) ;
if ( langName . startsWith ( " en " ) ) actLan = actEn ;
else actLan = actTW ;
}
auto LogoPath = " :/res/Logo-leyide.png " ;
iconPos = QRectF ( 38 , 20 , 64 , 64 ) ;
# elif defined(citta)
auto actPt = new QAction ( " Português " ) ;
actPt - > setCheckable ( true ) ;
actPt - > setObjectName ( " pt " ) ;
menuLang - > addAction ( actPt ) ;
langGrp - > addAction ( actPt ) ;
auto actEn = new QAction ( " English " ) ;
actEn - > setCheckable ( true ) ;
actEn - > setObjectName ( " en " ) ;
menuLang - > addAction ( actEn ) ;
langGrp - > addAction ( actEn ) ;
2023-04-18 14:14:46 +08:00
2024-06-06 21:55:36 +08:00
if ( ! langName . isEmpty ( ) ) {
if ( langName . endsWith ( " pt " ) ) actLan = actPt ;
else if ( langName . startsWith ( " en " ) ) actLan = actEn ;
}
if ( actLan = = 0 ) {
langName = QLocale ( ) . name ( ) ;
if ( langName . startsWith ( " en " ) ) actLan = actEn ;
else actLan = actPt ;
}
auto LogoPath = " :/res/Logo-citta.png " ;
iconPos = QRectF ( 14 , 20 , 132 , 64 ) ;
# else
2023-04-18 14:14:46 +08:00
auto actCN = new QAction ( " 中文 " ) ;
2022-08-25 18:37:24 +08:00
actCN - > setCheckable ( true ) ;
actCN - > setObjectName ( " zh_CN " ) ;
2023-04-18 14:14:46 +08:00
menuLang - > addAction ( actCN ) ;
2024-06-06 21:55:36 +08:00
langGrp - > addAction ( actCN ) ;
2023-04-18 14:14:46 +08:00
auto actTW = new QAction ( " 中文繁体 " ) ;
2022-08-25 18:37:24 +08:00
actTW - > setCheckable ( true ) ;
actTW - > setObjectName ( " zh_TW " ) ;
2023-04-18 14:14:46 +08:00
menuLang - > addAction ( actTW ) ;
2024-06-06 21:55:36 +08:00
langGrp - > addAction ( actTW ) ;
2023-04-18 14:14:46 +08:00
auto actEn = new QAction ( " English " ) ;
2022-08-25 18:37:24 +08:00
actEn - > setCheckable ( true ) ;
actEn - > setObjectName ( " en " ) ;
2023-04-18 14:14:46 +08:00
menuLang - > addAction ( actEn ) ;
2024-06-06 21:55:36 +08:00
langGrp - > addAction ( actEn ) ;
2023-04-18 14:14:46 +08:00
auto actJa = new QAction ( " 日本語 " ) ;
2022-08-25 18:37:24 +08:00
actJa - > setCheckable ( true ) ;
actJa - > setObjectName ( " ja " ) ;
menuLang - > addAction ( actJa ) ;
2024-06-06 21:55:36 +08:00
langGrp - > addAction ( actJa ) ;
2023-04-18 14:14:46 +08:00
2023-09-19 11:49:20 +08:00
auto actPt = new QAction ( " Português " ) ;
actPt - > setCheckable ( true ) ;
actPt - > setObjectName ( " pt " ) ;
menuLang - > addAction ( actPt ) ;
langGrp - > addAction ( actPt ) ;
2023-04-18 14:14:46 +08:00
2022-08-25 18:37:24 +08:00
if ( ! langName . isEmpty ( ) ) {
if ( langName . endsWith ( " CN " ) ) actLan = actCN ;
else if ( langName . endsWith ( " TW " ) ) actLan = actTW ;
else if ( langName . startsWith ( " en " ) ) actLan = actEn ;
else if ( langName . startsWith ( " ja " ) ) actLan = actJa ;
2023-09-19 11:49:20 +08:00
else if ( langName . startsWith ( " pt " ) ) actLan = actPt ;
2022-08-25 18:37:24 +08:00
}
2023-08-01 11:42:41 +08:00
if ( actLan = = 0 ) {
2022-08-25 18:37:24 +08:00
langName = QLocale ( ) . name ( ) ;
if ( langName . endsWith ( " TW " ) ) actLan = actTW ;
else if ( langName . startsWith ( " en " ) ) actLan = actEn ;
else if ( langName . startsWith ( " ja " ) ) actLan = actJa ;
2023-09-19 11:49:20 +08:00
else if ( langName . startsWith ( " pt " ) ) actLan = actPt ;
2022-08-25 18:37:24 +08:00
else actLan = actCN ;
}
2024-06-06 21:55:36 +08:00
auto LogoPath = " :/res/Logo.png " ;
setWindowTitle ( " LedOK Express " ) ;
iconPos = QRectF ( 38 , 20 , 64 , 64 ) ;
# endif
2022-08-25 18:37:24 +08:00
actLan - > setChecked ( true ) ;
2023-09-19 11:49:20 +08:00
emit menuLang - > triggered ( actLan ) ;
2025-12-30 17:22:43 +08:00
QCoreApplication : : installTranslator ( & qtTranslator ) ;
QCoreApplication : : installTranslator ( & appTranslator ) ;
2022-08-25 18:37:24 +08:00
2024-06-20 10:44:08 +08:00
auto geo = settings . value ( " MainGeo " ) . toRect ( ) ;
2023-04-18 14:14:46 +08:00
if ( geo . width ( ) > = 800 & & geo . height ( ) > = 500 & & geo . x ( ) > = - 600 & & geo . x ( ) < = 1280 & & geo . y ( ) > = - 200 & & geo . y ( ) < = 800 ) setGeometry ( geo ) ;
else resize ( 1280 , 800 ) ;
2022-08-25 18:37:24 +08:00
if ( settings . value ( " MainIsMax " , false ) . toBool ( ) ) setWindowState ( Qt : : WindowMaximized ) ;
2022-09-06 23:40:02 +08:00
gPlayPos = settings . value ( " PlayPos " ) . toPoint ( ) ;
2024-06-06 21:55:36 +08:00
icon . load ( LogoPath ) ;
2022-08-25 18:37:24 +08:00
titlePos = QPointF ( 26 , 80 ) ;
auto plt = palette ( ) ;
plt . setBrush ( QPalette : : Window , QColor ( 0xdddddd ) ) ;
setPalette ( plt ) ;
2022-01-04 18:11:48 +08:00
//项目保存的文档路径
2024-02-21 18:08:50 +08:00
auto dataDir = QStandardPaths : : writableLocation ( QStandardPaths : : AppDataLocation ) ;
if ( ! dataDir . isEmpty ( ) ) {
QDir dataQDir ( dataDir ) ;
if ( ! dataQDir . exists ( ) ) dataQDir . mkpath ( dataDir ) ;
2022-01-04 18:11:48 +08:00
}
2023-08-01 11:42:41 +08:00
auto vBox = new VBox ( center ) ;
2022-08-25 18:37:24 +08:00
vBox - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
vBox - > setSpacing ( 0 ) ;
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
//自定义的标题上的工具栏创建(语言和设置选项)
m_wTitle = new LoQTitleBar ( this ) ;
installEventFilter ( m_wTitle ) ;
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
//水平布局,放置配置按钮,最小化,最大化,关闭按钮
QHBoxLayout * pLayout = new QHBoxLayout ( m_wTitle ) ;
pLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
pLayout - > addStretch ( ) ;
2023-08-01 11:42:41 +08:00
bn_Setting = new QPushButton ;
2022-08-25 18:37:24 +08:00
bn_Setting - > setIcon ( QIcon ( " :/res/AppSetting.png " ) ) ;
2023-04-18 14:14:46 +08:00
bn_Setting - > setToolTip ( tr ( " Setting " ) ) ;
2022-08-25 18:37:24 +08:00
pLayout - > addWidget ( bn_Setting ) ;
pLayout - > addWidget ( m_wTitle - > bn_Minimize ) ;
pLayout - > addWidget ( m_wTitle - > bn_Maximize ) ;
pLayout - > addWidget ( m_wTitle - > bn_Close ) ;
2023-08-01 11:42:41 +08:00
auto menu_setting = new QMenu ;
2022-08-25 18:37:24 +08:00
2025-12-30 17:22:43 +08:00
actFirmware = new QAction ( tr ( " Firmware Manager " ) ) ;
2023-08-01 11:42:41 +08:00
connect ( actFirmware , & QAction : : triggered , this , [ this ] {
2023-09-19 11:49:20 +08:00
new UpgradeApkDialog ( this ) ;
2023-08-01 11:42:41 +08:00
} ) ;
2025-12-30 17:22:43 +08:00
# ifndef leyide
2023-08-01 11:42:41 +08:00
menu_setting - > addAction ( actFirmware ) ;
2025-12-30 17:22:43 +08:00
# endif
2023-08-01 11:42:41 +08:00
actPreferences = new QAction ( tr ( " Preferences " ) ) ;
connect ( actPreferences , & QAction : : triggered , this , [ this ] {
QDialog dlg ( this ) ;
dlg . setWindowFlag ( Qt : : WindowContextHelpButtonHint , 0 ) ;
dlg . resize ( 400 , 300 ) ;
dlg . setWindowTitle ( tr ( " Preferences " ) ) ;
auto vBox = new VBox ( & dlg ) ;
auto fdPress = new QCheckBox ( tr ( " Video compress to " ) + " 720p " ) ;
fdPress - > setChecked ( gVideoCompress ) ;
vBox - > addWidget ( fdPress ) ;
auto fdTrans = new QCheckBox ( tr ( " Video transcoding to " ) + " h264 " ) ;
fdTrans - > setChecked ( gVideoTranscoding ) ;
vBox - > addWidget ( fdTrans ) ;
2023-09-19 11:49:20 +08:00
auto hBox = new HBox ( vBox ) ;
hBox - > setContentsMargins ( - 1 , 0 , - 1 , - 1 ) ;
2023-08-01 11:42:41 +08:00
auto fdAnti = new QCheckBox ( tr ( " Text antialiasing " ) ) ;
fdAnti - > setChecked ( gTextAntialiasing ) ;
2023-09-19 11:49:20 +08:00
hBox - > addWidget ( fdAnti , 0 , Qt : : AlignTop ) ;
2023-08-01 11:42:41 +08:00
auto fdAntiTip = new QLabel ( tr ( " TextAntilaTip " ) ) ;
fdAntiTip - > setStyleSheet ( " QLabel{color: #f00;} " ) ;
fdAntiTip - > setWordWrap ( true ) ;
2023-09-19 11:49:20 +08:00
hBox - > addWidget ( fdAntiTip , 1 ) ;
2023-08-01 11:42:41 +08:00
2023-10-23 11:44:22 +08:00
auto fdWidthSplit = new QCheckBox ( tr ( " Ultra-Long Screen Split " ) ) ;
2023-08-01 11:42:41 +08:00
fdWidthSplit - > setChecked ( gWidthSplit ) ;
vBox - > addWidget ( fdWidthSplit ) ;
2023-09-19 11:49:20 +08:00
hBox = new HBox ( vBox ) ;
hBox - > addLabel ( tr ( " Program Send Batch " ) ) ;
auto fdSendBatch = new QSpinBox ;
fdSendBatch - > setRange ( 1 , 20 ) ;
fdSendBatch - > setValue ( gSendBatch ) ;
hBox - > addWidget ( fdSendBatch ) ;
hBox - > addStretch ( ) ;
2023-08-01 11:42:41 +08:00
auto fdHideDetect = new QCheckBox ( tr ( " Hide Detect Button " ) ) ;
fdHideDetect - > setChecked ( gHideDetect ) ;
vBox - > addWidget ( fdHideDetect ) ;
2024-08-07 18:18:37 +08:00
auto fdShowIP = new QCheckBox ( tr ( " Show IP in Terminal Control " ) ) ;
fdShowIP - > setChecked ( gShowIP ) ;
vBox - > addWidget ( fdShowIP ) ;
2024-02-21 18:08:50 +08:00
auto fdShowAlias = new QCheckBox ( tr ( " Show Alias in Terminal Control " ) ) ;
fdShowAlias - > setChecked ( gShowAlias ) ;
vBox - > addWidget ( fdShowAlias ) ;
2023-08-01 11:42:41 +08:00
auto fdShowLora = new QCheckBox ( tr ( " Show Lora Screen " ) ) ;
fdShowLora - > setChecked ( gShowLora ) ;
vBox - > addWidget ( fdShowLora ) ;
vBox - > addStretch ( ) ;
auto btnBox = new QDialogButtonBox ( QDialogButtonBox : : Ok ) ;
connect ( btnBox , & QDialogButtonBox : : accepted , & dlg , [ = , & dlg ] {
QSettings settings ;
settings . setValue ( " VideoCompress " , gVideoCompress = fdPress - > isChecked ( ) ) ;
settings . setValue ( " VideoTranscoding " , gVideoTranscoding = fdTrans - > isChecked ( ) ) ;
settings . setValue ( " TextAntialiasing " , gTextAntialiasing = fdAnti - > isChecked ( ) ) ;
settings . setValue ( " WidthSplit " , gWidthSplit = fdWidthSplit - > isChecked ( ) ) ;
2023-09-19 11:49:20 +08:00
settings . setValue ( " SendBatch " , gSendBatch = fdSendBatch - > value ( ) ) ;
2023-08-01 11:42:41 +08:00
settings . setValue ( " HideDetect " , gHideDetect = fdHideDetect - > isChecked ( ) ) ;
2024-08-07 18:18:37 +08:00
settings . setValue ( " ShowIP " , gShowIP = fdShowIP - > isChecked ( ) ) ;
2024-02-21 18:08:50 +08:00
settings . setValue ( " ShowAlias " , gShowAlias = fdShowAlias - > isChecked ( ) ) ;
2023-08-01 11:42:41 +08:00
settings . setValue ( " GuangYingPin " , gShowLora = fdShowLora - > isChecked ( ) ) ;
dlg . accept ( ) ;
} ) ;
vBox - > addWidget ( btnBox ) ;
2023-04-18 14:14:46 +08:00
dlg . exec ( ) ;
2023-08-01 11:42:41 +08:00
fdDetectCard - > setVisible ( ! gHideDetect ) ;
2024-02-21 18:08:50 +08:00
if ( mDevicePanel - > mDeviceTable - > isColumnHidden ( mDevicePanel - > mDeviceTable - > columnCount ( ) - 1 ) ) {
2024-08-07 18:18:37 +08:00
mDevicePanel - > mDeviceTable - > setColumnHidden ( " ip " , ! gShowIP ) ;
mDevicePanel - > mDeviceTable - > setColumnHidden ( " alias " , ! gShowAlias ) ;
2024-02-21 18:08:50 +08:00
mDevicePanel - > mDeviceTable - > adjSections ( - 1 , 0 ) ;
}
2023-08-01 11:42:41 +08:00
mBtnGrp - > button ( MainPage_LoraScreen ) - > setVisible ( gShowLora ) ;
2023-04-18 14:14:46 +08:00
} ) ;
2023-08-01 11:42:41 +08:00
menu_setting - > addAction ( actPreferences ) ;
2022-08-25 18:37:24 +08:00
2024-08-07 18:18:37 +08:00
act_lang = new QAction ;
act_lang - > setMenu ( menuLang ) ;
menu_setting - > addAction ( act_lang ) ;
2024-06-06 21:55:36 +08:00
# if !defined leyide && !defined citta
act_upd = new QAction ( tr ( " Check for updates " ) ) ;
connect ( act_upd , & QAction : : triggered , this , [ this ] {
2023-05-18 18:24:40 +08:00
{
QDialog dlg ( this ) ;
# ifdef Q_OS_WIN
dlg . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
# endif
dlg . setWindowTitle ( tr ( " Software Update " ) ) ;
dlg . resize ( 500 , 400 ) ;
auto vBox = new VBox ( & dlg ) ;
auto label = new QLabel ( tr ( " CurVersion " ) + " : " + APP_VERSION ) ;
auto font = label - > font ( ) ;
font . setPixelSize ( 18 ) ;
label - > setFont ( font ) ;
vBox - > addWidget ( label ) ;
label = new QLabel ( hasNewVer ? tr ( " Latest Version " ) + " : " + updates [ " ver " ] . toString ( ) : tr ( " The current version is already the latest version " ) ) ;
vBox - > addWidget ( label ) ;
label = new QLabel ( tr ( " Update Log " ) + " : " ) ;
vBox - > addWidget ( label ) ;
auto fdUpdLog = new QTextEdit ;
fdUpdLog - > setReadOnly ( true ) ;
vBox - > addWidget ( fdUpdLog ) ;
2025-05-06 18:28:05 +08:00
auto reply = NetReq ( updates [ " changelog_zh_CN " ] . toString ( ) ) . get ( ) ;
2023-10-23 11:44:22 +08:00
ConnReply ( reply , fdUpdLog ) [ = ] {
2023-05-18 18:24:40 +08:00
auto err = errStr ( reply ) ;
if ( ! err . isEmpty ( ) ) {
qCritical ( ) < < " Check Updates " < < err ;
return ;
}
fdUpdLog - > setPlainText ( reply - > readAll ( ) ) ;
} ) ;
auto btnBox = new QDialogButtonBox ;
if ( hasNewVer ) {
btnBox - > addButton ( tr ( " Download " ) , QDialogButtonBox : : AcceptRole ) ;
connect ( btnBox , & QDialogButtonBox : : accepted , & dlg , & QDialog : : accept ) ;
}
btnBox - > addButton ( QDialogButtonBox : : Cancel ) ;
connect ( btnBox , & QDialogButtonBox : : rejected , & dlg , & QDialog : : reject ) ;
vBox - > addWidget ( btnBox ) ;
2023-04-18 14:14:46 +08:00
2023-05-18 18:24:40 +08:00
if ( dlg . exec ( ) ! = QDialog : : Accepted ) return ;
}
auto filePath = QStandardPaths : : writableLocation ( QStandardPaths : : TempLocation ) + " /ledok-express-updater " ;
auto url = updates [ " url " ] . toString ( ) ;
auto idx = url . lastIndexOf ( ' . ' ) ;
2023-10-23 11:44:22 +08:00
if ( idx ! = - 1 ) filePath + = url . mid ( idx ) ;
2023-05-18 19:14:40 +08:00
qDebug ( ) < < " filePath " < < filePath ;
2023-05-18 18:24:40 +08:00
QFile qFile ( filePath ) ;
if ( ! qFile . open ( QFile : : WriteOnly ) ) {
QMessageBox : : critical ( this , tr ( " Fail " ) , tr ( " Cannot Save File " ) + " : " + qFile . errorString ( ) + " \n " + filePath ) ;
return ;
}
QMessageBox msgBox ( this ) ;
msgBox . setStandardButtons ( QMessageBox : : Cancel ) ;
msgBox . setWindowTitle ( tr ( " Downloading updates " ) ) ;
msgBox . setText ( tr ( " Downloading updates " ) + " : 0% " ) ;
auto reply = NetReq ( url ) . timeout ( 60000 ) . get ( ) ;
2023-10-23 11:44:22 +08:00
auto pfile = & qFile ;
ConnReply ( reply , & msgBox ) [ = , & msgBox ] {
2023-05-18 18:24:40 +08:00
auto err = errStr ( reply ) ;
if ( ! err . isEmpty ( ) ) {
msgBox . setIcon ( QMessageBox : : Critical ) ;
2025-05-06 18:28:05 +08:00
msgBox . setText ( translate ( " " , " Error " ) + " : " + err ) ;
2023-05-18 18:24:40 +08:00
return ;
2023-04-18 14:14:46 +08:00
}
2023-05-18 18:24:40 +08:00
msgBox . accept ( ) ;
2023-04-18 14:14:46 +08:00
} ) ;
2023-10-23 11:44:22 +08:00
connect ( reply , & QNetworkReply : : downloadProgress , & msgBox , [ = , & msgBox ] ( qint64 bytesReceived , qint64 bytesTotal ) {
if ( bytesTotal = = 0 ) return ;
msgBox . setText ( tr ( " Downloading updates " ) + " : " + QString : : number ( bytesReceived * 100 / bytesTotal ) + " % " ) ;
pfile - > write ( reply - > readAll ( ) ) ;
} ) ;
2023-05-18 18:24:40 +08:00
auto res = msgBox . exec ( ) ;
qFile . close ( ) ;
if ( res ! = QDialog : : Accepted ) return ;
2023-09-19 11:49:20 +08:00
QCoreApplication : : quit ( ) ;
2023-05-18 20:53:43 +08:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( filePath ) ) ;
2023-04-18 14:14:46 +08:00
} ) ;
2024-06-06 21:55:36 +08:00
menu_setting - > addAction ( act_upd ) ;
2022-08-25 18:37:24 +08:00
2025-05-06 18:28:05 +08:00
auto reply = NetReq ( UpdVerUrl ) . get ( ) ;
2023-10-23 11:44:22 +08:00
ConnReply ( reply , this ) [ = ] {
2023-05-18 18:24:40 +08:00
auto err = errStr ( reply ) ;
if ( ! err . isEmpty ( ) ) {
qCritical ( ) < < " Check Updates " < < err ;
return ;
}
auto data = reply - > readAll ( ) ;
QJsonParseError jsonErr ;
auto json = QJsonDocument : : fromJson ( data , & jsonErr ) ;
if ( jsonErr . error ! = QJsonParseError : : NoError ) {
qCritical ( ) < < " Check Updates JsonError " < < jsonErr . errorString ( ) ;
return ;
}
# ifdef Q_OS_WIN
2024-02-21 18:08:50 +08:00
# if(QT_VERSION_MAJOR > 5)
updates = json [ " win-64 " ] . toObject ( ) ;
# else
2024-06-19 18:54:32 +08:00
updates = json [ " win-32 " ] . toObject ( ) ;
2024-02-21 18:08:50 +08:00
# endif
2023-05-18 19:14:40 +08:00
# endif
# ifdef Q_OS_MAC
2023-05-18 18:24:40 +08:00
updates = json [ " mac " ] . toObject ( ) ;
# endif
if ( verCompare ( updates [ " ver " ] . toString ( ) , APP_VERSION ) > 0 ) {
hasNewVer = true ;
bn_Setting - > setIcon ( QIcon ( " :/res/AppSettingTip.png " ) ) ;
2024-06-06 21:55:36 +08:00
act_upd - > setIcon ( QIcon ( " :/res/reddot.png " ) ) ;
2023-05-18 18:24:40 +08:00
}
} ) ;
2024-06-06 21:55:36 +08:00
# endif
2023-05-18 18:24:40 +08:00
2024-08-07 18:18:37 +08:00
act_help = new QAction ;
2023-04-18 14:14:46 +08:00
connect ( act_help , & QAction : : triggered , this , [ this ] {
auto act = langGrp - > checkedAction ( ) ;
if ( act = = 0 ) return ;
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( QCoreApplication : : applicationDirPath ( ) + " /help/ " + act - > objectName ( ) + " .pdf " ) ) ;
} ) ;
2022-08-25 18:37:24 +08:00
menu_setting - > addAction ( act_help ) ;
2024-08-07 18:18:37 +08:00
// QMessageBox::information(this, tr("Info"), QFileInfo("aaa.file").absoluteFilePath()
// .append("\nSupportsSsl: ").append(QSslSocket::supportsSsl()?"true":"false")
// .append("\nSslLibraryBuildVersion: ").append(QSslSocket::sslLibraryBuildVersionString().append(" (").append(QString::number(QSslSocket::sslLibraryBuildVersionNumber())).append(")"))
// .append("\nSslLibraryVersion: ").append(QSslSocket::sslLibraryVersionString()).append(" (").append(QString::number(QSslSocket::sslLibraryVersionNumber())).append(")"));
2022-08-25 18:37:24 +08:00
2024-06-06 21:55:36 +08:00
# if !defined leyide && !defined citta
2022-08-25 18:37:24 +08:00
act_about = new QAction ( tr ( " About " ) ) ;
2024-06-06 21:55:36 +08:00
connect ( act_about , & QAction : : triggered , this , [ = ] {
2023-04-23 10:04:49 +08:00
QDialog dlg ( this ) ;
dlg . setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
dlg . setWindowTitle ( tr ( " About " ) ) ;
auto hBox = new HBox ( & dlg ) ;
hBox - > setContentsMargins ( 24 , 24 , 24 , 24 ) ;
hBox - > setSpacing ( 24 ) ;
auto label = new QLabel ;
2024-06-06 21:55:36 +08:00
label - > setPixmap ( QPixmap ( LogoPath ) ) ;
2023-04-23 10:04:49 +08:00
hBox - > addWidget ( label ) ;
auto vBox = new VBox ( hBox ) ;
label = new QLabel ( " LedOK Express " ) ;
label - > setAlignment ( Qt : : AlignCenter ) ;
auto font = label - > font ( ) ;
font . setPixelSize ( 30 ) ;
label - > setFont ( font ) ;
vBox - > addWidget ( label ) ;
2023-08-01 11:42:41 +08:00
label = new QLabel ( " V " APP_VERSION " - " __DATE__ ) ;
2023-04-23 10:04:49 +08:00
font = label - > font ( ) ;
font . setPixelSize ( 18 ) ;
label - > setFont ( font ) ;
label - > setAlignment ( Qt : : AlignCenter ) ;
vBox - > addWidget ( label ) ;
label = new QLabel ( " <a href= \" https://www.ledok.cn/ \" >www.ledok.cn " ) ;
font = label - > font ( ) ;
font . setPixelSize ( 20 ) ;
label - > setFont ( font ) ;
label - > setAlignment ( Qt : : AlignCenter ) ;
label - > setOpenExternalLinks ( true ) ;
vBox - > addWidget ( label ) ;
2023-04-18 14:14:46 +08:00
dlg . exec ( ) ;
} ) ;
2022-08-25 18:37:24 +08:00
menu_setting - > addAction ( act_about ) ;
2024-06-06 21:55:36 +08:00
# endif
2022-08-25 18:37:24 +08:00
bn_Setting - > setMenu ( menu_setting ) ; //按钮上添加下拉菜单
vBox - > addWidget ( m_wTitle ) ;
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
//设备管理,节目管理,高级节目管理页创建
2022-09-30 18:08:39 +08:00
mDevicePanel = new DevicePanel ( settings ) ;
2022-01-04 18:11:48 +08:00
2023-08-01 11:42:41 +08:00
auto hBox = new HBox ( vBox ) ;
2022-08-25 18:37:24 +08:00
hBox - > setSpacing ( 2 ) ;
2024-06-06 21:55:36 +08:00
hBox - > addSpacing ( 150 ) ;
2022-08-25 18:37:24 +08:00
mBtnGrp = new QButtonGroup ( this ) ;
for ( int i = 0 ; i < MainPage_End ; i + + ) {
auto btn = new ImgBtn ( ) ;
btn - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
btn - > setCheckable ( true ) ;
btn - > setIconSize ( QSize ( 40 , 40 ) ) ;
btn - > setProperty ( " ss " , " MainTab " ) ;
if ( i = = MainPage_DeviceManager ) btn - > setIcons ( QIcon { " :/res/DeviceManager_u.png " } , QIcon { " :/res/DeviceManager_s.png " } ) ;
else if ( i = = MainPage_ProgManager ) btn - > setIcons ( QIcon { " :/res/ProgramManager_u.png " } , QIcon { " :/res/ProgramManager_s.png " } ) ;
else if ( i = = MainPage_Setting ) btn - > setIcons ( QIcon { " :/res/DeviceSetting_u.png " } , QIcon { " :/res/DeviceSetting_s.png " } ) ;
else if ( i = = MainPage_LoraScreen ) btn - > setIcons ( QIcon { " :/res/GuangYingPin_u.png " } , QIcon { " :/res/GuangYingPin_s.png " } ) ;
hBox - > addWidget ( btn ) ;
mBtnGrp - > addButton ( btn , i ) ;
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
wgts [ MainPage_DeviceManager ] = mDevicePanel ;
wgts [ MainPage_Setting ] = mDevicePanel ;
2023-05-15 16:06:10 +08:00
vBox - > addWidget ( wgts [ mDevicePanel - > mainPanelIdx ] ) ; //初始化响应页面为终端管理页面
2022-08-25 18:37:24 +08:00
2023-05-15 16:06:10 +08:00
mBtnGrp - > button ( mDevicePanel - > mainPanelIdx ) - > setChecked ( true ) ;
2022-08-25 18:37:24 +08:00
connect ( mBtnGrp , & QButtonGroup : : idToggled , this , [ this , vBox ] ( int id , bool checked ) {
2023-05-15 16:06:10 +08:00
if ( ! checked | | id = = mDevicePanel - > mainPanelIdx ) return ;
if ( ( id ! = MainPage_DeviceManager | | mDevicePanel - > mainPanelIdx ! = MainPage_Setting ) & & ( id ! = MainPage_Setting | | mDevicePanel - > mainPanelIdx ! = MainPage_DeviceManager ) ) {
2023-08-01 11:42:41 +08:00
if ( wgts [ id ] = = 0 ) {
if ( id = = MainPage_ProgManager ) wgts [ id ] = mProgPanel = new ProgPanel ( center ) ;
else if ( id = = MainPage_LoraScreen ) wgts [ id ] = m_wGuangYingPinWidget = new mGuangYingPinWidget ;
}
2023-05-15 16:06:10 +08:00
vBox - > replaceWidget ( wgts [ mDevicePanel - > mainPanelIdx ] , wgts [ id ] ) ;
wgts [ mDevicePanel - > mainPanelIdx ] - > setParent ( 0 ) ;
}
mDevicePanel - > mainPanelIdx = id ;
if ( id = = MainPage_DeviceManager ) { //设备信息列表页面
2023-09-19 11:49:20 +08:00
mDevicePanel - > mDeviceTable - > hideColumn ( " check " ) ;
mDevicePanel - > mDeviceTable - > fdCheckAll - > hide ( ) ;
mDevicePanel - > fdCardNumInfo - > hide ( ) ;
2023-05-15 16:06:10 +08:00
if ( mDevicePanel - > mDeviceCtrlPanel ) {
2024-02-21 18:08:50 +08:00
for ( int j = " id " * * mDevicePanel - > mDeviceTable + 1 ; j < mDevicePanel - > mDeviceTable - > columnCount ( ) ; j + + ) mDevicePanel - > mDeviceTable - > showColumn ( j ) ;
2023-05-15 16:06:10 +08:00
mDevicePanel - > mDeviceTable - > setMaximumWidth ( 0xffffff ) ;
mDevicePanel - > mDeviceCtrlPanel - > hide ( ) ;
2022-01-04 18:11:48 +08:00
}
2023-05-15 16:06:10 +08:00
} else if ( id = = MainPage_Setting ) { //终端控制页面
2023-09-19 11:49:20 +08:00
mDevicePanel - > mDeviceTable - > showColumn ( " check " ) ;
mDevicePanel - > mDeviceTable - > fdCheckAll - > show ( ) ;
mDevicePanel - > fdCardNumInfo - > show ( ) ;
2024-08-07 18:18:37 +08:00
auto idxIP = ! gShowIP ? - 1 : " ip " * * mDevicePanel - > mDeviceTable ;
auto idxAlias = ! gShowAlias ? - 1 : " alias " * * mDevicePanel - > mDeviceTable ;
for ( int j = " id " * * mDevicePanel - > mDeviceTable + 1 ; j < mDevicePanel - > mDeviceTable - > columnCount ( ) ; j + + ) if ( j ! = idxIP & & j ! = idxAlias ) mDevicePanel - > mDeviceTable - > hideColumn ( j ) ;
2023-08-01 11:42:41 +08:00
if ( mDevicePanel - > mDeviceCtrlPanel ) mDevicePanel - > mDeviceCtrlPanel - > show ( ) ;
else mDevicePanel - > newCtrl ( ) ;
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
} ) ;
2022-01-04 18:11:48 +08:00
2023-08-01 11:42:41 +08:00
hBox = new HBox ( vBox ) ;
fdDetectCard = new QPushButton ;
fdDetectCard - > setCursor ( Qt : : PointingHandCursor ) ;
fdDetectCard - > setProperty ( " ssType " , " progManageTool " ) ;
connect ( fdDetectCard , & QPushButton : : clicked , this , [ this ] {
2025-05-06 18:28:05 +08:00
auto res = QMessageBox : : warning ( this , translate ( " " , " Tip " ) , tr ( " RestoreLedCardIpByUdpTip " ) , QMessageBox : : Ok , QMessageBox : : Cancel ) ;
2023-05-15 16:06:10 +08:00
if ( res ! = QMessageBox : : Ok ) return ;
QList < QNetworkInterface > networkinterfaces = QNetworkInterface : : allInterfaces ( ) ;
2025-05-06 18:28:05 +08:00
for ( QNetworkInterface & interfaces : networkinterfaces ) { //networkinterfaces负责提供主机的IP地址和网络接口的列表
for ( QNetworkAddressEntry & entry : interfaces . addressEntries ( ) ) { //QNetworkAddressEntry存储了一个IP地址, 子网掩码和广播地址
2023-05-15 16:06:10 +08:00
entry . setBroadcast ( QHostAddress : : Broadcast ) ;
QHostAddress broadcastAddress ( " 255.255.255.255 " ) ;
entry . setBroadcast ( QHostAddress : : Broadcast ) ;
RESTORE_IP stTempIp ;
memset ( & stTempIp , 0x00 , sizeof ( RESTORE_IP ) ) ;
QString strNew = entry . ip ( ) . toString ( ) ;
int itempOffset = strNew . lastIndexOf ( " . " ) ;
QString sstrNew = strNew . left ( itempOffset ) + " .254 " ;
if ( sstrNew . length ( ) < = 20 ) memcpy ( stTempIp . cNewIp , sstrNew . toLatin1 ( ) . data ( ) , sstrNew . length ( ) ) ;
QString strMask = entry . netmask ( ) . toString ( ) ;
if ( strMask . length ( ) < = 20 ) memcpy ( stTempIp . cMask , strMask . toLatin1 ( ) . data ( ) , strMask . length ( ) ) ;
QString strGateway = entry . ip ( ) . toString ( ) ;
if ( strGateway . length ( ) < = 20 ) memcpy ( stTempIp . cGateway , strGateway . toLatin1 ( ) . data ( ) , strGateway . length ( ) ) ;
if ( strGateway . length ( ) < = 20 ) memcpy ( stTempIp . cDns , strGateway . toLatin1 ( ) . data ( ) , strGateway . length ( ) ) ;
STREAM_PACKET packet ;
memset ( & packet , 0 , sizeof ( STREAM_PACKET ) ) ;
memset ( packet . SyncHead , 0x7e , 3 ) ;
memset ( packet . ucSerialCode , 0x00 , 20 ) ;
QByteArray ba ( " Broadcast! " ) ;
memcpy ( packet . ucSerialCode , ba . data ( ) , ba . size ( ) ) ;
packet . iLength = 80 ;
2023-05-19 18:50:21 +08:00
packet . ucCommType = 0X43 ;
2023-05-15 16:06:10 +08:00
memcpy ( packet . pDataBuffer , & stTempIp , 80 ) ;
packet . pDataBuffer [ packet . iLength ] = GetCheckCodeIn8 ( & packet . ucCommType , packet . iLength + sizeof ( packet . ucCommType ) + sizeof ( char ) * 20 + sizeof ( packet . iLength ) ) ;
int iLenPacket = packet . iLength + sizeof ( int ) + 3 * sizeof ( unsigned char ) + sizeof ( char ) + 20 * sizeof ( char ) + sizeof ( char ) ; /////除正文外的协议结构大小;
QUdpSocket * tempUdpSocket = new QUdpSocket ( this ) ;
if ( ! tempUdpSocket - > bind ( entry . ip ( ) ) ) break ;
tempUdpSocket - > writeDatagram ( ( char * ) & packet , iLenPacket , broadcastAddress , 31296 ) ;
}
}
2022-08-25 18:37:24 +08:00
} ) ;
2023-08-01 11:42:41 +08:00
hBox - > addWidget ( fdDetectCard ) ;
2024-02-21 18:08:50 +08:00
// auto btn = new QPushButton("Test");
// connect(btn, &QPushButton::clicked, this, [=] {
// auto www = new TTTWgt;
// www->show();
// });
// hBox->addWidget(btn);
2022-08-25 18:37:24 +08:00
hBox - > addStretch ( ) ;
2023-09-19 11:49:20 +08:00
hBox - > addLabel ( " V " APP_VERSION " - " __DATE__ ) ;
2022-08-25 18:37:24 +08:00
2023-09-19 11:49:20 +08:00
gApkHome = settings . value ( " ApkHome " ) . toString ( ) ;
2025-05-06 18:28:05 +08:00
gProgWidth = settings . value ( " ProgWidth " , 512 ) . toInt ( ) ;
gProgHeight = settings . value ( " ProgHeight " , 256 ) . toInt ( ) ;
2024-02-21 18:08:50 +08:00
gVideoCompress = settings . value ( " VideoCompress " ) . toBool ( ) ;
gVideoTranscoding = settings . value ( " VideoTranscoding " ) . toBool ( ) ;
gTextAntialiasing = settings . value ( " TextAntialiasing " ) . toBool ( ) ;
gWidthSplit = settings . value ( " WidthSplit " ) . toBool ( ) ;
2023-09-19 11:49:20 +08:00
gSendBatch = settings . value ( " SendBatch " , 5 ) . toInt ( ) ;
2024-02-21 18:08:50 +08:00
gHideDetect = settings . value ( " HideDetect " ) . toBool ( ) ;
gShowAlias = settings . value ( " ShowAlias " ) . toBool ( ) ;
2024-08-07 18:18:37 +08:00
gShowIP = settings . value ( " ShowIP " , ! gShowAlias ) . toBool ( ) ;
2024-02-21 18:08:50 +08:00
gShowLora = settings . value ( " GuangYingPin " ) . toBool ( ) ;
2022-10-27 15:07:45 +08:00
2023-08-01 11:42:41 +08:00
if ( gHideDetect ) fdDetectCard - > hide ( ) ;
if ( ! gShowLora ) mBtnGrp - > button ( MainPage_LoraScreen ) - > hide ( ) ;
2022-08-25 18:37:24 +08:00
if ( settings . value ( " AddFirewallFlag " ) . toString ( ) ! = " 1 " ) {
//添加exe到win防火墙例外
auto appFile = QCoreApplication : : applicationFilePath ( ) ;
appFile . replace ( ' / ' , ' \\ ' ) ;
QProcess cmd ;
connect ( & cmd , & QProcess : : readyReadStandardOutput , this , [ & cmd ] {
qDebug ( ) < < " out " < < QString : : fromLocal8Bit ( cmd . readAllStandardOutput ( ) ) ;
} ) ;
connect ( & cmd , & QProcess : : readyReadStandardError , this , [ & cmd ] {
qDebug ( ) < < " err " < < QString : : fromLocal8Bit ( cmd . readAllStandardError ( ) ) ;
} ) ;
qDebug ( ) < < " Add Firewall " < < appFile ;
cmd . start ( " netsh advfirewall firewall add rule name= \" allow LedOK \" dir=in program= \" " + appFile + " \" " , { " security=authnoencap " , " action=allow " } ) ;
cmd . waitForFinished ( ) ;
settings . setValue ( " AddFirewallFlag " , " 1 " ) ;
} ;
transUi ( ) ;
int ci = 0 ;
int grays [ ] = { 0 , 0x22 , 0x44 , 0x66 , 0x88 , 0x99 , 0xaa , 0xbb , 0xcc , 0xdd , 0xee , 0xff } ;
for ( ; ci < 12 ; ci + + ) QColorDialog : : setStandardColor ( ci , QColor ( grays [ ci ] , grays [ ci ] , grays [ ci ] ) ) ;
int higs [ ] = { 0x80 , 0xff , 0xff } ;
int mids [ ] = { 0x40 , 0x80 , 0xbf } ;
int lows [ ] = { 0 , 0 , 0x7f } ;
for ( int i = 0 ; i < 3 ; i + + ) {
QColorDialog : : setStandardColor ( ci + + , QColor ( higs [ i ] , lows [ i ] , lows [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( higs [ i ] , higs [ i ] , lows [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( lows [ i ] , higs [ i ] , lows [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( lows [ i ] , higs [ i ] , higs [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( lows [ i ] , lows [ i ] , higs [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( higs [ i ] , lows [ i ] , higs [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( higs [ i ] , lows [ i ] , mids [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( higs [ i ] , mids [ i ] , lows [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( mids [ i ] , higs [ i ] , lows [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( lows [ i ] , higs [ i ] , mids [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( lows [ i ] , mids [ i ] , higs [ i ] ) ) ;
QColorDialog : : setStandardColor ( ci + + , QColor ( mids [ i ] , lows [ i ] , higs [ i ] ) ) ;
2022-01-04 18:11:48 +08:00
}
2024-08-07 18:18:37 +08:00
gTick = new Tick ( this ) ;
2025-12-30 17:22:43 +08:00
auto timer = new QTimer ( this ) ;
connect ( timer , & QTimer : : timeout , this , [ = ] {
JObj json ;
json . insert ( " _id " , " GetApInfo " ) ;
json . insert ( " _type " , " GetApInfo " ) ;
auto reply = NetReq ( " http://192.168.43.1:2016/settings " ) . timeout ( 8000 ) . post ( json ) ;
connect ( reply , & QNetworkReply : : finished , this , [ = ] {
JValue json ;
auto err = errStrWithJson ( reply , & json ) ;
if ( ! err . isEmpty ( ) ) {
qDebug ( ) < < " GetApInfo Error " < < err ;
return ;
}
qDebug ( ) < < " GetApInfo " < < json ;
auto connCount = json [ " connectionCount " ] . toInt ( ) ;
if ( connCount < = 3 ) return ;
auto pswd = json [ " apPassword " ] . toStr ( ) ;
if ( isStrongPswd ( pswd ) ) return ;
auto apName = json [ " apName " ] . toStr ( ) ;
timer - > stop ( ) ;
auto dlg = new QDialog ;
dlg - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
dlg - > setWindowFlag ( Qt : : WindowCloseButtonHint , false ) ;
dlg - > setWindowFlag ( Qt : : WindowContextHelpButtonHint , false ) ;
dlg - > setModal ( true ) ;
dlg - > setWindowTitle ( " Change Hotspot Password " ) ;
dlg - > resize ( 300 , 200 ) ;
auto vBox = new VBox ( dlg ) ;
vBox - > addStretch ( ) ;
vBox - > addLabel ( translate ( " " , " The Device's Hotspot password is too weak, please change the password. " ) ) ;
vBox - > addStretch ( ) ;
vBox - > addLabel ( translate ( " " , " The password must have 8 characters at least and contain numbers, uppercase and lowercase letters " ) ) ;
vBox - > addStretch ( ) ;
auto grid = new Grid ( vBox ) ;
grid - > addLabel ( translate ( " " , " Hotspot Name " ) , 0 , 0 ) ;
grid - > addLabel ( apName , 0 , 1 ) ;
grid - > addLabel ( translate ( " " , " New password " ) , 1 , 0 ) ;
auto ed = new QLineEdit ;
grid - > addWidget ( ed , 1 , 1 ) ;
grid - > addLabel ( translate ( " " , " Confirm password " ) , 2 , 0 ) ;
auto ed2 = new QLineEdit ;
grid - > addWidget ( ed2 , 2 , 1 ) ;
vBox - > addStretch ( ) ;
auto btnBox = new QDialogButtonBox ( QDialogButtonBox : : Ok ) ;
connect ( btnBox , & QDialogButtonBox : : accepted , this , [ = ] {
auto pswd = ed - > text ( ) ;
if ( pswd . size ( ) < 8 | | ! isStrongPswd ( pswd ) ) {
QMessageBox : : warning ( this , translate ( " " , " Tip " ) , translate ( " " , " The password must have 8 characters at least and contain numbers, uppercase and lowercase letters " ) ) ;
return ;
}
if ( pswd ! = ed2 - > text ( ) ) {
QMessageBox : : warning ( this , translate ( " " , " Tip " ) , translate ( " " , " Two passwords are not same " ) ) ;
return ;
}
JObj json ;
json . insert ( " _id " , " ConfigurationHotSpot " ) ;
json . insert ( " _type " , " ConfigurationHotSpot " ) ;
json . insert ( " apName " , apName ) ;
//json.insert("apBand", edIs5G->isChecked() ? 1 : 0);
json . insert ( " password " , pswd ) ;
auto waitingDlg = new WaitingDlg ( this , tr ( " Config Hotspot " ) + " ... " ) ;
waitingDlg - > show ( ) ;
auto reply = NetReq ( " http://192.168.43.1:2016/settings " ) . post ( json ) ;
ConnReply ( reply , waitingDlg ) [ = ] {
waitingDlg - > close ( ) ;
auto err = errStrWithJson ( reply ) ;
if ( ! err . isEmpty ( ) ) {
QMessageBox : : critical ( this , translate ( " " , " Error " ) , err ) ;
return ;
}
QMessageBox : : information ( this , translate ( " " , " Tip " ) , translate ( " " , " Password changed successfully " ) ) ;
dlg - > accept ( ) ;
timer - > start ( 60000 ) ;
} ) ;
} ) ;
vBox - > addWidget ( btnBox ) ;
dlg - > show ( ) ;
} ) ;
} ) ;
timer - > start ( 20000 ) ;
// DWORD clientVersion = 2;
// PDWORD version = 0;
// HANDLE clientHandle = 0;
// auto ret = WlanOpenHandle(clientVersion, 0, version, &clientHandle);
// if(ret != ERROR_SUCCESS) {
// qDebug() << "Failed to open a client handle."<<ret;
// return;
// }
// PWLAN_INTERFACE_INFO_LIST interfaceList;
// ret = WlanEnumInterfaces(clientHandle, 0, &interfaceList);
// if(ret == ERROR_SUCCESS) {
// for(DWORD i=0; i<interfaceList->dwNumberOfItems; i++) {
// auto interfaceInfo = &interfaceList->InterfaceInfo[i];
// if(interfaceInfo->isState==wlan_interface_state_connected) {
// //WCHAR* ssidName = interfaceInfo->CurrentConnection.wlanAssociationAttributes.dot11Ssid;
// //QString wifiName = QString::fromWCharArray(ssidName);
// //qDebug() << "Current WiFi Name:" << wifiName;
// qDebug() << "Current WiFi Name:" << interfaceInfo->strInterfaceDescription;
// break; // Assuming you only want the first connected interface's SSID.
// }
// }
// } else {
// qDebug() << "Failed to get interface list.";
// }
// WlanCloseHandle(clientHandle, 0);
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
MainWindow : : ~ MainWindow ( ) {
QSettings settings ;
auto act = langGrp - > checkedAction ( ) ;
if ( act ) settings . setValue ( " Language " , act - > objectName ( ) ) ;
settings . setValue ( " MainGeo " , normalGeometry ( ) ) ;
settings . setValue ( " MainIsMax " , isMaximized ( ) ) ;
2022-09-06 23:40:02 +08:00
settings . setValue ( " PlayPos " , gPlayPos ) ;
2023-09-19 11:49:20 +08:00
if ( ! gApkHome . isEmpty ( ) ) settings . setValue ( " ApkHome " , gApkHome ) ;
2025-05-06 18:28:05 +08:00
settings . setValue ( " ProgWidth " , gProgWidth ) ;
settings . setValue ( " ProgHeight " , gProgHeight ) ;
2022-09-28 18:21:57 +08:00
if ( mDevicePanel - > fdIP ) {
2022-10-12 18:17:10 +08:00
auto ipstr = mDevicePanel - > fdIP - > toPlainText ( ) ;
if ( ! ipstr . isEmpty ( ) ) settings . setValue ( " SpecifyIP " , ipstr ) ;
2023-04-18 14:14:46 +08:00
else settings . remove ( " SpecifyIP " ) ;
2022-09-28 18:21:57 +08:00
}
2023-08-01 11:42:41 +08:00
if ( mProgPanel ) {
settings . setValue ( " ProgramListSortColumn " , mProgPanel - > mProgTree - > sortColumn ( ) ) ;
settings . setValue ( " ProgramListSortOrder " , mProgPanel - > mProgTree - > header ( ) - > sortIndicatorOrder ( ) ) ;
}
2022-01-04 18:11:48 +08:00
}
2023-09-19 11:49:20 +08:00
2022-08-25 18:37:24 +08:00
void MainWindow : : changeEvent ( QEvent * event ) {
BaseWin : : changeEvent ( event ) ;
if ( event - > type ( ) = = QEvent : : LanguageChange ) transUi ( ) ;
2022-01-04 18:11:48 +08:00
}
2022-08-25 18:37:24 +08:00
void MainWindow : : transUi ( ) {
m_wTitle - > refreshLable ( ) ;
mBtnGrp - > button ( MainPage_DeviceManager ) - > setText ( tr ( " Device " ) ) ;
mBtnGrp - > button ( MainPage_ProgManager ) - > setText ( tr ( " Program " ) ) ;
mBtnGrp - > button ( MainPage_Setting ) - > setText ( tr ( " Control " ) ) ;
2023-08-01 11:42:41 +08:00
mBtnGrp - > button ( MainPage_LoraScreen ) - > setText ( tr ( " Lora Screen " ) ) ;
fdDetectCard - > setText ( tr ( " Check card " ) ) ;
2022-08-25 18:37:24 +08:00
act_lang - > setText ( tr ( " Language " ) ) ;
act_help - > setText ( tr ( " Help " ) ) ;
2024-06-06 21:55:36 +08:00
if ( act_about ) act_about - > setText ( tr ( " About " ) ) ;
if ( act_upd ) act_upd - > setText ( tr ( " Check for updates " ) ) ;
2025-12-30 17:22:43 +08:00
actFirmware - > setText ( tr ( " Firmware Manager " ) ) ;
2023-08-01 11:42:41 +08:00
actPreferences - > setText ( tr ( " Preferences " ) ) ;
2022-08-25 18:37:24 +08:00
bn_Setting - > setToolTip ( tr ( " Setting " ) ) ;
2022-01-04 18:11:48 +08:00
}