17#include "ui_qgsauthconfigselect.h"
30#include <QRegularExpression>
34#include "moc_qgsauthconfigselect.cpp"
36using namespace Qt::StringLiterals;
40 , mDataProvider( dataprovider )
45 mAuthNotifyLayout =
new QVBoxLayout;
46 this->setLayout( mAuthNotifyLayout );
48 mAuthNotifyLayout->addWidget( mAuthNotify );
53 connect( cmbConfigSelect,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged );
54 connect( btnConfigAdd, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigAdd_clicked );
55 connect( btnConfigEdit, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigEdit_clicked );
56 connect( btnConfigRemove, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigRemove_clicked );
57 connect( btnConfigMsgClear, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigMsgClear_clicked );
65 btnConfigAdd->setText( QString() );
66 btnConfigRemove->setText( QString() );
67 btnConfigEdit->setText( QString() );
68 btnConfigMsgClear->setText( QString() );
74 populateConfigSelector();
80 if ( mDisabled && mAuthNotify )
82 mAuthNotify->setText(
QgsApplication::authManager()->disabledMessage() +
"\n\n" + tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
86 if ( mAuthCfg != authcfg )
92 mTemporarilyBlockLoad =
true;
93 populateConfigSelector();
94 mTemporarilyBlockLoad =
false;
107 populateConfigSelector();
110void QgsAuthConfigSelect::loadConfig()
113 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
117 QString methoddesc = tr(
"Missing authentication method description" );
123 cmbConfigSelect->setToolTip( tr(
124 "<ul><li><b>Method type:</b> %1</li>"
125 "<li><b>Configuration ID:</b> %2</li></ul>"
127 .arg( methoddesc, config.
id() ) );
128 btnConfigEdit->setEnabled(
true );
129 btnConfigRemove->setEnabled(
true );
134void QgsAuthConfigSelect::clearConfig()
136 cmbConfigSelect->setToolTip( QString() );
137 btnConfigEdit->setEnabled(
false );
138 btnConfigRemove->setEnabled(
false );
141void QgsAuthConfigSelect::validateConfig()
143 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
145 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
150void QgsAuthConfigSelect::populateConfigSelector()
152 loadAvailableConfigs();
155 cmbConfigSelect->blockSignals(
true );
156 cmbConfigSelect->clear();
157 cmbConfigSelect->addItem( tr(
"No Authentication" ),
"0" );
160 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
161 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
163 const QgsAuthMethodConfig config = cit.value();
164 sortmap.insert( u
"%1 (%2)"_s.arg( config.
name(), config.
method() ), cit.key() );
167 QgsStringMap::const_iterator sm = sortmap.constBegin();
168 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
170 cmbConfigSelect->addItem( sm.key(), sm.value() );
172 cmbConfigSelect->blockSignals(
false );
175 if ( !mAuthCfg.isEmpty() )
177 indx = cmbConfigSelect->findData( mAuthCfg );
179 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
188 leConfigMsg->setText( msg );
189 frConfigMsg->setVisible(
true );
198 leConfigMsg->clear();
199 frConfigMsg->setVisible(
false );
202void QgsAuthConfigSelect::loadAvailableConfigs()
208void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
210 const QString authcfg = cmbConfigSelect->itemData( index ).toString();
211 mAuthCfg = ( !authcfg.isEmpty() && authcfg !=
"0"_L1 ) ? authcfg : QString();
212 if ( !mTemporarilyBlockLoad )
216void QgsAuthConfigSelect::btnConfigAdd_clicked()
221 QgsAuthConfigEdit *ace =
new QgsAuthConfigEdit(
this, QString(), mDataProvider );
222 ace->setWindowModality( Qt::WindowModal );
230void QgsAuthConfigSelect::btnConfigEdit_clicked()
235 QgsAuthConfigEdit *ace =
new QgsAuthConfigEdit(
this, mAuthCfg, mDataProvider );
236 ace->setWindowModality( Qt::WindowModal );
245void QgsAuthConfigSelect::btnConfigRemove_clicked()
247 if ( QMessageBox::warning(
249 tr(
"Remove Authentication" ),
251 "Are you sure that you want to permanently remove this configuration right now?\n\n"
252 "Operation can NOT be undone!"
254 QMessageBox::Ok | QMessageBox::Cancel,
257 == QMessageBox::Cancel )
269void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
277#include <QPushButton>
285 mAuthNotifyLayout =
new QVBoxLayout;
286 this->setLayout( mAuthNotifyLayout );
288 mAuthNotifyLayout->addWidget( mAuthNotify );
294 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
296 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
297 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
298 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
300 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
305 wdgtAuthSelect->setDataProviderKey( dataprovider );
316 if ( datauri.isEmpty() )
319 mDataUri = mDataUriOrig = datauri;
321 teDataUri->setPlainText( mDataUri );
323 if ( authCfgIndex() == -1 )
325 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
329 selectAuthCfgInUri();
331 mAuthCfg = authCfgFromUri();
335 wdgtAuthSelect->blockSignals(
true );
336 wdgtAuthSelect->setConfigId( mAuthCfg );
337 wdgtAuthSelect->blockSignals(
false );
358void QgsAuthConfigUriEdit::saveChanges()
363void QgsAuthConfigUriEdit::resetChanges()
365 wdgtAuthSelect->clearMessage();
369void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
373 if ( mAuthCfg.size() != 7 )
376 removeAuthCfgFromUri();
380 updateUriWithAuthCfg();
383 teDataUri->setPlainText( mDataUri );
384 selectAuthCfgInUri();
387void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
389 if ( authCfgFromUri() == authcfg )
391 removeAuthCfgFromUri();
395int QgsAuthConfigUriEdit::authCfgIndex()
400QString QgsAuthConfigUriEdit::authCfgFromUri()
402 const int startindex = authCfgIndex();
403 if ( startindex == -1 )
406 return mDataUri.mid( startindex + 8, 7 );
409void QgsAuthConfigUriEdit::selectAuthCfgInUri()
411 const int startindex = authCfgIndex();
412 if ( startindex == -1 )
416 QTextCursor tc = teDataUri->textCursor();
417 tc.setPosition( startindex );
418 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
419 teDataUri->setTextCursor( tc );
420 teDataUri->setFocus();
423void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
425 const int startindex = authCfgIndex();
426 if ( startindex == -1 )
428 if ( mAuthCfg.size() == 7 )
430 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
435 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
438void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
440 int startindex = authCfgIndex();
441 if ( startindex == -1 )
446 if ( startindex - 1 >= 0 && ( mDataUri.at( startindex - 1 ).isSpace() || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
453 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
454 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
455 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,...
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)