@ -90,7 +90,6 @@ 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 ) ;
@ -121,7 +120,7 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView,
connect ( UBApplication : : webController , SIGNAL ( imageCaptured ( const QPixmap & , bool , const QUrl & ) )
connect ( UBApplication : : webController , SIGNAL ( imageCaptured ( const QPixmap & , bool , const QUrl & ) )
, this , SLOT ( addCapturedPixmap ( const QPixmap & , bool , const QUrl & ) ) ) ;
, this , SLOT ( addCapturedPixmap ( const QPixmap & , bool , const QUrl & ) ) ) ;
n etworkAccessManager = new QNetworkAccessManager ( this ) ;
mN etworkAccessManager = new QNetworkAccessManager ( this ) ;
QTimer : : singleShot ( 1000 , this , SLOT ( checkAtLaunch ( ) ) ) ;
QTimer : : singleShot ( 1000 , this , SLOT ( checkAtLaunch ( ) ) ) ;
}
}
@ -136,8 +135,6 @@ UBApplicationController::~UBApplicationController()
delete mBlackScene ;
delete mBlackScene ;
delete mMirror ;
delete mMirror ;
if ( mHttp ) delete mHttp ;
delete ( mOpenSankoreImporter ) ;
delete ( mOpenSankoreImporter ) ;
mOpenSankoreImporter = NULL ;
mOpenSankoreImporter = NULL ;
}
}
@ -478,85 +475,71 @@ void UBApplicationController::showDesktop(bool dontSwitchFrontProcess)
}
}
void UBApplicationController : : checkUpdate ( QString urlString )
void UBApplicationController : : checkUpdate ( const QUrl & url )
{
{
QUrl jsonUrl = url ;
if ( url . isEmpty ( ) )
jsonUrl = UBSettings : : settings ( ) - > appSoftwareUpdateURI - > get ( ) . toUrl ( ) ;
qDebug ( ) < < " Checking for update at url: " < < jsonUrl . toString ( ) ;
# if defined(QT_NO_DEBUG)
connect ( mNetworkAccessManager , SIGNAL ( finished ( QNetworkReply * ) ) ,
/*
this , SLOT ( updateRequestFinished ( QNetworkReply * ) ) ) ;
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 ( ) ) ;
mNetworkAccessManager - > get ( QNetworkRequest ( jsonUrl ) ) ;
*/
}
# else
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());
# endif
}
/*
void UBApplicationController : : updateRequestFinished ( QNetworkReply * reply )
void UBApplicationController : : updateHeaderReceived ( QHttpResponseHeader header )
{
{
if ( header . statusCode ( ) = = 302 & & header . hasKey ( " Location " ) ) {
if ( reply - > error ( ) ) {
mHttp - > close ( ) ;
qWarning ( ) < < " Error downloading update file: " < < reply - > errorString ( ) ;
checkUpdate ( header . value ( " Location " ) ) ;
return ;
}
}
}
// Check if we are being redirected. If so, call checkUpdate again
*/
void UBApplicationController : : updateHeaderReceived ( QNetworkRequest header )
{
//if(header.attribute(QNetworkRequest::HttpStatusCodeAttribute) == 302 && header.header(QNetworkRequest::LocationHeader)){
// mHttp->close();
mHttpreply - > close ( ) ;
//checkUpdate(header.value("Location"));
// }
}
void UBApplicationController : : updateRequestFinished ( int id , bool error )
QVariant redirect_target = reply - > attribute ( QNetworkRequest : : RedirectionTargetAttribute ) ;
{
if ( ! redirect_target . isNull ( ) ) {
if ( error ) {
// The returned URL might be relative. resolved() creates an absolute url from it
qWarning ( ) < < " http command id " < < id < < " return an error " ;
QUrl redirect_url ( reply - > url ( ) . resolved ( redirect_target . toUrl ( ) ) ) ;
}
else {
checkUpdate ( redirect_url ) ;
/* QString responseString = QString(mHttp->readAll());
return ;
qDebug ( ) < < responseString ;
if ( ! responseString . isEmpty ( ) & & responseString . contains ( " version " ) & & responseString . contains ( " url " ) ) {
mHttp - > close ( ) ;
mHttp - > deleteLater ( ) ;
mHttp = 0 ;
downloadJsonFinished ( responseString ) ;
}
}
*/
QString responseString = QString ( mHttpreply - > readAll ( ) ) ;
// No error and no redirect => we read the whole response
qDebug ( ) < < responseString ;
if ( ! responseString . isEmpty ( ) & & responseString . contains ( " version " ) & & responseString . contains ( " url " ) ) {
QString responseString = QString ( reply - > readAll ( ) ) ;
mHttpreply - > close ( ) ;
mHttpreply - > deleteLater ( ) ;
if ( ! responseString . isEmpty ( ) & &
mHttpreply = 0 ;
responseString . contains ( " version " ) & &
responseString . contains ( " url " ) ) {
reply - > close ( ) ;
reply - > deleteLater ( ) ;
downloadJsonFinished ( responseString ) ;
downloadJsonFinished ( responseString ) ;
}
}
}
}
}
void UBApplicationController : : downloadJsonFinished ( QString currentJson )
void UBApplicationController : : downloadJsonFinished ( QString currentJson )
{
{
/*
The . json files simply specify the latest version number available , and
the URL to send the user to , so they can download it .
They look like :
{
" version " : " 1.3.5 " ,
" url " : " http://openboard.ch "
}
*/
QScriptValue scriptValue ;
QScriptValue scriptValue ;
QScriptEngine scriptEngine ;
QScriptEngine scriptEngine ;
scriptValue = scriptEngine . evaluate ( " ( " + currentJson + " ) " ) ;
scriptValue = scriptEngine . evaluate ( " ( " + currentJson + " ) " ) ;
@ -564,18 +547,19 @@ void UBApplicationController::downloadJsonFinished(QString currentJson)
UBVersion installedVersion ( qApp - > applicationVersion ( ) ) ;
UBVersion installedVersion ( qApp - > applicationVersion ( ) ) ;
UBVersion jsonVersion ( scriptValue . property ( " version " ) . toString ( ) ) ;
UBVersion jsonVersion ( scriptValue . property ( " version " ) . toString ( ) ) ;
qDebug ( ) < < " json version: " < < jsonVersion . toUInt ( ) ;
qDebug ( ) < < " installed version: " < < installedVersion . toUInt ( ) ;
if ( jsonVersion > installedVersion ) {
if ( jsonVersion > installedVersion ) {
if ( UBApplication : : mainWindow - > yesNoQuestion ( tr ( " Update available " ) , tr ( " New update available, would you go to the web page ? " ) ) ) {
if ( UBApplication : : mainWindow - > yesNoQuestion ( tr ( " Update available " ) , tr ( " New update available, would you go to the web page ? " ) ) ) {
QUrl url ( scriptValue . property ( " url " ) . toString ( ) ) ;
QUrl url ( scriptValue . property ( " url " ) . toString ( ) ) ;
QDesktopServices : : openUrl ( url ) ;
QDesktopServices : : openUrl ( url ) ;
}
}
}
}
else {
else if ( isNoUpdateDisplayed ) {
if ( isNoUpdateDisplayed ) {
mMainWindow - > information ( tr ( " Update " ) , tr ( " No update available " ) ) ;
mMainWindow - > information ( tr ( " Update " ) , tr ( " No update available " ) ) ;
}
}
}
}
}
void UBApplicationController : : checkAtLaunch ( )
void UBApplicationController : : checkAtLaunch ( )
{
{
@ -583,14 +567,14 @@ void UBApplicationController::checkAtLaunch()
if ( UBSettings : : settings ( ) - > appEnableAutomaticSoftwareUpdates - > get ( ) . toBool ( ) ) {
if ( UBSettings : : settings ( ) - > appEnableAutomaticSoftwareUpdates - > get ( ) . toBool ( ) ) {
isNoUpdateDisplayed = false ;
isNoUpdateDisplayed = false ;
//checkUpdate ();
checkUpdate ( ) ;
}
}
}
}
void UBApplicationController : : checkUpdateRequest ( )
void UBApplicationController : : checkUpdateRequest ( )
{
{
isNoUpdateDisplayed = true ;
isNoUpdateDisplayed = true ;
//checkUpdate ();
checkUpdate ( ) ;
}
}
void UBApplicationController : : hideDesktop ( )
void UBApplicationController : : hideDesktop ( )