QGIS API Documentation  3.25.0-Master (10b47c2603)
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 
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( "referer" ), settings.value( path + connections[ i ] + "/referer" ).toString() );
461  el.setAttribute( QStringLiteral( "smoothPixmapTransform" ), settings.value( path + connections[i] + "/smoothPixmapTransform", false ).toBool() ? "true" : "false" );
462  el.setAttribute( QStringLiteral( "dpiMode" ), settings.value( path + connections[i] + "/dpiMode", "7" ).toInt() );
463  }
464 
465  path = "/qgis/" + service.toUpper() + '/';
466  el.setAttribute( QStringLiteral( "username" ), settings.value( path + connections[ i ] + "/username" ).toString() );
467  el.setAttribute( QStringLiteral( "password" ), settings.value( path + connections[ i ] + "/password" ).toString() );
468  root.appendChild( el );
469  }
470 
471  return doc;
472 }
473 
474 QDomDocument QgsManageConnectionsDialog::saveWfsConnections( const QStringList &connections )
475 {
476  QDomDocument doc( QStringLiteral( "connections" ) );
477  QDomElement root = doc.createElement( QStringLiteral( "qgsWFSConnections" ) );
478  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1" ) );
479  doc.appendChild( root );
480 
481  const QgsSettings settings;
482  QString path;
483  for ( int i = 0; i < connections.count(); ++i )
484  {
485  path = QStringLiteral( "/qgis/connections-wfs/" );
486  QDomElement el = doc.createElement( QStringLiteral( "wfs" ) );
487  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
488  el.setAttribute( QStringLiteral( "url" ), settings.value( path + connections[ i ] + "/url" ).toString() );
489 
490  el.setAttribute( QStringLiteral( "version" ), settings.value( path + connections[ i ] + "/version" ).toString() );
491  el.setAttribute( QStringLiteral( "maxnumfeatures" ), settings.value( path + connections[ i ] + "/maxnumfeatures" ).toString() );
492  el.setAttribute( QStringLiteral( "pagesize" ), settings.value( path + connections[ i ] + "/pagesize" ).toString() );
493  el.setAttribute( QStringLiteral( "pagingenabled" ), settings.value( path + connections[ i ] + "/pagingenabled", false ).toString() );
494  el.setAttribute( QStringLiteral( "ignoreAxisOrientation" ), settings.value( path + connections[ i ] + "/ignoreAxisOrientation", false ).toString() );
495  el.setAttribute( QStringLiteral( "invertAxisOrientation" ), settings.value( path + connections[ i ] + "/invertAxisOrientation", false ).toString() );
496 
497  path = QStringLiteral( "/qgis/WFS/" );
498  el.setAttribute( QStringLiteral( "username" ), settings.value( path + connections[ i ] + "/username" ).toString() );
499  el.setAttribute( QStringLiteral( "password" ), settings.value( path + connections[ i ] + "/password" ).toString() );
500  root.appendChild( el );
501  }
502 
503  return doc;
504 }
505 
506 QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections )
507 {
508  QDomDocument doc( QStringLiteral( "connections" ) );
509  QDomElement root = doc.createElement( QStringLiteral( "qgsPgConnections" ) );
510  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
511  doc.appendChild( root );
512 
513  const QgsSettings settings;
514  QString path;
515  for ( int i = 0; i < connections.count(); ++i )
516  {
517  path = "/PostgreSQL/connections/" + connections[ i ];
518  QDomElement el = doc.createElement( QStringLiteral( "postgis" ) );
519  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
520  el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
521  el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
522  el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
523  el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
524  el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
525  el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
526  el.setAttribute( QStringLiteral( "projectsInDatabase" ), settings.value( path + "/projectsInDatabase", "0" ).toString() );
527  el.setAttribute( QStringLiteral( "dontResolveType" ), settings.value( path + "/dontResolveType", "0" ).toString() );
528  el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
529  el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
530  el.setAttribute( QStringLiteral( "publicOnly" ), settings.value( path + "/publicOnly", "0" ).toString() );
531 
532  el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
533 
534  if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
535  {
536  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
537  }
538 
539  el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
540 
541  if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
542  {
543  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
544  }
545 
546  root.appendChild( el );
547  }
548 
549  return doc;
550 }
551 
552 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections )
553 {
554  QDomDocument doc( QStringLiteral( "connections" ) );
555  QDomElement root = doc.createElement( QStringLiteral( "qgsMssqlConnections" ) );
556  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
557  doc.appendChild( root );
558 
559  const QgsSettings settings;
560  QString path;
561  for ( int i = 0; i < connections.count(); ++i )
562  {
563  path = "/MSSQL/connections/" + connections[ i ];
564  QDomElement el = doc.createElement( QStringLiteral( "mssql" ) );
565  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
566  el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
567  el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
568  el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
569  el.setAttribute( QStringLiteral( "service" ), settings.value( path + "/service" ).toString() );
570  el.setAttribute( QStringLiteral( "sslmode" ), settings.value( path + "/sslmode", "1" ).toString() );
571  el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
572 
573  el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
574 
575  if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
576  {
577  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
578  }
579 
580  el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
581 
582  if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
583  {
584  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
585  }
586 
587  root.appendChild( el );
588  }
589 
590  return doc;
591 }
592 
593 QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections )
594 {
595  QDomDocument doc( QStringLiteral( "connections" ) );
596  QDomElement root = doc.createElement( QStringLiteral( "qgsOracleConnections" ) );
597  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
598  doc.appendChild( root );
599 
600  const QgsSettings settings;
601  QString path;
602  for ( int i = 0; i < connections.count(); ++i )
603  {
604  path = "/Oracle/connections/" + connections[ i ];
605  QDomElement el = doc.createElement( QStringLiteral( "oracle" ) );
606  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
607  el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host" ).toString() );
608  el.setAttribute( QStringLiteral( "port" ), settings.value( path + "/port" ).toString() );
609  el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database" ).toString() );
610  el.setAttribute( QStringLiteral( "dboptions" ), settings.value( path + "/dboptions" ).toString() );
611  el.setAttribute( QStringLiteral( "dbworkspace" ), settings.value( path + "/dbworkspace" ).toString() );
612  el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema" ).toString() );
613  el.setAttribute( QStringLiteral( "estimatedMetadata" ), settings.value( path + "/estimatedMetadata", "0" ).toString() );
614  el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", "0" ).toString() );
615  el.setAttribute( QStringLiteral( "geometryColumnsOnly" ), settings.value( path + "/geometryColumnsOnly", "0" ).toString() );
616  el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", "0" ).toString() );
617 
618  el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", "false" ).toString() );
619 
620  if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
621  {
622  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
623  }
624 
625  el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", "false" ).toString() );
626 
627  if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
628  {
629  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
630  }
631 
632  root.appendChild( el );
633  }
634 
635  return doc;
636 }
637 
638 QDomDocument QgsManageConnectionsDialog::saveHanaConnections( const QStringList &connections )
639 {
640  QDomDocument doc( QStringLiteral( "connections" ) );
641  QDomElement root = doc.createElement( QStringLiteral( "qgsHanaConnections" ) );
642  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
643  doc.appendChild( root );
644 
645  const QgsSettings settings;
646  QString path;
647  for ( int i = 0; i < connections.count(); ++i )
648  {
649  path = "/HANA/connections/" + connections[i];
650  QDomElement el = doc.createElement( QStringLiteral( "hana" ) );
651  el.setAttribute( QStringLiteral( "name" ), connections[i] );
652  el.setAttribute( QStringLiteral( "driver" ), settings.value( path + "/driver", QString() ).toString() );
653  el.setAttribute( QStringLiteral( "host" ), settings.value( path + "/host", QString() ).toString() );
654  el.setAttribute( QStringLiteral( "identifierType" ), settings.value( path + "/identifierType", QString() ).toString() );
655  el.setAttribute( QStringLiteral( "identifier" ), settings.value( path + "/identifier", QString() ).toString() );
656  el.setAttribute( QStringLiteral( "multitenant" ), settings.value( path + "/multitenant", QString() ).toString() );
657  el.setAttribute( QStringLiteral( "database" ), settings.value( path + "/database", QString() ).toString() );
658  el.setAttribute( QStringLiteral( "schema" ), settings.value( path + "/schema", QString() ).toString() );
659  el.setAttribute( QStringLiteral( "userTablesOnly" ), settings.value( path + "/userTablesOnly", QStringLiteral( "0" ) ).toString() );
660  el.setAttribute( QStringLiteral( "allowGeometrylessTables" ), settings.value( path + "/allowGeometrylessTables", QStringLiteral( "0" ) ).toString() );
661 
662  el.setAttribute( QStringLiteral( "saveUsername" ), settings.value( path + "/saveUsername", QStringLiteral( "false" ) ).toString() );
663  if ( settings.value( path + "/saveUsername", "false" ).toString() == QLatin1String( "true" ) )
664  {
665  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username", QString() ).toString() );
666  }
667 
668  el.setAttribute( QStringLiteral( "savePassword" ), settings.value( path + "/savePassword", QStringLiteral( "false" ) ).toString() );
669  if ( settings.value( path + "/savePassword", "false" ).toString() == QLatin1String( "true" ) )
670  {
671  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password", QString() ).toString() );
672  }
673 
674  el.setAttribute( QStringLiteral( "sslEnabled" ), settings.value( path + "/sslEnabled", QStringLiteral( "false" ) ).toString() );
675  el.setAttribute( QStringLiteral( "sslCryptoProvider" ), settings.value( path + "/sslCryptoProvider", QStringLiteral( "openssl" ) ).toString() );
676  el.setAttribute( QStringLiteral( "sslKeyStore" ), settings.value( path + "/sslKeyStore", QString() ).toString() );
677  el.setAttribute( QStringLiteral( "sslTrustStore" ), settings.value( path + "/sslTrustStore", QString() ).toString() );
678  el.setAttribute( QStringLiteral( "sslValidateCertificate" ), settings.value( path + "/sslValidateCertificate", QStringLiteral( "false" ) ).toString() );
679  el.setAttribute( QStringLiteral( "sslHostNameInCertificate" ), settings.value( path + "/sslHostNameInCertificate", QString() ).toString() );
680 
681  root.appendChild( el );
682  }
683 
684  return doc;
685 }
686 
687 QDomDocument QgsManageConnectionsDialog::saveGeonodeConnections( const QStringList &connections )
688 {
689  QDomDocument doc( QStringLiteral( "connections" ) );
690  QDomElement root = doc.createElement( QStringLiteral( "qgsGeoNodeConnections" ) );
691  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
692  doc.appendChild( root );
693 
694  const QgsSettings settings;
695  QString path;
696  for ( int i = 0; i < connections.count(); ++i )
697  {
698  path = QStringLiteral( "/qgis/connections-geonode/" );
699  QDomElement el = doc.createElement( QStringLiteral( "geonode" ) );
700  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
701  el.setAttribute( QStringLiteral( "url" ), settings.value( path + connections[ i ] + "/url" ).toString() );
702 
703  path = QStringLiteral( "/qgis/GeoNode/" );
704  el.setAttribute( QStringLiteral( "username" ), settings.value( path + connections[ i ] + "/username" ).toString() );
705  el.setAttribute( QStringLiteral( "password" ), settings.value( path + connections[ i ] + "/password" ).toString() );
706  root.appendChild( el );
707  }
708 
709  return doc;
710 }
711 
712 QDomDocument QgsManageConnectionsDialog::saveXyzTilesConnections( const QStringList &connections )
713 {
714  QDomDocument doc( QStringLiteral( "connections" ) );
715  QDomElement root = doc.createElement( QStringLiteral( "qgsXYZTilesConnections" ) );
716  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
717  doc.appendChild( root );
718 
719  const QgsSettings settings;
720  QString path;
721  for ( int i = 0; i < connections.count(); ++i )
722  {
723  path = "qgis/connections-xyz/" + connections[ i ];
724  QDomElement el = doc.createElement( QStringLiteral( "xyztiles" ) );
725 
726  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
727  el.setAttribute( QStringLiteral( "url" ), settings.value( path + "/url" ).toString() );
728  el.setAttribute( QStringLiteral( "zmin" ), settings.value( path + "/zmin", -1 ).toInt() );
729  el.setAttribute( QStringLiteral( "zmax" ), settings.value( path + "/zmax", -1 ).toInt() );
730  el.setAttribute( QStringLiteral( "authcfg" ), settings.value( path + "/authcfg" ).toString() );
731  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
732  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
733  el.setAttribute( QStringLiteral( "referer" ), settings.value( path + "/referer" ).toString() );
734  el.setAttribute( QStringLiteral( "tilePixelRatio" ), settings.value( path + "/tilePixelRatio", 0 ).toDouble() );
735 
736  root.appendChild( el );
737  }
738 
739  return doc;
740 }
741 
742 QDomDocument QgsManageConnectionsDialog::saveArcgisConnections( const QStringList &connections, const QString &service )
743 {
744  QDomDocument doc( QStringLiteral( "connections" ) );
745  QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" );
746  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
747  doc.appendChild( root );
748 
749  const QgsSettings settings;
750  QString path;
751  for ( int i = 0; i < connections.count(); ++i )
752  {
753  path = "/qgis/connections-" + service.toLower() + '/';
754  QDomElement el = doc.createElement( service.toLower() );
755  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
756  el.setAttribute( QStringLiteral( "url" ), settings.value( path + connections[ i ] + "/url" ).toString() );
757  el.setAttribute( QStringLiteral( "referer" ), settings.value( path + connections[ i ] + "/referer" ).toString() );
758 
759  path = "/qgis/" + service.toUpper() + '/';
760  el.setAttribute( QStringLiteral( "username" ), settings.value( path + connections[ i ] + "/username" ).toString() );
761  el.setAttribute( QStringLiteral( "password" ), settings.value( path + connections[ i ] + "/password" ).toString() );
762  el.setAttribute( QStringLiteral( "authcfg" ), settings.value( path + connections[ i ] + "/authcfg" ).toString() );
763  root.appendChild( el );
764  }
765 
766  return doc;
767 }
768 
769 QDomDocument QgsManageConnectionsDialog::saveVectorTileConnections( const QStringList &connections )
770 {
771  QDomDocument doc( QStringLiteral( "connections" ) );
772  QDomElement root = doc.createElement( QStringLiteral( "qgsVectorTileConnections" ) );
773  root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) );
774  doc.appendChild( root );
775 
776  const QgsSettings settings;
777  QString path;
778  for ( int i = 0; i < connections.count(); ++i )
779  {
780  path = "qgis/connections-vector-tile/" + connections[ i ];
781  QDomElement el = doc.createElement( QStringLiteral( "vectortile" ) );
782 
783  el.setAttribute( QStringLiteral( "name" ), connections[ i ] );
784  el.setAttribute( QStringLiteral( "url" ), settings.value( path + "/url" ).toString() );
785  el.setAttribute( QStringLiteral( "zmin" ), settings.value( path + "/zmin", -1 ).toInt() );
786  el.setAttribute( QStringLiteral( "zmax" ), settings.value( path + "/zmax", -1 ).toInt() );
787  el.setAttribute( QStringLiteral( "serviceType" ), settings.value( path + "/serviceType", QString() ).toString() );
788  el.setAttribute( QStringLiteral( "authcfg" ), settings.value( path + "/authcfg" ).toString() );
789  el.setAttribute( QStringLiteral( "username" ), settings.value( path + "/username" ).toString() );
790  el.setAttribute( QStringLiteral( "password" ), settings.value( path + "/password" ).toString() );
791  el.setAttribute( QStringLiteral( "referer" ), settings.value( path + "/referer" ).toString() );
792  el.setAttribute( QStringLiteral( "styleUrl" ), settings.value( path + "/styleUrl" ).toString() );
793 
794  root.appendChild( el );
795  }
796 
797  return doc;
798 }
799 
800 void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
801 {
802  const QDomElement root = doc.documentElement();
803  if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
804  {
805  QMessageBox::information( this, tr( "Loading Connections" ),
806  tr( "The file is not a %1 connections exchange file." ).arg( service ) );
807  return;
808  }
809 
810  QString connectionName;
811  QgsSettings settings;
812  settings.beginGroup( "/qgis/connections-" + service.toLower() );
813  QStringList keys = settings.childGroups();
814  settings.endGroup();
815  QDomElement child = root.firstChildElement();
816  bool prompt = true;
817  bool overwrite = true;
818 
819  while ( !child.isNull() )
820  {
821  connectionName = child.attribute( QStringLiteral( "name" ) );
822  if ( !items.contains( connectionName ) )
823  {
824  child = child.nextSiblingElement();
825  continue;
826  }
827 
828  // check for duplicates
829  if ( keys.contains( connectionName ) && prompt )
830  {
831  const int res = QMessageBox::warning( this,
832  tr( "Loading Connections" ),
833  tr( "Connection with name '%1' already exists. Overwrite?" )
834  .arg( connectionName ),
835  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
836 
837  switch ( res )
838  {
839  case QMessageBox::Cancel:
840  return;
841  case QMessageBox::No:
842  child = child.nextSiblingElement();
843  continue;
844  case QMessageBox::Yes:
845  overwrite = true;
846  break;
847  case QMessageBox::YesToAll:
848  prompt = false;
849  overwrite = true;
850  break;
851  case QMessageBox::NoToAll:
852  prompt = false;
853  overwrite = false;
854  break;
855  }
856  }
857 
858  if ( keys.contains( connectionName ) )
859  {
860  if ( !overwrite )
861  {
862  child = child.nextSiblingElement();
863  continue;
864  }
865  }
866  else
867  {
868  keys << connectionName;
869  }
870 
871  // no dups detected or overwrite is allowed
872  settings.beginGroup( "/qgis/connections-" + service.toLower() );
873  settings.setValue( QString( '/' + connectionName + "/url" ), child.attribute( QStringLiteral( "url" ) ) );
874  settings.setValue( QString( '/' + connectionName + "/ignoreGetMapURI" ), child.attribute( QStringLiteral( "ignoreGetMapURI" ) ) == QLatin1String( "true" ) );
875  settings.setValue( QString( '/' + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( QStringLiteral( "ignoreGetFeatureInfoURI" ) ) == QLatin1String( "true" ) );
876  settings.setValue( QString( '/' + connectionName + "/ignoreAxisOrientation" ), child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) == QLatin1String( "true" ) );
877  settings.setValue( QString( '/' + connectionName + "/invertAxisOrientation" ), child.attribute( QStringLiteral( "invertAxisOrientation" ) ) == QLatin1String( "true" ) );
878  settings.setValue( QString( '/' + connectionName + "/referer" ), child.attribute( QStringLiteral( "referer" ) ) );
879  settings.setValue( QString( '/' + connectionName + "/smoothPixmapTransform" ), child.attribute( QStringLiteral( "smoothPixmapTransform" ) ) == QLatin1String( "true" ) );
880  settings.setValue( QString( '/' + connectionName + "/dpiMode" ), child.attribute( QStringLiteral( "dpiMode" ), QStringLiteral( "7" ) ).toInt() );
881  settings.endGroup();
882 
883  if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
884  {
885  settings.beginGroup( "/qgis/" + service.toUpper() + '/' + connectionName );
886  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
887  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
888  settings.endGroup();
889  }
890  child = child.nextSiblingElement();
891  }
892 }
893 
894 void QgsManageConnectionsDialog::loadWfsConnections( const QDomDocument &doc, const QStringList &items )
895 {
896  const QDomElement root = doc.documentElement();
897  if ( root.tagName() != QLatin1String( "qgsWFSConnections" ) )
898  {
899  QMessageBox::information( this, tr( "Loading Connections" ),
900  tr( "The file is not a WFS connections exchange file." ) );
901  return;
902  }
903 
904  QString connectionName;
905  QgsSettings settings;
906  settings.beginGroup( QStringLiteral( "/qgis/connections-wfs" ) );
907  QStringList keys = settings.childGroups();
908  settings.endGroup();
909  QDomElement child = root.firstChildElement();
910  bool prompt = true;
911  bool overwrite = true;
912 
913  while ( !child.isNull() )
914  {
915  connectionName = child.attribute( QStringLiteral( "name" ) );
916  if ( !items.contains( connectionName ) )
917  {
918  child = child.nextSiblingElement();
919  continue;
920  }
921 
922  // check for duplicates
923  if ( keys.contains( connectionName ) && prompt )
924  {
925  const int res = QMessageBox::warning( this,
926  tr( "Loading Connections" ),
927  tr( "Connection with name '%1' already exists. Overwrite?" )
928  .arg( connectionName ),
929  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
930 
931  switch ( res )
932  {
933  case QMessageBox::Cancel:
934  return;
935  case QMessageBox::No:
936  child = child.nextSiblingElement();
937  continue;
938  case QMessageBox::Yes:
939  overwrite = true;
940  break;
941  case QMessageBox::YesToAll:
942  prompt = false;
943  overwrite = true;
944  break;
945  case QMessageBox::NoToAll:
946  prompt = false;
947  overwrite = false;
948  break;
949  }
950  }
951 
952  if ( keys.contains( connectionName ) )
953  {
954  if ( !overwrite )
955  {
956  child = child.nextSiblingElement();
957  continue;
958  }
959  }
960  else
961  {
962  keys << connectionName;
963  }
964 
965  // no dups detected or overwrite is allowed
966  settings.beginGroup( QStringLiteral( "/qgis/connections-wfs" ) );
967  settings.setValue( QString( '/' + connectionName + "/url" ), child.attribute( QStringLiteral( "url" ) ) );
968 
969  settings.setValue( QString( '/' + connectionName + "/version" ), child.attribute( QStringLiteral( "version" ) ) );
970  settings.setValue( QString( '/' + connectionName + "/maxnumfeatures" ), child.attribute( QStringLiteral( "maxnumfeatures" ) ) );
971  settings.setValue( QString( '/' + connectionName + "/pagesize" ), child.attribute( QStringLiteral( "pagesize" ) ) );
972  settings.setValue( QString( '/' + connectionName + "/pagingenabled" ), child.attribute( QStringLiteral( "pagingenabled" ) ) );
973  settings.setValue( QString( '/' + connectionName + "/ignoreAxisOrientation" ), child.attribute( QStringLiteral( "ignoreAxisOrientation" ) ) );
974  settings.setValue( QString( '/' + connectionName + "/invertAxisOrientation" ), child.attribute( QStringLiteral( "invertAxisOrientation" ) ) );
975  settings.endGroup();
976 
977  if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
978  {
979  settings.beginGroup( "/qgis/WFS/" + connectionName );
980  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
981  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
982  settings.endGroup();
983  }
984  child = child.nextSiblingElement();
985  }
986 }
987 
988 void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items )
989 {
990  const QDomElement root = doc.documentElement();
991  if ( root.tagName() != QLatin1String( "qgsPgConnections" ) )
992  {
993  QMessageBox::information( this,
994  tr( "Loading Connections" ),
995  tr( "The file is not a PostGIS connections exchange file." ) );
996  return;
997  }
998 
999  QString connectionName;
1000  QgsSettings settings;
1001  settings.beginGroup( QStringLiteral( "/PostgreSQL/connections" ) );
1002  QStringList keys = settings.childGroups();
1003  settings.endGroup();
1004  QDomElement child = root.firstChildElement();
1005  bool prompt = true;
1006  bool overwrite = true;
1007 
1008  while ( !child.isNull() )
1009  {
1010  connectionName = child.attribute( QStringLiteral( "name" ) );
1011  if ( !items.contains( connectionName ) )
1012  {
1013  child = child.nextSiblingElement();
1014  continue;
1015  }
1016 
1017  // check for duplicates
1018  if ( keys.contains( connectionName ) && prompt )
1019  {
1020  const int res = QMessageBox::warning( this,
1021  tr( "Loading Connections" ),
1022  tr( "Connection with name '%1' already exists. Overwrite?" )
1023  .arg( connectionName ),
1024  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1025  switch ( res )
1026  {
1027  case QMessageBox::Cancel:
1028  return;
1029  case QMessageBox::No:
1030  child = child.nextSiblingElement();
1031  continue;
1032  case QMessageBox::Yes:
1033  overwrite = true;
1034  break;
1035  case QMessageBox::YesToAll:
1036  prompt = false;
1037  overwrite = true;
1038  break;
1039  case QMessageBox::NoToAll:
1040  prompt = false;
1041  overwrite = false;
1042  break;
1043  }
1044  }
1045 
1046  if ( keys.contains( connectionName ) )
1047  {
1048  if ( !overwrite )
1049  {
1050  child = child.nextSiblingElement();
1051  continue;
1052  }
1053  }
1054  else
1055  {
1056  keys << connectionName;
1057  }
1058 
1059  //no dups detected or overwrite is allowed
1060  settings.beginGroup( "/PostgreSQL/connections/" + connectionName );
1061 
1062  settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1063  settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1064  settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1065  if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1066  {
1067  settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1068  }
1069  else
1070  {
1071  settings.setValue( QStringLiteral( "/service" ), "" );
1072  }
1073  settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1074  settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1075  settings.setValue( QStringLiteral( "/projectsInDatabase" ), child.attribute( QStringLiteral( "projectsInDatabase" ), 0 ) );
1076  settings.setValue( QStringLiteral( "/dontResolveType" ), child.attribute( QStringLiteral( "dontResolveType" ), 0 ) );
1077  settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ), 0 ) );
1078  settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ), 0 ) );
1079  settings.setValue( QStringLiteral( "/publicOnly" ), child.attribute( QStringLiteral( "publicOnly" ), 0 ) );
1080  settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1081  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1082  settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1083  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1084  settings.endGroup();
1085 
1086  child = child.nextSiblingElement();
1087  }
1088 }
1089 
1090 void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items )
1091 {
1092  const QDomElement root = doc.documentElement();
1093  if ( root.tagName() != QLatin1String( "qgsMssqlConnections" ) )
1094  {
1095  QMessageBox::information( this,
1096  tr( "Loading Connections" ),
1097  tr( "The file is not a MSSQL connections exchange file." ) );
1098  return;
1099  }
1100 
1101  QString connectionName;
1102  QgsSettings settings;
1103  settings.beginGroup( QStringLiteral( "/MSSQL/connections" ) );
1104  QStringList keys = settings.childGroups();
1105  settings.endGroup();
1106  QDomElement child = root.firstChildElement();
1107  bool prompt = true;
1108  bool overwrite = true;
1109 
1110  while ( !child.isNull() )
1111  {
1112  connectionName = child.attribute( QStringLiteral( "name" ) );
1113  if ( !items.contains( connectionName ) )
1114  {
1115  child = child.nextSiblingElement();
1116  continue;
1117  }
1118 
1119  // check for duplicates
1120  if ( keys.contains( connectionName ) && prompt )
1121  {
1122  const int res = QMessageBox::warning( this,
1123  tr( "Loading Connections" ),
1124  tr( "Connection with name '%1' already exists. Overwrite?" )
1125  .arg( connectionName ),
1126  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1127  switch ( res )
1128  {
1129  case QMessageBox::Cancel:
1130  return;
1131  case QMessageBox::No:
1132  child = child.nextSiblingElement();
1133  continue;
1134  case QMessageBox::Yes:
1135  overwrite = true;
1136  break;
1137  case QMessageBox::YesToAll:
1138  prompt = false;
1139  overwrite = true;
1140  break;
1141  case QMessageBox::NoToAll:
1142  prompt = false;
1143  overwrite = false;
1144  break;
1145  }
1146  }
1147 
1148  if ( keys.contains( connectionName ) )
1149  {
1150  if ( !overwrite )
1151  {
1152  child = child.nextSiblingElement();
1153  continue;
1154  }
1155  }
1156  else
1157  {
1158  keys << connectionName;
1159  }
1160 
1161  //no dups detected or overwrite is allowed
1162  settings.beginGroup( "/MSSQL/connections/" + connectionName );
1163 
1164  settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1165  settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1166  settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1167  if ( child.hasAttribute( QStringLiteral( "service" ) ) )
1168  {
1169  settings.setValue( QStringLiteral( "/service" ), child.attribute( QStringLiteral( "service" ) ) );
1170  }
1171  else
1172  {
1173  settings.setValue( QStringLiteral( "/service" ), "" );
1174  }
1175  settings.setValue( QStringLiteral( "/sslmode" ), child.attribute( QStringLiteral( "sslmode" ) ) );
1176  settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1177  settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1178  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1179  settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1180  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1181  settings.endGroup();
1182 
1183  child = child.nextSiblingElement();
1184  }
1185 }
1186 
1187 void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items )
1188 {
1189  const QDomElement root = doc.documentElement();
1190  if ( root.tagName() != QLatin1String( "qgsOracleConnections" ) )
1191  {
1192  QMessageBox::information( this,
1193  tr( "Loading Connections" ),
1194  tr( "The file is not an Oracle connections exchange file." ) );
1195  return;
1196  }
1197 
1198  QString connectionName;
1199  QgsSettings settings;
1200  settings.beginGroup( QStringLiteral( "/Oracle/connections" ) );
1201  QStringList keys = settings.childGroups();
1202  settings.endGroup();
1203  QDomElement child = root.firstChildElement();
1204  bool prompt = true;
1205  bool overwrite = true;
1206 
1207  while ( !child.isNull() )
1208  {
1209  connectionName = child.attribute( QStringLiteral( "name" ) );
1210  if ( !items.contains( connectionName ) )
1211  {
1212  child = child.nextSiblingElement();
1213  continue;
1214  }
1215 
1216  // check for duplicates
1217  if ( keys.contains( connectionName ) && prompt )
1218  {
1219  const int res = QMessageBox::warning( this,
1220  tr( "Loading Connections" ),
1221  tr( "Connection with name '%1' already exists. Overwrite?" )
1222  .arg( connectionName ),
1223  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1224  switch ( res )
1225  {
1226  case QMessageBox::Cancel:
1227  return;
1228  case QMessageBox::No:
1229  child = child.nextSiblingElement();
1230  continue;
1231  case QMessageBox::Yes:
1232  overwrite = true;
1233  break;
1234  case QMessageBox::YesToAll:
1235  prompt = false;
1236  overwrite = true;
1237  break;
1238  case QMessageBox::NoToAll:
1239  prompt = false;
1240  overwrite = false;
1241  break;
1242  }
1243  }
1244 
1245  if ( keys.contains( connectionName ) )
1246  {
1247  if ( !overwrite )
1248  {
1249  child = child.nextSiblingElement();
1250  continue;
1251  }
1252  }
1253  else
1254  {
1255  keys << connectionName;
1256  }
1257 
1258  //no dups detected or overwrite is allowed
1259  settings.beginGroup( "/Oracle/connections/" + connectionName );
1260 
1261  settings.setValue( QStringLiteral( "/host" ), child.attribute( QStringLiteral( "host" ) ) );
1262  settings.setValue( QStringLiteral( "/port" ), child.attribute( QStringLiteral( "port" ) ) );
1263  settings.setValue( QStringLiteral( "/database" ), child.attribute( QStringLiteral( "database" ) ) );
1264  settings.setValue( QStringLiteral( "/dboptions" ), child.attribute( QStringLiteral( "dboptions" ) ) );
1265  settings.setValue( QStringLiteral( "/dbworkspace" ), child.attribute( QStringLiteral( "dbworkspace" ) ) );
1266  settings.setValue( QStringLiteral( "/schema" ), child.attribute( QStringLiteral( "schema" ) ) );
1267  settings.setValue( QStringLiteral( "/estimatedMetadata" ), child.attribute( QStringLiteral( "estimatedMetadata" ) ) );
1268  settings.setValue( QStringLiteral( "/userTablesOnly" ), child.attribute( QStringLiteral( "userTablesOnly" ) ) );
1269  settings.setValue( QStringLiteral( "/geometryColumnsOnly" ), child.attribute( QStringLiteral( "geometryColumnsOnly" ) ) );
1270  settings.setValue( QStringLiteral( "/allowGeometrylessTables" ), child.attribute( QStringLiteral( "allowGeometrylessTables" ) ) );
1271  settings.setValue( QStringLiteral( "/saveUsername" ), child.attribute( QStringLiteral( "saveUsername" ) ) );
1272  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1273  settings.setValue( QStringLiteral( "/savePassword" ), child.attribute( QStringLiteral( "savePassword" ) ) );
1274  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1275  settings.endGroup();
1276 
1277  child = child.nextSiblingElement();
1278  }
1279 }
1280 
1281 void QgsManageConnectionsDialog::loadHanaConnections( const QDomDocument &doc, const QStringList &items )
1282 {
1283  QDomElement root = doc.documentElement();
1284  if ( root.tagName() != QLatin1String( "qgsHanaConnections" ) )
1285  {
1286  QMessageBox::warning( this,
1287  tr( "Loading Connections" ),
1288  tr( "The file is not a HANA connections exchange file." ) );
1289  return;
1290  }
1291 
1292  const QDomAttr version = root.attributeNode( "version" );
1293  if ( version.value() != QLatin1String( "1.0" ) )
1294  {
1295  QMessageBox::warning( this,
1296  tr( "Loading Connections" ),
1297  tr( "The HANA connections exchange file version '%1' is not supported." ).arg( version.value() ) );
1298  return;
1299  }
1300 
1301  QgsSettings settings;
1302  settings.beginGroup( QStringLiteral( "/HANA/connections" ) );
1303  QStringList keys = settings.childGroups();
1304  settings.endGroup();
1305  QDomElement child = root.firstChildElement();
1306  bool prompt = true;
1307  bool overwrite = true;
1308 
1309  while ( !child.isNull() )
1310  {
1311  const QString connectionName = child.attribute( QStringLiteral( "name" ) );
1312  if ( !items.contains( connectionName ) )
1313  {
1314  child = child.nextSiblingElement();
1315  continue;
1316  }
1317 
1318  // check for duplicates
1319  if ( keys.contains( connectionName ) && prompt )
1320  {
1321  const int res = QMessageBox::warning( this,
1322  tr( "Loading Connections" ),
1323  tr( "Connection with name '%1' already exists. Overwrite?" )
1324  .arg( connectionName ),
1325  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1326  switch ( res )
1327  {
1328  case QMessageBox::Cancel:
1329  return;
1330  case QMessageBox::No:
1331  child = child.nextSiblingElement();
1332  continue;
1333  case QMessageBox::Yes:
1334  overwrite = true;
1335  break;
1336  case QMessageBox::YesToAll:
1337  prompt = false;
1338  overwrite = true;
1339  break;
1340  case QMessageBox::NoToAll:
1341  prompt = false;
1342  overwrite = false;
1343  break;
1344  }
1345  }
1346 
1347  if ( keys.contains( connectionName ) )
1348  {
1349  if ( !overwrite )
1350  {
1351  child = child.nextSiblingElement();
1352  continue;
1353  }
1354  }
1355  else
1356  {
1357  keys << connectionName;
1358  }
1359 
1360  //no dups detected or overwrite is allowed
1361  settings.beginGroup( "/HANA/connections/" + connectionName );
1362 
1363  for ( const QString param :
1364  {"driver", "host", "database", "identifierType", "identifier", "multitenant", "schema", "userTablesOnly",
1365  "allowGeometrylessTables", "saveUsername", "username", "savePassword", "password", "sslEnabled",
1366  "sslCryptoProvider", "sslKeyStore", "sslTrustStore", "sslValidateCertificate", "sslHostNameInCertificate"
1367  } )
1368  settings.setValue( QStringLiteral( "/" ) + param, child.attribute( param ) );
1369 
1370  settings.endGroup();
1371 
1372  child = child.nextSiblingElement();
1373  }
1374 }
1375 
1376 void QgsManageConnectionsDialog::loadGeonodeConnections( const QDomDocument &doc, const QStringList &items )
1377 {
1378  const QDomElement root = doc.documentElement();
1379  if ( root.tagName() != QLatin1String( "qgsGeoNodeConnections" ) )
1380  {
1381  QMessageBox::information( this, tr( "Loading Connections" ),
1382  tr( "The file is not a GeoNode connections exchange file." ) );
1383  return;
1384  }
1385 
1386  QString connectionName;
1387  QgsSettings settings;
1388  settings.beginGroup( QStringLiteral( "/qgis/connections-geonode" ) );
1389  QStringList keys = settings.childGroups();
1390  settings.endGroup();
1391  QDomElement child = root.firstChildElement();
1392  bool prompt = true;
1393  bool overwrite = true;
1394 
1395  while ( !child.isNull() )
1396  {
1397  connectionName = child.attribute( QStringLiteral( "name" ) );
1398  if ( !items.contains( connectionName ) )
1399  {
1400  child = child.nextSiblingElement();
1401  continue;
1402  }
1403 
1404  // check for duplicates
1405  if ( keys.contains( connectionName ) && prompt )
1406  {
1407  const int res = QMessageBox::warning( this,
1408  tr( "Loading Connections" ),
1409  tr( "Connection with name '%1' already exists. Overwrite?" )
1410  .arg( connectionName ),
1411  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1412 
1413  switch ( res )
1414  {
1415  case QMessageBox::Cancel:
1416  return;
1417  case QMessageBox::No:
1418  child = child.nextSiblingElement();
1419  continue;
1420  case QMessageBox::Yes:
1421  overwrite = true;
1422  break;
1423  case QMessageBox::YesToAll:
1424  prompt = false;
1425  overwrite = true;
1426  break;
1427  case QMessageBox::NoToAll:
1428  prompt = false;
1429  overwrite = false;
1430  break;
1431  }
1432  }
1433 
1434  if ( keys.contains( connectionName ) )
1435  {
1436  if ( !overwrite )
1437  {
1438  child = child.nextSiblingElement();
1439  continue;
1440  }
1441  }
1442  else
1443  {
1444  keys << connectionName;
1445  }
1446 
1447  // no dups detected or overwrite is allowed
1448  settings.beginGroup( QStringLiteral( "/qgis/connections-geonode" ) );
1449  settings.setValue( QString( '/' + connectionName + "/url" ), child.attribute( QStringLiteral( "url" ) ) );
1450  settings.endGroup();
1451 
1452  if ( !child.attribute( QStringLiteral( "username" ) ).isEmpty() )
1453  {
1454  settings.beginGroup( "/qgis/GeoNode/" + connectionName );
1455  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1456  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1457  settings.endGroup();
1458  }
1459  child = child.nextSiblingElement();
1460  }
1461 }
1462 
1463 void QgsManageConnectionsDialog::loadXyzTilesConnections( const QDomDocument &doc, const QStringList &items )
1464 {
1465  const QDomElement root = doc.documentElement();
1466  if ( root.tagName() != QLatin1String( "qgsXYZTilesConnections" ) )
1467  {
1468  QMessageBox::information( this, tr( "Loading Connections" ),
1469  tr( "The file is not a XYZ Tiles connections exchange file." ) );
1470  return;
1471  }
1472 
1473  QString connectionName;
1474  QgsSettings settings;
1475  settings.beginGroup( QStringLiteral( "/qgis/connections-xyz" ) );
1476  QStringList keys = settings.childGroups();
1477  settings.endGroup();
1478  QDomElement child = root.firstChildElement();
1479  bool prompt = true;
1480  bool overwrite = true;
1481 
1482  while ( !child.isNull() )
1483  {
1484  connectionName = child.attribute( QStringLiteral( "name" ) );
1485  if ( !items.contains( connectionName ) )
1486  {
1487  child = child.nextSiblingElement();
1488  continue;
1489  }
1490 
1491  // check for duplicates
1492  if ( keys.contains( connectionName ) && prompt )
1493  {
1494  const int res = QMessageBox::warning( this,
1495  tr( "Loading Connections" ),
1496  tr( "Connection with name '%1' already exists. Overwrite?" )
1497  .arg( connectionName ),
1498  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1499 
1500  switch ( res )
1501  {
1502  case QMessageBox::Cancel:
1503  return;
1504  case QMessageBox::No:
1505  child = child.nextSiblingElement();
1506  continue;
1507  case QMessageBox::Yes:
1508  overwrite = true;
1509  break;
1510  case QMessageBox::YesToAll:
1511  prompt = false;
1512  overwrite = true;
1513  break;
1514  case QMessageBox::NoToAll:
1515  prompt = false;
1516  overwrite = false;
1517  break;
1518  }
1519  }
1520 
1521  if ( keys.contains( connectionName ) )
1522  {
1523  if ( !overwrite )
1524  {
1525  child = child.nextSiblingElement();
1526  continue;
1527  }
1528  }
1529  else
1530  {
1531  keys << connectionName;
1532  }
1533 
1534  settings.beginGroup( "qgis/connections-xyz/" + connectionName );
1535  settings.setValue( QStringLiteral( "url" ), child.attribute( QStringLiteral( "url" ) ) );
1536  settings.setValue( QStringLiteral( "zmin" ), child.attribute( QStringLiteral( "zmin" ) ) );
1537  settings.setValue( QStringLiteral( "zmax" ), child.attribute( QStringLiteral( "zmax" ) ) );
1538  settings.setValue( QStringLiteral( "authcfg" ), child.attribute( QStringLiteral( "authcfg" ) ) );
1539  settings.setValue( QStringLiteral( "username" ), child.attribute( QStringLiteral( "username" ) ) );
1540  settings.setValue( QStringLiteral( "password" ), child.attribute( QStringLiteral( "password" ) ) );
1541  settings.setValue( QStringLiteral( "referer" ), child.attribute( QStringLiteral( "referer" ) ) );
1542  settings.setValue( QStringLiteral( "tilePixelRatio" ), child.attribute( QStringLiteral( "tilePixelRatio" ) ) );
1543  settings.endGroup();
1544 
1545  child = child.nextSiblingElement();
1546  }
1547 }
1548 
1549 void QgsManageConnectionsDialog::loadArcgisConnections( const QDomDocument &doc, const QStringList &items, const QString &service )
1550 {
1551  const QDomElement root = doc.documentElement();
1552  if ( root.tagName() != "qgs" + service.toUpper() + "Connections" )
1553  {
1554  QMessageBox::information( this, tr( "Loading Connections" ),
1555  tr( "The file is not a %1 connections exchange file." ).arg( service ) );
1556  return;
1557  }
1558 
1559  QString connectionName;
1560  QgsSettings settings;
1561  settings.beginGroup( "/qgis/connections-" + service.toLower() );
1562  QStringList keys = settings.childGroups();
1563  settings.endGroup();
1564  QDomElement child = root.firstChildElement();
1565  bool prompt = true;
1566  bool overwrite = true;
1567 
1568  while ( !child.isNull() )
1569  {
1570  connectionName = child.attribute( QStringLiteral( "name" ) );
1571  if ( !items.contains( connectionName ) )
1572  {
1573  child = child.nextSiblingElement();
1574  continue;
1575  }
1576 
1577  // check for duplicates
1578  if ( keys.contains( connectionName ) && prompt )
1579  {
1580  const int res = QMessageBox::warning( this,
1581  tr( "Loading Connections" ),
1582  tr( "Connection with name '%1' already exists. Overwrite?" )
1583  .arg( connectionName ),
1584  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1585 
1586  switch ( res )
1587  {
1588  case QMessageBox::Cancel:
1589  return;
1590  case QMessageBox::No:
1591  child = child.nextSiblingElement();
1592  continue;
1593  case QMessageBox::Yes:
1594  overwrite = true;
1595  break;
1596  case QMessageBox::YesToAll:
1597  prompt = false;
1598  overwrite = true;
1599  break;
1600  case QMessageBox::NoToAll:
1601  prompt = false;
1602  overwrite = false;
1603  break;
1604  }
1605  }
1606 
1607  if ( keys.contains( connectionName ) )
1608  {
1609  if ( !overwrite )
1610  {
1611  child = child.nextSiblingElement();
1612  continue;
1613  }
1614  }
1615  else
1616  {
1617  keys << connectionName;
1618  }
1619 
1620  // no dups detected or overwrite is allowed
1621  settings.beginGroup( "/qgis/connections-" + service.toLower() );
1622  settings.setValue( QString( '/' + connectionName + "/url" ), child.attribute( QStringLiteral( "url" ) ) );
1623  settings.setValue( QString( '/' + connectionName + "/referer" ), child.attribute( QStringLiteral( "referer" ) ) );
1624  settings.endGroup();
1625 
1626  settings.beginGroup( "/qgis/" + service.toUpper() + '/' + connectionName );
1627  settings.setValue( QStringLiteral( "/username" ), child.attribute( QStringLiteral( "username" ) ) );
1628  settings.setValue( QStringLiteral( "/password" ), child.attribute( QStringLiteral( "password" ) ) );
1629  settings.setValue( QStringLiteral( "/authcfg" ), child.attribute( QStringLiteral( "authcfg" ) ) );
1630  settings.endGroup();
1631 
1632  child = child.nextSiblingElement();
1633  }
1634 }
1635 
1636 void QgsManageConnectionsDialog::loadVectorTileConnections( const QDomDocument &doc, const QStringList &items )
1637 {
1638  const QDomElement root = doc.documentElement();
1639  if ( root.tagName() != QLatin1String( "qgsVectorTileConnections" ) )
1640  {
1641  QMessageBox::information( this, tr( "Loading Connections" ),
1642  tr( "The file is not a Vector Tile connections exchange file." ) );
1643  return;
1644  }
1645 
1646  QString connectionName;
1647  QgsSettings settings;
1648  settings.beginGroup( QStringLiteral( "/qgis/connections-vector-tile" ) );
1649  QStringList keys = settings.childGroups();
1650  settings.endGroup();
1651  QDomElement child = root.firstChildElement();
1652  bool prompt = true;
1653  bool overwrite = true;
1654 
1655  while ( !child.isNull() )
1656  {
1657  connectionName = child.attribute( QStringLiteral( "name" ) );
1658  if ( !items.contains( connectionName ) )
1659  {
1660  child = child.nextSiblingElement();
1661  continue;
1662  }
1663 
1664  // check for duplicates
1665  if ( keys.contains( connectionName ) && prompt )
1666  {
1667  const int res = QMessageBox::warning( this,
1668  tr( "Loading Connections" ),
1669  tr( "Connection with name '%1' already exists. Overwrite?" )
1670  .arg( connectionName ),
1671  QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
1672 
1673  switch ( res )
1674  {
1675  case QMessageBox::Cancel:
1676  return;
1677  case QMessageBox::No:
1678  child = child.nextSiblingElement();
1679  continue;
1680  case QMessageBox::Yes:
1681  overwrite = true;
1682  break;
1683  case QMessageBox::YesToAll:
1684  prompt = false;
1685  overwrite = true;
1686  break;
1687  case QMessageBox::NoToAll:
1688  prompt = false;
1689  overwrite = false;
1690  break;
1691  }
1692  }
1693 
1694  if ( keys.contains( connectionName ) )
1695  {
1696  if ( !overwrite )
1697  {
1698  child = child.nextSiblingElement();
1699  continue;
1700  }
1701  }
1702  else
1703  {
1704  keys << connectionName;
1705  }
1706 
1707  settings.beginGroup( "qgis/connections-vector-tile/" + connectionName );
1708  settings.setValue( QStringLiteral( "url" ), child.attribute( QStringLiteral( "url" ) ) );
1709  settings.setValue( QStringLiteral( "zmin" ), child.attribute( QStringLiteral( "zmin" ) ) );
1710  settings.setValue( QStringLiteral( "zmax" ), child.attribute( QStringLiteral( "zmax" ) ) );
1711  settings.setValue( QStringLiteral( "serviceType" ), child.attribute( QStringLiteral( "serviceType" ) ) );
1712  settings.setValue( QStringLiteral( "authcfg" ), child.attribute( QStringLiteral( "authcfg" ) ) );
1713  settings.setValue( QStringLiteral( "username" ), child.attribute( QStringLiteral( "username" ) ) );
1714  settings.setValue( QStringLiteral( "password" ), child.attribute( QStringLiteral( "password" ) ) );
1715  settings.setValue( QStringLiteral( "referer" ), child.attribute( QStringLiteral( "referer" ) ) );
1716  settings.setValue( QStringLiteral( "styleUrl" ), child.attribute( QStringLiteral( "styleUrl" ) ) );
1717 
1718  settings.endGroup();
1719 
1720  child = child.nextSiblingElement();
1721  }
1722 }
1723 
1725 {
1726  listConnections->selectAll();
1727  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
1728 }
1729 
1731 {
1732  listConnections->clearSelection();
1733  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
1734 }
QgsManageConnectionsDialog(QWidget *parent=nullptr, Mode mode=Export, Type type=WMS, const QString &fileName=QString())
Constructor for QgsManageConnectionsDialog.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QStringList childGroups() 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.