18 #include "ui_qgsauthconfigselect.h" 21 #include <QMessageBox> 34 , mDataProvider( dataprovider )
37 , mAuthNotifyLayout( nullptr )
38 , mAuthNotify( nullptr )
46 mAuthNotifyLayout->
addWidget( mAuthNotify );
52 leConfigMsg->setStyleSheet(
QString(
"QLineEdit{background-color: %1}" )
57 populateConfigSelector();
67 if ( mDisabled && mAuthNotify )
70 tr(
"Authentication config id not loaded: %1" ).arg( authcfg ) );
74 if ( mAuthCfg != authcfg )
78 populateConfigSelector();
91 populateConfigSelector();
94 void QgsAuthConfigSelect::loadConfig()
101 QString methoddesc =
tr(
"Missing authentication method description" );
106 leConfigMethodDesc->setText( methoddesc );
107 leConfigMethodDesc->setCursorPosition( 0 );
108 leConfigId->setText( config.
id() );
109 btnConfigEdit->setEnabled(
true );
110 btnConfigRemove->setEnabled(
true );
115 void QgsAuthConfigSelect::clearConfig()
117 leConfigMethodDesc->clear();
119 btnConfigEdit->setEnabled(
false );
120 btnConfigRemove->setEnabled(
false );
123 void QgsAuthConfigSelect::validateConfig()
127 showMessage(
tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
132 void QgsAuthConfigSelect::populateConfigSelector()
134 loadAvailableConfigs();
137 cmbConfigSelect->blockSignals(
true );
138 cmbConfigSelect->clear();
139 cmbConfigSelect->addItem(
tr(
"No authentication" ),
"0" );
152 cmbConfigSelect->addItem( sm.
key(), sm.
value() );
154 cmbConfigSelect->blockSignals(
false );
159 indx = cmbConfigSelect->findData( mAuthCfg );
161 cmbConfigSelect->setCurrentIndex( indx > 0 ? indx : 0 );
170 leConfigMsg->setText( msg );
171 frConfigMsg->setVisible(
true );
180 leConfigMsg->clear();
181 frConfigMsg->setVisible(
false );
184 void QgsAuthConfigSelect::loadAvailableConfigs()
190 void QgsAuthConfigSelect::on_cmbConfigSelect_currentIndexChanged(
int index )
192 QString authcfg = cmbConfigSelect->itemData( index ).toString();
197 void QgsAuthConfigSelect::on_btnConfigAdd_clicked()
211 void QgsAuthConfigSelect::on_btnConfigEdit_clicked()
226 void QgsAuthConfigSelect::on_btnConfigRemove_clicked()
229 tr(
"Are you sure that you want to permanently remove this configuration right now?\n\n" 230 "Operation can NOT be undone!" ),
231 QMessageBox::Ok | QMessageBox::Cancel,
232 QMessageBox::Cancel ) == QMessageBox::Cancel )
244 void QgsAuthConfigSelect::on_btnConfigMsgClear_clicked()
252 #include <QPushButton> 260 , mAuthNotifyLayout( nullptr )
261 , mAuthNotify( nullptr )
269 mAuthNotifyLayout->
addWidget( mAuthNotify );
277 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
279 connect( buttonBox, SIGNAL(
accepted() ),
this, SLOT( saveChanges() ) );
281 connect( buttonBox->button( QDialogButtonBox::Reset ), SIGNAL( clicked() ),
this, SLOT( resetChanges() ) );
283 connect( wdgtAuthSelect, SIGNAL( selectedConfigIdChanged(
QString ) ),
this , SLOT( authCfgUpdated(
QString ) ) );
284 connect( wdgtAuthSelect, SIGNAL( selectedConfigIdRemoved(
QString ) ),
this , SLOT( authCfgRemoved(
QString ) ) );
286 wdgtAuthSelect->setDataProviderKey( dataprovider );
304 mDataUri = mDataUriOrig = datauri;
306 teDataUri->setPlainText( mDataUri );
308 if ( authCfgIndex() == -1 )
310 wdgtAuthSelect->showMessage(
tr(
"No authcfg in Data Source URI" ) );
314 selectAuthCfgInUri();
316 mAuthCfg = authCfgFromUri();
320 wdgtAuthSelect->blockSignals(
true );
321 wdgtAuthSelect->setConfigId( mAuthCfg );
322 wdgtAuthSelect->blockSignals(
false );
343 void QgsAuthConfigUriEdit::saveChanges()
348 void QgsAuthConfigUriEdit::resetChanges()
350 wdgtAuthSelect->clearMessage();
354 void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
358 if ( mAuthCfg.
size() != 7 )
361 removeAuthCfgFromUri();
365 updateUriWithAuthCfg();
368 teDataUri->setPlainText( mDataUri );
369 selectAuthCfgInUri();
372 void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
374 if ( authCfgFromUri() == authcfg )
376 removeAuthCfgFromUri();
380 int QgsAuthConfigUriEdit::authCfgIndex()
386 QString QgsAuthConfigUriEdit::authCfgFromUri()
388 int startindex = authCfgIndex();
389 if ( startindex == -1 )
392 return mDataUri.
mid( startindex + 8, 7 );
395 void QgsAuthConfigUriEdit::selectAuthCfgInUri()
397 int startindex = authCfgIndex();
398 if ( startindex == -1 )
404 tc.
setPosition( startindex + 15, QTextCursor::KeepAnchor );
405 teDataUri->setTextCursor( tc );
406 teDataUri->setFocus();
409 void QgsAuthConfigUriEdit::updateUriWithAuthCfg()
411 int startindex = authCfgIndex();
412 if ( startindex == -1 )
414 if ( mAuthCfg.
size() == 7 )
416 wdgtAuthSelect->showMessage(
tr(
"Adding authcfg to URI not supported" ) );
421 mDataUri = mDataUri.
replace( startindex + 8, 7, mAuthCfg );
424 void QgsAuthConfigUriEdit::removeAuthCfgFromUri()
426 int startindex = authCfgIndex();
427 if ( startindex == -1 )
432 if ( startindex - 1 >= 0
433 && ( mDataUri.
at( startindex - 1 ).
isSpace()
434 || mDataUri.
at( startindex - 1 ) ==
QChar(
'&' ) ) )
442 if ( mDataUri.
at( 0 ) ==
QChar(
'&' ) )
443 mDataUri = mDataUri.
remove( 0, 1 );
static QgsAuthManager * instance()
Enforce singleton pattern.
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.
const_iterator constBegin() const
void clearMessage()
Clear and hide small message bar.
QString dataSourceUri()
The returned, possibly edited data source URI.
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...
QString & remove(int position, int n)
QString tr(const char *sourceText, const char *disambiguation, int n)
void showMessage(const QString &msg)
Show a small message bar with a close button.
void setDataProviderKey(const QString &key)
Set key of layer provider, if applicable.
int indexIn(const QString &str, int offset, CaretMode caretMode) const
const char * name() const
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
Return whether a string includes an authcfg ID token.
const_iterator constEnd() const
QgsAuthMethodConfigsMap availableAuthMethodConfigs(const QString &dataprovider=QString())
Get mapping of authentication config ids and their base configs (not decrypted data) ...
void setConfigId(const QString &authcfg)
Set the authentication config id for the resource.
static bool hasConfigID(const QString &txt)
Whether a string contains an authcfg ID.
Configuration storage class for authentication method configurations.
const_iterator constEnd() const
const QString name() const
Get name of configuration.
void setText(const QString &)
const T value(const Key &key) const
void selectedConfigIdChanged(const QString &authcfg)
Emitted when authentication config is changed or missing.
QString & replace(int position, int n, QChar after)
const_iterator constBegin() const
QgsAuthMethod * configAuthMethod(const QString &authcfg)
Get authentication method from the config/provider cache.
Abstract base class for authentication method plugins.
QString mid(int position, int n) const
void setDataSourceUri(const QString &datauri)
Set the data source URI to parse.
const QChar at(int position) const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
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...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
const QString id() const
Get 'authcfg' 7-character alphanumeric ID of the config.
void setPosition(int pos, MoveMode m)
void selectedConfigIdRemoved(const QString &authcfg)
Emitted when authentication config is removed.