Merge branch 'master' into gps
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 11 May 2010 10:47:48 +0000 (13:47 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 11 May 2010 10:47:48 +0000 (13:47 +0300)
Conflicts:
images.qrc
src/engine/engine.cpp
src/engine/engine.h
src/src.pro
src/ui/mapviewscreen.h

12 files changed:
images.qrc
src/engine/engine.cpp
src/engine/engine.h
src/gps/README.txt [deleted file]
src/gps/gpsposition.cpp [new file with mode: 0644]
src/gps/gpsposition.h [new file with mode: 0644]
src/map/mapengine.cpp
src/src.pro
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index f825d3a..2d3b0d4 100644 (file)
@@ -26,5 +26,6 @@
         <file>res/images/list_item_top.png</file>
         <file>res/images/show_position.png</file>
         <file>res/images/show_position_s.png</file>
+               <file>res/dummy/nmealog.txt</file>
     </qresource>
 </RCC>
index b125837..8ab4e09 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "engine.h"
 #include "ui/mainwindow.h"
+#include "gps/gpsposition.h"
 
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent)
@@ -34,6 +35,8 @@ SituareEngine::SituareEngine(QMainWindow *parent)
 
     m_facebookAuthenticator = new FacebookAuthentication();
 
+    m_gps = new GPSPosition(this);
+
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
@@ -61,7 +64,13 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(m_ui, SIGNAL(refreshUserData()),
             this, SLOT(refreshUserData()));
 
-    m_facebookAuthenticator->start();
+    connect(m_gps, SIGNAL(timeout()), m_ui, SLOT(gpsTimeout()));
+    connect(m_gps, SIGNAL(error(QString)), m_ui, SLOT(gpsError(QString)));
+    connect(m_ui, SIGNAL(enableGPS(bool)), this, SLOT(enableGPS(bool)));
+    connect(m_gps, SIGNAL(position(QPointF)),
+            m_ui, SIGNAL(positionReceived(QPointF)));
+
+     m_facebookAuthenticator->start();
 }
 
 SituareEngine::~SituareEngine()
@@ -93,6 +102,7 @@ void SituareEngine::loginOk()
     m_facebookAuthenticator->close();
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
+    enableGPS(true);
 }
 
 void SituareEngine::requestAddress()
@@ -138,3 +148,13 @@ void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
     emit userLocationReady(user);
     emit friendsLocationsReady(friendsList);
 }
+
+void SituareEngine::enableGPS(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (enabled)
+        m_gps->start();
+    else
+        m_gps->stop();
+}
index cb8c40b..fe30675 100644 (file)
@@ -4,6 +4,7 @@
 
         Kaj Wallin - kaj.wallin@ixonos.com
         Henri Lampela - henri.lampela@ixonos.com
+        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
@@ -30,6 +31,8 @@
 #include "situareservice/situareservice.h"
 #include "ui/mainwindow.h"
 
+class GPSPosition;
+
 /**
 * @brief Engine class for Situare Application
 *
@@ -107,6 +110,13 @@ public slots:
     void userDataChanged(User *user, QList<User *> &friendsList);
 
     /**
+    * @brief Slot for gps enabling.
+    *
+    * @parma enabled true if gps should be enabled, false otherwise
+    */
+    void enableGPS(bool enabled);
+       
+       /**
     * @brief Slot to intercept signal when user has cancelled login process
     *
     */
@@ -135,8 +145,9 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    MainWindow *m_ui; ///< Instance of the MainWindow UI
     FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
+    GPSPosition *m_gps;   ///< Instance of the gps position
+    MainWindow *m_ui; ///< Instance of the MainWindow UI
     SituareService *m_situareService; ///< Instance of the situare server communication service
 };
 
