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