// 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
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
};
}
}
}
-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);
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;
}
}
{
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)));
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)));
{
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()));
{
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)));
{
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)),
/**
* @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
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();
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;
}
/**
* @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.
******************************************************************************/
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.
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;
}
}
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;
}
}
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)
{
qDebug() << __PRETTY_FUNCTION__;
- emit m_parent->error(SituareError::GPS_INITIALIZATION_FAILED);
+ emit m_parent->error(ErrorContext::SITUARE, SituareError::GPS_INITIALIZATION_FAILED);
}
void GPSPositionPrivate::stop()
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
******************************************************************************/
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.
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);
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
emit imageReceived(url, image);
}
else {
- emit error(SituareError::IMAGE_DOWNLOAD_FAILED);
+ emit error(ErrorContext::SITUARE, SituareError::IMAGE_DOWNLOAD_FAILED);
}
m_currentDownloads.removeAll(reply);
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
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!";
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()
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);
//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);
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();
}
}
/**
* @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
{
qDebug() << __PRETTY_FUNCTION__;
+ drawFullScreenButton(m_viewPortSize);
+
if(m_loggedIn) {
if(!m_friendsListPanel->isVisible()) {
m_friendsListPanel->show();
m_userPanelSidebar->hide();
setOwnLocationCrosshairVisibility(false);
}
- drawFullScreenButton(m_viewPortSize);
}
const QString MainWindow::username()
// 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());
}
}
/**
* @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