Skip to content
Permalink
Browse files

Merge pull request #5270 from boundlessgeo/auth_widget2

[auth][needs-docs] Authentication widget
  • Loading branch information
elpaso committed Oct 2, 2017
2 parents 65bade9 + e4a4d3d commit 5bdb605fdaa41d03fbab203df04b743ebfd8f44e
@@ -0,0 +1,108 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/auth/qgsauthsettingswidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




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.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsauthsettingswidget.h"
%End
public:

explicit QgsAuthSettingsWidget( QWidget *parent /TransferThis/ = 0,
const QString &configId = QString(),
const QString &username = QString(),
const QString &password = QString(),
const QString &dataprovider = QString() );
%Docstring
Create a dialog for setting an associated authentication config, either
from existing configs, or creating/removing them from auth database
\param parent Parent widget
\param configId authentication configuration id
\param username
\param password
\param dataprovider The key of the calling layer provider, if applicable
%End

void setWarningText( const QString &warningText );
%Docstring
setWarningText set the text of the warning label
\param warningText the text of the warning label
%End

void setBasicText( const QString &basicText );
%Docstring
setBasicText set the text of the warning label
\param basicText the text of the basic tab label
%End

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

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

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

int currentTabIndex( ) const;
%Docstring
currentTabIndex, mainly useful for unit tests
:return: active tab index
:rtype: int
%End

bool btnConvertToEncryptedIsEnabled( ) const;
%Docstring
convertButtonEnabled, mainly useful for unit tests
:return: true if the convert button is enabled
:rtype: bool
%End

public slots:

bool on_btnConvertToEncrypted_clicked( );
%Docstring
on_btnConvertToEncrypted_clicked create a Basic authentication configuration from
username and password specified in the Basic tab
:return: return true on success
:rtype: bool
%End




};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/auth/qgsauthsettingswidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -29,6 +29,7 @@
%Include auth/qgsauthcerttrustpolicycombobox.sip
%Include auth/qgsauthconfigeditor.sip
%Include auth/qgsauthconfigselect.sip
%Include auth/qgsauthsettingswidget.sip
%Include auth/qgsautheditorwidgets.sip
%Include auth/qgsauthidentitieseditor.sip
%Include auth/qgsauthimportcertdialog.sip
@@ -31,6 +31,7 @@
#include <QDomElement>
#include <QFileDialog>
#include <QPushButton>
#include <QToolButton>
#include <QMessageBox>
#include <QUrl>

