on eaecfc2 help sign in
unity8/plugins/Powerd/Powerd.cpp
83 lines 3.3 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
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; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
19#include "Powerd.h"
20#include <QDBusPendingCall>
22void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
24 bool value = g_settings_get_boolean(settings, key);
25 unityScreen->asyncCall("userAutobrightnessEnable", QVariant(value));
28void activityTimeoutChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
30 int value = g_settings_get_uint(settings, key);
31 unityScreen->asyncCall("setInactivityTimeouts", QVariant(value), QVariant(-1));
34void dimTimeoutChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
36 int value = g_settings_get_uint(settings, key);
37 unityScreen->asyncCall("setInactivityTimeouts", QVariant(-1), QVariant(value));
40Powerd::Powerd(QObject* parent)
41 : QObject(parent),
42 unityScreen(nullptr),
43 cachedStatus(Status::On)
45 unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
46 "/com/canonical/Unity/Screen",
47 "com.canonical.Unity.Screen",
48 QDBusConnection::SM_BUSNAME(), this);
50 unityScreen->connection().connect("com.canonical.Unity.Screen",
51 "/com/canonical/Unity/Screen",
52 "com.canonical.Unity.Screen",
53 "DisplayPowerStateChange",
54 this,
55 SLOT(handleDisplayPowerStateChange(int, int)));
57 systemSettings = g_settings_new("com.ubuntu.touch.system");
58 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
59 g_signal_connect(systemSettings, "changed::activity-timeout", G_CALLBACK(activityTimeoutChanged), unityScreen);
60 g_signal_connect(systemSettings, "changed::dim-timeout", G_CALLBACK(dimTimeoutChanged), unityScreen);
61 autoBrightnessChanged(systemSettings, "auto-brightness", unityScreen);
62 activityTimeoutChanged(systemSettings, "activity-timeout", unityScreen);
63 dimTimeoutChanged(systemSettings, "dim-timeout", unityScreen);
66Powerd::~Powerd()
68 g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
69 g_object_unref(systemSettings);
72Powerd::Status Powerd::status() const
74 return cachedStatus;
77void Powerd::handleDisplayPowerStateChange(int status, int reason)
79 if (cachedStatus != (Status)status) {
80 cachedStatus = (Status)status;
81 Q_EMIT statusChanged((DisplayStateChangeReason)reason);
82 }