Choice model settings was added

This commit is contained in:
2023-04-10 19:24:25 +02:00
parent 25e8a3ea79
commit 4a52926be9
31 changed files with 938 additions and 227 deletions

View File

@@ -12,6 +12,13 @@
BeerService::BeerService()
: QObject{nullptr}
{
m_actions = {
{ ActionGet, "get" },
{ ActionAdd, "add" },
{ ActionDelete, "del" },
{ ActionModify, "mod" }
};
restoreStash();
connect(&m_socket, &QWebSocket::textMessageReceived, this, [this](QString message) {
@@ -31,7 +38,7 @@ BeerService::BeerService()
}
});
connect(&m_socket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, [this](QAbstractSocket::SocketError error) {
connect(&m_socket, &QWebSocket::errorOccurred, this, [this](QAbstractSocket::SocketError error) {
qInfo() << error << m_socket.errorString();
});
@@ -60,11 +67,13 @@ SettingsService *BeerService::settings() const
return SettingsService::instance();
}
void BeerService::sendCommand(const QString &entity, const QString &action, const QVariantMap &data)
void BeerService::sendCommand(const QString &entity, Action action, const QVariantMap &data)
{
Q_ASSERT(action != ActionUndefined);
sendCommand(QVariantMap {
{ "entity", entity },
{ "action", action },
{ "action", m_actions[action] },
{ "data", data }
});
}
@@ -75,6 +84,12 @@ void BeerService::connectListener(QObject *listener)
m_listeners.insert(entity, listener);
}
void BeerService::removeListener(QObject *listener)
{
QString entity = listener->property("entity").toString();
m_listeners.remove(entity, listener);
}
QString BeerService::stashFileName() const
{
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/command.stash";
@@ -102,6 +117,7 @@ void BeerService::restoreStash()
QJsonDocument doc = QJsonDocument::fromJson(stash.readAll());
m_commandStash = doc.array().toVariantList();
stash.close();
stash.remove();
} else {
qWarning() << stash.errorString();
}