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 "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);

@ -30,6 +30,8 @@
#include <QtGui>
#include <QFtp>
#include <QHttpResponseHeader>
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);

Loading…
Cancel
Save