eric6/Preferences/ConfigurationPages/SecurityPage.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7196
ab0a91b82b37
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Security configuration page.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog
14
15 from .ConfigurationPageBase import ConfigurationPageBase
16 from .Ui_SecurityPage import Ui_SecurityPage
17
18 import Preferences
19
20
21 class SecurityPage(ConfigurationPageBase, Ui_SecurityPage):
22 """
23 Class implementing the Security configuration page.
24 """
25 def __init__(self, configDialog):
26 """
27 Constructor
28
29 @param configDialog reference to the configuration dialog
30 (ConfigurationDialog)
31 """
32 super(SecurityPage, self).__init__()
33 self.setupUi(self)
34 self.setObjectName("SecurityPage")
35
36 self.__configDlg = configDialog
37 self.__displayMode = None
38
39 # set initial values
40 self.savePasswordsCheckBox.setChecked(
41 Preferences.getUser("SavePasswords"))
42 self.masterPasswordCheckBox.setChecked(
43 Preferences.getUser("UseMasterPassword"))
44 self.masterPasswordButton.setEnabled(
45 Preferences.getUser("UseMasterPassword"))
46
47 self.__newPassword = ""
48 self.__oldUseMasterPassword = Preferences.getUser("UseMasterPassword")
49
50 def setMode(self, displayMode):
51 """
52 Public method to perform mode dependent setups.
53
54 @param displayMode mode of the configuration dialog
55 (ConfigurationWidget.DefaultMode,
56 ConfigurationWidget.HelpBrowserMode,
57 ConfigurationWidget.WebBrowserMode)
58 """
59 from ..ConfigurationDialog import ConfigurationWidget
60 assert displayMode in (
61 ConfigurationWidget.DefaultMode,
62 ConfigurationWidget.HelpBrowserMode,
63 ConfigurationWidget.WebBrowserMode
64 )
65
66 self.__displayMode = displayMode
67 if self.__displayMode == ConfigurationWidget.HelpBrowserMode:
68 try:
69 from PyQt5.QtWebKit import QWebSettings
70 if QWebSettings and \
71 hasattr(QWebSettings, "DnsPrefetchEnabled"):
72 self.dnsPrefetchCheckBox.setChecked(
73 Preferences.getHelp("DnsPrefetchEnabled"))
74 except ImportError:
75 self.dnsPrefetchCheckBox.setEnabled(False)
76 else:
77 if self.__configDlg.isUsingWebEngine():
78 self.dnsPrefetchCheckBox.setEnabled(False)
79 self.dnsGroup.hide()
80
81 def save(self):
82 """
83 Public slot to save the Help Viewers configuration.
84 """
85 Preferences.setUser(
86 "SavePasswords",
87 self.savePasswordsCheckBox.isChecked())
88 Preferences.setUser(
89 "UseMasterPassword",
90 self.masterPasswordCheckBox.isChecked())
91 if self.dnsPrefetchCheckBox.isEnabled():
92 Preferences.setHelp(
93 "DnsPrefetchEnabled",
94 self.dnsPrefetchCheckBox.isChecked())
95
96 if self.__oldUseMasterPassword != \
97 self.masterPasswordCheckBox.isChecked():
98 self.__configDlg.masterPasswordChanged.emit("", self.__newPassword)
99
100 @pyqtSlot(bool)
101 def on_masterPasswordCheckBox_clicked(self, checked):
102 """
103 Private slot to handle the use of a master password.
104
105 @param checked flag indicating the state of the check box (boolean)
106 """
107 if checked:
108 from .MasterPasswordEntryDialog import MasterPasswordEntryDialog
109 dlg = MasterPasswordEntryDialog("", self)
110 if dlg.exec_() == QDialog.Accepted:
111 Preferences.setUser(
112 "MasterPassword",
113 dlg.getMasterPassword())
114 self.masterPasswordButton.setEnabled(True)
115 self.__newPassword = dlg.getMasterPassword()
116 else:
117 self.masterPasswordCheckBox.setChecked(False)
118 else:
119 self.masterPasswordButton.setEnabled(False)
120 self.__newPassword = ""
121
122 @pyqtSlot()
123 def on_masterPasswordButton_clicked(self):
124 """
125 Private slot to change the master password.
126 """
127 from .MasterPasswordEntryDialog import MasterPasswordEntryDialog
128 dlg = MasterPasswordEntryDialog(
129 Preferences.getUser("MasterPassword"), self)
130 if dlg.exec_() == QDialog.Accepted:
131 Preferences.setUser(
132 "MasterPassword",
133 dlg.getMasterPassword())
134
135 if self.__oldUseMasterPassword != \
136 self.masterPasswordCheckBox.isChecked():
137 # the user is about to change the use of a master password
138 # just save the changed password
139 self.__newPassword = dlg.getMasterPassword()
140 else:
141 self.__configDlg.masterPasswordChanged.emit(
142 dlg.getCurrentPassword(), dlg.getMasterPassword())
143
144
145 def create(dlg):
146 """
147 Module function to create the configuration page.
148
149 @param dlg reference to the configuration dialog
150 @return reference to the instantiated page (ConfigurationPageBase)
151 """
152 page = SecurityPage(dlg)
153 return page

eric ide

mercurial