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