-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathPowerComponent.cpp
79 lines (69 loc) · 2.12 KB
/
PowerComponent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by Tobias Hieta on 25/03/15.
//
#include "PowerComponent.h"
#include "input/InputComponent.h"
#include "settings/SettingsComponent.h"
#ifdef Q_OS_MAC
#include "PowerComponentMac.h"
#elif defined(LINUX_DBUS)
#include "PowerComponentDBus.h"
#elif defined(USE_X11POWER)
#include "PowerComponentX11.h"
#elif defined(Q_OS_WIN32)
#include "PowerComponentWin.h"
#endif
/////////////////////////////////////////////////////////////////////////////////////////
PowerComponent& PowerComponent::Get()
{
#ifdef Q_OS_MAC
static PowerComponentMac instance;
return instance;
#elif defined(LINUX_DBUS)
static PowerComponentDBus instance;
return instance;
#elif defined(USE_X11POWER)
static PowerComponentX11 instance;
return instance;
#elif defined(Q_OS_WIN32)
static PowerComponentWin instance;
return instance;
#else
qWarning() << "Could not find a power component matching this platform. OS screensaver control disabled.";
static PowerComponent instance;
return instance;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////
bool PowerComponent::componentInitialize()
{
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
void PowerComponent::setScreensaverEnabled(bool enabled)
{
if (enabled)
{
qDebug() << "Enabling OS screensaver";
doEnableScreensaver();
}
else
{
qDebug() << "Disabling OS screensaver";
doDisableScreensaver();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
void PowerComponent::componentPostInitialize()
{
InputComponent::Get().registerHostCommand("poweroff", this, "PowerOff");
InputComponent::Get().registerHostCommand("reboot", this, "Reboot");
InputComponent::Get().registerHostCommand("suspend", this, "Suspend");
}
/////////////////////////////////////////////////////////////////////////////////////////
bool PowerComponent::checkCap(PowerCapabilities capability)
{
if (!SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "showPowerOptions").toBool())
return false;
return (getPowerCapabilities() & capability);
}