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" ),
90 tr(
"You should select at least one connection from list." ) );
95 items.reserve( selection.size() );
96 for (
int i = 0; i < selection.size(); ++i )
98 items.append( selection.at( i )->text() );
101 if ( mDialogMode ==
Export )
103 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(),
104 tr(
"XML files (*.xml *.XML)" ) );
108 if ( fileName.isEmpty() )
114 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
116 fileName += QLatin1String(
".xml" );
119 mFileName = fileName;
122 switch ( mConnectionType )
125 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
128 doc = saveWfsConnections( items );
131 doc = savePgConnections( items );
134 doc = saveMssqlConnections( items );
137 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
140 doc = saveOracleConnections( items );
143 doc = saveHanaConnections( items );
146 doc = saveXyzTilesConnections( items );
150 doc = saveArcgisConnections( items );
153 doc = saveVectorTileConnections( items );
156 doc = saveTiledSceneConnections( items );
159 doc = saveSensorThingsConnections( items );
162 doc = saveCloudStorageConnections( items );
165 doc = saveStacConnections( items );
169 QFile file( mFileName );
170 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
172 QMessageBox::warning(
this, tr(
"Saving Connections" ),
173 tr(
"Cannot write file %1:\n%2." )
175 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" ),
188 tr(
"Cannot read file %1:\n%2." )
190 file.errorString() ) );
199 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
201 QMessageBox::warning(
this, tr(
"Loading Connections" ),
202 tr(
"Parse error at line %1, column %2:\n%3" )
209 switch ( mConnectionType )
212 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
215 loadWfsConnections( doc, items );
218 loadPgConnections( doc, items );
221 loadMssqlConnections( doc, items );
224 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
227 loadOracleConnections( doc, items );
230 loadHanaConnections( doc, items );
233 loadXyzTilesConnections( doc, items );
236 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
239 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
242 loadVectorTileConnections( doc, items );
245 loadTiledSceneConnections( doc, items );
248 loadSensorThingsConnections( doc, items );
251 loadCloudStorageConnections( doc, items );
254 loadStacConnections( doc, items );
258 listConnections->clear();
265bool QgsManageConnectionsDialog::populateConnections()
268 if ( mDialogMode ==
Export )
270 QStringList connections;
272 switch ( mConnectionType )
284 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
288 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
292 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
296 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
307 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
310 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
313 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
316 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
319 connections = QgsStacConnection::sTreeConnectionStac->items();
322 for (
const QString &connection : std::as_const( connections ) )
324 QListWidgetItem *item =
new QListWidgetItem();
325 item->setText( connection );
326 listConnections->addItem( item );
332 QFile file( mFileName );
333 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
335 QMessageBox::warning(
this, tr(
"Loading Connections" ),
336 tr(
"Cannot read file %1:\n%2." )
338 file.errorString() ) );
347 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
349 QMessageBox::warning(
this, tr(
"Loading Connections" ),
350 tr(
"Parse error at line %1, column %2:\n%3" )
357 const QDomElement root = doc.documentElement();
358 switch ( mConnectionType )
361 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
363 QMessageBox::information(
this, tr(
"Loading Connections" ),
364 tr(
"The file is not a WMS connections exchange file." ) );
370 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
372 QMessageBox::information(
this, tr(
"Loading Connections" ),
373 tr(
"The file is not a WFS connections exchange file." ) );
379 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
381 QMessageBox::information(
this, tr(
"Loading Connections" ),
382 tr(
"The file is not a WCS connections exchange file." ) );
388 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
390 QMessageBox::information(
this, tr(
"Loading Connections" ),
391 tr(
"The file is not a PostGIS connections exchange file." ) );
397 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
399 QMessageBox::information(
this, tr(
"Loading Connections" ),
400 tr(
"The file is not a MS SQL Server connections exchange file." ) );
405 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
407 QMessageBox::information(
this, tr(
"Loading Connections" ),
408 tr(
"The file is not an Oracle connections exchange file." ) );
413 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
415 QMessageBox::warning(
this, tr(
"Loading Connections" ),
416 tr(
"The file is not a HANA connections exchange file." ) );
421 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
423 QMessageBox::information(
this, tr(
"Loading Connections" ),
424 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
429 if ( root.tagName() != QLatin1String(
"qgsARCGISMAPSERVERConnections" ) )
431 QMessageBox::information(
this, tr(
"Loading Connections" ),
432 tr(
"The file is not a ArcGIS Map Service connections exchange file." ) );
437 if ( root.tagName() != QLatin1String(
"qgsARCGISFEATURESERVERConnections" ) )
439 QMessageBox::information(
this, tr(
"Loading Connections" ),
440 tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
445 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
447 QMessageBox::information(
this, tr(
"Loading Connections" ),
448 tr(
"The file is not a Vector Tile connections exchange file." ) );
453 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
455 QMessageBox::information(
this, tr(
"Loading Connections" ),
456 tr(
"The file is not a tiled scene connections exchange file." ) );
461 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
463 QMessageBox::information(
this, tr(
"Loading Connections" ),
464 tr(
"The file is not a SensorThings connections exchange file." ) );
469 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
471 QMessageBox::information(
this, tr(
"Loading Connections" ),
472 tr(
"The file is not a cloud storage connections exchange file." ) );
477 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
479 QMessageBox::information(
this, tr(
"Loading Connections" ),
480 tr(
"The file is not a STAC connections exchange file." ) );
486 QDomElement child = root.firstChildElement();
487 while ( !child.isNull() )
489 QListWidgetItem *item =
new QListWidgetItem();
490 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
491 listConnections->addItem( item );
492 child = child.nextSiblingElement();
498QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
500 QDomDocument doc( QStringLiteral(
"connections" ) );
501 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
502 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
503 doc.appendChild( root );
505 for (
int i = 0; i < connections.count(); ++i )
507 QDomElement el = doc.createElement( service.toLower() );
508 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
511 if ( service == QLatin1String(
"WMS" ) )
521 httpHeader.updateDomElement( el );
526 root.appendChild( el );
532QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
534 QDomDocument doc( QStringLiteral(
"connections" ) );
535 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
536 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
537 doc.appendChild( root );
539 for (
int i = 0; i < connections.count(); ++i )
541 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
542 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
553 root.appendChild( el );
559QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
561 QDomDocument doc( QStringLiteral(
"connections" ) );
562 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
563 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
564 doc.appendChild( root );
568 for (
int i = 0; i < connections.count(); ++i )
570 path =
"/PostgreSQL/connections/" + connections[ i ];
571 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
572 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
573 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
574 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
575 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
576 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
577 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
578 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
579 el.setAttribute( QStringLiteral(
"projectsInDatabase" ), settings.
value( path +
"/projectsInDatabase",
"0" ).toString() );
580 el.setAttribute( QStringLiteral(
"dontResolveType" ), settings.
value( path +
"/dontResolveType",
"0" ).toString() );
581 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
582 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
583 el.setAttribute( QStringLiteral(
"publicOnly" ), settings.
value( path +
"/publicOnly",
"0" ).toString() );
585 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
587 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
589 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
592 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
594 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
596 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
599 root.appendChild( el );
605QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
607 QDomDocument doc( QStringLiteral(
"connections" ) );
608 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
609 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
610 doc.appendChild( root );
614 for (
int i = 0; i < connections.count(); ++i )
616 path =
"/MSSQL/connections/" + connections[ i ];
617 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
618 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
619 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
620 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
621 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
622 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
623 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
624 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
626 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
628 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
630 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
633 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
635 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
637 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
640 root.appendChild( el );
646QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
648 QDomDocument doc( QStringLiteral(
"connections" ) );
649 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
650 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
651 doc.appendChild( root );
655 for (
int i = 0; i < connections.count(); ++i )
657 path =
"/Oracle/connections/" + connections[ i ];
658 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
659 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
660 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
661 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
662 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
663 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
664 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
665 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
666 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
667 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
668 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
669 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
671 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
673 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
675 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
678 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
680 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
682 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
685 root.appendChild( el );
691QDomDocument QgsManageConnectionsDialog::saveHanaConnections(
const QStringList &connections )
693 QDomDocument doc( QStringLiteral(
"connections" ) );
694 QDomElement root = doc.createElement( QStringLiteral(
"qgsHanaConnections" ) );
695 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
696 doc.appendChild( root );
700 for (
int i = 0; i < connections.count(); ++i )
702 path =
"/HANA/connections/" + connections[i];
703 QDomElement el = doc.createElement( QStringLiteral(
"hana" ) );
704 el.setAttribute( QStringLiteral(
"name" ), connections[i] );
705 el.setAttribute( QStringLiteral(
"driver" ), settings.
value( path +
"/driver", QString() ).toString() );
706 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host", QString() ).toString() );
707 el.setAttribute( QStringLiteral(
"identifierType" ), settings.
value( path +
"/identifierType", QString() ).toString() );
708 el.setAttribute( QStringLiteral(
"identifier" ), settings.
value( path +
"/identifier", QString() ).toString() );
709 el.setAttribute( QStringLiteral(
"multitenant" ), settings.
value( path +
"/multitenant", QString() ).toString() );
710 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database", QString() ).toString() );
711 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema", QString() ).toString() );
712 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly", QStringLiteral(
"0" ) ).toString() );
713 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables", QStringLiteral(
"0" ) ).toString() );
715 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername", QStringLiteral(
"false" ) ).toString() );
716 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
718 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username", QString() ).toString() );
721 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword", QStringLiteral(
"false" ) ).toString() );
722 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
724 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password", QString() ).toString() );
727 el.setAttribute( QStringLiteral(
"sslEnabled" ), settings.
value( path +
"/sslEnabled", QStringLiteral(
"false" ) ).toString() );
728 el.setAttribute( QStringLiteral(
"sslCryptoProvider" ), settings.
value( path +
"/sslCryptoProvider", QStringLiteral(
"openssl" ) ).toString() );
729 el.setAttribute( QStringLiteral(
"sslKeyStore" ), settings.
value( path +
"/sslKeyStore", QString() ).toString() );
730 el.setAttribute( QStringLiteral(
"sslTrustStore" ), settings.
value( path +
"/sslTrustStore", QString() ).toString() );
731 el.setAttribute( QStringLiteral(
"sslValidateCertificate" ), settings.
value( path +
"/sslValidateCertificate", QStringLiteral(
"false" ) ).toString() );
732 el.setAttribute( QStringLiteral(
"sslHostNameInCertificate" ), settings.
value( path +
"/sslHostNameInCertificate", QString() ).toString() );
734 root.appendChild( el );
740QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
742 QDomDocument doc( QStringLiteral(
"connections" ) );
743 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
744 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
745 doc.appendChild( root );
747 for (
int i = 0; i < connections.count(); ++i )
750 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
752 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
762 httpHeader.updateDomElement( el );
764 root.appendChild( el );
770QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections )
772 QDomDocument doc( QStringLiteral(
"connections" ) );
773 QDomElement root = doc.createElement(
"qgsARCGISFEATURESERVERConnections" );
774 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
775 doc.appendChild( root );
777 for (
const QString &connection : connections )
779 QDomElement el = doc.createElement( QStringLiteral(
"arcgisfeatureserver" ) );
780 el.setAttribute( QStringLiteral(
"name" ), connection );
784 httpHeader.updateDomElement( el );
790 root.appendChild( el );
796QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
798 QDomDocument doc( QStringLiteral(
"connections" ) );
799 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
800 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
801 doc.appendChild( root );
803 for (
int i = 0; i < connections.count(); ++i )
805 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
807 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
808 el.setAttribute( QStringLiteral(
"url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[ i ] ) );
809 el.setAttribute( QStringLiteral(
"zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[ i ] ) );
810 el.setAttribute( QStringLiteral(
"zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[ i ] ) );
811 el.setAttribute( QStringLiteral(
"serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[ i ] ) );
812 el.setAttribute( QStringLiteral(
"authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
813 el.setAttribute( QStringLiteral(
"username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[ i ] ) );
814 el.setAttribute( QStringLiteral(
"password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[ i ] ) );
815 el.setAttribute( QStringLiteral(
"styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[ i ] ) );
817 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[ i ] ) );
818 httpHeader.updateDomElement( el );
820 root.appendChild( el );
826QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections(
const QStringList &connections )
828 QDomDocument doc( QStringLiteral(
"connections" ) );
829 QDomElement root = doc.createElement( QStringLiteral(
"qgsTiledSceneConnections" ) );
830 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
831 doc.appendChild( root );
833 for (
int i = 0; i < connections.count(); ++i )
835 QDomElement el = doc.createElement( QStringLiteral(
"tiledscene" ) );
837 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
838 el.setAttribute( QStringLiteral(
"provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[ i ] ) );
839 el.setAttribute( QStringLiteral(
"url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[ i ] ) );
840 el.setAttribute( QStringLiteral(
"authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
841 el.setAttribute( QStringLiteral(
"username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[ i ] ) );
842 el.setAttribute( QStringLiteral(
"password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[ i ] ) );
844 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
845 httpHeader.updateDomElement( el );
847 root.appendChild( el );
853QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections(
const QStringList &connections )
855 QDomDocument doc( QStringLiteral(
"connections" ) );
856 QDomElement root = doc.createElement( QStringLiteral(
"qgsSensorThingsConnections" ) );
857 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
858 doc.appendChild( root );
860 for (
int i = 0; i < connections.count(); ++i )
862 QDomElement el = doc.createElement( QStringLiteral(
"sensorthings" ) );
864 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
865 el.setAttribute( QStringLiteral(
"url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[ i ] ) );
866 el.setAttribute( QStringLiteral(
"authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
867 el.setAttribute( QStringLiteral(
"username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[ i ] ) );
868 el.setAttribute( QStringLiteral(
"password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[ i ] ) );
870 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[ i ] ) );
871 httpHeader.updateDomElement( el );
873 root.appendChild( el );
880QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections(
const QStringList &connections )
882 QDomDocument doc( QStringLiteral(
"connections" ) );
883 QDomElement root = doc.createElement( QStringLiteral(
"qgsCloudStorageConnections" ) );
884 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
885 doc.appendChild( root );
887 for (
int i = 0; i < connections.count(); ++i )
889 QDomElement el = doc.createElement( QStringLiteral(
"cloudstorage" ) );
891 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
892 el.setAttribute( QStringLiteral(
"handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[ i ] ) );
893 el.setAttribute( QStringLiteral(
"container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[ i ] ) );
894 el.setAttribute( QStringLiteral(
"path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[ i ] ) );
896 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[ i ] );
897 QString credentialString;
898 for (
auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
900 if ( !it.value().toString().isEmpty() )
902 credentialString += QStringLiteral(
"|credential:%1=%2" ).arg( it.key(), it.value().toString() );
905 el.setAttribute( QStringLiteral(
"credentials" ), credentialString );
907 root.appendChild( el );
913QDomDocument QgsManageConnectionsDialog::saveStacConnections(
const QStringList &connections )
915 QDomDocument doc( QStringLiteral(
"connections" ) );
916 QDomElement root = doc.createElement( QStringLiteral(
"qgsStacConnections" ) );
917 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
918 doc.appendChild( root );
920 for (
int i = 0; i < connections.count(); ++i )
922 QDomElement el = doc.createElement( QStringLiteral(
"stac" ) );
924 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
925 el.setAttribute( QStringLiteral(
"url" ), QgsStacConnection::settingsUrl->value( connections[ i ] ) );
926 el.setAttribute( QStringLiteral(
"authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[ i ] ) );
927 el.setAttribute( QStringLiteral(
"username" ), QgsStacConnection::settingsUsername->value( connections[ i ] ) );
928 el.setAttribute( QStringLiteral(
"password" ), QgsStacConnection::settingsPassword->value( connections[ i ] ) );
930 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[ i ] ) );
931 httpHeader.updateDomElement( el );
933 root.appendChild( el );
939void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
941 const QDomElement root = doc.documentElement();
942 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
944 QMessageBox::information(
this, tr(
"Loading Connections" ),
945 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( QStringLiteral(
"name" ) );
958 if ( !items.contains( connectionName ) )
960 child = child.nextSiblingElement();
967 const int res = QMessageBox::warning(
this,
968 tr(
"Loading Connections" ),
969 tr(
"Connection with name '%1' already exists. Overwrite?" )
970 .arg( connectionName ),
971 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
975 case QMessageBox::Cancel:
977 case QMessageBox::No:
978 child = child.nextSiblingElement();
980 case QMessageBox::Yes:
983 case QMessageBox::YesToAll:
987 case QMessageBox::NoToAll:
996 child = child.nextSiblingElement();
1012 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1017 child = child.nextSiblingElement();
1021void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
1023 const QDomElement root = doc.documentElement();
1024 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
1026 QMessageBox::information(
this, tr(
"Loading Connections" ),
1027 tr(
"The file is not a WFS connections exchange file." ) );
1031 QString connectionName;
1034 QDomElement child = root.firstChildElement();
1036 bool overwrite =
true;
1038 while ( !child.isNull() )
1040 connectionName = child.attribute( QStringLiteral(
"name" ) );
1041 if ( !items.contains( connectionName ) )
1043 child = child.nextSiblingElement();
1048 if ( keys.contains( connectionName ) && prompt )
1050 const int res = QMessageBox::warning(
this,
1051 tr(
"Loading Connections" ),
1052 tr(
"Connection with name '%1' already exists. Overwrite?" )
1053 .arg( connectionName ),
1054 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1058 case QMessageBox::Cancel:
1060 case QMessageBox::No:
1061 child = child.nextSiblingElement();
1063 case QMessageBox::Yes:
1066 case QMessageBox::YesToAll:
1070 case QMessageBox::NoToAll:
1077 if ( keys.contains( connectionName ) )
1081 child = child.nextSiblingElement();
1087 keys << connectionName;
1100 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1105 child = child.nextSiblingElement();
1109void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
1111 const QDomElement root = doc.documentElement();
1112 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
1114 QMessageBox::information(
this,
1115 tr(
"Loading Connections" ),
1116 tr(
"The file is not a PostGIS connections exchange file." ) );
1120 QString connectionName;
1122 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
1125 QDomElement child = root.firstChildElement();
1127 bool overwrite =
true;
1129 while ( !child.isNull() )
1131 connectionName = child.attribute( QStringLiteral(
"name" ) );
1132 if ( !items.contains( connectionName ) )
1134 child = child.nextSiblingElement();
1139 if ( keys.contains( connectionName ) && prompt )
1141 const int res = QMessageBox::warning(
this,
1142 tr(
"Loading Connections" ),
1143 tr(
"Connection with name '%1' already exists. Overwrite?" )
1144 .arg( connectionName ),
1145 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1148 case QMessageBox::Cancel:
1150 case QMessageBox::No:
1151 child = child.nextSiblingElement();
1153 case QMessageBox::Yes:
1156 case QMessageBox::YesToAll:
1160 case QMessageBox::NoToAll:
1167 if ( keys.contains( connectionName ) )
1171 child = child.nextSiblingElement();
1177 keys << connectionName;
1181 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1183 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1184 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1185 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1186 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1188 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1192 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1194 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1195 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1196 settings.
setValue( QStringLiteral(
"/projectsInDatabase" ), child.attribute( QStringLiteral(
"projectsInDatabase" ), 0 ) );
1197 settings.
setValue( QStringLiteral(
"/dontResolveType" ), child.attribute( QStringLiteral(
"dontResolveType" ), 0 ) );
1198 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ), 0 ) );
1199 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ), 0 ) );
1200 settings.
setValue( QStringLiteral(
"/publicOnly" ), child.attribute( QStringLiteral(
"publicOnly" ), 0 ) );
1201 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1202 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1203 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1204 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1207 child = child.nextSiblingElement();
1211void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1213 const QDomElement root = doc.documentElement();
1214 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1216 QMessageBox::information(
this,
1217 tr(
"Loading Connections" ),
1218 tr(
"The file is not a MS SQL Server connections exchange file." ) );
1222 QString connectionName;
1224 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1227 QDomElement child = root.firstChildElement();
1229 bool overwrite =
true;
1231 while ( !child.isNull() )
1233 connectionName = child.attribute( QStringLiteral(
"name" ) );
1234 if ( !items.contains( connectionName ) )
1236 child = child.nextSiblingElement();
1241 if ( keys.contains( connectionName ) && prompt )
1243 const int res = QMessageBox::warning(
this,
1244 tr(
"Loading Connections" ),
1245 tr(
"Connection with name '%1' already exists. Overwrite?" )
1246 .arg( connectionName ),
1247 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1250 case QMessageBox::Cancel:
1252 case QMessageBox::No:
1253 child = child.nextSiblingElement();
1255 case QMessageBox::Yes:
1258 case QMessageBox::YesToAll:
1262 case QMessageBox::NoToAll:
1269 if ( keys.contains( connectionName ) )
1273 child = child.nextSiblingElement();
1279 keys << connectionName;
1283 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1285 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1286 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1287 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1288 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1290 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1294 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1296 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1297 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1298 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1299 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1300 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1301 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1304 child = child.nextSiblingElement();
1308void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1310 const QDomElement root = doc.documentElement();
1311 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1313 QMessageBox::information(
this,
1314 tr(
"Loading Connections" ),
1315 tr(
"The file is not an Oracle connections exchange file." ) );
1319 QString connectionName;
1321 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1324 QDomElement child = root.firstChildElement();
1326 bool overwrite =
true;
1328 while ( !child.isNull() )
1330 connectionName = child.attribute( QStringLiteral(
"name" ) );
1331 if ( !items.contains( connectionName ) )
1333 child = child.nextSiblingElement();
1338 if ( keys.contains( connectionName ) && prompt )
1340 const int res = QMessageBox::warning(
this,
1341 tr(
"Loading Connections" ),
1342 tr(
"Connection with name '%1' already exists. Overwrite?" )
1343 .arg( connectionName ),
1344 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1347 case QMessageBox::Cancel:
1349 case QMessageBox::No:
1350 child = child.nextSiblingElement();
1352 case QMessageBox::Yes:
1355 case QMessageBox::YesToAll:
1359 case QMessageBox::NoToAll:
1366 if ( keys.contains( connectionName ) )
1370 child = child.nextSiblingElement();
1376 keys << connectionName;
1380 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1382 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1383 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1384 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1385 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1386 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1387 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1388 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1389 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1390 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1391 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1392 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1393 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1394 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1395 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1398 child = child.nextSiblingElement();
1402void QgsManageConnectionsDialog::loadHanaConnections(
const QDomDocument &doc,
const QStringList &items )
1404 QDomElement root = doc.documentElement();
1405 if ( root.tagName() != QLatin1String(
"qgsHanaConnections" ) )
1407 QMessageBox::warning(
this,
1408 tr(
"Loading Connections" ),
1409 tr(
"The file is not a HANA connections exchange file." ) );
1413 const QDomAttr version = root.attributeNode(
"version" );
1414 if ( version.value() != QLatin1String(
"1.0" ) )
1416 QMessageBox::warning(
this,
1417 tr(
"Loading Connections" ),
1418 tr(
"The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1423 settings.
beginGroup( QStringLiteral(
"/HANA/connections" ) );
1426 QDomElement child = root.firstChildElement();
1428 bool overwrite =
true;
1430 while ( !child.isNull() )
1432 const QString connectionName = child.attribute( QStringLiteral(
"name" ) );
1433 if ( !items.contains( connectionName ) )
1435 child = child.nextSiblingElement();
1440 if ( keys.contains( connectionName ) && prompt )
1442 const int res = QMessageBox::warning(
this,
1443 tr(
"Loading Connections" ),
1444 tr(
"Connection with name '%1' already exists. Overwrite?" )
1445 .arg( connectionName ),
1446 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1449 case QMessageBox::Cancel:
1451 case QMessageBox::No:
1452 child = child.nextSiblingElement();
1454 case QMessageBox::Yes:
1457 case QMessageBox::YesToAll:
1461 case QMessageBox::NoToAll:
1468 if ( keys.contains( connectionName ) )
1472 child = child.nextSiblingElement();
1478 keys << connectionName;
1482 settings.
beginGroup(
"/HANA/connections/" + connectionName );
1484 for (
const QString param :
1485 {
"driver",
"host",
"database",
"identifierType",
"identifier",
"multitenant",
"schema",
"userTablesOnly",
1486 "allowGeometrylessTables",
"saveUsername",
"username",
"savePassword",
"password",
"sslEnabled",
1487 "sslCryptoProvider",
"sslKeyStore",
"sslTrustStore",
"sslValidateCertificate",
"sslHostNameInCertificate"
1489 settings.
setValue( QStringLiteral(
"/" ) + param, child.attribute( param ) );
1493 child = child.nextSiblingElement();
1497void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1499 const QDomElement root = doc.documentElement();
1500 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1502 QMessageBox::information(
this, tr(
"Loading Connections" ),
1503 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1507 QString connectionName;
1509 QDomElement child = root.firstChildElement();
1511 bool overwrite =
true;
1513 while ( !child.isNull() )
1515 connectionName = child.attribute( QStringLiteral(
"name" ) );
1516 if ( !items.contains( connectionName ) )
1518 child = child.nextSiblingElement();
1523 if ( keys.contains( connectionName ) && prompt )
1525 const int res = QMessageBox::warning(
this,
1526 tr(
"Loading Connections" ),
1527 tr(
"Connection with name '%1' already exists. Overwrite?" )
1528 .arg( connectionName ),
1529 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1533 case QMessageBox::Cancel:
1535 case QMessageBox::No:
1536 child = child.nextSiblingElement();
1538 case QMessageBox::Yes:
1541 case QMessageBox::YesToAll:
1545 case QMessageBox::NoToAll:
1552 if ( keys.contains( connectionName ) )
1556 child = child.nextSiblingElement();
1562 keys << connectionName;
1577 child = child.nextSiblingElement();
1581void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1583 const QDomElement root = doc.documentElement();
1584 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1586 QMessageBox::information(
this, tr(
"Loading Connections" ),
1587 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1591 QString connectionName;
1593 QDomElement child = root.firstChildElement();
1595 bool overwrite =
true;
1597 while ( !child.isNull() )
1599 connectionName = child.attribute( QStringLiteral(
"name" ) );
1600 if ( !items.contains( connectionName ) )
1602 child = child.nextSiblingElement();
1607 if ( keys.contains( connectionName ) && prompt )
1609 const int res = QMessageBox::warning(
this,
1610 tr(
"Loading Connections" ),
1611 tr(
"Connection with name '%1' already exists. Overwrite?" )
1612 .arg( connectionName ),
1613 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1617 case QMessageBox::Cancel:
1619 case QMessageBox::No:
1620 child = child.nextSiblingElement();
1622 case QMessageBox::Yes:
1625 case QMessageBox::YesToAll:
1629 case QMessageBox::NoToAll:
1636 if ( keys.contains( connectionName ) )
1640 child = child.nextSiblingElement();
1646 keys << connectionName;
1659 child = child.nextSiblingElement();
1663void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1665 const QDomElement root = doc.documentElement();
1666 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1668 QMessageBox::information(
this, tr(
"Loading Connections" ),
1669 tr(
"The file is not a Vector Tile connections exchange file." ) );
1673 QString connectionName;
1675 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
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,
1695 tr(
"Loading Connections" ),
1696 tr(
"Connection with name '%1' already exists. Overwrite?" )
1697 .arg( connectionName ),
1698 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1702 case QMessageBox::Cancel:
1704 case QMessageBox::No:
1705 child = child.nextSiblingElement();
1707 case QMessageBox::Yes:
1710 case QMessageBox::YesToAll:
1714 case QMessageBox::NoToAll:
1721 if ( keys.contains( connectionName ) )
1725 child = child.nextSiblingElement();
1731 keys << connectionName;
1734 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1735 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral(
"zmin" ) ).toInt(), connectionName );
1736 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral(
"zmax" ) ).toInt(), connectionName );
1737 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral(
"serviceType" ) ), connectionName );
1738 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1739 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1740 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1741 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral(
"styleUrl" ) ), connectionName );
1744 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1746 child = child.nextSiblingElement();
1750void QgsManageConnectionsDialog::loadTiledSceneConnections(
const QDomDocument &doc,
const QStringList &items )
1752 const QDomElement root = doc.documentElement();
1753 if ( root.tagName() != QLatin1String(
"qgsTiledSceneConnections" ) )
1755 QMessageBox::information(
this, tr(
"Loading Connections" ),
1756 tr(
"The file is not a tiled scene connections exchange file." ) );
1760 QString connectionName;
1762 settings.
beginGroup( QStringLiteral(
"/qgis/connections-tiled-scene" ) );
1765 QDomElement child = root.firstChildElement();
1767 bool overwrite =
true;
1769 while ( !child.isNull() )
1771 connectionName = child.attribute( QStringLiteral(
"name" ) );
1772 if ( !items.contains( connectionName ) )
1774 child = child.nextSiblingElement();
1779 if ( keys.contains( connectionName ) && prompt )
1781 const int res = QMessageBox::warning(
this,
1782 tr(
"Loading Connections" ),
1783 tr(
"Connection with name '%1' already exists. Overwrite?" )
1784 .arg( connectionName ),
1785 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1789 case QMessageBox::Cancel:
1791 case QMessageBox::No:
1792 child = child.nextSiblingElement();
1794 case QMessageBox::Yes:
1797 case QMessageBox::YesToAll:
1801 case QMessageBox::NoToAll:
1808 if ( keys.contains( connectionName ) )
1812 child = child.nextSiblingElement();
1818 keys << connectionName;
1821 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral(
"provider" ) ), connectionName );
1822 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1823 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1824 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1825 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1828 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1830 child = child.nextSiblingElement();
1834void QgsManageConnectionsDialog::loadSensorThingsConnections(
const QDomDocument &doc,
const QStringList &items )
1836 const QDomElement root = doc.documentElement();
1837 if ( root.tagName() != QLatin1String(
"qgsSensorThingsConnections" ) )
1839 QMessageBox::information(
this, tr(
"Loading Connections" ),
1840 tr(
"The file is not a SensorThings connections exchange file." ) );
1844 QString connectionName;
1846 settings.
beginGroup( QStringLiteral(
"/connections/sensorthings/items" ) );
1849 QDomElement child = root.firstChildElement();
1851 bool overwrite =
true;
1853 while ( !child.isNull() )
1855 connectionName = child.attribute( QStringLiteral(
"name" ) );
1856 if ( !items.contains( connectionName ) )
1858 child = child.nextSiblingElement();
1863 if ( keys.contains( connectionName ) && prompt )
1865 const int res = QMessageBox::warning(
this,
1866 tr(
"Loading Connections" ),
1867 tr(
"Connection with name '%1' already exists. Overwrite?" )
1868 .arg( connectionName ),
1869 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1873 case QMessageBox::Cancel:
1875 case QMessageBox::No:
1876 child = child.nextSiblingElement();
1878 case QMessageBox::Yes:
1881 case QMessageBox::YesToAll:
1885 case QMessageBox::NoToAll:
1892 if ( keys.contains( connectionName ) )
1896 child = child.nextSiblingElement();
1902 keys << connectionName;
1905 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
1906 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
1907 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
1908 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
1911 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1913 child = child.nextSiblingElement();
1917void QgsManageConnectionsDialog::loadCloudStorageConnections(
const QDomDocument &doc,
const QStringList &items )
1919 const QDomElement root = doc.documentElement();
1920 if ( root.tagName() != QLatin1String(
"qgsCloudStorageConnections" ) )
1922 QMessageBox::information(
this, tr(
"Loading Connections" ),
1923 tr(
"The file is not a cloud storage connections exchange file." ) );
1927 QString connectionName;
1929 settings.
beginGroup( QStringLiteral(
"/connections/cloud/items" ) );
1932 QDomElement child = root.firstChildElement();
1934 bool overwrite =
true;
1936 while ( !child.isNull() )
1938 connectionName = child.attribute( QStringLiteral(
"name" ) );
1939 if ( !items.contains( connectionName ) )
1941 child = child.nextSiblingElement();
1946 if ( keys.contains( connectionName ) && prompt )
1948 const int res = QMessageBox::warning(
this,
1949 tr(
"Loading Connections" ),
1950 tr(
"Connection with name '%1' already exists. Overwrite?" )
1951 .arg( connectionName ),
1952 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1956 case QMessageBox::Cancel:
1958 case QMessageBox::No:
1959 child = child.nextSiblingElement();
1961 case QMessageBox::Yes:
1964 case QMessageBox::YesToAll:
1968 case QMessageBox::NoToAll:
1975 if ( keys.contains( connectionName ) )
1979 child = child.nextSiblingElement();
1985 keys << connectionName;
1988 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral(
"handler" ) ), connectionName );
1989 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral(
"container" ) ), connectionName );
1990 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral(
"path" ) ), connectionName );
1992 QString credentialString = child.attribute( QStringLiteral(
"credentials" ) );
1994 QVariantMap credentialOptions;
1997 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral(
"\\|credential:([^|]*)" ) );
1998 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral(
"(.*?)=(.*)" ) );
2000 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
2001 if ( match.hasMatch() )
2003 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
2004 if ( keyValueMatch.hasMatch() )
2006 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
2008 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
2016 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
2018 child = child.nextSiblingElement();
2022void QgsManageConnectionsDialog::loadStacConnections(
const QDomDocument &doc,
const QStringList &items )
2024 const QDomElement root = doc.documentElement();
2025 if ( root.tagName() != QLatin1String(
"qgsStacConnections" ) )
2027 QMessageBox::information(
this, tr(
"Loading Connections" ),
2028 tr(
"The file is not a STAC connections exchange file." ) );
2032 QString connectionName;
2034 settings.
beginGroup( QStringLiteral(
"/qgis/connections-stac" ) );
2037 QDomElement child = root.firstChildElement();
2039 bool overwrite =
true;
2041 while ( !child.isNull() )
2043 connectionName = child.attribute( QStringLiteral(
"name" ) );
2044 if ( !items.contains( connectionName ) )
2046 child = child.nextSiblingElement();
2051 if ( keys.contains( connectionName ) && prompt )
2053 const int res = QMessageBox::warning(
this,
2054 tr(
"Loading Connections" ),
2055 tr(
"Connection with name '%1' already exists. Overwrite?" )
2056 .arg( connectionName ),
2057 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
2061 case QMessageBox::Cancel:
2063 case QMessageBox::No:
2064 child = child.nextSiblingElement();
2066 case QMessageBox::Yes:
2069 case QMessageBox::YesToAll:
2073 case QMessageBox::NoToAll:
2080 if ( keys.contains( connectionName ) )
2084 child = child.nextSiblingElement();
2090 keys << connectionName;
2093 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral(
"url" ) ), connectionName );
2094 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral(
"authcfg" ) ), connectionName );
2095 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral(
"username" ) ), connectionName );
2096 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral(
"password" ) ), connectionName );
2099 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2101 child = child.nextSiblingElement();
2107 listConnections->selectAll();
2108 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2113 listConnections->clearSelection();
2114 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