QGIS API Documentation  2.12.0-Lyon
qgsauthmasterpassresetdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsauthmasterpassresetdialog.cpp
3  ---------------------
4  begin : September 10, 2015
5  copyright : (C) 2015 by Boundless Spatial, Inc. USA
6  author : Larry Shaffer
7  email : lshaffer at boundlessgeo dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
18 
19 #include <QLineEdit>
20 #include <QPushButton>
21 
22 #include "qgsauthguiutils.h"
23 #include "qgsauthmanager.h"
24 #include "qgslogger.h"
25 
26 
28  : QDialog( parent )
29  , mPassCurOk( false )
30  , mPassNewOk( false )
31  , mAuthNotifyLayout( 0 )
32  , mAuthNotify( 0 )
33 {
34  if ( QgsAuthManager::instance()->isDisabled() )
35  {
36  mAuthNotifyLayout = new QVBoxLayout;
37  this->setLayout( mAuthNotifyLayout );
38  mAuthNotify = new QLabel( QgsAuthManager::instance()->disabledMessage(), this );
39  mAuthNotifyLayout->addWidget( mAuthNotify );
40  }
41  else
42  {
43  setupUi( this );
44  }
45 }
46 
48 {
49 }
50 
51 bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup )
52 {
53  if ( !QgsAuthManager::instance()->isDisabled() )
54  {
55  validatePasswords();
56  leMasterPassCurrent->setFocus();
57 
58  bool ok = ( exec() == QDialog::Accepted );
59  //QgsDebugMsg( QString( "exec(): %1" ).arg( ok ? "true" : "false" ) );
60 
61  if ( ok )
62  {
63  *newpass = leMasterPassNew->text();
64  *oldpass = leMasterPassCurrent->text();
65  *keepbackup = chkKeepBackup->isChecked();
66  return true;
67  }
68  }
69  return false;
70 }
71 
72 void QgsMasterPasswordResetDialog::on_leMasterPassCurrent_textChanged( const QString& pass )
73 {
74  // since this is called on every keystroke, block signals emitted during verification of password
76  mPassCurOk = !pass.isEmpty();
78  validatePasswords();
79 }
80 
81 void QgsMasterPasswordResetDialog::on_leMasterPassNew_textChanged( const QString& pass )
82 {
83  mPassNewOk = !pass.isEmpty();
84  validatePasswords();
85 }
86 
87 void QgsMasterPasswordResetDialog::on_chkPassShowCurrent_stateChanged( int state )
88 {
89  leMasterPassCurrent->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
90 }
91 
92 void QgsMasterPasswordResetDialog::on_chkPassShowNew_stateChanged( int state )
93 {
94  leMasterPassNew->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
95 }
96 
97 void QgsMasterPasswordResetDialog::validatePasswords()
98 {
99  QString ss1 = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( "QLineEdit" )
100  : QgsAuthGuiUtils::redTextStyleSheet( "QLineEdit" );
101  leMasterPassCurrent->setStyleSheet( ss1 );
102  QString ss2 = mPassNewOk ? QgsAuthGuiUtils::greenTextStyleSheet( "QLineEdit" )
103  : QgsAuthGuiUtils::redTextStyleSheet( "QLineEdit" );
104  leMasterPassNew->setStyleSheet( ss2 );
105  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mPassCurOk && mPassNewOk );
106 }
107 
void setupUi(QWidget *widget)
static QgsAuthManager * instance()
Enforce singleton pattern.
int exec()
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
void setLayout(QLayout *layout)
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc.
bool isEmpty() const
bool requestMasterPasswordReset(QString *newpass, QString *oldpass, bool *keepbackup)
Utility functions for use by authentication GUI widgets or standalone apps.
bool blockSignals(bool block)