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