17 #include <QCloseEvent>
18 #include <QFileDialog>
19 #include <QMessageBox>
20 #include <QPushButton>
21 #include <QTextStream>
29 , mFileName( fileName )
31 , mConnectionType( type )
36 QPushButton *pb =
nullptr;
37 pb =
new QPushButton( tr(
"Select all" ) );
38 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
41 pb =
new QPushButton( tr(
"Clear selection" ) );
42 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
45 if ( mDialogMode ==
Import )
47 label->setText( tr(
"Select connections to import" ) );
48 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Import" ) );
49 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
54 buttonBox->button( QDialogButtonBox::Ok )->setText( tr(
"Export" ) );
55 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
58 if ( !populateConnections() )
60 QApplication::postEvent(
this,
new QCloseEvent() );
64 disconnect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
72 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
77 QList<QListWidgetItem *> selection = listConnections->selectedItems();
78 if ( selection.isEmpty() )
80 QMessageBox::warning(
this, tr(
"Export/Import Error" ),
81 tr(
"You should select at least one connection from list." ) );
86 items.reserve( selection.size() );
87 for (
int i = 0; i < selection.size(); ++i )
89 items.append( selection.at( i )->text() );
92 if ( mDialogMode ==
Export )
94 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save Connections" ), QDir::homePath(),
95 tr(
"XML files (*.xml *.XML)" ) );
96 if ( fileName.isEmpty() )
102 if ( !fileName.endsWith( QLatin1String(
".xml" ), Qt::CaseInsensitive ) )
104 fileName += QLatin1String(
".xml" );
107 mFileName = fileName;
110 switch ( mConnectionType )
113 doc = saveOWSConnections( items, QStringLiteral(
"WMS" ) );
116 doc = saveWfsConnections( items );
119 doc = savePgConnections( items );
122 doc = saveMssqlConnections( items );
125 doc = saveOWSConnections( items, QStringLiteral(
"WCS" ) );
128 doc = saveOracleConnections( items );
131 doc = saveDb2Connections( items );
134 doc = saveGeonodeConnections( items );
137 doc = saveXyzTilesConnections( items );
140 doc = saveArcgisConnections( items, QStringLiteral(
"ARCGISMAPSERVER" ) );
143 doc = saveArcgisConnections( items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
146 doc = saveVectorTileConnections( items );
150 QFile file( mFileName );
151 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
153 QMessageBox::warning(
this, tr(
"Saving Connections" ),
154 tr(
"Cannot write file %1:\n%2." )
156 file.errorString() ) );
160 QTextStream out( &file );
165 QFile file( mFileName );
166 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
168 QMessageBox::warning(
this, tr(
"Loading Connections" ),
169 tr(
"Cannot read file %1:\n%2." )
171 file.errorString() ) );
180 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
182 QMessageBox::warning(
this, tr(
"Loading Connections" ),
183 tr(
"Parse error at line %1, column %2:\n%3" )
190 switch ( mConnectionType )
193 loadOWSConnections( doc, items, QStringLiteral(
"WMS" ) );
196 loadWfsConnections( doc, items );
199 loadPgConnections( doc, items );
202 loadMssqlConnections( doc, items );
205 loadOWSConnections( doc, items, QStringLiteral(
"WCS" ) );
208 loadOracleConnections( doc, items );
211 loadDb2Connections( doc, items );
214 loadGeonodeConnections( doc, items );
217 loadXyzTilesConnections( doc, items );
220 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISMAPSERVER" ) );
223 loadArcgisConnections( doc, items, QStringLiteral(
"ARCGISFEATURESERVER" ) );
226 loadVectorTileConnections( doc, items );
230 listConnections->clear();
237 bool QgsManageConnectionsDialog::populateConnections()
240 if ( mDialogMode ==
Export )
243 switch ( mConnectionType )
246 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wms" ) );
249 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
252 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wcs" ) );
255 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
258 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
261 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
264 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
267 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
270 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
273 settings.
beginGroup( QStringLiteral(
"/qgis/connections-arcgismapserver" ) );
276 settings.
beginGroup( QStringLiteral(
"/qgis/connections-arcgisfeatureserver" ) );
279 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
283 QStringList::Iterator it = keys.begin();
284 while ( it != keys.end() )
286 QListWidgetItem *item =
new QListWidgetItem();
287 item->setText( *it );
288 listConnections->addItem( item );
296 QFile file( mFileName );
297 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
299 QMessageBox::warning(
this, tr(
"Loading Connections" ),
300 tr(
"Cannot read file %1:\n%2." )
302 file.errorString() ) );
311 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
313 QMessageBox::warning(
this, tr(
"Loading Connections" ),
314 tr(
"Parse error at line %1, column %2:\n%3" )
321 QDomElement root = doc.documentElement();
322 switch ( mConnectionType )
325 if ( root.tagName() != QLatin1String(
"qgsWMSConnections" ) )
327 QMessageBox::information(
this, tr(
"Loading Connections" ),
328 tr(
"The file is not a WMS connections exchange file." ) );
334 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
336 QMessageBox::information(
this, tr(
"Loading Connections" ),
337 tr(
"The file is not a WFS connections exchange file." ) );
343 if ( root.tagName() != QLatin1String(
"qgsWCSConnections" ) )
345 QMessageBox::information(
this, tr(
"Loading Connections" ),
346 tr(
"The file is not a WCS connections exchange file." ) );
352 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
354 QMessageBox::information(
this, tr(
"Loading Connections" ),
355 tr(
"The file is not a PostGIS connections exchange file." ) );
361 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
363 QMessageBox::information(
this, tr(
"Loading Connections" ),
364 tr(
"The file is not a MSSQL connections exchange file." ) );
369 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
371 QMessageBox::information(
this, tr(
"Loading Connections" ),
372 tr(
"The file is not an Oracle connections exchange file." ) );
377 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
379 QMessageBox::information(
this, tr(
"Loading Connections" ),
380 tr(
"The file is not a DB2 connections exchange file." ) );
385 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
387 QMessageBox::information(
this, tr(
"Loading Connections" ),
388 tr(
"The file is not a GeoNode connections exchange file." ) );
393 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
395 QMessageBox::information(
this, tr(
"Loading Connections" ),
396 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
401 if ( root.tagName() != QLatin1String(
"qgsARCGISMAPSERVERConnections" ) )
403 QMessageBox::information(
this, tr(
"Loading Connections" ),
404 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" ),
412 tr(
"The file is not a ArcGIS Feature Service connections exchange file." ) );
417 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
419 QMessageBox::information(
this, tr(
"Loading Connections" ),
420 tr(
"The file is not a Vector Tile connections exchange file." ) );
426 QDomElement child = root.firstChildElement();
427 while ( !child.isNull() )
429 QListWidgetItem *item =
new QListWidgetItem();
430 item->setText( child.attribute( QStringLiteral(
"name" ) ) );
431 listConnections->addItem( item );
432 child = child.nextSiblingElement();
438 QDomDocument QgsManageConnectionsDialog::saveOWSConnections(
const QStringList &connections,
const QString &service )
440 QDomDocument doc( QStringLiteral(
"connections" ) );
441 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
442 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
443 doc.appendChild( root );
447 for (
int i = 0; i < connections.count(); ++i )
449 path =
"/qgis/connections-" + service.toLower() +
'/';
450 QDomElement el = doc.createElement( service.toLower() );
451 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
452 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
454 if ( service == QLatin1String(
"WMS" ) )
456 el.setAttribute( QStringLiteral(
"ignoreGetMapURI" ), settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).toBool() ?
"true" :
"false" );
457 el.setAttribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ), settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).toBool() ?
"true" :
"false" );
458 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).toBool() ?
"true" :
"false" );
459 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).toBool() ?
"true" :
"false" );
460 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer" ).toString() );
461 el.setAttribute( QStringLiteral(
"smoothPixmapTransform" ), settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).toBool() ?
"true" :
"false" );
462 el.setAttribute( QStringLiteral(
"dpiMode" ), settings.
value( path + connections[i] +
"/dpiMode",
"7" ).toInt() );
465 path =
"/qgis/" + service.toUpper() +
'/';
466 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
467 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
468 root.appendChild( el );
474 QDomDocument QgsManageConnectionsDialog::saveWfsConnections(
const QStringList &connections )
476 QDomDocument doc( QStringLiteral(
"connections" ) );
477 QDomElement root = doc.createElement( QStringLiteral(
"qgsWFSConnections" ) );
478 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1" ) );
479 doc.appendChild( root );
483 for (
int i = 0; i < connections.count(); ++i )
485 path = QStringLiteral(
"/qgis/connections-wfs/" );
486 QDomElement el = doc.createElement( QStringLiteral(
"wfs" ) );
487 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
488 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
490 el.setAttribute( QStringLiteral(
"version" ), settings.
value( path + connections[ i ] +
"/version" ).toString() );
491 el.setAttribute( QStringLiteral(
"maxnumfeatures" ), settings.
value( path + connections[ i ] +
"/maxnumfeatures" ).toString() );
492 el.setAttribute( QStringLiteral(
"pagesize" ), settings.
value( path + connections[ i ] +
"/pagesize" ).toString() );
493 el.setAttribute( QStringLiteral(
"pagingenabled" ), settings.
value( path + connections[ i ] +
"/pagingenabled",
false ).toString() );
494 el.setAttribute( QStringLiteral(
"ignoreAxisOrientation" ), settings.
value( path + connections[ i ] +
"/ignoreAxisOrientation",
false ).toString() );
495 el.setAttribute( QStringLiteral(
"invertAxisOrientation" ), settings.
value( path + connections[ i ] +
"/invertAxisOrientation",
false ).toString() );
497 path = QStringLiteral(
"/qgis/WFS/" );
498 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
499 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
500 root.appendChild( el );
506 QDomDocument QgsManageConnectionsDialog::savePgConnections(
const QStringList &connections )
508 QDomDocument doc( QStringLiteral(
"connections" ) );
509 QDomElement root = doc.createElement( QStringLiteral(
"qgsPgConnections" ) );
510 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
511 doc.appendChild( root );
515 for (
int i = 0; i < connections.count(); ++i )
517 path =
"/PostgreSQL/connections/" + connections[ i ];
518 QDomElement el = doc.createElement( QStringLiteral(
"postgis" ) );
519 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
520 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
521 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
522 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
523 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
524 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
525 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
527 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
529 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
531 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
534 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
536 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
538 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
541 root.appendChild( el );
547 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections(
const QStringList &connections )
549 QDomDocument doc( QStringLiteral(
"connections" ) );
550 QDomElement root = doc.createElement( QStringLiteral(
"qgsMssqlConnections" ) );
551 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
552 doc.appendChild( root );
556 for (
int i = 0; i < connections.count(); ++i )
558 path =
"/MSSQL/connections/" + connections[ i ];
559 QDomElement el = doc.createElement( QStringLiteral(
"mssql" ) );
560 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
561 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
562 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
563 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
564 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
565 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
566 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
568 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
570 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
572 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
575 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
577 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
579 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
582 root.appendChild( el );
588 QDomDocument QgsManageConnectionsDialog::saveOracleConnections(
const QStringList &connections )
590 QDomDocument doc( QStringLiteral(
"connections" ) );
591 QDomElement root = doc.createElement( QStringLiteral(
"qgsOracleConnections" ) );
592 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
593 doc.appendChild( root );
597 for (
int i = 0; i < connections.count(); ++i )
599 path =
"/Oracle/connections/" + connections[ i ];
600 QDomElement el = doc.createElement( QStringLiteral(
"oracle" ) );
601 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
602 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
603 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
604 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
605 el.setAttribute( QStringLiteral(
"dboptions" ), settings.
value( path +
"/dboptions" ).toString() );
606 el.setAttribute( QStringLiteral(
"dbworkspace" ), settings.
value( path +
"/dbworkspace" ).toString() );
607 el.setAttribute( QStringLiteral(
"schema" ), settings.
value( path +
"/schema" ).toString() );
608 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
609 el.setAttribute( QStringLiteral(
"userTablesOnly" ), settings.
value( path +
"/userTablesOnly",
"0" ).toString() );
610 el.setAttribute( QStringLiteral(
"geometryColumnsOnly" ), settings.
value( path +
"/geometryColumnsOnly",
"0" ).toString() );
611 el.setAttribute( QStringLiteral(
"allowGeometrylessTables" ), settings.
value( path +
"/allowGeometrylessTables",
"0" ).toString() );
613 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
615 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
617 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
620 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
622 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
624 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
627 root.appendChild( el );
633 QDomDocument QgsManageConnectionsDialog::saveDb2Connections(
const QStringList &connections )
635 QDomDocument doc( QStringLiteral(
"connections" ) );
636 QDomElement root = doc.createElement( QStringLiteral(
"qgsDb2Connections" ) );
637 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
638 doc.appendChild( root );
642 for (
int i = 0; i < connections.count(); ++i )
644 path =
"/DB2/connections/" + connections[ i ];
645 QDomElement el = doc.createElement( QStringLiteral(
"db2" ) );
646 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
647 el.setAttribute( QStringLiteral(
"host" ), settings.
value( path +
"/host" ).toString() );
648 el.setAttribute( QStringLiteral(
"port" ), settings.
value( path +
"/port" ).toString() );
649 el.setAttribute( QStringLiteral(
"database" ), settings.
value( path +
"/database" ).toString() );
650 el.setAttribute( QStringLiteral(
"service" ), settings.
value( path +
"/service" ).toString() );
651 el.setAttribute( QStringLiteral(
"sslmode" ), settings.
value( path +
"/sslmode",
"1" ).toString() );
652 el.setAttribute( QStringLiteral(
"estimatedMetadata" ), settings.
value( path +
"/estimatedMetadata",
"0" ).toString() );
654 el.setAttribute( QStringLiteral(
"saveUsername" ), settings.
value( path +
"/saveUsername",
"false" ).toString() );
656 if ( settings.
value( path +
"/saveUsername",
"false" ).toString() == QLatin1String(
"true" ) )
658 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
661 el.setAttribute( QStringLiteral(
"savePassword" ), settings.
value( path +
"/savePassword",
"false" ).toString() );
663 if ( settings.
value( path +
"/savePassword",
"false" ).toString() == QLatin1String(
"true" ) )
665 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
668 root.appendChild( el );
674 QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections(
const QStringList &connections )
676 QDomDocument doc( QStringLiteral(
"connections" ) );
677 QDomElement root = doc.createElement( QStringLiteral(
"qgsGeoNodeConnections" ) );
678 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
679 doc.appendChild( root );
683 for (
int i = 0; i < connections.count(); ++i )
685 path = QStringLiteral(
"/qgis/connections-geonode/" );
686 QDomElement el = doc.createElement( QStringLiteral(
"geonode" ) );
687 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
688 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
690 path = QStringLiteral(
"/qgis/GeoNode/" );
691 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
692 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
693 root.appendChild( el );
699 QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections(
const QStringList &connections )
701 QDomDocument doc( QStringLiteral(
"connections" ) );
702 QDomElement root = doc.createElement( QStringLiteral(
"qgsXYZTilesConnections" ) );
703 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
704 doc.appendChild( root );
708 for (
int i = 0; i < connections.count(); ++i )
710 path =
"qgis/connections-xyz/" + connections[ i ];
711 QDomElement el = doc.createElement( QStringLiteral(
"xyztiles" ) );
713 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
714 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path +
"/url" ).toString() );
715 el.setAttribute( QStringLiteral(
"zmin" ), settings.
value( path +
"/zmin", -1 ).toInt() );
716 el.setAttribute( QStringLiteral(
"zmax" ), settings.
value( path +
"/zmax", -1 ).toInt() );
717 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path +
"/authcfg" ).toString() );
718 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
719 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
720 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path +
"/referer" ).toString() );
721 el.setAttribute( QStringLiteral(
"tilePixelRatio" ), settings.
value( path +
"/tilePixelRatio", 0 ).toDouble() );
723 root.appendChild( el );
729 QDomDocument QgsManageConnectionsDialog::saveArcgisConnections(
const QStringList &connections,
const QString &service )
731 QDomDocument doc( QStringLiteral(
"connections" ) );
732 QDomElement root = doc.createElement(
"qgs" + service.toUpper() +
"Connections" );
733 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
734 doc.appendChild( root );
738 for (
int i = 0; i < connections.count(); ++i )
740 path =
"/qgis/connections-" + service.toLower() +
'/';
741 QDomElement el = doc.createElement( service.toLower() );
742 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
743 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path + connections[ i ] +
"/url" ).toString() );
744 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path + connections[ i ] +
"/referer" ).toString() );
746 path =
"/qgis/" + service.toUpper() +
'/';
747 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path + connections[ i ] +
"/username" ).toString() );
748 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path + connections[ i ] +
"/password" ).toString() );
749 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path + connections[ i ] +
"/authcfg" ).toString() );
750 root.appendChild( el );
756 QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections(
const QStringList &connections )
758 QDomDocument doc( QStringLiteral(
"connections" ) );
759 QDomElement root = doc.createElement( QStringLiteral(
"qgsVectorTileConnections" ) );
760 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0" ) );
761 doc.appendChild( root );
765 for (
int i = 0; i < connections.count(); ++i )
767 path =
"qgis/connections-vector-tile/" + connections[ i ];
768 QDomElement el = doc.createElement( QStringLiteral(
"vectortile" ) );
770 el.setAttribute( QStringLiteral(
"name" ), connections[ i ] );
771 el.setAttribute( QStringLiteral(
"url" ), settings.
value( path +
"/url" ).toString() );
772 el.setAttribute( QStringLiteral(
"zmin" ), settings.
value( path +
"/zmin", -1 ).toInt() );
773 el.setAttribute( QStringLiteral(
"zmax" ), settings.
value( path +
"/zmax", -1 ).toInt() );
774 el.setAttribute( QStringLiteral(
"serviceType" ), settings.
value( path +
"/serviceType", -1 ).toInt() );
775 el.setAttribute( QStringLiteral(
"authcfg" ), settings.
value( path +
"/authcfg" ).toString() );
776 el.setAttribute( QStringLiteral(
"username" ), settings.
value( path +
"/username" ).toString() );
777 el.setAttribute( QStringLiteral(
"password" ), settings.
value( path +
"/password" ).toString() );
778 el.setAttribute( QStringLiteral(
"referer" ), settings.
value( path +
"/referer" ).toString() );
779 el.setAttribute( QStringLiteral(
"styleUrl" ), settings.
value( path +
"/styleUrl" ).toString() );
781 root.appendChild( el );
787 void QgsManageConnectionsDialog::loadOWSConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
789 QDomElement root = doc.documentElement();
790 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
792 QMessageBox::information(
this, tr(
"Loading Connections" ),
793 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
797 QString connectionName;
799 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
802 QDomElement child = root.firstChildElement();
804 bool overwrite =
true;
806 while ( !child.isNull() )
808 connectionName = child.attribute( QStringLiteral(
"name" ) );
809 if ( !items.contains( connectionName ) )
811 child = child.nextSiblingElement();
816 if ( keys.contains( connectionName ) && prompt )
818 int res = QMessageBox::warning(
this,
819 tr(
"Loading Connections" ),
820 tr(
"Connection with name '%1' already exists. Overwrite?" )
821 .arg( connectionName ),
822 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
826 case QMessageBox::Cancel:
828 case QMessageBox::No:
829 child = child.nextSiblingElement();
831 case QMessageBox::Yes:
834 case QMessageBox::YesToAll:
838 case QMessageBox::NoToAll:
845 if ( keys.contains( connectionName ) && !overwrite )
847 child = child.nextSiblingElement();
852 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
853 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
854 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetMapURI" ), child.attribute( QStringLiteral(
"ignoreGetMapURI" ) ) == QLatin1String(
"true" ) );
855 settings.
setValue( QString(
'/' + connectionName +
"/ignoreGetFeatureInfoURI" ), child.attribute( QStringLiteral(
"ignoreGetFeatureInfoURI" ) ) == QLatin1String(
"true" ) );
856 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) == QLatin1String(
"true" ) );
857 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) == QLatin1String(
"true" ) );
858 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
859 settings.
setValue( QString(
'/' + connectionName +
"/smoothPixmapTransform" ), child.attribute( QStringLiteral(
"smoothPixmapTransform" ) ) == QLatin1String(
"true" ) );
860 settings.
setValue( QString(
'/' + connectionName +
"/dpiMode" ), child.attribute( QStringLiteral(
"dpiMode" ), QStringLiteral(
"7" ) ).toInt() );
863 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
865 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
866 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
867 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
870 child = child.nextSiblingElement();
874 void QgsManageConnectionsDialog::loadWfsConnections(
const QDomDocument &doc,
const QStringList &items )
876 QDomElement root = doc.documentElement();
877 if ( root.tagName() != QLatin1String(
"qgsWFSConnections" ) )
879 QMessageBox::information(
this, tr(
"Loading Connections" ),
880 tr(
"The file is not a WFS connections exchange file." ) );
884 QString connectionName;
886 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
889 QDomElement child = root.firstChildElement();
891 bool overwrite =
true;
893 while ( !child.isNull() )
895 connectionName = child.attribute( QStringLiteral(
"name" ) );
896 if ( !items.contains( connectionName ) )
898 child = child.nextSiblingElement();
903 if ( keys.contains( connectionName ) && prompt )
905 int res = QMessageBox::warning(
this,
906 tr(
"Loading Connections" ),
907 tr(
"Connection with name '%1' already exists. Overwrite?" )
908 .arg( connectionName ),
909 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
913 case QMessageBox::Cancel:
915 case QMessageBox::No:
916 child = child.nextSiblingElement();
918 case QMessageBox::Yes:
921 case QMessageBox::YesToAll:
925 case QMessageBox::NoToAll:
932 if ( keys.contains( connectionName ) && !overwrite )
934 child = child.nextSiblingElement();
939 settings.
beginGroup( QStringLiteral(
"/qgis/connections-wfs" ) );
940 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
942 settings.
setValue( QString(
'/' + connectionName +
"/version" ), child.attribute( QStringLiteral(
"version" ) ) );
943 settings.
setValue( QString(
'/' + connectionName +
"/maxnumfeatures" ), child.attribute( QStringLiteral(
"maxnumfeatures" ) ) );
944 settings.
setValue( QString(
'/' + connectionName +
"/pagesize" ), child.attribute( QStringLiteral(
"pagesize" ) ) );
945 settings.
setValue( QString(
'/' + connectionName +
"/pagingenabled" ), child.attribute( QStringLiteral(
"pagingenabled" ) ) );
946 settings.
setValue( QString(
'/' + connectionName +
"/ignoreAxisOrientation" ), child.attribute( QStringLiteral(
"ignoreAxisOrientation" ) ) );
947 settings.
setValue( QString(
'/' + connectionName +
"/invertAxisOrientation" ), child.attribute( QStringLiteral(
"invertAxisOrientation" ) ) );
950 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
952 settings.
beginGroup(
"/qgis/WFS/" + connectionName );
953 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
954 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
957 child = child.nextSiblingElement();
961 void QgsManageConnectionsDialog::loadPgConnections(
const QDomDocument &doc,
const QStringList &items )
963 QDomElement root = doc.documentElement();
964 if ( root.tagName() != QLatin1String(
"qgsPgConnections" ) )
966 QMessageBox::information(
this,
967 tr(
"Loading Connections" ),
968 tr(
"The file is not a PostGIS connections exchange file." ) );
972 QString connectionName;
974 settings.
beginGroup( QStringLiteral(
"/PostgreSQL/connections" ) );
977 QDomElement child = root.firstChildElement();
979 bool overwrite =
true;
981 while ( !child.isNull() )
983 connectionName = child.attribute( QStringLiteral(
"name" ) );
984 if ( !items.contains( connectionName ) )
986 child = child.nextSiblingElement();
991 if ( keys.contains( connectionName ) && prompt )
993 int res = QMessageBox::warning(
this,
994 tr(
"Loading Connections" ),
995 tr(
"Connection with name '%1' already exists. Overwrite?" )
996 .arg( connectionName ),
997 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1000 case QMessageBox::Cancel:
1002 case QMessageBox::No:
1003 child = child.nextSiblingElement();
1005 case QMessageBox::Yes:
1008 case QMessageBox::YesToAll:
1012 case QMessageBox::NoToAll:
1019 if ( keys.contains( connectionName ) && !overwrite )
1021 child = child.nextSiblingElement();
1026 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
1028 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1029 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1030 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1031 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1033 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1037 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1039 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1040 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1041 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1042 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1043 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1044 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1047 child = child.nextSiblingElement();
1051 void QgsManageConnectionsDialog::loadMssqlConnections(
const QDomDocument &doc,
const QStringList &items )
1053 QDomElement root = doc.documentElement();
1054 if ( root.tagName() != QLatin1String(
"qgsMssqlConnections" ) )
1056 QMessageBox::information(
this,
1057 tr(
"Loading Connections" ),
1058 tr(
"The file is not a MSSQL connections exchange file." ) );
1062 QString connectionName;
1064 settings.
beginGroup( QStringLiteral(
"/MSSQL/connections" ) );
1067 QDomElement child = root.firstChildElement();
1069 bool overwrite =
true;
1071 while ( !child.isNull() )
1073 connectionName = child.attribute( QStringLiteral(
"name" ) );
1074 if ( !items.contains( connectionName ) )
1076 child = child.nextSiblingElement();
1081 if ( keys.contains( connectionName ) && prompt )
1083 int res = QMessageBox::warning(
this,
1084 tr(
"Loading Connections" ),
1085 tr(
"Connection with name '%1' already exists. Overwrite?" )
1086 .arg( connectionName ),
1087 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1090 case QMessageBox::Cancel:
1092 case QMessageBox::No:
1093 child = child.nextSiblingElement();
1095 case QMessageBox::Yes:
1098 case QMessageBox::YesToAll:
1102 case QMessageBox::NoToAll:
1109 if ( keys.contains( connectionName ) && !overwrite )
1111 child = child.nextSiblingElement();
1116 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
1118 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1119 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1120 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1121 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1123 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1127 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1129 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1130 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1131 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1132 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1133 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1134 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1137 child = child.nextSiblingElement();
1141 void QgsManageConnectionsDialog::loadOracleConnections(
const QDomDocument &doc,
const QStringList &items )
1143 QDomElement root = doc.documentElement();
1144 if ( root.tagName() != QLatin1String(
"qgsOracleConnections" ) )
1146 QMessageBox::information(
this,
1147 tr(
"Loading Connections" ),
1148 tr(
"The file is not an Oracle connections exchange file." ) );
1152 QString connectionName;
1154 settings.
beginGroup( QStringLiteral(
"/Oracle/connections" ) );
1157 QDomElement child = root.firstChildElement();
1159 bool overwrite =
true;
1161 while ( !child.isNull() )
1163 connectionName = child.attribute( QStringLiteral(
"name" ) );
1164 if ( !items.contains( connectionName ) )
1166 child = child.nextSiblingElement();
1171 if ( keys.contains( connectionName ) && prompt )
1173 int res = QMessageBox::warning(
this,
1174 tr(
"Loading Connections" ),
1175 tr(
"Connection with name '%1' already exists. Overwrite?" )
1176 .arg( connectionName ),
1177 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1180 case QMessageBox::Cancel:
1182 case QMessageBox::No:
1183 child = child.nextSiblingElement();
1185 case QMessageBox::Yes:
1188 case QMessageBox::YesToAll:
1192 case QMessageBox::NoToAll:
1199 if ( keys.contains( connectionName ) && !overwrite )
1201 child = child.nextSiblingElement();
1206 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
1208 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1209 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1210 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1211 settings.
setValue( QStringLiteral(
"/dboptions" ), child.attribute( QStringLiteral(
"dboptions" ) ) );
1212 settings.
setValue( QStringLiteral(
"/dbworkspace" ), child.attribute( QStringLiteral(
"dbworkspace" ) ) );
1213 settings.
setValue( QStringLiteral(
"/schema" ), child.attribute( QStringLiteral(
"schema" ) ) );
1214 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1215 settings.
setValue( QStringLiteral(
"/userTablesOnly" ), child.attribute( QStringLiteral(
"userTablesOnly" ) ) );
1216 settings.
setValue( QStringLiteral(
"/geometryColumnsOnly" ), child.attribute( QStringLiteral(
"geometryColumnsOnly" ) ) );
1217 settings.
setValue( QStringLiteral(
"/allowGeometrylessTables" ), child.attribute( QStringLiteral(
"allowGeometrylessTables" ) ) );
1218 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1219 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1220 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1221 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1224 child = child.nextSiblingElement();
1228 void QgsManageConnectionsDialog::loadDb2Connections(
const QDomDocument &doc,
const QStringList &items )
1230 QDomElement root = doc.documentElement();
1231 if ( root.tagName() != QLatin1String(
"qgsDb2Connections" ) )
1233 QMessageBox::information(
this,
1234 tr(
"Loading Connections" ),
1235 tr(
"The file is not a DB2 connections exchange file." ) );
1239 QString connectionName;
1241 settings.
beginGroup( QStringLiteral(
"/DB2/connections" ) );
1244 QDomElement child = root.firstChildElement();
1246 bool overwrite =
true;
1248 while ( !child.isNull() )
1250 connectionName = child.attribute( QStringLiteral(
"name" ) );
1251 if ( !items.contains( connectionName ) )
1253 child = child.nextSiblingElement();
1258 if ( keys.contains( connectionName ) && prompt )
1260 int res = QMessageBox::warning(
this,
1261 tr(
"Loading Connections" ),
1262 tr(
"Connection with name '%1' already exists. Overwrite?" )
1263 .arg( connectionName ),
1264 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1267 case QMessageBox::Cancel:
1269 case QMessageBox::No:
1270 child = child.nextSiblingElement();
1272 case QMessageBox::Yes:
1275 case QMessageBox::YesToAll:
1279 case QMessageBox::NoToAll:
1286 if ( keys.contains( connectionName ) && !overwrite )
1288 child = child.nextSiblingElement();
1293 settings.
beginGroup(
"/DB2/connections/" + connectionName );
1295 settings.
setValue( QStringLiteral(
"/host" ), child.attribute( QStringLiteral(
"host" ) ) );
1296 settings.
setValue( QStringLiteral(
"/port" ), child.attribute( QStringLiteral(
"port" ) ) );
1297 settings.
setValue( QStringLiteral(
"/database" ), child.attribute( QStringLiteral(
"database" ) ) );
1298 if ( child.hasAttribute( QStringLiteral(
"service" ) ) )
1300 settings.
setValue( QStringLiteral(
"/service" ), child.attribute( QStringLiteral(
"service" ) ) );
1304 settings.
setValue( QStringLiteral(
"/service" ),
"" );
1306 settings.
setValue( QStringLiteral(
"/sslmode" ), child.attribute( QStringLiteral(
"sslmode" ) ) );
1307 settings.
setValue( QStringLiteral(
"/estimatedMetadata" ), child.attribute( QStringLiteral(
"estimatedMetadata" ) ) );
1308 settings.
setValue( QStringLiteral(
"/saveUsername" ), child.attribute( QStringLiteral(
"saveUsername" ) ) );
1309 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1310 settings.
setValue( QStringLiteral(
"/savePassword" ), child.attribute( QStringLiteral(
"savePassword" ) ) );
1311 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1314 child = child.nextSiblingElement();
1318 void QgsManageConnectionsDialog::loadGeonodeConnections(
const QDomDocument &doc,
const QStringList &items )
1320 QDomElement root = doc.documentElement();
1321 if ( root.tagName() != QLatin1String(
"qgsGeoNodeConnections" ) )
1323 QMessageBox::information(
this, tr(
"Loading Connections" ),
1324 tr(
"The file is not a GeoNode connections exchange file." ) );
1328 QString connectionName;
1330 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1333 QDomElement child = root.firstChildElement();
1335 bool overwrite =
true;
1337 while ( !child.isNull() )
1339 connectionName = child.attribute( QStringLiteral(
"name" ) );
1340 if ( !items.contains( connectionName ) )
1342 child = child.nextSiblingElement();
1347 if ( keys.contains( connectionName ) && prompt )
1349 int res = QMessageBox::warning(
this,
1350 tr(
"Loading Connections" ),
1351 tr(
"Connection with name '%1' already exists. Overwrite?" )
1352 .arg( connectionName ),
1353 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1357 case QMessageBox::Cancel:
1359 case QMessageBox::No:
1360 child = child.nextSiblingElement();
1362 case QMessageBox::Yes:
1365 case QMessageBox::YesToAll:
1369 case QMessageBox::NoToAll:
1376 if ( keys.contains( connectionName ) && !overwrite )
1378 child = child.nextSiblingElement();
1383 settings.
beginGroup( QStringLiteral(
"/qgis/connections-geonode" ) );
1384 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1387 if ( !child.attribute( QStringLiteral(
"username" ) ).isEmpty() )
1389 settings.
beginGroup(
"/qgis/GeoNode/" + connectionName );
1390 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1391 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1394 child = child.nextSiblingElement();
1398 void QgsManageConnectionsDialog::loadXyzTilesConnections(
const QDomDocument &doc,
const QStringList &items )
1400 QDomElement root = doc.documentElement();
1401 if ( root.tagName() != QLatin1String(
"qgsXYZTilesConnections" ) )
1403 QMessageBox::information(
this, tr(
"Loading Connections" ),
1404 tr(
"The file is not a XYZ Tiles connections exchange file." ) );
1408 QString connectionName;
1410 settings.
beginGroup( QStringLiteral(
"/qgis/connections-xyz" ) );
1413 QDomElement child = root.firstChildElement();
1415 bool overwrite =
true;
1417 while ( !child.isNull() )
1419 connectionName = child.attribute( QStringLiteral(
"name" ) );
1420 if ( !items.contains( connectionName ) )
1422 child = child.nextSiblingElement();
1427 if ( keys.contains( connectionName ) && prompt )
1429 int res = QMessageBox::warning(
this,
1430 tr(
"Loading Connections" ),
1431 tr(
"Connection with name '%1' already exists. Overwrite?" )
1432 .arg( connectionName ),
1433 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1437 case QMessageBox::Cancel:
1439 case QMessageBox::No:
1440 child = child.nextSiblingElement();
1442 case QMessageBox::Yes:
1445 case QMessageBox::YesToAll:
1449 case QMessageBox::NoToAll:
1456 if ( keys.contains( connectionName ) && !overwrite )
1458 child = child.nextSiblingElement();
1462 settings.
beginGroup(
"qgis/connections-xyz/" + connectionName );
1463 settings.
setValue( QStringLiteral(
"url" ), child.attribute( QStringLiteral(
"url" ) ) );
1464 settings.
setValue( QStringLiteral(
"zmin" ), child.attribute( QStringLiteral(
"zmin" ) ) );
1465 settings.
setValue( QStringLiteral(
"zmax" ), child.attribute( QStringLiteral(
"zmax" ) ) );
1466 settings.
setValue( QStringLiteral(
"authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1467 settings.
setValue( QStringLiteral(
"username" ), child.attribute( QStringLiteral(
"username" ) ) );
1468 settings.
setValue( QStringLiteral(
"password" ), child.attribute( QStringLiteral(
"password" ) ) );
1469 settings.
setValue( QStringLiteral(
"referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1470 settings.
setValue( QStringLiteral(
"tilePixelRatio" ), child.attribute( QStringLiteral(
"tilePixelRatio" ) ) );
1473 child = child.nextSiblingElement();
1477 void QgsManageConnectionsDialog::loadArcgisConnections(
const QDomDocument &doc,
const QStringList &items,
const QString &service )
1479 QDomElement root = doc.documentElement();
1480 if ( root.tagName() !=
"qgs" + service.toUpper() +
"Connections" )
1482 QMessageBox::information(
this, tr(
"Loading Connections" ),
1483 tr(
"The file is not a %1 connections exchange file." ).arg( service ) );
1487 QString connectionName;
1489 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
1492 QDomElement child = root.firstChildElement();
1494 bool overwrite =
true;
1496 while ( !child.isNull() )
1498 connectionName = child.attribute( QStringLiteral(
"name" ) );
1499 if ( !items.contains( connectionName ) )
1501 child = child.nextSiblingElement();
1506 if ( keys.contains( connectionName ) && prompt )
1508 int res = QMessageBox::warning(
this,
1509 tr(
"Loading Connections" ),
1510 tr(
"Connection with name '%1' already exists. Overwrite?" )
1511 .arg( connectionName ),
1512 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1516 case QMessageBox::Cancel:
1518 case QMessageBox::No:
1519 child = child.nextSiblingElement();
1521 case QMessageBox::Yes:
1524 case QMessageBox::YesToAll:
1528 case QMessageBox::NoToAll:
1535 if ( keys.contains( connectionName ) && !overwrite )
1537 child = child.nextSiblingElement();
1542 settings.
beginGroup(
"/qgis/connections-" + service.toLower() );
1543 settings.
setValue( QString(
'/' + connectionName +
"/url" ), child.attribute( QStringLiteral(
"url" ) ) );
1544 settings.
setValue( QString(
'/' + connectionName +
"/referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1547 settings.
beginGroup(
"/qgis/" + service.toUpper() +
'/' + connectionName );
1548 settings.
setValue( QStringLiteral(
"/username" ), child.attribute( QStringLiteral(
"username" ) ) );
1549 settings.
setValue( QStringLiteral(
"/password" ), child.attribute( QStringLiteral(
"password" ) ) );
1550 settings.
setValue( QStringLiteral(
"/authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1553 child = child.nextSiblingElement();
1557 void QgsManageConnectionsDialog::loadVectorTileConnections(
const QDomDocument &doc,
const QStringList &items )
1559 QDomElement root = doc.documentElement();
1560 if ( root.tagName() != QLatin1String(
"qgsVectorTileConnections" ) )
1562 QMessageBox::information(
this, tr(
"Loading Connections" ),
1563 tr(
"The file is not a Vector Tile connections exchange file." ) );
1567 QString connectionName;
1569 settings.
beginGroup( QStringLiteral(
"/qgis/connections-vector-tile" ) );
1572 QDomElement child = root.firstChildElement();
1574 bool overwrite =
true;
1576 while ( !child.isNull() )
1578 connectionName = child.attribute( QStringLiteral(
"name" ) );
1579 if ( !items.contains( connectionName ) )
1581 child = child.nextSiblingElement();
1586 if ( keys.contains( connectionName ) && prompt )
1588 int res = QMessageBox::warning(
this,
1589 tr(
"Loading Connections" ),
1590 tr(
"Connection with name '%1' already exists. Overwrite?" )
1591 .arg( connectionName ),
1592 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1596 case QMessageBox::Cancel:
1598 case QMessageBox::No:
1599 child = child.nextSiblingElement();
1601 case QMessageBox::Yes:
1604 case QMessageBox::YesToAll:
1608 case QMessageBox::NoToAll:
1615 if ( keys.contains( connectionName ) && !overwrite )
1617 child = child.nextSiblingElement();
1621 settings.
beginGroup(
"qgis/connections-vector-tile/" + connectionName );
1622 settings.
setValue( QStringLiteral(
"url" ), child.attribute( QStringLiteral(
"url" ) ) );
1623 settings.
setValue( QStringLiteral(
"zmin" ), child.attribute( QStringLiteral(
"zmin" ) ) );
1624 settings.
setValue( QStringLiteral(
"zmax" ), child.attribute( QStringLiteral(
"zmax" ) ) );
1625 settings.
setValue( QStringLiteral(
"serviceType" ), child.attribute( QStringLiteral(
"serviceType" ) ) );
1626 settings.
setValue( QStringLiteral(
"authcfg" ), child.attribute( QStringLiteral(
"authcfg" ) ) );
1627 settings.
setValue( QStringLiteral(
"username" ), child.attribute( QStringLiteral(
"username" ) ) );
1628 settings.
setValue( QStringLiteral(
"password" ), child.attribute( QStringLiteral(
"password" ) ) );
1629 settings.
setValue( QStringLiteral(
"referer" ), child.attribute( QStringLiteral(
"referer" ) ) );
1630 settings.
setValue( QStringLiteral(
"styleUrl" ), child.attribute( QStringLiteral(
"styleUrl" ) ) );
1634 child = child.nextSiblingElement();
1640 listConnections->selectAll();
1641 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1646 listConnections->clearSelection();
1647 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );