171 lines
5.1 KiB
C++
171 lines
5.1 KiB
C++
#ifndef UDATABASE_H
|
||
#define UDATABASE_H
|
||
|
||
#include "donationmanager.h"
|
||
#include "qlistwidget.h"
|
||
#include <QObject>
|
||
#include <QString>
|
||
#include <QSqlDatabase>
|
||
#include <QSqlQuery>
|
||
#include <QSqlError>
|
||
#include <QVariant>
|
||
#include <QDebug>
|
||
#include <QFile>
|
||
#include <QTableWidget>
|
||
#include "timerinfo.h"
|
||
#include "webserverchat.h"
|
||
#include "webservernotify.h"
|
||
|
||
struct ChatSettings {
|
||
int id;
|
||
QString name;
|
||
QString type; // "chat" или "notification"
|
||
int port;
|
||
QStringList fontList;
|
||
QString backgroundColor;
|
||
QString blockColor;
|
||
QString borderColor;
|
||
int borderSize;
|
||
int padding;
|
||
int transparency;
|
||
QString fontFamily;
|
||
int fontSize;
|
||
QString fontColor;
|
||
bool freez;
|
||
int messageTimeout;
|
||
int maxMsgCount;
|
||
bool deleteByTime;
|
||
};
|
||
|
||
struct NotificationSettings {
|
||
int id;
|
||
QString name;
|
||
QString type;
|
||
int port;
|
||
QString blockColor;
|
||
QString borderColor;
|
||
int borderSize;
|
||
int transparency;
|
||
QString pageBackgroundColor;
|
||
QString titleFamily;
|
||
int titleSize;
|
||
QString titleColor;
|
||
QString contentFamily;
|
||
int contentSize;
|
||
QString contentColor;
|
||
int duration;
|
||
QDateTime createdAt;
|
||
};
|
||
|
||
struct ActionData {
|
||
int id = -1;
|
||
int type = 0; // 0 - клавиши, 1 - звук, 2 - уведомление
|
||
QString keyCombination;
|
||
QString audioFile;
|
||
QString notificationTitle;
|
||
QString notificationDescription;
|
||
QString notificationImage;
|
||
QString notificationSound;
|
||
};
|
||
|
||
struct EventActionLink {
|
||
int id;
|
||
QString eventType;
|
||
QString eventName;
|
||
int actionId;
|
||
};
|
||
|
||
class uDataBase : public QObject
|
||
{
|
||
Q_OBJECT
|
||
// Информация о таймере
|
||
|
||
|
||
public:
|
||
// Конструктор с указанием файла базы данных
|
||
explicit uDataBase(const QString& dbFileName, QObject* parent = nullptr);
|
||
|
||
// Деструктор
|
||
~uDataBase();
|
||
|
||
|
||
|
||
// Чтение настройки
|
||
QString readSetting(const QString& aName, const QString& aDefault = "");
|
||
|
||
// Запись настройки
|
||
bool writeSetting(const QString& aName, const QString& aValue);
|
||
|
||
|
||
bool LoadTableWidget(QTableWidget *tableWidget);
|
||
bool clearTable(const QString &tableName);
|
||
bool createTableForWidget(const QString &tableName, int columnCount);
|
||
bool tableExists(const QString &tableName);
|
||
bool SaveTableWidget(QTableWidget *tableWidget);
|
||
bool SaveTimers(QTableWidget *tableWidget, const QList<TimerInfo> &timers);
|
||
bool LoadTimers(QTableWidget *tableWidget, QList<TimerInfo> &timers);
|
||
bool SaveGroupResponses(const QString &groupName, const QStringList &responses);
|
||
bool createGroupResponseTable();
|
||
bool DeleteResponse(const QString &groupName, const QString &ResponseName);
|
||
bool DeleteGroup(const QString &groupName);
|
||
bool AddGroupResponse(const QString &groupName, const QString &response);
|
||
QString ProcessResponseTemplate(const QString &templateText);
|
||
QString GetRandomResponse(const QString &groupName);
|
||
bool LoadRandomResponses(const QString &groupName, QListWidget *listWidget);
|
||
bool LoadRandomGroups(QListWidget *listWidget);
|
||
QString ProcessResponseTemplateRecursive(const QString &templateText, int depth);
|
||
|
||
|
||
bool createChatsTable();
|
||
bool saveChat(const QString &name, const QString &type,
|
||
HttpServerChat *server, const QString &fontList);
|
||
bool updateChat(const QString &name, HttpServerChat *server,
|
||
const QString &fontList, int oldPort);
|
||
bool deleteChat(int port);
|
||
QList<ChatSettings> loadAllChats();
|
||
|
||
// Методы для уведомлений
|
||
bool createNotificationsTable();
|
||
bool saveNotification(const QString &name, HttpServer *server);
|
||
bool updateNotification(const QString &name, HttpServer *server, int oldPort);
|
||
QList<NotificationSettings> loadAllNotifications();
|
||
bool deleteNotification(int port);
|
||
|
||
// Проверка подключения к БД
|
||
bool isConnected() const;
|
||
|
||
bool close();
|
||
// Получение последней ошибки
|
||
QString lastError() const;
|
||
|
||
bool createActionsTable();
|
||
bool saveAction(const ActionData &action);
|
||
bool updateAction(int id, const ActionData &action);
|
||
bool deleteAction(int id);
|
||
QList<ActionData> loadAllActions();
|
||
bool clearActionsTable();
|
||
|
||
bool createDonationTriggersTable();
|
||
int saveDonationTrigger(const DonationTrigger &trigger);
|
||
bool deleteDonationTrigger(int id);
|
||
QList<DonationTrigger> loadAllDonationTriggers();
|
||
|
||
bool saveEventActionLink(const QString &eventType, const QString &eventName, int actionId);
|
||
bool deleteEventActionLink(int id);
|
||
QList<EventActionLink> getLinksForEvent(const QString &eventType, const QString &eventName);
|
||
bool deleteLinksForEvent(const QString &eventType, const QString &eventName);
|
||
bool deleteLinksByActionId(int actionId);
|
||
private:
|
||
|
||
|
||
|
||
// Инициализация базы данных (создание таблицы, если нужно)
|
||
bool initializeDatabase();
|
||
|
||
QSqlDatabase m_db;
|
||
QString m_dbFileName;
|
||
QString m_lastError;
|
||
};
|
||
|
||
#endif // DBSETTINGS_H
|