@@ -108,6 +108,9 @@ void QgsManageConnectionsDialog::doExportImport()
108
108
case PostGIS:
109
109
doc = savePgConnections ( items );
110
110
break ;
111
+ case MSSQL:
112
+ doc = saveMssqlConnections ( items );
113
+ break ;
111
114
}
112
115
113
116
QFile file ( mFileName );
@@ -161,6 +164,9 @@ void QgsManageConnectionsDialog::doExportImport()
161
164
case PostGIS:
162
165
loadPgConnections ( doc, items );
163
166
break ;
167
+ case MSSQL:
168
+ loadMssqlConnections ( doc, items );
169
+ break ;
164
170
}
165
171
// clear connections list and close window
166
172
listConnections->clear ();
@@ -187,6 +193,9 @@ bool QgsManageConnectionsDialog::populateConnections()
187
193
case PostGIS:
188
194
settings.beginGroup ( " /PostgreSQL/connections" );
189
195
break ;
196
+ case MSSQL:
197
+ settings.beginGroup ( " /MSSQL/connections" );
198
+ break ;
190
199
}
191
200
QStringList keys = settings.childGroups ();
192
201
QStringList::Iterator it = keys.begin ();
@@ -256,6 +265,15 @@ bool QgsManageConnectionsDialog::populateConnections()
256
265
return false ;
257
266
}
258
267
break ;
268
+
269
+ case MSSQL:
270
+ if ( root.tagName () != " qgsMssqlConnections" )
271
+ {
272
+ QMessageBox::information ( this , tr ( " Loading connections" ),
273
+ tr ( " The file is not an MSSQL connections exchange file." ) );
274
+ return false ;
275
+ }
276
+ break ;
259
277
}
260
278
261
279
QDomElement child = root.firstChildElement ();
@@ -363,6 +381,47 @@ QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &c
363
381
return doc;
364
382
}
365
383
384
+ QDomDocument QgsManageConnectionsDialog::saveMssqlConnections ( const QStringList &connections )
385
+ {
386
+ QDomDocument doc ( " connections" );
387
+ QDomElement root = doc.createElement ( " qgsMssqlConnections" );
388
+ root.setAttribute ( " version" , " 1.0" );
389
+ doc.appendChild ( root );
390
+
391
+ QSettings settings;
392
+ QString path;
393
+ for ( int i = 0 ; i < connections.count (); ++i )
394
+ {
395
+ path = " /MSSQL/connections/" + connections[ i ];
396
+ QDomElement el = doc.createElement ( " mssql" );
397
+ el.setAttribute ( " name" , connections[ i ] );
398
+ el.setAttribute ( " host" , settings.value ( path + " /host" , " " ).toString () );
399
+ el.setAttribute ( " port" , settings.value ( path + " /port" , " " ).toString () );
400
+ el.setAttribute ( " database" , settings.value ( path + " /database" , " " ).toString () );
401
+ el.setAttribute ( " service" , settings.value ( path + " /service" , " " ).toString () );
402
+ el.setAttribute ( " sslmode" , settings.value ( path + " /sslmode" , " 1" ).toString () );
403
+ el.setAttribute ( " estimatedMetadata" , settings.value ( path + " /estimatedMetadata" , " 0" ).toString () );
404
+
405
+ el.setAttribute ( " saveUsername" , settings.value ( path + " /saveUsername" , " false" ).toString () );
406
+
407
+ if ( settings.value ( path + " /saveUsername" , " false" ).toString () == " true" )
408
+ {
409
+ el.setAttribute ( " username" , settings.value ( path + " /username" , " " ).toString () );
410
+ }
411
+
412
+ el.setAttribute ( " savePassword" , settings.value ( path + " /savePassword" , " false" ).toString () );
413
+
414
+ if ( settings.value ( path + " /savePassword" , " false" ).toString () == " true" )
415
+ {
416
+ el.setAttribute ( " password" , settings.value ( path + " /password" , " " ).toString () );
417
+ }
418
+
419
+ root.appendChild ( el );
420
+ }
421
+
422
+ return doc;
423
+ }
424
+
366
425
void QgsManageConnectionsDialog::loadWMSConnections ( const QDomDocument &doc, const QStringList &items )
367
426
{
368
427
QDomElement root = doc.documentElement ();
@@ -616,6 +675,96 @@ void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, con
616
675
}
617
676
}
618
677
678
+ void QgsManageConnectionsDialog::loadMssqlConnections ( const QDomDocument &doc, const QStringList &items )
679
+ {
680
+ QDomElement root = doc.documentElement ();
681
+ if ( root.tagName () != " qgsMssqlConnections" )
682
+ {
683
+ QMessageBox::information ( this ,
684
+ tr ( " Loading connections" ),
685
+ tr ( " The file is not an PostGIS connections exchange file." ) );
686
+ return ;
687
+ }
688
+
689
+ QString connectionName;
690
+ QSettings settings;
691
+ settings.beginGroup ( " /MSSQL/connections" );
692
+ QStringList keys = settings.childGroups ();
693
+ settings.endGroup ();
694
+ QDomElement child = root.firstChildElement ();
695
+ bool prompt = true ;
696
+ bool overwrite = true ;
697
+
698
+ while ( !child.isNull () )
699
+ {
700
+ connectionName = child.attribute ( " name" );
701
+ if ( !items.contains ( connectionName ) )
702
+ {
703
+ child = child.nextSiblingElement ();
704
+ continue ;
705
+ }
706
+
707
+ // check for duplicates
708
+ if ( keys.contains ( connectionName ) && prompt )
709
+ {
710
+ int res = QMessageBox::warning ( this ,
711
+ tr ( " Loading connections" ),
712
+ tr ( " Connection with name '%1' already exists. Overwrite?" )
713
+ .arg ( connectionName ),
714
+ QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
715
+ switch ( res )
716
+ {
717
+ case QMessageBox::Cancel:
718
+ return ;
719
+ case QMessageBox::No:
720
+ child = child.nextSiblingElement ();
721
+ continue ;
722
+ case QMessageBox::Yes:
723
+ overwrite = true ;
724
+ break ;
725
+ case QMessageBox::YesToAll:
726
+ prompt = false ;
727
+ overwrite = true ;
728
+ break ;
729
+ case QMessageBox::NoToAll:
730
+ prompt = false ;
731
+ overwrite = false ;
732
+ break ;
733
+ }
734
+ }
735
+
736
+ if ( keys.contains ( connectionName ) && !overwrite )
737
+ {
738
+ child = child.nextSiblingElement ();
739
+ continue ;
740
+ }
741
+
742
+ // no dups detected or overwrite is allowed
743
+ settings.beginGroup ( " /MSSQL/connections/" + connectionName );
744
+
745
+ settings.setValue ( " /host" , child.attribute ( " host" ) );
746
+ settings.setValue ( " /port" , child.attribute ( " port" ) );
747
+ settings.setValue ( " /database" , child.attribute ( " database" ) );
748
+ if ( child.hasAttribute ( " service" ) )
749
+ {
750
+ settings.setValue ( " /service" , child.attribute ( " service" ) );
751
+ }
752
+ else
753
+ {
754
+ settings.setValue ( " /service" , " " );
755
+ }
756
+ settings.setValue ( " /sslmode" , child.attribute ( " sslmode" ) );
757
+ settings.setValue ( " /estimatedMetadata" , child.attribute ( " estimatedMetadata" ) );
758
+ settings.setValue ( " /saveUsername" , child.attribute ( " saveUsername" ) );
759
+ settings.setValue ( " /username" , child.attribute ( " username" ) );
760
+ settings.setValue ( " /savePassword" , child.attribute ( " savePassword" ) );
761
+ settings.setValue ( " /password" , child.attribute ( " password" ) );
762
+ settings.endGroup ();
763
+
764
+ child = child.nextSiblingElement ();
765
+ }
766
+ }
767
+
619
768
void QgsManageConnectionsDialog::selectAll ()
620
769
{
621
770
listConnections->selectAll ();
0 commit comments