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 |
|
29 |
void QgsVersionInfo::checkVersion()
|
30 |
{ |
31 |
QNetworkRequest request( QUrl( QStringLiteral( "https://version.qgis.org/version.txt" ) ) );
|
32 |
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork ); |
33 |
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request ); |
34 |
connect( reply, &QNetworkReply::finished, this, &QgsVersionInfo::versionReplyFinished );
|
35 |
} |
36 |
|
37 |
bool QgsVersionInfo::newVersionAvailable() const |
38 |
{ |
39 |
return mLatestVersion > Qgis::versionInt();
|
40 |
} |
41 |
|
42 |
bool QgsVersionInfo::isDevelopmentVersion() const |
43 |
{ |
44 |
return Qgis::versionInt() > mLatestVersion;
|
45 |
} |
46 |
|
47 |
void QgsVersionInfo::versionReplyFinished()
|
48 |
{ |
49 |
QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() ); |
50 |
Q_ASSERT( reply ); |
51 |
|
52 |
mError = reply->error(); |
53 |
mErrorString = reply->errorString(); |
54 |
|
55 |
if ( mError == QNetworkReply::NoError )
|
56 |
{ |
57 |
QString versionMessage = reply->readAll(); |
58 |
|
59 |
// strip the header
|
60 |
const QString contentFlag = QStringLiteral( "#QGIS Version" ); |
61 |
int pos = versionMessage.indexOf( contentFlag );
|
62 |
|
63 |
if ( pos > -1 ) |
64 |
{ |
65 |
pos += contentFlag.length(); |
66 |
|
67 |
versionMessage = versionMessage.mid( pos ); |
68 |
QStringList parts = versionMessage.split( '|', Qt::SkipEmptyParts );
|
69 |
// check the version from the server against our version
|
70 |
mLatestVersion = parts[0].toInt();
|
71 |
mDownloadInfo = parts.value( 1 );
|
72 |
mAdditionalHtml = parts.value( 2 );
|
73 |
} |
74 |
} |
75 |
|
76 |
// get error type
|
77 |
switch ( mError )
|
78 |
{ |
79 |
case QNetworkReply::ConnectionRefusedError:
|
80 |
mErrorString = tr( "Connection refused - server may be down" );
|
81 |
break;
|
82 |
case QNetworkReply::HostNotFoundError:
|
83 |
mErrorString = tr( "The host name %1 could not be resolved. Check your DNS settings or contact your system administrator." ).arg( reply->request().url().host() );
|
84 |
break;
|
85 |
case QNetworkReply::NoError:
|
86 |
mErrorString.clear(); |
87 |
break;
|
88 |
default:
|
89 |
mErrorString = reply->errorString(); |
90 |
break;
|
91 |
} |
92 |
|
93 |
reply->deleteLater(); |
94 |
|
95 |
emit versionInfoAvailable(); |
96 |
} |