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::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 );
971 case QMessageBox::Cancel:
973 case QMessageBox::No:
974 child = child.nextSiblingElement();
976 case QMessageBox::Yes:
979 case QMessageBox::YesToAll:
983 case QMessageBox::NoToAll:
992 child = child.nextSiblingElement();
1005 QgsHttpHeaders httpHeader( child );
1008 if ( !child.attribute( u
"username"_s ).isEmpty() )
1013 child = child.nextSiblingElement();
1017void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
1019 const QDomElement root = doc.documentElement();
1020 if ( root.tagName() !=
"qgsWFSConnections"_L1 )
1022 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WFS connections exchange file." ) );
1026 QString connectionName;
1029 QDomElement child = root.firstChildElement();
1031 bool overwrite =
true;
1033 while ( !child.isNull() )
1035 connectionName = child.attribute( u
"name"_s );
1036 if ( !items.contains( connectionName ) )
1038 child = child.nextSiblingElement();
1043 if ( keys.contains( connectionName ) && prompt )
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 );
1049 case QMessageBox::Cancel:
1051 case QMessageBox::No:
1052 child = child.nextSiblingElement();
1054 case QMessageBox::Yes:
1057 case QMessageBox::YesToAll:
1061 case QMessageBox::NoToAll:
1068 if ( keys.contains( connectionName ) )
1072 child = child.nextSiblingElement();
1078 keys << connectionName;
1093 if ( !child.attribute( u
"username"_s ).isEmpty() )
1098 child = child.nextSiblingElement();
1102void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1104 const QDomElement root = doc.documentElement();
1105 if ( root.tagName() !=
"qgsPgConnections"_L1 )
1107 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a PostGIS connections exchange file." ) );
1111 QString connectionName;
1112 QgsSettings settings;
1113 settings.
beginGroup( u
"/PostgreSQL/connections"_s );
1116 QDomElement child = root.firstChildElement();
1118 bool overwrite =
true;
1120 while ( !child.isNull() )
1122 connectionName = child.attribute( u
"name"_s );
1123 if ( !items.contains( connectionName ) )
1125 child = child.nextSiblingElement();
1130 if ( keys.contains( connectionName ) && prompt )
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 );
1135 case QMessageBox::Cancel:
1137 case QMessageBox::No:
1138 child = child.nextSiblingElement();
1140 case QMessageBox::Yes:
1143 case QMessageBox::YesToAll:
1147 case QMessageBox::NoToAll:
1154 if ( keys.contains( connectionName ) )
1158 child = child.nextSiblingElement();
1164 keys << connectionName;
1168 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
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 ) )
1175 settings.
setValue( u
"/service"_s, child.attribute( u
"service"_s ) );
1179 settings.
setValue( u
"/service"_s,
"" );
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 ) );
1195 child = child.nextSiblingElement();
1199void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1201 const QDomElement root = doc.documentElement();
1202 if ( root.tagName() !=
"qgsMssqlConnections"_L1 )
1204 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a MS SQL Server connections exchange file." ) );
1208 QString connectionName;
1209 QgsSettings settings;
1210 settings.
beginGroup( u
"/MSSQL/connections"_s );
1213 QDomElement child = root.firstChildElement();
1215 bool overwrite =
true;
1217 while ( !child.isNull() )
1219 connectionName = child.attribute( u
"name"_s );
1220 if ( !items.contains( connectionName ) )
1222 child = child.nextSiblingElement();
1227 if ( keys.contains( connectionName ) && prompt )
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 );
1232 case QMessageBox::Cancel:
1234 case QMessageBox::No:
1235 child = child.nextSiblingElement();
1237 case QMessageBox::Yes:
1240 case QMessageBox::YesToAll:
1244 case QMessageBox::NoToAll:
1251 if ( keys.contains( connectionName ) )
1255 child = child.nextSiblingElement();
1261 keys << connectionName;
1265 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
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 ) )
1272 settings.
setValue( u
"/service"_s, child.attribute( u
"service"_s ) );
1276 settings.
setValue( u
"/service"_s,
"" );
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 ) );
1286 child = child.nextSiblingElement();
1290void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1292 const QDomElement root = doc.documentElement();
1293 if ( root.tagName() !=
"qgsOracleConnections"_L1 )
1295 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not an Oracle connections exchange file." ) );
1299 QString connectionName;
1300 QgsSettings settings;
1301 settings.
beginGroup( u
"/Oracle/connections"_s );
1304 QDomElement child = root.firstChildElement();
1306 bool overwrite =
true;
1308 while ( !child.isNull() )
1310 connectionName = child.attribute( u
"name"_s );
1311 if ( !items.contains( connectionName ) )
1313 child = child.nextSiblingElement();
1318 if ( keys.contains( connectionName ) && prompt )
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 );
1323 case QMessageBox::Cancel:
1325 case QMessageBox::No:
1326 child = child.nextSiblingElement();
1328 case QMessageBox::Yes:
1331 case QMessageBox::YesToAll:
1335 case QMessageBox::NoToAll:
1342 if ( keys.contains( connectionName ) )
1346 child = child.nextSiblingElement();
1352 keys << connectionName;
1356 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
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 ) );
1374 child = child.nextSiblingElement();
1378void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1380 QDomElement root = doc.documentElement();
1381 if ( root.tagName() !=
"qgsHanaConnections"_L1 )
1383 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The file is not a HANA connections exchange file." ) );
1387 const QDomAttr version = root.attributeNode(
"version" );
1388 if ( version.value() !=
"1.0"_L1 )
1390 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1394 QgsSettings settings;
1395 settings.
beginGroup( u
"/HANA/connections"_s );
1398 QDomElement child = root.firstChildElement();
1400 bool overwrite =
true;
1402 while ( !child.isNull() )
1404 const QString connectionName = child.attribute( u
"name"_s );
1405 if ( !items.contains( connectionName ) )
1407 child = child.nextSiblingElement();
1412 if ( keys.contains( connectionName ) && prompt )
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 );
1417 case QMessageBox::Cancel:
1419 case QMessageBox::No:
1420 child = child.nextSiblingElement();
1422 case QMessageBox::Yes:
1425 case QMessageBox::YesToAll:
1429 case QMessageBox::NoToAll:
1436 if ( keys.contains( connectionName ) )
1440 child = child.nextSiblingElement();
1446 keys << connectionName;
1450 settings.
beginGroup(
"/HANA/connections/" + connectionName );
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"
1457 settings.
setValue( u
"/"_s + param, child.attribute( param ) );
1461 child = child.nextSiblingElement();
1465void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1467 const QDomElement root = doc.documentElement();
1468 if ( root.tagName() !=
"qgsXYZTilesConnections"_L1 )
1470 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1474 QString connectionName;
1476 QDomElement child = root.firstChildElement();
1478 bool overwrite =
true;
1480 while ( !child.isNull() )
1482 connectionName = child.attribute( u
"name"_s );
1483 if ( !items.contains( connectionName ) )
1485 child = child.nextSiblingElement();
1490 if ( keys.contains( connectionName ) && prompt )
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 );
1496 case QMessageBox::Cancel:
1498 case QMessageBox::No:
1499 child = child.nextSiblingElement();
1501 case QMessageBox::Yes:
1504 case QMessageBox::YesToAll:
1508 case QMessageBox::NoToAll:
1515 if ( keys.contains( connectionName ) )
1519 child = child.nextSiblingElement();
1525 keys << connectionName;
1537 QgsHttpHeaders httpHeader( child );
1540 child = child.nextSiblingElement();
1544void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1546 const QDomElement root = doc.documentElement();
1547 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1549 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1553 QString connectionName;
1555 QDomElement child = root.firstChildElement();
1557 bool overwrite =
true;
1559 while ( !child.isNull() )
1561 connectionName = child.attribute( u
"name"_s );
1562 if ( !items.contains( connectionName ) )
1564 child = child.nextSiblingElement();
1569 if ( keys.contains( connectionName ) && prompt )
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 );
1575 case QMessageBox::Cancel:
1577 case QMessageBox::No:
1578 child = child.nextSiblingElement();
1580 case QMessageBox::Yes:
1583 case QMessageBox::YesToAll:
1587 case QMessageBox::NoToAll:
1594 if ( keys.contains( connectionName ) )
1598 child = child.nextSiblingElement();
1604 keys << connectionName;
1617 child = child.nextSiblingElement();
1621void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1623 const QDomElement root = doc.documentElement();
1624 if ( root.tagName() !=
"qgsVectorTileConnections"_L1 )
1626 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a Vector Tile connections exchange file." ) );
1630 QString connectionName;
1631 QgsSettings settings;
1632 settings.
beginGroup( u
"/qgis/connections-vector-tile"_s );
1635 QDomElement child = root.firstChildElement();
1637 bool overwrite =
true;
1639 while ( !child.isNull() )
1641 connectionName = child.attribute( u
"name"_s );
1642 if ( !items.contains( connectionName ) )
1644 child = child.nextSiblingElement();
1649 if ( keys.contains( connectionName ) && prompt )
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 );
1655 case QMessageBox::Cancel:
1657 case QMessageBox::No:
1658 child = child.nextSiblingElement();
1660 case QMessageBox::Yes:
1663 case QMessageBox::YesToAll:
1667 case QMessageBox::NoToAll:
1674 if ( keys.contains( connectionName ) )
1678 child = child.nextSiblingElement();
1684 keys << connectionName;
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 );
1696 QgsHttpHeaders httpHeader( child );
1697 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1699 child = child.nextSiblingElement();
1703void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1705 const QDomElement root = doc.documentElement();
1706 if ( root.tagName() !=
"qgsTiledSceneConnections"_L1 )
1708 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a tiled scene connections exchange file." ) );
1712 QString connectionName;
1713 QgsSettings settings;
1714 settings.
beginGroup( u
"/qgis/connections-tiled-scene"_s );
1717 QDomElement child = root.firstChildElement();
1719 bool overwrite =
true;
1721 while ( !child.isNull() )
1723 connectionName = child.attribute( u
"name"_s );
1724 if ( !items.contains( connectionName ) )
1726 child = child.nextSiblingElement();
1731 if ( keys.contains( connectionName ) && prompt )
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 );
1737 case QMessageBox::Cancel:
1739 case QMessageBox::No:
1740 child = child.nextSiblingElement();
1742 case QMessageBox::Yes:
1745 case QMessageBox::YesToAll:
1749 case QMessageBox::NoToAll:
1756 if ( keys.contains( connectionName ) )
1760 child = child.nextSiblingElement();
1766 keys << connectionName;
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 );
1775 QgsHttpHeaders httpHeader( child );
1776 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1778 child = child.nextSiblingElement();
1782void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1784 const QDomElement root = doc.documentElement();
1785 if ( root.tagName() !=
"qgsSensorThingsConnections"_L1 )
1787 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a SensorThings connections exchange file." ) );
1791 QString connectionName;
1792 QgsSettings settings;
1793 settings.
beginGroup( u
"/connections/sensorthings/items"_s );
1796 QDomElement child = root.firstChildElement();
1798 bool overwrite =
true;
1800 while ( !child.isNull() )
1802 connectionName = child.attribute( u
"name"_s );
1803 if ( !items.contains( connectionName ) )
1805 child = child.nextSiblingElement();
1810 if ( keys.contains( connectionName ) && prompt )
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 );
1816 case QMessageBox::Cancel:
1818 case QMessageBox::No:
1819 child = child.nextSiblingElement();
1821 case QMessageBox::Yes:
1824 case QMessageBox::YesToAll:
1828 case QMessageBox::NoToAll:
1835 if ( keys.contains( connectionName ) )
1839 child = child.nextSiblingElement();
1845 keys << connectionName;
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 );
1853 QgsHttpHeaders httpHeader( child );
1854 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1856 child = child.nextSiblingElement();
1860void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1862 const QDomElement root = doc.documentElement();
1863 if ( root.tagName() !=
"qgsCloudStorageConnections"_L1 )
1865 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a cloud storage connections exchange file." ) );
1869 QString connectionName;
1870 QgsSettings settings;
1871 settings.
beginGroup( u
"/connections/cloud/items"_s );
1874 QDomElement child = root.firstChildElement();
1876 bool overwrite =
true;
1878 while ( !child.isNull() )
1880 connectionName = child.attribute( u
"name"_s );
1881 if ( !items.contains( connectionName ) )
1883 child = child.nextSiblingElement();
1888 if ( keys.contains( connectionName ) && prompt )
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 );
1894 case QMessageBox::Cancel:
1896 case QMessageBox::No:
1897 child = child.nextSiblingElement();
1899 case QMessageBox::Yes:
1902 case QMessageBox::YesToAll:
1906 case QMessageBox::NoToAll:
1913 if ( keys.contains( connectionName ) )
1917 child = child.nextSiblingElement();
1923 keys << connectionName;
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 );
1930 QString credentialString = child.attribute( u
"credentials"_s );
1932 QVariantMap credentialOptions;
1935 const thread_local QRegularExpression credentialOptionRegex( u
"\\|credential:([^|]*)"_s );
1936 const thread_local QRegularExpression credentialOptionKeyValueRegex( u
"(.*?)=(.*)"_s );
1938 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1939 if ( match.hasMatch() )
1941 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1942 if ( keyValueMatch.hasMatch() )
1944 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1946 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1954 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1956 child = child.nextSiblingElement();
1960void QgsManageConnectionsDialog::loadStacConnections(
const QDomDocument &doc,
const QStringList &items )
1962 const QDomElement root = doc.documentElement();
1963 if ( root.tagName() !=
"qgsStacConnections"_L1 )
1965 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a STAC connections exchange file." ) );
1969 QString connectionName;
1970 QgsSettings settings;
1971 settings.
beginGroup( u
"/qgis/connections-stac"_s );
1974 QDomElement child = root.firstChildElement();
1976 bool overwrite =
true;
1978 while ( !child.isNull() )
1980 connectionName = child.attribute( u
"name"_s );
1981 if ( !items.contains( connectionName ) )
1983 child = child.nextSiblingElement();
1988 if ( keys.contains( connectionName ) && prompt )
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 );
1994 case QMessageBox::Cancel:
1996 case QMessageBox::No:
1997 child = child.nextSiblingElement();
1999 case QMessageBox::Yes:
2002 case QMessageBox::YesToAll:
2006 case QMessageBox::NoToAll:
2013 if ( keys.contains( connectionName ) )
2017 child = child.nextSiblingElement();
2023 keys << connectionName;
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 );
2031 QgsHttpHeaders httpHeader( child );
2032 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2034 child = child.nextSiblingElement();
2040 listConnections->selectAll();
2041 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2046 listConnections->clearSelection();
2047 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