18 #include <QCloseEvent>
19 #include <QFileDialog>
20 #include <QMessageBox>
21 #include <QPushButton>
23 #include <QTextStream>
29 , mFileName( fileName )
31 , mConnectionType( type )
38 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
42 buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
45 if ( mDialogMode ==
Import )
47 label->setText(
tr(
"Select connections to import" ) );
48 buttonBox->button( QDialogButtonBox::Ok )->setText(
tr(
"Import" ) );
49 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
54 buttonBox->button( QDialogButtonBox::Ok )->setText(
tr(
"Export" ) );
55 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
58 if ( !populateConnections() )
72 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
81 tr(
"You should select at least one connection from list." ) );
86 for (
int i = 0; i < selection.
size(); ++i )
88 items.
append( selection.
at( i )->text() );
91 if ( mDialogMode ==
Export )
94 tr(
"XML files (*.xml *.XML)" ) );
106 mFileName = fileName;
109 switch ( mConnectionType )
112 doc = saveOWSConnections( items,
"WMS" );
115 doc = saveWFSConnections( items );
118 doc = savePgConnections( items );
121 doc = saveMssqlConnections( items );
124 doc = saveOWSConnections( items,
"WCS" );
127 doc = saveOracleConnections( items );
131 QFile file( mFileName );
132 if ( !file.
open( QIODevice::WriteOnly | QIODevice::Text ) )
135 tr(
"Cannot write file %1:\n%2." )
146 QFile file( mFileName );
147 if ( !file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
150 tr(
"Cannot read file %1:\n%2." )
161 if ( !doc.
setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
164 tr(
"Parse error at line %1, column %2:\n%3" )
171 switch ( mConnectionType )
174 loadOWSConnections( doc, items,
"WMS" );
177 loadWFSConnections( doc, items );
180 loadPgConnections( doc, items );
183 loadMssqlConnections( doc, items );
186 loadOWSConnections( doc, items,
"WCS" );
189 loadOracleConnections( doc, items );
193 listConnections->clear();
200 bool QgsManageConnectionsDialog::populateConnections()
203 if ( mDialogMode ==
Export )
206 switch ( mConnectionType )
209 settings.
beginGroup(
"/Qgis/connections-wms" );
212 settings.
beginGroup(
"/Qgis/connections-wfs" );
215 settings.
beginGroup(
"/Qgis/connections-wcs" );
218 settings.
beginGroup(
"/PostgreSQL/connections" );
229 while ( it != keys.
end() )
233 listConnections->addItem( item );
241 QFile file( mFileName );
242 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
245 tr(
"Cannot read file %1:\n%2." )
247 .arg( file.errorString() ) );
256 if ( !doc.
setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
259 tr(
"Parse error at line %1, column %2:\n%3" )
267 switch ( mConnectionType )
270 if ( root.
tagName() !=
"qgsWMSConnections" )
273 tr(
"The file is not an WMS connections exchange file." ) );
279 if ( root.
tagName() !=
"qgsWFSConnections" )
282 tr(
"The file is not an WFS connections exchange file." ) );
288 if ( root.
tagName() !=
"qgsWCSConnections" )
291 tr(
"The file is not an WCS connections exchange file." ) );
297 if ( root.
tagName() !=
"qgsPgConnections" )
300 tr(
"The file is not an PostGIS connections exchange file." ) );
306 if ( root.
tagName() !=
"qgsMssqlConnections" )
309 tr(
"The file is not an MSSQL connections exchange file." ) );
314 if ( root.
tagName() !=
"qgsOracleConnections" )
317 tr(
"The file is not an Oracle connections exchange file." ) );
328 listConnections->addItem( item );
344 for (
int i = 0; i < connections.
count(); ++i )
346 path =
"/Qgis/connections-" + service.
toLower() +
"/";
351 if ( service ==
"WMS" )
353 el.
setAttribute(
"ignoreGetMapURI", settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).
toBool() ?
"true" :
"false" );
354 el.
setAttribute(
"ignoreGetFeatureInfoURI", settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).
toBool() ?
"true" :
"false" );
355 el.
setAttribute(
"ignoreAxisOrientation", settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).
toBool() ?
"true" :
"false" );
356 el.
setAttribute(
"invertAxisOrientation", settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).
toBool() ?
"true" :
"false" );
358 el.
setAttribute(
"smoothPixmapTransform", settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).
toBool() ?
"true" :
"false" );
362 path =
"/Qgis/" + service.
toUpper() +
"/";
380 for (
int i = 0; i < connections.
count(); ++i )
382 path =
"/Qgis/connections-wfs/";
407 for (
int i = 0; i < connections.
count(); ++i )
409 path =
"/PostgreSQL/connections/" + connections[ i ];
421 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
428 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
448 for (
int i = 0; i < connections.
count(); ++i )
450 path =
"/MSSQL/connections/" + connections[ i ];
462 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
469 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
489 for (
int i = 0; i < connections.
count(); ++i )
491 path =
"/Oracle/connections/" + connections[ i ];
505 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
512 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
526 if ( root.
tagName() !=
"qgs" + service.
toUpper() +
"Connections" )
529 tr(
"The file is not an %1 connections exchange file." ).arg( service ) );
540 bool overwrite =
true;
544 connectionName = child.
attribute(
"name" );
545 if ( !items.
contains( connectionName ) )
552 if ( keys.
contains( connectionName ) && prompt )
555 tr(
"Loading connections" ),
556 tr(
"Connection with name '%1' already exists. Overwrite?" )
557 .arg( connectionName ),
558 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
562 case QMessageBox::Cancel:
564 case QMessageBox::No:
567 case QMessageBox::Yes:
570 case QMessageBox::YesToAll:
574 case QMessageBox::NoToAll:
581 if ( keys.
contains( connectionName ) && !overwrite )
590 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreGetMapURI" ), child.
attribute(
"ignoreGetMapURI" ) ==
"true" );
591 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreGetFeatureInfoURI" ), child.
attribute(
"ignoreGetFeatureInfoURI" ) ==
"true" );
592 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreAxisOrientation" ), child.
attribute(
"ignoreAxisOrientation" ) ==
"true" );
593 settings.
setValue(
QString(
"/" + connectionName +
"/invertAxisOrientation" ), child.
attribute(
"invertAxisOrientation" ) ==
"true" );
595 settings.
setValue(
QString(
"/" + connectionName +
"/smoothPixmapTransform" ), child.
attribute(
"smoothPixmapTransform" ) ==
"true" );
613 if ( root.
tagName() !=
"qgsWFSConnections" )
616 tr(
"The file is not an WFS connections exchange file." ) );
622 settings.
beginGroup(
"/Qgis/connections-wfs" );
627 bool overwrite =
true;
631 connectionName = child.
attribute(
"name" );
632 if ( !items.
contains( connectionName ) )
639 if ( keys.
contains( connectionName ) && prompt )
642 tr(
"Loading connections" ),
643 tr(
"Connection with name '%1' already exists. Overwrite?" )
644 .arg( connectionName ),
645 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
649 case QMessageBox::Cancel:
651 case QMessageBox::No:
654 case QMessageBox::Yes:
657 case QMessageBox::YesToAll:
661 case QMessageBox::NoToAll:
668 if ( keys.
contains( connectionName ) && !overwrite )
675 settings.
beginGroup(
"/Qgis/connections-wfs" );
681 settings.
beginGroup(
"/Qgis/WFS/" + connectionName );
694 if ( root.
tagName() !=
"qgsPgConnections" )
697 tr(
"Loading connections" ),
698 tr(
"The file is not an PostGIS connections exchange file." ) );
704 settings.
beginGroup(
"/PostgreSQL/connections" );
709 bool overwrite =
true;
713 connectionName = child.
attribute(
"name" );
714 if ( !items.
contains( connectionName ) )
721 if ( keys.
contains( connectionName ) && prompt )
724 tr(
"Loading connections" ),
725 tr(
"Connection with name '%1' already exists. Overwrite?" )
726 .arg( connectionName ),
727 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
730 case QMessageBox::Cancel:
732 case QMessageBox::No:
735 case QMessageBox::Yes:
738 case QMessageBox::YesToAll:
742 case QMessageBox::NoToAll:
749 if ( keys.
contains( connectionName ) && !overwrite )
756 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
767 settings.
setValue(
"/service",
"" );
770 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
784 if ( root.
tagName() !=
"qgsMssqlConnections" )
787 tr(
"Loading connections" ),
788 tr(
"The file is not an MSSQL connections exchange file." ) );
799 bool overwrite =
true;
803 connectionName = child.
attribute(
"name" );
804 if ( !items.
contains( connectionName ) )
811 if ( keys.
contains( connectionName ) && prompt )
814 tr(
"Loading connections" ),
815 tr(
"Connection with name '%1' already exists. Overwrite?" )
816 .arg( connectionName ),
817 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
820 case QMessageBox::Cancel:
822 case QMessageBox::No:
825 case QMessageBox::Yes:
828 case QMessageBox::YesToAll:
832 case QMessageBox::NoToAll:
839 if ( keys.
contains( connectionName ) && !overwrite )
846 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
857 settings.
setValue(
"/service",
"" );
860 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
874 if ( root.
tagName() !=
"qgsOracleConnections" )
877 tr(
"Loading connections" ),
878 tr(
"The file is not an Oracle connections exchange file." ) );
889 bool overwrite =
true;
893 connectionName = child.
attribute(
"name" );
894 if ( !items.
contains( connectionName ) )
901 if ( keys.
contains( connectionName ) && prompt )
904 tr(
"Loading connections" ),
905 tr(
"Connection with name '%1' already exists. Overwrite?" )
906 .arg( connectionName ),
907 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
910 case QMessageBox::Cancel:
912 case QMessageBox::No:
915 case QMessageBox::Yes:
918 case QMessageBox::YesToAll:
922 case QMessageBox::NoToAll:
929 if ( keys.
contains( connectionName ) && !overwrite )
936 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
942 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
944 settings.
setValue(
"/geometryColumnsOnly", child.
attribute(
"geometryColumnsOnly" ) );
945 settings.
setValue(
"/allowGeometrylessTables", child.
attribute(
"allowGeometrylessTables" ) );
958 listConnections->selectAll();
959 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
964 listConnections->clearSelection();
965 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
QString errorString() const
const T & at(int i) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QDomElement nextSiblingElement(const QString &tagName) const
QDomElement documentElement() const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setValue(const QString &key, const QVariant &value)
int count(const T &value) const
void append(const T &value)
int toInt(bool *ok) const
bool hasAttribute(const QString &name) const
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
QStringList childGroups() const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QVariant value(const QString &key, const QVariant &defaultValue) const
void save(QTextStream &str, int indent) const
QgsManageConnectionsDialog(QWidget *parent=NULL, Mode mode=Export, Type type=WMS, QString fileName="")
QDomElement firstChildElement(const QString &tagName) const
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QDomElement createElement(const QString &tagName)
void postEvent(QObject *receiver, QEvent *event)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void beginGroup(const QString &prefix)
void setText(const QString &text)
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)