Skip to content
Permalink
Browse files

Merge pull request #5281 from boundlessgeo/auth_use_settings_widget

[auth][needs-docs] Provider connection dialogs use the new auth settings widget
  • Loading branch information
elpaso committed Oct 5, 2017
2 parents 2f44d52 + 7528207 commit dcc672520cd0c8643f35ae69b2ed0d4b9f2ca563
@@ -14,6 +14,10 @@ class QgsAuthSettingsWidget : QWidget
%Docstring
Widget for entering authentication credentials both in the form username/password
and by using QGIS Authentication Database and its authentication configurations.

The widget also offers the functionality to convert username/password credentials
to an authentication configuration.

.. versionadded:: 3.0
%End

@@ -22,6 +26,12 @@ class QgsAuthSettingsWidget : QWidget
%End
public:

enum WarningType
{
ProjectFile,
UserSettings
};

explicit QgsAuthSettingsWidget( QWidget *parent /TransferThis/ = 0,
const QString &configId = QString(),
const QString &username = QString(),
@@ -41,6 +51,7 @@ class QgsAuthSettingsWidget : QWidget
%Docstring
setWarningText set the text of the warning label
\param warningText the text of the warning label
.. seealso:: formattedWarning()
%End

void setBasicText( const QString &basicText );
@@ -56,25 +67,57 @@ class QgsAuthSettingsWidget : QWidget
:rtype: str
%End

void setUsername( const QString &username );
%Docstring
setUsername set the username
\param username the user name
%End

const QString password( ) const;
%Docstring
password
:return: basic authentication password
:rtype: str
%End

void setPassword( const QString &password );
%Docstring
setPassword set the password
\param password the password
%End

const QString configId( ) const;
%Docstring
configId
:return: authentication configuration id
:rtype: str
%End

int currentTabIndex( ) const;
void setConfigId( const QString &configId );
%Docstring
currentTabIndex, mainly useful for unit tests
:return: active tab index
:rtype: int
setConfigId set the authentication configuration id
param configId the authentication configuration id
%End

void setDataprovider( const QString &dataprovider );
%Docstring
setDataprovider set the data provider key for filtering compatible authentication configurations
\param dataprovider data provider key
%End

const QString dataprovider( ) const;
%Docstring
dataprovider
:return: the data provider key used to filter compatible authentication configurations
:rtype: str
%End

static const QString formattedWarning( WarningType warning );
%Docstring
warning text message based upon where credentials are stored
\param warning enum of warning type
:return: pre-formatted warning text
:rtype: str
%End

bool btnConvertToEncryptedIsEnabled( ) const;
@@ -84,6 +127,50 @@ class QgsAuthSettingsWidget : QWidget
:rtype: bool
%End

void showStoreCheckboxes( bool enabled );
%Docstring
showStoreCheckboxes show the "Store" checkboxes for basic auth.
Some connection configurations allow the user to enter credentials
for testing the connection without storing them in the project.
"Store" checkboxes are disabled by default.
\param enabled
%End

void setStoreUsernameChecked( bool checked );
%Docstring
setStoreUsernameChecked check the "Store" checkbox for the username
\param checked
.. seealso:: showStoreCheckboxes
%End

void setStorePasswordChecked( bool checked );
%Docstring
setStorePasswordCheched check the "Store" checkbox for the password
\param checked
.. seealso:: showStoreCheckboxes
%End

bool storePasswordIsChecked( ) const;
%Docstring
storePassword
:return: true if "Store" checkbox for the password is checked
:rtype: bool
%End

bool storeUsernameIsChecked( ) const;
%Docstring
storeUsername
:return: true if "Store" checkbox for the username is checked
:rtype: bool
%End

bool configurationTabIsSelected( );
%Docstring
configurationTabIsSelected
:return: true if the configuration tab is the currently selected tab
:rtype: bool
%End

public slots:

bool convertToEncrypted( );
@@ -309,21 +309,18 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mDefaultTileMaxRetrySpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/defaultTileMaxRetry" ), "3" ).toInt() );

// Proxy stored authentication configurations
mProxyAuthConfigSelect = new QgsAuthConfigSelect( this, QStringLiteral( "proxy" ) );
tabAuth->insertTab( 1, mProxyAuthConfigSelect, tr( "Configurations" ) );
mAuthSettings->setDataprovider( QStringLiteral( "proxy" ) );
QString authcfg = mSettings->value( QStringLiteral( "proxy/authcfg" ) ).toString();
mProxyAuthConfigSelect->setConfigId( authcfg );
if ( !authcfg.isEmpty() )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( mProxyAuthConfigSelect ) );
}
mAuthSettings->setConfigId( authcfg );
mAuthSettings->setWarningText( mAuthSettings->formattedWarning( QgsAuthSettingsWidget::UserSettings ) );