diff --git a/src/gps/README.txt b/src/gps/README.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/gps/gpsposition.cpp b/src/gps/gpsposition.cpp
new file mode 100644 (file)
index 0000000..3c992ca
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+   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 <QGeoPositionInfoSource>
+#include <QNmeaPositionInfoSource>
+#include <QFile>
+#include <QDir>
+#include <QApplication>
+#include <QDebug>
+
+#include "gpsposition.h"
+
+GPSPosition::GPSPosition(QObject *parent)
+    : QObject(parent),
+      m_running(false),
+      m_updateInterval(DEFAULT_UPDATE_INTERVAL)
+{
+    m_gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
+
+    if (!m_gpsSource) {
+        QNmeaPositionInfoSource *nmeaSource = new QNmeaPositionInfoSource(
+                QNmeaPositionInfoSource::SimulationMode, this);
+        QFile *logFile = new QFile(":/res/dummy/nmealog.txt", this);
+        nmeaSource->setDevice(logFile);
+        m_gpsSource = nmeaSource;
+
+        emit error(tr("Could not start GPS. Using NMEA data source."));
+    }
+
+    m_gpsSource->setUpdateInterval(m_updateInterval);
+
+    connect(m_gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
+            this, SLOT(positionUpdated(QGeoPositionInfo)));
+    connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
+}
+
+GPSPosition::~GPSPosition()
+{
+    stop();
+}
+
+void GPSPosition::start()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_gpsSource && !isRunning()) {
+        m_gpsSource->startUpdates();
+        m_running = true;
+    }
+}
+
+void GPSPosition::stop()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_gpsSource && isRunning()) {
+        m_gpsSource->stopUpdates();
+        m_running = false;
+    }
+}
+
+bool GPSPosition::isRunning()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_running;
+}
+
+void GPSPosition::update()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit m_gpsSource->requestUpdate(DEFAULT_UPDATE_INTERVAL);
+}
+
+void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit position(QPointF(positionInfo.coordinate().longitude(),
+                          positionInfo.coordinate().latitude()));
+}
+
+void GPSPosition::updateTimeout()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit timeout();
+}
diff --git a/src/gps/gpsposition.h b/src/gps/gpsposition.h
new file mode 100644 (file)
index 0000000..15aa158
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+   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 GPSPOSITION_H
+#define GPSPOSITION_H
+
+#include <QGeoPositionInfoSource>
+#include <QPointF>
+
+QTM_USE_NAMESPACE
+
+/**
+* @brief GPSPosition class use GPS to receive location information.
+*
+* @class GPSPosition engine.h "gps/gpsposition.h"
+*/
+class GPSPosition : public QObject
+{
+    Q_OBJECT
+
+public:
+    /**
+    * @brief Start GPS.
+    */
+    GPSPosition(QObject *parent = 0);
+    ~GPSPosition();
+
+/******************************************************************************
+* MEMBER FUNCTIONS AND SLOTS
+******************************************************************************/
+public:
+    /**
+    * @brief Checks if GPS is running.
+    *
+    * @return true if GPS running, false otherwise
+    */
+    bool isRunning();
+
+    /**
+    * @brief Start GPS.
+    */
+    void start();
+
+    /**
+    * @brief Stop GPS.
+    */
+    void stop();
+
+    /**
+    * @brief Request GPS update.
+    */
+    void update();
+
+private slots:
+
+    /**
+    * @brief Slot for received position update.
+    *
+    * @param positionInfo Geo position info.
+    */
+    void positionUpdated(QGeoPositionInfo positionInfo);
+
+    /**
+    * @brief Slot for update timeout.
+    *
+    * Called when request timeout occurs.
+    */
+    void updateTimeout();
+
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
+signals:
+    /**
+    * @brief Signal for position information.
+    *
+    * @param latLonCoordinate latitude and longitude values
+    */
+    void position(QPointF latLonCoordinate);
+
+    /**
+    * @brief Signal for timeout.
+    */
+    void timeout();
+
+    /**
+    * @brief Signal for error.
+    *
+    * @param message error message
+    */
+    void error(const QString &message);
+
+private:
+    QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
+    bool m_running;                             ///< GPS is running
+    int m_updateInterval;                       ///< GPS update interval
+};
+
+const int DEFAULT_UPDATE_INTERVAL = 5000;   ///< Default update interval
+
+#endif // GPSPOSITION_H
index 8cd40d2..40210b4 100644 (file)
@@ -35,6 +35,8 @@
 #include "mapengine.h"
 #include "maptile.h"
 
+#include "gps/gpsposition.h"
+
 MapEngine::MapEngine(QObject *parent)
     : QObject(parent)
     , m_centerTile(QPoint(UNDEFINED, UNDEFINED))
index eecab14..a468092 100644 (file)
@@ -43,7 +43,8 @@ SOURCES += main.cpp \
     ui/panelsidebar.cpp \
     ui/panelsliderbar.cpp \
     map/friendgroupitem.cpp \
