nextcloud-desktop/src/gui/accountmanager.h

92 lines
2.2 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; version 2 of the License.
*
* 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-04-17 18:56:17 +03:00
typedef QSharedPointer<AccountState> AccountStatePtr;
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() {}
/**
2015-04-23 16:42:18 +03:00
* Saves the accounts to a given settings file
*/
void save();
/**
2015-04-23 16:42:18 +03:00
* Creates account objects from from a given settings file.
* return true if the account was restored
*/
bool restore();
2015-04-17 18:56:17 +03:00
/**
* Add this account in the list of saved account.
* 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 reason, one should normaly not keep a copy of them)
*/
2015-04-17 18:56:17 +03:00
QList<AccountStatePtr> accounts() { return _accounts; }
/**
* 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();
2015-04-17 18:56:17 +03:00
private:
2015-04-24 11:18:33 +03:00
void save(const AccountPtr& account, QSettings& settings);
AccountPtr load(QSettings& settings);
2015-04-23 16:42:18 +03:00
bool restoreFromLegacySettings();
2015-04-17 18:56:17 +03:00
2015-04-24 08:02:51 +03:00
bool isAccountIdAvailable(const QString& id) const;
QString generateFreeAccountId() const;
2015-04-17 18:56:17 +03:00
Q_SIGNALS:
2015-04-17 18:56:17 +03:00
void accountAdded(AccountState *account);
void accountRemoved(AccountState *account);
private:
AccountManager() {}
2015-04-17 18:56:17 +03:00
QList<AccountStatePtr> _accounts;
};
2015-04-23 16:42:18 +03:00
}