Skip to content

Commit

Permalink
Add support to update ProgressInfo item size.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedammar committed Jan 11, 2018
1 parent e7ef50a commit 9586121
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ void OwncloudPropagator::scheduleNextJobImpl()
}
}

void OwncloudPropagator::reportFileTotal(const SyncFileItem &item, quint64 newSize)
{
emit updateFileTotal(item, newSize);
}

void OwncloudPropagator::reportProgress(const SyncFileItem &item, quint64 bytes)
{
emit progress(item, bytes);
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class OwncloudPropagator : public QObject

void scheduleNextJob();
void reportProgress(const SyncFileItem &, quint64 bytes);
void reportFileTotal(const SyncFileItem &item, quint64 newSize);

void abort()
{
Expand Down Expand Up @@ -515,6 +516,7 @@ private slots:
void newItem(const SyncFileItemPtr &);
void itemCompleted(const SyncFileItemPtr &);
void progress(const SyncFileItem &, quint64 bytes);
void updateFileTotal(const SyncFileItem &, quint64 newSize);
void finished(bool success);

/** Emitted when propagation has problems with a locked file. */
Expand Down
18 changes: 17 additions & 1 deletion src/libsync/progressdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ void ProgressInfo::adjustTotalsForFile(const SyncFileItem &item)
}
}

void ProgressInfo::updateTotalsForFile(const SyncFileItem &item, quint64 newSize)
{
if (!shouldCountProgress(item)) {
return;
}

if (!_currentItems.contains(item._file)) {
_sizeProgress._total += newSize - item._size;
} else {
_sizeProgress._total += newSize - _currentItems[item._file]._progress._total;
}

setProgressItem(item, 0);
_currentItems[item._file]._progress._total = newSize;
}

quint64 ProgressInfo::totalFiles() const
{
return _fileProgress._total;
Expand Down Expand Up @@ -229,7 +245,7 @@ void ProgressInfo::setProgressComplete(const SyncFileItem &item)
_currentItems.remove(item._file);
_fileProgress.setCompleted(_fileProgress._completed + item._affectedItems);
if (ProgressInfo::isSizeDependent(item)) {
_totalSizeOfCompletedJobs += item._size;
_totalSizeOfCompletedJobs += _currentItems[item._file]._progress._total;
}
recomputeCompletedSize();
_lastCompletedItem = item;
Expand Down
13 changes: 13 additions & 0 deletions src/libsync/progressdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ class OWNCLOUDSYNC_EXPORT ProgressInfo : public QObject
*/
void adjustTotalsForFile(const SyncFileItem &item);

/**
* Update totals for item.
* adjustTotalsForFile is called during the treewalk phase to collect
* the initial total size and file count.
* updateTotalsForFile is called at most once per item during propagation
* to adjust them when new information has become available.
*
* Example: With delta-sync, the actual size of the download will only
* be known during propagation - this function adjusts the total size
* to account for it.
*/
void updateTotalsForFile(const SyncFileItem &item, quint64 newSize);

quint64 totalFiles() const;
quint64 completedFiles() const;

Expand Down
7 changes: 7 additions & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult)
this, &SyncEngine::slotItemCompleted);
connect(_propagator.data(), &OwncloudPropagator::progress,
this, &SyncEngine::slotProgress);
connect(_propagator.data(), &OwncloudPropagator::updateFileTotal,
this, &SyncEngine::updateFileTotal);
connect(_propagator.data(), &OwncloudPropagator::finished, this, &SyncEngine::slotFinished, Qt::QueuedConnection);
connect(_propagator.data(), &OwncloudPropagator::seenLockedFile, this, &SyncEngine::seenLockedFile);
connect(_propagator.data(), &OwncloudPropagator::touchedFile, this, &SyncEngine::slotAddTouchedFile);
Expand Down Expand Up @@ -1212,6 +1214,11 @@ void SyncEngine::slotProgress(const SyncFileItem &item, quint64 current)
emit transmissionProgress(*_progressInfo);
}

void SyncEngine::updateFileTotal(const SyncFileItem &item, quint64 newSize)
{
_progressInfo->updateTotalsForFile(item, newSize);
emit transmissionProgress(*_progressInfo);
}

/* Given a path on the remote, give the path as it is when the rename is done */
QString SyncEngine::adjustRenamedPath(const QString &original)
Expand Down
1 change: 1 addition & 0 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private slots:
void slotItemCompleted(const SyncFileItemPtr &item);
void slotFinished(bool success);
void slotProgress(const SyncFileItem &item, quint64 curent);
void updateFileTotal(const SyncFileItem &item, quint64 newSize);
void slotDiscoveryJobFinished(int updateResult);
void slotCleanPollsJobAborted(const QString &error);

Expand Down

0 comments on commit 9586121

Please sign in to comment.