-    map/frienditemshandler.cpp
+    map/frienditemshandler.cpp \
+       gps/gpsposition.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
     ui/listviewscreen.h \
@@ -84,10 +85,15 @@ HEADERS += ui/mainwindow.h \
     ui/panelsidebar.h \
     ui/panelsliderbar.h \
     map/friendgroupitem.h \
-    map/frienditemshandler.h
+    map/frienditemshandler.h \
+       gps/gpsposition.h
 QT += network \
     webkit
 
+CONFIG += mobility
+
+MOBILITY = location
+
 DEFINES += QT_NO_DEBUG_OUTPUT
 
 !maemo5 {
index edcacaa..7bcdac3 100644 (file)
 */
 
 #include <QtGui>
+
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
+#endif // Q_WS_MAEMO_5
+
 #include "mainwindow.h"
 #include "listviewscreen.h"
 #include "mapviewscreen.h"
@@ -61,7 +66,15 @@ MainWindow::MainWindow(QWidget *parent)
     connect(m_listViewScreen, SIGNAL(updateFriendsData()),
             this, SIGNAL(refreshUserData()));
 
+    connect(this, SIGNAL(enableAutoCentering(bool)),
+            m_mapViewScreen, SLOT(enableAutoCentering(bool)));
+    connect(this, SIGNAL(positionReceived(QPointF)),
+            m_mapViewScreen, SLOT(positionReceived(QPointF)));
+
     this->toggleProgressIndicator(true);
+
+    //Debug, use settings instead
+    autoCenteringToggled(true);
 }
 
 MainWindow::~MainWindow()
@@ -95,10 +108,20 @@ void MainWindow::createMenus()
     m_toSettingsAct = new QAction(tr("Settings"), this);
     m_toSettingsAct->setObjectName(tr("Settings"));
     connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
+    m_gpsToggleAct = new QAction(tr("GPS enabled"), this);
+    m_gpsToggleAct->setCheckable(true);
+    m_gpsToggleAct->setChecked(true);
+    connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
+    m_autoCenteringAct = new QAction(tr("Auto centering enabled"), this);
+    m_autoCenteringAct->setCheckable(true);
+    m_autoCenteringAct->setChecked(true);
+    connect(m_autoCenteringAct, SIGNAL(toggled(bool)), this, SLOT(autoCenteringToggled(bool)));
     m_viewMenu = menuBar()->addMenu(tr("View"));
     m_viewMenu->addAction(m_toListViewAct);
     m_viewMenu->addAction(m_toMapViewAct);
     m_viewMenu->addAction(m_toSettingsAct);
+    m_viewMenu->addAction(m_gpsToggleAct);
+    m_viewMenu->addAction(m_autoCenteringAct);
     m_viewMenu->setObjectName(tr("View Menu"));
 }
 
@@ -160,3 +183,61 @@ void MainWindow::openSettingsDialog()
     SettingsDialog *dialog = new SettingsDialog(this);
     dialog->show();
 }
+
+void MainWindow::gpsActionToggled(bool checked)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (checked) {
+        emit enableGPS(true);
+        m_gpsToggleAct->setText(tr("GPS enabled"));
+        showMaemoInformationBox(tr("GPS enabled"));
+        m_autoCenteringAct->setEnabled(true);
+    }
+    else {
+        emit enableGPS(false);
+        m_gpsToggleAct->setText(tr("GPS disabled"));
+        showMaemoInformationBox(tr("GPS disabled"));
+        m_autoCenteringAct->setEnabled(false);
+    }
+}
+
+void MainWindow::gpsTimeout()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    showMaemoInformationBox(tr("GPS timeout"));
+}
+
+void MainWindow::gpsError(const QString &message)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    showMaemoInformationBox(message);
+}
+
+void MainWindow::autoCenteringToggled(bool checked)
+{
+    qDebug() << __PRETTY_FUNCTION__ << " " << checked;
+
+    if (checked) {
+        emit enableAutoCentering(true);
+        m_autoCenteringAct->setText(tr("Auto centering enabled"));
+        showMaemoInformationBox(tr("Auto centering enabled"));
+    }
+    else {
+        emit enableAutoCentering(false);
+        m_autoCenteringAct->setText(tr("Auto centering disabled"));
+        showMaemoInformationBox(tr("Auto centering disabled"));
+    }
+}
+
+void MainWindow::showMaemoInformationBox(const QString &message)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+        QMaemo5InformationBox::information(this, message,
+                                           QMaemo5InformationBox::DefaultTimeout);
+#endif // Q_WS_MAEMO_5
+}
index 61565cb..8f68f2f 100644 (file)
@@ -105,6 +105,8 @@ private:
     */
     void switchView(int);
 
