25#include "moc_qgsmanageconnectionsdialog.cpp"
33#include "qgsgdalcloudconnection.h"
34#include "qgsstacconnection.h"
38 , mFileName( fileName )
40 , mConnectionType( type )
45 QPushButton *pb =
nullptr;
46 pb =
new QPushButton( tr(
"Select All" ) );
47 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
50 pb =
new QPushButton( tr(
"Clear Selection" ) );
51 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
54 if ( mDialogMode ==
Import )
56 label->setText( tr(
"Select connections to import" ) );
57 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
58 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
63 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
64 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
67 if ( !populateConnections() )
69 QApplication::postEvent(
this,
new QCloseEvent() );
73 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
81 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
86 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
87 if ( selection.isEmpty() )
89 QMessageBox::warning(
this, tr(
"Export/Import Error" ), tr(
"You should select at least one connection from list." ) );
94 items.reserve( selection.size() );
95 for (
int i = 0; i < selection.size(); ++i )
97 items.append( selection.at( i )->text() );
100 if ( mDialogMode ==
Export )
102 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
106 if ( fileName.isEmpty() )
112 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
114 fileName += QLatin1String(
".xml" );
117 mFileName = fileName;
120 switch ( mConnectionType )
123 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
126 doc = saveWfsConnections( items );
129 doc = savePgConnections( items );
132 doc = saveMssqlConnections( items );
135 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
138 doc = saveOracleConnections( items );
141 doc = saveHanaConnections( items );
144 doc = saveXyzTilesConnections( items );
148 doc = saveArcgisConnections( items );
151 doc = saveVectorTileConnections( items );
154 doc = saveTiledSceneConnections( items );
157 doc = saveSensorThingsConnections( items );
160 doc = saveCloudStorageConnections( items );
163 doc = saveStacConnections( items );
167 QFile file( mFileName );
168 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
170 QMessageBox::warning(
this, tr(
"Saving Connections" ), tr(
"Cannot write file %1:\n%2." ).arg( mFileName, file.errorString() ) );
174 QTextStream out( &file );
179 QFile file( mFileName );
180 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
182 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
191 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
193 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
197 switch ( mConnectionType )
200 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
203 loadWfsConnections( doc, items );
206 loadPgConnections( doc, items );
209 loadMssqlConnections( doc, items );
212 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
215 loadOracleConnections( doc, items );
218 loadHanaConnections( doc, items );
221 loadXyzTilesConnections( doc, items );
224 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
227 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
230 loadVectorTileConnections( doc, items );
233 loadTiledSceneConnections( doc, items );
236 loadSensorThingsConnections( doc, items );
239 loadCloudStorageConnections( doc, items );
242 loadStacConnections( doc, items );
246 listConnections->clear();
253bool QgsManageConnectionsDialog::populateConnections()
256 if ( mDialogMode ==
Export )
258 QStringList connections;
260 switch ( mConnectionType )
272 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
276 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
280 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
284 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
295 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
298 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
301 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
304 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
307 connections = QgsStacConnection::sTreeConnectionStac->items();
310 for (
const QString &connection : std::as_const( connections ) )
312 QListWidgetItem *item =
new QListWidgetItem();
313 item->setText( connection );
314 listConnections->addItem( item );
320 QFile file( mFileName );
321 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
323 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
332 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
334 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
338 const QDomElement root = doc.documentElement();
339 switch ( mConnectionType )
342 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
344 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WMS connections exchange file." ) );
350 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
352 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WFS connections exchange file." ) );
358 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
360 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WCS connections exchange file." ) );
366 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
368 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a PostGIS connections exchange file." ) );
374 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
376 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a MS SQL Server connections exchange file." ) );
381 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
383 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not an Oracle connections exchange file." ) );
388 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
390 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The file is not a HANA connections exchange file." ) );
395 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
397 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a XYZ Tiles connections exchange file." ) );
402 if ( root.tagName() != QLatin1String(
"qgsARCGISMAPSERVERConnections" ) )
404 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a ArcGIS Map Service connections exchange file." ) );
409 if ( root.tagName() != QLatin1String(
"qgsARCGISFEATURESERVERConnections" ) )
411 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
416 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
418 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a Vector Tile connections exchange file." ) );
423 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
425 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a tiled scene connections exchange file." ) );
430 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
432 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a SensorThings connections exchange file." ) );
437 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
439 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a cloud storage connections exchange file." ) );
444 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
446 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a STAC connections exchange file." ) );
452 QDomElement child = root.firstChildElement();
453 while ( !child.isNull() )
455 QListWidgetItem *item =
new QListWidgetItem();
456 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
457 listConnections->addItem( item );
458 child = child.nextSiblingElement();
464QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
466 QDomDocument doc( QStringLiteral(
"connections" ) );
467 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
468 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
469 doc.appendChild( root );
471 for (
int i = 0; i < connections.count(); ++i )
473 QDomElement el = doc.createElement( service.toLower() );
474 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
477 if ( service == QLatin1String(
"WMS" ) )
487 httpHeader.updateDomElement( el );
492 root.appendChild( el );
498QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
500 QDomDocument doc( QStringLiteral(
"connections" ) );
501 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
502 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
503 doc.appendChild( root );
505 for (
int i = 0; i < connections.count(); ++i )
507 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
508 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
519 root.appendChild( el );
525QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
527 QDomDocument doc( QStringLiteral(
"connections" ) );
528 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
529 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
530 doc.appendChild( root );
534 for (
int i = 0; i < connections.count(); ++i )
536 path =
"/PostgreSQL/connections/" + connections[i];
537 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
538 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
539 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
540 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
541 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
542 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
543 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
544 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
545 el.setAttribute( QStringLiteral(
"projectsInDatabase" ), settings.
value( path +
"/projectsInDatabase",
"0" ).toString() );
546 el.setAttribute( QStringLiteral(
"dontResolveType" ), settings.
value( path +
"/dontResolveType",
"0" ).toString() );
547 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
548 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
549 el.setAttribute( QStringLiteral(
"publicOnly" ), settings.
value( path +
"/publicOnly",
"0" ).toString() );
551 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
553 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
555 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
558 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
560 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
562 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
565 root.appendChild( el );
571QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
573 QDomDocument doc( QStringLiteral(
"connections" ) );
574 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
575 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
576 doc.appendChild( root );
580 for (
int i = 0; i < connections.count(); ++i )
582 path =
"/MSSQL/connections/" + connections[i];
583 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
584 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
585 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
586 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
587 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
588 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
589 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
590 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
592 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
594 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
596 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
599 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
601 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
603 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
606 root.appendChild( el );
612QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
614 QDomDocument doc( QStringLiteral(
"connections" ) );
615 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
616 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
617 doc.appendChild( root );
621 for (
int i = 0; i < connections.count(); ++i )
623 path =
"/Oracle/connections/" + connections[i];
624 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
625 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
626 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
627 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
628 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
629 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
630 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
631 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
632 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
633 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
634 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
635 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
637 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
639 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
641 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
644 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
646 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
648 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
651 root.appendChild( el );
657QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
659 QDomDocument doc( QStringLiteral(
"connections" ) );
660 QDomElement root = doc.createElement( QStringLiteral(
"qgsHanaConnections" ) );
661 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
662 doc.appendChild( root );
666 for (
int i = 0; i < connections.count(); ++i )
668 path =
"/HANA/connections/" + connections[i];
669 QDomElement el = doc.createElement( QStringLiteral(
"hana" ) );
670 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
671 el.setAttribute( QStringLiteral(
"driver" ), settings.
value( path +
"/driver", QString() ).toString() );
672 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host", QString() ).toString() );
673 el.setAttribute( QStringLiteral(
"identifierType" ), settings.
value( path +
"/identifierType", QString() ).toString() );
674 el.setAttribute( QStringLiteral(
"identifier" ), settings.
value( path +
"/identifier", QString() ).toString() );
675 el.setAttribute( QStringLiteral(
"multitenant" ), settings.
value( path +
"/multitenant", QString() ).toString() );
676 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database", QString() ).toString() );
677 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
678 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly", QStringLiteral(
"0" ) ).toString() );
679 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables", QStringLiteral(
"0" ) ).toString() );
681 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername", QStringLiteral(
"false" ) ).toString() );
682 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
684 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username", QString() ).toString() );
687 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword", QStringLiteral(
"false" ) ).toString() );
688 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
690 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password", QString() ).toString() );
693 el.setAttribute( QStringLiteral(
"sslEnabled" ), settings.
value( path +
"/sslEnabled", QStringLiteral(
"false" ) ).toString() );
694 el.setAttribute( QStringLiteral(
"sslCryptoProvider" ), settings.
value( path +
"/sslCryptoProvider", QStringLiteral(
"openssl" ) ).toString() );
695 el.setAttribute( QStringLiteral(
"sslKeyStore" ), settings.
value( path +
"/sslKeyStore", QString() ).toString() );
696 el.setAttribute( QStringLiteral(
"sslTrustStore" ), settings.
value( path +
"/sslTrustStore", QString() ).toString() );
697 el.setAttribute( QStringLiteral(
"sslValidateCertificate" ), settings.
value( path +
"/sslValidateCertificate", QStringLiteral(
"false" ) ).toString() );
698 el.setAttribute( QStringLiteral(
"sslHostNameInCertificate" ), settings.
value( path +
"/sslHostNameInCertificate", QString() ).toString() );
700 root.appendChild( el );
706QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
708 QDomDocument doc( QStringLiteral(
"connections" ) );
709 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
710 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
711 doc.appendChild( root );
713 for (
int i = 0; i < connections.count(); ++i )
715 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
717 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
727 httpHeader.updateDomElement( el );
729 root.appendChild( el );
735QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections )
737 QDomDocument doc( QStringLiteral(
"connections" ) );
738 QDomElement root = doc.createElement(
"qgsARCGISFEATURESERVERConnections" );
739 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
740 doc.appendChild( root );
742 for (
const QString &connection : connections )
744 QDomElement el = doc.createElement( QStringLiteral(
"arcgisfeatureserver" ) );
745 el.setAttribute( QStringLiteral(
"name" ), connection );
749 httpHeader.updateDomElement( el );
755 root.appendChild( el );
761QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
763 QDomDocument doc( QStringLiteral(
"connections" ) );
764 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
765 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
766 doc.appendChild( root );
768 for (
int i = 0; i < connections.count(); ++i )
770 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
772 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
773 el.setAttribute( QStringLiteral(
"url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[i] ) );
774 el.setAttribute( QStringLiteral(
"zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[i] ) );
775 el.setAttribute( QStringLiteral(
"zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[i] ) );
776 el.setAttribute( QStringLiteral(
"serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[i] ) );
777 el.setAttribute( QStringLiteral(
"authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[i] ) );
778 el.setAttribute( QStringLiteral(
"username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[i] ) );
779 el.setAttribute( QStringLiteral(
"password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[i] ) );
780 el.setAttribute( QStringLiteral(
"styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[i] ) );
782 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[i] ) );
783 httpHeader.updateDomElement( el );
785 root.appendChild( el );
791QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections(
const QStringList &connections )
793 QDomDocument doc( QStringLiteral(
"connections" ) );
794 QDomElement root = doc.createElement( QStringLiteral(
"qgsTiledSceneConnections" ) );
795 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
796 doc.appendChild( root );
798 for (
int i = 0; i < connections.count(); ++i )
800 QDomElement el = doc.createElement( QStringLiteral(
"tiledscene" ) );
802 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
803 el.setAttribute( QStringLiteral(
"provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[i] ) );
804 el.setAttribute( QStringLiteral(
"url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[i] ) );
805 el.setAttribute( QStringLiteral(
"authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[i] ) );
806 el.setAttribute( QStringLiteral(
"username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[i] ) );
807 el.setAttribute( QStringLiteral(
"password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[i] ) );
809 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
810 httpHeader.updateDomElement( el );
812 root.appendChild( el );
818QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections(
const QStringList &connections )
820 QDomDocument doc( QStringLiteral(
"connections" ) );
821 QDomElement root = doc.createElement( QStringLiteral(
"qgsSensorThingsConnections" ) );
822 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
823 doc.appendChild( root );
825 for (
int i = 0; i < connections.count(); ++i )
827 QDomElement el = doc.createElement( QStringLiteral(
"sensorthings" ) );
829 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
830 el.setAttribute( QStringLiteral(
"url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[i] ) );
831 el.setAttribute( QStringLiteral(
"authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[i] ) );
832 el.setAttribute( QStringLiteral(
"username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[i] ) );
833 el.setAttribute( QStringLiteral(
"password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[i] ) );
835 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
836 httpHeader.updateDomElement( el );
838 root.appendChild( el );
845QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections(
const QStringList &connections )
847 QDomDocument doc( QStringLiteral(
"connections" ) );
848 QDomElement root = doc.createElement( QStringLiteral(
"qgsCloudStorageConnections" ) );
849 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
850 doc.appendChild( root );
852 for (
int i = 0; i < connections.count(); ++i )
854 QDomElement el = doc.createElement( QStringLiteral(
"cloudstorage" ) );
856 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
857 el.setAttribute( QStringLiteral(
"handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[i] ) );
858 el.setAttribute( QStringLiteral(
"container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[i] ) );
859 el.setAttribute( QStringLiteral(
"path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[i] ) );
861 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[i] );
862 QString credentialString;
863 for (
auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
865 if ( !it.value().toString().isEmpty() )
867 credentialString += QStringLiteral(
"|credential:%1=%2" ).arg( it.key(), it.value().toString() );
870 el.setAttribute( QStringLiteral(
"credentials" ), credentialString );
872 root.appendChild( el );
878QDomDocument QgsManageConnectionsDialog::saveStacConnections(
const QStringList &connections )
880 QDomDocument doc( QStringLiteral(
"connections" ) );
881 QDomElement root = doc.createElement( QStringLiteral(
"qgsStacConnections" ) );
882 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
883 doc.appendChild( root );
885 for (
int i = 0; i < connections.count(); ++i )
887 QDomElement el = doc.createElement( QStringLiteral(
"stac" ) );
889 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
890 el.setAttribute( QStringLiteral(
"url" ), QgsStacConnection::settingsUrl->value( connections[i] ) );
891 el.setAttribute( QStringLiteral(
"authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[i] ) );
892 el.setAttribute( QStringLiteral(
"username" ), QgsStacConnection::settingsUsername->value( connections[i] ) );
893 el.setAttribute( QStringLiteral(
"password" ), QgsStacConnection::settingsPassword->value( connections[i] ) );
895 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[i] ) );
896 httpHeader.updateDomElement( el );
898 root.appendChild( el );
904void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
906 const QDomElement root = doc.documentElement();
907 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
909 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
913 QString connectionName;
915 QDomElement child = root.firstChildElement();
917 bool overwrite =
true;
919 while ( !child.isNull() )
921 connectionName = child.attribute( QStringLiteral(
"name" ) );
922 if ( !items.contains( connectionName ) )
924 child = child.nextSiblingElement();
931 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 );
935 case QMessageBox::Cancel:
937 case QMessageBox::No:
938 child = child.nextSiblingElement();
940 case QMessageBox::Yes:
943 case QMessageBox::YesToAll:
947 case QMessageBox::NoToAll:
956 child = child.nextSiblingElement();
972 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
977 child = child.nextSiblingElement();
981void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
983 const QDomElement root = doc.documentElement();
984 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
986 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a WFS connections exchange file." ) );
990 QString connectionName;
993 QDomElement child = root.firstChildElement();
995 bool overwrite =
true;
997 while ( !child.isNull() )
999 connectionName = child.attribute( QStringLiteral(
"name" ) );
1000 if ( !items.contains( connectionName ) )
1002 child = child.nextSiblingElement();
1007 if ( keys.contains( connectionName ) && prompt )
1009 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 );
1013 case QMessageBox::Cancel:
1015 case QMessageBox::No:
1016 child = child.nextSiblingElement();
1018 case QMessageBox::Yes:
1021 case QMessageBox::YesToAll:
1025 case QMessageBox::NoToAll:
1032 if ( keys.contains( connectionName ) )
1036 child = child.nextSiblingElement();
1042 keys << connectionName;
1055 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1060 child = child.nextSiblingElement();
1064void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1066 const QDomElement root = doc.documentElement();
1067 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
1069 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a PostGIS connections exchange file." ) );
1073 QString connectionName;
1075 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
1078 QDomElement child = root.firstChildElement();
1080 bool overwrite =
true;
1082 while ( !child.isNull() )
1084 connectionName = child.attribute( QStringLiteral(
"name" ) );
1085 if ( !items.contains( connectionName ) )
1087 child = child.nextSiblingElement();
1092 if ( keys.contains( connectionName ) && prompt )
1094 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 );
1097 case QMessageBox::Cancel:
1099 case QMessageBox::No:
1100 child = child.nextSiblingElement();
1102 case QMessageBox::Yes:
1105 case QMessageBox::YesToAll:
1109 case QMessageBox::NoToAll:
1116 if ( keys.contains( connectionName ) )
1120 child = child.nextSiblingElement();
1126 keys << connectionName;
1130 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1132 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1133 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1134 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1135 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1137 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1141 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1143 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1144 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1145 settings.
setValue( QStringLiteral(
"/projectsInDatabase" ), child.attribute( QStringLiteral(
"projectsInDatabase" ), 0 ) );
1146 settings.
setValue( QStringLiteral(
"/dontResolveType" ), child.attribute( QStringLiteral(
"dontResolveType" ), 0 ) );
1147 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ), 0 ) );
1148 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ), 0 ) );
1149 settings.
setValue( QStringLiteral(
"/publicOnly" ), child.attribute( QStringLiteral(
"publicOnly" ), 0 ) );
1150 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1151 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1152 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1153 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1156 child = child.nextSiblingElement();
1160void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1162 const QDomElement root = doc.documentElement();
1163 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1165 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a MS SQL Server connections exchange file." ) );
1169 QString connectionName;
1171 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1174 QDomElement child = root.firstChildElement();
1176 bool overwrite =
true;
1178 while ( !child.isNull() )
1180 connectionName = child.attribute( QStringLiteral(
"name" ) );
1181 if ( !items.contains( connectionName ) )
1183 child = child.nextSiblingElement();
1188 if ( keys.contains( connectionName ) && prompt )
1190 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 );
1193 case QMessageBox::Cancel:
1195 case QMessageBox::No:
1196 child = child.nextSiblingElement();
1198 case QMessageBox::Yes:
1201 case QMessageBox::YesToAll:
1205 case QMessageBox::NoToAll:
1212 if ( keys.contains( connectionName ) )
1216 child = child.nextSiblingElement();
1222 keys << connectionName;
1226 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1228 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1229 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1230 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1231 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1233 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1237 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1239 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1240 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1241 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1242 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1243 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1244 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1247 child = child.nextSiblingElement();
1251void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1253 const QDomElement root = doc.documentElement();
1254 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1256 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not an Oracle connections exchange file." ) );
1260 QString connectionName;
1262 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1265 QDomElement child = root.firstChildElement();
1267 bool overwrite =
true;
1269 while ( !child.isNull() )
1271 connectionName = child.attribute( QStringLiteral(
"name" ) );
1272 if ( !items.contains( connectionName ) )
1274 child = child.nextSiblingElement();
1279 if ( keys.contains( connectionName ) && prompt )
1281 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 );
1284 case QMessageBox::Cancel:
1286 case QMessageBox::No:
1287 child = child.nextSiblingElement();
1289 case QMessageBox::Yes:
1292 case QMessageBox::YesToAll:
1296 case QMessageBox::NoToAll:
1303 if ( keys.contains( connectionName ) )
1307 child = child.nextSiblingElement();
1313 keys << connectionName;
1317 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1319 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1320 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1321 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1322 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1323 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1324 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1325 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1326 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1327 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1328 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1329 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1330 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1331 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1332 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1335 child = child.nextSiblingElement();
1339void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1341 QDomElement root = doc.documentElement();
1342 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
1344 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The file is not a HANA connections exchange file." ) );
1348 const QDomAttr version = root.attributeNode(
"version" );
1349 if ( version.value() != QLatin1String(
"1.0" ) )
1351 QMessageBox::warning(
this, tr(
"Loading Connections" ), tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1356 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
1359 QDomElement child = root.firstChildElement();
1361 bool overwrite =
true;
1363 while ( !child.isNull() )
1365 const QString connectionName = child.attribute( QStringLiteral(
"name" ) );
1366 if ( !items.contains( connectionName ) )
1368 child = child.nextSiblingElement();
1373 if ( keys.contains( connectionName ) && prompt )
1375 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 );
1378 case QMessageBox::Cancel:
1380 case QMessageBox::No:
1381 child = child.nextSiblingElement();
1383 case QMessageBox::Yes:
1386 case QMessageBox::YesToAll:
1390 case QMessageBox::NoToAll:
1397 if ( keys.contains( connectionName ) )
1401 child = child.nextSiblingElement();
1407 keys << connectionName;
1411 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1413 for (
const QString param :
1414 {
"driver",
"host",
"database",
"identifierType",
"identifier",
"multitenant",
"schema",
"userTablesOnly",
1415 "allowGeometrylessTables",
"saveUsername",
"username",
"savePassword",
"password",
"sslEnabled",
1416 "sslCryptoProvider",
"sslKeyStore",
"sslTrustStore",
"sslValidateCertificate",
"sslHostNameInCertificate"
1418 settings.
setValue( QStringLiteral(
"/" ) + param, child.attribute( param ) );
1422 child = child.nextSiblingElement();
1426void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1428 const QDomElement root = doc.documentElement();
1429 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1431 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1435 QString connectionName;
1437 QDomElement child = root.firstChildElement();
1439 bool overwrite =
true;
1441 while ( !child.isNull() )
1443 connectionName = child.attribute( QStringLiteral(
"name" ) );
1444 if ( !items.contains( connectionName ) )
1446 child = child.nextSiblingElement();
1451 if ( keys.contains( connectionName ) && prompt )
1453 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 );
1457 case QMessageBox::Cancel:
1459 case QMessageBox::No:
1460 child = child.nextSiblingElement();
1462 case QMessageBox::Yes:
1465 case QMessageBox::YesToAll:
1469 case QMessageBox::NoToAll:
1476 if ( keys.contains( connectionName ) )
1480 child = child.nextSiblingElement();
1486 keys << connectionName;
1501 child = child.nextSiblingElement();
1505void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1507 const QDomElement root = doc.documentElement();
1508 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1510 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1514 QString connectionName;
1516 QDomElement child = root.firstChildElement();
1518 bool overwrite =
true;
1520 while ( !child.isNull() )
1522 connectionName = child.attribute( QStringLiteral(
"name" ) );
1523 if ( !items.contains( connectionName ) )
1525 child = child.nextSiblingElement();
1530 if ( keys.contains( connectionName ) && prompt )
1532 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 );
1536 case QMessageBox::Cancel:
1538 case QMessageBox::No:
1539 child = child.nextSiblingElement();
1541 case QMessageBox::Yes:
1544 case QMessageBox::YesToAll:
1548 case QMessageBox::NoToAll:
1555 if ( keys.contains( connectionName ) )
1559 child = child.nextSiblingElement();
1565 keys << connectionName;
1578 child = child.nextSiblingElement();
1582void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1584 const QDomElement root = doc.documentElement();
1585 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1587 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a Vector Tile connections exchange file." ) );
1591 QString connectionName;
1593 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
1596 QDomElement child = root.firstChildElement();
1598 bool overwrite =
true;
1600 while ( !child.isNull() )
1602 connectionName = child.attribute( QStringLiteral(
"name" ) );
1603 if ( !items.contains( connectionName ) )
1605 child = child.nextSiblingElement();
1610 if ( keys.contains( connectionName ) && prompt )
1612 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 );
1616 case QMessageBox::Cancel:
1618 case QMessageBox::No:
1619 child = child.nextSiblingElement();
1621 case QMessageBox::Yes:
1624 case QMessageBox::YesToAll:
1628 case QMessageBox::NoToAll:
1635 if ( keys.contains( connectionName ) )
1639 child = child.nextSiblingElement();
1645 keys << connectionName;
1648 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1649 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral(
"zmin" ) ).toInt(), connectionName );
1650 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral(
"zmax" ) ).toInt(), connectionName );
1651 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral(
"serviceType" ) ), connectionName );
1652 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1653 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1654 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1655 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral(
"styleUrl" ) ), connectionName );
1658 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1660 child = child.nextSiblingElement();
1664void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1666 const QDomElement root = doc.documentElement();
1667 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
1669 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a tiled scene connections exchange file." ) );
1673 QString connectionName;
1675 settings.
beginGroup( QStringLiteral(
"/qgis/connections-tiled-scene" ) );
1678 QDomElement child = root.firstChildElement();
1680 bool overwrite =
true;
1682 while ( !child.isNull() )
1684 connectionName = child.attribute( QStringLiteral(
"name" ) );
1685 if ( !items.contains( connectionName ) )
1687 child = child.nextSiblingElement();
1692 if ( keys.contains( connectionName ) && prompt )
1694 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 );
1698 case QMessageBox::Cancel:
1700 case QMessageBox::No:
1701 child = child.nextSiblingElement();
1703 case QMessageBox::Yes:
1706 case QMessageBox::YesToAll:
1710 case QMessageBox::NoToAll:
1717 if ( keys.contains( connectionName ) )
1721 child = child.nextSiblingElement();
1727 keys << connectionName;
1730 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral(
"provider" ) ), connectionName );
1731 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1732 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1733 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1734 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1737 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1739 child = child.nextSiblingElement();
1743void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1745 const QDomElement root = doc.documentElement();
1746 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
1748 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a SensorThings connections exchange file." ) );
1752 QString connectionName;
1754 settings.
beginGroup( QStringLiteral(
"/connections/sensorthings/items" ) );
1757 QDomElement child = root.firstChildElement();
1759 bool overwrite =
true;
1761 while ( !child.isNull() )
1763 connectionName = child.attribute( QStringLiteral(
"name" ) );
1764 if ( !items.contains( connectionName ) )
1766 child = child.nextSiblingElement();
1771 if ( keys.contains( connectionName ) && prompt )
1773 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 );
1777 case QMessageBox::Cancel:
1779 case QMessageBox::No:
1780 child = child.nextSiblingElement();
1782 case QMessageBox::Yes:
1785 case QMessageBox::YesToAll:
1789 case QMessageBox::NoToAll:
1796 if ( keys.contains( connectionName ) )
1800 child = child.nextSiblingElement();
1806 keys << connectionName;
1809 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1810 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1811 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1812 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1815 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1817 child = child.nextSiblingElement();
1821void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1823 const QDomElement root = doc.documentElement();
1824 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
1826 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a cloud storage connections exchange file." ) );
1830 QString connectionName;
1832 settings.
beginGroup( QStringLiteral(
"/connections/cloud/items" ) );
1835 QDomElement child = root.firstChildElement();
1837 bool overwrite =
true;
1839 while ( !child.isNull() )
1841 connectionName = child.attribute( QStringLiteral(
"name" ) );
1842 if ( !items.contains( connectionName ) )
1844 child = child.nextSiblingElement();
1849 if ( keys.contains( connectionName ) && prompt )
1851 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 );
1855 case QMessageBox::Cancel:
1857 case QMessageBox::No:
1858 child = child.nextSiblingElement();
1860 case QMessageBox::Yes:
1863 case QMessageBox::YesToAll:
1867 case QMessageBox::NoToAll:
1874 if ( keys.contains( connectionName ) )
1878 child = child.nextSiblingElement();
1884 keys << connectionName;
1887 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral(
"handler" ) ), connectionName );
1888 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral(
"container" ) ), connectionName );
1889 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral(
"path" ) ), connectionName );
1891 QString credentialString = child.attribute( QStringLiteral(
"credentials" ) );
1893 QVariantMap credentialOptions;
1896 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral(
"\\|credential:([^|]*)" ) );
1897 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral(
"(.*?)=(.*)" ) );
1899 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1900 if ( match.hasMatch() )
1902 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1903 if ( keyValueMatch.hasMatch() )
1905 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1907 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1915 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1917 child = child.nextSiblingElement();
1921void QgsManageConnectionsDialog::loadStacConnections(
const QDomDocument &doc,
const QStringList &items )
1923 const QDomElement root = doc.documentElement();
1924 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
1926 QMessageBox::information(
this, tr(
"Loading Connections" ), tr(
"The file is not a STAC connections exchange file." ) );
1930 QString connectionName;
1932 settings.
beginGroup( QStringLiteral(
"/qgis/connections-stac" ) );
1935 QDomElement child = root.firstChildElement();
1937 bool overwrite =
true;
1939 while ( !child.isNull() )
1941 connectionName = child.attribute( QStringLiteral(
"name" ) );
1942 if ( !items.contains( connectionName ) )
1944 child = child.nextSiblingElement();
1949 if ( keys.contains( connectionName ) && prompt )
1951 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 );
1955 case QMessageBox::Cancel:
1957 case QMessageBox::No:
1958 child = child.nextSiblingElement();
1960 case QMessageBox::Yes:
1963 case QMessageBox::YesToAll:
1967 case QMessageBox::NoToAll:
1974 if ( keys.contains( connectionName ) )
1978 child = child.nextSiblingElement();
1984 keys << connectionName;
1987 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1988 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1989 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1990 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1993 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1995 child = child.nextSiblingElement();
2001 listConnections->selectAll();
2002 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2007 listConnections->clearSelection();
2008 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 QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const
Returns the list of items.
This class is a composition of two QSettings instances:
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