Merge branch 'master' into kinetic
[situare] / src / engine / engine.cpp
index 78be25f..c146edd 100644 (file)
@@ -207,27 +207,43 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
     }
 }
 
-void SituareEngine::error(const int error)
+void SituareEngine::error(const int context, const int error)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     switch(error)
     {
-    case QNetworkReply::ConnectionRefusedError:
+    case SituareError::ERROR_GENERAL:
+        if(context == ErrorContext::SITUARE) {
+            m_ui->toggleProgressIndicator(false);
+            m_ui->buildInformationBox(tr("Unknown server error"), true);
+        }
+        break;
+    case SituareError::ERROR_MISSING_ARGUMENT | QNetworkReply::ConnectionRefusedError :
         m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Connection refused by the server"), true);
+        if(context == ErrorContext::SITUARE) {
+            m_ui->buildInformationBox(tr("Missing argument from request"), true);
+        } else if(context == ErrorContext::NETWORK) {
+            m_ui->buildInformationBox(tr("Connection refused by the server"), true);
+        }
         break;
     case QNetworkReply::RemoteHostClosedError:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Connection closed by the server"), true);
+        if(context == ErrorContext::NETWORK) {
+            m_ui->toggleProgressIndicator(false);
+            m_ui->buildInformationBox(tr("Connection closed by the server"), true);
+        }
         break;
     case QNetworkReply::HostNotFoundError:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Remote server not found"), true);
+        if(context == ErrorContext::NETWORK) {
+            m_ui->toggleProgressIndicator(false);
+            m_ui->buildInformationBox(tr("Remote server not found"), true);
+        }
         break;
     case QNetworkReply::TimeoutError:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Connection timed out"), true);
+        if(context == ErrorContext::NETWORK) {
+            m_ui->toggleProgressIndicator(false);
+            m_ui->buildInformationBox(tr("Connection timed out"), true);
+        }
         break;
     case SituareError::SESSION_EXPIRED:
         m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
@@ -262,18 +278,30 @@ void SituareEngine::error(const int error)
         enableGPS(false);
         m_ui->buildInformationBox(tr("GPS initialization failed"), true);
         break;
-    case SituareError::UNKNOWN_REPLY:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Unknown server response"), true);
-        break;
     case SituareError::INVALID_JSON:
         m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
         m_ui->loggedIn(false);
         m_facebookAuthenticator->clearAccountInformation(false); // clean all
         break;
+    case SituareError::ERROR_GEOLOCATION_SERVER_UNAVAILABLE:
+        m_ui->toggleProgressIndicator(false);
+        m_ui->buildInformationBox(tr("Geolocation server not responding"), true);
+        break;
+    case SituareError::ERROR_GEOLOCATION_REQUEST_FAIL:
+        m_ui->toggleProgressIndicator(false);
+        m_ui->buildInformationBox(tr("Geolocation request failed, please try again"), true);
+        break;
+    case SituareError::ERROR_GEOLOCATION_LONLAT_INVALID:
+        m_ui->toggleProgressIndicator(false);
+        m_ui->buildInformationBox(tr("Invalid lat/lon value, please try again"), true);
+        break;
     default:
         m_ui->toggleProgressIndicator(false);
-        qCritical() << "QNetworkReply::NetworkError :" << error;
+        if(context == ErrorContext::NETWORK)
+            qCritical() << "QNetworkReply::NetworkError: " << error;
+        else
+            qCritical() << "Unknown error: " << error;
+
         break;
     }
 }
@@ -439,8 +467,8 @@ void SituareEngine::signalsFromFacebookAuthenticator()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_facebookAuthenticator, SIGNAL(error(int)),
-            this, SLOT(error(int)));
+    connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
@@ -468,8 +496,8 @@ void SituareEngine::signalsFromGPS()
     connect(m_gps, SIGNAL(timeout()),
             m_ui, SLOT(gpsTimeout()));
 
-    connect(m_gps, SIGNAL(error(int)),
-            this, SLOT(error(int)));
+    connect(m_gps, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 
     connect(m_gps, SIGNAL(position(QPointF,qreal)),
             this, SLOT(saveGPSPosition(QPointF)));
@@ -479,8 +507,8 @@ void SituareEngine::signalsFromMainWindow()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_ui, SIGNAL(error(int)),
-            this, SLOT(error(int)));
+    connect(m_ui, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 
     connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
             this, SLOT(fetchUsernameFromSettings()));
@@ -547,8 +575,8 @@ void SituareEngine::signalsFromMapEngine()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_mapEngine, SIGNAL(error(int)),
-            this, SLOT(error(int)));
+    connect(m_mapEngine, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 
     connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
             m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
@@ -576,10 +604,10 @@ void SituareEngine::signalsFromSituareService()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_situareService, SIGNAL(error(int)),
-            this, SLOT(error(int)));
+    connect(m_situareService, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 
-    connect(m_situareService, SIGNAL(error(int)),
+    connect(m_situareService, SIGNAL(error(int, int)),
             m_ui, SIGNAL(messageSendingFailed(int)));
 
     connect(m_situareService, SIGNAL(reverseGeoReady(QString)),