mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 05:01:25 -07:00
parent
0defb7d79d
commit
bd31eddb94
1 changed files with 14 additions and 21 deletions
|
@ -311,9 +311,11 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
|
||||||
|
|
||||||
connect(m_ui->actionManageCookies, &QAction::triggered, this, &MainWindow::manageCookies);
|
connect(m_ui->actionManageCookies, &QAction::triggered, this, &MainWindow::manageCookies);
|
||||||
|
|
||||||
|
// Initialise system sleep inhibition timer
|
||||||
m_pwr = new PowerManagement(this);
|
m_pwr = new PowerManagement(this);
|
||||||
m_preventTimer = new QTimer(this);
|
m_preventTimer = new QTimer(this);
|
||||||
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::updatePowerManagementState);
|
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::updatePowerManagementState);
|
||||||
|
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
|
||||||
|
|
||||||
// Configure BT session according to options
|
// Configure BT session according to options
|
||||||
loadPreferences();
|
loadPreferences();
|
||||||
|
@ -1448,19 +1450,7 @@ void MainWindow::loadPreferences()
|
||||||
|
|
||||||
showStatusBar(pref->isStatusbarDisplayed());
|
showStatusBar(pref->isStatusbarDisplayed());
|
||||||
|
|
||||||
if (pref->preventFromSuspendWhenDownloading() || pref->preventFromSuspendWhenSeeding())
|
updatePowerManagementState();
|
||||||
{
|
|
||||||
if (!m_preventTimer->isActive())
|
|
||||||
{
|
|
||||||
updatePowerManagementState();
|
|
||||||
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_preventTimer->stop();
|
|
||||||
m_pwr->setActivityState(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_transferListWidget->setAlternatingRowColors(pref->useAlternatingRowColors());
|
m_transferListWidget->setAlternatingRowColors(pref->useAlternatingRowColors());
|
||||||
m_propertiesWidget->getFilesList()->setAlternatingRowColors(pref->useAlternatingRowColors());
|
m_propertiesWidget->getFilesList()->setAlternatingRowColors(pref->useAlternatingRowColors());
|
||||||
|
@ -1924,17 +1914,20 @@ void MainWindow::on_actionAutoShutdown_toggled(bool enabled)
|
||||||
|
|
||||||
void MainWindow::updatePowerManagementState()
|
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 QVector<BitTorrent::Torrent *> allTorrents = BitTorrent::Session::instance()->torrents();
|
||||||
const bool hasUnfinishedTorrents = 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() && !torrent->isErrored() && torrent->hasMetadata());
|
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 hasRunningSeed = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](const BitTorrent::Torrent *torrent)
|
|
||||||
{
|
|
||||||
return (torrent->isFinished() && !torrent->isPaused());
|
|
||||||
});
|
|
||||||
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && hasUnfinishedTorrents)
|
|
||||||
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && hasRunningSeed);
|
|
||||||
m_pwr->setActivityState(inhibitSuspend);
|
m_pwr->setActivityState(inhibitSuspend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue