Added MCE class.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 21 Jun 2010 10:17:24 +0000 (13:17 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 21 Jun 2010 10:17:24 +0000 (13:17 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/mce.cpp [new file with mode: 0644]
src/mce.h [new file with mode: 0644]
src/mceprivate.cpp [new file with mode: 0644]
src/mceprivate.h [new file with mode: 0644]
src/src.pro

index f087fa9..275dd11 100644 (file)
 #include "map/mapengine.h"
 #include "situareservice/situareservice.h"
 #include "ui/mainwindow.h"
+#include "mce.h"
 #include <cmath>
 
 #include "engine.h"
 
+
 const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
 const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
 const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12;  ///< Default zoom level when GPS available
@@ -47,6 +49,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
       m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
       m_userMoved(false),
+      m_automaticUpdateScreenOff(false),
       m_automaticUpdateIntervalTimer(0),
       m_lastUpdatedGPSPosition(QPointF())
 {    
@@ -99,6 +102,9 @@ SituareEngine::SituareEngine(QMainWindow *parent)
 
     m_gps->setMode(GPSPosition::Default);
     initializeGpsAndAutocentering();
+
+    m_mce = new MCE(this);
+    connect(m_mce, SIGNAL(displayOn(bool)), this, SLOT(displayOn(bool)));
 }
 
 SituareEngine::~SituareEngine()
@@ -120,6 +126,9 @@ void SituareEngine::automaticUpdateIntervalTimerTimeout()
         requestUpdateLocation();
         m_userMoved = false;
     }
+
+    if (!m_mce->isDisplayOn())
+        m_gps->requestUpdate();
 }
 
 void SituareEngine::changeAutoCenteringSetting(bool enabled)
@@ -138,6 +147,16 @@ void SituareEngine::disableAutoCentering()
     m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
+void SituareEngine::displayOn(bool on)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_displayOn = on;
+
+    if (m_autoCenteringEnabled)
+        enableAutoCentering(on);
+}
+
 void SituareEngine::enableAutoCentering(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -419,6 +438,10 @@ void SituareEngine::saveGPSPosition(QPointF position)
         m_lastUpdatedGPSPosition = position;
         m_userMoved = true;
     }
+
+    if (m_automaticUpdateGPSRequest) {
+        m_
+    }
 }
 
 void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
index 9bbef2d..9007860 100644 (file)
@@ -39,6 +39,7 @@ class MainWindow;
 class MapEngine;
 class SituareService;
 class User;
+class MCE;
 
 class QTimer;
 
