[Pkg-owncloud-commits] [owncloud-client] 01/332: Issue-142 : added time estimation and bandwidth indicator to the systry and active download

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:31 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 46ffd1c29abe04a235c886d91d5c47fc0c7ecae5
Author: Eran <etherpulse at gmail.com>
Date:   Fri Apr 25 01:08:25 2014 +0300

    Issue-142 : added time estimation and bandwidth indicator to the systry and active download
---
 src/mirall/accountsettings.cpp  |  5 ++++-
 src/mirall/owncloudgui.cpp      |  6 ++++--
 src/mirall/progressdispatcher.h | 46 ++++++++++++++++++++++++++++++++++++++++-
 src/mirall/utility.cpp          | 11 ++++++++++
 src/mirall/utility.h            |  6 ++++++
 5 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp
index cfcd876..e05c53b 100644
--- a/src/mirall/accountsettings.cpp
+++ b/src/mirall/accountsettings.cpp
@@ -616,7 +616,10 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf
         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);
+		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()) );
     } else {
         //: Example text: "uploading foobar.png"
         fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp
index 5999a5b..ee1f5f1 100644
--- a/src/mirall/owncloudgui.cpp
+++ b/src/mirall/owncloudgui.cpp
@@ -408,8 +408,10 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const Progress::Info
     QString s1 = Utility::octetsToString( completedSize );
     QString s2 = Utility::octetsToString( progress._totalSize );
 
-    _actionStatus->setText(tr("Syncing %1 of %2 (%3 of %4)")
-        .arg(currentFile).arg(progress._totalFileCount).arg(s1, s2));
+	_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())) );
 
     _actionRecent->setIcon( QIcon() ); // Fixme: Set a "in-progress"-item eventually.
 
diff --git a/src/mirall/progressdispatcher.h b/src/mirall/progressdispatcher.h
index 6b52d98..8756fd2 100644
--- a/src/mirall/progressdispatcher.h
+++ b/src/mirall/progressdispatcher.h
@@ -36,12 +36,39 @@ namespace Progress
 
 
     struct Info {
-        Info() : _totalFileCount(0), _totalSize(0), _completedFileCount(0), _completedSize(0) {}
+		Info() : _totalFileCount(0), _totalSize(0), _completedFileCount(0), _completedSize(0), _etaEstimate()  {}
 
         quint64 _totalFileCount;
         quint64 _totalSize;
         quint64 _completedFileCount;
         quint64 _completedSize;
+		struct EtaEstimate {
+			EtaEstimate() :  _startedTime(QDateTime::currentMSecsSinceEpoch()), _agvEtaMSecs(0),_effectiveBandwidth(0) {}
+			
+			static const int AVG_DIVIDER=10;
+			
+			quint64	_startedTime ;
+			quint64	_agvEtaMSecs;
+			quint64 _effectiveBandwidth;
+			
+			/**
+			 * update the estimated eta time with more current data.
+			 * @param quint64 completed the amount the was completed.
+			 * @param quint64 total the total amout that should be completed.
+			 */
+			void updateTime(quint64 completed, quint64 total) {
+				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) ); 
+				}
+			}
+			
+	       quint64 getEtaEstimate() const {
+			   return _agvEtaMSecs / AVG_DIVIDER;
+	       } 
+		};
+		EtaEstimate _etaEstimate;
 
         struct ProgressItem {
             ProgressItem() : _completedSize(0) {}
@@ -63,6 +90,7 @@ namespace Progress
             _currentItems[item._file]._item = item;
             _currentItems[item._file]._completedSize = size;
             _lastCompletedItem = SyncFileItem();
+			_etaEstimate.updateTime(this->completedSize(),this->_totalSize);
         }
 
         quint64 completedSize() const {
@@ -72,6 +100,22 @@ namespace Progress
             }
             return r;
         }
+        
+        /**
+		 * Get the eta estimate in milliseconds 
+		 * @return quint64 the estimate amount of milliseconds to end the process.
+		 */
+        quint64 etaEstimate() const {
+			return _etaEstimate.getEtaEstimate();
+        }
+        
+        /**
+		 * Get the estimated average bandwidth usage.
+		 * @return quint64 the estimated bandwidth usage in bytes.
+		 */
+        quint64 getEstimatedBandwidth() const {
+			return ( this->_totalSize - this->completedSize() ) / (1+_etaEstimate.getEtaEstimate()/1000) ;
+        }
     };
 
     QString asActionString( const SyncFileItem& item );
diff --git a/src/mirall/utility.cpp b/src/mirall/utility.cpp
index 0291c7b..8be0f4d 100644
--- a/src/mirall/utility.cpp
+++ b/src/mirall/utility.cpp
@@ -452,6 +452,17 @@ qint64 Utility::qDateTimeToTime_t(const QDateTime& t)
     return t.toMSecsSinceEpoch() / 1000;
 }
 
+QString Utility::timeConversion(quint64 msecs)
+{
+	msecs = msecs / 1000;
+	int hours = msecs/(3600);
+	int minutes = (msecs-(hours*3600))/(60);
+	int seconds = (msecs-(minutes*60)-(hours*3600));
+	
+	return 	(hours > 0 ? QString("%1h ").arg(hours): QString())
+			.append(minutes > 0 ? QString("%1m ").arg(minutes, 2, 10, QChar('0'))  : QString())
+			.append(QString("%1s").arg(seconds, 2, 10, QChar('0')) );
+}
 
 
 bool Utility::isWindows()
diff --git a/src/mirall/utility.h b/src/mirall/utility.h
index 3fb7051..8b4caaf 100644
--- a/src/mirall/utility.h
+++ b/src/mirall/utility.h
@@ -61,6 +61,12 @@ namespace Utility
     QDateTime qDateTimeFromTime_t(qint64 t);
     qint64 qDateTimeToTime_t(const QDateTime &t);
 
+	/**
+	 * Convert milliseconds to HMS string.
+	 * @param quint64 msecs the milliseconds to convert to string
+	 * @return an HMS representation of the milliseconds value.
+	 */
+	QString timeConversion(quint64 msecs);
 
     // convinience OS detection methods
     bool isWindows();

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