diff options
author | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-01-25 13:12:38 +0300 |
---|---|---|
committer | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-01-26 01:26:23 +0300 |
commit | 1fc5a76622c7e1811c296c9550884cf124f3e864 (patch) | |
tree | fed4f3d29a6546c53f6005b36c62ca31f83632a3 | |
parent | a764d7eb86b40315931e3a0c9fac20ef7a83c09c (diff) |
Pass the SyncFileItem as SyncFileItemPtr in itemCompleted
This will allow us to keep a reference on the items in connected slots.
-rw-r--r-- | src/gui/folder.cpp | 10 | ||||
-rw-r--r-- | src/gui/folder.h | 2 | ||||
-rw-r--r-- | src/gui/protocolwidget.cpp | 10 | ||||
-rw-r--r-- | src/gui/protocolwidget.h | 2 | ||||
-rw-r--r-- | src/libsync/owncloudpropagator.cpp | 6 | ||||
-rw-r--r-- | src/libsync/owncloudpropagator.h | 6 | ||||
-rw-r--r-- | src/libsync/progressdispatcher.h | 2 | ||||
-rw-r--r-- | src/libsync/syncengine.cpp | 17 | ||||
-rw-r--r-- | src/libsync/syncengine.h | 4 | ||||
-rw-r--r-- | src/libsync/syncfileitem.h | 1 | ||||
-rw-r--r-- | src/libsync/syncfilestatustracker.cpp | 32 | ||||
-rw-r--r-- | src/libsync/syncfilestatustracker.h | 2 | ||||
-rw-r--r-- | test/syncenginetestutils.h | 6 | ||||
-rw-r--r-- | test/testsyncengine.cpp | 26 |
14 files changed, 64 insertions, 62 deletions
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 2823d04b7..9d805be02 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -102,8 +102,8 @@ Folder::Folder(const FolderDefinition& definition, SLOT(slotAboutToRestoreBackup(bool*))); connect(_engine.data(), SIGNAL(folderDiscovered(bool,QString)), this, SLOT(slotFolderDiscovered(bool,QString))); connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo))); - connect(_engine.data(), SIGNAL(itemCompleted(const SyncFileItem &)), - this, SLOT(slotItemCompleted(const SyncFileItem &))); + connect(_engine.data(), SIGNAL(itemCompleted(const SyncFileItemPtr &)), + this, SLOT(slotItemCompleted(const SyncFileItemPtr &))); connect(_engine.data(), SIGNAL(newBigFolder(QString)), this, SLOT(slotNewBigFolderDiscovered(QString))); connect(_engine.data(), SIGNAL(seenLockedFile(QString)), FolderMan::instance(), SLOT(slotSyncOnceFileUnlocks(QString))); connect(_engine.data(), SIGNAL(aboutToPropagate(SyncFileItemVector&)), @@ -917,13 +917,13 @@ void Folder::slotTransmissionProgress(const ProgressInfo &pi) } // a item is completed: count the errors and forward to the ProgressDispatcher -void Folder::slotItemCompleted(const SyncFileItem &item) +void Folder::slotItemCompleted(const SyncFileItemPtr &item) { - if (Progress::isWarningKind(item._status)) { + if (Progress::isWarningKind(item->_status)) { // Count all error conditions. _syncResult.setWarnCount(_syncResult.warnCount()+1); } - _fileLog->logItem(item); + _fileLog->logItem(*item); emit ProgressDispatcher::instance()->itemCompleted(alias(), item); } diff --git a/src/gui/folder.h b/src/gui/folder.h index e220337e8..eb9e3ca75 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -280,7 +280,7 @@ private slots: void slotFolderDiscovered(bool local, QString folderName); void slotTransmissionProgress(const ProgressInfo& pi); - void slotItemCompleted(const SyncFileItem&); + void slotItemCompleted(const SyncFileItemPtr&); void slotRunEtagJob(); void etagRetreived(const QString &); diff --git a/src/gui/protocolwidget.cpp b/src/gui/protocolwidget.cpp index 6adf2fc54..8828d2fd6 100644 --- a/src/gui/protocolwidget.cpp +++ b/src/gui/protocolwidget.cpp @@ -44,8 +44,8 @@ ProtocolWidget::ProtocolWidget(QWidget *parent) : connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,ProgressInfo)), this, SLOT(slotProgressInfo(QString,ProgressInfo))); - connect(ProgressDispatcher::instance(), SIGNAL(itemCompleted(QString,SyncFileItem)), - this, SLOT(slotItemCompleted(QString,SyncFileItem))); + connect(ProgressDispatcher::instance(), SIGNAL(itemCompleted(QString,SyncFileItemPtr)), + this, SLOT(slotItemCompleted(QString,SyncFileItemPtr))); connect(_ui->_treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), SLOT(slotOpenFile(QTreeWidgetItem*,int))); @@ -221,11 +221,11 @@ void ProtocolWidget::slotProgressInfo( const QString& folder, const ProgressInfo } } -void ProtocolWidget::slotItemCompleted(const QString &folder, const SyncFileItem &item) +void ProtocolWidget::slotItemCompleted(const QString &folder, const SyncFileItemPtr &item) { - QTreeWidgetItem *line = createCompletedTreewidgetItem(folder, item); + QTreeWidgetItem *line = createCompletedTreewidgetItem(folder, *item); if(line) { - if( item.hasErrorStatus() ) { + if( item->hasErrorStatus() ) { _issueItemView->insertTopLevelItem(0, line); emit issueItemCountUpdated(_issueItemView->topLevelItemCount()); } else { diff --git a/src/gui/protocolwidget.h b/src/gui/protocolwidget.h index 9faf0dd48..de11bdcd0 100644 --- a/src/gui/protocolwidget.h +++ b/src/gui/protocolwidget.h @@ -52,7 +52,7 @@ public: public slots: void slotProgressInfo( const QString& folder, const ProgressInfo& progress ); - void slotItemCompleted( const QString& folder, const SyncFileItem& item); + void slotItemCompleted( const QString& folder, const SyncFileItemPtr& item); void slotOpenFile( QTreeWidgetItem* item, int ); protected: diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 6d87f53b7..22174df50 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -172,7 +172,7 @@ void PropagateItemJob::done(SyncFileItem::Status status, const QString &errorStr _item->_status = status; - emit itemCompleted(*_item); + emit itemCompleted(_item); emit finished(status); } @@ -403,8 +403,8 @@ void OwncloudPropagator::start(const SyncFileItemVector& items) _rootJob->append(it); } - connect(_rootJob.data(), SIGNAL(itemCompleted(const SyncFileItem &)), - this, SIGNAL(itemCompleted(const SyncFileItem &))); + connect(_rootJob.data(), SIGNAL(itemCompleted(const SyncFileItemPtr &)), + this, SIGNAL(itemCompleted(const SyncFileItemPtr &))); connect(_rootJob.data(), SIGNAL(progress(const SyncFileItem &,quint64)), this, SIGNAL(progress(const SyncFileItem &,quint64))); connect(_rootJob.data(), SIGNAL(finished(SyncFileItem::Status)), this, SLOT(emitFinished(SyncFileItem::Status))); connect(_rootJob.data(), SIGNAL(ready()), this, SLOT(scheduleNextJob()), Qt::QueuedConnection); diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index 70220d44c..766ecc7de 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -114,7 +114,7 @@ signals: /** * Emitted when one item has been completed within a job. */ - void itemCompleted(const SyncFileItem &); + void itemCompleted(const SyncFileItemPtr &); /** * Emitted when all the sub-jobs have been finished and @@ -231,7 +231,7 @@ private slots: bool possiblyRunNextJob(PropagatorJob *next) { if (next->_state == NotYetStarted) { connect(next, SIGNAL(finished(SyncFileItem::Status)), this, SLOT(slotSubJobFinished(SyncFileItem::Status)), Qt::QueuedConnection); - connect(next, SIGNAL(itemCompleted(const SyncFileItem &)), this, SIGNAL(itemCompleted(const SyncFileItem &))); + connect(next, SIGNAL(itemCompleted(const SyncFileItemPtr &)), this, SIGNAL(itemCompleted(const SyncFileItemPtr &))); connect(next, SIGNAL(progress(const SyncFileItem &,quint64)), this, SIGNAL(progress(const SyncFileItem &,quint64))); connect(next, SIGNAL(ready()), this, SIGNAL(ready())); _runningNow++; @@ -355,7 +355,7 @@ private slots: void scheduleNextJob(); signals: - void itemCompleted(const SyncFileItem &); + void itemCompleted(const SyncFileItemPtr &); void progress(const SyncFileItem&, quint64 bytes); void finished(bool success); diff --git a/src/libsync/progressdispatcher.h b/src/libsync/progressdispatcher.h index 49e29d14c..4571ed947 100644 --- a/src/libsync/progressdispatcher.h +++ b/src/libsync/progressdispatcher.h @@ -250,7 +250,7 @@ signals: /** * @brief: the item was completed by a job */ - void itemCompleted(const QString &folder, const SyncFileItem & item); + void itemCompleted(const QString &folder, const SyncFileItemPtr & item); protected: void setProgressInfo(const QString& folder, const ProgressInfo& progress); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 0460a9301..20535345e 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -77,6 +77,7 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath, , _anotherSyncNeeded(NoFollowUpSync) { qRegisterMetaType<SyncFileItem>("SyncFileItem"); + qRegisterMetaType<SyncFileItemPtr>("SyncFileItemPtr"); qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status"); qRegisterMetaType<SyncFileStatus>("SyncFileStatus"); qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector"); @@ -1004,8 +1005,8 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) _propagator = QSharedPointer<OwncloudPropagator>( new OwncloudPropagator (_account, _localPath, _remotePath, _journal)); - connect(_propagator.data(), SIGNAL(itemCompleted(const SyncFileItem &)), - this, SLOT(slotItemCompleted(const SyncFileItem &))); + connect(_propagator.data(), SIGNAL(itemCompleted(const SyncFileItemPtr &)), + this, SLOT(slotItemCompleted(const SyncFileItemPtr &))); connect(_propagator.data(), SIGNAL(progress(const SyncFileItem &,quint64)), this, SLOT(slotProgress(const SyncFileItem &,quint64))); connect(_propagator.data(), SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)), Qt::QueuedConnection); @@ -1061,15 +1062,15 @@ void SyncEngine::setNetworkLimits(int upload, int download) } } -void SyncEngine::slotItemCompleted(const SyncFileItem &item) +void SyncEngine::slotItemCompleted(const SyncFileItemPtr &item) { - const char * instruction_str = csync_instruction_str(item._instruction); - qDebug() << Q_FUNC_INFO << item._file << instruction_str << item._status << item._errorString; + const char * instruction_str = csync_instruction_str(item->_instruction); + qDebug() << Q_FUNC_INFO << item->_file << instruction_str << item->_status << item->_errorString; - _progressInfo->setProgressComplete(item); + _progressInfo->setProgressComplete(*item); - if (item._status == SyncFileItem::FatalError) { - emit csyncError(item._errorString); + if (item->_status == SyncFileItem::FatalError) { + emit csyncError(item->_errorString); } emit transmissionProgress(*_progressInfo); diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h index de4a03c3c..52f695a1a 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -121,7 +121,7 @@ signals: void aboutToPropagate(SyncFileItemVector&); // after each item completed by a job (successful or not) - void itemCompleted(const SyncFileItem&); + void itemCompleted(const SyncFileItemPtr&); // after sync is done void treeWalkResult(const SyncFileItemVector&); @@ -155,7 +155,7 @@ signals: private slots: void slotRootEtagReceived(const QString &); - void slotItemCompleted(const SyncFileItem& item); + void slotItemCompleted(const SyncFileItemPtr& item); void slotFinished(bool success); void slotProgress(const SyncFileItem& item, quint64 curent); void slotDiscoveryJobFinished(int updateResult); diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index 20c0bf005..414763aea 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -202,5 +202,6 @@ typedef QVector<SyncFileItemPtr> SyncFileItemVector; } Q_DECLARE_METATYPE(OCC::SyncFileItem) +Q_DECLARE_METATYPE(OCC::SyncFileItemPtr) #endif // SYNCFILEITEM_H diff --git a/src/libsync/syncfilestatustracker.cpp b/src/libsync/syncfilestatustracker.cpp index 23f97fa16..4179e3bf6 100644 --- a/src/libsync/syncfilestatustracker.cpp +++ b/src/libsync/syncfilestatustracker.cpp @@ -77,8 +77,8 @@ SyncFileStatusTracker::SyncFileStatusTracker(SyncEngine *syncEngine) { connect(syncEngine, SIGNAL(aboutToPropagate(SyncFileItemVector&)), SLOT(slotAboutToPropagate(SyncFileItemVector&))); - connect(syncEngine, SIGNAL(itemCompleted(const SyncFileItem&)), - SLOT(slotItemCompleted(const SyncFileItem&))); + connect(syncEngine, SIGNAL(itemCompleted(const SyncFileItemPtr&)), + SLOT(slotItemCompleted(const SyncFileItemPtr&))); connect(syncEngine, SIGNAL(finished(bool)), SLOT(slotSyncFinished())); connect(syncEngine, SIGNAL(started()), SLOT(slotSyncEngineRunningChanged())); connect(syncEngine, SIGNAL(finished(bool)), SLOT(slotSyncEngineRunningChanged())); @@ -223,28 +223,28 @@ void SyncFileStatusTracker::slotAboutToPropagate(SyncFileItemVector& items) } } -void SyncFileStatusTracker::slotItemCompleted(const SyncFileItem &item) +void SyncFileStatusTracker::slotItemCompleted(const SyncFileItemPtr &item) { // qDebug() << Q_FUNC_INFO << item.destination() << item._status << item._instruction; - if (showErrorInSocketApi(item)) { - _syncProblems[item._file] = SyncFileStatus::StatusError; - invalidateParentPaths(item.destination()); - } else if (showWarningInSocketApi(item)) { - _syncProblems[item._file] = SyncFileStatus::StatusWarning; + if (showErrorInSocketApi(*item)) { + _syncProblems[item->_file] = SyncFileStatus::StatusError; + invalidateParentPaths(item->destination()); + } else if (showWarningInSocketApi(*item)) { + _syncProblems[item->_file] = SyncFileStatus::StatusWarning; } else { - _syncProblems.erase(item._file); + _syncProblems.erase(item->_file); } - SharedFlag sharedFlag = item._remotePerm.contains("S") ? Shared : NotShared; - if (item._instruction != CSYNC_INSTRUCTION_NONE - && item._instruction != CSYNC_INSTRUCTION_UPDATE_METADATA - && item._instruction != CSYNC_INSTRUCTION_IGNORE - && item._instruction != CSYNC_INSTRUCTION_ERROR) { + SharedFlag sharedFlag = item->_remotePerm.contains("S") ? Shared : NotShared; + if (item->_instruction != CSYNC_INSTRUCTION_NONE + && item->_instruction != CSYNC_INSTRUCTION_UPDATE_METADATA + && item->_instruction != CSYNC_INSTRUCTION_IGNORE + && item->_instruction != CSYNC_INSTRUCTION_ERROR) { // decSyncCount calls *must* be symetric with incSyncCount calls in slotAboutToPropagate - decSyncCountAndEmitStatusChanged(item.destination(), sharedFlag); + decSyncCountAndEmitStatusChanged(item->destination(), sharedFlag); } else { - emit fileStatusChanged(getSystemDestination(item.destination()), resolveSyncAndErrorStatus(item.destination(), sharedFlag)); + emit fileStatusChanged(getSystemDestination(item->destination()), resolveSyncAndErrorStatus(item->destination(), sharedFlag)); } } diff --git a/src/libsync/syncfilestatustracker.h b/src/libsync/syncfilestatustracker.h index 4858944b4..015f80cc2 100644 --- a/src/libsync/syncfilestatustracker.h +++ b/src/libsync/syncfilestatustracker.h @@ -46,7 +46,7 @@ signals: private slots: void slotAboutToPropagate(SyncFileItemVector& items); - void slotItemCompleted(const SyncFileItem& item); + void slotItemCompleted(const SyncFileItemPtr& item); void slotSyncFinished(); void slotSyncEngineRunningChanged(); diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 76b74c15e..8fbe3d56d 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -818,15 +818,15 @@ public: } void execUntilItemCompleted(const QString &relativePath) { - QSignalSpy spy(_syncEngine.get(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy spy(_syncEngine.get(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); QElapsedTimer t; t.start(); while (t.elapsed() < 5000) { spy.clear(); QVERIFY(spy.wait()); for(const QList<QVariant> &args : spy) { - auto item = args[0].value<OCC::SyncFileItem>(); - if (item.destination() == relativePath) + auto item = args[0].value<OCC::SyncFileItemPtr>(); + if (item->destination() == relativePath) return; } } diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 7e9f42f54..03f8f1ea8 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -14,8 +14,8 @@ using namespace OCC; bool itemDidComplete(const QSignalSpy &spy, const QString &path) { for(const QList<QVariant> &args : spy) { - SyncFileItem item = args[0].value<SyncFileItem>(); - if (item.destination() == path) + auto item = args[0].value<SyncFileItemPtr>(); + if (item->destination() == path) return true; } return false; @@ -24,9 +24,9 @@ bool itemDidComplete(const QSignalSpy &spy, const QString &path) bool itemDidCompleteSuccessfully(const QSignalSpy &spy, const QString &path) { for(const QList<QVariant> &args : spy) { - SyncFileItem item = args[0].value<SyncFileItem>(); - if (item.destination() == path) - return item._status == SyncFileItem::Success; + auto item = args[0].value<SyncFileItemPtr>(); + if (item->destination() == path) + return item->_status == SyncFileItem::Success; } return false; } @@ -38,7 +38,7 @@ class TestSyncEngine : public QObject private slots: void testFileDownload() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.remoteModifier().insert("A/a0"); fakeFolder.syncOnce(); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a0")); @@ -47,7 +47,7 @@ private slots: void testFileUpload() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.localModifier().insert("A/a0"); fakeFolder.syncOnce(); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a0")); @@ -56,7 +56,7 @@ private slots: void testDirDownload() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.remoteModifier().mkdir("Y"); fakeFolder.remoteModifier().mkdir("Z"); fakeFolder.remoteModifier().insert("Z/d0"); @@ -69,7 +69,7 @@ private slots: void testDirUpload() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.localModifier().mkdir("Y"); fakeFolder.localModifier().mkdir("Z"); fakeFolder.localModifier().insert("Z/d0"); @@ -82,7 +82,7 @@ private slots: void testLocalDelete() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.remoteModifier().remove("A/a1"); fakeFolder.syncOnce(); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a1")); @@ -91,7 +91,7 @@ private slots: void testRemoteDelete() { FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.localModifier().remove("A/a1"); fakeFolder.syncOnce(); QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/a1")); @@ -107,7 +107,7 @@ private slots: // fakeFolder.syncOnce(); fakeFolder.syncOnce(); - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); // Touch the file without changing the content, shouldn't upload fakeFolder.localModifier().setContents("a1.eml", 'A'); // Change the content/size @@ -204,7 +204,7 @@ private slots: QCOMPARE(fakeFolder.currentLocalState(), remoteState); expectedServerState = fakeFolder.currentRemoteState(); - QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItem &))); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); fakeFolder.syncOnce(); // This sync should do nothing QCOMPARE(completeSpy.count(), 0); |