]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Move file provider components to macOS folder
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 30 Nov 2022 14:25:42 +0000 (15:25 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 12 May 2023 05:21:06 +0000 (13:21 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/CMakeLists.txt
src/gui/fileprovider.h [deleted file]
src/gui/fileprovider_mac.mm [deleted file]
src/gui/macOS/fileprovider.h [new file with mode: 0644]
src/gui/macOS/fileprovider_mac.mm [new file with mode: 0644]
src/gui/main.cpp

index 5c4904d115a8c30ded49d51afb3e8313dcb87d05..7374b41ec5a0e130ace8b38ceb0eb03a5d232da8 100644 (file)
@@ -280,7 +280,9 @@ endif()
 IF( APPLE )
     list(APPEND client_SRCS cocoainitializer_mac.mm)
     list(APPEND client_SRCS systray.mm)
-    list(APPEND client_SRCS fileprovider_mac.mm)
+    list(APPEND client_SRCS
+        macOS/fileprovider.h
+        macOS/fileprovider_mac.mm)
 
     if(SPARKLE_FOUND AND BUILD_UPDATER)
         # Define this, we need to check in updater.cpp
diff --git a/src/gui/fileprovider.h b/src/gui/fileprovider.h
deleted file mode 100644 (file)
index 296ebc5..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 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.
- */
-
-#ifndef FILEPROVIDER_H
-#define FILEPROVIDER_H
-
-#include <QObject>
-#include <QScopedPointer>
-
-#include "accountstate.h"
-
-namespace OCC {
-namespace Mac {
-
-// NOTE: For the file provider extension to work, the app bundle will
-// need to be correctly codesigned!
-
-class FileProvider : public QObject
-{
-public:
-    static FileProvider *instance();
-    ~FileProvider() override;
-
-    void setupFileProviderDomains();
-
-private slots:
-    void addFileProviderDomainForAccount(AccountState *accountState);
-    void removeFileProviderDomainForAccount(AccountState *accountState);
-    void setFileProviderForAccountIsConnected(AccountState *accountState);
-
-private:
-    explicit FileProvider(QObject *parent = nullptr);
-    static FileProvider *_instance;
-    class Private;
-    QScopedPointer<Private> d;
-};
-
-} // namespace Mac
-} // namespace OCC
-
-#endif
diff --git a/src/gui/fileprovider_mac.mm b/src/gui/fileprovider_mac.mm
deleted file mode 100644 (file)
index 4f2669f..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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 <Foundation/Foundation.h>
-#import <FileProvider/FileProvider.h>
-
-#include "application.h"
-#include "fileprovider.h"
-
-namespace OCC {
-
-Q_LOGGING_CATEGORY(lcMacFileProvider, "nextcloud.gui.macfileprovider")
-
-namespace Mac {
-
-FileProvider *FileProvider::_instance = nullptr;
-
-class FileProvider::Private {
-  public:
-    Private()
-    {
-    }
-
-    ~Private() = default;
-
-    void addFileProviderDomain(const AccountState *accountState)
-    {
-        const QString accountDisplayName = accountState->account()->displayName();
-        const QString accountId = accountState->account()->id();
-
-        qCDebug(lcMacFileProvider) << "Adding new file provider domain for account with id: " << accountId;
-
-        if(_registeredDomains.contains(accountId) && _registeredDomains.value(accountId) != nil) {
-            qCDebug(lcMacFileProvider) << "File provider domain for account with id already exists: " << accountId;
-            return;
-        }
-
-        NSFileProviderDomain *fileProviderDomain = [[NSFileProviderDomain alloc] initWithIdentifier:accountId.toNSString() displayName:accountDisplayName.toNSString()];
-        [NSFileProviderManager addDomain:fileProviderDomain completionHandler:^(NSError *error) {
-            if(error) {
-                qCDebug(lcMacFileProvider) << "Error adding file provider domain: " << [error code] << [error localizedDescription];
-            }
-        }];
-
-        _registeredDomains.insert(accountId, fileProviderDomain);
-    }
-
-    void removeFileProviderDomain(const AccountState *accountState)
-    {
-        const QString accountId = accountState->account()->id();
-        qCDebug(lcMacFileProvider) << "Removing file provider domain for account with id: " << accountId;
-
-        if(!_registeredDomains.contains(accountId)) {
-            qCDebug(lcMacFileProvider) << "File provider domain not found for id: " << accountId;
-            return;
-        }
-
-        NSFileProviderDomain* fileProviderDomain = _registeredDomains[accountId];
-
-        [NSFileProviderManager removeDomain:fileProviderDomain completionHandler:^(NSError *error) {
-            if(error) {
-                qCDebug(lcMacFileProvider) << "Error removing file provider domain: " << [error code] << [error localizedDescription];
-            }
-        }];
-
-        NSFileProviderDomain* domain = _registeredDomains.take(accountId);
-        [domain release];
-    }
-
-    void removeAllFileProviderDomains()
-    {
-        qCDebug(lcMacFileProvider) << "Removing all file provider domains.";
-
-        [NSFileProviderManager removeAllDomainsWithCompletionHandler:^(NSError *error) {
-            if(error) {
-                qCDebug(lcMacFileProvider) << "Error removing all file provider domains: " << [error code] << [error localizedDescription];
-            }
-        }];
-    }
-
-    void setFileProviderDomainConnected(const AccountState *accountState)
-    {
-        const QString accountDisplayName = accountState->account()->displayName();
-        const QString accountId = accountState->account()->id();
-        const bool accountIsConnected = accountState->isConnected();
-
-        qCDebug(lcMacFileProvider) << "Account state for account changed: " << accountDisplayName << accountIsConnected;
-
-        if(!_registeredDomains.contains(accountId)) {
-            qCDebug(lcMacFileProvider) << "File provider domain not found for id: " << accountId;
-            return;
-        }
-
-        NSFileProviderDomain* accountDomain = _registeredDomains.value(accountId);
-        NSFileProviderManager* providerManager = [NSFileProviderManager managerForDomain:accountDomain];
-
-        if(accountIsConnected) {
-            [providerManager reconnectWithCompletionHandler:^(NSError *error) {
-                if(error) {
-                    qCDebug(lcMacFileProvider) << "Error reconnecting file provider domain: " << accountDisplayName << [error code] << [error localizedDescription];
-                }
-            }];
-        } else {
-            NSString* reason = @"Nextcloud account disconnected.";
-            const auto isTemporary = accountState->state() != AccountState::SignedOut && accountState->state() != AccountState::ConfigurationError;
-            NSFileProviderManagerDisconnectionOptions disconnectOption = isTemporary ? 0 : NSFileProviderManagerDisconnectionOptionsTemporary;
-
-            [providerManager disconnectWithReason:reason options:disconnectOption completionHandler:^(NSError *error) {
-                if(error) {
-                    qCDebug(lcMacFileProvider) << "Error disconnecting file provider domain: " << accountDisplayName << [error code] << [error localizedDescription];
-                }
-            }];
-        }
-    }
-
-private:
-    QHash<QString, NSFileProviderDomain*> _registeredDomains;
-};
-
-FileProvider::FileProvider(QObject *parent)
-    : QObject(parent)
-{
-    d.reset(new FileProvider::Private());
-
-    connect(AccountManager::instance(), &AccountManager::accountAdded,
-            this, &FileProvider::addFileProviderDomainForAccount);
-    connect(AccountManager::instance(), &AccountManager::accountRemoved,
-            this, &FileProvider::removeFileProviderDomainForAccount);
-
-    setupFileProviderDomains(); // Initially fetch accounts in manager
-}
-
-FileProvider::~FileProvider()
-{
-    d->removeAllFileProviderDomains();
-}
-
-FileProvider *FileProvider::instance()
-{
-    if (!_instance) {
-        _instance = new FileProvider();
-    }
-    return _instance;
-}
-
-void FileProvider::setupFileProviderDomains()
-{
-    for(auto &accountState : AccountManager::instance()->accounts()) {
-        addFileProviderDomainForAccount(accountState.data());
-    }
-}
-
-void FileProvider::addFileProviderDomainForAccount(AccountState *accountState)
-{
-    d->addFileProviderDomain(accountState);
-
-    connect(accountState, &AccountState::isConnectedChanged,
-            this, [this, accountState]{ setFileProviderForAccountIsConnected(accountState); });
-}
-
-void FileProvider::removeFileProviderDomainForAccount(AccountState* accountState)
-{
-    d->removeFileProviderDomain(accountState);
-}
-
-void FileProvider::setFileProviderForAccountIsConnected(AccountState *accountState)
-{
-    d->setFileProviderDomainConnected(accountState);
-}
-
-} // namespace Mac
-} // namespace OCC
diff --git a/src/gui/macOS/fileprovider.h b/src/gui/macOS/fileprovider.h
new file mode 100644 (file)
index 0000000..fc169f2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 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.
+ */
+
+#ifndef FILEPROVIDER_H
+#define FILEPROVIDER_H
+
+#include <QObject>
+#include <QScopedPointer>
+
+#include "gui/accountstate.h"
+
+namespace OCC {
+namespace Mac {
+
+// NOTE: For the file provider extension to work, the app bundle will
+// need to be correctly codesigned!
+
+class FileProvider : public QObject
+{
+public:
+    static FileProvider *instance();
+    ~FileProvider() override;
+
+    void setupFileProviderDomains();
+
+private slots:
+    void addFileProviderDomainForAccount(AccountState *accountState);
+    void removeFileProviderDomainForAccount(AccountState *accountState);
+    void setFileProviderForAccountIsConnected(AccountState *accountState);
+
+private:
+    explicit FileProvider(QObject *parent = nullptr);
+    static FileProvider *_instance;
+    class Private;
+    QScopedPointer<Private> d;
+};
+
+} // namespace Mac
+} // namespace OCC
+
+#endif
diff --git a/src/gui/macOS/fileprovider_mac.mm b/src/gui/macOS/fileprovider_mac.mm
new file mode 100644 (file)
index 0000000..540a662
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * 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 <Foundation/Foundation.h>
+#import <FileProvider/FileProvider.h>
+
+#include "gui/application.h"
+#include "fileprovider.h"
+
+namespace OCC {
+
+Q_LOGGING_CATEGORY(lcMacFileProvider, "nextcloud.gui.macfileprovider")
+
+namespace Mac {
+
+FileProvider *FileProvider::_instance = nullptr;
+
+class FileProvider::Private {
+  public:
+    Private()
+    {
+    }
+
+    ~Private() = default;
+
+    void addFileProviderDomain(const AccountState *accountState)
+    {
+        const QString accountDisplayName = accountState->account()->displayName();
+        const QString accountId = accountState->account()->id();
+
+        qCDebug(lcMacFileProvider) << "Adding new file provider domain for account with id: " << accountId;
+
+        if(_registeredDomains.contains(accountId) && _registeredDomains.value(accountId) != nil) {
+            qCDebug(lcMacFileProvider) << "File provider domain for account with id already exists: " << accountId;
+            return;
+        }
+
+        NSFileProviderDomain *fileProviderDomain = [[NSFileProviderDomain alloc] initWithIdentifier:accountId.toNSString() displayName:accountDisplayName.toNSString()];
+        [NSFileProviderManager addDomain:fileProviderDomain completionHandler:^(NSError *error) {
+            if(error) {
+                qCDebug(lcMacFileProvider) << "Error adding file provider domain: " << [error code] << [error localizedDescription];
+            }
+        }];
+
+        _registeredDomains.insert(accountId, fileProviderDomain);
+    }
+
+    void removeFileProviderDomain(const AccountState *accountState)
+    {
+        const QString accountId = accountState->account()->id();
+        qCDebug(lcMacFileProvider) << "Removing file provider domain for account with id: " << accountId;
+
+        if(!_registeredDomains.contains(accountId)) {
+            qCDebug(lcMacFileProvider) << "File provider domain not found for id: " << accountId;
+            return;
+        }
+
+        NSFileProviderDomain* fileProviderDomain = _registeredDomains[accountId];
+
+        [NSFileProviderManager removeDomain:fileProviderDomain completionHandler:^(NSError *error) {
+            if(error) {
+                qCDebug(lcMacFileProvider) << "Error removing file provider domain: " << [error code] << [error localizedDescription];
+            }
+        }];
+
+        NSFileProviderDomain* domain = _registeredDomains.take(accountId);
+        [domain release];
+    }
+
+    void removeAllFileProviderDomains()
+    {
+        qCDebug(lcMacFileProvider) << "Removing all file provider domains.";
+
+        [NSFileProviderManager removeAllDomainsWithCompletionHandler:^(NSError *error) {
+            if(error) {
+                qCDebug(lcMacFileProvider) << "Error removing all file provider domains: " << [error code] << [error localizedDescription];
+            }
+        }];
+    }
+
+    void setFileProviderDomainConnected(const AccountState *accountState)
+    {
+        const QString accountDisplayName = accountState->account()->displayName();
+        const QString accountId = accountState->account()->id();
+        const bool accountIsConnected = accountState->isConnected();
+
+        qCDebug(lcMacFileProvider) << "Account state for account changed: " << accountDisplayName << accountIsConnected;
+
+        if(!_registeredDomains.contains(accountId)) {
+            qCDebug(lcMacFileProvider) << "File provider domain not found for id: " << accountId;
+            return;
+        }
+
+        NSFileProviderDomain* accountDomain = _registeredDomains.value(accountId);
+        NSFileProviderManager* providerManager = [NSFileProviderManager managerForDomain:accountDomain];
+
+        if(accountIsConnected) {
+            [providerManager reconnectWithCompletionHandler:^(NSError *error) {
+                if(error) {
+                    qCDebug(lcMacFileProvider) << "Error reconnecting file provider domain: " << accountDisplayName << [error code] << [error localizedDescription];
+                }
+            }];
+        } else {
+            NSString* reason = @"Nextcloud account disconnected.";
+            const auto isTemporary = accountState->state() != AccountState::SignedOut && accountState->state() != AccountState::ConfigurationError;
+            NSFileProviderManagerDisconnectionOptions disconnectOption = isTemporary ? 0 : NSFileProviderManagerDisconnectionOptionsTemporary;
+
+            [providerManager disconnectWithReason:reason options:disconnectOption completionHandler:^(NSError *error) {
+                if(error) {
+                    qCDebug(lcMacFileProvider) << "Error disconnecting file provider domain: " << accountDisplayName << [error code] << [error localizedDescription];
+                }
+            }];
+        }
+    }
+
+private:
+    QHash<QString, NSFileProviderDomain*> _registeredDomains;
+};
+
+FileProvider::FileProvider(QObject *parent)
+    : QObject(parent)
+{
+    d.reset(new FileProvider::Private());
+
+    connect(AccountManager::instance(), &AccountManager::accountAdded,
+            this, &FileProvider::addFileProviderDomainForAccount);
+    connect(AccountManager::instance(), &AccountManager::accountRemoved,
+            this, &FileProvider::removeFileProviderDomainForAccount);
+
+    setupFileProviderDomains(); // Initially fetch accounts in manager
+}
+
+FileProvider::~FileProvider()
+{
+    d->removeAllFileProviderDomains();
+}
+
+FileProvider *FileProvider::instance()
+{
+    if (!_instance) {
+        _instance = new FileProvider();
+    }
+    return _instance;
+}
+
+void FileProvider::setupFileProviderDomains()
+{
+    for(auto &accountState : AccountManager::instance()->accounts()) {
+        addFileProviderDomainForAccount(accountState.data());
+    }
+}
+
+void FileProvider::addFileProviderDomainForAccount(AccountState *accountState)
+{
+    d->addFileProviderDomain(accountState);
+
+    connect(accountState, &AccountState::isConnectedChanged,
+            this, [this, accountState]{ setFileProviderForAccountIsConnected(accountState); });
+}
+
+void FileProvider::removeFileProviderDomainForAccount(AccountState* accountState)
+{
+    d->removeFileProviderDomain(accountState);
+}
+
+void FileProvider::setFileProviderForAccountIsConnected(AccountState *accountState)
+{
+    d->setFileProviderDomainConnected(accountState);
+}
+
+} // namespace Mac
+} // namespace OCC
index 7ab8c99418082c5c7deebc6bc20aef27c45199df..8542993c992bc9a3fe5ef1dbcca51fb8debb79b6 100644 (file)
@@ -23,7 +23,7 @@
 #endif
 
 #ifdef Q_OS_MACOS
-#include "fileprovider.h"
+#include "macOS/fileprovider.h"
 #endif
 
 #include "application.h"