-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
qgsnewhttpconnection.cpp
250 lines (214 loc) · 9.33 KB
/
qgsnewhttpconnection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/***************************************************************************
qgsnewhttpconnection.cpp - selector for a new HTTP server for WMS, etc.
-------------------
begin : 3 April 2005
copyright : (C) 2005 by Brendan Morley
email : morb at ozemail dot com dot au
***************************************************************************/
/***************************************************************************
* *
* 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 "qgsnewhttpconnection.h"
#include "qgscontexthelp.h"
#include <QSettings>
#include <QMessageBox>
#include <QUrl>
#include <QPushButton>
#include <QRegExpValidator>
QgsNewHttpConnection::QgsNewHttpConnection(
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl ):
QDialog( parent, fl ),
mBaseKey( baseKey ),
mOriginalConnName( connName )
{
setupUi( this );
QString service = baseKey.mid( 18, 3 ).toUpper();
setWindowTitle( tr( "Create a new %1 connection" ).arg( service ) );
// It would be obviously much better to use mBaseKey also for credentials,
// but for some strange reason a different hardcoded key was used instead.
// WFS and WMS credentials were mixed with the same key WMS.
// Only WMS and WFS providers are using QgsNewHttpConnection at this moment
// using connection-wms and connection-wfs -> parse credential key fro it.
mCredentialsBaseKey = mBaseKey.split( '-' ).last().toUpper();
txtName->setValidator( new QRegExpValidator( QRegExp( "[^/]+" ), txtName ) );
cmbDpiMode->clear();
cmbDpiMode->addItem( tr( "all" ) );
cmbDpiMode->addItem( tr( "off" ) );
cmbDpiMode->addItem( tr( "QGIS" ) );
cmbDpiMode->addItem( tr( "UMN" ) );
cmbDpiMode->addItem( tr( "GeoServer" ) );
if ( !connName.isEmpty() )
{
// populate the dialog with the information stored for the connection
// populate the fields with the stored setting parameters
QSettings settings;
QString key = mBaseKey + connName;
QString credentialsKey = "/Qgis/" + mCredentialsBaseKey + "/" + connName;
txtName->setText( connName );
txtUrl->setText( settings.value( key + "/url" ).toString() );
cbxIgnoreGetMapURI->setChecked( settings.value( key + "/ignoreGetMapURI", false ).toBool() );
cbxIgnoreAxisOrientation->setChecked( settings.value( key + "/ignoreAxisOrientation", false ).toBool() );
cbxInvertAxisOrientation->setChecked( settings.value( key + "/invertAxisOrientation", false ).toBool() );
cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool() );
cbxSmoothPixmapTransform->setChecked( settings.value( key + "/smoothPixmapTransform", false ).toBool() );
int dpiIdx;
switch ( settings.value( key + "/dpiMode", 7 ).toInt() )
{
case 0: // off
dpiIdx = 1;
break;
case 1: // QGIS
dpiIdx = 2;
break;
case 2: // UMN
dpiIdx = 3;
break;
case 4: // GeoServer
dpiIdx = 4;
break;
default: // other => all
dpiIdx = 0;
break;
}
cmbDpiMode->setCurrentIndex( dpiIdx );
txtReferer->setText( settings.value( key + "/referer" ).toString() );
txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
}
if ( mBaseKey != "/Qgis/connections-wms/" )
{
if ( mBaseKey == "/Qgis/connections-wcs/" )
{
cbxIgnoreGetMapURI->setText( tr( "Ignore GetCoverage URI reported in capabilities" ) );
cbxIgnoreAxisOrientation->setText( tr( "Ignore axis orientation" ) );
}
else
{
cbxIgnoreGetMapURI->setVisible( false );
cbxIgnoreAxisOrientation->setVisible( false );
cbxInvertAxisOrientation->setVisible( false );
cbxSmoothPixmapTransform->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreGetMapURI );
mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
mGroupBox->layout()->removeWidget( cbxSmoothPixmapTransform );
}
cbxIgnoreGetFeatureInfoURI->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
cmbDpiMode->setVisible( false );
mGroupBox->layout()->removeWidget( cmbDpiMode );
lblDpiMode->setVisible( false );
mGroupBox->layout()->removeWidget( lblDpiMode );
txtReferer->setVisible( false );
mGroupBox->layout()->removeWidget( txtReferer );
lblReferer->setVisible( false );
mGroupBox->layout()->removeWidget( lblReferer );
// Adjust height
int w = width();
adjustSize();
resize( w, height() );
}
on_txtName_textChanged( connName );
}
QgsNewHttpConnection::~QgsNewHttpConnection()
{
}
void QgsNewHttpConnection::on_txtName_textChanged( const QString &text )
{
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
}
void QgsNewHttpConnection::on_txtUrl_textChanged( const QString &text )
{
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
}
void QgsNewHttpConnection::accept()
{
QSettings settings;
QString key = mBaseKey + txtName->text();
QString credentialsKey = "/Qgis/" + mCredentialsBaseKey + "/" + txtName->text();
// warn if entry was renamed to an existing connection
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
settings.contains( key + "/url" ) &&
QMessageBox::question( this,
tr( "Save connection" ),
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
if ( !txtPassword->text().isEmpty() &&
QMessageBox::question( this,
tr( "Saving passwords" ),
tr( "WARNING: You have entered a password. It will be stored in plain text in your project files and in your home directory on Unix-like systems, or in your user profile on Windows. If you do not want this to happen, please press the Cancel button.\nNote: giving the password is optional. It will be requested interactivly, when needed." ),
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
// on rename delete original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
{
settings.remove( mBaseKey + mOriginalConnName );
settings.remove( "/Qgis/" + mCredentialsBaseKey + "/" + mOriginalConnName );
}
QUrl url( txtUrl->text().trimmed() );
const QList< QPair<QByteArray, QByteArray> > &items = url.encodedQueryItems();
QHash< QString, QPair<QByteArray, QByteArray> > params;
for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
{
params.insert( QString( it->first ).toUpper(), *it );
}
if ( params["SERVICE"].second.toUpper() == "WMS" ||
params["SERVICE"].second.toUpper() == "WFS" ||
params["SERVICE"].second.toUpper() == "WCS" )
{
url.removeEncodedQueryItem( params["SERVICE"].first );
url.removeEncodedQueryItem( params["REQUEST"].first );
url.removeEncodedQueryItem( params["FORMAT"].first );
}
if ( url.encodedPath().isEmpty() )
{
url.setEncodedPath( "/" );
}
settings.setValue( key + "/url", url.toString() );
if ( mBaseKey == "/Qgis/connections-wms/" || mBaseKey == "/Qgis/connections-wcs/" )
{
settings.setValue( key + "/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
settings.setValue( key + "/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
settings.setValue( key + "/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
settings.setValue( key + "/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
int dpiMode = 0;
switch ( cmbDpiMode->currentIndex() )
{
case 0: // all => QGIS|UMN|GeoServer
dpiMode = 7;
break;
case 1: // off
dpiMode = 0;
break;
case 2: // QGIS
dpiMode = 1;
break;
case 3: // UMN
dpiMode = 2;
break;
case 4: // GeoServer
dpiMode = 4;
break;
}
settings.setValue( key + "/dpiMode", dpiMode );
}
if ( mBaseKey == "/Qgis/connections-wms/" )
{
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
}
settings.setValue( key + "/referer", txtReferer->text() );
settings.setValue( credentialsKey + "/username", txtUserName->text() );
settings.setValue( credentialsKey + "/password", txtPassword->text() );
settings.setValue( mBaseKey + "/selected", txtName->text() );
QDialog::accept();
}