Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 3 additions & 8 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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?
Expand Down Expand Up @@ -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()) {
Expand Down
12 changes: 2 additions & 10 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -561,11 +558,6 @@ void AccountState::slotCredentialsFetched()
}


Account *AccountState::accountForQml() const
{
return _account;
}

std::unique_ptr<QSettings> AccountState::settings()
{
auto s = ConfigFile::settingsWithGroup(QStringLiteral("Accounts"));
Expand Down
7 changes: 3 additions & 4 deletions src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -173,7 +173,6 @@ protected Q_SLOTS:
void slotCredentialsFetched();

private:
Account *accountForQml() const;
QPointer<Account> _account;
JobQueueGuard _queueGuard;
State _state;
Expand Down