Skip to content

Commit

Permalink
Reworked progress again following mirall bug #137
Browse files Browse the repository at this point in the history
  • Loading branch information
dragotin committed Jul 23, 2013
1 parent 85d810d commit 274f59f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 172 deletions.
128 changes: 65 additions & 63 deletions src/mirall/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ void AccountSettings::slotSetOverallProgress( const QString& folder, const QStri
item->setData( fileNo, FolderStatusDelegate::OverallFileNo);
item->setData( fileCnt, FolderStatusDelegate::OverallFileCount);
item->setData( file, FolderStatusDelegate::OverallCurrentFile);

}
_lastOverallProgress = p1;
}

void AccountSettings::slotSetProgress( Progress::Kind kind, const QString& folder, const QString& file, long p1, long p2 )
Expand All @@ -489,70 +489,72 @@ void AccountSettings::slotSetProgress( Progress::Kind kind, const QString& folde

QStandardItem *item = itemForFolder( folder );

if( item ) {
if( p1 == p2 ) { // File upload finished.
item->setData( 100, FolderStatusDelegate::SyncProgressPercent1);
item->setData( 100, FolderStatusDelegate::SyncProgressPercent2);
if( p1 == 0 ) {
item->setData( (qlonglong) _lastSyncProgress, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) _lastSyncProgress, FolderStatusDelegate::SyncProgressBytes2);
} else {
item->setData( (qlonglong) p1, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) p2, FolderStatusDelegate::SyncProgressBytes2);
}
// item->setData( QVariant(QString::null), FolderStatusDelegate::SyncFileName );

// 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);
} else if( p1 == 0 ) { // File upload starts.
if( _hideProgressTimers.contains(item) ) {
// The timer is still running.
QTimer *t = _hideProgressTimers.take(item);
t->stop();
t->deleteLater();
}
// calculate the normalization factor and set the min and max
// _progressFactor = 100.0/p2;
item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace );
item->setData( 0, FolderStatusDelegate::SyncProgressPercent1);
item->setData( 100, FolderStatusDelegate::SyncProgressPercent2);
item->setData( (qlonglong) 0, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) p2, FolderStatusDelegate::SyncProgressBytes2);

// strip off the server prefix from the file name
QString shortFile(file);
if(shortFile.startsWith(QLatin1String("ownclouds://")) ||
shortFile.startsWith(QLatin1String("owncloud://")) ) {
// rip off the whole ownCloud URL.
Folder *f = FolderMan::instance()->folder(folder);
if( f ) {
QString regexp = QString("^owncloud[s]*://.*/remote.php/webdav/%1/").arg(f->secondPath());
QRegExp re( regexp );
re.setMinimal(true);
shortFile.remove(re);
}
if( item == NULL ) {
return;
}
// Set the verb if up- or download
if( kind != Progress::Context ) {
_kindContext = Progress::asString(kind);
}
QString kindString = _kindContext;
item->setData( kindString, FolderStatusDelegate::SyncFileKind );

if( kind == Progress::EndDownload ||
kind == Progress::EndUpload ) { // File upload/download finished.
item->setData( 100, FolderStatusDelegate::SyncProgressPercent1);
item->setData( 100, FolderStatusDelegate::SyncProgressPercent2);
item->setData( (qlonglong) _lastSyncProgress, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) _lastSyncProgress, FolderStatusDelegate::SyncProgressBytes2);
item->setData( tr("Finished"), FolderStatusDelegate::SyncFileProgressString);

// 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);
} else if( kind == Progress::StartDownload ||
kind == Progress::StartUpload ) { // File upload starts.
if( _hideProgressTimers.contains(item) ) {
// The timer is still running.
QTimer *t = _hideProgressTimers.take(item);
t->stop();
t->deleteLater();
}
item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace );
item->setData( 0, FolderStatusDelegate::SyncProgressPercent1);
item->setData( 100, FolderStatusDelegate::SyncProgressPercent2);
item->setData( (qlonglong) 0, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) p2, FolderStatusDelegate::SyncProgressBytes2);

