Browse Source

Improved start_All and resume_All functions to detect if a torrent's state changed or not. This way, it doesn't flood the GUI if the user keeps on clicking on those buttons

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
d12e510fad
  1. 66
      src/GUI.cpp
  2. 10
      src/bittorrent.cpp
  3. 4
      src/bittorrent.h

66
src/GUI.cpp

@ -1300,25 +1300,26 @@ void GUI::configureSession(bool deleteOptions){
void GUI::on_actionPause_All_triggered(){ void GUI::on_actionPause_All_triggered(){
QString fileHash; QString fileHash;
// Pause all torrents // Pause all torrents
BTSession.pauseAllTorrents(); 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 // Create .paused file
QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
paused_file.open(QIODevice::WriteOnly | QIODevice::Text); paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
paused_file.close(); 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.));
DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Paused"))); DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(i, ETA), QVariant((qlonglong)-1)); DLListModel->setData(DLListModel->index(i, ETA), QVariant((qlonglong)-1));
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");
} }
setInfoBar(tr("All downloads were paused.")); setInfoBar(tr("All downloads were paused."));
}
} }
// pause selected items in the list // pause selected items in the list
@ -1351,19 +1352,20 @@ void GUI::on_actionPause_triggered(){
void GUI::on_actionStart_All_triggered(){ void GUI::on_actionStart_All_triggered(){
QString fileHash; QString fileHash;
// Pause all torrents // Pause all torrents
BTSession.resumeAllTorrents(); if(BTSession.resumeAllTorrents()){
// 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();
// Remove .paused file // Remove .paused file
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
// Update DL list items // Update DL list items
DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Connecting...", "i.e: Connecting to the tracker..."))); DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Connecting...", "i.e: Connecting to the tracker...")));
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");
} }
setInfoBar(tr("All downloads were resumed.")); setInfoBar(tr("All downloads were resumed."));
}
} }
// start selected items in the list // start selected items in the list

10
src/bittorrent.cpp

@ -612,25 +612,31 @@ void bittorrent::saveTrackerFile(const QString& hash){
} }
// Pause all torrents in session // Pause all torrents in session
void bittorrent::pauseAllTorrents(){ bool bittorrent::pauseAllTorrents(){
bool paused_torrents = false;
std::vector<torrent_handle> handles = s->get_torrents(); std::vector<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){ for(unsigned int i=0; i<handles.size(); ++i){
torrent_handle h = handles[i]; torrent_handle h = handles[i];
if(h.is_valid() && !h.is_paused()){ if(h.is_valid() && !h.is_paused()){
h.pause(); h.pause();
paused_torrents = true;
} }
} }
return paused_torrents;
} }
// Resume all torrents in session // Resume all torrents in session
void bittorrent::resumeAllTorrents(){ bool bittorrent::resumeAllTorrents(){
bool resumed_torrents = false;
std::vector<torrent_handle> handles = s->get_torrents(); std::vector<torrent_handle> handles = s->get_torrents();
for(unsigned int i=0; i<handles.size(); ++i){ for(unsigned int i=0; i<handles.size(); ++i){
torrent_handle h = handles[i]; torrent_handle h = handles[i];
if(h.is_valid() && h.is_paused()){ if(h.is_valid() && h.is_paused()){
h.resume(); h.resume();
resumed_torrents = true;
} }
} }
return resumed_torrents;
} }
// Add uT PeX extension to bittorrent session // Add uT PeX extension to bittorrent session

4
src/bittorrent.h

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

Loading…
Cancel
Save