//Web proxy settings
grpProxy->setChecked( mSettings->value( QStringLiteral( "proxy/proxyEnabled" ), "0" ).toBool() );
leProxyHost->setText( mSettings->value( QStringLiteral( "proxy/proxyHost" ), "" ).toString() );
leProxyPort->setText( mSettings->value( QStringLiteral( "proxy/proxyPort" ), "" ).toString() );
leProxyUser->setText( mSettings->value( QStringLiteral( "proxy/proxyUser" ), "" ).toString() );
leProxyPassword->setText( mSettings->value( QStringLiteral( "proxy/proxyPassword" ), "" ).toString() );

mAuthSettings->setPassword( mSettings->value( QStringLiteral( "proxy/proxyUser" ), "" ).toString() );
mAuthSettings->setUsername( mSettings->value( QStringLiteral( "proxy/proxyPassword" ), "" ).toString() );

//available proxy types
mProxyTypeComboBox->insertItem( 0, QStringLiteral( "DefaultProxy" ) );
@@ -1174,14 +1171,14 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/defaultTileMaxRetry" ), mDefaultTileMaxRetrySpinBox->value() );

// Proxy stored authentication configurations
mSettings->setValue( QStringLiteral( "proxy/authcfg" ), mProxyAuthConfigSelect->configId( ) );
mSettings->setValue( QStringLiteral( "proxy/authcfg" ), mAuthSettings->configId( ) );

//Web proxy settings
mSettings->setValue( QStringLiteral( "proxy/proxyEnabled" ), grpProxy->isChecked() );
mSettings->setValue( QStringLiteral( "proxy/proxyHost" ), leProxyHost->text() );
mSettings->setValue( QStringLiteral( "proxy/proxyPort" ), leProxyPort->text() );
mSettings->setValue( QStringLiteral( "proxy/proxyUser" ), leProxyUser->text() );
mSettings->setValue( QStringLiteral( "proxy/proxyPassword" ), leProxyPassword->text() );
mSettings->setValue( QStringLiteral( "proxy/proxyUser" ), mAuthSettings->username() );
mSettings->setValue( QStringLiteral( "proxy/proxyPassword" ), mAuthSettings->password() );
mSettings->setValue( QStringLiteral( "proxy/proxyType" ), mProxyTypeComboBox->currentText() );

if ( !mCacheDirectory->text().isEmpty() )
@@ -256,7 +256,6 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption

QList< QgsOptionsPageWidget * > mAdditionalOptionWidgets;
QgsLocatorOptionsWidget *mLocatorOptionsWidget = nullptr;
QgsAuthConfigSelect *mProxyAuthConfigSelect = nullptr;

};

@@ -25,6 +25,7 @@ QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
const QString &password,
const QString &dataprovider )
: QWidget( parent )
, mDataprovider( dataprovider )
{
setupUi( this );
txtPassword->setText( password );
@@ -36,13 +37,16 @@ QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
if ( ! configId.isEmpty( ) )
{
mAuthConfigSelect->setConfigId( configId );
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
}
else if ( !( username.isEmpty() && password.isEmpty( ) ) )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabBasic ) );
}
setBasicText( "" );
// default to warning about basic settings stored in project file
setWarningText( formattedWarning( ProjectFile ) );
connect( btnConvertToEncrypted, &QPushButton::clicked, this, &QgsAuthSettingsWidget::convertToEncrypted );
connect( txtUserName, &QLineEdit::textChanged, this, &QgsAuthSettingsWidget::userNameTextChanged );
connect( txtPassword, &QLineEdit::textChanged, this, &QgsAuthSettingsWidget::passwordTextChanged );
// Hide store password and username by default
showStoreCheckboxes( false );
updateSelectedTab();
updateConvertBtnState();
}