// strip off the server prefix from the file name
QString shortFile(file);
if(shortFile.startsWith(QLatin1String("ownclouds://")) ||
shortFile.startsWith(QLatin1String("owncloud://")) ) {
// rip off the whole ownCloud URL.
Folder *f = FolderMan::instance()->folder(folder);
if( f ) {
QString regexp = QString("^owncloud[s]*://.*/remote.php/webdav/%1/").arg(f->secondPath());
QRegExp re( regexp );
re.setMinimal(true);
shortFile.remove(re);
}
// Set the verb if up- or download
QString kindString = Progress::asString(kind);

shortFile = kindString + QLatin1String(" ") + shortFile;
item->setData( shortFile, FolderStatusDelegate::SyncFileName );
} else { // File progress
// item->setData( int(_progressFactor * p1), FolderStatusDelegate::SyncProgressPercent1);
item->setData( (qlonglong) p1, FolderStatusDelegate::SyncProgressBytes1);
_lastSyncProgress = p1;

}
item->setData( shortFile, FolderStatusDelegate::SyncFileName );
item->setData( tr("Start"), FolderStatusDelegate::SyncFileProgressString);
} else { // File progress
item->setData( (qlonglong) p1, FolderStatusDelegate::SyncProgressBytes1);
item->setData( (qlonglong) p2, FolderStatusDelegate::SyncProgressBytes2);
item->setData( (qlonglong) _lastOverallProgress+p1, FolderStatusDelegate::OverallProgress1 );
item->setData( tr("Currently"), FolderStatusDelegate::SyncFileProgressString);

_lastSyncProgress = p1;
}

ui->_folderList->repaint();
Expand Down
2 changes: 2 additions & 0 deletions src/mirall/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ protected slots:
QHash<QStandardItem*, QTimer*> _hideProgressTimers;
QTimer *_timer;
long _lastSyncProgress;
QString _kindContext;
qlonglong _lastOverallProgress;
};

} // namespace Mirall
Expand Down
14 changes: 1 addition & 13 deletions src/mirall/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,19 +635,7 @@ void Folder::slotCSyncFinished()

void Folder::slotFileTransmissionProgress(Progress::Kind kind, const QString& file ,long p1, long p2)
{
if( kind == Progress::StartDownload ) {
_progressKind = Progress::Download;
}
if( kind == Progress::StartUpload ) {
_progressKind = Progress::Upload;
}

// qDebug() << "Upload Progress: " << file << p1 << p2;
ProgressDispatcher::instance()->setFolderProgress( _progressKind, alias(), file, p1, p2 );

if( kind == Progress::EndDownload || kind == Progress::EndUpload ) {
_progressKind = Progress::Inactive;
}
ProgressDispatcher::instance()->setFolderProgress( kind, alias(), file, p1, p2 );
}

