Skip to content

Commit 9551745

Browse files
committed
[BACKPORT] port qgis version check to network access manager/qgis.org
1 parent b86243e commit 9551745

File tree

2 files changed

+71
-101
lines changed

2 files changed

+71
-101
lines changed

src/app/qgisapp.cpp

100644100755
Lines changed: 68 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,128 +4675,101 @@ void QgisApp::loadPythonSupport()
46754675
void QgisApp::checkQgisVersion()
46764676
{
46774677
QApplication::setOverrideCursor( Qt::WaitCursor );
4678-
/* QUrlOperator op = new QUrlOperator( "http://mrcc.com/qgis/version.txt" );
4679-
connect(op, SIGNAL(data()), SLOT(urlData()));
4680-
connect(op, SIGNAL(finished(QNetworkOperation)), SLOT(urlFinished(QNetworkOperation)));
46814678

4682-
op.get(); */
4683-
mSocket = new QTcpSocket( this );
4684-
connect( mSocket, SIGNAL( connected() ), SLOT( socketConnected() ) );
4685-
connect( mSocket, SIGNAL( connectionClosed() ), SLOT( socketConnectionClosed() ) );
4686-
connect( mSocket, SIGNAL( readyRead() ), SLOT( socketReadyRead() ) );
4687-
connect( mSocket, SIGNAL( error( QAbstractSocket::SocketError ) ),
4688-
SLOT( socketError( QAbstractSocket::SocketError ) ) );
4689-
mSocket->connectToHost( "mrcc.com", 80 );
4679+
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( QUrl( "http://qgis.org/version.txt" ) ) );
4680+
connect( reply, SIGNAL( finished() ), this, SLOT( versionReplyFinished() ) );
46904681
}
46914682

4692-
void QgisApp::socketConnected()
4683+
void QgisApp::versionReplyFinished()
46934684
{
4694-
QTextStream os( mSocket );
4695-
mVersionMessage = "";
4696-
// send the qgis version string
4697-
// os << QGIS_VERSION << "\r\n";
4698-
os << "GET /qgis/version.txt HTTP/1.0\n\n";
4685+
QApplication::restoreOverrideCursor();
46994686

4687+
QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
4688+
if ( !reply )
4689+
return;
47004690

4701-
}
4691+
QNetworkReply::NetworkError error = reply->error();
47024692

