eric7/Preferences/ConfigurationPages/SecurityPage.py

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

eric ide

mercurial