Add sendMessage to fileprovidersocketcontroller
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 28 Dec 2022 16:46:12 +0000 (17:46 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 12 May 2023 05:21:08 +0000 (13:21 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileprovidersocketcontroller.cpp
src/gui/macOS/fileprovidersocketcontroller.h

index 04cf67964cd860f8b156403155de7328812d1c12..af90a22f05e200d035a440eb848e971b491f381d 100644 (file)
@@ -57,6 +57,24 @@ void FileProviderSocketController::slotReadyRead()
     }
 }
 
+void FileProviderSocketController::sendMessage(const QString &message) const
+{
+    if (!_socket) {
+        qCWarning(lcFileProviderSocketController) << "Not sending message on dead file provider socket:" << message;
+        return;
+    }
+
+    qCDebug(lcFileProviderSocketController) << "Sending File Provider socket message:" << message;
+    const auto lineEndChar = '\n';
+    const auto messageToSend = message.endsWith(lineEndChar) ? message : message + lineEndChar;
+    const auto bytesToSend = messageToSend.toUtf8();
+    const auto sent = _socket->write(bytesToSend);
+
+    if (sent != bytesToSend.length()) {
+        qCWarning(lcFileProviderSocketController) << "Could not send all data on file provider socket for:" << message;
+    }
+}
+
 }
 
 }
index 6a17eb8263c9177aa1aa0d3d19be108c165307c1..54ad59c7bd280b9e81c820b4d8c5880e8fa3cbff 100644 (file)
@@ -32,6 +32,9 @@ public:
 signals:
     void socketDestroyed(const QLocalSocket * const socket);
 
+public slots:
+    void sendMessage(const QString &message) const;
+
 private slots:
     void slotOnDisconnected();
     void slotSocketDestroyed(QObject *object);