Skip to content

Commit 5bdb605

Browse files
authored
Merge pull request #5270 from boundlessgeo/auth_widget2
[auth][needs-docs] Authentication widget
2 parents 65bade9 + e4a4d3d commit 5bdb605

13 files changed

+784
-105
lines changed
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/auth/qgsauthsettingswidget.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsAuthSettingsWidget : QWidget
13+
{
14+
%Docstring
15+
Widget for entering authentication credentials both in the form username/password
16+
and by using QGIS Authentication Database and its authentication configurations.
17+
.. versionadded:: 3.0
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgsauthsettingswidget.h"
22+
%End
23+
public:
24+
25+
explicit QgsAuthSettingsWidget( QWidget *parent /TransferThis/ = 0,
26+
const QString &configId = QString(),
27+
const QString &username = QString(),
28+
const QString &password = QString(),
29+
const QString &dataprovider = QString() );
30+
%Docstring
31+
Create a dialog for setting an associated authentication config, either
32+
from existing configs, or creating/removing them from auth database
33+
\param parent Parent widget
34+
\param configId authentication configuration id
35+
\param username
36+
\param password
37+
\param dataprovider The key of the calling layer provider, if applicable
38+
%End
39+
40+
void setWarningText( const QString &warningText );
41+
%Docstring
42+
setWarningText set the text of the warning label
43+
\param warningText the text of the warning label
44+
%End
45+
46+
void setBasicText( const QString &basicText );
47+
%Docstring
48+
setBasicText set the text of the warning label
49+
\param basicText the text of the basic tab label
50+
%End
51+
52+
const QString username( ) const;
53+
%Docstring
54+
username
55+
:return: basic authentication username
56+
:rtype: str
57+
%End
58+
59+
const QString password( ) const;
60+
%Docstring
61+
password
62+
:return: basic authentication password
63+
:rtype: str
64+
%End
65+
66+
const QString configId( ) const;
67+
%Docstring
68+
configId
69+
:return: authentication configuration id
70+
:rtype: str
71+
%End
72+
73+
int currentTabIndex( ) const;
74+
%Docstring
75+
currentTabIndex, mainly useful for unit tests
76+
:return: active tab index
77+
:rtype: int
78+
%End
79+
80+
bool btnConvertToEncryptedIsEnabled( ) const;
81+
%Docstring
82+
convertButtonEnabled, mainly useful for unit tests
83+
:return: true if the convert button is enabled
84+
:rtype: bool
85+
%End
86+
87+
public slots:
88+
89+
bool on_btnConvertToEncrypted_clicked( );
90+
%Docstring
91+
on_btnConvertToEncrypted_clicked create a Basic authentication configuration from
92+
username and password specified in the Basic tab
93+
:return: return true on success
94+
:rtype: bool
95+
%End
96+
97+
98+
99+
100+
};
101+
102+
/************************************************************************
103+
* This file has been generated automatically from *
104+
* *
105+
* src/gui/auth/qgsauthsettingswidget.h *
106+
* *
107+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
108+
************************************************************************/

python/gui/gui_auto.sip

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
%Include auth/qgsauthcerttrustpolicycombobox.sip
3030
%Include auth/qgsauthconfigeditor.sip
3131
%Include auth/qgsauthconfigselect.sip
32+
%Include auth/qgsauthsettingswidget.sip
3233
%Include auth/qgsautheditorwidgets.sip
3334
%Include auth/qgsauthidentitieseditor.sip
3435
%Include auth/qgsauthimportcertdialog.sip

src/app/qgshandlebadlayers.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <QDomElement>
3232
#include <QFileDialog>
3333
#include <QPushButton>
34+
#include <QToolButton>
3435
#include <QMessageBox>
3536
#include <QUrl>
3637

