QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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( "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( "username", username );
61  mUri.setParam( "password", password );
62  }
63 
64  bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
65  bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
66  bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
67  bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
68  if ( ignoreGetMap )
69  {
70  mUri.setParam( "IgnoreGetMapUrl", "1" );
71  }
72  if ( ignoreGetFeatureInfo )
73  {
74  mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" );
75  }
76  if ( ignoreAxisOrientation )
77  {
78  mUri.setParam( "IgnoreAxisOrientation", "1" );
79  }
80  if ( invertAxisOrientation )
81  {
82  mUri.setParam( "InvertAxisOrientation", "1" );
83  }
84 
85  QgsDebugMsg( QString( "encoded uri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
86 }
87 
89 {
90 
91 }
92 
94 {
95  return mConnectionInfo;
96 }
97 
99 {
100  return mUri;
101 }
102 
103 QStringList QgsOWSConnection::connectionList( const QString & theService )
104 {
105  QSettings settings;
106  settings.beginGroup( "/Qgis/connections-" + theService.toLower() );
107  return settings.childGroups();
108 }
109 
110 QString QgsOWSConnection::selectedConnection( const QString & theService )
111 {
112  QSettings settings;
113  return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString();
114 }
115 
116 void QgsOWSConnection::setSelectedConnection( const QString & theService, const QString & name )
117 {
118  QSettings settings;
119  settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name );
120 }
121 
122 void QgsOWSConnection::deleteConnection( const QString & theService, const QString & name )
123 {
124  QSettings settings;
125  settings.remove( "/Qgis/connections-" + theService.toLower() + "/" + name );
126  settings.remove( "/Qgis/" + theService + "/" + name );
127 }