From b6eda9076e37b81127da463e094f373dd61e5e63 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 15 Aug 2014 16:26:38 +0200 Subject: [PATCH] Selective sync: add a page in the folder wizard --- src/mirall/accountsettings.cpp | 5 ++- src/mirall/folderman.cpp | 4 ++- src/mirall/folderman.h | 3 +- src/mirall/folderwizard.cpp | 50 +++++++++++++++++++++++++++++- src/mirall/folderwizard.h | 25 ++++++++++++++- src/mirall/selectivesyncdialog.cpp | 12 +++---- src/mirall/selectivesyncdialog.h | 10 ++++-- 7 files changed, 96 insertions(+), 13 deletions(-) diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index f76d5a4eb..934fbba1e 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -193,10 +193,13 @@ void AccountSettings::slotFolderWizardAccepted() QString alias = folderWizard->field(QLatin1String("alias")).toString(); QString sourceFolder = folderWizard->field(QLatin1String("sourceFolder")).toString(); QString targetPath = folderWizard->property("targetPath").toString(); + QStringList selectiveSyncBlackList + = folderWizard->property("selectiveSyncBlackList").toStringList(); if (!FolderMan::ensureJournalGone( sourceFolder )) return; - folderMan->addFolderDefinition(alias, sourceFolder, targetPath ); + + folderMan->addFolderDefinition(alias, sourceFolder, targetPath, selectiveSyncBlackList ); Folder *f = folderMan->setupFolderFromConfigFile( alias ); slotAddFolder( f ); folderMan->setSyncEnabled(true); diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 24ad66743..185d47c52 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -516,7 +516,8 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& ) QTimer::singleShot(200, this, SLOT(slotScheduleFolderSync())); } -void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder, const QString& targetPath ) +void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder, + const QString& targetPath, const QStringList &selectiveSyncBlackList ) { QString escapedAlias = escapeAlias(alias); // Create a settings file named after the alias @@ -527,6 +528,7 @@ void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceF // for compat reasons settings.setValue(QLatin1String("backend"), "owncloud" ); settings.setValue(QLatin1String("connection"), Theme::instance()->appName()); + settings.setValue(QLatin1String("blackList"), selectiveSyncBlackList); settings.sync(); } diff --git a/src/mirall/folderman.h b/src/mirall/folderman.h index abfaf1253..469b24b40 100644 --- a/src/mirall/folderman.h +++ b/src/mirall/folderman.h @@ -50,7 +50,8 @@ public: * QString sourceFolder on local machine * QString targetPath on remote */ - void addFolderDefinition(const QString&, const QString&, const QString& ); + void addFolderDefinition(const QString&, const QString&, const QString& , + const QStringList &selectiveSyncBlacklist = QStringList{} ); /** Returns the folder which the file or directory stored in path is in */ Folder* folderForPath(const QString& path); diff --git a/src/mirall/folderwizard.cpp b/src/mirall/folderwizard.cpp index e5792abe0..e619cd78c 100644 --- a/src/mirall/folderwizard.cpp +++ b/src/mirall/folderwizard.cpp @@ -18,6 +18,7 @@ #include "mirall/theme.h" #include "mirall/networkjobs.h" #include "mirall/account.h" +#include "selectivesyncdialog.h" #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include @@ -424,6 +426,50 @@ void FolderWizardRemotePath::showWarn( const QString& msg ) const // ==================================================================================== +FolderWizardSelectiveSync::FolderWizardSelectiveSync() +{ + QVBoxLayout *layout = new QVBoxLayout(this); + _treeView = new SelectiveSyncTreeView(this); + layout->addWidget(new QLabel(tr("Selective Sync: You can optionally deselect subfolders you do not wish to synchronize."))); + layout->addWidget(_treeView); +} + +FolderWizardSelectiveSync::~FolderWizardSelectiveSync() +{ +} + + +void FolderWizardSelectiveSync::initializePage() +{ + QString alias = wizard()->field(QLatin1String("alias")).toString(); + QString targetPath = wizard()->property("targetPath").toString(); + if (targetPath.startsWith('/')) { + targetPath = targetPath.mid(1); + } + _treeView->setFolderInfo(targetPath, alias, {}); + QWizardPage::initializePage(); +} + +bool FolderWizardSelectiveSync::validatePage() +{ + wizard()->setProperty("selectiveSyncBlackList", QVariant(_treeView->createBlackList())); + return true; +} + +void FolderWizardSelectiveSync::cleanupPage() +{ + QString alias = wizard()->field(QLatin1String("alias")).toString(); + QString targetPath = wizard()->property("targetPath").toString(); + _treeView->setFolderInfo(targetPath, alias, {}); + QWizardPage::cleanupPage(); +} + + + + +// ==================================================================================== + + /** * Folder wizard itself */ @@ -431,7 +477,8 @@ void FolderWizardRemotePath::showWarn( const QString& msg ) const FolderWizard::FolderWizard( QWidget *parent ) : QWizard(parent), _folderWizardSourcePage(new FolderWizardLocalPath), - _folderWizardTargetPage(0) + _folderWizardTargetPage(0), + _folderWizardSelectiveSyncPage(new FolderWizardSelectiveSync) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setPage(Page_Source, _folderWizardSourcePage ); @@ -439,6 +486,7 @@ FolderWizard::FolderWizard( QWidget *parent ) _folderWizardTargetPage = new FolderWizardRemotePath(); setPage(Page_Target, _folderWizardTargetPage ); } + setPage(Page_SelectiveSync, _folderWizardSelectiveSyncPage); setWindowTitle( tr("Add Folder") ); setOptions(QWizard::CancelButtonOnLeft); diff --git a/src/mirall/folderwizard.h b/src/mirall/folderwizard.h index 8db9b1319..157d29c24 100644 --- a/src/mirall/folderwizard.h +++ b/src/mirall/folderwizard.h @@ -26,6 +26,8 @@ namespace Mirall { +class SelectiveSyncTreeView; + class ownCloudInfo; class FormatWarningsWizardPage : public QWizardPage { @@ -90,6 +92,25 @@ private: }; + +class FolderWizardSelectiveSync : public QWizardPage +{ + Q_OBJECT +public: + FolderWizardSelectiveSync(); + ~FolderWizardSelectiveSync(); + + virtual bool validatePage() Q_DECL_OVERRIDE; + + virtual void initializePage() Q_DECL_OVERRIDE; + virtual void cleanupPage() Q_DECL_OVERRIDE; + +private: + SelectiveSyncTreeView *_treeView; + +}; + + /** * */ @@ -100,7 +121,8 @@ public: enum { Page_Source, - Page_Target + Page_Target, + Page_SelectiveSync }; FolderWizard(QWidget *parent = 0); @@ -110,6 +132,7 @@ private: FolderWizardLocalPath *_folderWizardSourcePage; FolderWizardRemotePath *_folderWizardTargetPage; + FolderWizardSelectiveSync *_folderWizardSelectiveSyncPage; }; diff --git a/src/mirall/selectivesyncdialog.cpp b/src/mirall/selectivesyncdialog.cpp index aa15f3916..64018718c 100644 --- a/src/mirall/selectivesyncdialog.cpp +++ b/src/mirall/selectivesyncdialog.cpp @@ -28,9 +28,8 @@ namespace Mirall { -SelectiveSyncTreeView::SelectiveSyncTreeView(const QString& folderPath, const QString &rootName, - const QStringList &oldBlackList, QWidget* parent) - : QTreeWidget(parent), _folderPath(folderPath), _rootName(rootName), _oldBlackList(oldBlackList) +SelectiveSyncTreeView::SelectiveSyncTreeView(QWidget* parent) + : QTreeWidget(parent) { connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(slotItemExpanded(QTreeWidgetItem*))); connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemChanged(QTreeWidgetItem*,int))); @@ -121,7 +120,8 @@ void SelectiveSyncTreeView::slotUpdateDirectories(const QStringList&list) pathToRemove.append('/'); } pathToRemove.append(_folderPath); - pathToRemove.append('/'); + if (!_folderPath.isEmpty()) + pathToRemove.append('/'); foreach (QString path, list) { path.remove(pathToRemove); @@ -245,7 +245,7 @@ SelectiveSyncDialog::SelectiveSyncDialog(Folder* folder, QWidget* parent, Qt::Wi : QDialog(parent, f), _folder(folder) { QVBoxLayout *layout = new QVBoxLayout(this); - _treeView = new SelectiveSyncTreeView(_folder->remotePath(), _folder->alias(), _folder->selectiveSyncBlackList(), parent); + _treeView = new SelectiveSyncTreeView(parent); layout->addWidget(_treeView); QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal); QPushButton *button; @@ -258,7 +258,7 @@ SelectiveSyncDialog::SelectiveSyncDialog(Folder* folder, QWidget* parent, Qt::Wi // Make sure we don't get crashes if the folder is destroyed while we are still open connect(_folder, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater())); - _treeView->refreshFolders(); + _treeView->setFolderInfo(_folder->remotePath(), _folder->alias(), _folder->selectiveSyncBlackList()); } void SelectiveSyncDialog::accept() diff --git a/src/mirall/selectivesyncdialog.h b/src/mirall/selectivesyncdialog.h index 45bc80997..44cab643b 100644 --- a/src/mirall/selectivesyncdialog.h +++ b/src/mirall/selectivesyncdialog.h @@ -25,10 +25,16 @@ class Folder; class SelectiveSyncTreeView : public QTreeWidget { Q_OBJECT public: - explicit SelectiveSyncTreeView(const QString &folderPath, const QString &rootName, - const QStringList &oldBlackList, QWidget* parent = 0); + explicit SelectiveSyncTreeView(QWidget* parent = 0); QStringList createBlackList(QTreeWidgetItem* root = 0) const; void refreshFolders(); + void setFolderInfo(const QString &folderPath, const QString &rootName, + const QStringList &oldBlackList) { + _folderPath = folderPath; + _rootName = rootName; + _oldBlackList = oldBlackList; + refreshFolders(); + } private slots: void slotUpdateDirectories(const QStringList &); void slotItemExpanded(QTreeWidgetItem *);