def __init__(self, parent=None):
     '''
     Constructor
     '''
     QtGui.QDialog.__init__(self, parent)
     self._ui = Ui_LoginDialog()
     self._ui.setupUi(self)
     
     self._errorTimer = QtCore.QTimer(self)
     self._errorTimer.setInterval(5000)
     self._errorTimer.setSingleShot(True)
     
     self._makeConnections()
class LoginDialog(QtGui.QDialog):
    '''
    Dialog for identifying user.
    '''


    def __init__(self, parent=None):
        '''
        Constructor
        '''
        QtGui.QDialog.__init__(self, parent)
        self._ui = Ui_LoginDialog()
        self._ui.setupUi(self)
        
        self._errorTimer = QtCore.QTimer(self)
        self._errorTimer.setInterval(5000)
        self._errorTimer.setSingleShot(True)
        
        self._makeConnections()
        
        
    def _updateUi(self):
        pass
    
    def _makeConnections(self):
        self._ui.buttonBox.button(QtGui.QDialogButtonBox.Ok).clicked.connect(self._validateLogin)
        self._ui.registerForgotLabel.linkActivated.connect(self._registerOrForgot)
        self._errorTimer.timeout.connect(self._hideErrorMessage)

    def _validateLogin(self):
        username = self._ui.usernameLineEdit.text()
        password = sha224(self._ui.passwordLineEdit.text().encode('utf8')).hexdigest()
        stored_password = '******'
        
        settings = QtCore.QSettings()
        settings.beginGroup('RegisteredUsers')
        user_exists = username in settings.childGroups()
        if user_exists:
            settings.beginGroup(username)
            stored_password = settings.value('password', '')
            settings.endGroup()
        settings.endGroup()
        
        if user_exists and stored_password == password:
            self.accept()
        else:
            self._loginError()
    
    
    def _registerOrForgot(self, link):
        if link == 'mapclient.register':
            registerUser(self)
            
    def _loginError(self):
        self._ui.errorOutputLabel.setText('Error: login details incorrect')
        self._ui.errorOutputLabel.setStyleSheet(invalid_style_sheet)
        self._errorTimer.start()
        
    def _hideErrorMessage(self):
        self._ui.errorOutputLabel.setText('')
        self._ui.errorOutputLabel.setStyleSheet('')
        
    def username(self):
        return self._ui.usernameLineEdit.text()