nextcloud-desktop/src/gui/accountmanager.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
3.5 KiB
C
Raw Normal View History

/*
* Copyright (C) by Olivier Goffart <ogoffart@woboq.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 "account.h"
2015-04-17 18:56:17 +03:00
#include "accountstate.h"
namespace OCC {
2015-06-29 19:56:09 +03:00
/**
@brief The AccountManager class
@ingroup gui
*/
2015-06-15 15:53:36 +03:00
class AccountManager : public QObject
{
Q_OBJECT
public:
static AccountManager *instance();
~AccountManager() override = default;
/**
2015-04-23 16:42:18 +03:00
* Saves the accounts to a given settings file
*/
void save(bool saveCredentials = true);
/**
* Creates account objects from a given settings file.
*
* Returns false if there was an error reading the settings,
* but note that settings not existing is not an error.
*/
bool restore(bool alsoRestoreLegacySettings = true);
2015-04-17 18:56:17 +03:00
/**
* Add this account in the list of saved accounts.
2015-04-17 18:56:17 +03:00
* Typically called from the wizard
*/
AccountState *addAccount(const AccountPtr &newAccount);
2015-04-17 18:56:17 +03:00
/**
* remove all accounts
*/
void shutdown();
/**
* Return a list of all accounts.
* (this is a list of QSharedPointer for internal reasons, one should normally not keep a copy of them)
*/
[[nodiscard]] QList<AccountStatePtr> accounts() const;
2015-04-17 18:56:17 +03:00
/**
* Return the account state pointer for an account identified by its display name
*/
AccountStatePtr account(const QString &name);
/**
* Return the account state pointer for an account from its id
*/
[[nodiscard]] AccountStatePtr accountFromUserId(const QString &id) const;
/**
* Delete the AccountState
*/
void deleteAccount(AccountState *account);
/**
* Creates an account and sets up some basic handlers.
* Does *not* add the account to the account manager just yet.
*/
static AccountPtr createAccount();
/**
* Returns the list of settings keys that can't be read because
* they are from the future.
*/
static void backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringList *ignoreKeys);
2015-04-17 18:56:17 +03:00
private:
// saving and loading Account to settings
void saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials = true);
AccountPtr loadAccountHelper(QSettings &settings);
2015-04-23 16:42:18 +03:00
bool restoreFromLegacySettings();
2015-04-17 18:56:17 +03:00
[[nodiscard]] bool isAccountIdAvailable(const QString &id) const;
[[nodiscard]] QString generateFreeAccountId() const;
2015-04-24 08:02:51 +03:00
// Adds an account to the tracked list, emitting accountAdded()
void addAccountState(AccountState *accountState);
AccountManager() = default;
QList<AccountStatePtr> _accounts;
/// Account ids from settings that weren't read
QSet<QString> _additionalBlockedAccountIds;
public slots:
/// Saves account data, not including the credentials
void saveAccount(OCC::Account *a);
/// Saves account state data, not including the account
void saveAccountState(OCC::AccountState *a);
2015-04-17 18:56:17 +03:00
Q_SIGNALS:
void accountAdded(OCC::AccountState *account);
void accountRemoved(OCC::AccountState *account);
void accountSyncConnectionRemoved(OCC::AccountState *account);
void removeAccountFolders(OCC::AccountState *account);
};
2015-04-23 16:42:18 +03:00
}