Multi-account WIP

This commit is contained in:
Olivier Goffart 2015-04-17 17:56:17 +02:00
parent 2da3bfb96f
commit a932eac832
16 changed files with 174 additions and 234 deletions

View file

@ -12,6 +12,7 @@
*/
#include "accountmanager.h"
#include "sslerrordialog.h"
#include <theme.h>
#include <creds/credentialsfactory.h>
#include <creds/abstractcredentials.h>
@ -37,17 +38,6 @@ AccountManager *AccountManager::instance()
return &instance;
}
void AccountManager::setAccount(AccountPtr account)
{
if (_account) {
emit accountRemoved(_account);
}
_account = account;
if (account) {
emit accountAdded(account);
}
}
bool AccountManager::restore()
{
// try to open the correctly themed settings
@ -113,7 +103,8 @@ bool AccountManager::restore()
settings->beginGroup(QLatin1String("General"));
acc->setApprovedCerts(QSslCertificate::fromData(settings->value(caCertsKeyC).toByteArray()));
acc->setMigrated(migratedCreds);
setAccount(acc);
acc->setSslErrorHandler(new SslDialogErrorHandler);
addAccount(acc);
return true;
}
return false;
@ -122,8 +113,13 @@ bool AccountManager::restore()
void AccountManager::save()
{
auto acc = account();
if (!acc) { return; }
foreach (const auto &acc , _accounts) {
save(acc->account());
}
}
void AccountManager::save(const AccountPtr& acc)
{
QScopedPointer<QSettings> settings(Account::settingsWithGroup(Theme::instance()->appName()));
settings->setValue(QLatin1String(urlC), acc->_url.toString());
if (acc->_credentials) {
@ -160,5 +156,21 @@ void AccountManager::save()
}
}
void AccountManager::addAccount(const AccountPtr& newAccount)
{
AccountStatePtr newAccountState(new AccountState(newAccount));
_accounts << newAccountState;
emit accountAdded(newAccountState.data());
}
void AccountManager::shutdown()
{
auto accountsCopy = _accounts;
_accounts.clear();
foreach (const auto &acc, accountsCopy) {
emit accountRemoved(acc.data());
}
}
}

View file

@ -14,18 +14,18 @@
#pragma once
#include "account.h"
#include "accountstate.h"
namespace OCC {
typedef QSharedPointer<AccountState> AccountStatePtr;
class OWNCLOUDSYNC_EXPORT AccountManager : public QObject {
Q_OBJECT
public:
static AccountManager *instance();
~AccountManager() {}
void setAccount(AccountPtr account);
AccountPtr account() { return _account; }
/**
* Saves the account to a given settings file
*/
@ -37,13 +37,30 @@ public:
*/
bool restore();
/**
* Add this account in the list of saved account.
* Typically called from the wizard
*/
void addAccount(const AccountPtr &newAccount);
/**
* remove all accounts
*/
void shutdown();
QList<AccountStatePtr> accounts() { return _accounts; }
private:
void save(const AccountPtr &account);
Q_SIGNALS:
void accountAdded(AccountPtr account);
void accountRemoved(AccountPtr account);
void accountAdded(AccountState *account);
void accountRemoved(AccountState *account);
private:
AccountManager() {}
AccountPtr _account;
QList<AccountStatePtr> _accounts;
};
}

View file

