19 #include <QPushButton> 32 , mDataProvider( dataprovider )
38 if ( !disabled && !authcfg.isEmpty() )
43 if ( disabled || !idok )
45 mAuthNotifyLayout =
new QVBoxLayout;
46 this->setLayout( mAuthNotifyLayout );
49 if ( !authcfg.isEmpty() )
51 msg +=
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg );
53 mAuthNotify =
new QLabel( msg,
this );
54 mAuthNotifyLayout->addWidget( mAuthNotify );
57 buttonBox->button( QDialogButtonBox::Save )->setEnabled(
false );
62 connect( btnClear, &QToolButton::clicked,
this, &QgsAuthConfigEdit::btnClear_clicked );
63 connect( leName, &QLineEdit::textChanged,
this, &QgsAuthConfigEdit::leName_textChanged );
64 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
65 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigEdit::saveConfig );
66 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigEdit::resetConfig );
68 populateAuthMethods();
70 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
71 stkwAuthMethods, &QStackedWidget::setCurrentIndex );
72 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
73 this, [ = ] { validateAuth(); } );
84 if ( cmbAuthMethods->count() > 0 )
86 cmbAuthMethods->setCurrentIndex( 0 );
87 stkwAuthMethods->setCurrentIndex( 0 );
97 void QgsAuthConfigEdit::populateAuthMethods()
102 QMap<QString, QgsAuthMethod *> descmap;
103 Q_FOREACH (
const QString &authMethodKey, authMethodKeys )
108 QgsDebugMsg( QString(
"Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
114 QMap<QString, QgsAuthMethod *>::iterator it = descmap.begin();
115 for ( it = descmap.begin(); it != descmap.end(); ++it )
121 QgsDebugMsg( QString(
"Load auth method edit widget FAILED for auth method key (%1)" ).arg( it.value()->key() ) );
126 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
127 stkwAuthMethods->addWidget( editWidget );
131 void QgsAuthConfigEdit::loadConfig()
133 bool emptyAuthCfg = mAuthCfg.isEmpty();
134 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
150 QgsDebugMsg( QString(
"Loading FAILED for authcfg: %1" ).arg( mAuthCfg ) );
154 if ( !mconfig.
isValid(
true ) )
156 QgsDebugMsg( QString(
"Loading FAILED for authcfg (%1): invalid config" ).arg( mAuthCfg ) );
161 leName->setText( mconfig.
name() );
162 leResource->setText( mconfig.
uri() );
163 authCfgEdit->setAuthConfigId( mconfig.
id() );
167 QgsDebugMsg( QString(
"Loading authcfg: %1" ).arg( mAuthCfg ) );
168 QgsDebugMsg( QString(
"Loading auth method: %1" ).arg( authMethodKey ) );
170 if ( authMethodKey.isEmpty() )
172 QgsDebugMsg( QString(
"Loading FAILED for authcfg (%1): no auth method found" ).arg( mAuthCfg ) );
176 if ( mconfig.
method() != authMethodKey )
178 QgsDebugMsg( QString(
"Loading FAILED for authcfg (%1): auth method and key mismatch" ).arg( mAuthCfg ) );
182 int indx = authMethodIndex( authMethodKey );
185 QgsDebugMsg( QString(
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'" )
186 .arg( mAuthCfg, authMethodKey ) );
187 if ( cmbAuthMethods->count() > 0 )
189 cmbAuthMethods->setCurrentIndex( 0 );
190 stkwAuthMethods->setCurrentIndex( 0 );
195 cmbAuthMethods->setCurrentIndex( indx );
196 stkwAuthMethods->setCurrentIndex( indx );
201 QgsDebugMsg( QString(
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)" )
202 .arg( mAuthCfg, authMethodKey ) );
209 void QgsAuthConfigEdit::resetConfig()
216 void QgsAuthConfigEdit::saveConfig()
221 QString authMethodKey = cmbAuthMethods->currentData().toString();
226 QgsDebugMsg( QString(
"Cast to edit widget FAILED)" ) );
233 QgsDebugMsg( QString(
"Save auth config FAILED when loading auth method instance from key (%1)" ).arg( authMethodKey ) );
238 mconfig.
setName( leName->text() );
239 mconfig.
setUri( leResource->text() );
246 QgsDebugMsg(
"Save auth config FAILED: config invalid" );
250 QString authCfgId( authCfgEdit->configId() );
251 if ( !mAuthCfg.isEmpty() )
253 if ( authCfgId == mAuthCfg )
255 mconfig.
setId( mAuthCfg );
262 QgsDebugMsg( QString(
"Updating auth config FAILED for authcfg: %1" ).arg( mAuthCfg ) );
267 mconfig.
setId( authCfgId );
273 QgsDebugMsg( QString(
"Removal of older auth config FAILED" ) );
275 mAuthCfg = authCfgId;
279 QgsDebugMsg( QString(
"Storing new auth config with user-created unique ID FAILED" ) );
283 else if ( mAuthCfg.isEmpty() )
285 if ( authCfgId.isEmpty() )
289 mAuthCfg = mconfig.
id();
294 QgsDebugMsg( QString(
"Storing new auth config FAILED" ) );
299 mconfig.
setId( authCfgId );
302 mAuthCfg = authCfgId;
307 QgsDebugMsg( QString(
"Storing new auth config with user-created unique ID FAILED" ) );
315 void QgsAuthConfigEdit::btnClear_clicked()
320 QgsDebugMsg( QString(
"Cast to edit widget FAILED)" ) );
329 void QgsAuthConfigEdit::clearAll()
333 authCfgEdit->clear();
335 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
347 void QgsAuthConfigEdit::validateAuth()
349 bool authok = !leName->text().isEmpty();
354 QgsDebugMsg( QString(
"Cast to edit widget FAILED" ) );
360 authok = authok && authCfgEdit->validate();
362 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
365 void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
371 int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
373 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
virtual QgsStringMap configMap() const =0
The configuration key-vale map of subclasses.
void setUri(const QString &uri)
QgsStringMap configMap() const
Gets extended configuration, mapped to key/value pairs of QStrings.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
void setId(const QString &id)
Sets auth config ID.
int version() const
Increment this if method is significantly updated, allow updater code to be written for previously st...
void validityChanged(bool valid)
Validity of the ID has changed.
void authenticationConfigUpdated(const QString &authcfg)
Emit current id when an existing config is updated in auth database.
Abstract base class for the edit widget of authentication method plugins.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Gets keys of supported authentication methods.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Gets authentication method from the config/provider cache via its key.
QgsAuthConfigEdit(QWidget *parent=nullptr, const QString &authcfg=QString(), const QString &dataprovider=QString())
Create a dialog for editing an authentication configuration.
virtual void clearConfig()=0
Clear GUI controls in subclassed widget.
virtual void loadConfig(const QgsStringMap &configmap)=0
Load an existing config map into subclassed widget.
void validityChanged(bool valid)
Emitted when the configuration validatity changes.
void setMethod(const QString &method)
Configuration storage class for authentication method configurations.
const QString name() const
Gets name of configuration.
QStringList configIds() const
Gets list of authentication ids from database.
QWidget * authMethodEditWidget(const QString &authMethodKey, QWidget *parent)
Gets authentication method edit widget via its key.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
QString configAuthMethodKey(const QString &authcfg) const
Gets key of authentication method associated with config ID.
virtual bool validateConfig()=0
Validate the configuration of subclasses.
Abstract base class for authentication method plugins.
void authenticationConfigStored(const QString &authcfg)
Emit generated id when a new config is saved to auth database.
virtual QString displayDescription() const =0
Translatable display version of the 'description()'.
bool storeAuthenticationConfig(QgsAuthMethodConfig &mconfig)
Store an authentication config in the database.
void setVersion(int version)
Sets version of the configuration.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
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.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.