*/
#include <QMessageBox>
+#include <QNetworkReply>
#include "common.h"
#include "facebookservice/facebookauthentication.h"
{
qDebug() << __PRETTY_FUNCTION__;
- m_ui->setGPSButtonEnabled(enabled);
- m_mapEngine->setGPSEnabled(enabled);
+ if (m_gps->isInitialized()) {
+ m_ui->setGPSButtonEnabled(enabled);
+ m_mapEngine->setGPSEnabled(enabled);
- if (enabled && !m_gps->isRunning()) {
- m_gps->start();
- enableAutoCentering(m_autoCenteringEnabled);
- m_gps->requestLastPosition();
+ if (enabled && !m_gps->isRunning()) {
+ m_gps->start();
+ enableAutoCentering(m_autoCenteringEnabled);
+ m_gps->requestLastPosition();
- if (!m_automaticUpdateEnabled && m_loggedIn)
- m_ui->requestAutomaticLocationUpdateSettings();
+ if (!m_automaticUpdateEnabled && m_loggedIn)
+ m_ui->requestAutomaticLocationUpdateSettings();
+ }
+ else if (!enabled && m_gps->isRunning()) {
+ m_gps->stop();
+ enableAutoCentering(false);
+ enableAutomaticLocationUpdate(false);
+ }
}
- else if (!enabled && m_gps->isRunning()) {
- m_gps->stop();
- enableAutoCentering(false);
- enableAutomaticLocationUpdate(false);
+ else {
+ if (enabled)
+ m_ui->buildInformationBox(tr("Unable to start GPS"));
+ m_ui->setGPSButtonEnabled(false);
+ m_mapEngine->setGPSEnabled(false);
}
}
}
}
-void SituareEngine::error(const QString &error)
+void SituareEngine::error(const int error)
{
qDebug() << __PRETTY_FUNCTION__;
- m_ui->buildInformationBox(error, true);
+ switch(error)
+ {
+ case QNetworkReply::ConnectionRefusedError:
+ m_ui->buildInformationBox(tr("Connection refused by the server"), true);
+ break;
+ case QNetworkReply::RemoteHostClosedError:
+ m_ui->buildInformationBox(tr("Connection closed by the server"), true);
+ break;
+ case QNetworkReply::HostNotFoundError:
+ m_ui->buildInformationBox(tr("Remote server not found"), true);
+ break;
+ case QNetworkReply::TimeoutError:
+ m_ui->buildInformationBox(tr("Connection timed out"), true);
+ break;
+ case SituareError::SESSION_EXPIRED:
+ m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
+ break;
+ case SituareError::LOGIN_FAILED:
+ m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
+ break;
+ case SituareError::UPDATE_FAILED:
+ m_ui->buildInformationBox(tr("Update failed, please try again"), true);
+ break;
+ case SituareError::DATA_RETRIEVAL_FAILED:
+ m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
+ break;
+ case SituareError::ADDRESS_RETRIEVAL_FAILED:
+ m_ui->buildInformationBox(tr("Address retrieval failed, please try again"), true);
+ break;
+ case SituareError::DOWNLOAD_FAILED:
+ m_ui->buildInformationBox(tr("Image download failed"), true);
+ break;
+ case SituareError::GPS_INITIALIZATION_FAILED:
+ enableGPS(false);
+ m_ui->buildInformationBox(tr("GPS initialization failed"), true);
+ break;
+ default:
+ qCritical() << "QNetworkReply::NetworkError :" << error;
+ break;
+ }
- if(error.compare(SESSION_EXPIRED) == 0) {
+ if(error == SituareError::SESSION_EXPIRED) {
m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
m_ui->loggedIn(false);
m_ui->loginFailed();
QSettings settings(DIRECTORY_NAME, FILE_NAME);
QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
- QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
-
- if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
+ QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
- connect(m_gps, SIGNAL(position(QPointF,qreal)),
- this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+ if (m_gps->isInitialized()) {
- changeAutoCenteringSetting(true);
- enableGPS(true);
+ if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
- m_ui->buildInformationBox(tr("GPS enabled"));
- m_ui->buildInformationBox(tr("Auto centering enabled"));
+ connect(m_gps, SIGNAL(position(QPointF,qreal)),
+ this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
- } else { // Normal start
- changeAutoCenteringSetting(autoCenteringEnabled.toBool());
- enableGPS(gpsEnabled.toBool());
+ changeAutoCenteringSetting(true);
+ enableGPS(true);
- if (gpsEnabled.toBool())
m_ui->buildInformationBox(tr("GPS enabled"));
-
- if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
m_ui->buildInformationBox(tr("Auto centering enabled"));
+
+ } else { // Normal start
+ changeAutoCenteringSetting(autoCenteringEnabled.toBool());
+ enableGPS(gpsEnabled.toBool());
+
+ if (gpsEnabled.toBool())
+ m_ui->buildInformationBox(tr("GPS enabled"));
+
+ if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
+ m_ui->buildInformationBox(tr("Auto centering enabled"));
+ }
+ } else {
+ enableGPS(false);
}
}
{
qDebug() << __PRETTY_FUNCTION__;
- connect(m_facebookAuthenticator, SIGNAL(error(QString)),
- this, SLOT(error(QString)));
+ connect(m_facebookAuthenticator, SIGNAL(error(int)),
+ this, SLOT(error(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(QString)),
- this, SLOT(error(QString)));
+ connect(m_gps, SIGNAL(error(int)),
+ this, SLOT(error(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(fetchUsernameFromSettings()),
this, SLOT(fetchUsernameFromSettings()));
connect(m_ui, SIGNAL(refreshUserData()),
this, SLOT(refreshUserData()));
- connect (m_ui, SIGNAL(notificateUpdateFailing(QString)),
- this, SLOT(error(QString)));
-
connect(m_ui, SIGNAL(findUser(QPointF)),
m_mapEngine, SLOT(setViewLocation(QPointF)));
{
qDebug() << __PRETTY_FUNCTION__;
- connect(m_mapEngine, SIGNAL(error(QString)),
- this, SLOT(error(QString)));
+ connect(m_mapEngine, SIGNAL(error(int)),
+ this, SLOT(error(int)));
connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
{
qDebug() << __PRETTY_FUNCTION__;
- connect(m_situareService, SIGNAL(error(QString)),
- this, SLOT(error(QString)));
+ connect(m_situareService, SIGNAL(error(int)),
+ this, SLOT(error(int)));
connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
m_ui, SIGNAL(reverseGeoReady(QString)));
connect(m_situareService, SIGNAL(updateWasSuccessful()),
m_ui, SIGNAL(updateWasSuccessful()));
- connect(m_situareService, SIGNAL(error(QString)),
- m_ui, SIGNAL(messageSendingFailed(QString)));
+ connect(m_situareService, SIGNAL(error(int)),
+ m_ui, SIGNAL(messageSendingFailed(int)));
}
void SituareEngine::updateWasSuccessful()