18#include "moc_qgsauthconfigselect.cpp"
19#include "ui_qgsauthconfigselect.h"
32#include <QRegularExpression>
37 , mDataProvider( dataprovider )
42 mAuthNotifyLayout =
new QVBoxLayout;
43 this->setLayout( mAuthNotifyLayout );
45 mAuthNotifyLayout->addWidget( mAuthNotify );
50 connect( cmbConfigSelect,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged );
51 connect( btnConfigAdd, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigAdd_clicked );
52 connect( btnConfigEdit, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigEdit_clicked );
53 connect( btnConfigRemove, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigRemove_clicked );
54 connect( btnConfigMsgClear, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigMsgClear_clicked );
62 btnConfigAdd->setText( QString() );
63 btnConfigRemove->setText( QString() );
64 btnConfigEdit->setText( QString() );
65 btnConfigMsgClear->setText( QString() );
67 leConfigMsg->setStyleSheet( QStringLiteral(
"QLineEdit{background-color: %1}" )
72 populateConfigSelector();
78 if ( mDisabled && mAuthNotify )
80 mAuthNotify->setText(
QgsApplication::authManager()->disabledMessage() +
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
84 if ( mAuthCfg != authcfg )
90 mTemporarilyBlockLoad =
true;
91 populateConfigSelector();
92 mTemporarilyBlockLoad =
false;
105 populateConfigSelector();
108void QgsAuthConfigSelect::loadConfig()
111 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
115 QString methoddesc = tr(
"Missing authentication method description" );
121 cmbConfigSelect->setToolTip( tr(
"<ul><li><b>Method type:</b> %1</li>"
122 "<li><b>Configuration ID:</b> %2</li></ul>" )
123 .arg( methoddesc, config.
id() ) );
124 btnConfigEdit->setEnabled(
true );
125 btnConfigRemove->setEnabled(
true );
130void QgsAuthConfigSelect::clearConfig()
132 cmbConfigSelect->setToolTip( QString() );
133 btnConfigEdit->setEnabled(
false );
134 btnConfigRemove->setEnabled(
false );
137void QgsAuthConfigSelect::validateConfig()
139 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
141 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
146void QgsAuthConfigSelect::populateConfigSelector()
148 loadAvailableConfigs();
151 cmbConfigSelect->blockSignals(
true );
152 cmbConfigSelect->clear();
153 cmbConfigSelect->addItem( tr(
"No Authentication" ),
"0" );
156 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
157 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
160 sortmap.insert( QStringLiteral(
"%1 (%2)" ).arg( config.
name(), config.
method() ), cit.key() );
163 QgsStringMap::const_iterator sm = sortmap.constBegin();
164 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
166 cmbConfigSelect->addItem( sm.key(), sm.value() );
168 cmbConfigSelect->blockSignals(
false );
171 if ( !mAuthCfg.isEmpty() )
173 indx = cmbConfigSelect->findData( mAuthCfg );
175 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
184 leConfigMsg->setText( msg );
185 frConfigMsg->setVisible(
true );
194 leConfigMsg->clear();
195 frConfigMsg->setVisible(
false );
198void QgsAuthConfigSelect::loadAvailableConfigs()
204void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
206 const QString authcfg = cmbConfigSelect->itemData( index ).toString();
207 mAuthCfg = ( !authcfg.isEmpty() && authcfg != QLatin1String(
"0" ) ) ? authcfg : QString();
208 if ( !mTemporarilyBlockLoad )
212void QgsAuthConfigSelect::btnConfigAdd_clicked()
218 ace->setWindowModality( Qt::WindowModal );
226void QgsAuthConfigSelect::btnConfigEdit_clicked()
232 ace->setWindowModality( Qt::WindowModal );
241void QgsAuthConfigSelect::btnConfigRemove_clicked()
243 if ( QMessageBox::warning(
this, tr(
"Remove Authentication" ), tr(
"Are you sure that you want to permanently remove this configuration right now?\n\n"
244 "Operation can NOT be undone!" ),
245 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel )
246 == QMessageBox::Cancel )
258void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
266#include <QPushButton>
274 mAuthNotifyLayout =
new QVBoxLayout;
275 this->setLayout( mAuthNotifyLayout );
277 mAuthNotifyLayout->addWidget( mAuthNotify );
283 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
285 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
286 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
287 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
289 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
294 wdgtAuthSelect->setDataProviderKey( dataprovider );
305 if ( datauri.isEmpty() )
308 mDataUri = mDataUriOrig = datauri;
310 teDataUri->setPlainText( mDataUri );
312 if ( authCfgIndex() == -1 )
314 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
318 selectAuthCfgInUri();
320 mAuthCfg = authCfgFromUri();
322 QgsDebugMsgLevel( QStringLiteral(
"Parsed authcfg ID: %1" ).arg( mAuthCfg ), 2 );
324 wdgtAuthSelect->blockSignals(
true );
325 wdgtAuthSelect->setConfigId( mAuthCfg );
326 wdgtAuthSelect->blockSignals(
false );
347void QgsAuthConfigUriEdit::saveChanges()
352void QgsAuthConfigUriEdit::resetChanges()
354 wdgtAuthSelect->clearMessage();
358void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
362 if ( mAuthCfg.size() != 7 )
365 removeAuthCfgFromUri();
369 updateUriWithAuthCfg();
372 teDataUri->setPlainText( mDataUri );
373 selectAuthCfgInUri();
376void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
378 if ( authCfgFromUri() == authcfg )
380 removeAuthCfgFromUri();
384int QgsAuthConfigUriEdit::authCfgIndex()
389QString QgsAuthConfigUriEdit::authCfgFromUri()
391 const int startindex = authCfgIndex();
392 if ( startindex == -1 )
395 return mDataUri.mid( startindex + 8, 7 );
398void QgsAuthConfigUriEdit::selectAuthCfgInUri()
400 const int startindex = authCfgIndex();
401 if ( startindex == -1 )
405 QTextCursor tc = teDataUri->textCursor();
406 tc.setPosition( startindex );
407 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
408 teDataUri->setTextCursor( tc );
409 teDataUri->setFocus();
412void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
414 const int startindex = authCfgIndex();
415 if ( startindex == -1 )
417 if ( mAuthCfg.size() == 7 )
419 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
424 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
427void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
429 int startindex = authCfgIndex();
430 if ( startindex == -1 )
435 if ( startindex - 1 >= 0
436 && ( mDataUri.at( startindex - 1 ).isSpace() || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
443 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
444 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
445 mDataUri = mDataUri.remove( 0, 1 );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Widget for editing an authentication configuration.
const QString configId() const
Authentication config id, updated with generated id when a new config is saved to auth database.
void clearMessage()
Clear and hide small message bar.
void setConfigId(const QString &authcfg)
Sets the authentication config id for the resource.
void selectedConfigIdRemoved(const QString &authcfg)
Emitted when authentication config is removed.
QgsAuthConfigSelect(QWidget *parent=nullptr, const QString &dataprovider=QString())
Create a dialog for setting an associated authentication config, either from existing configs,...
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
void setDataProviderKey(const QString &key)
Sets key of layer provider, if applicable.
void showMessage(const QString &msg)
Show a small message bar with a close button.
void setDataSourceUri(const QString &datauri)
Sets the data source URI to parse.
static bool hasConfigId(const QString &txt)
Whether a string contains an authcfg ID.
QString dataSourceUri()
The returned, possibly edited data source URI.
QgsAuthConfigUriEdit(QWidget *parent=nullptr, const QString &datauri=QString(), const QString &dataprovider=QString())
Construct wrapper dialog for select widget to edit an authcfg in a data source URI.
static QColor yellowColor()
Yellow color representing caution regarding action.
static bool hasConfigId(const QString &txt)
Returns whether a string includes an authcfg ID token.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
QgsAuthMethodConfigsMap availableAuthMethodConfigs(const QString &dataprovider=QString())
Gets mapping of authentication config ids and their base configs (not decrypted data)
QString configAuthMethodKey(const QString &authcfg) const
Gets key of authentication method associated with config ID.
Configuration storage class for authentication method configurations.
QString method() const
Textual key of the associated authentication method.
const QString name() const
Gets name of configuration.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
QMap< QString, QString > QgsStringMap
#define QgsDebugMsgLevel(str, level)