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 )
81 tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
85 if ( mAuthCfg != authcfg )
91 mTemporarilyBlockLoad =
true;
92 populateConfigSelector();
93 mTemporarilyBlockLoad =
false;
106 populateConfigSelector();
109void QgsAuthConfigSelect::loadConfig()
112 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
116 QString methoddesc = tr(
"Missing authentication method description" );
122 cmbConfigSelect->setToolTip( tr(
"<ul><li><b>Method type:</b> %1</li>"
123 "<li><b>Configuration ID:</b> %2</li></ul>" ).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" ),
244 tr(
"Are you sure that you want to permanently remove this configuration right now?\n\n"
245 "Operation can NOT be undone!" ),
246 QMessageBox::Ok | QMessageBox::Cancel,
247 QMessageBox::Cancel ) == QMessageBox::Cancel )
259void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
267#include <QPushButton>
275 mAuthNotifyLayout =
new QVBoxLayout;
276 this->setLayout( mAuthNotifyLayout );
278 mAuthNotifyLayout->addWidget( mAuthNotify );
284 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
286 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
287 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
288 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
290 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
295 wdgtAuthSelect->setDataProviderKey( dataprovider );
306 if ( datauri.isEmpty() )
309 mDataUri = mDataUriOrig = datauri;
311 teDataUri->setPlainText( mDataUri );
313 if ( authCfgIndex() == -1 )
315 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
319 selectAuthCfgInUri();
321 mAuthCfg = authCfgFromUri();
323 QgsDebugMsgLevel( QStringLiteral(
"Parsed authcfg ID: %1" ).arg( mAuthCfg ), 2 );
325 wdgtAuthSelect->blockSignals(
true );
326 wdgtAuthSelect->setConfigId( mAuthCfg );
327 wdgtAuthSelect->blockSignals(
false );
348void QgsAuthConfigUriEdit::saveChanges()
353void QgsAuthConfigUriEdit::resetChanges()
355 wdgtAuthSelect->clearMessage();
359void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
363 if ( mAuthCfg.size() != 7 )
366 removeAuthCfgFromUri();
370 updateUriWithAuthCfg();
373 teDataUri->setPlainText( mDataUri );
374 selectAuthCfgInUri();
377void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
379 if ( authCfgFromUri() == authcfg )
381 removeAuthCfgFromUri();
385int QgsAuthConfigUriEdit::authCfgIndex()
390QString QgsAuthConfigUriEdit::authCfgFromUri()
392 const int startindex = authCfgIndex();
393 if ( startindex == -1 )
396 return mDataUri.mid( startindex + 8, 7 );
399void QgsAuthConfigUriEdit::selectAuthCfgInUri()
401 const int startindex = authCfgIndex();
402 if ( startindex == -1 )
406 QTextCursor tc = teDataUri->textCursor();
407 tc.setPosition( startindex );
408 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
409 teDataUri->setTextCursor( tc );
410 teDataUri->setFocus();
413void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
415 const int startindex = authCfgIndex();
416 if ( startindex == -1 )
418 if ( mAuthCfg.size() == 7 )
420 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
425 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
428void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
430 int startindex = authCfgIndex();
431 if ( startindex == -1 )
436 if ( startindex - 1 >= 0
437 && ( mDataUri.at( startindex - 1 ).isSpace()
438 || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
445 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
446 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
447 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)