Selective sync: add a page in the folder wizard

This commit is contained in:
Olivier Goffart 2014-08-15 16:26:38 +02:00
parent 4c4d02c0d0
commit b6eda9076e
7 changed files with 96 additions and 13 deletions

View file

@ -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);

View file

@ -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();
}

View file

@ -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);

View file

@ -18,6 +18,7 @@
#include "mirall/theme.h"
#include "mirall/networkjobs.h"
#include "mirall/account.h"
#include "selectivesyncdialog.h"
#include <QDebug>
#include <QDesktopServices>
@ -30,6 +31,7 @@
#include <QValidator>
#include <QWizardPage>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <stdlib.h>
@ -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);

View file

@ -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;
};

View file

@ -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()

View file

@ -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 *);