31#include "moc_qgsauthconfigedit.cpp"
36 , mDataProvider( dataprovider )
42 if ( !disabled && !authcfg.isEmpty() )
47 if ( disabled || !idok )
49 mAuthNotifyLayout =
new QVBoxLayout;
50 this->setLayout( mAuthNotifyLayout );
53 if ( !authcfg.isEmpty() )
55 msg +=
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg );
57 mAuthNotify =
new QLabel( msg,
this );
58 mAuthNotifyLayout->addWidget( mAuthNotify );
61 buttonBox->button( QDialogButtonBox::Save )->setEnabled(
false );
66 connect( btnClear, &QToolButton::clicked,
this, &QgsAuthConfigEdit::btnClear_clicked );
67 connect( leName, &QLineEdit::textChanged,
this, &QgsAuthConfigEdit::leName_textChanged );
68 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
69 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigEdit::saveConfig );
70 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigEdit::resetConfig );
71 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [] {
72 QgsHelp::openHelp( QStringLiteral(
"auth_system/auth_overview.html#authentication-configurations" ) );
75 populateAuthMethods();
77 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ), stkwAuthMethods, &QStackedWidget::setCurrentIndex );
78 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this] { validateAuth(); } );
82 if ( cmbAuthMethods->count() > 0 )
84 cmbAuthMethods->setCurrentIndex( 0 );
85 stkwAuthMethods->setCurrentIndex( 0 );
98void QgsAuthConfigEdit::populateAuthMethods()
103 QMap<QString, const QgsAuthMethodMetadata *> descmap;
104 const auto constAuthMethodKeys = authMethodKeys;
105 for (
const QString &authMethodKey : constAuthMethodKeys )
110 QgsDebugError( QStringLiteral(
"Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
116 QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
117 for ( it = descmap.begin(); it != descmap.end(); ++it )
119 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>(
124 QgsDebugError( QStringLiteral(
"Load auth method edit widget FAILED for auth method key (%1)" ).arg( it.value()->key() ) );
129 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
130 stkwAuthMethods->addWidget( editWidget );
134void QgsAuthConfigEdit::loadConfig()
136 const bool emptyAuthCfg = mAuthCfg.isEmpty();
137 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
150 QgsAuthMethodConfig mconfig;
153 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg: %1" ).arg( mAuthCfg ) );
157 if ( !mconfig.
isValid(
true ) )
159 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): invalid config" ).arg( mAuthCfg ) );
164 leName->setText( mconfig.
name() );
165 leResource->setText( mconfig.
uri() );
166 authCfgEdit->setAuthConfigId( mconfig.
id() );
170 QgsDebugMsgLevel( QStringLiteral(
"Loading authcfg: %1" ).arg( mAuthCfg ), 2 );
171 QgsDebugMsgLevel( QStringLiteral(
"Loading auth method: %1" ).arg( authMethodKey ), 2 );
173 if ( authMethodKey.isEmpty() )
175 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no auth method found" ).arg( mAuthCfg ) );
179 if ( mconfig.
method() != authMethodKey )
181 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): auth method and key mismatch" ).arg( mAuthCfg ) );
185 const int indx = authMethodIndex( authMethodKey );
188 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'" )
189 .arg( mAuthCfg, authMethodKey ) );
190 if ( cmbAuthMethods->count() > 0 )
192 cmbAuthMethods->setCurrentIndex( 0 );
193 stkwAuthMethods->setCurrentIndex( 0 );
198 cmbAuthMethods->setCurrentIndex( indx );
199 stkwAuthMethods->setCurrentIndex( indx );
201 QgsAuthMethodEdit *editWidget = currentEditWidget();
204 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)" )
205 .arg( mAuthCfg, authMethodKey ) );
212void QgsAuthConfigEdit::resetConfig()
219void QgsAuthConfigEdit::saveConfig()
224 const QString authMethodKey = cmbAuthMethods->currentData().toString();
226 QgsAuthMethodEdit *editWidget = currentEditWidget();
229 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
236 QgsDebugError( QStringLiteral(
"Save auth config FAILED when loading auth method instance from key (%1)" ).arg( authMethodKey ) );
240 QgsAuthMethodConfig mconfig;
241 mconfig.
setName( leName->text() );
242 mconfig.
setUri( leResource->text() );
249 QgsDebugError( QStringLiteral(
"Save auth config FAILED: config invalid" ) );
253 const QString authCfgId( authCfgEdit->configId() );
254 if ( !mAuthCfg.isEmpty() )
256 if ( authCfgId == mAuthCfg )
258 mconfig.
setId( mAuthCfg );
265 QgsDebugError( QStringLiteral(
"Updating auth config FAILED for authcfg: %1" ).arg( mAuthCfg ) );
270 mconfig.
setId( authCfgId );
276 QgsDebugError( QStringLiteral(
"Removal of older auth config FAILED" ) );
278 mAuthCfg = authCfgId;
282 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
286 else if ( mAuthCfg.isEmpty() )
288 if ( authCfgId.isEmpty() )
292 mAuthCfg = mconfig.
id();
297 QgsDebugError( QStringLiteral(
"Storing new auth config FAILED" ) );
302 mconfig.
setId( authCfgId );
305 mAuthCfg = authCfgId;
310 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
318void QgsAuthConfigEdit::btnClear_clicked()
320 QgsAuthMethodEdit *editWidget = currentEditWidget();
323 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
332void QgsAuthConfigEdit::clearAll()
336 authCfgEdit->clear();
338 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
340 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->widget( i ) );
350void QgsAuthConfigEdit::validateAuth()
352 bool authok = !leName->text().isEmpty();
354 QgsAuthMethodEdit *editWidget = currentEditWidget();
357 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED" ) );
363 authok = authok && authCfgEdit->validate();
365 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
368void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
374int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
376 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
381 return qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->currentWidget() );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
void authenticationConfigStored(const QString &authcfg)
Emit generated id when a new config is saved to auth database.
void authenticationConfigUpdated(const QString &authcfg)
Emit current id when an existing config is updated in auth database.
QgsAuthConfigEdit(QWidget *parent=nullptr, const QString &authcfg=QString(), const QString &dataprovider=QString())
Create a dialog for editing an authentication configuration.
void validityChanged(bool valid)
Validity of the ID has changed.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
QStringList configIds() const
Gets list of authentication ids from database.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Gets authentication method from the config/provider cache via its key.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Gets keys of supported authentication methods.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
QString configAuthMethodKey(const QString &authcfg) const
Gets key of authentication method associated with config ID.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
QString method() const
Textual key of the associated authentication method.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
void setName(const QString &name)
Sets name of configuration.
void setConfigMap(const QgsStringMap &map)
Set extended configuration map.
void setVersion(int version)
Sets version of the configuration.
const QString name() const
Gets name of configuration.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
QgsStringMap configMap() const
Gets extended configuration, mapped to key/value pairs of QStrings.
void setMethod(const QString &method)
void setUri(const QString &uri)
void setId(const QString &id)
Sets auth config ID.
Abstract base class for the edit widget of authentication method plugins.
virtual bool validateConfig()=0
Validate the configuration of subclasses.
void validityChanged(bool valid)
Emitted when the configuration validatity changes.
virtual void clearConfig()=0
Clear GUI controls in subclassed widget.
virtual QgsStringMap configMap() const =0
The configuration key-vale map of subclasses.
virtual void loadConfig(const QgsStringMap &configmap)=0
Load an existing config map into subclassed widget.
int version() const
Increment this if method is significantly updated, allow updater code to be written for previously st...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)