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