From eadcdab8e7e87ceb5f15bf9ddfc4c3ae4a44c5ce Mon Sep 17 00:00:00 2001 From: Eran Date: Sun, 27 Apr 2014 00:48:12 +0300 Subject: [PATCH] Issue-#142 : Added support for current file completion estimation. Changed the account settings estimation to display both current file and overwhole estimation. Decresed the progress font size to fit the added information --- src/mirall/accountsettings.cpp | 11 ++++-- src/mirall/folderstatusmodel.cpp | 2 +- src/mirall/owncloudgui.cpp | 4 +- src/mirall/progressdispatcher.h | 65 ++++++++++++++++++++++---------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index e05c53bfb9..1b343ee91c 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -618,8 +618,8 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf //: Example text: "uploading foobar.png (1MB of 2MB)" fileProgressString = tr("%1 %2 (%3 of %4) , Time left : %5 at a rate of %6/s") .arg(kindString, itemFileName, s1, s2) - .arg( Utility::timeConversion(progress.etaEstimate())) - .arg(Utility::octetsToString(progress.getEstimatedBandwidth()) ); + .arg( Utility::timeConversion(progress.currentFileEstimate().getEtaEstimate()) ) + .arg( Utility::octetsToString(progress.currentFileEstimate().getEstimatedBandwidth()) ); } else { //: Example text: "uploading foobar.png" fileProgressString = tr("%1 %2").arg(kindString, itemFileName); @@ -631,8 +631,11 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf 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); + QString overallSyncString = tr("%1 of %2, file %3 of %4\n%5") + .arg(s1, s2) + .arg(currentFile).arg(progress._totalFileCount) + .arg( Utility::timeConversion(progress.totalEstimate().getEtaEstimate()) ); + //.arg( Utility::octetsToString(progress.totalEstimate().getEstimatedBandwidth()) ); item->setData( overallSyncString, FolderStatusDelegate::SyncProgressOverallString ); int overallPercent = 0; diff --git a/src/mirall/folderstatusmodel.cpp b/src/mirall/folderstatusmodel.cpp index 633e0c38a9..9918544943 100644 --- a/src/mirall/folderstatusmodel.cpp +++ b/src/mirall/folderstatusmodel.cpp @@ -110,7 +110,7 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem & QFont errorFont = subFont; QFont progressFont = subFont; - progressFont.setPointSize( subFont.pointSize()-1); + progressFont.setPointSize( subFont.pointSize()-2); //font.setPixelSize(font.weight()+); aliasFont.setBold(true); aliasFont.setPointSize( subFont.pointSize()+2 ); diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp index ee1f5f1aa4..6fe9f0bb37 100644 --- a/src/mirall/owncloudgui.cpp +++ b/src/mirall/owncloudgui.cpp @@ -410,8 +410,8 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const Progress::Info _actionStatus->setText( tr("Syncing %1 of %2 (%3 of %4) \nETA : %5 , %6/s") .arg(currentFile).arg(progress._totalFileCount).arg(s1, s2) - .arg( Utility::timeConversion(progress.etaEstimate()) ) - .arg(Utility::octetsToString(progress.getEstimatedBandwidth())) ); + .arg( Utility::timeConversion(progress.totalEstimate().getEtaEstimate()) ) + .arg( Utility::octetsToString(progress.totalEstimate().getEstimatedBandwidth())) ); _actionRecent->setIcon( QIcon() ); // Fixme: Set a "in-progress"-item eventually. diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h index 8756fd2712..78c55922a2 100644 --- a/src/mirall/progressdispatcher.h +++ b/src/mirall/progressdispatcher.h @@ -36,20 +36,28 @@ namespace Progress struct Info { - Info() : _totalFileCount(0), _totalSize(0), _completedFileCount(0), _completedSize(0), _etaEstimate() {} + Info() : _totalFileCount(0), _totalSize(0), _completedFileCount(0), _completedSize(0), _totalEtaEstimate(),_currentEtaEstimate() {} quint64 _totalFileCount; quint64 _totalSize; quint64 _completedFileCount; quint64 _completedSize; struct EtaEstimate { - EtaEstimate() : _startedTime(QDateTime::currentMSecsSinceEpoch()), _agvEtaMSecs(0),_effectiveBandwidth(0) {} + EtaEstimate() : _startedTime(QDateTime::currentMSecsSinceEpoch()), _agvEtaMSecs(0),_effectivProgressPerSec(0) {} static const int AVG_DIVIDER=10; quint64 _startedTime ; quint64 _agvEtaMSecs; - quint64 _effectiveBandwidth; + quint64 _effectivProgressPerSec; + + /** + * reset the estiamte. + */ + void reset() { + _startedTime = QDateTime::currentMSecsSinceEpoch(); + _effectivProgressPerSec = _agvEtaMSecs = 0; + } /** * update the estimated eta time with more current data. @@ -60,15 +68,28 @@ namespace Progress if(total != 0) { quint64 elapsedTime = QDateTime::currentMSecsSinceEpoch() - this->_startedTime ; // (elapsedTime-1) to avoid float "rounding" issue (ie. 0.99999999999999999999....) - _agvEtaMSecs = _agvEtaMSecs - (_agvEtaMSecs / AVG_DIVIDER) + (elapsedTime * ((float) total / completed ) - (elapsedTime-1) ); + _agvEtaMSecs = _agvEtaMSecs - (_agvEtaMSecs / AVG_DIVIDER) + (elapsedTime * ((float) total / completed ) - (elapsedTime-1) ); + _effectivProgressPerSec = ( total - completed ) / (1+this->getEtaEstimate()/1000); } } - - quint64 getEtaEstimate() const { + /** + * Get the eta estimate in milliseconds + * @return quint64 the estimate amount of milliseconds to end the process. + */ + quint64 getEtaEstimate() const { return _agvEtaMSecs / AVG_DIVIDER; - } + } + + /** + * Get the estimated average bandwidth usage. + * @return quint64 the estimated bandwidth usage in bytes. + */ + quint64 getEstimatedBandwidth() const { + return _effectivProgressPerSec; + } }; - EtaEstimate _etaEstimate; + EtaEstimate _totalEtaEstimate; + EtaEstimate _currentEtaEstimate; struct ProgressItem { ProgressItem() : _completedSize(0) {} @@ -85,13 +106,16 @@ namespace Progress } _completedFileCount++; _lastCompletedItem = item; + _currentEtaEstimate.reset(); } void setProgressItem(const SyncFileItem &item, quint64 size) { _currentItems[item._file]._item = item; _currentItems[item._file]._completedSize = size; _lastCompletedItem = SyncFileItem(); - _etaEstimate.updateTime(this->completedSize(),this->_totalSize); - } + + _totalEtaEstimate.updateTime(this->completedSize(),this->_totalSize); + _currentEtaEstimate.updateTime(size,item._size); + } quint64 completedSize() const { quint64 r = _completedSize; @@ -102,20 +126,21 @@ namespace Progress } /** - * Get the eta estimate in milliseconds - * @return quint64 the estimate amount of milliseconds to end the process. + * Get the total completion estimate structure + * @return EtaEstimate a structure containing the total completion information. */ - quint64 etaEstimate() const { - return _etaEstimate.getEtaEstimate(); + EtaEstimate totalEstimate() const { + return _totalEtaEstimate; } - + /** - * Get the estimated average bandwidth usage. - * @return quint64 the estimated bandwidth usage in bytes. + * Get the current file completion estimate structure + * @return EtaEstimate a structure containing the current file completion information. */ - quint64 getEstimatedBandwidth() const { - return ( this->_totalSize - this->completedSize() ) / (1+_etaEstimate.getEtaEstimate()/1000) ; - } + EtaEstimate currentFileEstimate() const { + return _currentEtaEstimate; + } + }; QString asActionString( const SyncFileItem& item );