- In DEBUG mode,the Openboard application crashes after a checkUpdate

("http://get.openboard.org/update.json").
=> the url do not exists.
preferencesAboutTextFull
agriche 9 years ago
parent 2bf6a6d6e0
commit 1ddeaa0d61
  1. 101
      src/core/UBApplicationController.cpp

@ -22,9 +22,7 @@
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>. * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QScriptValue>
#include <QScriptEngine>
#include <QUrl>
#include "UBApplicationController.h" #include "UBApplicationController.h"
@ -67,6 +65,9 @@
#include "ui_mainWindow.h" #include "ui_mainWindow.h"
#ifdef Q_WS_MAC
#include <Carbon/Carbon.h>
#endif
#include "core/memcheck.h" #include "core/memcheck.h"
@ -85,6 +86,7 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView,
, mAutomaticCheckForUpdates(false) , mAutomaticCheckForUpdates(false)
, mCheckingForUpdates(false) , mCheckingForUpdates(false)
, mIsShowingDesktop(false) , mIsShowingDesktop(false)
, mHttp(0)
{ {
mDisplayManager = new UBDisplayManager(this); mDisplayManager = new UBDisplayManager(this);
@ -119,7 +121,7 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView,
QTimer::singleShot (1000, this, SLOT (checkAtLaunch())); QTimer::singleShot (1000, this, SLOT (checkAtLaunch()));
#ifdef Q_OS_LINUX #ifdef Q_WS_X11
mMainWindow->setStyleSheet("QToolButton { font-size: 11px}"); mMainWindow->setStyleSheet("QToolButton { font-size: 11px}");
#endif #endif
@ -136,6 +138,8 @@ UBApplicationController::~UBApplicationController()
delete mBlackScene; delete mBlackScene;
delete mMirror; delete mMirror;
if (mHttp) delete mHttp;
delete(mOpenSankoreImporter); delete(mOpenSankoreImporter);
mOpenSankoreImporter = NULL; mOpenSankoreImporter = NULL;
} }
@ -475,53 +479,82 @@ void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
} }
void UBApplicationController::checkUpdate(QString urlString) void UBApplicationController::checkUpdate(QString urlString)
{ {
//connect(networkAccessManager, &QNetworkAccessManager::finished,
// this, &UBApplicationController::updateRequestFinished);
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(updateRequestFinished(QNetworkReply*)));
networkAccessManager->get(QNetworkRequest(QUrl(urlString))); #if defined(QT_NO_DEBUG)
/*
if(mHttp)
mHttp->deleteLater();
QUrl url(urlString);
mHttp = new QHttpPart(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());
*/
if(mHttpreply)
mHttpreply->deleteLater();
QUrl url(urlString);
mHttpreply = qnam.get(QNetworkRequest(url));
connect(mHttpreply, SIGNAL(requestFinished(int,bool)), this, SLOT(updateRequestFinished(int,bool)));
connect(mHttpreply, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(updateHeaderReceived(QHttpResponseHeader)));
// mHttpreply->setUrl(url.path());
//mHttp->get(url.path());
#else
void UBApplicationController::updateRequestFinished(QNetworkReply * reply) #endif
{
if (reply->error()) {
qWarning() << "HTTP Error";
return;
} }
// Check if we are being redirected. If so, call checkUpdate again
QVariant redirect_target = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (!redirect_target.isNull()) { /*
// The returned URL might be relative. resolved() creates an absolute url from it void UBApplicationController::updateHeaderReceived(QHttpResponseHeader header)
QUrl redirect_url(reply->url().resolved(redirect_target.toUrl())); {
if(header.statusCode() == 302 && header.hasKey("Location")){
checkUpdate(redirect_url.toString()); mHttp->close();
return; checkUpdate(header.value("Location"));
} }
}
*/
void UBApplicationController::updateHeaderReceived(QNetworkRequest header )
{
//if(header.attribute(QNetworkRequest::HttpStatusCodeAttribute) == 302 && header.header(QNetworkRequest::LocationHeader)){
// mHttp->close();
mHttpreply->close();
//checkUpdate(header.value("Location"));
// }
}
// No error and no redirect => we read the whole response void UBApplicationController::updateRequestFinished(int id, bool error)
{
QString responseString = QString(reply->readAll()); if (error){
qWarning() << "http command id" << id << "return an error";
}
else{
/* QString responseString = QString(mHttp->readAll());
qDebug() << responseString; qDebug() << responseString;
if (!responseString.isEmpty() && responseString.contains("version") && responseString.contains("url")){
if (!responseString.isEmpty() && mHttp->close();
responseString.contains("version") && mHttp->deleteLater();
responseString.contains("url")) { mHttp = 0;
reply->close();
reply->deleteLater();
downloadJsonFinished(responseString); downloadJsonFinished(responseString);
} }
*/
QString responseString = QString(mHttpreply->readAll());
qDebug() << responseString;
if (!responseString.isEmpty() && responseString.contains("version") && responseString.contains("url")){
mHttpreply->close();
mHttpreply->deleteLater();
mHttpreply = 0;
downloadJsonFinished(responseString);
} }
}
}
void UBApplicationController::downloadJsonFinished(QString currentJson) void UBApplicationController::downloadJsonFinished(QString currentJson)

Loading…
Cancel
Save