diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 2aec3f25fdf..50809b875ea 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -108,9 +108,9 @@ bool AccountManager::restore() settings->beginGroup(accountIndex); if (auto acc = loadAccountHelper(*settings)) { acc->_groupIndex = accountIndex; - if (auto accState = AccountState::loadFromSettings(acc, *settings)) { - addAccountState(accState); - } + AccountState *accState = new AccountState(acc); + accState->loadSettings(*settings); + addAccountState(accState); } settings->endGroup(); } diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 206e73d2ae9..1954e3135fd 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -522,16 +522,12 @@ void AccountSettings::buildManageAccountMenu() ui->manageAccountButton->setMenu(menu); } -// Refactoring todo: the signal sends the new account state, refactor this to use that param void AccountSettings::slotAccountStateChanged(AccountState::State state) { if (!_accountState || !_accountState->account()) { return; } - Account *account = _accountState->account(); - qCDebug(lcAccountSettings) << "Account state changed to" << state << "for account" << account; - FolderMan *folderMan = FolderMan::instance(); for (auto *folder : folderMan->folders()) { _model->slotUpdateFolderState(folder); @@ -541,11 +537,9 @@ void AccountSettings::slotAccountStateChanged(AccountState::State state) case AccountState::Connected: { QStringList errors; StatusIcon icon = StatusIcon::Connected; - if (account->serverSupportLevel() != Account::ServerSupportLevel::Supported) { - errors << tr("The server version %1 is unsupported! Proceed at your own risk.").arg(account->capabilities().status().versionString()); - icon = StatusIcon::Warning; - } + showConnectionLabel(tr("Connected"), icon, errors); + // todo: this does not belong here in the gui. connect(_accountState->account()->spacesManager(), &GraphApi::SpacesManager::updated, this, &AccountSettings::slotSpacesUpdated, Qt::UniqueConnection); // Refactoring todo: won't this get called every time the state changes to connected even if the spaces manager is already // triggering the slot? ie duplicate call to slotSpacesUpdated? @@ -587,6 +581,7 @@ void AccountSettings::slotAccountStateChanged(AccountState::State state) } } +// todo: #47 - incorporate existing todo's below as well void AccountSettings::slotSpacesUpdated() { if (!_accountState || !_accountState->account() || !_accountState->account()->spacesManager()) { diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 50e9a8c21b7..79899632acb 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -115,16 +115,13 @@ void AccountState::connectNetworkInformation() connect(NetworkInformation::instance(), &NetworkInformation::isBehindCaptivePortalChanged, this, &AccountState::onBehindCaptivePortalChanged); } -AccountState *AccountState::loadFromSettings(Account *account, const QSettings &settings) +void AccountState::loadSettings(const QSettings &settings) { - auto accountState = new AccountState(account); const bool userExplicitlySignedOut = settings.value(userExplicitlySignedOutC(), false).toBool(); if (userExplicitlySignedOut) { // see writeToSettings below - accountState->setState(SignedOut); + setState(SignedOut); } - - return accountState; } void AccountState::writeToSettings(QSettings &settings) const @@ -561,11 +558,6 @@ void AccountState::slotCredentialsFetched() } -Account *AccountState::accountForQml() const -{ - return _account; -} - std::unique_ptr AccountState::settings() { auto s = ConfigFile::settingsWithGroup(QStringLiteral("Accounts")); diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 3ab618247b3..c54355acd8c 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -47,7 +47,7 @@ class FetchServerSettingsJob; class OWNCLOUDGUI_EXPORT AccountState : public QObject { Q_OBJECT - Q_PROPERTY(Account *account READ accountForQml CONSTANT) + Q_PROPERTY(Account *account READ account CONSTANT) Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged) Q_PROPERTY(AccountState::State state READ state NOTIFY stateChanged) QML_ELEMENT @@ -95,11 +95,11 @@ class OWNCLOUDGUI_EXPORT AccountState : public QObject explicit AccountState(Account *account); ~AccountState() override; - /** Creates an account state from settings and an Account object. + /** loads the state's settings * * Use from AccountManager with a prepared QSettings object only. */ - static AccountState *loadFromSettings(Account *account, const QSettings &settings); + void loadSettings(const QSettings &settings); /** Writes account state information to settings. * @@ -173,7 +173,6 @@ protected Q_SLOTS: void slotCredentialsFetched(); private: - Account *accountForQml() const; QPointer _account; JobQueueGuard _queueGuard; State _state;