Preferences/ConfigurationPages/SecurityPage.py

Sat, 14 Dec 2013 23:44:25 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sat, 14 Dec 2013 23:44:25 +0100
branch
Py2 comp.
changeset 3145
a9de05d4a22f
parent 3060
5883ce99ee12
child 3161
06f57a834adf
permissions
-rw-r--r--

# __IGNORE_WARNING__ added/ removed.

# -*- coding: utf-8 -*-

# Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Security configuration page.
"""

from __future__ import unicode_literals

from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import QDialog
from PyQt4.QtWebKit import QWebSettings

from .ConfigurationPageBase import ConfigurationPageBase
from .Ui_SecurityPage import Ui_SecurityPage

import Preferences


class SecurityPage(ConfigurationPageBase, Ui_SecurityPage):
    """
    Class implementing the Security configuration page.
    """
    def __init__(self, configDialog):
        """
        Constructor
        
        @param configDialog reference to the configuration dialog
            (ConfigurationDialog)
        """
        super(SecurityPage, self).__init__()
        self.setupUi(self)
        self.setObjectName("SecurityPage")
        
        self.__configDlg = configDialog
        
        # set initial values
        self.savePasswordsCheckBox.setChecked(
            Preferences.getUser("SavePasswords"))
        self.masterPasswordCheckBox.setChecked(
            Preferences.getUser("UseMasterPassword"))
        self.masterPasswordButton.setEnabled(
            Preferences.getUser("UseMasterPassword"))
        if hasattr(QWebSettings, "DnsPrefetchEnabled"):
            self.dnsPrefetchCheckBox.setChecked(
                Preferences.getHelp("DnsPrefetchEnabled"))
        else:
            self.dnsPrefetchCheckBox.setEnabled(False)
        
        self.__newPassword = ""
        self.__oldUseMasterPassword = Preferences.getUser("UseMasterPassword")
    
    def save(self):
        """
        Public slot to save the Help Viewers configuration.
        """
        Preferences.setUser(
            "SavePasswords",
            self.savePasswordsCheckBox.isChecked())
        Preferences.setUser(
            "UseMasterPassword",
            self.masterPasswordCheckBox.isChecked())
        if self.dnsPrefetchCheckBox.isEnabled():
            Preferences.setHelp(
                "DnsPrefetchEnabled",
                self.dnsPrefetchCheckBox.isChecked())
        
        if self.__oldUseMasterPassword != \
                self.masterPasswordCheckBox.isChecked():
            self.__configDlg.masterPasswordChanged.emit("", self.__newPassword)
    
    @pyqtSlot(bool)
    def on_masterPasswordCheckBox_clicked(self, checked):
        """
        Private slot to handle the use of a master password.
        
        @param checked flag indicating the state of the check box (boolean)
        """
        if checked:
            from .MasterPasswordEntryDialog import MasterPasswordEntryDialog
            dlg = MasterPasswordEntryDialog("", self)
            if dlg.exec_() == QDialog.Accepted:
                Preferences.setUser(
                    "MasterPassword",
                    dlg.getMasterPassword())
                self.masterPasswordButton.setEnabled(True)
                self.__newPassword = dlg.getMasterPassword()
            else:
                self.masterPasswordCheckBox.setChecked(False)
        else:
            self.masterPasswordButton.setEnabled(False)
            self.__newPassword = ""
    
    @pyqtSlot()
    def on_masterPasswordButton_clicked(self):
        """
        Private slot to change the master password.
        """
        from .MasterPasswordEntryDialog import MasterPasswordEntryDialog
        dlg = MasterPasswordEntryDialog(
            Preferences.getUser("MasterPassword"), self)
        if dlg.exec_() == QDialog.Accepted:
            Preferences.setUser(
                "MasterPassword",
                dlg.getMasterPassword())
            
            if self.__oldUseMasterPassword != \
                    self.masterPasswordCheckBox.isChecked():
                # the user is about to change the use of a master password
                # just save the changed password
                self.__newPassword = dlg.getMasterPassword()
            else:
                self.__configDlg.masterPasswordChanged.emit(
                    dlg.getCurrentPassword(), dlg.getMasterPassword())


def create(dlg):
    """
    Module function to create the configuration page.
    
    @param dlg reference to the configuration dialog
    @return reference to the instantiated page (ConfigurationPageBase)
    """
    page = SecurityPage(dlg)
    return page

eric ide

mercurial