AccountState: Allow storing state in settings
This will be useful if we ever want to store account-level gui state. I built this originally because I thought a paused account would be this kind of state.
Esse commit está contido em:
@@ -53,9 +53,11 @@ bool AccountManager::restore()
|
||||
|
||||
foreach (const auto& accountId, settings->childGroups()) {
|
||||
settings->beginGroup(accountId);
|
||||
if (auto acc = load(*settings)) {
|
||||
if (auto acc = loadAccountHelper(*settings)) {
|
||||
acc->_id = accountId;
|
||||
addAccount(acc);
|
||||
if (auto accState = AccountState::loadFromSettings(acc, *settings)) {
|
||||
addAccountState(accState);
|
||||
}
|
||||
}
|
||||
settings->endGroup();
|
||||
}
|
||||
@@ -110,7 +112,7 @@ bool AccountManager::restoreFromLegacySettings()
|
||||
|
||||
// Try to load the single account.
|
||||
if (!settings->childKeys().isEmpty()) {
|
||||
if (auto acc = load(*settings)) {
|
||||
if (auto acc = loadAccountHelper(*settings)) {
|
||||
if (migratedCreds) {
|
||||
acc->setMigrated(true);
|
||||
}
|
||||
@@ -127,7 +129,8 @@ void AccountManager::save(bool saveCredentials)
|
||||
settings->setValue(QLatin1String(versionC), 2);
|
||||
foreach (const auto &acc, _accounts) {
|
||||
settings->beginGroup(acc->account()->id());
|
||||
save(acc->account(), *settings, saveCredentials);
|
||||
saveAccountHelper(acc->account().data(), *settings, saveCredentials);
|
||||
acc->writeToSettings(*settings);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
@@ -135,19 +138,31 @@ void AccountManager::save(bool saveCredentials)
|
||||
qDebug() << "Saved all account settings, status:" << settings->status();
|
||||
}
|
||||
|
||||
void AccountManager::wantsAccountSavedSlot(AccountPtr a)
|
||||
void AccountManager::saveAccount(Account* a)
|
||||
{
|
||||
qDebug() << "Saving account" << a->url().toString();
|
||||
auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
|
||||
settings->beginGroup(a->id());
|
||||
save(a, *settings, false); // don't save credentials they might not have been loaded yet
|
||||
saveAccountHelper(a, *settings, false); // don't save credentials they might not have been loaded yet
|
||||
settings->endGroup();
|
||||
|
||||
settings->sync();
|
||||
qDebug() << "Saved account settings, status:" << settings->status();
|
||||
}
|
||||
|
||||
void AccountManager::save(const AccountPtr& acc, QSettings& settings, bool saveCredentials)
|
||||
void AccountManager::saveAccountState(AccountState* a)
|
||||
{
|
||||
qDebug() << "Saving account state" << a->account()->url().toString();
|
||||
auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
|
||||
settings->beginGroup(a->account()->id());
|
||||
a->writeToSettings(*settings);
|
||||
settings->endGroup();
|
||||
|
||||
settings->sync();
|
||||
qDebug() << "Saved account state settings, status:" << settings->status();
|
||||
}
|
||||
|
||||
void AccountManager::saveAccountHelper(Account* acc, QSettings& settings, bool saveCredentials)
|
||||
{
|
||||
settings.setValue(QLatin1String(urlC), acc->_url.toString());
|
||||
if (acc->_credentials) {
|
||||
@@ -190,7 +205,7 @@ void AccountManager::save(const AccountPtr& acc, QSettings& settings, bool saveC
|
||||
}
|
||||
}
|
||||
|
||||
AccountPtr AccountManager::load(QSettings& settings)
|
||||
AccountPtr AccountManager::loadAccountHelper(QSettings& settings)
|
||||
{
|
||||
auto acc = createAccount();
|
||||
|
||||
@@ -233,13 +248,9 @@ AccountState *AccountManager::addAccount(const AccountPtr& newAccount)
|
||||
}
|
||||
newAccount->_id = id;
|
||||
|
||||
QObject::connect(newAccount.data(), SIGNAL(wantsAccountSaved(AccountPtr)),
|
||||
this, SLOT(wantsAccountSavedSlot(AccountPtr)));
|
||||
|
||||
AccountStatePtr newAccountState(new AccountState(newAccount));
|
||||
_accounts << newAccountState;
|
||||
emit accountAdded(newAccountState.data());
|
||||
return newAccountState.data();
|
||||
auto newAccountState = new AccountState(newAccount);
|
||||
addAccountState(newAccountState);
|
||||
return newAccountState;
|
||||
}
|
||||
|
||||
void AccountManager::deleteAccount(AccountState* account)
|
||||
@@ -296,4 +307,15 @@ QString AccountManager::generateFreeAccountId() const
|
||||
}
|
||||
}
|
||||
|
||||
void AccountManager::addAccountState(AccountState* accountState)
|
||||
{
|
||||
QObject::connect(accountState->account().data(),
|
||||
SIGNAL(wantsAccountSaved(Account*)),
|
||||
SLOT(saveAccount(Account*)));
|
||||
|
||||
AccountStatePtr ptr(accountState);
|
||||
_accounts << ptr;
|
||||
emit accountAdded(accountState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,15 +76,24 @@ public:
|
||||
static AccountPtr createAccount();
|
||||
|
||||
private:
|
||||
void save(const AccountPtr& account, QSettings& settings, bool saveCredentials = true);
|
||||
AccountPtr load(QSettings& settings);
|
||||
// saving and loading Account to settings
|
||||
void saveAccountHelper(Account* account, QSettings& settings, bool saveCredentials = true);
|
||||
AccountPtr loadAccountHelper(QSettings& settings);
|
||||
|
||||
bool restoreFromLegacySettings();
|
||||
|
||||
bool isAccountIdAvailable(const QString& id) const;
|
||||
QString generateFreeAccountId() const;
|
||||
|
||||
// Adds an account to the tracked list, emitting accountAdded()
|
||||
void addAccountState(AccountState* accountState);
|
||||
|
||||
public slots:
|
||||
void wantsAccountSavedSlot(AccountPtr a);
|
||||
/// Saves account data, not including the credentials
|
||||
void saveAccount(Account* a);
|
||||
|
||||
/// Saves account state data, not including the account
|
||||
void saveAccountState(AccountState* a);
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
@@ -46,6 +46,16 @@ AccountState::~AccountState()
|
||||
{
|
||||
}
|
||||
|
||||
AccountState *AccountState::loadFromSettings(AccountPtr account, QSettings& /*settings*/)
|
||||
{
|
||||
auto accountState = new AccountState(account);
|
||||
return accountState;
|
||||
}
|
||||
|
||||
void AccountState::writeToSettings(QSettings& /*settings*/)
|
||||
{
|
||||
}
|
||||
|
||||
AccountPtr AccountState::account() const
|
||||
{
|
||||
return _account;
|
||||
|
||||
@@ -64,9 +64,21 @@ public:
|
||||
typedef ConnectionValidator::Status ConnectionStatus;
|
||||
|
||||
/// Use the account as parent
|
||||
AccountState(AccountPtr account);
|
||||
explicit AccountState(AccountPtr account);
|
||||
~AccountState();
|
||||
|
||||
/** Creates an account state from settings and an Account object.
|
||||
*
|
||||
* Use from AccountManager with a prepared QSettings object only.
|
||||
*/
|
||||
static AccountState* loadFromSettings(AccountPtr account, QSettings& settings);
|
||||
|
||||
/** Writes account state information to settings.
|
||||
*
|
||||
* It does not write the Account data.
|
||||
*/
|
||||
void writeToSettings(QSettings& settings);
|
||||
|
||||
AccountPtr account() const;
|
||||
|
||||
ConnectionStatus connectionStatus() const;
|
||||
|
||||
@@ -565,7 +565,7 @@ void FolderMan::slotAccountStateChanged()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Account" << accountName << "disconnected, "
|
||||
qDebug() << "Account" << accountName << "disconnected or paused, "
|
||||
"terminating or descheduling sync folders";
|
||||
|
||||
if (_currentSyncFolder
|
||||
|
||||
@@ -418,7 +418,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply , QList<QSslError> errors
|
||||
if (_sslErrorHandler->handleErrors(errors, reply->sslConfiguration(), &approvedCerts, sharedFromThis())) {
|
||||
QSslSocket::addDefaultCaCertificates(approvedCerts);
|
||||
addApprovedCerts(approvedCerts);
|
||||
emit wantsAccountSaved(sharedFromThis());
|
||||
emit wantsAccountSaved(this);
|
||||
// all ssl certs are known and accepted. We can ignore the problems right away.
|
||||
// qDebug() << out << "Certs are known and trusted! This is not an actual error.";
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ signals:
|
||||
void proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
|
||||
|
||||
// e.g. when the approved SSL certificates changed
|
||||
void wantsAccountSaved(AccountPtr acc);
|
||||
void wantsAccountSaved(Account* acc);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void slotHandleSslErrors(QNetworkReply*,QList<QSslError>);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// stub to prevent linker error
|
||||
#include "accountmanager.h"
|
||||
OCC::AccountManager *OCC::AccountManager::instance() { return 0; }
|
||||
|
||||
void OCC::AccountManager::saveAccountState(AccountState *) { }
|
||||
void OCC::AccountManager::save(bool saveCredentials) { Q_UNUSED(saveCredentials); }
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário