handling redirection for check new version request

preferencesAboutTextFull
Claudio Valerio 11 years ago
parent e4382f6a9e
commit 23451a3bd8
  1. 17
      src/core/UBApplicationController.cpp
  2. 6
      src/core/UBApplicationController.h

@ -24,7 +24,6 @@
#include "UBApplicationController.h" #include "UBApplicationController.h"
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
@ -481,16 +480,27 @@ void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
} }
void UBApplicationController::checkUpdate() void UBApplicationController::checkUpdate(QString urlString)
{ {
if(mHttp) if(mHttp)
delete mHttp; delete mHttp;
QUrl url("http://get.openboard.org/update.json"); QUrl url(urlString);
mHttp = new QHttp(url.host()); mHttp = new QHttp(url.host());
connect(mHttp, SIGNAL(requestFinished(int,bool)), this, SLOT(updateRequestFinished(int,bool))); connect(mHttp, SIGNAL(requestFinished(int,bool)), this, SLOT(updateRequestFinished(int,bool)));
connect(mHttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(updateHeaderReceived(QHttpResponseHeader)));
mHttp->get(url.path()); 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) void UBApplicationController::updateRequestFinished(int id, bool error)
{ {
if (error){ if (error){
@ -499,6 +509,7 @@ void UBApplicationController::updateRequestFinished(int id, bool error)
} }
else{ else{
QString responseString = QString(mHttp->readAll()); QString responseString = QString(mHttp->readAll());
qDebug() << responseString;
if (!responseString.isEmpty() && responseString.contains("version") && responseString.contains("url")){ if (!responseString.isEmpty() && responseString.contains("version") && responseString.contains("url")){
mHttp->close(); mHttp->close();
downloadJsonFinished(responseString); downloadJsonFinished(responseString);

@ -30,6 +30,8 @@
#include <QtGui> #include <QtGui>
#include <QFtp> #include <QFtp>
#include <QHttpResponseHeader>
class UBBoardView; class UBBoardView;
class UBDocumentProxy; class UBDocumentProxy;
@ -145,6 +147,8 @@ class UBApplicationController : public QObject
private slots: private slots:
void updateRequestFinished(int id, bool error); void updateRequestFinished(int id, bool error);
void updateHeaderReceived(QHttpResponseHeader header);
protected: protected:
@ -178,7 +182,7 @@ class UBApplicationController : public QObject
bool mIsShowingDesktop; bool mIsShowingDesktop;
bool isNoUpdateDisplayed; bool isNoUpdateDisplayed;
void checkUpdate (); void checkUpdate (QString urlString = "http://get.openboard.org/update.json");
QNetworkAccessManager *networkAccessManager; QNetworkAccessManager *networkAccessManager;
void downloadJsonFinished(QString updateString); void downloadJsonFinished(QString updateString);

Loading…
Cancel
Save