Implemented CloudMade authentication using user token route_json
authorlampehe-local <henri.lampela@ixonos.com>
Wed, 21 Jul 2010 10:30:07 +0000 (13:30 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Wed, 21 Jul 2010 10:30:07 +0000 (13:30 +0300)
src/engine/engine.cpp
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapengine.h
src/routing/route.cpp
src/routing/route.h
src/routing/routesegment.cpp
src/routing/routesegment.h
src/routing/routingservice.cpp
src/routing/routingservice.h

index d1a269f..2c5850d 100644 (file)
@@ -86,8 +86,8 @@ SituareEngine::SituareEngine()
 
     // build routing service
     m_routingService = new RoutingService(this); // create this when needed, not in constructor!
-    connect(m_routingService, SIGNAL(routeParsed(Route)),
-            m_mapEngine, SLOT(setRoute(Route)));
+    connect(m_routingService, SIGNAL(routeParsed(Route&)),
+            m_mapEngine, SLOT(setRoute(Route&)));
 
     // connect signals
     signalsFromMapEngine();
@@ -116,7 +116,7 @@ SituareEngine::SituareEngine()
 
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
-            this, SLOT(startAutomaticUpdateget()));
+            this, SLOT(startAutomaticUpdate()));
 
     // signals connected, now it's time to show the main window
     // but init the MapEngine before so starting location is set
@@ -132,7 +132,7 @@ SituareEngine::SituareEngine()
     connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(enablePowerSave(bool)));
 
     /// @todo for testing, remove after real route start and end points are available
-    m_routingService->requestRoute(QPointF(65.010193,25.509859), QPointF(65.015152, 25.46645));
+    //m_routingService->requestRoute(QPointF(65.010193,25.509859), QPointF(65.015152, 25.46645));
 }
 
 SituareEngine::~SituareEngine()
index cf927ef..a290dce 100644 (file)
@@ -59,7 +59,6 @@ public:
     /**
     * @brief Constructor
     *
-    * @param parent
     */
     SituareEngine();
 
index e6c950b..a5495aa 100644 (file)
@@ -493,22 +493,22 @@ void MapEngine::setGPSEnabled(bool enabled)
     m_gpsLocationItem->setEnabled(enabled);
 }
 
-void MapEngine::setRoute(Route route)
+void MapEngine::setRoute(Route &route)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_route = route;
 
-    qWarning() << __PRETTY_FUNCTION__ << "from:" << m_route.startPointName();
-    qWarning() << __PRETTY_FUNCTION__ << "to:" << m_route.endPointName();
-    qWarning() << __PRETTY_FUNCTION__ << "distance:" << m_route.totalDistance();
-    qWarning() << __PRETTY_FUNCTION__ << "estimated time:" << m_route.totalTime();
+    qDebug() << __PRETTY_FUNCTION__ << "from:" << m_route.startPointName();
+    qDebug() << __PRETTY_FUNCTION__ << "to:" << m_route.endPointName();
+    qDebug() << __PRETTY_FUNCTION__ << "distance:" << m_route.totalDistance();
+    qDebug() << __PRETTY_FUNCTION__ << "estimated time:" << m_route.totalTime();
 
     foreach (QPointF point, m_route.geometryPoints())
-        qWarning() << __PRETTY_FUNCTION__ << "geometry point:" << point.x() << point.y();
+        qDebug() << __PRETTY_FUNCTION__ << "geometry point:" << point.x() << point.y();
 
     foreach (RouteSegment segment, m_route.segments()) {
-        qWarning() << __PRETTY_FUNCTION__ << "segment:" << segment.instruction();
+        qDebug() << __PRETTY_FUNCTION__ << "segment:" << segment.instruction();
     }
 
     // delete old route track (if exists)
index 9720f33..57c510d 100644 (file)
@@ -368,7 +368,12 @@ private slots:
      */
     void setCenterPosition(QPoint scenePosition);
 
