Browse Source

- Improved start/Pause & start_all/pause_all functions

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
c6285d8f67
  1. 5
      TODO
  2. 33
      src/GUI.cpp
  3. 55
      src/bittorrent.cpp
  4. 6
      src/bittorrent.h
  5. 2
      src/src.pro

5
TODO

@ -49,3 +49,8 @@
- upload/download limit per torrent - upload/download limit per torrent
- double free or corruption on exit - double free or corruption on exit
- Crash due to connection_queue - Crash due to connection_queue
LANGUAGES UPDATED:
- French
- English
- Japanese
- Swedish

33
src/GUI.cpp

@ -588,6 +588,8 @@ void GUI::updateDlList(bool force){
setRowColor(row, "red"); setRowColor(row, "red");
BTSession->pauseTorrent(fileHash); BTSession->pauseTorrent(fileHash);
continue; continue;
}else{
qDebug("%s should be paused but it hasn't finished checking yet", (const char*)DLListModel->index(row, NAME).data().toString().toUtf8());
} }
} }
if(delayedSorting && BTSession->getUncheckedTorrentsList().indexOf(fileHash) != -1){ if(delayedSorting && BTSession->getUncheckedTorrentsList().indexOf(fileHash) != -1){
@ -1370,16 +1372,12 @@ void GUI::configureSession(bool deleteOptions){
// Pause All Downloads in DL list // Pause All Downloads in DL list
void GUI::on_actionPause_All_triggered(){ void GUI::on_actionPause_All_triggered(){
QString fileHash; QString fileHash;
// Pause all torrents bool change = false;
if(BTSession->pauseAllTorrents()){
// update download list // update download list
unsigned int nbRows = DLListModel->rowCount(); unsigned int nbRows = DLListModel->rowCount();
for(unsigned int i=0; i<nbRows; ++i){ for(unsigned int i=0; i<nbRows; ++i){
fileHash = DLListModel->data(DLListModel->index(i, HASH)).toString(); fileHash = DLListModel->data(DLListModel->index(i, HASH)).toString();
// Create .paused file if(BTSession->pauseTorrent(fileHash)){
QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
paused_file.close();
// Update DL list items // Update DL list items
DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.)); DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.));
DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.)); DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.));
@ -1387,9 +1385,11 @@ void GUI::on_actionPause_All_triggered(){
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole); DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(i, SEEDSLEECH), QVariant("0/0")); DLListModel->setData(DLListModel->index(i, SEEDSLEECH), QVariant("0/0"));
setRowColor(i, "red"); setRowColor(i, "red");
change = true;
} }
setInfoBar(tr("All downloads were paused."));
} }
if(change)
setInfoBar(tr("All downloads were paused."));
} }
// pause selected items in the list // pause selected items in the list
@ -1400,9 +1400,7 @@ void GUI::on_actionPause_triggered(){
if(index.column() == NAME){ if(index.column() == NAME){
// Get the file name // Get the file name
QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString();
if(!BTSession->isPaused(fileHash)){ if(BTSession->pauseTorrent(fileHash)){
// Pause the torrent
BTSession->pauseTorrent(fileHash);
// Update DL status // Update DL status
int row = index.row(); int row = index.row();
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0)); DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0));
@ -1420,21 +1418,20 @@ void GUI::on_actionPause_triggered(){
// Resume All Downloads in DL list // Resume All Downloads in DL list
void GUI::on_actionStart_All_triggered(){ void GUI::on_actionStart_All_triggered(){
QString fileHash; QString fileHash;
// Pause all torrents
if(BTSession->resumeAllTorrents()){
// update download list
unsigned int nbRows = DLListModel->rowCount(); unsigned int nbRows = DLListModel->rowCount();
bool change = false;
for(unsigned int i=0; i<nbRows; ++i){ for(unsigned int i=0; i<nbRows; ++i){
fileHash = DLListModel->data(DLListModel->index(i, HASH)).toString(); fileHash = DLListModel->data(DLListModel->index(i, HASH)).toString();
// Remove .paused file // Remove .paused file
if(QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){ if(BTSession->resumeTorrent(fileHash)){
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(i, "grey"); setRowColor(i, "grey");
change = true;
} }
} }
if(change)
setInfoBar(tr("All downloads were resumed.")); setInfoBar(tr("All downloads were resumed."));
} }
}
// start selected items in the list // start selected items in the list
void GUI::on_actionStart_triggered(){ void GUI::on_actionStart_triggered(){
@ -1444,11 +1441,7 @@ void GUI::on_actionStart_triggered(){
if(index.column() == NAME){ if(index.column() == NAME){
// Get the file name // Get the file name
QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString();
if(BTSession->isPaused(fileHash)){ if(BTSession->resumeTorrent(fileHash)){
// Resume the torrent
BTSession->resumeTorrent(fileHash);
// Delete .paused file
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
// Update DL status // Update DL status
int row = index.row(); int row = index.row();
setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str()))); setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str())));

55
src/bittorrent.cpp

@ -190,33 +190,48 @@ void bittorrent::cleanDeleter(deleteThread* deleter){
} }
// Pause a running torrent // Pause a running torrent
void bittorrent::pauseTorrent(QString hash){ bool bittorrent::pauseTorrent(QString hash){
bool change = false;
torrent_handle h = s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString()))); torrent_handle h = s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString())));
if(h.is_valid() && !h.is_paused()){ if(h.is_valid() && !h.is_paused()){
h.pause(); h.pause();
// Create .paused file change = true;
QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
paused_file.close();
qDebug("Torrent paused successfully"); qDebug("Torrent paused successfully");
}else{ }else{
qDebug("Could not pause torrent, invalid or already paused."); qDebug("Could not pause torrent, invalid or already paused.");
} }
// Create .paused file if necessary
if(!QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")){
QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
paused_file.close();
}
// Remove from the list of torrents to pause after checking
int index = torrentsToPauseAfterChecking.indexOf(hash); int index = torrentsToPauseAfterChecking.indexOf(hash);
if(index != -1) { if(index != -1) {
torrentsToPauseAfterChecking.removeAt(index); torrentsToPauseAfterChecking.removeAt(index);
qDebug("A torrent was paused just after checking, good"); qDebug("A torrent was paused just after checking, good");
} }
return change;
} }
// Resume a torrent in paused state // Resume a torrent in paused state
void bittorrent::resumeTorrent(QString hash){ bool bittorrent::resumeTorrent(QString hash){
bool success = false;
torrent_handle h = s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString()))); torrent_handle h = s->find_torrent(misc::fromString<sha1_hash>((hash.toStdString())));
if(h.is_valid() && h.is_paused()){ if(h.is_valid() && h.is_paused()){
h.resume(); h.resume();
success = true;
}
// Delete .paused file // Delete .paused file
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"))
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
int index = torrentsToPauseAfterChecking.indexOf(hash);
if(index != -1){
torrentsToPauseAfterChecking.removeAt(index);
success = true;
} }
return success;
} }
void bittorrent::loadWebSeeds(QString fileHash){ void bittorrent::loadWebSeeds(QString fileHash){
@ -811,34 +826,6 @@ void bittorrent::saveTrackerFile(QString hash){
tracker_file.close(); tracker_file.close();
} }
// Pause all torrents in session
bool bittorrent::pauseAllTorrents(){
bool paused_torrents = false;
std::vector<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){
torrent_handle h = handles[i];
if(h.is_valid() && !h.is_paused()){
h.pause();
paused_torrents = true;
}
}
return paused_torrents;
}
// Resume all torrents in session
bool bittorrent::resumeAllTorrents(){
bool resumed_torrents = false;
std::vector<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){
torrent_handle h = handles[i];
if(h.is_valid() && h.is_paused()){
h.resume();
resumed_torrents = true;
}
}
return resumed_torrents;
}
// Add uT PeX extension to bittorrent session // Add uT PeX extension to bittorrent session
void bittorrent::enablePeerExchange(){ void bittorrent::enablePeerExchange(){
qDebug("Enabling Peer eXchange"); qDebug("Enabling Peer eXchange");

6
src/bittorrent.h

@ -88,10 +88,8 @@ class bittorrent : public QObject{
void downloadFromUrl(QString url); void downloadFromUrl(QString url);
void downloadFromURLList(const QStringList& url_list); void downloadFromURLList(const QStringList& url_list);
void deleteTorrent(QString hash, bool permanent = false); void deleteTorrent(QString hash, bool permanent = false);
void pauseTorrent(QString hash); bool pauseTorrent(QString hash);
bool pauseAllTorrents(); bool resumeTorrent(QString hash);
bool resumeAllTorrents();
void resumeTorrent(QString hash);
void enableDHT(); void enableDHT();
void disableDHT(); void disableDHT();
void saveDHTEntry(); void saveDHTEntry();

2
src/src.pro

@ -18,10 +18,12 @@ DEFINES += VERSION_BUGFIX=0
contains(DEBUG_MODE, 1){ contains(DEBUG_MODE, 1){
CONFIG += debug CONFIG += debug
CONFIG -= release
message(Debug build!) message(Debug build!)
} }
contains(DEBUG_MODE, 0){ contains(DEBUG_MODE, 0){
CONFIG -= debug CONFIG -= debug
CONFIG += release
message(Release build!) message(Release build!)
} }

Loading…
Cancel
Save