20 #include <QMessageBox>
22 #include <QPushButton>
23 #include <QRegExpValidator>
26 QWidget *parent,
const QString& baseKey,
const QString& connName, Qt::WindowFlags fl ):
27 QDialog( parent, fl ),
29 mOriginalConnName( connName )
33 QString service = baseKey.mid( 18, 3 ).toUpper();
34 setWindowTitle(
tr(
"Create a new %1 connection" ).arg( service ) );
41 mCredentialsBaseKey = mBaseKey.split(
'-' ).last().toUpper();
43 txtName->setValidator(
new QRegExpValidator( QRegExp(
"[^\\/]+" ), txtName ) );
46 cmbDpiMode->addItem(
tr(
"all" ) );
47 cmbDpiMode->addItem(
tr(
"off" ) );
48 cmbDpiMode->addItem(
tr(
"QGIS" ) );
49 cmbDpiMode->addItem(
tr(
"UMN" ) );
50 cmbDpiMode->addItem(
tr(
"GeoServer" ) );
52 if ( !connName.isEmpty() )
59 QString key = mBaseKey + connName;
60 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
"/" + connName;
61 txtName->setText( connName );
62 txtUrl->setText( settings.value( key +
"/url" ).toString() );
64 cbxIgnoreGetMapURI->setChecked( settings.value( key +
"/ignoreGetMapURI",
false ).toBool() );
65 cbxIgnoreAxisOrientation->setChecked( settings.value( key +
"/ignoreAxisOrientation",
false ).toBool() );
66 cbxInvertAxisOrientation->setChecked( settings.value( key +
"/invertAxisOrientation",
false ).toBool() );
67 cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
68 cbxSmoothPixmapTransform->setChecked( settings.value( key +
"/smoothPixmapTransform",
false ).toBool() );
71 switch ( settings.value( key +
"/dpiMode", 7 ).toInt() )
89 cmbDpiMode->setCurrentIndex( dpiIdx );
91 txtReferer->setText( settings.value( key +
"/referer" ).toString() );
93 txtUserName->setText( settings.value( credentialsKey +
"/username" ).toString() );
94 txtPassword->setText( settings.value( credentialsKey +
"/password" ).toString() );
97 if ( mBaseKey !=
"/Qgis/connections-wms/" )
99 if ( mBaseKey ==
"/Qgis/connections-wcs/" )
101 cbxIgnoreGetMapURI->setText(
tr(
"Ignore GetCoverage URI reported in capabilities" ) );
102 cbxIgnoreAxisOrientation->setText(
tr(
"Ignore axis orientation" ) );
106 cbxIgnoreGetMapURI->setVisible(
false );
107 cbxIgnoreAxisOrientation->setVisible(
false );
108 cbxInvertAxisOrientation->setVisible(
false );
109 cbxSmoothPixmapTransform->setVisible(
false );
110 mGroupBox->layout()->removeWidget( cbxIgnoreGetMapURI );
111 mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
112 mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
113 mGroupBox->layout()->removeWidget( cbxSmoothPixmapTransform );
116 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
117 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
119 cmbDpiMode->setVisible(
false );
120 mGroupBox->layout()->removeWidget( cmbDpiMode );
121 lblDpiMode->setVisible(
false );
122 mGroupBox->layout()->removeWidget( lblDpiMode );
124 txtReferer->setVisible(
false );
125 mGroupBox->layout()->removeWidget( txtReferer );
126 lblReferer->setVisible(
false );
127 mGroupBox->layout()->removeWidget( lblReferer );
132 resize( w, height() );
145 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
151 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
157 QString key = mBaseKey + txtName->text();
158 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
"/" + txtName->text();
161 if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
162 settings.contains( key +
"/url" ) &&
163 QMessageBox::question(
this,
164 tr(
"Save connection" ),
165 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
166 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
171 if ( !txtPassword->text().isEmpty() &&
172 QMessageBox::question(
this,
173 tr(
"Saving passwords" ),
174 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." ),
175 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
181 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
183 settings.remove( mBaseKey + mOriginalConnName );
184 settings.remove(
"/Qgis/" + mCredentialsBaseKey +
"/" + mOriginalConnName );
187 QUrl url( txtUrl->text().trimmed() );
188 const QList< QPair<QByteArray, QByteArray> > &items = url.encodedQueryItems();
189 QHash< QString, QPair<QByteArray, QByteArray> > params;
190 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
192 params.insert( QString( it->first ).toUpper(), *it );
195 if ( params[
"SERVICE"].second.toUpper() ==
"WMS" ||
196 params[
"SERVICE"].second.toUpper() ==
"WFS" ||
197 params[
"SERVICE"].second.toUpper() ==
"WCS" )
199 url.removeEncodedQueryItem( params[
"SERVICE"].first );
200 url.removeEncodedQueryItem( params[
"REQUEST"].first );
201 url.removeEncodedQueryItem( params[
"FORMAT"].first );
204 if ( url.encodedPath().isEmpty() )
206 url.setEncodedPath(
"/" );
209 settings.setValue( key +
"/url", url.toString() );
210 if ( mBaseKey ==
"/Qgis/connections-wms/" || mBaseKey ==
"/Qgis/connections-wcs/" )
212 settings.setValue( key +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
213 settings.setValue( key +
"/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
214 settings.setValue( key +
"/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
215 settings.setValue( key +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
218 switch ( cmbDpiMode->currentIndex() )
237 settings.setValue( key +
"/dpiMode", dpiMode );
239 if ( mBaseKey ==
"/Qgis/connections-wms/" )
241 settings.setValue( key +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
244 settings.setValue( key +
"/referer", txtReferer->text() );
246 settings.setValue( credentialsKey +
"/username", txtUserName->text() );
247 settings.setValue( credentialsKey +
"/password", txtPassword->text() );
249 settings.setValue( mBaseKey +
"/selected", txtName->text() );