25 m_Manager(manager), m_NodeManagers(nodeManagers)
27 for (
auto &nodeManager : m_NodeManagers)
29 if (nodeManager->cloud() ==
nullptr)
32 connect(nodeManager->cloud(), &Node::connected,
this, &Cloud::onConnected);
33 connect(nodeManager->cloud(), &Node::disconnected,
this, &Cloud::onDisconnected);
34 connect(nodeManager->cloud(), &Node::onTextReceived,
this, &Cloud::onTextReceived);
37 connect(
this, &Cloud::newImage,
this, &Cloud::uploadImage);
38 connect(Options::self(), &Options::EkosLiveCloudChanged,
this, &Cloud::updateOptions);
44bool Cloud::isConnected()
const
46 return std::any_of(m_NodeManagers.begin(), m_NodeManagers.end(), [](
auto & nodeManager)
48 return nodeManager->cloud() && nodeManager->cloud()->isConnected();
56void Cloud::onConnected()
62 qCInfo(KSTARS_EKOS) <<
"Connected to Cloud Websocket server at" << node->url().toDisplayString();
70void Cloud::onDisconnected()
72 qCInfo(KSTARS_EKOS) <<
"Disconnected from Cloud Websocket server.";
75 for (
auto &oneFile : temporaryFiles)
77 temporaryFiles.clear();
85void Cloud::onTextReceived(
const QString &message)
87 qCInfo(KSTARS_EKOS) <<
"Cloud Text Websocket Message" << message;
92 qCWarning(KSTARS_EKOS) <<
"Ekos Live Parsing Error" << error.errorString();
97 const QString command = payload[
"type"].toString();
98 if (command == commands[SET_BLOBS])
99 m_sendBlobs = payload[
"payload"].toBool();
100 else if (command == commands[OPTION_SET])
102 const QJsonArray options = payload[
"options"].toArray();
103 for (
const auto &oneOption : options)
105 auto name = oneOption[QStringLiteral(
"name")].toString().
toLatin1();
106 auto value = oneOption[QStringLiteral(
"value")].toVariant();
108 Options::self()->setProperty(name, value);
111 if (name ==
"ekosLiveCloud")
115 Options::self()->save();
117 else if (command == commands[LOGOUT])
119 for (
auto &nodeManager : m_NodeManagers)
121 if (nodeManager->cloud() ==
nullptr)
124 nodeManager->cloud()->disconnectServer();
134 if (Options::ekosLiveCloud() ==
false || m_sendBlobs ==
false)
137#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
153 for (
const auto &oneRecord : data->getRecords())
155 if (oneRecord.key.isEmpty() || oneRecord.value.toString().isEmpty())
161 QString filepath = data->filename();
165 metadata.
insert(
"uuid", uuid);
166 metadata.
insert(
"filename", filenameOnly);
167 metadata.
insert(
"filesize",
static_cast<int>(data->size()));
169 metadata.
insert(
"Content-Disposition",
QString(
"attachment;filename=%1.fz").arg(filenameOnly));
177 data->saveImage(compressedFile + QStringLiteral(
"[compress R]"));
179 QFile compressedImage(compressedFile);
182 image += compressedImage.
readAll();
183 emit newImage(image);
184 qCInfo(KSTARS_EKOS) <<
"Uploaded" << compressedFile <<
" to the cloud";
195void Cloud::uploadImage(
const QByteArray &image)
197 for (
auto &nodeManager : m_NodeManagers)
199 if (nodeManager->cloud() ==
nullptr)
202 nodeManager->cloud()->sendBinaryMessage(image);
209void Cloud::updateOptions()
213 QJsonObject payload = {{
"name",
"ekosLiveCloud"}, {
"value", Options::ekosLiveCloud()}};
216 {
"type", commands[OPTION_SET]},
220 for (
auto &nodeManager : m_NodeManagers)
222 if (nodeManager->cloud() ==
nullptr)