+    void showMaemoInformationBox(const QString &message);
+
 private slots:
     /**
     * @brief Private slot, which starts UpdateLocationDialog
@@ -112,6 +114,34 @@ private slots:
     */
     void openLocationUpdateDialog();
 
+    /**
+    * @brief Slot for gps enabling.
+    *
+    * @param checked true if button state is checked, false otherwise
+    */
+    void gpsActionToggled(bool checked);
+
+    /**
+    * @brief Slot for gps timeout.
+    *
+    * Called when request timeout occurs.
+    */
+    void gpsTimeout();
+
+    /**
+    * @brief Slot for gps error.
+    *
+    * @param message error message
+    */
+    void gpsError(const QString &message);
+
+    /**
+    * @brief Slot for auto centering enabling.
+    *
+    * @param checked true if button state is checked, false otherwise
+    */
+    void autoCenteringToggled(bool checked);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -157,6 +187,27 @@ signals:
     */
     void refreshUserData();
 
+    /**
+    * @brief Signal for gps position.
+    *
+    * @param position longitude and latitude values
+    */
+    void positionReceived(QPointF position);
+
+    /**
+    * @brief Signal for gps enabling.
+    *
+    * @param enabled true if gps should be enabled
+    */
+    void enableGPS(bool enabled);
+
+    /**
+    * @brief Signal for map auto centering
+    *
+    * @param enabled true if map should auto center to gps location
+    */
+    void enableAutoCentering(bool enabled);
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
@@ -165,6 +216,8 @@ private:
     UpdateLocationDialog *m_locationDialog; ///< Message dialog
     MapViewScreen *m_mapViewScreen; ///< Instance of the map view
     QStackedWidget *m_situareViews; ///< Stacked widget that hold both view widgets
+    QAction *m_autoCenteringAct;    ///< Action to auto center map using gps position
+    QAction *m_gpsToggleAct;    ///< Action to trigger gps toggle
     QAction *m_toListViewAct; ///< Action to trigger switch to list view
     QAction *m_toMapViewAct; ///< Action to trigger switch to map view
     QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
index 6154842..3cf787f 100644 (file)
@@ -31,7 +31,8 @@
 #include "panelsidebar.h"
 
 MapViewScreen::MapViewScreen(QWidget *parent)
-   : QWidget(parent)
+   : QWidget(parent),
+     m_autoCenteringEnabled(false)
 {
     MapView *mapView = new MapView(this);
     mapEngine = new MapEngine(this);
@@ -105,3 +106,18 @@ void MapViewScreen::drawOsmLicense(int width, int height)
     osmLicense->move(width - osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
                      height - osmLicense->fontMetrics().height());
 }
+
+void MapViewScreen::positionReceived(QPointF position)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_autoCenteringEnabled)
+        mapEngine->setViewLocation(position);
+}
+
+void MapViewScreen::enableAutoCentering(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_autoCenteringEnabled = enabled;
+}
index ad7ba1f..9034622 100644 (file)
@@ -51,6 +51,14 @@ public:
  ******************************************************************************/
 
 private slots:
+
+    /**
+    * @brief Slot for enabling auto centering.
+    *
+    * @param enabled true if map should center to GPS position, false otherwise
+    */
+    void enableAutoCentering(bool enabled);
+
     /**
     * @brief Slot for drawing the Open Street Map license text
     *
@@ -59,6 +67,13 @@ private slots:
     */
     void drawOsmLicense(int width, int height);
 
+    /**
+    * @brief Slot for GPS position.
+    *
+    * @param position latitude and longitude values
+    */
+    void positionReceived(QPointF position);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -84,6 +99,7 @@ signals:
  ******************************************************************************/
 
 private:
+    bool m_autoCenteringEnabled;        ///< Enable
     FriendListPanel *friendsListPanel; ///< Instance of friends list panel
     MapEngine *mapEngine; ///< MapEngine
     QLabel *osmLicense; ///< Label for Open Street Map license