964 lines
34 KiB
C++
964 lines
34 KiB
C++
#include <iostream>
|
|
#include "widget.h"
|
|
#include <QScreen>
|
|
#include "./ui_widget.h"
|
|
#include "UI/Language/Index.h"
|
|
|
|
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget){
|
|
ui->setupUi(this);
|
|
//------------------------------------------------------------------------------------------------
|
|
//COPYFile(WebSubPaths,"");
|
|
Configuration::ReadConfigInit();
|
|
LanguageSwitching();
|
|
InitUi();
|
|
setAttribute(Qt::WA_TranslucentBackground); //设置窗口背景透明
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint); //去掉窗口边框
|
|
setAreaMovable(ui->widget_3->rect());
|
|
this->setWindowIcon(QIcon(":logo.png"));
|
|
CCString logopath = Configuration::ExePath + "logo.png";
|
|
QIcon trayIconIcon(logopath.c_str()); // 使用你的图标路径
|
|
trayIcon->setIcon(trayIconIcon);
|
|
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
|
connect(showAction, &QAction::triggered, this, &Widget::show);
|
|
trayIconMenu->addAction(showAction);
|
|
trayIconMenu->addAction(quitAction);
|
|
trayIcon->setContextMenu(trayIconMenu);
|
|
trayIcon->show();
|
|
SetPage(0);
|
|
Btns.emplace_back(ui->HomeBtn);
|
|
Btns.emplace_back(ui->SettingsBtn);
|
|
Initlogo();
|
|
//------------------------------------------------------------------------------------------------
|
|
connect(ui->HomeBtn, &QPushButton::clicked, this, &Widget::on_pushButton_clicked);
|
|
connect(ui->SelectSub_IPBtn, &QPushButton::clicked, this, &Widget::ReadSub_IP);
|
|
connect(ui->SettingsBtn, &QPushButton::clicked, this, &Widget::on_pushButton_clicked2);
|
|
connect(ui->CloseBtn, &QPushButton::clicked, this, [this](){this->close();});
|
|
connect(ui->MinBtn, &QPushButton::clicked, this, [this](){this->showMinimized();});
|
|
connect(ui->OpenServerBtn, &QPushButton::clicked, this, &Widget::OpenServerClick);
|
|
connect(ui->RestBtn, &QPushButton::clicked, this, &Widget::ServerConfigInit);
|
|
connect(ui->SetSaveBtn, &QPushButton::clicked, this, &Widget::SetSaveBtn);
|
|
connect(ui->ReadCSInfoBtn, &QPushButton::clicked, this, &Widget::ReadCSInfoFun);
|
|
connect(ui->Web_Port, &QLineEdit::textChanged,this, &Widget::onTextChanged);
|
|
connect(ui->OpenPCStart, &QCheckBox::stateChanged,this, &Widget::slotCheckedChanged);
|
|
connect(ui->LabguageBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
this, &Widget::onCurrentIndexChanged_t);
|
|
connect(ui->RapidDeployment, &QPushButton::clicked, this, [this]()
|
|
{
|
|
QMetaObject::invokeMethod(this, [this]() {
|
|
Deploy(this);
|
|
}, Qt::QueuedConnection);
|
|
});
|
|
if(Configuration::CORSEn == "true"){
|
|
ui->CORSEn->setChecked(true);
|
|
}
|
|
ui->Sub_Origins->setEnabled(ui->CORSEn->isChecked());
|
|
connect(ui->CORSEn, &QCheckBox::stateChanged,this, [this]()
|
|
{
|
|
ui->Sub_Origins->setEnabled(ui->CORSEn->isChecked());
|
|
SetState(ServerFlag);
|
|
});
|
|
connect(ui->GJSZBtn, &QPushButton::clicked,this, [this]()
|
|
{
|
|
auto* window = new widgetYZ(this);
|
|
int w = this->width() / 2 - (window->width() / 2);
|
|
int h = this->height() / 2 - (window->height() / 2);
|
|
window->move(w,h);
|
|
window->show();
|
|
});
|
|
ui->HomeBtn->setFocusPolicy(Qt::NoFocus);
|
|
ui->SettingsBtn->setFocusPolicy(Qt::NoFocus);
|
|
ui->CloseBtn->setFocusPolicy(Qt::NoFocus);
|
|
ui->MinBtn->setFocusPolicy(Qt::NoFocus);
|
|
ui->OpenServerBtn->setFocusPolicy(Qt::NoFocus);
|
|
//------------------------------------------------------------------------------------------------
|
|
ui->ServerConsele->append("Path:" + QApplication::applicationDirPath());
|
|
SetBtn(0);
|
|
Configuration::IPBS_NSSMF(false);
|
|
Configuration::CloseSub_Server();
|
|
Configuration::CloseSub_Web();
|
|
Configuration::IPBS_NSSMF(true);
|
|
CCThread([this](){
|
|
CCString State = Configuration::State;
|
|
CCString CORSEn = Configuration::CORSEn;
|
|
int Op = Configuration::OpenSleep;
|
|
if(Op > 0){
|
|
OpenSleepValue = Op;
|
|
}
|
|
if(State == "Open"){
|
|
while (OpenSleepValue > 0){
|
|
Threading::Sleep(1000 * 1000);
|
|
QMetaObject::invokeMethod(this, [this]() {
|
|
ui->ServerConsele->append(
|
|
CCString(std::to_string(OpenSleepValue) + Index::Lang("Note2")).c_str()
|
|
);
|
|
});
|
|
OpenSleepValue--;
|
|
if(ServerFlag){
|
|
break;
|
|
}
|
|
}
|
|
if(!ServerFlag){
|
|
OpenServerClick();
|
|
OpenFlagBtn(true);
|
|
}
|
|
}
|
|
if(CORSEn == "true"){
|
|
ui->CORSEn->setChecked(true);
|
|
}
|
|
else{
|
|
ui->CORSEn->setChecked(false);
|
|
}
|
|
while (ServerThread.Sign()){
|
|
if(ServerFlag){
|
|
char bus[1024] = {0};
|
|
sprintf(bus,"%d天%d小时%d分%d秒",t,h,f,s);
|
|
s++;
|
|
if(s >= 60){
|
|
f++;
|
|
s = 0;
|
|
if(f >= 60){
|
|
f = 0;
|
|
if(h >= 24){
|
|
t++;
|
|
h = 0;
|
|
}
|
|
h++;
|
|
}
|
|
}
|
|
QMetaObject::invokeMethod(this,[this,bus]()
|
|
{
|
|
QString str = bus;
|
|
ui->RunTime->setText(str);
|
|
});
|
|
}
|
|
QMetaObject::invokeMethod(this, [this](){
|
|
// 获取当前的日期和时间
|
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
// 将日期时间对象转换为字符串格式
|
|
QString currentTime = currentDateTime.toString("yyyy-MM-dd-hh:mm:ss");
|
|
ui->NowTime->setText(currentTime);
|
|
|
|
});
|
|
CCThread::Sleep(1000 * 1000);
|
|
}
|
|
}).detach();
|
|
if(Configuration::FirstRun == 1){
|
|
PrintMessage(Index::Lang("Note1"));
|
|
auto th = std::thread([this](){
|
|
CCThread::Sleep(1000 * 1000 * 5);
|
|
QMetaObject::invokeMethod(this, [this]() {
|
|
Deploy(this);
|
|
}, Qt::QueuedConnection);
|
|
});
|
|
th.detach();
|
|
}
|
|
ui->OpenPCStart->setCheckState(checkAutoStartEntry("IPBS_Station(Web)") ? Qt::Checked:Qt::Unchecked);
|
|
ServerThread.SetThread(&Widget::ServerListening,this);
|
|
ServerThread.Start();
|
|
OpenSerice(true);
|
|
JSON Ret;std::vector<JSON> Value;
|
|
for (int i = 0;i<1000;i++){
|
|
JSON A;
|
|
A["Vol"] = 8;
|
|
A["IP"] = "127.0.0.1";
|
|
Value.push_back(A);
|
|
}
|
|
Ret["State"] = Value;
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
}
|
|
|
|
Widget::~Widget(){
|
|
delete ui;
|
|
}
|
|
|
|
void Widget::on_pushButton_clicked() {
|
|
SetBtn(0);
|
|
SetPage(0);
|
|
}
|
|
|
|
void Widget::on_pushButton_clicked2() {
|
|
SetBtn(1);
|
|
SetPage(1);
|
|
}
|
|
|
|
void Widget::WebThreadRun() {
|
|
Configuration::OpenSub_Server();
|
|
while (Configuration::SubRun.IsRunning()){
|
|
CCString Line = Configuration::SubRun.ReadLineBuffer();
|
|
if(!Line.empty()){
|
|
CCString A = CCEncode::Format(Line,Encode.GBK,Encode.UTF8);
|
|
PrintMessage(A);
|
|
}
|
|
Threading::Sleep(1000 * 50);
|
|
}
|
|
// PrintMessage("Sub Close!");
|
|
}
|
|
|
|
void Widget::closeEvent(QCloseEvent *event) {
|
|
QMessageBox msgBox;
|
|
msgBox.setWindowTitle(tr(Index::Lang("ExitProgram").c_str()));
|
|
msgBox.setText(tr(Index::Lang("AreYouSureYouWantToQuit").c_str()));
|
|
QPushButton *yesButton = msgBox.addButton(tr(Index::Lang("EndProgram").c_str()), QMessageBox::YesRole);
|
|
msgBox.addButton(tr(Index::Lang("ToPallet").c_str()), QMessageBox::NoRole);
|
|
msgBox.exec();
|
|
if (msgBox.clickedButton() == yesButton)
|
|
{
|
|
Configuration::IPBS_NSSMF(false);
|
|
Configuration::CloseSub_Server();
|
|
Configuration::CloseSub_Web();
|
|
Configuration::State = "Close";
|
|
SetServerConfig();
|
|
ServerThread.Stop();
|
|
WebThread.Stop();
|
|
event->accept();
|
|
QCoreApplication::quit();
|
|
}
|
|
else
|
|
{
|
|
this->hide();
|
|
event->ignore(); // 阻止窗口关闭
|
|
}
|
|
}
|
|
|
|
bool Widget::WebRunFun() {
|
|
if(!ServerFlag){
|
|
if(!WebThread.Sign()){
|
|
ServerFlag = true;
|
|
SetState(ServerFlag);
|
|
CCThread([this](){
|
|
WebThreadRun();
|
|
}).detach();
|
|
CCThread([this]()
|
|
{
|
|
Configuration::OpenSub_Web();
|
|
while (Configuration::WebRun.IsRunning()){
|
|
CCString Line = Configuration::WebRun.ReadLineBuffer();
|
|
if(!Line.empty()){
|
|
PrintMessage(Line);
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
CCThread::Sleep(1000 * 1000);
|
|
}
|
|
PrintMessage("Link: " + Configuration::Web_URL);
|
|
}).detach();
|
|
QMetaObject::invokeMethod(this,[this]()
|
|
{
|
|
ui->URL_Text->setOpenExternalLinks(true);//设置为true才能打开网页
|
|
const CCString URL1 = "<a style='color: green;' href = "+ Configuration::Web_URL +"> "+ Configuration::Web_URL +"";
|
|
ui->URL_Text->setText(URL1.c_str());
|
|
});
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void Widget::SetPage(int i) {
|
|
// ui->ServerConsele->append(ServerSttingsPath.c_str());
|
|
ui->stackedWidget->setCurrentIndex(i);
|
|
if(i == 1){
|
|
InitUi();
|
|
}
|
|
}
|
|
|
|
void Widget::SetBtn(int i) {
|
|
for (auto & Btn : Btns) {
|
|
Btn->setStyleSheet("QPushButton{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(255, 255, 255, 0);\n"
|
|
"}\n"
|
|
"\n"
|
|
"QPushButton:hover{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(74,89,146, 255);\n"
|
|
"}");
|
|
}
|
|
Btns[i]->setStyleSheet("QPushButton{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(74,89,146, 255);\n"
|
|
"}\n"
|
|
"\n"
|
|
"QPushButton:hover{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(74,89,146, 255);\n"
|
|
"}");
|
|
}
|
|
|
|
void Widget::OpenServerClick() {
|
|
auto A = CText::ReadConfig(Configuration::CfgPath.c_str());
|
|
if(A.size() >= 8){
|
|
try {
|
|
ServerReRun();
|
|
}
|
|
catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
else{
|
|
QMessageBox::information(this,Index::Lang("Hint").c_str(),
|
|
Index::Lang("IncorrectStartupParameters").c_str());
|
|
}
|
|
}
|
|
|
|
void Widget::OpenFlagBtn(bool F) {
|
|
if(!F){
|
|
ui->OpenServerBtn->setStyleSheet("QPushButton{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(255,68,138,255);\n"
|
|
"}\n"
|
|
"\n"
|
|
"QPushButton:hover{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(255,100,150, 255);\n"
|
|
"}");
|
|
ui->OpenServerBtn->setText(Index::Lang("OpenService").c_str());
|
|
}
|
|
else{
|
|
ui->OpenServerBtn->setStyleSheet("QPushButton{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(255,0,0,255);\n"
|
|
"}\n"
|
|
"\n"
|
|
"QPushButton:hover{\n"
|
|
"\tborder-radius:10px;\n"
|
|
"\tcolor: rgb(255, 255, 255);\n"
|
|
"\tbackground-color: rgba(255,100,150, 255);\n"
|
|
"}");
|
|
ui->OpenServerBtn->setText(Index::Lang("ShutDownService").c_str());
|
|
}
|
|
}
|
|
|
|
void Widget::ServerListening() {
|
|
bool F = false,S = false;
|
|
while (ServerThread.Sign()){
|
|
Threading::Sleep(1000 * 1000 * 5);
|
|
try {
|
|
F = Configuration::GetSub_Status();
|
|
S = Configuration::GetSub_Web_Status();
|
|
QMetaObject::invokeMethod(this,[this,F,S]()
|
|
{
|
|
SetSuBState(F);
|
|
SetWebState(S);
|
|
});
|
|
if(!F && ServerFlag){
|
|
QMetaObject::invokeMethod(this, [this,&F](){
|
|
if(!F){
|
|
Configuration::OpenSub_Server();
|
|
PrintMessage("Sub Res Start OK!");
|
|
}
|
|
Threading::Sleep(1000 * 1000 * 5);
|
|
});
|
|
}
|
|
if(!S && ServerFlag){
|
|
try{
|
|
if(!S){
|
|
Configuration::OpenSub_Web();
|
|
PrintMessage("Web Res Start OK!");
|
|
PrintMessage("Link: " + Configuration::Web_URL);
|
|
}
|
|
Threading::Sleep(1000 * 1000 * 5);
|
|
}
|
|
catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
}
|
|
catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool Widget::isJarRunning(const char *jarName) {
|
|
#ifdef _WIN32
|
|
CCString str = jarName;
|
|
str.append(".exe");
|
|
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
if (hSnapshot == INVALID_HANDLE_VALUE) {
|
|
return false;
|
|
}
|
|
PROCESSENTRY32 pe32;
|
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
|
if (Process32First(hSnapshot, &pe32)) {
|
|
do {
|
|
if (_tcsstr(pe32.szExeFile, str.c_str()) != nullptr) {
|
|
CloseHandle(hSnapshot);
|
|
return true;
|
|
}
|
|
} while (Process32Next(hSnapshot, &pe32));
|
|
}
|
|
|
|
CloseHandle(hSnapshot);
|
|
return false;
|
|
#elif __linux__
|
|
#endif
|
|
}
|
|
|
|
void Widget::ServerReRun() {
|
|
if(ServerFlag){
|
|
try {
|
|
if(ServerFlag){
|
|
ServerFlag = false;
|
|
SetState(ServerFlag);
|
|
OpenFlagBtn(false);
|
|
WebThread.Stop();
|
|
PrintMessage("Server Close");
|
|
ui->RunTime->setVisible(false);
|
|
t = 0;h = 0;f = 0;s = 0;
|
|
}
|
|
Configuration::CloseSub_Server();
|
|
Configuration::CloseSub_Web();
|
|
}
|
|
catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
else{
|
|
WebRunFun();
|
|
OpenFlagBtn(true);
|
|
t = 0;h = 0;f = 0;s = 0;
|
|
ui->RunTime->setVisible(true);
|
|
}
|
|
}
|
|
|
|
void Widget::onCurrentIndexChanged(int index) {
|
|
ui->Web_IP->setText(ui->Sub_IP->text());
|
|
CCString URL = ui->Sub_IP->text().toStdString()+":"+ui->Web_Port->text().toStdString();
|
|
Configuration::Web_URL = "http://" + URL + '/';
|
|
QString str = CCString("['http://" + ui->Sub_IP->text().toStdString() + ":" + Configuration::Web_Port + "']").c_str();
|
|
ui->Sub_Origins->setText(str);
|
|
}
|
|
|
|
void Widget::onCurrentIndexChangedCSIP(int index)
|
|
{
|
|
try
|
|
{
|
|
if(CSPortList.empty())
|
|
{
|
|
return;
|
|
}
|
|
CCVar str = CCInt(CSPortList[index]).to_String().c_str();
|
|
ui->CS_Port->setText(str);
|
|
}
|
|
catch (CCException& exception){}
|
|
}
|
|
|
|
void Widget::SetSuBState(bool F) {
|
|
if(F){
|
|
ui->SubLabel->setStyleSheet("color: rgb(0, 255, 0);");
|
|
ui->SubLabel->setText(Index::Lang("SubLabel_1").c_str());
|
|
}
|
|
else{
|
|
ui->SubLabel->setStyleSheet("color: rgb(255, 0, 0);");
|
|
ui->SubLabel->setText(Index::Lang("SubLabel_0").c_str());
|
|
}
|
|
}
|
|
|
|
void Widget::SetWebState(bool F) {
|
|
if(F){
|
|
ui->WebLabel->setStyleSheet("color: rgb(0, 255, 0);");
|
|
ui->WebLabel->setText(Index::Lang("WebLabel_1").c_str());
|
|
}
|
|
else{
|
|
ui->WebLabel->setStyleSheet("color: rgb(255, 0, 0);");
|
|
ui->WebLabel->setText(Index::Lang("WebLabel_0").c_str());
|
|
}
|
|
}
|
|
|
|
void Widget::onTextChanged(const QString &text) {
|
|
ui->Web_IP->setText(ui->Sub_IP->text());
|
|
CCString URL = ui->Sub_IP->text().toStdString()+":"+ui->Web_Port->text().toStdString();
|
|
Configuration::Web_URL = "http://" + URL + '/';
|
|
QString str = CCString("['http://" + ui->Web_IP->text().toStdString() + ":" + text.toStdString() + "']").c_str();
|
|
ui->Sub_Origins->setText(str);
|
|
}
|
|
|
|
void Widget::SetSaveBtn() {
|
|
if(ui->CS_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote1").c_str());
|
|
return;
|
|
}
|
|
if(ui->CS_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote2").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote3").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote4").c_str());
|
|
return;
|
|
}
|
|
if(ui->Web_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote5").c_str());
|
|
return;
|
|
}
|
|
if(ui->Web_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote6").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Audio_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote7").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Origins->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote8").c_str());
|
|
return;
|
|
}
|
|
SetServerConfig();
|
|
QMessageBox::StandardButton reply = QMessageBox::question(this,
|
|
Index::Lang("Hint").c_str(), Index::Lang("ErrorNote9").c_str(),QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
if(ServerFlag){
|
|
try {
|
|
if(ServerFlag){
|
|
ServerFlag = false;
|
|
SetState(ServerFlag);
|
|
OpenFlagBtn(false);
|
|
WebThread.Stop();
|
|
PrintMessage("Server Close");
|
|
ui->RunTime->setVisible(false);
|
|
t = 0;h = 0;f = 0;s = 0;
|
|
}
|
|
Configuration::CloseSub_Server();
|
|
Configuration::CloseSub_Web();
|
|
}
|
|
catch (const std::exception& e) {
|
|
PrintMessage("Error: " + CCString(e.what()));
|
|
}
|
|
CCThread::Sleep(1000 * 100);
|
|
}
|
|
ServerReRun();
|
|
} else {
|
|
// 用户点击了“否”按钮
|
|
}
|
|
}
|
|
|
|
void Widget::ServerConfigInit() {
|
|
Configuration::CfgInit();
|
|
SetPage(1);
|
|
const QMessageBox::StandardButton reply = QMessageBox::question(this, Index::Lang("Hint").c_str(),
|
|
Index::Lang("ErrorNote10").c_str(),
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
SetSaveBtn();
|
|
}
|
|
else {
|
|
|
|
}
|
|
}
|
|
|
|
void Widget::Initlogo() {
|
|
CCString str = Configuration::ExePath + Sub_Logo;
|
|
QPixmap pixmap(str.c_str()); // 替换为你的图片路径
|
|
ui->logoIMG->setPixmap(pixmap);
|
|
ui->logoIMG->setScaledContents(true); // 图片自动缩放以适应 QLabel 大小
|
|
ui->logoIMG->setMaximumSize(111,61); // 设置 QLabel 最小尺寸
|
|
ui->logoIMG->setMaximumSize(320,180); // 设置 QLabel 最小尺寸
|
|
ImGLoad = ui->logoIMG;
|
|
}
|
|
|
|
void Widget::SetServerConfig() {
|
|
Configuration::CS_IP = ui->CS_IP->text().toStdString();
|
|
Configuration::CS_Port = ui->CS_Port->text().toStdString();
|
|
Configuration::Sub_IP = ui->Sub_IP->text().toStdString();
|
|
Configuration::Sub_Port = ui->Sub_Port->text().toStdString();
|
|
Configuration::Sub_Audio_Port = ui->Sub_Audio_Port->text().toStdString();
|
|
Configuration::Web_IP = ui->Web_IP->text().toStdString();
|
|
Configuration::Web_Port = ui->Web_Port->text().toStdString();
|
|
Configuration::Sub_Org = ui->Sub_Origins->text().toStdString();
|
|
Configuration::Language = ui->LabguageBox->currentText().toStdString();
|
|
Configuration::OpenSleep = ui->OpenSleep->value();
|
|
Configuration::SaveJarCfg();
|
|
Configuration::SaveWebCfg();
|
|
Configuration::ReadConfigInit();
|
|
}
|
|
|
|
void Widget::SetState(bool F) {
|
|
Configuration::State = F ? "Open" : "Close";
|
|
Configuration::CORSEn = ui->CORSEn->isChecked() ? "true" : "false";
|
|
SetServerConfig();
|
|
}
|
|
|
|
void Widget::SetAutoStart(const QString &path, bool enable) {
|
|
QSettings startupSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", QSettings::NativeFormat);
|
|
if (enable) {
|
|
startupSettings.setValue("IPBS_Station(Web)", path);
|
|
}
|
|
else {
|
|
startupSettings.remove("IPBS_Station(Web)");
|
|
}
|
|
}
|
|
|
|
void Widget::OpenSerice(bool F) {
|
|
#ifdef _WIN32
|
|
|
|
#elif __linux__
|
|
|
|
#endif
|
|
}
|
|
|
|
void Widget::slotCheckedChanged(int i) {
|
|
CCString str = "IPBS_Start";
|
|
if(ui->OpenPCStart->isChecked()){
|
|
SetAutoStart(str.c_str(),true);
|
|
}
|
|
else{
|
|
SetAutoStart(str.c_str(),false);
|
|
}
|
|
str = Configuration::ExePath + QApplication::applicationName().toStdString() + ".exe.lnk";
|
|
if(ui->OpenPCStart->isChecked()){
|
|
CreateShortO();
|
|
CCString A = OpenKit + QApplication::applicationName().toStdString() + ".exe.lnk";
|
|
CCFile file = CCFile(str.c_str(), CC::ios::w,false);
|
|
file.Copy(A);
|
|
file.Deleted();
|
|
}
|
|
else{
|
|
str = OpenKit + QApplication::applicationName().toStdString() + ".exe.lnk";
|
|
CCFile file = CCFile(str.c_str(), CC::ios::w,false);
|
|
file.Deleted();
|
|
}
|
|
}
|
|
|
|
void Widget::ReadCSInfoFun(){
|
|
CCVar* cs4 = new CSInfoW4(this);
|
|
int w = this->width() / 2 - (cs4->width() / 2);
|
|
int h = this->height() / 2 - (cs4->height() / 2);
|
|
cs4->move(w,h);
|
|
cs4->IPEdit1 = ui->CS_IP;
|
|
cs4->IPEdit2 = ui->CS_Port;
|
|
cs4->exec();
|
|
}
|
|
|
|
void Widget::PrintMessage(CCString str)
|
|
{
|
|
QMetaObject::invokeMethod(this,[this,str]()
|
|
{
|
|
const CCTimeData time;
|
|
CCString S = "[" + time.to_String() + "] -> " + str;
|
|
ui->ServerConsele->append(S.c_str());
|
|
});
|
|
}
|
|
|
|
void Widget::ReadSub_IP(){
|
|
CCVar* sub = new Sub_IPUI(this);
|
|
int w = this->width() / 2 - (sub->width() / 2);
|
|
int h = this->height() / 2 - (sub->height() / 2);
|
|
sub->move(w,h);
|
|
sub->IPEdit = ui->Sub_IP;
|
|
sub->show();
|
|
}
|
|
|
|
void Widget::Deploy(QWidget* PR){
|
|
Configuration::CloseSub_Server();
|
|
Configuration::CloseSub_Web();
|
|
if(ServerFlag){
|
|
const QMessageBox::StandardButton reply = QMessageBox::question(PR, Index::Lang("Hint").c_str(),
|
|
Index::Lang("ErrorNote11").c_str(),
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
ServerReRun();
|
|
}
|
|
else {
|
|
QMessageBox::information(PR, Index::Lang("Hint").c_str(),
|
|
Index::Lang("ErrorNote12").c_str());
|
|
}
|
|
}
|
|
boolean F1 = false,F2 = false;
|
|
PrintMessage(Index::Lang("ErrorNote13"));
|
|
while (true){
|
|
CCThread::Sleep(1000 * 500);
|
|
Configuration::ReadSub_IP();
|
|
if(!Configuration::SubIPList.empty()){
|
|
if(Configuration::SubIPList.size() > 1){
|
|
PrintMessage(Index::Lang("ErrorNote14").c_str());
|
|
CCVar* sub = new Sub_IPUI(nullptr);
|
|
int top = this->geometry().top();
|
|
int left = this->geometry().left();
|
|
int screenWidth = this->width();
|
|
int screenHeight = this->height();
|
|
int w = screenWidth / 2 - (sub->width() / 2) + left;
|
|
int h = screenHeight / 2 - (sub->height() / 2) + top;
|
|
sub->move(w,h);
|
|
sub->IPEdit = ui->Sub_IP;
|
|
const int ret = sub->exec();
|
|
if(ret == QDialog::Accepted){
|
|
PrintMessage(Index::Lang("ErrorNote15").c_str());
|
|
}
|
|
else if (ret == QDialog::Rejected){
|
|
Configuration::Sub_IP = "";
|
|
F2 = false;
|
|
PrintMessage(Index::Lang("ErrorNote16").c_str());
|
|
break;
|
|
}
|
|
}
|
|
else{
|
|
Configuration::Sub_IP = Configuration::SubIPList[0];
|
|
PrintMessage(Index::Lang("ErrorNote17").c_str());
|
|
}
|
|
F2 = true;
|
|
break;
|
|
}
|
|
else{
|
|
bool A1 = false,A2 = false;
|
|
const QMessageBox::StandardButton reply = QMessageBox::question(PR,
|
|
Index::Lang("Hint").c_str(),Index::Lang("ErrorNote18").c_str(),
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
A2 = true;
|
|
A1 = true;
|
|
}
|
|
else {
|
|
Configuration::Sub_IP = "";
|
|
A2 = true;
|
|
F2 = false;
|
|
PrintMessage(Index::Lang("ErrorNote16").c_str());
|
|
}
|
|
if(A1){
|
|
continue;
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
PrintMessage(Index::Lang("ErrorNote19"));
|
|
while (true){
|
|
PrintMessage(Index::Lang("ErrorNote20"));
|
|
CCThread::Sleep(1000 * 500);
|
|
Configuration::ReadCSInfo();
|
|
if(!Configuration::CSIPList.empty()){
|
|
if(Configuration::CSIPList.size() > 1){
|
|
PrintMessage(Index::Lang("ErrorNote21"));
|
|
CCVar* cs4 = new CSInfoW4(nullptr);
|
|
int top = this->geometry().top();
|
|
int left = this->geometry().left();
|
|
int screenWidth = this->width();
|
|
int screenHeight = this->height();
|
|
int w = screenWidth / 2 - (cs4->width() / 2) + left;
|
|
const int h = screenHeight / 2 - (cs4->height() / 2) + top;
|
|
cs4->move(w,h);
|
|
cs4->IPEdit1 = ui->CS_IP;
|
|
cs4->IPEdit2 = ui->CS_Port;
|
|
const int ret = cs4->exec();
|
|
if(ret == QDialog::Accepted){
|
|
PrintMessage(Index::Lang("ErrorNote22"));
|
|
}
|
|
else if (ret == QDialog::Rejected){
|
|
Configuration::CS_IP = "";
|
|
Configuration::CS_Port = "";
|
|
F1 = false;
|
|
PrintMessage(Index::Lang("ErrorNote23"));
|
|
break;
|
|
}
|
|
}
|
|
else{
|
|
Configuration::CS_IP = Configuration::CSIPList[0];
|
|
Configuration::CS_Port = Configuration::CSPortList[0].to_String();
|
|
PrintMessage(Index::Lang("ErrorNote22"));
|
|
}
|
|
F1 = true;
|
|
break;
|
|
}
|
|
else{
|
|
bool A1 = false;
|
|
Configuration::CS_IP = "";
|
|
Configuration::CS_Port = "";
|
|
QMessageBox::StandardButton reply = QMessageBox::question(PR, Index::Lang("Hint").c_str(),
|
|
Index::Lang("ErrorNote35").c_str(),QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
A1 = true;
|
|
}
|
|
else {
|
|
Configuration::CS_IP = "";
|
|
Configuration::CS_Port = "";
|
|
F1 = false;
|
|
PrintMessage(Index::Lang("ErrorNote23"));
|
|
A1 = false;
|
|
}
|
|
if(A1){
|
|
continue;
|
|
}
|
|
else{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
PrintMessage(Index::Lang("ErrorNote24"));
|
|
CCVar Ports = Configuration::getAvailablePorts(3,5417);
|
|
if(Ports.size() == 3){
|
|
Configuration::Sub_Port = Ports[0].to_String();
|
|
Configuration::Sub_Audio_Port = Ports[1].to_String();
|
|
Configuration::Web_Port = Ports[2].to_String();
|
|
Configuration::Web_IP = Configuration::Sub_IP;
|
|
}
|
|
else{
|
|
Configuration::Sub_Port = "";
|
|
Configuration::Sub_Audio_Port = "";
|
|
Configuration::Web_Port = "";
|
|
Configuration::Web_IP = Configuration::Sub_IP = "";
|
|
}
|
|
PrintMessage(Index::Lang("ErrorNote25"));
|
|
PrintMessage(Index::Lang("ErrorNote26"));
|
|
Configuration::Sub_Org = "['http://" + Configuration::Web_IP + ":" + Configuration::Web_Port + "']";
|
|
PrintMessage(Index::Lang("ErrorNote27"));
|
|
ui->CS_IP->setText(Configuration::CS_IP.c_str());
|
|
ui->CS_Port->setText(Configuration::CS_Port.c_str());
|
|
ui->Sub_IP->setText(Configuration::Sub_IP.c_str());
|
|
ui->Sub_Port->setText(Configuration::Sub_Port.c_str());
|
|
ui->Sub_Audio_Port->setText(Configuration::Sub_Audio_Port.c_str());
|
|
ui->Sub_Origins->setText(Configuration::Sub_Org.c_str());
|
|
if(Configuration::Language == "English"){
|
|
ui->LabguageBox->setCurrentIndex(1);
|
|
}
|
|
else{
|
|
ui->LabguageBox->setCurrentIndex(0);
|
|
}
|
|
ui->Web_Port->setText(Configuration::Web_Port.c_str());
|
|
ui->Web_IP->setText(ui->Sub_IP->text());
|
|
ui->OpenSleep->setValue(Configuration::OpenSleep);
|
|
PrintMessage(Index::Lang("ErrorNote28"));
|
|
PrintMessage(Index::Lang("ErrorNote29"));
|
|
SetServerConfig();
|
|
PrintMessage(Index::Lang("ErrorNote30"));
|
|
if(F1 && F2){
|
|
try {
|
|
Configuration::terminateProcessByName("java");
|
|
Configuration::terminateProcessByName("nginx");
|
|
if(ServerFlag){
|
|
WebThread.Stop();
|
|
ui->ServerConsele->append("Server Close");
|
|
OpenFlagBtn(false);
|
|
ServerFlag = false;
|
|
SetState(ServerFlag);
|
|
ui->RunTime->setVisible(false);
|
|
t = 0;h = 0;f = 0;s = 0;
|
|
}
|
|
}
|
|
catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
}
|
|
if(ui->CS_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote1").c_str());
|
|
return;
|
|
}
|
|
if(ui->CS_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote2").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote3").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote4").c_str());
|
|
return;
|
|
}
|
|
if(ui->Web_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote5").c_str());
|
|
return;
|
|
}
|
|
if(ui->Web_IP->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote6").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Audio_Port->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote7").c_str());
|
|
return;
|
|
}
|
|
if(ui->Sub_Origins->text().isEmpty()){
|
|
QMessageBox::information(this, "Error", Index::Lang("ErrorNote8").c_str());
|
|
return;
|
|
}
|
|
PrintMessage(Index::Lang("ErrorNote31"));
|
|
OpenServerClick();
|
|
}
|
|
else{
|
|
if(!F1){
|
|
PrintMessage(Index::Lang("ErrorNote32"));
|
|
}
|
|
if(!F2){
|
|
PrintMessage(Index::Lang("ErrorNote33"));
|
|
}
|
|
PrintMessage(Index::Lang("ErrorNote34"));
|
|
}
|
|
}
|
|
|
|
void Widget::InitUi(){
|
|
ui->CS_IP->setText(Configuration::CS_IP.c_str());
|
|
ui->CS_Port->setText(Configuration::CS_Port.c_str());
|
|
ui->Sub_IP->setText(Configuration::Sub_IP.c_str());
|
|
ui->Sub_Port->setText(Configuration::Sub_Port.c_str());
|
|
ui->Sub_Audio_Port->setText(Configuration::Sub_Audio_Port.c_str());
|
|
ui->Sub_Origins->setText(Configuration::Sub_Org.c_str());
|
|
if(Configuration::Language == "English"){
|
|
ui->LabguageBox->setCurrentIndex(1);
|
|
}
|
|
else{
|
|
ui->LabguageBox->setCurrentIndex(0);
|
|
}
|
|
ui->Web_Port->setText(Configuration::Web_Port.c_str());
|
|
ui->Web_IP->setText(ui->Sub_IP->text());
|
|
ui->OpenSleep->setValue(Configuration::OpenSleep);
|
|
}
|
|
|
|
bool Widget::checkAutoStartEntry(const QString &appName) {
|
|
QSettings startupSettings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", QSettings::NativeFormat);
|
|
return startupSettings.contains(appName);
|
|
}
|
|
|
|
void Widget::LanguageSwitching() {
|
|
if(Configuration::Language == "English"){
|
|
Index::Language = 1;
|
|
}
|
|
else{
|
|
Index::Language = 0;
|
|
}
|
|
ui->label_12->setText(Index::Lang("label_12").c_str());
|
|
ui->OpenServerBtn->setText(Index::Lang("OpenServerBtn").c_str());
|
|
ui->RapidDeployment->setText(Index::Lang("RapidDeployment").c_str());
|
|
ui->groupBox->setTitle(Index::Lang("groupBox").c_str());
|
|
ui->label->setText(Index::Lang("label").c_str());
|
|
ui->label_2->setText(Index::Lang("label_2").c_str());
|
|
ui->label_3->setText(Index::Lang("label_3").c_str());
|
|
ui->label_4->setText(Index::Lang("label_4").c_str());
|
|
ui->label_5->setText(Index::Lang("label_5").c_str());
|
|
ui->label_6->setText(Index::Lang("label_6").c_str());
|
|
ui->CORSEn->setText(Index::Lang("CORSEn").c_str());
|
|
ui->label_7->setText(Index::Lang("label_7").c_str());
|
|
ui->groupBox_2->setTitle(Index::Lang("groupBox_2").c_str());
|
|
ui->label_9->setText(Index::Lang("label_9").c_str());
|
|
ui->label_8->setText(Index::Lang("label_8").c_str());
|
|
ui->label_10->setText(Index::Lang("label_10").c_str());
|
|
ui->RestBtn->setText(Index::Lang("RestBtn").c_str());
|
|
ui->GJSZBtn->setText(Index::Lang("GJSZBtn").c_str());
|
|
ui->OpenPCStart->setText(Index::Lang("OpenPCStart").c_str());
|
|
ui->SetSaveBtn->setText(Index::Lang("SetSaveBtn").c_str());
|
|
ui->HomeBtn->setText(Index::Lang("HomeBtn").c_str());
|
|
ui->SettingsBtn->setText(Index::Lang("SettingsBtn").c_str());
|
|
ui->label_13->setText(Index::Lang("label_13").c_str());
|
|
ui->ReadCSInfoBtn->setText(Index::Lang("Choose").c_str());
|
|
ui->SelectSub_IPBtn->setText(Index::Lang("Choose").c_str());
|
|
}
|
|
|
|
void Widget::onCurrentIndexChanged_t(int index) {
|
|
Configuration::Language = ui->LabguageBox->currentText().toStdString();
|
|
LanguageSwitching();
|
|
}
|
|
|
|
|
|
|
|
|