|
|
@@ -2,10 +2,6 @@
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
#include <QJsonObject>
|
|
|
-#include <QJsonArray>
|
|
|
-#include <QStandardPaths>
|
|
|
-#include <QFile>
|
|
|
-#include <QDebug>
|
|
|
|
|
|
#include "settingsservice.h"
|
|
|
|
|
|
@@ -19,6 +15,7 @@ BeerService::BeerService()
|
|
|
{ ActionModify, "mod" }
|
|
|
};
|
|
|
|
|
|
+ m_dumpService.setEntityName("command");
|
|
|
restoreStash();
|
|
|
|
|
|
connect(&m_socket, &QWebSocket::textMessageReceived, this, [this](QString message) {
|
|
|
@@ -58,7 +55,7 @@ BeerService::BeerService()
|
|
|
|
|
|
BeerService::~BeerService()
|
|
|
{
|
|
|
- saveStash();
|
|
|
+ m_dumpService.dump(m_commandStash);
|
|
|
m_socket.close();
|
|
|
}
|
|
|
|
|
|
@@ -90,37 +87,10 @@ void BeerService::removeListener(QObject *listener)
|
|
|
m_listeners.remove(entity, listener);
|
|
|
}
|
|
|
|
|
|
-QString BeerService::stashFileName() const
|
|
|
-{
|
|
|
- return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/command.stash";
|
|
|
-}
|
|
|
-
|
|
|
-void BeerService::saveStash() const
|
|
|
-{
|
|
|
- if (m_commandStash.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- QFile stash(stashFileName());
|
|
|
- if (stash.open(QIODevice::WriteOnly)) {
|
|
|
- stash.write(QJsonDocument::fromVariant(m_commandStash).toJson(QJsonDocument::Compact));
|
|
|
- stash.close();
|
|
|
- } else {
|
|
|
- qWarning() << stash.errorString();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void BeerService::restoreStash()
|
|
|
{
|
|
|
- QFile stash(stashFileName());
|
|
|
- if (stash.open(QIODevice::ReadOnly)) {
|
|
|
- QJsonDocument doc = QJsonDocument::fromJson(stash.readAll());
|
|
|
- m_commandStash = doc.array().toVariantList();
|
|
|
- stash.close();
|
|
|
- stash.remove();
|
|
|
- } else {
|
|
|
- qWarning() << stash.errorString();
|
|
|
- }
|
|
|
+ m_commandStash = m_dumpService.loadList();
|
|
|
+ m_dumpService.clear();
|
|
|
}
|
|
|
|
|
|
void BeerService::reconnect()
|
|
|
@@ -135,7 +105,6 @@ void BeerService::reconnect()
|
|
|
QNetworkRequest request(serverUrl);
|
|
|
request.setRawHeader("Authorization", "Basic " + QString("%1:pass").arg(userId).toLatin1().toBase64());
|
|
|
m_socket.open(request);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void BeerService::sendCommand(const QVariantMap &command)
|