[Pkg-owncloud-commits] [owncloud-client] 141/333: Refactor the progress
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:45 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit aacc278583a783ad7c4f66bfef8ba9cf247a938f
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Fri Mar 14 13:03:16 2014 +0100
Refactor the progress
Consider that there might be several files processed at the same time
---
src/mirall/accountsettings.cpp | 175 +++++++++++++--------------------
src/mirall/accountsettings.h | 5 +-
src/mirall/csyncthread.cpp | 92 +++++++----------
src/mirall/csyncthread.h | 15 ++-
src/mirall/folder.cpp | 23 +----
src/mirall/folder.h | 2 +-
src/mirall/owncloudgui.cpp | 60 +++++------
src/mirall/owncloudpropagator.cpp | 12 +--
src/mirall/owncloudpropagator.h | 14 +--
src/mirall/progressdispatcher.cpp | 202 +++++++-------------------------------
src/mirall/progressdispatcher.h | 88 ++++++++++-------
src/mirall/propagator_legacy.cpp | 19 ++--
src/mirall/propagator_qnam.cpp | 30 +++++-
src/mirall/propagator_qnam.h | 8 +-
src/mirall/propagatorjobs.cpp | 12 +--
src/mirall/protocolwidget.cpp | 68 ++++---------
src/mirall/protocolwidget.h | 4 +-
src/mirall/settingsdialog.cpp | 4 +-
src/owncloudcmd/owncloudcmd.cpp | 12 +--
19 files changed, 301 insertions(+), 544 deletions(-)
diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp
index 22a854d..1762896 100644
--- a/src/mirall/accountsettings.cpp
+++ b/src/mirall/accountsettings.cpp
@@ -206,11 +206,9 @@ void AccountSettings::slotAddFolder( Folder *folder )
folderToModelItem( item, folder );
_model->appendRow( item );
// in order to update the enabled state of the "Sync now" button
- connect(folder, SIGNAL(syncStateChange()), this, SLOT(slotButtonsSetEnabled()), Qt::UniqueConnection);
+ connect(folder, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
}
-
-
void AccountSettings::slotButtonsSetEnabled()
{
QModelIndex selected = ui->_folderList->currentIndex();
@@ -556,126 +554,56 @@ void AccountSettings::slotProgressProblem(const QString& folder, const Progress:
void AccountSettings::slotSetProgress(const QString& folder, const Progress::Info &progress )
{
- // qDebug() << "================================> Progress for folder " << folder << " progress " << Progress::asResultString(progress.kind);
QStandardItem *item = itemForFolder( folder );
- qint64 prog1 = progress.current_file_bytes;
- qint64 prog2 = progress.file_size;
-
- if( item == NULL ) {
- return;
- }
-
- // Hotfix for a crash that I experienced in a very rare case/setup
- if (progress.kind == Mirall::Progress::Invalid) {
- qDebug() << "================================> INVALID Progress for folder " << folder;
- return;
- }
- if( (progress.kind == Progress::StartSync)
- && progress.overall_file_count == 0 ) {
- // do not show progress if nothing is transmitted.
- return;
- }
-
- QString itemFileName = shortenFilename(folder, progress.current_file);
- QString syncFileProgressString;
+ if( !item ) return;
- // stay with the previous kind-string for Context.
- if( progress.kind != Progress::Context ) {
- _kindContext = Progress::asActionString(progress.kind);
- } else {
- if( _kindContext.isEmpty() ) {
- // empty kind context means that the dialog was opened after the action
- // was started.
- Progress::Kind kind = ProgressDispatcher::instance()->currentFolderContext(progress.folder);
- if( kind != Progress::Invalid ) {
- _kindContext = Progress::asActionString(kind);
- }
+ // find the single item to display: This is going to be the bigger item, or the last completed
+ // item if no items are in progress.
+ SyncFileItem curItem = progress._lastCompletedItem;
+ qint64 curItemProgress = -1; // -1 means finished
+ quint64 biggerItemSize = -1;
+ foreach(const Progress::Info::ProgressItem &citm, progress._currentItems) {
+ if (curItemProgress == -1 || (Progress::isSizeDependent(citm._item._instruction)
+ && biggerItemSize < citm._item._size)) {
+ curItemProgress = citm._completedSize;
+ curItem = citm._item;
+ biggerItemSize = citm._item._size;
}
}
- QString kindString = _kindContext;
-
- switch( progress.kind ) {
- case Progress::StartSync:
- item->setData( QVariant(0), FolderStatusDelegate::WarningCount );
- break;
- case Progress::StartDownload:
- case Progress::StartUpload:
- case Progress::StartDelete:
- case Progress::StartRename:
- syncFileProgressString = tr("Start");
- if( _hideProgressTimers.contains(item) ) {
- // The timer is still running.
- QTimer *t = _hideProgressTimers.take(item);
- t->stop();
- t->deleteLater();
- }
- break;
- case Progress::Context:
- syncFileProgressString = tr("Currently");
- break;
- case Progress::EndDownload:
- case Progress::EndUpload:
- case Progress::EndDelete:
- case Progress::EndRename:
- break;
- case Progress::EndSync:
- syncFileProgressString = tr("Completely");
-
- // start a timer to stop the progress display
- QTimer *timer;
- if( _hideProgressTimers.contains(item) ) {
- timer = _hideProgressTimers[item];
- // there is already one timer running.
- } else {
- timer = new QTimer;
- connect(timer, SIGNAL(timeout()), this, SLOT(slotHideProgress()));
- timer->setSingleShot(true);
- _hideProgressTimers.insert(item, timer);
- }
- timer->start(5000);
- break;
- case Progress::Invalid:
- case Progress::Download:
- case Progress::Upload:
- case Progress::Inactive:
- case Progress::SoftError:
- case Progress::NormalError:
- case Progress::FatalError:
- break;
- case Progress::StartLocalUpdate:
- case Progress::EndLocalUpdate:
- case Progress::StartRemoteUpdate:
- case Progress::EndRemoteUpdate:
- // FIXME could be interesting to show this to the user
- break;
+ if (curItemProgress == -1) {
+ curItemProgress = curItem._size;
}
- QString fileProgressString;
- QString s1 = Utility::octetsToString( prog1 );
- QString s2 = Utility::octetsToString( prog2 );
+ QString itemFileName = shortenFilename(folder, curItem._file);
+ QString kindString = Progress::asActionString(curItem);
// switch on extra space.
item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace );
- if( progress.kind != Progress::EndSync ) {
- // Example text: "Currently uploading foobar.png (1MB of 2MB)"
- fileProgressString = tr("%1 %2 %3 (%4 of %5)").arg(syncFileProgressString).arg(kindString).
- arg(itemFileName).arg(s1).arg(s2);
+ QString fileProgressString;
+ if (Progress::isSizeDependent(curItem._instruction)) {
+ QString s1 = Utility::octetsToString( curItemProgress );
+ QString s2 = Utility::octetsToString( curItem._size );
+ //: Example text: "uploading foobar.png (1MB of 2MB)"
+ fileProgressString = tr("%1 %2 (%3 of %4)").arg(kindString, itemFileName, s1, s2);
} else {
- fileProgressString = tr("Completely finished.");
+ //: Example text: "uploading foobar.png"
+ fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
}
item->setData( fileProgressString,FolderStatusDelegate::SyncProgressItemString);
// overall progress
- s1 = Utility::octetsToString( progress.overall_current_bytes );
- s2 = Utility::octetsToString( progress.overall_transmission_size );
- QString overallSyncString = tr("%1 of %2, file %3 of %4").arg(s1).arg(s2)
- .arg(progress.current_file_no).arg(progress.overall_file_count);
+ quint64 completedSize = progress.completedSize();
+ quint64 currentFile = progress._completedFileCount + progress._currentItems.count();
+ QString s1 = Utility::octetsToString( completedSize );
+ QString s2 = Utility::octetsToString( progress._totalSize );
+ QString overallSyncString = tr("%1 of %2, file %3 of %4").arg(s1, s2)
+ .arg(currentFile).arg(progress._totalFileCount);
item->setData( overallSyncString, FolderStatusDelegate::SyncProgressOverallString );
int overallPercent = 0;
- if( progress.overall_transmission_size > 0 ) {
- overallPercent = qRound(double(progress.overall_current_bytes)/double(progress.overall_transmission_size) * 100.0);
+ if( progress._totalSize > 0 ) {
+ overallPercent = qRound(double(completedSize)/double(progress._totalSize) * 100.0);
}
item->setData( overallPercent, FolderStatusDelegate::SyncProgressOverallPercent);
}
@@ -697,10 +625,10 @@ void AccountSettings::slotHideProgress()
}
if( ok ) {
- item->setData( QVariant(false), FolderStatusDelegate::AddProgressSpace );
- item->setData( QVariant(QString::null), FolderStatusDelegate::SyncProgressOverallString );
- item->setData( QVariant(QString::null), FolderStatusDelegate::SyncProgressItemString );
- item->setData( 0, FolderStatusDelegate::SyncProgressOverallPercent );
+ item->setData( false, FolderStatusDelegate::AddProgressSpace );
+ item->setData( QString(), FolderStatusDelegate::SyncProgressOverallString );
+ item->setData( QString(), FolderStatusDelegate::SyncProgressItemString );
+ item->setData( 0, FolderStatusDelegate::SyncProgressOverallPercent );
}
_hideProgressTimers.remove(item);
break;
@@ -711,6 +639,35 @@ void AccountSettings::slotHideProgress()
send_timer->deleteLater();
}
+void AccountSettings::slotFolderSyncStateChange()
+{
+ slotButtonsSetEnabled();
+ Folder* folder = qobject_cast<Folder *>(sender());
+ if (!folder) return;
+
+ QStandardItem *item = itemForFolder( folder->alias() );
+ if( !item ) return;
+
+ SyncResult::Status state = folder->syncResult().status();
+ if (state == SyncResult::SyncPrepare) {
+ item->setData( QVariant(0), FolderStatusDelegate::WarningCount );
+ } else if (state == SyncResult::Success || state == SyncResult::Problem) {
+ // start a timer to stop the progress display
+ QTimer *timer;
+ if( _hideProgressTimers.contains(item) ) {
+ timer = _hideProgressTimers[item];
+ // there is already one timer running.
+ } else {
+ timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(slotHideProgress()));
+ timer->setSingleShot(true);
+ _hideProgressTimers.insert(item, timer);
+ }
+ timer->start(5000);
+ }
+}
+
+
void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
{
if( total > 0 ) {
diff --git a/src/mirall/accountsettings.h b/src/mirall/accountsettings.h
index daff6ae..f29752f 100644
--- a/src/mirall/accountsettings.h
+++ b/src/mirall/accountsettings.h
@@ -62,7 +62,7 @@ public slots:
void slotUpdateFolderState( Folder* );
void slotDoubleClicked( const QModelIndex& );
void slotFolderOpenAction( const QString& );
- void slotSetProgress(const QString&, const Progress::Info& progress);
+ void slotSetProgress(const QString& folder, const Progress::Info& progress);
void slotProgressProblem(const QString& folder, const Progress::SyncProblem& problem);
void slotButtonsSetEnabled();
@@ -95,10 +95,11 @@ private:
QStandardItemModel *_model;
QUrl _OCUrl;
QHash<QStandardItem*, QTimer*> _hideProgressTimers;
- QString _kindContext;
QStringList _generalErrors;
bool _wasDisabledBefore;
Account *_account;
+private slots:
+ void slotFolderSyncStateChange();
};
} // namespace Mirall
diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp
index b2104c3..c9c2b6d 100644
--- a/src/mirall/csyncthread.cpp
+++ b/src/mirall/csyncthread.cpp
@@ -57,7 +57,6 @@ void csyncLogCatcher(int /*verbosity*/,
QMutex CSyncThread::_syncMutex;
CSyncThread::CSyncThread(CSYNC *ctx, const QString& localPath, const QString& remoteURL, const QString& remotePath, Mirall::SyncJournalDb* journal)
- :_previousIndex(-1)
{
_localPath = localPath;
_remotePath = remotePath;
@@ -243,7 +242,7 @@ bool CSyncThread::checkBlacklisting( SyncFileItem *item )
// FIXME: put the error string into an .arg(..) later
item->_errorString = tr("The item is not synced because of previous errors:")
+ QLatin1String(" ")+ entry._errorString;
- slotProgress( Progress::SoftError, *item );
+ progressProblem( Progress::SoftError, *item );
}
}
@@ -321,8 +320,8 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
case CSYNC_INSTRUCTION_CONFLICT:
case CSYNC_INSTRUCTION_RENAME:
case CSYNC_INSTRUCTION_REMOVE:
- _progressInfo.overall_file_count++;
- _progressInfo.overall_transmission_size += file->size;
+ _progressInfo._totalFileCount++;
+ _progressInfo._totalSize += file->size;
//fall trough
default:
_needsUpdate = true;
@@ -357,7 +356,7 @@ int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
case CSYNC_INSTRUCTION_IGNORE:
case CSYNC_INSTRUCTION_ERROR:
//
- slotProgress(Progress::SoftError, item, 0, 0);
+ progressProblem(Progress::SoftError, item);
dir = SyncFileItem::None;
break;
case CSYNC_INSTRUCTION_EVAL:
@@ -417,21 +416,20 @@ void CSyncThread::handleSyncError(CSYNC *ctx, const char *state) {
void csyncthread_updater_progress_callback(CSYNC_PROGRESS *progress, void *userdata)
{
- Progress::Info pInfo;
+ Progress::Kind kind;
if (progress->kind == CSYNC_NOTIFY_START_LOCAL_UPDATE) {
- pInfo.kind = Progress::StartLocalUpdate;
+ kind = Progress::StartLocalUpdate;
} else if (progress->kind == CSYNC_NOTIFY_FINISHED_LOCAL_UPDATE) {
- pInfo.kind = Progress::EndLocalUpdate;
+ kind = Progress::EndLocalUpdate;
} else if (progress->kind == CSYNC_NOTIFY_START_REMOTE_UPDATE) {
- pInfo.kind = Progress::StartRemoteUpdate;
+ kind = Progress::StartRemoteUpdate;
} else if (progress->kind == CSYNC_NOTIFY_FINISHED_REMOTE_UPDATE) {
- pInfo.kind = Progress::EndRemoteUpdate;
+ kind = Progress::EndRemoteUpdate;
} else {
return; // FIXME, but most progress stuff should come from the new propagator
}
- pInfo.timestamp = QDateTime::currentDateTime();
CSyncThread *self = static_cast<CSyncThread*>(userdata);
- emit self->transmissionProgress( pInfo );
+ emit self->transmissionProgress( kind, self->_progressInfo );
}
void CSyncThread::startSync()
@@ -538,9 +536,9 @@ void CSyncThread::slotUpdateFinished(int updateResult)
return;
}
- slotProgress(Progress::StartSync, SyncFileItem(), 0, 0);
_progressInfo = Progress::Info();
+ emit transmissionProgress(Progress::StartSync, _progressInfo);
_hasFiles = false;
bool walkOk = true;
@@ -583,10 +581,10 @@ void CSyncThread::slotUpdateFinished(int updateResult)
_propagator.reset(new OwncloudPropagator (session, _localPath, _remoteUrl, _remotePath,
_journal, &_thread));
connect(_propagator.data(), SIGNAL(completed(SyncFileItem)),
- this, SLOT(transferCompleted(SyncFileItem)), Qt::QueuedConnection);
- connect(_propagator.data(), SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)),
- this, SLOT(slotProgress(Progress::Kind,SyncFileItem,quint64,quint64)));
- connect(_propagator.data(), SIGNAL(progressChanged(qint64)), this, SLOT(slotProgressChanged(qint64)));
+ this, SLOT(slotJobCompleted(SyncFileItem)));
+ connect(_propagator.data(), SIGNAL(progress(SyncFileItem,quint64)),
+ this, SLOT(slotProgress(SyncFileItem,quint64)));
+ connect(_propagator.data(), SIGNAL(adjustTotalTransmissionSize(qint64)), this, SLOT(slotAdjustTotalTransmissionSize(qint64)));
connect(_propagator.data(), SIGNAL(finished()), this, SLOT(slotFinished()));
setNetworkLimits();
@@ -618,7 +616,7 @@ void CSyncThread::setNetworkLimits()
qDebug() << " N------N Network Limits changed!";
}
-void CSyncThread::transferCompleted(const SyncFileItem &item)
+void CSyncThread::slotJobCompleted(const SyncFileItem &item)
{
qDebug() << Q_FUNC_INFO << item._file << item._status << item._errorString;
@@ -631,11 +629,21 @@ void CSyncThread::transferCompleted(const SyncFileItem &item)
} else {
qWarning() << Q_FUNC_INFO << "Could not find index in synced items!";
+
}
+ _progressInfo.setProgressComplete(item);
+
if (item._status == SyncFileItem::FatalError) {
+ progressProblem(Progress::FatalError, item);
emit csyncError(item._errorString);
+ } else if (item._status == SyncFileItem::NormalError) {
+ progressProblem(Progress::FatalError, item);
+ } else if (item._status == SyncFileItem::SoftError) {
+ progressProblem(Progress::SoftError, item);
}
+
+ emit transmissionProgress(Progress::Context, _progressInfo);
}
void CSyncThread::slotFinished()
@@ -650,7 +658,7 @@ void CSyncThread::slotFinished()
csync_commit(_csync_ctx);
qDebug() << "CSync run took " << _syncTime.elapsed() << " Milliseconds";
- slotProgress(Progress::EndSync,SyncFileItem(), 0 , 0);
+ emit transmissionProgress(Progress::EndSync, _progressInfo);
emit finished();
_propagator.reset(0);
_syncMutex.unlock();
@@ -671,50 +679,16 @@ void CSyncThread::progressProblem(Progress::Kind kind, const SyncFileItem& item)
emit transmissionProblem( problem );
}
-void CSyncThread::slotProgressChanged(qint64 change)
+void CSyncThread::slotProgress(const SyncFileItem& item, quint64 current)
{
- _progressInfo.overall_transmission_size += change;
+ _progressInfo.setProgressItem(item, current);
+ emit transmissionProgress(Progress::Context, _progressInfo);
}
-void CSyncThread::slotProgress(Progress::Kind kind, const SyncFileItem& item, quint64 curr, quint64 total)
-{
- if( Progress::isErrorKind(kind) ) {
- progressProblem(kind, item);
- return;
- }
- if( kind == Progress::StartSync ) {
- _currentFileNo = 0;
- _lastOverallBytes = 0;
- }
- if( kind == Progress::StartDelete ||
- kind == Progress::StartDownload ||
- kind == Progress::StartRename ||
- kind == Progress::StartUpload ) {
- int indx = _syncedItems.indexOf(item);
- if( _previousIndex != indx ) {
- _currentFileNo += 1;
- _previousIndex = indx;
- }
- curr = 0;
- }
-
- if( kind == Progress::EndUpload ||
- kind == Progress::EndDownload) {
- _lastOverallBytes += total;
- }
-
- Progress::Info pInfo(_progressInfo);
- pInfo.kind = kind;
- pInfo.current_file = item._file;
- pInfo.rename_target = item._renameTarget;
- pInfo.file_size = total;
- pInfo.current_file_bytes = curr;
- pInfo.current_file_no = _currentFileNo;
- pInfo.timestamp = QDateTime::currentDateTime();
- pInfo.overall_current_bytes = _lastOverallBytes + curr;
- // Connect to something in folder!
- emit transmissionProgress( pInfo );
+void CSyncThread::slotAdjustTotalTransmissionSize(qint64 change)
+{
+ _progressInfo._totalSize += change;
}
/* Given a path on the remote, give the path as it is when the rename is done */
diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h
index b3fede8..8d97d43 100644
--- a/src/mirall/csyncthread.h
+++ b/src/mirall/csyncthread.h
@@ -65,7 +65,7 @@ signals:
void csyncUnavailable();
void treeWalkResult(const SyncFileItemVector&);
- void transmissionProgress( const Progress::Info& progress );
+ void transmissionProgress( const Progress::Kind, const Progress::Info& progress );
void transmissionProblem( const Progress::SyncProblem& problem );
void csyncStateDbFile( const QString& );
@@ -77,10 +77,10 @@ signals:
void aboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel);
private slots:
- void transferCompleted(const SyncFileItem& item);
+ void slotJobCompleted(const SyncFileItem& item);
void slotFinished();
- void slotProgress(Progress::Kind kind, const SyncFileItem &item, quint64 curr = 0, quint64 total = 0);
- void slotProgressChanged(qint64 change);
+ void slotProgress(const SyncFileItem& item, quint64 curent);
+ void slotAdjustTotalTransmissionSize(qint64 change);
void slotUpdateFinished(int updateResult);
private:
@@ -109,19 +109,16 @@ private:
QHash <QString, QString> _seenFiles;
QThread _thread;
+ Progress::Info _progressInfo;
// maps the origin and the target of the folders that have been renamed
QHash<QString, QString> _renamedFolders;
QString adjustRenamedPath(const QString &original);
bool _hasFiles; // true if there is at least one file that is not ignored or removed
- Progress::Info _progressInfo;
+
int _downloadLimit;
int _uploadLimit;
- int _previousIndex; // store the index of the previous item in progress update slot
- qint64 _currentFileNo;
- qint64 _overallFileCount;
- quint64 _lastOverallBytes;
friend struct CSyncRunScopeHelper;
};
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index f8eccbe..0769825 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -610,7 +610,7 @@ void Folder::startSync(const QStringList &pathList)
//blocking connection so the message box happens in this thread, but block the csync thread.
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(transmissionProgress(Progress::Kind,Progress::Info)), this, SLOT(slotTransmissionProgress(Progress::Kind,Progress::Info)));
connect(_csync, SIGNAL(transmissionProblem(Progress::SyncProblem)), this, SLOT(slotTransmissionProblem(Progress::SyncProblem)));
QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection);
@@ -701,28 +701,13 @@ void Folder::slotTransmissionProblem( const Progress::SyncProblem& problem )
// 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)
+void Folder::slotTransmissionProgress(Progress::Kind kind, const Progress::Info &pi)
{
- Progress::Info newInfo = progress;
- newInfo.folder = alias();
-
- if(newInfo.current_file.startsWith(QLatin1String("ownclouds://")) ||
- newInfo.current_file.startsWith(QLatin1String("owncloud://")) ) {
- // rip off the whole ownCloud URL.
- newInfo.current_file.remove(Utility::toCSyncScheme(remoteUrl().toString()));
- }
- QString localPath = path();
- if( newInfo.current_file.startsWith(localPath) ) {
- // remove the local dir.
- newInfo.current_file = newInfo.current_file.right( newInfo.current_file.length() - localPath.length());
- }
-
// remember problems happening to set the correct Sync status in slot slotCSyncFinished.
- if( newInfo.kind == Progress::StartSync ) {
+ if( kind == Progress::StartSync ) {
_syncResult.setWarnCount(0);
}
-
- ProgressDispatcher::instance()->setProgressInfo(alias(), newInfo);
+ ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
}
void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel)
diff --git a/src/mirall/folder.h b/src/mirall/folder.h
index 01058e5..f2ecec6 100644
--- a/src/mirall/folder.h
+++ b/src/mirall/folder.h
@@ -174,7 +174,7 @@ private slots:
void slotCsyncUnavailable();
void slotCSyncFinished();
- void slotTransmissionProgress(const Progress::Info& progress);
+ void slotTransmissionProgress(Progress::Kind kind, const Progress::Info& pi);
void slotTransmissionProblem( const Progress::SyncProblem& problem );
void slotPollTimerTimeout();
diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp
index 8cd33d1..7ef12fd 100644
--- a/src/mirall/owncloudgui.cpp
+++ b/src/mirall/owncloudgui.cpp
@@ -286,9 +286,6 @@ void ownCloudGui::setupContextMenu()
_contextMenu->addAction(_actionLogin);
}
_contextMenu->addAction(_actionQuit);
-
- // Populate once at start
- slotRebuildRecentMenus();
}
@@ -380,28 +377,17 @@ void ownCloudGui::slotProgressSyncProblem(const QString& folder, const Progress:
// display a warn icon if warnings happend.
QIcon warnIcon(":/mirall/resources/warning-16");
_actionRecent->setIcon(warnIcon);
-
- slotRebuildRecentMenus();
}
void ownCloudGui::slotRebuildRecentMenus()
{
_recentActionsMenu->clear();
- const QList<Progress::Info>& progressInfoList = ProgressDispatcher::instance()->recentChangedItems(5);
-
- if( progressInfoList.size() == 0 ) {
- _recentActionsMenu->addAction(tr("No items synced recently"))->setEnabled(false);
- } else {
- QListIterator<Progress::Info> i(progressInfoList);
-
- while(i.hasNext()) {
- Progress::Info info = i.next();
- QString kindStr = Progress::asResultString(info);
- QString timeStr = info.timestamp.toString("hh:mm");
-
- QString actionText = tr("%1 (%2, %3)").arg(info.current_file).arg(kindStr).arg(timeStr);
- QAction *action = _recentActionsMenu->addAction( actionText );
-
+ // TODO
+ //_recentActionsMenu->addAction(tr("No items synced recently"))->setEnabled(false);
+/* QString kindStr = Progress::asResultString(info);
+ QString timeStr = info.timestamp.toString("hh:mm");
+ QString actionText = tr("%1 (%2, %3)").arg(info.current_file).arg(kindStr).arg(timeStr);
+ QAction *action = _recentActionsMenu->addAction( actionText );
Folder *folder = FolderMan::instance()->folder(info.folder);
if (folder) {
QString fullPath = folder->path() + '/' + info.current_file;
@@ -413,9 +399,11 @@ void ownCloudGui::slotRebuildRecentMenus()
}
}
}
- }
+ }*/
+
+
// add a more... entry.
- _recentActionsMenu->addSeparator();
+// _recentActionsMenu->addSeparator();
_recentActionsMenu->addAction(_actionRecent);
}
@@ -424,26 +412,22 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const Progress::Info
{
Q_UNUSED(folder);
- // shows an entry in the context menu.
- QString curAmount = Utility::octetsToString(progress.overall_current_bytes);
- QString totalAmount = Utility::octetsToString(progress.overall_transmission_size);
- _actionStatus->setText(tr("Syncing %1 of %2 (%3 of %4) ").arg(progress.current_file_no)
- .arg(progress.overall_file_count).arg(curAmount, totalAmount));
+ quint64 completedSize = progress.completedSize();
+ quint64 currentFile = progress._completedFileCount + progress._currentItems.count();
+ QString s1 = Utility::octetsToString( completedSize );
+ QString s2 = Utility::octetsToString( progress._totalSize );
- // wipe the problem list at start of sync.
- if( progress.kind == Progress::StartSync ) {
- _actionRecent->setIcon( QIcon() ); // Fixme: Set a "in-progress"-item eventually.
- }
+ _actionStatus->setText(tr("Syncing %1 of %2 (%3 of %4)")
+ .arg(currentFile).arg(progress._totalFileCount).arg(s1, s2));
- // If there was a change in the file list, redo the progress menu.
- if( progress.kind == Progress::EndDownload || progress.kind == Progress::EndUpload ||
- progress.kind == Progress::EndDelete || progress.kind == Progress::EndRename ) {
+ _actionRecent->setIcon( QIcon() ); // Fixme: Set a "in-progress"-item eventually.
+
+ if (!progress._lastCompletedItem.isEmpty()) {
slotRebuildRecentMenus();
- }
- if (progress.kind == Progress::EndSync) {
- slotRebuildRecentMenus(); // show errors.
- QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
+ if (progress._completedFileCount == progress._totalFileCount) {
+ QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
+ }
}
}
diff --git a/src/mirall/owncloudpropagator.cpp b/src/mirall/owncloudpropagator.cpp
index 062dd93..1a2c680 100644
--- a/src/mirall/owncloudpropagator.cpp
+++ b/src/mirall/owncloudpropagator.cpp
@@ -46,14 +46,10 @@ void PropagateItemJob::done(SyncFileItem::Status status, const QString &errorStr
switch( status ) {
case SyncFileItem::SoftError:
// do not blacklist in case of soft error.
- emit progress( Progress::SoftError, _item, 0, 0 );
break;
case SyncFileItem::FatalError:
case SyncFileItem::NormalError:
_propagator->_journal->updateBlacklistEntry( record );
- if( status == SyncFileItem::NormalError ) {
- emit progress( Progress::NormalError, _item, 0, 0 );
- }
break;
case SyncFileItem::Success:
if( _item._blacklistedInDb ) {
@@ -223,18 +219,12 @@ void OwncloudPropagator::start(const SyncFileItemVector& _syncedItems)
}
connect(_rootJob.data(), SIGNAL(completed(SyncFileItem)), this, SIGNAL(completed(SyncFileItem)));
- connect(_rootJob.data(), SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), this,
- SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)));
+ connect(_rootJob.data(), SIGNAL(progress(SyncFileItem,quint64)), this, SIGNAL(progress(SyncFileItem,quint64)));
connect(_rootJob.data(), SIGNAL(finished(SyncFileItem::Status)), this, SIGNAL(finished()));
QMetaObject::invokeMethod(_rootJob.data(), "start", Qt::QueuedConnection);
}
-void OwncloudPropagator::overallTransmissionSizeChanged(qint64 change)
-{
- emit progressChanged(change);
-}
-
bool OwncloudPropagator::isInSharedDirectory(const QString& file)
{
bool re = false;
diff --git a/src/mirall/owncloudpropagator.h b/src/mirall/owncloudpropagator.h
index 4ff6176..cda44c8 100644
--- a/src/mirall/owncloudpropagator.h
+++ b/src/mirall/owncloudpropagator.h
@@ -21,7 +21,6 @@
#include <qelapsedtimer.h>
#include "syncfileitem.h"
-#include "progressdispatcher.h"
struct hbf_transfer_s;
struct ne_session_s;
@@ -67,7 +66,7 @@ signals:
*/
void ready();
- void progress(Progress::Kind, const SyncFileItem& item, quint64 bytes, quint64 total);
+ void progress(const SyncFileItem& item, quint64 bytes);
};
@@ -115,7 +114,7 @@ private slots:
void startJob(PropagatorJob *next) {
connect(next, SIGNAL(finished(SyncFileItem::Status)), this, SLOT(slotSubJobFinished(SyncFileItem::Status)), Qt::QueuedConnection);
connect(next, SIGNAL(completed(SyncFileItem)), this, SIGNAL(completed(SyncFileItem)));
- connect(next, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)), this, SIGNAL(progress(Progress::Kind,SyncFileItem,quint64,quint64)));
+ connect(next, SIGNAL(progress(SyncFileItem,quint64)), this, SIGNAL(progress(SyncFileItem,quint64)));
connect(next, SIGNAL(ready()), this, SLOT(slotSubJobReady()));
_runningNow++;
QMetaObject::invokeMethod(next, "start", Qt::QueuedConnection);
@@ -212,7 +211,6 @@ public:
/* The number of currently active jobs */
int _activeJobs;
- void overallTransmissionSizeChanged( qint64 change );
bool isInSharedDirectory(const QString& file);
@@ -227,9 +225,13 @@ public:
signals:
void completed(const SyncFileItem &);
- void progress(Progress::Kind kind, const SyncFileItem&, quint64 bytes, quint64 total);
- void progressChanged(qint64 change);
+ void progress(const SyncFileItem&, quint64 bytes);
void finished();
+ /**
+ * Called when we detect that the total number of bytes changes (because a download or upload
+ * turns out to be bigger or smaller than what was initially computed in the update phase
+ */
+ void adjustTotalTransmissionSize( qint64 adjust );
};
diff --git a/src/mirall/progressdispatcher.cpp b/src/mirall/progressdispatcher.cpp
index a0e52b3..1c054db 100644
--- a/src/mirall/progressdispatcher.cpp
+++ b/src/mirall/progressdispatcher.cpp
@@ -21,117 +21,45 @@
namespace Mirall {
ProgressDispatcher* ProgressDispatcher::_instance = 0;
-QString Progress::asResultString( const Progress::Info& progress)
+
+QString Progress::asResultString( const SyncFileItem& item)
{
- QString re;
-
- switch(progress.kind) {
- case Download:
- case EndDownload:
- re = QCoreApplication::translate( "progress", "Download");
- break;
- case Upload:
- re = QCoreApplication::translate( "progress", "Upload");
- break;
- case Context:
- re = QCoreApplication::translate( "progress", "Context" );
- break;
- case Inactive:
- re = QCoreApplication::translate( "progress", "Inactive");
- break;
- case StartDownload:
- re = QCoreApplication::translate( "progress", "Download");
- break;
- case StartUpload:
- case EndUpload:
- re = QCoreApplication::translate( "progress", "Upload");
- break;
- case StartSync:
- re = QCoreApplication::translate( "progress", "Start");
- break;
- case EndSync:
- re = QCoreApplication::translate( "progress", "Finished");
- break;
- case StartDelete:
- re = QCoreApplication::translate( "progress", "For deletion");
- break;
- case EndDelete:
- re = QCoreApplication::translate( "progress", "deleted");
- break;
- case StartRename:
- re = QCoreApplication::translate( "progress", "Moved to %1").arg(progress.rename_target);
- break;
- case EndRename:
- re = QCoreApplication::translate( "progress", "Moved to %1").arg(progress.rename_target);
- break;
- case StartLocalUpdate:
- case EndLocalUpdate:
- case StartRemoteUpdate:
- case EndRemoteUpdate:
- break; // FIXME
- default:
- Q_ASSERT(false);
+ switch(item._instruction) {
+ case CSYNC_INSTRUCTION_CONFLICT:
+ case CSYNC_INSTRUCTION_SYNC:
+ case CSYNC_INSTRUCTION_NEW:
+ if (item._dir == SyncFileItem::Down)
+ return QCoreApplication::translate( "progress", "Downloaded");
+ else
+ return QCoreApplication::translate( "progress", "Uploaded");
+ case CSYNC_INSTRUCTION_REMOVE:
+ return QCoreApplication::translate( "progress", "Deleted");
+ case CSYNC_INSTRUCTION_EVAL_RENAME:
+ return QCoreApplication::translate( "progress", "Moved to %1").arg(item._renameTarget);
+ default:
+ // Should normaly not happen
+ return QCoreApplication::translate( "progress", "Unknown");
}
- return re;
-
}
-QString Progress::asActionString( Kind kind )
+QString Progress::asActionString( const SyncFileItem &item )
{
- QString re;
-
- switch(kind) {
- case Download:
- re = QCoreApplication::translate( "progress", "downloading");
- break;
- case Upload:
- re = QCoreApplication::translate( "progress", "uploading");
- break;
- case Context:
- re = QCoreApplication::translate( "progress", "Context");
- break;
- case Inactive:
- re = QCoreApplication::translate( "progress", "inactive");
- break;
- case StartDownload:
- re = QCoreApplication::translate( "progress", "downloading");
- break;
- case StartUpload:
- re = QCoreApplication::translate( "progress", "uploading");
- break;
- case EndDownload:
- re = QCoreApplication::translate( "progress", "downloading");
- break;
- case EndUpload:
- re = QCoreApplication::translate( "progress", "uploading");
- break;
- case StartSync:
- re = QCoreApplication::translate( "progress", "starting");
- break;
- case EndSync:
- re = QCoreApplication::translate( "progress", "finished");
- break;
- case StartDelete:
- re = QCoreApplication::translate( "progress", "delete");
- break;
- case EndDelete:
- re = QCoreApplication::translate( "progress", "deleted");
- break;
- case StartRename:
- re = QCoreApplication::translate( "progress", "move");
- break;
- case EndRename:
- re = QCoreApplication::translate( "progress", "moved");
- break;
- case StartLocalUpdate:
- case EndLocalUpdate:
- case StartRemoteUpdate:
- case EndRemoteUpdate:
- break; // FIXME
+ switch(item._instruction) {
+ case CSYNC_INSTRUCTION_CONFLICT:
+ case CSYNC_INSTRUCTION_SYNC:
+ case CSYNC_INSTRUCTION_NEW:
+ if (item._dir == SyncFileItem::Down)
+ return QCoreApplication::translate( "progress", "downloading");
+ else
+ return QCoreApplication::translate( "progress", "uploading");
+ case CSYNC_INSTRUCTION_REMOVE:
+ return QCoreApplication::translate( "progress", "deleting");
+ case CSYNC_INSTRUCTION_EVAL_RENAME:
+ return QCoreApplication::translate( "progress", "moving");
default:
- Q_ASSERT(false);
+ // Should normaly not happen
+ return QCoreApplication::translate( "progress", "processing");
}
- return re;
}
bool Progress::isErrorKind( Kind kind )
@@ -151,8 +79,7 @@ ProgressDispatcher* ProgressDispatcher::instance() {
}
ProgressDispatcher::ProgressDispatcher(QObject *parent) :
- QObject(parent),
- _QueueSize(50)
+ QObject(parent)
{
}
@@ -162,30 +89,10 @@ ProgressDispatcher::~ProgressDispatcher()
}
-QList<Progress::Info> ProgressDispatcher::recentChangedItems(int count)
-{
- if( count > 0 ) {
- return _recentChanges.mid(0, count);
- }
- return _recentChanges;
-}
-
-QList<Progress::SyncProblem> ProgressDispatcher::recentProblems(int count)
-{
- if( count > 0 ) {
- return _recentProblems.mid(0, 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 );
}
@@ -194,49 +101,8 @@ void ProgressDispatcher::setProgressInfo(const QString& folder, const Progress::
if( folder.isEmpty() ) {
return;
}
- Progress::Info newProgress(progress);
-
- Q_ASSERT( !Progress::isErrorKind(progress.kind));
-
- 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 );
-
+ emit progressInfo( folder, progress );
}
-Progress::Kind ProgressDispatcher::currentFolderContext( const QString& folder )
-{
- if( _currentAction.contains(folder)) {
- return _currentAction[folder];
- }
- return Progress::Invalid;
-}
}
diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h
index 6a38b6d..ec1b74d 100644
--- a/src/mirall/progressdispatcher.h
+++ b/src/mirall/progressdispatcher.h
@@ -19,15 +19,62 @@
#include <QTime>
#include <QQueue>
#include <QElapsedTimer>
+#include "syncfileitem.h"
namespace Mirall {
-
/**
* @brief The FolderScheduler class schedules folders for sync
*/
namespace Progress
{
+ /** Return true is the size need to be taken in account in the total amount of time */
+ inline bool isSizeDependent(csync_instructions_e instruction) {
+ return instruction == CSYNC_INSTRUCTION_CONFLICT || instruction == CSYNC_INSTRUCTION_SYNC
+ || instruction == CSYNC_INSTRUCTION_NEW;
+ }
+
+
+ struct Info {
+ Info() : _totalFileCount(0), _totalSize(0), _completedFileCount(0), _completedSize(0) {}
+
+ quint64 _totalFileCount;
+ quint64 _totalSize;
+ quint64 _completedFileCount;
+ quint64 _completedSize;
+
+ struct ProgressItem {
+ ProgressItem() : _completedSize(0) {}
+ SyncFileItem _item;
+ quint64 _completedSize;
+ };
+ QHash<QString, ProgressItem> _currentItems;
+ SyncFileItem _lastCompletedItem;
+
+ void setProgressComplete(const SyncFileItem &item) {
+ _currentItems.remove(item._file);
+ if (Progress::isSizeDependent(item._instruction)) {
+ _completedSize += item._size;
+ }
+ _completedFileCount++;
+ _lastCompletedItem = item;
+ }
+ void setProgressItem(const SyncFileItem &item, quint64 size) {
+ _currentItems[item._file]._item = item;
+ _currentItems[item._file]._completedSize = size;
+ _lastCompletedItem = SyncFileItem();
+ }
+
+ quint64 completedSize() const {
+ quint64 r = _completedSize;
+ foreach(const ProgressItem &i, _currentItems) {
+ r += i._completedSize;
+ }
+ return r;
+ }
+ };
+
+
enum Kind {
Invalid,
StartSync,
@@ -53,27 +100,6 @@ namespace Progress
EndRemoteUpdate
};
- struct Info {
- Kind kind;
- QString folder;
- QString current_file;
- QString rename_target;
-
- qint64 file_size;
- qint64 current_file_bytes;
-
- qint64 overall_file_count;
- qint64 current_file_no;
- qint64 overall_transmission_size;
- qint64 overall_current_bytes;
-
- QDateTime timestamp;
-
- Info() : kind(Invalid), file_size(0), current_file_bytes(0),
- overall_file_count(0), current_file_no(0),
- overall_transmission_size(0), overall_current_bytes(0) { }
- };
-
struct SyncProblem {
Kind kind;
QString folder;
@@ -85,10 +111,11 @@ namespace Progress
SyncProblem() : kind(Invalid), error_code(0) {}
};
- QString asActionString( Kind );
- QString asResultString( const Progress::Info& progress );
+ QString asActionString( const SyncFileItem& item );
+ QString asResultString( const SyncFileItem& item );
bool isErrorKind( Kind );
+
}
/**
@@ -109,20 +136,14 @@ public:
static ProgressDispatcher* instance();
~ProgressDispatcher();
- QList<Progress::Info> recentChangedItems(int count);
- QList<Progress::SyncProblem> recentProblems(int count);
-
- Progress::Kind currentFolderContext( const QString& folder );
-
signals:
/**
@brief Signals the progress of data transmission.
@param[out] folder The folder which is being processed
- @param[out] newProgress A struct with all progress info.
+ @param[out] progress A struct with all progress info.
*/
-
void progressInfo( const QString& folder, const Progress::Info& progress );
void progressSyncProblem( const QString& folder, const Progress::SyncProblem& problem );
@@ -132,11 +153,6 @@ protected:
private:
ProgressDispatcher(QObject* parent = 0);
- const int _QueueSize;
- QList<Progress::Info> _recentChanges;
- QList<Progress::SyncProblem> _recentProblems;
-
- QHash<QString, Progress::Kind> _currentAction;
QElapsedTimer _timer;
static ProgressDispatcher* _instance;
diff --git a/src/mirall/propagator_legacy.cpp b/src/mirall/propagator_legacy.cpp
index 05ea4ea..0884c9b 100644
--- a/src/mirall/propagator_legacy.cpp
+++ b/src/mirall/propagator_legacy.cpp
@@ -84,14 +84,15 @@ void PropagateUploadFileLegacy::start()
// couple of seconds and retries.
if(_previousFileSize > 0) {
qDebug() << "File size changed underway: " << trans->stat_size - _previousFileSize;
- // Report the change of the overall transmission size to the propagator
- _propagator->overallTransmissionSizeChanged(qint64(trans->stat_size - _previousFileSize));
+ // Report the change of the overall transmission size to the propagator (queued connection because we are in a thread)
+ QMetaObject::invokeMethod(_propagator, "adjustTotalTransmissionSize", Qt::QueuedConnection,
+ Q_ARG(qint64, trans->stat_size - _previousFileSize));
// update the item's values to the current from trans. hbf_splitlist does a stat
_item._size = trans->stat_size;
_item._modtime = trans->modtime;
}
- emit progress(Progress::StartUpload, _item, 0, trans->stat_size);
+ emit progress(_item, 0);
if (progressInfo._valid) {
if (Utility::qDateTimeToTime_t(progressInfo._modtime) == _item._modtime) {
@@ -209,9 +210,6 @@ void PropagateUploadFileLegacy::start()
return;
}
-
-
- emit progress(Progress::EndUpload, _item, _item._size, _item._size);
done(SyncFileItem::Success);
return;
@@ -240,9 +238,7 @@ void PropagateUploadFileLegacy::notify_status_cb(void* userdata, ne_session_stat
PropagateUploadFileLegacy* that = reinterpret_cast<PropagateUploadFileLegacy*>(userdata);
if (status == ne_status_sending && info->sr.total > 0) {
- emit that->progress(Progress::Context, that->_item,
- that->_chunked_done + info->sr.progress,
- that->_chunked_total_size ? that->_chunked_total_size : info->sr.total );
+ emit that->progress(that->_item, that->_chunked_done + info->sr.progress);
that->limitBandwidth(that->_chunked_done + info->sr.progress, that->_propagator->_uploadLimit.fetchAndAddAcquire(0));
}
@@ -431,7 +427,7 @@ void PropagateDownloadFileLegacy::notify_status_cb(void* userdata, ne_session_st
{
PropagateDownloadFileLegacy* that = reinterpret_cast<PropagateDownloadFileLegacy*>(userdata);
if (status == ne_status_recving && info->sr.total > 0) {
- emit that->progress(Progress::Context, that->_item, info->sr.progress, info->sr.total );
+ emit that->progress(that->_item, info->sr.progress );
that->limitBandwidth(info->sr.progress, that->_propagator->_downloadLimit.fetchAndAddAcquire(0));
}
@@ -442,7 +438,7 @@ void PropagateDownloadFileLegacy::start()
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
- emit progress(Progress::StartDownload, _item, 0, _item._size);
+ emit progress(_item, 0);
QString tmpFileName;
const SyncJournalDb::DownloadInfo progressInfo = _propagator->_journal->getDownloadInfo(_item._file);
@@ -598,7 +594,6 @@ void PropagateDownloadFileLegacy::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, _item._size, _item._size);
done(isConflict ? SyncFileItem::Conflict : SyncFileItem::Success);
}
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index c68ce81..648e33f 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -58,6 +58,9 @@ void PUTFileJob::start() {
if( reply()->error() != QNetworkReply::NoError ) {
qWarning() << Q_FUNC_INFO << " Network error: " << reply()->errorString();
}
+
+ connect(reply(), SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(uploadProgress(qint64,qint64)));
+
AbstractNetworkJob::start();
}
@@ -92,7 +95,7 @@ void PropagateUploadFileQNAM::start()
_currentChunk = 0;
_propagator->_activeJobs++;
- emit progress(Progress::StartUpload, _item, 0, fileSize);
+ emit progress(_item, 0);
emitReady();
this->startNextChunk();
}
@@ -168,6 +171,7 @@ void PropagateUploadFileQNAM::startNextChunk()
_job = new PUTFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + path, device, headers);
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished()));
+ connect(_job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64)));
_job->start();
}
@@ -216,7 +220,7 @@ void PropagateUploadFileQNAM::slotPutFinished()
SyncJournalDb::UploadInfo pi;
pi._valid = true;
- pi._chunk = _currentChunk; // next chunk to start with
+ pi._chunk = (_currentChunk + _startChunk) % _chunkCount; // next chunk to start with
pi._transferid = _transferId;
pi._modtime = Utility::qDateTimeFromTime_t(_item._modtime);
_propagator->_journal->setUploadInfo(_item._file, pi);
@@ -251,10 +255,18 @@ void PropagateUploadFileQNAM::slotPutFinished()
_propagator->_journal->setUploadInfo(_item._file, SyncJournalDb::UploadInfo());
_propagator->_journal->commit("upload file start");
- emit progress(Progress::EndUpload, _item, _item._size, _item._size);
done(SyncFileItem::Success);
}
+void PropagateUploadFileQNAM::slotUploadProgress(qint64 sent, qint64)
+{
+ int progressChunk = _currentChunk + _startChunk;
+ if (progressChunk >= _chunkCount)
+ progressChunk = _currentChunk;
+ emit progress(_item, sent + _currentChunk * CHUNKING_SIZE);
+}
+
+
void PropagateUploadFileQNAM::abort()
{
if (_job && _job->reply())
@@ -277,6 +289,7 @@ void GETFileJob::start() {
}
connect(reply(), SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
+ connect(reply(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));
AbstractNetworkJob::start();
}
@@ -295,7 +308,7 @@ void PropagateDownloadFileQNAM::start()
qDebug() << Q_FUNC_INFO << _item._file << _propagator->_activeJobs;
- emit progress(Progress::StartDownload, _item, 0, _item._size);
+ emit progress(_item, 0);
QString tmpFileName;
const SyncJournalDb::DownloadInfo progressInfo = _propagator->_journal->getDownloadInfo(_item._file);
@@ -352,10 +365,12 @@ void PropagateDownloadFileQNAM::start()
headers["Range"] = "bytes=" + QByteArray::number(done) +'-';
headers["Accept-Ranges"] = "bytes";
qDebug() << "Retry with range " << headers["Range"];
+ _startSize = done;
}
_job = new GETFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + _item._file, &_tmpFile, headers);
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
+ connect(_job, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64)));
_propagator->_activeJobs ++;
_job->start();
emitReady();
@@ -435,10 +450,15 @@ void PropagateDownloadFileQNAM::downloadFinished()
_propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
_propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
_propagator->_journal->commit("download file start2");
- emit progress(Progress::EndDownload, _item, _item._size, _item._size);
done(isConflict ? SyncFileItem::Conflict : SyncFileItem::Success);
}
+void PropagateDownloadFileQNAM::slotDownloadProgress(qint64 received, qint64)
+{
+ emit progress(_item, received + _startSize);
+}
+
+
void PropagateDownloadFileQNAM::abort()
{
if (_job && _job->reply())
diff --git a/src/mirall/propagator_qnam.h b/src/mirall/propagator_qnam.h
index 75e2b0b..f42bf07 100644
--- a/src/mirall/propagator_qnam.h
+++ b/src/mirall/propagator_qnam.h
@@ -68,6 +68,7 @@ public:
signals:
void finishedSignal();
+ void uploadProgress(qint64,qint64);
};
@@ -85,6 +86,7 @@ public:
void start();
private slots:
void slotPutFinished();
+ void slotUploadProgress(qint64,qint64);
void abort();
void startNextChunk();
@@ -108,6 +110,7 @@ public:
signals:
void finishedSignal();
+ void downloadProgress(qint64,qint64);
private slots:
void slotReadyRead();
};
@@ -120,14 +123,17 @@ class PropagateDownloadFileQNAM : public PropagateItemJob {
// QFile *_file;
QFile _tmpFile;
+ quint64 _startSize;
public:
PropagateDownloadFileQNAM(OwncloudPropagator* propagator,const SyncFileItem& item)
- : PropagateItemJob(propagator, item) {}
+ : PropagateItemJob(propagator, item), _startSize(0) {}
void start();
private slots:
void slotGetFinished();
void abort();
void downloadFinished();
+ void slotDownloadProgress(qint64,qint64);
+
};
diff --git a/src/mirall/propagatorjobs.cpp b/src/mirall/propagatorjobs.cpp
index 1376a2e..0a951a1 100644
--- a/src/mirall/propagatorjobs.cpp
+++ b/src/mirall/propagatorjobs.cpp
@@ -93,11 +93,10 @@ void PropagateLocalRemove::start()
return;
}
}
- emit progress(Progress::StartDelete, _item, 0, _item._size);
+ emit progress(_item, 0);
_propagator->_journal->deleteFileRecord(_item._originalFile, _item._isDirectory);
_propagator->_journal->commit("Local remove");
done(SyncFileItem::Success);
- emit progress(Progress::EndDelete, _item, _item._size, _item._size);
}
void PropagateLocalMkdir::start()
@@ -120,7 +119,7 @@ void PropagateRemoteRemove::start()
QScopedPointer<char, QScopedPointerPodDeleter> uri(
ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8()));
- emit progress(Progress::StartDelete, _item, 0, _item._size);
+ emit progress(_item, 0);
qDebug() << "** DELETE " << uri.data();
int rc = ne_delete(_propagator->_session, uri.data());
@@ -139,7 +138,6 @@ void PropagateRemoteRemove::start()
_propagator->_journal->deleteFileRecord(_item._originalFile, _item._isDirectory);
_propagator->_journal->commit("Remote Remove");
done(SyncFileItem::Success);
- emit progress(Progress::EndDelete, _item, _item._size, _item._size);
}
void PropagateRemoteMkdir::start()
@@ -169,10 +167,9 @@ void PropagateLocalRename::start()
// if the file is a file underneath a moved dir, the _item.file is equal
// to _item.renameTarget and the file is not moved as a result.
if (_item._file != _item._renameTarget) {
- emit progress(Progress::StartRename, _item, 0, _item._size);
+ emit progress(_item, 0);
qDebug() << "MOVE " << _propagator->_localDir + _item._file << " => " << _propagator->_localDir + _item._renameTarget;
QFile::rename(_propagator->_localDir + _item._file, _propagator->_localDir + _item._renameTarget);
- emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_item._instruction = CSYNC_INSTRUCTION_DELETED;
@@ -218,7 +215,7 @@ void PropagateRemoteRename::start()
}
return;
} else {
- emit progress(Progress::StartRename, _item, 0, _item._size);
+ emit progress(_item, 0);
QScopedPointer<char, QScopedPointerPodDeleter> uri1(ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8()));
QScopedPointer<char, QScopedPointerPodDeleter> uri2(ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8()));
@@ -239,7 +236,6 @@ void PropagateRemoteRename::start()
if (!updateMTimeAndETag(uri2.data(), _item._modtime))
return;
- emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_propagator->_journal->deleteFileRecord(_item._originalFile);
diff --git a/src/mirall/protocolwidget.cpp b/src/mirall/protocolwidget.cpp
index 25ef610..a8e908d 100644
--- a/src/mirall/protocolwidget.cpp
+++ b/src/mirall/protocolwidget.cpp
@@ -73,36 +73,6 @@ ProtocolWidget::ProtocolWidget(QWidget *parent) :
cfg.restoreGeometryHeader(_ui->_treeWidget->header());
}
-void ProtocolWidget::initializeList()
-{
- QList<Progress::Info> progressList = ProgressDispatcher::instance()->recentChangedItems(0); // All.
- QList<QTreeWidgetItem*> items;
- QTreeWidgetItem *item;
-
- _ui->_treeWidget->clear();
-
- QList<Progress::SyncProblem> problemList = ProgressDispatcher::instance()->recentProblems(0);
- items.clear();
- foreach( Progress::SyncProblem prob, problemList ) {
- item = createProblemTreewidgetItem(prob);
- if (item) {
- items.append(item);
- }
- }
- _ui->_treeWidget->addTopLevelItems(items);
-
- foreach( Progress::Info info, progressList ) {
- item = createProgressTreewidgetItem(info);
- if(item) {
- items.append(item);
- }
- }
- _ui->_treeWidget->addTopLevelItems(items);
-
- computeResyncButtonEnabled();
-
-}
-
ProtocolWidget::~ProtocolWidget()
{
MirallConfigFile cfg;
@@ -238,6 +208,7 @@ void ProtocolWidget::slotProgressProblem( const QString& folder, const Progress:
Q_UNUSED(folder);
QTreeWidgetItem *item = createProblemTreewidgetItem(problem);
_ui->_treeWidget->insertTopLevelItem(0, item);
+ computeResyncButtonEnabled();
}
void ProtocolWidget::slotOpenFile( QTreeWidgetItem *item, int )
@@ -255,23 +226,26 @@ void ProtocolWidget::slotOpenFile( QTreeWidgetItem *item, int )
}
}
-QTreeWidgetItem* ProtocolWidget::createProgressTreewidgetItem( const Progress::Info& progress )
+QTreeWidgetItem* ProtocolWidget::createCompletedTreewidgetItem(const QString& folder, const SyncFileItem& item)
{
QStringList columns;
- const QString timeStr = timeString(progress.timestamp);
- const QString longTimeStr = timeString(progress.timestamp, QLocale::LongFormat);
- const QString actionStr = Progress::asResultString(progress);
+ QDateTime timestamp = QDateTime::currentDateTime();
+ const QString timeStr = timeString(timestamp);
+ const QString longTimeStr = timeString(timestamp, QLocale::LongFormat);
+ const QString actionStr = Progress::asResultString(item);
columns << timeStr;
- columns << progress.current_file;
- columns << progress.folder;
+ columns << item._file;
+ columns << folder;
columns << actionStr;
- columns << Utility::octetsToString( progress.file_size );
+ if (Progress::isSizeDependent(item._instruction)) {
+ columns << Utility::octetsToString( item._size );
+ }
- QTreeWidgetItem *item = new QTreeWidgetItem(columns);
- item->setToolTip(0, longTimeStr);
- item->setToolTip(3, actionStr);
- return item;
+ QTreeWidgetItem *twitem = new QTreeWidgetItem(columns);
+ twitem->setToolTip(0, longTimeStr);
+ twitem->setToolTip(3, actionStr);
+ return twitem;
}
void ProtocolWidget::computeResyncButtonEnabled()
@@ -296,6 +270,7 @@ void ProtocolWidget::computeResyncButtonEnabled()
void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::Info& progress )
{
+ /*
if( progress.kind == Progress::StartSync ) {
cleanErrorItems( folder );
_clearBlacklistBtn->setEnabled(false);
@@ -304,14 +279,11 @@ void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::In
if( progress.kind == Progress::EndSync ) {
computeResyncButtonEnabled();
}
+ */
+ SyncFileItem last = progress._lastCompletedItem;
+ if (last.isEmpty()) return;
- // Ingore other events than finishing an individual up- or download.
- if( !(progress.kind == Progress::EndDownload || progress.kind == Progress::EndUpload
- || progress.kind == Progress::EndDelete || progress.kind == Progress::EndRename)) {
- return;
- }
-
- QTreeWidgetItem *item = createProgressTreewidgetItem(progress);
+ QTreeWidgetItem *item = createCompletedTreewidgetItem(folder, last);
if(item) {
_ui->_treeWidget->insertTopLevelItem(0, item);
}
diff --git a/src/mirall/protocolwidget.h b/src/mirall/protocolwidget.h
index 69b82b1..25b4bba 100644
--- a/src/mirall/protocolwidget.h
+++ b/src/mirall/protocolwidget.h
@@ -39,8 +39,6 @@ public:
explicit ProtocolWidget(QWidget *parent = 0);
~ProtocolWidget();
- void initializeList();
-
signals:
public slots:
@@ -60,7 +58,7 @@ private:
void cleanErrorItems( const QString& folder );
void computeResyncButtonEnabled();
- QTreeWidgetItem* createProgressTreewidgetItem(const Progress::Info& progress );
+ QTreeWidgetItem* createCompletedTreewidgetItem(const QString &folder, const SyncFileItem &item );
QTreeWidgetItem* createProblemTreewidgetItem( const Progress::SyncProblem& problem);
QList<QTreeWidgetItem*> errorItems(const QString &folder);
diff --git a/src/mirall/settingsdialog.cpp b/src/mirall/settingsdialog.cpp
index 8c5afb8..28932cf 100644
--- a/src/mirall/settingsdialog.cpp
+++ b/src/mirall/settingsdialog.cpp
@@ -171,9 +171,7 @@ void SettingsDialog::accept() {
}
void SettingsDialog::slotRefreshResultList() {
- if( _protocolWidget ) {
- _protocolWidget->initializeList();
- }
+
}
void SettingsDialog::showActivityPage()
diff --git a/src/owncloudcmd/owncloudcmd.cpp b/src/owncloudcmd/owncloudcmd.cpp
index bf08411..98090a7 100644
--- a/src/owncloudcmd/owncloudcmd.cpp
+++ b/src/owncloudcmd/owncloudcmd.cpp
@@ -37,17 +37,17 @@ class OwncloudCmd : public QObject {
public:
OwncloudCmd() : QObject() { }
public slots:
- void transmissionProgressSlot(Progress::Info pI) {
+ void transmissionProgressSlot(Progress::Kind pI) {
static QElapsedTimer localTimer;
static QElapsedTimer remoteTimer;
- if (pI.kind == Progress::StartLocalUpdate) {
+ if (pI == Progress::StartLocalUpdate) {
localTimer.start();
- } else if (pI.kind == Progress::EndLocalUpdate) {
+ } else if (pI == Progress::EndLocalUpdate) {
// There is also localTimer.nsecsElapsed()
qDebug() << "Local Update took" << localTimer.elapsed() << "msec";
- } else if (pI.kind == Progress::StartRemoteUpdate) {
+ } else if (pI == Progress::StartRemoteUpdate) {
remoteTimer.start();
- } else if (pI.kind == Progress::EndRemoteUpdate) {
+ } else if (pI == Progress::EndRemoteUpdate) {
qDebug() << "Remote Update took" << remoteTimer.elapsed() << "msec";
}
}
@@ -222,7 +222,7 @@ int main(int argc, char **argv) {
SyncJournalDb db(options.source_dir);
CSyncThread csyncthread(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), folder, &db);
QObject::connect(&csyncthread, SIGNAL(finished()), &app, SLOT(quit()));
- QObject::connect(&csyncthread, SIGNAL(transmissionProgress(Progress::Info)), &owncloudCmd, SLOT(transmissionProgressSlot(Progress::Info)));
+ QObject::connect(&csyncthread, SIGNAL(transmissionProgress(Progress::Kind,Progress::Info)), &owncloudCmd, SLOT(transmissionProgressSlot(Progress::Kind)));
csyncthread.startSync();
app.exec();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list