|
Quantum GIS API Documentation
master-693a1fe
|
00001 /*************************************************************************** 00002 qgsmanageconnectionsdialog.cpp 00003 --------------------- 00004 begin : Dec 2009 00005 copyright : (C) 2009 by Alexander Bruy 00006 email : alexander dot bruy at gmail dot com 00007 00008 *************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 00018 #include <QCloseEvent> 00019 #include <QFileDialog> 00020 #include <QMessageBox> 00021 #include <QPushButton> 00022 #include <QSettings> 00023 #include <QTextStream> 00024 00025 #include "qgsmanageconnectionsdialog.h" 00026 00027 QgsManageConnectionsDialog::QgsManageConnectionsDialog( QWidget *parent, Mode mode, Type type, QString fileName ) 00028 : QDialog( parent ) 00029 , mFileName( fileName ) 00030 , mDialogMode( mode ) 00031 , mConnectionType( type ) 00032 { 00033 setupUi( this ); 00034 00035 // additional buttons 00036 QPushButton *pb; 00037 pb = new QPushButton( tr( "Select all" ) ); 00038 buttonBox->addButton( pb, QDialogButtonBox::ActionRole ); 00039 connect( pb, SIGNAL( clicked() ), this, SLOT( selectAll() ) ); 00040 00041 pb = new QPushButton( tr( "Clear selection" ) ); 00042 buttonBox->addButton( pb, QDialogButtonBox::ActionRole ); 00043 connect( pb, SIGNAL( clicked() ), this, SLOT( clearSelection() ) ); 00044 00045 if ( mDialogMode == Import ) 00046 { 00047 label->setText( tr( "Select connections to import" ) ); 00048 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) ); 00049 } 00050 else 00051 { 00052 //label->setText( tr( "Select connections to export" ) ); 00053 buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Export" ) ); 00054 } 00055 00056 if ( !populateConnections() ) 00057 { 00058 QApplication::postEvent( this, new QCloseEvent() ); 00059 } 00060 00061 // use Ok button for starting import and export operations 00062 disconnect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); 00063 connect( buttonBox, SIGNAL( accepted() ), this, SLOT( doExportImport() ) ); 00064 } 00065 00066 void QgsManageConnectionsDialog::doExportImport() 00067 { 00068 QList<QListWidgetItem *> selection = listConnections->selectedItems(); 00069 if ( selection.isEmpty() ) 00070 { 00071 QMessageBox::warning( this, tr( "Export/import error" ), 00072 tr( "You should select at least one connection from list." ) ); 00073 return; 00074 } 00075 00076 QStringList items; 00077 for ( int i = 0; i < selection.size(); ++i ) 00078 { 00079 items.append( selection.at( i )->text() ); 00080 } 00081 00082 if ( mDialogMode == Export ) 00083 { 00084 QString fileName = QFileDialog::getSaveFileName( this, tr( "Save connections" ), ".", 00085 tr( "XML files (*.xml *.XML)" ) ); 00086 if ( fileName.isEmpty() ) 00087 { 00088 return; 00089 } 00090 00091 // ensure the user never ommited the extension from the file name 00092 if ( !fileName.toLower().endsWith( ".xml" ) ) 00093 { 00094 fileName += ".xml"; 00095 } 00096 00097 mFileName = fileName; 00098 00099 QDomDocument doc; 00100 switch ( mConnectionType ) 00101 { 00102 case WMS: 00103 doc = saveOWSConnections( items, "WMS" ); 00104 break; 00105 case WFS: 00106 doc = saveWFSConnections( items ); 00107 break; 00108 case PostGIS: 00109 doc = savePgConnections( items ); 00110 break; 00111 case MSSQL: 00112 doc = saveMssqlConnections( items ); 00113 break; 00114 case WCS: 00115 doc = saveOWSConnections( items, "WCS" ); 00116 break; 00117 case Oracle: 00118 doc = saveOracleConnections( items ); 00119 break; 00120 } 00121 00122 QFile file( mFileName ); 00123 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) 00124 { 00125 QMessageBox::warning( this, tr( "Saving connections" ), 00126 tr( "Cannot write file %1:\n%2." ) 00127 .arg( mFileName ) 00128 .arg( file.errorString() ) ); 00129 return; 00130 } 00131 00132 QTextStream out( &file ); 00133 doc.save( out, 4 ); 00134 } 00135 else // import connections 00136 { 00137 QFile file( mFileName ); 00138 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) 00139 { 00140 QMessageBox::warning( this, tr( "Loading connections" ), 00141 tr( "Cannot read file %1:\n%2." ) 00142 .arg( mFileName ) 00143 .arg( file.errorString() ) ); 00144 return; 00145 } 00146 00147 QDomDocument doc; 00148 QString errorStr; 00149 int errorLine; 00150 int errorColumn; 00151 00152 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) ) 00153 { 00154 QMessageBox::warning( this, tr( "Loading connections" ), 00155 tr( "Parse error at line %1, column %2:\n%3" ) 00156 .arg( errorLine ) 00157 .arg( errorColumn ) 00158 .arg( errorStr ) ); 00159 return; 00160 } 00161 00162 switch ( mConnectionType ) 00163 { 00164 case WMS: 00165 loadOWSConnections( doc, items, "WMS" ); 00166 break; 00167 case WFS: 00168 loadWFSConnections( doc, items ); 00169 break; 00170 case PostGIS: 00171 loadPgConnections( doc, items ); 00172 break; 00173 case MSSQL: 00174 loadMssqlConnections( doc, items ); 00175 break; 00176 case WCS: 00177 loadOWSConnections( doc, items, "WCS" ); 00178 break; 00179 case Oracle: 00180 loadOracleConnections( doc, items ); 00181 break; 00182 } 00183 // clear connections list and close window 00184 listConnections->clear(); 00185 accept(); 00186 } 00187 00188 mFileName = ""; 00189 } 00190 00191 bool QgsManageConnectionsDialog::populateConnections() 00192 { 00193 // Export mode. Populate connections list from settings 00194 if ( mDialogMode == Export ) 00195 { 00196 QSettings settings; 00197 switch ( mConnectionType ) 00198 { 00199 case WMS: 00200 settings.beginGroup( "/Qgis/connections-wms" ); 00201 break; 00202 case WFS: 00203 settings.beginGroup( "/Qgis/connections-wfs" ); 00204 break; 00205 case WCS: 00206 settings.beginGroup( "/Qgis/connections-wcs" ); 00207 break; 00208 case PostGIS: 00209 settings.beginGroup( "/PostgreSQL/connections" ); 00210 break; 00211 case MSSQL: 00212 settings.beginGroup( "/MSSQL/connections" ); 00213 break; 00214 case Oracle: 00215 settings.beginGroup( "/Oracle/connections" ); 00216 break; 00217 } 00218 QStringList keys = settings.childGroups(); 00219 QStringList::Iterator it = keys.begin(); 00220 while ( it != keys.end() ) 00221 { 00222 QListWidgetItem *item = new QListWidgetItem(); 00223 item->setText( *it ); 00224 listConnections->addItem( item ); 00225 ++it; 00226 } 00227 settings.endGroup(); 00228 } 00229 // Import mode. Populate connections list from file 00230 else 00231 { 00232 QFile file( mFileName ); 00233 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) 00234 { 00235 QMessageBox::warning( this, tr( "Loading connections" ), 00236 tr( "Cannot read file %1:\n%2." ) 00237 .arg( mFileName ) 00238 .arg( file.errorString() ) ); 00239 return false; 00240 } 00241 00242 QDomDocument doc; 00243 QString errorStr; 00244 int errorLine; 00245 int errorColumn; 00246 00247 if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) ) 00248 { 00249 QMessageBox::warning( this, tr( "Loading connections" ), 00250 tr( "Parse error at line %1, column %2:\n%3" ) 00251 .arg( errorLine ) 00252 .arg( errorColumn ) 00253 .arg( errorStr ) ); 00254 return false; 00255 } 00256 00257 QDomElement root = doc.documentElement(); 00258 switch ( mConnectionType ) 00259 { 00260 case WMS: 00261 if ( root.tagName() != "qgsWMSConnections" ) 00262 { 00263 QMessageBox::information( this, tr( "Loading connections" ), 00264 tr( "The file is not an WMS connections exchange file." ) ); 00265 return false; 00266 } 00267 break; 00268 00269 case WFS: 00270 if ( root.tagName() != "qgsWFSConnections" ) 00271 { 00272 QMessageBox::information( this, tr( "Loading connections" ), 00273 tr( "The file is not an WFS connections exchange file." ) ); 00274 return false; 00275 } 00276 break; 00277 00278 case WCS: 00279 if ( root.tagName() != "qgsWCSConnections" ) 00280 { 00281 QMessageBox::information( this, tr( "Loading connections" ), 00282 tr( "The file is not an WCS connections exchange file." ) ); 00283 return false; 00284 } 00285 break; 00286 00287 case PostGIS: 00288 if ( root.tagName() != "qgsPgConnections" ) 00289 { 00290 QMessageBox::information( this, tr( "Loading connections" ), 00291 tr( "The file is not an PostGIS connections exchange file." ) ); 00292 return false; 00293 } 00294 break; 00295 00296 case MSSQL: 00297 if ( root.tagName() != "qgsMssqlConnections" ) 00298 { 00299 QMessageBox::information( this, tr( "Loading connections" ), 00300 tr( "The file is not an MSSQL connections exchange file." ) ); 00301 return false; 00302 } 00303 break; 00304 case Oracle: 00305 if ( root.tagName() != "qgsOracleConnections" ) 00306 { 00307 QMessageBox::information( this, tr( "Loading connections" ), 00308 tr( "The file is not an Oracle connections exchange file." ) ); 00309 return false; 00310 } 00311 break; 00312 } 00313 00314 QDomElement child = root.firstChildElement(); 00315 while ( !child.isNull() ) 00316 { 00317 QListWidgetItem *item = new QListWidgetItem(); 00318 item->setText( child.attribute( "name" ) ); 00319 listConnections->addItem( item ); 00320 child = child.nextSiblingElement(); 00321 } 00322 } 00323 return true; 00324 } 00325 00326 QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &connections, const QString & service ) 00327 { 00328 QDomDocument doc( "connections" ); 00329 QDomElement root = doc.createElement( "qgs" + service.toUpper() + "Connections" ); 00330 root.setAttribute( "version", "1.0" ); 00331 doc.appendChild( root ); 00332 00333 QSettings settings; 00334 QString path; 00335 for ( int i = 0; i < connections.count(); ++i ) 00336 { 00337 path = "/Qgis/connections-" + service.toLower() + "/"; 00338 QDomElement el = doc.createElement( service.toLower() ); 00339 el.setAttribute( "name", connections[ i ] ); 00340 el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() ); 00341 00342 if ( service == "WMS" ) 00343 { 00344 el.setAttribute( "ignoreGetMapURI", settings.value( path + connections[i] + "/ignoreGetMapURI", false ).toBool() ? "true" : "false" ); 00345 el.setAttribute( "ignoreGetFeatureInfoURI", settings.value( path + connections[i] + "/ignoreGetFeatureInfoURI", false ).toBool() ? "true" : "false" ); 00346 el.setAttribute( "ignoreAxisOrientation", settings.value( path + connections[i] + "/ignoreAxisOrientation", false ).toBool() ? "true" : "false" ); 00347 el.setAttribute( "invertAxisOrientation", settings.value( path + connections[i] + "/invertAxisOrientation", false ).toBool() ? "true" : "false" ); 00348 el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() ); 00349 el.setAttribute( "smoothPixmapTransform", settings.value( path + connections[i] + "/smoothPixmapTransform", false ).toBool() ? "true" : "false" ); 00350 } 00351 00352 path = "/Qgis/" + service.toUpper() + "/"; 00353 el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() ); 00354 el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() ); 00355 root.appendChild( el ); 00356 } 00357 00358 return doc; 00359 } 00360 00361 QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &connections ) 00362 { 00363 QDomDocument doc( "connections" ); 00364 QDomElement root = doc.createElement( "qgsWFSConnections" ); 00365 root.setAttribute( "version", "1.0" ); 00366 doc.appendChild( root ); 00367 00368 QSettings settings; 00369 QString path; 00370 for ( int i = 0; i < connections.count(); ++i ) 00371 { 00372 path = "/Qgis/connections-wfs/"; 00373 QDomElement el = doc.createElement( "wfs" ); 00374 el.setAttribute( "name", connections[ i ] ); 00375 el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() ); 00376 00377 el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() ); 00378 00379 path = "/Qgis/WFS/"; 00380 el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() ); 00381 el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() ); 00382 root.appendChild( el ); 00383 } 00384 00385 return doc; 00386 } 00387 00388 QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &connections ) 00389 { 00390 QDomDocument doc( "connections" ); 00391 QDomElement root = doc.createElement( "qgsPgConnections" ); 00392 root.setAttribute( "version", "1.0" ); 00393 doc.appendChild( root ); 00394 00395 QSettings settings; 00396 QString path; 00397 for ( int i = 0; i < connections.count(); ++i ) 00398 { 00399 path = "/PostgreSQL/connections/" + connections[ i ]; 00400 QDomElement el = doc.createElement( "postgis" ); 00401 el.setAttribute( "name", connections[ i ] ); 00402 el.setAttribute( "host", settings.value( path + "/host", "" ).toString() ); 00403 el.setAttribute( "port", settings.value( path + "/port", "" ).toString() ); 00404 el.setAttribute( "database", settings.value( path + "/database", "" ).toString() ); 00405 el.setAttribute( "service", settings.value( path + "/service", "" ).toString() ); 00406 el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() ); 00407 el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() ); 00408 00409 el.setAttribute( "saveUsername", settings.value( path + "/saveUsername", "false" ).toString() ); 00410 00411 if ( settings.value( path + "/saveUsername", "false" ).toString() == "true" ) 00412 { 00413 el.setAttribute( "username", settings.value( path + "/username", "" ).toString() ); 00414 } 00415 00416 el.setAttribute( "savePassword", settings.value( path + "/savePassword", "false" ).toString() ); 00417 00418 if ( settings.value( path + "/savePassword", "false" ).toString() == "true" ) 00419 { 00420 el.setAttribute( "password", settings.value( path + "/password", "" ).toString() ); 00421 } 00422 00423 root.appendChild( el ); 00424 } 00425 00426 return doc; 00427 } 00428 00429 QDomDocument QgsManageConnectionsDialog::saveMssqlConnections( const QStringList &connections ) 00430 { 00431 QDomDocument doc( "connections" ); 00432 QDomElement root = doc.createElement( "qgsMssqlConnections" ); 00433 root.setAttribute( "version", "1.0" ); 00434 doc.appendChild( root ); 00435 00436 QSettings settings; 00437 QString path; 00438 for ( int i = 0; i < connections.count(); ++i ) 00439 { 00440 path = "/MSSQL/connections/" + connections[ i ]; 00441 QDomElement el = doc.createElement( "mssql" ); 00442 el.setAttribute( "name", connections[ i ] ); 00443 el.setAttribute( "host", settings.value( path + "/host", "" ).toString() ); 00444 el.setAttribute( "port", settings.value( path + "/port", "" ).toString() ); 00445 el.setAttribute( "database", settings.value( path + "/database", "" ).toString() ); 00446 el.setAttribute( "service", settings.value( path + "/service", "" ).toString() ); 00447 el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() ); 00448 el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() ); 00449 00450 el.setAttribute( "saveUsername", settings.value( path + "/saveUsername", "false" ).toString() ); 00451 00452 if ( settings.value( path + "/saveUsername", "false" ).toString() == "true" ) 00453 { 00454 el.setAttribute( "username", settings.value( path + "/username", "" ).toString() ); 00455 } 00456 00457 el.setAttribute( "savePassword", settings.value( path + "/savePassword", "false" ).toString() ); 00458 00459 if ( settings.value( path + "/savePassword", "false" ).toString() == "true" ) 00460 { 00461 el.setAttribute( "password", settings.value( path + "/password", "" ).toString() ); 00462 } 00463 00464 root.appendChild( el ); 00465 } 00466 00467 return doc; 00468 } 00469 00470 QDomDocument QgsManageConnectionsDialog::saveOracleConnections( const QStringList &connections ) 00471 { 00472 QDomDocument doc( "connections" ); 00473 QDomElement root = doc.createElement( "qgsOracleConnections" ); 00474 root.setAttribute( "version", "1.0" ); 00475 doc.appendChild( root ); 00476 00477 QSettings settings; 00478 QString path; 00479 for ( int i = 0; i < connections.count(); ++i ) 00480 { 00481 path = "/Oracle/connections/" + connections[ i ]; 00482 QDomElement el = doc.createElement( "oracle" ); 00483 el.setAttribute( "name", connections[ i ] ); 00484 el.setAttribute( "host", settings.value( path + "/host", "" ).toString() ); 00485 el.setAttribute( "port", settings.value( path + "/port", "" ).toString() ); 00486 el.setAttribute( "database", settings.value( path + "/database", "" ).toString() ); 00487 el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() ); 00488 el.setAttribute( "userTablesOnly", settings.value( path + "/userTablesOnly", "0" ).toString() ); 00489 el.setAttribute( "geometryColumnsOnly", settings.value( path + "/geometryColumnsOnly", "0" ).toString() ); 00490 el.setAttribute( "allowGeometrylessTables", settings.value( path + "/allowGeometrylessTables", "0" ).toString() ); 00491 00492 el.setAttribute( "saveUsername", settings.value( path + "/saveUsername", "false" ).toString() ); 00493 00494 if ( settings.value( path + "/saveUsername", "false" ).toString() == "true" ) 00495 { 00496 el.setAttribute( "username", settings.value( path + "/username", "" ).toString() ); 00497 } 00498 00499 el.setAttribute( "savePassword", settings.value( path + "/savePassword", "false" ).toString() ); 00500 00501 if ( settings.value( path + "/savePassword", "false" ).toString() == "true" ) 00502 { 00503 el.setAttribute( "password", settings.value( path + "/password", "" ).toString() ); 00504 } 00505 00506 root.appendChild( el ); 00507 } 00508 00509 return doc; 00510 } 00511 00512 void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, const QStringList &items, const QString &service ) 00513 { 00514 QDomElement root = doc.documentElement(); 00515 if ( root.tagName() != "qgs" + service.toUpper() + "Connections" ) 00516 { 00517 QMessageBox::information( this, tr( "Loading connections" ), 00518 tr( "The file is not an %1 connections exchange file." ).arg( service ) ); 00519 return; 00520 } 00521 00522 QString connectionName; 00523 QSettings settings; 00524 settings.beginGroup( "/Qgis/connections-" + service.toLower() ); 00525 QStringList keys = settings.childGroups(); 00526 settings.endGroup(); 00527 QDomElement child = root.firstChildElement(); 00528 bool prompt = true; 00529 bool overwrite = true; 00530 00531 while ( !child.isNull() ) 00532 { 00533 connectionName = child.attribute( "name" ); 00534 if ( !items.contains( connectionName ) ) 00535 { 00536 child = child.nextSiblingElement(); 00537 continue; 00538 } 00539 00540 // check for duplicates 00541 if ( keys.contains( connectionName ) && prompt ) 00542 { 00543 int res = QMessageBox::warning( this, 00544 tr( "Loading connections" ), 00545 tr( "Connection with name '%1' already exists. Overwrite?" ) 00546 .arg( connectionName ), 00547 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel ); 00548 00549 switch ( res ) 00550 { 00551 case QMessageBox::Cancel: 00552 return; 00553 case QMessageBox::No: 00554 child = child.nextSiblingElement(); 00555 continue; 00556 case QMessageBox::Yes: 00557 overwrite = true; 00558 break; 00559 case QMessageBox::YesToAll: 00560 prompt = false; 00561 overwrite = true; 00562 break; 00563 case QMessageBox::NoToAll: 00564 prompt = false; 00565 overwrite = false; 00566 break; 00567 } 00568 } 00569 00570 if ( keys.contains( connectionName ) && !overwrite ) 00571 { 00572 child = child.nextSiblingElement(); 00573 continue; 00574 } 00575 00576 // no dups detected or overwrite is allowed 00577 settings.beginGroup( "/Qgis/connections-" + service.toLower() ); 00578 settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) ); 00579 settings.setValue( QString( "/" + connectionName + "/ignoreGetMapURI" ), child.attribute( "ignoreGetMapURI" ) == "true" ); 00580 settings.setValue( QString( "/" + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( "ignoreGetFeatureInfoURI" ) == "true" ); 00581 settings.setValue( QString( "/" + connectionName + "/ignoreAxisOrientation" ), child.attribute( "ignoreAxisOrientation" ) == "true" ); 00582 settings.setValue( QString( "/" + connectionName + "/invertAxisOrientation" ), child.attribute( "invertAxisOrientation" ) == "true" ); 00583 settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) ); 00584 settings.setValue( QString( "/" + connectionName + "/smoothPixmapTransform" ), child.attribute( "smoothPixmapTransform" ) == "true" ); 00585 settings.endGroup(); 00586 00587 if ( !child.attribute( "username" ).isEmpty() ) 00588 { 00589 settings.beginGroup( "/Qgis/" + service.toUpper() + "/" + connectionName ); 00590 settings.setValue( "/username", child.attribute( "username" ) ); 00591 settings.setValue( "/password", child.attribute( "password" ) ); 00592 settings.endGroup(); 00593 } 00594 child = child.nextSiblingElement(); 00595 } 00596 } 00597 00598 void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, const QStringList &items ) 00599 { 00600 QDomElement root = doc.documentElement(); 00601 if ( root.tagName() != "qgsWFSConnections" ) 00602 { 00603 QMessageBox::information( this, tr( "Loading connections" ), 00604 tr( "The file is not an WFS connections exchange file." ) ); 00605 return; 00606 } 00607 00608 QString connectionName; 00609 QSettings settings; 00610 settings.beginGroup( "/Qgis/connections-wfs" ); 00611 QStringList keys = settings.childGroups(); 00612 settings.endGroup(); 00613 QDomElement child = root.firstChildElement(); 00614 bool prompt = true; 00615 bool overwrite = true; 00616 00617 while ( !child.isNull() ) 00618 { 00619 connectionName = child.attribute( "name" ); 00620 if ( !items.contains( connectionName ) ) 00621 { 00622 child = child.nextSiblingElement(); 00623 continue; 00624 } 00625 00626 // check for duplicates 00627 if ( keys.contains( connectionName ) && prompt ) 00628 { 00629 int res = QMessageBox::warning( this, 00630 tr( "Loading connections" ), 00631 tr( "Connection with name '%1' already exists. Overwrite?" ) 00632 .arg( connectionName ), 00633 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel ); 00634 00635 switch ( res ) 00636 { 00637 case QMessageBox::Cancel: 00638 return; 00639 case QMessageBox::No: 00640 child = child.nextSiblingElement(); 00641 continue; 00642 case QMessageBox::Yes: 00643 overwrite = true; 00644 break; 00645 case QMessageBox::YesToAll: 00646 prompt = false; 00647 overwrite = true; 00648 break; 00649 case QMessageBox::NoToAll: 00650 prompt = false; 00651 overwrite = false; 00652 break; 00653 } 00654 } 00655 00656 if ( keys.contains( connectionName ) && !overwrite ) 00657 { 00658 child = child.nextSiblingElement(); 00659 continue; 00660 } 00661 00662 // no dups detected or overwrite is allowed 00663 settings.beginGroup( "/Qgis/connections-wfs" ); 00664 settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) ); 00665 settings.endGroup(); 00666 00667 if ( !child.attribute( "username" ).isEmpty() ) 00668 { 00669 settings.beginGroup( "/Qgis/WFS/" + connectionName ); 00670 settings.setValue( "/username", child.attribute( "username" ) ); 00671 settings.setValue( "/password", child.attribute( "password" ) ); 00672 settings.endGroup(); 00673 } 00674 child = child.nextSiblingElement(); 00675 } 00676 } 00677 00678 00679 void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, const QStringList &items ) 00680 { 00681 QDomElement root = doc.documentElement(); 00682 if ( root.tagName() != "qgsPgConnections" ) 00683 { 00684 QMessageBox::information( this, 00685 tr( "Loading connections" ), 00686 tr( "The file is not an PostGIS connections exchange file." ) ); 00687 return; 00688 } 00689 00690 QString connectionName; 00691 QSettings settings; 00692 settings.beginGroup( "/PostgreSQL/connections" ); 00693 QStringList keys = settings.childGroups(); 00694 settings.endGroup(); 00695 QDomElement child = root.firstChildElement(); 00696 bool prompt = true; 00697 bool overwrite = true; 00698 00699 while ( !child.isNull() ) 00700 { 00701 connectionName = child.attribute( "name" ); 00702 if ( !items.contains( connectionName ) ) 00703 { 00704 child = child.nextSiblingElement(); 00705 continue; 00706 } 00707 00708 // check for duplicates 00709 if ( keys.contains( connectionName ) && prompt ) 00710 { 00711 int res = QMessageBox::warning( this, 00712 tr( "Loading connections" ), 00713 tr( "Connection with name '%1' already exists. Overwrite?" ) 00714 .arg( connectionName ), 00715 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel ); 00716 switch ( res ) 00717 { 00718 case QMessageBox::Cancel: 00719 return; 00720 case QMessageBox::No: 00721 child = child.nextSiblingElement(); 00722 continue; 00723 case QMessageBox::Yes: 00724 overwrite = true; 00725 break; 00726 case QMessageBox::YesToAll: 00727 prompt = false; 00728 overwrite = true; 00729 break; 00730 case QMessageBox::NoToAll: 00731 prompt = false; 00732 overwrite = false; 00733 break; 00734 } 00735 } 00736 00737 if ( keys.contains( connectionName ) && !overwrite ) 00738 { 00739 child = child.nextSiblingElement(); 00740 continue; 00741 } 00742 00743 //no dups detected or overwrite is allowed 00744 settings.beginGroup( "/PostgreSQL/connections/" + connectionName ); 00745 00746 settings.setValue( "/host", child.attribute( "host" ) ); 00747 settings.setValue( "/port", child.attribute( "port" ) ); 00748 settings.setValue( "/database", child.attribute( "database" ) ); 00749 if ( child.hasAttribute( "service" ) ) 00750 { 00751 settings.setValue( "/service", child.attribute( "service" ) ); 00752 } 00753 else 00754 { 00755 settings.setValue( "/service", "" ); 00756 } 00757 settings.setValue( "/sslmode", child.attribute( "sslmode" ) ); 00758 settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) ); 00759 settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) ); 00760 settings.setValue( "/username", child.attribute( "username" ) ); 00761 settings.setValue( "/savePassword", child.attribute( "savePassword" ) ); 00762 settings.setValue( "/password", child.attribute( "password" ) ); 00763 settings.endGroup(); 00764 00765 child = child.nextSiblingElement(); 00766 } 00767 } 00768 00769 void QgsManageConnectionsDialog::loadMssqlConnections( const QDomDocument &doc, const QStringList &items ) 00770 { 00771 QDomElement root = doc.documentElement(); 00772 if ( root.tagName() != "qgsMssqlConnections" ) 00773 { 00774 QMessageBox::information( this, 00775 tr( "Loading connections" ), 00776 tr( "The file is not an MSSQL connections exchange file." ) ); 00777 return; 00778 } 00779 00780 QString connectionName; 00781 QSettings settings; 00782 settings.beginGroup( "/MSSQL/connections" ); 00783 QStringList keys = settings.childGroups(); 00784 settings.endGroup(); 00785 QDomElement child = root.firstChildElement(); 00786 bool prompt = true; 00787 bool overwrite = true; 00788 00789 while ( !child.isNull() ) 00790 { 00791 connectionName = child.attribute( "name" ); 00792 if ( !items.contains( connectionName ) ) 00793 { 00794 child = child.nextSiblingElement(); 00795 continue; 00796 } 00797 00798 // check for duplicates 00799 if ( keys.contains( connectionName ) && prompt ) 00800 { 00801 int res = QMessageBox::warning( this, 00802 tr( "Loading connections" ), 00803 tr( "Connection with name '%1' already exists. Overwrite?" ) 00804 .arg( connectionName ), 00805 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel ); 00806 switch ( res ) 00807 { 00808 case QMessageBox::Cancel: 00809 return; 00810 case QMessageBox::No: 00811 child = child.nextSiblingElement(); 00812 continue; 00813 case QMessageBox::Yes: 00814 overwrite = true; 00815 break; 00816 case QMessageBox::YesToAll: 00817 prompt = false; 00818 overwrite = true; 00819 break; 00820 case QMessageBox::NoToAll: 00821 prompt = false; 00822 overwrite = false; 00823 break; 00824 } 00825 } 00826 00827 if ( keys.contains( connectionName ) && !overwrite ) 00828 { 00829 child = child.nextSiblingElement(); 00830 continue; 00831 } 00832 00833 //no dups detected or overwrite is allowed 00834 settings.beginGroup( "/MSSQL/connections/" + connectionName ); 00835 00836 settings.setValue( "/host", child.attribute( "host" ) ); 00837 settings.setValue( "/port", child.attribute( "port" ) ); 00838 settings.setValue( "/database", child.attribute( "database" ) ); 00839 if ( child.hasAttribute( "service" ) ) 00840 { 00841 settings.setValue( "/service", child.attribute( "service" ) ); 00842 } 00843 else 00844 { 00845 settings.setValue( "/service", "" ); 00846 } 00847 settings.setValue( "/sslmode", child.attribute( "sslmode" ) ); 00848 settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) ); 00849 settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) ); 00850 settings.setValue( "/username", child.attribute( "username" ) ); 00851 settings.setValue( "/savePassword", child.attribute( "savePassword" ) ); 00852 settings.setValue( "/password", child.attribute( "password" ) ); 00853 settings.endGroup(); 00854 00855 child = child.nextSiblingElement(); 00856 } 00857 } 00858 00859 void QgsManageConnectionsDialog::loadOracleConnections( const QDomDocument &doc, const QStringList &items ) 00860 { 00861 QDomElement root = doc.documentElement(); 00862 if ( root.tagName() != "qgsOracleConnections" ) 00863 { 00864 QMessageBox::information( this, 00865 tr( "Loading connections" ), 00866 tr( "The file is not an Oracle connections exchange file." ) ); 00867 return; 00868 } 00869 00870 QString connectionName; 00871 QSettings settings; 00872 settings.beginGroup( "/Oracle/connections" ); 00873 QStringList keys = settings.childGroups(); 00874 settings.endGroup(); 00875 QDomElement child = root.firstChildElement(); 00876 bool prompt = true; 00877 bool overwrite = true; 00878 00879 while ( !child.isNull() ) 00880 { 00881 connectionName = child.attribute( "name" ); 00882 if ( !items.contains( connectionName ) ) 00883 { 00884 child = child.nextSiblingElement(); 00885 continue; 00886 } 00887 00888 // check for duplicates 00889 if ( keys.contains( connectionName ) && prompt ) 00890 { 00891 int res = QMessageBox::warning( this, 00892 tr( "Loading connections" ), 00893 tr( "Connection with name '%1' already exists. Overwrite?" ) 00894 .arg( connectionName ), 00895 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel ); 00896 switch ( res ) 00897 { 00898 case QMessageBox::Cancel: 00899 return; 00900 case QMessageBox::No: 00901 child = child.nextSiblingElement(); 00902 continue; 00903 case QMessageBox::Yes: 00904 overwrite = true; 00905 break; 00906 case QMessageBox::YesToAll: 00907 prompt = false; 00908 overwrite = true; 00909 break; 00910 case QMessageBox::NoToAll: 00911 prompt = false; 00912 overwrite = false; 00913 break; 00914 } 00915 } 00916 00917 if ( keys.contains( connectionName ) && !overwrite ) 00918 { 00919 child = child.nextSiblingElement(); 00920 continue; 00921 } 00922 00923 //no dups detected or overwrite is allowed 00924 settings.beginGroup( "/Oracle/connections/" + connectionName ); 00925 00926 settings.setValue( "/host", child.attribute( "host" ) ); 00927 settings.setValue( "/port", child.attribute( "port" ) ); 00928 settings.setValue( "/database", child.attribute( "database" ) ); 00929 settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) ); 00930 settings.setValue( "/userTablesOnly", child.attribute( "userTablesOnly" ) ); 00931 settings.setValue( "/geometryColumnsOnly", child.attribute( "geometryColumnsOnly" ) ); 00932 settings.setValue( "/allowGeometrylessTables", child.attribute( "allowGeometrylessTables" ) ); 00933 settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) ); 00934 settings.setValue( "/username", child.attribute( "username" ) ); 00935 settings.setValue( "/savePassword", child.attribute( "savePassword" ) ); 00936 settings.setValue( "/password", child.attribute( "password" ) ); 00937 settings.endGroup(); 00938 00939 child = child.nextSiblingElement(); 00940 } 00941 } 00942 00943 void QgsManageConnectionsDialog::selectAll() 00944 { 00945 listConnections->selectAll(); 00946 } 00947 00948 void QgsManageConnectionsDialog::clearSelection() 00949 { 00950 listConnections->clearSelection(); 00951 }