fixed bug in display of upload progress

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5228 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-06-17 13:45:17 +00:00
parent be177ecb27
commit 8ef3d851de
2 changed files with 21 additions and 10 deletions

View File

@ -355,13 +355,26 @@ class CompressedChunkMap
static uint32_t getCompressedSize(uint32_t size) { return (size>>5) + !!(size&31) ; } static uint32_t getCompressedSize(uint32_t size) { return (size>>5) + !!(size&31) ; }
uint32_t filledChunks(uint32_t nbchks) uint32_t filledChunks(uint32_t nbchks) const
{ {
uint32_t res = 0 ; uint32_t res = 0 ;
for(uint32_t i=0;i<std::min(nbchks,(uint32_t)_map.size()*32);++i) for(uint32_t i=0;i<std::min(nbchks,(uint32_t)_map.size()*32);++i)
res += operator[](i) ; res += operator[](i) ;
return res ; return res ;
} }
uint64_t computeProgress(uint64_t total_size,uint32_t chunk_size) const
{
if(total_size == 0)
return 0 ;
uint32_t nbchks = (uint32_t)((total_size + (uint64_t)chunk_size - 1) / (uint64_t)chunk_size) ;
uint32_t residue = total_size%chunk_size ;
if(residue && operator[](nbchks-1))
return (filledChunks(nbchks)-1)*chunk_size + (total_size%chunk_size) ;
else
return filledChunks(nbchks)*chunk_size ;
}
inline bool operator[](uint32_t i) const { return (_map[i >> 5] & (1 << (i & 31))) > 0 ; } inline bool operator[](uint32_t i) const { return (_map[i >> 5] & (1 << (i & 31))) > 0 ; }
inline void set(uint32_t j) { _map[j >> 5] |= (1 << (j & 31)) ; } inline void set(uint32_t j) { _map[j >> 5] |= (1 << (j & 31)) ; }

View File

@ -336,14 +336,14 @@ TransfersDialog::TransfersDialog(QWidget *parent)
resumeAct = new QAction(QIcon(IMAGE_RESUME), tr("Resume"), this); resumeAct = new QAction(QIcon(IMAGE_RESUME), tr("Resume"), this);
connect(resumeAct, SIGNAL(triggered()), this, SLOT(resumeFileTransfer())); connect(resumeAct, SIGNAL(triggered()), this, SLOT(resumeFileTransfer()));
#ifdef USE_NEW_CHUNK_CHECKING_CODE //#ifdef USE_NEW_CHUNK_CHECKING_CODE
// *********WARNING********** // *********WARNING**********
// csoler: this has been suspended because it needs the file transfer to consider a file as complete only if all chunks are // csoler: this has been suspended because it needs the file transfer to consider a file as complete only if all chunks are
// verified by hash. As users are goign to slowly switch to new checking code, this will not be readily available. // verified by hash. As users are goign to slowly switch to new checking code, this will not be readily available.
// //
forceCheckAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Force Check" ), this ); forceCheckAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Force Check" ), this );
connect( forceCheckAct , SIGNAL( triggered() ), this, SLOT( forceCheck() ) ); connect( forceCheckAct , SIGNAL( triggered() ), this, SLOT( forceCheck() ) );
#endif //#endif
cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this ); cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this );
connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) ); connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) );
@ -565,9 +565,9 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint /*point*/ )
if(info.downloadStatus != FT_STATE_COMPLETE) if(info.downloadStatus != FT_STATE_COMPLETE)
{ {
#ifdef USE_NEW_CHUNK_CHECKING_CODE //#ifdef USE_NEW_CHUNK_CHECKING_CODE
contextMnu.addAction( forceCheckAct); contextMnu.addAction( forceCheckAct);
#endif //#endif
contextMnu.addAction( cancelAct); contextMnu.addAction( cancelAct);
} }
@ -1027,9 +1027,7 @@ void TransfersDialog::insertTransfers()
// transmit the completion info. // transmit the completion info.
// //
uint32_t chunk_size = 1024*1024 ; uint32_t chunk_size = 1024*1024 ;
uint32_t nb_chunks = (uint32_t)(info.size / (uint64_t)(chunk_size) ) ; uint32_t nb_chunks = (uint32_t)((info.size + (uint64_t)chunk_size - 1) / (uint64_t)(chunk_size)) ;
if((info.size % (uint64_t)chunk_size) != 0)
++nb_chunks ;
uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ; uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ;
pinfo.type = FileProgressInfo::UPLOAD_LINE ; pinfo.type = FileProgressInfo::UPLOAD_LINE ;
@ -1037,8 +1035,8 @@ void TransfersDialog::insertTransfers()
if(filled_chunks > 0 && nb_chunks > 0) if(filled_chunks > 0 && nb_chunks > 0)
{ {
pinfo.progress = filled_chunks*100.0/nb_chunks ; completed = pinfo.cmap.computeProgress(info.size,chunk_size) ;
completed = std::min(info.size,((uint64_t)filled_chunks)*chunk_size) ; // we use min, because the last chunk might be smaller than chunk_size. pinfo.progress = completed / (float)info.size * 100.0f ;
} }
else else
{ {