@@ -73,6 +73,7 @@ SET(QGIS_GUI_SRCS
auth/qgsauthconfigeditor.cpp
auth/qgsauthconfigidedit.cpp
auth/qgsauthconfigselect.cpp
auth/qgsauthsettingswidget.cpp
auth/qgsautheditorwidgets.cpp
auth/qgsauthguiutils.cpp
auth/qgsauthidentitieseditor.cpp
@@ -579,6 +580,7 @@ SET(QGIS_GUI_MOC_HDRS
auth/qgsauthconfigeditor.h
auth/qgsauthconfigidedit.h
auth/qgsauthconfigselect.h
auth/qgsauthsettingswidget.h
auth/qgsautheditorwidgets.h
auth/qgsauthidentitieseditor.h
auth/qgsauthimportcertdialog.h
@@ -728,6 +730,7 @@ SET(QGIS_GUI_HDRS
auth/qgsauthconfigeditor.h
auth/qgsauthconfigidedit.h
auth/qgsauthconfigselect.h
auth/qgsauthsettingswidget.h
auth/qgsautheditorwidgets.h
auth/qgsauthguiutils.h
auth/qgsauthidentitieseditor.h
@@ -782,6 +785,7 @@ SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigeditor.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigidedit.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigselect.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthsettingswidget.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfiguriedit.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsautheditorwidgets.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthidentitieseditor.h
@@ -26,6 +26,7 @@
#include "qgsauthmanager.h"
#include "qgsauthconfigedit.h"
#include "qgslogger.h"
#include "qgsapplication.h"


QgsAuthConfigSelect::QgsAuthConfigSelect( QWidget *parent, const QString &dataprovider )
@@ -44,6 +45,17 @@ QgsAuthConfigSelect::QgsAuthConfigSelect( QWidget *parent, const QString &datapr
{
setupUi( this );

// Set icons and remove texts
btnConfigAdd->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyAdd.svg" ) ) );
btnConfigRemove->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyRemove.svg" ) ) );
btnConfigEdit->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
btnConfigMsgClear->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconClose.svg" ) ) );

btnConfigAdd->setText( QStringLiteral( "" ) );
btnConfigRemove->setText( QStringLiteral( "" ) );
btnConfigEdit->setText( QStringLiteral( "" ) );
btnConfigMsgClear->setText( QStringLiteral( "" ) );

leConfigMsg->setStyleSheet( QStringLiteral( "QLineEdit{background-color: %1}" )
.arg( QgsAuthGuiUtils::yellowColor().name() ) );

@@ -94,9 +106,8 @@ void QgsAuthConfigSelect::loadConfig()
{
methoddesc = authmethod->description();
}
leConfigMethodDesc->setText( methoddesc );
leConfigMethodDesc->setCursorPosition( 0 ); // left justify
leConfigId->setText( config.id() );
cmbConfigSelect->setToolTip( tr( "<ul><li><b>Method type:</b> %1</li>"
"<li><b>Configuration ID:</b> %2</li></ul>" ).arg( methoddesc, config.id( ) ) );
btnConfigEdit->setEnabled( true );
btnConfigRemove->setEnabled( true );
}
@@ -105,8 +116,7 @@ void QgsAuthConfigSelect::loadConfig()

void QgsAuthConfigSelect::clearConfig()
{
leConfigMethodDesc->clear();
leConfigId->clear();
cmbConfigSelect->setToolTip( QStringLiteral( "" ) );
btnConfigEdit->setEnabled( false );
btnConfigRemove->setEnabled( false );
}
@@ -134,7 +144,7 @@ void QgsAuthConfigSelect::populateConfigSelector()
for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
{
QgsAuthMethodConfig config = cit.value();
sortmap.insert( config.name(), cit.key() );
sortmap.insert( QStringLiteral( "%1 (%2)" ).arg( config.name(), config.method() ), cit.key() );
}

QgsStringMap::const_iterator sm = sortmap.constBegin();
@@ -18,6 +18,7 @@
#define QGSAUTHCONFIGSELECT_H

#include <QWidget>
#include <QLabel>
#include "qgis.h"

#include "ui_qgsauthconfigselect.h"
@@ -0,0 +1,119 @@
/***************************************************************************
qgsauthsettingswidget.cpp - QgsAuthSettingsWidget
---------------------
begin : 28.9.2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsauthsettingswidget.h"
#include "qgsauthmanager.h"
#include "qgsauthconfig.h"

#include <QDateTime>

QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
const QString &configId,
const QString &username,
const QString &password,
const QString &dataprovider )
: QWidget( parent )
{
setupUi( this );
txtPassword->setText( password );
txtUserName->setText( username );
if ( ! dataprovider.isEmpty( ) )
{
mAuthConfigSelect->setDataProviderKey( dataprovider );
}
if ( ! configId.isEmpty( ) )
{
mAuthConfigSelect->setConfigId( configId );
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
}
else if ( !( username.isEmpty() && password.isEmpty( ) ) )
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabBasic ) );
}
updateConvertBtnState();
}

void QgsAuthSettingsWidget::setWarningText( const QString &warningText )
{
lblWarning->setText( warningText );
}

void QgsAuthSettingsWidget::setBasicText( const QString &basicText )
{
lblBasic->setText( basicText );
}

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

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

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

int QgsAuthSettingsWidget::currentTabIndex() const
{
return tabAuth->currentIndex( );
}

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

bool QgsAuthSettingsWidget::on_btnConvertToEncrypted_clicked()
{
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
QgsAuthMethodConfig config( QStringLiteral( "Basic" ) );
config.setName( tr( "Converted config %1" ).arg( QDateTime::currentDateTime().toString( ) ) );
config.setConfig( QStringLiteral( "username" ), txtUserName->text() );
config.setConfig( QStringLiteral( "password" ), txtPassword->text() );
if ( ! QgsAuthManager::instance()->storeAuthenticationConfig( config ) )
{
mAuthConfigSelect->showMessage( tr( "Couldn't create a Basic authentication configuration!" ) );
return false;
}
else
{
txtUserName->setText( QString( ) );
txtPassword->setText( QString( ) );
mAuthConfigSelect->setConfigId( config.id( ) );
return true;
}
}

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

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

void QgsAuthSettingsWidget::updateConvertBtnState()
{
btnConvertToEncrypted->setEnabled( ! txtUserName->text().isEmpty() || ! txtPassword->text().isEmpty() );
}

0 comments on commit 5bdb605

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