QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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"
30
31
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 if ( fileName.isEmpty() )
103 {
104 return;
105 }
106
107 // ensure the user never omitted the extension from the file name
108 if ( !fileName.endsWith( QLatin1String( ".xml" ), Qt::CaseInsensitive ) )
109 {
110 fileName += QLatin1String( ".xml" );
111 }
112
113 mFileName = fileName;
114
115 QDomDocument doc;
116 switch ( mConnectionType )
117 {
118 case WMS:
119 doc = saveOWSConnections( items, QStringLiteral( "WMS" ) );
120 break;
121 case WFS:
122 doc = saveWfsConnections( items );
123 break;
124 case PostGIS:
125 doc = savePgConnections( items );
126 break;
127 case MSSQL:
128 doc = saveMssqlConnections( items );
129 break;
130 case WCS:
131 doc = saveOWSConnections( items, QStringLiteral( "WCS" ) );
132 break;
133 case Oracle:
134 doc = saveOracleConnections( items );
135 break;
136 case HANA:
137 doc = saveHanaConnections( items );
138 break;
139 case XyzTiles:
140 doc = saveXyzTilesConnections( items );
141 break;
142 case ArcgisMapServer:
144 doc = saveArcgisConnections( items );
145 break;
146 case VectorTile:
147 doc = saveVectorTileConnections( items );
148 break;
149 }
150
151 QFile file( mFileName );
152 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
153 {
154 QMessageBox::warning( this, tr( "Saving Connections" ),
155 tr( "Cannot write file %1:\n%2." )
156 .arg( mFileName,
157 file.errorString() ) );
158 return;
159 }
160
161 QTextStream out( &file );
162 doc.save( out, 4 );
163 }
164 else // import connections
165 {
166 QFile file( mFileName );
167 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
168 {
169 QMessageBox::warning( this, tr( "Loading Connections" ),
170 tr( "Cannot read file %1:\n%2." )
171 .arg( mFileName,
172 file.errorString() ) );
173 return;
174 }
175
176 QDomDocument doc;
177 QString errorStr;
178 int errorLine;
179 int errorColumn;
180
181 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
182 {
183 QMessageBox::warning( this, tr( "Loading Connections" ),
184 tr( "Parse error at line %1, column %2:\n%3" )
185 .arg( errorLine )
186 .arg( errorColumn )
187 .arg( errorStr ) );
188 return;
189 }
190
191 switch ( mConnectionType )
192 {
193 case WMS:
194 loadOWSConnections( doc, items, QStringLiteral( "WMS" ) );
195 break;
196 case WFS:
197 loadWfsConnections( doc, items );
198 break;
199 case PostGIS:
200 loadPgConnections( doc, items );
201 break;
202 case MSSQL:
203 loadMssqlConnections( doc, items );
204 break;
205 case WCS:
206 loadOWSConnections( doc, items, QStringLiteral( "WCS" ) );
207 break;
208 case Oracle:
209 loadOracleConnections( doc, items );
210 break;
211 case HANA:
212 loadHanaConnections( doc, items );
213 break;
214 case XyzTiles:
215 loadXyzTilesConnections( doc, items );
216 break;
217 case ArcgisMapServer:
218 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISMAPSERVER" ) );
219 break;
221 loadArcgisConnections( doc, items, QStringLiteral( "ARCGISFEATURESERVER" ) );
222 break;
223 case VectorTile:
224 loadVectorTileConnections( doc, items );
225 break;
226 }
227 // clear connections list and close window
228 listConnections->clear();
229 accept();
230 }
231
232 mFileName.clear();
233}
234
235bool QgsManageConnectionsDialog::populateConnections()
236{
237 // Export mode. Populate connections list from settings
238 if ( mDialogMode == Export )
239 {
240 QStringList connections;
241 QgsSettings settings;
242 switch ( mConnectionType )
243 {
244 case WMS:
245 connections = QgsOwsConnection::sTreeOwsConnections->items( {QStringLiteral( "wms" )} );
246 break;
247 case WFS:
248 connections = QgsOwsConnection::sTreeOwsConnections->items( {QStringLiteral( "wfs" )} );
249 break;
250 case WCS:
251 connections = QgsOwsConnection::sTreeOwsConnections->items( {QStringLiteral( "wcs" )} );
252 break;
253 case PostGIS:
254 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
255 break;
256 case MSSQL:
257 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
258 break;
259 case Oracle:
260 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
261 break;
262 case HANA:
263 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
264 break;
265 case XyzTiles:
267 break;
268 case ArcgisMapServer:
271 break;
272 case VectorTile:
273 connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
274 break;
275 }
276 if ( !settings.group().isEmpty() )
277 {
278 QStringList keys = settings.childGroups();
279 QStringList::Iterator it = keys.begin();
280 while ( it != keys.end() )
281 {
282 QListWidgetItem *item = new QListWidgetItem();
283 item->setText( *it );
284 listConnections->addItem( item );
285 ++it;
286 }
287 settings.endGroup();
288 }
289 }
290 // Import mode. Populate connections list from file
291 else
292 {
293 QFile file( mFileName );
294 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
295 {
296 QMessageBox::warning( this, tr( "Loading Connections" ),
297 tr( "Cannot read file %1:\n%2." )
298 .arg( mFileName,
299 file.errorString() ) );
300 return false;
301 }
302
303 QDomDocument doc;
304 QString errorStr;
305 int errorLine;
306 int errorColumn;
307
308 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
309 {
310 QMessageBox::warning( this, tr( "Loading Connections" ),
311 tr( "Parse error at line %1, column %2:\n%3" )
312 .arg( errorLine )
313 .arg( errorColumn )
314 .arg( errorStr ) );
315 return false;
316 }
317
318 const QDomElement root = doc.documentElement();
319 switch ( mConnectionType )
320 {
321 case WMS:
322 if ( root.tagName() != QLatin1String( "qgsWMSConnections" ) )
323 {
324 QMessageBox::information( this, tr( "Loading Connections" ),
325 tr( "The file is not a WMS connections exchange file." ) );
326 return false;
327 }
328 break;
329
330 case WFS:
331 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
332 {
333 QMessageBox::information( this, tr( "Loading Connections" ),
334 tr( "The file is not a WFS connections exchange file." ) );
335 return false;
336 }
337 break;
338
339 case WCS:
340 if ( root.tagName() != QLatin1String( "qgsWCSConnections" ) )
341 {
342 QMessageBox::information( this, tr( "Loading Connections" ),
343 tr( "The file is not a WCS connections exchange file." ) );
344 return false;
345 }
346 break;
347
348 case PostGIS:
349 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
350 {
351 QMessageBox::information( this, tr( "Loading Connections" ),
352 tr( "The file is not a PostGIS connections exchange file." ) );
353 return false;
354 }
355 break;
356
357 case MSSQL:
358 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
359 {
360 QMessageBox::information( this, tr( "Loading Connections" ),
361 tr( "The file is not a MS SQL Server connections exchange file." ) );
362 return false;
363 }
364 break;
365 case Oracle:
366 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
367 {
368 QMessageBox::information( this, tr( "Loading Connections" ),
369 tr( "The file is not an Oracle connections exchange file." ) );
370 return false;
371 }
372 break;
373 case HANA:
374 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
375 {
376 QMessageBox::warning( this, tr( "Loading Connections" ),
377 tr( "The file is not a HANA connections exchange file." ) );
378 return false;
379 }
380 break;
381 case XyzTiles:
382 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
383 {
384 QMessageBox::information( this, tr( "Loading Connections" ),
385 tr( "The file is not a XYZ Tiles connections exchange file." ) );
386 return false;
387 }
388 break;
389 case ArcgisMapServer:
390 if ( root.tagName() != QLatin1String( "qgsARCGISMAPSERVERConnections" ) )
391 {
392 QMessageBox::information( this, tr( "Loading Connections" ),
393 tr( "The file is not a ArcGIS Map Service connections exchange file." ) );
394 return false;
395 }
396 break;
398 if ( root.tagName() != QLatin1String( "qgsARCGISFEATURESERVERConnections" ) )
399 {
400 QMessageBox::information( this, tr( "Loading Connections" ),
401 tr( "The file is not a ArcGIS Feature Service connections exchange file." ) );
402 return false;
403 }
404 break;
405 case VectorTile:
406 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
407 {
408 QMessageBox::information( this, tr( "Loading Connections" ),
409 tr( "The file is not a Vector Tile connections exchange file." ) );
410 return false;
411 }
412 break;
413 }
414
415 QDomElement child = root.firstChildElement();
416 while ( !child.isNull() )
417 {
418 QListWidgetItem *item = new QListWidgetItem();
419 item->setText( child.attribute( QStringLiteral( "name" ) ) );
420 listConnections->addItem( item );
421 child = child.nextSiblingElement();
422 }
423 }
424 return true;
425}
426
427QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &connections, const QString &service )
428{
429 QDomDocument doc( QStringLiteral( "connections" ) );
430 QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" );
431 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
432 doc.appendChild( root );
433
434 for ( int i = 0; i < connections.count(); ++i )
435 {
436 QDomElement el = doc.createElement( service.toLower() );
437 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
438 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( {service.toLower(), connections[i] } ) );
439
440 if ( service == QLatin1String( "WMS" ) )
441 {
442 el.setAttribute( QStringLiteral( "ignoreGetMapURI" ), QgsOwsConnection::settingsIgnoreGetMapURI->value( {service.toLower(), connections[i] } ) );
443 el.setAttribute( QStringLiteral( "ignoreGetFeatureInfoURI" ), QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->value( {service.toLower(), connections[i] } ) );
444 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( {service.toLower(), connections[i] } ) );
445 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( {service.toLower(), connections[i] } ) );
446 el.setAttribute( QStringLiteral( "smoothPixmapTransform" ), QgsOwsConnection::settingsSmoothPixmapTransform->value( {service.toLower(), connections[i] } ) );
447 el.setAttribute( QStringLiteral( "dpiMode" ), static_cast<int>( QgsOwsConnection::settingsDpiMode->value( {service.toLower(), connections[i] } ) ) );
448
449 QgsHttpHeaders httpHeader( QgsOwsConnection::settingsHeaders->value( {service.toLower(), connections[i] } ) );
450 httpHeader.updateDomElement( el );
451 }
452
453 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( {service.toLower(), connections[i] } ) );
454 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( {service.toLower(), connections[i] } ) );
455 root.appendChild( el );
456 }
457
458 return doc;
459}
460
461QDomDocument QgsManageConnectionsDialog::saveWfsConnections( const QStringList &connections )
462{
463 QDomDocument doc( QStringLiteral( "connections" ) );
464 QDomElement root = doc.createElement( QStringLiteral( "qgsWFSConnections" ) );
465 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1" ) );
466 doc.appendChild( root );
467
468 for ( int i = 0; i < connections.count(); ++i )
469 {
470 QDomElement el = doc.createElement( QStringLiteral( "wfs" ) );
471 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
472 el.setAttribute( QStringLiteral( "url" ), QgsOwsConnection::settingsUrl->value( {QStringLiteral( "wfs" ), connections[i] } ) );
473
474 el.setAttribute( QStringLiteral( "version" ), QgsOwsConnection::settingsVersion->value( {QStringLiteral( "wfs" ), connections[i] } ) );
475 el.setAttribute( QStringLiteral( "maxnumfeatures" ), QgsOwsConnection::settingsMaxNumFeatures->value( {QStringLiteral( "wfs" ), connections[i] } ) );
476 el.setAttribute( QStringLiteral( "pagesize" ), QgsOwsConnection::settingsPagesize->value( {QStringLiteral( "wfs" ), connections[i] } ) );
477 el.setAttribute( QStringLiteral( "pagingenabled" ), QgsOwsConnection::settingsPagingEnabled->value( {QStringLiteral( "wfs" ), connections[i] } ) );
478 el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), QgsOwsConnection::settingsIgnoreAxisOrientation->value( {QStringLiteral( "wfs" ), connections[i] } ) );
479 el.setAttribute( QStringLiteral( "invertAxisOrientation" ), QgsOwsConnection::settingsInvertAxisOrientation->value( {QStringLiteral( "wfs" ), connections[i] } ) );
480 el.setAttribute( QStringLiteral( "username" ), QgsOwsConnection::settingsUsername->value( {QStringLiteral( "wfs" ), connections[i] } ) );
481 el.setAttribute( QStringLiteral( "password" ), QgsOwsConnection::settingsPassword->value( {QStringLiteral( "wfs" ), connections[i] } ) );
482 root.appendChild( el );
483 }
484
485 return doc;
486}
487
488QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
489{
490 QDomDocument doc( QStringLiteral( "connections" ) );
491 QDomElement root = doc.createElement( QStringLiteral( "qgsPgConnections" ) );
492 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
493 doc.appendChild( root );
494
495 const QgsSettings settings;
496 QString path;
497 for ( int i = 0; i < connections.count(); ++i )
498 {
499 path = "/PostgreSQL/connections/" + connections[ i ];
500 QDomElement el = doc.createElement( QStringLiteral( "postgis" ) );
501 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
502 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
503 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
504 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
505 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
506 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
507 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
508 el.setAttribute( QStringLiteral( "projectsInDatabase" ), settings.value( path + "/projectsInDatabase", "0" ).toString() );
509 el.setAttribute( QStringLiteral( "dontResolveType" ), settings.value( path + "/dontResolveType", "0" ).toString() );
510 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
511 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
512 el.setAttribute( QStringLiteral( "publicOnly" ), settings.value( path + "/publicOnly", "0" ).toString() );
513
514 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
515
516 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
517 {
518 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
519 }
520
521 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
522
523 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
524 {
525 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
526 }
527
528 root.appendChild( el );
529 }
530
531 return doc;
532}
533
534QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
535{
536 QDomDocument doc( QStringLiteral( "connections" ) );
537 QDomElement root = doc.createElement( QStringLiteral( "qgsMssqlConnections" ) );
538 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
539 doc.appendChild( root );
540
541 const QgsSettings settings;
542 QString path;
543 for ( int i = 0; i < connections.count(); ++i )
544 {
545 path = "/MSSQL/connections/" + connections[ i ];
546 QDomElement el = doc.createElement( QStringLiteral( "mssql" ) );
547 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
548 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
549 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
550 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
551 el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
552 el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
553 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
554
555 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
556
557 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
558 {
559 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
560 }
561
562 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
563
564 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
565 {
566 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
567 }
568
569 root.appendChild( el );
570 }
571
572 return doc;
573}
574
575QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections )
576{
577 QDomDocument doc( QStringLiteral( "connections" ) );
578 QDomElement root = doc.createElement( QStringLiteral( "qgsOracleConnections" ) );
579 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
580 doc.appendChild( root );
581
582 const QgsSettings settings;
583 QString path;
584 for ( int i = 0; i < connections.count(); ++i )
585 {
586 path = "/Oracle/connections/" + connections[ i ];
587 QDomElement el = doc.createElement( QStringLiteral( "oracle" ) );
588 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
589 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
590 el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
591 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
592 el.setAttribute( QStringLiteral( "dboptions" ), settings.value( path + "/dboptions" ).toString() );
593 el.setAttribute( QStringLiteral( "dbworkspace" ), settings.value( path + "/dbworkspace" ).toString() );
594 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
595 el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
596 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", "0" ).toString() );
597 el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
598 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
599
600 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
601
602 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
603 {
604 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
605 }
606
607 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
608
609 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
610 {
611 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
612 }
613
614 root.appendChild( el );
615 }
616
617 return doc;
618}
619
620QDomDocument QgsManageConnectionsDialog::saveHanaConnections( const QStringList &connections )
621{
622 QDomDocument doc( QStringLiteral( "connections" ) );
623 QDomElement root = doc.createElement( QStringLiteral( "qgsHanaConnections" ) );
624 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
625 doc.appendChild( root );
626
627 const QgsSettings settings;
628 QString path;
629 for ( int i = 0; i < connections.count(); ++i )
630 {
631 path = "/HANA/connections/" + connections[i];
632 QDomElement el = doc.createElement( QStringLiteral( "hana" ) );
633 el.setAttribute( QStringLiteral( "name" ), connections[i] );
634 el.setAttribute( QStringLiteral( "driver" ), settings.value( path + "/driver", QString() ).toString() );
635 el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host", QString() ).toString() );
636 el.setAttribute( QStringLiteral( "identifierType" ), settings.value( path + "/identifierType", QString() ).toString() );
637 el.setAttribute( QStringLiteral( "identifier" ), settings.value( path + "/identifier", QString() ).toString() );
638 el.setAttribute( QStringLiteral( "multitenant" ), settings.value( path + "/multitenant", QString() ).toString() );
639 el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database", QString() ).toString() );
640 el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema", QString() ).toString() );
641 el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", QStringLiteral( "0" ) ).toString() );
642 el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", QStringLiteral( "0" ) ).toString() );
643
644 el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", QStringLiteral( "false" ) ).toString() );
645 if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
646 {
647 el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", QString() ).toString() );
648 }
649
650 el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", QStringLiteral( "false" ) ).toString() );
651 if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
652 {
653 el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", QString() ).toString() );
654 }
655
656 el.setAttribute( QStringLiteral( "sslEnabled" ), settings.value( path + "/sslEnabled", QStringLiteral( "false" ) ).toString() );
657 el.setAttribute( QStringLiteral( "sslCryptoProvider" ), settings.value( path + "/sslCryptoProvider", QStringLiteral( "openssl" ) ).toString() );
658 el.setAttribute( QStringLiteral( "sslKeyStore" ), settings.value( path + "/sslKeyStore", QString() ).toString() );
659 el.setAttribute( QStringLiteral( "sslTrustStore" ), settings.value( path + "/sslTrustStore", QString() ).toString() );
660 el.setAttribute( QStringLiteral( "sslValidateCertificate" ), settings.value( path + "/sslValidateCertificate", QStringLiteral( "false" ) ).toString() );
661 el.setAttribute( QStringLiteral( "sslHostNameInCertificate" ), settings.value( path + "/sslHostNameInCertificate", QString() ).toString() );
662
663 root.appendChild( el );
664 }
665
666 return doc;
667}
668
669QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
670{
671 QDomDocument doc( QStringLiteral( "connections" ) );
672 QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
673 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
674 doc.appendChild( root );
675
676 for ( int i = 0; i < connections.count(); ++i )
677 {
678
679 QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
680
681 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
682 el.setAttribute( QStringLiteral( "url" ), QgsXyzConnectionSettings::settingsUrl->value( connections[ i ] ) );
683 el.setAttribute( QStringLiteral( "zmin" ), QgsXyzConnectionSettings::settingsZmin->value( connections[ i ] ) );
684 el.setAttribute( QStringLiteral( "zmax" ), QgsXyzConnectionSettings::settingsZmax->value( connections[ i ] ) );
685 el.setAttribute( QStringLiteral( "authcfg" ), QgsXyzConnectionSettings::settingsAuthcfg->value( connections[ i ] ) );
686 el.setAttribute( QStringLiteral( "username" ), QgsXyzConnectionSettings::settingsUsername->value( connections[ i ] ) );
687 el.setAttribute( QStringLiteral( "password" ), QgsXyzConnectionSettings::settingsPassword->value( connections[ i ] ) );
688 el.setAttribute( QStringLiteral( "tilePixelRatio" ), QgsXyzConnectionSettings::settingsTilePixelRatio->value( connections[ i ] ) );
689
690 QgsHttpHeaders httpHeader( QgsXyzConnectionSettings::settingsHeaders->value( connections[ i ] ) );
691 httpHeader.updateDomElement( el );
692
693 root.appendChild( el );
694 }
695
696 return doc;
697}
698
699QDomDocument QgsManageConnectionsDialog::saveArcgisConnections( const QStringList &connections )
700{
701 QDomDocument doc( QStringLiteral( "connections" ) );
702 QDomElement root = doc.createElement( "qgsARCGISFEATURESERVERConnections" );
703 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
704 doc.appendChild( root );
705
706 for ( const QString &connection : connections )
707 {
708 QDomElement el = doc.createElement( QStringLiteral( "arcgisfeatureserver" ) );
709 el.setAttribute( QStringLiteral( "name" ), connection );
710 el.setAttribute( QStringLiteral( "url" ), QgsArcGisConnectionSettings::settingsUrl->value( connection ) );
711
712 QgsHttpHeaders httpHeader( QgsArcGisConnectionSettings::settingsHeaders->value( connection ) );
713 httpHeader.updateDomElement( el );
714
715 el.setAttribute( QStringLiteral( "username" ), QgsArcGisConnectionSettings::settingsUsername->value( connection ) );
716 el.setAttribute( QStringLiteral( "password" ), QgsArcGisConnectionSettings::settingsPassword->value( connection ) );
717 el.setAttribute( QStringLiteral( "authcfg" ), QgsArcGisConnectionSettings::settingsAuthcfg->value( connection ) );
718
719 root.appendChild( el );
720 }
721
722 return doc;
723}
724
725QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections( const QStringList &connections )
726{
727 QDomDocument doc( QStringLiteral( "connections" ) );
728 QDomElement root = doc.createElement( QStringLiteral( "qgsVectorTileConnections" ) );
729 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
730 doc.appendChild( root );
731
732 for ( int i = 0; i < connections.count(); ++i )
733 {
734 QDomElement el = doc.createElement( QStringLiteral( "vectortile" ) );
735
736 el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
737 el.setAttribute( QStringLiteral( "url" ), QgsVectorTileProviderConnection::settingsUrl->value( connections[ i ] ) );
738 el.setAttribute( QStringLiteral( "zmin" ), QgsVectorTileProviderConnection::settingsZmin->value( connections[ i ] ) );
739 el.setAttribute( QStringLiteral( "zmax" ), QgsVectorTileProviderConnection::settingsZmax->value( connections[ i ] ) );
740 el.setAttribute( QStringLiteral( "serviceType" ), QgsVectorTileProviderConnection::settingsServiceType->value( connections[ i ] ) );
741 el.setAttribute( QStringLiteral( "authcfg" ), QgsVectorTileProviderConnection::settingsAuthcfg->value( connections[ i ] ) );
742 el.setAttribute( QStringLiteral( "username" ), QgsVectorTileProviderConnection::settingsUsername->value( connections[ i ] ) );
743 el.setAttribute( QStringLiteral( "password" ), QgsVectorTileProviderConnection::settingsPassword->value( connections[ i ] ) );
744 el.setAttribute( QStringLiteral( "styleUrl" ), QgsVectorTileProviderConnection::settingsStyleUrl->value( connections[ i ] ) );
745
746 QgsHttpHeaders httpHeader( QgsVectorTileProviderConnection::settingsHeaders->value( connections[ i ] ) );
747 httpHeader.updateDomElement( el );
748
749 root.appendChild( el );
750 }
751
752 return doc;
753}
754
755void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
756{
757 const QDomElement root = doc.documentElement();
758 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
759 {
760 QMessageBox::information( this, tr( "Loading Connections" ),
761 tr( "The file is not a %1 connections exchange file." ).arg( service ) );
762 return;
763 }
764
765 QString connectionName;
766
767 QDomElement child = root.firstChildElement();
768 bool prompt = true;
769 bool overwrite = true;
770
771 while ( !child.isNull() )
772 {
773 connectionName = child.attribute( QStringLiteral( "name" ) );
774 if ( !items.contains( connectionName ) )
775 {
776 child = child.nextSiblingElement();
777 continue;
778 }
779
780 // check for duplicates
781 if ( QgsOwsConnection::settingsUrl->exists( {service.toLower(), connectionName} ) && prompt )
782 {
783 const int res = QMessageBox::warning( this,
784 tr( "Loading Connections" ),
785 tr( "Connection with name '%1' already exists. Overwrite?" )
786 .arg( connectionName ),
787 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
788
789 switch ( res )
790 {
791 case QMessageBox::Cancel:
792 return;
793 case QMessageBox::No:
794 child = child.nextSiblingElement();
795 continue;
796 case QMessageBox::Yes:
797 overwrite = true;
798 break;
799 case QMessageBox::YesToAll:
800 prompt = false;
801 overwrite = true;
802 break;
803 case QMessageBox::NoToAll:
804 prompt = false;
805 overwrite = false;
806 break;
807 }
808 }
809
810 if ( QgsOwsConnection::settingsUrl->exists( {service.toLower(), connectionName} ) && !overwrite )
811 {
812 child = child.nextSiblingElement();
813 continue;
814 }
815
816 // no dups detected or overwrite is allowed
817 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), {service.toLower(), connectionName} );
818 QgsOwsConnection::settingsIgnoreGetMapURI->setValue( child.attribute( QStringLiteral( "ignoreGetMapURI" ) ) == QLatin1String( "true" ), {service.toLower(), connectionName} );
819 QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( child.attribute( QStringLiteral( "ignoreGetFeatureInfoURI" ) ) == QLatin1String( "true" ), {service.toLower(), connectionName} );
820 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) == QLatin1String( "true" ), {service.toLower(), connectionName} );
821 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ) == QLatin1String( "true" ), {service.toLower(), connectionName} );
822 QgsOwsConnection::settingsSmoothPixmapTransform->setValue( child.attribute( QStringLiteral( "smoothPixmapTransform" ) ) == QLatin1String( "true" ), {service.toLower(), connectionName} );
823 QgsOwsConnection::settingsDpiMode->setValue( static_cast<Qgis::DpiMode>( child.attribute( QStringLiteral( "dpiMode" ), QStringLiteral( "7" ) ).toInt() ), {service.toLower(), connectionName} );
824
825 QgsHttpHeaders httpHeader( child );
826 QgsOwsConnection::settingsHeaders->setValue( httpHeader.headers(), {service.toLower(), connectionName} );
827
828 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
829 {
830 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), {service.toUpper(), connectionName} );
831 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), {service.toUpper(), connectionName} );
832 }
833 child = child.nextSiblingElement();
834 }
835}
836
837void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
838{
839 const QDomElement root = doc.documentElement();
840 if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
841 {
842 QMessageBox::information( this, tr( "Loading Connections" ),
843 tr( "The file is not a WFS connections exchange file." ) );
844 return;
845 }
846
847 QString connectionName;
848 QStringList keys = QgsOwsConnection::sTreeOwsConnections->items( {QStringLiteral( "geonode" ) } );
849
850 QDomElement child = root.firstChildElement();
851 bool prompt = true;
852 bool overwrite = true;
853
854 while ( !child.isNull() )
855 {
856 connectionName = child.attribute( QStringLiteral( "name" ) );
857 if ( !items.contains( connectionName ) )
858 {
859 child = child.nextSiblingElement();
860 continue;
861 }
862
863 // check for duplicates
864 if ( keys.contains( connectionName ) && prompt )
865 {
866 const int res = QMessageBox::warning( this,
867 tr( "Loading Connections" ),
868 tr( "Connection with name '%1' already exists. Overwrite?" )
869 .arg( connectionName ),
870 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
871
872 switch ( res )
873 {
874 case QMessageBox::Cancel:
875 return;
876 case QMessageBox::No:
877 child = child.nextSiblingElement();
878 continue;
879 case QMessageBox::Yes:
880 overwrite = true;
881 break;
882 case QMessageBox::YesToAll:
883 prompt = false;
884 overwrite = true;
885 break;
886 case QMessageBox::NoToAll:
887 prompt = false;
888 overwrite = false;
889 break;
890 }
891 }
892
893 if ( keys.contains( connectionName ) )
894 {
895 if ( !overwrite )
896 {
897 child = child.nextSiblingElement();
898 continue;
899 }
900 }
901 else
902 {
903 keys << connectionName;
904 }
905
906 // no dups detected or overwrite is allowed
907
908 QgsOwsConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), {QStringLiteral( "wfs" ), connectionName} );
909 QgsOwsConnection::settingsVersion->setValue( child.attribute( QStringLiteral( "version" ) ), {QStringLiteral( "wfs" ), connectionName} );
910 QgsOwsConnection::settingsMaxNumFeatures->setValue( child.attribute( QStringLiteral( "maxnumfeatures" ) ), {QStringLiteral( "wfs" ), connectionName} );
911 QgsOwsConnection::settingsPagesize->setValue( child.attribute( QStringLiteral( "pagesize" ) ), {QStringLiteral( "wfs" ), connectionName} );
912 QgsOwsConnection::settingsPagingEnabled->setValue( child.attribute( QStringLiteral( "pagingenabled" ) ).toInt(), {QStringLiteral( "wfs" ), connectionName} );
913 QgsOwsConnection::settingsIgnoreAxisOrientation->setValue( child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ).toInt(), {QStringLiteral( "wfs" ), connectionName} );
914 QgsOwsConnection::settingsInvertAxisOrientation->setValue( child.attribute( QStringLiteral( "invertAxisOrientation" ) ).toInt(), {QStringLiteral( "wfs" ), connectionName} );
915
916 if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
917 {
918 QgsOwsConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), {QStringLiteral( "wfs" ), connectionName} );
919 QgsOwsConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), {QStringLiteral( "wfs" ), connectionName} );
920 }
921 child = child.nextSiblingElement();
922 }
923}
924
925void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
926{
927 const QDomElement root = doc.documentElement();
928 if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
929 {
930 QMessageBox::information( this,
931 tr( "Loading Connections" ),
932 tr( "The file is not a PostGIS connections exchange file." ) );
933 return;
934 }
935
936 QString connectionName;
937 QgsSettings settings;
938 settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
939 QStringList keys = settings.childGroups();
940 settings.endGroup();
941 QDomElement child = root.firstChildElement();
942 bool prompt = true;
943 bool overwrite = true;
944
945 while ( !child.isNull() )
946 {
947 connectionName = child.attribute( QStringLiteral( "name" ) );
948 if ( !items.contains( connectionName ) )
949 {
950 child = child.nextSiblingElement();
951 continue;
952 }
953
954 // check for duplicates
955 if ( keys.contains( connectionName ) && prompt )
956 {
957 const int res = QMessageBox::warning( this,
958 tr( "Loading Connections" ),
959 tr( "Connection with name '%1' already exists. Overwrite?" )
960 .arg( connectionName ),
961 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
962 switch ( res )
963 {
964 case QMessageBox::Cancel:
965 return;
966 case QMessageBox::No:
967 child = child.nextSiblingElement();
968 continue;
969 case QMessageBox::Yes:
970 overwrite = true;
971 break;
972 case QMessageBox::YesToAll:
973 prompt = false;
974 overwrite = true;
975 break;
976 case QMessageBox::NoToAll:
977 prompt = false;
978 overwrite = false;
979 break;
980 }
981 }
982
983 if ( keys.contains( connectionName ) )
984 {
985 if ( !overwrite )
986 {
987 child = child.nextSiblingElement();
988 continue;
989 }
990 }
991 else
992 {
993 keys << connectionName;
994 }
995
996 //no dups detected or overwrite is allowed
997 settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
998
999 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1000 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1001 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1002 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1003 {
1004 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1005 }
1006 else
1007 {
1008 settings.setValue( QStringLiteral( "/service" ), "" );
1009 }
1010 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1011 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1012 settings.setValue( QStringLiteral( "/projectsInDatabase" ), child.attribute( QStringLiteral( "projectsInDatabase" ), 0 ) );
1013 settings.setValue( QStringLiteral( "/dontResolveType" ), child.attribute( QStringLiteral( "dontResolveType" ), 0 ) );
1014 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ), 0 ) );
1015 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ), 0 ) );
1016 settings.setValue( QStringLiteral( "/publicOnly" ), child.attribute( QStringLiteral( "publicOnly" ), 0 ) );
1017 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1018 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1019 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1020 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1021 settings.endGroup();
1022
1023 child = child.nextSiblingElement();
1024 }
1025}
1026
1027void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1028{
1029 const QDomElement root = doc.documentElement();
1030 if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
1031 {
1032 QMessageBox::information( this,
1033 tr( "Loading Connections" ),
1034 tr( "The file is not a MS SQL Server connections exchange file." ) );
1035 return;
1036 }
1037
1038 QString connectionName;
1039 QgsSettings settings;
1040 settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
1041 QStringList keys = settings.childGroups();
1042 settings.endGroup();
1043 QDomElement child = root.firstChildElement();
1044 bool prompt = true;
1045 bool overwrite = true;
1046
1047 while ( !child.isNull() )
1048 {
1049 connectionName = child.attribute( QStringLiteral( "name" ) );
1050 if ( !items.contains( connectionName ) )
1051 {
1052 child = child.nextSiblingElement();
1053 continue;
1054 }
1055
1056 // check for duplicates
1057 if ( keys.contains( connectionName ) && prompt )
1058 {
1059 const int res = QMessageBox::warning( this,
1060 tr( "Loading Connections" ),
1061 tr( "Connection with name '%1' already exists. Overwrite?" )
1062 .arg( connectionName ),
1063 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1064 switch ( res )
1065 {
1066 case QMessageBox::Cancel:
1067 return;
1068 case QMessageBox::No:
1069 child = child.nextSiblingElement();
1070 continue;
1071 case QMessageBox::Yes:
1072 overwrite = true;
1073 break;
1074 case QMessageBox::YesToAll:
1075 prompt = false;
1076 overwrite = true;
1077 break;
1078 case QMessageBox::NoToAll:
1079 prompt = false;
1080 overwrite = false;
1081 break;
1082 }
1083 }
1084
1085 if ( keys.contains( connectionName ) )
1086 {
1087 if ( !overwrite )
1088 {
1089 child = child.nextSiblingElement();
1090 continue;
1091 }
1092 }
1093 else
1094 {
1095 keys << connectionName;
1096 }
1097
1098 //no dups detected or overwrite is allowed
1099 settings.beginGroup( "/MSSQL/connections/" + connectionName );
1100
1101 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1102 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1103 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1104 if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1105 {
1106 settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1107 }
1108 else
1109 {
1110 settings.setValue( QStringLiteral( "/service" ), "" );
1111 }
1112 settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1113 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1114 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1115 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1116 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1117 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1118 settings.endGroup();
1119
1120 child = child.nextSiblingElement();
1121 }
1122}
1123
1124void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1125{
1126 const QDomElement root = doc.documentElement();
1127 if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
1128 {
1129 QMessageBox::information( this,
1130 tr( "Loading Connections" ),
1131 tr( "The file is not an Oracle connections exchange file." ) );
1132 return;
1133 }
1134
1135 QString connectionName;
1136 QgsSettings settings;
1137 settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
1138 QStringList keys = settings.childGroups();
1139 settings.endGroup();
1140 QDomElement child = root.firstChildElement();
1141 bool prompt = true;
1142 bool overwrite = true;
1143
1144 while ( !child.isNull() )
1145 {
1146 connectionName = child.attribute( QStringLiteral( "name" ) );
1147 if ( !items.contains( connectionName ) )
1148 {
1149 child = child.nextSiblingElement();
1150 continue;
1151 }
1152
1153 // check for duplicates
1154 if ( keys.contains( connectionName ) && prompt )
1155 {
1156 const int res = QMessageBox::warning( this,
1157 tr( "Loading Connections" ),
1158 tr( "Connection with name '%1' already exists. Overwrite?" )
1159 .arg( connectionName ),
1160 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1161 switch ( res )
1162 {
1163 case QMessageBox::Cancel:
1164 return;
1165 case QMessageBox::No:
1166 child = child.nextSiblingElement();
1167 continue;
1168 case QMessageBox::Yes:
1169 overwrite = true;
1170 break;
1171 case QMessageBox::YesToAll:
1172 prompt = false;
1173 overwrite = true;
1174 break;
1175 case QMessageBox::NoToAll:
1176 prompt = false;
1177 overwrite = false;
1178 break;
1179 }
1180 }
1181
1182 if ( keys.contains( connectionName ) )
1183 {
1184 if ( !overwrite )
1185 {
1186 child = child.nextSiblingElement();
1187 continue;
1188 }
1189 }
1190 else
1191 {
1192 keys << connectionName;
1193 }
1194
1195 //no dups detected or overwrite is allowed
1196 settings.beginGroup( "/Oracle/connections/" + connectionName );
1197
1198 settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1199 settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1200 settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1201 settings.setValue( QStringLiteral( "/dboptions" ), child.attribute( QStringLiteral( "dboptions" ) ) );
1202 settings.setValue( QStringLiteral( "/dbworkspace" ), child.attribute( QStringLiteral( "dbworkspace" ) ) );
1203 settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1204 settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1205 settings.setValue( QStringLiteral( "/userTablesOnly" ), child.attribute( QStringLiteral( "userTablesOnly" ) ) );
1206 settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ) ) );
1207 settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ) ) );
1208 settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1209 settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1210 settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1211 settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1212 settings.endGroup();
1213
1214 child = child.nextSiblingElement();
1215 }
1216}
1217
1218void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1219{
1220 QDomElement root = doc.documentElement();
1221 if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
1222 {
1223 QMessageBox::warning( this,
1224 tr( "Loading Connections" ),
1225 tr( "The file is not a HANA connections exchange file." ) );
1226 return;
1227 }
1228
1229 const QDomAttr version = root.attributeNode( "version" );
1230 if ( version.value() != QLatin1String( "1.0" ) )
1231 {
1232 QMessageBox::warning( this,
1233 tr( "Loading Connections" ),
1234 tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1235 return;
1236 }
1237
1238 QgsSettings settings;
1239 settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
1240 QStringList keys = settings.childGroups();
1241 settings.endGroup();
1242 QDomElement child = root.firstChildElement();
1243 bool prompt = true;
1244 bool overwrite = true;
1245
1246 while ( !child.isNull() )
1247 {
1248 const QString connectionName = child.attribute( QStringLiteral( "name" ) );
1249 if ( !items.contains( connectionName ) )
1250 {
1251 child = child.nextSiblingElement();
1252 continue;
1253 }
1254
1255 // check for duplicates
1256 if ( keys.contains( connectionName ) && prompt )
1257 {
1258 const int res = QMessageBox::warning( this,
1259 tr( "Loading Connections" ),
1260 tr( "Connection with name '%1' already exists. Overwrite?" )
1261 .arg( connectionName ),
1262 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1263 switch ( res )
1264 {
1265 case QMessageBox::Cancel:
1266 return;
1267 case QMessageBox::No:
1268 child = child.nextSiblingElement();
1269 continue;
1270 case QMessageBox::Yes:
1271 overwrite = true;
1272 break;
1273 case QMessageBox::YesToAll:
1274 prompt = false;
1275 overwrite = true;
1276 break;
1277 case QMessageBox::NoToAll:
1278 prompt = false;
1279 overwrite = false;
1280 break;
1281 }
1282 }
1283
1284 if ( keys.contains( connectionName ) )
1285 {
1286 if ( !overwrite )
1287 {
1288 child = child.nextSiblingElement();
1289 continue;
1290 }
1291 }
1292 else
1293 {
1294 keys << connectionName;
1295 }
1296
1297 //no dups detected or overwrite is allowed
1298 settings.beginGroup( "/HANA/connections/" + connectionName );
1299
1300 for ( const QString param :
1301 {"driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1302 "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1303 "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1304 } )
1305 settings.setValue( QStringLiteral( "/" ) + param, child.attribute( param ) );
1306
1307 settings.endGroup();
1308
1309 child = child.nextSiblingElement();
1310 }
1311}
1312
1313void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1314{
1315 const QDomElement root = doc.documentElement();
1316 if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
1317 {
1318 QMessageBox::information( this, tr( "Loading Connections" ),
1319 tr( "The file is not a XYZ Tiles connections exchange file." ) );
1320 return;
1321 }
1322
1323 QString connectionName;
1325 QDomElement child = root.firstChildElement();
1326 bool prompt = true;
1327 bool overwrite = true;
1328
1329 while ( !child.isNull() )
1330 {
1331 connectionName = child.attribute( QStringLiteral( "name" ) );
1332 if ( !items.contains( connectionName ) )
1333 {
1334 child = child.nextSiblingElement();
1335 continue;
1336 }
1337
1338 // check for duplicates
1339 if ( keys.contains( connectionName ) && prompt )
1340 {
1341 const int res = QMessageBox::warning( this,
1342 tr( "Loading Connections" ),
1343 tr( "Connection with name '%1' already exists. Overwrite?" )
1344 .arg( connectionName ),
1345 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1346
1347 switch ( res )
1348 {
1349 case QMessageBox::Cancel:
1350 return;
1351 case QMessageBox::No:
1352 child = child.nextSiblingElement();
1353 continue;
1354 case QMessageBox::Yes:
1355 overwrite = true;
1356 break;
1357 case QMessageBox::YesToAll:
1358 prompt = false;
1359 overwrite = true;
1360 break;
1361 case QMessageBox::NoToAll:
1362 prompt = false;
1363 overwrite = false;
1364 break;
1365 }
1366 }
1367
1368 if ( keys.contains( connectionName ) )
1369 {
1370 if ( !overwrite )
1371 {
1372 child = child.nextSiblingElement();
1373 continue;
1374 }
1375 }
1376 else
1377 {
1378 keys << connectionName;
1379 }
1380
1381
1382 QgsXyzConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1383 QgsXyzConnectionSettings::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1384 QgsXyzConnectionSettings::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1385 QgsXyzConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1386 QgsXyzConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1387 QgsXyzConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1388 QgsXyzConnectionSettings::settingsTilePixelRatio->setValue( child.attribute( QStringLiteral( "tilePixelRatio" ) ).toInt(), connectionName );
1389
1390 QgsHttpHeaders httpHeader( child );
1391 QgsXyzConnectionSettings::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1392
1393 child = child.nextSiblingElement();
1394 }
1395}
1396
1397void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1398{
1399 const QDomElement root = doc.documentElement();
1400 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1401 {
1402 QMessageBox::information( this, tr( "Loading Connections" ),
1403 tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1404 return;
1405 }
1406
1407 QString connectionName;
1409 QDomElement child = root.firstChildElement();
1410 bool prompt = true;
1411 bool overwrite = true;
1412
1413 while ( !child.isNull() )
1414 {
1415 connectionName = child.attribute( QStringLiteral( "name" ) );
1416 if ( !items.contains( connectionName ) )
1417 {
1418 child = child.nextSiblingElement();
1419 continue;
1420 }
1421
1422 // check for duplicates
1423 if ( keys.contains( connectionName ) && prompt )
1424 {
1425 const int res = QMessageBox::warning( this,
1426 tr( "Loading Connections" ),
1427 tr( "Connection with name '%1' already exists. Overwrite?" )
1428 .arg( connectionName ),
1429 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1430
1431 switch ( res )
1432 {
1433 case QMessageBox::Cancel:
1434 return;
1435 case QMessageBox::No:
1436 child = child.nextSiblingElement();
1437 continue;
1438 case QMessageBox::Yes:
1439 overwrite = true;
1440 break;
1441 case QMessageBox::YesToAll:
1442 prompt = false;
1443 overwrite = true;
1444 break;
1445 case QMessageBox::NoToAll:
1446 prompt = false;
1447 overwrite = false;
1448 break;
1449 }
1450 }
1451
1452 if ( keys.contains( connectionName ) )
1453 {
1454 if ( !overwrite )
1455 {
1456 child = child.nextSiblingElement();
1457 continue;
1458 }
1459 }
1460 else
1461 {
1462 keys << connectionName;
1463 }
1464
1465 // no dups detected or overwrite is allowed
1466 QgsArcGisConnectionSettings::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1467
1468 QgsArcGisConnectionSettings::settingsHeaders->setValue( QgsHttpHeaders( child ).headers(), connectionName );
1469
1470
1471 QgsArcGisConnectionSettings::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1472 QgsArcGisConnectionSettings::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1473 QgsArcGisConnectionSettings::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1474
1475 child = child.nextSiblingElement();
1476 }
1477}
1478
1479void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1480{
1481 const QDomElement root = doc.documentElement();
1482 if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
1483 {
1484 QMessageBox::information( this, tr( "Loading Connections" ),
1485 tr( "The file is not a Vector Tile connections exchange file." ) );
1486 return;
1487 }
1488
1489 QString connectionName;
1490 QgsSettings settings;
1491 settings.beginGroup( QStringLiteral( "/qgis/connections-vector-tile" ) );
1492 QStringList keys = settings.childGroups();
1493 settings.endGroup();
1494 QDomElement child = root.firstChildElement();
1495 bool prompt = true;
1496 bool overwrite = true;
1497
1498 while ( !child.isNull() )
1499 {
1500 connectionName = child.attribute( QStringLiteral( "name" ) );
1501 if ( !items.contains( connectionName ) )
1502 {
1503 child = child.nextSiblingElement();
1504 continue;
1505 }
1506
1507 // check for duplicates
1508 if ( keys.contains( connectionName ) && prompt )
1509 {
1510 const int res = QMessageBox::warning( this,
1511 tr( "Loading Connections" ),
1512 tr( "Connection with name '%1' already exists. Overwrite?" )
1513 .arg( connectionName ),
1514 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1515
1516 switch ( res )
1517 {
1518 case QMessageBox::Cancel:
1519 return;
1520 case QMessageBox::No:
1521 child = child.nextSiblingElement();
1522 continue;
1523 case QMessageBox::Yes:
1524 overwrite = true;
1525 break;
1526 case QMessageBox::YesToAll:
1527 prompt = false;
1528 overwrite = true;
1529 break;
1530 case QMessageBox::NoToAll:
1531 prompt = false;
1532 overwrite = false;
1533 break;
1534 }
1535 }
1536
1537 if ( keys.contains( connectionName ) )
1538 {
1539 if ( !overwrite )
1540 {
1541 child = child.nextSiblingElement();
1542 continue;
1543 }
1544 }
1545 else
1546 {
1547 keys << connectionName;
1548 }
1549
1550 QgsVectorTileProviderConnection::settingsUrl->setValue( child.attribute( QStringLiteral( "url" ) ), connectionName );
1551 QgsVectorTileProviderConnection::settingsZmin->setValue( child.attribute( QStringLiteral( "zmin" ) ).toInt(), connectionName );
1552 QgsVectorTileProviderConnection::settingsZmax->setValue( child.attribute( QStringLiteral( "zmax" ) ).toInt(), connectionName );
1553 QgsVectorTileProviderConnection::settingsServiceType->setValue( child.attribute( QStringLiteral( "serviceType" ) ), connectionName );
1554 QgsVectorTileProviderConnection::settingsAuthcfg->setValue( child.attribute( QStringLiteral( "authcfg" ) ), connectionName );
1555 QgsVectorTileProviderConnection::settingsUsername->setValue( child.attribute( QStringLiteral( "username" ) ), connectionName );
1556 QgsVectorTileProviderConnection::settingsPassword->setValue( child.attribute( QStringLiteral( "password" ) ), connectionName );
1557 QgsVectorTileProviderConnection::settingsStyleUrl->setValue( child.attribute( QStringLiteral( "styleUrl" ) ), connectionName );
1558
1559 QgsHttpHeaders httpHeader( child );
1560 QgsVectorTileProviderConnection::settingsHeaders->setValue( httpHeader.headers(), connectionName );
1561
1562 child = child.nextSiblingElement();
1563 }
1564}
1565
1567{
1568 listConnections->selectAll();
1569 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1570}
1571
1573{
1574 listConnections->clearSelection();
1575 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
1576}
DpiMode
DpiMode enum.
Definition: qgis.h:2119
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.
static const QgsSettingsEntryBool * 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
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(T value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
QStringList items(const QStringList &parentsNamedItems=QStringList()) const SIP_THROW(QgsSettingsException)
Returns the list of items.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:63
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.
Definition: qgssettings.cpp:99
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QString group() const
Returns the current group.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:89
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