QGIS API Documentation 3.43.0-Master (7996e1b587e)
qgsmanageconnectionsdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmanageconnectionsdialog.cpp
3 ---------------------
4 begin : Dec 2009
5 copyright : (C) 2009 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include <QCloseEvent>
18#include <QFileDialog>
19#include <QMessageBox>
20#include <QPushButton>
21#include <QTextStream>
22
23#include "qgssettings.h"
25#include "moc_qgsmanageconnectionsdialog.cpp"
26#include "qgshttpheaders.h"
27#include "qgsowsconnection.h"
33#include "qgsgdalcloudconnection.h"
34#include "qgsstacconnection.h"
35
36QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type, const QString &fileName )
37 : QDialog( parent )
38 , mFileName( fileName )
39 , mDialogMode( mode )
40 , mConnectionType( type )
41{
42 setupUi( this );
43
44 // additional buttons
45 QPushButton *pb = nullptr;
46 pb = new QPushButton( tr( "Select All" ) );
47 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
48 connect( pb, &QAbstractButton::clicked, this, &QgsManageConnectionsDialog::selectAll );
49
50 pb = new QPushButton( tr( "Clear Selection" ) );
51 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
52 connect( pb, &QAbstractButton::clicked, this, &QgsManageConnectionsDialog::clearSelection );
53
54 if ( mDialogMode == Import )
55 {
56 label->setText( tr( "Select connections to import" ) );
57 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) );
58 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
59 }
60 else
61 {
62 //label->setText( tr( "Select connections to export" ) );
63 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Export" ) );
64 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
65 }
66
67 if ( !populateConnections() )
68 {
69 QApplication::postEvent( this, new QCloseEvent() );
70 }
71
72 // use OK button for starting import and export operations
73 disconnect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
74 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsManageConnectionsDialog::doExportImport );
75
76 connect( listConnections, &QListWidget::itemSelectionChanged, this, &QgsManageConnectionsDialog::selectionChanged );
77}
78
80{
81 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
82}
83
85{
86 const QList<QListWidgetItem *> selection = listConnections->selectedItems();
87 if ( selection.isEmpty() )
88 {
89 QMessageBox::warning( this, tr( "Export/Import Error" ), tr( "You should select at least one connection from list." ) );
90 return;
91 }
92
93 QStringList items;
94 items.reserve( selection.size() );
95 for ( int i = 0; i < selection.size(); ++i )
96 {
97 items.append( selection.at( i )->text() );
98 }
99
100 if ( mDialogMode == Export )
101 {
102 QString fileName = QFileDialog::getSaveFileName( this, tr( "Save Connections" ), QDir::homePath(), tr( "XML files (*.xml *.XML)" ) );
103 // return dialog focus on Mac
104 activateWindow();
105 raise();
106 if ( fileName.isEmpty() )
107 {
108 return;
109 }
110
111 // ensure the user never omitted the extension from the file name
112 if ( !fileName.endsWith( QLatin1String( ".xml" ), Qt::CaseInsensitive ) )
113 {
114 fileName += QLatin1String( ".xml" );
115 }
116
117 mFileName = fileName;
118
119 QDomDocument doc;
120 switch ( mConnectionType )
121 {
122 case WMS:
123 doc = saveOWSConnections( items, QStringLiteral( "WMS" ) );
124 break;
125 case WFS:
126 doc = saveWfsConnections( items );
127 break;
128 case PostGIS:
129 doc = savePgConnections( items );
130 break;
131 case MSSQL:
132 doc = saveMssqlConnections( items );
133 break;
134 case WCS:
135 doc = saveOWSConnections( items, QStringLiteral( "WCS" ) );
136 break;
137 case Oracle:
138 doc = saveOracleConnections( items );
139 break;
140 case HANA:
141 doc = saveHanaConnections( items );
142 break;
143 case XyzTiles:
144 doc = saveXyzTilesConnections( items );
145 break;
146 case ArcgisMapServer:
148 doc = saveArcgisConnections( items );
149 break;
150 case VectorTile:
151 doc = saveVectorTileConnections( items );
152 break;
153 case TiledScene:
154 doc = saveTiledSceneConnections( items );
155 break;
156 case SensorThings:
157 doc = saveSensorThingsConnections( items );
158 break;
159 case CloudStorage:
160 doc = saveCloudStorageConnections( items );
161 break;
162 case STAC:
163 doc = saveStacConnections( items );
164 break;
165 }
166
167 QFile file( mFileName );
168 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
169 {
170 QMessageBox::warning( this, tr( "Saving Connections" ), tr( "Cannot write file %1:\n%2." ).arg( mFileName, file.errorString() ) );
171 return;
172 }
173
174 QTextStream out( &file );
175 doc.save( out, 4 );
176 }
177 else // import connections
178 {
179 QFile file( mFileName );
180 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
181 {
182 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
183 return;
184 }
185
186 QDomDocument doc;
187 QString errorStr;
188 int errorLine;
189 int errorColumn;
190
191 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
192 {
193 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
194 return;
195 }
196
197 switch ( mConnectionType )
198 {
199 case WMS:
200 loadOWSConnections( doc, items, QStringLiteral( "WMS" ) );
201 break;
202 case WFS:
203 loadWfsConnections( doc, items );
204 break;
205 case PostGIS:
206 loadPgConnections( doc, items );
207 break;
208 case MSSQL:
209 loadMssqlConnections( doc, items );
210 break;
211 case WCS:
212 loadOWSConnections( doc, items, QStringLiteral( "WCS" ) );
213 break;
214 case Oracle:
215 loadOracleConnections( doc, items );
216 break;
217 case HANA:
218 loadHanaConnections( doc, items );
219 break;
220 case XyzTiles:
221 loadXyzTilesConnections( doc, items );
222 break;
223 case ArcgisMapServer:
224 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISMAPSERVER" ) );
225 break;
227 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISFEATURESERVER" ) );
228 break;
229 case VectorTile:
230 loadVectorTileConnections( doc, items );
231 break;
232 case TiledScene:
233 loadTiledSceneConnections( doc, items );
234 break;
235 case SensorThings:
236 loadSensorThingsConnections( doc, items );
237 break;
238 case CloudStorage:
239 loadCloudStorageConnections( doc, items );
240 break;
241 case STAC:
242 loadStacConnections( doc, items );
243 break;
244 }
245 // clear connections list and close window
246 listConnections->clear();
247 accept();
248 }
249
250 mFileName.clear();
251}
252
253bool QgsManageConnectionsDialog::populateConnections()
254{
255 // Export mode. Populate connections list from settings
256 if ( mDialogMode == Export )
257 {
258 QStringList connections;
259 QgsSettings settings;
260 switch ( mConnectionType )
261 {
262 case WMS:
263 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wms" ) } );
264 break;
265 case WFS:
266 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wfs" ) } );
267 break;
268 case WCS:
269 connections = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wcs" ) } );
270 break;
271 case PostGIS:
272 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
273 connections = settings.childGroups();
274 break;
275 case MSSQL:
276 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
277 connections = settings.childGroups();
278 break;
279 case Oracle:
280 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
281 connections = settings.childGroups();
282 break;
283 case HANA:
284 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
285 connections = settings.childGroups();
286 break;
287 case XyzTiles:
289 break;
290 case ArcgisMapServer:
293 break;
294 case VectorTile:
295 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
296 break;
297 case TiledScene:
298 connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
299 break;
300 case SensorThings:
301 connections = QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
302 break;
303 case CloudStorage:
304 connections = QgsGdalCloudProviderConnection::sTreeConnectionCloud->items();
305 break;
306 case STAC:
307 connections = QgsStacConnection::sTreeConnectionStac->items();
308 break;
309 }
310 for ( const QString &connection : std::as_const( connections ) )
311 {
312 QListWidgetItem *item = new QListWidgetItem();
313 item->setText( connection );
314 listConnections->addItem( item );
315 }
316 }
317 // Import mode. Populate connections list from file
318 else
319 {
320 QFile file( mFileName );
321 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
322 {
323 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Cannot read file %1:\n%2." ).arg( mFileName, file.errorString() ) );
324 return false;
325 }
326
327 QDomDocument doc;
328 QString errorStr;
329 int errorLine;
330 int errorColumn;
331
332 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
333 {
334 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Parse error at line %1, column %2:\n%3" ).arg( errorLine ).arg( errorColumn ).arg( errorStr ) );
335 return false;
336 }
337
338 const QDomElement root = doc.documentElement();
339 switch ( mConnectionType )
340 {
341 case WMS:
342 if ( root.tagName() != QLatin1String( "qgsWMSConnections" ) )
343 {
344 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WMS connections exchange file." ) );
345 return false;
346 }
347 break;
348
349 case WFS:
350 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
351 {
352 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
353 return false;
354 }
355 break;
356
357 case WCS:
358 if ( root.tagName() != QLatin1String( "qgsWCSConnections" ) )
359 {
360 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WCS connections exchange file." ) );
361 return false;
362 }
363 break;
364
365 case PostGIS:
366 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
367 {
368 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
369 return false;
370 }
371 break;
372
373 case MSSQL:
374 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
375 {
376 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
377 return false;
378 }
379 break;
380 case Oracle:
381 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
382 {
383 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
384 return false;
385 }
386 break;
387 case HANA:
388 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
389 {
390 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
391 return false;
392 }
393 break;
394 case XyzTiles:
395 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
396 {
397 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
398 return false;
399 }
400 break;
401 case ArcgisMapServer:
402 if ( root.tagName() != QLatin1String( "qgsARCGISMAPSERVERConnections" ) )
403 {
404 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a ArcGIS Map Service connections exchange file." ) );
405 return false;
406 }
407 break;
409 if ( root.tagName() != QLatin1String( "qgsARCGISFEATURESERVERConnections" ) )
410 {
411 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a ArcGIS Feature Service connections exchange file." ) );
412 return false;
413 }
414 break;
415 case VectorTile:
416 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
417 {
418 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
419 return false;
420 }
421 break;
422 case TiledScene:
423 if ( root.tagName() != QLatin1String( "qgsTiledSceneConnections" ) )
424 {
425 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
426 return false;
427 }
428 break;
429 case SensorThings:
430 if ( root.tagName() != QLatin1String( "qgsSensorThingsConnections" ) )
431 {
432 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
433 return false;
434 }
435 break;
436 case CloudStorage:
437 if ( root.tagName() != QLatin1String( "qgsCloudStorageConnections" ) )
438 {
439 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
440 return false;
441 }
442 break;
443 case STAC:
444 if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
445 {
446 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
447 return false;
448 }
449 break;
450 }
451
452 QDomElement child = root.firstChildElement();
453 while ( !child.isNull() )
454 {
455 QListWidgetItem *item = new QListWidgetItem();
456 item->setText( child.attribute( QStringLiteral( "name" ) ) );
457 listConnections->addItem( item );
458 child = child.nextSiblingElement();
459 }
460 }
461 return true;
462}
463
464static void addNamespaceDeclarations( QDomElement &root, const QMap<QString, QString> &namespaceDeclarations )
465{
466 for ( auto it = namespaceDeclarations.begin(); it != namespaceDeclarations.end(); ++it )
467 {
468 root.setAttribute( QStringLiteral( "xmlns:" ) + it.key(), it.value() );
469 }
470}
471
472QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &connections, const QString &service )
473{
474 QDomDocument doc( QStringLiteral( "connections" ) );
475 QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" );
476 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
477 doc.appendChild( root );
478
479 QMap<QString, QString> namespaceDeclarations;
480 for ( int i = 0; i < connections.count(); ++i )
481 {
482 QDomElement el = doc.createElement( service.toLower() );
483 el.setAttribute( QStringLiteral( "name" ), connections[i] );
484 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { service.toLower(), connections[i] } ) );
485
486 if ( service == QLatin1String( "WMS" ) )
487 {
488 el.setAttribute( QStringLiteral( "ignoreGetMapURI" ), QgsOwsConnection::settingsIgnoreGetMapURI->value( { service.toLower(), connections[i] } ) );
489 el.setAttribute( QStringLiteral( "ignoreGetFeatureInfoURI" ), QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->value( { service.toLower(), connections[i] } ) );
490 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { service.toLower(), connections[i] } ) );
491 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { service.toLower(), connections[i] } ) );
492 el.setAttribute( QStringLiteral( "smoothPixmapTransform" ), QgsOwsConnection::settingsSmoothPixmapTransform->value( { service.toLower(), connections[i] } ) );
493 el.setAttribute( QStringLiteral( "dpiMode" ), static_cast<int>( QgsOwsConnection::settingsDpiMode->value( { service.toLower(), connections[i] } ) ) );
494
495 QgsHttpHeaders httpHeader( QgsOwsConnection::settingsHeaders->value( { service.toLower(), connections[i] } ) );
496 httpHeader.updateDomElement( el, namespaceDeclarations );
497 }
498
499 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { service.toLower(), connections[i] } ) );
500 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { service.toLower(), connections[i] } ) );
501 root.appendChild( el );
502 }
503
504 addNamespaceDeclarations( root, namespaceDeclarations );
505
506 return doc;
507}
508
509QDomDocument QgsManageConnectionsDialog::saveWfsConnections( const QStringList &connections )
510{
511 QDomDocument doc( QStringLiteral( "connections" ) );
512 QDomElement root = doc.createElement( QStringLiteral( "qgsWFSConnections" ) );
513 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1" ) );
514 doc.appendChild( root );
515
516 for ( int i = 0; i < connections.count(); ++i )
517 {
518 QDomElement el = doc.createElement( QStringLiteral( "wfs" ) );
519 el.setAttribute( QStringLiteral( "name" ), connections[i] );
520 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { QStringLiteral( "wfs" ), connections[i] } ) );
521
522 el.setAttribute( QStringLiteral( "version" ), QgsOwsConnection::settingsVersion->value( { QStringLiteral( "wfs" ), connections[i] } ) );
523 el.setAttribute( QStringLiteral( "maxnumfeatures" ), QgsOwsConnection::settingsMaxNumFeatures->value( { QStringLiteral( "wfs" ), connections[i] } ) );
524 el.setAttribute( QStringLiteral( "pagesize" ), QgsOwsConnection::settingsPagesize->value( { QStringLiteral( "wfs" ), connections[i] } ) );
525 el.setAttribute( QStringLiteral( "pagingenabled" ), QgsOwsConnection::settingsPagingEnabled->value( { QStringLiteral( "wfs" ), connections[i] } ) );
526 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
527 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
528 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { QStringLiteral( "wfs" ), connections[i] } ) );
529 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { QStringLiteral( "wfs" ), connections[i] } ) );
530 el.setAttribute( QStringLiteral( "httpMethod" ), QgsOwsConnection::settingsPreferredHttpMethod->value( { QStringLiteral( "wfs" ), connections[i] } ) == Qgis::HttpMethod::Post ? QStringLiteral( "post" ) : QStringLiteral( "get" ) );
531 el.setAttribute( QStringLiteral( "featureMode" ), QgsOwsConnection::settingsWfsFeatureMode->value( { QStringLiteral( "wfs" ), connections[i] } ) );
532 root.appendChild( el );
533 }
534
535 return doc;
536}
537
538QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
539{
540 QDomDocument doc( QStringLiteral( "connections" ) );
541 QDomElement root = doc.createElement( QStringLiteral( "qgsPgConnections" ) );
542 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
543 doc.appendChild( root );
544
545 const QgsSettings settings;
546 QString path;
547 for ( int i = 0; i < connections.count(); ++i )
548 {
549 path = "/PostgreSQL/connections/" + connections[i];
550 QDomElement el = doc.createElement( QStringLiteral( "postgis" ) );
551 el.setAttribute( QStringLiteral( "name" ), connections[i] );
552 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
553 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
554 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
555 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
556 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
557 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
558 el.setAttribute( QStringLiteral( "projectsInDatabase" ), settings.value( path + "/projectsInDatabase", "0" ).toString() );
559 el.setAttribute( QStringLiteral( "dontResolveType" ), settings.value( path + "/dontResolveType", "0" ).toString() );
560 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
561 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
562 el.setAttribute( QStringLiteral( "publicOnly" ), settings.value( path + "/publicOnly", "0" ).toString() );
563 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
564 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
565
566 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
567 {
568 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
569 }
570
571 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
572
573 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
574 {
575 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
576 }
577
578 root.appendChild( el );
579 }
580
581 return doc;
582}
583
584QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
585{
586 QDomDocument doc( QStringLiteral( "connections" ) );
587 QDomElement root = doc.createElement( QStringLiteral( "qgsMssqlConnections" ) );
588 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
589 doc.appendChild( root );
590
591 const QgsSettings settings;
592 QString path;
593 for ( int i = 0; i < connections.count(); ++i )
594 {
595 path = "/MSSQL/connections/" + connections[i];
596 QDomElement el = doc.createElement( QStringLiteral( "mssql" ) );
597 el.setAttribute( QStringLiteral( "name" ), connections[i] );
598 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
599 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
600 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
601 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
602 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
603 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
604
605 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
606
607 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
608 {
609 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
610 }
611
612 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
613
614 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
615 {
616 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
617 }
618
619 root.appendChild( el );
620 }
621
622 return doc;
623}
624
625QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections )
626{
627 QDomDocument doc( QStringLiteral( "connections" ) );
628 QDomElement root = doc.createElement( QStringLiteral( "qgsOracleConnections" ) );
629 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
630 doc.appendChild( root );
631
632 const QgsSettings settings;
633 QString path;
634 for ( int i = 0; i < connections.count(); ++i )
635 {
636 path = "/Oracle/connections/" + connections[i];
637 QDomElement el = doc.createElement( QStringLiteral( "oracle" ) );
638 el.setAttribute( QStringLiteral( "name" ), connections[i] );
639 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
640 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
641 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
642 el.setAttribute( QStringLiteral( "dboptions" ), settings.value( path + "/dboptions" ).toString() );
643 el.setAttribute( QStringLiteral( "dbworkspace" ), settings.value( path + "/dbworkspace" ).toString() );
644 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
645 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
646 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", "0" ).toString() );
647 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
648 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
649
650 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
651
652 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
653 {
654 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
655 }
656
657 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
658
659 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
660 {
661 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
662 }
663
664 root.appendChild( el );
665 }
666
667 return doc;
668}
669
670QDomDocument QgsManageConnectionsDialog::saveHanaConnections( const QStringList &connections )
671{
672 QDomDocument doc( QStringLiteral( "connections" ) );
673 QDomElement root = doc.createElement( QStringLiteral( "qgsHanaConnections" ) );
674 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
675 doc.appendChild( root );
676
677 const QgsSettings settings;
678 QString path;
679 for ( int i = 0; i < connections.count(); ++i )
680 {
681 path = "/HANA/connections/" + connections[i];
682 QDomElement el = doc.createElement( QStringLiteral( "hana" ) );
683 el.setAttribute( QStringLiteral( "name" ), connections[i] );
684 el.setAttribute( QStringLiteral( "driver" ), settings.value( path + "/driver", QString() ).toString() );
685 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host", QString() ).toString() );
686 el.setAttribute( QStringLiteral( "identifierType" ), settings.value( path + "/identifierType", QString() ).toString() );
687 el.setAttribute( QStringLiteral( "identifier" ), settings.value( path + "/identifier", QString() ).toString() );
688 el.setAttribute( QStringLiteral( "multitenant" ), settings.value( path + "/multitenant", QString() ).toString() );
689 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database", QString() ).toString() );
690 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema", QString() ).toString() );
691 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", QStringLiteral( "0" ) ).toString() );
692 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", QStringLiteral( "0" ) ).toString() );
693
694 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", QStringLiteral( "false" ) ).toString() );
695 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
696 {
697 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", QString() ).toString() );
698 }
699
700 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", QStringLiteral( "false" ) ).toString() );
701 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
702 {
703 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", QString() ).toString() );
704 }
705
706 el.setAttribute( QStringLiteral( "sslEnabled" ), settings.value( path + "/sslEnabled", QStringLiteral( "false" ) ).toString() );
707 el.setAttribute( QStringLiteral( "sslCryptoProvider" ), settings.value( path + "/sslCryptoProvider", QStringLiteral( "openssl" ) ).toString() );
708 el.setAttribute( QStringLiteral( "sslKeyStore" ), settings.value( path + "/sslKeyStore", QString() ).toString() );
709 el.setAttribute( QStringLiteral( "sslTrustStore" ), settings.value( path + "/sslTrustStore", QString() ).toString() );
710 el.setAttribute( QStringLiteral( "sslValidateCertificate" ), settings.value( path + "/sslValidateCertificate", QStringLiteral( "false" ) ).toString() );
711 el.setAttribute( QStringLiteral( "sslHostNameInCertificate" ), settings.value( path + "/sslHostNameInCertificate", QString() ).toString() );
712
713 root.appendChild( el );
714 }
715
716 return doc;
717}
718
719QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
720{
721 QDomDocument doc( QStringLiteral( "connections" ) );
722 QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
723 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
724 doc.appendChild( root );
725
726 QMap<QString, QString> namespaceDeclarations;
727 for ( int i = 0; i < connections.count(); ++i )
728 {
729 QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
730
731 el.setAttribute( QStringLiteral( "name" ), connections[i] );
732 el.setAttribute( QStringLiteral( "url" ), QgsXyzConnectionSettings::settingsUrl->value( connections[i] ) );
733 el.setAttribute( QStringLiteral( "zmin" ), QgsXyzConnectionSettings::settingsZmin->value( connections[i] ) );
734 el.setAttribute( QStringLiteral( "zmax" ), QgsXyzConnectionSettings::settingsZmax->value( connections[i] ) );
735 el.setAttribute( QStringLiteral( "authcfg" ), QgsXyzConnectionSettings::settingsAuthcfg->value( connections[i] ) );
736 el.setAttribute( QStringLiteral( "username" ), QgsXyzConnectionSettings::settingsUsername->value( connections[i] ) );
737 el.setAttribute( QStringLiteral( "password" ), QgsXyzConnectionSettings::settingsPassword->value( connections[i] ) );
738 el.setAttribute( QStringLiteral( "tilePixelRatio" ), QgsXyzConnectionSettings::settingsTilePixelRatio->value( connections[i] ) );
739
740 QgsHttpHeaders httpHeader( QgsXyzConnectionSettings::settingsHeaders->value( connections[i] ) );
741 httpHeader.updateDomElement( el, namespaceDeclarations );
742
743 root.appendChild( el );
744 }
745
746 addNamespaceDeclarations( root, namespaceDeclarations );
747
748 return doc;
749}
750
751QDomDocument QgsManageConnectionsDialog::saveArcgisConnections( const QStringList &connections )
752{
753 QDomDocument doc( QStringLiteral( "connections" ) );
754 QDomElement root = doc.createElement( "qgsARCGISFEATURESERVERConnections" );
755 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
756 doc.appendChild( root );
757
758 QMap<QString, QString> namespaceDeclarations;
759 for ( const QString &connection : connections )
760 {
761 QDomElement el = doc.createElement( QStringLiteral( "arcgisfeatureserver" ) );
762 el.setAttribute( QStringLiteral( "name" ), connection );
763 el.setAttribute( QStringLiteral( "url" ), QgsArcGisConnectionSettings::settingsUrl->value( connection ) );
764
765 QgsHttpHeaders httpHeader( QgsArcGisConnectionSettings::settingsHeaders->value( connection ) );
766 httpHeader.updateDomElement( el, namespaceDeclarations );
767
768 el.setAttribute( QStringLiteral( "username" ), QgsArcGisConnectionSettings::settingsUsername->value( connection ) );
769 el.setAttribute( QStringLiteral( "password" ), QgsArcGisConnectionSettings::settingsPassword->value( connection ) );
770 el.setAttribute( QStringLiteral( "authcfg" ), QgsArcGisConnectionSettings::settingsAuthcfg->value( connection ) );
771
772 root.appendChild( el );
773 }
774
775 addNamespaceDeclarations( root, namespaceDeclarations );
776
777 return doc;
778}
779
780QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections( const QStringList &connections )
781{
782 QDomDocument doc( QStringLiteral( "connections" ) );
783 QDomElement root = doc.createElement( QStringLiteral( "qgsVectorTileConnections" ) );
784 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
785 doc.appendChild( root );
786
787 QMap<QString, QString> namespaceDeclarations;
788 for ( int i = 0; i < connections.count(); ++i )
789 {
790 QDomElement el = doc.createElement( QStringLiteral( "vectortile" ) );
791
792 el.setAttribute( QStringLiteral( "name" ), connections[i] );
793 el.setAttribute( QStringLiteral( "url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[i] ) );
794 el.setAttribute( QStringLiteral( "zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[i] ) );
795 el.setAttribute( QStringLiteral( "zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[i] ) );
796 el.setAttribute( QStringLiteral( "serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[i] ) );
797 el.setAttribute( QStringLiteral( "authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[i] ) );
798 el.setAttribute( QStringLiteral( "username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[i] ) );
799 el.setAttribute( QStringLiteral( "password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[i] ) );
800 el.setAttribute( QStringLiteral( "styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[i] ) );
801
802 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[i] ) );
803 httpHeader.updateDomElement( el, namespaceDeclarations );
804
805 root.appendChild( el );
806 }
807
808 addNamespaceDeclarations( root, namespaceDeclarations );
809
810 return doc;
811}
812
813QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections( const QStringList &connections )
814{
815 QDomDocument doc( QStringLiteral( "connections" ) );
816 QDomElement root = doc.createElement( QStringLiteral( "qgsTiledSceneConnections" ) );
817 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
818 doc.appendChild( root );
819
820 QMap<QString, QString> namespaceDeclarations;
821 for ( int i = 0; i < connections.count(); ++i )
822 {
823 QDomElement el = doc.createElement( QStringLiteral( "tiledscene" ) );
824
825 el.setAttribute( QStringLiteral( "name" ), connections[i] );
826 el.setAttribute( QStringLiteral( "provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[i] ) );
827 el.setAttribute( QStringLiteral( "url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[i] ) );
828 el.setAttribute( QStringLiteral( "authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[i] ) );
829 el.setAttribute( QStringLiteral( "username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[i] ) );
830 el.setAttribute( QStringLiteral( "password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[i] ) );
831
832 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
833 httpHeader.updateDomElement( el, namespaceDeclarations );
834
835 root.appendChild( el );
836 }
837
838 addNamespaceDeclarations( root, namespaceDeclarations );
839
840 return doc;
841}
842
843QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections( const QStringList &connections )
844{
845 QDomDocument doc( QStringLiteral( "connections" ) );
846 QDomElement root = doc.createElement( QStringLiteral( "qgsSensorThingsConnections" ) );
847 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
848 doc.appendChild( root );
849
850 QMap<QString, QString> namespaceDeclarations;
851 for ( int i = 0; i < connections.count(); ++i )
852 {
853 QDomElement el = doc.createElement( QStringLiteral( "sensorthings" ) );
854
855 el.setAttribute( QStringLiteral( "name" ), connections[i] );
856 el.setAttribute( QStringLiteral( "url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[i] ) );
857 el.setAttribute( QStringLiteral( "authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[i] ) );
858 el.setAttribute( QStringLiteral( "username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[i] ) );
859 el.setAttribute( QStringLiteral( "password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[i] ) );
860
861 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
862 httpHeader.updateDomElement( el, namespaceDeclarations );
863
864 root.appendChild( el );
865 }
866
867 addNamespaceDeclarations( root, namespaceDeclarations );
868
869 return doc;
870}
871
872
873QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections( const QStringList &connections )
874{
875 QDomDocument doc( QStringLiteral( "connections" ) );
876 QDomElement root = doc.createElement( QStringLiteral( "qgsCloudStorageConnections" ) );
877 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
878 doc.appendChild( root );
879
880 for ( int i = 0; i < connections.count(); ++i )
881 {
882 QDomElement el = doc.createElement( QStringLiteral( "cloudstorage" ) );
883
884 el.setAttribute( QStringLiteral( "name" ), connections[i] );
885 el.setAttribute( QStringLiteral( "handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[i] ) );
886 el.setAttribute( QStringLiteral( "container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[i] ) );
887 el.setAttribute( QStringLiteral( "path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[i] ) );
888
889 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[i] );
890 QString credentialString;
891 for ( auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
892 {
893 if ( !it.value().toString().isEmpty() )
894 {
895 credentialString += QStringLiteral( "|credential:%1=%2" ).arg( it.key(), it.value().toString() );
896 }
897 }
898 el.setAttribute( QStringLiteral( "credentials" ), credentialString );
899
900 root.appendChild( el );
901 }
902
903 return doc;
904}
905
906QDomDocument QgsManageConnectionsDialog::saveStacConnections( const QStringList &connections )
907{
908 QDomDocument doc( QStringLiteral( "connections" ) );
909 QDomElement root = doc.createElement( QStringLiteral( "qgsStacConnections" ) );
910 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
911 doc.appendChild( root );
912
913 QMap<QString, QString> namespaceDeclarations;
914 for ( int i = 0; i < connections.count(); ++i )
915 {
916 QDomElement el = doc.createElement( QStringLiteral( "stac" ) );
917
918 el.setAttribute( QStringLiteral( "name" ), connections[i] );
919 el.setAttribute( QStringLiteral( "url" ), QgsStacConnection::settingsUrl->value( connections[i] ) );
920 el.setAttribute( QStringLiteral( "authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[i] ) );
921 el.setAttribute( QStringLiteral( "username" ), QgsStacConnection::settingsUsername->value( connections[i] ) );
922 el.setAttribute( QStringLiteral( "password" ), QgsStacConnection::settingsPassword->value( connections[i] ) );
923
924 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[i] ) );
925 httpHeader.updateDomElement( el, namespaceDeclarations );
926
927 root.appendChild( el );
928 }
929
930 addNamespaceDeclarations( root, namespaceDeclarations );
931
932 return doc;
933}
934
935void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
936{
937 const QDomElement root = doc.documentElement();
938 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
939 {
940 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
941 return;
942 }
943
944 QString connectionName;
945
946 QDomElement child = root.firstChildElement();
947 bool prompt = true;
948 bool overwrite = true;
949
950 while ( !child.isNull() )
951 {
952 connectionName = child.attribute( QStringLiteral( "name" ) );
953 if ( !items.contains( connectionName ) )
954 {
955 child = child.nextSiblingElement();
956 continue;
957 }
958
959 // check for duplicates
960 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && prompt )
961 {
962 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
963
964 switch ( res )
965 {
966 case QMessageBox::Cancel:
967 return;
968 case QMessageBox::No:
969 child = child.nextSiblingElement();
970 continue;
971 case QMessageBox::Yes:
972 overwrite = true;
973 break;
974 case QMessageBox::YesToAll:
975 prompt = false;
976 overwrite = true;
977 break;
978 case QMessageBox::NoToAll:
979 prompt = false;
980 overwrite = false;
981 break;
982 }
983 }
984
985 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && !overwrite )
986 {
987 child = child.nextSiblingElement();
988 continue;
989 }
990
991 // no dups detected or overwrite is allowed
992 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { service.toLower(), connectionName } );
993 QgsOwsConnection::settingsIgnoreGetMapURI->setValue( child.attribute( QStringLiteral( "ignoreGetMapURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
994 QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( child.attribute( QStringLiteral( "ignoreGetFeatureInfoURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
995 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
996 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
997 QgsOwsConnection::settingsSmoothPixmapTransform->setValue( child.attribute( QStringLiteral( "smoothPixmapTransform" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
998 QgsOwsConnection::settingsDpiMode->setValue( static_cast<Qgis::DpiMode>( child.attribute( QStringLiteral( "dpiMode" ), QStringLiteral( "7" ) ).toInt() ), { service.toLower(), connectionName } );
999
1000 QgsHttpHeaders httpHeader( child );
1001 QgsOwsConnection::settingsHeaders->setValue( httpHeader.headers(), { service.toLower(), connectionName } );
1002
1003 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1004 {
1005 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { service.toUpper(), connectionName } );
1006 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { service.toUpper(), connectionName } );
1007 }
1008 child = child.nextSiblingElement();
1009 }
1010}
1011
1012void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
1013{
1014 const QDomElement root = doc.documentElement();
1015 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
1016 {
1017 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
1018 return;
1019 }
1020
1021 QString connectionName;
1022 QStringList keys = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wfs" ) } );
1023
1024 QDomElement child = root.firstChildElement();
1025 bool prompt = true;
1026 bool overwrite = true;
1027
1028 while ( !child.isNull() )
1029 {
1030 connectionName = child.attribute( QStringLiteral( "name" ) );
1031 if ( !items.contains( connectionName ) )
1032 {
1033 child = child.nextSiblingElement();
1034 continue;
1035 }
1036
1037 // check for duplicates
1038 if ( keys.contains( connectionName ) && prompt )
1039 {
1040 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1041
1042 switch ( res )
1043 {
1044 case QMessageBox::Cancel:
1045 return;
1046 case QMessageBox::No:
1047 child = child.nextSiblingElement();
1048 continue;
1049 case QMessageBox::Yes:
1050 overwrite = true;
1051 break;
1052 case QMessageBox::YesToAll:
1053 prompt = false;
1054 overwrite = true;
1055 break;
1056 case QMessageBox::NoToAll:
1057 prompt = false;
1058 overwrite = false;
1059 break;
1060 }
1061 }
1062
1063 if ( keys.contains( connectionName ) )
1064 {
1065 if ( !overwrite )
1066 {
1067 child = child.nextSiblingElement();
1068 continue;
1069 }
1070 }
1071 else
1072 {
1073 keys << connectionName;
1074 }
1075
1076 // no dups detected or overwrite is allowed
1077
1078 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { QStringLiteral( "wfs" ), connectionName } );
1079 QgsOwsConnection::settingsVersion->setValue( child.attribute( QStringLiteral( "version" ) ), { QStringLiteral( "wfs" ), connectionName } );
1080 QgsOwsConnection::settingsMaxNumFeatures->setValue( child.attribute( QStringLiteral( "maxnumfeatures" ) ), { QStringLiteral( "wfs" ), connectionName } );
1081 QgsOwsConnection::settingsPagesize->setValue( child.attribute( QStringLiteral( "pagesize" ) ), { QStringLiteral( "wfs" ), connectionName } );
1082 QgsOwsConnection::settingsPagingEnabled->setValue( child.attribute( QStringLiteral( "pagingenabled" ) ), { QStringLiteral( "wfs" ), connectionName } );
1083 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1084 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1085 QgsOwsConnection::settingsPreferredHttpMethod->setValue( child.attribute( QStringLiteral( "httpMethod" ) ).compare( QLatin1String( "post" ), Qt::CaseInsensitive ) == 0 ? Qgis::HttpMethod::Post : Qgis::HttpMethod::Get, { QStringLiteral( "wfs" ), connectionName } );
1086 QgsOwsConnection::settingsWfsFeatureMode->setValue( child.attribute( QStringLiteral( "featureMode" ) ), { QStringLiteral( "wfs" ), connectionName } );
1087
1088 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1089 {
1090 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { QStringLiteral( "wfs" ), connectionName } );
1091 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { QStringLiteral( "wfs" ), connectionName } );
1092 }
1093 child = child.nextSiblingElement();
1094 }
1095}
1096
1097void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
1098{
1099 const QDomElement root = doc.documentElement();
1100 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
1101 {
1102 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
1103 return;
1104 }
1105
1106 QString connectionName;
1107 QgsSettings settings;
1108 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
1109 QStringList keys = settings.childGroups();
1110 settings.endGroup();
1111 QDomElement child = root.firstChildElement();
1112 bool prompt = true;
1113 bool overwrite = true;
1114
1115 while ( !child.isNull() )
1116 {
1117 connectionName = child.attribute( QStringLiteral( "name" ) );
1118 if ( !items.contains( connectionName ) )
1119 {
1120 child = child.nextSiblingElement();
1121 continue;
1122 }
1123
1124 // check for duplicates
1125 if ( keys.contains( connectionName ) && prompt )
1126 {
1127 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1128 switch ( res )
1129 {
1130 case QMessageBox::Cancel:
1131 return;
1132 case QMessageBox::No:
1133 child = child.nextSiblingElement();
1134 continue;
1135 case QMessageBox::Yes:
1136 overwrite = true;
1137 break;
1138 case QMessageBox::YesToAll:
1139 prompt = false;
1140 overwrite = true;
1141 break;
1142 case QMessageBox::NoToAll:
1143 prompt = false;
1144 overwrite = false;
1145 break;
1146 }
1147 }
1148
1149 if ( keys.contains( connectionName ) )
1150 {
1151 if ( !overwrite )
1152 {
1153 child = child.nextSiblingElement();
1154 continue;
1155 }
1156 }
1157 else
1158 {
1159 keys << connectionName;
1160 }
1161
1162 //no dups detected or overwrite is allowed
1163 settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
1164
1165 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1166 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1167 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1168 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1169 {
1170 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1171 }
1172 else
1173 {
1174 settings.setValue( QStringLiteral( "/service" ), "" );
1175 }
1176 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1177 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1178 settings.setValue( QStringLiteral( "/projectsInDatabase" ), child.attribute( QStringLiteral( "projectsInDatabase" ), 0 ) );
1179 settings.setValue( QStringLiteral( "/dontResolveType" ), child.attribute( QStringLiteral( "dontResolveType" ), 0 ) );
1180 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ), 0 ) );
1181 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ), 0 ) );
1182 settings.setValue( QStringLiteral( "/publicOnly" ), child.attribute( QStringLiteral( "publicOnly" ), 0 ) );
1183 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1184 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1185 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1186 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1187 settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1188 settings.endGroup();
1189
1190 child = child.nextSiblingElement();
1191 }
1192}
1193
1194void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1195{
1196 const QDomElement root = doc.documentElement();
1197 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
1198 {
1199 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
1200 return;
1201 }
1202
1203 QString connectionName;
1204 QgsSettings settings;
1205 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
1206 QStringList keys = settings.childGroups();
1207 settings.endGroup();
1208 QDomElement child = root.firstChildElement();
1209 bool prompt = true;
1210 bool overwrite = true;
1211
1212 while ( !child.isNull() )
1213 {
1214 connectionName = child.attribute( QStringLiteral( "name" ) );
1215 if ( !items.contains( connectionName ) )
1216 {
1217 child = child.nextSiblingElement();
1218 continue;
1219 }
1220
1221 // check for duplicates
1222 if ( keys.contains( connectionName ) && prompt )
1223 {
1224 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1225 switch ( res )
1226 {
1227 case QMessageBox::Cancel:
1228 return;
1229 case QMessageBox::No:
1230 child = child.nextSiblingElement();
1231 continue;
1232 case QMessageBox::Yes:
1233 overwrite = true;
1234 break;
1235 case QMessageBox::YesToAll:
1236 prompt = false;
1237 overwrite = true;
1238 break;
1239 case QMessageBox::NoToAll:
1240 prompt = false;
1241 overwrite = false;
1242 break;
1243 }
1244 }
1245
1246 if ( keys.contains( connectionName ) )
1247 {
1248 if ( !overwrite )
1249 {
1250 child = child.nextSiblingElement();
1251 continue;
1252 }
1253 }
1254 else
1255 {
1256 keys << connectionName;
1257 }
1258
1259 //no dups detected or overwrite is allowed
1260 settings.beginGroup( "/MSSQL/connections/" + connectionName );
1261
1262 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1263 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1264 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1265 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1266 {
1267 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1268 }
1269 else
1270 {
1271 settings.setValue( QStringLiteral( "/service" ), "" );
1272 }
1273 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1274 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1275 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1276 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1277 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1278 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1279 settings.endGroup();
1280
1281 child = child.nextSiblingElement();
1282 }
1283}
1284
1285void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1286{
1287 const QDomElement root = doc.documentElement();
1288 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
1289 {
1290 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
1291 return;
1292 }
1293
1294 QString connectionName;
1295 QgsSettings settings;
1296 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
1297 QStringList keys = settings.childGroups();
1298 settings.endGroup();
1299 QDomElement child = root.firstChildElement();
1300 bool prompt = true;
1301 bool overwrite = true;
1302
1303 while ( !child.isNull() )
1304 {
1305 connectionName = child.attribute( QStringLiteral( "name" ) );
1306 if ( !items.contains( connectionName ) )
1307 {
1308 child = child.nextSiblingElement();
1309 continue;
1310 }
1311
1312 // check for duplicates
1313 if ( keys.contains( connectionName ) && prompt )
1314 {
1315 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1316 switch ( res )
1317 {
1318 case QMessageBox::Cancel:
1319 return;
1320 case QMessageBox::No:
1321 child = child.nextSiblingElement();
1322 continue;
1323 case QMessageBox::Yes:
1324 overwrite = true;
1325 break;
1326 case QMessageBox::YesToAll:
1327 prompt = false;
1328 overwrite = true;
1329 break;
1330 case QMessageBox::NoToAll:
1331 prompt = false;
1332 overwrite = false;
1333 break;
1334 }
1335 }
1336
1337 if ( keys.contains( connectionName ) )
1338 {
1339 if ( !overwrite )
1340 {
1341 child = child.nextSiblingElement();
1342 continue;
1343 }
1344 }
1345 else
1346 {
1347 keys << connectionName;
1348 }
1349
1350 //no dups detected or overwrite is allowed
1351 settings.beginGroup( "/Oracle/connections/" + connectionName );
1352
1353 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1354 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1355 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1356 settings.setValue( QStringLiteral( "/dboptions" ), child.attribute( QStringLiteral( "dboptions" ) ) );
1357 settings.setValue( QStringLiteral( "/dbworkspace" ), child.attribute( QStringLiteral( "dbworkspace" ) ) );
1358 settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1359 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1360 settings.setValue( QStringLiteral( "/userTablesOnly" ), child.attribute( QStringLiteral( "userTablesOnly" ) ) );
1361 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ) ) );
1362 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ) ) );
1363 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1364 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1365 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1366 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1367 settings.endGroup();
1368
1369 child = child.nextSiblingElement();
1370 }
1371}
1372
1373void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1374{
1375 QDomElement root = doc.documentElement();
1376 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
1377 {
1378 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
1379 return;
1380 }
1381
1382 const QDomAttr version = root.attributeNode( "version" );
1383 if ( version.value() != QLatin1String( "1.0" ) )
1384 {
1385 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1386 return;
1387 }
1388
1389 QgsSettings settings;
1390 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
1391 QStringList keys = settings.childGroups();
1392 settings.endGroup();
1393 QDomElement child = root.firstChildElement();
1394 bool prompt = true;
1395 bool overwrite = true;
1396
1397 while ( !child.isNull() )
1398 {
1399 const QString connectionName = child.attribute( QStringLiteral( "name" ) );
1400 if ( !items.contains( connectionName ) )
1401 {
1402 child = child.nextSiblingElement();
1403 continue;
1404 }
1405
1406 // check for duplicates
1407 if ( keys.contains( connectionName ) && prompt )
1408 {
1409 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1410 switch ( res )
1411 {
1412 case QMessageBox::Cancel:
1413 return;
1414 case QMessageBox::No:
1415 child = child.nextSiblingElement();
1416 continue;
1417 case QMessageBox::Yes:
1418 overwrite = true;
1419 break;
1420 case QMessageBox::YesToAll:
1421 prompt = false;
1422 overwrite = true;
1423 break;
1424 case QMessageBox::NoToAll:
1425 prompt = false;
1426 overwrite = false;
1427 break;
1428 }
1429 }
1430
1431 if ( keys.contains( connectionName ) )
1432 {
1433 if ( !overwrite )
1434 {
1435 child = child.nextSiblingElement();
1436 continue;
1437 }
1438 }
1439 else
1440 {
1441 keys << connectionName;
1442 }
1443
1444 //no dups detected or overwrite is allowed
1445 settings.beginGroup( "/HANA/connections/" + connectionName );
1446
1447 for ( const QString param :
1448 { "driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1449 "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1450 "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1451 } )
1452 settings.setValue( QStringLiteral( "/" ) + param, child.attribute( param ) );
1453
1454 settings.endGroup();
1455
1456 child = child.nextSiblingElement();
1457 }
1458}
1459
1460void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1461{
1462 const QDomElement root = doc.documentElement();
1463 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
1464 {
1465 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
1466 return;
1467 }
1468
1469 QString connectionName;
1471 QDomElement child = root.firstChildElement();
1472 bool prompt = true;
1473 bool overwrite = true;
1474
1475 while ( !child.isNull() )
1476 {
1477 connectionName = child.attribute( QStringLiteral( "name" ) );
1478 if ( !items.contains( connectionName ) )
1479 {
1480 child = child.nextSiblingElement();
1481 continue;
1482 }
1483
1484 // check for duplicates
1485 if ( keys.contains( connectionName ) && prompt )
1486 {
1487 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1488
1489 switch ( res )
1490 {
1491 case QMessageBox::Cancel:
1492 return;
1493 case QMessageBox::No:
1494 child = child.nextSiblingElement();
1495 continue;
1496 case QMessageBox::Yes:
1497 overwrite = true;
1498 break;
1499 case QMessageBox::YesToAll:
1500 prompt = false;
1501 overwrite = true;
1502 break;
1503 case QMessageBox::NoToAll:
1504 prompt = false;
1505 overwrite = false;
1506 break;
1507 }
1508 }
1509
1510 if ( keys.contains( connectionName ) )
1511 {
1512 if ( !overwrite )
1513 {
1514 child = child.nextSiblingElement();
1515 continue;
1516 }
1517 }
1518 else
1519 {
1520 keys << connectionName;
1521 }
1522
1523
1524 QgsXyzConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1525 QgsXyzConnectionSettings::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1526 QgsXyzConnectionSettings::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1527 QgsXyzConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1528 QgsXyzConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1529 QgsXyzConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1530 QgsXyzConnectionSettings::settingsTilePixelRatio->setValue( child.attribute( QStringLiteral( "tilePixelRatio" ) ).toInt(), connectionName );
1531
1532 QgsHttpHeaders httpHeader( child );
1533 QgsXyzConnectionSettings::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1534
1535 child = child.nextSiblingElement();
1536 }
1537}
1538
1539void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1540{
1541 const QDomElement root = doc.documentElement();
1542 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1543 {
1544 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1545 return;
1546 }
1547
1548 QString connectionName;
1550 QDomElement child = root.firstChildElement();
1551 bool prompt = true;
1552 bool overwrite = true;
1553
1554 while ( !child.isNull() )
1555 {
1556 connectionName = child.attribute( QStringLiteral( "name" ) );
1557 if ( !items.contains( connectionName ) )
1558 {
1559 child = child.nextSiblingElement();
1560 continue;
1561 }
1562
1563 // check for duplicates
1564 if ( keys.contains( connectionName ) && prompt )
1565 {
1566 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1567
1568 switch ( res )
1569 {
1570 case QMessageBox::Cancel:
1571 return;
1572 case QMessageBox::No:
1573 child = child.nextSiblingElement();
1574 continue;
1575 case QMessageBox::Yes:
1576 overwrite = true;
1577 break;
1578 case QMessageBox::YesToAll:
1579 prompt = false;
1580 overwrite = true;
1581 break;
1582 case QMessageBox::NoToAll:
1583 prompt = false;
1584 overwrite = false;
1585 break;
1586 }
1587 }
1588
1589 if ( keys.contains( connectionName ) )
1590 {
1591 if ( !overwrite )
1592 {
1593 child = child.nextSiblingElement();
1594 continue;
1595 }
1596 }
1597 else
1598 {
1599 keys << connectionName;
1600 }
1601
1602 // no dups detected or overwrite is allowed
1603 QgsArcGisConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1604
1605 QgsArcGisConnectionSettings::settingsHeaders->setValue( QgsHttpHeaders( child ).headers(), connectionName );
1606
1607
1608 QgsArcGisConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1609 QgsArcGisConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1610 QgsArcGisConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1611
1612 child = child.nextSiblingElement();
1613 }
1614}
1615
1616void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1617{
1618 const QDomElement root = doc.documentElement();
1619 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
1620 {
1621 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
1622 return;
1623 }
1624
1625 QString connectionName;
1626 QgsSettings settings;
1627 settings.beginGroup( QStringLiteral( "/qgis/connections-vector-tile" ) );
1628 QStringList keys = settings.childGroups();
1629 settings.endGroup();
1630 QDomElement child = root.firstChildElement();
1631 bool prompt = true;
1632 bool overwrite = true;
1633
1634 while ( !child.isNull() )
1635 {
1636 connectionName = child.attribute( QStringLiteral( "name" ) );
1637 if ( !items.contains( connectionName ) )
1638 {
1639 child = child.nextSiblingElement();
1640 continue;
1641 }
1642
1643 // check for duplicates
1644 if ( keys.contains( connectionName ) && prompt )
1645 {
1646 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1647
1648 switch ( res )
1649 {
1650 case QMessageBox::Cancel:
1651 return;
1652 case QMessageBox::No:
1653 child = child.nextSiblingElement();
1654 continue;
1655 case QMessageBox::Yes:
1656 overwrite = true;
1657 break;
1658 case QMessageBox::YesToAll:
1659 prompt = false;
1660 overwrite = true;
1661 break;
1662 case QMessageBox::NoToAll:
1663 prompt = false;
1664 overwrite = false;
1665 break;
1666 }
1667 }
1668
1669 if ( keys.contains( connectionName ) )
1670 {
1671 if ( !overwrite )
1672 {
1673 child = child.nextSiblingElement();
1674 continue;
1675 }
1676 }
1677 else
1678 {
1679 keys << connectionName;
1680 }
1681
1682 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1683 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1684 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1685 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral( "serviceType" ) ), connectionName );
1686 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1687 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1688 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1689 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral( "styleUrl" ) ), connectionName );
1690
1691 QgsHttpHeaders httpHeader( child );
1692 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1693
1694 child = child.nextSiblingElement();
1695 }
1696}
1697
1698void QgsManageConnectionsDialog::loadTiledSceneConnections( const QDomDocument &doc, const QStringList &items )
1699{
1700 const QDomElement root = doc.documentElement();
1701 if ( root.tagName() != QLatin1String( "qgsTiledSceneConnections" ) )
1702 {
1703 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
1704 return;
1705 }
1706
1707 QString connectionName;
1708 QgsSettings settings;
1709 settings.beginGroup( QStringLiteral( "/qgis/connections-tiled-scene" ) );
1710 QStringList keys = settings.childGroups();
1711 settings.endGroup();
1712 QDomElement child = root.firstChildElement();
1713 bool prompt = true;
1714 bool overwrite = true;
1715
1716 while ( !child.isNull() )
1717 {
1718 connectionName = child.attribute( QStringLiteral( "name" ) );
1719 if ( !items.contains( connectionName ) )
1720 {
1721 child = child.nextSiblingElement();
1722 continue;
1723 }
1724
1725 // check for duplicates
1726 if ( keys.contains( connectionName ) && prompt )
1727 {
1728 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1729
1730 switch ( res )
1731 {
1732 case QMessageBox::Cancel:
1733 return;
1734 case QMessageBox::No:
1735 child = child.nextSiblingElement();
1736 continue;
1737 case QMessageBox::Yes:
1738 overwrite = true;
1739 break;
1740 case QMessageBox::YesToAll:
1741 prompt = false;
1742 overwrite = true;
1743 break;
1744 case QMessageBox::NoToAll:
1745 prompt = false;
1746 overwrite = false;
1747 break;
1748 }
1749 }
1750
1751 if ( keys.contains( connectionName ) )
1752 {
1753 if ( !overwrite )
1754 {
1755 child = child.nextSiblingElement();
1756 continue;
1757 }
1758 }
1759 else
1760 {
1761 keys << connectionName;
1762 }
1763
1764 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral( "provider" ) ), connectionName );
1765 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1766 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1767 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1768 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1769
1770 QgsHttpHeaders httpHeader( child );
1771 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1772
1773 child = child.nextSiblingElement();
1774 }
1775}
1776
1777void QgsManageConnectionsDialog::loadSensorThingsConnections( const QDomDocument &doc, const QStringList &items )
1778{
1779 const QDomElement root = doc.documentElement();
1780 if ( root.tagName() != QLatin1String( "qgsSensorThingsConnections" ) )
1781 {
1782 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
1783 return;
1784 }
1785
1786 QString connectionName;
1787 QgsSettings settings;
1788 settings.beginGroup( QStringLiteral( "/connections/sensorthings/items" ) );
1789 QStringList keys = settings.childGroups();
1790 settings.endGroup();
1791 QDomElement child = root.firstChildElement();
1792 bool prompt = true;
1793 bool overwrite = true;
1794
1795 while ( !child.isNull() )
1796 {
1797 connectionName = child.attribute( QStringLiteral( "name" ) );
1798 if ( !items.contains( connectionName ) )
1799 {
1800 child = child.nextSiblingElement();
1801 continue;
1802 }
1803
1804 // check for duplicates
1805 if ( keys.contains( connectionName ) && prompt )
1806 {
1807 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1808
1809 switch ( res )
1810 {
1811 case QMessageBox::Cancel:
1812 return;
1813 case QMessageBox::No:
1814 child = child.nextSiblingElement();
1815 continue;
1816 case QMessageBox::Yes:
1817 overwrite = true;
1818 break;
1819 case QMessageBox::YesToAll:
1820 prompt = false;
1821 overwrite = true;
1822 break;
1823 case QMessageBox::NoToAll:
1824 prompt = false;
1825 overwrite = false;
1826 break;
1827 }
1828 }
1829
1830 if ( keys.contains( connectionName ) )
1831 {
1832 if ( !overwrite )
1833 {
1834 child = child.nextSiblingElement();
1835 continue;
1836 }
1837 }
1838 else
1839 {
1840 keys << connectionName;
1841 }
1842
1843 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1844 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1845 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1846 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1847
1848 QgsHttpHeaders httpHeader( child );
1849 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1850
1851 child = child.nextSiblingElement();
1852 }
1853}
1854
1855void QgsManageConnectionsDialog::loadCloudStorageConnections( const QDomDocument &doc, const QStringList &items )
1856{
1857 const QDomElement root = doc.documentElement();
1858 if ( root.tagName() != QLatin1String( "qgsCloudStorageConnections" ) )
1859 {
1860 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
1861 return;
1862 }
1863
1864 QString connectionName;
1865 QgsSettings settings;
1866 settings.beginGroup( QStringLiteral( "/connections/cloud/items" ) );
1867 QStringList keys = settings.childGroups();
1868 settings.endGroup();
1869 QDomElement child = root.firstChildElement();
1870 bool prompt = true;
1871 bool overwrite = true;
1872
1873 while ( !child.isNull() )
1874 {
1875 connectionName = child.attribute( QStringLiteral( "name" ) );
1876 if ( !items.contains( connectionName ) )
1877 {
1878 child = child.nextSiblingElement();
1879 continue;
1880 }
1881
1882 // check for duplicates
1883 if ( keys.contains( connectionName ) && prompt )
1884 {
1885 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1886
1887 switch ( res )
1888 {
1889 case QMessageBox::Cancel:
1890 return;
1891 case QMessageBox::No:
1892 child = child.nextSiblingElement();
1893 continue;
1894 case QMessageBox::Yes:
1895 overwrite = true;
1896 break;
1897 case QMessageBox::YesToAll:
1898 prompt = false;
1899 overwrite = true;
1900 break;
1901 case QMessageBox::NoToAll:
1902 prompt = false;
1903 overwrite = false;
1904 break;
1905 }
1906 }
1907
1908 if ( keys.contains( connectionName ) )
1909 {
1910 if ( !overwrite )
1911 {
1912 child = child.nextSiblingElement();
1913 continue;
1914 }
1915 }
1916 else
1917 {
1918 keys << connectionName;
1919 }
1920
1921 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral( "handler" ) ), connectionName );
1922 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral( "container" ) ), connectionName );
1923 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral( "path" ) ), connectionName );
1924
1925 QString credentialString = child.attribute( QStringLiteral( "credentials" ) );
1926
1927 QVariantMap credentialOptions;
1928 while ( true )
1929 {
1930 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral( "\\|credential:([^|]*)" ) );
1931 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral( "(.*?)=(.*)" ) );
1932
1933 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1934 if ( match.hasMatch() )
1935 {
1936 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1937 if ( keyValueMatch.hasMatch() )
1938 {
1939 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1940 }
1941 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1942 }
1943 else
1944 {
1945 break;
1946 }
1947 }
1948
1949 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1950
1951 child = child.nextSiblingElement();
1952 }
1953}
1954
1955void QgsManageConnectionsDialog::loadStacConnections( const QDomDocument &doc, const QStringList &items )
1956{
1957 const QDomElement root = doc.documentElement();
1958 if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
1959 {
1960 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
1961 return;
1962 }
1963
1964 QString connectionName;
1965 QgsSettings settings;
1966 settings.beginGroup( QStringLiteral( "/qgis/connections-stac" ) );
1967 QStringList keys = settings.childGroups();
1968 settings.endGroup();
1969 QDomElement child = root.firstChildElement();
1970 bool prompt = true;
1971 bool overwrite = true;
1972
1973 while ( !child.isNull() )
1974 {
1975 connectionName = child.attribute( QStringLiteral( "name" ) );
1976 if ( !items.contains( connectionName ) )
1977 {
1978 child = child.nextSiblingElement();
1979 continue;
1980 }
1981
1982 // check for duplicates
1983 if ( keys.contains( connectionName ) && prompt )
1984 {
1985 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1986
1987 switch ( res )
1988 {
1989 case QMessageBox::Cancel:
1990 return;
1991 case QMessageBox::No:
1992 child = child.nextSiblingElement();
1993 continue;
1994 case QMessageBox::Yes:
1995 overwrite = true;
1996 break;
1997 case QMessageBox::YesToAll:
1998 prompt = false;
1999 overwrite = true;
2000 break;
2001 case QMessageBox::NoToAll:
2002 prompt = false;
2003 overwrite = false;
2004 break;
2005 }
2006 }
2007
2008 if ( keys.contains( connectionName ) )
2009 {
2010 if ( !overwrite )
2011 {
2012 child = child.nextSiblingElement();
2013 continue;
2014 }
2015 }
2016 else
2017 {
2018 keys << connectionName;
2019 }
2020
2021 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
2022 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
2023 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
2024 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
2025
2026 QgsHttpHeaders httpHeader( child );
2027 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
2028
2029 child = child.nextSiblingElement();
2030 }
2031}
2032
2034{
2035 listConnections->selectAll();
2036 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2037}
2038
2040{
2041 listConnections->clearSelection();
2042 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
2043}
DpiMode
DpiMode enum.
Definition qgis.h:3226
@ Post
POST method.
@ Get
GET method.
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryVariantMap * settingsHeaders
static QgsSettingsTreeNamedListNode * sTreeConnectionArcgis
static const QgsSettingsEntryString * settingsAuthcfg
Implements simple HTTP header management.
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
@ STAC
SpatioTemporal Asset Catalog connections.
@ SensorThings
SensorThings connections.
@ TiledScene
Tiled scene connection.
@ CloudStorage
Cloud storage connections.
static const QgsSettingsEntryEnumFlag< Qgis::HttpMethod > * settingsPreferredHttpMethod
static const QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryString * settingsWfsFeatureMode
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
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.
Stores settings for use within QGIS.
Definition qgssettings.h:66
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