Skip to content

Commit

Permalink
Make it possible to check whether an account has vfs enabled or not
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Sep 4, 2023
1 parent 16b22b5 commit 42147a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gui/macOS/ui/fileprovidersettingscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ 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);

private:
explicit FileProviderSettingsController(QObject *parent = nullptr);
~FileProviderSettingsController() override;
Expand Down
30 changes: 30 additions & 0 deletions src/gui/macOS/ui/fileprovidersettingscontroller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

// FileProviderSettingsPage properties -- make sure they match up in QML file!
constexpr auto fpSettingsControllerProp = "FileProviderSettingsController";

// NSUserDefaults entries
constexpr auto enabledAccountsSettingsKey = "enabledAccounts";
} // namespace

namespace OCC {
Expand All @@ -49,7 +52,29 @@
[_userDefaults release];
};

QStringList enabledAccounts() const
{
QStringList qEnabledAccounts;
NSArray<NSString *> *const enabledAccounts = nsEnabledAccounts();
for (NSString *const userIdAtHostString in enabledAccounts) {
qEnabledAccounts.append(QString::fromNSString(userIdAtHostString));
}
return qEnabledAccounts;
}

bool vfsEnabledForAccount(const QString &userIdAtHost) const
{
NSArray<NSString *> *const vfsEnabledAccounts = nsEnabledAccounts();
return [vfsEnabledAccounts containsObject:userIdAtHost.toNSString()];
}

private:
NSArray<NSString *> *nsEnabledAccounts() const
{
NSString *const accsKey = [NSString stringWithUTF8String:enabledAccountsSettingsKey];
return (NSArray<NSString *> *)[_userDefaults objectForKey:accsKey];
}

FileProviderSettingsController *q = nullptr;
NSUserDefaults *_userDefaults = nil;
};
Expand Down Expand Up @@ -77,6 +102,11 @@
return settingsViewWidget;
}

bool FileProviderSettingsController::vfsEnabledForAccount(const QString &userIdAtHost)
{
return d->vfsEnabledForAccount(userIdAtHost);
}

} // namespace Mac

} // namespace OCC

0 comments on commit 42147a5

Please sign in to comment.