Merge branch 'qml' of https://vcs.maemo.org/git/situare into qml
authorJanne Kiiski <janne.kiiski@ixonos.com>
Fri, 12 Nov 2010 14:09:27 +0000 (16:09 +0200)
committerJanne Kiiski <janne.kiiski@ixonos.com>
Fri, 12 Nov 2010 14:09:27 +0000 (16:09 +0200)
Conflicts:
src/engine/engine.cpp

src/engine/engine.cpp
src/qmlui/RoutingPanel.qml

index 9039629..cdfeb67 100644 (file)
@@ -62,13 +62,49 @@ const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
 
 class SituareEnginePrivate
 {
+    Q_DECLARE_PUBLIC(SituareEngine)
+    SituareEngine* q_ptr;
+
 public:
     FriendModel friendModel;
     RouteModel routeModel;
+
+    QDeclarativeView* ui;
+
+    int progressIndicatorCount;
+
+    SituareEnginePrivate(SituareEngine* parent)
+        : q_ptr(parent), routeModel(0), ui(0), progressIndicatorCount(0)
+    {}
+
+    void toggleProgressIndicator(bool value)
+    {
+#ifdef QML_UI
+        qDebug() << __PRETTY_FUNCTION__;
+
+    #ifdef Q_WS_MAEMO_5
+        if(value) {
+            progressIndicatorCount++;
+            ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+        } else {
+            if(progressIndicatorCount > 0)
+                progressIndicatorCount--;
+
+            if(progressIndicatorCount == 0)
+                ui->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+        }
+    #else
+        Q_UNUSED(value);
+    #endif // Q_WS_MAEMO_5
+#else
+        Q_Q(SituareEngine);
+        q->m_ui->toggleProgressIndicator(value);
+#endif
+    }
 };
 
 SituareEngine::SituareEngine()
-    : d_ptr(new SituareEnginePrivate),
+    : d_ptr(new SituareEnginePrivate(this)),
       m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
       m_automaticUpdateRequest(false),
@@ -146,30 +182,27 @@ SituareEngine::SituareEngine()
 #ifdef QML_UI
     qmlRegisterType<GeoMap>("MapPlugin", 1, 0, "GeoMap");
 
-    QDeclarativeView* view = new QDeclarativeView(QApplication::desktop());
+    Q_D(SituareEngine);
+
+    d->ui = new QDeclarativeView(QApplication::desktop());
 #ifdef Q_WS_MAEMO_5
-//    view.setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+//    d->ui->setAttribute(Qt::WA_Maemo5AutoOrientation, true);
 #endif
-    Q_D(SituareEngine);
     Rotation *rotation = new Rotation();
-    view->rootContext()->setContextProperty("deviceRotation", static_cast<QObject *>(rotation));
-    view->rootContext()->setContextProperty("facebookAuthenticator", m_facebookAuthenticator);
-
-    // test segments
-    for( int i = 0; i < 4; ++i) {
-        RouteSegment segment;
-        segment.setInstruction(i != 3 ? "Turn left" : "You're back at starting point");
-        d->routeModel.addSegment(segment);
-    }
-    view->rootContext()->setContextProperty("routingModel", &d->routeModel);
-    view->rootContext()->setContextProperty("friendModel", &d->friendModel);
-    view->rootContext()->setContextProperty("engine", this);
+    d->ui->rootContext()->setContextProperty("deviceRotation", static_cast<QObject *>(rotation));
+    d->ui->rootContext()->setContextProperty("facebookAuthenticator", m_facebookAuthenticator);
+    d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
+    d->ui->rootContext()->setContextProperty("friendModel", &d->friendModel);
+    d->ui->rootContext()->setContextProperty("engine", this);
+
+    d->ui->rootContext()->setContextProperty("routingModel", &d->routeModel);
+    d->ui->rootContext()->setContextProperty("engine", this);
 
-    view->setSource(QUrl("qrc:/Main.qml"));
-    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
-    view->show();
+    d->ui->setSource(QUrl("qrc:/Main.qml"));
+    d->ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    d->ui->show();
 
