From f2a8bd8d06d8f06b580a59542f74483e461583dc Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Sep 2023 10:43:01 +0800 Subject: [PATCH] Implement modification of file provider enabled for account Signed-off-by: Claudio Cambra --- .../macOS/ui/fileprovidersettingscontroller.h | 5 +++- .../ui/fileprovidersettingscontroller_mac.mm | 30 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gui/macOS/ui/fileprovidersettingscontroller.h b/src/gui/macOS/ui/fileprovidersettingscontroller.h index 15ff403fb7db8..4bf463493371c 100644 --- a/src/gui/macOS/ui/fileprovidersettingscontroller.h +++ b/src/gui/macOS/ui/fileprovidersettingscontroller.h @@ -31,7 +31,10 @@ class FileProviderSettingsController : public QObject [[nodiscard]] QQuickWidget *settingsViewWidget(QWidget *const parent = nullptr, const QQuickWidget::ResizeMode resizeMode = QQuickWidget::SizeRootObjectToView); - [[nodiscard]] Q_INVOKABLE bool vfsEnabledForAccount(const QString &userIdAtHost); + [[nodiscard]] Q_INVOKABLE bool vfsEnabledForAccount(const QString &userIdAtHost) const; + +public slots: + void setVfsEnabledForAccount(const QString &userIdAtHost, const bool setEnabled); private: explicit FileProviderSettingsController(QObject *parent = nullptr); diff --git a/src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm b/src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm index 512eb7f11ff66..1b1ee9f8abded 100644 --- a/src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm +++ b/src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm @@ -68,6 +68,29 @@ bool vfsEnabledForAccount(const QString &userIdAtHost) const return [vfsEnabledAccounts containsObject:userIdAtHost.toNSString()]; } + void setVfsEnabledForAccount(const QString &userIdAtHost, const bool setEnabled) const + { + NSArray *const vfsEnabledAccounts = nsEnabledAccounts(); + NSString *const nsUserIdAtHost = userIdAtHost.toNSString(); + const BOOL accountEnabled = [vfsEnabledAccounts containsObject:nsUserIdAtHost]; + + if (accountEnabled == setEnabled) { + return; + } + + NSMutableArray *const mutableVfsAccounts = vfsEnabledAccounts.mutableCopy; + + if (setEnabled) { + [mutableVfsAccounts addObject:nsUserIdAtHost]; + } else { + [mutableVfsAccounts removeObject:nsUserIdAtHost]; + } + + NSArray *const modifiedVfsAccounts = mutableVfsAccounts.copy; + NSString *const accsKey = [NSString stringWithUTF8String:enabledAccountsSettingsKey]; + [_userDefaults setObject:modifiedVfsAccounts forKey:accsKey]; + } + private: NSArray *nsEnabledAccounts() const { @@ -102,11 +125,16 @@ bool vfsEnabledForAccount(const QString &userIdAtHost) const return settingsViewWidget; } -bool FileProviderSettingsController::vfsEnabledForAccount(const QString &userIdAtHost) +bool FileProviderSettingsController::vfsEnabledForAccount(const QString &userIdAtHost) const { return d->vfsEnabledForAccount(userIdAtHost); } +void FileProviderSettingsController::setVfsEnabledForAccount(const QString &userIdAtHost, const bool setEnabled) +{ + d->setVfsEnabledForAccount(userIdAtHost, setEnabled); +} + } // namespace Mac } // namespace OCC