126 lines
3.4 KiB
C++
126 lines
3.4 KiB
C++
#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 ¬ification);
|
|
void clearNotifications();
|
|
|
|
// Методы для доступа к настройкам (нужно реализовать хранение)
|
|
void setBlockColor(const QString &color);
|
|
QString getBlockColor() const;
|
|
void setBorderColor(const QString &color);
|
|
QString getBorderColor() const;
|
|
void setBorderSize(int size);
|
|
int getBorderSize() const;
|
|
void setTransparency(int transparency);
|
|
int getTransparency() const;
|
|
void setPageBackgroundColor(const QString &color);
|
|
QString getPageBackgroundColor() const;
|
|
void setTitleFont(const QString &family, int size, const QString &color);
|
|
void getTitleFont(QString &family, int &size, QString &color) const;
|
|
void setContentFont(const QString &family, int size, const QString &color);
|
|
void getContentFont(QString &family, int &size, QString &color) const;
|
|
void setDuration(int duration);
|
|
int getDuration() const;
|
|
|
|
|
|
QString getTitleFamily() const;
|
|
int getTitleSize() const;
|
|
QString getTitleColor() const;
|
|
QString getContentFamily() const;
|
|
int getContentSize() const;
|
|
QString getContentColor() const;
|
|
|
|
|
|
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; // Цвет фона страницы
|
|
|
|
|
|
QString m_blockColor;
|
|
QString m_borderColor;
|
|
int m_borderSize;
|
|
int m_transparency;
|
|
QString m_titleFamily;
|
|
int m_titleSize;
|
|
QString m_titleColor;
|
|
QString m_contentFamily;
|
|
int m_contentSize;
|
|
QString m_contentColor;
|
|
int m_duration;
|
|
|
|
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
|