src/eric7/Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostFingerprintDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot 10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox 11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
12 12
13 from .Ui_HgUserConfigHostFingerprintDialog import ( 13 from .Ui_HgUserConfigHostFingerprintDialog import Ui_HgUserConfigHostFingerprintDialog
14 Ui_HgUserConfigHostFingerprintDialog
15 )
16 14
17 15
18 class HgUserConfigHostFingerprintDialog( 16 class HgUserConfigHostFingerprintDialog(QDialog, Ui_HgUserConfigHostFingerprintDialog):
19 QDialog, Ui_HgUserConfigHostFingerprintDialog):
20 """ 17 """
21 Class implementing a dialog to edit a host fingerprint. 18 Class implementing a dialog to edit a host fingerprint.
22 """ 19 """
20
23 supportedHashes = ("sha1", "sha256", "sha512") 21 supportedHashes = ("sha1", "sha256", "sha512")
24 fingerprintLength = { 22 fingerprintLength = {
25 "sha1": 40, 23 "sha1": 40,
26 "sha256": 64, 24 "sha256": 64,
27 "sha512": 128, 25 "sha512": 128,
28 } 26 }
29 27
30 def __init__(self, parent=None, host="", fingerprint="", 28 def __init__(self, parent=None, host="", fingerprint="", version=(0, 0, 0)):
31 version=(0, 0, 0)):
32 """ 29 """
33 Constructor 30 Constructor
34 31
35 @param parent reference to the parent widget 32 @param parent reference to the parent widget
36 @type QWidget 33 @type QWidget
37 @param host host name 34 @param host host name
38 @type str 35 @type str
39 @param fingerprint fingerprint for the host 36 @param fingerprint fingerprint for the host
41 @param version Mercurial version info 38 @param version Mercurial version info
42 @type tuple of three integers 39 @type tuple of three integers
43 """ 40 """
44 super().__init__(parent) 41 super().__init__(parent)
45 self.setupUi(self) 42 self.setupUi(self)
46 43
47 self.__version = version 44 self.__version = version
48 45
49 self.hashComboBox.addItem("") 46 self.hashComboBox.addItem("")
50 self.hashComboBox.addItems( 47 self.hashComboBox.addItems(HgUserConfigHostFingerprintDialog.supportedHashes)
51 HgUserConfigHostFingerprintDialog.supportedHashes)
52 if self.__version < (3, 9, 0): 48 if self.__version < (3, 9, 0):
53 self.hashLabel.setEnabled(False) 49 self.hashLabel.setEnabled(False)
54 self.hashComboBox.setEnabled(False) 50 self.hashComboBox.setEnabled(False)
55 hashType = "sha1" 51 hashType = "sha1"
56 else: 52 else:
57 if fingerprint and fingerprint.startswith("sha"): 53 if fingerprint and fingerprint.startswith("sha"):
58 hashType, fingerprint = fingerprint.split(":", 1) 54 hashType, fingerprint = fingerprint.split(":", 1)
59 else: 55 else:
60 hashType = "" 56 hashType = ""
61 57
62 index = self.hashComboBox.findText(hashType) 58 index = self.hashComboBox.findText(hashType)
63 self.hashComboBox.setCurrentIndex(index) 59 self.hashComboBox.setCurrentIndex(index)
64 self.hostEdit.setText(host) 60 self.hostEdit.setText(host)
65 self.fingerprintEdit.setText(fingerprint) 61 self.fingerprintEdit.setText(fingerprint)
66 62
67 msh = self.minimumSizeHint() 63 msh = self.minimumSizeHint()
68 self.resize(max(self.width(), msh.width()), msh.height()) 64 self.resize(max(self.width(), msh.width()), msh.height())
69 65
70 self.__updateOkButton() 66 self.__updateOkButton()
71 67
72 def __updateOkButton(self): 68 def __updateOkButton(self):
73 """ 69 """
74 Private method to update the status of the Ok button. 70 Private method to update the status of the Ok button.
75 """ 71 """
76 enabled = ( 72 enabled = bool(self.hostEdit.text()) and bool(self.fingerprintEdit.text())
77 bool(self.hostEdit.text()) and
78 bool(self.fingerprintEdit.text())
79 )
80 if self.__version >= (3, 9, 0): 73 if self.__version >= (3, 9, 0):
81 hashType = self.hashComboBox.currentText() 74 hashType = self.hashComboBox.currentText()
82 enabled &= bool(hashType) 75 enabled &= bool(hashType)
83 if hashType: 76 if hashType:
84 enabled &= ( 77 enabled &= (
85 len(self.fingerprintEdit.text().replace(":", "")) == 78 len(self.fingerprintEdit.text().replace(":", ""))
86 HgUserConfigHostFingerprintDialog.fingerprintLength[ 79 == HgUserConfigHostFingerprintDialog.fingerprintLength[hashType]
87 hashType]) 80 )
88 81
89 self.buttonBox.button( 82 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
90 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) 83
91
92 @pyqtSlot(str) 84 @pyqtSlot(str)
93 def on_hostEdit_textChanged(self, txt): 85 def on_hostEdit_textChanged(self, txt):
94 """ 86 """
95 Private slot to handle changes of the host edit. 87 Private slot to handle changes of the host edit.
96 88
97 @param txt current text 89 @param txt current text
98 @type str 90 @type str
99 """ 91 """
100 self.__updateOkButton() 92 self.__updateOkButton()
101 93
102 @pyqtSlot(int) 94 @pyqtSlot(int)
103 def on_hashComboBox_currentIndexChanged(self, index): 95 def on_hashComboBox_currentIndexChanged(self, index):
104 """ 96 """
105 Private slot to handle changes of the hash combo. 97 Private slot to handle changes of the hash combo.
106 98
107 @param index current index 99 @param index current index
108 @type int 100 @type int
109 """ 101 """
110 self.__updateOkButton() 102 self.__updateOkButton()
111 103
112 @pyqtSlot(str) 104 @pyqtSlot(str)
113 def on_fingerprintEdit_textChanged(self, txt): 105 def on_fingerprintEdit_textChanged(self, txt):
114 """ 106 """
115 Private slot to handle changes of the fingerprint edit. 107 Private slot to handle changes of the fingerprint edit.
116 108
117 @param txt current text 109 @param txt current text
118 @type str 110 @type str
119 """ 111 """
120 if txt != txt.strip(): 112 if txt != txt.strip():
121 # get rid of whitespace 113 # get rid of whitespace
122 txt = txt.strip() 114 txt = txt.strip()
123 self.fingerprintEdit.setText(txt) 115 self.fingerprintEdit.setText(txt)
124 116
125 if txt.startswith(tuple( 117 if txt.startswith(
126 h + ":" for h in 118 tuple(h + ":" for h in HgUserConfigHostFingerprintDialog.supportedHashes)
127 HgUserConfigHostFingerprintDialog.supportedHashes)): 119 ):
128 parts = txt.split(":", 1) 120 parts = txt.split(":", 1)
129 if len(parts) == 2: 121 if len(parts) == 2:
130 self.fingerprintEdit.setText(parts[1]) 122 self.fingerprintEdit.setText(parts[1])
131 hashIndex = self.hashComboBox.findText(parts[0].strip()) 123 hashIndex = self.hashComboBox.findText(parts[0].strip())
132 if hashIndex > -1: 124 if hashIndex > -1:
133 self.hashComboBox.setCurrentIndex(hashIndex) 125 self.hashComboBox.setCurrentIndex(hashIndex)
134 126
135 self.__updateOkButton() 127 self.__updateOkButton()
136 128
137 def getData(self): 129 def getData(self):
138 """ 130 """
139 Public method to retrieve the data. 131 Public method to retrieve the data.
140 132
141 @return tuple containig the host name and the fingerprint 133 @return tuple containig the host name and the fingerprint
142 @rtype tuple of two str 134 @rtype tuple of two str
143 """ 135 """
144 fingerprint = ( 136 fingerprint = (
145 self.fingerprintEdit.text() 137 self.fingerprintEdit.text()
146 if self.__version < (3, 9, 0) else 138 if self.__version < (3, 9, 0)
147 "{0}:{1}".format(self.hashComboBox.currentText(), 139 else "{0}:{1}".format(
148 self.fingerprintEdit.text().strip()) 140 self.hashComboBox.currentText(), self.fingerprintEdit.text().strip()
141 )
149 ) 142 )
150 143
151 return self.hostEdit.text().strip(), fingerprint 144 return self.hostEdit.text().strip(), fingerprint

eric ide

mercurial