on aafc6d8 help sign in
unity8/plugins/Powerd/Powerd.cpp
67 lines 2.4 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));
28Powerd::Powerd(QObject* parent)
29 : QObject(parent),
30 unityScreen(NULL),
31 cachedStatus(Status::On)
33 unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
34 "/com/canonical/Unity/Screen",
35 "com.canonical.Unity.Screen",
36 QDBusConnection::SM_BUSNAME(), this);
38 unityScreen->connection().connect("com.canonical.Unity.Screen",
39 "/com/canonical/Unity/Screen",
40 "com.canonical.Unity.Screen",
41 "DisplayPowerStateChange",
42 this,
43 SLOT(handleDisplayPowerStateChange(int, int)));
45 systemSettings = g_settings_new("com.ubuntu.touch.system");
46 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
47 autoBrightnessChanged(systemSettings, "auto-brightness", unityScreen);
50Powerd::~Powerd()
52 g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
53 g_object_unref(systemSettings);
56Powerd::Status Powerd::status() const
58 return cachedStatus;
61void Powerd::handleDisplayPowerStateChange(int status, int reason)
63 if (cachedStatus != (Status)status) {
64 cachedStatus = (Status)status;
65 Q_EMIT statusChanged((DisplayStateChangeReason)reason);
66 }