|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgsowsconnection.cpp - selector for WMS servers, etc. 00003 ------------------- 00004 begin : 3 April 2005 00005 copyright : 00006 original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au 00007 wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG 00008 wms-c support : (C) 2010 Juergen E. Fischer < jef at norbit dot de >, norBIT GmbH 00009 generalized : (C) 2012 Radim Blazek, based on qgswmsconnection.cpp 00010 00011 ***************************************************************************/ 00012 00013 /*************************************************************************** 00014 * * 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU General Public License as published by * 00017 * the Free Software Foundation; either version 2 of the License, or * 00018 * (at your option) any later version. * 00019 * * 00020 ***************************************************************************/ 00021 00022 #include "qgis.h" // GEO_EPSG_CRS_ID 00023 #include "qgsdatasourceuri.h" 00024 #include "qgslogger.h" 00025 #include "qgsproject.h" 00026 #include "qgsproviderregistry.h" 00027 #include "qgsowsconnection.h" 00028 00029 #include <QInputDialog> 00030 #include <QMessageBox> 00031 #include <QPicture> 00032 #include <QSettings> 00033 #include <QUrl> 00034 00035 #include <QNetworkRequest> 00036 #include <QNetworkReply> 00037 00038 QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString & theConnName ) : 00039 mConnName( theConnName ), 00040 mService( theService ) 00041 { 00042 QgsDebugMsg( "theConnName = " + theConnName ); 00043 00044 QSettings settings; 00045 00046 // WMS (providers/wfs/qgswmsconnection.cpp): 00047 //QString key = "/Qgis/connections-wms/" + mConnName; 00048 //QString credentialsKey = "/Qgis/WMS/" + mConnName; 00049 00050 // WFS (providers/wfs/qgswfsconnection.cpp): 00051 //QString key = "/Qgis/connections-wfs/" + mConnName + "/url"; 00052 00053 // WCS - there was no WCS before 00054 00055 QString key = "/Qgis/connections-" + mService.toLower() + "/" + mConnName; 00056 QString credentialsKey = "/Qgis/" + mService + "/" + mConnName; 00057 00058 QStringList connStringParts; 00059 00060 mConnectionInfo = settings.value( key + "/url" ).toString(); 00061 mUri.setParam( "url", settings.value( key + "/url" ).toString() ); 00062 00063 // Check for credentials and prepend to the connection info 00064 QString username = settings.value( credentialsKey + "/username" ).toString(); 00065 QString password = settings.value( credentialsKey + "/password" ).toString(); 00066 if ( !username.isEmpty() ) 00067 { 00068 // check for a password, if none prompt to get it 00069 if ( password.isEmpty() ) 00070 { 00071 password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), tr( "Password" ), QLineEdit::Password ); 00072 } 00073 mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo; 00074 mUri.setParam( "username", username ); 00075 mUri.setParam( "password", password ); 00076 } 00077 00078 bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool(); 00079 bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool(); 00080 bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool(); 00081 bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool(); 00082 if ( ignoreGetMap ) 00083 { 00084 mUri.setParam( "IgnoreGetMapUrl", "1" ); 00085 } 00086 if ( ignoreGetFeatureInfo ) 00087 { 00088 mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" ); 00089 } 00090 if ( ignoreAxisOrientation ) 00091 { 00092 mUri.setParam( "IgnoreAxisOrientation", "1" ); 00093 } 00094 if ( invertAxisOrientation ) 00095 { 00096 mUri.setParam( "InvertAxisOrientation", "1" ); 00097 } 00098 00099 QgsDebugMsg( QString( "Connection info: '%1'." ).arg( mConnectionInfo ) ); 00100 } 00101 00102 QgsOWSConnection::~QgsOWSConnection() 00103 { 00104 00105 } 00106 00107 QString QgsOWSConnection::connectionInfo( ) 00108 { 00109 return mConnectionInfo; 00110 } 00111 00112 QgsDataSourceURI QgsOWSConnection::uri() 00113 { 00114 return mUri; 00115 } 00116 /* 00117 QgsDataProvider * QgsOWSConnection::provider( ) 00118 { 00119 // TODO: remove completely from this class? 00120 00121 // load the server data provider plugin 00122 QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); 00123 00124 //QMap<QString,QString> keys; 00125 00126 QgsDataProvider *provider = 00127 ( QgsDataProvider* ) pReg->provider( "wms", mUri.encodedUri() ); 00128 00129 return provider; 00130 } 00131 */ 00132 00133 00134 QStringList QgsOWSConnection::connectionList( const QString & theService ) 00135 { 00136 QSettings settings; 00137 //settings.beginGroup( "/Qgis/connections-wms" ); 00138 settings.beginGroup( "/Qgis/connections-" + theService.toLower() ); 00139 return settings.childGroups(); 00140 } 00141 00142 QString QgsOWSConnection::selectedConnection( const QString & theService ) 00143 { 00144 QSettings settings; 00145 //return settings.value( "/Qgis/connections-wms/selected" ).toString(); 00146 return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString(); 00147 } 00148 00149 void QgsOWSConnection::setSelectedConnection( const QString & theService, const QString & name ) 00150 { 00151 QSettings settings; 00152 //settings.setValue( "/Qgis/connections-wms/selected", name ); 00153 settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name ); 00154 } 00155 00156 void QgsOWSConnection::deleteConnection( const QString & theService, const QString & name ) 00157 { 00158 QSettings settings; 00159 //settings.remove( "/Qgis/connections-wms/" + name ); 00160 //settings.remove( "/Qgis/WMS/" + name ); 00161 settings.remove( "/Qgis/connections-" + theService.toLower() + "/" + name ); 00162 settings.remove( "/Qgis/" + theService + "/" + name ); 00163 }