17#include "ui_qgsauthconfigselect.h"
34#include <QRegularExpression>
38#include "moc_qgsauthconfigselect.cpp"
43using namespace Qt::StringLiterals;
47 , mDataProvider( dataprovider )
52 mAuthNotifyLayout =
new QVBoxLayout;
53 this->setLayout( mAuthNotifyLayout );
55 mAuthNotifyLayout->addWidget( mAuthNotify );
60 connect( cmbConfigSelect,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged );
61 connect( btnConfigAdd, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigAdd_clicked );
62 connect( btnConfigEdit, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigEdit_clicked );
63 connect( btnConfigRemove, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigRemove_clicked );
64 connect( btnConfigMsgClear, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigMsgClear_clicked );
72 btnConfigAdd->setText( QString() );
73 btnConfigRemove->setText( QString() );
74 btnConfigEdit->setText( QString() );
75 btnConfigMsgClear->setText( QString() );
81 populateConfigSelector();
87 if ( mDisabled && mAuthNotify )
89 mAuthNotify->setText(
QgsApplication::authManager()->disabledMessage() +
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
93 if ( mAuthCfg != authcfg )
99 mTemporarilyBlockLoad =
true;
100 populateConfigSelector();
101 mTemporarilyBlockLoad =
false;
114 populateConfigSelector();
117void QgsAuthConfigSelect::loadConfig()
120 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
124 QString methoddesc = tr(
"Missing authentication method description" );
130 cmbConfigSelect->setToolTip( tr(
131 "<ul><li><b>Method type:</b> %1</li>"
132 "<li><b>Configuration ID:</b> %2</li></ul>"
134 .arg( methoddesc, config.
id() ) );
135 btnConfigEdit->setEnabled( authCfgDetailsDisplayed() );
136 btnConfigRemove->setEnabled( authCfgDetailsDisplayed() );
141void QgsAuthConfigSelect::clearConfig()
143 cmbConfigSelect->setToolTip( QString() );
144 btnConfigEdit->setEnabled(
false );
145 btnConfigRemove->setEnabled(
false );
148void QgsAuthConfigSelect::validateConfig()
150 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
152 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
157void QgsAuthConfigSelect::populateConfigSelector()
159 loadAvailableConfigs();
162 cmbConfigSelect->blockSignals(
true );
163 cmbConfigSelect->clear();
164 cmbConfigSelect->addItem( tr(
"No Authentication" ),
"0" );
167 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
168 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
170 const QgsAuthMethodConfig config = cit.value();
171 sortmap.insert( u
"%1 (%2)"_s.arg( config.
name(), config.
method() ), cit.key() );
174 QgsStringMap::const_iterator sm = sortmap.constBegin();
175 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
177 cmbConfigSelect->addItem( sm.key(), sm.value() );
179 cmbConfigSelect->blockSignals(
false );
182 if ( !mAuthCfg.isEmpty() )
184 indx = cmbConfigSelect->findData( mAuthCfg );
186 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
195 leConfigMsg->setText( msg );
196 frConfigMsg->setVisible(
true );
205 leConfigMsg->clear();
206 frConfigMsg->setVisible(
false );
209void QgsAuthConfigSelect::loadAvailableConfigs()
215void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
217 const QString authcfg = cmbConfigSelect->itemData( index ).toString();
218 mAuthCfg = ( !authcfg.isEmpty() && authcfg !=
"0"_L1 ) ? authcfg : QString();
219 if ( !mTemporarilyBlockLoad )
223void QgsAuthConfigSelect::btnConfigAdd_clicked()
228 QgsAuthConfigEdit *ace =
new QgsAuthConfigEdit(
this, QString(), mDataProvider );
229 ace->setWindowModality( Qt::WindowModal );
237void QgsAuthConfigSelect::btnConfigEdit_clicked()
242 if ( !authCfgDetailsDisplayed() )
247 QgsAuthConfigEdit *ace =
new QgsAuthConfigEdit(
this, mAuthCfg, mDataProvider );
248 ace->setWindowModality( Qt::WindowModal );
257bool QgsAuthConfigSelect::authCfgDetailsDisplayed()
const
261 for (
auto it = nonEditableAuthStores.constBegin(); it != nonEditableAuthStores.constEnd(); ++it )
264 if ( authCfgStorage )
275void QgsAuthConfigSelect::btnConfigRemove_clicked()
277 if ( !authCfgDetailsDisplayed() )
282 if ( QMessageBox::warning(
284 tr(
"Remove Authentication" ),
286 "Are you sure that you want to permanently remove this configuration right now?\n\n"
287 "Operation can NOT be undone!"
289 QMessageBox::Ok | QMessageBox::Cancel,
292 == QMessageBox::Cancel )
304void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
312#include <QPushButton>
320 mAuthNotifyLayout =
new QVBoxLayout;
321 this->setLayout( mAuthNotifyLayout );
323 mAuthNotifyLayout->addWidget( mAuthNotify );
329 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
331 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
332 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
333 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
335 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
340 wdgtAuthSelect->setDataProviderKey( dataprovider );
351 if ( datauri.isEmpty() )
354 mDataUri = mDataUriOrig = datauri;
356 teDataUri->setPlainText( mDataUri );
358 if ( authCfgIndex() == -1 )
360 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
364 selectAuthCfgInUri();
366 mAuthCfg = authCfgFromUri();
370 wdgtAuthSelect->blockSignals(
true );
371 wdgtAuthSelect->setConfigId( mAuthCfg );
372 wdgtAuthSelect->blockSignals(
false );
393void QgsAuthConfigUriEdit::saveChanges()
398void QgsAuthConfigUriEdit::resetChanges()
400 wdgtAuthSelect->clearMessage();
404void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
408 if ( mAuthCfg.size() != 7 )
411 removeAuthCfgFromUri();
415 updateUriWithAuthCfg();
418 teDataUri->setPlainText( mDataUri );
419 selectAuthCfgInUri();
422void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
424 if ( authCfgFromUri() == authcfg )
426 removeAuthCfgFromUri();
430int QgsAuthConfigUriEdit::authCfgIndex()
435QString QgsAuthConfigUriEdit::authCfgFromUri()
437 const int startindex = authCfgIndex();
438 if ( startindex == -1 )
441 return mDataUri.mid( startindex + 8, 7 );
444void QgsAuthConfigUriEdit::selectAuthCfgInUri()
446 const int startindex = authCfgIndex();
447 if ( startindex == -1 )
451 QTextCursor tc = teDataUri->textCursor();
452 tc.setPosition( startindex );
453 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
454 teDataUri->setTextCursor( tc );
455 teDataUri->setFocus();
458void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
460 const int startindex = authCfgIndex();
461 if ( startindex == -1 )
463 if ( mAuthCfg.size() == 7 )
465 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
470 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
473void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
475 int startindex = authCfgIndex();
476 if ( startindex == -1 )
481 if ( startindex - 1 >= 0 && ( mDataUri.at( startindex - 1 ).isSpace() || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
488 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
489 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
490 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.
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,...
static const QgsSettingsEntryStringList * settingsDetailsNotDisplayedAuthStores
Settings entry details not displayed auth stores.
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.
QgsAuthConfigurationStorage * storage(const QString &id) const
Returns the storage with the specified id or nullptr if not found in the registry.
virtual bool methodConfigExists(const QString &id) const =0
Check if an authentication configuration exists in the storage.
static QColor yellowColor()
Yellow color representing caution regarding action.
static bool hasConfigId(const QString &txt)
Returns whether a string includes an authcfg ID token.
QgsAuthConfigurationStorageRegistry * authConfigurationStorageRegistry() const
Returns the authentication configuration storage registry.
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.
A string list settings entry.
static QgsSettingsTreeNode * sTreeQgis
QMap< QString, QString > QgsStringMap
#define QgsDebugMsgLevel(str, level)