Moved gps settings from situarecommon.h to engine.cpp.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 14 May 2010 12:42:13 +0000 (15:42 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 14 May 2010 12:42:13 +0000 (15:42 +0300)
src/engine/engine.cpp
src/gps/gpsposition.cpp
src/gps/gpsposition.h
src/gps/gpspositioninterface.h
src/gps/gpspositionmockup.h
src/situarecommon.h
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h

index 1c43872..ca2afd4 100644 (file)
@@ -32,6 +32,9 @@
 #include "gps/gpspositionmockup.h"
 #endif
 
+const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED";
+const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
+
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
       m_autoCenteringEnabled(false),
@@ -97,8 +100,8 @@ SituareEngine::SituareEngine(QMainWindow *parent)
             m_ui, SLOT(loginFailed()));
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    QVariant gpsEnabled = settings.value(GPS_ENABLED);
-    QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
+    QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
+    QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
 
     enableGPS(gpsEnabled.toBool());
     enableAutoCentering(autoCenteringEnabled.toBool());
@@ -115,8 +118,8 @@ SituareEngine::~SituareEngine()
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
     qDebug() << __PRETTY_FUNCTION__ << m_gpsEnabled;
     qDebug() << __PRETTY_FUNCTION__ << m_autoCenteringEnabled;
-    settings.setValue(GPS_ENABLED, m_gpsEnabled);
-    settings.setValue(AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
+    settings.setValue(SETTINGS_GPS_ENABLED, m_gpsEnabled);
+    settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
 }
 
 void SituareEngine::loginProcessCancelled()
@@ -146,7 +149,13 @@ void SituareEngine::requestAddress()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
+    QPointF coordinates;
+
+    if (m_gpsEnabled)
+        coordinates = m_gps->lastPosition();
+    else
+        coordinates = QPointF(0, 0);    //Manual position from map
+
     m_situareService->reverseGeo(coordinates);
 }
 
@@ -156,7 +165,13 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
 
     m_ui->toggleProgressIndicator(true);
 
-    QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
+    QPointF coordinates;
+
+    if (m_gpsEnabled)
+        coordinates = m_gps->lastPosition();
+    else
+        coordinates = QPointF(0, 0);    //Manual position from map
+
     m_situareService->updateLocation(coordinates, status, publish);
 }
 
@@ -193,7 +208,7 @@ void SituareEngine::enableGPS(bool enabled)
     m_gpsEnabled = enabled;
 
     if (enabled) {
-        m_gps->lastPosition();
+        m_gps->requestLastPosition();
         m_gps->start();
         m_ui->setGPSButton(true);
     }
@@ -212,7 +227,7 @@ void SituareEngine::enableAutoCentering(bool enabled)
     if (enabled) {
         m_ui->setAutoCenteringButton(true);
         m_ui->autoCenteringEnabled(true);
-        m_gps->lastPosition();
+        m_gps->requestLastPosition();
     }
     else {
         m_ui->setAutoCenteringButton(false);
index 676fda1..e286cbb 100644 (file)
@@ -106,7 +106,13 @@ void GPSPosition::update()
     emit m_gpsSource->requestUpdate(DEFAULT_UPDATE_INTERVAL);
 }
 
