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