2015-04-09 17:19:17 +03:00
|
|
|
/*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-04-09 17:19:17 +03:00
|
|
|
*
|
|
|
|
* 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"
|
2015-04-09 17:19:17 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
@brief The AccountManager class
|
|
|
|
@ingroup gui
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-06-15 15:53:36 +03:00
|
|
|
class AccountManager : public QObject
|
|
|
|
{
|
2015-04-09 17:19:17 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static AccountManager *instance();
|
|
|
|
~AccountManager() {}
|
|
|
|
|
|
|
|
/**
|
2015-04-23 16:42:18 +03:00
|
|
|
* Saves the accounts to a given settings file
|
2015-04-09 17:19:17 +03:00
|
|
|
*/
|
2015-08-06 13:49:18 +03:00
|
|
|
void save(bool saveCredentials = true);
|
2015-04-09 17:19:17 +03:00
|
|
|
|
|
|
|
/**
|
2015-10-05 07:21:19 +03:00
|
|
|
* Creates account objects from a given settings file.
|
2017-02-08 16:28:50 +03:00
|
|
|
*
|
|
|
|
* Returns false if there was an error reading the settings,
|
|
|
|
* but note that settings not existing is not an error.
|
2015-04-09 17:19:17 +03:00
|
|
|
*/
|
|
|
|
bool restore();
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
/**
|
2015-10-05 07:21:19 +03:00
|
|
|
* Add this account in the list of saved accounts.
|
2015-04-17 18:56:17 +03:00
|
|
|
* Typically called from the wizard
|
|
|
|
*/
|
2015-04-27 18:43:07 +03:00
|
|
|
AccountState *addAccount(const AccountPtr &newAccount);
|
2015-04-17 18:56:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* remove all accounts
|
|
|
|
*/
|
|
|
|
void shutdown();
|
|
|
|
|
2015-04-27 18:43:07 +03:00
|
|
|
/**
|
|
|
|
* Return a list of all accounts.
|
2015-10-05 07:21:19 +03:00
|
|
|
* (this is a list of QSharedPointer for internal reasons, one should normally not keep a copy of them)
|
2015-04-27 18:43:07 +03:00
|
|
|
*/
|
2015-04-17 18:56:17 +03:00
|
|
|
QList<AccountStatePtr> accounts() { return _accounts; }
|
|
|
|
|
2015-11-12 19:50:00 +03:00
|
|
|
/**
|
|
|
|
* Return the account state pointer for an account identified by its display name
|
|
|
|
*/
|
|
|
|
AccountStatePtr account(const QString &name);
|
|
|
|
|
2015-05-12 16:16:32 +03:00
|
|
|
/**
|
|
|
|
* Delete the AccountState
|
|
|
|
*/
|
|
|
|
void deleteAccount(AccountState *account);
|
|
|
|
|
2015-07-16 15:21:51 +03:00
|
|
|
/**
|
|
|
|
* 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:
|
2016-03-01 18:08:23 +03:00
|
|
|
// 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
|
|
|
|
2015-04-24 08:02:51 +03:00
|
|
|
bool isAccountIdAvailable(const QString &id) const;
|
|
|
|
QString generateFreeAccountId() const;
|
|
|
|
|
2016-03-01 18:08:23 +03:00
|
|
|
// Adds an account to the tracked list, emitting accountAdded()
|
|
|
|
void addAccountState(AccountState *accountState);
|
|
|
|
|
2015-08-14 12:31:01 +03:00
|
|
|
public slots:
|
2016-03-01 18:08:23 +03:00
|
|
|
/// Saves account data, not including the credentials
|
|
|
|
void saveAccount(Account *a);
|
|
|
|
|
|
|
|
/// Saves account state data, not including the account
|
|
|
|
void saveAccountState(AccountState *a);
|
2015-08-14 12:31:01 +03:00
|
|
|
|
2018-01-21 21:50:40 +03:00
|
|
|
/// Display a Box with the mnemonic so the user can copy it to a safe place.
|
|
|
|
static void displayMnemonic(const QString& mnemonic);
|
|
|
|
|
2015-04-17 18:56:17 +03:00
|
|
|
|
2015-04-09 17:19:17 +03:00
|
|
|
Q_SIGNALS:
|
2015-04-17 18:56:17 +03:00
|
|
|
void accountAdded(AccountState *account);
|
|
|
|
void accountRemoved(AccountState *account);
|
2019-07-24 14:56:21 +03:00
|
|
|
void removeAccountFolders(AccountState *account);
|
2015-04-09 17:19:17 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
AccountManager() {}
|
2015-04-17 18:56:17 +03:00
|
|
|
QList<AccountStatePtr> _accounts;
|
2015-04-09 17:19:17 +03:00
|
|
|
};
|
2015-04-23 16:42:18 +03:00
|
|
|
}
|