Changeset View
Changeset View
Standalone View
Standalone View
libcolorcorrect/autotests/mock_kwin.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | *********************************************************************/ | ||||
17 | #include "mock_kwin.h" | ||||
18 | | ||||
19 | #include <QDBusConnection> | ||||
20 | | ||||
21 | using namespace ColorCorrect; | ||||
22 | | ||||
23 | kwin_dbus::kwin_dbus() | ||||
24 | { | ||||
25 | } | ||||
26 | | ||||
27 | kwin_dbus::~kwin_dbus() | ||||
28 | { | ||||
29 | } | ||||
30 | | ||||
31 | bool kwin_dbus::registerDBus() | ||||
32 | { | ||||
33 | bool ret; | ||||
34 | QDBusConnection dbus = QDBusConnection::sessionBus(); | ||||
35 | ret = dbus.registerObject("/ColorCorrect", this, QDBusConnection::ExportAllContents); | ||||
36 | ret &= dbus.registerService("org.kde.KWin"); | ||||
37 | return ret; | ||||
38 | } | ||||
39 | | ||||
40 | bool kwin_dbus::unregisterDBus() | ||||
41 | { | ||||
42 | bool ret; | ||||
43 | QDBusConnection dbus = QDBusConnection::sessionBus(); | ||||
44 | ret = dbus.unregisterService("org.kde.KWin"); | ||||
45 | dbus.unregisterObject("/ColorCorrect"); | ||||
46 | return ret; | ||||
47 | } | ||||
48 | | ||||
49 | QHash<QString, QVariant> kwin_dbus::nightColorInfo() | ||||
50 | { | ||||
51 | return getData(); | ||||
52 | } | ||||
53 | | ||||
54 | QHash<QString, QVariant> kwin_dbus::getData() | ||||
55 | { | ||||
56 | QHash<QString, QVariant> ret; | ||||
57 | ret["Available"] = nightColorAvailable; | ||||
58 | | ||||
59 | ret["ActiveEnabled"] = activeEnabled; | ||||
60 | ret["Active"] = active; | ||||
61 | | ||||
62 | ret["ModeEnabled"] = modeEnabled; | ||||
63 | ret["Mode"] = mode; | ||||
64 | | ||||
65 | ret["NightTemperatureEnabled"] = nightTemperatureEnabled; | ||||
66 | ret["NightTemperature"] = nightTemperature; | ||||
67 | | ||||
68 | ret["Running"] = running; | ||||
69 | ret["CurrentColorTemperature"] = currentColorTemperature; | ||||
70 | | ||||
71 | ret["LatitudeAuto"] = latitudeAuto; | ||||
72 | ret["LongitudeAuto"] = longitudeAuto; | ||||
73 | | ||||
74 | ret["LocationEnabled"] = locationEnabled; | ||||
75 | ret["LatitudeFixed"] = latitudeFixed; | ||||
76 | ret["LongitudeFixed"] = longitudeFixed; | ||||
77 | | ||||
78 | ret["TimingsEnabled"] = timingsEnabled; | ||||
79 | ret["MorningBeginFixed"] = morningBeginFixed.toString(Qt::ISODate); | ||||
80 | ret["EveningBeginFixed"] = eveningBeginFixed.toString(Qt::ISODate); | ||||
81 | ret["TransitionTime"] = transitionTime; | ||||
82 | | ||||
83 | return ret; | ||||
84 | } | ||||
85 | | ||||
86 | bool kwin_dbus::nightColorConfigChange(QHash<QString, QVariant> data) | ||||
87 | { | ||||
88 | if (!configChangeExpectSuccess) { | ||||
89 | return false; | ||||
90 | } | ||||
91 | | ||||
92 | if (data.contains("Active")) { | ||||
93 | active = data["Active"].toBool(); | ||||
94 | } | ||||
95 | if (data.contains("Mode")) { | ||||
96 | mode = data["Mode"].toInt(); | ||||
97 | } | ||||
98 | if (data.contains("NightTemperature")) { | ||||
99 | nightTemperature = data["NightTemperature"].toInt(); | ||||
100 | } | ||||
101 | if (data.contains("LatitudeFixed")) { | ||||
102 | latitudeFixed = data["LatitudeFixed"].toDouble(); | ||||
103 | longitudeFixed = data["LongitudeFixed"].toDouble(); | ||||
104 | } | ||||
105 | if (data.contains("MorningBeginFixed")) { | ||||
106 | morningBeginFixed = QTime::fromString(data["MorningBeginFixed"].toString(), Qt::ISODate); | ||||
107 | eveningBeginFixed = QTime::fromString(data["EveningBeginFixed"].toString(), Qt::ISODate); | ||||
108 | transitionTime = data["TransitionTime"].toInt(); | ||||
109 | } | ||||
110 | running = active; | ||||
111 | | ||||
112 | emit nightColorConfigChangeSignal(getData()); | ||||
113 | return true; | ||||
114 | } | ||||
115 | | ||||
116 | void kwin_dbus::nightColorAutoLocationUpdate(double latitude, double longitude) | ||||
117 | { | ||||
118 | latitudeAuto = latitude; | ||||
119 | longitudeAuto = longitude; | ||||
120 | | ||||
121 | emit nightColorConfigChangeSignal(getData()); | ||||
122 | } |