QGIS API Documentation 3.99.0-Master (d270888f95f)
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::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 );
968
969 switch ( res )
970 {
971 case QMessageBox::Cancel:
972 return;
973 case QMessageBox::No:
974 child = child.nextSiblingElement();
975 continue;
976 case QMessageBox::Yes:
977 overwrite = true;
978 break;
979 case QMessageBox::YesToAll:
980 prompt = false;
981 overwrite = true;
982 break;
983 case QMessageBox::NoToAll:
984 prompt = false;
985 overwrite = false;
986 break;
987 }
988 }
989
990 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && !overwrite )
991 {
992 child = child.nextSiblingElement();
993 continue;
994 }
995
996 // no dups detected or overwrite is allowed
997 QgsOwsConnection::settingsUrl->setValue( child.attribute( u"url"_s ), { service.toLower(), connectionName } );
998 QgsOwsConnection::settingsIgnoreGetMapURI->setValue( child.attribute( u"ignoreGetMapURI"_s ) == "true"_L1, { service.toLower(), connectionName } );
999 QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( child.attribute( u"ignoreGetFeatureInfoURI"_s ) == "true"_L1, { service.toLower(), connectionName } );
1000 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( u"ignoreAxisOrientation"_s ) == "true"_L1, { service.toLower(), connectionName } );
1001 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( u"invertAxisOrientation"_s ) == "true"_L1, { service.toLower(), connectionName } );
1002 QgsOwsConnection::settingsSmoothPixmapTransform->setValue( child.attribute( u"smoothPixmapTransform"_s ) == "true"_L1, { service.toLower(), connectionName } );
1003 QgsOwsConnection::settingsDpiMode->setValue( static_cast<Qgis::DpiMode>( child.attribute( u"dpiMode"_s, u"7"_s ).toInt() ), { service.toLower(), connectionName } );
1004
1005 QgsHttpHeaders httpHeader( child );
1006 QgsOwsConnection::settingsHeaders->setValue( httpHeader.headers(), { service.toLower(), connectionName } );
1007
1008 if ( !child.attribute( u"username"_s ).isEmpty() )
1009 {
1010 QgsOwsConnection::settingsUsername->setValue( child.attribute( u"username"_s ), { service.toUpper(), connectionName } );
1011 QgsOwsConnection::settingsPassword->setValue( child.attribute( u"password"_s ), { service.toUpper(), connectionName } );
1012 }
1013 child = child.nextSiblingElement();
1014 }
1015}
1016
1017void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
1018{
1019 const QDomElement root = doc.documentElement();
1020 if ( root.tagName() != "qgsWFSConnections"_L1 )
1021 {
1022 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
1023 return;
1024 }
1025
1026 QString connectionName;
1027 QStringList keys = QgsOwsConnection::sTreeOwsConnections->items( { u"wfs"_s } );
1028
1029 QDomElement child = root.firstChildElement();
1030 bool prompt = true;
1031 bool overwrite = true;
1032
1033 while ( !child.isNull() )
1034 {
1035 connectionName = child.attribute( u"name"_s );
1036 if ( !items.contains( connectionName ) )
1037 {
1038 child = child.nextSiblingElement();
1039 continue;
1040 }
1041
1042 // check for duplicates
1043 if ( keys.contains( connectionName ) && prompt )
1044 {
1045 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 );
1046
1047 switch ( res )
1048 {
1049 case QMessageBox::Cancel:
1050 return;
1051 case QMessageBox::No:
1052 child = child.nextSiblingElement();
1053 continue;
1054 case QMessageBox::Yes:
1055 overwrite = true;
1056 break;
1057 case QMessageBox::YesToAll:
1058 prompt = false;
1059 overwrite = true;
1060 break;
1061 case QMessageBox::NoToAll:
1062 prompt = false;
1063 overwrite = false;
1064 break;
1065 }
1066 }
1067
1068 if ( keys.contains( connectionName ) )
1069 {
1070 if ( !overwrite )
1071 {
1072 child = child.nextSiblingElement();
1073 continue;
1074 }
1075 }
1076 else
1077 {
1078 keys << connectionName;
1079 }
1080
1081 // no dups detected or overwrite is allowed
1082
1083 QgsOwsConnection::settingsUrl->setValue( child.attribute( u"url"_s ), { u"wfs"_s, connectionName } );
1084 QgsOwsConnection::settingsVersion->setValue( child.attribute( u"version"_s ), { u"wfs"_s, connectionName } );
1085 QgsOwsConnection::settingsMaxNumFeatures->setValue( child.attribute( u"maxnumfeatures"_s ), { u"wfs"_s, connectionName } );
1086 QgsOwsConnection::settingsPagesize->setValue( child.attribute( u"pagesize"_s ), { u"wfs"_s, connectionName } );
1087 QgsOwsConnection::settingsPagingEnabled->setValue( child.attribute( u"pagingenabled"_s ), { u"wfs"_s, connectionName } );
1088 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( u"ignoreAxisOrientation"_s ).toInt(), { u"wfs"_s, connectionName } );
1089 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( u"invertAxisOrientation"_s ).toInt(), { u"wfs"_s, connectionName } );
1090 QgsOwsConnection::settingsPreferredHttpMethod->setValue( child.attribute( u"httpMethod"_s ).compare( "post"_L1, Qt::CaseInsensitive ) == 0 ? Qgis::HttpMethod::Post : Qgis::HttpMethod::Get, { u"wfs"_s, connectionName } );
1091 QgsOwsConnection::settingsWfsFeatureMode->setValue( child.attribute( u"featureMode"_s ), { u"wfs"_s, connectionName } );
1092
1093 if ( !child.attribute( u"username"_s ).isEmpty() )
1094 {
1095 QgsOwsConnection::settingsUsername->setValue( child.attribute( u"username"_s ), { u"wfs"_s, connectionName } );
1096 QgsOwsConnection::settingsPassword->setValue( child.attribute( u"password"_s ), { u"wfs"_s, connectionName } );
1097 }
1098 child = child.nextSiblingElement();
1099 }
1100}
1101
1102void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
1103{
1104 const QDomElement root = doc.documentElement();
1105 if ( root.tagName() != "qgsPgConnections"_L1 )
1106 {
1107 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
1108 return;
1109 }
1110
1111 QString connectionName;
1112 QgsSettings settings;
1113 settings.beginGroup( u"/PostgreSQL/connections"_s );
1114 QStringList keys = settings.childGroups();
1115 settings.endGroup();
1116 QDomElement child = root.firstChildElement();
1117 bool prompt = true;
1118 bool overwrite = true;
1119
1120 while ( !child.isNull() )
1121 {
1122 connectionName = child.attribute( u"name"_s );
1123 if ( !items.contains( connectionName ) )
1124 {
1125 child = child.nextSiblingElement();
1126 continue;
1127 }
1128
1129 // check for duplicates
1130 if ( keys.contains( connectionName ) && prompt )
1131 {
1132 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 );
1133 switch ( res )
1134 {
1135 case QMessageBox::Cancel:
1136 return;
1137 case QMessageBox::No:
1138 child = child.nextSiblingElement();
1139 continue;
1140 case QMessageBox::Yes:
1141 overwrite = true;
1142 break;
1143 case QMessageBox::YesToAll:
1144 prompt = false;
1145 overwrite = true;
1146 break;
1147 case QMessageBox::NoToAll:
1148 prompt = false;
1149 overwrite = false;
1150 break;
1151 }
1152 }
1153
1154 if ( keys.contains( connectionName ) )
1155 {
1156 if ( !overwrite )
1157 {
1158 child = child.nextSiblingElement();
1159 continue;
1160 }
1161 }
1162 else
1163 {
1164 keys << connectionName;
1165 }
1166
1167 //no dups detected or overwrite is allowed
1168 settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
1169
1170 settings.setValue( u"/host"_s, child.attribute( u"host"_s ) );
1171 settings.setValue( u"/port"_s, child.attribute( u"port"_s ) );
1172 settings.setValue( u"/database"_s, child.attribute( u"database"_s ) );
1173 if ( child.hasAttribute( u"service"_s ) )
1174 {
1175 settings.setValue( u"/service"_s, child.attribute( u"service"_s ) );
1176 }
1177 else
1178 {
1179 settings.setValue( u"/service"_s, "" );
1180 }
1181 settings.setValue( u"/sslmode"_s, child.attribute( u"sslmode"_s ) );
1182 settings.setValue( u"/estimatedMetadata"_s, child.attribute( u"estimatedMetadata"_s ) );
1183 settings.setValue( u"/projectsInDatabase"_s, child.attribute( u"projectsInDatabase"_s, 0 ) );
1184 settings.setValue( u"/dontResolveType"_s, child.attribute( u"dontResolveType"_s, 0 ) );
1185 settings.setValue( u"/allowGeometrylessTables"_s, child.attribute( u"allowGeometrylessTables"_s, 0 ) );
1186 settings.setValue( u"/geometryColumnsOnly"_s, child.attribute( u"geometryColumnsOnly"_s, 0 ) );
1187 settings.setValue( u"/publicOnly"_s, child.attribute( u"publicOnly"_s, 0 ) );
1188 settings.setValue( u"/saveUsername"_s, child.attribute( u"saveUsername"_s ) );
1189 settings.setValue( u"/username"_s, child.attribute( u"username"_s ) );
1190 settings.setValue( u"/savePassword"_s, child.attribute( u"savePassword"_s ) );
1191 settings.setValue( u"/password"_s, child.attribute( u"password"_s ) );
1192 settings.setValue( u"/schema"_s, child.attribute( u"schema"_s ) );
1193 settings.endGroup();
1194
1195 child = child.nextSiblingElement();
1196 }
1197}
1198
1199void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1200{
1201 const QDomElement root = doc.documentElement();
1202 if ( root.tagName() != "qgsMssqlConnections"_L1 )
1203 {
1204 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
1205 return;
1206 }
1207
1208 QString connectionName;
1209 QgsSettings settings;
1210 settings.beginGroup( u"/MSSQL/connections"_s );
1211 QStringList keys = settings.childGroups();
1212 settings.endGroup();
1213 QDomElement child = root.firstChildElement();
1214 bool prompt = true;
1215 bool overwrite = true;
1216
1217 while ( !child.isNull() )
1218 {
1219 connectionName = child.attribute( u"name"_s );
1220 if ( !items.contains( connectionName ) )
1221 {
1222 child = child.nextSiblingElement();
1223 continue;
1224 }
1225
1226 // check for duplicates
1227 if ( keys.contains( connectionName ) && prompt )
1228 {
1229 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 );
1230 switch ( res )
1231 {
1232 case QMessageBox::Cancel:
1233 return;
1234 case QMessageBox::No:
1235 child = child.nextSiblingElement();
1236 continue;
1237 case QMessageBox::Yes:
1238 overwrite = true;
1239 break;
1240 case QMessageBox::YesToAll:
1241 prompt = false;
1242 overwrite = true;
1243 break;
1244 case QMessageBox::NoToAll:
1245 prompt = false;
1246 overwrite = false;
1247 break;
1248 }
1249 }
1250
1251 if ( keys.contains( connectionName ) )
1252 {
1253 if ( !overwrite )
1254 {
1255 child = child.nextSiblingElement();
1256 continue;
1257 }
1258 }
1259 else
1260 {
1261 keys << connectionName;
1262 }
1263
1264 //no dups detected or overwrite is allowed
1265 settings.beginGroup( "/MSSQL/connections/" + connectionName );
1266
1267 settings.setValue( u"/host"_s, child.attribute( u"host"_s ) );
1268 settings.setValue( u"/port"_s, child.attribute( u"port"_s ) );
1269 settings.setValue( u"/database"_s, child.attribute( u"database"_s ) );
1270 if ( child.hasAttribute( u"service"_s ) )
1271 {
1272 settings.setValue( u"/service"_s, child.attribute( u"service"_s ) );
1273 }
1274 else
1275 {
1276 settings.setValue( u"/service"_s, "" );
1277 }
1278 settings.setValue( u"/sslmode"_s, child.attribute( u"sslmode"_s ) );
1279 settings.setValue( u"/estimatedMetadata"_s, child.attribute( u"estimatedMetadata"_s ) );
1280 settings.setValue( u"/saveUsername"_s, child.attribute( u"saveUsername"_s ) );
1281 settings.setValue( u"/username"_s, child.attribute( u"username"_s ) );
1282 settings.setValue( u"/savePassword"_s, child.attribute( u"savePassword"_s ) );
1283 settings.setValue( u"/password"_s, child.attribute( u"password"_s ) );
1284 settings.endGroup();
1285
1286 child = child.nextSiblingElement();
1287 }
1288}
1289
1290void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1291{
1292 const QDomElement root = doc.documentElement();
1293 if ( root.tagName() != "qgsOracleConnections"_L1 )
1294 {
1295 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
1296 return;
1297 }
1298
1299 QString connectionName;
1300 QgsSettings settings;
1301 settings.beginGroup( u"/Oracle/connections"_s );
1302 QStringList keys = settings.childGroups();
1303 settings.endGroup();
1304 QDomElement child = root.firstChildElement();
1305 bool prompt = true;
1306 bool overwrite = true;
1307
1308 while ( !child.isNull() )
1309 {
1310 connectionName = child.attribute( u"name"_s );
1311 if ( !items.contains( connectionName ) )
1312 {
1313 child = child.nextSiblingElement();
1314 continue;
1315 }
1316
1317 // check for duplicates
1318 if ( keys.contains( connectionName ) && prompt )
1319 {
1320 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 );
1321 switch ( res )
1322 {
1323 case QMessageBox::Cancel:
1324 return;
1325 case QMessageBox::No:
1326 child = child.nextSiblingElement();
1327 continue;
1328 case QMessageBox::Yes:
1329 overwrite = true;
1330 break;
1331 case QMessageBox::YesToAll:
1332 prompt = false;
1333 overwrite = true;
1334 break;
1335 case QMessageBox::NoToAll:
1336 prompt = false;
1337 overwrite = false;
1338 break;
1339 }
1340 }
1341
1342 if ( keys.contains( connectionName ) )
1343 {
1344 if ( !overwrite )
1345 {
1346 child = child.nextSiblingElement();
1347 continue;
1348 }
1349 }
1350 else
1351 {
1352 keys << connectionName;
1353 }
1354
1355 //no dups detected or overwrite is allowed
1356 settings.beginGroup( "/Oracle/connections/" + connectionName );
1357
1358 settings.setValue( u"/host"_s, child.attribute( u"host"_s ) );
1359 settings.setValue( u"/port"_s, child.attribute( u"port"_s ) );
1360 settings.setValue( u"/database"_s, child.attribute( u"database"_s ) );
1361 settings.setValue( u"/dboptions"_s, child.attribute( u"dboptions"_s ) );
1362 settings.setValue( u"/dbworkspace"_s, child.attribute( u"dbworkspace"_s ) );
1363 settings.setValue( u"/schema"_s, child.attribute( u"schema"_s ) );
1364 settings.setValue( u"/estimatedMetadata"_s, child.attribute( u"estimatedMetadata"_s ) );
1365 settings.setValue( u"/userTablesOnly"_s, child.attribute( u"userTablesOnly"_s ) );
1366 settings.setValue( u"/geometryColumnsOnly"_s, child.attribute( u"geometryColumnsOnly"_s ) );
1367 settings.setValue( u"/allowGeometrylessTables"_s, child.attribute( u"allowGeometrylessTables"_s ) );
1368 settings.setValue( u"/saveUsername"_s, child.attribute( u"saveUsername"_s ) );
1369 settings.setValue( u"/username"_s, child.attribute( u"username"_s ) );
1370 settings.setValue( u"/savePassword"_s, child.attribute( u"savePassword"_s ) );
1371 settings.setValue( u"/password"_s, child.attribute( u"password"_s ) );
1372 settings.endGroup();
1373
1374 child = child.nextSiblingElement();
1375 }
1376}
1377
1378void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1379{
1380 QDomElement root = doc.documentElement();
1381 if ( root.tagName() != "qgsHanaConnections"_L1 )
1382 {
1383 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
1384 return;
1385 }
1386
1387 const QDomAttr version = root.attributeNode( "version" );
1388 if ( version.value() != "1.0"_L1 )
1389 {
1390 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1391 return;
1392 }
1393
1394 QgsSettings settings;
1395 settings.beginGroup( u"/HANA/connections"_s );
1396 QStringList keys = settings.childGroups();
1397 settings.endGroup();
1398 QDomElement child = root.firstChildElement();
1399 bool prompt = true;
1400 bool overwrite = true;
1401
1402 while ( !child.isNull() )
1403 {
1404 const QString connectionName = child.attribute( u"name"_s );
1405 if ( !items.contains( connectionName ) )
1406 {
1407 child = child.nextSiblingElement();
1408 continue;
1409 }
1410
1411 // check for duplicates
1412 if ( keys.contains( connectionName ) && prompt )
1413 {
1414 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 );
1415 switch ( res )
1416 {
1417 case QMessageBox::Cancel:
1418 return;
1419 case QMessageBox::No:
1420 child = child.nextSiblingElement();
1421 continue;
1422 case QMessageBox::Yes:
1423 overwrite = true;
1424 break;
1425 case QMessageBox::YesToAll:
1426 prompt = false;
1427 overwrite = true;
1428 break;
1429 case QMessageBox::NoToAll:
1430 prompt = false;
1431 overwrite = false;
1432 break;
1433 }
1434 }
1435
1436 if ( keys.contains( connectionName ) )
1437 {
1438 if ( !overwrite )
1439 {
1440 child = child.nextSiblingElement();
1441 continue;
1442 }
1443 }
1444 else
1445 {
1446 keys << connectionName;
1447 }
1448
1449 //no dups detected or overwrite is allowed
1450 settings.beginGroup( "/HANA/connections/" + connectionName );
1451
1452 for ( const QString param :
1453 { "driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1454 "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1455 "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1456 } )
1457 settings.setValue( u"/"_s + param, child.attribute( param ) );
1458
1459 settings.endGroup();
1460
1461 child = child.nextSiblingElement();
1462 }
1463}
1464
1465void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1466{
1467 const QDomElement root = doc.documentElement();
1468 if ( root.tagName() != "qgsXYZTilesConnections"_L1 )
1469 {
1470 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
1471 return;
1472 }
1473
1474 QString connectionName;
1476 QDomElement child = root.firstChildElement();
1477 bool prompt = true;
1478 bool overwrite = true;
1479
1480 while ( !child.isNull() )
1481 {
1482 connectionName = child.attribute( u"name"_s );
1483 if ( !items.contains( connectionName ) )
1484 {
1485 child = child.nextSiblingElement();
1486 continue;
1487 }
1488
1489 // check for duplicates
1490 if ( keys.contains( connectionName ) && prompt )
1491 {
1492 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 );
1493
1494 switch ( res )
1495 {
1496 case QMessageBox::Cancel:
1497 return;
1498 case QMessageBox::No:
1499 child = child.nextSiblingElement();
1500 continue;
1501 case QMessageBox::Yes:
1502 overwrite = true;
1503 break;
1504 case QMessageBox::YesToAll:
1505 prompt = false;
1506 overwrite = true;
1507 break;
1508 case QMessageBox::NoToAll:
1509 prompt = false;
1510 overwrite = false;
1511 break;
1512 }
1513 }
1514
1515 if ( keys.contains( connectionName ) )
1516 {
1517 if ( !overwrite )
1518 {
1519 child = child.nextSiblingElement();
1520 continue;
1521 }
1522 }
1523 else
1524 {
1525 keys << connectionName;
1526 }
1527
1528
1529 QgsXyzConnectionSettings::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
1530 QgsXyzConnectionSettings::settingsZmin->setValue( child.attribute( u"zmin"_s ).toInt(), connectionName );
1531 QgsXyzConnectionSettings::settingsZmax->setValue( child.attribute( u"zmax"_s ).toInt(), connectionName );
1532 QgsXyzConnectionSettings::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
1533 QgsXyzConnectionSettings::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
1534 QgsXyzConnectionSettings::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
1535 QgsXyzConnectionSettings::settingsTilePixelRatio->setValue( child.attribute( u"tilePixelRatio"_s ).toInt(), connectionName );
1536
1537 QgsHttpHeaders httpHeader( child );
1538 QgsXyzConnectionSettings::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1539
1540 child = child.nextSiblingElement();
1541 }
1542}
1543
1544void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1545{
1546 const QDomElement root = doc.documentElement();
1547 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1548 {
1549 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1550 return;
1551 }
1552
1553 QString connectionName;
1555 QDomElement child = root.firstChildElement();
1556 bool prompt = true;
1557 bool overwrite = true;
1558
1559 while ( !child.isNull() )
1560 {
1561 connectionName = child.attribute( u"name"_s );
1562 if ( !items.contains( connectionName ) )
1563 {
1564 child = child.nextSiblingElement();
1565 continue;
1566 }
1567
1568 // check for duplicates
1569 if ( keys.contains( connectionName ) && prompt )
1570 {
1571 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 );
1572
1573 switch ( res )
1574 {
1575 case QMessageBox::Cancel:
1576 return;
1577 case QMessageBox::No:
1578 child = child.nextSiblingElement();
1579 continue;
1580 case QMessageBox::Yes:
1581 overwrite = true;
1582 break;
1583 case QMessageBox::YesToAll:
1584 prompt = false;
1585 overwrite = true;
1586 break;
1587 case QMessageBox::NoToAll:
1588 prompt = false;
1589 overwrite = false;
1590 break;
1591 }
1592 }
1593
1594 if ( keys.contains( connectionName ) )
1595 {
1596 if ( !overwrite )
1597 {
1598 child = child.nextSiblingElement();
1599 continue;
1600 }
1601 }
1602 else
1603 {
1604 keys << connectionName;
1605 }
1606
1607 // no dups detected or overwrite is allowed
1608 QgsArcGisConnectionSettings::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
1609
1610 QgsArcGisConnectionSettings::settingsHeaders->setValue( QgsHttpHeaders( child ).headers(), connectionName );
1611
1612
1613 QgsArcGisConnectionSettings::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
1614 QgsArcGisConnectionSettings::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
1615 QgsArcGisConnectionSettings::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
1616
1617 child = child.nextSiblingElement();
1618 }
1619}
1620
1621void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1622{
1623 const QDomElement root = doc.documentElement();
1624 if ( root.tagName() != "qgsVectorTileConnections"_L1 )
1625 {
1626 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
1627 return;
1628 }
1629
1630 QString connectionName;
1631 QgsSettings settings;
1632 settings.beginGroup( u"/qgis/connections-vector-tile"_s );
1633 QStringList keys = settings.childGroups();
1634 settings.endGroup();
1635 QDomElement child = root.firstChildElement();
1636 bool prompt = true;
1637 bool overwrite = true;
1638
1639 while ( !child.isNull() )
1640 {
1641 connectionName = child.attribute( u"name"_s );
1642 if ( !items.contains( connectionName ) )
1643 {
1644 child = child.nextSiblingElement();
1645 continue;
1646 }
1647
1648 // check for duplicates
1649 if ( keys.contains( connectionName ) && prompt )
1650 {
1651 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 );
1652
1653 switch ( res )
1654 {
1655 case QMessageBox::Cancel:
1656 return;
1657 case QMessageBox::No:
1658 child = child.nextSiblingElement();
1659 continue;
1660 case QMessageBox::Yes:
1661 overwrite = true;
1662 break;
1663 case QMessageBox::YesToAll:
1664 prompt = false;
1665 overwrite = true;
1666 break;
1667 case QMessageBox::NoToAll:
1668 prompt = false;
1669 overwrite = false;
1670 break;
1671 }
1672 }
1673
1674 if ( keys.contains( connectionName ) )
1675 {
1676 if ( !overwrite )
1677 {
1678 child = child.nextSiblingElement();
1679 continue;
1680 }
1681 }
1682 else
1683 {
1684 keys << connectionName;
1685 }
1686
1687 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
1688 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( u"zmin"_s ).toInt(), connectionName );
1689 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( u"zmax"_s ).toInt(), connectionName );
1690 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( u"serviceType"_s ), connectionName );
1691 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
1692 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
1693 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
1694 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( u"styleUrl"_s ), connectionName );
1695
1696 QgsHttpHeaders httpHeader( child );
1697 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1698
1699 child = child.nextSiblingElement();
1700 }
1701}
1702
1703void QgsManageConnectionsDialog::loadTiledSceneConnections( const QDomDocument &doc, const QStringList &items )
1704{
1705 const QDomElement root = doc.documentElement();
1706 if ( root.tagName() != "qgsTiledSceneConnections"_L1 )
1707 {
1708 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
1709 return;
1710 }
1711
1712 QString connectionName;
1713 QgsSettings settings;
1714 settings.beginGroup( u"/qgis/connections-tiled-scene"_s );
1715 QStringList keys = settings.childGroups();
1716 settings.endGroup();
1717 QDomElement child = root.firstChildElement();
1718 bool prompt = true;
1719 bool overwrite = true;
1720
1721 while ( !child.isNull() )
1722 {
1723 connectionName = child.attribute( u"name"_s );
1724 if ( !items.contains( connectionName ) )
1725 {
1726 child = child.nextSiblingElement();
1727 continue;
1728 }
1729
1730 // check for duplicates
1731 if ( keys.contains( connectionName ) && prompt )
1732 {
1733 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 );
1734
1735 switch ( res )
1736 {
1737 case QMessageBox::Cancel:
1738 return;
1739 case QMessageBox::No:
1740 child = child.nextSiblingElement();
1741 continue;
1742 case QMessageBox::Yes:
1743 overwrite = true;
1744 break;
1745 case QMessageBox::YesToAll:
1746 prompt = false;
1747 overwrite = true;
1748 break;
1749 case QMessageBox::NoToAll:
1750 prompt = false;
1751 overwrite = false;
1752 break;
1753 }
1754 }
1755
1756 if ( keys.contains( connectionName ) )
1757 {
1758 if ( !overwrite )
1759 {
1760 child = child.nextSiblingElement();
1761 continue;
1762 }
1763 }
1764 else
1765 {
1766 keys << connectionName;
1767 }
1768
1769 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( u"provider"_s ), connectionName );
1770 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
1771 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
1772 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
1773 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
1774
1775 QgsHttpHeaders httpHeader( child );
1776 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1777
1778 child = child.nextSiblingElement();
1779 }
1780}
1781
1782void QgsManageConnectionsDialog::loadSensorThingsConnections( const QDomDocument &doc, const QStringList &items )
1783{
1784 const QDomElement root = doc.documentElement();
1785 if ( root.tagName() != "qgsSensorThingsConnections"_L1 )
1786 {
1787 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
1788 return;
1789 }
1790
1791 QString connectionName;
1792 QgsSettings settings;
1793 settings.beginGroup( u"/connections/sensorthings/items"_s );
1794 QStringList keys = settings.childGroups();
1795 settings.endGroup();
1796 QDomElement child = root.firstChildElement();
1797 bool prompt = true;
1798 bool overwrite = true;
1799
1800 while ( !child.isNull() )
1801 {
1802 connectionName = child.attribute( u"name"_s );
1803 if ( !items.contains( connectionName ) )
1804 {
1805 child = child.nextSiblingElement();
1806 continue;
1807 }
1808
1809 // check for duplicates
1810 if ( keys.contains( connectionName ) && prompt )
1811 {
1812 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 );
1813
1814 switch ( res )
1815 {
1816 case QMessageBox::Cancel:
1817 return;
1818 case QMessageBox::No:
1819 child = child.nextSiblingElement();
1820 continue;
1821 case QMessageBox::Yes:
1822 overwrite = true;
1823 break;
1824 case QMessageBox::YesToAll:
1825 prompt = false;
1826 overwrite = true;
1827 break;
1828 case QMessageBox::NoToAll:
1829 prompt = false;
1830 overwrite = false;
1831 break;
1832 }
1833 }
1834
1835 if ( keys.contains( connectionName ) )
1836 {
1837 if ( !overwrite )
1838 {
1839 child = child.nextSiblingElement();
1840 continue;
1841 }
1842 }
1843 else
1844 {
1845 keys << connectionName;
1846 }
1847
1848 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
1849 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
1850 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
1851 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
1852
1853 QgsHttpHeaders httpHeader( child );
1854 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1855
1856 child = child.nextSiblingElement();
1857 }
1858}
1859
1860void QgsManageConnectionsDialog::loadCloudStorageConnections( const QDomDocument &doc, const QStringList &items )
1861{
1862 const QDomElement root = doc.documentElement();
1863 if ( root.tagName() != "qgsCloudStorageConnections"_L1 )
1864 {
1865 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
1866 return;
1867 }
1868
1869 QString connectionName;
1870 QgsSettings settings;
1871 settings.beginGroup( u"/connections/cloud/items"_s );
1872 QStringList keys = settings.childGroups();
1873 settings.endGroup();
1874 QDomElement child = root.firstChildElement();
1875 bool prompt = true;
1876 bool overwrite = true;
1877
1878 while ( !child.isNull() )
1879 {
1880 connectionName = child.attribute( u"name"_s );
1881 if ( !items.contains( connectionName ) )
1882 {
1883 child = child.nextSiblingElement();
1884 continue;
1885 }
1886
1887 // check for duplicates
1888 if ( keys.contains( connectionName ) && prompt )
1889 {
1890 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 );
1891
1892 switch ( res )
1893 {
1894 case QMessageBox::Cancel:
1895 return;
1896 case QMessageBox::No:
1897 child = child.nextSiblingElement();
1898 continue;
1899 case QMessageBox::Yes:
1900 overwrite = true;
1901 break;
1902 case QMessageBox::YesToAll:
1903 prompt = false;
1904 overwrite = true;
1905 break;
1906 case QMessageBox::NoToAll:
1907 prompt = false;
1908 overwrite = false;
1909 break;
1910 }
1911 }
1912
1913 if ( keys.contains( connectionName ) )
1914 {
1915 if ( !overwrite )
1916 {
1917 child = child.nextSiblingElement();
1918 continue;
1919 }
1920 }
1921 else
1922 {
1923 keys << connectionName;
1924 }
1925
1926 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( u"handler"_s ), connectionName );
1927 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( u"container"_s ), connectionName );
1928 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( u"path"_s ), connectionName );
1929
1930 QString credentialString = child.attribute( u"credentials"_s );
1931
1932 QVariantMap credentialOptions;
1933 while ( true )
1934 {
1935 const thread_local QRegularExpression credentialOptionRegex( u"\\|credential:([^|]*)"_s );
1936 const thread_local QRegularExpression credentialOptionKeyValueRegex( u"(.*?)=(.*)"_s );
1937
1938 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1939 if ( match.hasMatch() )
1940 {
1941 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1942 if ( keyValueMatch.hasMatch() )
1943 {
1944 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1945 }
1946 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1947 }
1948 else
1949 {
1950 break;
1951 }
1952 }
1953
1954 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1955
1956 child = child.nextSiblingElement();
1957 }
1958}
1959
1960void QgsManageConnectionsDialog::loadStacConnections( const QDomDocument &doc, const QStringList &items )
1961{
1962 const QDomElement root = doc.documentElement();
1963 if ( root.tagName() != "qgsStacConnections"_L1 )
1964 {
1965 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
1966 return;
1967 }
1968
1969 QString connectionName;
1970 QgsSettings settings;
1971 settings.beginGroup( u"/qgis/connections-stac"_s );
1972 QStringList keys = settings.childGroups();
1973 settings.endGroup();
1974 QDomElement child = root.firstChildElement();
1975 bool prompt = true;
1976 bool overwrite = true;
1977
1978 while ( !child.isNull() )
1979 {
1980 connectionName = child.attribute( u"name"_s );
1981 if ( !items.contains( connectionName ) )
1982 {
1983 child = child.nextSiblingElement();
1984 continue;
1985 }
1986
1987 // check for duplicates
1988 if ( keys.contains( connectionName ) && prompt )
1989 {
1990 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 );
1991
1992 switch ( res )
1993 {
1994 case QMessageBox::Cancel:
1995 return;
1996 case QMessageBox::No:
1997 child = child.nextSiblingElement();
1998 continue;
1999 case QMessageBox::Yes:
2000 overwrite = true;
2001 break;
2002 case QMessageBox::YesToAll:
2003 prompt = false;
2004 overwrite = true;
2005 break;
2006 case QMessageBox::NoToAll:
2007 prompt = false;
2008 overwrite = false;
2009 break;
2010 }
2011 }
2012
2013 if ( keys.contains( connectionName ) )
2014 {
2015 if ( !overwrite )
2016 {
2017 child = child.nextSiblingElement();
2018 continue;
2019 }
2020 }
2021 else
2022 {
2023 keys << connectionName;
2024 }
2025
2026 QgsStacConnection::settingsUrl->setValue( child.attribute( u"url"_s ), connectionName );
2027 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( u"authcfg"_s ), connectionName );
2028 QgsStacConnection::settingsUsername->setValue( child.attribute( u"username"_s ), connectionName );
2029 QgsStacConnection::settingsPassword->setValue( child.attribute( u"password"_s ), connectionName );
2030
2031 QgsHttpHeaders httpHeader( child );
2032 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2033
2034 child = child.nextSiblingElement();
2035 }
2036}
2037
2039{
2040 listConnections->selectAll();
2041 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2042}
2043
2045{
2046 listConnections->clearSelection();
2047 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
2048}
DpiMode
DpiMode enum.
Definition qgis.h:3417
@ Post
POST method.
Definition qgis.h:1058
@ Get
GET method.
Definition qgis.h:1057
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