mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Merge pull request #9244 from Couchy/inhibit_sleep_options
Inhibit sleep for running downloads or uploads regardless of network activity
This commit is contained in:
commit
366239ca7b
@ -1863,20 +1863,26 @@ TorrentHandle *Session::findTorrent(const InfoHash &hash) const
|
||||
|
||||
bool Session::hasActiveTorrents() const
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
if (TorrentFilter::ActiveTorrent.match(torrent))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentHandle *torrent)
|
||||
{
|
||||
return TorrentFilter::ActiveTorrent.match(torrent);
|
||||
});
|
||||
}
|
||||
|
||||
bool Session::hasUnfinishedTorrents() const
|
||||
{
|
||||
foreach (TorrentHandle *const torrent, m_torrents)
|
||||
if (!torrent->isSeed() && !torrent->isPaused())
|
||||
return true;
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandle *torrent)
|
||||
{
|
||||
return (!torrent->isSeed() && !torrent->isPaused());
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
bool Session::hasRunningSeed() const
|
||||
{
|
||||
return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentHandle *torrent)
|
||||
{
|
||||
return (torrent->isSeed() && !torrent->isPaused());
|
||||
});
|
||||
}
|
||||
|
||||
void Session::banIP(const QString &ip)
|
||||
|
@ -454,6 +454,7 @@ namespace BitTorrent
|
||||
TorrentStatusReport torrentStatusReport() const;
|
||||
bool hasActiveTorrents() const;
|
||||
bool hasUnfinishedTorrents() const;
|
||||
bool hasRunningSeed() const;
|
||||
const SessionStatus &status() const;
|
||||
const CacheStatus &cacheStatus() const;
|
||||
quint64 getAlltimeDL() const;
|
||||
|
@ -255,14 +255,24 @@ void Preferences::setSplashScreenDisabled(bool b)
|
||||
}
|
||||
|
||||
// Preventing from system suspend while active torrents are presented.
|
||||
bool Preferences::preventFromSuspend() const
|
||||
bool Preferences::preventFromSuspendWhenDownloading() const
|
||||
{
|
||||
return value("Preferences/General/PreventFromSuspend", false).toBool();
|
||||
return value("Preferences/General/PreventFromSuspendWhenDownloading", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setPreventFromSuspend(bool b)
|
||||
void Preferences::setPreventFromSuspendWhenDownloading(bool b)
|
||||
{
|
||||
setValue("Preferences/General/PreventFromSuspend", b);
|
||||
setValue("Preferences/General/PreventFromSuspendWhenDownloading", b);
|
||||
}
|
||||
|
||||
bool Preferences::preventFromSuspendWhenSeeding() const
|
||||
{
|
||||
return value("Preferences/General/PreventFromSuspendWhenSeeding", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setPreventFromSuspendWhenSeeding(bool b)
|
||||
{
|
||||
setValue("Preferences/General/PreventFromSuspendWhenSeeding", b);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -1582,6 +1592,8 @@ void Preferences::setSpeedWidgetGraphEnable(int id, const bool enable)
|
||||
|
||||
void Preferences::upgrade()
|
||||
{
|
||||
SettingsStorage *settingsStorage = SettingsStorage::instance();
|
||||
|
||||
QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
||||
if (!labels.isEmpty()) {
|
||||
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
|
||||
@ -1590,10 +1602,17 @@ void Preferences::upgrade()
|
||||
categories[label] = "";
|
||||
}
|
||||
setValue("BitTorrent/Session/Categories", categories);
|
||||
SettingsStorage::instance()->removeValue("TransferListFilters/customLabels");
|
||||
settingsStorage->removeValue("TransferListFilters/customLabels");
|
||||
}
|
||||
|
||||
SettingsStorage::instance()->removeValue("Preferences/Downloads/AppendLabel");
|
||||
settingsStorage->removeValue("Preferences/Downloads/AppendLabel");
|
||||
|
||||
// Inhibit sleep based on running downloads/available seeds rather than network activity.
|
||||
if (value("Preferences/General/PreventFromSuspend", false).toBool()) {
|
||||
setPreventFromSuspendWhenDownloading(true);
|
||||
setPreventFromSuspendWhenSeeding(true);
|
||||
}
|
||||
settingsStorage->removeValue("Preferences/General/PreventFromSuspend");
|
||||
}
|
||||
|
||||
void Preferences::apply()
|
||||
|
@ -123,8 +123,10 @@ public:
|
||||
void setStartMinimized(bool b);
|
||||
bool isSplashScreenDisabled() const;
|
||||
void setSplashScreenDisabled(bool b);
|
||||
bool preventFromSuspend() const;
|
||||
void setPreventFromSuspend(bool b);
|
||||
bool preventFromSuspendWhenDownloading() const;
|
||||
void setPreventFromSuspendWhenDownloading(bool b);
|
||||
bool preventFromSuspendWhenSeeding() const;
|
||||
void setPreventFromSuspendWhenSeeding(bool b);
|
||||
#ifdef Q_OS_WIN
|
||||
bool WinStartup() const;
|
||||
void setWinStartup(bool b);
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user