17 |
17 |
18 class SyncEncryptionPage(QWizardPage, Ui_SyncEncryptionPage): |
18 class SyncEncryptionPage(QWizardPage, Ui_SyncEncryptionPage): |
19 """ |
19 """ |
20 Class implementing encryption settings wizard page. |
20 Class implementing encryption settings wizard page. |
21 """ |
21 """ |
|
22 |
22 def __init__(self, parent=None): |
23 def __init__(self, parent=None): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param parent reference to the parent widget (QWidget) |
27 @param parent reference to the parent widget (QWidget) |
27 """ |
28 """ |
28 super().__init__(parent) |
29 super().__init__(parent) |
29 self.setupUi(self) |
30 self.setupUi(self) |
30 |
31 |
31 self.keySizeComboBox.addItem(self.tr("128 Bits"), 16) |
32 self.keySizeComboBox.addItem(self.tr("128 Bits"), 16) |
32 self.keySizeComboBox.addItem(self.tr("192 Bits"), 24) |
33 self.keySizeComboBox.addItem(self.tr("192 Bits"), 24) |
33 self.keySizeComboBox.addItem(self.tr("256 Bits"), 32) |
34 self.keySizeComboBox.addItem(self.tr("256 Bits"), 32) |
34 |
35 |
35 self.registerField("ReencryptData", self.reencryptCheckBox) |
36 self.registerField("ReencryptData", self.reencryptCheckBox) |
36 |
37 |
37 self.encryptionGroupBox.setChecked( |
38 self.encryptionGroupBox.setChecked(Preferences.getWebBrowser("SyncEncryptData")) |
38 Preferences.getWebBrowser("SyncEncryptData")) |
39 self.encryptionKeyEdit.setText(Preferences.getWebBrowser("SyncEncryptionKey")) |
39 self.encryptionKeyEdit.setText( |
|
40 Preferences.getWebBrowser("SyncEncryptionKey")) |
|
41 self.encryptionKeyAgainEdit.setEnabled(False) |
40 self.encryptionKeyAgainEdit.setEnabled(False) |
42 self.keySizeComboBox.setCurrentIndex(self.keySizeComboBox.findData( |
41 self.keySizeComboBox.setCurrentIndex( |
43 Preferences.getWebBrowser("SyncEncryptionKeyLength"))) |
42 self.keySizeComboBox.findData( |
|
43 Preferences.getWebBrowser("SyncEncryptionKeyLength") |
|
44 ) |
|
45 ) |
44 self.loginsOnlyCheckBox.setChecked( |
46 self.loginsOnlyCheckBox.setChecked( |
45 Preferences.getWebBrowser("SyncEncryptPasswordsOnly")) |
47 Preferences.getWebBrowser("SyncEncryptPasswordsOnly") |
46 |
48 ) |
|
49 |
47 def nextId(self): |
50 def nextId(self): |
48 """ |
51 """ |
49 Public method returning the ID of the next wizard page. |
52 Public method returning the ID of the next wizard page. |
50 |
53 |
51 @return next wizard page ID (integer) |
54 @return next wizard page ID (integer) |
52 """ |
55 """ |
53 Preferences.setWebBrowser( |
56 Preferences.setWebBrowser( |
54 "SyncEncryptData", self.encryptionGroupBox.isChecked()) |
57 "SyncEncryptData", self.encryptionGroupBox.isChecked() |
|
58 ) |
|
59 Preferences.setWebBrowser("SyncEncryptionKey", self.encryptionKeyEdit.text()) |
55 Preferences.setWebBrowser( |
60 Preferences.setWebBrowser( |
56 "SyncEncryptionKey", self.encryptionKeyEdit.text()) |
61 "SyncEncryptionKeyLength", |
|
62 self.keySizeComboBox.itemData(self.keySizeComboBox.currentIndex()), |
|
63 ) |
57 Preferences.setWebBrowser( |
64 Preferences.setWebBrowser( |
58 "SyncEncryptionKeyLength", self.keySizeComboBox.itemData( |
65 "SyncEncryptPasswordsOnly", self.loginsOnlyCheckBox.isChecked() |
59 self.keySizeComboBox.currentIndex())) |
66 ) |
60 Preferences.setWebBrowser( |
67 |
61 "SyncEncryptPasswordsOnly", self.loginsOnlyCheckBox.isChecked()) |
|
62 |
|
63 from . import SyncGlobals |
68 from . import SyncGlobals |
|
69 |
64 return SyncGlobals.PageType |
70 return SyncGlobals.PageType |
65 |
71 |
66 def isComplete(self): |
72 def isComplete(self): |
67 """ |
73 """ |
68 Public method to check the completeness of the page. |
74 Public method to check the completeness of the page. |
69 |
75 |
70 @return flag indicating completeness (boolean) |
76 @return flag indicating completeness (boolean) |
71 """ |
77 """ |
72 if self.encryptionGroupBox.isChecked(): |
78 if self.encryptionGroupBox.isChecked(): |
73 if self.encryptionKeyEdit.text() == "": |
79 if self.encryptionKeyEdit.text() == "": |
74 complete = False |
80 complete = False |
75 else: |
81 else: |
76 if self.reencryptCheckBox.isChecked(): |
82 if self.reencryptCheckBox.isChecked(): |
77 complete = (self.encryptionKeyEdit.text() == |
83 complete = ( |
78 self.encryptionKeyAgainEdit.text()) |
84 self.encryptionKeyEdit.text() |
|
85 == self.encryptionKeyAgainEdit.text() |
|
86 ) |
79 else: |
87 else: |
80 complete = True |
88 complete = True |
81 else: |
89 else: |
82 complete = True |
90 complete = True |
83 |
91 |
84 return complete |
92 return complete |
85 |
93 |
86 def __updateUI(self): |
94 def __updateUI(self): |
87 """ |
95 """ |
88 Private slot to update the variable parts of the UI. |
96 Private slot to update the variable parts of the UI. |
89 """ |
97 """ |
90 error = "" |
98 error = "" |
91 |
99 |
92 if self.encryptionGroupBox.isChecked(): |
100 if self.encryptionGroupBox.isChecked(): |
93 self.encryptionKeyAgainEdit.setEnabled( |
101 self.encryptionKeyAgainEdit.setEnabled(self.reencryptCheckBox.isChecked()) |
94 self.reencryptCheckBox.isChecked()) |
102 |
95 |
|
96 if self.encryptionKeyEdit.text() == "": |
103 if self.encryptionKeyEdit.text() == "": |
97 error = error or self.tr( |
104 error = error or self.tr("Encryption key must not be empty.") |
98 "Encryption key must not be empty.") |
105 |
99 |
|
100 if ( |
106 if ( |
101 self.encryptionKeyEdit.text() != "" and |
107 self.encryptionKeyEdit.text() != "" |
102 self.reencryptCheckBox.isChecked() and |
108 and self.reencryptCheckBox.isChecked() |
103 (self.encryptionKeyEdit.text() != |
109 and ( |
104 self.encryptionKeyAgainEdit.text()) |
110 self.encryptionKeyEdit.text() != self.encryptionKeyAgainEdit.text() |
|
111 ) |
105 ): |
112 ): |
106 error = error or self.tr( |
113 error = error or self.tr("Repeated encryption key is wrong.") |
107 "Repeated encryption key is wrong.") |
114 |
108 |
|
109 self.errorLabel.setText(error) |
115 self.errorLabel.setText(error) |
110 self.completeChanged.emit() |
116 self.completeChanged.emit() |
111 |
117 |
112 @pyqtSlot(str) |
118 @pyqtSlot(str) |
113 def on_encryptionKeyEdit_textChanged(self, txt): |
119 def on_encryptionKeyEdit_textChanged(self, txt): |
114 """ |
120 """ |
115 Private slot to handle changes of the encryption key. |
121 Private slot to handle changes of the encryption key. |
116 |
122 |
117 @param txt content of the edit widget (string) |
123 @param txt content of the edit widget (string) |
118 """ |
124 """ |
119 self.passwordMeter.checkPasswordStrength(txt) |
125 self.passwordMeter.checkPasswordStrength(txt) |
120 self.__updateUI() |
126 self.__updateUI() |
121 |
127 |
122 @pyqtSlot(str) |
128 @pyqtSlot(str) |
123 def on_encryptionKeyAgainEdit_textChanged(self, txt): |
129 def on_encryptionKeyAgainEdit_textChanged(self, txt): |
124 """ |
130 """ |
125 Private slot to handle changes of the encryption key repetition. |
131 Private slot to handle changes of the encryption key repetition. |
126 |
132 |
127 @param txt content of the edit widget (string) |
133 @param txt content of the edit widget (string) |
128 """ |
134 """ |
129 self.__updateUI() |
135 self.__updateUI() |
130 |
136 |
131 @pyqtSlot(bool) |
137 @pyqtSlot(bool) |
132 def on_encryptionGroupBox_toggled(self, on): |
138 def on_encryptionGroupBox_toggled(self, on): |
133 """ |
139 """ |
134 Private slot to handle changes of the encryption selection. |
140 Private slot to handle changes of the encryption selection. |
135 |
141 |
136 @param on state of the group box (boolean) |
142 @param on state of the group box (boolean) |
137 """ |
143 """ |
138 self.__updateUI() |
144 self.__updateUI() |
139 |
145 |
140 @pyqtSlot(bool) |
146 @pyqtSlot(bool) |
141 def on_reencryptCheckBox_toggled(self, on): |
147 def on_reencryptCheckBox_toggled(self, on): |
142 """ |
148 """ |
143 Private slot to handle changes of the re-encryption selection. |
149 Private slot to handle changes of the re-encryption selection. |
144 |
150 |
145 @param on state of the check box (boolean) |
151 @param on state of the check box (boolean) |
146 """ |
152 """ |
147 self.__updateUI() |
153 self.__updateUI() |