18#include "ui_qgsauthconfigselect.h"
31#include <QRegularExpression>
36 , mDataProvider( dataprovider )
41 mAuthNotifyLayout =
new QVBoxLayout;
42 this->setLayout( mAuthNotifyLayout );
44 mAuthNotifyLayout->addWidget( mAuthNotify );
49 connect( cmbConfigSelect,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged );
50 connect( btnConfigAdd, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigAdd_clicked );
51 connect( btnConfigEdit, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigEdit_clicked );
52 connect( btnConfigRemove, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigRemove_clicked );
53 connect( btnConfigMsgClear, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigMsgClear_clicked );
61 btnConfigAdd->setText( QString() );
62 btnConfigRemove->setText( QString() );
63 btnConfigEdit->setText( QString() );
64 btnConfigMsgClear->setText( QString() );
66 leConfigMsg->setStyleSheet( QStringLiteral(
"QLineEdit{background-color: %1}" )
71 populateConfigSelector();
77 if ( mDisabled && mAuthNotify )
80 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>" ).arg( methoddesc, config.
id( ) ) );
123 btnConfigEdit->setEnabled(
true );
124 btnConfigRemove->setEnabled(
true );
129void QgsAuthConfigSelect::clearConfig()
131 cmbConfigSelect->setToolTip( QString() );
132 btnConfigEdit->setEnabled(
false );
133 btnConfigRemove->setEnabled(
false );
136void QgsAuthConfigSelect::validateConfig()
138 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
140 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
145void QgsAuthConfigSelect::populateConfigSelector()
147 loadAvailableConfigs();
150 cmbConfigSelect->blockSignals(
true );
151 cmbConfigSelect->clear();
152 cmbConfigSelect->addItem( tr(
"No Authentication" ),
"0" );
155 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
156 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
159 sortmap.insert( QStringLiteral(
"%1 (%2)" ).arg( config.
name(), config.
method() ), cit.key() );
162 QgsStringMap::const_iterator sm = sortmap.constBegin();
163 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
165 cmbConfigSelect->addItem( sm.key(), sm.value() );
167 cmbConfigSelect->blockSignals(
false );
170 if ( !mAuthCfg.isEmpty() )
172 indx = cmbConfigSelect->findData( mAuthCfg );
174 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
183 leConfigMsg->setText( msg );
184 frConfigMsg->setVisible(
true );
193 leConfigMsg->clear();
194 frConfigMsg->setVisible(
false );
197void QgsAuthConfigSelect::loadAvailableConfigs()
203void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
205 const QString authcfg = cmbConfigSelect->itemData( index ).toString();
206 mAuthCfg = ( !authcfg.isEmpty() && authcfg != QLatin1String(
"0" ) ) ? authcfg : QString();
207 if ( !mTemporarilyBlockLoad )
211void QgsAuthConfigSelect::btnConfigAdd_clicked()
217 ace->setWindowModality( Qt::WindowModal );
225void QgsAuthConfigSelect::btnConfigEdit_clicked()
231 ace->setWindowModality( Qt::WindowModal );
240void QgsAuthConfigSelect::btnConfigRemove_clicked()
242 if ( QMessageBox::warning(
this, tr(
"Remove Authentication" ),
243 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,
246 QMessageBox::Cancel ) == 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()
437 || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
444 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
445 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
446 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)