Fix coding style

This commit is contained in:
thalieht
2018-05-31 12:19:07 +03:00
committed by sledgehammer999
parent faf84e483a
commit 6ce4c885b9
28 changed files with 195 additions and 223 deletions

View File

@@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
@@ -24,16 +24,15 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "powermanagement.h"
#include <QtGlobal>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
#include "powermanagement_x11.h"
#endif
#include "powermanagement.h"
#ifdef Q_OS_MAC
#include <IOKit/pwr_mgt/IOPMLib.h>
@@ -43,7 +42,9 @@
#include <windows.h>
#endif
PowerManagement::PowerManagement(QObject *parent) : QObject(parent), m_busy(false)
PowerManagement::PowerManagement(QObject *parent)
: QObject(parent)
, m_busy(false)
{
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor = new PowerManagementInhibitor(this);
@@ -56,8 +57,10 @@ PowerManagement::~PowerManagement()
void PowerManagement::setActivityState(bool busy)
{
if (busy) setBusy();
else setIdle();
if (busy)
setBusy();
else
setIdle();
}
void PowerManagement::setBusy()
@@ -68,10 +71,11 @@ void PowerManagement::setBusy()
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor->RequestBusy();
m_inhibitor->requestBusy();
#elif defined(Q_OS_MAC)
IOReturn success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &m_assertionID);
if (success != kIOReturnSuccess) m_busy = false;
if (success != kIOReturnSuccess)
m_busy = false;
#endif
}
@@ -83,7 +87,7 @@ void PowerManagement::setIdle()
#ifdef Q_OS_WIN
SetThreadExecutionState(ES_CONTINUOUS);
#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
m_inhibitor->RequestIdle();
m_inhibitor->requestIdle();
#elif defined(Q_OS_MAC)
IOPMAssertionRelease(m_assertionID);
#endif

View File

@@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
@@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef POWERMANAGEMENT_H

View File

@@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
@@ -24,48 +24,45 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "powermanagement_x11.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDBusPendingReply>
#include "powermanagement_x11.h"
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) : QObject(parent)
PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent)
: QObject(parent)
{
if (!QDBusConnection::sessionBus().isConnected())
{
if (!QDBusConnection::sessionBus().isConnected()) {
qDebug("D-Bus: Could not connect to session bus");
m_state = error;
m_state = Error;
}
else
{
m_state = idle;
else {
m_state = Idle;
}
m_intended_state = idle;
m_intendedState = Idle;
m_cookie = 0;
m_use_gsm = false;
m_useGSM = false;
}
PowerManagementInhibitor::~PowerManagementInhibitor()
{
}
void PowerManagementInhibitor::RequestIdle()
void PowerManagementInhibitor::requestIdle()
{
m_intended_state = idle;
if (m_state == error || m_state == idle || m_state == request_idle || m_state == request_busy)
m_intendedState = Idle;
if ((m_state == Error) || (m_state == Idle) || (m_state == RequestIdle) || (m_state == RequestBusy))
return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting idle");
QDBusMessage call;
if (!m_use_gsm)
if (!m_useGSM)
call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit",
@@ -78,7 +75,7 @@ void PowerManagementInhibitor::RequestIdle()
"org.gnome.SessionManager",
"Uninhibit");
m_state = request_idle;
m_state = RequestIdle;
QList<QVariant> args;
args << m_cookie;
@@ -86,20 +83,20 @@ void PowerManagementInhibitor::RequestIdle()
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::OnAsyncReply);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
}
void PowerManagementInhibitor::RequestBusy()
void PowerManagementInhibitor::requestBusy()
{
m_intended_state = busy;
if (m_state == error || m_state == busy || m_state == request_busy || m_state == request_idle)
m_intendedState = Busy;
if ((m_state == Error) || (m_state == Busy) || (m_state == RequestBusy) || (m_state == RequestIdle))
return;
qDebug("D-Bus: PowerManagementInhibitor: Requesting busy");
QDBusMessage call;
if (!m_use_gsm)
if (!m_useGSM)
call = QDBusMessage::createMethodCall(
"org.freedesktop.PowerManagement",
"/org/freedesktop/PowerManagement/Inhibit",
@@ -112,71 +109,64 @@ void PowerManagementInhibitor::RequestBusy()
"org.gnome.SessionManager",
"Inhibit");
m_state = request_busy;
m_state = RequestBusy;
QList<QVariant> args;
args << "qBittorrent";
if (m_use_gsm) args << 0u;
if (m_useGSM) args << 0u;
args << "Active torrents are presented";
if (m_use_gsm) args << 8u;
if (m_useGSM) args << 8u;
call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::OnAsyncReply);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
}
void PowerManagementInhibitor::OnAsyncReply(QDBusPendingCallWatcher *call)
void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call)
{
if (m_state == request_idle)
{
if (m_state == RequestIdle) {
QDBusPendingReply<> reply = *call;
if (reply.isError())
{
if (reply.isError()) {
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
m_state = error;
m_state = Error;
}
else
{
m_state = idle;
else {
m_state = Idle;
qDebug("D-Bus: PowerManagementInhibitor: Request successful");
if (m_intended_state == busy) RequestBusy();
if (m_intendedState == Busy)
requestBusy();
}
}
else if (m_state == request_busy)
{
else if (m_state == RequestBusy) {
QDBusPendingReply<uint> reply = *call;
if (reply.isError())
{
if (reply.isError()) {
qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message()));
if (!m_use_gsm)
{
if (!m_useGSM) {
qDebug("D-Bus: Falling back to org.gnome.SessionManager");
m_use_gsm = true;
m_state = idle;
if (m_intended_state == busy)
RequestBusy();
m_useGSM = true;
m_state = Idle;
if (m_intendedState == Busy)
requestBusy();
}
else
{
m_state = error;
else {
m_state = Error;
}
}
else
{
m_state = busy;
else {
m_state = Busy;
m_cookie = reply.value();
qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie);
if (m_intended_state == idle) RequestIdle();
if (m_intendedState == Idle)
requestIdle();
}
}
else
{
else {
qDebug("D-Bus: Unexpected reply in state %d", m_state);
m_state = error;
m_state = Error;
}
call->deleteLater();

View File

@@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
@@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef POWERMANAGEMENTINHIBITOR_H
@@ -33,9 +31,7 @@
#include <QObject>
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
QT_END_NAMESPACE
class PowerManagementInhibitor : public QObject
{
@@ -45,27 +41,27 @@ public:
PowerManagementInhibitor(QObject *parent = nullptr);
virtual ~PowerManagementInhibitor();
void RequestIdle();
void RequestBusy();
void requestIdle();
void requestBusy();
private slots:
void OnAsyncReply(QDBusPendingCallWatcher *call);
void onAsyncReply(QDBusPendingCallWatcher *call);
private:
enum _state
enum State
{
error,
idle,
request_busy,
busy,
request_idle
Error,
Idle,
RequestBusy,
Busy,
RequestIdle
};
enum _state m_state;
enum _state m_intended_state;
enum State m_state;
enum State m_intendedState;
unsigned int m_cookie;
bool m_use_gsm;
bool m_useGSM;
};
#endif // POWERMANAGEMENTINHIBITOR_H