QGIS API Documentation  2.2.0-Valmiera
 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  if ( password.isEmpty() )
61  {
62  password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), tr( "Password" ), QLineEdit::Password );
63  }
64  mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo;
65  mUri.setParam( "username", username );
66  mUri.setParam( "password", password );
67  }
68 
69  bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
70  bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
71  bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
72  bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
73  if ( ignoreGetMap )
74  {
75  mUri.setParam( "IgnoreGetMapUrl", "1" );
76  }
77  if ( ignoreGetFeatureInfo )
78  {
79  mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" );
80  }
81  if ( ignoreAxisOrientation )
82  {
83  mUri.setParam( "IgnoreAxisOrientation", "1" );
84  }
85  if ( invertAxisOrientation )
86  {
87  mUri.setParam( "InvertAxisOrientation", "1" );
88  }
89 
90  QgsDebugMsg( QString( "Connection info: '%1'." ).arg( mConnectionInfo ) );
91 }
92 
94 {
95 
96 }
97 
99 {
100  return mConnectionInfo;
101 }
102 
104 {
105  return mUri;
106 }
107 
108 #if 0
109 QgsDataProvider * QgsOWSConnection::provider()
110 {
111  // TODO: remove completely from this class?
112 
113  // load the server data provider plugin
115 
116  //QMap<QString,QString> keys;
117 
118  QgsDataProvider *provider =
119  ( QgsDataProvider* ) pReg->provider( "wms", mUri.encodedUri() );
120 
121  return provider;
122 }
123 #endif
124 
125 
126 QStringList QgsOWSConnection::connectionList( const QString & theService )
127 {
128  QSettings settings;
129  settings.beginGroup( "/Qgis/connections-" + theService.toLower() );
130  return settings.childGroups();
131 }
132 
133 QString QgsOWSConnection::selectedConnection( const QString & theService )
134 {
135  QSettings settings;
136  return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString();
137 }
138 
139 void QgsOWSConnection::setSelectedConnection( const QString & theService, const QString & name )
140 {
141  QSettings settings;
142  settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name );
143 }
144 
145 void QgsOWSConnection::deleteConnection( const QString & theService, const QString & name )
146 {
147  QSettings settings;
148  settings.remove( "/Qgis/connections-" + theService.toLower() + "/" + name );
149  settings.remove( "/Qgis/" + theService + "/" + name );
150 }