33 , mDataProvider( dataprovider )
39 if ( !disabled && !authcfg.isEmpty() )
44 if ( disabled || !idok )
46 mAuthNotifyLayout =
new QVBoxLayout;
47 this->setLayout( mAuthNotifyLayout );
50 if ( !authcfg.isEmpty() )
52 msg +=
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg );
54 mAuthNotify =
new QLabel( msg,
this );
55 mAuthNotifyLayout->addWidget( mAuthNotify );
58 buttonBox->button( QDialogButtonBox::Save )->setEnabled(
false );
63 connect( btnClear, &QToolButton::clicked,
this, &QgsAuthConfigEdit::btnClear_clicked );
64 connect( leName, &QLineEdit::textChanged,
this, &QgsAuthConfigEdit::leName_textChanged );
65 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
66 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigEdit::saveConfig );
67 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigEdit::resetConfig );
69 populateAuthMethods();
71 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
72 stkwAuthMethods, &QStackedWidget::setCurrentIndex );
73 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
74 this, [ = ] { validateAuth(); } );
85 if ( cmbAuthMethods->count() > 0 )
87 cmbAuthMethods->setCurrentIndex( 0 );
88 stkwAuthMethods->setCurrentIndex( 0 );
100void QgsAuthConfigEdit::populateAuthMethods()
105 QMap<QString, const QgsAuthMethodMetadata *> descmap;
106 const auto constAuthMethodKeys = authMethodKeys;
107 for (
const QString &authMethodKey : constAuthMethodKeys )
112 QgsDebugError( QStringLiteral(
"Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
118 QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
119 for ( it = descmap.begin(); it != descmap.end(); ++it )
125 QgsDebugError( QStringLiteral(
"Load auth method edit widget FAILED for auth method key (%1)" ).arg( it.value()->key() ) );
130 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
131 stkwAuthMethods->addWidget( editWidget );
135void QgsAuthConfigEdit::loadConfig()
137 const bool emptyAuthCfg = mAuthCfg.isEmpty();
138 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
154 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg: %1" ).arg( mAuthCfg ) );
158 if ( !mconfig.
isValid(
true ) )
160 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): invalid config" ).arg( mAuthCfg ) );
165 leName->setText( mconfig.
name() );
166 leResource->setText( mconfig.
uri() );
167 authCfgEdit->setAuthConfigId( mconfig.
id() );
171 QgsDebugMsgLevel( QStringLiteral(
"Loading authcfg: %1" ).arg( mAuthCfg ), 2 );
172 QgsDebugMsgLevel( QStringLiteral(
"Loading auth method: %1" ).arg( authMethodKey ), 2 );
174 if ( authMethodKey.isEmpty() )
176 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no auth method found" ).arg( mAuthCfg ) );
180 if ( mconfig.
method() != authMethodKey )
182 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): auth method and key mismatch" ).arg( mAuthCfg ) );
186 const int indx = authMethodIndex( authMethodKey );
189 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'" )
190 .arg( mAuthCfg, authMethodKey ) );
191 if ( cmbAuthMethods->count() > 0 )
193 cmbAuthMethods->setCurrentIndex( 0 );
194 stkwAuthMethods->setCurrentIndex( 0 );
199 cmbAuthMethods->setCurrentIndex( indx );
200 stkwAuthMethods->setCurrentIndex( indx );
205 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)" )
206 .arg( mAuthCfg, authMethodKey ) );
213void QgsAuthConfigEdit::resetConfig()
220void QgsAuthConfigEdit::saveConfig()
225 const QString authMethodKey = cmbAuthMethods->currentData().toString();
230 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
237 QgsDebugError( QStringLiteral(
"Save auth config FAILED when loading auth method instance from key (%1)" ).arg( authMethodKey ) );
242 mconfig.
setName( leName->text() );
243 mconfig.
setUri( leResource->text() );
250 QgsDebugError( QStringLiteral(
"Save auth config FAILED: config invalid" ) );
254 const QString authCfgId( authCfgEdit->configId() );
255 if ( !mAuthCfg.isEmpty() )
257 if ( authCfgId == mAuthCfg )
259 mconfig.
setId( mAuthCfg );
266 QgsDebugError( QStringLiteral(
"Updating auth config FAILED for authcfg: %1" ).arg( mAuthCfg ) );
271 mconfig.
setId( authCfgId );
277 QgsDebugError( QStringLiteral(
"Removal of older auth config FAILED" ) );
279 mAuthCfg = authCfgId;
283 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
287 else if ( mAuthCfg.isEmpty() )
289 if ( authCfgId.isEmpty() )
293 mAuthCfg = mconfig.
id();
298 QgsDebugError( QStringLiteral(
"Storing new auth config FAILED" ) );
303 mconfig.
setId( authCfgId );
306 mAuthCfg = authCfgId;
311 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
319void QgsAuthConfigEdit::btnClear_clicked()
324 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
333void QgsAuthConfigEdit::clearAll()
337 authCfgEdit->clear();
339 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
341 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->widget( i ) );
351void QgsAuthConfigEdit::validateAuth()
353 bool authok = !leName->text().isEmpty();
358 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED" ) );
364 authok = authok && authCfgEdit->validate();
366 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
369void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
375int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
377 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
382 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.
Configuration storage class for authentication method configurations.
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.
Abstract base class for authentication method plugins.
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...
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)