Plugins/VcsPlugins/vcsMercurial/HgUserConfigHostFingerprintDialog.py

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

eric ide

mercurial