19 #include <QPushButton>
31 , mDataProvider( dataprovider )
32 , mAuthNotifyLayout( 0 )
38 if ( !disabled && !authcfg.
isEmpty() )
43 if ( disabled || !idok )
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 );
64 connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL( clicked() ),
this, SLOT( resetConfig() ) );
66 populateAuthMethods();
68 connect( cmbAuthMethods, SIGNAL( currentIndexChanged(
int ) ),
69 stkwAuthMethods, SLOT( setCurrentIndex(
int ) ) );
70 connect( cmbAuthMethods, SIGNAL( currentIndexChanged(
int ) ),
71 this, SLOT( validateAuth() ) );
73 connect( authCfgEdit, SIGNAL( validityChanged(
bool ) ),
this, SLOT( validateAuth() ) );
82 if ( cmbAuthMethods->count() > 0 )
84 cmbAuthMethods->setCurrentIndex( 0 );
85 stkwAuthMethods->setCurrentIndex( 0 );
99 void QgsAuthConfigEdit::populateAuthMethods()
105 Q_FOREACH (
const QString &authMethodKey, authMethodKeys )
110 QgsDebugMsg(
QString(
"Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
117 for ( it = descmap.
begin(); it != descmap.
end(); ++it )
123 QgsDebugMsg(
QString(
"Load auth method edit widget FAILED for auth method key (%1)" ).arg( it.
value()->key() ) );
126 connect( editWidget, SIGNAL( validityChanged(
bool ) ),
this, SLOT( validateAuth() ) );
129 stkwAuthMethods->addWidget( editWidget );
133 void QgsAuthConfigEdit::loadConfig()
135 bool emptyAuthCfg = mAuthCfg.
isEmpty();
136 authCfgEdit->setAllowEmptyId( emptyAuthCfg );
156 if ( !mconfig.
isValid(
true ) )
158 QgsDebugMsg(
QString(
"Loading FAILED for authcfg (%1): invalid config" ).arg( mAuthCfg ) );
163 leName->setText( mconfig.
name() );
164 leResource->setText( mconfig.
uri() );
165 authCfgEdit->setAuthConfigId( mconfig.
id() );
174 QgsDebugMsg(
QString(
"Loading FAILED for authcfg (%1): no auth method found" ).arg( mAuthCfg ) );
178 if ( mconfig.
method() != authMethodKey )
180 QgsDebugMsg(
QString(
"Loading FAILED for authcfg (%1): auth method and key mismatch" ).arg( mAuthCfg ) );
184 int indx = authMethodIndex( authMethodKey );
187 QgsDebugMsg(
QString(
"Loading FAILED for authcfg (%1): no edit widget loaded for auth method '%2'" )
188 .arg( mAuthCfg, authMethodKey ) );
189 if ( cmbAuthMethods->count() > 0 )
191 cmbAuthMethods->setCurrentIndex( 0 );
192 stkwAuthMethods->setCurrentIndex( 0 );
197 cmbAuthMethods->setCurrentIndex( indx );
198 stkwAuthMethods->setCurrentIndex( indx );
203 QgsDebugMsg(
QString(
"Cast to edit widget FAILED for authcfg (%1) and auth method key (%2)" )
204 .arg( mAuthCfg, authMethodKey ) );
211 void QgsAuthConfigEdit::resetConfig()
218 void QgsAuthConfigEdit::saveConfig()
223 QString authMethodKey = cmbAuthMethods->itemData( cmbAuthMethods->currentIndex() ).
toString();
235 QgsDebugMsg(
QString(
"Save auth config FAILED when loading auth method instance from key (%1)" ).arg( authMethodKey ) );
240 mconfig.
setName( leName->text() );
241 mconfig.
setUri( leResource->text() );
248 QgsDebugMsg(
"Save auth config FAILED: config invalid" );
252 QString authCfgId( authCfgEdit->configId() );
255 if ( authCfgId == mAuthCfg )
257 mconfig.
setId( mAuthCfg );
264 QgsDebugMsg(
QString(
"Updating auth config FAILED for authcfg: %1" ).arg( mAuthCfg ) );
269 mconfig.
setId( authCfgId );
277 mAuthCfg = authCfgId;
281 QgsDebugMsg(
QString(
"Storing new auth config with user-created unique ID FAILED" ) );
287 if ( authCfgId.isEmpty() )
291 mAuthCfg = mconfig.
id();
301 mconfig.
setId( authCfgId );
304 mAuthCfg = authCfgId;
309 QgsDebugMsg(
QString(
"Storing new auth config with user-created unique ID FAILED" ) );
317 void QgsAuthConfigEdit::on_btnClear_clicked()
331 void QgsAuthConfigEdit::clearAll()
335 authCfgEdit->clear();
337 for (
int i = 0; i < stkwAuthMethods->count(); i++ )
349 void QgsAuthConfigEdit::validateAuth()
351 bool authok = !leName->text().isEmpty();
362 authok = authok && authCfgEdit->validate();
364 buttonBox->button( QDialogButtonBox::Save )->setEnabled( authok );
367 void QgsAuthConfigEdit::on_leName_textChanged(
const QString& txt )
373 int QgsAuthConfigEdit::authMethodIndex(
const QString &authMethodKey )
375 return cmbAuthMethods->findData(
QVariant( authMethodKey ) );
virtual QgsStringMap configMap() const =0
The configuration key-vale map of subclasses.
void setUri(const QString &uri)
void setId(const QString &id)
Set auth config ID.
static QgsAuthManager * instance()
Enforce singleton pattern.
void authenticationConfigUpdated(const QString &authcfg)
Emit current id when an existing config is updated in auth database.
QgsAuthConfigEdit(QWidget *parent=0, const QString &authcfg=QString(), const QString &dataprovider=QString())
Create a dialog for editing an authentication configuration.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Abstract base class for the edit widget of authentication method plugins.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Get keys of supported authentication methods.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Get authentication method from the config/provider cache via its key.
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual void clearConfig()=0
Clear GUI controls in subclassed widget.
const QString name() const
Get name of configuration.
virtual void loadConfig(const QgsStringMap &configmap)=0
Load an existing config map into subclassed widget.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
QgsStringMap configMap() const
Get extended configuration, mapped to key/value pairs of QStrings.
void setMethod(const QString &method)
Configuration storage class for authentication method configurations.
int version() const
Increment this if method is significantly updated, allow updater code to be written for previously st...
const QString id() const
Get 'authcfg' 7-character alphanumeric ID of the config.
QWidget * authMethodEditWidget(const QString &authMethodKey, QWidget *parent)
Get authentication method edit widget via its key.
QString configAuthMethodKey(const QString &authcfg) const
Get key of authentication method associated with config ID.
virtual bool validateConfig()=0
Validate the configuration of subclasses.
Abstract base class for authentication method plugins.
QStringList configIds() const
Get list of authentication ids from database.
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)
Set version of the configuration.
iterator insert(const Key &key, const T &value)
bool isValid(bool validateid=false) const
Whether the configuration is valid.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setName(const QString &name)
Set name of configuration.
void setConfigMap(const QgsStringMap &map)
Set extended configuration map.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString method() const
Textual key of the associated authentication method.
char * toString(const QLatin1String &string)