From 3b1006bfa47bba853402c81b7dbb9395c385dbe6 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 21 Mar 2010 15:35:20 +0000 Subject: [PATCH] fixed a bug in download queue when ticking inactive files. Added a checkbox for showing cache transfers. Cleaned the dialog cleaning method. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2583 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftcontroller.cc | 19 ++--- libretroshare/src/ft/ftfilecreator.cc | 5 ++ libretroshare/src/ft/ftfilecreator.h | 3 +- retroshare-gui/src/gui/TransfersDialog.cpp | 82 +++++++--------------- retroshare-gui/src/gui/TransfersDialog.ui | 14 ++-- 5 files changed, 51 insertions(+), 72 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 4cab9330e..5a0045eb8 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -57,6 +57,7 @@ * #define CONTROL_DEBUG 1 * #define DEBUG_DWLQUEUE 1 *****/ +#define DEBUG_DWLQUEUE 1 static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds. static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released @@ -410,16 +411,23 @@ void ftController::checkDownloadQueue() // Check for inactive transfers. // time_t now = time(NULL) ; + uint32_t nb_moved = 0 ; // don't move more files than the size of the queue. - for(std::map::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it) + for(std::map::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it) if( it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED - && now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED) + && now > it->second->mCreator->lastRecvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED) { +#ifdef DEBUG_DWLQUEUE + std::cerr << " - Inactive file " << it->second->mName << " at position " << it->second->mQueuePosition << " moved to end of the queue. mState=" << it->second->mState << ", time lapse=" << now - it->second->mCreator->lastRecvTimeStamp() << std::endl ; +#endif locked_bottomQueue(it->second->mQueuePosition) ; #ifdef DEBUG_DWLQUEUE - std::cerr << " - Inactive file " << it->second->mName << " moved to end of the queue" << std::endl ; + std::cerr << " new position: " << it->second->mQueuePosition << std::endl ; + std::cerr << " new state: " << it->second->mState << std::endl ; #endif + it->second->mCreator->resetRecvTimeStamp() ; // very important! + ++nb_moved ; } } @@ -541,11 +549,6 @@ void ftController::locked_swapQueue(uint32_t pos1,uint32_t pos2) locked_checkQueueElement(pos2) ; } -//void ftController::checkQueueElements() -//{ -// for(uint32_t pos=0;pos<_queue.size();++pos) -// checkQueueElement(pos) ; -//} void ftController::locked_checkQueueElement(uint32_t pos) { _queue[pos]->mQueuePosition = pos ; diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 6f19c7e96..d18faa286 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -58,6 +58,11 @@ time_t ftFileCreator::lastRecvTimeStamp() RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ return _last_recv_time_t ; } +void ftFileCreator::resetRecvTimeStamp() +{ + RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ + _last_recv_time_t = time(NULL) ; +} void ftFileCreator::closeFile() { diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index 88b3f7941..d44f02a21 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -76,8 +76,9 @@ class ftFileCreator: public ftFileProvider // removes the designated file source from the chunkmap. void removeFileSource(const std::string& peer_id) ; - // Returns the time stamp of the last data receive. + // Returns resets the time stamp of the last data receive. time_t lastRecvTimeStamp() ; + void resetRecvTimeStamp() ; // actually store data in the file, and update chunks info // diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index a82987734..23a6bfea3 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -201,6 +201,7 @@ TransfersDialog::TransfersDialog(QWidget *parent) #endif + QObject::connect(ui._showCacheTransfers_CB,SIGNAL(toggled(bool)),this,SLOT(insertTransfers())) ; } @@ -629,50 +630,23 @@ void TransfersDialog::insertTransfers() // std::list dwlDetails; // rsFiles->getDwlDetails(dwlDetails); - //first clean the model in case some files are not download anymore - //remove items that are not fiends anymore - int removeIndex = 0; - while (removeIndex < DLListModel->rowCount()) { - std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::EditRole).toString().toStdString(); - std::list::iterator downHashesIt; - bool found = false; - for (downHashesIt = downHashes.begin(); downHashesIt != downHashes.end(); downHashesIt++) { - if (hash == *downHashesIt) { - found = true; - break; - } - } -// if (!found) { -// //look in the queued files -// std::list::iterator dwlDetailsIt; -// for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) { -// if (hash == dwlDetailsIt->hash) { -// found = true; -// break; -// } -// } -// } - if (!found) { - DLListModel->takeRow(removeIndex); - } else { - removeIndex++; - } - } + + + std::set used_hashes ; // clear all source peers. std::list::iterator it; - for (it = downHashes.begin(); it != downHashes.end(); it++) { + for (it = downHashes.begin(); it != downHashes.end(); it++) + { FileInfo info; if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) { //if file transfer is a cache file index file, don't show it continue; } - if ((info.flags & CB_CODE_CACHE)) { - /*(!_show_cache_transfers) &&*/ + if((info.flags & CB_CODE_CACHE) && !ui._showCacheTransfers_CB->isChecked()) continue; - } QString fileName = QString::fromUtf8(info.fname.c_str()); QString fileHash = QString::fromStdString(info.hash); @@ -729,6 +703,7 @@ void TransfersDialog::insertTransfers() pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ; int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime); + used_hashes.insert(info.hash) ; /* continue to next download item if no peers to add */ if (!info.peers.size()) continue; @@ -776,7 +751,7 @@ void TransfersDialog::insertTransfers() // std::cerr << std::endl ; // std::cerr << std::endl ; - std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ; +// std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ; int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo); used_rows.insert(row_id) ; @@ -791,31 +766,22 @@ void TransfersDialog::insertTransfers() if(used_rows.find(r) == used_rows.end()) dlItem->takeRow(r) ; } + // remove hashes that where not shown + //first clean the model in case some files are not download anymore + //remove items that are not fiends anymore + int removeIndex = 0; + while (removeIndex < DLListModel->rowCount()) + { + std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::EditRole).toString().toStdString(); - /* here i will insert files from the download queue - which are - * not started yet and can't be find in FileDownloads - * */ - // std::list::iterator dit; - // for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++) - // { - //// switch (dit->priority) { - //// case 0: priority = tr("Low"); break; - //// case 1: priority = tr("Normal"); break; - //// case 2: priority = tr("High"); break; - //// case 3: priority = tr("Auto"); break; - //// default: priority = tr("Auto"); break; - //// } - // - // FileProgressInfo pinfo ; - // pinfo.progress = 0.0 ; - // pinfo.nb_chunks = 0 ; - // - // addItem("", QString::fromUtf8(dit->fname.c_str()), - // QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0, - // tr("Queued"), "", 0, 0, 0); - // } - // + if(used_hashes.find(hash) == used_hashes.end()) + DLListModel->takeRow(removeIndex); + else + removeIndex++; + } + // Now show upload hashes + // std::list upHashes; rsFiles->FileUploads(upHashes); //first clean the model in case some files are not uploaded anymore @@ -847,7 +813,7 @@ void TransfersDialog::insertTransfers() if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) { continue; } - if (/*(!_show_cache_transfers) &&*/ (info.flags & CB_CODE_CACHE)) + if((info.flags & CB_CODE_CACHE) && !ui._showCacheTransfers_CB->isChecked()) continue ; std::list::iterator pit; diff --git a/retroshare-gui/src/gui/TransfersDialog.ui b/retroshare-gui/src/gui/TransfersDialog.ui index 3c39d21fc..a51faba20 100644 --- a/retroshare-gui/src/gui/TransfersDialog.ui +++ b/retroshare-gui/src/gui/TransfersDialog.ui @@ -602,6 +602,13 @@ p, li { white-space: pre-wrap; } + + + + Show cache transfers + + + @@ -658,9 +665,6 @@ p, li { white-space: pre-wrap; } false - - false - @@ -843,8 +847,8 @@ p, li { white-space: pre-wrap; } 0 0 - 98 - 28 + 578 + 113