first commit

This commit is contained in:
2026-01-26 22:26:19 +03:00
commit 31fccd85f2
95 changed files with 115400 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
#ifndef WEBSERVERNOTIFY_H
#define WEBSERVERNOTIFY_H
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QMap>
#include <QFile>
#include <QTimer>
#include <QList>
#include <QJsonArray>
#include <QJsonObject>
#include <QDateTime>
struct Notification {
QString nickname;
QString url;
QString content;
QString soundURL;
QString blockColor;
QString borderColor;
int borderSize;
int duration;
QString titleColor;
QString titleFamily;
int titleSize;
QString contentColor;
QString contentFamily;
int contentSize;
qint64 timestamp;
// Новое поле для цвета фона страницы
QString pageBackgroundColor;
Notification() :
borderSize(2),
duration(10),
titleSize(16),
contentSize(14),
timestamp(0),
pageBackgroundColor("transparent") // По умолчанию прозрачный
{}
};
class HttpServer : public QObject
{
Q_OBJECT
public:
explicit HttpServer(QObject *parent = nullptr);
~HttpServer();
bool start(quint16 port);
void stop();
quint16 port() const;
void addNotification(const Notification &notification);
void clearNotifications();
signals:
void serverStarted(bool success);
private slots:
void onNewConnection();
void readClient();
void discardClient();
private:
QTcpServer *m_server;
QList<QTcpSocket*> m_clients;
QList<Notification> m_notifications;
QString m_pageBackgroundColor; // Цвет фона страницы
void processRequest(QTcpSocket *socket, const QString &request);
void sendResponse(QTcpSocket *socket, const QString &contentType, const QString &content, int statusCode = 200);
void sendHtmlPage(QTcpSocket *socket);
void sendJSONMessages(QTcpSocket *socket);
void serveStaticFile(QTcpSocket *socket, const QString &filePath);
QString getMimeType(const QString &filePath);
QString generateHTML();
QString generateJSON();
void cleanOldMessages();
};
#endif // WEBSERVERNOTIFY_H