@ -26,7 +26,6 @@
#include "accountstate.h"
#include "quotainfo.h"
#include "creds/abstractcredentials.h"
#include "accountmanager.h"
#include <math.h>
@ -57,11 +56,11 @@ static const char progressBarStyleC[] =
"background-color: %1; width: 1px;"
"}";
AccountSettings::AccountSettings(QWidget *parent) :
AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
QWidget(parent),
ui(new Ui::AccountSettings),
_wasDisabledBefore(false),
_accountState(AccountStateManager::instance()->accountState())
_accountState(accountState)
{
ui->setupUi(this);
@ -119,9 +118,17 @@ AccountSettings::AccountSettings(QWidget *parent) :
ui->connectLabel->setText(tr("No account configured."));
connect(AccountStateManager::instance(), SIGNAL(accountStateAdded(AccountState*)),
this, SLOT(slotAccountStateChanged(AccountState*)));
slotAccountStateChanged(AccountStateManager::instance()->accountState());
connect(_accountState, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
slotAccountStateChanged(_accountState->state());
QuotaInfo *quotaInfo = _accountState->quotaInfo();
connect( quotaInfo, SIGNAL(quotaUpdated(qint64,qint64)),
this, SLOT(slotUpdateQuota(qint64,qint64)));
slotUpdateQuota(quotaInfo->lastQuotaTotalBytes(), quotaInfo->lastQuotaUsedBytes());
connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, Progress::Info)),
this, SLOT(slotSetProgress(QString, Progress::Info)) );
}
void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
@ -149,28 +156,6 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
menu->exec(tv->mapToGlobal(pos));
}
void AccountSettings::slotAccountStateChanged(AccountState *newAccountState)
{
if (_accountState) {
disconnect(_accountState, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
disconnect(_accountState->quotaInfo(), SIGNAL(quotaUpdated(qint64,qint64)),
this, SLOT(slotUpdateQuota(qint64,qint64)));
disconnect(_accountState, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
}
_accountState = newAccountState;
if (_accountState) {
connect(_accountState, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
slotAccountStateChanged(_accountState->state());
QuotaInfo *quotaInfo = _accountState->quotaInfo();
connect( quotaInfo, SIGNAL(quotaUpdated(qint64,qint64)),
this, SLOT(slotUpdateQuota(qint64,qint64)));
slotUpdateQuota(quotaInfo->lastQuotaTotalBytes(), quotaInfo->lastQuotaUsedBytes());
}
}
void AccountSettings::slotFolderActivated( const QModelIndex& indx )
{
if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
@ -184,7 +169,7 @@ void AccountSettings::slotAddFolder()
FolderMan *folderMan = FolderMan::instance();
folderMan->setSyncEnabled(false); // do not start more syncs.
FolderWizard *folderWizard = new FolderWizard(AccountManager::instance()->account(), this);
FolderWizard *folderWizard = new FolderWizard(_accountState->account(), this);
connect(folderWizard, SIGNAL(accepted()), SLOT(slotFolderWizardAccepted()));
connect(folderWizard, SIGNAL(rejected()), SLOT(slotFolderWizardRejected()));

View file

@ -45,7 +45,7 @@ class AccountSettings : public QWidget
Q_OBJECT
public:
explicit AccountSettings(QWidget *parent = 0);
explicit AccountSettings(AccountState *accountState, QWidget *parent = 0);
~AccountSettings();
@ -66,6 +66,7 @@ public slots:
void slotAccountStateChanged(int state);
void setGeneralErrors( const QStringList& errors );
AccountState* accountsState() { return _accountState; };
protected slots:
void slotAddFolder();
@ -92,7 +93,6 @@ private:
QLabel *_quotaLabel;
private slots:
void slotFolderSyncStateChange();
void slotAccountStateChanged(AccountState*);
void slotCustomContextMenuRequested(const QPoint&);
};

View file

@ -21,39 +21,6 @@
namespace OCC {
Q_GLOBAL_STATIC(AccountStateManager, g_accountStateManager)
AccountStateManager *AccountStateManager::instance()
{
return g_accountStateManager();
}
AccountStateManager::AccountStateManager()
: _accountState(0)
{
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountPtr)),
SLOT(slotAccountAdded(AccountPtr)));
}
AccountStateManager::~AccountStateManager()
{}
void AccountStateManager::setAccountState(AccountState *accountState)
{
if (_accountState) {
emit accountStateRemoved(_accountState);
}
_accountState = accountState;
if (accountState) {
emit accountStateAdded(accountState);
}
}
void AccountStateManager::slotAccountAdded(AccountPtr account)
{
setAccountState(new AccountState(account));
}
AccountState::AccountState(AccountPtr account)
: QObject(account.data())
, _account(account)
@ -78,7 +45,7 @@ AccountState::~AccountState()
AccountPtr AccountState::account() const
{
return _account.toStrongRef();
return _account;
}
AccountState::ConnectionStatus AccountState::connectionStatus() const
@ -267,4 +234,12 @@ void AccountState::slotCredentialsFetched(AbstractCredentials* credentials)
checkConnectivity();
}
QString AccountState::displayName()
{
auto user = account()->credentials()->user();
auto url = account()->url();
return tr("%1@%2").arg(user, url.host());
}
} // namespace OCC

View file

