From 11ce908e156fa52804bd03f814d4b39d7db0e8a8 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 12 Mar 2010 23:29:50 +0000 Subject: [PATCH] fixed the pause system git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2529 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftcontroller.cc | 24 +++++++++++------ libretroshare/src/ft/ftcontroller.h | 3 ++- libretroshare/src/ft/fttransfermodule.cc | 31 ---------------------- libretroshare/src/ft/fttransfermodule.h | 3 --- libretroshare/src/rsiface/rstypes.h | 1 + retroshare-gui/src/RetroShare.pro | 1 - retroshare-gui/src/gui/TransfersDialog.cpp | 19 ++++++------- 7 files changed, 29 insertions(+), 53 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 19c009ba1..8915517a1 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -277,7 +277,7 @@ void ftController::tickTransfers() // Collect all non queued files. // for(std::map::iterator it(mDownloads.begin()); it != mDownloads.end(); it++) - if(it->second->mState != ftFileControl::QUEUED) + if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED) priority_tab[it->second->mPriority].push_back(it->second->mTransfer) ; // 2 - tick arrays with a probability proportional to priority @@ -412,7 +412,9 @@ void ftController::checkDownloadQueue() time_t now = time(NULL) ; for(std::map::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it) - if(it->second->mState != ftFileControl::QUEUED && now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED) + if( it->second->mState != ftFileControl::QUEUED + && it->second->mState != ftFileControl::PAUSED + && now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED) { locked_bottomQueue(it->second->mQueuePosition) ; #ifdef DEBUG_DWLQUEUE @@ -555,7 +557,7 @@ void ftController::locked_checkQueueElement(uint32_t pos) mTurtle->monitorFileTunnels(_queue[pos]->mName,_queue[pos]->mHash,_queue[pos]->mSize) ; } - if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED) + if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED) { _queue[pos]->mState = ftFileControl::QUEUED ; _queue[pos]->mCreator->closeFile() ; @@ -1315,10 +1317,12 @@ bool ftController::FileCancel(std::string hash) bool ftController::FileControl(std::string hash, uint32_t flags) { -#ifdef CONTROL_DEBUG +//#ifdef CONTROL_DEBUG std::cerr << "ftController::FileControl(" << hash << ","; std::cerr << flags << ")"<::iterator mit=mDownloads.find(hash); if (mit==mDownloads.end()) @@ -1330,14 +1334,15 @@ bool ftController::FileControl(std::string hash, uint32_t flags) } /*find the point to transfer module*/ - ftTransferModule* ft=(mit->second)->mTransfer; switch (flags) { case RS_FILE_CTRL_PAUSE: - ft->pauseTransfer(); + mit->second->mState = ftFileControl::PAUSED ; + std::cerr << "setting state to " << ftFileControl::PAUSED << std::endl ; break; case RS_FILE_CTRL_START: - ft->resumeTransfer(); + mit->second->mState = ftFileControl::DOWNLOADING ; + std::cerr << "setting state to " << ftFileControl::DOWNLOADING << std::endl ; break; default: return false; @@ -1564,6 +1569,9 @@ bool ftController::FileDetails(std::string hash, FileInfo &info) if(it->second->mState == ftFileControl::QUEUED) info.downloadStatus = FT_STATE_QUEUED ; + if(it->second->mState == ftFileControl::PAUSED) + info.downloadStatus = FT_STATE_PAUSED ; + info.tfRate = totalRate; info.size = (it->second)->mSize; diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index ee77ed53f..2dd955f2e 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -69,7 +69,8 @@ class ftFileControl enum { DOWNLOADING = 0, COMPLETED = 1, ERROR_COMPLETION = 2, - QUEUED = 3 + QUEUED = 3, + PAUSED = 4 }; ftFileControl(); diff --git a/libretroshare/src/ft/fttransfermodule.cc b/libretroshare/src/ft/fttransfermodule.cc index 702940211..b4e600903 100644 --- a/libretroshare/src/ft/fttransfermodule.cc +++ b/libretroshare/src/ft/fttransfermodule.cc @@ -403,37 +403,6 @@ bool ftTransferModule::queryInactive() return true; } -bool ftTransferModule::pauseTransfer() -{ - RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ - -/* - std::map::iterator mit; - for(mit = mOnlinePeers.begin(); mit != mOnlinePeers.end(); mit++) - { - (mit->second).state = PQIPEER_SUSPEND; - } -*/ - mFileStatus.stat=ftFileStatus::PQIFILE_PAUSE; - - return 1; -} - -bool ftTransferModule::resumeTransfer() -{ - RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ -/* - std::map::iterator mit; - for(mit = mOnlinePeers.begin(); mit != mOnlinePeers.end(); mit++) - { - (mit->second).state = PQIPEER_IDLE; - } -*/ - mFileStatus.stat=ftFileStatus::PQIFILE_DOWNLOADING; - - return 1; -} - bool ftTransferModule::cancelTransfer() { RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/ diff --git a/libretroshare/src/ft/fttransfermodule.h b/libretroshare/src/ft/fttransfermodule.h index 3d6015308..4a8a7f46b 100644 --- a/libretroshare/src/ft/fttransfermodule.h +++ b/libretroshare/src/ft/fttransfermodule.h @@ -105,7 +105,6 @@ public: PQIFILE_INIT, PQIFILE_NOT_ONLINE, PQIFILE_DOWNLOADING, - PQIFILE_PAUSE, PQIFILE_COMPLETE, PQIFILE_FAIL, PQIFILE_FAIL_CANCEL, @@ -138,8 +137,6 @@ public: bool getFileSources(std::list &peerIds); bool getPeerState(std::string peerId,uint32_t &state,uint32_t &tfRate); uint32_t getDataRate(std::string peerId); - bool pauseTransfer(); - bool resumeTransfer(); bool cancelTransfer(); bool completeFileTransfer(); diff --git a/libretroshare/src/rsiface/rstypes.h b/libretroshare/src/rsiface/rstypes.h index 29fbe93a8..a4168d8c2 100644 --- a/libretroshare/src/rsiface/rstypes.h +++ b/libretroshare/src/rsiface/rstypes.h @@ -45,6 +45,7 @@ const uint32_t FT_STATE_WAITING = 0x0002 ; const uint32_t FT_STATE_DOWNLOADING = 0x0003 ; const uint32_t FT_STATE_COMPLETE = 0x0004 ; const uint32_t FT_STATE_QUEUED = 0x0005 ; +const uint32_t FT_STATE_PAUSED = 0x0006 ; class TransferInfo { diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 4dd2c9df7..59c615d67 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -11,7 +11,6 @@ MOC_DIR = temp/moc #CONFIG += debug debug { - DEFINES += PEERS_DEBUG QMAKE_CXXFLAGS *= -g } diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 3fc50608e..cdd429e10 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -362,7 +362,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point ) for (int i = 0; i < lst.count (); i++) { - if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_WAITING ) + if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_PAUSED ) all_downld = false ; if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_DOWNLOADING ) all_paused = false ; @@ -384,10 +384,6 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point ) if(all_downloading) contextMnu.addMenu( chunkMenu); - if(!all_paused) - contextMnu.addAction( pauseAct); - if(!all_downld) - contextMnu.addAction( resumeAct); if(info.downloadStatus != FT_STATE_COMPLETE) contextMnu.addAction( cancelAct); @@ -406,6 +402,11 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point ) contextMnu.addAction( openfolderAct); contextMnu.addAction( detailsfileAct); contextMnu.addSeparator(); + + if(info.downloadStatus == FT_STATE_PAUSED) + contextMnu.addAction( resumeAct); + else if(info.downloadStatus != FT_STATE_COMPLETE) + contextMnu.addAction( pauseAct); } contextMnu.addAction( clearcompletedAct); @@ -670,7 +671,7 @@ void TransfersDialog::insertTransfers() QString fileName = QString::fromUtf8(info.fname.c_str()); QString fileHash = QString::fromStdString(info.hash); qlonglong fileSize = info.size; - double fileDlspeed = info.tfRate * 1024.0; + double fileDlspeed = (info.downloadStatus==FT_STATE_PAUSED)?0.0:(info.tfRate * 1024.0); /* get the sources (number of online peers) */ int online = 0; @@ -690,6 +691,7 @@ void TransfersDialog::insertTransfers() case FT_STATE_DOWNLOADING: status = tr("Downloading"); break; case FT_STATE_COMPLETE: status = tr("Complete"); break; case FT_STATE_QUEUED: status = tr("Queued"); break; + case FT_STATE_PAUSED: status = tr("Paused"); break; default: status = tr("Unknown"); break; } @@ -751,10 +753,8 @@ void TransfersDialog::insertTransfers() default: status = tr(""); break; } double peerDlspeed = 0; - if ((uint32_t)pit->status == FT_STATE_DOWNLOADING) - { + if ((uint32_t)pit->status == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED) peerDlspeed = pit->tfRate * 1024.0; - } FileProgressInfo peerpinfo ; peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId]; @@ -1125,6 +1125,7 @@ bool TransfersDialog::controlTransferFile(uint32_t flags) std::set::iterator it; getIdOfSelectedItems(items); for (it = items.begin(); it != items.end(); it ++) { + std::cerr << "changing file mode for hash " << (*it)->data(Qt::DisplayRole).toString().toStdString() << " to " << flags << std::endl; result &= rsFiles->FileControl((*it)->data(Qt::DisplayRole).toString().toStdString(), flags); }