void Folder::slotOverallTransmissionProgress( const QString& fileName, int fileNo, int fileCnt,
Expand Down
122 changes: 26 additions & 96 deletions src/mirall/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,24 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &

QFontMetrics subFm( subFont );
QFontMetrics aliasFm( aliasFont );
QFontMetrics progressFm( progressFont );

int aliasMargin = aliasFm.height()/2;
int margin = subFm.height()/4;

QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
QString aliasText = qvariant_cast<QString>(index.data(FolderAliasRole));
QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
QString remotePath = qvariant_cast<QString>(index.data(FolderSecondPathRole));
QString errorText = qvariant_cast<QString>(index.data(FolderErrorMsg));
QString syncFile = qvariant_cast<QString>(index.data(SyncFileName));
int progressPercent1 = qvariant_cast<int>(index.data(SyncProgressPercent1));
int progressPercent2 = qvariant_cast<int>(index.data(SyncProgressPercent2));
qlonglong fileBytes1 = qvariant_cast<qlonglong>(index.data(SyncProgressBytes1));
qlonglong fileBytes2 = qvariant_cast<qlonglong>(index.data(SyncProgressBytes2));

qlonglong overallBytes1 = qvariant_cast<qlonglong>(index.data(OverallProgress1));
qlonglong overallBytes2 = qvariant_cast<qlonglong>(index.data(OverallProgress2));
QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
QString aliasText = qvariant_cast<QString>(index.data(FolderAliasRole));
QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
QString remotePath = qvariant_cast<QString>(index.data(FolderSecondPathRole));
QString errorText = qvariant_cast<QString>(index.data(FolderErrorMsg));
QString syncFile = qvariant_cast<QString>(index.data(SyncFileName));
QString syncFileKind = qvariant_cast<QString>(index.data(SyncFileKind));
QString syncFileProgress = qvariant_cast<QString>(index.data(SyncFileProgressString));
qlonglong fileBytes1 = qvariant_cast<qlonglong>(index.data(SyncProgressBytes1));
qlonglong fileBytes2 = qvariant_cast<qlonglong>(index.data(SyncProgressBytes2));

qlonglong overallBytes1 = qvariant_cast<qlonglong>(index.data(OverallProgress1));
qlonglong overallBytes2 = qvariant_cast<qlonglong>(index.data(OverallProgress2));
int currentFileCount = qvariant_cast<int>(index.data(OverallFileNo));
int overallFileCount = qvariant_cast<int>(index.data(OverallFileCount));

Expand Down Expand Up @@ -233,31 +234,30 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
}
h += aliasMargin;

