Unity 8
 All Classes Functions Properties
Powerd.cpp
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  */
18 
19 #include "Powerd.h"
20 #include <QDBusPendingCall>
21 
22 void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface *powerd)
23 {
24  bool value = g_settings_get_boolean(settings, key);
25  powerd->asyncCall("userAutobrightnessEnable", QVariant(value));
26 }
27 
28 Powerd::Powerd(QObject* parent)
29  : QObject(parent),
30  powerd(NULL)
31 {
32  powerd = new QDBusInterface("com.canonical.powerd",
33  "/com/canonical/powerd",
34  "com.canonical.powerd",
35  QDBusConnection::SM_BUSNAME(), this);
36 
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)));
43 
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);
47 }
48 
49 Powerd::~Powerd()
50 {
51  g_signal_handlers_disconnect_by_data(systemSettings, powerd);
52  g_object_unref(systemSettings);
53 }