From 07ce6cfa7941116db95737fb948df0dff5169e89 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 16 May 2013 14:50:36 +0200 Subject: [PATCH] don't use member variable of the propagator --- src/mirall/csyncthread.cpp | 24 +++++++++++++----------- src/mirall/csyncthread.h | 4 +++- src/mirall/owncloudpropagator.cpp | 7 ++++++- src/mirall/owncloudpropagator.h | 13 +++++++------ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 39f206480..e04e6f30b 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -56,6 +56,7 @@ CSyncThread::CSyncThread(CSYNC *csync, const QString &localPath, const QString & _csync_ctx = csync; _mutex.unlock(); qRegisterMetaType("SyncFileItem"); + qRegisterMetaType("CSYNC_ERROR_CODE"); } CSyncThread::~CSyncThread() @@ -350,8 +351,8 @@ void CSyncThread::startSync() _progressDataBase.load(_localPath); _propagator.reset(new OwncloudPropagator (session, _localPath, _remotePath, &_progressDataBase)); - connect(_propagator.data(), SIGNAL(completed(SyncFileItem)), - this, SLOT(transferCompleted(SyncFileItem)), Qt::QueuedConnection); + connect(_propagator.data(), SIGNAL(completed(SyncFileItem, CSYNC_ERROR_CODE)), + this, SLOT(transferCompleted(SyncFileItem, CSYNC_ERROR_CODE)), Qt::QueuedConnection); _iterator = 0; startNextTransfer(); @@ -361,24 +362,25 @@ void CSyncThread::startSync() // } } -void CSyncThread::transferCompleted(const SyncFileItem &item) +void CSyncThread::transferCompleted(const SyncFileItem &item, CSYNC_ERROR_CODE error) { Action a; - a.instruction = _propagator->_instruction; + a.instruction = item._instruction; // if the propagator had an error for a file, put the error string into the synced item - if( _propagator->_errorCode != CSYNC_ERR_NONE + if( error != CSYNC_ERR_NONE || a.instruction == CSYNC_INSTRUCTION_ERROR) { - // search for the item in the starting from _iterator because it should be a bit before it. + // Search for the item in the starting from _iterator because it should be a bit before it. + // This works because SyncFileItem::operator== only compare the file name; int idx = _syncedItems.lastIndexOf(item, _iterator); if (idx >= 0) { _syncedItems[idx]._instruction = CSYNC_INSTRUCTION_ERROR; - _syncedItems[idx]._errorString = csyncErrorToString( _propagator->_errorCode ); - _syncedItems[idx]._errorDetail = _propagator->_errorString; - _syncedItems[idx]._httpCode = _propagator->_httpStatusCode; + _syncedItems[idx]._errorString = csyncErrorToString( error ); + _syncedItems[idx]._errorDetail = item._errorString; + _syncedItems[idx]._httpCode = item._httpCode; qDebug() << "File " << item._file << " propagator error " << _syncedItems[idx]._errorString - << "(" << _propagator->_errorString << ")"; + << "(" << item._errorString << ")"; } if (item._isDirectory && item._instruction == CSYNC_INSTRUCTION_REMOVE @@ -389,7 +391,7 @@ void CSyncThread::transferCompleted(const SyncFileItem &item) } } - a.etag = _propagator->_etag; + a.etag = item._etag; _performedActions.insert(item._originalFile, a); if (item._instruction == CSYNC_INSTRUCTION_RENAME) { diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 6087d0aa6..43da6b803 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -31,6 +31,8 @@ class QProcess; +Q_DECLARE_METATYPE(CSYNC_ERROR_CODE) + namespace Mirall { class OwncloudPropagator; @@ -70,7 +72,7 @@ signals: void started(); private slots: - void transferCompleted(const SyncFileItem &); + void transferCompleted(const SyncFileItem& item, CSYNC_ERROR_CODE error); void startNextTransfer(); private: diff --git a/src/mirall/owncloudpropagator.cpp b/src/mirall/owncloudpropagator.cpp index 952648252..31aa811c7 100644 --- a/src/mirall/owncloudpropagator.cpp +++ b/src/mirall/owncloudpropagator.cpp @@ -85,7 +85,12 @@ void OwncloudPropagator::propagate(const SyncFileItem &item) _instruction = item._instruction; break; } - emit completed(item); + SyncFileItem newItem = item; + newItem._instruction = _instruction; + newItem._errorDetail = _errorString; + newItem._httpCode = _httpStatusCode; + newItem._etag = _etag; + emit completed(newItem, _errorCode); } // compare two files with given filename and return true if they have the same content diff --git a/src/mirall/owncloudpropagator.h b/src/mirall/owncloudpropagator.h index cbc7fae6b..d9a072030 100644 --- a/src/mirall/owncloudpropagator.h +++ b/src/mirall/owncloudpropagator.h @@ -36,6 +36,11 @@ class OwncloudPropagator : public QObject { ne_session_s *_session; ProgressDatabase *_progressDb; + QString _errorString; + CSYNC_ERROR_CODE _errorCode; + int _httpStatusCode; + csync_instructions_e _instruction; + bool check_neon_session(); @@ -68,15 +73,11 @@ public: if (!remoteDir.endsWith(QChar('/'))) _remoteDir+='/'; } void propagate(const SyncFileItem &); - QString _errorString; - CSYNC_ERROR_CODE _errorCode; - int _httpStatusCode; - bool _hasFatalError; QByteArray _etag; - csync_instructions_e _instruction; + bool _hasFatalError; signals: - void completed(const SyncFileItem &); + void completed(const SyncFileItem &, CSYNC_ERROR_CODE); };