Confirm feature: Confirm for any folder, not only shared ones

issue #3148
This commit is contained in:
Olivier Goffart 2015-07-27 09:54:20 +02:00
parent fea997c84a
commit 0ccaae9a22
13 changed files with 50 additions and 52 deletions

View file

@ -92,7 +92,7 @@ struct csync_s {
/* hooks for checking the white list (uses the update_callback_userdata) */ /* hooks for checking the white list (uses the update_callback_userdata) */
int (*checkSelectiveSyncBlackListHook)(void*, const char*); int (*checkSelectiveSyncBlackListHook)(void*, const char*);
int (*checkSelectiveSyncNewShareHook)(void*, const char*); int (*checkSelectiveSyncNewFolderHook)(void*, const char*);
csync_vio_opendir_hook remote_opendir_hook; csync_vio_opendir_hook remote_opendir_hook;

View file

@ -401,14 +401,12 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
/* file not found in statedb */ /* file not found in statedb */
st->instruction = CSYNC_INSTRUCTION_NEW; st->instruction = CSYNC_INSTRUCTION_NEW;
if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY && ctx->current == REMOTE_REPLICA && ctx->callbacks.checkSelectiveSyncNewShareHook) { if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY && ctx->current == REMOTE_REPLICA && ctx->callbacks.checkSelectiveSyncNewFolderHook) {
if (strchr(fs->remotePerm, 'S') != NULL) { /* check that the directory is shared */ if (ctx->callbacks.checkSelectiveSyncNewFolderHook(ctx->callbacks.update_callback_userdata, path)) {
if (ctx->callbacks.checkSelectiveSyncNewShareHook(ctx->callbacks.update_callback_userdata, path)) {
SAFE_FREE(st); SAFE_FREE(st);
return 1; return 1;
} }
} }
}
goto out; goto out;
} }
} }

View file

@ -850,14 +850,14 @@ void Folder::startSync(const QStringList &pathList)
connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo))); connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo)));
connect(_engine.data(), SIGNAL(jobCompleted(const SyncFileItem &)), this, SLOT(slotJobCompleted(const SyncFileItem &))); connect(_engine.data(), SIGNAL(jobCompleted(const SyncFileItem &)), this, SLOT(slotJobCompleted(const SyncFileItem &)));
connect(_engine.data(), SIGNAL(syncItemDiscovered(const SyncFileItem &)), this, SLOT(slotSyncItemDiscovered(const SyncFileItem &))); connect(_engine.data(), SIGNAL(syncItemDiscovered(const SyncFileItem &)), this, SLOT(slotSyncItemDiscovered(const SyncFileItem &)));
connect(_engine.data(), SIGNAL(newSharedFolder(QString)), this, SLOT(slotNewSharedBigFolderDiscovered(QString))); connect(_engine.data(), SIGNAL(newBigFolder(QString)), this, SLOT(slotNewBigFolderDiscovered(QString)));
setDirtyNetworkLimits(); setDirtyNetworkLimits();
ConfigFile cfgFile; ConfigFile cfgFile;
auto newFolderLimit = cfgFile.newSharedFolderSizeLimit(); auto newFolderLimit = cfgFile.newBigFolderSizeLimit();
quint64 limit = newFolderLimit.first ? newFolderLimit.second * 1000 * 1000 : -1; // convert from MB to B quint64 limit = newFolderLimit.first ? newFolderLimit.second * 1000 * 1000 : -1; // convert from MB to B
_engine->setNewSharedFolderSizeLimit(limit); _engine->setNewBigFolderSizeLimit(limit);
QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection); QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection);
@ -1044,7 +1044,7 @@ void Folder::slotSyncItemDiscovered(const SyncFileItem & item)
emit ProgressDispatcher::instance()->syncItemDiscovered(alias(), item); emit ProgressDispatcher::instance()->syncItemDiscovered(alias(), item);
} }
void Folder::slotNewSharedBigFolderDiscovered(const QString &newF) void Folder::slotNewBigFolderDiscovered(const QString &newF)
{ {
auto newFolder = newF; auto newFolder = newF;
if (!newFolder.endsWith(QLatin1Char('/'))) { if (!newFolder.endsWith(QLatin1Char('/'))) {
@ -1065,7 +1065,7 @@ void Folder::slotNewSharedBigFolderDiscovered(const QString &newF)
if (!undecidedList.contains(newFolder)) { if (!undecidedList.contains(newFolder)) {
undecidedList.append(newFolder); undecidedList.append(newFolder);
journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, undecidedList); journal->setSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, undecidedList);
emit newSharedBigFolderDiscovered(newFolder); emit newBigFolderDiscovered(newFolder);
} }
} }

