Skip to content
Permalink
Browse files

[auth] DB2 use the new authentication widget

  • Loading branch information
elpaso committed Oct 2, 2017
1 parent dfdf2ce commit 6378042bd10fda9c5037142a2d982de661591a55
Showing with 82 additions and 149 deletions.
  1. +21 −20 src/providers/db2/qgsdb2newconnection.cpp
  2. +0 −1 src/providers/db2/qgsdb2newconnection.h
  3. +61 −128 src/ui/qgsdb2newconnectionbase.ui
@@ -34,8 +34,8 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa
setupUi( this );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsDb2NewConnection::showHelp );

mAuthConfigSelect = new QgsAuthConfigSelect( this, QStringLiteral( "db2" ) );
tabAuthentication->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );
mAuthSettings->setDataprovider( QStringLiteral( "db2" ) );
mAuthSettings->showStoreCheckboxes( true );

if ( !connName.isEmpty() )
{
@@ -52,23 +52,19 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa

if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
chkStoreUsername->setChecked( true );
mAuthSettings->setUsername( settings.value( key + "/username" ).toString() );
mAuthSettings->setStoreUsername( true );
}

if ( settings.value( key + "/savePassword" ).toString() == QLatin1String( "true" ) )
{
txtPassword->setText( settings.value( key + "/password" ).toString() );
chkStorePassword->setChecked( true );
mAuthSettings->setPassword( settings.value( key + "/password" ).toString() );
mAuthSettings->setStorePassword( true );
}

QString authcfg = settings.value( key + "/authcfg" ).toString();
QgsDebugMsg( QString( "authcfg: %1" ).arg( authcfg ) );
mAuthConfigSelect->setConfigId( authcfg );
if ( !authcfg.isEmpty() )
{
tabAuthentication->setCurrentIndex( tabAuthentication->indexOf( mAuthConfigSelect ) );
}
mAuthSettings->setConfigId( authcfg );

txtName->setText( connName );
}
@@ -81,9 +77,9 @@ void QgsDb2NewConnection::accept()
QgsSettings settings;
QString baseKey = QStringLiteral( "/DB2/connections/" );
settings.setValue( baseKey + "selected", txtName->text() );
bool hasAuthConfigID = !mAuthConfigSelect->configId().isEmpty();
bool hasAuthConfigID = !mAuthSettings->configId().isEmpty();
QgsDebugMsg( QString( "hasAuthConfigID: %1" ).arg( hasAuthConfigID ) );
if ( !hasAuthConfigID && chkStorePassword->isChecked() &&
if ( !hasAuthConfigID && mAuthSettings->storePasswordIsChecked( ) &&
QMessageBox::question( this,
tr( "Saving passwords" ),
tr( "WARNING: You have opted to save your password. It will be stored in plain text in your project files and in your home directory on Unix-like systems, or in your user profile on Windows. If you do not want this to happen, please press the Cancel button.\n" ),
@@ -118,11 +114,11 @@ void QgsDb2NewConnection::accept()
settings.setValue( baseKey + "/port", txtPort->text() );
settings.setValue( baseKey + "/driver", txtDriver->text() );
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/username", chkStoreUsername->isChecked() && !hasAuthConfigID ? txtUsername->text() : QLatin1String( "" ) );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() && !hasAuthConfigID ? txtPassword->text() : QLatin1String( "" ) );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/authcfg", mAuthConfigSelect->configId() );
settings.setValue( baseKey + "/username", mAuthSettings->storeUsernameIsChecked( ) && !hasAuthConfigID ? mAuthSettings->username( ) : QLatin1String( "" ) );
settings.setValue( baseKey + "/password", mAuthSettings->storePasswordIsChecked( ) && !hasAuthConfigID ? mAuthSettings->password( ) : QLatin1String( "" ) );
settings.setValue( baseKey + "/saveUsername", mAuthSettings->storeUsernameIsChecked() && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", mAuthSettings->storePasswordIsChecked( ) && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/authcfg", mAuthSettings->configId() );

QDialog::accept();
}
@@ -151,14 +147,19 @@ bool QgsDb2NewConnection::testConnection()
QString authcfg;
QString connInfo;
QString errMsg;
// If the configuration tab is selected, test the authcfg in the connection
if ( mAuthSettings->configurationTabIsSelected( ) )
{
authcfg = mAuthSettings->configId( );
}
bool rc = QgsDb2ConnectionItem::ConnInfoFromParameters(
txtService->text().trimmed(),
txtDriver->text().trimmed(),
txtHost->text().trimmed(),
txtPort->text().trimmed(),
txtDatabase->text().trimmed(),
txtUsername->text().trimmed(),
txtPassword->text().trimmed(),
mAuthSettings->username().trimmed(),
mAuthSettings->password().trimmed(),
authcfg,
connInfo, errMsg );

@@ -47,7 +47,6 @@ class QgsDb2NewConnection : public QDialog, private Ui::QgsDb2NewConnectionBase
void on_cb_trustedConnection_clicked();
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
QgsAuthConfigSelect *mAuthConfigSelect = nullptr;
void showHelp();
};

@@ -6,29 +6,50 @@
<rect>
<x>0</x>
<y>0</y>
<width>445</width>
<height>399</height>
<width>506</width>
<height>583</height>
</rect>
</property>
<property name="windowTitle">
<string>Create a New DB2 Connection</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsMessageBar" name="bar" native="true">
<zorder>groupBox</zorder>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Connection Information</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="1">
<widget class="QLineEdit" name="txtPort"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtHost"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="DB2ServiceLabel">
<property name="text">
<string>Service/DSN</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtService"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="DB2ServiceLabel_2">
<property name="text">
<string>Driver</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtDriver"/>
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="DB2HostLabel">
@@ -37,149 +58,69 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="database">
<property name="text">
<string>Database</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="txtDatabase"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtHost"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="DB2port">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="txtPort"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="database">
<property name="text">
<string>Database</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="DB2ServiceLabel_3">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="DB2ServiceLabel">
<property name="text">
<string>Service/DSN</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtService"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>&amp;Test connection</string>
</property>
</widget>
<item row="2" column="1">
<widget class="QLineEdit" name="txtDriver"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="QTabWidget" name="tabAuthentication">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabBasic">
<attribute name="title">
<string>Authentication</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="TextLabel3">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>txtUsername</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsPasswordLineEdit" name="txtPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="chkStoreUsername">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="TextLabel3_2">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>txtPassword</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtUsername"/>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="chkStorePassword">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mAuthGroupBox">
<property name="title">
<string>Authentication</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QgsAuthSettingsWidget" name="mAuthSettings" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<item>
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>&amp;Test connection</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -189,16 +130,14 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsPasswordLineEdit</class>
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
<class>QgsAuthSettingsWidget</class>
<extends>QWidget</extends>
<header>auth/qgsauthsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
@@ -214,12 +153,6 @@
<tabstop>txtHost</tabstop>
<tabstop>txtPort</tabstop>
<tabstop>txtDatabase</tabstop>
<tabstop>tabAuthentication</tabstop>
<tabstop>txtUsername</tabstop>
<tabstop>chkStoreUsername</tabstop>
<tabstop>txtPassword</tabstop>
<tabstop>chkStorePassword</tabstop>
<tabstop>btnConnect</tabstop>
</tabstops>
<resources/>
<connections>

0 comments on commit 6378042

Please sign in to comment.
You can’t perform that action at this time.