USA.
*/
+#include "situarecommon.h"
#include "engine.h"
#include "ui/mainwindow.h"
#include "gps/gpspositioninterface.h"
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)));
+ connect(m_gps, SIGNAL(position(QPointF, qreal)),
+ m_ui, SIGNAL(positionReceived(QPointF, qreal)));
+ connect(m_ui, SIGNAL(enableAutoCentering(bool)),
+ this, SLOT(enableAutoCentering(bool)));
m_facebookAuthenticator->start();
}
SituareEngine::~SituareEngine()
{
qDebug() << __PRETTY_FUNCTION__;
+
delete m_ui;
}
{
qDebug() << __PRETTY_FUNCTION__;
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ QVariant gpsEnabled = settings.value(GPS_ENABLED);
+ QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
+
m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
m_facebookAuthenticator->close();
m_ui->show();
m_situareService->fetchLocations(); // request user locations
- //Debug, use settings instead
- enableGPS(true);
- m_ui->autoCenteringToggled(true);
+ qDebug() << __PRETTY_FUNCTION__ << "GPS: " << gpsEnabled;
+ qDebug() << __PRETTY_FUNCTION__ << "Center: " << autoCenteringEnabled;
+ enableGPS(gpsEnabled.toBool());
+ enableAutoCentering(autoCenteringEnabled.toBool());
}
void SituareEngine::requestAddress()
void SituareEngine::enableGPS(bool enabled)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__ << enabled;
- if (enabled)
+ if (enabled) {
+ m_gps->lastPosition();
m_gps->start();
- else
+ m_ui->setGPSButton(true);
+ }
+ else {
m_gps->stop();
+ m_ui->setGPSButton(false);
+ }
+}
+
+void SituareEngine::enableAutoCentering(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__ << enabled;
+
+ if (enabled) {
+ m_ui->setAutoCenteringButton(true);
+ m_ui->autoCenteringEnabled(true);
+ m_gps->lastPosition();
+ }
+ else {
+ m_ui->setAutoCenteringButton(false);
+ m_ui->autoCenteringEnabled(false);
+ }
}
void userDataChanged(User *user, QList<User *> &friendsList);
/**
+ * @brief Slot for auto centering enabling.
+ *
+ * Calls gps to send last known position
+ * @parma enabled true if auto centering was enabled, false otherwise
+ */
+ void enableAutoCentering(bool enabled);
+
+ /**
* @brief Slot for gps enabling.
*
* @parma enabled true if gps should be enabled, false otherwise
#include <QMaemo5InformationBox>
#endif // Q_WS_MAEMO_5
+#include "situarecommon.h"
#include "facebookauthentication.h"
#include "facebookcommon.h"
#include "parser.h"
const QString LOGIN_FAILURE_REPLY = "https://login.facebook.com/login.php?login_attempt=";
const QString LOGIN_PAGE = "http://www.facebook.com/login.php?api_key=";
-// QSettings identifiers
-const QString DIRECTORY_NAME = "Ixonos";
-const QString FILE_NAME = "Situare";
-
#endif // FACEBOOKCOMMON_H
emit m_gpsSource->requestUpdate(DEFAULT_UPDATE_INTERVAL);
}
+void GPSPosition::lastPosition()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QGeoCoordinate coordinate = m_gpsSource->lastKnownPosition().coordinate();
+
+ if (coordinate.isValid()) {
+ qreal accuracy = biggerAccuracy(m_gpsSource->lastKnownPosition());
+ emit position(QPointF(coordinate.longitude(), coordinate.latitude()), accuracy);
+ }
+}
+
void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
{
qDebug() << __PRETTY_FUNCTION__;
- emit position(QPointF(positionInfo.coordinate().longitude(),
- positionInfo.coordinate().latitude()));
+ if (positionInfo.coordinate().isValid()) {
+
+ qreal accuracy = biggerAccuracy(positionInfo);
+
+ emit position(QPointF(positionInfo.coordinate().longitude(),
+ positionInfo.coordinate().latitude()), accuracy);
+ }
}
void GPSPosition::updateTimeout()
void GPSPosition::setUpdateInterval(int interval)
{
+ qDebug() << __PRETTY_FUNCTION__;
+
if (m_updateInterval != interval) {
m_updateInterval = interval;
m_gpsSource->setUpdateInterval(m_updateInterval);
}
}
+
+qreal GPSPosition::biggerAccuracy(QGeoPositionInfo positionInfo)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qreal horizontalAccuracy = -1;
+ qreal verticalAccuracy = -1;
+
+ if (positionInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
+ horizontalAccuracy = positionInfo.attribute(QGeoPositionInfo::HorizontalAccuracy);
+
+ if (positionInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy))
+ verticalAccuracy = positionInfo.attribute(QGeoPositionInfo::VerticalAccuracy);
+
+ int accuracy = verticalAccuracy;
+
+ if (horizontalAccuracy > accuracy)
+ accuracy = horizontalAccuracy;
+
+ return accuracy;
+}
bool isRunning();
/**
+ * @brief Informs gps to emit last known position.
+ */
+ void lastPosition();
+
+ /**
* @brief Set GPS update interval
*
* @return interval interval in milliseconds
*/
void stop();
+private:
+ /**
+ * @brief Return bigger accuracy value from latitude and longitude values.
+ *
+ * @param positionInfo geo position info
+ * @return bigger accuracy value, -1 if undefined
+ */
+ qreal biggerAccuracy(QGeoPositionInfo positionInfo);
+
private slots:
/**
virtual bool isRunning() = 0;
/**
+ * @brief Informs gps to emit last known position.
+ */
+ virtual void lastPosition() = 0;
+
+ /**
* @brief Set GPS update interval
*
* @return interval interval in milliseconds
* @brief Signal for position information.
*
* @param latLonCoordinate latitude and longitude values
+ * @param accuracy accuracy in metres
*/
- void position(QPointF latLonCoordinate);
+ void position(QPointF latLonCoordinate, qreal accuracy);
/**
* @brief Signal for timeout.
{
qDebug() << __PRETTY_FUNCTION__;
}
+
+void GPSPositionMockup::lastPosition()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
bool isRunning();
/**
+ * @brief Informs gps to emit last known position.
+ *
+ * DOES NOTHING.
+ */
+ void lastPosition();
+
+ /**
* @brief Set GPS update interval.
*
* DOES NOTHING.
const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
+const int AUTO_CENTERING_DISABLE_DISTANCE = 200; ///< Distance in pixels
+
/**
* @var UNDEFINED
* @brief Value to be used when zoom level, tile numbers or position are not defined
MapEngine::MapEngine(QObject *parent)
: QObject(parent)
+ , m_autoCenteringEnabled(false)
, m_centerTile(QPoint(UNDEFINED, UNDEFINED))
+ , m_lastManualPosition(QPoint(0, 0))
, m_viewSize(QSize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT))
, m_zoomedIn(false)
, m_zoomLevel(DEFAULT_ZOOM_LEVEL)
+
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- setLocation(convertLatLonToSceneCoordinate(latLonCoordinate));
+ QPoint sceneCoordinate = convertLatLonToSceneCoordinate(latLonCoordinate);
+
+ m_lastManualPosition = sceneCoordinate;
+
+ setLocation(sceneCoordinate);
}
void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
+ if (disableAutoCentering(sceneCoordinate))
+ emit mapScrolled();
+
m_sceneCoordinate = sceneCoordinate;
emit locationChanged(m_sceneCoordinate);
if (!m_ownLocation->isVisible())
m_ownLocation->show();
}
+
+bool MapEngine::disableAutoCentering(QPoint sceneCoordinate)
+{
+ if (isAutoCenteringEnabled()) {
+ QPoint oldPixelValue = QPoint(m_lastManualPosition.x() / m_zoomLevel,
+ m_lastManualPosition.y() / m_zoomLevel);
+
+ QPoint newPixelValue = QPoint(sceneCoordinate.x() / m_zoomLevel,
+ sceneCoordinate.y() / m_zoomLevel);
+
+ if ((abs(oldPixelValue.x() - newPixelValue.x()) > AUTO_CENTERING_DISABLE_DISTANCE) ||
+ (abs(oldPixelValue.y() - newPixelValue.y()) > AUTO_CENTERING_DISABLE_DISTANCE))
+ return true;
+ }
+
+ return false;
+}
+
+bool MapEngine::isAutoCenteringEnabled()
+{
+ return m_autoCenteringEnabled;
+}
+
+void MapEngine::setAutoCentering(bool enabled)
+{
+ m_autoCenteringEnabled = enabled;
+}
QGraphicsScene* scene();
/**
+ * @brief Set auto centering.
+ *
+ * @param enabled true if enabled, false otherwise
+ */
+ void setAutoCentering(bool enabled);
+
+ /**
* @brief Return tile path created from tile values.
*
* @param zoomLevel tile's zoom level
void getTiles(QPoint sceneCoordinate);
/**
+ * @brief Check if auto centering is enabled
+ *
+ * @param true if enabled, false otherwise
+ */
+ bool isAutoCenteringEnabled();
+
+ /**
* @brief Check if center tile has changed.
*
* @param sceneCoordinate scene's center coordinate
bool isCenterTileChanged(QPoint sceneCoordinate);
/**
+ * @brief Check if auto centering should be disabled.
+ *
+ * @param sceneCoordinate scene's center coordinate
+ * @return bool true if auto centering should be disabled
+ */
+ bool disableAutoCentering(QPoint sceneCoordinate);
+
+ /**
* @brief Calculate maximum value for tile in this zoom level.
*
* @param zoomLevel zoom level
void locationChanged(QPoint sceneCoordinate);
/**
+ * @brief Signal to notify map scrolling.
+ */
+ void mapScrolled();
+
+ /**
* @brief Signal for zoom level change
*
* @param newZoomLevel New zoom level
* DATA MEMBERS
******************************************************************************/
private:
+ bool m_autoCenteringEnabled; ///< Auto centering enabled
QPoint m_centerTile; ///< Current center tile
FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
+ QPoint m_lastManualPosition; ///< Last manually set position in scene coordinate
MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
MapScene *m_mapScene; ///< Scene for map tiles
MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons
--- /dev/null
+/*
+ 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 SITUARECOMMON_H
+#define SITUARECOMMON_H
+
+#include <QString>
+
+// QSettings identifiers
+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
ui/panelsliderbar.h \
map/friendgroupitem.h \
map/frienditemshandler.h \
- gps/gpspositioninterface.h
+ gps/gpspositioninterface.h \
+ situarecommon.h
QT += network \
webkit
#DEFINES += QT_NO_DEBUG_OUTPUT
m_distanceLabel = new QLabel();
m_distanceLabel->setFixedHeight(IMAGE_HEIGHT);
-// QLabel *button = new QLabel();
-// button->setPixmap(QPixmap(":/res/images/show_position.png"));
-// button->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
m_findButton = new ImageButton(this, ":/res/images/show_position.png",
":/res/images/show_position_s.png");
* SIGNALS
******************************************************************************/
signals:
-
+ /**
+ * @brief Signal for finding friend.
+ *
+ * @param coordinates friend's geo coordinates
+ */
void findFriend(const QPointF &coordinates);
/******************************************************************************
#include "settingsdialog.h"
#include "facebookservice/facebookauthentication.h"
#include "situareservice/situareservice.h"
+#include "situarecommon.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
- connect(this, SIGNAL(enableAutoCentering(bool)),
+ connect(this, SIGNAL(autoCentering(bool)),
m_mapViewScreen, SLOT(enableAutoCentering(bool)));
- connect(this, SIGNAL(positionReceived(QPointF)),
- m_mapViewScreen, SLOT(positionReceived(QPointF)));
+ connect(this, SIGNAL(positionReceived(QPointF, qreal)),
+ m_mapViewScreen, SLOT(positionReceived(QPointF, qreal)));
connect(m_mapViewScreen, SIGNAL(mapLocationChanged()), this, SLOT(mapLocationChanged()));
this->toggleProgressIndicator(true);
m_gpsToggleAct = new QAction(tr("GPS"), this);
m_gpsToggleAct->setCheckable(true);
m_gpsToggleAct->setChecked(true);
- connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
+ connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsToggled(bool)));
m_autoCenteringAct = new QAction(tr("Auto centering"), this);
m_autoCenteringAct->setCheckable(true);
m_autoCenteringAct->setChecked(true);
dialog->show();
}
-void MainWindow::gpsActionToggled(bool checked)
+void MainWindow::gpsToggled(bool checked)
{
qDebug() << __PRETTY_FUNCTION__;
- if (checked) {
+ if (checked)
emit enableGPS(true);
+ else
+ emit enableGPS(false);
+}
+
+void MainWindow::setGPSButton(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (enabled) {
showMaemoInformationBox(tr("GPS enabled"));
+ m_gpsToggleAct->setChecked(true);
m_autoCenteringAct->setVisible(true);
}
else {
- emit enableGPS(false);
showMaemoInformationBox(tr("GPS disabled"));
+ m_gpsToggleAct->setChecked(false);
m_autoCenteringAct->setVisible(false);
+ }
+}
+void MainWindow::setAutoCenteringButton(bool enabled)
+{
+ if (enabled) {
+ showMaemoInformationBox(tr("Auto centering enabled"));
+ m_autoCenteringAct->setChecked(true);
+ }
+ else {
+ showMaemoInformationBox(tr("Auto centering disabled"));
+ m_autoCenteringAct->setChecked(false);
}
}
{
qDebug() << __PRETTY_FUNCTION__;
- m_autoCenteringAct->setChecked(false);
+ emit enableAutoCentering(false);
}
void MainWindow::autoCenteringToggled(bool checked)
{
- qDebug() << __PRETTY_FUNCTION__ << " " << checked;
+ qDebug() << __PRETTY_FUNCTION__ << checked;
- if (checked) {
+ if (checked)
emit enableAutoCentering(true);
- showMaemoInformationBox(tr("Auto centering enabled"));
- }
- else {
+ else
emit enableAutoCentering(false);
- showMaemoInformationBox(tr("Auto centering disabled"));
- }
+}
+
+void MainWindow::autoCenteringEnabled(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__ << enabled;
+
+ emit autoCentering(enabled);
}
void MainWindow::showMaemoInformationBox(const QString &message)
Q_UNUSED(message);
#endif
}
+
+MainWindow::~MainWindow()
+{
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(GPS_ENABLED, m_gpsToggleAct->isChecked());
+ settings.setValue(AUTO_CENTERING_ENABLED, m_autoCenteringAct->isChecked());
+}
*/
MainWindow(QWidget *parent = 0);
+ /**
+ * @brief Destructor.
+ */
+ ~MainWindow();
+
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+public:
+ void setGPSButton(bool enabled);
+
+ void setAutoCenteringButton(bool enabled);
+
+ void autoCenteringEnabled(bool enabled);
+
public slots:
/**
* @brief Slot for auto centering enabling.
void autoCenteringToggled(bool checked);
/**
+ * @brief Slot for gps enabling.
+ *
+ * @param checked true if button state is checked, false otherwise
+ */
+ void gpsToggled(bool checked);
+
+ /**
* @brief Slot for map location change.
*/
void mapLocationChanged();
void showMaemoInformationBox(const QString &message);
private slots:
- /**
- * @brief Slot for gps enabling.
- *
- * @param checked true if button state is checked, false otherwise
- */
- void gpsActionToggled(bool checked);
-
/**
* @brief Slot for gps timeout.
*
* SIGNALS
******************************************************************************/
signals:
- /**
+ /**
* @brief Signal for map auto centering
*
* @param enabled true if map should auto center to gps location
*/
- void enableAutoCentering(bool enabled);
+ void autoCentering(bool enabled);
/**
* @brief Signal for gps enabling.
*/
void enableGPS(bool enabled);
+ /**
+ * @brief Signal for auto centering enabling.
+ *
+ * @param enabled if auto centering should be enabled
+ */
+ void enableAutoCentering(bool enabled);
+
/**
* @brief Signal for friend location ready.
*
*/
void friendsLocationsReady(QList<User *> &friendsList);
- /**
+ /**
* @brief Signal for gps position.
*
* @param position longitude and latitude values
+ * @param accuracy coordinate accuracy in metres
*/
- void positionReceived(QPointF position);
+ void positionReceived(QPointF position, qreal accuracy);
/**
* @brief Signal for refreshing user data.
private:
UpdateLocationDialog *m_locationDialog; ///< Message dialog
MapViewScreen *m_mapViewScreen; ///< Instance of the map view
- QAction *m_autoCenteringAct; ///< Action to auto center map using gps position
+ QAction *m_autoCenteringAct; ///< Action to auto center map using gps position
QAction *m_gpsToggleAct; ///< Action to trigger gps toggle
- QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
+ QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
QMenu *m_viewMenu; ///< Object that hold the view menu items
};
connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
- connect(mapView, SIGNAL(viewScrolled(QPoint)), this, SLOT(locationChanged()));
+ connect(mapEngine, SIGNAL(mapScrolled()), this, SLOT(locationChanged()));
QHBoxLayout *mapViewLayout = new QHBoxLayout;
void MapViewScreen::locationChanged()
{
- qDebug() << __PRETTY_FUNCTION__ << " m_autoCentering: " << m_autoCenteringEnabled;
+ qDebug() << __PRETTY_FUNCTION__;
if (m_autoCenteringEnabled)
emit mapLocationChanged();
}
-void MapViewScreen::positionReceived(QPointF position)
+void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
m_autoCenteringEnabled = enabled;
+ mapEngine->setAutoCentering(enabled);
}
* @brief Slot for GPS position.
*
* @param position latitude and longitude values
+ * @param accuracy coordinate accuracy in metres
*/
- void positionReceived(QPointF position);
+ void positionReceived(QPointF position, qreal accuracy);
/*******************************************************************************
* SIGNALS
#include <QtGui>
#include <QDebug>
-#include "facebookservice/facebookcommon.h"
+#include "situarecommon.h"
#include "settingsdialog.h"
const QString AUTOMATIC_LOCATION_UPDATE("Automatic_location_update");
void SettingsDialog::saveValues()
{
qDebug() << __PRETTY_FUNCTION__;
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
+// QSettings settings(DIRECTORY_NAME, FILE_NAME);
+// settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
accept();
}