@@ -54,33 +58,110 @@ void QgsAuthSettingsWidget::setWarningText( const QString &warningText )
void QgsAuthSettingsWidget::setBasicText( const QString &basicText )
{
lblBasic->setText( basicText );
// hide unused widget so its word wrapping does not add to parent widget's height
lblBasic->setVisible( ! basicText.isEmpty() );
}

const QString QgsAuthSettingsWidget::username() const
{
return txtUserName->text();
}

void QgsAuthSettingsWidget::setUsername( const QString &username )
{
txtUserName->setText( username );
updateSelectedTab();
}

const QString QgsAuthSettingsWidget::password() const
{
return txtPassword->text();
}

const QString QgsAuthSettingsWidget::configId() const
void QgsAuthSettingsWidget::setPassword( const QString &password )
{
return mAuthConfigSelect->configId();
txtPassword->setText( password );
updateSelectedTab();
}

void QgsAuthSettingsWidget::setConfigId( const QString &configId )
{
mAuthConfigSelect->setConfigId( configId );
updateSelectedTab();
}

void QgsAuthSettingsWidget::setDataprovider( const QString &dataprovider )
{
mDataprovider = dataprovider;
mAuthConfigSelect->setDataProviderKey( dataprovider );
}

const QString QgsAuthSettingsWidget::dataprovider() const
{
return mDataprovider;
}

int QgsAuthSettingsWidget::currentTabIndex() const
const QString QgsAuthSettingsWidget::formattedWarning( WarningType warning )
{
return tabAuth->currentIndex( );
QString out = tr( "<div>Warning: credentials stored as plain text in %1.</div>" );
switch ( warning )
{
case ProjectFile:
return out.arg( tr( "project file" ) );
case UserSettings:
return out.arg( tr( "user settings" ) );
}
}

const QString QgsAuthSettingsWidget::configId() const
{
return mAuthConfigSelect->configId();
}

bool QgsAuthSettingsWidget::btnConvertToEncryptedIsEnabled() const
{
return btnConvertToEncrypted->isEnabled( );
}

void QgsAuthSettingsWidget::showStoreCheckboxes( bool enabled )
{
if ( enabled )
{
cbStorePassword->show();
cbStoreUsername->show();
}
else
{
cbStorePassword->hide();
cbStoreUsername->hide();
}
}

void QgsAuthSettingsWidget::setStoreUsernameChecked( bool checked )
{
cbStoreUsername->setChecked( checked );
}

void QgsAuthSettingsWidget::setStorePasswordChecked( bool checked )
{
cbStorePassword->setChecked( checked );
}

bool QgsAuthSettingsWidget::storePasswordIsChecked() const
{
return cbStorePassword->isChecked( );
}

bool QgsAuthSettingsWidget::storeUsernameIsChecked() const
{
return cbStoreUsername->isChecked( );
}

bool QgsAuthSettingsWidget::configurationTabIsSelected()
{
return tabAuth->currentIndex( ) == tabAuth->indexOf( tabConfigurations );
}

bool QgsAuthSettingsWidget::convertToEncrypted( )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
@@ -102,13 +183,13 @@ bool QgsAuthSettingsWidget::convertToEncrypted( )
}
}

void QgsAuthSettingsWidget::on_txtUserName_textChanged( const QString &text )
void QgsAuthSettingsWidget::userNameTextChanged( const QString &text )
{
Q_UNUSED( text );
updateConvertBtnState();
}

void QgsAuthSettingsWidget::on_txtPassword_textChanged( const QString &text )
void QgsAuthSettingsWidget::passwordTextChanged( const QString &text )
{
Q_UNUSED( text );
updateConvertBtnState();
@@ -118,3 +199,15 @@ void QgsAuthSettingsWidget::updateConvertBtnState()
{
btnConvertToEncrypted->setEnabled( ! txtUserName->text().isEmpty() || ! txtPassword->text().isEmpty() );
}

void QgsAuthSettingsWidget::updateSelectedTab()
{
if ( ! mAuthConfigSelect->configId().isEmpty( ) )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
}
else if ( !( txtUserName->text( ).isEmpty() && txtPassword->text( ).isEmpty( ) ) )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabBasic ) );
}
}

0 comments on commit dcc6725

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