From c582e297734bf47f36800a6ededdb2b59c0b679a Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 1 Mar 2010 22:47:48 +0000 Subject: [PATCH] Added Download Time column to Downloads changed show for Remaining the Filesize which need to be downloaded, on Download Time column show the remaining Time. added to DetailsDialog Download Time label added formating the filesize's for FileTransferInfoWidget git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2470 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/DLListDelegate.cpp | 54 +++++++++++++------ retroshare-gui/src/gui/DLListDelegate.h | 3 +- retroshare-gui/src/gui/DetailsDialog.cpp | 7 ++- retroshare-gui/src/gui/DetailsDialog.h | 1 + retroshare-gui/src/gui/DetailsDialog.ui | 40 +++++++++++++- .../src/gui/FileTransferInfoWidget.cpp | 7 +-- retroshare-gui/src/gui/TransfersDialog.cpp | 21 +++++--- retroshare-gui/src/gui/TransfersDialog.h | 2 +- 8 files changed, 104 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/DLListDelegate.cpp b/retroshare-gui/src/gui/DLListDelegate.cpp index 1d821d9b7..63f79bb71 100644 --- a/retroshare-gui/src/gui/DLListDelegate.cpp +++ b/retroshare-gui/src/gui/DLListDelegate.cpp @@ -53,6 +53,7 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti qlonglong remaining; QString temp , status; qlonglong completed; + qlonglong downloadtime; //set text color QVariant value = index.data(Qt::TextColorRole); @@ -102,23 +103,22 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti break; case REMAINING: remaining = index.data().toLongLong(); - minutes = remaining / 60; - seconds = remaining % 60; - hours = minutes / 60; - minutes = minutes % 60 ; - days = hours / 24; - hours = hours % 24 ; - if(days > 0) { - temp = QString::number(days)+"d "+QString::number(hours)+"h" ; - } else if(hours > 0 || days > 0) { - temp = QString::number(hours)+"h "+QString::number(minutes)+"m" ; - } else if(minutes > 0 || hours > 0) { - temp = QString::number(minutes)+"m"+QString::number(seconds)+"s" ; - } else if(seconds > 0) { - temp = QString::number(seconds)+"s" ; - } else - temp = "" ; - painter->drawText(option.rect, Qt::AlignCenter, temp); + if(remaining <= 0){ + temp = ""; + } else { + multi = 1.0; + for(int i = 0; i < 5; ++i) { + if (remaining < 1024) { + remaining = index.data().toLongLong(); + temp.sprintf("%.2f ", remaining / multi); + temp += byteUnits[i]; + break; + } + remaining /= 1024; + multi *= 1024.0; + } + } + painter->drawText(option.rect, Qt::AlignRight, temp); break; case COMPLETED: completed = index.data().toLongLong(); @@ -179,6 +179,26 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti } painter->drawText(option.rect, Qt::AlignCenter, newopt.text); break; + case DOWNLOADTIME: + downloadtime = index.data().toLongLong(); + minutes = downloadtime / 60; + seconds = downloadtime % 60; + hours = minutes / 60; + minutes = minutes % 60 ; + days = hours / 24; + hours = hours % 24 ; + if(days > 0) { + temp = QString::number(days)+"d "+QString::number(hours)+"h" ; + } else if(hours > 0 || days > 0) { + temp = QString::number(hours)+"h "+QString::number(minutes)+"m" ; + } else if(minutes > 0 || hours > 0) { + temp = QString::number(minutes)+"m"+QString::number(seconds)+"s" ; + } else if(seconds > 0) { + temp = QString::number(seconds)+"s" ; + } else + temp = "" ; + painter->drawText(option.rect, Qt::AlignCenter, temp); + break; case NAME: // decoration value = index.data(Qt::DecorationRole); diff --git a/retroshare-gui/src/gui/DLListDelegate.h b/retroshare-gui/src/gui/DLListDelegate.h index 1f309ce9e..0e69f70cf 100644 --- a/retroshare-gui/src/gui/DLListDelegate.h +++ b/retroshare-gui/src/gui/DLListDelegate.h @@ -36,7 +36,8 @@ #define STATUS 6 #define PRIORITY 7 #define REMAINING 8 -#define ID 9 +#define DOWNLOADTIME 9 +#define ID 10 #define MAX_CHAR_TMP 128 diff --git a/retroshare-gui/src/gui/DetailsDialog.cpp b/retroshare-gui/src/gui/DetailsDialog.cpp index 2abcc01c3..1f832dafd 100644 --- a/retroshare-gui/src/gui/DetailsDialog.cpp +++ b/retroshare-gui/src/gui/DetailsDialog.cpp @@ -178,7 +178,12 @@ void DetailsDialog::setCompleted(const qulonglong & completed) void DetailsDialog::setRemaining(const qulonglong & remaining) { - ui.remaining_line->setText(misc::userFriendlyDuration(remaining)); + ui.remaining_line->setText(misc::friendlyUnit(remaining)); +} + +void DetailsDialog::setDownloadtime(const qulonglong & downloadtime) +{ + ui.downloadtime_line->setText(misc::userFriendlyDuration(downloadtime)); } void DetailsDialog::setLink(const QString & link) diff --git a/retroshare-gui/src/gui/DetailsDialog.h b/retroshare-gui/src/gui/DetailsDialog.h index 21450eac2..7f7325a73 100644 --- a/retroshare-gui/src/gui/DetailsDialog.h +++ b/retroshare-gui/src/gui/DetailsDialog.h @@ -59,6 +59,7 @@ public slots: void setDatarate(const double & datarate); void setCompleted(const qulonglong & completed); void setRemaining(const qulonglong & remaining) ; + void setDownloadtime(const qulonglong & downloadtime); void setType(const QString & type); diff --git a/retroshare-gui/src/gui/DetailsDialog.ui b/retroshare-gui/src/gui/DetailsDialog.ui index ab7c0ae58..010699764 100644 --- a/retroshare-gui/src/gui/DetailsDialog.ui +++ b/retroshare-gui/src/gui/DetailsDialog.ui @@ -7,7 +7,7 @@ 0 0 525 - 448 + 480 @@ -31,7 +31,7 @@ General - + @@ -291,6 +291,42 @@ p, li { white-space: pre-wrap; } + + + Date + + + + + + Download time: + + + + + + + Download Time Label + + + + + + + Qt::Horizontal + + + + 274 + 20 + + + + + + + + Qt::Vertical diff --git a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp index 117179372..a5b28f021 100644 --- a/retroshare-gui/src/gui/FileTransferInfoWidget.cpp +++ b/retroshare-gui/src/gui/FileTransferInfoWidget.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "util/misc.h" #include "FileTransferInfoWidget.h" // Variables to decide of display behaviour. Should be adapted to window size. @@ -218,13 +219,13 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info y += block_sep ; y += text_height ; painter->drawText(20,y,tr("File hash: ")) ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash)) ; y += block_sep ; - y += text_height ; painter->drawText(20,y,tr("File size: ")) ; painter->drawText(tab_size,y,QString::number(info.file_size)) ; + y += text_height ; painter->drawText(20,y,tr("File size: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(info.file_size)) ; y += block_sep ; - y += text_height ; painter->drawText(20,y,tr("Chunk size: ")) ; painter->drawText(tab_size,y,QString::number(info.chunk_size)) ; + y += text_height ; painter->drawText(20,y,tr("Chunk size: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(info.chunk_size)) ; y += block_sep ; y += text_height ; painter->drawText(20,y,tr("Number of chunks: ")) ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ; y += block_sep ; - y += text_height ; painter->drawText(20,y,tr("Transfered: ")) ; painter->drawText(tab_size,y,QString::number(nfo.transfered)) ; + y += text_height ; painter->drawText(20,y,tr("Transfered: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(nfo.transfered)) ; y += block_sep ; y += text_height ; painter->drawText(20,y,tr("Number of sources: ")) ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ; y += block_sep ; diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 3c91a77fc..ceacf7165 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -93,7 +93,8 @@ TransfersDialog::TransfersDialog(QWidget *parent) DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources")); DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status")); DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Speed / Queue priority")); - DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining", "i.e: Estimated Time of Arrival / Time left")); + DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining")); + DLListModel->setHeaderData(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left")); DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID")); ui.downloadList->setModel(DLListModel); ui.downloadList->hideColumn(ID); @@ -423,7 +424,7 @@ TransfersDialog::~TransfersDialog() int TransfersDialog::addItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong fileSize, const FileProgressInfo& pinfo, double dlspeed, - const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining) + const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime) { int row; QList list = DLListModel->findItems(coreID, Qt::MatchExactly, ID); @@ -444,6 +445,7 @@ int TransfersDialog::addItem(const QString& symbol, const QString& name, const Q DLListModel->setData(DLListModel->index(row, STATUS), QVariant((QString)status)); DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((QString)priority)); DLListModel->setData(DLListModel->index(row, REMAINING), QVariant((qlonglong)remaining)); + DLListModel->setData(DLListModel->index(row, DOWNLOADTIME), QVariant((qlonglong)downloadtime)); DLListModel->setData(DLListModel->index(row, ID), QVariant((QString)coreID)); @@ -688,8 +690,10 @@ void TransfersDialog::insertTransfers() { default: priority = tr("Average");break; } - qlonglong completed = info.transfered; - qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0); + qlonglong completed = info.transfered; + qlonglong remaining = info.size - info.transfered; + qlonglong downloadtime = (info.size - info.transfered) / (info.tfRate * 1024.0); + FileChunksInfo fcinfo ; if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo)) @@ -701,7 +705,7 @@ void TransfersDialog::insertTransfers() { pinfo.progress = completed*100.0/info.size ; pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ; - int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining); + int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime); /* continue to next download item if no peers to add */ if (!info.peers.size()) continue; @@ -770,7 +774,7 @@ void TransfersDialog::insertTransfers() { addItem("", QString::fromUtf8(dit->fname.c_str()), QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0, - tr("Queued"), "", 0, 0); + tr("Queued"), "", 0, 0, 0); } @@ -993,6 +997,8 @@ void TransfersDialog::showDetailsDialog() qulonglong fcompleted = ind.model ()->data (ind.model ()->index (ind.row (), COMPLETED)).toULongLong() ; qulonglong fremaining = ind.model ()->data (ind.model ()->index (ind.row (), REMAINING)).toULongLong() ; + qulonglong fdownloadtime = ind.model ()->data (ind.model ()->index (ind.row (), DOWNLOADTIME)).toULongLong() ; + int nb_select = 0 ; for(int i = 0; i <= DLListModel->rowCount(); i++) @@ -1021,6 +1027,9 @@ void TransfersDialog::showDetailsDialog() detailsdlg->setCompleted(fcompleted); detailsdlg->setRemaining(fremaining); + //Date GroupBox + detailsdlg->setDownloadtime(fdownloadtime); + // retroshare link(s) Tab analyzer.setRetroShareLink (fname, fsize, fhash); detailsdlg->setLink(analyzer.getRetroShareLink ()); diff --git a/retroshare-gui/src/gui/TransfersDialog.h b/retroshare-gui/src/gui/TransfersDialog.h index 4e42b6ea5..96ef432d2 100644 --- a/retroshare-gui/src/gui/TransfersDialog.h +++ b/retroshare-gui/src/gui/TransfersDialog.h @@ -171,7 +171,7 @@ private: Ui::TransfersDialog ui; public slots: - int addItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining); + int addItem(const QString& symbol, const QString& name, const QString& coreID, qlonglong size, const FileProgressInfo& pinfo, double dlspeed, const QString& sources, const QString& status, const QString& priority, qlonglong completed, qlonglong remaining, qlonglong downloadtime); bool addPeerToItem(int row, const QString& name, const QString& coreID, double dlspeed, const QString& status, const FileProgressInfo& peerInfo); void delItem(int row);