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( QStringLiteral(
"" ) );
60 btnConfigRemove->setText( QStringLiteral(
"" ) );
61 btnConfigEdit->setText( QStringLiteral(
"" ) );
62 btnConfigMsgClear->setText( QStringLiteral(
"" ) );
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 )
86 populateConfigSelector();
99 populateConfigSelector();
102 void QgsAuthConfigSelect::loadConfig()
105 if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
109 QString methoddesc = tr(
"Missing authentication method description" );
114 cmbConfigSelect->setToolTip( tr(
"<ul><li><b>Method type:</b> %1</li>" 115 "<li><b>Configuration ID:</b> %2</li></ul>" ).arg( methoddesc, config.
id( ) ) );
116 btnConfigEdit->setEnabled(
true );
117 btnConfigRemove->setEnabled(
true );
122 void QgsAuthConfigSelect::clearConfig()
124 cmbConfigSelect->setToolTip( QStringLiteral(
"" ) );
125 btnConfigEdit->setEnabled(
false );
126 btnConfigRemove->setEnabled(
false );
129 void QgsAuthConfigSelect::validateConfig()
131 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
133 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
138 void QgsAuthConfigSelect::populateConfigSelector()
140 loadAvailableConfigs();
143 cmbConfigSelect->blockSignals(
true );
144 cmbConfigSelect->clear();
145 cmbConfigSelect->addItem( tr(
"No authentication" ),
"0" );
148 QgsAuthMethodConfigsMap::const_iterator cit = mConfigs.constBegin();
149 for ( cit = mConfigs.constBegin(); cit != mConfigs.constEnd(); ++cit )
152 sortmap.insert( QStringLiteral(
"%1 (%2)" ).arg( config.
name(), config.
method() ), cit.key() );
155 QgsStringMap::const_iterator sm = sortmap.constBegin();
156 for ( sm = sortmap.constBegin(); sm != sortmap.constEnd(); ++sm )
158 cmbConfigSelect->addItem( sm.key(), sm.value() );
160 cmbConfigSelect->blockSignals(
false );
163 if ( !mAuthCfg.isEmpty() )
165 indx = cmbConfigSelect->findData( mAuthCfg );
167 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
176 leConfigMsg->setText( msg );
177 frConfigMsg->setVisible(
true );
186 leConfigMsg->clear();
187 frConfigMsg->setVisible(
false );
190 void QgsAuthConfigSelect::loadAvailableConfigs()
196 void QgsAuthConfigSelect::cmbConfigSelect_currentIndexChanged(
int index )
198 QString authcfg = cmbConfigSelect->itemData( index ).toString();
199 mAuthCfg = ( !authcfg.isEmpty() && authcfg != QLatin1String(
"0" ) ) ? authcfg : QString();
203 void QgsAuthConfigSelect::btnConfigAdd_clicked()
209 ace->setWindowModality( Qt::WindowModal );
217 void QgsAuthConfigSelect::btnConfigEdit_clicked()
223 ace->setWindowModality( Qt::WindowModal );
232 void QgsAuthConfigSelect::btnConfigRemove_clicked()
234 if ( QMessageBox::warning(
this, tr(
"Remove Authentication" ),
235 tr(
"Are you sure that you want to permanently remove this configuration right now?\n\n" 236 "Operation can NOT be undone!" ),
237 QMessageBox::Ok | QMessageBox::Cancel,
238 QMessageBox::Cancel ) == QMessageBox::Cancel )
250 void QgsAuthConfigSelect::btnConfigMsgClear_clicked()
258 #include <QPushButton> 266 mAuthNotifyLayout =
new QVBoxLayout;
267 this->setLayout( mAuthNotifyLayout );
269 mAuthNotifyLayout->addWidget( mAuthNotify );
275 setWindowTitle( tr(
"Authentication Config ID String Editor" ) );
277 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
278 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
279 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsAuthConfigUriEdit::saveChanges );
281 connect( buttonBox->button( QDialogButtonBox::Reset ), &QAbstractButton::clicked,
this, &QgsAuthConfigUriEdit::resetChanges );
286 wdgtAuthSelect->setDataProviderKey( dataprovider );
297 if ( datauri.isEmpty() )
300 mDataUri = mDataUriOrig = datauri;
302 teDataUri->setPlainText( mDataUri );
304 if ( authCfgIndex() == -1 )
306 wdgtAuthSelect->showMessage( tr(
"No authcfg in Data Source URI" ) );
310 selectAuthCfgInUri();
312 mAuthCfg = authCfgFromUri();
314 QgsDebugMsg( QString(
"Parsed authcfg ID: %1" ).arg( mAuthCfg ) );
316 wdgtAuthSelect->blockSignals(
true );
317 wdgtAuthSelect->setConfigId( mAuthCfg );
318 wdgtAuthSelect->blockSignals(
false );
339 void QgsAuthConfigUriEdit::saveChanges()
344 void QgsAuthConfigUriEdit::resetChanges()
346 wdgtAuthSelect->clearMessage();
350 void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
354 if ( mAuthCfg.size() != 7 )
357 removeAuthCfgFromUri();
361 updateUriWithAuthCfg();
364 teDataUri->setPlainText( mDataUri );
365 selectAuthCfgInUri();
368 void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
370 if ( authCfgFromUri() == authcfg )
372 removeAuthCfgFromUri();
376 int QgsAuthConfigUriEdit::authCfgIndex()
379 return rx.indexIn( mDataUri );
382 QString QgsAuthConfigUriEdit::authCfgFromUri()
384 int startindex = authCfgIndex();
385 if ( startindex == -1 )
388 return mDataUri.mid( startindex + 8, 7 );
391 void QgsAuthConfigUriEdit::selectAuthCfgInUri()
393 int startindex = authCfgIndex();
394 if ( startindex == -1 )
398 QTextCursor tc = teDataUri->textCursor();
399 tc.setPosition( startindex );
400 tc.setPosition( startindex + 15, QTextCursor::KeepAnchor );
401 teDataUri->setTextCursor( tc );
402 teDataUri->setFocus();
405 void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
407 int startindex = authCfgIndex();
408 if ( startindex == -1 )
410 if ( mAuthCfg.size() == 7 )
412 wdgtAuthSelect->showMessage( tr(
"Adding authcfg to URI not supported" ) );
417 mDataUri = mDataUri.replace( startindex + 8, 7, mAuthCfg );
420 void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
422 int startindex = authCfgIndex();
423 if ( startindex == -1 )
428 if ( startindex - 1 >= 0
429 && ( mDataUri.at( startindex - 1 ).isSpace()
430 || mDataUri.at( startindex - 1 ) == QChar(
'&' ) ) )
437 mDataUri = mDataUri.remove( startindex, rmvlen ).trimmed();
438 if ( mDataUri.at( 0 ) == QChar(
'&' ) )
439 mDataUri = mDataUri.remove( 0, 1 );
static bool hasConfigId(const QString &txt)
Whether a string contains an authcfg ID.
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.
void clearMessage()
Clear and hide small message bar.
QString dataSourceUri()
The returned, possibly edited data source URI.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
static QColor yellowColor()
Yellow color representing caution regarding action.
QgsAuthConfigSelect(QWidget *parent=nullptr, const QString &dataprovider=QString())
Create a dialog for setting an associated authentication config, either from existing configs...
QMap< QString, QString > QgsStringMap
void showMessage(const QString &msg)
Show a small message bar with a close button.
void setDataProviderKey(const QString &key)
Sets key of layer provider, if applicable.
virtual QString description() const =0
A non-translated short description representing the auth method for use in debug output and About dia...
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) ...
void setConfigId(const QString &authcfg)
Sets the authentication config id for the resource.
Configuration storage class for authentication method configurations.
const QString name() const
Gets name of configuration.
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
QgsAuthMethod * configAuthMethod(const QString &authcfg)
Gets authentication method from the config/provider cache.
Abstract base class for authentication method plugins.
void setDataSourceUri(const QString &datauri)
Sets the data source URI to parse.
QString method() const
Textual key of the associated authentication method.
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...
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
void selectedConfigIdRemoved(const QString &authcfg)
Emitted when authentication config is removed.