Skip to content

Commit

Permalink
Time estimate: Refactor remaining time guess. #2328
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Jan 30, 2015
1 parent a7a8ffe commit cd5e433
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 189 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ int main(int argc, char **argv) {

SyncEngine engine(account, _csync_ctx, options.source_dir, QUrl(options.target_url).path(), folder, &db);
QObject::connect(&engine, SIGNAL(finished()), &app, SLOT(quit()));
QObject::connect(&engine, SIGNAL(transmissionProgress(Progress::Info)), &cmd, SLOT(transmissionProgressSlot()));
QObject::connect(&engine, SIGNAL(transmissionProgress(ProgressInfo)), &cmd, SLOT(transmissionProgressSlot()));

engine.setSelectiveSyncBlackList(selectiveSyncList);

Expand Down
25 changes: 13 additions & 12 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ QString AccountSettings::shortenFilename( const QString& folder, const QString&
return shortFile;
}

void AccountSettings::slotSetProgress(const QString& folder, const Progress::Info &progress )
void AccountSettings::slotSetProgress(const QString& folder, const ProgressInfo &progress )
{
QStandardItem *item = itemForFolder( folder );
if( !item ) return;
Expand All @@ -620,10 +620,10 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf
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)
foreach(const ProgressInfo::ProgressItem &citm, progress._currentItems) {
if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
&& biggerItemSize < citm._item._size)) {
curItemProgress = citm._completedSize;
curItemProgress = citm._progress.completed();
curItem = citm._item;
biggerItemSize = citm._item._size;
}
Expand All @@ -638,15 +638,15 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf


QString fileProgressString;
if (Progress::isSizeDependent(curItem)) {
if (ProgressInfo::isSizeDependent(curItem)) {
QString s1 = Utility::octetsToString( curItemProgress );
QString s2 = Utility::octetsToString( curItem._size );
quint64 estimatedBw = progress.getFileEstimate(curItem).getEstimatedBandwidth();
quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
if (estimatedBw) {
//: Example text: "uploading foobar.png (1MB of 2MB) time left 2 minutes at a rate of 24Kb/s"
fileProgressString = tr("%1 %2 (%3 of %4) %5 left at a rate of %6/s")
.arg(kindString, itemFileName, s1, s2,
Utility::timeToDescriptiveString(progress.getFileEstimate(curItem).getEtaEstimate(), 3, " ", true),
Utility::timeToDescriptiveString(progress.fileProgress(curItem).estimatedEta, 3, " ", true),
Utility::octetsToString(estimatedBw) );
} else {
//: Example text: "uploading foobar.png (2MB of 2MB)"
Expand All @@ -660,19 +660,20 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf

// overall progress
quint64 completedSize = progress.completedSize();
quint64 currentFile = progress._completedFileCount + progress._currentItems.count();
quint64 completedFile = progress.completedFiles();
quint64 currentFile = progress.currentFile();
if (currentFile == ULLONG_MAX)
currentFile = 0;
quint64 totalSize = qMax(completedSize, progress._totalSize);
quint64 totalFileCount = qMax(currentFile, progress._totalFileCount);
quint64 totalSize = qMax(completedSize, progress.totalSize());
quint64 totalFileCount = qMax(currentFile, progress.totalFiles());
QString overallSyncString;
if (totalSize > 0) {
QString s1 = Utility::octetsToString( completedSize );
QString s2 = Utility::octetsToString( totalSize );
overallSyncString = tr("%1 of %2, file %3 of %4\nTotal time left %5")
.arg(s1, s2)
.arg(currentFile).arg(totalFileCount)
.arg( Utility::timeToDescriptiveString(progress.totalEstimate().getEtaEstimate(), 3, " ", true) );
.arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 3, " ", true) );
} else if (totalFileCount > 0) {
// Don't attemt to estimate the time left if there is no kb to transfer.
overallSyncString = tr("file %1 of %2") .arg(currentFile).arg(totalFileCount);
Expand All @@ -683,7 +684,7 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf
int overallPercent = 0;
if( totalFileCount > 0 ) {
// Add one 'byte' for each files so the percentage is moving when deleting or renaming files
overallPercent = qRound(double(completedSize + progress._completedFileCount)/double(totalSize + totalFileCount) * 100.0);
overallPercent = qRound(double(completedSize + completedFile)/double(totalSize + totalFileCount) * 100.0);
}
item->setData( overallPercent, FolderStatusDelegate::SyncProgressOverallPercent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public slots:
void slotOpenOC();
void slotUpdateFolderState( Folder* );
void slotDoubleClicked( const QModelIndex& );
void slotSetProgress(const QString& folder, const Progress::Info& progress);
void slotSetProgress(const QString& folder, const ProgressInfo& progress);
void slotButtonsSetEnabled();

void slotUpdateQuota( qint64,qint64 );
Expand Down
2 changes: 0 additions & 2 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ Application::Application(int &argc, char **argv) :

setQuitOnLastWindowClosed(false);

qRegisterMetaType<Progress::Info>("Progress::Info");

ConfigFile cfg;
_theme->setSystrayUseMonoIcons(cfg.monoIcons());
connect (_theme, SIGNAL(systrayUseMonoIconsChanged(bool)), SLOT(slotUseMonoIconsChanged(bool)));
Expand Down
10 changes: 5 additions & 5 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void Folder::startSync(const QStringList &pathList)
connect(_engine.data(), SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)),
SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*)));
connect(_engine.data(), SIGNAL(folderDiscovered(bool,QString)), this, SLOT(slotFolderDiscovered(bool,QString)));
connect(_engine.data(), SIGNAL(transmissionProgress(Progress::Info)), this, SLOT(slotTransmissionProgress(Progress::Info)));
connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo)));
connect(_engine.data(), SIGNAL(jobCompleted(SyncFileItem)), this, SLOT(slotJobCompleted(SyncFileItem)));
connect(_engine.data(), SIGNAL(syncItemDiscovered(SyncFileItem)), this, SLOT(slotSyncItemDiscovered(SyncFileItem)));

