QGIS API Documentation  2.99.0-Master (c558d51)
qgsowsconnection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsowsconnection.cpp - selector for WMS servers, etc.
3  -------------------
4  begin : 3 April 2005
5  copyright :
6  original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
7  wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
8  wms-c support : (C) 2010 Juergen E. Fischer < jef at norbit dot de >, norBIT GmbH
9  generalized : (C) 2012 Radim Blazek, based on qgswmsconnection.cpp
10 
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include "qgis.h" // GEO_EPSG_CRS_ID
23 #include "qgsdatasourceuri.h"
24 #include "qgslogger.h"
25 #include "qgsproject.h"
26 #include "qgsproviderregistry.h"
27 #include "qgsowsconnection.h"
28 
29 #include <QInputDialog>
30 #include <QMessageBox>
31 #include <QPicture>
32 #include <QSettings>
33 #include <QUrl>
34 
35 #include <QNetworkRequest>
36 #include <QNetworkReply>
37 
38 QgsOwsConnection::QgsOwsConnection( const QString & theService, const QString & theConnName )
39  : mConnName( theConnName )
40  , mService( theService )
41 {
42  QgsDebugMsg( "theConnName = " + theConnName );
43 
44  QSettings settings;
45 
46  QString key = "/Qgis/connections-" + mService.toLower() + '/' + mConnName;
47  QString credentialsKey = "/Qgis/" + mService + '/' + mConnName;
48 
49  QStringList connStringParts;
50 
51  mConnectionInfo = settings.value( key + "/url" ).toString();
52  mUri.setParam( QStringLiteral( "url" ), settings.value( key + "/url" ).toString() );
53 
54  // Check for credentials and prepend to the connection info
55  QString username = settings.value( credentialsKey + "/username" ).toString();
56  QString password = settings.value( credentialsKey + "/password" ).toString();
57  if ( !username.isEmpty() )
58  {
59  // check for a password, if none prompt to get it
60  mUri.setParam( QStringLiteral( "username" ), username );
61  mUri.setParam( QStringLiteral( "password" ), password );
62  }
63 
64  QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
65  if ( !authcfg.isEmpty() )
66  {
67  mUri.setParam( QStringLiteral( "authcfg" ), authcfg );
68  }
69  mConnectionInfo.append( ",authcfg=" + authcfg );
70 
71  bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
72  bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
73  bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
74  bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
75  if ( ignoreGetMap )
76  {
77  mUri.setParam( QStringLiteral( "IgnoreGetMapUrl" ), QStringLiteral( "1" ) );
78  }
79  if ( ignoreGetFeatureInfo )
80  {
81  mUri.setParam( QStringLiteral( "IgnoreGetFeatureInfoUrl" ), QStringLiteral( "1" ) );
82  }
83  if ( ignoreAxisOrientation )
84  {
85  mUri.setParam( QStringLiteral( "IgnoreAxisOrientation" ), QStringLiteral( "1" ) );
86  }
87  if ( invertAxisOrientation )
88  {
89  mUri.setParam( QStringLiteral( "InvertAxisOrientation" ), QStringLiteral( "1" ) );
90  }
91 
92  QgsDebugMsg( QString( "encoded uri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
93 }
94 
96 {
97 
98 }
99 
101 {
102  return mUri;
103 }
104 
105 QStringList QgsOwsConnection::connectionList( const QString & theService )
106 {
107  QSettings settings;
108  settings.beginGroup( "/Qgis/connections-" + theService.toLower() );
109  return settings.childGroups();
110 }
111 
112 QString QgsOwsConnection::selectedConnection( const QString & theService )
113 {
114  QSettings settings;
115  return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString();
116 }
117 
118 void QgsOwsConnection::setSelectedConnection( const QString & theService, const QString & name )
119 {
120  QSettings settings;
121  settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name );
122 }
123 
124 void QgsOwsConnection::deleteConnection( const QString & theService, const QString & name )
125 {
126  QSettings settings;
127  settings.remove( "/Qgis/connections-" + theService.toLower() + '/' + name );
128  settings.remove( "/Qgis/" + theService + '/' + name );
129 }
static QStringList connectionList(const QString &theService)
Returns the list of connections for the specified service.
static void deleteConnection(const QString &theService, const QString &name)
Deletes the connection for the specified service with the specified name.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsOwsConnection(const QString &theService, const QString &theConnName)
Constructor.
static QString selectedConnection(const QString &theService)
Retreives the selected connection for the specified service.
~QgsOwsConnection()
Destructor.
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
QgsDataSourceUri mUri
QByteArray encodedUri() const
return complete encoded uri (generic mode)
static void setSelectedConnection(const QString &theService, const QString &name)
Marks the specified connection for the specified service as selected.
QgsDataSourceUri uri() const
Returns the connection uri.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.