Browse Source

Inhibit system sleep while torrents are moving

PR #18783.
adaptive-webui-19844
Sentox6 2 years ago committed by GitHub
parent
commit
bd31eddb94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      src/gui/mainwindow.cpp

35
src/gui/mainwindow.cpp

@ -311,9 +311,11 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState) @@ -311,9 +311,11 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
connect(m_ui->actionManageCookies, &QAction::triggered, this, &MainWindow::manageCookies);
// Initialise system sleep inhibition timer
m_pwr = new PowerManagement(this);
m_preventTimer = new QTimer(this);
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::updatePowerManagementState);
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
// Configure BT session according to options
loadPreferences();
@ -1448,19 +1450,7 @@ void MainWindow::loadPreferences() @@ -1448,19 +1450,7 @@ void MainWindow::loadPreferences()
showStatusBar(pref->isStatusbarDisplayed());
if (pref->preventFromSuspendWhenDownloading() || pref->preventFromSuspendWhenSeeding())
{
if (!m_preventTimer->isActive())
{
updatePowerManagementState();
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
}
}
else
{
m_preventTimer->stop();
m_pwr->setActivityState(false);
}
updatePowerManagementState();
m_transferListWidget->setAlternatingRowColors(pref->useAlternatingRowColors());
m_propertiesWidget->getFilesList()->setAlternatingRowColors(pref->useAlternatingRowColors());
@ -1924,17 +1914,20 @@ void MainWindow::on_actionAutoShutdown_toggled(bool enabled) @@ -1924,17 +1914,20 @@ void MainWindow::on_actionAutoShutdown_toggled(bool enabled)
void MainWindow::updatePowerManagementState()
{
const bool preventFromSuspendWhenDownloading = Preferences::instance()->preventFromSuspendWhenDownloading();
const bool preventFromSuspendWhenSeeding = Preferences::instance()->preventFromSuspendWhenSeeding();
const QVector<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
const bool hasUnfinishedTorrents = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
{
return (!torrent->isFinished() && !torrent->isPaused() && !torrent->isErrored() && torrent->hasMetadata());
});
const bool hasRunningSeed = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
const bool inhibitSuspend = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [&](const BitTorrent::Torrent *torrent)
{
return (torrent->isFinished() && !torrent->isPaused());
if (preventFromSuspendWhenDownloading && (!torrent->isFinished() && !torrent->isPaused() && !torrent->isErrored() && torrent->hasMetadata()))
return true;
if (preventFromSuspendWhenSeeding && (torrent->isFinished() && !torrent->isPaused()))
return true;
return torrent->isMoving();
});
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && hasUnfinishedTorrents)
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && hasRunningSeed);
m_pwr->setActivityState(inhibitSuspend);
}

Loading…
Cancel
Save