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