macOS/fileproviderdomainmanager_mac.mm
macOS/fileprovidersocketcontroller.h
macOS/fileprovidersocketcontroller.cpp
- macOS/fileprovidersocketmanager.h
- macOS/fileprovidersocketmanager.cpp
- macOS/fileprovidersocketmanager_mac.mm)
+ macOS/fileprovidersocketserver.h
+ macOS/fileprovidersocketserver.cpp
+ macOS/fileprovidersocketserver_mac.mm)
if(SPARKLE_FOUND AND BUILD_UPDATER)
# Define this, we need to check in updater.cpp
#include "fileprovidersocketcontroller.h"
-namespace OCC
-{
+#include <QLoggingCategory>
-namespace Mac
-{
+namespace OCC {
+
+namespace Mac {
+
+Q_LOGGING_CATEGORY(lcFileProviderSocketController, "nextcloud.gui.macos.fileprovider.socketcontroller", QtInfoMsg)
FileProviderSocketController::FileProviderSocketController(QLocalSocket *socket, QObject *parent)
: QObject{parent}
, _socket(socket)
{
+ connect(socket, &QLocalSocket::disconnected,
+ this, &FileProviderSocketController::slotOnDisconnected);
+ connect(socket, &QLocalSocket::destroyed,
+ this, &FileProviderSocketController::slotSocketDestroyed);
+}
+void FileProviderSocketController::slotOnDisconnected()
+{
+ qCInfo(lcFileProviderSocketController) << "File provider socket disconnected";
+ _socket->deleteLater();
+ Q_EMIT socketDestroyed(_socket);
+}
+
+void FileProviderSocketController::slotSocketDestroyed(QObject *object)
+{
+ Q_UNUSED(object)
+ qCInfo(lcFileProviderSocketController) << "File provider socket object has been destroyed, destroying controller";
+ Q_EMIT socketDestroyed(_socket);
}
}
#include <QPointer>
#include <QLocalSocket>
-namespace OCC
-{
+namespace OCC {
-namespace Mac
-{
+namespace Mac {
class FileProviderSocketController : public QObject
{
public:
explicit FileProviderSocketController(QLocalSocket *socket, QObject *parent = nullptr);
+signals:
+ void socketDestroyed(const QLocalSocket * const socket);
+
+private slots:
+ void slotOnDisconnected();
+ void slotSocketDestroyed(QObject *object);
+
private:
QPointer<QLocalSocket> _socket;
};
+++ /dev/null
-/*
- * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include "fileprovidersocketmanager.h"
-
-#include <QLocalSocket>
-
-#include "fileprovidersocketcontroller.h"
-
-namespace OCC
-{
-
-namespace Mac
-{
-
-Q_LOGGING_CATEGORY(lcFileProviderSocketManager, "nextcloud.gui.macos.fileprovider.socketmanager", QtInfoMsg)
-
-FileProviderSocketManager::FileProviderSocketManager(QObject *parent)
- : QObject{parent}
-{
-#ifdef Q_OS_MACOS
- _socketPath = fileProviderSocketPath();
-#endif
- startListening();
-}
-
-void FileProviderSocketManager::startListening()
-{
- QLocalServer::removeServer(_socketPath);
-
- const auto serverStarted = _socketServer.listen(_socketPath);
- if (!serverStarted) {
- qCWarning(lcFileProviderSocketManager) << "Could not start file provider socket server"
- << _socketPath;
- } else {
- qCInfo(lcFileProviderSocketManager) << "File provider socket server started, listening"
- << _socketPath;
- }
-
- connect(&_socketServer, &QLocalServer::newConnection,
- this, &FileProviderSocketManager::slotNewConnection);
-}
-
-void FileProviderSocketManager::slotNewConnection()
-{
- if (!_socketServer.hasPendingConnections()) {
- return;
- }
-
- const auto socket = _socketServer.nextPendingConnection();
- if (!socket) {
- return;
- }
-
- connect(socket, &QLocalSocket::disconnected,
- this, &FileProviderSocketManager::slotOnDisconnected);
- connect(socket, &QLocalSocket::destroyed,
- this, &FileProviderSocketManager::slotSocketDestroyed);
-
- const FileProviderSocketControllerPtr controller(new FileProviderSocketController(socket));
- _socketControllers.insert(socket, controller);
-}
-
-void FileProviderSocketManager::slotOnDisconnected()
-{
- const auto socket = qobject_cast<QLocalSocket *>(sender());
- Q_ASSERT(socket);
- socket->deleteLater();
-}
-
-void FileProviderSocketManager::slotSocketDestroyed(QObject *object)
-{
- const auto socket = qobject_cast<QLocalSocket *>(object);
- _socketControllers.remove(socket);
-}
-
-} // namespace Mac
-
-} // namespace OCC
+++ /dev/null
-/*
- * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#pragma once
-
-#include <QObject>
-#include <QLocalServer>
-#include <QLoggingCategory>
-
-namespace OCC
-{
-
-namespace Mac {
-
-class FileProviderSocketController;
-using FileProviderSocketControllerPtr = QSharedPointer<FileProviderSocketController>;
-
-#ifdef Q_OS_MACOS
-QString fileProviderSocketPath();
-#endif
-
-class FileProviderSocketManager : public QObject
-{
- Q_OBJECT
-
-public:
- explicit FileProviderSocketManager(QObject *parent = nullptr);
-
-private slots:
- void startListening();
- void slotNewConnection();
- void slotOnDisconnected();
- void slotSocketDestroyed(QObject *object);
-
-private:
- QString _socketPath;
- QLocalServer _socketServer;
- QHash<QLocalSocket*, FileProviderSocketControllerPtr> _socketControllers;
-};
-
-} // namespace Mac
-
-} // namespace OCC
+++ /dev/null
-/*
- * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#import <Cocoa/Cocoa.h>
-#import <QString>
-
-#include "config.h"
-
-namespace OCC
-{
-
-namespace Mac
-{
-
-QString fileProviderSocketPath()
-{
- // This must match the code signing Team setting of the extension
- // Example for developer builds (with ad-hoc signing identity): "" "com.owncloud.desktopclient" ".fileprovidersocket"
- // Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".fileprovidersocket"
- NSString *appGroupId = @SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN;
-
- NSURL *container = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
- NSURL *socketPath = [container URLByAppendingPathComponent:@".fileprovidersocket" isDirectory:false];
- return QString::fromNSString(socketPath.path);
-}
-
-} // namespace Mac
-
-} // namespace OCC
--- /dev/null
+/*
+ * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "fileprovidersocketserver.h"
+
+#include <QLocalSocket>
+
+#include "fileprovidersocketcontroller.h"
+
+namespace OCC {
+
+namespace Mac {
+
+Q_LOGGING_CATEGORY(lcFileProviderSocketServer, "nextcloud.gui.macos.fileprovider.socketserver", QtInfoMsg)
+
+FileProviderSocketServer::FileProviderSocketServer(QObject *parent)
+ : QObject{parent}
+{
+#ifdef Q_OS_MACOS
+ _socketPath = fileProviderSocketPath();
+#endif
+ startListening();
+}
+
+void FileProviderSocketServer::startListening()
+{
+ QLocalServer::removeServer(_socketPath);
+
+ const auto serverStarted = _socketServer.listen(_socketPath);
+ if (!serverStarted) {
+ qCWarning(lcFileProviderSocketServer) << "Could not start file provider socket server"
+ << _socketPath;
+ } else {
+ qCInfo(lcFileProviderSocketServer) << "File provider socket server started, listening"
+ << _socketPath;
+ }
+
+ connect(&_socketServer, &QLocalServer::newConnection,
+ this, &FileProviderSocketServer::slotNewConnection);
+}
+
+void FileProviderSocketServer::slotNewConnection()
+{
+ if (!_socketServer.hasPendingConnections()) {
+ return;
+ }
+
+ qCInfo(lcFileProviderSocketServer) << "New connection in file provider socket server";
+ const auto socket = _socketServer.nextPendingConnection();
+ if (!socket) {
+ return;
+ }
+
+ const FileProviderSocketControllerPtr socketController(new FileProviderSocketController(socket, this));
+ connect(socketController.data(), &FileProviderSocketController::socketDestroyed,
+ this, &FileProviderSocketServer::slotSocketDestroyed);
+ _socketControllers.insert(socket, socketController);
+}
+
+void FileProviderSocketServer::slotSocketDestroyed(const QLocalSocket * const socket)
+{
+ _socketControllers.remove(socket);
+}
+
+} // namespace Mac
+
+} // namespace OCC
--- /dev/null
+/*
+ * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#pragma once
+
+#include <QObject>
+#include <QLocalServer>
+#include <QLoggingCategory>
+
+namespace OCC {
+
+namespace Mac {
+
+class FileProviderSocketController;
+using FileProviderSocketControllerPtr = QSharedPointer<FileProviderSocketController>;
+
+#ifdef Q_OS_MACOS
+QString fileProviderSocketPath();
+#endif
+
+class FileProviderSocketServer : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit FileProviderSocketServer(QObject *parent = nullptr);
+
+private slots:
+ void startListening();
+ void slotNewConnection();
+ void slotSocketDestroyed(const QLocalSocket * const socket);
+
+private:
+ QString _socketPath;
+ QLocalServer _socketServer;
+ QHash<const QLocalSocket*, FileProviderSocketControllerPtr> _socketControllers;
+};
+
+} // namespace Mac
+
+} // namespace OCC
--- /dev/null
+/*
+ * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <QString>
+
+#include "config.h"
+
+namespace OCC
+{
+
+namespace Mac
+{
+
+QString fileProviderSocketPath()
+{
+ // This must match the code signing Team setting of the extension
+ // Example for developer builds (with ad-hoc signing identity): "" "com.owncloud.desktopclient" ".fileprovidersocket"
+ // Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".fileprovidersocket"
+ NSString *appGroupId = @SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN;
+
+ NSURL *container = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
+ NSURL *socketPath = [container URLByAppendingPathComponent:@".fileprovidersocket" isDirectory:false];
+ return QString::fromNSString(socketPath.path);
+}
+
+} // namespace Mac
+
+} // namespace OCC