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),
#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
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) {
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;
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:
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
void SituareEngine::refreshUserData()
{
+ Q_D(SituareEngine);
+
qDebug() << __PRETTY_FUNCTION__;
if (m_networkAccessManager->isConnected()) {
- m_ui->toggleProgressIndicator(true);
+ d->toggleProgressIndicator(true);
m_situareService->fetchLocations();
}
else {
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);
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);
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);
}
{
qDebug() << __PRETTY_FUNCTION__;
- m_ui->toggleProgressIndicator(true);
+ Q_D(SituareEngine);
+ d->toggleProgressIndicator(true);
m_routingService->requestRoute(GeoCoordinate(fromLatitude, fromLongitude), GeoCoordinate(toLatitude, toLongitude));
}