@ -27,29 +27,6 @@ class AccountState;
class Account;
class AbstractCredentials;
class AccountStateManager : public QObject {
Q_OBJECT
public:
static AccountStateManager *instance();
AccountStateManager();
~AccountStateManager();
AccountState *accountState() { return _accountState; }
signals:
void accountStateAdded(AccountState *accountState);
void accountStateRemoved(AccountState *accountState);
private slots:
void slotAccountAdded(AccountPtr account);
private:
void setAccountState(AccountState *account);
AccountState *_accountState;
};
/**
* @brief Extra info about an ownCloud server account.
*/
@ -108,6 +85,9 @@ public:
/// connection status and errors.
void checkConnectivity();
// The name of the account as shown in the toolbar
QString displayName();
private:
void setState(State state);
@ -120,9 +100,7 @@ protected Q_SLOTS:
void slotCredentialsFetched(AbstractCredentials* creds);
private:
// A strong reference here would keep Account and AccountState
// alive indefinitely since Account is the parent of AccountState.
QWeakPointer<Account> _account;
AccountPtr _account;
QuotaInfo *_quotaInfo;
State _state;
ConnectionStatus _connectionStatus;

View file

@ -123,13 +123,7 @@ Application::Application(int &argc, char **argv) :
connect(this, SIGNAL(messageReceived(QString, QObject*)), SLOT(slotParseMessage(QString, QObject*)));
// Create the account info manager to ensure it's listening to the
// account manager.
AccountStateManager::instance();
if (AccountManager::instance()->restore()) {
AccountManager::instance()->account()->setSslErrorHandler(new SslDialogErrorHandler);
}
AccountManager::instance()->restore();
FolderMan::instance()->setSyncEnabled(false);
@ -149,12 +143,12 @@ Application::Application(int &argc, char **argv) :
_gui->slotToggleLogBrowser(); // _showLogWindow is set in parseOptions.
}
connect(AccountStateManager::instance(), SIGNAL(accountStateAdded(AccountState*)),
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
SLOT(slotAccountStateAdded(AccountState*)));
connect(AccountStateManager::instance(), SIGNAL(accountStateRemoved(AccountState*)),
connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
SLOT(slotAccountStateRemoved(AccountState*)));
if (AccountState *ai = AccountStateManager::instance()->accountState()) {
slotAccountStateAdded(ai);
foreach (auto ai , AccountManager::instance()->accounts()) {
slotAccountStateAdded(ai.data());
}
connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)),
@ -180,22 +174,26 @@ Application::Application(int &argc, char **argv) :
Application::~Application()
{
// Remove the account from the account manager so it can be deleted.
AccountManager::instance()->setAccount(AccountPtr());
AccountManager::instance()->shutdown();
}
void Application::slotLogin()
{
AccountState *a = AccountStateManager::instance()->accountState();
if (a) {
auto list = AccountManager::instance()->accounts();
if (!list.isEmpty()) {
FolderMan::instance()->setupFolders();
}
foreach (const auto &a, list) {
a->setSignedOut(false);
}
}
void Application::slotLogout()
{
AccountState* ai = AccountStateManager::instance()->accountState();
if (ai) {
auto list = AccountManager::instance()->accounts();
foreach (const auto &ai, list) {
AccountPtr a = ai->account();
// invalidate & forget token/password
a->credentials()->invalidateToken();
@ -207,6 +205,9 @@ void Application::slotLogout()
// show result
_gui->slotComputeOverallSyncStatus();
}
if (!list.isEmpty()) {
FolderMan::instance()->setupFolders();
}
}
void Application::slotAccountStateRemoved(AccountState *accountState)
@ -244,12 +245,12 @@ void Application::slotStartUpdateDetector()
void Application::slotCheckConnection()
{
AccountState *accountState = AccountStateManager::instance()->accountState();
if( accountState ) {
auto list = AccountManager::instance()->accounts();
foreach (const auto &accountState , list) {
accountState->checkConnectivity();
}
} else {
if (list.isEmpty()) {
// let gui open the setup wizard
_gui->slotOpenSettingsDialog( true );
@ -301,10 +302,13 @@ void Application::slotUpdateConnectionErrors(int accountState)
_startupNetworkError = accountState == AccountState::NetworkError;
}
#warning FIXME
#if 0
AccountState *as = AccountStateManager::instance()->accountState();
if (as) {
_gui->setConnectionErrors( isConnected, as->connectionErrors() );
}
#endif
}
void Application::slotownCloudWizardDone( int res )

View file

@ -76,7 +76,7 @@ FolderMan::FolderMan(QObject *parent) :
connect(&_startScheduledSyncTimer, SIGNAL(timeout()),
SLOT(slotStartScheduledFolderSync()));
connect(AccountStateManager::instance(), SIGNAL(accountStateRemoved(AccountState*)),
connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
SLOT(slotRemoveFoldersForAccount(AccountState*)));
}
@ -201,15 +201,6 @@ int FolderMan::setupFolders()
dir.setFilter(QDir::Files | QDir::Hidden);
QStringList list = dir.entryList();
if( list.count() == 0 ) {
// maybe the account was just migrated.
AccountPtr acc = AccountManager::instance()->account();
if ( acc && acc->wasMigrated() ) {
AccountMigrator accMig;
list = accMig.migrateFolderDefinitons();
}
}
foreach ( const QString& alias, list ) {
Folder *f = setupFolderFromConfigFile( alias );
if( f ) {
@ -354,7 +345,8 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
targetPath.remove(0,1);
}
AccountState* accountState = AccountStateManager::instance()->accountState();
#warning fixme
AccountState* accountState = AccountManager::instance()->accounts().value(0).data();
if (!accountState) {
qWarning() << "can't create folder without an account";
return 0;

View file

@ -136,7 +136,7 @@ void ownCloudGui::setupOverlayIcons()
void ownCloudGui::slotOpenSettingsDialog( bool openSettings )
{
// if account is set up, start the configuration wizard.
if( AccountManager::instance()->account() ) {
if( !AccountManager::instance()->accounts().isEmpty() ) {
if( openSettings ) {
if (_settingsDialog.isNull() || !_settingsDialog->isVisible()) {
slotShowSettings();
@ -207,16 +207,14 @@ void ownCloudGui::slotAccountStateChanged()
void ownCloudGui::setConnectionErrors( bool /*connected*/, const QStringList& fails )
{
_startupFails = fails; // store that for the settings dialog once it appears.
if( !_settingsDialog.isNull() ) {
_settingsDialog->setGeneralErrors( _startupFails );
}
slotComputeOverallSyncStatus();
}
void ownCloudGui::slotComputeOverallSyncStatus()
{
if (AccountState *a = AccountStateManager::instance()->accountState()) {
#warning FIXME
if (AccountState *a = AccountManager::instance()->accounts().value(0).data()) {
if (a->isSignedOut()) {
_tray->setIcon(Theme::instance()->folderOfflineIcon(true));
_tray->setToolTip(tr("Please sign in"));
@ -234,10 +232,6 @@ void ownCloudGui::slotComputeOverallSyncStatus()
Folder::Map map = folderMan->map();
SyncResult overallResult = FolderMan::accountStatus(map.values());
// if there have been startup problems, show an error message.
if( !_settingsDialog.isNull() )
_settingsDialog->setGeneralErrors( _startupFails );
if( !_startupFails.isEmpty() ) {
trayMessage = _startupFails.join(QLatin1String("\n"));
QIcon statusIcon;
@ -281,7 +275,8 @@ void ownCloudGui::setupContextMenu()
{
FolderMan *folderMan = FolderMan::instance();
AccountState *a = AccountStateManager::instance()->accountState();
#warning FIXME
AccountState *a = AccountManager::instance()->accounts().value(0).data();
bool isConfigured = (a != 0);
_actionOpenoC->setEnabled(isConfigured);
@ -560,7 +555,6 @@ void ownCloudGui::slotShowSettings()
_settingsDialog->setAttribute( Qt::WA_DeleteOnClose, true );
_settingsDialog->show();
}
_settingsDialog->setGeneralErrors( _startupFails );
raiseDialog(_settingsDialog.data());
}
@ -595,8 +589,8 @@ void ownCloudGui::slotToggleLogBrowser()
void ownCloudGui::slotOpenOwnCloud()
{
if (AccountPtr account = AccountManager::instance()->account()) {
QDesktopServices::openUrl(account->url());
if (auto account = AccountManager::instance()->accounts().value(0)) {
QDesktopServices::openUrl(account->account()->url());
}
}
@ -645,14 +639,15 @@ void ownCloudGui::raiseDialog( QWidget *raiseWidget )
void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed)
{
AccountPtr account = AccountManager::instance()->account();
#warning FIXME
auto account = AccountManager::instance()->accounts().value(0);
if (!account) {
qDebug() << "Could not open share dialog because no account is configured";
return;
}
qDebug() << Q_FUNC_INFO << "Opening share dialog";
ShareDialog *w = new ShareDialog(account, sharePath, localPath, resharingAllowed);
ShareDialog *w = new ShareDialog(account->account(), sharePath, localPath, resharingAllowed);
w->getShares();
w->setAttribute( Qt::WA_DeleteOnClose, true );
raiseDialog(w);

View file

@ -454,14 +454,6 @@ bool OwncloudSetupWizard::ensureStartFromScratch(const QString &localFolder) {
return renameOk;
}
void OwncloudSetupWizard::replaceDefaultAccountWith(AccountPtr newAccount)
{
// new Account
AccountManager *mgr = AccountManager::instance();
mgr->setAccount(newAccount);
mgr->save();
}
// Method executed when the user ends has finished the basic setup.
void OwncloudSetupWizard::slotAssistantFinished( int result )
{
@ -511,26 +503,9 @@ void OwncloudSetupWizard::slotSkipFolderConfiguration()
void OwncloudSetupWizard::applyAccountChanges()
{
AccountPtr newAccount = _ocWizard->account();
AccountPtr origAccount = AccountManager::instance()->account();
auto manager = AccountManager::instance();
bool isInitialSetup = (origAccount == 0);
// check if either the account changed in a major way
bool reinitRequired =
newAccount->changed(origAccount, true /* ignoreProtocol, allows http->https */);
// If this is a completely new account, replace it entirely
// thereby clearing all folder definitions.
if (isInitialSetup || reinitRequired) {
replaceDefaultAccountWith(newAccount);
qDebug() << "Significant changes or first setup: switched to new account";
}
// Otherwise, set only URL and credentials
else {
origAccount->setUrl(newAccount->url());
origAccount->setCredentials(_ocWizard->getCredentials());
qDebug() << "Only password or schema was changed, adjusted existing account";
}
manager->addAccount(newAccount);
}

View file

@ -79,7 +79,6 @@ private:
void createRemoteFolder();
void finalizeSetup( bool );
bool ensureStartFromScratch(const QString &localFolder);
void replaceDefaultAccountWith(AccountPtr newAccount);
void applyAccountChanges();
bool checkDowngradeAdvised(QNetworkReply* reply);

View file

@ -23,6 +23,7 @@
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "protocolwidget.h"
#include "accountmanager.h"
#include <QLabel>
#include <QStandardItemModel>
@ -47,8 +48,7 @@ namespace OCC {
//
SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
QDialog(parent)
, _ui(new Ui::SettingsDialog)
, _accountSettings(new AccountSettings)
, _ui(new Ui::SettingsDialog), _gui(gui)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@ -72,11 +72,6 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
setWindowTitle(Theme::instance()->appNameGUI());
QIcon accountIcon(QLatin1String(":/client/resources/account.png"));
QAction *accountAction = toolBar->addAction(accountIcon, tr("Account"));
accountAction->setCheckable(true);
_ui->stack->addWidget(_accountSettings);
QIcon protocolIcon(QLatin1String(":/client/resources/activity.png"));
_protocolAction = toolBar->addAction(protocolIcon, tr("Activity"));
_protocolAction->setCheckable(true);
@ -95,29 +90,27 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
NetworkSettings *networkSettings = new NetworkSettings;
_ui->stack->addWidget(networkSettings);
_actions.insert(accountAction, _accountSettings);
_actions.insert(_protocolAction, protocolWidget);
_actions.insert(generalAction, generalSettings);
_actions.insert(networkAction, networkSettings);
QActionGroup *group = new QActionGroup(this);
group->addAction(accountAction);
group->addAction(_protocolAction);
group->addAction(generalAction);
group->addAction(networkAction);
group->setExclusive(true);
connect(group, SIGNAL(triggered(QAction*)), SLOT(slotSwitchPage(QAction*)));
connect( _accountSettings, SIGNAL(folderChanged()), gui, SLOT(slotFoldersChanged()));
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
gui, SLOT(slotFolderOpenAction(QString)));
connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, Progress::Info)),
_accountSettings, SLOT(slotSetProgress(QString, Progress::Info)) );
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
this, SLOT(accountAdded(AccountState*)));
connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
this, SLOT(accountRemoved(AccountState*)));
foreach (auto ai , AccountManager::instance()->accounts()) {
accountAdded(ai.data());
}
// default to Account
accountAction->setChecked(true);
toolBar->actions().at(0)->setChecked(true);
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
connect(closeButton, SIGNAL(clicked()), SLOT(accept()));
@ -136,11 +129,6 @@ SettingsDialog::~SettingsDialog()
delete _ui;
}
void SettingsDialog::setGeneralErrors(const QStringList &errors)
{
_accountSettings->setGeneralErrors(errors);
}
// close event is not being called here
void SettingsDialog::reject() {
ConfigFile cfg;
@ -166,5 +154,44 @@ void SettingsDialog::showActivityPage()
}
}
void SettingsDialog::accountAdded(AccountState *s)
{
QIcon accountIcon(QLatin1String(":/client/resources/account.png"));
auto toolBar = qobject_cast<QToolBar*>(layout()->menuBar());
Q_ASSERT(toolBar);
auto accountAction = new QAction(accountIcon, s->displayName(), this);
toolBar->insertAction(toolBar->actions().at(0), accountAction);
accountAction->setCheckable(true);
auto accountSettings = new AccountSettings(s, this);
_ui->stack->insertWidget(0 , accountSettings);
_actions.insert(accountAction, accountSettings);
auto group = findChild<QActionGroup*>(QString(), Qt::FindDirectChildrenOnly);
Q_ASSERT(group);
group->addAction(accountAction);
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged()));
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)),
_gui, SLOT(slotFolderOpenAction(QString)));
}
void SettingsDialog::accountRemoved(AccountState *s)
{
for (auto it = _actions.begin(); it != _actions.end(); ++it) {
auto as = qobject_cast<AccountSettings *>(*it);
if (!as) {
continue;
}
if (as->accountsState() == s) {
delete it.key();
delete it.value();
_actions.erase(it);
break;
}
}
}
} // namespace OCC

View file

@ -24,6 +24,8 @@ class QStandardItemModel;
namespace OCC {
class AccountState;
namespace Ui {
class SettingsDialog;
}
@ -41,7 +43,6 @@ public:
~SettingsDialog();
void addAccount(const QString &title, QWidget *widget);
void setGeneralErrors( const QStringList& errors );
public slots:
void showActivityPage();
@ -52,12 +53,14 @@ protected:
void accept() Q_DECL_OVERRIDE;
private slots:
void accountAdded(AccountState *);
void accountRemoved(AccountState *);
private:
Ui::SettingsDialog * const _ui;
QHash<QAction*, QWidget*> _actions;
AccountSettings * const _accountSettings;
QAction * _protocolAction;
ownCloudGui *_gui;
};
}

View file

@ -285,7 +285,7 @@ void ShareDialog::slotSharesFetched(const QString &reply)
bool success = false;
QVariantMap json = QtJson::parse(reply, success).toMap();
ShareDialog::_shares = json.value("ocs").toMap().value("data").toList();
const QString versionString = AccountManager::instance()->account()->serverVersion();
const QString versionString = _account->serverVersion();
Q_FOREACH(auto share, ShareDialog::_shares) {
QVariantMap data = share.toMap();

View file

@ -25,13 +25,7 @@ void AbstractCredentialsWizardPage::cleanupPage()
{
// Reset the credentials when the 'Back' button is used.
// Unfortunately this code is also run when the Wizard finishes
// prematurely with 'Skip Folder Configuration'. Therefore we need to
// avoid resetting credentials on active accounts.
AccountPtr account = static_cast<OwncloudWizard*>(wizard())->account();
if (account == AccountManager::instance()->account())
return;
AbstractCredentials *creds = account->credentials();
if (creds) {
if (!creds->inherits("DummyCredentials")) {

View file

@ -27,7 +27,6 @@
#include "theme.h"
#include "configfile.h"
#include "selectivesyncdialog.h"
#include <accountmanager.h>
#include "creds/abstractcredentials.h"
#include "networkjobs.h"
@ -160,25 +159,10 @@ void OwncloudAdvancedSetupPage::updateStatus()
wizard()->resize(wizard()->sizeHint());
}
/* obsolete */
bool OwncloudAdvancedSetupPage::dataChanged()
{
OwncloudWizard* ocWizard(dynamic_cast< OwncloudWizard* >(wizard()));
AccountPtr oldAccount = AccountManager::instance()->account();
if (!ocWizard || !oldAccount) {
// If there was no account configured before, the data is new (hence changed)
return true;
}
const QString url(field("OCUrl").toString());
AbstractCredentials* newCredentials(ocWizard->getCredentials());
AbstractCredentials* oldCredentials(oldAccount->credentials());
const bool differentCreds(oldCredentials->changed(newCredentials));
delete newCredentials;
const QString newLocalFolder(QDir::toNativeSeparators(_ui.pbSelectLocalFolder->text()));
const QString oldLocalFolder(QDir::toNativeSeparators(_oldLocalFolder));
return ((url != oldAccount->url().toString()) || differentCreds || (oldLocalFolder != newLocalFolder));
return true;
}
void OwncloudAdvancedSetupPage::startSpinner()