-void GPSPosition::lastPosition()
+QPointF GPSPosition::lastPosition()
+{
+    QGeoCoordinate coordinate = m_gpsSource->lastKnownPosition().coordinate();
+    return QPointF(coordinate.longitude(), coordinate.latitude());
+}
+
+void GPSPosition::requestLastPosition()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -120,7 +126,7 @@ void GPSPosition::lastPosition()
 
 void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__ << positionInfo;
 
     if (positionInfo.coordinate().isValid()) {
 
index c2fa7d4..af614ce 100644 (file)
@@ -65,9 +65,14 @@ public:
     bool isRunning();
 
     /**
+    * @brief Return last known position.
+    */
+    QPointF lastPosition();
+
+    /**
     * @brief Informs gps to emit last known position.
     */
-    void lastPosition();
+    void requestLastPosition();
 
     /**
     * @brief Set GPS mode.
@@ -131,7 +136,7 @@ private:
     int m_updateInterval;                       ///< GPS update interval
 };
 
-const int ACCURACY_UNDEFINED = 1;               ///< Undefined accuracy
+const int ACCURACY_UNDEFINED = -1;               ///< Undefined accuracy
 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
 
 #endif // GPSPOSITION_H
index d86ac26..7441fe2 100644 (file)
@@ -62,9 +62,14 @@ public:
     virtual bool isRunning() = 0;
 
     /**
+    * @brief Return last known position.
+    */
+    virtual QPointF lastPosition() = 0;
+
+    /**
     * @brief Informs gps to emit last known position.
     */
-    virtual void lastPosition() = 0;
+    virtual void requestLastPosition() = 0;
 
     /**
     * @brief Set GPS mode.
index b145c15..072aa3e 100644 (file)
@@ -59,11 +59,14 @@ public:
     bool isRunning();
 
     /**
+    * @brief Return last known position.
+    */
+    QPointF lastPosition();
+
+    /**
     * @brief Informs gps to emit last known position.
-    *
-    * DOES NOTHING.
     */
-    void lastPosition();
+    void requestLastPosition();
 
     /**
     * @brief Set GPS update interval.
index d4d842b..fa8da52 100644 (file)
@@ -28,7 +28,4 @@
 const QString DIRECTORY_NAME = "Ixonos";
 const QString FILE_NAME = "Situare";
 
-const QString GPS_ENABLED = "GPS_ENABLED";
-const QString AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
-
 #endif // SITUARECOMMON_H
index ee7e8eb..a412899 100644 (file)
 #include "avatarimage.h"
 #include "imagebutton.h"
 
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
+const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
+const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
+const int ICON_HEIGHT = 24;     ///< Icon height
+const int ICON_WIDTH = 24;       ///< Icon width
+const int IMAGE_HEIGHT = 60; ///< Friend image height
+const int IMAGE_WIDTH = 60;  ///< Friend image width
+const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
+const int ITEM_MAX_WIDTH = 368;  ///< Maximum width for item
+const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
+const int ITEM_MIN_WIDTH = 368;  ///< Minimum width for item
+const int MARGIN = 5;   ///< Icon margin
+const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
+const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
+/**
+* @var NAME_LABEL_MAX_WIDTH
+*
+* @brief Name label's maximum width
+*/
+const int NAME_LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH;
+/**
+* @var LABEL_MAX_WIDTH
+*
+* @brief All label's maximum width
+*/
+const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
+
 FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
     , m_expanded(false)
@@ -210,14 +239,14 @@ void FriendListItem::setText(bool expanded)
 
 void FriendListItem::mousePressEvent(QMouseEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_mousePosition = event->pos();
 }
 
 void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+    qDebug() << __PRETTY_FUNCTION__;
 
     if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
         (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
@@ -234,7 +263,9 @@ void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
 
 void FriendListItem::paintEvent(QPaintEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(event);
 
     QPainter painter(this);
 
index 79bf67e..2c6c3a6 100644 (file)
@@ -142,33 +142,4 @@ private:
     User *m_user;                    ///< User data
 };
 
-const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
-const int ICON_HEIGHT = 24;     ///< Icon height
-const int ICON_WIDTH = 24;       ///< Icon width
-const int IMAGE_HEIGHT = 60; ///< Friend image height
-const int IMAGE_WIDTH = 60;  ///< Friend image width
-const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
-const int ITEM_MAX_WIDTH = 368;  ///< Maximum width for item
-const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
-const int ITEM_MIN_WIDTH = 368;  ///< Minimum width for item
-const int MARGIN = 5;   ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
-/**
-* @var NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
-
 #endif // FRIENDLISTITEM_H