18 #include "ui_qgsauthconfigselect.h"
29 #include <QMessageBox>
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();
108 void 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 );
129 void QgsAuthConfigSelect::clearConfig()
131 cmbConfigSelect->setToolTip( QString() );
132 btnConfigEdit->setEnabled(
false );
133 btnConfigRemove->setEnabled(
false );
136 void QgsAuthConfigSelect::validateConfig()
138 if ( !mAuthCfg.isEmpty() && !mConfigs.contains( mAuthCfg ) )
140 showMessage( tr(
"Configuration '%1' not in database" ).arg( mAuthCfg ) );
145 void 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 );
197 void QgsAuthConfigSelect::loadAvailableConfigs()
203 void 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 )
211 void QgsAuthConfigSelect::btnConfigAdd_clicked()
217 ace->setWindowModality( Qt::WindowModal );
225 void QgsAuthConfigSelect::btnConfigEdit_clicked()
231 ace->setWindowModality( Qt::WindowModal );
240 void 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 )
258 void 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 QgsDebugMsg( QStringLiteral(
"Parsed authcfg ID: %1" ).arg( mAuthCfg ) );
324 wdgtAuthSelect->blockSignals(
true );
325 wdgtAuthSelect->setConfigId( mAuthCfg );
326 wdgtAuthSelect->blockSignals(
false );
347 void QgsAuthConfigUriEdit::saveChanges()
352 void QgsAuthConfigUriEdit::resetChanges()
354 wdgtAuthSelect->clearMessage();
358 void QgsAuthConfigUriEdit::authCfgUpdated(
const QString &authcfg )
362 if ( mAuthCfg.size() != 7 )
365 removeAuthCfgFromUri();
369 updateUriWithAuthCfg();
372 teDataUri->setPlainText( mDataUri );
373 selectAuthCfgInUri();
376 void QgsAuthConfigUriEdit::authCfgRemoved(
const QString &authcfg )
378 if ( authCfgFromUri() == authcfg )
380 removeAuthCfgFromUri();
384 int QgsAuthConfigUriEdit::authCfgIndex()
389 QString QgsAuthConfigUriEdit::authCfgFromUri()
391 const int startindex = authCfgIndex();
392 if ( startindex == -1 )
395 return mDataUri.mid( startindex + 8, 7 );
398 void 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();
412 void 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 );
427 void 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 );