src/gui/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SET(QGIS_GUI_SRCS
7373
auth/qgsauthconfigeditor.cpp
7474
auth/qgsauthconfigidedit.cpp
7575
auth/qgsauthconfigselect.cpp
76+
auth/qgsauthsettingswidget.cpp
7677
auth/qgsautheditorwidgets.cpp
7778
auth/qgsauthguiutils.cpp
7879
auth/qgsauthidentitieseditor.cpp
@@ -579,6 +580,7 @@ SET(QGIS_GUI_MOC_HDRS
579580
auth/qgsauthconfigeditor.h
580581
auth/qgsauthconfigidedit.h
581582
auth/qgsauthconfigselect.h
583+
auth/qgsauthsettingswidget.h
582584
auth/qgsautheditorwidgets.h
583585
auth/qgsauthidentitieseditor.h
584586
auth/qgsauthimportcertdialog.h
@@ -728,6 +730,7 @@ SET(QGIS_GUI_HDRS
728730
auth/qgsauthconfigeditor.h
729731
auth/qgsauthconfigidedit.h
730732
auth/qgsauthconfigselect.h
733+
auth/qgsauthsettingswidget.h
731734
auth/qgsautheditorwidgets.h
732735
auth/qgsauthguiutils.h
733736
auth/qgsauthidentitieseditor.h
@@ -782,6 +785,7 @@ SET(QGIS_GUI_UI_HDRS
782785
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigeditor.h
783786
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigidedit.h
784787
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfigselect.h
788+
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthsettingswidget.h
785789
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthconfiguriedit.h
786790
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsautheditorwidgets.h
787791
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsauthidentitieseditor.h

src/gui/auth/qgsauthconfigselect.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsauthmanager.h"
2727
#include "qgsauthconfigedit.h"
2828
#include "qgslogger.h"
29+
#include "qgsapplication.h"
2930

3031

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

48+
// Set icons and remove texts
49+
btnConfigAdd->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyAdd.svg" ) ) );
50+
btnConfigRemove->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/symbologyRemove.svg" ) ) );
51+
btnConfigEdit->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionToggleEditing.svg" ) ) );
52+
btnConfigMsgClear->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconClose.svg" ) ) );
53+
54+
btnConfigAdd->setText( QStringLiteral( "" ) );
55+
btnConfigRemove->setText( QStringLiteral( "" ) );
56+
btnConfigEdit->setText( QStringLiteral( "" ) );
57+
btnConfigMsgClear->setText( QStringLiteral( "" ) );
58+
4759
leConfigMsg->setStyleSheet( QStringLiteral( "QLineEdit{background-color: %1}" )
4860
.arg( QgsAuthGuiUtils::yellowColor().name() ) );
4961

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

106117
void QgsAuthConfigSelect::clearConfig()
107118
{
108-
leConfigMethodDesc->clear();
109-
leConfigId->clear();
119+
cmbConfigSelect->setToolTip( QStringLiteral( "" ) );
110120
btnConfigEdit->setEnabled( false );
111121
btnConfigRemove->setEnabled( false );
112122
}
@@ -134,7 +144,7 @@ void QgsAuthConfigSelect::populateConfigSelector()
134144
for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
135145
{
136146
QgsAuthMethodConfig config = cit.value();
137-
sortmap.insert( config.name(), cit.key() );
147+
sortmap.insert( QStringLiteral( "%1 (%2)" ).arg( config.name(), config.method() ), cit.key() );
138148
}
139149

140150
QgsStringMap::const_iterator sm = sortmap.constBegin();

src/gui/auth/qgsauthconfigselect.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define QGSAUTHCONFIGSELECT_H
1919

2020
#include <QWidget>
21+
#include <QLabel>
2122
#include "qgis.h"
2223

2324
#include "ui_qgsauthconfigselect.h"
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/***************************************************************************
2+
qgsauthsettingswidget.cpp - QgsAuthSettingsWidget
3+
4+
---------------------
5+
begin : 28.9.2017
6+
copyright : (C) 2017 by Alessandro Pasotti
7+
email : apasotti at boundlessgeo dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#include "qgsauthsettingswidget.h"
17+
#include "qgsauthmanager.h"
18+
#include "qgsauthconfig.h"
19+
20+
#include <QDateTime>
21+
22+
QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
23+
const QString &configId,
24+
const QString &username,
25+
const QString &password,
26+
const QString &dataprovider )
27+
: QWidget( parent )
28+
{
29+
setupUi( this );
30+
txtPassword->setText( password );
31+
txtUserName->setText( username );
32+
if ( ! dataprovider.isEmpty( ) )
33+
{
34+
mAuthConfigSelect->setDataProviderKey( dataprovider );
35+
}
36+
if ( ! configId.isEmpty( ) )
37+
{
38+
mAuthConfigSelect->setConfigId( configId );
39+
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
40+
}
41+
else if ( !( username.isEmpty() && password.isEmpty( ) ) )
42+
{
43+
tabAuth->setCurrentIndex( tabAuth->indexOf( tabBasic ) );
44+
}
45+
updateConvertBtnState();
46+
}
47+
48+
void QgsAuthSettingsWidget::setWarningText( const QString &warningText )
49+
{
50+
lblWarning->setText( warningText );
51+
}
52+
53+
void QgsAuthSettingsWidget::setBasicText( const QString &basicText )
54+
{
55+
lblBasic->setText( basicText );
56+
}
57+
58+
const QString QgsAuthSettingsWidget::username() const
59+
{
60+
return txtUserName->text();
61+
}
62+
63+
const QString QgsAuthSettingsWidget::password() const
64+
{
65+
return txtPassword->text();
66+
}
67+
68+
const QString QgsAuthSettingsWidget::configId() const
69+
{
70+
return mAuthConfigSelect->configId();
71+
}
72+
73+
int QgsAuthSettingsWidget::currentTabIndex() const
74+
{
75+
return tabAuth->currentIndex( );
76+
}
77+
78+
bool QgsAuthSettingsWidget::btnConvertToEncryptedIsEnabled() const
79+
{
80+
return btnConvertToEncrypted->isEnabled( );
81+
}
82+
83+
bool QgsAuthSettingsWidget::on_btnConvertToEncrypted_clicked()
84+
{
85+
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );
86+
QgsAuthMethodConfig config( QStringLiteral( "Basic" ) );
87+
config.setName( tr( "Converted config %1" ).arg( QDateTime::currentDateTime().toString( ) ) );
88+
config.setConfig( QStringLiteral( "username" ), txtUserName->text() );
89+
config.setConfig( QStringLiteral( "password" ), txtPassword->text() );
90+
if ( ! QgsAuthManager::instance()->storeAuthenticationConfig( config ) )
91+
{
92+
mAuthConfigSelect->showMessage( tr( "Couldn't create a Basic authentication configuration!" ) );
93+
return false;
94+
}
95+
else
96+
{
97+
txtUserName->setText( QString( ) );
98+
txtPassword->setText( QString( ) );
99+
mAuthConfigSelect->setConfigId( config.id( ) );
100+
return true;
101+
}
102+
}
103+
104+
void QgsAuthSettingsWidget::on_txtUserName_textChanged( const QString &text )
105+
{
106+
Q_UNUSED( text );
107+
updateConvertBtnState();
108+
}
109+
110+
void QgsAuthSettingsWidget::on_txtPassword_textChanged( const QString &text )
111+
{
112+
Q_UNUSED( text );
113+
updateConvertBtnState();
114+
}
115+
116+
void QgsAuthSettingsWidget::updateConvertBtnState()
117+
{
118+
btnConvertToEncrypted->setEnabled( ! txtUserName->text().isEmpty() || ! txtPassword->text().isEmpty() );
119+
}

0 commit comments

Comments
 (0)