18#include "moc_qgsauthconfigedit.cpp"
34 , mDataProvider( dataprovider )
40 if ( !disabled && !authcfg.isEmpty() )
45 if ( disabled || !idok )
47 mAuthNotifyLayout =
new QVBoxLayout;
48 this->setLayout( mAuthNotifyLayout );
51 if ( !authcfg.isEmpty() )
53 msg +=
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg );
55 mAuthNotify =
new QLabel( msg,
this );
56 mAuthNotifyLayout->addWidget( mAuthNotify );
59 buttonBox->button( QDialogButtonBox::Save )->setEnabled(
false );
64 connect( btnClear, &QToolButton::clicked,
this, &QgsAuthConfigEdit::btnClear_clicked );
65 connect( leName, &QLineEdit::textChanged,
this, &QgsAuthConfigEdit::leName_textChanged );
66 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
67 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigEdit::saveConfig );
68 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigEdit::resetConfig );
70 populateAuthMethods();
72 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
73 stkwAuthMethods, &QStackedWidget::setCurrentIndex );
74 connect( cmbAuthMethods,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
75 this, [ = ] { validateAuth(); } );
86 if ( cmbAuthMethods->count() > 0 )
88 cmbAuthMethods->setCurrentIndex( 0 );
89 stkwAuthMethods->setCurrentIndex( 0 );
101void QgsAuthConfigEdit::populateAuthMethods()
106 QMap<QString, const QgsAuthMethodMetadata *> descmap;
107 const auto constAuthMethodKeys = authMethodKeys;
108 for (
const QString &authMethodKey : constAuthMethodKeys )
113 QgsDebugError( QStringLiteral(
"Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
119 QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
120 for ( it = descmap.begin(); it != descmap.end(); ++it )
126 QgsDebugError( QStringLiteral(
"Load auth method edit widget FAILED for auth method key (%1)" ).arg( it.value()->key() ) );
131 cmbAuthMethods->addItem( it.key(), QVariant( it.value()->key() ) );
132 stkwAuthMethods->addWidget( editWidget );
136void QgsAuthConfigEdit::loadConfig()
138 const bool emptyAuthCfg = mAuthCfg.isEmpty();
139 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
155 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg: %1" ).arg( mAuthCfg ) );
159 if ( !mconfig.
isValid(
true ) )
161 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): invalid config" ).arg( mAuthCfg ) );
166 leName->setText( mconfig.
name() );
167 leResource->setText( mconfig.
uri() );
168 authCfgEdit->setAuthConfigId( mconfig.
id() );
172 QgsDebugMsgLevel( QStringLiteral(
"Loading authcfg: %1" ).arg( mAuthCfg ), 2 );
173 QgsDebugMsgLevel( QStringLiteral(
"Loading auth method: %1" ).arg( authMethodKey ), 2 );
175 if ( authMethodKey.isEmpty() )
177 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no auth method found" ).arg( mAuthCfg ) );
181 if ( mconfig.
method() != authMethodKey )
183 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): auth method and key mismatch" ).arg( mAuthCfg ) );
187 const int indx = authMethodIndex( authMethodKey );
190 QgsDebugError( QStringLiteral(
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'" )
191 .arg( mAuthCfg, authMethodKey ) );
192 if ( cmbAuthMethods->count() > 0 )
194 cmbAuthMethods->setCurrentIndex( 0 );
195 stkwAuthMethods->setCurrentIndex( 0 );
200 cmbAuthMethods->setCurrentIndex( indx );
201 stkwAuthMethods->setCurrentIndex( indx );
206 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)" )
207 .arg( mAuthCfg, authMethodKey ) );
214void QgsAuthConfigEdit::resetConfig()
221void QgsAuthConfigEdit::saveConfig()
226 const QString authMethodKey = cmbAuthMethods->currentData().toString();
231 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
238 QgsDebugError( QStringLiteral(
"Save auth config FAILED when loading auth method instance from key (%1)" ).arg( authMethodKey ) );
243 mconfig.
setName( leName->text() );
244 mconfig.
setUri( leResource->text() );
251 QgsDebugError( QStringLiteral(
"Save auth config FAILED: config invalid" ) );
255 const QString authCfgId( authCfgEdit->configId() );
256 if ( !mAuthCfg.isEmpty() )
258 if ( authCfgId == mAuthCfg )
260 mconfig.
setId( mAuthCfg );
267 QgsDebugError( QStringLiteral(
"Updating auth config FAILED for authcfg: %1" ).arg( mAuthCfg ) );
272 mconfig.
setId( authCfgId );
278 QgsDebugError( QStringLiteral(
"Removal of older auth config FAILED" ) );
280 mAuthCfg = authCfgId;
284 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
288 else if ( mAuthCfg.isEmpty() )
290 if ( authCfgId.isEmpty() )
294 mAuthCfg = mconfig.
id();
299 QgsDebugError( QStringLiteral(
"Storing new auth config FAILED" ) );
304 mconfig.
setId( authCfgId );
307 mAuthCfg = authCfgId;
312 QgsDebugError( QStringLiteral(
"Storing new auth config with user-created unique ID FAILED" ) );
320void QgsAuthConfigEdit::btnClear_clicked()
325 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED)" ) );
334void QgsAuthConfigEdit::clearAll()
338 authCfgEdit->clear();
340 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
342 QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>( stkwAuthMethods->widget( i ) );
352void QgsAuthConfigEdit::validateAuth()
354 bool authok = !leName->text().isEmpty();
359 QgsDebugError( QStringLiteral(
"Cast to edit widget FAILED" ) );
365 authok = authok && authCfgEdit->validate();
367 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
370void QgsAuthConfigEdit::leName_textChanged(
const QString &txt )
376int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
378 return cmbAuthMethods->findData( QVariant( authMethodKey ) );
383 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)