Skip to content
Permalink
Browse files

Ask before automatically syncing a folder that was just shared.

  • Loading branch information
shaan7 committed Apr 11, 2019
1 parent 8491ef4 commit 0dcf32af5016fbe00c0e4e952ef9354f27609583
@@ -1085,11 +1085,16 @@ void AccountSettings::refreshSelectiveSyncStatus()
ui->bigFolderUi->setVisible(false);
} else {
ConfigFile cfg;
QString info = !cfg.confirmExternalStorage()
? tr("There are folders that were not synchronized because they are too big: ")
: !cfg.newBigFolderSizeLimit().first
? tr("There are folders that were not synchronized because they are external storages: ")
: tr("There are folders that were not synchronized because they are too big or external storages: ");
QString info;
if (cfg.confirmExternalStorage() && !cfg.newBigFolderSizeLimit().first && !cfg.confirmSharedFolder()) {
info = tr("There are folders that were not synchronized because they are external storages: ");
} else if (cfg.newBigFolderSizeLimit().first && !cfg.confirmExternalStorage() && !cfg.confirmSharedFolder()) {
info = tr("There are folders that were not synchronized because they are too big: ");
} else if (cfg.confirmSharedFolder() && !cfg.newBigFolderSizeLimit().first && !cfg.confirmExternalStorage()) {
info = tr("There are folders that were not synchronized because they were shared with you: ");
} else {
info = tr("There are folders that were excluded as per your settings: ");
}

ui->selectiveSyncNotification->setText(info + msg);
ui->selectiveSyncButtons->setVisible(false);
@@ -25,7 +25,6 @@
#include "common/syncjournalfilerecord.h"
#include "syncresult.h"
#include "clientproxy.h"
#include "syncengine.h"
#include "syncrunfilelog.h"
#include "socketapi.h"
#include "theme.h"
@@ -96,8 +95,8 @@ Folder::Folder(const FolderDefinition &definition,
connect(_engine.data(), &SyncEngine::transmissionProgress, this, &Folder::slotTransmissionProgress);
connect(_engine.data(), &SyncEngine::itemCompleted,
this, &Folder::slotItemCompleted);
connect(_engine.data(), &SyncEngine::newBigFolder,
this, &Folder::slotNewBigFolderDiscovered);
connect(_engine.data(), &SyncEngine::newProblematicFolder,
this, &Folder::slotNewProblematicFolderDiscovered);
connect(_engine.data(), &SyncEngine::seenLockedFile, FolderMan::instance(), &FolderMan::slotSyncOnceFileUnlocks);
connect(_engine.data(), &SyncEngine::aboutToPropagate,
this, &Folder::slotLogPropagationStart);
@@ -685,6 +684,7 @@ void Folder::setSyncOptions()
auto newFolderLimit = cfgFile.newBigFolderSizeLimit();
opt._newBigFolderSizeLimit = newFolderLimit.first ? newFolderLimit.second * 1000LL * 1000LL : -1; // convert from MB to B
opt._confirmExternalStorage = cfgFile.confirmExternalStorage();
opt._confirmSharedFolder = cfgFile.confirmSharedFolder();
opt._moveFilesToTrash = cfgFile.moveToTrash();

QByteArray chunkSizeEnv = qgetenv("OWNCLOUD_CHUNK_SIZE");
@@ -925,7 +925,7 @@ void Folder::slotItemCompleted(const SyncFileItemPtr &item)
emit ProgressDispatcher::instance()->itemCompleted(alias(), item);
}

void Folder::slotNewBigFolderDiscovered(const QString &newF, bool isExternal)
void Folder::slotNewProblematicFolderDiscovered(const QString &newF, SyncEngine::ProblemReason reason)
{
auto newFolder = newF;
if (!newFolder.endsWith(QLatin1Char('/'))) {
@@ -950,10 +950,24 @@ void Folder::slotNewBigFolderDiscovered(const QString &newF, bool isExternal)
journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, undecidedList);
emit newBigFolderDiscovered(newFolder);
}
QString message = !isExternal ? (tr("A new folder larger than %1 MB has been added: %2.\n")
QString message;

switch (reason) {
case DiscoveryJob::IsBig:
message = tr("A new folder larger than %1 MB has been added: %2.\n")
.arg(ConfigFile().newBigFolderSizeLimit().second)
.arg(newF))
: (tr("A folder from an external storage has been added.\n"));
.arg(newF);
break;

case DiscoveryJob::IsExternal:
message = tr("A folder from an external storage has been added.\n");
break;

case DiscoveryJob::IsShared:
message = tr("A folder has been shared with you.\n");
break;
}

message += tr("Please go in the settings to select it if you wish to download it.");

auto logger = Logger::instance();
@@ -18,6 +18,7 @@
#define MIRALL_FOLDER_H

#include "syncresult.h"
#include "syncengine.h"
#include "progressdispatcher.h"
#include "common/syncjournaldb.h"
#include "networkjobs.h"
@@ -34,8 +35,6 @@ class QThread;
class QSettings;

namespace OCC {

class SyncEngine;
class AccountState;
class SyncRunFileLog;
class FolderWatcher;
@@ -303,7 +302,7 @@ private slots:

void slotEmitFinishedDelayed();

void slotNewBigFolderDiscovered(const QString &, bool isExternal);
void slotNewProblematicFolderDiscovered(const QString &newF, SyncEngine::ProblemReason reason);

void slotLogPropagationStart();

@@ -71,6 +71,7 @@ GeneralSettings::GeneralSettings(QWidget *parent)
connect(_ui->newFolderLimitCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->newFolderLimitSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &GeneralSettings::saveMiscSettings);
connect(_ui->newExternalStorage, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);
connect(_ui->newSharedFolder, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings);

#ifndef WITH_CRASHREPORTER
_ui->crashreporterCheckBox->setVisible(false);
@@ -123,6 +124,7 @@ void GeneralSettings::loadMiscSettings()
_ui->newFolderLimitCheckBox->setChecked(newFolderLimit.first);
_ui->newFolderLimitSpinBox->setValue(newFolderLimit.second);
_ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage());
_ui->newSharedFolder->setChecked(cfgFile.confirmSharedFolder());
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
}