-    void setRoute(Route route);
+    /**
+     * @brief Builds and sets route, also centers it
+     *
+     * @param route Route route information
+     */
+    void setRoute(Route &route);
 
     /**
      * @brief Slot for actions after view zoom is finished
index 676e326..0e8d1ac 100644 (file)
@@ -39,14 +39,14 @@ void Route::appendGeometryPoint(QPointF geometryPoint)
     m_geometryPoints.append(geometryPoint);
 }
 
-void Route::appendSegment(RouteSegment segment)
+void Route::appendSegment(RouteSegment &segment)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_segments.append(segment);
 }
 
-QString Route::endPointName() const
+const QString& Route::endPointName() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -95,7 +95,7 @@ void Route::setTotalTime(int seconds)
     m_totalTime = seconds;
 }
 
-QString Route::startPointName() const
+const QString& Route::startPointName() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index 370b21e..08e52f2 100644 (file)
@@ -62,14 +62,14 @@ public:
     *
     * @param segment Route segment object
     */
-    void appendSegment(RouteSegment segment);
+    void appendSegment(RouteSegment &segment);
 
     /**
     * @brief Getter for route end point name
     *
     * @returns Name of the end point (or empty QString)
     */
-    QString endPointName() const;
+    const QString& endPointName() const;
 
     /**
     * @brief Get list of geometry points
@@ -118,7 +118,7 @@ public:
     *
     * @returns Name of the start point (or empty QString)
     */
-    QString startPointName() const;
+    const QString& startPointName() const;
 
     /**
     * @brief Getter for total route distance
index 4c08739..79bd520 100644 (file)
@@ -43,14 +43,14 @@ qreal RouteSegment::azimuth() const
     return m_azimuth;
 }
 
-QString RouteSegment::earthDirection() const
+const QString& RouteSegment::earthDirection() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_earthDirection;
 }
 
-QString RouteSegment::instruction() const
+const QString& RouteSegment::instruction() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -64,7 +64,7 @@ qreal RouteSegment::length() const
     return m_length;
 }
 
-QString RouteSegment::lengthCaption() const
+const QString& RouteSegment::lengthCaption() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -159,7 +159,7 @@ QString RouteSegment::street() const
     // cut beginning of the instruction
     // (but only if it matches with the expected value)
 
-    if (m_turnType == "") {
+    if (m_turnType.isEmpty()) {
         // first segment (without turn type code)
         QRegExp regexp(REGEXP_1ST_SEGMENT);
         result.replace(regexp, "");
@@ -214,7 +214,7 @@ qreal RouteSegment::turnAngle() const
     return m_turnAngle;
 }
 
-QString RouteSegment::turnType() const
+const QString& RouteSegment::turnType() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index 24283c0..11c69b9 100644 (file)
@@ -54,7 +54,7 @@ public:
     *
     * @returns Earth direction (N, NE, E, SE, S, SW, W, NW)
     */
-    QString earthDirection() const;
+    const QString& earthDirection() const;
 
     /**
     * @brief Getter for text instruction
@@ -63,7 +63,7 @@ public:
     *
     * @returns Instruction text
     */
-    QString instruction() const;
+    const QString& instruction() const;
 
     /**
     * @brief Getter for segment length
@@ -79,7 +79,7 @@ public:
     *
     * @returns Length of the segment text
     */
-    QString lengthCaption() const;
+    const QString& lengthCaption() const;
 
     /**
     * @brief Getter for the route geometry position index of the segment
@@ -187,7 +187,7 @@ public:
     *
     * @returns Turn type code
     */
-    QString turnType() const;
+    const QString& turnType() const;
 
 private:
     int m_timeSeconds;          ///< estimated time required to travel the segment in seconds
index 220e2b3..a613e35 100644 (file)
@@ -67,17 +67,10 @@ RoutingService::RoutingService(QObject *parent)
 
 }
 
-RoutingService::~RoutingService()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-}
-
 void RoutingService::parseRouteData(const QByteArray &jsonReply)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qWarning() << __PRETTY_FUNCTION__ << jsonReply;
