QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
464QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &connections, const QString &service )
465{
466 QDomDocument doc( QStringLiteral( "connections" ) );
467 QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" );
468 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
469 doc.appendChild( root );
470
471 for ( int i = 0; i < connections.count(); ++i )
472 {
473 QDomElement el = doc.createElement( service.toLower() );
474 el.setAttribute( QStringLiteral( "name" ), connections[i] );
475 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { service.toLower(), connections[i] } ) );
476
477 if ( service == QLatin1String( "WMS" ) )
478 {
479 el.setAttribute( QStringLiteral( "ignoreGetMapURI" ), QgsOwsConnection::settingsIgnoreGetMapURI->value( { service.toLower(), connections[i] } ) );
480 el.setAttribute( QStringLiteral( "ignoreGetFeatureInfoURI" ), QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->value( { service.toLower(), connections[i] } ) );
481 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { service.toLower(), connections[i] } ) );
482 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { service.toLower(), connections[i] } ) );
483 el.setAttribute( QStringLiteral( "smoothPixmapTransform" ), QgsOwsConnection::settingsSmoothPixmapTransform->value( { service.toLower(), connections[i] } ) );
484 el.setAttribute( QStringLiteral( "dpiMode" ), static_cast<int>( QgsOwsConnection::settingsDpiMode->value( { service.toLower(), connections[i] } ) ) );
485
486 QgsHttpHeaders httpHeader( QgsOwsConnection::settingsHeaders->value( { service.toLower(), connections[i] } ) );
487 httpHeader.updateDomElement( el );
488 }
489
490 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { service.toLower(), connections[i] } ) );
491 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { service.toLower(), connections[i] } ) );
492 root.appendChild( el );
493 }
494
495 return doc;
496}
497
498QDomDocument QgsManageConnectionsDialog::saveWfsConnections( const QStringList &connections )
499{
500 QDomDocument doc( QStringLiteral( "connections" ) );
501 QDomElement root = doc.createElement( QStringLiteral( "qgsWFSConnections" ) );
502 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1" ) );
503 doc.appendChild( root );
504
505 for ( int i = 0; i < connections.count(); ++i )
506 {
507 QDomElement el = doc.createElement( QStringLiteral( "wfs" ) );
508 el.setAttribute( QStringLiteral( "name" ), connections[i] );
509 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( { QStringLiteral( "wfs" ), connections[i] } ) );
510
511 el.setAttribute( QStringLiteral( "version" ), QgsOwsConnection::settingsVersion->value( { QStringLiteral( "wfs" ), connections[i] } ) );
512 el.setAttribute( QStringLiteral( "maxnumfeatures" ), QgsOwsConnection::settingsMaxNumFeatures->value( { QStringLiteral( "wfs" ), connections[i] } ) );
513 el.setAttribute( QStringLiteral( "pagesize" ), QgsOwsConnection::settingsPagesize->value( { QStringLiteral( "wfs" ), connections[i] } ) );
514 el.setAttribute( QStringLiteral( "pagingenabled" ), QgsOwsConnection::settingsPagingEnabled->value( { QStringLiteral( "wfs" ), connections[i] } ) );
515 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
516 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( { QStringLiteral( "wfs" ), connections[i] } ) );
517 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( { QStringLiteral( "wfs" ), connections[i] } ) );
518 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( { QStringLiteral( "wfs" ), connections[i] } ) );
519 root.appendChild( el );
520 }
521
522 return doc;
523}
524
525QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
526{
527 QDomDocument doc( QStringLiteral( "connections" ) );
528 QDomElement root = doc.createElement( QStringLiteral( "qgsPgConnections" ) );
529 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
530 doc.appendChild( root );
531
532 const QgsSettings settings;
533 QString path;
534 for ( int i = 0; i < connections.count(); ++i )
535 {
536 path = "/PostgreSQL/connections/" + connections[i];
537 QDomElement el = doc.createElement( QStringLiteral( "postgis" ) );
538 el.setAttribute( QStringLiteral( "name" ), connections[i] );
539 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
540 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
541 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
542 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
543 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
544 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
545 el.setAttribute( QStringLiteral( "projectsInDatabase" ), settings.value( path + "/projectsInDatabase", "0" ).toString() );
546 el.setAttribute( QStringLiteral( "dontResolveType" ), settings.value( path + "/dontResolveType", "0" ).toString() );
547 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
548 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
549 el.setAttribute( QStringLiteral( "publicOnly" ), settings.value( path + "/publicOnly", "0" ).toString() );
550
551 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
552
553 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
554 {
555 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
556 }
557
558 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
559
560 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
561 {
562 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
563 }
564
565 root.appendChild( el );
566 }
567
568 return doc;
569}
570
571QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
572{
573 QDomDocument doc( QStringLiteral( "connections" ) );
574 QDomElement root = doc.createElement( QStringLiteral( "qgsMssqlConnections" ) );
575 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
576 doc.appendChild( root );
577
578 const QgsSettings settings;
579 QString path;
580 for ( int i = 0; i < connections.count(); ++i )
581 {
582 path = "/MSSQL/connections/" + connections[i];
583 QDomElement el = doc.createElement( QStringLiteral( "mssql" ) );
584 el.setAttribute( QStringLiteral( "name" ), connections[i] );
585 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
586 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
587 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
588 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
589 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
590 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
591
592 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
593
594 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
595 {
596 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
597 }
598
599 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
600
601 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
602 {
603 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
604 }
605
606 root.appendChild( el );
607 }
608
609 return doc;
610}
611
612QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections )
613{
614 QDomDocument doc( QStringLiteral( "connections" ) );
615 QDomElement root = doc.createElement( QStringLiteral( "qgsOracleConnections" ) );
616 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
617 doc.appendChild( root );
618
619 const QgsSettings settings;
620 QString path;
621 for ( int i = 0; i < connections.count(); ++i )
622 {
623 path = "/Oracle/connections/" + connections[i];
624 QDomElement el = doc.createElement( QStringLiteral( "oracle" ) );
625 el.setAttribute( QStringLiteral( "name" ), connections[i] );
626 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
627 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
628 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
629 el.setAttribute( QStringLiteral( "dboptions" ), settings.value( path + "/dboptions" ).toString() );
630 el.setAttribute( QStringLiteral( "dbworkspace" ), settings.value( path + "/dbworkspace" ).toString() );
631 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
632 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
633 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", "0" ).toString() );
634 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
635 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
636
637 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
638
639 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
640 {
641 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
642 }
643
644 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
645
646 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
647 {
648 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
649 }
650
651 root.appendChild( el );
652 }
653
654 return doc;
655}
656
657QDomDocument QgsManageConnectionsDialog::saveHanaConnections( const QStringList &connections )
658{
659 QDomDocument doc( QStringLiteral( "connections" ) );
660 QDomElement root = doc.createElement( QStringLiteral( "qgsHanaConnections" ) );
661 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
662 doc.appendChild( root );
663
664 const QgsSettings settings;
665 QString path;
666 for ( int i = 0; i < connections.count(); ++i )
667 {
668 path = "/HANA/connections/" + connections[i];
669 QDomElement el = doc.createElement( QStringLiteral( "hana" ) );
670 el.setAttribute( QStringLiteral( "name" ), connections[i] );
671 el.setAttribute( QStringLiteral( "driver" ), settings.value( path + "/driver", QString() ).toString() );
672 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host", QString() ).toString() );
673 el.setAttribute( QStringLiteral( "identifierType" ), settings.value( path + "/identifierType", QString() ).toString() );
674 el.setAttribute( QStringLiteral( "identifier" ), settings.value( path + "/identifier", QString() ).toString() );
675 el.setAttribute( QStringLiteral( "multitenant" ), settings.value( path + "/multitenant", QString() ).toString() );
676 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database", QString() ).toString() );
677 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema", QString() ).toString() );
678 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", QStringLiteral( "0" ) ).toString() );
679 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", QStringLiteral( "0" ) ).toString() );
680
681 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", QStringLiteral( "false" ) ).toString() );
682 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
683 {
684 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", QString() ).toString() );
685 }
686
687 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", QStringLiteral( "false" ) ).toString() );
688 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
689 {
690 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", QString() ).toString() );
691 }
692
693 el.setAttribute( QStringLiteral( "sslEnabled" ), settings.value( path + "/sslEnabled", QStringLiteral( "false" ) ).toString() );
694 el.setAttribute( QStringLiteral( "sslCryptoProvider" ), settings.value( path + "/sslCryptoProvider", QStringLiteral( "openssl" ) ).toString() );
695 el.setAttribute( QStringLiteral( "sslKeyStore" ), settings.value( path + "/sslKeyStore", QString() ).toString() );
696 el.setAttribute( QStringLiteral( "sslTrustStore" ), settings.value( path + "/sslTrustStore", QString() ).toString() );
697 el.setAttribute( QStringLiteral( "sslValidateCertificate" ), settings.value( path + "/sslValidateCertificate", QStringLiteral( "false" ) ).toString() );
698 el.setAttribute( QStringLiteral( "sslHostNameInCertificate" ), settings.value( path + "/sslHostNameInCertificate", QString() ).toString() );
699
700 root.appendChild( el );
701 }
702
703 return doc;
704}
705
706QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
707{
708 QDomDocument doc( QStringLiteral( "connections" ) );
709 QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
710 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
711 doc.appendChild( root );
712
713 for ( int i = 0; i < connections.count(); ++i )
714 {
715 QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
716
717 el.setAttribute( QStringLiteral( "name" ), connections[i] );
718 el.setAttribute( QStringLiteral( "url" ), QgsXyzConnectionSettings::settingsUrl->value( connections[i] ) );
719 el.setAttribute( QStringLiteral( "zmin" ), QgsXyzConnectionSettings::settingsZmin->value( connections[i] ) );
720 el.setAttribute( QStringLiteral( "zmax" ), QgsXyzConnectionSettings::settingsZmax->value( connections[i] ) );
721 el.setAttribute( QStringLiteral( "authcfg" ), QgsXyzConnectionSettings::settingsAuthcfg->value( connections[i] ) );
722 el.setAttribute( QStringLiteral( "username" ), QgsXyzConnectionSettings::settingsUsername->value( connections[i] ) );
723 el.setAttribute( QStringLiteral( "password" ), QgsXyzConnectionSettings::settingsPassword->value( connections[i] ) );
724 el.setAttribute( QStringLiteral( "tilePixelRatio" ), QgsXyzConnectionSettings::settingsTilePixelRatio->value( connections[i] ) );
725
726 QgsHttpHeaders httpHeader( QgsXyzConnectionSettings::settingsHeaders->value( connections[i] ) );
727 httpHeader.updateDomElement( el );
728
729 root.appendChild( el );
730 }
731
732 return doc;
733}
734
735QDomDocument QgsManageConnectionsDialog::saveArcgisConnections( const QStringList &connections )
736{
737 QDomDocument doc( QStringLiteral( "connections" ) );
738 QDomElement root = doc.createElement( "qgsARCGISFEATURESERVERConnections" );
739 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
740 doc.appendChild( root );
741
742 for ( const QString &connection : connections )
743 {
744 QDomElement el = doc.createElement( QStringLiteral( "arcgisfeatureserver" ) );
745 el.setAttribute( QStringLiteral( "name" ), connection );
746 el.setAttribute( QStringLiteral( "url" ), QgsArcGisConnectionSettings::settingsUrl->value( connection ) );
747
748 QgsHttpHeaders httpHeader( QgsArcGisConnectionSettings::settingsHeaders->value( connection ) );
749 httpHeader.updateDomElement( el );
750
751 el.setAttribute( QStringLiteral( "username" ), QgsArcGisConnectionSettings::settingsUsername->value( connection ) );
752 el.setAttribute( QStringLiteral( "password" ), QgsArcGisConnectionSettings::settingsPassword->value( connection ) );
753 el.setAttribute( QStringLiteral( "authcfg" ), QgsArcGisConnectionSettings::settingsAuthcfg->value( connection ) );
754
755 root.appendChild( el );
756 }
757
758 return doc;
759}
760
761QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections( const QStringList &connections )
762{
763 QDomDocument doc( QStringLiteral( "connections" ) );
764 QDomElement root = doc.createElement( QStringLiteral( "qgsVectorTileConnections" ) );
765 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
766 doc.appendChild( root );
767
768 for ( int i = 0; i < connections.count(); ++i )
769 {
770 QDomElement el = doc.createElement( QStringLiteral( "vectortile" ) );
771
772 el.setAttribute( QStringLiteral( "name" ), connections[i] );
773 el.setAttribute( QStringLiteral( "url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[i] ) );
774 el.setAttribute( QStringLiteral( "zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[i] ) );
775 el.setAttribute( QStringLiteral( "zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[i] ) );
776 el.setAttribute( QStringLiteral( "serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[i] ) );
777 el.setAttribute( QStringLiteral( "authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[i] ) );
778 el.setAttribute( QStringLiteral( "username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[i] ) );
779 el.setAttribute( QStringLiteral( "password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[i] ) );
780 el.setAttribute( QStringLiteral( "styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[i] ) );
781
782 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[i] ) );
783 httpHeader.updateDomElement( el );
784
785 root.appendChild( el );
786 }
787
788 return doc;
789}
790
791QDomDocument QgsManageConnectionsDialog::saveTiledSceneConnections( const QStringList &connections )
792{
793 QDomDocument doc( QStringLiteral( "connections" ) );
794 QDomElement root = doc.createElement( QStringLiteral( "qgsTiledSceneConnections" ) );
795 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
796 doc.appendChild( root );
797
798 for ( int i = 0; i < connections.count(); ++i )
799 {
800 QDomElement el = doc.createElement( QStringLiteral( "tiledscene" ) );
801
802 el.setAttribute( QStringLiteral( "name" ), connections[i] );
803 el.setAttribute( QStringLiteral( "provider" ), QgsTiledSceneProviderConnection::settingsProvider->value( connections[i] ) );
804 el.setAttribute( QStringLiteral( "url" ), QgsTiledSceneProviderConnection::settingsUrl->value( connections[i] ) );
805 el.setAttribute( QStringLiteral( "authcfg" ), QgsTiledSceneProviderConnection::settingsAuthcfg->value( connections[i] ) );
806 el.setAttribute( QStringLiteral( "username" ), QgsTiledSceneProviderConnection::settingsUsername->value( connections[i] ) );
807 el.setAttribute( QStringLiteral( "password" ), QgsTiledSceneProviderConnection::settingsPassword->value( connections[i] ) );
808
809 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
810 httpHeader.updateDomElement( el );
811
812 root.appendChild( el );
813 }
814
815 return doc;
816}
817
818QDomDocument QgsManageConnectionsDialog::saveSensorThingsConnections( const QStringList &connections )
819{
820 QDomDocument doc( QStringLiteral( "connections" ) );
821 QDomElement root = doc.createElement( QStringLiteral( "qgsSensorThingsConnections" ) );
822 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
823 doc.appendChild( root );
824
825 for ( int i = 0; i < connections.count(); ++i )
826 {
827 QDomElement el = doc.createElement( QStringLiteral( "sensorthings" ) );
828
829 el.setAttribute( QStringLiteral( "name" ), connections[i] );
830 el.setAttribute( QStringLiteral( "url" ), QgsSensorThingsProviderConnection::settingsUrl->value( connections[i] ) );
831 el.setAttribute( QStringLiteral( "authcfg" ), QgsSensorThingsProviderConnection::settingsAuthcfg->value( connections[i] ) );
832 el.setAttribute( QStringLiteral( "username" ), QgsSensorThingsProviderConnection::settingsUsername->value( connections[i] ) );
833 el.setAttribute( QStringLiteral( "password" ), QgsSensorThingsProviderConnection::settingsPassword->value( connections[i] ) );
834
835 QgsHttpHeaders httpHeader( QgsTiledSceneProviderConnection::settingsHeaders->value( connections[i] ) );
836 httpHeader.updateDomElement( el );
837
838 root.appendChild( el );
839 }
840
841 return doc;
842}
843
844
845QDomDocument QgsManageConnectionsDialog::saveCloudStorageConnections( const QStringList &connections )
846{
847 QDomDocument doc( QStringLiteral( "connections" ) );
848 QDomElement root = doc.createElement( QStringLiteral( "qgsCloudStorageConnections" ) );
849 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
850 doc.appendChild( root );
851
852 for ( int i = 0; i < connections.count(); ++i )
853 {
854 QDomElement el = doc.createElement( QStringLiteral( "cloudstorage" ) );
855
856 el.setAttribute( QStringLiteral( "name" ), connections[i] );
857 el.setAttribute( QStringLiteral( "handler" ), QgsGdalCloudProviderConnection::settingsVsiHandler->value( connections[i] ) );
858 el.setAttribute( QStringLiteral( "container" ), QgsGdalCloudProviderConnection::settingsContainer->value( connections[i] ) );
859 el.setAttribute( QStringLiteral( "path" ), QgsGdalCloudProviderConnection::settingsPath->value( connections[i] ) );
860
861 const QVariantMap credentialOptions = QgsGdalCloudProviderConnection::settingsCredentialOptions->value( connections[i] );
862 QString credentialString;
863 for ( auto it = credentialOptions.constBegin(); it != credentialOptions.constEnd(); ++it )
864 {
865 if ( !it.value().toString().isEmpty() )
866 {
867 credentialString += QStringLiteral( "|credential:%1=%2" ).arg( it.key(), it.value().toString() );
868 }
869 }
870 el.setAttribute( QStringLiteral( "credentials" ), credentialString );
871
872 root.appendChild( el );
873 }
874
875 return doc;
876}
877
878QDomDocument QgsManageConnectionsDialog::saveStacConnections( const QStringList &connections )
879{
880 QDomDocument doc( QStringLiteral( "connections" ) );
881 QDomElement root = doc.createElement( QStringLiteral( "qgsStacConnections" ) );
882 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
883 doc.appendChild( root );
884
885 for ( int i = 0; i < connections.count(); ++i )
886 {
887 QDomElement el = doc.createElement( QStringLiteral( "stac" ) );
888
889 el.setAttribute( QStringLiteral( "name" ), connections[i] );
890 el.setAttribute( QStringLiteral( "url" ), QgsStacConnection::settingsUrl->value( connections[i] ) );
891 el.setAttribute( QStringLiteral( "authcfg" ), QgsStacConnection::settingsAuthcfg->value( connections[i] ) );
892 el.setAttribute( QStringLiteral( "username" ), QgsStacConnection::settingsUsername->value( connections[i] ) );
893 el.setAttribute( QStringLiteral( "password" ), QgsStacConnection::settingsPassword->value( connections[i] ) );
894
895 QgsHttpHeaders httpHeader( QgsStacConnection::settingsHeaders->value( connections[i] ) );
896 httpHeader.updateDomElement( el );
897
898 root.appendChild( el );
899 }
900
901 return doc;
902}
903
904void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
905{
906 const QDomElement root = doc.documentElement();
907 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
908 {
909 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
910 return;
911 }
912
913 QString connectionName;
914
915 QDomElement child = root.firstChildElement();
916 bool prompt = true;
917 bool overwrite = true;
918
919 while ( !child.isNull() )
920 {
921 connectionName = child.attribute( QStringLiteral( "name" ) );
922 if ( !items.contains( connectionName ) )
923 {
924 child = child.nextSiblingElement();
925 continue;
926 }
927
928 // check for duplicates
929 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && prompt )
930 {
931 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
932
933 switch ( res )
934 {
935 case QMessageBox::Cancel:
936 return;
937 case QMessageBox::No:
938 child = child.nextSiblingElement();
939 continue;
940 case QMessageBox::Yes:
941 overwrite = true;
942 break;
943 case QMessageBox::YesToAll:
944 prompt = false;
945 overwrite = true;
946 break;
947 case QMessageBox::NoToAll:
948 prompt = false;
949 overwrite = false;
950 break;
951 }
952 }
953
954 if ( QgsOwsConnection::settingsUrl->exists( { service.toLower(), connectionName } ) && !overwrite )
955 {
956 child = child.nextSiblingElement();
957 continue;
958 }
959
960 // no dups detected or overwrite is allowed
961 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { service.toLower(), connectionName } );
962 QgsOwsConnection::settingsIgnoreGetMapURI->setValue( child.attribute( QStringLiteral( "ignoreGetMapURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
963 QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( child.attribute( QStringLiteral( "ignoreGetFeatureInfoURI" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
964 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
965 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
966 QgsOwsConnection::settingsSmoothPixmapTransform->setValue( child.attribute( QStringLiteral( "smoothPixmapTransform" ) ) == QLatin1String( "true" ), { service.toLower(), connectionName } );
967 QgsOwsConnection::settingsDpiMode->setValue( static_cast<Qgis::DpiMode>( child.attribute( QStringLiteral( "dpiMode" ), QStringLiteral( "7" ) ).toInt() ), { service.toLower(), connectionName } );
968
969 QgsHttpHeaders httpHeader( child );
970 QgsOwsConnection::settingsHeaders->setValue( httpHeader.headers(), { service.toLower(), connectionName } );
971
972 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
973 {
974 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { service.toUpper(), connectionName } );
975 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { service.toUpper(), connectionName } );
976 }
977 child = child.nextSiblingElement();
978 }
979}
980
981void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
982{
983 const QDomElement root = doc.documentElement();
984 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
985 {
986 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a WFS connections exchange file." ) );
987 return;
988 }
989
990 QString connectionName;
991 QStringList keys = QgsOwsConnection::sTreeOwsConnections->items( { QStringLiteral( "wfs" ) } );
992
993 QDomElement child = root.firstChildElement();
994 bool prompt = true;
995 bool overwrite = true;
996
997 while ( !child.isNull() )
998 {
999 connectionName = child.attribute( QStringLiteral( "name" ) );
1000 if ( !items.contains( connectionName ) )
1001 {
1002 child = child.nextSiblingElement();
1003 continue;
1004 }
1005
1006 // check for duplicates
1007 if ( keys.contains( connectionName ) && prompt )
1008 {
1009 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1010
1011 switch ( res )
1012 {
1013 case QMessageBox::Cancel:
1014 return;
1015 case QMessageBox::No:
1016 child = child.nextSiblingElement();
1017 continue;
1018 case QMessageBox::Yes:
1019 overwrite = true;
1020 break;
1021 case QMessageBox::YesToAll:
1022 prompt = false;
1023 overwrite = true;
1024 break;
1025 case QMessageBox::NoToAll:
1026 prompt = false;
1027 overwrite = false;
1028 break;
1029 }
1030 }
1031
1032 if ( keys.contains( connectionName ) )
1033 {
1034 if ( !overwrite )
1035 {
1036 child = child.nextSiblingElement();
1037 continue;
1038 }
1039 }
1040 else
1041 {
1042 keys << connectionName;
1043 }
1044
1045 // no dups detected or overwrite is allowed
1046
1047 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), { QStringLiteral( "wfs" ), connectionName } );
1048 QgsOwsConnection::settingsVersion->setValue( child.attribute( QStringLiteral( "version" ) ), { QStringLiteral( "wfs" ), connectionName } );
1049 QgsOwsConnection::settingsMaxNumFeatures->setValue( child.attribute( QStringLiteral( "maxnumfeatures" ) ), { QStringLiteral( "wfs" ), connectionName } );
1050 QgsOwsConnection::settingsPagesize->setValue( child.attribute( QStringLiteral( "pagesize" ) ), { QStringLiteral( "wfs" ), connectionName } );
1051 QgsOwsConnection::settingsPagingEnabled->setValue( child.attribute( QStringLiteral( "pagingenabled" ) ), { QStringLiteral( "wfs" ), connectionName } );
1052 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1053 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ).toInt(), { QStringLiteral( "wfs" ), connectionName } );
1054
1055 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1056 {
1057 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), { QStringLiteral( "wfs" ), connectionName } );
1058 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), { QStringLiteral( "wfs" ), connectionName } );
1059 }
1060 child = child.nextSiblingElement();
1061 }
1062}
1063
1064void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
1065{
1066 const QDomElement root = doc.documentElement();
1067 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
1068 {
1069 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a PostGIS connections exchange file." ) );
1070 return;
1071 }
1072
1073 QString connectionName;
1074 QgsSettings settings;
1075 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
1076 QStringList keys = settings.childGroups();
1077 settings.endGroup();
1078 QDomElement child = root.firstChildElement();
1079 bool prompt = true;
1080 bool overwrite = true;
1081
1082 while ( !child.isNull() )
1083 {
1084 connectionName = child.attribute( QStringLiteral( "name" ) );
1085 if ( !items.contains( connectionName ) )
1086 {
1087 child = child.nextSiblingElement();
1088 continue;
1089 }
1090
1091 // check for duplicates
1092 if ( keys.contains( connectionName ) && prompt )
1093 {
1094 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1095 switch ( res )
1096 {
1097 case QMessageBox::Cancel:
1098 return;
1099 case QMessageBox::No:
1100 child = child.nextSiblingElement();
1101 continue;
1102 case QMessageBox::Yes:
1103 overwrite = true;
1104 break;
1105 case QMessageBox::YesToAll:
1106 prompt = false;
1107 overwrite = true;
1108 break;
1109 case QMessageBox::NoToAll:
1110 prompt = false;
1111 overwrite = false;
1112 break;
1113 }
1114 }
1115
1116 if ( keys.contains( connectionName ) )
1117 {
1118 if ( !overwrite )
1119 {
1120 child = child.nextSiblingElement();
1121 continue;
1122 }
1123 }
1124 else
1125 {
1126 keys << connectionName;
1127 }
1128
1129 //no dups detected or overwrite is allowed
1130 settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
1131
1132 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1133 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1134 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1135 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1136 {
1137 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1138 }
1139 else
1140 {
1141 settings.setValue( QStringLiteral( "/service" ), "" );
1142 }
1143 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1144 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1145 settings.setValue( QStringLiteral( "/projectsInDatabase" ), child.attribute( QStringLiteral( "projectsInDatabase" ), 0 ) );
1146 settings.setValue( QStringLiteral( "/dontResolveType" ), child.attribute( QStringLiteral( "dontResolveType" ), 0 ) );
1147 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ), 0 ) );
1148 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ), 0 ) );
1149 settings.setValue( QStringLiteral( "/publicOnly" ), child.attribute( QStringLiteral( "publicOnly" ), 0 ) );
1150 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1151 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1152 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1153 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1154 settings.endGroup();
1155
1156 child = child.nextSiblingElement();
1157 }
1158}
1159
1160void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1161{
1162 const QDomElement root = doc.documentElement();
1163 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
1164 {
1165 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a MS SQL Server connections exchange file." ) );
1166 return;
1167 }
1168
1169 QString connectionName;
1170 QgsSettings settings;
1171 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
1172 QStringList keys = settings.childGroups();
1173 settings.endGroup();
1174 QDomElement child = root.firstChildElement();
1175 bool prompt = true;
1176 bool overwrite = true;
1177
1178 while ( !child.isNull() )
1179 {
1180 connectionName = child.attribute( QStringLiteral( "name" ) );
1181 if ( !items.contains( connectionName ) )
1182 {
1183 child = child.nextSiblingElement();
1184 continue;
1185 }
1186
1187 // check for duplicates
1188 if ( keys.contains( connectionName ) && prompt )
1189 {
1190 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1191 switch ( res )
1192 {
1193 case QMessageBox::Cancel:
1194 return;
1195 case QMessageBox::No:
1196 child = child.nextSiblingElement();
1197 continue;
1198 case QMessageBox::Yes:
1199 overwrite = true;
1200 break;
1201 case QMessageBox::YesToAll:
1202 prompt = false;
1203 overwrite = true;
1204 break;
1205 case QMessageBox::NoToAll:
1206 prompt = false;
1207 overwrite = false;
1208 break;
1209 }
1210 }
1211
1212 if ( keys.contains( connectionName ) )
1213 {
1214 if ( !overwrite )
1215 {
1216 child = child.nextSiblingElement();
1217 continue;
1218 }
1219 }
1220 else
1221 {
1222 keys << connectionName;
1223 }
1224
1225 //no dups detected or overwrite is allowed
1226 settings.beginGroup( "/MSSQL/connections/" + connectionName );
1227
1228 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1229 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1230 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1231 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1232 {
1233 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1234 }
1235 else
1236 {
1237 settings.setValue( QStringLiteral( "/service" ), "" );
1238 }
1239 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1240 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1241 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1242 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1243 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1244 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1245 settings.endGroup();
1246
1247 child = child.nextSiblingElement();
1248 }
1249}
1250
1251void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1252{
1253 const QDomElement root = doc.documentElement();
1254 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
1255 {
1256 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not an Oracle connections exchange file." ) );
1257 return;
1258 }
1259
1260 QString connectionName;
1261 QgsSettings settings;
1262 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
1263 QStringList keys = settings.childGroups();
1264 settings.endGroup();
1265 QDomElement child = root.firstChildElement();
1266 bool prompt = true;
1267 bool overwrite = true;
1268
1269 while ( !child.isNull() )
1270 {
1271 connectionName = child.attribute( QStringLiteral( "name" ) );
1272 if ( !items.contains( connectionName ) )
1273 {
1274 child = child.nextSiblingElement();
1275 continue;
1276 }
1277
1278 // check for duplicates
1279 if ( keys.contains( connectionName ) && prompt )
1280 {
1281 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1282 switch ( res )
1283 {
1284 case QMessageBox::Cancel:
1285 return;
1286 case QMessageBox::No:
1287 child = child.nextSiblingElement();
1288 continue;
1289 case QMessageBox::Yes:
1290 overwrite = true;
1291 break;
1292 case QMessageBox::YesToAll:
1293 prompt = false;
1294 overwrite = true;
1295 break;
1296 case QMessageBox::NoToAll:
1297 prompt = false;
1298 overwrite = false;
1299 break;
1300 }
1301 }
1302
1303 if ( keys.contains( connectionName ) )
1304 {
1305 if ( !overwrite )
1306 {
1307 child = child.nextSiblingElement();
1308 continue;
1309 }
1310 }
1311 else
1312 {
1313 keys << connectionName;
1314 }
1315
1316 //no dups detected or overwrite is allowed
1317 settings.beginGroup( "/Oracle/connections/" + connectionName );
1318
1319 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1320 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1321 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1322 settings.setValue( QStringLiteral( "/dboptions" ), child.attribute( QStringLiteral( "dboptions" ) ) );
1323 settings.setValue( QStringLiteral( "/dbworkspace" ), child.attribute( QStringLiteral( "dbworkspace" ) ) );
1324 settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1325 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1326 settings.setValue( QStringLiteral( "/userTablesOnly" ), child.attribute( QStringLiteral( "userTablesOnly" ) ) );
1327 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ) ) );
1328 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ) ) );
1329 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1330 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1331 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1332 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1333 settings.endGroup();
1334
1335 child = child.nextSiblingElement();
1336 }
1337}
1338
1339void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1340{
1341 QDomElement root = doc.documentElement();
1342 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
1343 {
1344 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The file is not a HANA connections exchange file." ) );
1345 return;
1346 }
1347
1348 const QDomAttr version = root.attributeNode( "version" );
1349 if ( version.value() != QLatin1String( "1.0" ) )
1350 {
1351 QMessageBox::warning( this, tr( "Loading Connections" ), tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1352 return;
1353 }
1354
1355 QgsSettings settings;
1356 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
1357 QStringList keys = settings.childGroups();
1358 settings.endGroup();
1359 QDomElement child = root.firstChildElement();
1360 bool prompt = true;
1361 bool overwrite = true;
1362
1363 while ( !child.isNull() )
1364 {
1365 const QString connectionName = child.attribute( QStringLiteral( "name" ) );
1366 if ( !items.contains( connectionName ) )
1367 {
1368 child = child.nextSiblingElement();
1369 continue;
1370 }
1371
1372 // check for duplicates
1373 if ( keys.contains( connectionName ) && prompt )
1374 {
1375 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1376 switch ( res )
1377 {
1378 case QMessageBox::Cancel:
1379 return;
1380 case QMessageBox::No:
1381 child = child.nextSiblingElement();
1382 continue;
1383 case QMessageBox::Yes:
1384 overwrite = true;
1385 break;
1386 case QMessageBox::YesToAll:
1387 prompt = false;
1388 overwrite = true;
1389 break;
1390 case QMessageBox::NoToAll:
1391 prompt = false;
1392 overwrite = false;
1393 break;
1394 }
1395 }
1396
1397 if ( keys.contains( connectionName ) )
1398 {
1399 if ( !overwrite )
1400 {
1401 child = child.nextSiblingElement();
1402 continue;
1403 }
1404 }
1405 else
1406 {
1407 keys << connectionName;
1408 }
1409
1410 //no dups detected or overwrite is allowed
1411 settings.beginGroup( "/HANA/connections/" + connectionName );
1412
1413 for ( const QString param :
1414 { "driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1415 "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1416 "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1417 } )
1418 settings.setValue( QStringLiteral( "/" ) + param, child.attribute( param ) );
1419
1420 settings.endGroup();
1421
1422 child = child.nextSiblingElement();
1423 }
1424}
1425
1426void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1427{
1428 const QDomElement root = doc.documentElement();
1429 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
1430 {
1431 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a XYZ Tiles connections exchange file." ) );
1432 return;
1433 }
1434
1435 QString connectionName;
1437 QDomElement child = root.firstChildElement();
1438 bool prompt = true;
1439 bool overwrite = true;
1440
1441 while ( !child.isNull() )
1442 {
1443 connectionName = child.attribute( QStringLiteral( "name" ) );
1444 if ( !items.contains( connectionName ) )
1445 {
1446 child = child.nextSiblingElement();
1447 continue;
1448 }
1449
1450 // check for duplicates
1451 if ( keys.contains( connectionName ) && prompt )
1452 {
1453 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1454
1455 switch ( res )
1456 {
1457 case QMessageBox::Cancel:
1458 return;
1459 case QMessageBox::No:
1460 child = child.nextSiblingElement();
1461 continue;
1462 case QMessageBox::Yes:
1463 overwrite = true;
1464 break;
1465 case QMessageBox::YesToAll:
1466 prompt = false;
1467 overwrite = true;
1468 break;
1469 case QMessageBox::NoToAll:
1470 prompt = false;
1471 overwrite = false;
1472 break;
1473 }
1474 }
1475
1476 if ( keys.contains( connectionName ) )
1477 {
1478 if ( !overwrite )
1479 {
1480 child = child.nextSiblingElement();
1481 continue;
1482 }
1483 }
1484 else
1485 {
1486 keys << connectionName;
1487 }
1488
1489
1490 QgsXyzConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1491 QgsXyzConnectionSettings::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1492 QgsXyzConnectionSettings::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1493 QgsXyzConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1494 QgsXyzConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1495 QgsXyzConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1496 QgsXyzConnectionSettings::settingsTilePixelRatio->setValue( child.attribute( QStringLiteral( "tilePixelRatio" ) ).toInt(), connectionName );
1497
1498 QgsHttpHeaders httpHeader( child );
1499 QgsXyzConnectionSettings::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1500
1501 child = child.nextSiblingElement();
1502 }
1503}
1504
1505void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1506{
1507 const QDomElement root = doc.documentElement();
1508 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1509 {
1510 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1511 return;
1512 }
1513
1514 QString connectionName;
1516 QDomElement child = root.firstChildElement();
1517 bool prompt = true;
1518 bool overwrite = true;
1519
1520 while ( !child.isNull() )
1521 {
1522 connectionName = child.attribute( QStringLiteral( "name" ) );
1523 if ( !items.contains( connectionName ) )
1524 {
1525 child = child.nextSiblingElement();
1526 continue;
1527 }
1528
1529 // check for duplicates
1530 if ( keys.contains( connectionName ) && prompt )
1531 {
1532 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1533
1534 switch ( res )
1535 {
1536 case QMessageBox::Cancel:
1537 return;
1538 case QMessageBox::No:
1539 child = child.nextSiblingElement();
1540 continue;
1541 case QMessageBox::Yes:
1542 overwrite = true;
1543 break;
1544 case QMessageBox::YesToAll:
1545 prompt = false;
1546 overwrite = true;
1547 break;
1548 case QMessageBox::NoToAll:
1549 prompt = false;
1550 overwrite = false;
1551 break;
1552 }
1553 }
1554
1555 if ( keys.contains( connectionName ) )
1556 {
1557 if ( !overwrite )
1558 {
1559 child = child.nextSiblingElement();
1560 continue;
1561 }
1562 }
1563 else
1564 {
1565 keys << connectionName;
1566 }
1567
1568 // no dups detected or overwrite is allowed
1569 QgsArcGisConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1570
1571 QgsArcGisConnectionSettings::settingsHeaders->setValue( QgsHttpHeaders( child ).headers(), connectionName );
1572
1573
1574 QgsArcGisConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1575 QgsArcGisConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1576 QgsArcGisConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1577
1578 child = child.nextSiblingElement();
1579 }
1580}
1581
1582void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1583{
1584 const QDomElement root = doc.documentElement();
1585 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
1586 {
1587 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a Vector Tile connections exchange file." ) );
1588 return;
1589 }
1590
1591 QString connectionName;
1592 QgsSettings settings;
1593 settings.beginGroup( QStringLiteral( "/qgis/connections-vector-tile" ) );
1594 QStringList keys = settings.childGroups();
1595 settings.endGroup();
1596 QDomElement child = root.firstChildElement();
1597 bool prompt = true;
1598 bool overwrite = true;
1599
1600 while ( !child.isNull() )
1601 {
1602 connectionName = child.attribute( QStringLiteral( "name" ) );
1603 if ( !items.contains( connectionName ) )
1604 {
1605 child = child.nextSiblingElement();
1606 continue;
1607 }
1608
1609 // check for duplicates
1610 if ( keys.contains( connectionName ) && prompt )
1611 {
1612 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1613
1614 switch ( res )
1615 {
1616 case QMessageBox::Cancel:
1617 return;
1618 case QMessageBox::No:
1619 child = child.nextSiblingElement();
1620 continue;
1621 case QMessageBox::Yes:
1622 overwrite = true;
1623 break;
1624 case QMessageBox::YesToAll:
1625 prompt = false;
1626 overwrite = true;
1627 break;
1628 case QMessageBox::NoToAll:
1629 prompt = false;
1630 overwrite = false;
1631 break;
1632 }
1633 }
1634
1635 if ( keys.contains( connectionName ) )
1636 {
1637 if ( !overwrite )
1638 {
1639 child = child.nextSiblingElement();
1640 continue;
1641 }
1642 }
1643 else
1644 {
1645 keys << connectionName;
1646 }
1647
1648 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1649 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1650 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1651 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral( "serviceType" ) ), connectionName );
1652 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1653 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1654 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1655 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral( "styleUrl" ) ), connectionName );
1656
1657 QgsHttpHeaders httpHeader( child );
1658 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1659
1660 child = child.nextSiblingElement();
1661 }
1662}
1663
1664void QgsManageConnectionsDialog::loadTiledSceneConnections( const QDomDocument &doc, const QStringList &items )
1665{
1666 const QDomElement root = doc.documentElement();
1667 if ( root.tagName() != QLatin1String( "qgsTiledSceneConnections" ) )
1668 {
1669 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a tiled scene connections exchange file." ) );
1670 return;
1671 }
1672
1673 QString connectionName;
1674 QgsSettings settings;
1675 settings.beginGroup( QStringLiteral( "/qgis/connections-tiled-scene" ) );
1676 QStringList keys = settings.childGroups();
1677 settings.endGroup();
1678 QDomElement child = root.firstChildElement();
1679 bool prompt = true;
1680 bool overwrite = true;
1681
1682 while ( !child.isNull() )
1683 {
1684 connectionName = child.attribute( QStringLiteral( "name" ) );
1685 if ( !items.contains( connectionName ) )
1686 {
1687 child = child.nextSiblingElement();
1688 continue;
1689 }
1690
1691 // check for duplicates
1692 if ( keys.contains( connectionName ) && prompt )
1693 {
1694 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1695
1696 switch ( res )
1697 {
1698 case QMessageBox::Cancel:
1699 return;
1700 case QMessageBox::No:
1701 child = child.nextSiblingElement();
1702 continue;
1703 case QMessageBox::Yes:
1704 overwrite = true;
1705 break;
1706 case QMessageBox::YesToAll:
1707 prompt = false;
1708 overwrite = true;
1709 break;
1710 case QMessageBox::NoToAll:
1711 prompt = false;
1712 overwrite = false;
1713 break;
1714 }
1715 }
1716
1717 if ( keys.contains( connectionName ) )
1718 {
1719 if ( !overwrite )
1720 {
1721 child = child.nextSiblingElement();
1722 continue;
1723 }
1724 }
1725 else
1726 {
1727 keys << connectionName;
1728 }
1729
1730 QgsTiledSceneProviderConnection::settingsProvider->setValue( child.attribute( QStringLiteral( "provider" ) ), connectionName );
1731 QgsTiledSceneProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1732 QgsTiledSceneProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1733 QgsTiledSceneProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1734 QgsTiledSceneProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1735
1736 QgsHttpHeaders httpHeader( child );
1737 QgsTiledSceneProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1738
1739 child = child.nextSiblingElement();
1740 }
1741}
1742
1743void QgsManageConnectionsDialog::loadSensorThingsConnections( const QDomDocument &doc, const QStringList &items )
1744{
1745 const QDomElement root = doc.documentElement();
1746 if ( root.tagName() != QLatin1String( "qgsSensorThingsConnections" ) )
1747 {
1748 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a SensorThings connections exchange file." ) );
1749 return;
1750 }
1751
1752 QString connectionName;
1753 QgsSettings settings;
1754 settings.beginGroup( QStringLiteral( "/connections/sensorthings/items" ) );
1755 QStringList keys = settings.childGroups();
1756 settings.endGroup();
1757 QDomElement child = root.firstChildElement();
1758 bool prompt = true;
1759 bool overwrite = true;
1760
1761 while ( !child.isNull() )
1762 {
1763 connectionName = child.attribute( QStringLiteral( "name" ) );
1764 if ( !items.contains( connectionName ) )
1765 {
1766 child = child.nextSiblingElement();
1767 continue;
1768 }
1769
1770 // check for duplicates
1771 if ( keys.contains( connectionName ) && prompt )
1772 {
1773 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1774
1775 switch ( res )
1776 {
1777 case QMessageBox::Cancel:
1778 return;
1779 case QMessageBox::No:
1780 child = child.nextSiblingElement();
1781 continue;
1782 case QMessageBox::Yes:
1783 overwrite = true;
1784 break;
1785 case QMessageBox::YesToAll:
1786 prompt = false;
1787 overwrite = true;
1788 break;
1789 case QMessageBox::NoToAll:
1790 prompt = false;
1791 overwrite = false;
1792 break;
1793 }
1794 }
1795
1796 if ( keys.contains( connectionName ) )
1797 {
1798 if ( !overwrite )
1799 {
1800 child = child.nextSiblingElement();
1801 continue;
1802 }
1803 }
1804 else
1805 {
1806 keys << connectionName;
1807 }
1808
1809 QgsSensorThingsProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1810 QgsSensorThingsProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1811 QgsSensorThingsProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1812 QgsSensorThingsProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1813
1814 QgsHttpHeaders httpHeader( child );
1815 QgsSensorThingsProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1816
1817 child = child.nextSiblingElement();
1818 }
1819}
1820
1821void QgsManageConnectionsDialog::loadCloudStorageConnections( const QDomDocument &doc, const QStringList &items )
1822{
1823 const QDomElement root = doc.documentElement();
1824 if ( root.tagName() != QLatin1String( "qgsCloudStorageConnections" ) )
1825 {
1826 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a cloud storage connections exchange file." ) );
1827 return;
1828 }
1829
1830 QString connectionName;
1831 QgsSettings settings;
1832 settings.beginGroup( QStringLiteral( "/connections/cloud/items" ) );
1833 QStringList keys = settings.childGroups();
1834 settings.endGroup();
1835 QDomElement child = root.firstChildElement();
1836 bool prompt = true;
1837 bool overwrite = true;
1838
1839 while ( !child.isNull() )
1840 {
1841 connectionName = child.attribute( QStringLiteral( "name" ) );
1842 if ( !items.contains( connectionName ) )
1843 {
1844 child = child.nextSiblingElement();
1845 continue;
1846 }
1847
1848 // check for duplicates
1849 if ( keys.contains( connectionName ) && prompt )
1850 {
1851 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1852
1853 switch ( res )
1854 {
1855 case QMessageBox::Cancel:
1856 return;
1857 case QMessageBox::No:
1858 child = child.nextSiblingElement();
1859 continue;
1860 case QMessageBox::Yes:
1861 overwrite = true;
1862 break;
1863 case QMessageBox::YesToAll:
1864 prompt = false;
1865 overwrite = true;
1866 break;
1867 case QMessageBox::NoToAll:
1868 prompt = false;
1869 overwrite = false;
1870 break;
1871 }
1872 }
1873
1874 if ( keys.contains( connectionName ) )
1875 {
1876 if ( !overwrite )
1877 {
1878 child = child.nextSiblingElement();
1879 continue;
1880 }
1881 }
1882 else
1883 {
1884 keys << connectionName;
1885 }
1886
1887 QgsGdalCloudProviderConnection::settingsVsiHandler->setValue( child.attribute( QStringLiteral( "handler" ) ), connectionName );
1888 QgsGdalCloudProviderConnection::settingsContainer->setValue( child.attribute( QStringLiteral( "container" ) ), connectionName );
1889 QgsGdalCloudProviderConnection::settingsPath->setValue( child.attribute( QStringLiteral( "path" ) ), connectionName );
1890
1891 QString credentialString = child.attribute( QStringLiteral( "credentials" ) );
1892
1893 QVariantMap credentialOptions;
1894 while ( true )
1895 {
1896 const thread_local QRegularExpression credentialOptionRegex( QStringLiteral( "\\|credential:([^|]*)" ) );
1897 const thread_local QRegularExpression credentialOptionKeyValueRegex( QStringLiteral( "(.*?)=(.*)" ) );
1898
1899 const QRegularExpressionMatch match = credentialOptionRegex.match( credentialString );
1900 if ( match.hasMatch() )
1901 {
1902 const QRegularExpressionMatch keyValueMatch = credentialOptionKeyValueRegex.match( match.captured( 1 ) );
1903 if ( keyValueMatch.hasMatch() )
1904 {
1905 credentialOptions.insert( keyValueMatch.captured( 1 ), keyValueMatch.captured( 2 ) );
1906 }
1907 credentialString = credentialString.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
1908 }
1909 else
1910 {
1911 break;
1912 }
1913 }
1914
1915 QgsGdalCloudProviderConnection::settingsCredentialOptions->setValue( credentialOptions, connectionName );
1916
1917 child = child.nextSiblingElement();
1918 }
1919}
1920
1921void QgsManageConnectionsDialog::loadStacConnections( const QDomDocument &doc, const QStringList &items )
1922{
1923 const QDomElement root = doc.documentElement();
1924 if ( root.tagName() != QLatin1String( "qgsStacConnections" ) )
1925 {
1926 QMessageBox::information( this, tr( "Loading Connections" ), tr( "The file is not a STAC connections exchange file." ) );
1927 return;
1928 }
1929
1930 QString connectionName;
1931 QgsSettings settings;
1932 settings.beginGroup( QStringLiteral( "/qgis/connections-stac" ) );
1933 QStringList keys = settings.childGroups();
1934 settings.endGroup();
1935 QDomElement child = root.firstChildElement();
1936 bool prompt = true;
1937 bool overwrite = true;
1938
1939 while ( !child.isNull() )
1940 {
1941 connectionName = child.attribute( QStringLiteral( "name" ) );
1942 if ( !items.contains( connectionName ) )
1943 {
1944 child = child.nextSiblingElement();
1945 continue;
1946 }
1947
1948 // check for duplicates
1949 if ( keys.contains( connectionName ) && prompt )
1950 {
1951 const int res = QMessageBox::warning( this, tr( "Loading Connections" ), tr( "Connection with name '%1' already exists. Overwrite?" ).arg( connectionName ), QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1952
1953 switch ( res )
1954 {
1955 case QMessageBox::Cancel:
1956 return;
1957 case QMessageBox::No:
1958 child = child.nextSiblingElement();
1959 continue;
1960 case QMessageBox::Yes:
1961 overwrite = true;
1962 break;
1963 case QMessageBox::YesToAll:
1964 prompt = false;
1965 overwrite = true;
1966 break;
1967 case QMessageBox::NoToAll:
1968 prompt = false;
1969 overwrite = false;
1970 break;
1971 }
1972 }
1973
1974 if ( keys.contains( connectionName ) )
1975 {
1976 if ( !overwrite )
1977 {
1978 child = child.nextSiblingElement();
1979 continue;
1980 }
1981 }
1982 else
1983 {
1984 keys << connectionName;
1985 }
1986
1987 QgsStacConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1988 QgsStacConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1989 QgsStacConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1990 QgsStacConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1991
1992 QgsHttpHeaders httpHeader( child );
1993 QgsStacConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1994
1995 child = child.nextSiblingElement();
1996 }
1997}
1998
2000{
2001 listConnections->selectAll();
2002 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
2003}
2004
2006{
2007 listConnections->clearSelection();
2008 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
2009}
DpiMode
DpiMode enum.
Definition qgis.h:3154
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryVariantMap * settingsHeaders
static QgsSettingsTreeNamedListNode * sTreeConnectionArcgis
static const QgsSettingsEntryString * settingsAuthcfg
This class 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 QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const
Returns the list of items.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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