summaryrefslogtreecommitdiff
path: root/src/location/places/provider/qplacedetailsreplyimpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/places/provider/qplacedetailsreplyimpl.cpp')
-rw-r--r--src/location/places/provider/qplacedetailsreplyimpl.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/location/places/provider/qplacedetailsreplyimpl.cpp b/src/location/places/provider/qplacedetailsreplyimpl.cpp
new file mode 100644
index 00000000..95b6eb56
--- /dev/null
+++ b/src/location/places/provider/qplacedetailsreplyimpl.cpp
@@ -0,0 +1,70 @@
+#include "qplacedetailsreplyimpl.h"
+
+#if defined(QT_PLACES_LOGGING)
+ #include <QDebug>
+#endif
+
+using namespace QT_PLACES_NAMESPACE;
+
+/*!
+ Constructor.
+*/
+QPlaceDetailsReplyImpl::QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QObject *parent) :
+ QPlaceDetailsReply(parent),
+ restReply(reply)
+{
+ parser = new QPlaceJSonDetailsParser(this);
+
+ if (restReply) {
+ restReply->setParent(this);
+ connect(restReply, SIGNAL(finished(const QString &reply)),
+ parser, SLOT(processData(const QString &data)));
+ connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)),
+ this, SLOT(restError(QPlaceRestReply::Error)));
+ connect(parser, SIGNAL(finished(QPlaceJSonDetailsParser::Error,QString)),
+ this, SLOT(predictionsReady(QPlaceJSonDetailsParser::Error,QString)));
+ }
+}
+
+/*!
+ Destructor.
+*/
+QPlaceDetailsReplyImpl::~QPlaceDetailsReplyImpl()
+{
+}
+
+void QPlaceDetailsReplyImpl::abort()
+{
+ restReply->cancelProcessing();
+}
+
+void QPlaceDetailsReplyImpl::restError(QPlaceRestReply::Error errorId)
+{
+ if (errorId == QPlaceRestReply::Canceled) {
+ this->setError(CancelError, "ReauestCanceled");
+ } else if (errorId == QPlaceRestReply::NetworkError) {
+ this->setError(CommunicationError, "Network error");
+ }
+ emit error(this->error(), this->errorString());
+ emit processingError(this, this->error(), this->errorString());
+ emit finished();
+ emit processingFinished(this);
+}
+
+void QPlaceDetailsReplyImpl::predictionsReady(const QPlaceJSonDetailsParser::Error &errorId,
+ const QString &errorMessage)
+{
+ if (errorId == QPlaceJSonDetailsParser::NoError) {
+ setResult(parser->result());
+ } else if (errorId == QPlaceJSonDetailsParser::ParsingError) {
+ setError(ParseError, errorMessage);
+ emit error(this->error(), this->errorString());
+ emit processingError(this, ParseError, errorMessage);
+ }
+ emit finished();
+ emit processingFinished(this);
+ delete parser;
+ parser = NULL;
+ restReply->deleteLater();
+ restReply = NULL;
+}