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