QGIS API Documentation 3.43.0-Master (3ee7834ace6)
qgsmanageconnectionsdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmanageconnectionsdialog.cpp
3 ---------------------
4 begin : Dec 2009
5 copyright : (C) 2009 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include <QCloseEvent>
18#include <QFileDialog>
19#include <QMessageBox>
20#include <QPushButton>
21#include <QTextStream>
22
23#include "qgssettings.h"
25#include "moc_qgsmanageconnectionsdialog.cpp"
26#include "qgshttpheaders.h"
27#include "qgsowsconnection.h"
33#include "qgsgdalcloudconnection.h"
34#include "qgsstacconnection.h"
35
36QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type, const QString &fileName )
37 : QDialog( parent )
38 , mFileName( fileName )
39 , mDialogMode( mode )
40 , mConnectionType( type )
41{
42 setupUi( this );
43
44 // additional buttons
45 QPushButton *pb = nullptr;
46 pb = new QPushButton( tr( "Select All" ) );
47 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
48 connect( pb, &QAbstractButton::clicked, this, &QgsManageConnectionsDialog::selectAll );
49
50 pb = new QPushButton( tr( "Clear Selection" ) );
51 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
52 connect( pb, &QAbstractButton::clicked, this, &QgsManageConnectionsDialog::clearSelection );
53
54 if ( mDialogMode == Import )
55 {
56 label->setText( tr( "Select connections to import" ) );
57 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) );
58 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
59 }
60 else
61 {
62 //label->setText( tr( "Select connections to export" ) );
63 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Export" ) );
64 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
65 }
66
67 if ( !populateConnections() )
68 {
69 QApplication::postEvent( this, new QCloseEvent() );
70 }
71
72 // use OK button for starting import and export operations
73 disconnect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
74 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsManageConnectionsDialog::doExportImport );
75
76 connect( listConnections, &QListWidget::itemSelectionChanged, this, &QgsManageConnectionsDialog::selectionChanged );
77}
78
80{
81 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
82}
83
85{
86 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
87 if ( selection.isEmpty() )
88 {
89 QMessageBox::warning( this, tr( "Export/Import Error" ), tr( "You should select at least one connection from list." ) );
90 return;
91 }
92
93 QStringList items;
94 items.reserve( selection.size() );
95 for ( int i = 0; i < selection.size(); ++i )
96 {
97 items.append( selection.at( i )->text() );
98 }
99
100 if ( mDialogMode == Export )
101 {
102 QString fileName = QFileDialog::getSaveFileName( this, tr( "Save Connections" ), QDir::homePath(), tr( "XML files (*.xml *.XML)" ) );
103 // return dialog focus on Mac
104 activateWindow();
105 raise();
106 if ( fileName.isEmpty() )
107 {
108 return;
109 }
110
111 // ensure the user never omitted the extension from the file name
112 if ( !fileName.endsWith( QLatin1String( ".xml" ), Qt::CaseInsensitive ) )
113 {
114 fileName += QLatin1String( ".xml" );
115 }
116
117 mFileName = fileName;
118
119 QDomDocument doc;
120 switch ( mConnectionType )
121 {
122 case WMS:
123 doc = saveOWSConnections( items, QStringLiteral( "WMS" ) );
124 break;
125 case WFS:
126 doc = saveWfsConnections( items );
127 break;
128 case PostGIS:
129 doc = savePgConnections( items );
130 break;
131 case MSSQL:
132 doc = saveMssqlConnections( items );
133 break;
134 case WCS:
135 doc = saveOWSConnections( items, QStringLiteral( "WCS" ) );
136 break;
137 case Oracle:
138 doc = saveOracleConnections( items );
139 break;
140 case HANA:
141 doc = saveHanaConnections( items );
142 break;
143 case XyzTiles:
144 doc = saveXyzTilesConnections( items );
145 break;
146 case ArcgisMapServer:
148 doc = saveArcgisConnections( items );
149 break;
150 case VectorTile:
151 doc = saveVectorTileConnections( items );
152 break;
153 case TiledScene:
154 doc = saveTiledSceneConnections( items );
155 break;
156 case SensorThings:
157 doc = saveSensorThingsConnections( items );
158 break;
159 case CloudStorage:
160 doc = saveCloudStorageConnections( items );
161 break;
162 case STAC:
163 doc = saveStacConnections( items );
164 break;
165 }
166
167 QFile file( mFileName );
168 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
169 {
170 QMessageBox::warning( this, tr( "Saving Connections" ), tr( "Cannot write file %1:\n%2." ).arg( mFileName, file.errorString() ) );
171 return;
172 }
173
174 QTextStream out( &file );
175 doc.save( out, 4 );
176 }
177 else // import connections
178 {
179 QFile file( mFileName );
180 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
181 {
182 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
183 return;
184 }
185
186 QDomDocument doc;
187 QString errorStr;
188 int errorLine;
189 int errorColumn;
190
191 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
192 {
193 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
194 return;
195 }
196
197 switch ( mConnectionType )
198 {
199 case WMS:
200 loadOWSConnections( doc, items, QStringLiteral( "WMS" ) );
201 break;
202 case WFS:
203 loadWfsConnections( doc, items );
204 break;
205 case PostGIS:
206 loadPgConnections( doc, items );
207 break;
208 case MSSQL:
209 loadMssqlConnections( doc, items );
210 break;
211 case WCS:
212 loadOWSConnections( doc, items, QStringLiteral( "WCS" ) );
213 break;
214 case Oracle:
215 loadOracleConnections( doc, items );
216 break;
217 case HANA:
218 loadHanaConnections( doc, items );
219 break;
220 case XyzTiles:
221 loadXyzTilesConnections( doc, items );
222 break;
223 case ArcgisMapServer:
224 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISMAPSERVER" ) );
225 break;
227 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISFEATURESERVER" ) );
228 break;
229 case VectorTile:
230 loadVectorTileConnections( doc, items );
231 break;
232 case TiledScene:
233 loadTiledSceneConnections( doc, items );
234 break;
235 case SensorThings:
236 loadSensorThingsConnections( doc, items );
237 break;
238 case CloudStorage:
239 loadCloudStorageConnections( doc, items );
240 break;
241 case STAC:
242 loadStacConnections( doc, items );
243 break;
244 }
245 // clear connections list and close window
246 listConnections->clear();
247 accept();
248 }
249
250 mFileName.clear();
251}
252
253bool QgsManageConnectionsDialog::populateConnections()
254{
255 // Export mode. Populate connections list from settings
256 if ( mDialogMode == Export )
257 {
258 QStringList connections;
259 QgsSettings settings;
260 switch ( mConnectionType )
261 {
262 case WMS:
263 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wms" ) } );
264 break;
265 case WFS:
266 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wfs" ) } );
267 break;
268 case WCS:
269 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wcs" ) } );
270 break;
271 case PostGIS:
272 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
273 connections = settings.childGroups();
274 break;
275 case MSSQL:
276 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
277 connections = settings.childGroups();
278 break;
279 case Oracle:
280 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
281 connections = settings.childGroups();
282 break;
283 case HANA:
284 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
285 connections = settings.childGroups();
286 break;
287 case XyzTiles:
289 break;
290 case ArcgisMapServer:
293 break;
294 case VectorTile:
295 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
296 break;
297 case TiledScene:
298 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
299 break;
300 case SensorThings:
301 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
302 break;
303 case CloudStorage:
304 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
305 break;
306 case STAC:
307 connections = QgsStacConnection::sTreeConnectionStac->items();
308 break;
309 }
310 for ( const QString &connection : std::as_const( connections ) )
311 {
312 QListWidgetItem *item = new QListWidgetItem();
313 item->setText( connection );
314 listConnections->addItem( item );
315 }
316 }
317 // Import mode. Populate connections list from file
318 else
319 {
320 QFile file( mFileName );
321 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
322 {
323 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
324 return false;
325 }
326
327 QDomDocument doc;
328 QString errorStr;
329 int errorLine;
330 int errorColumn;
331
332 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
333 {
334 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
335 return false;
336 }
337
338 const QDomElement root = doc.documentElement();
339 switch ( mConnectionType )
340 {
341 case WMS:
342 if ( root.tagName() != QLatin1String( "qgsWMSConnections" ) )
343 {
344 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WMS connections exchange file." ) );
345 return false;
346 }
347 break;
348
349 case WFS:
350 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
351 {
352 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
353 return false;
354 }
355 break;
356
357 case WCS:
358 if ( root.tagName() != QLatin1String( "qgsWCSConnections" ) )
359 {
360 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WCS connections exchange file." ) );
361 return false;
362 }
363 break;
364
365 case PostGIS:
366 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
367 {
368 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
369 return false;
370 }
371 break;
372
373 case MSSQL:
374 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
375 {
376 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
377 return false;
378 }
379 break;
380 case Oracle:
381 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
382 {
383 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
384 return false;
385 }
386 break;
387 case HANA:
388 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
389 {
390 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
391 return false;
392 }
393 break;
394 case XyzTiles:
395 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
396 {
397 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
398 return false;
399 }
400 break;
401 case ArcgisMapServer:
402 if ( root.tagName() != QLatin1String( "qgsARCGISMAPSERVERConnections" ) )
403 {
404 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a ArcGIS Map Service connections exchange file." ) );
405 return false;
406 }
407 break;
409 if ( root.tagName() != QLatin1String( "qgsARCGISFEATURESERVERConnections" ) )
410 {
411 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a ArcGIS Feature Service connections exchange file." ) );
412 return false;
413 }
414 break;
415 case VectorTile:
416 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
417 {
418 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
419 return false;
420 }
421 break;
422 case TiledScene:
423 if ( root.tagName() != QLatin1String( "qgsTiledSceneConnections" ) )
424 {
425 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
426 return false;
427 }
428 break;
429 case SensorThings:
430 if ( root.tagName() != QLatin1String( "qgsSensorThingsConnections" ) )
431 {
432 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
433 return false;
434 }
435 break;
436 case CloudStorage:
437 if ( root.tagName() != QLatin1String( "qgsCloudStorageConnections" ) )
438 {
439 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
440 return false;
441 }
442 break;
443 case STAC:
444 if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
445 {
446 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
447 return false;
448 }
449 break;
450 }
451
452 QDomElement child = root.firstChildElement();
453 while ( !child.isNull() )
454 {
455 QListWidgetItem *item = new QListWidgetItem();
456 item->setText( child.attribute( QStringLiteral( "name" ) ) );
457 listConnections->addItem( item );
458 child = child.nextSiblingElement();
459 }
460 }
461 return true;
462}
463
464static void addNamespaceDeclarations( QDomElement &root, const QMap<QString, QString> &namespaceDeclarations )
465{
466 for ( auto it = namespaceDeclarations.begin(); it != namespaceDeclarations.end(); ++it )
467 {
468 root.setAttribute( QStringLiteral( "xmlns:" ) + it.key(), it.value() );
469 }
470}
471
472QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &connections, const QString &service )
473{
474 QDomDocument doc( QStringLiteral( "connections" ) );
475 QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" );
476 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
477 doc.appendChild( root );
478
479 QMap<QString, QString> namespaceDeclarations;
480 for ( int i = 0; i < connections.count(); ++i )
481 {
482 QDomElement el = doc.createElement( service.toLower() );
483 el.setAttribute( QStringLiteral( "name" ), connections[i] );
484 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { service.toLower(), connections[i] } ) );
485
486 if ( service == QLatin1String( "WMS" ) )
487 {
488 el.setAttribute( QStringLiteral( "ignoreGetMapURI" ), QgsOwsConnection::settingsIgnoreGetMapURI->value( { service.toLower(), connections[i] } ) );
489 el.setAttribute( QStringLiteral( "ignoreGetFeatureInfoURI" ), QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->value( { service.toLower(), connections[i] } ) );
490 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { service.toLower(), connections[i] } ) );
491 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { service.toLower(), connections[i] } ) );
492 el.setAttribute( QStringLiteral( "smoothPixmapTransform" ), QgsOwsConnection::settingsSmoothPixmapTransform->value( { service.toLower(), connections[i] } ) );
493 el.setAttribute( QStringLiteral( "dpiMode" ), static_cast<int>( QgsOwsConnection::settingsDpiMode->value( { service.toLower(), connections[i] } ) ) );
494
495 QgsHttpHeaders httpHeader( QgsOwsConnection::settingsHeaders->value( { service.toLower(), connections[i] } ) );
496 httpHeader.updateDomElement( el, namespaceDeclarations );
497 }
498
499 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { service.toLower(), connections[i] } ) );
500 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { service.toLower(), connections[i] } ) );
501 root.appendChild( el );
502 }
503
504 addNamespaceDeclarations( root, namespaceDeclarations );
505
506 return doc;
507}
508
509QDomDocument QgsManageConnectionsDialog::saveWfsConnections( const QStringList &connections )
510{
511 QDomDocument doc( QStringLiteral( "connections" ) );
512 QDomElement root = doc.createElement( QStringLiteral( "qgsWFSConnections" ) );
513 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1" ) );
514 doc.appendChild( root );
515
516 for ( int i = 0; i < connections.count(); ++i )
517 {
518 QDomElement el = doc.createElement( QStringLiteral( "wfs" ) );
519 el.setAttribute( QStringLiteral( "name" ), connections[i] );
520 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { QStringLiteral( "wfs" ), connections[i] } ) );
521
522 el.setAttribute( QStringLiteral( "version" ), QgsOwsConnection::settingsVersion->value( { QStringLiteral( "wfs" ), connections[i] } ) );
523 el.setAttribute( QStringLiteral( "maxnumfeatures" ), QgsOwsConnection::settingsMaxNumFeatures->value( { QStringLiteral( "wfs" ), connections[i] } ) );
524 el.setAttribute( QStringLiteral( "pagesize" ), QgsOwsConnection::settingsPagesize->value( { QStringLiteral( "wfs" ), connections[i] } ) );
525 el.setAttribute( QStringLiteral( "pagingenabled" ), QgsOwsConnection::settingsPagingEnabled->value( { QStringLiteral( "wfs" ), connections[i] } ) );
526 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
527 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
528 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { QStringLiteral( "wfs" ), connections[i] } ) );
529 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { QStringLiteral( "wfs" ), connections[i] } ) );
530 el.setAttribute( QStringLiteral( "httpMethod" ), QgsOwsConnection::settingsPreferredHttpMethod->value( { QStringLiteral( "wfs" ), connections[i] } ) == Qgis::HttpMethod::Post ? QStringLiteral( "post" ) : QStringLiteral( "get" ) );
531 root.appendChild( el );
532 }
533
534 return doc;
535}
536
537QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
538{
539 QDomDocument doc( QStringLiteral( "connections" ) );
540 QDomElement root = doc.createElement( QStringLiteral( "qgsPgConnections" ) );
541 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
542 doc.appendChild( root );
543
544 const QgsSettings settings;
545 QString path;
546 for ( int i = 0; i < connections.count(); ++i )
547 {
548 path = "/PostgreSQL/connections/" + connections[i];
549 QDomElement el = doc.createElement( QStringLiteral( "postgis" ) );
550 el.setAttribute( QStringLiteral( "name" ), connections[i] );
551 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
552 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
553 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
554 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
555 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
556 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
557 el.setAttribute( QStringLiteral( "projectsInDatabase" ), settings.value( path + "/projectsInDatabase", "0" ).toString() );
558 el.setAttribute( QStringLiteral( "dontResolveType" ), settings.value( path + "/dontResolveType", "0" ).toString() );
559 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
560 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
561 el.setAttribute( QStringLiteral( "publicOnly" ), settings.value( path + "/publicOnly", "0" ).toString() );
562
563 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
564
565 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
566 {
567 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
568 }
569
570 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
571
572 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
573 {
574 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
575 }
576
577 root.appendChild( el );
578 }
579
580 return doc;
581}
582
583QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
584{
585 QDomDocument doc( QStringLiteral( "connections" ) );
586 QDomElement root = doc.createElement( QStringLiteral( "qgsMssqlConnections" ) );
587 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
588 doc.appendChild( root );
589
590 const QgsSettings settings;
591 QString path;
592 for ( int i = 0; i < connections.count(); ++i )
593 {
594 path = "/MSSQL/connections/" + connections[i];
595 QDomElement el = doc.createElement( QStringLiteral( "mssql" ) );
596 el.setAttribute( QStringLiteral( "name" ), connections[i] );
597 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
598 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
599 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
600 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
601 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
602 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
603
604 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
605
606 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
607 {
608 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
609 }
610
611 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
612
613 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
614 {
615 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
616 }
617
618 root.appendChild( el );
619 }
620
621 return doc;
622}
623
624QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections )
625{
626 QDomDocument doc( QStringLiteral( "connections" ) );
627 QDomElement root = doc.createElement( QStringLiteral( "qgsOracleConnections" ) );
628 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
629 doc.appendChild( root );
630
631 const QgsSettings settings;
632 QString path;
633 for ( int i = 0; i < connections.count(); ++i )
634 {
635 path = "/Oracle/connections/" + connections[i];
636 QDomElement el = doc.createElement( QStringLiteral( "oracle" ) );
637 el.setAttribute( QStringLiteral( "name" ), connections[i] );
638 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
639 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
640 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
641 el.setAttribute( QStringLiteral( "dboptions" ), settings.value( path + "/dboptions" ).toString() );
642 el.setAttribute( QStringLiteral( "dbworkspace" ), settings.value( path + "/dbworkspace" ).toString() );
643 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
644 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
645 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", "0" ).toString() );
646 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
647 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
648
649 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
650
651 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
652 {
653 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
654 }
655
656 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
657
658 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
659 {
660 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
661 }
662
663 root.appendChild( el );
664 }
665
666 return doc;
667}
668
669QDomDocument QgsManageConnectionsDialog::saveHanaConnections( const QStringList &connections )
670{
671 QDomDocument doc( QStringLiteral( "connections" ) );
672 QDomElement root = doc.createElement( QStringLiteral( "qgsHanaConnections" ) );
673 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
674 doc.appendChild( root );
675
676 const QgsSettings settings;
677 QString path;
678 for ( int i = 0; i < connections.count(); ++i )
679 {
680 path = "/HANA/connections/" + connections[i];
681 QDomElement el = doc.createElement( QStringLiteral( "hana" ) );
682 el.setAttribute( QStringLiteral( "name" ), connections[i] );
683 el.setAttribute( QStringLiteral( "driver" ), settings.value( path + "/driver", QString() ).toString() );
684 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host", QString() ).toString() );
685 el.setAttribute( QStringLiteral( "identifierType" ), settings.value( path + "/identifierType", QString() ).toString() );
686 el.setAttribute( QStringLiteral( "identifier" ), settings.value( path + "/identifier", QString() ).toString() );
687 el.setAttribute( QStringLiteral( "multitenant" ), settings.value( path + "/multitenant", QString() ).toString() );
688 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database", QString() ).toString() );
689 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema", QString() ).toString() );
690 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", QStringLiteral( "0" ) ).toString() );
691 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", QStringLiteral( "0" ) ).toString() );
692
693 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", QStringLiteral( "false" ) ).toString() );
694 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
695 {
696 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", QString() ).toString() );
697 }
698
699 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", QStringLiteral( "false" ) ).toString() );
700 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
701 {
702 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", QString() ).toString() );
703 }
704
705 el.setAttribute( QStringLiteral( "sslEnabled" ), settings.value( path + "/sslEnabled", QStringLiteral( "false" ) ).toString() );
706 el.setAttribute( QStringLiteral( "sslCryptoProvider" ), settings.value( path + "/sslCryptoProvider", QStringLiteral( "openssl" ) ).toString() );
707 el.setAttribute( QStringLiteral( "sslKeyStore" ), settings.value( path + "/sslKeyStore", QString() ).toString() );
708 el.setAttribute( QStringLiteral( "sslTrustStore" ), settings.value( path + "/sslTrustStore", QString() ).toString() );
709 el.setAttribute( QStringLiteral( "sslValidateCertificate" ), settings.value( path + "/sslValidateCertificate", QStringLiteral( "false" ) ).toString() );
710 el.setAttribute( QStringLiteral( "sslHostNameInCertificate" ), settings.value( path + "/sslHostNameInCertificate", QString() ).toString() );
711
712 root.appendChild( el );
713 }
714
715 return doc;
716}
717
718QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
719{
720 QDomDocument doc( QStringLiteral( "connections" ) );
721 QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
722 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
723 doc.appendChild( root );
724
725 QMap<QString, QString> namespaceDeclarations;
726 for ( int i = 0; i < connections.count(); ++i )
727 {
728 QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
729
730 el.setAttribute( QStringLiteral( "name" ), connections[i] );
731 el.setAttribute( QStringLiteral( "url" ), QgsXyzConnectionSettings::settingsUrl->value( connections[i] ) );
732 el.setAttribute( QStringLiteral( "zmin" ), QgsXyzConnectionSettings::settingsZmin->value( connections[i] ) );
733 el.setAttribute( QStringLiteral( "zmax" ), QgsXyzConnectionSettings::settingsZmax->value( connections[i] ) );
734 el.setAttribute( QStringLiteral( "authcfg" ), QgsXyzConnectionSettings::settingsAuthcfg->value( connections[i] ) );
735 el.setAttribute( QStringLiteral( "username" ), QgsXyzConnectionSettings::settingsUsername->value( connections[i] ) );
736 el.setAttribute( QStringLiteral( "password" ), QgsXyzConnectionSettings::settingsPassword->value( connections[i] ) );
737 el.setAttribute( QStringLiteral( "tilePixelRatio" ), QgsXyzConnectionSettings::settingsTilePixelRatio->value( connections[i] ) );
738
739 QgsHttpHeaders httpHeader( QgsXyzConnectionSettings::settingsHeaders->value( connections[i] ) );
740 httpHeader.updateDomElement( el, namespaceDeclarations );
741
742 root.appendChild( el );
743 }
744
745 addNamespaceDeclarations( root, namespaceDeclarations );
746
747 return doc;
748}
749
750QDomDocument QgsManageConnectionsDialog::saveArcgisConnections( const QStringList &connections )
751{
752 QDomDocument doc( QStringLiteral( "connections" ) );
753 QDomElement root = doc.createElement( "qgsARCGISFEATURESERVERConnections" );
754 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
755 doc.appendChild( root );
756
757 QMap<QString, QString> namespaceDeclarations;
758 for ( const QString &connection : connections )
759 {
760 QDomElement el = doc.createElement( QStringLiteral( "arcgisfeatureserver" ) );
761 el.setAttribute( QStringLiteral( "name" ), connection );
762 el.setAttribute( QStringLiteral( "url" ), QgsArcGisConnectionSettings::settingsUrl->value( connection ) );
763
764 QgsHttpHeaders httpHeader( QgsArcGisConnectionSettings::settingsHeaders->value( connection ) );
765 httpHeader.updateDomElement( el, namespaceDeclarations );
766
767 el.setAttribute( QStringLiteral( "username" ), QgsArcGisConnectionSettings::settingsUsername->value( connection ) );
768 el.setAttribute( QStringLiteral( "password" ), QgsArcGisConnectionSettings::settingsPassword->value( connection ) );
769 el.setAttribute( QStringLiteral( "authcfg" ), QgsArcGisConnectionSettings::settingsAuthcfg->value( connection ) );
770
771 root.appendChild( el );
772 }
773
774 addNamespaceDeclarations( root, namespaceDeclarations );
775
776 return doc;
777}
778
779QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections( const QStringList &connections )
780{
781 QDomDocument doc( QStringLiteral( "connections" ) );
782 QDomElement root = doc.createElement( QStringLiteral( "qgsVectorTileConnections" ) );
783 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
784 doc.appendChild( root );
785
786 QMap<QString, QString> namespaceDeclarations;
787 for ( int i = 0; i < connections.count(); ++i )
788 {
789 QDomElement el = doc.createElement( QStringLiteral( "vectortile" ) );
790
791 el.setAttribute( QStringLiteral( "name" ), connections[i] );
792 el.setAttribute( QStringLiteral( "url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[i] ) );
793 el.setAttribute( QStringLiteral( "zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[i] ) );
794 el.setAttribute( QStringLiteral( "zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[i] ) );
795 el.setAttribute( QStringLiteral( "serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[i] ) );
796 el.setAttribute( QStringLiteral( "authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[i] ) );
797 el.setAttribute( QStringLiteral( "username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[i] ) );
798 el.setAttribute( QStringLiteral( "password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[i] ) );
799 el.setAttribute( QStringLiteral( "styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[i] ) );
800
801 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[i] ) );
802 httpHeader.updateDomElement( el, namespaceDeclarations );
803
804 root.appendChild( el );
805 }
806
807 addNamespaceDeclarations( root, namespaceDeclarations );
808
809 return doc;
810}
811
812QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections( const QStringList &connections )
813{
814 QDomDocument doc( QStringLiteral( "connections" ) );
815 QDomElement root = doc.createElement( QStringLiteral( "qgsTiledSceneConnections" ) );
816 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
817 doc.appendChild( root );
818
819 QMap<QString, QString> namespaceDeclarations;
820 for ( int i = 0; i < connections.count(); ++i )
821 {
822 QDomElement el = doc.createElement( QStringLiteral( "tiledscene" ) );
823
824 el.setAttribute( QStringLiteral( "name" ), connections[i] );
825 el.setAttribute( QStringLiteral( "provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[i] ) );
826 el.setAttribute( QStringLiteral( "url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[i] ) );
827 el.setAttribute( QStringLiteral( "authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[i] ) );
828 el.setAttribute( QStringLiteral( "username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[i] ) );
829 el.setAttribute( QStringLiteral( "password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[i] ) );
830
831 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
832 httpHeader.updateDomElement( el, namespaceDeclarations );
833
834 root.appendChild( el );
835 }
836
837 addNamespaceDeclarations( root, namespaceDeclarations );
838
839 return doc;
840}
841
842QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections( const QStringList &connections )
843{
844 QDomDocument doc( QStringLiteral( "connections" ) );
845 QDomElement root = doc.createElement( QStringLiteral( "qgsSensorThingsConnections" ) );
846 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
847 doc.appendChild( root );
848
849 QMap<QString, QString> namespaceDeclarations;
850 for ( int i = 0; i < connections.count(); ++i )
851 {
852 QDomElement el = doc.createElement( QStringLiteral( "sensorthings" ) );
853
854 el.setAttribute( QStringLiteral( "name" ), connections[i] );
855 el.setAttribute( QStringLiteral( "url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[i] ) );
856 el.setAttribute( QStringLiteral( "authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[i] ) );
857 el.setAttribute( QStringLiteral( "username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[i] ) );
858 el.setAttribute( QStringLiteral( "password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[i] ) );
859
860 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
861 httpHeader.updateDomElement( el, namespaceDeclarations );
862
863 root.appendChild( el );
864 }
865
866 addNamespaceDeclarations( root, namespaceDeclarations );
867
868 return doc;
869}
870
871
872QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections( const QStringList &connections )
873{
874 QDomDocument doc( QStringLiteral( "connections" ) );
875 QDomElement root = doc.createElement( QStringLiteral( "qgsCloudStorageConnections" ) );
876 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
877 doc.appendChild( root );
878
879 for ( int i = 0; i < connections.count(); ++i )
880 {
881 QDomElement el = doc.createElement( QStringLiteral( "cloudstorage" ) );
882
883 el.setAttribute( QStringLiteral( "name" ), connections[i] );
884 el.setAttribute( QStringLiteral( "handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[i] ) );
885 el.setAttribute( QStringLiteral( "container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[i] ) );
886 el.setAttribute( QStringLiteral( "path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[i] ) );
887
888 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[i] );
889 QString credentialString;
890 for ( auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
891 {
892 if ( !it.value().toString().isEmpty() )
893 {
894 credentialString += QStringLiteral( "|credential:%1=%2" ).arg( it.key(), it.value().toString() );
895 }
896 }
897 el.setAttribute( QStringLiteral( "credentials" ), credentialString );
898
899 root.appendChild( el );
900 }
901
902 return doc;
903}
904
905QDomDocument QgsManageConnectionsDialog::saveStacConnections( const QStringList &connections )
906{
907 QDomDocument doc( QStringLiteral( "connections" ) );
908 QDomElement root = doc.createElement( QStringLiteral( "qgsStacConnections" ) );
909 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
910 doc.appendChild( root );
911
912 QMap<QString, QString> namespaceDeclarations;
913 for ( int i = 0; i < connections.count(); ++i )
914 {
915 QDomElement el = doc.createElement( QStringLiteral( "stac" ) );
916
917 el.setAttribute( QStringLiteral( "name" ), connections[i] );
918 el.setAttribute( QStringLiteral( "url" ), QgsStacConnection::settingsUrl->value( connections[i] ) );
919 el.setAttribute( QStringLiteral( "authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[i] ) );
920 el.setAttribute( QStringLiteral( "username" ), QgsStacConnection::settingsUsername->value( connections[i] ) );
921 el.setAttribute( QStringLiteral( "password" ), QgsStacConnection::settingsPassword->value( connections[i] ) );
922
923 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[i] ) );
924 httpHeader.updateDomElement( el, namespaceDeclarations );
925
926 root.appendChild( el );
927 }
928
929 addNamespaceDeclarations( root, namespaceDeclarations );
930
931 return doc;
932}
933
934void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
935{
936 const QDomElement root = doc.documentElement();
937 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
938 {
939 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
940 return;
941 }
942
943 QString connectionName;
944
945 QDomElement child = root.firstChildElement();
946 bool prompt = true;
947 bool overwrite = true;
948
949 while ( !child.isNull() )
950 {
951 connectionName = child.attribute( QStringLiteral( "name" ) );
952 if ( !items.contains( connectionName ) )
953 {
954 child = child.nextSiblingElement();
955 continue;
956 }
957
958 // check for duplicates
959 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && prompt )
960 {
961 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
962
963 switch ( res )
964 {
965 case QMessageBox::Cancel:
966 return;
967 case QMessageBox::No:
968 child = child.nextSiblingElement();
969 continue;
970 case QMessageBox::Yes:
971 overwrite = true;
972 break;
973 case QMessageBox::YesToAll:
974 prompt = false;
975 overwrite = true;
976 break;
977 case QMessageBox::NoToAll:
978 prompt = false;
979 overwrite = false;
980 break;
981 }
982 }
983
984 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && !overwrite )
985 {
986 child = child.nextSiblingElement();
987 continue;
988 }
989
990 // no dups detected or overwrite is allowed
991 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { service.toLower(), connectionName } );
992 QgsOwsConnection::settingsIgnoreGetMapURI->setValue( child.attribute( QStringLiteral( "ignoreGetMapURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
993 QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( child.attribute( QStringLiteral( "ignoreGetFeatureInfoURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
994 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
995 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
996 QgsOwsConnection::settingsSmoothPixmapTransform->setValue( child.attribute( QStringLiteral( "smoothPixmapTransform" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
997 QgsOwsConnection::settingsDpiMode->setValue( static_cast<Qgis::DpiMode>( child.attribute( QStringLiteral( "dpiMode" ), QStringLiteral( "7" ) ).toInt() ), { service.toLower(), connectionName } );
998
999 QgsHttpHeaders httpHeader( child );
1000 QgsOwsConnection::settingsHeaders->setValue( httpHeader.headers(), { service.toLower(), connectionName } );
1001
1002 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1003 {
1004 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { service.toUpper(), connectionName } );
1005 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { service.toUpper(), connectionName } );
1006 }
1007 child = child.nextSiblingElement();
1008 }
1009}
1010
1011void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
1012{
1013 const QDomElement root = doc.documentElement();
1014 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
1015 {
1016 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
1017 return;
1018 }
1019
1020 QString connectionName;
1021 QStringList keys = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wfs" ) } );
1022
1023 QDomElement child = root.firstChildElement();
1024 bool prompt = true;
1025 bool overwrite = true;
1026
1027 while ( !child.isNull() )
1028 {
1029 connectionName = child.attribute( QStringLiteral( "name" ) );
1030 if ( !items.contains( connectionName ) )
1031 {
1032 child = child.nextSiblingElement();
1033 continue;
1034 }
1035
1036 // check for duplicates
1037 if ( keys.contains( connectionName ) && prompt )
1038 {
1039 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1040
1041 switch ( res )
1042 {
1043 case QMessageBox::Cancel:
1044 return;
1045 case QMessageBox::No:
1046 child = child.nextSiblingElement();
1047 continue;
1048 case QMessageBox::Yes:
1049 overwrite = true;
1050 break;
1051 case QMessageBox::YesToAll:
1052 prompt = false;
1053 overwrite = true;
1054 break;
1055 case QMessageBox::NoToAll:
1056 prompt = false;
1057 overwrite = false;
1058 break;
1059 }
1060 }
1061
1062 if ( keys.contains( connectionName ) )
1063 {
1064 if ( !overwrite )
1065 {
1066 child = child.nextSiblingElement();
1067 continue;
1068 }
1069 }
1070 else
1071 {
1072 keys << connectionName;
1073 }
1074
1075 // no dups detected or overwrite is allowed
1076
1077 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { QStringLiteral( "wfs" ), connectionName } );
1078 QgsOwsConnection::settingsVersion->setValue( child.attribute( QStringLiteral( "version" ) ), { QStringLiteral( "wfs" ), connectionName } );
1079 QgsOwsConnection::settingsMaxNumFeatures->setValue( child.attribute( QStringLiteral( "maxnumfeatures" ) ), { QStringLiteral( "wfs" ), connectionName } );
1080 QgsOwsConnection::settingsPagesize->setValue( child.attribute( QStringLiteral( "pagesize" ) ), { QStringLiteral( "wfs" ), connectionName } );
1081 QgsOwsConnection::settingsPagingEnabled->setValue( child.attribute( QStringLiteral( "pagingenabled" ) ), { QStringLiteral( "wfs" ), connectionName } );
1082 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1083 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1084 QgsOwsConnection::settingsPreferredHttpMethod->setValue( child.attribute( QStringLiteral( "httpMethod" ) ).compare( QLatin1String( "post" ), Qt::CaseInsensitive ) == 0 ? Qgis::HttpMethod::Post : Qgis::HttpMethod::Get, { QStringLiteral( "wfs" ), connectionName } );
1085
1086 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1087 {
1088 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { QStringLiteral( "wfs" ), connectionName } );
1089 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { QStringLiteral( "wfs" ), connectionName } );
1090 }
1091 child = child.nextSiblingElement();
1092 }
1093}
1094
1095void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
1096{
1097 const QDomElement root = doc.documentElement();
1098 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
1099 {
1100 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
1101 return;
1102 }
1103
1104 QString connectionName;
1105 QgsSettings settings;
1106 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
1107 QStringList keys = settings.childGroups();
1108 settings.endGroup();
1109 QDomElement child = root.firstChildElement();
1110 bool prompt = true;
1111 bool overwrite = true;
1112
1113 while ( !child.isNull() )
1114 {
1115 connectionName = child.attribute( QStringLiteral( "name" ) );
1116 if ( !items.contains( connectionName ) )
1117 {
1118 child = child.nextSiblingElement();
1119 continue;
1120 }
1121
1122 // check for duplicates
1123 if ( keys.contains( connectionName ) && prompt )
1124 {
1125 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1126 switch ( res )
1127 {
1128 case QMessageBox::Cancel:
1129 return;
1130 case QMessageBox::No:
1131 child = child.nextSiblingElement();
1132 continue;
1133 case QMessageBox::Yes:
1134 overwrite = true;
1135 break;
1136 case QMessageBox::YesToAll:
1137 prompt = false;
1138 overwrite = true;
1139 break;
1140 case QMessageBox::NoToAll:
1141 prompt = false;
1142 overwrite = false;
1143 break;
1144 }
1145 }
1146
1147 if ( keys.contains( connectionName ) )
1148 {
1149 if ( !overwrite )
1150 {
1151 child = child.nextSiblingElement();
1152 continue;
1153 }
1154 }
1155 else
1156 {
1157 keys << connectionName;
1158 }
1159
1160 //no dups detected or overwrite is allowed
1161 settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
1162
1163 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1164 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1165 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1166 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1167 {
1168 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1169 }
1170 else
1171 {
1172 settings.setValue( QStringLiteral( "/service" ), "" );
1173 }
1174 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1175 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1176 settings.setValue( QStringLiteral( "/projectsInDatabase" ), child.attribute( QStringLiteral( "projectsInDatabase" ), 0 ) );
1177 settings.setValue( QStringLiteral( "/dontResolveType" ), child.attribute( QStringLiteral( "dontResolveType" ), 0 ) );
1178 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ), 0 ) );
1179 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ), 0 ) );
1180 settings.setValue( QStringLiteral( "/publicOnly" ), child.attribute( QStringLiteral( "publicOnly" ), 0 ) );
1181 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1182 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1183 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1184 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1185 settings.endGroup();
1186
1187 child = child.nextSiblingElement();
1188 }
1189}
1190
1191void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1192{
1193 const QDomElement root = doc.documentElement();
1194 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
1195 {
1196 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
1197 return;
1198 }
1199
1200 QString connectionName;
1201 QgsSettings settings;
1202 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
1203 QStringList keys = settings.childGroups();
1204 settings.endGroup();
1205 QDomElement child = root.firstChildElement();
1206 bool prompt = true;
1207 bool overwrite = true;
1208
1209 while ( !child.isNull() )
1210 {
1211 connectionName = child.attribute( QStringLiteral( "name" ) );
1212 if ( !items.contains( connectionName ) )
1213 {
1214 child = child.nextSiblingElement();
1215 continue;
1216 }
1217
1218 // check for duplicates
1219 if ( keys.contains( connectionName ) && prompt )
1220 {
1221 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1222 switch ( res )
1223 {
1224 case QMessageBox::Cancel:
1225 return;
1226 case QMessageBox::No:
1227 child = child.nextSiblingElement();
1228 continue;
1229 case QMessageBox::Yes:
1230 overwrite = true;
1231 break;
1232 case QMessageBox::YesToAll:
1233 prompt = false;
1234 overwrite = true;
1235 break;
1236 case QMessageBox::NoToAll:
1237 prompt = false;
1238 overwrite = false;
1239 break;
1240 }
1241 }
1242
1243 if ( keys.contains( connectionName ) )
1244 {
1245 if ( !overwrite )
1246 {
1247 child = child.nextSiblingElement();
1248 continue;
1249 }
1250 }
1251 else
1252 {
1253 keys << connectionName;
1254 }
1255
1256 //no dups detected or overwrite is allowed
1257 settings.beginGroup( "/MSSQL/connections/" + connectionName );
1258
1259 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1260 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1261 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1262 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1263 {
1264 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1265 }
1266 else
1267 {
1268 settings.setValue( QStringLiteral( "/service" ), "" );
1269 }
1270 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1271 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1272 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1273 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1274 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1275 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1276 settings.endGroup();
1277
1278 child = child.nextSiblingElement();
1279 }
1280}
1281
1282void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1283{
1284 const QDomElement root = doc.documentElement();
1285 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
1286 {
1287 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
1288 return;
1289 }
1290
1291 QString connectionName;
1292 QgsSettings settings;
1293 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
1294 QStringList keys = settings.childGroups();
1295 settings.endGroup();
1296 QDomElement child = root.firstChildElement();
1297 bool prompt = true;
1298 bool overwrite = true;
1299
1300 while ( !child.isNull() )
1301 {
1302 connectionName = child.attribute( QStringLiteral( "name" ) );
1303 if ( !items.contains( connectionName ) )
1304 {
1305 child = child.nextSiblingElement();
1306 continue;
1307 }
1308
1309 // check for duplicates
1310 if ( keys.contains( connectionName ) && prompt )
1311 {
1312 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1313 switch ( res )
1314 {
1315 case QMessageBox::Cancel:
1316 return;
1317 case QMessageBox::No:
1318 child = child.nextSiblingElement();
1319 continue;
1320 case QMessageBox::Yes:
1321 overwrite = true;
1322 break;
1323 case QMessageBox::YesToAll:
1324 prompt = false;
1325 overwrite = true;
1326 break;
1327 case QMessageBox::NoToAll:
1328 prompt = false;
1329 overwrite = false;
1330 break;
1331 }
1332 }
1333
1334 if ( keys.contains( connectionName ) )
1335 {
1336 if ( !overwrite )
1337 {
1338 child = child.nextSiblingElement();
1339 continue;
1340 }
1341 }
1342 else
1343 {
1344 keys << connectionName;
1345 }
1346
1347 //no dups detected or overwrite is allowed
1348 settings.beginGroup( "/Oracle/connections/" + connectionName );
1349
1350 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1351 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1352 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1353 settings.setValue( QStringLiteral( "/dboptions" ), child.attribute( QStringLiteral( "dboptions" ) ) );
1354 settings.setValue( QStringLiteral( "/dbworkspace" ), child.attribute( QStringLiteral( "dbworkspace" ) ) );
1355 settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1356 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1357 settings.setValue( QStringLiteral( "/userTablesOnly" ), child.attribute( QStringLiteral( "userTablesOnly" ) ) );
1358 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ) ) );
1359 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ) ) );
1360 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1361 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1362 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1363 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1364 settings.endGroup();
1365
1366 child = child.nextSiblingElement();
1367 }
1368}
1369
1370void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1371{
1372 QDomElement root = doc.documentElement();
1373 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
1374 {
1375 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
1376 return;
1377 }
1378
1379 const QDomAttr version = root.attributeNode( "version" );
1380 if ( version.value() != QLatin1String( "1.0" ) )
1381 {
1382 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1383 return;
1384 }
1385
1386 QgsSettings settings;
1387 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
1388 QStringList keys = settings.childGroups();
1389 settings.endGroup();
1390 QDomElement child = root.firstChildElement();
1391 bool prompt = true;
1392 bool overwrite = true;
1393
1394 while ( !child.isNull() )
1395 {
1396 const QString connectionName = child.attribute( QStringLiteral( "name" ) );
1397 if ( !items.contains( connectionName ) )
1398 {
1399 child = child.nextSiblingElement();
1400 continue;
1401 }
1402
1403 // check for duplicates
1404 if ( keys.contains( connectionName ) && prompt )
1405 {
1406 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1407 switch ( res )
1408 {
1409 case QMessageBox::Cancel:
1410 return;
1411 case QMessageBox::No:
1412 child = child.nextSiblingElement();
1413 continue;
1414 case QMessageBox::Yes:
1415 overwrite = true;
1416 break;
1417 case QMessageBox::YesToAll:
1418 prompt = false;
1419 overwrite = true;
1420 break;
1421 case QMessageBox::NoToAll:
1422 prompt = false;
1423 overwrite = false;
1424 break;
1425 }
1426 }
1427
1428 if ( keys.contains( connectionName ) )
1429 {
1430 if ( !overwrite )
1431 {
1432 child = child.nextSiblingElement();
1433 continue;
1434 }
1435 }
1436 else
1437 {
1438 keys << connectionName;
1439 }
1440
1441 //no dups detected or overwrite is allowed
1442 settings.beginGroup( "/HANA/connections/" + connectionName );
1443
1444 for ( const QString param :
1445 { "driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1446 "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1447 "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1448 } )
1449 settings.setValue( QStringLiteral( "/" ) + param, child.attribute( param ) );
1450
1451 settings.endGroup();
1452
1453 child = child.nextSiblingElement();
1454 }
1455}
1456
1457void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1458{
1459 const QDomElement root = doc.documentElement();
1460 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
1461 {
1462 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
1463 return;
1464 }
1465
1466 QString connectionName;
1468 QDomElement child = root.firstChildElement();
1469 bool prompt = true;
1470 bool overwrite = true;
1471
1472 while ( !child.isNull() )
1473 {
1474 connectionName = child.attribute( QStringLiteral( "name" ) );
1475 if ( !items.contains( connectionName ) )
1476 {
1477 child = child.nextSiblingElement();
1478 continue;
1479 }
1480
1481 // check for duplicates
1482 if ( keys.contains( connectionName ) && prompt )
1483 {
1484 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1485
1486 switch ( res )
1487 {
1488 case QMessageBox::Cancel:
1489 return;
1490 case QMessageBox::No:
1491 child = child.nextSiblingElement();
1492 continue;
1493 case QMessageBox::Yes:
1494 overwrite = true;
1495 break;
1496 case QMessageBox::YesToAll:
1497 prompt = false;
1498 overwrite = true;
1499 break;
1500 case QMessageBox::NoToAll:
1501 prompt = false;
1502 overwrite = false;
1503 break;
1504 }
1505 }
1506
1507 if ( keys.contains( connectionName ) )
1508 {
1509 if ( !overwrite )
1510 {
1511 child = child.nextSiblingElement();
1512 continue;
1513 }
1514 }
1515 else
1516 {
1517 keys << connectionName;
1518 }
1519
1520
1521 QgsXyzConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1522 QgsXyzConnectionSettings::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1523 QgsXyzConnectionSettings::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1524 QgsXyzConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1525 QgsXyzConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1526 QgsXyzConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1527 QgsXyzConnectionSettings::settingsTilePixelRatio->setValue( child.attribute( QStringLiteral( "tilePixelRatio" ) ).toInt(), connectionName );
1528
1529 QgsHttpHeaders httpHeader( child );
1530 QgsXyzConnectionSettings::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1531
1532 child = child.nextSiblingElement();
1533 }
1534}
1535
1536void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1537{
1538 const QDomElement root = doc.documentElement();
1539 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1540 {
1541 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1542 return;
1543 }
1544
1545 QString connectionName;
1547 QDomElement child = root.firstChildElement();
1548 bool prompt = true;
1549 bool overwrite = true;
1550
1551 while ( !child.isNull() )
1552 {
1553 connectionName = child.attribute( QStringLiteral( "name" ) );
1554 if ( !items.contains( connectionName ) )
1555 {
1556 child = child.nextSiblingElement();
1557 continue;
1558 }
1559
1560 // check for duplicates
1561 if ( keys.contains( connectionName ) && prompt )
1562 {
1563 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1564
1565 switch ( res )
1566 {
1567 case QMessageBox::Cancel:
1568 return;
1569 case QMessageBox::No:
1570 child = child.nextSiblingElement();
1571 continue;
1572 case QMessageBox::Yes:
1573 overwrite = true;
1574 break;
1575 case QMessageBox::YesToAll:
1576 prompt = false;
1577 overwrite = true;
1578 break;
1579 case QMessageBox::NoToAll:
1580 prompt = false;
1581 overwrite = false;
1582 break;
1583 }
1584 }
1585
1586 if ( keys.contains( connectionName ) )
1587 {
1588 if ( !overwrite )
1589 {
1590 child = child.nextSiblingElement();
1591 continue;
1592 }
1593 }
1594 else
1595 {
1596 keys << connectionName;
1597 }
1598
1599 // no dups detected or overwrite is allowed
1600 QgsArcGisConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1601
1602 QgsArcGisConnectionSettings::settingsHeaders->setValue( QgsHttpHeaders( child ).headers(), connectionName );
1603
1604
1605 QgsArcGisConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1606 QgsArcGisConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1607 QgsArcGisConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1608
1609 child = child.nextSiblingElement();
1610 }
1611}
1612
1613void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1614{
1615 const QDomElement root = doc.documentElement();
1616 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
1617 {
1618 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
1619 return;
1620 }
1621
1622 QString connectionName;
1623 QgsSettings settings;
1624 settings.beginGroup( QStringLiteral( "/qgis/connections-vector-tile" ) );
1625 QStringList keys = settings.childGroups();
1626 settings.endGroup();
1627 QDomElement child = root.firstChildElement();
1628 bool prompt = true;
1629 bool overwrite = true;
1630
1631 while ( !child.isNull() )
1632 {
1633 connectionName = child.attribute( QStringLiteral( "name" ) );
1634 if ( !items.contains( connectionName ) )
1635 {
1636 child = child.nextSiblingElement();
1637 continue;
1638 }
1639
1640 // check for duplicates
1641 if ( keys.contains( connectionName ) && prompt )
1642 {
1643 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1644
1645 switch ( res )
1646 {
1647 case QMessageBox::Cancel:
1648 return;
1649 case QMessageBox::No:
1650 child = child.nextSiblingElement();
1651 continue;
1652 case QMessageBox::Yes:
1653 overwrite = true;
1654 break;
1655 case QMessageBox::YesToAll:
1656 prompt = false;
1657 overwrite = true;
1658 break;
1659 case QMessageBox::NoToAll:
1660 prompt = false;
1661 overwrite = false;
1662 break;
1663 }
1664 }
1665
1666 if ( keys.contains( connectionName ) )
1667 {
1668 if ( !overwrite )
1669 {
1670 child = child.nextSiblingElement();
1671 continue;
1672 }
1673 }
1674 else
1675 {
1676 keys << connectionName;
1677 }
1678
1679 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1680 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1681 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1682 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral( "serviceType" ) ), connectionName );
1683 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1684 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1685 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1686 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral( "styleUrl" ) ), connectionName );
1687
1688 QgsHttpHeaders httpHeader( child );
1689 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1690
1691 child = child.nextSiblingElement();
1692 }
1693}
1694
1695void QgsManageConnectionsDialog::loadTiledSceneConnections( const QDomDocument &doc, const QStringList &items )
1696{
1697 const QDomElement root = doc.documentElement();
1698 if ( root.tagName() != QLatin1String( "qgsTiledSceneConnections" ) )
1699 {
1700 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
1701 return;
1702 }
1703
1704 QString connectionName;
1705 QgsSettings settings;
1706 settings.beginGroup( QStringLiteral( "/qgis/connections-tiled-scene" ) );
1707 QStringList keys = settings.childGroups();
1708 settings.endGroup();
1709 QDomElement child = root.firstChildElement();
1710 bool prompt = true;
1711 bool overwrite = true;
1712
1713 while ( !child.isNull() )
1714 {
1715 connectionName = child.attribute( QStringLiteral( "name" ) );
1716 if ( !items.contains( connectionName ) )
1717 {
1718 child = child.nextSiblingElement();
1719 continue;
1720 }
1721
1722 // check for duplicates
1723 if ( keys.contains( connectionName ) && prompt )
1724 {
1725 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1726
1727 switch ( res )
1728 {
1729 case QMessageBox::Cancel:
1730 return;
1731 case QMessageBox::No:
1732 child = child.nextSiblingElement();
1733 continue;
1734 case QMessageBox::Yes:
1735 overwrite = true;
1736 break;
1737 case QMessageBox::YesToAll:
1738 prompt = false;
1739 overwrite = true;
1740 break;
1741 case QMessageBox::NoToAll:
1742 prompt = false;
1743 overwrite = false;
1744 break;
1745 }
1746 }
1747
1748 if ( keys.contains( connectionName ) )
1749 {
1750 if ( !overwrite )
1751 {
1752 child = child.nextSiblingElement();
1753 continue;
1754 }
1755 }
1756 else
1757 {
1758 keys << connectionName;
1759 }
1760
1761 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral( "provider" ) ), connectionName );
1762 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1763 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1764 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1765 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1766
1767 QgsHttpHeaders httpHeader( child );
1768 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1769
1770 child = child.nextSiblingElement();
1771 }
1772}
1773
1774void QgsManageConnectionsDialog::loadSensorThingsConnections( const QDomDocument &doc, const QStringList &items )
1775{
1776 const QDomElement root = doc.documentElement();
1777 if ( root.tagName() != QLatin1String( "qgsSensorThingsConnections" ) )
1778 {
1779 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
1780 return;
1781 }
1782
1783 QString connectionName;
1784 QgsSettings settings;
1785 settings.beginGroup( QStringLiteral( "/connections/sensorthings/items" ) );
1786 QStringList keys = settings.childGroups();
1787 settings.endGroup();
1788 QDomElement child = root.firstChildElement();
1789 bool prompt = true;
1790 bool overwrite = true;
1791
1792 while ( !child.isNull() )
1793 {
1794 connectionName = child.attribute( QStringLiteral( "name" ) );
1795 if ( !items.contains( connectionName ) )
1796 {
1797 child = child.nextSiblingElement();
1798 continue;
1799 }
1800
1801 // check for duplicates
1802 if ( keys.contains( connectionName ) && prompt )
1803 {
1804 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1805
1806 switch ( res )
1807 {
1808 case QMessageBox::Cancel:
1809 return;
1810 case QMessageBox::No:
1811 child = child.nextSiblingElement();
1812 continue;
1813 case QMessageBox::Yes:
1814 overwrite = true;
1815 break;
1816 case QMessageBox::YesToAll:
1817 prompt = false;
1818 overwrite = true;
1819 break;
1820 case QMessageBox::NoToAll:
1821 prompt = false;
1822 overwrite = false;
1823 break;
1824 }
1825 }
1826
1827 if ( keys.contains( connectionName ) )
1828 {
1829 if ( !overwrite )
1830 {
1831 child = child.nextSiblingElement();
1832 continue;
1833 }
1834 }
1835 else
1836 {
1837 keys << connectionName;
1838 }
1839
1840 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1841 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1842 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1843 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1844
1845 QgsHttpHeaders httpHeader( child );
1846 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1847
1848 child = child.nextSiblingElement();
1849 }
1850}
1851
1852void QgsManageConnectionsDialog::loadCloudStorageConnections( const QDomDocument &doc, const QStringList &items )
1853{
1854 const QDomElement root = doc.documentElement();
1855 if ( root.tagName() != QLatin1String( "qgsCloudStorageConnections" ) )
1856 {
1857 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
1858 return;
1859 }
1860
1861 QString connectionName;
1862 QgsSettings settings;
1863 settings.beginGroup( QStringLiteral( "/connections/cloud/items" ) );
1864 QStringList keys = settings.childGroups();
1865 settings.endGroup();
1866 QDomElement child = root.firstChildElement();
1867 bool prompt = true;
1868 bool overwrite = true;
1869
1870 while ( !child.isNull() )
1871 {
1872 connectionName = child.attribute( QStringLiteral( "name" ) );
1873 if ( !items.contains( connectionName ) )
1874 {
1875 child = child.nextSiblingElement();
1876 continue;
1877 }
1878
1879 // check for duplicates
1880 if ( keys.contains( connectionName ) && prompt )
1881 {
1882 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1883
1884 switch ( res )
1885 {
1886 case QMessageBox::Cancel:
1887 return;
1888 case QMessageBox::No:
1889 child = child.nextSiblingElement();
1890 continue;
1891 case QMessageBox::Yes:
1892 overwrite = true;
1893 break;
1894 case QMessageBox::YesToAll:
1895 prompt = false;
1896 overwrite = true;
1897 break;
1898 case QMessageBox::NoToAll:
1899 prompt = false;
1900 overwrite = false;
1901 break;
1902 }
1903 }
1904
1905 if ( keys.contains( connectionName ) )
1906 {
1907 if ( !overwrite )
1908 {
1909 child = child.nextSiblingElement();
1910 continue;
1911 }
1912 }
1913 else
1914 {
1915 keys << connectionName;
1916 }
1917
1918 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral( "handler" ) ), connectionName );
1919 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral( "container" ) ), connectionName );
1920 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral( "path" ) ), connectionName );
1921
1922 QString credentialString = child.attribute( QStringLiteral( "credentials" ) );
1923
1924 QVariantMap credentialOptions;
1925 while ( true )
1926 {
1927 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral( "\\|credential:([^|]*)" ) );
1928 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral( "(.*?)=(.*)" ) );
1929
1930 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1931 if ( match.hasMatch() )
1932 {
1933 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1934 if ( keyValueMatch.hasMatch() )
1935 {
1936 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1937 }
1938 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1939 }
1940 else
1941 {
1942 break;
1943 }
1944 }
1945
1946 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1947
1948 child = child.nextSiblingElement();
1949 }
1950}
1951
1952void QgsManageConnectionsDialog::loadStacConnections( const QDomDocument &doc, const QStringList &items )
1953{
1954 const QDomElement root = doc.documentElement();
1955 if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
1956 {
1957 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
1958 return;
1959 }
1960
1961 QString connectionName;
1962 QgsSettings settings;
1963 settings.beginGroup( QStringLiteral( "/qgis/connections-stac" ) );
1964 QStringList keys = settings.childGroups();
1965 settings.endGroup();
1966 QDomElement child = root.firstChildElement();
1967 bool prompt = true;
1968 bool overwrite = true;
1969
1970 while ( !child.isNull() )
1971 {
1972 connectionName = child.attribute( QStringLiteral( "name" ) );
1973 if ( !items.contains( connectionName ) )
1974 {
1975 child = child.nextSiblingElement();
1976 continue;
1977 }
1978
1979 // check for duplicates
1980 if ( keys.contains( connectionName ) && prompt )
1981 {
1982 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1983
1984 switch ( res )
1985 {
1986 case QMessageBox::Cancel:
1987 return;
1988 case QMessageBox::No:
1989 child = child.nextSiblingElement();
1990 continue;
1991 case QMessageBox::Yes:
1992 overwrite = true;
1993 break;
1994 case QMessageBox::YesToAll:
1995 prompt = false;
1996 overwrite = true;
1997 break;
1998 case QMessageBox::NoToAll:
1999 prompt = false;
2000 overwrite = false;
2001 break;
2002 }
2003 }
2004
2005 if ( keys.contains( connectionName ) )
2006 {
2007 if ( !overwrite )
2008 {
2009 child = child.nextSiblingElement();
2010 continue;
2011 }
2012 }
2013 else
2014 {
2015 keys << connectionName;
2016 }
2017
2018 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
2019 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
2020 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
2021 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
2022
2023 QgsHttpHeaders httpHeader( child );
2024 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2025
2026 child = child.nextSiblingElement();
2027 }
2028}
2029
2031{
2032 listConnections->selectAll();
2033 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2034}
2035
2037{
2038 listConnections->clearSelection();
2039 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
2040}
DpiMode
DpiMode enum.
Definition qgis.h:3226
@ Post
POST method.
@ Get
GET method.
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryVariantMap * settingsHeaders
static QgsSettingsTreeNamedListNode * sTreeConnectionArcgis
static const QgsSettingsEntryString * settingsAuthcfg
This class implements simple http header management.
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
@ STAC
SpatioTemporal Asset Catalog connections.
@ SensorThings
SensorThings connections.
@ TiledScene
Tiled scene connection.
@ CloudStorage
Cloud storage connections.
static const QgsSettingsEntryEnumFlag< Qgis::HttpMethod > * settingsPreferredHttpMethod
static const QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const
Returns the list of items.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QStringList childGroups(Qgis::SettingsOrigin origin=Qgis::SettingsOrigin::Any) const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QgsSettingsTreeNamedListNode * sTreeXyzConnections
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryDouble * settingsTilePixelRatio
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsAuthcfg
static const QgsSettingsEntryInteger * settingsZmin
static const QgsSettingsEntryInteger * settingsZmax
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryVariantMap * settingsHeaders