-
     QJson::Parser parser;
     bool ok;
     QVariantMap result = parser.parse (jsonReply, &ok).toMap();
@@ -124,7 +117,7 @@ void RoutingService::parseRouteData(const QByteArray &jsonReply)
 
 void RoutingService::requestAuthorizationToken()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     // create token request of format: http://auth.cloudmade.com/token/APIKEY?userid=UserID
     // where APIKEY is our application specific key and userID is md5 hashed value of IMEI code
@@ -143,7 +136,7 @@ void RoutingService::requestAuthorizationToken()
         qDebug() << reply.errorMessage();
     else {
         QList<QVariant> args = reply.arguments();
-        qWarning() << QString("Phone's IMEI: %1").arg(args.at(0).toString());
+        qDebug() << QString("Phone's IMEI: %1").arg(args.at(0).toString());
         rawData = args.at(0).toByteArray();
     }
 #else
@@ -161,20 +154,22 @@ void RoutingService::requestAuthorizationToken()
 
 void RoutingService::requestFinished(QNetworkReply *reply)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_currentRequests.contains(reply)) {
-        qWarning() << reply->readAll();
+
+        QByteArray replyArray = reply->readAll();
+        qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
+
         if (reply->error()) {
             emit error(ErrorContext::NETWORK, reply->error());
         } else if(reply->url().toString().contains(CLOUDMADE_AUTH_PART)) {
-            m_token = reply->readAll();
+            m_token = replyArray;
             m_pendingRequest.append(m_token);
             sendRequest(m_pendingRequest);
             m_pendingRequest.clear();
-            qWarning() << m_token;
         } else {
-            parseRouteData(reply->readAll());
+            parseRouteData(replyArray);
         }
 
         m_currentRequests.removeAll(reply);
@@ -184,7 +179,7 @@ void RoutingService::requestFinished(QNetworkReply *reply)
 
 void RoutingService::requestRoute(QPointF from, QPointF to)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     QString url = "http://routes.cloudmade.com/";
     url.append(CLOUDMADE_API_KEY);
@@ -200,13 +195,11 @@ void RoutingService::requestRoute(QPointF from, QPointF to)
         url.append(m_token);
         sendRequest(QUrl(url));
     }
-    //sendRequest(QUrl("http://routes.cloudmade.com/BC9A493B41014CAABB98F0471D759707/api/0.3/47.25976,9.58423,47.26117,9.59882/bicycle.js"));
 }
 
 void RoutingService::sendRequest(const QUrl &url)
 {
-    qWarning() << __PRETTY_FUNCTION__;
-    qWarning() << url.toString();
+    qDebug() << __PRETTY_FUNCTION__;
 
     QNetworkRequest request;
 
@@ -214,7 +207,7 @@ void RoutingService::sendRequest(const QUrl &url)
     request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
 
     QByteArray ba;
-    QNetworkReply *reply = m_networkManager->post(request, ba, true);
+    QNetworkReply *reply = m_networkManager->post(request, ba, false);
 
     m_currentRequests.append(reply);
 }
index 7f734db..1012593 100644 (file)
@@ -52,12 +52,6 @@ public:
     */
     RoutingService(QObject *parent = 0);
 
-    /**
-    * @brief Destructor
-    *
-    */
-    ~RoutingService();
-
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
@@ -118,7 +112,7 @@ signals:
     *
     * @param route Route item containing parsed route details
     */
-    void routeParsed(Route route);
+    void routeParsed(Route &route);
 
 /*******************************************************************************
  * DATA MEMBERS
@@ -128,7 +122,7 @@ private:
     QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
 
     QString m_pendingRequest;                   ///< Placeholder for pending route request
-    QString m_token;                            ///< Placeholder for authentication token
+    QString m_token;                         ///< Placeholder for authentication token
 
     NetworkAccessManager *m_networkManager;     ///< Pointer to QNetworkAccessManager
 };