@@ -159,6 +161,7 @@ void GeneralSettings::saveMiscSettings()
cfgFile.setNewBigFolderSizeLimit(_ui->newFolderLimitCheckBox->isChecked(),
_ui->newFolderLimitSpinBox->value());
cfgFile.setConfirmExternalStorage(_ui->newExternalStorage->isChecked());
cfgFile.setConfirmSharedFolder(_ui->newSharedFolder->isChecked());
}

void GeneralSettings::slotToggleLaunchOnStartup(bool enable)
@@ -242,6 +242,17 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QCheckBox" name="newSharedFolder">
<property name="text">
<string>Ask for confirmation before synchronizing s&amp;hared storages</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
@@ -76,6 +76,9 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
_ui.confSpinBox->hide();
_ui.confTraillingSizeLabel->hide();
}
if (theme->wizardHideSharedFoldersConfirmationCheckbox()) {
_ui.confCheckBoxShared->hide();
}
}

void OwncloudAdvancedSetupPage::setupCustomization()
@@ -135,6 +138,7 @@ void OwncloudAdvancedSetupPage::initializePage()
_ui.confCheckBoxSize->setChecked(newFolderLimit.first);
_ui.confSpinBox->setValue(newFolderLimit.second);
_ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage());
_ui.confCheckBoxShared->setChecked(cfgFile.confirmSharedFolder());
}

// Called if the user changes the user- or url field. Adjust the texts and
@@ -252,6 +256,7 @@ bool OwncloudAdvancedSetupPage::validatePage()
cfgFile.setNewBigFolderSizeLimit(_ui.confCheckBoxSize->isChecked(),
_ui.confSpinBox->value());
cfgFile.setConfirmExternalStorage(_ui.confCheckBoxExternal->isChecked());
cfgFile.setConfirmSharedFolder(_ui.confCheckBoxShared->isChecked());
}

emit createLocalAndRemoteFolders(localFolder(), _remoteFolder);
@@ -124,22 +124,6 @@
<property name="horizontalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
@@ -168,13 +152,36 @@
</item>
</layout>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="confCheckBoxExternal">
<property name="text">
<string>Ask for confirmation before synchronizing e&amp;xternal storages</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="confCheckBoxShared">
<property name="text">
<string>Ask for confirmation before synchronizing s&amp;hared storages</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -81,6 +81,7 @@ static const char downloadLimitC[] = "BWLimit/downloadLimit";
static const char newBigFolderSizeLimitC[] = "newBigFolderSizeLimit";
static const char useNewBigFolderSizeLimitC[] = "useNewBigFolderSizeLimit";
static const char confirmExternalStorageC[] = "confirmExternalStorage";
static const char confirmSharedFolderC[] = "confirmSharedFolder";
static const char moveToTrashC[] = "moveToTrash";

static const char maxLogLinesC[] = "Logging/maxLogLines";
@@ -737,6 +738,16 @@ void ConfigFile::setConfirmExternalStorage(bool isChecked)
setValue(confirmExternalStorageC, isChecked);
}

bool ConfigFile::confirmSharedFolder() const
{
return getValue(confirmSharedFolderC, QString(), false).toBool();
}

void ConfigFile::setConfirmSharedFolder(bool isChecked)
{
setValue(confirmSharedFolderC, isChecked);
}

