From 5cd376d2c3e1af685075742416ac6f9b5e616705 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 14 Nov 2010 19:22:39 +0000 Subject: [PATCH] Code clean up --- src/qtlibtorrent/qbtsession.cpp | 26 ++++++++++++++------------ src/transferlistwidget.cpp | 22 ---------------------- src/transferlistwidget.h | 3 --- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 0677a9cf7..68737c7cf 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -802,12 +802,13 @@ void QBtSession::pauseAllTorrents() { std::vector torrents = s->get_torrents(); std::vector::iterator torrentIT; for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { - QTorrentHandle h = QTorrentHandle(*torrentIT); - if(!h.is_valid()) continue; - if(!h.is_paused()) { - h.pause(); - emit pausedTorrent(h); - } + try { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(!h.is_paused()) { + h.pause(); + emit pausedTorrent(h); + } + } catch(invalid_handle&) {} } } @@ -819,12 +820,13 @@ void QBtSession::resumeAllTorrents() { std::vector torrents = s->get_torrents(); std::vector::iterator torrentIT; for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { - QTorrentHandle h = QTorrentHandle(*torrentIT); - if(!h.is_valid()) continue; - if(h.is_paused()) { - h.resume(); - emit resumedTorrent(h); - } + try { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(h.is_paused()) { + h.resume(); + emit resumedTorrent(h); + } + } catch(invalid_handle&) {} } } diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 199a25763..394fddb08 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -131,10 +131,6 @@ TorrentModel* TransferListWidget::getSourceModel() const { return listModel; } -int TransferListWidget::getNbTorrents() const { - return listModel->rowCount(); -} - void TransferListWidget::previewFile(QString filePath) { #ifdef Q_WS_WIN QDesktopServices::openUrl(QUrl(QString("file:///")+filePath)); @@ -260,15 +256,6 @@ void TransferListWidget::startSelectedTorrents() { } } -void TransferListWidget::startAllTorrents() { - for(int i=0; irowCount(); ++i) { - QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i)); - if(h.is_valid() && h.is_paused()) { - h.resume(); - } - } -} - void TransferListWidget::startVisibleTorrents() { QStringList hashes; for(int i=0; irowCount(); ++i) { @@ -293,15 +280,6 @@ void TransferListWidget::pauseSelectedTorrents() { } } -void TransferListWidget::pauseAllTorrents() { - for(int i=0; irowCount(); ++i) { - QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i)); - if(h.is_valid() && !h.is_paused()) { - h.pause(); - } - } -} - void TransferListWidget::pauseVisibleTorrents() { QStringList hashes; for(int i=0; irowCount(); ++i) { diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 122c053d3..da672b8bd 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -50,7 +50,6 @@ class TransferListWidget: public QTreeView { public: TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession* BTSession); ~TransferListWidget(); - int getNbTorrents() const; TorrentModel* getSourceModel() const; public slots: @@ -58,10 +57,8 @@ public slots: void setRefreshInterval(int t); void setSelectedTorrentsLocation(); void startSelectedTorrents(); - void startAllTorrents(); void startVisibleTorrents(); void pauseSelectedTorrents(); - void pauseAllTorrents(); void pauseVisibleTorrents(); void deleteSelectedTorrents(); void deleteVisibleTorrents();