@@ -98,13 +98,17 @@ void QgsManageConnectionsDialog::doExportImport()
9898 mFileName = fileName;
9999
100100 QDomDocument doc;
101- if ( mConnectionType == WMS )
101+ switch ( mConnectionType )
102102 {
103- doc = saveWMSConnections ( items );
104- }
105- else
106- {
107- doc = savePgConnections ( items );
103+ case WMS:
104+ doc = saveWMSConnections ( items );
105+ break ;
106+ case WFS:
107+ doc = saveWFSConnections ( items );
108+ break ;
109+ case PostGIS:
110+ doc = savePgConnections ( items );
111+ break ;
108112 }
109113
110114 QFile file ( mFileName );
@@ -147,13 +151,17 @@ void QgsManageConnectionsDialog::doExportImport()
147151 return ;
148152 }
149153
150- if ( mConnectionType == WMS )
154+ switch ( mConnectionType )
151155 {
152- loadWMSConnections ( doc, items );
153- }
154- else
155- {
156- loadPgConnections ( doc, items );
156+ case WMS:
157+ loadWMSConnections ( doc, items );
158+ break ;
159+ case WFS:
160+ loadWFSConnections ( doc, items );
161+ break ;
162+ case PostGIS:
163+ loadPgConnections ( doc, items );
164+ break ;
157165 }
158166 // clear connections list and close window
159167 listConnections->clear ();
@@ -169,13 +177,17 @@ bool QgsManageConnectionsDialog::populateConnections()
169177 if ( mDialogMode == Export )
170178 {
171179 QSettings settings;
172- if ( mConnectionType == WMS )
173- {
174- settings.beginGroup ( " /Qgis/connections-wms" );
175- }
176- else
180+ switch ( mConnectionType )
177181 {
178- settings.beginGroup ( " /PostgreSQL/connections" );
182+ case WMS:
183+ settings.beginGroup ( " /Qgis/connections-wms" );
184+ break ;
185+ case WFS:
186+ settings.beginGroup ( " /Qgis/connections-wfs" );
187+ break ;
188+ case PostGIS:
189+ settings.beginGroup ( " /PostgreSQL/connections" );
190+ break ;
179191 }
180192 QStringList keys = settings.childGroups ();
181193 QStringList::Iterator it = keys.begin ();
@@ -217,23 +229,34 @@ bool QgsManageConnectionsDialog::populateConnections()
217229 }
218230
219231 QDomElement root = doc.documentElement ();
220- if ( mConnectionType == WMS )
232+ switch ( mConnectionType )
221233 {
222- if ( root.tagName () != " qgsWMSConnections" )
223- {
224- QMessageBox::information ( this , tr ( " Loading connections" ),
225- tr ( " The file is not an WMS connections exchange file." ) );
226- return false ;
227- }
228- }
229- else
230- {
231- if ( root.tagName () != " qgsPgConnections" )
232- {
233- QMessageBox::information ( this , tr ( " Loading connections" ),
234- tr ( " The file is not an PostGIS connections exchange file." ) );
235- return false ;
236- }
234+ case WMS:
235+ if ( root.tagName () != " qgsWMSConnections" )
236+ {
237+ QMessageBox::information ( this , tr ( " Loading connections" ),
238+ tr ( " The file is not an WMS connections exchange file." ) );
239+ return false ;
240+ }
241+ break ;
242+
243+ case WFS:
244+ if ( root.tagName () != " qgsWFSConnections" )
245+ {
246+ QMessageBox::information ( this , tr ( " Loading connections" ),
247+ tr ( " The file is not an WFS connections exchange file." ) );
248+ return false ;
249+ }
250+ break ;
251+
252+ case PostGIS:
253+ if ( root.tagName () != " qgsPgConnections" )
254+ {
255+ QMessageBox::information ( this , tr ( " Loading connections" ),
256+ tr ( " The file is not an PostGIS connections exchange file." ) );
257+ return false ;
258+ }
259+ break ;
237260 }
238261
239262 QDomElement child = root.firstChildElement ();
@@ -273,6 +296,31 @@ QDomDocument QgsManageConnectionsDialog::saveWMSConnections( const QStringList &
273296 return doc;
274297}
275298
299+ QDomDocument QgsManageConnectionsDialog::saveWFSConnections ( const QStringList &connections )
300+ {
301+ QDomDocument doc ( " connections" );
302+ QDomElement root = doc.createElement ( " qgsWFSConnections" );
303+ root.setAttribute ( " version" , " 1.0" );
304+ doc.appendChild ( root );
305+
306+ QSettings settings;
307+ QString path;
308+ for ( int i = 0 ; i < connections.count (); ++i )
309+ {
310+ path = " /Qgis/connections-wfs/" ;
311+ QDomElement el = doc.createElement ( " wfs" );
312+ el.setAttribute ( " name" , connections[ i ] );
313+ el.setAttribute ( " url" , settings.value ( path + connections[ i ] + " /url" , " " ).toString () );
314+
315+ path = " /Qgis/WFS/" ;
316+ el.setAttribute ( " username" , settings.value ( path + connections[ i ] + " /username" , " " ).toString () );
317+ el.setAttribute ( " password" , settings.value ( path + connections[ i ] + " /password" , " " ).toString () );
318+ root.appendChild ( el );
319+ }
320+
321+ return doc;
322+ }
323+
276324QDomDocument QgsManageConnectionsDialog::savePgConnections ( const QStringList &connections )
277325{
278326 QDomDocument doc ( " connections" );
@@ -388,6 +436,81 @@ void QgsManageConnectionsDialog::loadWMSConnections( const QDomDocument &doc, co
388436 }
389437}
390438
439+ void QgsManageConnectionsDialog::loadWFSConnections ( const QDomDocument &doc, const QStringList &items )
440+ {
441+ QDomElement root = doc.documentElement ();
442+ if ( root.tagName () != " qgsWFSConnections" )
443+ {
444+ QMessageBox::information ( this , tr ( " Loading connections" ),
445+ tr ( " The file is not an WFS connections exchange file." ) );
446+ return ;
447+ }
448+
449+ QString connectionName;
450+ QSettings settings;
451+ settings.beginGroup ( " /Qgis/connections-wfs" );
452+ QStringList keys = settings.childGroups ();
453+ settings.endGroup ();
454+ QDomElement child = root.firstChildElement ();
455+ bool prompt = true ;
456+ bool overwrite = true ;
457+
458+ while ( !child.isNull () )
459+ {
460+ connectionName = child.attribute ( " name" );
461+ if ( !items.contains ( connectionName ) )
462+ {
463+ child = child.nextSiblingElement ();
464+ continue ;
465+ }
466+
467+ // check for duplicates
468+ if ( keys.contains ( connectionName ) && prompt )
469+ {
470+ int res = QMessageBox::warning ( this , tr ( " Loading connections" ),
471+ tr ( " Connection with name '%1' already exists. Overwrite?" )
472+ .arg ( connectionName ),
473+ QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
474+
475+ switch ( res )
476+ {
477+ case QMessageBox::Cancel: return ;
478+ case QMessageBox::No: child = child.nextSiblingElement ();
479+ continue ;
480+ case QMessageBox::Yes: overwrite = true ;
481+ break ;
482+ case QMessageBox::YesToAll: prompt = false ;
483+ overwrite = true ;
484+ break ;
485+ case QMessageBox::NoToAll: prompt = false ;
486+ overwrite = false ;
487+ break ;
488+ }
489+ }
490+
491+ if ( keys.contains ( connectionName ) && !overwrite )
492+ {
493+ child = child.nextSiblingElement ();
494+ continue ;
495+ }
496+
497+ // no dups detected or overwrite is allowed
498+ settings.beginGroup ( " /Qgis/connections-wfs" );
499+ settings.setValue ( QString ( " /" + connectionName + " /url" ) , child.attribute ( " url" ) );
500+ settings.endGroup ();
501+
502+ if ( !child.attribute ( " username" ).isEmpty () )
503+ {
504+ settings.beginGroup ( " /Qgis/WFS/" + connectionName );
505+ settings.setValue ( " /username" , child.attribute ( " username" ) );
506+ settings.setValue ( " /password" , child.attribute ( " password" ) );
507+ settings.endGroup ();
508+ }
509+ child = child.nextSiblingElement ();
510+ }
511+ }
512+
513+
391514void QgsManageConnectionsDialog::loadPgConnections ( const QDomDocument &doc, const QStringList &items )
392515{
393516 QDomElement root = doc.documentElement ();
0 commit comments