Browse Source

Merge pull request #12404 from Chocobo1/pwr

Fix wrong logic that disables "prevent sleeping" timer
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
f647b5a97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/gui/mainwindow.cpp
  2. 11
      src/gui/powermanagement/powermanagement.cpp
  3. 4
      src/gui/powermanagement/powermanagement.h

22
src/gui/mainwindow.cpp

@ -28,6 +28,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <chrono>
#include <QCloseEvent> #include <QCloseEvent>
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
@ -99,9 +101,6 @@
#include "programupdater.h" #include "programupdater.h"
#endif #endif
#define TIME_TRAY_BALLOON 5000
#define PREVENT_SUSPEND_INTERVAL 60000
namespace namespace
{ {
#define SETTINGS_KEY(name) "GUI/" name #define SETTINGS_KEY(name) "GUI/" name
@ -119,6 +118,9 @@ namespace
// Misc // Misc
const QString KEY_DOWNLOAD_TRACKER_FAVICON = QStringLiteral(SETTINGS_KEY("DownloadTrackerFavicon")); const QString KEY_DOWNLOAD_TRACKER_FAVICON = QStringLiteral(SETTINGS_KEY("DownloadTrackerFavicon"));
const int TIME_TRAY_BALLOON = 5000;
const std::chrono::seconds PREVENT_SUSPEND_INTERVAL {60};
// just a shortcut // just a shortcut
inline SettingsStorage *settings() inline SettingsStorage *settings()
{ {
@ -776,8 +778,9 @@ void MainWindow::cleanup()
if (m_systrayCreator) if (m_systrayCreator)
m_systrayCreator->stop(); m_systrayCreator->stop();
#endif #endif
if (m_preventTimer)
m_preventTimer->stop(); m_preventTimer->stop();
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) #if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
m_programUpdateTimer->stop(); m_programUpdateTimer->stop();
#endif #endif
@ -1401,7 +1404,7 @@ void MainWindow::showStatusBar(bool show)
} }
} }
void MainWindow::loadPreferences(bool configureSession) void MainWindow::loadPreferences(const bool configureSession)
{ {
Logger::instance()->addMessage(tr("Options were saved successfully.")); Logger::instance()->addMessage(tr("Options were saved successfully."));
const Preferences *const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
@ -1451,8 +1454,11 @@ void MainWindow::loadPreferences(bool configureSession)
showStatusBar(pref->isStatusbarDisplayed()); showStatusBar(pref->isStatusbarDisplayed());
if ((pref->preventFromSuspendWhenDownloading() || pref->preventFromSuspendWhenSeeding()) && !m_preventTimer->isActive()) { if (pref->preventFromSuspendWhenDownloading() || pref->preventFromSuspendWhenSeeding()) {
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL); if (!m_preventTimer->isActive()) {
updatePowerManagementState();
m_preventTimer->start(PREVENT_SUSPEND_INTERVAL);
}
} }
else { else {
m_preventTimer->stop(); m_preventTimer->stop();

11
src/gui/powermanagement/powermanagement.cpp

@ -30,10 +30,6 @@
#include <QtGlobal> #include <QtGlobal>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
#include "powermanagement_x11.h"
#endif
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
#include <IOKit/pwr_mgt/IOPMLib.h> #include <IOKit/pwr_mgt/IOPMLib.h>
#endif #endif
@ -42,9 +38,12 @@
#include <windows.h> #include <windows.h>
#endif #endif
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
#include "powermanagement_x11.h"
#endif
PowerManagement::PowerManagement(QObject *parent) PowerManagement::PowerManagement(QObject *parent)
: QObject(parent) : QObject(parent)
, m_busy(false)
{ {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
m_inhibitor = new PowerManagementInhibitor(this); m_inhibitor = new PowerManagementInhibitor(this);
@ -55,7 +54,7 @@ PowerManagement::~PowerManagement()
{ {
} }
void PowerManagement::setActivityState(bool busy) void PowerManagement::setActivityState(const bool busy)
{ {
if (busy) if (busy)
setBusy(); setBusy();

4
src/gui/powermanagement/powermanagement.h

@ -52,11 +52,11 @@ public:
void setActivityState(bool busy); void setActivityState(bool busy);
private: private:
bool m_busy;
void setBusy(); void setBusy();
void setIdle(); void setIdle();
bool m_busy = false;
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
PowerManagementInhibitor *m_inhibitor; PowerManagementInhibitor *m_inhibitor;
#endif #endif

Loading…
Cancel
Save