#include "map/mapengine.h"
#include "situareservice/situareservice.h"
#include "ui/mainwindow.h"
+#include "networkhandler.h"
#include "engine.h"
qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
+ // build NetworkHandler
+ m_networkHandler = new NetworkHandler(this);
+
// build MapEngine
m_mapEngine = new MapEngine(this);
m_ui->setMapViewScene(m_mapEngine->scene());
m_facebookAuthenticator = new FacebookAuthentication(this);
// connect signals
+ signalsFromNetworkHandler();
signalsFromMapEngine();
signalsFromGPS();
signalsFromSituareService();
if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
+ //Request network connection.
+// m_networkHandler->connect();
m_facebookAuthenticator->start();
}
enableAutoCentering(enabled);
}
+void SituareEngine::connectedToNetwork()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+// m_facebookAuthenticator->start();
+ //TODO: Start map image fetching
+}
+
void SituareEngine::disableAutoCentering()
{
qDebug() << __PRETTY_FUNCTION__;
m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
}
+void SituareEngine::disconnectedFromNetwork()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ //TODO: Stop map image fetching
+}
+
void SituareEngine::enableAutoCentering(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
m_ui, SIGNAL(locationItemClicked(QList<QString>)));
}
+void SituareEngine::signalsFromNetworkHandler()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ connect(m_networkHandler, SIGNAL(connected()),
+ this, SLOT(connectedToNetwork()));
+
+ connect(m_networkHandler, SIGNAL(disconnected()),
+ this, SLOT(disconnectedFromNetwork()));
+}
+
void SituareEngine::signalsFromSituareService()
{
qDebug() << __PRETTY_FUNCTION__;
class MapEngine;
class SituareService;
class User;
+class NetworkHandler;
/**
* @brief Engine class for Situare Application
void signalsFromMapView();
/**
+ * @brief Connect signals coming from NetworkHandler.
+ */
+ void signalsFromNetworkHandler();
+
+ /**
* @brief Connect signals coming from Situare
*/
void signalsFromSituareService();
void changeAutoCenteringSetting(bool enabled);
/**
+ * @brief Slot for connected to network.
+ *
+ * Starts network requests.
+ */
+ void connectedToNetwork();
+
+ /**
* @brief Slot for disabling automatic centering when map is scrolled manually
*/
void disableAutoCentering();
/**
+ * @brief Slot for disconnecting from network.
+ *
+ * Stops all network requests.
+ */
+ void disconnectedFromNetwork();
+
+ /**
* @brief Slot for auto centering enabling.
*
* Calls gps to send last known position
MainWindow *m_ui; ///< Instance of the MainWindow UI
MapEngine *m_mapEngine; ///< MapEngine
SituareService *m_situareService; ///< Instance of the situare server communication service
+ NetworkHandler *m_networkHandler; ///< Instance of NetworkHandler
};
#endif // ENGINE_H
--- /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.
+*/
+
+#include <QNetworkRequest>
+
+#include "networkhandler.h"
+#include "networkaccessmanager.h"
+
+NetworkAccessManager::NetworkAccessManager(QObject *parent)
+ : QNetworkAccessManager(parent),
+ m_networkHandler(0)
+{
+ m_networkHandler = new NetworkHandler(this);
+
+ connect(m_networkHandler, SIGNAL(connected()),
+ this, SLOT(connected()));
+}
+
+QNetworkReply *NetworkAccessManager::getti(const QNetworkRequest &request)
+{
+ if (!m_networkHandler->isConnected()) {
+ m_requestQueue.append(request);
+ m_networkHandler->connect();
+ return createRequest(QNetworkAccessManager::GetOperation, request);
+ }
+ else {
+ return get(request);
+ }
+}
+
+void NetworkAccessManager::connected()
+{
+ foreach (QNetworkRequest request, m_requestQueue)
+ get(request);
+
+ m_requestQueue.clear();
+}
--- /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 NETWORKACCESSMANAGER_H
+#define NETWORKACCESSMANAGER_H
+
+#include <QNetworkAccessManager>
+#include <QList>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+
+class NetworkHandler;
+
+class NetworkAccessManager : public QNetworkAccessManager
+{
+ Q_OBJECT
+
+public:
+ NetworkAccessManager(QObject *parent = 0);
+
+ QNetworkReply *getti(const QNetworkRequest &request);
+
+private slots:
+ void connected();
+
+private:
+ NetworkHandler *m_networkHandler;
+ QList<QNetworkRequest> m_requestQueue;
+};
+
+#endif // NETWORKACCESSMANAGER_H
--- /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.
+*/
+
+#include <icd/dbus_api.h>
+
+#include "networkhandler.h"
+
+static QDBusConnection dBusConnection = QDBusConnection::systemBus();
+const int CONNECTION_STATE_INDEX = 7;
+enum ConnectionState {DISCONNECTED, CONNECTING, CONNECTED, DISCONNECTING};
+
+NetworkHandler::NetworkHandler(QObject *parent)
+ : QObject(parent),
+ m_connected(false)
+{
+ dBusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
+ ICD_DBUS_API_INTERFACE, dBusConnection);
+
+ dBusConnection.connect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, ICD_DBUS_API_INTERFACE,
+ ICD_DBUS_API_STATE_SIG,
+ this, SLOT(stateChanged(const QDBusMessage &)));
+}
+
+void NetworkHandler::stateChanged(const QDBusMessage &message)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if (message.arguments().count() >= 8) {
+
+ bool conversionOk;
+ int connectionState = message.arguments().at(CONNECTION_STATE_INDEX).toInt(&conversionOk);
+
+ if (conversionOk) {
+ if (connectionState == DISCONNECTED) {
+ m_connected = false;
+ emit disconnected();
+ }
+ else if (connectionState == CONNECTED) {
+ m_connected = true;
+ emit connected();
+ }
+ }
+ }
+}
+
+void NetworkHandler::connect()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ dBusInterface->call(ICD_DBUS_API_CONNECT_REQ,
+ QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
+}
+
+void NetworkHandler::disconnect()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ dBusInterface->call(ICD_DBUS_API_DISCONNECT_REQ,
+ QVariant((unsigned int)ICD_CONNECTION_FLAG_USER_EVENT));
+}
+
+bool NetworkHandler::isConnected()
+{
+ return m_connected;
+}
--- /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 NETWORKHANDLER_H
+#define NETWORKHANDLER_H
+
+#include <QtDBus>
+
+/**
+* @brief NetworkHandler class.
+*
+* This class handles network connection. Class notifies about
+* network connection states.
+*/
+class NetworkHandler : public QObject
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief Constructor.
+ *
+ * Creates ICD D-Bus interface.
+ */
+ NetworkHandler(QObject *parent = 0);
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+ /**
+ * @brief Requests network connection.
+ *
+ * Request is done via ICD D-Bus.
+ */
+ void connect();
+
+ /**
+ * @brief Requests to disconnect a connection.
+ *
+ * Request is done via ICD D-Bus.
+ */
+ void disconnect();
+
+ /**
+ * @brief Checks if connected to network.
+ *
+ * @return true if connected, false otherwise
+ */
+ bool isConnected();
+
+private slots:
+ /**
+ * @brief Slot for ICD D-Bus state change.
+ *
+ * @param message received D-Bus message
+ */
+ void stateChanged(const QDBusMessage &message);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+ /**
+ * @brief Signals when connected to network.
+ */
+ void connected();
+
+ /**
+ * @brief Signals when disconnected from network.
+ */
+ void disconnected();
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+ QDBusInterface *dBusInterface; ///< D-Bus interface
+ bool m_connected; ///< Connection state variable
+};
+
+#endif // NETWORKHANDLER_H
m_mapScene = new MapScene(this);
- m_mapFetcher = new MapFetcher(new QNetworkAccessManager(this), this);
+ m_mapFetcher = new MapFetcher(new NetworkAccessManager(this), this);
connect(this, SIGNAL(fetchImage(int, int, int)),
m_mapFetcher, SLOT(enqueueFetchMapImage(int, int, int)));
connect(m_mapFetcher, SIGNAL(mapImageReceived(int, int, int, QPixmap)),
#include "mapfetcher.h"
#include "mapcommon.h"
+#include "engine/networkaccessmanager.h"
const int MAX_PARALLEL_DOWNLOADS = 2; ///< Max simultaneous parallel downloads
const int NOT_FOUND = -1; ///< Return value if matching request is not found from the list
-MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent)
+MapFetcher::MapFetcher(NetworkAccessManager *manager, QObject *parent)
: QObject(parent)
, m_pendingRequestsSize(0)
, m_fetchMapImagesTimerRunning(false)
QNetworkRequest request(url);
request.setRawHeader("User-Agent", "Situare");
- QNetworkReply *reply = m_manager->get(request);
+ QNetworkReply *reply = m_manager->getti(request);
m_currentDownloads.append(reply);
}
#include <QNetworkAccessManager>
#include "maptilerequest.h"
+#include "engine/networkaccessmanager.h"
class QNetworkReply;
class QUrl;
* @param manager Network access manager
* @param parent parent object
*/
- MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0);
+ MapFetcher(NetworkAccessManager *manager, QObject *parent = 0);
/*******************************************************************************
* CLASS SPECIFIC MEMBER FUNCTIONS AND SLOTS
QList<QNetworkReply*> m_currentDownloads; ///< List of current downloads
int m_pendingRequestsSize; ///< Max number of pending requests
bool m_fetchMapImagesTimerRunning; ///< is the singleshot timer already running
- QNetworkAccessManager *m_manager; ///< Network access manager
+ NetworkAccessManager *m_manager; ///< Network access manager
QList<MapTileRequest> m_pendingRequests; ///< List of map image fetching requests
};
# -------------------------------------------------
TARGET = ../situare
TEMPLATE = app
-INCLUDEPATH += "/usr/include/qjson"
-LIBS += "-lqjson"
+INCLUDEPATH += /usr/include/qjson /usr/include/glib-2.0 /usr/lib/glib-2.0/include
+LIBS += -lqjson
+CONFIG += icd2 qdbus
RESOURCES += ../images.qrc
SOURCES += main.cpp \
ui/mainwindow.cpp \
map/gpslocationitem.cpp \
ui/zoombuttonpanel.cpp \
ui/userinfo.cpp \
- ui/sidepanel.cpp
+ engine/networkhandler.cpp \
+ ui/sidepanel.cpp \
+ engine/networkaccessmanager.cpp
HEADERS += ui/mainwindow.h \
map/mapengine.h \
map/mapview.h \
ui/zoombuttonpanel.h \
common.h \
ui/userinfo.h \
- ui/sidepanel.h
+ engine/networkhandler.h \
+ ui/sidepanel.h \
+ engine/networkaccessmanager.h
QT += network \
webkit