View file

@ -198,7 +198,7 @@ signals:
void syncFinished(const SyncResult &result); void syncFinished(const SyncResult &result);
void scheduleToSync(Folder*); void scheduleToSync(Folder*);
void progressInfo(const ProgressInfo& progress); void progressInfo(const ProgressInfo& progress);
void newSharedBigFolderDiscovered(const QString &); // A new folder bigger than the threshold was discovered void newBigFolderDiscovered(const QString &); // A new folder bigger than the threshold was discovered
public slots: public slots:
@ -253,7 +253,7 @@ private slots:
void slotEmitFinishedDelayed(); void slotEmitFinishedDelayed();
void watcherSlot(QString); void watcherSlot(QString);
void slotNewSharedBigFolderDiscovered(const QString &); void slotNewBigFolderDiscovered(const QString &);
private: private:
bool init(); bool init();

View file

@ -58,7 +58,7 @@ void FolderStatusModel::setAccountState(const AccountState* accountState)
connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection); connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection);
connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection); connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
connect(f, SIGNAL(newSharedBigFolderDiscovered(QString)), this, SIGNAL(dirtyChanged()), Qt::UniqueConnection); connect(f, SIGNAL(newBigFolderDiscovered(QString)), this, SIGNAL(dirtyChanged()), Qt::UniqueConnection);
} }
endResetModel(); endResetModel();

View file

@ -93,7 +93,7 @@ void GeneralSettings::loadMiscSettings()
_ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons());
_ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications());
_ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter());
auto newFolderLimit = cfgFile.newSharedFolderSizeLimit(); auto newFolderLimit = cfgFile.newBigFolderSizeLimit();
_ui->newFolderLimitCheckBox->setChecked(newFolderLimit.first); _ui->newFolderLimitCheckBox->setChecked(newFolderLimit.first);
_ui->newFolderLimitSpinBox->setValue(newFolderLimit.second); _ui->newFolderLimitSpinBox->setValue(newFolderLimit.second);
} }
@ -120,7 +120,7 @@ void GeneralSettings::saveMiscSettings()
Theme::instance()->setSystrayUseMonoIcons(isChecked); Theme::instance()->setSystrayUseMonoIcons(isChecked);
cfgFile.setCrashReporter(_ui->crashreporterCheckBox->isChecked()); cfgFile.setCrashReporter(_ui->crashreporterCheckBox->isChecked());
cfgFile.setNewSharedFolderSizeLimit(_ui->newFolderLimitCheckBox->isChecked(), cfgFile.setNewBigFolderSizeLimit(_ui->newFolderLimitCheckBox->isChecked(),
_ui->newFolderLimitSpinBox->value()); _ui->newFolderLimitSpinBox->value());
} }

View file

@ -58,7 +58,7 @@
<item> <item>
<widget class="QCheckBox" name="newFolderLimitCheckBox"> <widget class="QCheckBox" name="newFolderLimitCheckBox">
<property name="text"> <property name="text">
<string>Ask confirmation before downloading shared folders larger than</string> <string>Ask confirmation before downloading folders larger than</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>

View file

