18 #include "ui_qgsauthconfigselect.h"
21 #include <QMessageBox>
34 , mDataProvider( dataprovider )
39 mAuthNotifyLayout =
new QVBoxLayout;
40 this->setLayout( mAuthNotifyLayout );
42 mAuthNotifyLayout->addWidget( mAuthNotify );
47 connect( cmbConfigSelect,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged );
48 connect( btnConfigAdd, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigAdd_clicked );
49 connect( btnConfigEdit, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigEdit_clicked );
50 connect( btnConfigRemove, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigRemove_clicked );
51 connect( btnConfigMsgClear, &QToolButton::clicked,
this, &QgsAuthConfigSelect::btnConfigMsgClear_clicked );
59 btnConfigAdd->setText( QString() );
60 btnConfigRemove->setText( QString() );
61 btnConfigEdit->setText( QString() );
62 btnConfigMsgClear->setText( QString() );
64 leConfigMsg->setStyleSheet( QStringLiteral(
"QLineEdit{background-color: %1}" )
69 populateConfigSelector();
75 if ( mDisabled && mAuthNotify )
78 tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
82 if ( mAuthCfg != authcfg )
88 mTemporarilyBlockLoad =
true;
89 populateConfigSelector();
90 mTemporarilyBlockLoad =
false;
103 populateConfigSelector();
106 void QgsAuthConfigSelect::loadConfig()
109 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
113 QString methoddesc = tr(
"Missing authentication method description" );
118 cmbConfigSelect->setToolTip( tr(
"<ul><li><b>Method type:</b> %1</li>"
119 "<li><b>Configuration ID:</b> %2</li></ul>" ).arg( methoddesc, config.
id( ) ) );
120 btnConfigEdit->setEnabled(
true );
121 btnConfigRemove->setEnabled(
true );
126 void QgsAuthConfigSelect::clearConfig()
128 cmbConfigSelect->setToolTip( QString() );
129 btnConfigEdit->setEnabled(
false );
130 btnConfigRemove->setEnabled(
false );
133 void QgsAuthConfigSelect::validateConfig()
135 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
137 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
142 void QgsAuthConfigSelect::populateConfigSelector()
144 loadAvailableConfigs();
147 cmbConfigSelect->blockSignals(
true );
148 cmbConfigSelect->clear();
149 cmbConfigSelect->addItem( tr(
"No Authentication" ),
"0" );
152 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
153 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
156 sortmap.insert( QStringLiteral(
"%1 (%2)" ).arg( config.
name(), config.
method() ), cit.key() );
159 QgsStringMap::const_iterator sm = sortmap.constBegin();
160 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
162 cmbConfigSelect->addItem( sm.key(), sm.value() );
164 cmbConfigSelect->blockSignals(
false );
167 if ( !mAuthCfg.isEmpty() )
169 indx = cmbConfigSelect->findData( mAuthCfg );
171 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
180 leConfigMsg->setText( msg );
181 frConfigMsg->setVisible(
true );
190 leConfigMsg->clear();
191 frConfigMsg->setVisible(
false );
194 void QgsAuthConfigSelect::loadAvailableConfigs()
200 void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
202 QString authcfg = cmbConfigSelect->itemData( index ).toString();
203 mAuthCfg = ( !authcfg.isEmpty() && authcfg != QLatin1String(
"0" ) ) ? authcfg : QString();
204 if ( !mTemporarilyBlockLoad )
208 void QgsAuthConfigSelect::btnConfigAdd_clicked()
214 ace->setWindowModality( Qt::WindowModal );
222 void QgsAuthConfigSelect::btnConfigEdit_clicked()
228 ace->setWindowModality( Qt::WindowModal );
237 void QgsAuthConfigSelect::btnConfigRemove_clicked()
239 if ( QMessageBox::warning(
this, tr(
"Remove Authentication" ),
240 tr(
"Are you sure that you want to permanently remove this configuration right now?\n\n"
241 "Operation can NOT be undone!" ),
242 QMessageBox::Ok | QMessageBox::Cancel,
243 QMessageBox::Cancel ) == QMessageBox::Cancel )
255 void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
263 #include <QPushButton>
271 mAuthNotifyLayout =
new QVBoxLayout;
272 this->setLayout( mAuthNotifyLayout );
274 mAuthNotifyLayout->addWidget( mAuthNotify );
280 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
282 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
283 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
284 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
286 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
291 wdgtAuthSelect->setDataProviderKey( dataprovider );
302 if ( datauri.isEmpty() )
305 mDataUri = mDataUriOrig = datauri;
307 teDataUri->setPlainText( mDataUri );
309 if ( authCfgIndex() == -1 )
311 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
315 selectAuthCfgInUri();
317 mAuthCfg = authCfgFromUri();
319 QgsDebugMsg( QStringLiteral(
"Parsed authcfg ID: %1" ).arg( mAuthCfg ) );
321 wdgtAuthSelect->blockSignals(
true );
322 wdgtAuthSelect->setConfigId( mAuthCfg );
323 wdgtAuthSelect->blockSignals(
false );
344 void QgsAuthConfigUriEdit::saveChanges()
349 void QgsAuthConfigUriEdit::resetChanges()
351 wdgtAuthSelect->clearMessage();
355 void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
359 if ( mAuthCfg.size() != 7 )
362 removeAuthCfgFromUri();
366 updateUriWithAuthCfg();
369 teDataUri->setPlainText( mDataUri );
370 selectAuthCfgInUri();
373 void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
375 if ( authCfgFromUri() == authcfg )
377 removeAuthCfgFromUri();
381 int QgsAuthConfigUriEdit::authCfgIndex()
384 return rx.indexIn( mDataUri );
387 QString QgsAuthConfigUriEdit::authCfgFromUri()
389 int startindex = authCfgIndex();
390 if ( startindex == -1 )
393 return mDataUri.mid( startindex + 8, 7 );
396 void QgsAuthConfigUriEdit::selectAuthCfgInUri()
398 int startindex = authCfgIndex();
399 if ( startindex == -1 )
403 QTextCursor tc = teDataUri->textCursor();
404 tc.setPosition( startindex );
405 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
406 teDataUri->setTextCursor( tc );
407 teDataUri->setFocus();
410 void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
412 int startindex = authCfgIndex();
413 if ( startindex == -1 )
415 if ( mAuthCfg.size() == 7 )
417 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
422 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
425 void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
427 int startindex = authCfgIndex();
428 if ( startindex == -1 )
433 if ( startindex - 1 >= 0
434 && ( mDataUri.at( startindex - 1 ).isSpace()
435 || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
442 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
443 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
444 mDataUri = mDataUri.remove( 0, 1 );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
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.
QgsAuthMethod * configAuthMethod(const QString &authcfg)
Gets authentication method from the config/provider cache.
bool hasConfigId(const QString &txt) const
Returns whether a string includes an authcfg ID token.
QgsAuthMethodConfigsMap availableAuthMethodConfigs(const QString &dataprovider=QString())
Gets mapping of authentication config ids and their base configs (not decrypted data)
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.
Abstract base class for authentication method plugins.
virtual QString description() const =0
A non-translated short description representing the auth method for use in debug output and About dia...
QMap< QString, QString > QgsStringMap