From f09328c13c9446a4bbc63f1ee4a433301d4bac32 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 16 Nov 2013 19:29:50 +0200 Subject: [PATCH] Fix inhibit system functionality. Closes #766. --- src/mainwindow.cpp | 6 +----- src/qtlibtorrent/torrentmodel.cpp | 18 ++++++++++++++++++ src/qtlibtorrent/torrentmodel.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fad5791d1..d4e85a436 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1409,11 +1409,7 @@ void MainWindow::on_actionAutoShutdown_system_toggled(bool enabled) void MainWindow::checkForActiveTorrents() { - const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport(); - if (report.nb_active > 0) // Active torrents are present; prevent system from suspend - m_pwr->setActivityState(true); - else - m_pwr->setActivityState(false); + m_pwr->setActivityState(transferList->getSourceModel()->inhibitSystem()); } QIcon MainWindow::getSystrayIcon() const diff --git a/src/qtlibtorrent/torrentmodel.cpp b/src/qtlibtorrent/torrentmodel.cpp index d51b2665e..785cccb63 100644 --- a/src/qtlibtorrent/torrentmodel.cpp +++ b/src/qtlibtorrent/torrentmodel.cpp @@ -483,3 +483,21 @@ void TorrentModel::handleTorrentAboutToBeRemoved(const QTorrentHandle &h) emit torrentAboutToBeRemoved(m_torrents.at(row)); } } + +bool TorrentModel::inhibitSystem() +{ + QList::const_iterator it = m_torrents.constBegin(); + QList::const_iterator itend = m_torrents.constEnd(); + for ( ; it != itend; ++it) { + switch((*it)->data(TorrentModelItem::TR_STATUS).toInt()) { + case TorrentModelItem::STATE_DOWNLOADING: + case TorrentModelItem::STATE_STALLED_DL: + case TorrentModelItem::STATE_SEEDING: + case TorrentModelItem::STATE_STALLED_UP: + return true; + default: + break; + } + } + return false; +} diff --git a/src/qtlibtorrent/torrentmodel.h b/src/qtlibtorrent/torrentmodel.h index c858df818..94e9dcae9 100644 --- a/src/qtlibtorrent/torrentmodel.h +++ b/src/qtlibtorrent/torrentmodel.h @@ -94,6 +94,7 @@ public: TorrentStatusReport getTorrentStatusReport() const; Qt::ItemFlags flags(const QModelIndex &index) const; void populate(); + bool inhibitSystem(); signals: void torrentAdded(TorrentModelItem *torrentItem);