Updated error handling, added error contexts. Fixed fullscreen button
authorlampehe-local <henri.lampela@ixonos.com>
Tue, 22 Jun 2010 10:14:52 +0000 (13:14 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Tue, 22 Jun 2010 10:14:52 +0000 (13:14 +0300)
location bug. Added geo coordinates for address fields when street
address isn't available.

Reviewed by: Pekka Nissinen

20 files changed:
src/common.h
src/engine/engine.cpp
src/engine/engine.h
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/gps/gpsposition.h
src/gps/gpspositionprivate.cpp
src/gps/gpspositionprivateliblocation.cpp
src/gps/gpspositionprivatestub.cpp
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapfetcher.cpp
src/map/mapfetcher.h
src/situareservice/imagefetcher.cpp
src/situareservice/imagefetcher.h
src/situareservice/situarecommon.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index b104f72..0f400bd 100644 (file)
@@ -59,6 +59,8 @@ const QString FACEBOOK_LOGIN_ENDING = "&fbconnect=true&return_session=true&";
 // Situare errors
 namespace SituareError {
     enum errors {
+        ERROR_GENERAL = 0,          // an unknown/unspecified error
+        ERROR_MISSING_ARGUMENT,     // missing mandatory argument for requested action
         SESSION_EXPIRED = 10,       // situare session credentials expired
         LOGIN_FAILED,               // login to situare service failed
         UPDATE_FAILED,              // location update to situare failed
@@ -67,8 +69,18 @@ namespace SituareError {
         IMAGE_DOWNLOAD_FAILED,      // image download failed from facebook
         MAP_IMAGE_DOWNLOAD_FAILED,  // map image download failed from OSM
         GPS_INITIALIZATION_FAILED,  // GPS intialization failed
-        UNKNOWN_REPLY,              // unknown reply from situare server
-        INVALID_JSON                // JSON parsing failed i.e. invalid JSON string
+        INVALID_JSON,               // JSON parsing failed i.e. invalid JSON string
+        ERROR_GEOLOCATION_SERVER_UNAVAILABLE = 501, // reverseGeo server not responding
+        ERROR_GEOLOCATION_REQUEST_FAIL,             // reverseGeo response failed
+        ERROR_GEOLOCATION_LONLAT_INVALID            // reverseGeo failed, invalid lon/lat
+    };
+}
+
+// Error contexts
+namespace ErrorContext {
+    enum context {
+        SITUARE = 0,                // situare context
+        NETWORK                     // QNetworkReply context
     };
 }
 
index f087fa9..778867f 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)),
index 9bbef2d..85e31ae 100644 (file)
@@ -71,9 +71,10 @@ public slots:
     /**
     * @brief Slot to intercept error signal from ImageFetcher and SituareService
     *
+    * @param context Error context
     * @param error Error message
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
     /**
     * @brief Slot to intercept signal when username is fetched from settings
index 716b054..f69d167 100644 (file)
@@ -131,7 +131,7 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
                         QVariantMap result = parser.parse (jsonString, &ok).toMap();
 
                         if (!ok) {
-                            emit error(SituareError::INVALID_JSON);
+                            emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
                             found = false;
                         } else {
                             qDebug() << "Session Key" << result[SESSION_KEY].toString();
@@ -168,22 +168,22 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
             qDebug() << callbackUrl;
             clearAccountInformation(true);
             if(m_freshLogin) {
-                emit error(SituareError::LOGIN_FAILED);
+                emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
             } else {
                 m_freshLogin = true;
-                emit error(SituareError::SESSION_EXPIRED);
+                emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
             }
         } else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {
             qDebug() << "correct loginPage";
         } else {
             qDebug() << "totally wrong webPage";
             // we should not get a wrong page at this point
-            emit error(SituareError::LOGIN_FAILED);
+            emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
         }
     } else {
         qDebug() << " Loading of page failed invalid URL" << endl;
         // we should not get a wrong page at this point
-        emit error(SituareError::LOGIN_FAILED);
+        emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
     }
     return found;
 }
index 0f06828..11dc05a 100644 (file)
@@ -110,9 +110,10 @@ signals:
     /**
     * @brief Signals error
     *
+    * @param context error context
     * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
     /**
     * @brief This signal is emitted if updateCredentials method finds credentials from URL.
index be69bf1..fe0ca2b 100644 (file)
@@ -111,11 +111,12 @@ public:
 ******************************************************************************/
 signals:
     /**
-    * @brief Signal for error.
+    * @brief Signals error
     *
+    * @param context error context
     * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
     /**
     * @brief Signal for position information.
index 8184ea2..6259915 100644 (file)
@@ -63,7 +63,7 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
 
         if (!m_gpsSource) {
             m_initialized = false;
-            emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
+            emit m_parent->error(ErrorContext::SITUARE, SituareError::GPS_INITIALIZATION_FAILED);
             return;
         }
     }
index 4ce2acd..af4789a 100644 (file)
@@ -66,7 +66,7 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
 
         if (!m_liblocationWrapper) {     
             m_initialized = false;
-            emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
+            emit m_parent->error(ErrorContext::SITUARE, SituareError::GPS_INITIALIZATION_FAILED);
             return;
         }
     }
@@ -148,7 +148,7 @@ void GPSPositionPrivate::locationError(const QString &errorMessage)
 
     Q_UNUSED(errorMessage);
 
-    emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
+    emit m_parent->error(ErrorContext::SITUARE, SituareError::GPS_INITIALIZATION_FAILED);
 }
 
 void GPSPositionPrivate::setUpdateInterval(int interval)
index 8f23493..f525b17 100644 (file)
@@ -66,7 +66,7 @@ void GPSPositionPrivate::start()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
+    emit m_parent->error(ErrorContext::SITUARE, SituareError::GPS_INITIALIZATION_FAILED);
 }
 
 void GPSPositionPrivate::stop()
index ca6d33e..30085d6 100644 (file)
@@ -64,8 +64,8 @@ MapEngine::MapEngine(QObject *parent)
             m_mapFetcher, SLOT(enqueueFetchMapImage(int, int, int)));
     connect(m_mapFetcher, SIGNAL(mapImageReceived(int, int, int, QPixmap)),
             this, SLOT(mapImageReceived(int, int, int, QPixmap)));
-    connect(m_mapFetcher, SIGNAL(error(int)),
-            this, SIGNAL(error(int)));
+    connect(m_mapFetcher, SIGNAL(error(int, int)),
+            this, SIGNAL(error(int, int)));
 
     m_ownLocation = new OwnLocationItem();
     m_ownLocation->hide(); // hide until first location info is received
index 810f25f..d267072 100644 (file)
@@ -361,11 +361,12 @@ private slots:
  ******************************************************************************/
 signals:
     /**
-     * @brief Signals error
-     *
-     * @param error error code
-     */
-    void error(const int error);
+    * @brief Signals error
+    *
+    * @param context error context
+    * @param error error code
+    */
+    void error(const int context, const int error);
 
     /**
      * @brief Signal for image fetching.
index 7d4ce6d..8a601b3 100644 (file)
@@ -127,7 +127,7 @@ void MapFetcher::downloadFinished(QNetworkReply *reply)
             emit mapImageReceived(zoomLevel, x, y, QPixmap::fromImage(image));
         }
         else {
-            emit error(SituareError::MAP_IMAGE_DOWNLOAD_FAILED);
+            emit error(ErrorContext::SITUARE, SituareError::MAP_IMAGE_DOWNLOAD_FAILED);
         }
 
         m_currentDownloads.removeAll(reply);
index e530e61..11c1838 100644 (file)
@@ -178,12 +178,12 @@ signals:
     void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
 
     /**
-    * @brief Signal which is emitted when there is error
-    * in network reply.
+    * @brief Signals error
     *
+    * @param context error context
     * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
 /*******************************************************************************
  * DATA MEMBERS
index ee2fb80..b89edaa 100644 (file)
@@ -77,7 +77,7 @@ void ImageFetcher::downloadFinished(QNetworkReply *reply)
             emit imageReceived(url, image);
         }
         else {
-            emit error(SituareError::IMAGE_DOWNLOAD_FAILED);
+            emit error(ErrorContext::SITUARE, SituareError::IMAGE_DOWNLOAD_FAILED);
         }
 
         m_currentDownloads.removeAll(reply);
index ef7d503..a7a837c 100644 (file)
@@ -90,12 +90,12 @@ signals:
     void imageReceived(const QUrl &url, const QPixmap &image);
 
     /**
-    * @brief Signal which is emitted when there is error
-    * in network reply.
+    * @brief Signals error
     *
+    * @param context error context
     * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
 /*******************************************************************************
  * DATA MEMBERS
index c5b925e..a341f9d 100644 (file)
@@ -69,6 +69,7 @@ const QString PUBLISH = "publish";
 const QString PUBLISH_TRUE = "true";
 const QString PUBLISH_FALSE = "false";
 const QString DATA = "data";
+const QString JSON_FORMAT = "&format=json";
 
 // Situare server error messages
 const QString ERROR_LAT = "Wrong lat value: . Latitude must be between -90 and 90!";
index 7b9cd3d..53b7dcf 100644 (file)
@@ -47,8 +47,8 @@ SituareService::SituareService(QObject *parent)
             m_imageFetcher, SLOT(fetchImage(QUrl)));
     connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QPixmap)),
             this, SLOT(imageReceived(QUrl, QPixmap)));
-    connect(m_imageFetcher, SIGNAL(error(int)),
-            this, SIGNAL(error(int)));
+    connect(m_imageFetcher, SIGNAL(error(int, int)),
+            this, SIGNAL(error(int, int)));
 }
 
 SituareService::~SituareService()
@@ -85,6 +85,7 @@ void SituareService::reverseGeo(const QPointF &coordinates)
                                 m_credentials.sig(), EN_LOCALE);
 
     QString urlParameters = formUrlParameters(coordinates);
+    urlParameters.append(JSON_FORMAT);
     QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
 
     sendRequest(url, COOKIE, cookie);
@@ -245,45 +246,36 @@ void SituareService::requestFinished(QNetworkReply *reply)
     //Reply from situare
     if (m_currentRequests.contains(reply)) {
 
-        QUrl url = reply->url();
         qDebug() << "BytesAvailable: " << reply->bytesAvailable();
 
         if (reply->error()) {
-            emit error(reply->error());
+            emit error(ErrorContext::NETWORK, reply->error());
         } else {
-            qint64 max = reply->size();
-            QByteArray replyArray = reply->read(max);
-            qDebug() << "Reply from: " << url << "reply " << replyArray;
+            QByteArray replyArray = reply->readAll();
+            qDebug() << "Reply from: " << reply->url() << "reply " << replyArray;
 
             if(replyArray == ERROR_LAT.toAscii()) {
                 qDebug() << "Error: " << ERROR_LAT;
-                emit error(SituareError::UPDATE_FAILED);
+                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
             } else if(replyArray == ERROR_LON.toAscii()) {
                 qDebug() << "Error: " << ERROR_LON;
-                emit error(SituareError::UPDATE_FAILED);
+                emit error(ErrorContext::SITUARE, SituareError::UPDATE_FAILED);
             } else if(replyArray.contains(ERROR_SESSION.toAscii())) {
                 qDebug() << "Error: " << ERROR_SESSION;
-                emit error(SituareError::SESSION_EXPIRED);
+                emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
             } else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
                 qDebug() << "JSON string";
                 parseUserData(replyArray);
             } else if(replyArray.isEmpty()) {
-                if(url.toString().contains(UPDATE_LOCATION.toAscii())) {
+                if(reply->url().toString().contains(UPDATE_LOCATION.toAscii())) {
                     emit updateWasSuccessful();
-                } else if(url.toString().contains(REVERSE_GEO.toAscii())) {
-                    // reversegeo failed
-                    emit error(SituareError::ADDRESS_RETRIEVAL_FAILED);
                 } else {
                     // session credentials are invalid
-                    emit error(SituareError::SESSION_EXPIRED);
+                    emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
                 }
-            } else if(url.toString().contains(REVERSE_GEO.toAscii())) {
-                // Street address ready
-                QString address = QString::fromUtf8(replyArray);
-                emit reverseGeoReady(address);
             } else {
                 // unknown reply
-                emit error(SituareError::UNKNOWN_REPLY);
+                emit error(ErrorContext::SITUARE, SituareError::ERROR_GENERAL);
             }
         }
         m_currentRequests.removeAll(reply);
@@ -318,51 +310,86 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
 
     QVariantMap result = parser.parse (jsonReply, &ok).toMap();
     if (!ok) {
-        emit error(SituareError::INVALID_JSON);
+        emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
         return;
     } else {
 
-        QVariant userVariant = result.value("user");
-        QMap<QString, QVariant> userMap = userVariant.toMap();
+        if(result.contains("ErrorCode")) {
+            QVariant errorVariant = result.value("ErrorCode");
+            emit error(ErrorContext::SITUARE, errorVariant.toInt());
+            return;
+        } else if(result.contains("user")) {
 
-        QPointF coordinates(userMap["longitude"].toReal(), userMap["latitude"].toReal());
+            QVariant userVariant = result.value("user");
+            QMap<QString, QVariant> userMap = userVariant.toMap();
 
-        QUrl imageUrl = userMap[NORMAL_SIZE_PROFILE_IMAGE].toUrl();
+            QPointF coordinates(userMap["longitude"].toReal(), userMap["latitude"].toReal());
 
-        if(imageUrl.isEmpty()) {
-            // user doesn't have profile image, so we need to get him a silhouette image
-            m_defaultImage = true;
-        }
-
-        m_user = new User(userMap["address"].toString(), coordinates, userMap["name"].toString(),
-                      userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
-                      true, userMap["uid"].toString());
-
-        foreach (QVariant friendsVariant, result["friends"].toList()) {
-          QMap<QString, QVariant> friendMap = friendsVariant.toMap();
-          QVariant distance = friendMap["distance"];
-          QMap<QString, QVariant> distanceMap = distance.toMap();
+            QUrl imageUrl = userMap[NORMAL_SIZE_PROFILE_IMAGE].toUrl();
 
-          QPointF coordinates(friendMap["longitude"].toReal(), friendMap["latitude"].toReal());
-
-          QUrl imageUrl = friendMap["profile_pic"].toUrl();
+            if(imageUrl.isEmpty()) {
+                // user doesn't have profile image, so we need to get him a silhouette image
+                m_defaultImage = true;
+            }
 
-          if(imageUrl.isEmpty()) {
-              // friend doesn't have profile image, so we need to get him a silhouette image
-              m_defaultImage = true;
-          }
+            QString address = userMap["address"].toString();
+            if(address.isEmpty()) {
+                QStringList location;
+                location.append(QString::number(coordinates.y()));
+                location.append(QString::number(coordinates.x()));
+                address = location.join(", ");
+            }
 
-          User *user = new User(friendMap["address"].toString(), coordinates,
-                                friendMap["name"].toString(),
-                                friendMap["note"].toString(), imageUrl,
-                                friendMap["timestamp"].toString(),
-                                false, friendMap["uid"].toString(),
-                                distanceMap["units"].toString(),
-                                distanceMap["value"].toDouble());
+            m_user = new User(address, coordinates, userMap["name"].toString(),
+                          userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
+                          true, userMap["uid"].toString());
+
+            foreach (QVariant friendsVariant, result["friends"].toList()) {
+              QMap<QString, QVariant> friendMap = friendsVariant.toMap();
+              QVariant distance = friendMap["distance"];
+              QMap<QString, QVariant> distanceMap = distance.toMap();
+
+              QPointF coordinates(friendMap["longitude"].toReal(), friendMap["latitude"].toReal());
+
+              QUrl imageUrl = friendMap["profile_pic"].toUrl();
+
+              if(imageUrl.isEmpty()) {
+                  // friend doesn't have profile image, so we need to get him a silhouette image
+                  m_defaultImage = true;
+              }
+
+              QString address = friendMap["address"].toString();
+              if(address.isEmpty()) {
+                  QStringList location;
+                  location.append(QString::number(coordinates.y()));
+                  location.append(QString::number(coordinates.x()));
+                  address = location.join(", ");
+              }
+
+              User *user = new User(address, coordinates,
+                                    friendMap["name"].toString(),
+                                    friendMap["note"].toString(), imageUrl,
+                                    friendMap["timestamp"].toString(),
+                                    false, friendMap["uid"].toString(),
+                                    distanceMap["units"].toString(),
+                                    distanceMap["value"].toDouble());
+
+              m_friendsList.append(user);
+            }
+            addProfileImages();
+        } else {
+            QVariant address = result.value("address");
+            if(!address.toString().isEmpty()) {
+                emit reverseGeoReady(address.toString());
+            } else {
+                QStringList coordinates;
+                coordinates.append(result.value("lat").toString());
+                coordinates.append(result.value("lon").toString());
 
-          m_friendsList.append(user);
+                emit error(ErrorContext::SITUARE, SituareError::ADDRESS_RETRIEVAL_FAILED);
+                emit reverseGeoReady(coordinates.join(", "));
+            }
         }
-        addProfileImages();
     }
 }
 
index 1b40c14..362f72a 100644 (file)
@@ -189,9 +189,10 @@ signals:
     /**
     * @brief Signals error
     *
+    * @param context error context
     * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
     /**
     * @brief Signal for image fetching
index 48d63e5..6a98875 100644 (file)
@@ -880,6 +880,8 @@ void MainWindow::showPanels()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    drawFullScreenButton(m_viewPortSize);
+
     if(m_loggedIn) {
         if(!m_friendsListPanel->isVisible()) {
             m_friendsListPanel->show();
@@ -946,7 +948,6 @@ void MainWindow::updateItemVisibility()
         m_userPanelSidebar->hide();
         setOwnLocationCrosshairVisibility(false);
     }
-    drawFullScreenButton(m_viewPortSize);
 }
 
 const QString MainWindow::username()
@@ -964,7 +965,7 @@ void MainWindow::webViewRequestFinished(QNetworkReply *reply)
     // qwebview starts to load a new page while the current page loading is not finished
     if(reply->error() != QNetworkReply::OperationCanceledError &&
        reply->error() != QNetworkReply::NoError) {
-        emit error(reply->error());
+        emit error(ErrorContext::NETWORK, reply->error());
     }
 }
 
index d34798a..a0829ed 100644 (file)
@@ -425,9 +425,10 @@ signals:
     /**
     * @brief Signals error
     *
-    * @param error Error code
+    * @param context error context
+    * @param error error code
     */
-    void error(const int error);
+    void error(const int context, const int error);
 
     /**
     * @brief Signal for requesting username from settings