IPBS_Station/widget.h
“zhangsan” 7fa0d39fed V0.3
2024-08-22 17:26:05 +08:00

199 lines
6.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "CCSocket.h"
#include "CCThread.h"
#include "nlohmann/json.hpp"
#include "QMessageBox"
#include "ctime"
#include <QCloseEvent>
#include <QPaintEvent>
#include <QPainter>
#include <QMetaMethod>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QProcess>
#include "QDateTime"
#include "QCoreApplication"
#include "CCString.h"
#include "QFile"
#include "CCFile.h"
#include "vector"
#include "Tools/CText.h"
#include <QAbstractSocket>
#include <QHostAddress>
#include <QNetworkInterface>
#include <QFileDialog>
#include <QSettings>
#include <QApplication>
#include <filesystem>
#include <fstream>
#include <QDir>
#include <QDesktopServices>
#include <QShortcut>
#ifdef _WIN32
#include <tchar.h>
#include <windows.h>
#include <tlhelp32.h>
#include <shlobj.h> // 包含 ShellLink 和 IPersistFile 接口
#elif __linux__
#endif
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
namespace fs = std::filesystem;
class Widget : public QWidget
{
Q_OBJECT
private:
//E:/project/UDate/Project/QtProject/WebDeploy/
const CCString WebSubPaths = QApplication::applicationDirPath().toStdString() + "/";
const CCString ServerSttingsPath = WebSubPaths + "src/main/resources/ServerSettings/ServerSettings.CText";
const CCString NginxSttingsPath = WebSubPaths + "conf/nginx.conf";
CCThread WebThread, ServerThread;
#ifdef _WIN32
const CCString OpenKit = "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp/";
const CCString NginxExe = WebSubPaths + "nginx.exe";
const CCString JavaExe = "WebSub/jreWin/bin/java.exe";
#elif __linux__
const CCString NginxExe = "./WebSub/nginx";
const CCString JavaExe = "WebSub/jreLinux/bin/java";
#endif
QRect m_areaMovable;//可移动窗口的区域,鼠标只有在该区域按下才能移动窗口
bool m_bPressed,closeflag = false;//鼠标按下标志(不分左右键)
QPoint m_ptPress;//鼠标按下的初始位置
QProcess* NginxP;
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
QMenu *trayIconMenu = new QMenu(this);
QAction *quitAction = new QAction(tr("&退出"), this);
QAction *showAction = new QAction(tr("&显示"), this);
std::map<CCString,CCString> ServerSettings;
int t = 0,h = 0,f = 0,s = 0;
int OpenSleepValue = 10;
public:
Widget(QWidget *parent = nullptr);
~Widget();
void on_pushButton_clicked();
void on_pushButton_clicked2();
void WebThreadRun();
bool WebRunFun();
void ServerListening();
void OpenServerClick();
bool isJarRunning(const char* jarName);
bool terminateProcessByName(const char* processName);
void ServerReRun();
void onCurrentIndexChanged(int index);
void SetSuBState(bool F);
void SetWebState(bool F);
void SetSaveBtn();
void Initlogo();
void SelectFile();
void slotCheckedChanged(int i);
private:
Ui::Widget *ui;
bool ServerFlag = false;
std::vector<QPushButton*> Btns;
void OpenFlagBtn(bool F);
void SetPage(int i);
void SetBtn(int i);
void ServerConfigInit();
void onTextChanged(const QString &text);
void SetServerConfig();
void SetState(bool F);
bool checkAutoStartEntry(const QString &appName);
void SetAutoStart(const QString &path, bool enable);
void OpenSerice(bool F);
void copy_file(const fs::path& source, const fs::path& dest) {
std::ifstream src(source, std::ios::binary);
std::ofstream dst(dest, std::ios::binary);
dst << src.rdbuf();
}
void copy_directory_recursively(const fs::path& source, const fs::path& dest) {
// 如果目标目录不存在,则创建它
if (!fs::exists(dest)) {
fs::create_directories(dest);
}
for (const auto& entry : fs::directory_iterator(source)) {
fs::path dest_path = dest / entry.path().filename();
if (entry.is_regular_file()) {
// 复制文件
copy_file(entry.path(), dest_path);
} else if (entry.is_directory()) {
// 递归复制子目录
copy_directory_recursively(entry.path(), dest_path);
}
}
}
bool COPYFile(fs::path n,fs::path m){
try {
copy_directory_recursively(n, m);
return true;
} catch (const fs::filesystem_error& e) {
return false;
}
}
protected:
void closeEvent(QCloseEvent *event) override;
void paintEvent(QPaintEvent * event) override{
QPainter painter(this);// 创建一个QPainter对象并指定绘制设备为this即当前窗口
painter.setRenderHint(QPainter::Antialiasing); // 设置绘制选项为反锯齿,使绘制的图形边缘更加平滑
painter.setBrush(QBrush(QColor(255, 255, 255))); //设置画刷颜色,这里为白色
painter.setPen(Qt::transparent); //设置画笔颜色为透明,即不绘制边框线
QRect rect = this->rect(); //获取当前窗口的矩形区域
painter.drawRoundedRect(rect, 15, 15);
}
void mousePressEvent(QMouseEvent *e) override {
// 鼠标左键
if (e->button() == Qt::LeftButton) {
m_ptPress = e->pos();
m_bPressed = true; // 修改这里总是设置为true因为我们希望点击控件时移动窗口
}
}
void mouseMoveEvent(QMouseEvent *e) override {
if (m_bPressed) {
move(pos() + e->pos() - m_ptPress);
}
}
void mouseReleaseEvent(QMouseEvent *) override {
m_bPressed = false;
}
void setAreaMovable(const QRect rt) {
// 这里不需要再判断是否改变,因为我们将直接在控件上响应鼠标事件
m_areaMovable = rt;
}
};
#endif // WIDGET_H
#ifdef _WIN32
inline void CreateShortO(){
CoInitialize(nullptr);
IShellLink* psl;
CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
CCString str = QApplication::applicationFilePath().toStdString();
CCString str1 = QApplication::applicationDirPath().toStdString() + "/IPBS_Station.exe.lnk";
CCString workingDir = QApplication::applicationDirPath().toStdString();
psl->SetPath(str.c_str());
psl->SetWorkingDirectory(workingDir.c_str());
IPersistFile* ppf;
psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
WCHAR wszPath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, str1.c_str(), -1, wszPath, MAX_PATH);
ppf->Save(wszPath, TRUE);
ppf->Release();
psl->Release();
CoUninitialize();
}
#elif __linux__
#endif