on f621663 help sign in
unity8/plugins/Powerd/Powerd.cpp
69 lines 2.9 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)
44 unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
45 "/com/canonical/Unity/Screen",
46 "com.canonical.Unity.Screen",
47 QDBusConnection::SM_BUSNAME(), this);
49 unityScreen->connection().connect("com.canonical.Unity.Screen",
50 "/com/canonical/Unity/Screen",
51 "com.canonical.Unity.Screen",
52 "DisplayPowerStateChange",
53 this,
54 SIGNAL(displayPowerStateChange(int, int)));
56 systemSettings = g_settings_new("com.ubuntu.touch.system");
57 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
58 g_signal_connect(systemSettings, "changed::activity-timeout", G_CALLBACK(activityTimeoutChanged), unityScreen);
59 g_signal_connect(systemSettings, "changed::dim-timeout", G_CALLBACK(dimTimeoutChanged), unityScreen);
60 autoBrightnessChanged(systemSettings, "auto-brightness", unityScreen);
61 activityTimeoutChanged(systemSettings, "activity-timeout", unityScreen);
62 dimTimeoutChanged(systemSettings, "dim-timeout", unityScreen);
65Powerd::~Powerd()
67 g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
68 g_object_unref(systemSettings);