4703-
void QgisApp::socketConnectionClosed()
4704-
{
4705-
QApplication::restoreOverrideCursor();
4706-
// strip the header
4707-
QString contentFlag = "#QGIS Version";
4708-
int pos = mVersionMessage.indexOf( contentFlag );
4709-
if ( pos > -1 )
4710-
{
4711-
pos += contentFlag.length();
4712-
// QgsDebugMsg(mVersionMessage);
4713-
// QgsDebugMsg(QString("Pos is %1").arg(pos));
4714-
mVersionMessage = mVersionMessage.mid( pos );
4715-
QStringList parts = mVersionMessage.split( "|", QString::SkipEmptyParts );
4716-
// check the version from the server against our version
4717-
QString versionInfo;
4718-
int currentVersion = parts[0].toInt();
4719-
if ( currentVersion > QGis::QGIS_VERSION_INT )
4720-
{
4721-
// show version message from server
4722-
versionInfo = tr( "There is a new version of QGIS available" ) + "\n";
4723-
}
4724-
else
4693+
if ( error == QNetworkReply::NoError )
4694+
{
4695+
QString versionMessage = reply->readAll();
4696+
QgsDebugMsg( QString( "version message: %1" ).arg( versionMessage ) );
4697+
4698+
// strip the header
4699+
QString contentFlag = "#QGIS Version";
4700+
int pos = versionMessage.indexOf( contentFlag );
4701+
if ( pos > -1 )
47254702
{
4726-
if ( QGis::QGIS_VERSION_INT > currentVersion )
4703+
pos += contentFlag.length();
4704+
QgsDebugMsg( QString( "Pos is %1" ).arg( pos ) );
4705+
4706+
versionMessage = versionMessage.mid( pos );
4707+
QStringList parts = versionMessage.split( "|", QString::SkipEmptyParts );
4708+
// check the version from the server against our version
4709+
QString versionInfo;
4710+
int currentVersion = parts[0].toInt();
4711+
if ( currentVersion > QGis::QGIS_VERSION_INT )
4712+
{
4713+
// show version message from server
4714+
versionInfo = tr( "There is a new version of QGIS available" ) + "\n";
4715+
}
4716+
else if ( QGis::QGIS_VERSION_INT > currentVersion )
47274717
{
47284718
versionInfo = tr( "You are running a development version of QGIS" ) + "\n";
47294719
}
47304720
else
47314721
{
47324722
versionInfo = tr( "You are running the current version of QGIS" ) + "\n";
47334723
}
4734-
}
4735-
if ( parts.count() > 1 )
4736-
{
4737-
versionInfo += parts[1] + "\n\n" + tr( "Would you like more information?" );
4738-
;
4739-
QMessageBox::StandardButton result = QMessageBox::information( this,
4740-
tr( "QGIS Version Information" ), versionInfo, QMessageBox::Ok |
4741-
QMessageBox::Cancel );
4742-
if ( result == QMessageBox::Ok )
4724+
4725+
if ( parts.count() > 1 )
47434726
{
4744-
// show more info
4745-
QgsMessageViewer *mv = new QgsMessageViewer( this );
4746-
mv->setWindowTitle( tr( "QGIS - Changes since last release" ) );
4747-
mv->setMessageAsHtml( parts[2] );
4748-
mv->exec();
4727+
versionInfo += parts[1] + "\n\n" + tr( "Would you like more information?" );
4728+
4729+
QMessageBox::StandardButton result = QMessageBox::information( this,
4730+
tr( "QGIS Version Information" ), versionInfo, QMessageBox::Ok |
4731+
QMessageBox::Cancel );
4732+
if ( result == QMessageBox::Ok )
4733+
{
4734+
// show more info
4735+
QgsMessageViewer *mv = new QgsMessageViewer( this );
4736+
mv->setWindowTitle( tr( "QGIS - Changes since last release" ) );
4737+
mv->setMessageAsHtml( parts[2] );
4738+
mv->exec();
4739+
}
4740+
}
4741+
else
4742+
{
4743+
QMessageBox::information( this, tr( "QGIS Version Information" ), versionInfo );
47494744
}
47504745
}
47514746
else
47524747
{
4753-
QMessageBox::information( this, tr( "QGIS Version Information" ), versionInfo );
4748+
QMessageBox::warning( this, tr( "QGIS Version Information" ), tr( "Unable to get current version information from server" ) );
47544749
}
47554750
}
47564751
else
47574752
{
4758-
QMessageBox::warning( this, tr( "QGIS Version Information" ), tr( "Unable to get current version information from server" ) );
4759-
}
4760-
}
4761-
void QgisApp::socketError( QAbstractSocket::SocketError e )
4762-
{
4763-
if ( e == QAbstractSocket::RemoteHostClosedError )
4764-
return;
4765-
4766-
QApplication::restoreOverrideCursor();
4767-
// get error type
4768-
QString detail;
4769-
switch ( e )
4770-
{
4771-
case QAbstractSocket::ConnectionRefusedError:
4772-
detail = tr( "Connection refused - server may be down" );
4773-
break;
4774-
case QAbstractSocket::HostNotFoundError:
4775-
detail = tr( "QGIS server was not found" );
4776-
break;
4777-
case QAbstractSocket::NetworkError:
4778-
detail = tr( "Network error while communicating with server" );
4779-
break;
4780-
default:
4781-
detail = tr( "Unknown network socket error" );
4782-
break;
4783-
}
4784-
4785-
// show version message from server
4786-
QMessageBox::critical( this, tr( "QGIS Version Information" ), tr( "Unable to communicate with QGIS Version server\n%1" ).arg( detail ) );
4787-
}
4753+
// get error type
4754+
QString detail;
4755+
switch ( error )
4756+
{
4757+
case QNetworkReply::ConnectionRefusedError:
4758+
detail = tr( "Connection refused - server may be down" );
4759+
break;
4760+
case QNetworkReply::HostNotFoundError:
4761+
detail = tr( "QGIS server was not found" );
4762+
break;
4763+
default:
4764+
detail = tr( "Unknown network socket error: %1" ).arg( error );
4765+
break;
4766+
}
47884767

4789-
void QgisApp::socketReadyRead()
4790-
{
4791-
while ( mSocket->bytesAvailable() > 0 )
4792-
{
4793-
char *data = new char[mSocket->bytesAvailable() + 1];
4794-
memset( data, '\0', mSocket->bytesAvailable() + 1 );
4795-
mSocket->read( data, mSocket->bytesAvailable() );
4796-
mVersionMessage += data;
4797-
delete[]data;
4768+
// show version message from server
4769+
QMessageBox::critical( this, tr( "QGIS Version Information" ), tr( "Unable to communicate with QGIS Version server\n%1" ).arg( detail ) );
47984770
}
47994771

4772+
reply->deleteLater();
48004773
}
48014774

48024775
void QgisApp::configureShortcuts()

src/app/qgisapp.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
431431
QStringList const & styles,
432432
QString const & format,
433433
QString const & crs );
434+
435+
void versionReplyFinished();
436+
434437
protected:
435438

436439
//! Handle state changes (WindowTitleChange)
@@ -592,10 +595,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
592595
void options();
593596
//! Whats-this help slot
594597
void whatsThis();
595-
void socketConnected();
596-
void socketConnectionClosed();
597-
void socketReadyRead();
598-
void socketError( QAbstractSocket::SocketError e );
599598
//! Set project properties, including map untis
600599
void projectProperties();
601600
//! Open project properties dialog and show the projections tab
@@ -998,8 +997,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
998997
QgisAppInterface *mQgisInterface;
999998
friend class QgisAppInterface;
1000999

1001-
QTcpSocket *mSocket;
1002-
QString mVersionMessage;
10031000
QSplashScreen *mSplash;
10041001
//! list of recently opened/saved project files
10051002
QStringList mRecentProjectPaths;

0 commit comments

Comments
 (0)