Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add version info to the welcome screen
- Loading branch information
Showing
7 changed files
with
237 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*************************************************************************** | ||
---------------------------------------------------- | ||
date : 18.8.2015 | ||
copyright : (C) 2015 by Matthias Kuhn | ||
email : matthias (at) opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsversioninfo.h" | ||
#include "qgis.h" | ||
|
||
#include "qgsnetworkaccessmanager.h" | ||
|
||
QgsVersionInfo::QgsVersionInfo( QObject *parent ) : QObject(parent) | ||
{ | ||
|
||
} | ||
|
||
void QgsVersionInfo::checkVersion() | ||
{ | ||
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( QUrl( "https://qgis.org/version.txt" ) ) ); | ||
connect( reply, SIGNAL( finished() ), this, SLOT( versionReplyFinished() ) ); | ||
} | ||
|
||
bool QgsVersionInfo::newVersionAvailable() const | ||
{ | ||
return mLatestVersion > QGis::QGIS_VERSION_INT; | ||
} | ||
|
||
bool QgsVersionInfo::isDevelopmentVersion() const | ||
{ | ||
return QGis::QGIS_VERSION_INT > mLatestVersion; | ||
} | ||
|
||
void QgsVersionInfo::versionReplyFinished() | ||
{ | ||
QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() ); | ||
Q_ASSERT( reply ); | ||
|
||
mError = reply->error(); | ||
mErrorString = reply->errorString(); | ||
|
||
if ( mError == QNetworkReply::NoError ) | ||
{ | ||
QString versionMessage = reply->readAll(); | ||
|
||
// strip the header | ||
QString contentFlag = "#QGIS Version"; | ||
int pos = versionMessage.indexOf( contentFlag ); | ||
|
||
if ( pos > -1 ) | ||
{ | ||
pos += contentFlag.length(); | ||
|
||
versionMessage = versionMessage.mid( pos ); | ||
QStringList parts = versionMessage.split( "|", QString::SkipEmptyParts ); | ||
// check the version from the server against our version | ||
mLatestVersion = parts[0].toInt(); | ||
mDownloadInfo = parts.value( 1 ); | ||
mAdditionalHtml = parts.value( 2 ); | ||
} | ||
} | ||
|
||
// get error type | ||
switch ( mError ) | ||
{ | ||
case QNetworkReply::ConnectionRefusedError: | ||
mErrorString = tr( "Connection refused - server may be down" ); | ||
break; | ||
case QNetworkReply::HostNotFoundError: | ||
mErrorString = tr( "The host name qgis.org could not be resolved. Check your DNS settings or contact your system administrator." ); | ||
break; | ||
case QNetworkReply::NoError: | ||
mErrorString = ""; | ||
break; | ||
default: | ||
mErrorString = reply->errorString(); | ||
break; | ||
} | ||
|
||
reply->deleteLater(); | ||
|
||
emit versionInfoAvailable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*************************************************************************** | ||
---------------------------------------------------- | ||
date : 18.8.2015 | ||
copyright : (C) 2015 by Matthias Kuhn | ||
email : matthias (at) opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSVERSIONINFO_H | ||
#define QGSVERSIONINFO_H | ||
|
||
#include <QObject> | ||
#include <QNetworkReply> | ||
|
||
class QgsVersionInfo : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsVersionInfo( QObject *parent = 0 ); | ||
|
||
public slots: | ||
/** | ||
* Connects to qgis.org and checks for new versions. | ||
*/ | ||
void checkVersion(); | ||
|
||
QString html() const { return mAdditionalHtml; } | ||
|
||
QString downloadInfo() const { return mDownloadInfo; } | ||
|
||
int latestVersionCode() const { return mLatestVersion; } | ||
|
||
bool newVersionAvailable() const; | ||
|
||
bool isDevelopmentVersion() const; | ||
|
||
QNetworkReply::NetworkError error() const { return mError; } | ||
|
||
QString errorString() const { return mErrorString; } | ||
|
||
private slots: | ||
void versionReplyFinished(); | ||
|
||
signals: | ||
void versionInfoAvailable(); | ||
|
||
private: | ||
int mLatestVersion; | ||
QString mDownloadInfo; | ||
QString mAdditionalHtml; | ||
QNetworkReply::NetworkError mError; | ||
QString mErrorString; | ||
}; | ||
|
||
#endif // QGSVERSIONINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.