bool ConfigFile::moveToTrash() const
{
return getValue(moveToTrashC, QString(), false).toBool();
@@ -121,6 +121,8 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
void setNewBigFolderSizeLimit(bool isChecked, quint64 mbytes);
bool confirmExternalStorage() const;
void setConfirmExternalStorage(bool);
bool confirmSharedFolder() const;
void setConfirmSharedFolder(bool);

/** If we should move the files deleted on the server in the trash */
bool moveToTrash() const;
@@ -103,7 +103,7 @@ bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString &path, RemotePermis
return false;
}

emit newBigFolder(path, true);
emit newProblematicFolder(path, IsExternal);
return true;
}

@@ -112,6 +112,12 @@ bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString &path, RemotePermis
return false;
}

if (_syncOptions._confirmSharedFolder
&& remotePerm.hasPermission(RemotePermissions::IsShared)) {
emit newProblematicFolder(path, IsShared);
return true;
}

auto limit = _syncOptions._newBigFolderSizeLimit;
if (limit < 0) {
// no limit, everything is allowed;
@@ -129,7 +135,7 @@ bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString &path, RemotePermis

if (result >= limit) {
// we tell the UI there is a new folder
emit newBigFolder(path, false);
emit newProblematicFolder(path, IsBig);
return true;
} else {
// it is not too big, put it in the white list (so we will not do more query for the children)
@@ -187,6 +187,11 @@ class DiscoveryJob : public QObject


public:
enum ProblemReason {
IsBig = 1,
IsExternal = 2,
IsShared = 3
};
explicit DiscoveryJob(CSYNC *ctx, QObject *parent = nullptr)
: QObject(parent)
, _csync_ctx(ctx)
@@ -205,6 +210,6 @@ class DiscoveryJob : public QObject
void doGetSizeSignal(const QString &path, qint64 *result);

// A new folder was discovered and was not synced because of the confirmation feature
void newBigFolder(const QString &folder, bool isExternal);
void newProblematicFolder(const QString &folder, ProblemReason reason);
};
}
@@ -83,6 +83,7 @@ SyncEngine::SyncEngine(AccountPtr account, const QString &localPath,
qRegisterMetaType<SyncFileStatus>("SyncFileStatus");
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
qRegisterMetaType<ProblemReason>("ProblemReason");

// Everything in the SyncEngine expects a trailing slash for the localPath.
ASSERT(localPath.endsWith(QLatin1Char('/')));
@@ -911,8 +912,8 @@ void SyncEngine::startSync()
connect(discoveryJob, &DiscoveryJob::folderDiscovered,
this, &SyncEngine::slotFolderDiscovered);

connect(discoveryJob, &DiscoveryJob::newBigFolder,
this, &SyncEngine::newBigFolder);
connect(discoveryJob, &DiscoveryJob::newProblematicFolder,
this, &SyncEngine::newProblematicFolder);


// This is used for the DiscoveryJob to be able to request the main thread/
@@ -62,6 +62,8 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
{
Q_OBJECT
public:
using ProblemReason = DiscoveryJob::ProblemReason;

SyncEngine(AccountPtr account, const QString &localPath,
const QString &remotePath, SyncJournalDb *journal);
~SyncEngine();
@@ -159,7 +161,7 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
void aboutToRestoreBackup(bool *restore);

// A new folder was discovered and was not synced because of the confirmation feature
void newBigFolder(const QString &folder, bool isExternal);
void newProblematicFolder(const QString &folder, DiscoveryJob::ProblemReason reason);

/** Emitted when propagation has problems with a locked file.
*
@@ -33,6 +33,9 @@ struct SyncOptions
/** If a confirmation should be asked for external storages */
bool _confirmExternalStorage = false;

/** If a confirmation should be asked for shared folders */
bool _confirmSharedFolder = false;

/** If remotely deleted files are needed to move to trash */
bool _moveFilesToTrash = false;

@@ -318,6 +318,11 @@ bool Theme::wizardHideFolderSizeLimitCheckbox() const
return false;
}

bool Theme::wizardHideSharedFoldersConfirmationCheckbox() const
{
return false;
}

QString Theme::gitSHA1() const
{
QString devString;
@@ -247,6 +247,11 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
* in the account wizard
*/
virtual bool wizardHideExternalStorageConfirmationCheckbox() const;
/**
* Hide the checkbox that says "Ask for confirmation before synchronizing shared folders"
* in the account wizard
*/
virtual bool wizardHideSharedFoldersConfirmationCheckbox() const;

/**
* Alternative path on the server that provides access to the webdav capabilities

0 comments on commit 0dcf32a

Please sign in to comment.
You can’t perform that action at this time.