Added missing mce files to src/engine.
[situare] / src / engine / 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 #include <QTimer>
25
26 #include <mce/dbus-names.h>
27 #include <mce/mode-names.h>
28
29 #include "mce.h"
30 #include "mceprivate.h"
31
32 const int DISPLAY_STATE_INDEX = 0;
33
34 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
35
36 MCEPrivate::MCEPrivate(QObject *parent)
37     : QObject(parent),
38       m_displayOn(true)
39 {
40     qDebug() << __PRETTY_FUNCTION__;
41
42     m_parent = static_cast<MCE*>(parent);
43
44     m_dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
45                                        MCE_REQUEST_IF, dBusConnection, this);
46
47     dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
48                            MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &)));
49
50     m_dBusInterface->callWithCallback(MCE_DISPLAY_STATUS_GET, QList<QVariant>(), this,
51                                       SLOT(setDisplayState(QString)),
52                                       SLOT(displayStateError(QDBusError)));
53 }
54
55 void MCEPrivate::displayStateChanged(const QDBusMessage &message)
56 {
57     qDebug() << __PRETTY_FUNCTION__;
58
59     QString state = message.arguments().at(DISPLAY_STATE_INDEX).toString();
60     setDisplayState(state);
61 }
62
63 void MCEPrivate::displayStateError(const QDBusError &error)
64 {
65     qDebug() << __PRETTY_FUNCTION__;
66
67     Q_UNUSED(error);
68 }
69
70 bool MCEPrivate::isDisplayOn()
71 {
72     qDebug() << __PRETTY_FUNCTION__;
73
74     return m_displayOn;
75 }
76
77 void MCEPrivate::setDisplayState(const QString &state)
78 {
79     qDebug() << __PRETTY_FUNCTION__;
80
81     if (!state.isEmpty()) {
82         if (state == MCE_DISPLAY_ON_STRING) {
83             m_displayOn = true;
84             emit m_parent->displayStateChanged(true);
85         }
86         else if (state == MCE_DISPLAY_OFF_STRING) {
87             m_displayOn = false;
88             emit m_parent->displayStateChanged(false);
89         }
90     }
91 }