From 23451a3bd847f19d9beda5edf0cd09cf4d4c58ef Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 15 Aug 2013 10:21:21 +0200 Subject: [PATCH] handling redirection for check new version request --- src/core/UBApplicationController.cpp | 17 ++++++++++++++--- src/core/UBApplicationController.h | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 04876b79..cb9d593f 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -24,7 +24,6 @@ - #include "UBApplicationController.h" #include "frameworks/UBPlatformUtils.h" @@ -481,16 +480,27 @@ void UBApplicationController::showDesktop(bool dontSwitchFrontProcess) } -void UBApplicationController::checkUpdate() +void UBApplicationController::checkUpdate(QString urlString) { if(mHttp) delete mHttp; - QUrl url("http://get.openboard.org/update.json"); + QUrl url(urlString); mHttp = new QHttp(url.host()); connect(mHttp, SIGNAL(requestFinished(int,bool)), this, SLOT(updateRequestFinished(int,bool))); + connect(mHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(updateHeaderReceived(QHttpResponseHeader))); + mHttp->get(url.path()); } +void UBApplicationController::updateHeaderReceived(QHttpResponseHeader header) +{ + if(header.statusCode() == 302 && header.hasKey("Location")){ + mHttp->close(); + checkUpdate(header.value("Location")); + } + +} + void UBApplicationController::updateRequestFinished(int id, bool error) { if (error){ @@ -499,6 +509,7 @@ void UBApplicationController::updateRequestFinished(int id, bool error) } else{ QString responseString = QString(mHttp->readAll()); + qDebug() << responseString; if (!responseString.isEmpty() && responseString.contains("version") && responseString.contains("url")){ mHttp->close(); downloadJsonFinished(responseString); diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index 9760a6e8..a33da6d7 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -30,6 +30,8 @@ #include #include +#include + class UBBoardView; class UBDocumentProxy; @@ -145,6 +147,8 @@ class UBApplicationController : public QObject private slots: void updateRequestFinished(int id, bool error); + void updateHeaderReceived(QHttpResponseHeader header); + protected: @@ -178,7 +182,7 @@ class UBApplicationController : public QObject bool mIsShowingDesktop; bool isNoUpdateDisplayed; - void checkUpdate (); + void checkUpdate (QString urlString = "http://get.openboard.org/update.json"); QNetworkAccessManager *networkAccessManager; void downloadJsonFinished(QString updateString);