mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-03-02 11:49:36 -05:00
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
This commit is contained in:
parent
20fd24d7b8
commit
3b1006bfa4
@ -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<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<std::string,ftFileControl*>::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 ;
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
//
|
||||
|
@ -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> 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<std::string>::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<DwlDetails>::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<std::string> used_hashes ;
|
||||
|
||||
// clear all source peers.
|
||||
|
||||
std::list<std::string>::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<DwlDetails>::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<std::string> 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<TransferInfo>::iterator pit;
|
||||
|
@ -602,6 +602,13 @@ p, li { white-space: pre-wrap; }
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="_showCacheTransfers_CB">
|
||||
<property name="text">
|
||||
<string>Show cache transfers</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -658,9 +665,6 @@ p, li { white-space: pre-wrap; }
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -843,8 +847,8 @@ p, li { white-space: pre-wrap; }
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>98</width>
|
||||
<height>28</height>
|
||||
<width>578</width>
|
||||
<height>113</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user