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