23 #include <QPushButton>
29 return QString(
"%1{color: rgb(200, 0, 0);}" ).
arg( selector );
40 Qt::BlockingQueuedConnection );
42 this, SLOT( requestCredentialsMasterPassword(
QString *,
bool,
bool * ) ),
43 Qt::BlockingQueuedConnection );
44 mOkButton = buttonBox->button( QDialogButtonBox::Ok );
45 leMasterPass->setPlaceholderText(
tr(
"Required" ) );
59 QgsDebugMsg(
QString(
"signal returned %1 (username=%2, password=%3)" ).arg( ok ?
"true" :
"false", username, password ) );
63 requestCredentials( realm, &username, &password, message, &ok );
68 void QgsCredentialDialog::requestCredentials(
const QString& realm,
QString *username,
QString *password,
const QString& message,
bool *ok )
71 stackedWidget->setCurrentIndex( 0 );
73 labelRealm->setText( realm );
74 leUsername->setText( *username );
75 lePassword->setText( *password );
76 labelMessage->setText( message );
77 labelMessage->setHidden( message.
isEmpty() );
79 if ( !leUsername->text().isEmpty() )
80 lePassword->setFocus();
82 QWidget *activeWindow = qApp->activeWindow();
87 *ok =
exec() == QDialog::Accepted;
93 activeWindow->
raise();
97 *username = leUsername->text();
98 *password = lePassword->text();
112 requestCredentialsMasterPassword( &password, stored, &ok );
117 void QgsCredentialDialog::requestCredentialsMasterPassword(
QString * password,
bool stored ,
bool *ok )
120 stackedWidget->setCurrentIndex( 1 );
122 QString titletxt( stored ?
tr(
"Enter CURRENT master authentication password" ) :
tr(
"Set NEW master authentication password" ) );
123 lblPasswordTitle->setText( titletxt );
125 leMasterPassVerify->setVisible( !stored );
126 lblDontForget->setVisible( !stored );
130 grpbxPassAttempts->setVisible(
false );
136 if ( passfailed >= 3 )
138 lblSavedForSession->setVisible(
false );
139 grpbxPassAttempts->setTitle(
tr(
"Password attempts: %1" ).arg( passfailed ) );
140 grpbxPassAttempts->setVisible(
true );
149 *ok =
exec() == QDialog::Accepted;
154 bool passok = !leMasterPass->text().isEmpty();
155 if ( passok && stored && !chkbxEraseAuthDb->isChecked() )
160 if ( passok && !stored )
162 passok = ( leMasterPass->text() == leMasterPassVerify->text() );
165 if ( passok || chkbxEraseAuthDb->isChecked() )
167 if ( stored && chkbxEraseAuthDb->isChecked() )
173 *password = leMasterPass->text();
183 if ( leMasterPassVerify->isVisible() )
194 if ( passfailed >= 5 )
201 leMasterPass->
clear();
202 chkMasterPassShow->setChecked(
false );
203 leMasterPassVerify->clear();
205 chkbxEraseAuthDb->setChecked(
false );
206 lblSavedForSession->setVisible(
true );
214 if ( passfailed >= 5 )
220 void QgsCredentialDialog::on_chkMasterPassShow_stateChanged(
int state )
222 leMasterPass->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
223 leMasterPassVerify->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
226 void QgsCredentialDialog::on_leMasterPass_textChanged(
const QString &pass )
228 leMasterPass->setStyleSheet(
"" );
230 if ( leMasterPassVerify->isVisible() )
232 leMasterPassVerify->setStyleSheet(
"" );
233 passok = passok && ( leMasterPass->text() == leMasterPassVerify->text() );
237 if ( leMasterPassVerify->isVisible() && !passok )
244 void QgsCredentialDialog::on_leMasterPassVerify_textChanged(
const QString &pass )
246 if ( leMasterPassVerify->isVisible() )
248 leMasterPass->setStyleSheet(
"" );
249 leMasterPassVerify->setStyleSheet(
"" );
252 bool passok = !pass.
isEmpty() && ( leMasterPass->text() == leMasterPassVerify->text() );
262 void QgsCredentialDialog::on_chkbxEraseAuthDb_toggled(
bool checked )
static QgsAuthManager * instance()
Enforce singleton pattern.
QgsCredentialDialog(QWidget *parent=0, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
QString tr(const char *sourceText, const char *disambiguation, int n)
static QString invalidStyle_(const QString &selector="QLineEdit")
void setOverrideCursor(const QCursor &cursor)
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString::null) override
request a password
void restoreOverrideCursor()
virtual QSize sizeHint() const
void setScheduledAuthDbErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
QThread * currentThread()
bool verifyMasterPassword(const QString &compare=QString::null)
Verify the supplied master password against any existing hash in authentication database.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
void credentialsRequestedMasterPassword(QString *, bool, bool *)
void credentialsRequested(QString, QString *, QString *, QString, bool *)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setInstance(QgsCredentials *theInstance)
register instance