mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-04 14:42:29 -06:00
Inhibit sleep regardless of activity
"Active torrents" is a somewhat unintuitive concept as a basis for preventing sleep, as torrents can become active or inactive on the network at any time. This brings some predictability to the inhibit sleep option, and will inhibit sleep as long as there are unpaused downloads or uploads, regardless of network activity. Closes #1696, #4592, #4655, #7019, #7159, #7452
This commit is contained in:
committed by
sledgehammer999
parent
052206efa1
commit
5e90156e9e
@@ -344,7 +344,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
m_pwr = new PowerManagement(this);
|
||||
m_preventTimer = new QTimer(this);
|
||||
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::checkForActiveTorrents);
|
||||
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::updatePowerManagementState);
|
||||
|
||||
// Configure BT session according to options
|
||||
loadPreferences(false);
|
||||
@@ -1478,7 +1478,7 @@ void MainWindow::loadPreferences(bool configureSession)
|
||||
|
||||
showStatusBar(pref->isStatusbarDisplayed());
|
||||
|
||||
if (pref->preventFromSuspend() && !m_preventTimer->isActive()) {
|
||||
if ((pref->preventFromSuspendWhenDownloading() || pref->preventFromSuspendWhenSeeding()) && !m_preventTimer->isActive()) {
|
||||
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
|
||||
}
|
||||
else {
|
||||
@@ -2004,9 +2004,11 @@ void MainWindow::on_actionAutoShutdown_toggled(bool enabled)
|
||||
Preferences::instance()->setShutdownWhenDownloadsComplete(enabled);
|
||||
}
|
||||
|
||||
void MainWindow::checkForActiveTorrents()
|
||||
void MainWindow::updatePowerManagementState()
|
||||
{
|
||||
m_pwr->setActivityState(BitTorrent::Session::instance()->hasActiveTorrents());
|
||||
const bool inhibitSuspend = (Preferences::instance()->preventFromSuspendWhenDownloading() && BitTorrent::Session::instance()->hasUnfinishedTorrents())
|
||||
|| (Preferences::instance()->preventFromSuspendWhenSeeding() && BitTorrent::Session::instance()->hasRunningSeed());
|
||||
m_pwr->setActivityState(inhibitSuspend);
|
||||
}
|
||||
|
||||
#ifndef Q_OS_MAC
|
||||
|
||||
@@ -174,8 +174,8 @@ private slots:
|
||||
void on_actionDownloadFromURL_triggered();
|
||||
void on_actionExit_triggered();
|
||||
void on_actionLock_triggered();
|
||||
// Check for active torrents and set preventing from suspend state
|
||||
void checkForActiveTorrents();
|
||||
// Check for unpaused downloading or seeding torrents and prevent system suspend/sleep according to preferences
|
||||
void updatePowerManagementState();
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
void checkProgramUpdate();
|
||||
#endif
|
||||
|
||||
@@ -225,10 +225,12 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
||||
connect(m_ui->checkShowSplash, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkProgramExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkProgramAutoExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkPreventFromSuspend, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkPreventFromSuspendWhenDownloading, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->checkPreventFromSuspendWhenSeeding, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->comboTrayIcon, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && !defined(QT_DBUS_LIB)
|
||||
m_ui->checkPreventFromSuspend->setDisabled(true);
|
||||
m_ui->checkPreventFromSuspendWhenDownloading->setDisabled(true);
|
||||
m_ui->checkPreventFromSuspendWhenSeeding->setDisabled(true);
|
||||
#endif
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
connect(m_ui->checkAssociateTorrents, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
|
||||
@@ -556,7 +558,8 @@ void OptionsDialog::saveOptions()
|
||||
pref->setSplashScreenDisabled(isSplashScreenDisabled());
|
||||
pref->setConfirmOnExit(m_ui->checkProgramExitConfirm->isChecked());
|
||||
pref->setDontConfirmAutoExit(!m_ui->checkProgramAutoExitConfirm->isChecked());
|
||||
pref->setPreventFromSuspend(preventFromSuspend());
|
||||
pref->setPreventFromSuspendWhenDownloading(m_ui->checkPreventFromSuspendWhenDownloading->isChecked());
|
||||
pref->setPreventFromSuspendWhenSeeding(m_ui->checkPreventFromSuspendWhenSeeding->isChecked());
|
||||
#ifdef Q_OS_WIN
|
||||
pref->setWinStartup(WinStartup());
|
||||
// Windows: file association settings
|
||||
@@ -793,7 +796,8 @@ void OptionsDialog::loadOptions()
|
||||
}
|
||||
#endif
|
||||
|
||||
m_ui->checkPreventFromSuspend->setChecked(pref->preventFromSuspend());
|
||||
m_ui->checkPreventFromSuspendWhenDownloading->setChecked(pref->preventFromSuspendWhenDownloading());
|
||||
m_ui->checkPreventFromSuspendWhenSeeding->setChecked(pref->preventFromSuspendWhenSeeding());
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
m_ui->checkStartup->setChecked(pref->WinStartup());
|
||||
@@ -1407,11 +1411,6 @@ bool OptionsDialog::WinStartup() const
|
||||
}
|
||||
#endif
|
||||
|
||||
bool OptionsDialog::preventFromSuspend() const
|
||||
{
|
||||
return m_ui->checkPreventFromSuspend->isChecked();
|
||||
}
|
||||
|
||||
bool OptionsDialog::preAllocateAllFiles() const
|
||||
{
|
||||
return m_ui->checkPreallocateAll->isChecked();
|
||||
|
||||
@@ -122,7 +122,6 @@ private:
|
||||
#endif
|
||||
bool startMinimized() const;
|
||||
bool isSplashScreenDisabled() const;
|
||||
bool preventFromSuspend() const;
|
||||
#ifdef Q_OS_WIN
|
||||
bool WinStartup() const;
|
||||
#endif
|
||||
|
||||
@@ -479,9 +479,16 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_16">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkPreventFromSuspend">
|
||||
<widget class="QCheckBox" name="checkPreventFromSuspendWhenDownloading">
|
||||
<property name="text">
|
||||
<string>Inhibit system sleep when torrents are active</string>
|
||||
<string>Inhibit system sleep when torrents are downloading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkPreventFromSuspendWhenSeeding">
|
||||
<property name="text">
|
||||
<string>Inhibit system sleep when torrents are seeding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -3369,7 +3376,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
|
||||
<tabstop>comboTrayIcon</tabstop>
|
||||
<tabstop>checkAssociateTorrents</tabstop>
|
||||
<tabstop>checkAssociateMagnetLinks</tabstop>
|
||||
<tabstop>checkPreventFromSuspend</tabstop>
|
||||
<tabstop>checkPreventFromSuspendWhenDownloading</tabstop>
|
||||
<tabstop>checkPreventFromSuspendWhenSeeding</tabstop>
|
||||
<tabstop>checkAdditionDialog</tabstop>
|
||||
<tabstop>checkAdditionDialogFront</tabstop>
|
||||
<tabstop>checkPreallocateAll</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user