on 2492425 help sign in
unity8/plugins/Powerd/Powerd.cpp
53 lines 2.0 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 *powerd)
24 bool value = g_settings_get_boolean(settings, key);
25 powerd->asyncCall("userAutobrightnessEnable", QVariant(value));
28Powerd::Powerd(QObject* parent)
29 : QObject(parent),
30 powerd(NULL)
32 powerd = new QDBusInterface("com.canonical.powerd",
33 "/com/canonical/powerd",
34 "com.canonical.powerd",
35 QDBusConnection::SM_BUSNAME(), this);
37 powerd->connection().connect("com.canonical.powerd",
38 "/com/canonical/powerd",
39 "com.canonical.powerd",
40 "DisplayPowerStateChange",
41 this,
42 SIGNAL(displayPowerStateChange(int, unsigned int)));
44 systemSettings = g_settings_new("com.ubuntu.touch.system");
45 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), powerd);
46 autoBrightnessChanged(systemSettings, "auto-brightness", powerd);
49Powerd::~Powerd()
51 g_signal_handlers_disconnect_by_data(systemSettings, powerd);
52 g_object_unref(systemSettings);