Expand Down Expand Up @@ -959,18 +959,18 @@ void Folder::slotEmitFinishedDelayed()

void Folder::slotFolderDiscovered(bool, QString folderName)
{
Progress::Info pi;
ProgressInfo pi;
pi._currentDiscoveredFolder = folderName;
ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
}


// 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 &pi)
void Folder::slotTransmissionProgress(const ProgressInfo &pi)
{
if( pi._completedFileCount ) {
// No job completed yet, this is the beginning of a sync, set the warning level to 0
if( !pi.hasStarted() ) {
// this is the beginning of a sync, set the warning level to 0
_syncResult.setWarnCount(0);
}
ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private slots:
void slotSyncFinished();

void slotFolderDiscovered(bool local, QString folderName);
void slotTransmissionProgress(const Progress::Info& pi);
void slotTransmissionProgress(const ProgressInfo& pi);
void slotJobCompleted(const SyncFileItem&);
void slotSyncItemDiscovered(const SyncFileItem & item);

Expand Down
22 changes: 11 additions & 11 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ ownCloudGui::ownCloudGui(Application *parent) :
this, SLOT(slotOpenPath(QString)));

ProgressDispatcher *pd = ProgressDispatcher::instance();
connect( pd, SIGNAL(progressInfo(QString,Progress::Info)), this,
SLOT(slotUpdateProgress(QString,Progress::Info)) );
connect( pd, SIGNAL(progressInfo(QString,ProgressInfo)), this,
SLOT(slotUpdateProgress(QString,ProgressInfo)) );

FolderMan *folderMan = FolderMan::instance();
connect( folderMan, SIGNAL(folderSyncStateChange(QString)),
Expand Down Expand Up @@ -469,24 +469,24 @@ void ownCloudGui::slotRebuildRecentMenus()
}


void ownCloudGui::slotUpdateProgress(const QString &folder, const Progress::Info& progress)
void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo& progress)
{
Q_UNUSED(folder);

if (!progress._currentDiscoveredFolder.isEmpty()) {
_actionStatus->setText( tr("Discovering '%1'")
.arg( progress._currentDiscoveredFolder ));
} else if (progress._totalSize == 0 ) {
quint64 currentFile = progress._completedFileCount + progress._currentItems.count();
quint64 totalFileCount = qMax(progress._totalFileCount, currentFile);
} else if (progress.totalSize() == 0 ) {
quint64 currentFile = progress.currentFile();
quint64 totalFileCount = qMax(progress.totalFiles(), currentFile);
_actionStatus->setText( tr("Syncing %1 of %2 (%3 left)")
.arg( currentFile ).arg( totalFileCount )
.arg( Utility::timeToDescriptiveString(progress.totalEstimate().getEtaEstimate(), 2, " ",true) ) );
.arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 2, " ",true) ) );
} else {
QString totalSizeStr = Utility::octetsToString( progress._totalSize );
QString totalSizeStr = Utility::octetsToString( progress.totalSize() );
_actionStatus->setText( tr("Syncing %1 (%2 left)")
.arg( totalSizeStr )
.arg( Utility::timeToDescriptiveString(progress.totalEstimate().getEtaEstimate(), 2, " ",true) ) );
.arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 2, " ",true) ) );
}


