2014-08-11 17:09:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
#include "selectivesyncdialog.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "account.h"
|
2016-03-16 21:07:40 +03:00
|
|
|
#include "excludedfiles.h"
|
2014-08-11 17:09:17 +04:00
|
|
|
#include "networkjobs.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "folderman.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <QFileIconProvider>
|
2014-08-15 18:49:22 +04:00
|
|
|
#include <QHeaderView>
|
2014-08-11 17:09:17 +04:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QScopedValueRollback>
|
2015-04-14 21:00:42 +03:00
|
|
|
#include <QTreeWidgetItem>
|
2014-08-27 19:31:57 +04:00
|
|
|
#include <QLabel>
|
2014-08-11 17:09:17 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2014-08-11 17:09:17 +04:00
|
|
|
|
2015-04-14 21:00:42 +03:00
|
|
|
|
|
|
|
class SelectiveSyncTreeViewItem : public QTreeWidgetItem {
|
|
|
|
public:
|
|
|
|
SelectiveSyncTreeViewItem(int type = QTreeWidgetItem::Type)
|
|
|
|
: QTreeWidgetItem(type) { }
|
|
|
|
SelectiveSyncTreeViewItem(const QStringList &strings, int type = QTreeWidgetItem::Type)
|
|
|
|
: QTreeWidgetItem(strings, type) { }
|
|
|
|
SelectiveSyncTreeViewItem(QTreeWidget *view, int type = QTreeWidgetItem::Type)
|
|
|
|
: QTreeWidgetItem(view, type) { }
|
|
|
|
SelectiveSyncTreeViewItem(QTreeWidgetItem *parent, int type = QTreeWidgetItem::Type)
|
|
|
|
: QTreeWidgetItem(parent, type) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool operator<(const QTreeWidgetItem &other)const {
|
|
|
|
int column = treeWidget()->sortColumn();
|
|
|
|
if (column == 1) {
|
|
|
|
return data(1, Qt::UserRole).toLongLong() < other.data(1, Qt::UserRole).toLongLong();
|
|
|
|
}
|
|
|
|
return QTreeWidgetItem::operator <(other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
SelectiveSyncTreeView::SelectiveSyncTreeView(AccountPtr account, QWidget* parent)
|
2014-10-08 20:56:30 +04:00
|
|
|
: QTreeWidget(parent), _inserting(false), _account(account)
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
2014-10-22 15:48:05 +04:00
|
|
|
_loading = new QLabel(tr("Loading ..."), this);
|
2014-08-15 16:58:16 +04:00
|
|
|
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(slotItemExpanded(QTreeWidgetItem*)));
|
|
|
|
connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
|
2014-10-01 15:44:23 +04:00
|
|
|
setSortingEnabled(true);
|
|
|
|
sortByColumn(0, Qt::AscendingOrder);
|
2015-01-14 17:07:17 +03:00
|
|
|
setColumnCount(2);
|
2015-01-14 18:30:10 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
2015-01-14 17:07:17 +03:00
|
|
|
header()->setSectionResizeMode(0, QHeaderView::QHeaderView::ResizeToContents);
|
|
|
|
header()->setSectionResizeMode(1, QHeaderView::QHeaderView::ResizeToContents);
|
2015-07-14 16:18:55 +03:00
|
|
|
#else
|
|
|
|
header()->resizeSection(0, sizeHint().width()/2);
|
2015-01-14 18:30:10 +03:00
|
|
|
#endif
|
2015-01-14 17:07:17 +03:00
|
|
|
header()->setStretchLastSection(true);
|
|
|
|
headerItem()->setText(0, tr("Name"));
|
|
|
|
headerItem()->setText(1, tr("Size"));
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-21 14:18:08 +03:00
|
|
|
QSize SelectiveSyncTreeView::sizeHint() const
|
|
|
|
{
|
|
|
|
return QTreeView::sizeHint().expandedTo(QSize(400, 400));
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:58:16 +04:00
|
|
|
void SelectiveSyncTreeView::refreshFolders()
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
2014-08-27 21:03:11 +04:00
|
|
|
LsColJob *job = new LsColJob(_account, _folderPath, this);
|
2016-02-11 17:06:00 +03:00
|
|
|
job->setProperties(QList<QByteArray>() << "resourcetype" << "http://owncloud.org/ns:size");
|
2014-12-02 14:25:51 +03:00
|
|
|
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
|
2014-08-11 17:09:17 +04:00
|
|
|
this, SLOT(slotUpdateDirectories(QStringList)));
|
2015-02-06 14:25:58 +03:00
|
|
|
connect(job, SIGNAL(finishedWithError(QNetworkReply*)),
|
|
|
|
this, SLOT(slotLscolFinishedWithError(QNetworkReply*)));
|
2014-08-11 17:09:17 +04:00
|
|
|
job->start();
|
2014-08-15 16:58:16 +04:00
|
|
|
clear();
|
2014-10-22 15:48:05 +04:00
|
|
|
_loading->show();
|
2015-01-21 14:18:08 +03:00
|
|
|
_loading->move(10,header()->height() + 10);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
|
2015-02-06 14:02:42 +03:00
|
|
|
void SelectiveSyncTreeView::setFolderInfo(const QString& folderPath, const QString& rootName, const QStringList& oldBlackList)
|
|
|
|
{
|
|
|
|
_folderPath = folderPath;
|
|
|
|
if (_folderPath.startsWith(QLatin1Char('/'))) {
|
|
|
|
// remove leading '/'
|
|
|
|
_folderPath = folderPath.mid(1);
|
|
|
|
}
|
|
|
|
_rootName = rootName;
|
|
|
|
_oldBlackList = oldBlackList;
|
|
|
|
refreshFolders();
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
static QTreeWidgetItem* findFirstChild(QTreeWidgetItem *parent, const QString& text)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < parent->childCount(); ++i) {
|
|
|
|
QTreeWidgetItem *child = parent->child(i);
|
|
|
|
if (child->text(0) == text) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-14 17:07:17 +03:00
|
|
|
void SelectiveSyncTreeView::recursiveInsert(QTreeWidgetItem* parent, QStringList pathTrail, QString path, qint64 size)
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
|
|
|
QFileIconProvider prov;
|
|
|
|
QIcon folderIcon = prov.icon(QFileIconProvider::Folder);
|
|
|
|
if (pathTrail.size() == 0) {
|
|
|
|
if (path.endsWith('/')) {
|
|
|
|
path.chop(1);
|
|
|
|
}
|
|
|
|
parent->setToolTip(0, path);
|
|
|
|
parent->setData(0, Qt::UserRole, path);
|
|
|
|
} else {
|
2015-04-14 21:00:42 +03:00
|
|
|
SelectiveSyncTreeViewItem *item = static_cast<SelectiveSyncTreeViewItem*>(findFirstChild(parent, pathTrail.first()));
|
2014-08-11 17:09:17 +04:00
|
|
|
if (!item) {
|
2015-04-14 21:00:42 +03:00
|
|
|
item = new SelectiveSyncTreeViewItem(parent);
|
2014-09-17 18:35:23 +04:00
|
|
|
if (parent->checkState(0) == Qt::Checked
|
|
|
|
|| parent->checkState(0) == Qt::PartiallyChecked) {
|
2014-08-15 14:29:10 +04:00
|
|
|
item->setCheckState(0, Qt::Checked);
|
2014-08-15 16:58:16 +04:00
|
|
|
foreach(const QString &str , _oldBlackList) {
|
2015-01-22 17:53:33 +03:00
|
|
|
if (str == path || str == QLatin1String("/")) {
|
2014-08-15 14:29:10 +04:00
|
|
|
item->setCheckState(0, Qt::Unchecked);
|
2014-08-11 17:09:17 +04:00
|
|
|
break;
|
|
|
|
} else if (str.startsWith(path)) {
|
|
|
|
item->setCheckState(0, Qt::PartiallyChecked);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 18:35:23 +04:00
|
|
|
} else if (parent->checkState(0) == Qt::Unchecked) {
|
|
|
|
item->setCheckState(0, Qt::Unchecked);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
item->setIcon(0, folderIcon);
|
|
|
|
item->setText(0, pathTrail.first());
|
2016-02-22 19:26:09 +03:00
|
|
|
if (size >= 0) {
|
|
|
|
item->setText(1, Utility::octetsToString(size));
|
|
|
|
item->setData(1, Qt::UserRole, size);
|
|
|
|
}
|
2014-08-11 17:09:17 +04:00
|
|
|
// item->setData(0, Qt::UserRole, pathTrail.first());
|
|
|
|
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
|
|
|
|
}
|
|
|
|
|
|
|
|
pathTrail.removeFirst();
|
2015-01-14 17:07:17 +03:00
|
|
|
recursiveInsert(item, pathTrail, path, size);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:22:52 +03:00
|
|
|
void SelectiveSyncTreeView::slotUpdateDirectories(QStringList list)
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
2015-01-14 17:07:17 +03:00
|
|
|
auto job = qobject_cast<LsColJob *>(sender());
|
2014-08-11 17:09:17 +04:00
|
|
|
QScopedValueRollback<bool> isInserting(_inserting);
|
|
|
|
_inserting = true;
|
|
|
|
|
2015-04-14 21:00:42 +03:00
|
|
|
SelectiveSyncTreeViewItem *root = static_cast<SelectiveSyncTreeViewItem*>(topLevelItem(0));
|
2015-02-06 14:25:58 +03:00
|
|
|
|
2015-08-24 13:52:41 +03:00
|
|
|
QUrl url = _account->davUrl();
|
|
|
|
QString pathToRemove = url.path();
|
|
|
|
if (!pathToRemove.endsWith('/')) {
|
|
|
|
pathToRemove.append('/');
|
|
|
|
}
|
|
|
|
pathToRemove.append(_folderPath);
|
|
|
|
if (!_folderPath.isEmpty())
|
|
|
|
pathToRemove.append('/');
|
|
|
|
|
2015-10-02 14:22:52 +03:00
|
|
|
// Check for excludes.
|
|
|
|
QMutableListIterator<QString> it(list);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2016-03-16 21:07:40 +03:00
|
|
|
if (ExcludedFiles::instance().isExcluded(it.value(), pathToRemove, FolderMan::instance()->ignoreHiddenFiles()))
|
2015-10-02 14:22:52 +03:00
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
|
2015-08-24 13:52:41 +03:00
|
|
|
// Since / cannot be in the blacklist, expand it to the actual
|
|
|
|
// list of top-level folders as soon as possible.
|
|
|
|
if (_oldBlackList == QStringList("/")) {
|
|
|
|
_oldBlackList.clear();
|
|
|
|
foreach (QString path, list) {
|
2016-03-18 15:52:45 +03:00
|
|
|
path.remove(pathToRemove);
|
2015-08-24 13:52:41 +03:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_oldBlackList.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:25:58 +03:00
|
|
|
if (!root && list.size() <= 1) {
|
|
|
|
_loading->setText(tr("No subfolders currently on the server."));
|
|
|
|
_loading->resize(_loading->sizeHint()); // because it's not in a layout
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_loading->hide();
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
if (!root) {
|
2015-04-14 21:00:42 +03:00
|
|
|
root = new SelectiveSyncTreeViewItem(this);
|
2014-08-15 16:58:16 +04:00
|
|
|
root->setText(0, _rootName);
|
2014-08-11 17:09:17 +04:00
|
|
|
root->setIcon(0, Theme::instance()->applicationIcon());
|
2014-08-27 19:18:40 +04:00
|
|
|
root->setData(0, Qt::UserRole, QString());
|
2014-08-15 16:58:16 +04:00
|
|
|
if (_oldBlackList.isEmpty()) {
|
2014-08-11 17:09:17 +04:00
|
|
|
root->setCheckState(0, Qt::Checked);
|
|
|
|
} else {
|
|
|
|
root->setCheckState(0, Qt::PartiallyChecked);
|
|
|
|
}
|
2015-10-19 11:58:54 +03:00
|
|
|
qint64 size = job ? job->_sizes.value(pathToRemove, -1) : -1;
|
|
|
|
if (size >= 0) {
|
|
|
|
root->setText(1, Utility::octetsToString(size));
|
|
|
|
root->setData(1, Qt::UserRole, size);
|
|
|
|
}
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
2014-08-15 16:58:16 +04:00
|
|
|
|
2016-05-19 16:36:46 +03:00
|
|
|
Utility::sortFilenames(list);
|
2014-08-11 17:09:17 +04:00
|
|
|
foreach (QString path, list) {
|
2015-01-14 17:07:17 +03:00
|
|
|
auto size = job ? job->_sizes.value(path) : 0;
|
2014-08-15 16:58:16 +04:00
|
|
|
path.remove(pathToRemove);
|
2014-08-11 17:09:17 +04:00
|
|
|
QStringList paths = path.split('/');
|
|
|
|
if (paths.last().isEmpty()) paths.removeLast();
|
2014-08-15 16:58:16 +04:00
|
|
|
if (paths.isEmpty())
|
|
|
|
continue;
|
2014-10-24 17:46:35 +04:00
|
|
|
if (!path.endsWith('/')) {
|
|
|
|
path.append('/');
|
|
|
|
}
|
2015-01-14 17:07:17 +03:00
|
|
|
recursiveInsert(root, paths, path, size);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
2015-01-14 17:07:17 +03:00
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
root->setExpanded(true);
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:25:58 +03:00
|
|
|
void SelectiveSyncTreeView::slotLscolFinishedWithError(QNetworkReply *r)
|
|
|
|
{
|
|
|
|
if (r->error() == QNetworkReply::ContentNotFoundError) {
|
|
|
|
_loading->setText(tr("No subfolders currently on the server."));
|
|
|
|
} else {
|
2016-02-20 12:33:13 +03:00
|
|
|
_loading->setText(tr("An error occurred while loading the list of sub folders."));
|
2015-02-06 14:25:58 +03:00
|
|
|
}
|
|
|
|
_loading->resize(_loading->sizeHint()); // because it's not in a layout
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:58:16 +04:00
|
|
|
void SelectiveSyncTreeView::slotItemExpanded(QTreeWidgetItem *item)
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
|
|
|
QString dir = item->data(0, Qt::UserRole).toString();
|
2014-08-27 19:18:40 +04:00
|
|
|
if (dir.isEmpty()) return;
|
|
|
|
QString prefix;
|
|
|
|
if (!_folderPath.isEmpty()) {
|
|
|
|
prefix = _folderPath + QLatin1Char('/');
|
|
|
|
}
|
2014-08-27 21:03:11 +04:00
|
|
|
LsColJob *job = new LsColJob(_account, prefix + dir, this);
|
2016-02-11 17:06:00 +03:00
|
|
|
job->setProperties(QList<QByteArray>() << "resourcetype" << "http://owncloud.org/ns:size");
|
2014-12-02 14:25:51 +03:00
|
|
|
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
|
2014-08-11 17:09:17 +04:00
|
|
|
SLOT(slotUpdateDirectories(QStringList)));
|
|
|
|
job->start();
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:58:16 +04:00
|
|
|
void SelectiveSyncTreeView::slotItemChanged(QTreeWidgetItem *item, int col)
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
|
|
|
if (col != 0 || _inserting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (item->checkState(0) == Qt::Checked) {
|
|
|
|
// If we are checked, check that we may need to check the parent as well if
|
2015-10-05 07:21:19 +03:00
|
|
|
// all the siblings are also checked
|
2014-08-11 17:09:17 +04:00
|
|
|
QTreeWidgetItem *parent = item->parent();
|
|
|
|
if (parent && parent->checkState(0) != Qt::Checked) {
|
|
|
|
bool hasUnchecked = false;
|
|
|
|
for (int i = 0; i < parent->childCount(); ++i) {
|
|
|
|
if (parent->child(i)->checkState(0) != Qt::Checked) {
|
|
|
|
hasUnchecked = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasUnchecked) {
|
|
|
|
parent->setCheckState(0, Qt::Checked);
|
|
|
|
} else if (parent->checkState(0) == Qt::Unchecked) {
|
|
|
|
parent->setCheckState(0, Qt::PartiallyChecked);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 18:35:23 +04:00
|
|
|
// also check all the children
|
2014-08-11 17:09:17 +04:00
|
|
|
for (int i = 0; i < item->childCount(); ++i) {
|
|
|
|
if (item->child(i)->checkState(0) != Qt::Checked) {
|
|
|
|
item->child(i)->setCheckState(0, Qt::Checked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->checkState(0) == Qt::Unchecked) {
|
|
|
|
QTreeWidgetItem *parent = item->parent();
|
2014-09-17 18:35:23 +04:00
|
|
|
if (parent && parent->checkState(0) == Qt::Checked) {
|
|
|
|
parent->setCheckState(0, Qt::PartiallyChecked);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
|
2014-09-17 18:35:23 +04:00
|
|
|
// Uncheck all the children
|
2014-08-11 17:09:17 +04:00
|
|
|
for (int i = 0; i < item->childCount(); ++i) {
|
|
|
|
if (item->child(i)->checkState(0) != Qt::Unchecked) {
|
|
|
|
item->child(i)->setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 18:35:23 +04:00
|
|
|
|
|
|
|
// Can't uncheck the root.
|
|
|
|
if (!parent) {
|
|
|
|
item->setCheckState(0, Qt::PartiallyChecked);
|
|
|
|
}
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item->checkState(0) == Qt::PartiallyChecked) {
|
|
|
|
QTreeWidgetItem *parent = item->parent();
|
|
|
|
if (parent && parent->checkState(0) != Qt::PartiallyChecked) {
|
|
|
|
parent->setCheckState(0, Qt::PartiallyChecked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:58:16 +04:00
|
|
|
QStringList SelectiveSyncTreeView::createBlackList(QTreeWidgetItem* root) const
|
2014-08-11 17:09:17 +04:00
|
|
|
{
|
|
|
|
if (!root) {
|
2014-08-15 16:58:16 +04:00
|
|
|
root = topLevelItem(0);
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
2014-08-18 19:03:47 +04:00
|
|
|
if (!root) return QStringList();
|
2014-08-11 17:09:17 +04:00
|
|
|
|
|
|
|
switch(root->checkState(0)) {
|
|
|
|
case Qt::Unchecked:
|
2014-10-24 17:46:35 +04:00
|
|
|
return QStringList(root->data(0, Qt::UserRole).toString() + "/");
|
2014-08-15 14:29:10 +04:00
|
|
|
case Qt::Checked:
|
2014-08-18 19:03:47 +04:00
|
|
|
return QStringList();
|
2014-08-11 17:09:17 +04:00
|
|
|
case Qt::PartiallyChecked:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList result;
|
2014-08-12 13:12:58 +04:00
|
|
|
if (root->childCount()) {
|
|
|
|
for (int i = 0; i < root->childCount(); ++i) {
|
2014-08-15 14:29:10 +04:00
|
|
|
result += createBlackList(root->child(i));
|
2014-08-12 13:12:58 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-08-15 16:58:16 +04:00
|
|
|
// We did not load from the server so we re-use the one from the old black list
|
2014-08-12 13:12:58 +04:00
|
|
|
QString path = root->data(0, Qt::UserRole).toString();
|
2014-08-15 16:58:16 +04:00
|
|
|
foreach (const QString & it, _oldBlackList) {
|
2014-08-12 13:12:58 +04:00
|
|
|
if (it.startsWith(path))
|
|
|
|
result += it;
|
|
|
|
}
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-08-24 13:52:41 +03:00
|
|
|
QStringList SelectiveSyncTreeView::oldBlackList() const
|
|
|
|
{
|
|
|
|
return _oldBlackList;
|
|
|
|
}
|
|
|
|
|
2015-01-14 17:59:36 +03:00
|
|
|
qint64 SelectiveSyncTreeView::estimatedSize(QTreeWidgetItem* root)
|
|
|
|
{
|
|
|
|
if (!root) {
|
|
|
|
root = topLevelItem(0);
|
|
|
|
}
|
|
|
|
if (!root) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
switch(root->checkState(0)) {
|
|
|
|
case Qt::Unchecked:
|
|
|
|
return 0;
|
|
|
|
case Qt::Checked:
|
|
|
|
return root->data(1, Qt::UserRole).toLongLong();
|
|
|
|
case Qt::PartiallyChecked:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 result = 0;
|
|
|
|
if (root->childCount()) {
|
|
|
|
for (int i = 0; i < root->childCount(); ++i) {
|
|
|
|
auto r = estimatedSize(root->child(i));
|
|
|
|
if (r < 0) return r;
|
|
|
|
result += r;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We did not load from the server so we have no idea how much we will sync from this branch
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-18 14:09:48 +03:00
|
|
|
SelectiveSyncDialog::SelectiveSyncDialog(AccountPtr account, Folder* folder, QWidget* parent, Qt::WindowFlags f)
|
2016-04-06 16:01:28 +03:00
|
|
|
: QDialog(parent, f), _folder(folder),
|
|
|
|
_okButton(0) // defined in init()
|
2014-08-28 14:25:44 +04:00
|
|
|
{
|
2016-04-06 16:01:28 +03:00
|
|
|
bool ok;
|
2015-02-05 18:20:42 +03:00
|
|
|
init(account, tr("Unchecked folders will be <b>removed</b> from your local file system and will not be synchronized to this computer anymore"));
|
2016-04-06 16:01:28 +03:00
|
|
|
QStringList selectiveSyncList = _folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
|
|
|
|
if( ok ) {
|
|
|
|
_treeView->setFolderInfo(_folder->remotePath(), _folder->alias(),selectiveSyncList);
|
|
|
|
} else {
|
|
|
|
_okButton->setEnabled(false);
|
|
|
|
}
|
2014-08-28 14:25:44 +04:00
|
|
|
// 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()));
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:02:42 +03:00
|
|
|
SelectiveSyncDialog::SelectiveSyncDialog(AccountPtr account, const QString &folder,
|
|
|
|
const QStringList& blacklist, QWidget* parent, Qt::WindowFlags f)
|
2014-08-28 14:25:44 +04:00
|
|
|
: QDialog(parent, f), _folder(0)
|
|
|
|
{
|
2015-02-05 18:20:42 +03:00
|
|
|
init(account,
|
|
|
|
Theme::instance()->wizardSelectiveSyncDefaultNothing() ?
|
|
|
|
tr("Choose What to Sync: Select remote subfolders you wish to synchronize.") :
|
|
|
|
tr("Choose What to Sync: Deselect remote subfolders you do not wish to synchronize."));
|
2015-02-06 16:49:45 +03:00
|
|
|
_treeView->setFolderInfo(folder, folder, blacklist);
|
2014-08-28 14:25:44 +04:00
|
|
|
}
|
|
|
|
|
2015-02-05 18:20:42 +03:00
|
|
|
void SelectiveSyncDialog::init(const AccountPtr &account, const QString &labelText)
|
2014-08-15 16:58:16 +04:00
|
|
|
{
|
2014-10-21 20:30:07 +04:00
|
|
|
setWindowTitle(tr("Choose What to Sync"));
|
2014-08-15 16:58:16 +04:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
2014-08-28 14:25:44 +04:00
|
|
|
_treeView = new SelectiveSyncTreeView(account, this);
|
2015-02-05 18:20:42 +03:00
|
|
|
auto label = new QLabel(labelText);
|
2014-10-27 13:30:42 +03:00
|
|
|
label->setWordWrap(true);
|
|
|
|
layout->addWidget(label);
|
2014-08-15 16:58:16 +04:00
|
|
|
layout->addWidget(_treeView);
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal);
|
2016-04-06 16:01:28 +03:00
|
|
|
_okButton = buttonBox->addButton(QDialogButtonBox::Ok);
|
|
|
|
connect(_okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
2014-08-15 16:58:16 +04:00
|
|
|
QPushButton *button;
|
|
|
|
button = buttonBox->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
layout->addWidget(buttonBox);
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
void SelectiveSyncDialog::accept()
|
|
|
|
{
|
2014-08-27 21:03:11 +04:00
|
|
|
if (_folder) {
|
2016-04-06 16:01:28 +03:00
|
|
|
bool ok;
|
|
|
|
auto oldBlackListSet = _folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok).toSet();
|
|
|
|
if( ! ok ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-27 21:03:11 +04:00
|
|
|
QStringList blackList = _treeView->createBlackList();
|
2015-05-21 13:22:50 +03:00
|
|
|
_folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, blackList);
|
2014-08-11 17:09:17 +04:00
|
|
|
|
2014-08-28 18:27:46 +04:00
|
|
|
FolderMan *folderMan = FolderMan::instance();
|
|
|
|
if (_folder->isBusy()) {
|
2014-09-26 14:43:54 +04:00
|
|
|
_folder->slotTerminateSync();
|
2014-08-28 18:27:46 +04:00
|
|
|
}
|
2014-10-09 17:27:41 +04:00
|
|
|
|
|
|
|
//The part that changed should not be read from the DB on next sync because there might be new folders
|
|
|
|
// (the ones that are no longer in the blacklist)
|
|
|
|
auto blackListSet = blackList.toSet();
|
|
|
|
auto changes = (oldBlackListSet - blackListSet) + (blackListSet - oldBlackListSet);
|
|
|
|
foreach(const auto &it, changes) {
|
|
|
|
_folder->journalDb()->avoidReadFromDbOnNextSync(it);
|
|
|
|
}
|
|
|
|
|
2015-04-28 16:13:39 +03:00
|
|
|
folderMan->slotScheduleSync(_folder);
|
2014-08-27 21:03:11 +04:00
|
|
|
}
|
2014-08-11 17:09:17 +04:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:03:11 +04:00
|
|
|
QStringList SelectiveSyncDialog::createBlackList() const
|
|
|
|
{
|
|
|
|
return _treeView->createBlackList();
|
|
|
|
}
|
|
|
|
|
2015-08-24 13:52:41 +03:00
|
|
|
QStringList SelectiveSyncDialog::oldBlackList() const
|
|
|
|
{
|
|
|
|
return _treeView->oldBlackList();
|
|
|
|
}
|
|
|
|
|
2015-01-15 15:07:16 +03:00
|
|
|
qint64 SelectiveSyncDialog::estimatedSize()
|
2015-01-14 17:59:36 +03:00
|
|
|
{
|
|
|
|
return _treeView->estimatedSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-11 17:09:17 +04:00
|
|
|
}
|
|
|
|
|