// Sync File Progress Bar: Show it if syncFile is not empty.
if( !syncFile.isEmpty()) {
int fileNameTextHeight = subFm.boundingRect(tr("File")).height();
int barHeight = fileNameTextHeight;
int overallWidth = option.rect.width()-2*aliasMargin;

painter->save();
// painter->setBrush( option.palette.brightText() );
// painter->drawRoundedRect( progressRect, 2, 2 ); // do not draw the box.

// Sizes-Text
QString s1 = Utility::octetsToString( overallBytes1+fileBytes1 );
QString s1 = Utility::octetsToString( overallBytes1 );
QString s2 = Utility::octetsToString( overallBytes2 );
QString overallSyncString = tr("%1 of %2, file %3 of %4").arg(s1).arg(s2).arg(currentFileCount).arg(overallFileCount);

QRect octetRect = subFm.boundingRect( overallSyncString );
int progressTextWidth = octetRect.width();

// Overall Bar.
// Overall Progress Bar.
QRect pBRect;
pBRect.setTop( h );
pBRect.setLeft( iconRect.left());
pBRect.setHeight(barHeight);
pBRect.setWidth( overallWidth - progressTextWidth - margin );

int overallPercent = (overallBytes1+fileBytes1) *100.0/overallBytes2;
int overallPercent = (overallBytes1) *100.0/overallBytes2;
QStyleOptionProgressBarV2 pBarOpt;
pBarOpt.state = option.state | QStyle::State_Horizontal;
pBarOpt.minimum = 0;
Expand All @@ -278,93 +278,23 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
painter->setFont(progressFont);
painter->drawText( overallProgressRect, Qt::AlignRight+Qt::AlignVCenter, overallSyncString);

s1 = Utility::octetsToString( fileBytes2);
octetRect = subFm.boundingRect( tr("%1 of %2").arg(s1).arg(s1) );
progressTextWidth = octetRect.width()+20;
// Individual File Progress
s1 = Utility::octetsToString( fileBytes1);
s2 = Utility::octetsToString( fileBytes2);

QRect fileRect;
fileRect.setTop( pBRect.bottom() + margin);
fileRect.setLeft( iconRect.left());
fileRect.setWidth( overallWidth - margin - progressTextWidth );
fileRect.setWidth(overallWidth);
fileRect.setHeight(fileNameTextHeight);
painter->drawText( fileRect, syncFile );

QRect fileProgressRect;
fileProgressRect.setTop(pBRect.bottom()+margin);
fileProgressRect.setLeft(fileRect.right()+margin);
fileProgressRect.setWidth(progressTextWidth);
fileProgressRect.setHeight(fileNameTextHeight);
s1 = Utility::octetsToString(fileBytes1);
s2 = Utility::octetsToString(fileBytes2);
QString fileProgressString = tr("%1 of %2").arg(s1).arg(s2);
painter->drawText( fileProgressRect, Qt::AlignRight+Qt::AlignVCenter, fileProgressString );
}
#if 0
/* Display the sync progress. */
if( !syncFile.isEmpty() ) {
int fileNameTextHeight = subFm.boundingRect(tr("File")).height();
int barHeight = fileNameTextHeight;

QRect progressRect;
progressRect.setLeft( iconRect.left());
progressRect.setTop( localPathRect.bottom()+margin );
progressRect.setHeight( 3 * margin + fileNameTextHeight + barHeight );
progressRect.setRight( option.rect.right()-aliasMargin);

painter->save();
// painter->setBrush( option.palette.brightText() );
// painter->drawRoundedRect( progressRect, 2, 2 ); // do not draw the box.

painter->setFont(progressFont);

QRect fileNameRect;
fileNameRect.setTop(progressRect.top() + margin);
fileNameRect.setLeft(progressRect.left() + margin);
fileNameRect.setWidth( progressRect.width() - 2*margin );
fileNameRect.setHeight(fileNameTextHeight);

QString pText = subFm.elidedText( tr("File %1: ").arg(syncFile), Qt::ElideLeft, fileNameRect.width());
painter->drawText(fileNameRect, pText);

// Sizes-Text
QString s1 = Utility::octetsToString( progressBytes2 );
QRect octetRect = subFm.boundingRect( tr("%1 of %2").arg(s1).arg(s1) );
int progressTextWidth = octetRect.width()+20;

QRect pBRect;
pBRect.setTop( fileNameRect.bottom() + margin );
pBRect.setLeft( fileNameRect.left());
pBRect.setHeight(barHeight);
pBRect.setWidth( fileNameRect.width() - progressTextWidth - margin );
QString fileProgressString = tr("%1 %2 %3 (%4 of %5)").arg(syncFileProgress).arg(syncFileKind).arg(syncFile).arg(s1).arg(s2);
QString elidedProgress = progressFm.elidedText(fileProgressString, Qt::ElideLeft, fileRect.width());
painter->drawText( fileRect, Qt::AlignLeft+Qt::AlignVCenter, elidedProgress);

QStyleOptionProgressBarV2 pBarOpt;
pBarOpt.state = option.state | QStyle::State_Horizontal;
pBarOpt.minimum = 0;
pBarOpt.maximum = progressPercent2;
pBarOpt.progress = progressPercent1;
pBarOpt.orientation = Qt::Horizontal;
pBarOpt.palette = option.palette;
pBarOpt.rect = pBRect;

QApplication::style()->drawControl( QStyle::CE_ProgressBar, &pBarOpt, painter );

QRect sizeRect;
sizeRect.setTop(pBRect.top());
sizeRect.setHeight(pBRect.height());

sizeRect.setLeft(pBRect.right() + margin);
sizeRect.setWidth( progressTextWidth );
QString ps1 = Utility::octetsToString( progressBytes1 );
QString ps2 = Utility::octetsToString( progressBytes2 );

painter->drawText(sizeRect, tr("%1 of %2").arg(ps1).arg(ps2));
painter->restore();

}
#endif
// painter->drawText(lastSyncRect, tr("Last Sync: %1").arg( statusText ));
// painter->drawText(statusRect, tr("Sync Status: %1").arg( syncStatus ));
painter->restore();

}

bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
Expand Down
2 changes: 2 additions & 0 deletions src/mirall/folderstatusmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class FolderStatusDelegate : public QStyledItemDelegate
FolderSyncEnabled,
FolderStatusIconRole,
SyncFileName,
SyncFileKind,
SyncFileProgressString, // stuff like Currently ... or Finished...
SyncProgressPercent1,
SyncProgressPercent2,
SyncProgressBytes1,
Expand Down

0 comments on commit 274f59f

Please sign in to comment.