Expand Down Expand Up @@ -524,8 +524,8 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const Progress::Info
slotRebuildRecentMenus();
}

if (progress._completedFileCount != ULLONG_MAX
&& progress._completedFileCount >= progress._totalFileCount
if (progress.hasStarted()
&& progress.completedFiles() >= progress.totalFiles()
&& progress._currentDiscoveredFolder.isEmpty()) {
QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public slots:
void slotFolderOpenAction( const QString& alias );
void slotRefreshQuotaDisplay( qint64 total, qint64 used );
void slotRebuildRecentMenus();
void slotUpdateProgress(const QString &folder, const Progress::Info& progress);
void slotUpdateProgress(const QString &folder, const ProgressInfo& progress);
void slotShowGuiMessage(const QString &title, const QString &message);
void slotFoldersChanged();
void slotShowSettings();
Expand Down
12 changes: 6 additions & 6 deletions src/gui/protocolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ ProtocolWidget::ProtocolWidget(QWidget *parent) :
{
_ui->setupUi(this);

connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,Progress::Info)),
this, SLOT(slotProgressInfo(QString,Progress::Info)));
connect(ProgressDispatcher::instance(), SIGNAL(progressInfo(QString,ProgressInfo)),
this, SLOT(slotProgressInfo(QString,ProgressInfo)));

connect(_ui->_treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), SLOT(slotOpenFile(QTreeWidgetItem*,int)));

Expand Down Expand Up @@ -229,7 +229,7 @@ QTreeWidgetItem* ProtocolWidget::createCompletedTreewidgetItem(const QString& fo
message = item._errorString;
}
columns << message;
if (Progress::isSizeDependent(item)) {
if (ProgressInfo::isSizeDependent(item)) {
columns << Utility::octetsToString( item._size );
}
}
Expand Down Expand Up @@ -272,13 +272,13 @@ void ProtocolWidget::computeResyncButtonEnabled()

}

void ProtocolWidget::slotProgressInfo( const QString& folder, const Progress::Info& progress )
void ProtocolWidget::slotProgressInfo( const QString& folder, const ProgressInfo& progress )
{
if( progress._completedFileCount == ULLONG_MAX ) {
if( !progress.hasStarted() ) {
// The sync is restarting, clean the old items
cleanIgnoreItems(folder);
computeResyncButtonEnabled();
} else if (progress._completedFileCount >= progress._totalFileCount) {
} else if (progress.completedFiles() >= progress.totalFiles()) {
//Sync completed
computeResyncButtonEnabled();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/protocolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProtocolWidget : public QWidget
signals:

public slots:
void slotProgressInfo( const QString& folder, const Progress::Info& progress );
void slotProgressInfo( const QString& folder, const ProgressInfo& progress );
void slotOpenFile( QTreeWidgetItem* item, int );

protected slots:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
gui, SLOT(slotFolderOpenAction(QString)));

connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, Progress::Info)),
_accountSettings, SLOT(slotSetProgress(QString, Progress::Info)) );
connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, ProgressInfo)),
_accountSettings, SLOT(slotSetProgress(QString, ProgressInfo)) );


// default to Account
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/progressdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ProgressDispatcher::~ProgressDispatcher()

}

void ProgressDispatcher::setProgressInfo(const QString& folder, const Progress::Info& progress)
void ProgressDispatcher::setProgressInfo(const QString& folder, const ProgressInfo& progress)
{
if( folder.isEmpty())
// The update phase now also has progress
Expand Down
Loading

0 comments on commit cd5e433

Please sign in to comment.