@ -63,8 +63,8 @@ static const char useDownloadLimitC[] = "BWLimit/useDownloadLimit";
static const char uploadLimitC[] = "BWLimit/uploadLimit"; static const char uploadLimitC[] = "BWLimit/uploadLimit";
static const char downloadLimitC[] = "BWLimit/downloadLimit"; static const char downloadLimitC[] = "BWLimit/downloadLimit";
static const char newSharedFolderSizeLimitC[] = "newSharedFolderSizeLimit"; static const char newBigFolderSizeLimitC[] = "newBigFolderSizeLimit";
static const char useNewSharedFolderSizeLimitC[] = "useNewSharedFolderSizeLimit"; static const char useNewBigFolderSizeLimitC[] = "useNewBigFolderSizeLimit";
static const char maxLogLinesC[] = "Logging/maxLogLines"; static const char maxLogLinesC[] = "Logging/maxLogLines";
@ -571,17 +571,17 @@ void ConfigFile::setDownloadLimit(int kbytes)
setValue(downloadLimitC, kbytes); setValue(downloadLimitC, kbytes);
} }
QPair<bool, quint64> ConfigFile::newSharedFolderSizeLimit() const QPair<bool, quint64> ConfigFile::newBigFolderSizeLimit() const
{ {
qint64 value = getValue(newSharedFolderSizeLimitC, QString(), 100).toLongLong(); qint64 value = getValue(newBigFolderSizeLimitC, QString(), 100).toLongLong();
bool use = value >= 0 && getValue(useNewSharedFolderSizeLimitC, QString(), true).toBool(); bool use = value >= 0 && getValue(useNewBigFolderSizeLimitC, QString(), true).toBool();
return qMakePair(use, quint64(qMax<qint64>(0, value))); return qMakePair(use, quint64(qMax<qint64>(0, value)));
} }
void ConfigFile::setNewSharedFolderSizeLimit(bool isChecked, quint64 mbytes) void ConfigFile::setNewBigFolderSizeLimit(bool isChecked, quint64 mbytes)
{ {
setValue(newSharedFolderSizeLimitC, mbytes); setValue(newBigFolderSizeLimitC, mbytes);
setValue(useNewSharedFolderSizeLimitC, isChecked); setValue(useNewBigFolderSizeLimitC, isChecked);
} }
bool ConfigFile::monoIcons() const bool ConfigFile::monoIcons() const

View file

@ -100,8 +100,8 @@ public:
void setUploadLimit(int kbytes); void setUploadLimit(int kbytes);
void setDownloadLimit(int kbytes); void setDownloadLimit(int kbytes);
/** [checked, size in MB] **/ /** [checked, size in MB] **/
QPair<bool, quint64> newSharedFolderSizeLimit() const; QPair<bool, quint64> newBigFolderSizeLimit() const;
void setNewSharedFolderSizeLimit(bool isChecked, quint64 mbytes); void setNewBigFolderSizeLimit(bool isChecked, quint64 mbytes);
static bool setConfDir(const QString &value); static bool setConfDir(const QString &value);

View file