-    connect(view->engine()->networkAccessManager(),
+    connect(d->ui->engine()->networkAccessManager(),
             SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
             m_facebookAuthenticator, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
 #else
@@ -256,18 +289,18 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
 
 void SituareEngine::error(const int context, const int error)
 {
+    Q_D(SituareEngine);
     qDebug() << __PRETTY_FUNCTION__;
-
     switch(error)
     {
     case SituareError::ERROR_GENERAL:
         if(context == ErrorContext::SITUARE) {
-            m_ui->toggleProgressIndicator(false);
+            d->toggleProgressIndicator(false);
             m_ui->buildInformationBox(tr("Unknown server error"), true);
         }
         break;
     case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         if(context == ErrorContext::SITUARE) {
             m_ui->buildInformationBox(tr("Missing parameter from request"), true);
         } else if(context == ErrorContext::NETWORK) {
@@ -276,25 +309,25 @@ void SituareEngine::error(const int context, const int error)
         break;
     case QNetworkReply::RemoteHostClosedError:
         if(context == ErrorContext::NETWORK) {
-            m_ui->toggleProgressIndicator(false);
+            d->toggleProgressIndicator(false);
             m_ui->buildInformationBox(tr("Connection closed by the server"), true);
         }
         break;
     case QNetworkReply::HostNotFoundError:
         if(context == ErrorContext::NETWORK) {
-            m_ui->toggleProgressIndicator(false);
+            d->toggleProgressIndicator(false);
             m_ui->buildInformationBox(tr("Remote server not found"), true);
         }
         break;
     case QNetworkReply::TimeoutError:
         if(context == ErrorContext::NETWORK) {
-            m_ui->toggleProgressIndicator(false);
+            d->toggleProgressIndicator(false);
             m_ui->buildInformationBox(tr("Connection timed out"), true);
         }
         break;
     case QNetworkReply::UnknownNetworkError:
         if(context == ErrorContext::NETWORK) {
-            m_ui->toggleProgressIndicator(false);
+            d->toggleProgressIndicator(false);
             m_ui->buildInformationBox(tr("No network connection"), true);
         }
         break;
@@ -304,15 +337,15 @@ void SituareEngine::error(const int context, const int error)
         m_facebookAuthenticator->login();
         break;
     case SituareError::UPDATE_FAILED:
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Update failed, please try again"), true);
         break;
     case SituareError::DATA_RETRIEVAL_FAILED:
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
         break;
     case SituareError::ADDRESS_RETRIEVAL_FAILED:
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Address retrieval failed"), true);
         break;
     case SituareError::IMAGE_DOWNLOAD_FAILED:
@@ -331,14 +364,14 @@ void SituareEngine::error(const int context, const int error)
         m_facebookAuthenticator->clearAccountInformation(false); // clean all
         break;
     case SituareError::ERROR_ROUTING_FAILED:
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Routing failed"), true);
         break;
     case SituareError::ERROR_LOCATION_SEARCH_FAILED:
         m_ui->buildInformationBox(tr("No results found"), true);
         break;
     default:
-        m_ui->toggleProgressIndicator(false);
+        d->toggleProgressIndicator(false);
         if(context == ErrorContext::NETWORK)
             qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
         else
@@ -432,10 +465,12 @@ void SituareEngine::onLogout()
 
 void SituareEngine::refreshUserData()
 {
+    Q_D(SituareEngine);
+
     qDebug() << __PRETTY_FUNCTION__;
 
     if (m_networkAccessManager->isConnected()) {
-        m_ui->toggleProgressIndicator(true);
+        d->toggleProgressIndicator(true);
         m_situareService->fetchLocations();
     }
     else {
@@ -461,9 +496,10 @@ void SituareEngine::requestAddress()
 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    Q_D(SituareEngine);
 
     if (m_networkAccessManager->isConnected()) {
-        m_ui->toggleProgressIndicator(true);
+        d->toggleProgressIndicator(true);
 
         if (m_gps->isRunning())
             m_situareService->updateLocation(m_gps->lastPosition(), status, publish);
@@ -503,14 +539,15 @@ void SituareEngine::routeParsed(Route &route)
 
     d->routeModel.setSegments(route.segments());
 
-    m_ui->toggleProgressIndicator(false);
+    d->toggleProgressIndicator(false);
 }
 
 void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
 {
+    Q_D(SituareEngine);
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_ui->toggleProgressIndicator(true);
+    d->toggleProgressIndicator(true);
 
     if (m_gps->isRunning())
         m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
@@ -826,12 +863,11 @@ void SituareEngine::updateWasSuccessful()
 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->toggleProgressIndicator(false);
+    Q_D(SituareEngine);
+    d->toggleProgressIndicator(false);
 
     emit userLocationReady(user);
     emit friendsLocationsReady(friendsList);
-    Q_D(SituareEngine);
     d->friendModel.setFriends(friendsList);
 }
 
@@ -839,7 +875,8 @@ void SituareEngine::routeFromTo(double fromLatitude, double fromLongitude, doubl
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_ui->toggleProgressIndicator(true);
+    Q_D(SituareEngine);
+    d->toggleProgressIndicator(true);
 
     m_routingService->requestRoute(GeoCoordinate(fromLatitude, fromLongitude), GeoCoordinate(toLatitude, toLongitude));
 }
index 7068e5e..5770c86 100644 (file)
@@ -19,14 +19,18 @@ Item {
         height: panel.height
         width: panel.width
 
-        Button {
+        Image {
             id: routeTo
-            text: "route to cursor"
+            fillMode: Image.PreserveAspectFit
             width: parent.width
-            height: 30
-            onButtonClicked: {
-                console.log("clicked: Route to cursor")
-                engine.routeFromTo(map.gpsLocationLatitude, map.gpsLocationLongitude, map.centerLatitude, map.centerLongitude);
+            source: "qrc:/res/images/route_to_cursor.png"
+            anchors.horizontalCenter: parent.horizontalCenter
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    console.log("clicked: Route to cursor")
+                    engine.routeFromTo(map.gpsLocationLatitude, map.gpsLocationLongitude, map.centerLatitude, map.centerLongitude);
+                }
             }
         }