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:
Lukas Greib 2018-08-02 15:45:21 -04:00 committed by sledgehammer999
parent 052206efa1
commit 5e90156e9e
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
9 changed files with 72 additions and 36 deletions

View file

@ -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()