@ -62,14 +62,14 @@ int DiscoveryJob::isInSelectiveSyncBlackListCallback(void *data, const char *pat
return static_cast<DiscoveryJob*>(data)->isInSelectiveSyncBlackList(QString::fromUtf8(path)); return static_cast<DiscoveryJob*>(data)->isInSelectiveSyncBlackList(QString::fromUtf8(path));
} }
bool DiscoveryJob::checkSelectiveSyncNewShare(const QString& path) bool DiscoveryJob::checkSelectiveSyncNewFolder(const QString& path)
{ {
// If this path or the parent is in the white list, then we do not block this file // If this path or the parent is in the white list, then we do not block this file
if (findPathInList(_selectiveSyncWhiteList, path)) { if (findPathInList(_selectiveSyncWhiteList, path)) {
return false; return false;
} }
if (_newSharedFolderSizeLimit < 0) { if (_newBigFolderSizeLimit < 0) {
// no limit, everything is allowed; // no limit, everything is allowed;
return false; return false;
} }
@ -83,10 +83,10 @@ bool DiscoveryJob::checkSelectiveSyncNewShare(const QString& path)
_vioWaitCondition.wait(&_vioMutex); _vioWaitCondition.wait(&_vioMutex);
} }
auto limit = _newSharedFolderSizeLimit; auto limit = _newBigFolderSizeLimit;
if (result > limit) { if (result > limit) {
// we tell the UI there is a new folder // we tell the UI there is a new folder
emit newSharedFolder(path); emit newBigFolder(path);
return true; return true;
} else { } else {
// it is not too big, put it in the white list (so we will not do more query for the children) // it is not too big, put it in the white list (so we will not do more query for the children)
@ -100,9 +100,9 @@ bool DiscoveryJob::checkSelectiveSyncNewShare(const QString& path)
} }
} }
int DiscoveryJob::checkSelectiveSyncNewShareCallback(void *data, const char *path) int DiscoveryJob::checkSelectiveSyncNewFolderCallback(void *data, const char *path)
{ {
return static_cast<DiscoveryJob*>(data)->checkSelectiveSyncNewShare(QString::fromUtf8(path)); return static_cast<DiscoveryJob*>(data)->checkSelectiveSyncNewFolder(QString::fromUtf8(path));
} }
@ -594,7 +594,7 @@ void DiscoveryJob::start() {
_csync_ctx->callbacks.update_callback_userdata = this; _csync_ctx->callbacks.update_callback_userdata = this;
_csync_ctx->callbacks.update_callback = update_job_update_callback; _csync_ctx->callbacks.update_callback = update_job_update_callback;
_csync_ctx->callbacks.checkSelectiveSyncBlackListHook = isInSelectiveSyncBlackListCallback; _csync_ctx->callbacks.checkSelectiveSyncBlackListHook = isInSelectiveSyncBlackListCallback;
_csync_ctx->callbacks.checkSelectiveSyncNewShareHook = checkSelectiveSyncNewShareCallback; _csync_ctx->callbacks.checkSelectiveSyncNewFolderHook = checkSelectiveSyncNewFolderCallback;
_csync_ctx->callbacks.remote_opendir_hook = remote_vio_opendir_hook; _csync_ctx->callbacks.remote_opendir_hook = remote_vio_opendir_hook;
_csync_ctx->callbacks.remote_readdir_hook = remote_vio_readdir_hook; _csync_ctx->callbacks.remote_readdir_hook = remote_vio_readdir_hook;
@ -607,7 +607,7 @@ void DiscoveryJob::start() {
_lastUpdateProgressCallbackCall.invalidate(); _lastUpdateProgressCallbackCall.invalidate();
int ret = csync_update(_csync_ctx); int ret = csync_update(_csync_ctx);
_csync_ctx->callbacks.checkSelectiveSyncNewShareHook = 0; _csync_ctx->callbacks.checkSelectiveSyncNewFolderHook = 0;
_csync_ctx->callbacks.checkSelectiveSyncBlackListHook = 0; _csync_ctx->callbacks.checkSelectiveSyncBlackListHook = 0;
_csync_ctx->callbacks.update_callback = 0; _csync_ctx->callbacks.update_callback = 0;
_csync_ctx->callbacks.update_callback_userdata = 0; _csync_ctx->callbacks.update_callback_userdata = 0;

View file

@ -161,8 +161,8 @@ class DiscoveryJob : public QObject {
*/ */
bool isInSelectiveSyncBlackList(const QString &path) const; bool isInSelectiveSyncBlackList(const QString &path) const;
static int isInSelectiveSyncBlackListCallback(void *, const char *); static int isInSelectiveSyncBlackListCallback(void *, const char *);
bool checkSelectiveSyncNewShare(const QString &path); bool checkSelectiveSyncNewFolder(const QString &path);
static int checkSelectiveSyncNewShareCallback(void*, const char*); static int checkSelectiveSyncNewFolderCallback(void*, const char*);
// Just for progress // Just for progress
static void update_job_update_callback (bool local, static void update_job_update_callback (bool local,
@ -182,7 +182,7 @@ class DiscoveryJob : public QObject {
public: public:
explicit DiscoveryJob(CSYNC *ctx, QObject* parent = 0) explicit DiscoveryJob(CSYNC *ctx, QObject* parent = 0)
: QObject(parent), _csync_ctx(ctx), _newSharedFolderSizeLimit(-1) { : QObject(parent), _csync_ctx(ctx), _newBigFolderSizeLimit(-1) {
// We need to forward the log property as csync uses thread local // We need to forward the log property as csync uses thread local
// and updates run in another thread // and updates run in another thread
_log_callback = csync_get_log_callback(); _log_callback = csync_get_log_callback();
@ -192,7 +192,7 @@ public:
QStringList _selectiveSyncBlackList; QStringList _selectiveSyncBlackList;
QStringList _selectiveSyncWhiteList; QStringList _selectiveSyncWhiteList;
qint64 _newSharedFolderSizeLimit; qint64 _newBigFolderSizeLimit;
Q_INVOKABLE void start(); Q_INVOKABLE void start();
signals: signals:
void finished(int result); void finished(int result);
@ -202,8 +202,8 @@ signals:
void doOpendirSignal(QString url, DiscoveryDirectoryResult*); void doOpendirSignal(QString url, DiscoveryDirectoryResult*);
void doGetSizeSignal(const QString &path, qint64 *result); void doGetSizeSignal(const QString &path, qint64 *result);
// A new shared folder was discovered and was not synced because of the confirmation feature // A new folder was discovered and was not synced because of the confirmation feature
void newSharedFolder(const QString &folder); void newBigFolder(const QString &folder);
}; };
} }

View file

@ -70,7 +70,7 @@ SyncEngine::SyncEngine(AccountPtr account, CSYNC *ctx, const QString& localPath,
, _hasRemoveFile(false) , _hasRemoveFile(false)
, _uploadLimit(0) , _uploadLimit(0)
, _downloadLimit(0) , _downloadLimit(0)
, _newSharedFolderSizeLimit(-1) , _newBigFolderSizeLimit(-1)
, _anotherSyncNeeded(false) , _anotherSyncNeeded(false)
{ {
qRegisterMetaType<SyncFileItem>("SyncFileItem"); qRegisterMetaType<SyncFileItem>("SyncFileItem");
@ -657,14 +657,14 @@ void SyncEngine::startSync()
discoveryJob->_selectiveSyncBlackList = selectiveSyncBlackList; discoveryJob->_selectiveSyncBlackList = selectiveSyncBlackList;
discoveryJob->_selectiveSyncWhiteList = discoveryJob->_selectiveSyncWhiteList =
_journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList); _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList);
discoveryJob->_newSharedFolderSizeLimit = _newSharedFolderSizeLimit; discoveryJob->_newBigFolderSizeLimit = _newBigFolderSizeLimit;
discoveryJob->moveToThread(&_thread); discoveryJob->moveToThread(&_thread);
connect(discoveryJob, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int))); connect(discoveryJob, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int)));
connect(discoveryJob, SIGNAL(folderDiscovered(bool,QString)), connect(discoveryJob, SIGNAL(folderDiscovered(bool,QString)),
this, SIGNAL(folderDiscovered(bool,QString))); this, SIGNAL(folderDiscovered(bool,QString)));
connect(discoveryJob, SIGNAL(newSharedFolder(QString)), connect(discoveryJob, SIGNAL(newBigFolder(QString)),
this, SIGNAL(newSharedFolder(QString))); this, SIGNAL(newBigFolder(QString)));
// This is used for the DiscoveryJob to be able to request the main thread/ // This is used for the DiscoveryJob to be able to request the main thread/

View file

@ -66,10 +66,10 @@ public:
/* Abort the sync. Called from the main thread */ /* Abort the sync. Called from the main thread */
void abort(); void abort();
/* Set the maximum size a shared folder can have without asking for confirmation /* Set the maximum size a folder can have without asking for confirmation
* -1 means infinite * -1 means infinite
*/ */
void setNewSharedFolderSizeLimit(qint64 limit) { _newSharedFolderSizeLimit = limit; } void setNewBigFolderSizeLimit(qint64 limit) { _newBigFolderSizeLimit = limit; }
Utility::StopWatch &stopWatch() { return _stopWatch; } Utility::StopWatch &stopWatch() { return _stopWatch; }
@ -116,8 +116,8 @@ signals:
void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel); void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel);
// A new shared folder was discovered and was not synced because of the confirmation feature // A new folder was discovered and was not synced because of the confirmation feature
void newSharedFolder(const QString &folder); void newBigFolder(const QString &folder);
private slots: private slots:
void slotRootEtagReceived(QString); void slotRootEtagReceived(QString);
@ -206,8 +206,8 @@ private:
int _uploadLimit; int _uploadLimit;
int _downloadLimit; int _downloadLimit;
/* maximum size a shared folder can have without asking for confirmation: -1 means infinite */ /* maximum size a folder can have without asking for confirmation: -1 means infinite */
qint64 _newSharedFolderSizeLimit; qint64 _newBigFolderSizeLimit;
// hash containing the permissions on the remote directory // hash containing the permissions on the remote directory
QHash<QString, QByteArray> _remotePerms; QHash<QString, QByteArray> _remotePerms;