16
16
***************************************************************************/
17
17
18
18
#include < QMessageBox>
19
- #include < QUrl>
20
- #include " qgslogger.h"
21
-
22
19
#include " qgsgeonodenewconnection.h"
23
- #include " qgsauthmanager.h"
24
- #include " qgsdatasourceuri.h"
25
20
#include " qgsgeonodeconnection.h"
26
- #include " qgssettings.h"
27
21
#include " qgsgeonoderequest.h"
28
22
29
23
QgsGeoNodeNewConnection::QgsGeoNodeNewConnection ( QWidget *parent, const QString &connName, Qt::WindowFlags fl )
30
- : QDialog( parent, fl )
31
- , mOriginalConnName( connName )
32
- , mAuthConfigSelect( nullptr )
24
+ : QgsNewHttpConnection( parent, 0 , QgsGeoNodeConnectionUtils::pathGeoNodeConnection(), connName, QgsNewHttpConnection::FlagShowTestConnection, fl )
33
25
{
34
- setupUi ( this );
35
-
36
- mBaseKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnection ();
37
- mCredentialsBaseKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnection ();
38
-
39
- mAuthConfigSelect = new QgsAuthConfigSelect ( this );
40
- tabAuth->insertTab ( 1 , mAuthConfigSelect , tr ( " Configurations" ) );
41
-
42
- cmbDpiMode->clear ();
43
- cmbDpiMode->addItem ( tr ( " all" ) );
44
- cmbDpiMode->addItem ( tr ( " off" ) );
45
- cmbDpiMode->addItem ( tr ( " QGIS" ) );
46
- cmbDpiMode->addItem ( tr ( " UMN" ) );
47
- cmbDpiMode->addItem ( tr ( " GeoServer" ) );
48
-
49
- cmbVersion->clear ();
50
- cmbVersion->addItem ( tr ( " Auto-detect" ) );
51
- cmbVersion->addItem ( tr ( " 1.0" ) );
52
- cmbVersion->addItem ( tr ( " 1.1" ) );
53
- cmbVersion->addItem ( tr ( " 2.0" ) );
54
-
55
- if ( !connName.isEmpty () )
56
- {
57
- // populate the dialog with the information stored for the connection
58
- // populate the fields with the stored setting parameters
59
- QgsSettings settings;
60
-
61
- QString key = mBaseKey + ' /' + connName;
62
- QString credentialsKey = mCredentialsBaseKey + ' /' + connName;
63
- txtName->setText ( connName );
64
- txtUrl->setText ( settings.value ( key + " /url" , " " , QgsSettings::Providers ).toString () );
65
-
66
- cbxIgnoreGetMapURI->setChecked ( settings.value ( key + " /wms/ignoreGetMapURI" , false , QgsSettings::Providers ).toBool () );
67
- cbxWfsIgnoreAxisOrientation->setChecked ( settings.value ( key + " /wfs/ignoreAxisOrientation" , false , QgsSettings::Providers ).toBool () );
68
- cbxWmsIgnoreAxisOrientation->setChecked ( settings.value ( key + " /wms/ignoreAxisOrientation" , false , QgsSettings::Providers ).toBool () );
69
- cbxWfsInvertAxisOrientation->setChecked ( settings.value ( key + " /wfs/invertAxisOrientation" , false , QgsSettings::Providers ).toBool () );
70
- cbxWmsInvertAxisOrientation->setChecked ( settings.value ( key + " /wms/invertAxisOrientation" , false , QgsSettings::Providers ).toBool () );
71
- cbxIgnoreGetFeatureInfoURI->setChecked ( settings.value ( key + " /wms/ignoreGetFeatureInfoURI" , false , QgsSettings::Providers ).toBool () );
72
- cbxSmoothPixmapTransform->setChecked ( settings.value ( key + " /wms/smoothPixmapTransform" , false , QgsSettings::Providers ).toBool () );
73
-
74
- int dpiIdx;
75
- switch ( settings.value ( key + " /dpiMode" , 7 , QgsSettings::Providers ).toInt () )
76
- {
77
- case 0 : // off
78
- dpiIdx = 1 ;
79
- break ;
80
- case 1 : // QGIS
81
- dpiIdx = 2 ;
82
- break ;
83
- case 2 : // UMN
84
- dpiIdx = 3 ;
85
- break ;
86
- case 4 : // GeoServer
87
- dpiIdx = 4 ;
88
- break ;
89
- default : // other => all
90
- dpiIdx = 0 ;
91
- break ;
92
- }
93
- cmbDpiMode->setCurrentIndex ( dpiIdx );
94
-
95
- QString version = settings.value ( key + " /version" , QLatin1String ( " 1.0.0" ), QgsSettings::Providers ).toString ();
96
- int versionIdx = 0 ; // AUTO
97
- if ( version == QLatin1String ( " 1.0.0" ) )
98
- versionIdx = 1 ;
99
- else if ( version == QLatin1String ( " 1.1.0" ) )
100
- versionIdx = 2 ;
101
- else if ( version == QLatin1String ( " 2.0.0" ) )
102
- versionIdx = 3 ;
103
- cmbVersion->setCurrentIndex ( versionIdx );
104
-
105
- txtReferer->setText ( settings.value ( key + " /referer" , " " , QgsSettings::Providers ).toString () );
106
- txtMaxNumFeatures->setText ( settings.value ( key + " /maxnumfeatures" , QgsSettings::Providers ).toString () );
107
-
108
- txtUserName->setText ( settings.value ( credentialsKey + " /username" , " " , QgsSettings::Providers ).toString () );
109
- txtPassword->setText ( settings.value ( credentialsKey + " /password" , " " , QgsSettings::Providers ).toString () );
110
-
111
- QString authcfg = settings.value ( credentialsKey + " /authcfg" , " " , QgsSettings::Providers ).toString ();
112
- mAuthConfigSelect ->setConfigId ( authcfg );
113
- if ( !authcfg.isEmpty () )
114
- {
115
- tabAuth->setCurrentIndex ( tabAuth->indexOf ( mAuthConfigSelect ) );
116
- }
117
- }
26
+ setWindowTitle ( tr ( " Create a New GeoNode Connection" ) );
118
27
119
- // Adjust height
120
- int w = width ();
121
- adjustSize ();
122
- resize ( w, height () );
123
-
124
- buttonBox->button ( QDialogButtonBox::Ok )->setDisabled ( true );
125
- connect ( txtName, &QLineEdit::textChanged, this , &QgsGeoNodeNewConnection::okButtonBehavior );
126
- connect ( txtUrl, &QLineEdit::textChanged, this , &QgsGeoNodeNewConnection::okButtonBehavior );
127
- connect ( btnConnect, &QPushButton::clicked, this , &QgsGeoNodeNewConnection::testConnection );
128
- }
129
-
130
- QString QgsGeoNodeNewConnection::name () const
131
- {
132
- return txtName->text ();
133
- }
134
-
135
- void QgsGeoNodeNewConnection::accept ()
136
- {
137
- QgsSettings settings;
138
- QString key = mBaseKey + ' /' + txtName->text ();
139
- QString credentialsKey = mCredentialsBaseKey + ' /' + txtName->text ();
140
-
141
- // warn if entry was renamed to an existing connection
142
- if ( ( mOriginalConnName .isNull () || mOriginalConnName .compare ( txtName->text (), Qt::CaseInsensitive ) != 0 ) &&
143
- settings.contains ( key + " /url" , QgsSettings::Providers ) &&
144
- QMessageBox::question ( this ,
145
- tr ( " Save connection" ),
146
- tr ( " Should the existing connection %1 be overwritten?" ).arg ( txtName->text () ),
147
- QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
148
- {
149
- return ;
150
- }
151
-
152
- if ( !txtPassword->text ().isEmpty () &&
153
- QMessageBox::question ( this ,
154
- tr ( " Saving passwords" ),
155
- trUtf8 ( " WARNING: You have entered a password. It will be stored in unsecured plain text in your project files and your home directory (Unix-like OS) or user profile (Windows). If you want to avoid this, press Cancel and either:\n\n a) Don't provide a password in the connection settings — it will be requested interactively when needed;\n b) Use the Configuration tab to add your credentials in an HTTP Basic Authentication method and store them in an encrypted database." ),
156
- QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
157
- {
158
- return ;
159
- }
160
-
161
- // on rename delete original entry first
162
- if ( !mOriginalConnName .isNull () && mOriginalConnName != key )
163
- {
164
- // Manually add Section here
165
- settings.remove ( " providers/" + mBaseKey + ' /' + mOriginalConnName );
166
- settings.remove ( " providers/qgis//" + mCredentialsBaseKey + ' /' + mOriginalConnName );
167
- settings.sync ();
168
- }
169
-
170
- if ( !txtUrl->text ().contains ( " ://" ) &&
171
- QMessageBox::information (
172
- this ,
173
- tr ( " Invalid URL" ),
174
- tr ( " Your URL doesn't contains protocol (e.g. http or https). Please add the protocol." ) ) == QMessageBox::Ok )
175
- {
176
- return ;
177
- }
178
- QUrl url ( txtUrl->text () );
179
-
180
- settings.setValue ( key + " /url" , url.toString (), QgsSettings::Providers );
181
-
182
- settings.setValue ( key + " /wfs/ignoreAxisOrientation" , cbxWfsIgnoreAxisOrientation->isChecked (), QgsSettings::Providers );
183
- settings.setValue ( key + " /wms/ignoreAxisOrientation" , cbxWmsIgnoreAxisOrientation->isChecked (), QgsSettings::Providers );
184
- settings.setValue ( key + " /wfs/invertAxisOrientation" , cbxWfsInvertAxisOrientation->isChecked (), QgsSettings::Providers );
185
- settings.setValue ( key + " /wms/invertAxisOrientation" , cbxWmsInvertAxisOrientation->isChecked (), QgsSettings::Providers );
186
-
187
- settings.setValue ( key + " /wms/ignoreGetMapURI" , cbxIgnoreGetMapURI->isChecked (), QgsSettings::Providers );
188
- settings.setValue ( key + " /wms/smoothPixmapTransform" , cbxSmoothPixmapTransform->isChecked (), QgsSettings::Providers );
189
- settings.setValue ( key + " /wms/ignoreGetFeatureInfoURI" , cbxIgnoreGetFeatureInfoURI->isChecked (), QgsSettings::Providers );
190
-
191
- int dpiMode = 0 ;
192
- switch ( cmbDpiMode->currentIndex () )
193
- {
194
- case 0 : // all => QGIS|UMN|GeoServer
195
- dpiMode = 7 ;
196
- break ;
197
- case 1 : // off
198
- dpiMode = 0 ;
199
- break ;
200
- case 2 : // QGIS
201
- dpiMode = 1 ;
202
- break ;
203
- case 3 : // UMN
204
- dpiMode = 2 ;
205
- break ;
206
- case 4 : // GeoServer
207
- dpiMode = 4 ;
208
- break ;
209
- }
210
-
211
- settings.setValue ( key + " /wms/dpiMode" , dpiMode, QgsSettings::Providers );
212
- settings.setValue ( key + " /wms/referer" , txtReferer->text (), QgsSettings::Providers );
213
-
214
- QString version = QStringLiteral ( " auto" );
215
- switch ( cmbVersion->currentIndex () )
216
- {
217
- case 0 :
218
- version = QStringLiteral ( " auto" );
219
- break ;
220
- case 1 :
221
- version = QStringLiteral ( " 1.0.0" );
222
- break ;
223
- case 2 :
224
- version = QStringLiteral ( " 1.1.0" );
225
- break ;
226
- case 3 :
227
- version = QStringLiteral ( " 2.0.0" );
228
- break ;
229
- }
230
-
231
- settings.setValue ( key + " /wfs/version" , version, QgsSettings::Providers );
232
- settings.setValue ( key + " /wfs/maxnumfeatures" , txtMaxNumFeatures->text (), QgsSettings::Providers );
233
-
234
- settings.setValue ( credentialsKey + " /username" , txtUserName->text (), QgsSettings::Providers );
235
- settings.setValue ( credentialsKey + " /password" , txtPassword->text (), QgsSettings::Providers );
236
-
237
- settings.setValue ( credentialsKey + " /authcfg" , mAuthConfigSelect ->configId (), QgsSettings::Providers );
238
-
239
- settings.setValue ( mBaseKey + " /selected" , txtName->text (), QgsSettings::Providers );
240
-
241
- QDialog::accept ();
242
- }
243
-
244
- void QgsGeoNodeNewConnection::okButtonBehavior ( const QString &text )
245
- {
246
- Q_UNUSED ( text );
247
- buttonBox->button ( QDialogButtonBox::Ok )->setDisabled ( txtName->text ().isEmpty () || txtUrl->text ().isEmpty () );
248
- buttonBox->button ( QDialogButtonBox::Ok )->setEnabled ( !txtName->text ().isEmpty () && !txtUrl->text ().isEmpty () );
28
+ connect ( testConnectButton (), &QPushButton::clicked, this , &QgsGeoNodeNewConnection::testConnection );
249
29
}
250
30
251
31
void QgsGeoNodeNewConnection::testConnection ()
252
32
{
253
33
QApplication::setOverrideCursor ( Qt::BusyCursor );
254
- QString url = txtUrl->text ();
255
- QgsGeoNodeRequest geonodeRequest ( url, true );
34
+ QgsGeoNodeRequest geonodeRequest ( url (), true );
256
35
257
36
QList<QgsGeoNodeRequest::ServiceLayerDetail> layers = geonodeRequest.fetchLayersBlocking ();
258
37
QApplication::restoreOverrideCursor ();
@@ -261,12 +40,25 @@ void QgsGeoNodeNewConnection::testConnection()
261
40
{
262
41
QMessageBox::information ( this ,
263
42
tr ( " Test connection" ),
264
- tr ( " \n Connection to %1 was successful, \n\n %1 is a valid geonode instance.\n\n " ).arg ( txtUrl-> text () ) );
43
+ tr ( " \n Connection to %1 was successful, \n\n %1 is a valid geonode instance.\n\n " ).arg ( url () ) );
265
44
}
266
45
else
267
46
{
268
47
QMessageBox::information ( this ,
269
48
tr ( " Test connection" ),
270
- tr ( " \n Connection failed, \n\n please check whether %1 is a valid geonode instance.\n\n " ).arg ( txtUrl->text () ) );
49
+ tr ( " \n Connection failed, \n\n please check whether %1 is a valid geonode instance.\n\n " ).arg ( url () ) );
50
+ }
51
+ }
52
+
53
+ bool QgsGeoNodeNewConnection::validate ()
54
+ {
55
+ if ( !url ().contains ( " ://" ) )
56
+ {
57
+ QMessageBox::warning (
58
+ this ,
59
+ tr ( " Invalid URL" ),
60
+ tr ( " Your URL doesn't contain a protocol (e.g. http or https). Please add the protocol." ) );
61
+ return false ;
271
62
}
63
+ return QgsNewHttpConnection::validate ();
272
64
}
0 commit comments