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