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