Pass the SyncFileItem as SyncFileItemPtr in itemCompleted

This will allow us to keep a reference on the items in connected slots.
This commit is contained in:
Jocelyn Turcotte 2017-01-25 11:12:38 +01:00
parent a764d7eb86
commit 1fc5a76622
14 changed files with 64 additions and 62 deletions

View file

@ -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);
}

View file

@ -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 &);

View file

@ -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 {

View file

@ -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:

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -202,5 +202,6 @@ typedef QVector<SyncFileItemPtr> SyncFileItemVector;
}
Q_DECLARE_METATYPE(OCC::SyncFileItem)
Q_DECLARE_METATYPE(OCC::SyncFileItemPtr)
#endif // SYNCFILEITEM_H

View file

@ -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));
}
}

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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);