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." ) );
87 for (
int i = 0; i < selection.
size(); ++i )
89 items.
append( selection.
at( i )->text() );
92 if ( mDialogMode ==
Export )
95 tr(
"XML files (*.xml *.XML)" ) );
107 mFileName = fileName;
110 switch ( mConnectionType )
113 doc = saveOWSConnections( items,
"WMS" );
116 doc = saveWFSConnections( items );
119 doc = savePgConnections( items );
122 doc = saveMssqlConnections( items );
125 doc = saveOWSConnections( items,
"WCS" );
128 doc = saveOracleConnections( items );
132 QFile file( mFileName );
133 if ( !file.
open( QIODevice::WriteOnly | QIODevice::Text ) )
136 tr(
"Cannot write file %1:\n%2." )
147 QFile file( mFileName );
148 if ( !file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
151 tr(
"Cannot read file %1:\n%2." )
162 if ( !doc.
setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
165 tr(
"Parse error at line %1, column %2:\n%3" )
172 switch ( mConnectionType )
175 loadOWSConnections( doc, items,
"WMS" );
178 loadWFSConnections( doc, items );
181 loadPgConnections( doc, items );
184 loadMssqlConnections( doc, items );
187 loadOWSConnections( doc, items,
"WCS" );
190 loadOracleConnections( doc, items );
194 listConnections->clear();
201 bool QgsManageConnectionsDialog::populateConnections()
204 if ( mDialogMode ==
Export )
207 switch ( mConnectionType )
210 settings.
beginGroup(
"/Qgis/connections-wms" );
213 settings.
beginGroup(
"/Qgis/connections-wfs" );
216 settings.
beginGroup(
"/Qgis/connections-wcs" );
219 settings.
beginGroup(
"/PostgreSQL/connections" );
230 while ( it != keys.
end() )
234 listConnections->addItem( item );
242 QFile file( mFileName );
243 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
246 tr(
"Cannot read file %1:\n%2." )
248 file.errorString() ) );
257 if ( !doc.
setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
260 tr(
"Parse error at line %1, column %2:\n%3" )
268 switch ( mConnectionType )
271 if ( root.
tagName() !=
"qgsWMSConnections" )
274 tr(
"The file is not an WMS connections exchange file." ) );
280 if ( root.
tagName() !=
"qgsWFSConnections" )
283 tr(
"The file is not an WFS connections exchange file." ) );
289 if ( root.
tagName() !=
"qgsWCSConnections" )
292 tr(
"The file is not an WCS connections exchange file." ) );
298 if ( root.
tagName() !=
"qgsPgConnections" )
301 tr(
"The file is not an PostGIS connections exchange file." ) );
307 if ( root.
tagName() !=
"qgsMssqlConnections" )
310 tr(
"The file is not an MSSQL connections exchange file." ) );
315 if ( root.
tagName() !=
"qgsOracleConnections" )
318 tr(
"The file is not an Oracle connections exchange file." ) );
329 listConnections->addItem( item );
345 for (
int i = 0; i < connections.
count(); ++i )
347 path =
"/Qgis/connections-" + service.
toLower() +
"/";
352 if ( service ==
"WMS" )
354 el.
setAttribute(
"ignoreGetMapURI", settings.
value( path + connections[i] +
"/ignoreGetMapURI",
false ).
toBool() ?
"true" :
"false" );
355 el.
setAttribute(
"ignoreGetFeatureInfoURI", settings.
value( path + connections[i] +
"/ignoreGetFeatureInfoURI",
false ).
toBool() ?
"true" :
"false" );
356 el.
setAttribute(
"ignoreAxisOrientation", settings.
value( path + connections[i] +
"/ignoreAxisOrientation",
false ).
toBool() ?
"true" :
"false" );
357 el.
setAttribute(
"invertAxisOrientation", settings.
value( path + connections[i] +
"/invertAxisOrientation",
false ).
toBool() ?
"true" :
"false" );
359 el.
setAttribute(
"smoothPixmapTransform", settings.
value( path + connections[i] +
"/smoothPixmapTransform",
false ).
toBool() ?
"true" :
"false" );
363 path =
"/Qgis/" + service.
toUpper() +
"/";
381 for (
int i = 0; i < connections.
count(); ++i )
383 path =
"/Qgis/connections-wfs/";
408 for (
int i = 0; i < connections.
count(); ++i )
410 path =
"/PostgreSQL/connections/" + connections[ i ];
422 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
429 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
449 for (
int i = 0; i < connections.
count(); ++i )
451 path =
"/MSSQL/connections/" + connections[ i ];
463 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
470 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
490 for (
int i = 0; i < connections.
count(); ++i )
492 path =
"/Oracle/connections/" + connections[ i ];
506 if ( settings.
value( path +
"/saveUsername",
"false" ).
toString() ==
"true" )
513 if ( settings.
value( path +
"/savePassword",
"false" ).
toString() ==
"true" )
527 if ( root.
tagName() !=
"qgs" + service.
toUpper() +
"Connections" )
530 tr(
"The file is not an %1 connections exchange file." ).arg( service ) );
541 bool overwrite =
true;
545 connectionName = child.
attribute(
"name" );
546 if ( !items.
contains( connectionName ) )
553 if ( keys.
contains( connectionName ) && prompt )
556 tr(
"Loading connections" ),
557 tr(
"Connection with name '%1' already exists. Overwrite?" )
558 .arg( connectionName ),
559 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
563 case QMessageBox::Cancel:
565 case QMessageBox::No:
568 case QMessageBox::Yes:
571 case QMessageBox::YesToAll:
575 case QMessageBox::NoToAll:
582 if ( keys.
contains( connectionName ) && !overwrite )
591 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreGetMapURI" ), child.
attribute(
"ignoreGetMapURI" ) ==
"true" );
592 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreGetFeatureInfoURI" ), child.
attribute(
"ignoreGetFeatureInfoURI" ) ==
"true" );
593 settings.
setValue(
QString(
"/" + connectionName +
"/ignoreAxisOrientation" ), child.
attribute(
"ignoreAxisOrientation" ) ==
"true" );
594 settings.
setValue(
QString(
"/" + connectionName +
"/invertAxisOrientation" ), child.
attribute(
"invertAxisOrientation" ) ==
"true" );
596 settings.
setValue(
QString(
"/" + connectionName +
"/smoothPixmapTransform" ), child.
attribute(
"smoothPixmapTransform" ) ==
"true" );
614 if ( root.
tagName() !=
"qgsWFSConnections" )
617 tr(
"The file is not an WFS connections exchange file." ) );
623 settings.
beginGroup(
"/Qgis/connections-wfs" );
628 bool overwrite =
true;
632 connectionName = child.
attribute(
"name" );
633 if ( !items.
contains( connectionName ) )
640 if ( keys.
contains( connectionName ) && prompt )
643 tr(
"Loading connections" ),
644 tr(
"Connection with name '%1' already exists. Overwrite?" )
645 .arg( connectionName ),
646 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
650 case QMessageBox::Cancel:
652 case QMessageBox::No:
655 case QMessageBox::Yes:
658 case QMessageBox::YesToAll:
662 case QMessageBox::NoToAll:
669 if ( keys.
contains( connectionName ) && !overwrite )
676 settings.
beginGroup(
"/Qgis/connections-wfs" );
682 settings.
beginGroup(
"/Qgis/WFS/" + connectionName );
695 if ( root.
tagName() !=
"qgsPgConnections" )
698 tr(
"Loading connections" ),
699 tr(
"The file is not an PostGIS connections exchange file." ) );
705 settings.
beginGroup(
"/PostgreSQL/connections" );
710 bool overwrite =
true;
714 connectionName = child.
attribute(
"name" );
715 if ( !items.
contains( connectionName ) )
722 if ( keys.
contains( connectionName ) && prompt )
725 tr(
"Loading connections" ),
726 tr(
"Connection with name '%1' already exists. Overwrite?" )
727 .arg( connectionName ),
728 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
731 case QMessageBox::Cancel:
733 case QMessageBox::No:
736 case QMessageBox::Yes:
739 case QMessageBox::YesToAll:
743 case QMessageBox::NoToAll:
750 if ( keys.
contains( connectionName ) && !overwrite )
757 settings.
beginGroup(
"/PostgreSQL/connections/" + connectionName );
768 settings.
setValue(
"/service",
"" );
771 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
785 if ( root.
tagName() !=
"qgsMssqlConnections" )
788 tr(
"Loading connections" ),
789 tr(
"The file is not an MSSQL connections exchange file." ) );
800 bool overwrite =
true;
804 connectionName = child.
attribute(
"name" );
805 if ( !items.
contains( connectionName ) )
812 if ( keys.
contains( connectionName ) && prompt )
815 tr(
"Loading connections" ),
816 tr(
"Connection with name '%1' already exists. Overwrite?" )
817 .arg( connectionName ),
818 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
821 case QMessageBox::Cancel:
823 case QMessageBox::No:
826 case QMessageBox::Yes:
829 case QMessageBox::YesToAll:
833 case QMessageBox::NoToAll:
840 if ( keys.
contains( connectionName ) && !overwrite )
847 settings.
beginGroup(
"/MSSQL/connections/" + connectionName );
858 settings.
setValue(
"/service",
"" );
861 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
875 if ( root.
tagName() !=
"qgsOracleConnections" )
878 tr(
"Loading connections" ),
879 tr(
"The file is not an Oracle connections exchange file." ) );
890 bool overwrite =
true;
894 connectionName = child.
attribute(
"name" );
895 if ( !items.
contains( connectionName ) )
902 if ( keys.
contains( connectionName ) && prompt )
905 tr(
"Loading connections" ),
906 tr(
"Connection with name '%1' already exists. Overwrite?" )
907 .arg( connectionName ),
908 QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll | QMessageBox::Cancel );
911 case QMessageBox::Cancel:
913 case QMessageBox::No:
916 case QMessageBox::Yes:
919 case QMessageBox::YesToAll:
923 case QMessageBox::NoToAll:
930 if ( keys.
contains( connectionName ) && !overwrite )
937 settings.
beginGroup(
"/Oracle/connections/" + connectionName );
943 settings.
setValue(
"/estimatedMetadata", child.
attribute(
"estimatedMetadata" ) );
945 settings.
setValue(
"/geometryColumnsOnly", child.
attribute(
"geometryColumnsOnly" ) );
946 settings.
setValue(
"/allowGeometrylessTables", child.
attribute(
"allowGeometrylessTables" ) );
959 listConnections->selectAll();
960 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( !listConnections->selectedItems().isEmpty() );
965 listConnections->clearSelection();
966 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)
QgsManageConnectionsDialog(QWidget *parent=NULL, Mode mode=Export, Type type=WMS, const QString &fileName="")
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
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)