/
lipsticksettings.cpp
128 lines (111 loc) · 4.08 KB
/
lipsticksettings.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// This file is part of lipstick, a QML desktop library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License version 2.1 as published by the Free Software Foundation
// and appearing in the file LICENSE.LGPL included in the packaging
// of this file.
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// Copyright (c) 2012, Robin Burchell <robin+nemo@viroteck.net>
//
#include <QGuiApplication>
#include <QScreen>
#include <MGConfItem>
#include "screenlock/screenlock.h"
#include "homeapplication.h"
#include "lipsticksettings.h"
Q_GLOBAL_STATIC(LipstickSettings, settingsInstance)
LipstickSettings::LipstickSettings()
: QObject()
, m_screenLock(0)
{
}
LipstickSettings *LipstickSettings::instance()
{
return settingsInstance();
}
void LipstickSettings::setScreenLock(ScreenLock *screenLock)
{
// TODO: Disconnect from previous screenlock signals?
m_screenLock = screenLock;
connect(screenLock, SIGNAL(screenLockedChanged(bool)), this, SIGNAL(lockscreenVisibleChanged()));
connect(screenLock, SIGNAL(lowPowerModeChanged()), this, SIGNAL(lowPowerModeChanged()));
connect(screenLock, SIGNAL(blankingPolicyChanged(QString)), this, SIGNAL(blankingPolicyChanged()));
}
bool LipstickSettings::lockscreenVisible() const
{
return m_screenLock != 0 ? m_screenLock->isScreenLocked() : false;
}
void LipstickSettings::setLockscreenVisible(bool lockscreenVisible)
{
if (m_screenLock != 0 && lockscreenVisible != m_screenLock->isScreenLocked()) {
if (lockscreenVisible) {
m_screenLock->lockScreen();
} else {
m_screenLock->unlockScreen();
}
}
}
bool LipstickSettings::lowPowerMode() const
{
return (m_screenLock && m_screenLock->isLowPowerMode());
}
void LipstickSettings::lockScreen(bool immediate)
{
if (m_screenLock != 0 && (!m_screenLock->isScreenLocked() || immediate)) {
m_screenLock->lockScreen(immediate);
}
}
void LipstickSettings::setInteractionExpected(bool expected)
{
if (m_screenLock != 0) {
m_screenLock->setInteractionExpected(expected);
}
}
QSize LipstickSettings::screenSize()
{
return QGuiApplication::primaryScreen()->size();
}
void LipstickSettings::exportScreenProperties()
{
const int defaultValue = 0;
MGConfItem widthConf("/lipstick/screen/primary/width");
QScreen *primaryScreen = QGuiApplication::primaryScreen();
QSize primaryScreenSize = primaryScreen->size();
if (widthConf.value(defaultValue) != primaryScreenSize.width()) {
widthConf.set(primaryScreenSize.width());
widthConf.sync();
}
MGConfItem heightConf("/lipstick/screen/primary/height");
if (heightConf.value(defaultValue) != primaryScreenSize.height()) {
heightConf.set(primaryScreenSize.height());
heightConf.sync();
}
MGConfItem physicalDotsPerInchConf("/lipstick/screen/primary/physicalDotsPerInch");
if (physicalDotsPerInchConf.value(defaultValue) != primaryScreen->physicalDotsPerInch()) {
physicalDotsPerInchConf.set(primaryScreen->physicalDotsPerInch());
physicalDotsPerInchConf.sync();
}
MGConfItem physicalDotsPerInchXConf("/lipstick/screen/primary/physicalDotsPerInchX");
if (physicalDotsPerInchXConf.value(defaultValue) != primaryScreen->physicalDotsPerInchX()) {
physicalDotsPerInchXConf.set(primaryScreen->physicalDotsPerInchX());
physicalDotsPerInchXConf.sync();
}
MGConfItem physicalDotsPerInchYConf("/lipstick/screen/primary/physicalDotsPerInchY");
if (physicalDotsPerInchYConf.value(defaultValue) != primaryScreen->physicalDotsPerInchY()) {
physicalDotsPerInchYConf.set(primaryScreen->physicalDotsPerInchY());
physicalDotsPerInchYConf.sync();
}
}
QString LipstickSettings::blankingPolicy()
{
if (m_screenLock) {
return m_screenLock->blankingPolicy();
}
return "default";
}