diff options
author | Klaas Freitag <freitag@owncloud.com> | 2013-11-25 19:16:33 +0400 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2013-11-25 19:18:07 +0400 |
commit | dc29046d618dece67c90f5a0b7a993689d95d60c (patch) | |
tree | 1d233667499284196a611fe7ee3a56e58c2633e1 | |
parent | 0c6dca25c4b6e424dc542b58bc2ba44b81169272 (diff) |
Add new progressProblem signal and slots.
Now the sync problems are handled differently than the sync progress
to ease error message handling and stuff.
-rw-r--r-- | src/mirall/csyncthread.cpp | 34 | ||||
-rw-r--r-- | src/mirall/csyncthread.h | 5 | ||||
-rw-r--r-- | src/mirall/folder.cpp | 30 | ||||
-rw-r--r-- | src/mirall/folder.h | 1 | ||||
-rw-r--r-- | src/mirall/owncloudpropagator.cpp | 75 | ||||
-rw-r--r-- | src/mirall/owncloudpropagator.h | 8 | ||||
-rw-r--r-- | src/mirall/progressdispatcher.cpp | 90 | ||||
-rw-r--r-- | src/mirall/progressdispatcher.h | 9 |
8 files changed, 153 insertions, 99 deletions
diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index f1c974924..d894a837d 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -225,6 +225,8 @@ bool CSyncThread::checkBlacklisting( SyncFileItem *item ) qDebug() << "Item is on blacklist: " << entry._file << "retries:" << entry._retryCount; item->_blacklistedInDb = true; item->_instruction = CSYNC_INSTRUCTION_IGNORE; + item->_errorString = tr("The item is not synced because it is on the blacklist."); + slotProgressProblem( Progress::SoftError, *item ); } } @@ -316,6 +318,8 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote ) case CSYNC_INSTRUCTION_CONFLICT: case CSYNC_INSTRUCTION_IGNORE: case CSYNC_INSTRUCTION_ERROR: + // + slotProgressProblem(Progress::SoftError, item ); dir = SyncFileItem::None; break; case CSYNC_INSTRUCTION_EVAL: @@ -474,6 +478,8 @@ void CSyncThread::startSync() return; } + slotProgress(Progress::StartSync, SyncFileItem(), 0, 0); + _progressInfo = Progress::Info(); _hasFiles = false; @@ -518,8 +524,8 @@ void CSyncThread::startSync() _journal, &_abortRequested)); connect(_propagator.data(), SIGNAL(completed(SyncFileItem)), this, SLOT(transferCompleted(SyncFileItem)), Qt::QueuedConnection); - connect(_propagator.data(), SIGNAL(progress(Progress::Kind,QString,quint64,quint64)), - this, SLOT(slotProgress(Progress::Kind,QString,quint64,quint64))); + connect(_propagator.data(), SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), + this, SLOT(slotProgress(Progress::Kind,SyncFileItem,quint64,quint64))); connect(_propagator.data(), SIGNAL(finished()), this, SLOT(slotFinished())); int downloadLimit = 0; @@ -537,7 +543,6 @@ void CSyncThread::startSync() } _propagator->_uploadLimit = uploadLimit; - slotProgress(Progress::StartSync, QString(), 0, 0); _propagator->start(_syncedItems); } @@ -573,18 +578,29 @@ void CSyncThread::slotFinished() csync_commit(_csync_ctx); qDebug() << "CSync run took " << _syncTime.elapsed() << " Milliseconds"; - slotProgress(Progress::EndSync,QString(), 0 , 0); + slotProgress(Progress::EndSync,SyncFileItem(), 0 , 0); emit finished(); _propagator.reset(0); _syncMutex.unlock(); thread()->quit(); } - -void CSyncThread::slotProgress(Progress::Kind kind, const QString &file, quint64 curr, quint64 total) +void CSyncThread::slotProgressProblem(Progress::Kind kind, const SyncFileItem& item) { - Progress::Info pInfo = _progressInfo; + Progress::SyncProblem problem; + problem.kind = kind; + problem.current_file = item._file; + problem.error_message = item._errorString; + problem.error_code = item._httpErrorCode; + problem.timestamp = QDateTime::currentDateTime(); + + // connected to something in folder. + emit transmissionProblem( problem ); +} + +void CSyncThread::slotProgress(Progress::Kind kind, const SyncFileItem& item, quint64 curr, quint64 total) +{ if( kind == Progress::StartSync ) { QMutexLocker lock(&_mutex); _currentFileNo = 0; @@ -597,8 +613,10 @@ void CSyncThread::slotProgress(Progress::Kind kind, const QString &file, quint64 _currentFileNo += 1; } + Progress::Info pInfo = _progressInfo; + pInfo.kind = kind; - pInfo.current_file = file; + pInfo.current_file = item._file; pInfo.file_size = total; pInfo.current_file_bytes = curr; pInfo.current_file_no = _currentFileNo; diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 8d76b18c2..b4ea714a6 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -68,6 +68,8 @@ signals: void treeWalkResult(const SyncFileItemVector&); void transmissionProgress( const Progress::Info& progress ); + void transmissionProblem( const Progress::SyncProblem& problem ); + void csyncStateDbFile( const QString& ); void wipeDb(); @@ -79,7 +81,8 @@ signals: private slots: void transferCompleted(const SyncFileItem& item); void slotFinished(); - void slotProgress(Progress::Kind kind, const QString& file, quint64, quint64); + void slotProgress(Progress::Kind kind, const SyncFileItem &item, quint64, quint64); + void slotProgressProblem(Progress::Kind kind, const SyncFileItem& item); private: void handleSyncError(CSYNC *ctx, const char *state); diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 9922b0ab2..a769bfa28 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -627,6 +627,7 @@ void Folder::startSync(const QStringList &pathList) connect(_csync, SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), Qt::BlockingQueuedConnection); connect(_csync, SIGNAL(transmissionProgress(Progress::Info)), this, SLOT(slotTransmissionProgress(Progress::Info))); + connect(_csync, SIGNAL(transmissionProblem(Progress::SyncProblem)), this, SLOT(slotTransmissionProblem(Progress::SyncProblem))); _thread->start(); _thread->setPriority(QThread::LowPriority); @@ -687,6 +688,32 @@ void Folder::slotCSyncFinished() emit syncFinished( _syncResult ); } +// the problem comes without a folder and the valid path set. Add that here +// and hand the result over to the progress dispatcher. +void Folder::slotTransmissionProblem( const Progress::SyncProblem& problem ) +{ + Progress::SyncProblem newProb = problem; + newProb.folder = alias(); + + if(newProb.current_file.startsWith(QLatin1String("ownclouds://")) || + newProb.current_file.startsWith(QLatin1String("owncloud://")) ) { + // rip off the whole ownCloud URL. + newProb.current_file.remove(Utility::toCSyncScheme(remoteUrl().toString())); + } + QString localPath = path(); + if( newProb.current_file.startsWith(localPath) ) { + // remove the local dir. + newProb.current_file = newProb.current_file.right( newProb.current_file.length() - localPath.length()); + } + + // Count all error conditions. + _syncResult.setWarnCount( _syncResult.warnCount()+1 ); + + ProgressDispatcher::instance()->setProgressProblem(alias(), newProb); +} + +// the progress comes without a folder and the valid path set. Add that here +// and hand the result over to the progress dispatcher. void Folder::slotTransmissionProgress(const Progress::Info& progress) { Progress::Info newInfo = progress; @@ -707,9 +734,6 @@ void Folder::slotTransmissionProgress(const Progress::Info& progress) if( newInfo.kind == Progress::StartSync ) { _syncResult.setWarnCount(0); } - if( newInfo.kind == Progress::Error ) { - _syncResult.setWarnCount( _syncResult.warnCount()+1 ); - } ProgressDispatcher::instance()->setProgressInfo(alias(), newInfo); } diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 37a2d46a4..6d30051af 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -174,6 +174,7 @@ private slots: void slotCSyncFinished(); void slotTransmissionProgress(const Progress::Info& progress); + void slotTransmissionProblem( const Progress::SyncProblem& problem ); void slotPollTimerTimeout(); void etagRetreived(const QString &); diff --git a/src/mirall/owncloudpropagator.cpp b/src/mirall/owncloudpropagator.cpp index 44d109589..c9152f582 100644 --- a/src/mirall/owncloudpropagator.cpp +++ b/src/mirall/owncloudpropagator.cpp @@ -267,7 +267,7 @@ private: PropagateUploadFile* that = reinterpret_cast<PropagateUploadFile*>(userdata); if (status == ne_status_sending && info->sr.total > 0) { - emit that->progress(Progress::Context, that->_item._file , + emit that->progress(Progress::Context, that->_item, that->_chunked_done + info->sr.progress, that->_chunked_total_size ? that->_chunked_total_size : info->sr.total ); @@ -281,7 +281,7 @@ private: void PropagateUploadFile::start() { - emit progress(Progress::StartUpload, _item._file, 0, _item._size); + emit progress(Progress::StartUpload, _item, 0, _item._size); QFile file(_propagator->_localDir + _item._file); if (!file.open(QIODevice::ReadOnly)) { @@ -352,39 +352,39 @@ void PropagateUploadFile::start() /* If the source file changed during submission, lets try again */ if( state == HBF_SOURCE_FILE_CHANGE ) { - if( attempts++ < 20 ) { /* FIXME: How often do we want to try? */ - qDebug("SOURCE file has changed during upload, retry #%d in two seconds!", attempts); - sleep(2); - continue; - } - // Still the file change error, but we tried a couple of times. - // Ignore this file for now. - // Lets remove the file from the server (at least if it is new) as it is different - // from our file here. - if( _item._instruction == CSYNC_INSTRUCTION_NEW ) { - QScopedPointer<char, QScopedPointerPodDeleter> uri( - ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8())); - - int rc = ne_delete(_propagator->_session, uri.data()); - qDebug() << "Remove the invalid file from server:" << rc; - } - - const QString errMsg = tr("Local file changed during sync, syncing once it arrived completely"); - done( SyncFileItem::SoftError, errMsg ); - emit progress(Progress::Error, _item._file, 0, - (quint64) "Local file changed during sync, syncing once it arrived completely"); // FIXME: Use errMsg - - return; + if( attempts++ < 20 ) { /* FIXME: How often do we want to try? */ + qDebug("SOURCE file has changed during upload, retry #%d in two seconds!", attempts); + sleep(2); + continue; + } + // Still the file change error, but we tried a couple of times. + // Ignore this file for now. + // Lets remove the file from the server (at least if it is new) as it is different + // from our file here. + if( _item._instruction == CSYNC_INSTRUCTION_NEW ) { + QScopedPointer<char, QScopedPointerPodDeleter> uri( + ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8())); + + int rc = ne_delete(_propagator->_session, uri.data()); + qDebug() << "Remove the invalid file from server:" << rc; + } + + const QString errMsg = tr("Local file changed during sync, syncing once it arrived completely"); + done( SyncFileItem::SoftError, errMsg ); + _item._errorString = errMsg; + emit progressProblem( Progress::SoftError, _item ); + return; } else if( state == HBF_USER_ABORTED ) { const QString errMsg = tr("Sync was aborted by user."); done( SyncFileItem::SoftError, errMsg); - emit progress(Progress::Error, _item._file, 0, - (quint64) "User terminated sync process!" ); // FIXME: Use errMsg + _item._errorString = errMsg; + emit progressProblem( Progress::SoftError, _item ); } else { + // Other HBF error conditions. // FIXME: find out the error class. _item._httpErrorCode = hbf_fail_http_code(trans.data()); done(SyncFileItem::NormalError, hbf_error_string(trans.data(), state)); - emit progress(Progress::EndUpload, _item._file, 0, _item._size); + emit progressProblem(Progress::NormalError, _item); } return; } @@ -401,7 +401,7 @@ void PropagateUploadFile::start() // Remove from the progress database: _propagator->_journal->setUploadInfo(_item._file, SyncJournalDb::UploadInfo()); _propagator->_journal->commit("upload file start"); - emit progress(Progress::EndUpload, _item._file, 0, _item._size); + emit progress(Progress::EndUpload, _item, 0, _item._size); done(SyncFileItem::Success); return; @@ -595,7 +595,7 @@ private: { PropagateDownloadFile* that = reinterpret_cast<PropagateDownloadFile*>(userdata); if (status == ne_status_recving && info->sr.total > 0) { - emit that->progress(Progress::Context, that->_item._file, info->sr.progress, info->sr.total ); + emit that->progress(Progress::Context, that->_item, info->sr.progress, info->sr.total ); that->limitBandwidth(info->sr.progress, that->_propagator->_downloadLimit); } } @@ -603,7 +603,7 @@ private: void PropagateDownloadFile::start() { - emit progress(Progress::StartDownload, _item._file, 0, _item._size); + emit progress(Progress::StartDownload, _item, 0, _item._size); QString tmpFileName; const SyncJournalDb::DownloadInfo progressInfo = _propagator->_journal->getDownloadInfo(_item._file); @@ -777,7 +777,7 @@ void PropagateDownloadFile::start() _propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn)); _propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo()); _propagator->_journal->commit("download file start2"); - emit progress(Progress::EndDownload, _item._file, 0, _item._size); + emit progress(Progress::EndDownload, _item, 0, _item._size); done(isConflict ? SyncFileItem::Conflict : SyncFileItem::Success); } @@ -785,7 +785,7 @@ DECLARE_JOB(PropagateLocalRename) void PropagateLocalRename::start() { - emit progress(Progress::StartRename, _item._file, 0, _item._size); + emit progress(Progress::StartRename, _item, 0, _item._size); if (_item._file != _item._renameTarget) { qDebug() << "MOVE " << _propagator->_localDir + _item._file << " => " << _propagator->_localDir + _item._renameTarget; QFile::rename(_propagator->_localDir + _item._file, _propagator->_localDir + _item._renameTarget); @@ -803,7 +803,7 @@ void PropagateLocalRename::start() _propagator->_journal->setFileRecord(record); _propagator->_journal->commit("localRename"); - emit progress(Progress::EndRename, _item._file, 0, _item._size); + emit progress(Progress::EndRename, _item, 0, _item._size); done(SyncFileItem::Success); } @@ -831,7 +831,7 @@ void PropagateRemoteRename::start() } return; } else { - emit progress(Progress::StartRename, _item._file, 0, _item._size); + emit progress(Progress::StartRename, _item, 0, _item._size); QScopedPointer<char, QScopedPointerPodDeleter> uri1(ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8())); QScopedPointer<char, QScopedPointerPodDeleter> uri2(ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8())); @@ -843,7 +843,7 @@ void PropagateRemoteRename::start() } updateMTimeAndETag(uri2.data(), _item._modtime); - emit progress(Progress::EndRename, _item._file, 0, _item._size); + emit progress(Progress::EndRename, _item, 0, _item._size); } @@ -996,7 +996,8 @@ void OwncloudPropagator::start(const SyncFileItemVector& _syncedItems) } connect(_rootJob.data(), SIGNAL(completed(SyncFileItem)), this, SIGNAL(completed(SyncFileItem))); - connect(_rootJob.data(), SIGNAL(progress(Progress::Kind,QString,quint64,quint64)), this, SIGNAL(progress(Progress::Kind,QString,quint64,quint64))); + connect(_rootJob.data(), SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), this, + SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64))); connect(_rootJob.data(), SIGNAL(finished(SyncFileItem::Status)), this, SIGNAL(finished())); _rootJob->start(); diff --git a/src/mirall/owncloudpropagator.h b/src/mirall/owncloudpropagator.h index 11c31aece..fed659533 100644 --- a/src/mirall/owncloudpropagator.h +++ b/src/mirall/owncloudpropagator.h @@ -43,7 +43,8 @@ public slots: signals: void finished(SyncFileItem::Status); void completed(const SyncFileItem &); - void progress(Progress::Kind, const QString &filename, quint64 bytes, quint64 total); + void progress(Progress::Kind, const SyncFileItem& item, quint64 bytes, quint64 total); + void progressProblem( Progress::Kind, const SyncFileItem& ); }; /* @@ -84,7 +85,7 @@ private slots: void startJob(PropagatorJob *next) { connect(next, SIGNAL(finished(SyncFileItem::Status)), this, SLOT(proceedNext(SyncFileItem::Status)), Qt::QueuedConnection); connect(next, SIGNAL(completed(SyncFileItem)), this, SIGNAL(completed(SyncFileItem))); - connect(next, SIGNAL(progress(Progress::Kind,QString,quint64,quint64)), this, SIGNAL(progress(Progress::Kind,QString,quint64,quint64))); + connect(next, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), this, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64))); next->start(); } @@ -170,7 +171,8 @@ public: signals: void completed(const SyncFileItem &); - void progress(Progress::Kind, const QString &filename, quint64 bytes, quint64 total); + void progress(Progress::Kind kind, const SyncFileItem&, quint64 bytes, quint64 total); + void progressProblem( Progress::Kind, const SyncFileItem& ); void finished(); }; diff --git a/src/mirall/progressdispatcher.cpp b/src/mirall/progressdispatcher.cpp index f5a23f6b8..f7aea4349 100644 --- a/src/mirall/progressdispatcher.cpp +++ b/src/mirall/progressdispatcher.cpp @@ -168,59 +168,57 @@ QList<Progress::SyncProblem> ProgressDispatcher::recentProblems(int count) return _recentProblems; } +void ProgressDispatcher::setProgressProblem(const QString& folder, const Progress::SyncProblem &problem) +{ + Q_ASSERT( Progress::isErrorKind(problem.kind)); + + _recentProblems.prepend( problem ); + if( _recentProblems.size() > _QueueSize ) { + _recentProblems.removeLast(); + } + emit progressSyncProblem( folder, problem ); +} + void ProgressDispatcher::setProgressInfo(const QString& folder, const Progress::Info& progress) { if( folder.isEmpty() ) { return; } - Progress::Info newProgress = progress; - - if( newProgress.kind == Progress::Error ) { - Progress::SyncProblem err; - err.folder = folder; - err.current_file = newProgress.current_file; - // its really - err.error_message = QString::fromLocal8Bit( (const char*)newProgress.file_size ); - err.error_code = newProgress.current_file_bytes; - err.timestamp = QDateTime::currentDateTime(); - - _recentProblems.prepend( err ); - if( _recentProblems.size() > _QueueSize ) { - _recentProblems.removeLast(); - } - emit progressSyncProblem( folder, err ); - } else { - if( newProgress.kind == Progress::StartSync ) { - _recentProblems.clear(); - _timer.start(); - } - if( newProgress.kind == Progress::EndSync ) { - newProgress.overall_current_bytes = newProgress.overall_transmission_size; - newProgress.current_file_no = newProgress.overall_file_count; - _currentAction.remove(newProgress.folder); - qint64 msecs = _timer.elapsed(); - - qDebug()<< "[PROGRESS] progressed " << newProgress.overall_transmission_size - << " bytes in " << newProgress.overall_file_count << " files" - << " in msec " << msecs; - } - if( newProgress.kind == Progress::EndDownload || - newProgress.kind == Progress::EndUpload || - newProgress.kind == Progress::EndDelete || - newProgress.kind == Progress::EndRename ) { - _recentChanges.prepend(newProgress); - if( _recentChanges.size() > _QueueSize ) { - _recentChanges.removeLast(); - } - } - // store the last real action to help clients that start during - // the Context-phase of an upload or download. - if( newProgress.kind != Progress::Context ) { - _currentAction[folder] = newProgress.kind; - } + Progress::Info newProgress(progress); + + Q_ASSERT( !Progress::isErrorKind(progress.kind)); - emit progressInfo( folder, newProgress ); + if( newProgress.kind == Progress::StartSync ) { + _recentProblems.clear(); + _timer.start(); + } + if( newProgress.kind == Progress::EndSync ) { + newProgress.overall_current_bytes = newProgress.overall_transmission_size; + newProgress.current_file_no = newProgress.overall_file_count; + _currentAction.remove(newProgress.folder); + qint64 msecs = _timer.elapsed(); + + qDebug()<< "[PROGRESS] progressed " << newProgress.overall_transmission_size + << " bytes in " << newProgress.overall_file_count << " files" + << " in msec " << msecs; + } + if( newProgress.kind == Progress::EndDownload || + newProgress.kind == Progress::EndUpload || + newProgress.kind == Progress::EndDelete || + newProgress.kind == Progress::EndRename ) { + _recentChanges.prepend(newProgress); + if( _recentChanges.size() > _QueueSize ) { + _recentChanges.removeLast(); + } + } + // store the last real action to help clients that start during + // the Context-phase of an upload or download. + if( newProgress.kind != Progress::Context ) { + _currentAction[folder] = newProgress.kind; } + + emit progressInfo( folder, newProgress ); + } Progress::Kind ProgressDispatcher::currentFolderContext( const QString& folder ) diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h index dbeab03f2..12a2dc123 100644 --- a/src/mirall/progressdispatcher.h +++ b/src/mirall/progressdispatcher.h @@ -69,15 +69,20 @@ namespace Progress }; struct SyncProblem { + Kind kind; QString folder; QString current_file; QString error_message; int error_code; QDateTime timestamp; + + SyncProblem() : kind(Invalid), error_code(0) {} }; QString asActionString( Kind ); QString asResultString( Kind ); + + bool isErrorKind( Kind ); } /** @@ -102,6 +107,7 @@ public: QList<Progress::SyncProblem> recentProblems(int count); Progress::Kind currentFolderContext( const QString& folder ); + signals: /** @brief Signals the progress of data transmission. @@ -115,7 +121,8 @@ signals: void progressSyncProblem( const QString& folder, const Progress::SyncProblem& problem ); protected: - void setProgressInfo(const QString &folder, const Progress::Info& progress); + void setProgressInfo(const QString& folder, const Progress::Info& progress); + void setProgressProblem( const QString& folder, const Progress::SyncProblem& problem); private: ProgressDispatcher(QObject* parent = 0); |