Added MCE class.
[situare] / src / mceprivate.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #include <QString>
23 #include <QDebug>
24
25 #include <mce/dbus-names.h>
26 #include <mce/mode-names.h>
27
28 #include "mce.h"
29 #include "mceprivate.h"
30
31 const int DISPLAY_STATE_INDEX = 0;
32
33 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
34
35 MCEPrivate::MCEPrivate(QObject *parent)
36     : QObject(parent),
37       m_displayOn(true)
38 {
39     qDebug() << __PRETTY_FUNCTION__;
40
41     m_parent = static_cast<MCE*>(parent);
42
43     m_dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
44                                        MCE_REQUEST_IF, dBusConnection, this);
45
46     dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
47                            MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &)));
48
49     m_dBusInterface->call(MCE_DISPLAY_STATUS_GET);
50 }
51
52 bool MCEPrivate::isDisplayOn()
53 {
54     qDebug() << __PRETTY_FUNCTION__;
55
56     return m_displayOn;
57 }
58
59 void MCEPrivate::displayStateChanged(const QDBusMessage &message)
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62
63     QString content = message.arguments().at(DISPLAY_STATE_INDEX).toString();
64
65     if (!content.isEmpty()) {
66         if (content == MCE_DISPLAY_ON_STRING)
67             emit m_parent->displayOn(true);
68         else if (content == MCE_DISPLAY_OFF_STRING)
69             emit m_parent->displayOn(false);
70     }
71 }