Skip to content
Permalink
Browse files

Add version info to the welcome screen

  • Loading branch information
m-kuhn committed Aug 19, 2015
1 parent b3a868f commit bb69f166ad9990889212b246fc006616c889d2e0
Showing with 237 additions and 78 deletions.
  1. +2 −0 src/app/CMakeLists.txt
  2. +26 −76 src/app/qgisapp.cpp
  3. +2 −0 src/app/qgisapp.h
  4. +91 −0 src/app/qgsversioninfo.cpp
  5. +62 −0 src/app/qgsversioninfo.h
  6. +51 −2 src/app/qgswelcomepage.cpp
  7. +3 −0 src/app/qgswelcomepage.h
@@ -52,6 +52,7 @@ SET(QGIS_APP_SRCS
qgsguivectorlayertools.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
qgsversioninfo.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdpart.cpp
@@ -212,6 +213,7 @@ SET (QGIS_APP_MOC_HDRS
qgsguivectorlayertools.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
qgsversioninfo.h

qgsmaptooladdfeature.h
qgsmaptoolcapture.h
@@ -213,6 +213,7 @@
#include "qgsmaplayeractionregistry.h"
#include "qgswelcomepage.h"
#include "qgsmaprendererparalleljob.h"
#include "qgsversioninfo.h"

#include "qgssublayersdialog.h"
#include "ogr/qgsopenvectorlayerdialog.h"
@@ -7734,102 +7735,51 @@ void QgisApp::loadPythonSupport()

void QgisApp::checkQgisVersion()
{
QgsVersionInfo* versionInfo = new QgsVersionInfo();
QApplication::setOverrideCursor( Qt::WaitCursor );

QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( QUrl( "http://qgis.org/version.txt" ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( versionReplyFinished() ) );
connect( versionInfo, SIGNAL(versionInfoAvailable()), this, SLOT(versionReplyFinished()));
versionInfo->checkVersion();
}

void QgisApp::versionReplyFinished()
{
QApplication::restoreOverrideCursor();

QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
if ( !reply )
return;

QNetworkReply::NetworkError error = reply->error();
QgsVersionInfo* versionInfo = qobject_cast<QgsVersionInfo*>( sender() );
Q_ASSERT( versionInfo );

if ( error == QNetworkReply::NoError )
if( versionInfo->error() == QNetworkReply::NoError )
{
QString versionMessage = reply->readAll();
QgsDebugMsg( QString( "version message: %1" ).arg( versionMessage ) );
QString info;

// strip the header
QString contentFlag = "#QGIS Version";
int pos = versionMessage.indexOf( contentFlag );
if ( pos > -1 )
if ( versionInfo->newVersionAvailable() )
{
pos += contentFlag.length();
QgsDebugMsg( QString( "Pos is %1" ).arg( pos ) );

versionMessage = versionMessage.mid( pos );
QStringList parts = versionMessage.split( "|", QString::SkipEmptyParts );
// check the version from the server against our version
QString versionInfo;
int currentVersion = parts[0].toInt();
if ( currentVersion > QGis::QGIS_VERSION_INT )
{
// show version message from server
versionInfo = tr( "There is a new version of QGIS available" ) + "\n";
}
else if ( QGis::QGIS_VERSION_INT > currentVersion )
{
versionInfo = tr( "You are running a development version of QGIS" ) + "\n";
}
else
{
versionInfo = tr( "You are running the current version of QGIS" ) + "\n";
}

if ( parts.count() > 1 )
{
versionInfo += parts[1] + "\n\n" + tr( "Would you like more information?" );

QMessageBox::StandardButton result = QMessageBox::information( this,
tr( "QGIS Version Information" ), versionInfo, QMessageBox::Ok |
QMessageBox::Cancel );
if ( result == QMessageBox::Ok )
{
// show more info
QgsMessageViewer *mv = new QgsMessageViewer( this );
mv->setWindowTitle( tr( "QGIS - Changes since last release" ) );
mv->setMessageAsHtml( parts[2] );
mv->exec();
}
}
else
{
QMessageBox::information( this, tr( "QGIS Version Information" ), versionInfo );
}
info = tr( "There is a new version of QGIS available" );
}
else if ( versionInfo->isDevelopmentVersion() )
{
info = tr( "You are running a development version of QGIS" );
}
else
{
QMessageBox::warning( this, tr( "QGIS Version Information" ), tr( "Unable to get current version information from server" ) );
info = tr( "You are running the current version of QGIS" );
}

info = QString( "<b>%1</b>" ).arg( info );

info += "<br>" + versionInfo->downloadInfo();

QMessageBox mb( QMessageBox::Information, tr( "QGIS Version Information" ), info );
mb.setInformativeText( versionInfo->html() );
mb.exec();
}
else
{
// get error type
QString detail;
switch ( error )
{
case QNetworkReply::ConnectionRefusedError:
detail = tr( "Connection refused - server may be down" );
break;
case QNetworkReply::HostNotFoundError:
detail = tr( "QGIS server was not found" );
break;
default:
detail = tr( "Unknown network socket error: %1" ).arg( error );
break;
}

// show version message from server
QMessageBox::critical( this, tr( "QGIS Version Information" ), tr( "Unable to communicate with QGIS Version server\n%1" ).arg( detail ) );
QMessageBox mb( QMessageBox::Warning, tr( "QGIS Version Information" ), tr( "Unable to get current version information from server" ) );
mb.setDetailedText( versionInfo->errorString() );
mb.exec();
}

reply->deleteLater();
}

void QgisApp::configureShortcuts()
@@ -480,6 +480,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
static LONG WINAPI qgisCrashDump( struct _EXCEPTION_POINTERS *ExceptionInfo );
#endif

void parseVersionInfo(QNetworkReply* reply, int& latestVersion, QStringList& versionInfo );

public slots:
void layerTreeViewDoubleClicked( const QModelIndex& index );
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
@@ -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();
}
@@ -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
@@ -16,24 +16,55 @@
#include "qgswelcomepage.h"
#include "qgsproject.h"
#include "qgisapp.h"
#include "qgsversioninfo.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QListView>
#include <QSettings>

QgsWelcomePage::QgsWelcomePage( QWidget* parent )
: QWidget( parent )
{
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->setMargin( 0 );
setLayout( mainLayout );

QHBoxLayout* layout = new QHBoxLayout();
layout->setMargin( 9 );
setLayout( layout );

mainLayout->addLayout( layout );

QListView* welcomeScreenListView = new QListView();
mModel = new QgsWelcomePageItemsModel();
welcomeScreenListView->setModel( mModel );
layout->addWidget( welcomeScreenListView );
welcomeScreenListView->setStyleSheet( "QListView::item {"
" margin-top: 5px;"
" margin-bottom: 5px;"
" margin-left: 15px;"
" margin-right: 15px;"
" border-width: 1px;"
" border-color: #535353;"
" border-radius: 9px;"
" background: #cccccc;"
" padding: 10px;"
"}"
"QListView::item:selected:active {"
" background: #aaaaaa;"
"}");

QgsWebView* webView = new QgsWebView();
webView->setUrl( QUrl( "http://blog.qgis.org" ) );
layout->addWidget( webView );

mVersionInformation = new QLabel;
mainLayout->addWidget( mVersionInformation );
mVersionInformation->setVisible( false );

setWindowTitle( tr( "Recent Projects..." ) );
QgsVersionInfo* versionInfo = new QgsVersionInfo();
connect( versionInfo, SIGNAL(versionInfoAvailable()), this, SLOT(versionInfoReceived()));
versionInfo->checkVersion();

connect( welcomeScreenListView, SIGNAL( doubleClicked( QModelIndex ) ), this, SLOT( itemDoubleClicked( QModelIndex ) ) );
}
@@ -47,3 +78,21 @@ void QgsWelcomePage::itemDoubleClicked( const QModelIndex& index )
{
QgisApp::instance()->openProject( mModel->data( index, Qt::ToolTipRole ).toString() );
}

void QgsWelcomePage::versionInfoReceived()
{
QgsVersionInfo* versionInfo = qobject_cast<QgsVersionInfo*>( sender() );
Q_ASSERT( versionInfo );

if ( versionInfo->isDevelopmentVersion() )
{
mVersionInformation->setVisible( true );
mVersionInformation->setText( QString( "<b>%1</b>: %2")
.arg( tr( "There is a new QGIS version available" ) )
.arg( versionInfo->downloadInfo() ) );
mVersionInformation->setStyleSheet("QLabel{"
" background-color: #dddd00;"
" padding: 5px;"
"}");
}
}

0 comments on commit bb69f16

Please sign in to comment.
You can’t perform that action at this time.