Skip to content

Commit

Permalink
Implement modification of file provider enabled for account
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Sep 5, 2023
1 parent 42147a5 commit f2a8bd8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/gui/macOS/ui/fileprovidersettingscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 29 additions & 1 deletion src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *const vfsEnabledAccounts = nsEnabledAccounts();
NSString *const nsUserIdAtHost = userIdAtHost.toNSString();
const BOOL accountEnabled = [vfsEnabledAccounts containsObject:nsUserIdAtHost];

if (accountEnabled == setEnabled) {
return;
}

NSMutableArray<NSString *> *const mutableVfsAccounts = vfsEnabledAccounts.mutableCopy;

if (setEnabled) {
[mutableVfsAccounts addObject:nsUserIdAtHost];
} else {
[mutableVfsAccounts removeObject:nsUserIdAtHost];
}

NSArray<NSString *> *const modifiedVfsAccounts = mutableVfsAccounts.copy;
NSString *const accsKey = [NSString stringWithUTF8String:enabledAccountsSettingsKey];
[_userDefaults setObject:modifiedVfsAccounts forKey:accsKey];
}

private:
NSArray<NSString *> *nsEnabledAccounts() const
{
Expand Down Expand Up @@ -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

0 comments on commit f2a8bd8

Please sign in to comment.