Skip to content

Commit

Permalink
Folderwizard: Prepare for multiaccount. #43
Browse files Browse the repository at this point in the history
Avoid accessing the global account instance and instead pass it in
from the outside.
  • Loading branch information
ckamm committed Jan 28, 2015
1 parent 2a3df55 commit 350ad98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void AccountSettings::slotAddFolder()
FolderMan *folderMan = FolderMan::instance();
folderMan->setSyncEnabled(false); // do not start more syncs.

FolderWizard *folderWizard = new FolderWizard(this);
FolderWizard *folderWizard = new FolderWizard(AccountManager::instance()->account(), this);

connect(folderWizard, SIGNAL(accepted()), SLOT(slotFolderWizardAccepted()));
connect(folderWizard, SIGNAL(rejected()), SLOT(slotFolderWizardRejected()));
Expand Down
21 changes: 11 additions & 10 deletions src/gui/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ void FolderWizardLocalPath::slotChooseLocalFolder()
}

// =================================================================================
FolderWizardRemotePath::FolderWizardRemotePath()
FolderWizardRemotePath::FolderWizardRemotePath(AccountPtr account)
: FormatWarningsWizardPage()
,_warnWasVisible(false)
,_account(account)

{
_ui.setupUi(this);
Expand Down Expand Up @@ -272,7 +273,7 @@ void FolderWizardRemotePath::slotCreateRemoteFolder(const QString &folder)
}
fullPath += "/" + folder;

MkColJob *job = new MkColJob(AccountManager::instance()->account(), fullPath, this);
MkColJob *job = new MkColJob(_account, fullPath, this);
/* check the owncloud configuration file and query the ownCloud */
connect(job, SIGNAL(finished(QNetworkReply::NetworkError)),
SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));
Expand Down Expand Up @@ -334,7 +335,7 @@ void FolderWizardRemotePath::recursiveInsert(QTreeWidgetItem *parent, QStringLis

void FolderWizardRemotePath::slotUpdateDirectories(const QStringList &list)
{
QString webdavFolder = QUrl(AccountManager::instance()->account()->davUrl()).path();
QString webdavFolder = QUrl(_account->davUrl()).path();

QTreeWidgetItem *root = _ui.folderTreeWidget->topLevelItem(0);
if (!root) {
Expand All @@ -355,7 +356,7 @@ void FolderWizardRemotePath::slotUpdateDirectories(const QStringList &list)

void FolderWizardRemotePath::slotRefreshFolders()
{
LsColJob *job = new LsColJob(AccountManager::instance()->account(), "/", this);
LsColJob *job = new LsColJob(_account, "/", this);
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
SLOT(slotUpdateDirectories(QStringList)));
job->start();
Expand All @@ -365,7 +366,7 @@ void FolderWizardRemotePath::slotRefreshFolders()
void FolderWizardRemotePath::slotItemExpanded(QTreeWidgetItem *item)
{
QString dir = item->data(0, Qt::UserRole).toString();
LsColJob *job = new LsColJob(AccountManager::instance()->account(), dir, this);
LsColJob *job = new LsColJob(_account, dir, this);
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
SLOT(slotUpdateDirectories(QStringList)));
job->start();
Expand Down Expand Up @@ -436,10 +437,10 @@ void FolderWizardRemotePath::showWarn( const QString& msg ) const

// ====================================================================================

FolderWizardSelectiveSync::FolderWizardSelectiveSync()
FolderWizardSelectiveSync::FolderWizardSelectiveSync(AccountPtr account)
{
QVBoxLayout *layout = new QVBoxLayout(this);
_treeView = new SelectiveSyncTreeView(AccountManager::instance()->account(), this);
_treeView = new SelectiveSyncTreeView(account, this);
layout->addWidget(new QLabel(tr("Choose What to Sync: You can optionally deselect remote subfolders you do not wish to synchronize.")));
layout->addWidget(_treeView);
}
Expand Down Expand Up @@ -484,16 +485,16 @@ void FolderWizardSelectiveSync::cleanupPage()
* Folder wizard itself
*/

FolderWizard::FolderWizard( QWidget *parent )
FolderWizard::FolderWizard(AccountPtr account, QWidget *parent)
: QWizard(parent),
_folderWizardSourcePage(new FolderWizardLocalPath),
_folderWizardTargetPage(0),
_folderWizardSelectiveSyncPage(new FolderWizardSelectiveSync)
_folderWizardSelectiveSyncPage(new FolderWizardSelectiveSync(account))
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setPage(Page_Source, _folderWizardSourcePage );
if (!Theme::instance()->singleSyncFolder()) {
_folderWizardTargetPage = new FolderWizardRemotePath();
_folderWizardTargetPage = new FolderWizardRemotePath(account);
setPage(Page_Target, _folderWizardTargetPage );
}
setPage(Page_SelectiveSync, _folderWizardSelectiveSyncPage);
Expand Down
9 changes: 5 additions & 4 deletions src/gui/folderwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QTimer>

#include "folder.h"
#include "accountfwd.h"

#include "ui_folderwizardsourcepage.h"
#include "ui_folderwizardtargetpage.h"
Expand Down Expand Up @@ -67,7 +68,7 @@ class FolderWizardRemotePath : public FormatWarningsWizardPage
{
Q_OBJECT
public:
FolderWizardRemotePath();
explicit FolderWizardRemotePath(AccountPtr account);
~FolderWizardRemotePath();

virtual bool isComplete() const Q_DECL_OVERRIDE;
Expand All @@ -89,15 +90,15 @@ protected slots:
void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path);
Ui_FolderWizardTargetPage _ui;
bool _warnWasVisible;

AccountPtr _account;
};


class FolderWizardSelectiveSync : public QWizardPage
{
Q_OBJECT
public:
FolderWizardSelectiveSync();
explicit FolderWizardSelectiveSync(AccountPtr account);
~FolderWizardSelectiveSync();

virtual bool validatePage() Q_DECL_OVERRIDE;
Expand Down Expand Up @@ -125,7 +126,7 @@ class FolderWizard : public QWizard
Page_SelectiveSync
};

FolderWizard(QWidget *parent = 0);
explicit FolderWizard(AccountPtr account, QWidget *parent = 0);
~FolderWizard();

private:
Expand Down

0 comments on commit 350ad98

Please sign in to comment.