19#include "qgsgdalcloudconnection.h"
26#include "qgsstacconnection.h"
37#include "moc_qgsmanageconnectionsdialog.cpp"
39using namespace Qt::StringLiterals;
43 , mFileName( fileName )
45 , mConnectionType( type )
50 QPushButton *pb =
nullptr;
51 pb =
new QPushButton( tr(
"Select All" ) );
52 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
55 pb =
new QPushButton( tr(
"Clear Selection" ) );
56 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
59 if ( mDialogMode ==
Import )
61 label->setText( tr(
"Select connections to import" ) );
62 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
63 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
68 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
69 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
72 if ( !populateConnections() )
74 QApplication::postEvent(
this,
new QCloseEvent() );
78 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
86 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
91 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
92 if ( selection.isEmpty() )
94 QMessageBox::warning(
this, tr(
"Export/Import Error" ), tr(
"You should select at least one connection from list." ) );
99 items.reserve( selection.size() );
100 for (
int i = 0; i < selection.size(); ++i )
102 items.append( selection.at( i )->text() );
105 if ( mDialogMode ==
Export )
107 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
111 if ( fileName.isEmpty() )
117 if ( !fileName.endsWith(
".xml"_L1, Qt::CaseInsensitive ) )
119 fileName +=
".xml"_L1;
122 mFileName = fileName;
125 switch ( mConnectionType )
128 doc = saveOWSConnections( items, u
"WMS"_s );
131 doc = saveWfsConnections( items );
134 doc = savePgConnections( items );
137 doc = saveMssqlConnections( items );
140 doc = saveOWSConnections( items, u
"WCS"_s );
143 doc = saveOracleConnections( items );
146 doc = saveHanaConnections( items );
149 doc = saveXyzTilesConnections( items );
153 doc = saveArcgisConnections( items );
156 doc = saveVectorTileConnections( items );
159 doc = saveTiledSceneConnections( items );
162 doc = saveSensorThingsConnections( items );
165 doc = saveCloudStorageConnections( items );
168 doc = saveStacConnections( items );
172 QFile file( mFileName );
173 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
175 QMessageBox::warning(
this, tr(
"Saving Connections" ), tr(
"Cannot write file %1:\n%2." ).arg( mFileName, file.errorString() ) );
179 QTextStream out( &file );
184 QFile file( mFileName );
185 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
187 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
196 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
198 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
202 switch ( mConnectionType )
205 loadOWSConnections( doc, items, u
"WMS"_s );
208 loadWfsConnections( doc, items );
211 loadPgConnections( doc, items );
214 loadMssqlConnections( doc, items );
217 loadOWSConnections( doc, items, u
"WCS"_s );
220 loadOracleConnections( doc, items );
223 loadHanaConnections( doc, items );
226 loadXyzTilesConnections( doc, items );
229 loadArcgisConnections( doc, items, u
"ARCGISMAPSERVER"_s );
232 loadArcgisConnections( doc, items, u
"ARCGISFEATURESERVER"_s );
235 loadVectorTileConnections( doc, items );
238 loadTiledSceneConnections( doc, items );
241 loadSensorThingsConnections( doc, items );
244 loadCloudStorageConnections( doc, items );
247 loadStacConnections( doc, items );
251 listConnections->clear();
258bool QgsManageConnectionsDialog::populateConnections()
261 if ( mDialogMode ==
Export )
263 QStringList connections;
265 switch ( mConnectionType )
277 settings.
beginGroup( u
"/PostgreSQL/connections"_s );
281 settings.
beginGroup( u
"/MSSQL/connections"_s );
285 settings.
beginGroup( u
"/Oracle/connections"_s );
289 settings.
beginGroup( u
"/HANA/connections"_s );
300 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
303 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
306 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
309 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
312 connections = QgsStacConnection::sTreeConnectionStac->items();
315 for (
const QString &connection : std::as_const( connections ) )
317 QListWidgetItem *item =
new QListWidgetItem();
318 item->setText( connection );
319 listConnections->addItem( item );
325 QFile file( mFileName );
326 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
328 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
337 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
339 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
343 const QDomElement root = doc.documentElement();
344 switch ( mConnectionType )
347 if ( root.tagName() !=
"qgsWMSConnections"_L1 )
349 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WMS connections exchange file." ) );
355 if ( root.tagName() !=
"qgsWFSConnections"_L1 )
357 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WFS connections exchange file." ) );
363 if ( root.tagName() !=
"qgsWCSConnections"_L1 )
365 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WCS connections exchange file." ) );
371 if ( root.tagName() !=
"qgsPgConnections"_L1 )
373 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a PostGIS connections exchange file." ) );
379 if ( root.tagName() !=
"qgsMssqlConnections"_L1 )
381 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a MS SQL Server connections exchange file." ) );
386 if ( root.tagName() !=
"qgsOracleConnections"_L1 )
388 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not an Oracle connections exchange file." ) );
393 if ( root.tagName() !=
"qgsHanaConnections"_L1 )
395 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The file is not a HANA connections exchange file." ) );
400 if ( root.tagName() !=
"qgsXYZTilesConnections"_L1 )
402 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a XYZ Tiles connections exchange file." ) );
407 if ( root.tagName() !=
"qgsARCGISMAPSERVERConnections"_L1 )
409 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a ArcGIS Map Service connections exchange file." ) );
414 if ( root.tagName() !=
"qgsARCGISFEATURESERVERConnections"_L1 )
416 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
421 if ( root.tagName() !=
"qgsVectorTileConnections"_L1 )
423 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a Vector Tile connections exchange file." ) );
428 if ( root.tagName() !=
"qgsTiledSceneConnections"_L1 )
430 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a tiled scene connections exchange file." ) );
435 if ( root.tagName() !=
"qgsSensorThingsConnections"_L1 )
437 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a SensorThings connections exchange file." ) );
442 if ( root.tagName() !=
"qgsCloudStorageConnections"_L1 )
444 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a cloud storage connections exchange file." ) );
449 if ( root.tagName() !=
"qgsStacConnections"_L1 )
451 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a STAC connections exchange file." ) );
457 QDomElement child = root.firstChildElement();
458 while ( !child.isNull() )
460 QListWidgetItem *item =
new QListWidgetItem();
461 item->setText( child.attribute( u
"name"_s ) );
462 listConnections->addItem( item );
463 child = child.nextSiblingElement();
469static void addNamespaceDeclarations( QDomElement &root,
const QMap<QString, QString> &namespaceDeclarations )
471 for (
auto it = namespaceDeclarations.begin(); it != namespaceDeclarations.end(); ++it )
473 root.setAttribute( u
"xmlns:"_s + it.key(), it.value() );
477QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
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 );
484 QMap<QString, QString> namespaceDeclarations;
485 for (
int i = 0; i < connections.count(); ++i )
487 QDomElement el = doc.createElement( service.toLower() );
488 el.setAttribute( u
"name"_s, connections[i] );
491 if ( service ==
"WMS"_L1 )
501 httpHeader.updateDomElement( el, namespaceDeclarations );
506 root.appendChild( el );
509 addNamespaceDeclarations( root, namespaceDeclarations );
514QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
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 );
521 for (
int i = 0; i < connections.count(); ++i )
523 QDomElement el = doc.createElement( u
"wfs"_s );
524 el.setAttribute( u
"name"_s, connections[i] );
537 root.appendChild( el );
543QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
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 );
550 const QgsSettings settings;
552 for (
int i = 0; i < connections.count(); ++i )
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() );
571 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() ==
"true"_L1 )
573 el.setAttribute( u
"username"_s, settings.
value( path +
"/username" ).toString() );
576 el.setAttribute( u
"savePassword"_s, settings.
value( path +
"/savePassword",
"false" ).toString() );
578 if ( settings.
value( path +
"/savePassword",
"false" ).toString() ==
"true"_L1 )
580 el.setAttribute( u
"password"_s, settings.
value( path +
"/password" ).toString() );
583 root.appendChild( el );
589QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
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 );
596 const QgsSettings settings;
598 for (
int i = 0; i < connections.count(); ++i )
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() );
610 el.setAttribute( u
"saveUsername"_s, settings.
value( path +
"/saveUsername",
"false" ).toString() );
612 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() ==
"true"_L1 )
614 el.setAttribute( u
"username"_s, settings.
value( path +
"/username" ).toString() );
617 el.setAttribute( u
"savePassword"_s, settings.
value( path +
"/savePassword",
"false" ).toString() );
619 if ( settings.
value( path +
"/savePassword",
"false" ).toString() ==
"true"_L1 )
621 el.setAttribute( u
"password"_s, settings.
value( path +
"/password" ).toString() );
624 root.appendChild( el );
630QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
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 );
637 const QgsSettings settings;
639 for (
int i = 0; i < connections.count(); ++i )
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() );
655 el.setAttribute( u
"saveUsername"_s, settings.
value( path +
"/saveUsername",
"false" ).toString() );
657 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() ==
"true"_L1 )
659 el.setAttribute( u
"username"_s, settings.
value( path +
"/username" ).toString() );
662 el.setAttribute( u
"savePassword"_s, settings.
value( path +
"/savePassword",
"false" ).toString() );
664 if ( settings.
value( path +
"/savePassword",
"false" ).toString() ==
"true"_L1 )
666 el.setAttribute( u
"password"_s, settings.
value( path +
"/password" ).toString() );
669 root.appendChild( el );
675QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
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 );
682 const QgsSettings settings;
684 for (
int i = 0; i < connections.count(); ++i )
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() );
699 el.setAttribute( u
"saveUsername"_s, settings.
value( path +
"/saveUsername", u
"false"_s ).toString() );
700 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() ==
"true"_L1 )
702 el.setAttribute( u
"username"_s, settings.
value( path +
"/username", QString() ).toString() );
705 el.setAttribute( u
"savePassword"_s, settings.
value( path +
"/savePassword", u
"false"_s ).toString() );
706 if ( settings.
value( path +
"/savePassword",
"false" ).toString() ==
"true"_L1 )
708 el.setAttribute( u
"password"_s, settings.
value( path +
"/password", QString() ).toString() );
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() );
718 root.appendChild( el );
724QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
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 );
731 QMap<QString, QString> namespaceDeclarations;
732 for (
int i = 0; i < connections.count(); ++i )
734 QDomElement el = doc.createElement( u
"xyztiles"_s );
736 el.setAttribute( u
"name"_s, connections[i] );
746 httpHeader.updateDomElement( el, namespaceDeclarations );
748 root.appendChild( el );
751 addNamespaceDeclarations( root, namespaceDeclarations );
756QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections )
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 );
763 QMap<QString, QString> namespaceDeclarations;
764 for (
const QString &connection : connections )
766 QDomElement el = doc.createElement( u
"arcgisfeatureserver"_s );
767 el.setAttribute( u
"name"_s, connection );
771 httpHeader.updateDomElement( el, namespaceDeclarations );
777 root.appendChild( el );
780 addNamespaceDeclarations( root, namespaceDeclarations );
785QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
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 );
792 QMap<QString, QString> namespaceDeclarations;
793 for (
int i = 0; i < connections.count(); ++i )
795 QDomElement el = doc.createElement( u
"vectortile"_s );
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] ) );
807 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[i] ) );
808 httpHeader.updateDomElement( el, namespaceDeclarations );
810 root.appendChild( el );
813 addNamespaceDeclarations( root, namespaceDeclarations );
818QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections(
const QStringList &connections )
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 );
825 QMap<QString, QString> namespaceDeclarations;
826 for (
int i = 0; i < connections.count(); ++i )
828 QDomElement el = doc.createElement( u
"tiledscene"_s );
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] ) );
837 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
838 httpHeader.updateDomElement( el, namespaceDeclarations );
840 root.appendChild( el );
843 addNamespaceDeclarations( root, namespaceDeclarations );
848QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections(
const QStringList &connections )
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 );
855 QMap<QString, QString> namespaceDeclarations;
856 for (
int i = 0; i < connections.count(); ++i )
858 QDomElement el = doc.createElement( u
"sensorthings"_s );
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] ) );
866 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
867 httpHeader.updateDomElement( el, namespaceDeclarations );
869 root.appendChild( el );
872 addNamespaceDeclarations( root, namespaceDeclarations );
878QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections(
const QStringList &connections )
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 );
885 for (
int i = 0; i < connections.count(); ++i )
887 QDomElement el = doc.createElement( u
"cloudstorage"_s );
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] ) );
894 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[i] );
895 QString credentialString;
896 for (
auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
898 if ( !it.value().toString().isEmpty() )
900 credentialString += u
"|credential:%1=%2"_s.arg( it.key(), it.value().toString() );
903 el.setAttribute( u
"credentials"_s, credentialString );
905 root.appendChild( el );
911QDomDocument QgsManageConnectionsDialog::saveStacConnections(
const QStringList &connections )
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 );
918 QMap<QString, QString> namespaceDeclarations;
919 for (
int i = 0; i < connections.count(); ++i )
921 QDomElement el = doc.createElement( u
"stac"_s );
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] ) );
929 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[i] ) );
930 httpHeader.updateDomElement( el, namespaceDeclarations );
932 root.appendChild( el );
935 addNamespaceDeclarations( root, namespaceDeclarations );
940void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
942 const QDomElement root = doc.documentElement();
943 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
945 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
949 QString connectionName;
951 QDomElement child = root.firstChildElement();
953 bool overwrite =
true;
955 while ( !child.isNull() )
957 connectionName = child.attribute( u
"name"_s );
958 if ( !items.contains( connectionName ) )
960 child = child.nextSiblingElement();
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 );
972 case QMessageBox::Cancel:
974 case QMessageBox::No:
975 child = child.nextSiblingElement();
977 case QMessageBox::Yes:
980 case QMessageBox::YesToAll:
984 case QMessageBox::NoToAll:
993 child = child.nextSiblingElement();
1006 QgsHttpHeaders httpHeader( child );
1009 if ( !child.attribute( u
"username"_s ).isEmpty() )
1014 child = child.nextSiblingElement();
1018void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
1020 const QDomElement root = doc.documentElement();
1021 if ( root.tagName() !=
"qgsWFSConnections"_L1 )
1023 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WFS connections exchange file." ) );
1027 QString connectionName;
1030 QDomElement child = root.firstChildElement();
1032 bool overwrite =
true;
1034 while ( !child.isNull() )
1036 connectionName = child.attribute( u
"name"_s );
1037 if ( !items.contains( connectionName ) )
1039 child = child.nextSiblingElement();
1044 if ( keys.contains( connectionName ) && prompt )
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 );
1051 case QMessageBox::Cancel:
1053 case QMessageBox::No:
1054 child = child.nextSiblingElement();
1056 case QMessageBox::Yes:
1059 case QMessageBox::YesToAll:
1063 case QMessageBox::NoToAll:
1070 if ( keys.contains( connectionName ) )
1074 child = child.nextSiblingElement();
1080 keys << connectionName;
1096 if ( !child.attribute( u
"username"_s ).isEmpty() )
1101 child = child.nextSiblingElement();
1105void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1107 const QDomElement root = doc.documentElement();
1108 if ( root.tagName() !=
"qgsPgConnections"_L1 )
1110 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a PostGIS connections exchange file." ) );
1114 QString connectionName;
1115 QgsSettings settings;
1116 settings.
beginGroup( u
"/PostgreSQL/connections"_s );
1119 QDomElement child = root.firstChildElement();
1121 bool overwrite =
true;
1123 while ( !child.isNull() )
1125 connectionName = child.attribute( u
"name"_s );
1126 if ( !items.contains( connectionName ) )
1128 child = child.nextSiblingElement();
1133 if ( keys.contains( connectionName ) && prompt )
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 );
1139 case QMessageBox::Cancel:
1141 case QMessageBox::No:
1142 child = child.nextSiblingElement();
1144 case QMessageBox::Yes:
1147 case QMessageBox::YesToAll:
1151 case QMessageBox::NoToAll:
1158 if ( keys.contains( connectionName ) )
1162 child = child.nextSiblingElement();
1168 keys << connectionName;
1172 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
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 ) )
1179 settings.
setValue( u
"/service"_s, child.attribute( u
"service"_s ) );
1183 settings.
setValue( u
"/service"_s,
"" );
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 ) );
1199 child = child.nextSiblingElement();
1203void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1205 const QDomElement root = doc.documentElement();
1206 if ( root.tagName() !=
"qgsMssqlConnections"_L1 )
1208 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a MS SQL Server connections exchange file." ) );
1212 QString connectionName;
1213 QgsSettings settings;
1214 settings.
beginGroup( u
"/MSSQL/connections"_s );
1217 QDomElement child = root.firstChildElement();
1219 bool overwrite =
true;
1221 while ( !child.isNull() )
1223 connectionName = child.attribute( u
"name"_s );
1224 if ( !items.contains( connectionName ) )
1226 child = child.nextSiblingElement();
1231 if ( keys.contains( connectionName ) && prompt )
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 );
1237 case QMessageBox::Cancel:
1239 case QMessageBox::No:
1240 child = child.nextSiblingElement();
1242 case QMessageBox::Yes:
1245 case QMessageBox::YesToAll:
1249 case QMessageBox::NoToAll:
1256 if ( keys.contains( connectionName ) )
1260 child = child.nextSiblingElement();
1266 keys << connectionName;
1270 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
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 ) )
1277 settings.
setValue( u
"/service"_s, child.attribute( u
"service"_s ) );
1281 settings.
setValue( u
"/service"_s,
"" );
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 ) );
1291 child = child.nextSiblingElement();
1295void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1297 const QDomElement root = doc.documentElement();
1298 if ( root.tagName() !=
"qgsOracleConnections"_L1 )
1300 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not an Oracle connections exchange file." ) );
1304 QString connectionName;
1305 QgsSettings settings;
1306 settings.
beginGroup( u
"/Oracle/connections"_s );
1309 QDomElement child = root.firstChildElement();
1311 bool overwrite =
true;
1313 while ( !child.isNull() )
1315 connectionName = child.attribute( u
"name"_s );
1316 if ( !items.contains( connectionName ) )
1318 child = child.nextSiblingElement();
1323 if ( keys.contains( connectionName ) && prompt )
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 );
1329 case QMessageBox::Cancel:
1331 case QMessageBox::No:
1332 child = child.nextSiblingElement();
1334 case QMessageBox::Yes:
1337 case QMessageBox::YesToAll:
1341 case QMessageBox::NoToAll:
1348 if ( keys.contains( connectionName ) )
1352 child = child.nextSiblingElement();
1358 keys << connectionName;
1362 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
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 ) );
1380 child = child.nextSiblingElement();
1384void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1386 QDomElement root = doc.documentElement();
1387 if ( root.tagName() !=
"qgsHanaConnections"_L1 )
1389 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The file is not a HANA connections exchange file." ) );
1393 const QDomAttr version = root.attributeNode(
"version" );
1394 if ( version.value() !=
"1.0"_L1 )
1396 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1400 QgsSettings settings;
1401 settings.
beginGroup( u
"/HANA/connections"_s );
1404 QDomElement child = root.firstChildElement();
1406 bool overwrite =
true;
1408 while ( !child.isNull() )
1410 const QString connectionName = child.attribute( u
"name"_s );
1411 if ( !items.contains( connectionName ) )
1413 child = child.nextSiblingElement();
1418 if ( keys.contains( connectionName ) && prompt )
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 );
1424 case QMessageBox::Cancel:
1426 case QMessageBox::No:
1427 child = child.nextSiblingElement();
1429 case QMessageBox::Yes:
1432 case QMessageBox::YesToAll:
1436 case QMessageBox::NoToAll:
1443 if ( keys.contains( connectionName ) )
1447 child = child.nextSiblingElement();
1453 keys << connectionName;
1457 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1459 for (
const QString param :
1468 "allowGeometrylessTables",
1474 "sslCryptoProvider",
1477 "sslValidateCertificate",
1478 "sslHostNameInCertificate" } )
1479 settings.
setValue( u
"/"_s + param, child.attribute( param ) );
1483 child = child.nextSiblingElement();
1487void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1489 const QDomElement root = doc.documentElement();
1490 if ( root.tagName() !=
"qgsXYZTilesConnections"_L1 )
1492 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1496 QString connectionName;
1498 QDomElement child = root.firstChildElement();
1500 bool overwrite =
true;
1502 while ( !child.isNull() )
1504 connectionName = child.attribute( u
"name"_s );
1505 if ( !items.contains( connectionName ) )
1507 child = child.nextSiblingElement();
1512 if ( keys.contains( connectionName ) && prompt )
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 );
1519 case QMessageBox::Cancel:
1521 case QMessageBox::No:
1522 child = child.nextSiblingElement();
1524 case QMessageBox::Yes:
1527 case QMessageBox::YesToAll:
1531 case QMessageBox::NoToAll:
1538 if ( keys.contains( connectionName ) )
1542 child = child.nextSiblingElement();
1548 keys << connectionName;
1560 QgsHttpHeaders httpHeader( child );
1563 child = child.nextSiblingElement();
1567void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1569 const QDomElement root = doc.documentElement();
1570 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1572 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1576 QString connectionName;
1578 QDomElement child = root.firstChildElement();
1580 bool overwrite =
true;
1582 while ( !child.isNull() )
1584 connectionName = child.attribute( u
"name"_s );
1585 if ( !items.contains( connectionName ) )
1587 child = child.nextSiblingElement();
1592 if ( keys.contains( connectionName ) && prompt )
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 );
1599 case QMessageBox::Cancel:
1601 case QMessageBox::No:
1602 child = child.nextSiblingElement();
1604 case QMessageBox::Yes:
1607 case QMessageBox::YesToAll:
1611 case QMessageBox::NoToAll:
1618 if ( keys.contains( connectionName ) )
1622 child = child.nextSiblingElement();
1628 keys << connectionName;
1641 child = child.nextSiblingElement();
1645void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1647 const QDomElement root = doc.documentElement();
1648 if ( root.tagName() !=
"qgsVectorTileConnections"_L1 )
1650 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a Vector Tile connections exchange file." ) );
1654 QString connectionName;
1655 QgsSettings settings;
1656 settings.
beginGroup( u
"/qgis/connections-vector-tile"_s );
1659 QDomElement child = root.firstChildElement();
1661 bool overwrite =
true;
1663 while ( !child.isNull() )
1665 connectionName = child.attribute( u
"name"_s );
1666 if ( !items.contains( connectionName ) )
1668 child = child.nextSiblingElement();
1673 if ( keys.contains( connectionName ) && prompt )
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 );
1680 case QMessageBox::Cancel:
1682 case QMessageBox::No:
1683 child = child.nextSiblingElement();
1685 case QMessageBox::Yes:
1688 case QMessageBox::YesToAll:
1692 case QMessageBox::NoToAll:
1699 if ( keys.contains( connectionName ) )
1703 child = child.nextSiblingElement();
1709 keys << connectionName;
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 );
1721 QgsHttpHeaders httpHeader( child );
1722 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1724 child = child.nextSiblingElement();
1728void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1730 const QDomElement root = doc.documentElement();
1731 if ( root.tagName() !=
"qgsTiledSceneConnections"_L1 )
1733 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a tiled scene connections exchange file." ) );
1737 QString connectionName;
1738 QgsSettings settings;
1739 settings.
beginGroup( u
"/qgis/connections-tiled-scene"_s );
1742 QDomElement child = root.firstChildElement();
1744 bool overwrite =
true;
1746 while ( !child.isNull() )
1748 connectionName = child.attribute( u
"name"_s );
1749 if ( !items.contains( connectionName ) )
1751 child = child.nextSiblingElement();
1756 if ( keys.contains( connectionName ) && prompt )
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 );
1763 case QMessageBox::Cancel:
1765 case QMessageBox::No:
1766 child = child.nextSiblingElement();
1768 case QMessageBox::Yes:
1771 case QMessageBox::YesToAll:
1775 case QMessageBox::NoToAll:
1782 if ( keys.contains( connectionName ) )
1786 child = child.nextSiblingElement();
1792 keys << connectionName;
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 );
1801 QgsHttpHeaders httpHeader( child );
1802 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1804 child = child.nextSiblingElement();
1808void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1810 const QDomElement root = doc.documentElement();
1811 if ( root.tagName() !=
"qgsSensorThingsConnections"_L1 )
1813 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a SensorThings connections exchange file." ) );
1817 QString connectionName;
1818 QgsSettings settings;
1819 settings.
beginGroup( u
"/connections/sensorthings/items"_s );
1822 QDomElement child = root.firstChildElement();
1824 bool overwrite =
true;
1826 while ( !child.isNull() )
1828 connectionName = child.attribute( u
"name"_s );
1829 if ( !items.contains( connectionName ) )
1831 child = child.nextSiblingElement();
1836 if ( keys.contains( connectionName ) && prompt )
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 );
1843 case QMessageBox::Cancel:
1845 case QMessageBox::No:
1846 child = child.nextSiblingElement();
1848 case QMessageBox::Yes:
1851 case QMessageBox::YesToAll:
1855 case QMessageBox::NoToAll:
1862 if ( keys.contains( connectionName ) )
1866 child = child.nextSiblingElement();
1872 keys << connectionName;
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 );
1880 QgsHttpHeaders httpHeader( child );
1881 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1883 child = child.nextSiblingElement();
1887void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1889 const QDomElement root = doc.documentElement();
1890 if ( root.tagName() !=
"qgsCloudStorageConnections"_L1 )
1892 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a cloud storage connections exchange file." ) );
1896 QString connectionName;
1897 QgsSettings settings;
1898 settings.
beginGroup( u
"/connections/cloud/items"_s );
1901 QDomElement child = root.firstChildElement();
1903 bool overwrite =
true;
1905 while ( !child.isNull() )
1907 connectionName = child.attribute( u
"name"_s );
1908 if ( !items.contains( connectionName ) )
1910 child = child.nextSiblingElement();
1915 if ( keys.contains( connectionName ) && prompt )
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 );
1922 case QMessageBox::Cancel:
1924 case QMessageBox::No:
1925 child = child.nextSiblingElement();
1927 case QMessageBox::Yes:
1930 case QMessageBox::YesToAll:
1934 case QMessageBox::NoToAll:
1941 if ( keys.contains( connectionName ) )
1945 child = child.nextSiblingElement();
1951 keys << connectionName;
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 );
1958 QString credentialString = child.attribute( u
"credentials"_s );
1960 QVariantMap credentialOptions;
1963 const thread_local QRegularExpression credentialOptionRegex( u
"\\|credential:([^|]*)"_s );
1964 const thread_local QRegularExpression credentialOptionKeyValueRegex( u
"(.*?)=(.*)"_s );
1966 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1967 if ( match.hasMatch() )
1969 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1970 if ( keyValueMatch.hasMatch() )
1972 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1974 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1982 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1984 child = child.nextSiblingElement();
1988void QgsManageConnectionsDialog::loadStacConnections(
const QDomDocument &doc,
const QStringList &items )
1990 const QDomElement root = doc.documentElement();
1991 if ( root.tagName() !=
"qgsStacConnections"_L1 )
1993 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a STAC connections exchange file." ) );
1997 QString connectionName;
1998 QgsSettings settings;
1999 settings.
beginGroup( u
"/qgis/connections-stac"_s );
2002 QDomElement child = root.firstChildElement();
2004 bool overwrite =
true;
2006 while ( !child.isNull() )
2008 connectionName = child.attribute( u
"name"_s );
2009 if ( !items.contains( connectionName ) )
2011 child = child.nextSiblingElement();
2016 if ( keys.contains( connectionName ) && prompt )
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 );
2023 case QMessageBox::Cancel:
2025 case QMessageBox::No:
2026 child = child.nextSiblingElement();
2028 case QMessageBox::Yes:
2031 case QMessageBox::YesToAll:
2035 case QMessageBox::NoToAll:
2042 if ( keys.contains( connectionName ) )
2046 child = child.nextSiblingElement();
2052 keys << connectionName;
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 );
2060 QgsHttpHeaders httpHeader( child );
2061 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2063 child = child.nextSiblingElement();
2069 listConnections->selectAll();
2070 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2075 listConnections->clearSelection();
2076 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
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.
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