@@ -228,6 +229,13 @@ private slots:
     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
 
     /**
+    * @brief Slot for display on.
+    *
+    * @param on true if on, false otherwise
+    */
+    void displayOn(bool on);
+
+    /**
      * @brief Sets zoom level to default when first GPS location is received if autocentering
      * is enabled.
      *
@@ -282,13 +290,17 @@ signals:
 private:
     bool m_autoCenteringEnabled;        ///< Auto centering flag
     bool m_automaticUpdateFirstStart;   ///< Automatic location update first start flag
+    bool m_automaticUpdateScreenOff;    ///< Flag for automatic location update when screen is off
+    bool m_screenOn;                    ///< Flag for device screen on
     bool m_userMoved;                   ///< Flag for user moving
 
+
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
     GPSPosition *m_gps;                              ///< Instance of the gps position
     MainWindow *m_ui;                                ///< Instance of the MainWindow UI
     MapEngine *m_mapEngine;                          ///< MapEngine
     SituareService *m_situareService;  ///< Instance of the situare server communication service
+    MCE *m_mce;                        ///< Instance of the MCE
 
     QTimer *m_automaticUpdateIntervalTimer; ///< Automatic update interval timer
     QPointF m_lastUpdatedGPSPosition;       ///< Last updated GPS position
diff --git a/src/mce.cpp b/src/mce.cpp
new file mode 100644 (file)
index 0000000..54b39eb
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QDebug>
+
+#include "mce.h"
+
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+#include "mceprivate.h"
+#else
+#include "mceprivatestub.h"
+#endif
+
+MCE::MCE(QObject *parent)
+    : QObject(parent)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_mcePrivate = new MCEPrivate(this);
+}
+
+bool MCE::isDisplayOn()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_mcePrivate->isDisplayOn();
+}
diff --git a/src/mce.h b/src/mce.h
new file mode 100644 (file)
index 0000000..218fe53
--- /dev/null
+++ b/src/mce.h
@@ -0,0 +1,48 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef MCE_H
+#define MCE_H
+
+#include <QObject>
+
+class MCEPrivate;
+
+class MCE : public QObject
+{
+    Q_OBJECT
+
+public:
+    friend class MCEPrivate;
+
+    MCE(QObject *parent = 0);
+
+public:
+    bool isDisplayOn();
+
+signals:
+    void displayOn(bool on);
+
+private:
+    MCEPrivate *m_mcePrivate;
+};
+
+#endif // MCE_H
diff --git a/src/mceprivate.cpp b/src/mceprivate.cpp
new file mode 100644 (file)
index 0000000..3797878
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QString>
+#include <QDebug>
+
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+
+#include "mce.h"
+#include "mceprivate.h"
+
+const int DISPLAY_STATE_INDEX = 0;
+
+static QDBusConnection dBusConnection = QDBusConnection::systemBus();
+
+MCEPrivate::MCEPrivate(QObject *parent)
+    : QObject(parent),
+      m_displayOn(true)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_parent = static_cast<MCE*>(parent);
+
+    m_dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
+                                       MCE_REQUEST_IF, dBusConnection, this);
+
+    dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
+                           MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &)));
+
+    m_dBusInterface->call(MCE_DISPLAY_STATUS_GET);
+}
+
+bool MCEPrivate::isDisplayOn()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_displayOn;
+}
+
+void MCEPrivate::displayStateChanged(const QDBusMessage &message)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString content = message.arguments().at(DISPLAY_STATE_INDEX).toString();
+
+    if (!content.isEmpty()) {
+        if (content == MCE_DISPLAY_ON_STRING)
+            emit m_parent->displayOn(true);
+        else if (content == MCE_DISPLAY_OFF_STRING)
+            emit m_parent->displayOn(false);
+    }
+}
diff --git a/src/mceprivate.h b/src/mceprivate.h
new file mode 100644 (file)
index 0000000..c4a3abb
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef MCEPRIVATE_H
+#define MCEPRIVATE_H
+
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusMessage>
+
+class MCE;
+
+class MCEPrivate : public QObject
+{
+    Q_OBJECT
+
+public:
+    MCEPrivate(QObject *parent);
+
+public:
+    bool isDisplayOn();
+
+private slots:
+    void displayStateChanged(const QDBusMessage &message);
+
+private:
+    QDBusInterface *m_dBusInterface;  ///< D-Bus interface
+    MCE *m_parent;                    ///< Parent object
+    bool m_displayOn;                 ///< Flag for display on/off
+};
+
+#endif // MCEPRIVATE_H
index 9f5825e..aa90192 100644 (file)
@@ -52,7 +52,8 @@ SOURCES += main.cpp \
     ui/zoombutton.cpp \
     ui/zoombuttonpanel.cpp \
     user/user.cpp \
-    ui/fullscreenbutton.cpp
+    ui/fullscreenbutton.cpp \
+    mce.cpp
 HEADERS += common.h \
     engine/engine.h \
     facebookservice/facebookauthentication.h \
@@ -102,10 +103,12 @@ HEADERS += common.h \
     ui/zoombutton.h \
     ui/zoombuttonpanel.h \
     user/user.h \
-    ui/fullscreenbutton.h
+    ui/fullscreenbutton.h \
+    mce.h
 QT += network \
     webkit
-DEFINES += QT_NO_DEBUG_OUTPUT
+
+#DEFINES += QT_NO_DEBUG_OUTPUT
 
 simulator {
     SOURCES += network/networkhandlerprivatestub.cpp \
@@ -119,8 +122,10 @@ simulator {
     armel {
         DEFINES += ARMEL
         INCLUDEPATH += /usr/include/glib-2.0 /usr/lib/glib-2.0/include
-        SOURCES += network/networkhandlerprivate.cpp
-        HEADERS += network/networkhandlerprivate.h
+        SOURCES += network/networkhandlerprivate.cpp \
+                   mceprivate.cpp
+        HEADERS += network/networkhandlerprivate.h \
+                   mceprivate.h
         QT += dbus
         CONFIG += icd2 qdbus
         SOURCES += gps/gpspositionprivateliblocation.cpp \
@@ -132,13 +137,15 @@ simulator {
                    gps/geopositioninfo.h \
                    gps/geocoordinate.h
         CONFIG += link_pkgconfig
-        PKGCONFIG += glib-2.0 liblocation
+        PKGCONFIG += glib-2.0 liblocation mce
         LIBS += -llocation
     } else {
         SOURCES += gps/gpspositionprivatestub.cpp \
-                   network/networkhandlerprivatestub.cpp
+                   network/networkhandlerprivatestub.cpp \
+                   mceprivatestub.cpp
         HEADERS += gps/gpspositionprivatestub.h \
-                   network/networkhandlerprivatestub.h
+                   network/networkhandlerprivatestub.h \
+                   mceprivatestub.h
     }
 
     QT += maemo5