Warn if we detect that all fles are about to be removed.

This commit is contained in:
Olivier Goffart 2013-06-08 15:40:45 +02:00
parent 76580840dd
commit d2579a7754
4 changed files with 38 additions and 0 deletions

View file

@ -191,6 +191,11 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
int re = 0;
if (file->instruction != CSYNC_INSTRUCTION_IGNORE
&& file->instruction != CSYNC_INSTRUCTION_REMOVE) {
_hasFiles = true;
}
switch(file->instruction) {
case CSYNC_INSTRUCTION_NONE:
case CSYNC_INSTRUCTION_IGNORE:
@ -327,6 +332,7 @@ void CSyncThread::startSync()
return;
}
_hasFiles = false;
bool walkOk = true;
if( csync_walk_local_tree(_csync_ctx, &treewalkLocal, 0) < 0 ) {
qDebug() << "Error in local treewalk.";
@ -336,6 +342,16 @@ void CSyncThread::startSync()
qDebug() << "Error in remote treewalk.";
}
if (!_hasFiles && !_syncedItems.isEmpty()) {
qDebug() << Q_FUNC_INFO << "All the files are going to be removed, asking the user";
bool cancel = true;
emit aboutToRemoveAllFiles(&cancel);
if (cancel) {
qDebug() << Q_FUNC_INFO << "Abort sync";
return;
}
}
if (_needsUpdate)
emit(started());

View file

@ -56,6 +56,8 @@ signals:
void finished();
void started();
void aboutToRemoveAllFiles(bool *cancel);
private:
void handleSyncError(CSYNC *ctx, const char *state);
static void progress(const char *remote_url,
@ -79,6 +81,8 @@ private:
CSYNC *_csync_ctx;
bool _needsUpdate;
bool _hasFiles; // true if there is at least one file that is not ignored or removed
friend class CSyncRunScopeHelper;
};
}

View file

@ -33,6 +33,7 @@
#include <QNetworkProxy>
#include <QNetworkAccessManager>
#include <QNetworkProxyFactory>
#include <QMessageBox>
namespace Mirall {
@ -290,6 +291,10 @@ void ownCloudFolder::startSync(const QStringList &pathList)
connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished()), Qt::QueuedConnection);
connect(_csync, SIGNAL(csyncError(QString)), SLOT(slotCSyncError(QString)), Qt::QueuedConnection);
connect(_csync, SIGNAL(csyncUnavailable()), SLOT(slotCsyncUnavailable()), Qt::QueuedConnection);
//blocking connection so the message box happens in this thread, but block the csync thread.
connect(_csync, SIGNAL(aboutToRemoveAllFiles(bool*)), SLOT(slotAboutToRemoveAllFiles(bool*)), Qt::BlockingQueuedConnection);
_thread->start();
QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection);
emit syncStarted();
@ -488,5 +493,17 @@ void ServerActionNotifier::slotSyncFinished(const SyncResult &result)
}
}
void ownCloudFolder::slotAboutToRemoveAllFiles(bool *cancel)
{
QMessageBox::StandardButton ret = QMessageBox::warning(0,
tr("All files removed"),
tr("The sync operation is about to remove all the file in the current folder."
"Do you want to continue and remove all the files?"),
QMessageBox::Ok| QMessageBox::Abort, QMessageBox::Ok);
*cancel = (ret == QMessageBox::Abort);
}
} // ns

View file

@ -77,6 +77,7 @@ public:
public slots:
void startSync();
void slotTerminateSync();
void slotAboutToRemoveAllFiles(bool*);
protected slots:
void slotLocalPathChanged( const QString& );