qgis / src / app / qgsversioninfo.cpp @ master
History | View | Annotate | Download (3.14 KB)
1 |
/***************************************************************************
|
---|---|
2 |
|
3 |
----------------------------------------------------
|
4 |
date : 18.8.2015
|
5 |
copyright : (C) 2015 by Matthias Kuhn
|
6 |
email : matthias (at) opengis.ch
|
7 |
***************************************************************************
|
8 |
* *
|
9 |
* This program is free software; you can redistribute it and/or modify *
|
10 |
* it under the terms of the GNU General Public License as published by *
|
11 |
* the Free Software Foundation; either version 2 of the License, or *
|
12 |
* (at your option) any later version. *
|
13 |
* *
|
14 |
***************************************************************************/
|
15 |
|
16 |
#include "qgsversioninfo.h" |
17 |
#include "moc_qgsversioninfo.cpp" |
18 |
#include "qgis.h" |
19 |
#include "qgsapplication.h" |
20 |
#include "qgsnetworkaccessmanager.h" |
21 |
#include <QUrl> |
22 |
|
23 |
QgsVersionInfo::QgsVersionInfo( QObject *parent ) |
24 |
: QObject( parent ) |
25 |
{ |
26 |
} |
27 |
|
28 |
void QgsVersionInfo::checkVersion()
|
29 |
{ |
30 |
QNetworkRequest request( QUrl( QStringLiteral( "https://version.qgis.org/version.txt" ) ) );
|
31 |
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork ); |
32 |
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request ); |
33 |
connect( reply, &QNetworkReply::finished, this, &QgsVersionInfo::versionReplyFinished );
|
34 |
} |
35 |
|
36 |
bool QgsVersionInfo::newVersionAvailable() const |
37 |
{ |
38 |
return mLatestVersion > Qgis::versionInt();
|
39 |
} |
40 |
|
41 |
bool QgsVersionInfo::isDevelopmentVersion() const |
42 |
{ |
43 |
return Qgis::versionInt() > mLatestVersion;
|
44 |
} |
45 |
|
46 |
void QgsVersionInfo::versionReplyFinished()
|
47 |
{ |
48 |
QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() ); |
49 |
Q_ASSERT( reply ); |
50 |
|
51 |
mError = reply->error(); |
52 |
mErrorString = reply->errorString(); |
53 |
|
54 |
if ( mError == QNetworkReply::NoError )
|
55 |
{ |
56 |
QString versionMessage = reply->readAll(); |
57 |
|
58 |
// strip the header
|
59 |
const QString contentFlag = QStringLiteral( "#QGIS Version" ); |
60 |
int pos = versionMessage.indexOf( contentFlag );
|
61 |
|
62 |
if ( pos > -1 ) |
63 |
{ |
64 |
pos += contentFlag.length(); |
65 |
|
66 |
versionMessage = versionMessage.mid( pos ); |
67 |
QStringList parts = versionMessage.split( '|', Qt::SkipEmptyParts );
|
68 |
// check the version from the server against our version
|
69 |
mLatestVersion = parts[0].toInt();
|
70 |
mDownloadInfo = parts.value( 1 );
|
71 |
mAdditionalHtml = parts.value( 2 );
|
72 |
} |
73 |
} |
74 |
|
75 |
// get error type
|
76 |
switch ( mError )
|
77 |
{ |
78 |
case QNetworkReply::ConnectionRefusedError:
|
79 |
mErrorString = tr( "Connection refused - server may be down" );
|
80 |
break;
|
81 |
case QNetworkReply::HostNotFoundError:
|
82 |
mErrorString = tr( "The host name %1 could not be resolved. Check your DNS settings or contact your system administrator." ).arg( reply->request().url().host() );
|
83 |
break;
|
84 |
case QNetworkReply::NoError:
|
85 |
mErrorString.clear(); |
86 |
break;
|
87 |
default:
|
88 |
mErrorString = reply->errorString(); |
89 |
break;
|
90 |
} |
91 |
|
92 |
reply->deleteLater(); |
93 |
|
94 |
emit versionInfoAvailable(); |
95 |
} |