11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, QUuid |
12 from PyQt5.QtCore import pyqtSlot, QUuid |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from E5Gui import E5MessageBox |
|
16 from E5Gui.E5PathPicker import E5PathPickerModes |
16 |
17 |
17 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
18 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
18 |
19 |
19 from Utilities.crypto import pwConvert |
20 from Utilities.crypto import pwConvert |
20 |
21 |
30 @param client reference to the MQTT client object |
31 @param client reference to the MQTT client object |
31 @type MqttClient |
32 @type MqttClient |
32 @param options dictionary containing the connection options to |
33 @param options dictionary containing the connection options to |
33 populate the dialog with. It must have the keys "ClientId", |
34 populate the dialog with. It must have the keys "ClientId", |
34 "Keepalive", "CleanSession", "Username", "Password", "WillTopic", |
35 "Keepalive", "CleanSession", "Username", "Password", "WillTopic", |
35 "WillMessage", "WillQos", "WillRetain". |
36 "WillMessage", "WillQos", "WillRetain", "TlsEnable", "TlsCaCert". |
36 @type dict |
37 @type dict |
37 @param parent reference to the parent widget |
38 @param parent reference to the parent widget |
38 @type QWidget |
39 @type QWidget |
39 """ |
40 """ |
40 super(MqttConnectionOptionsDialog, self).__init__(parent) |
41 super(MqttConnectionOptionsDialog, self).__init__(parent) |
41 self.setupUi(self) |
42 self.setupUi(self) |
42 |
43 |
43 self.__client = client |
44 self.__client = client |
|
45 |
|
46 self.tlsCertsFilePicker.setMode(E5PathPickerModes.OpenFileMode) |
|
47 self.tlsCertsFilePicker.setFilters( |
|
48 self.tr("Certificate Files (*.crt *.pem);;All Files (*)")) |
44 |
49 |
45 self.__populateDefaults(options=options) |
50 self.__populateDefaults(options=options) |
46 |
51 |
47 self.__updateOkButton() |
52 self.__updateOkButton() |
48 |
53 |
89 default values. |
94 default values. |
90 |
95 |
91 @param options dictionary containing the connection options to populate |
96 @param options dictionary containing the connection options to populate |
92 the dialog with. It must have the keys "ClientId", "Keepalive", |
97 the dialog with. It must have the keys "ClientId", "Keepalive", |
93 "CleanSession", "Username", "Password", "WillTopic", "WillMessage", |
98 "CleanSession", "Username", "Password", "WillTopic", "WillMessage", |
94 "WillQos", "WillRetain". |
99 "WillQos", "WillRetain", "TlsEnable", "TlsCaCert". |
95 @type dict |
100 @type dict |
96 """ |
101 """ |
97 if options is None: |
102 if options is None: |
98 options = self.__client.defaultConnectionOptions() |
103 options = self.__client.defaultConnectionOptions() |
99 |
104 |
109 # last will and testament |
114 # last will and testament |
110 self.willQosSpinBox.setValue(options["WillQos"]) |
115 self.willQosSpinBox.setValue(options["WillQos"]) |
111 self.willRetainCheckBox.setChecked(options["WillRetain"]) |
116 self.willRetainCheckBox.setChecked(options["WillRetain"]) |
112 self.willTopicEdit.setText(options["WillTopic"]) |
117 self.willTopicEdit.setText(options["WillTopic"]) |
113 self.willMessageEdit.setPlainText(options["WillMessage"]) |
118 self.willMessageEdit.setPlainText(options["WillMessage"]) |
|
119 |
|
120 # TLS parameters |
|
121 self.tlsEnableCheckBox.setChecked(options["TlsEnable"]) |
|
122 self.tlsCertsFilePicker.setText(options["TlsCaCert"]) |
114 |
123 |
115 def getConnectionOptions(self): |
124 def getConnectionOptions(self): |
116 """ |
125 """ |
117 Public method get the entered connection options. |
126 Public method get the entered connection options. |
118 |
127 |
119 @return dictionary containing the connection options. It has the keys |
128 @return dictionary containing the connection options. It has the keys |
120 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
129 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
121 "WillTopic", "WillMessage", "WillQos", "WillRetain". |
130 "WillTopic", "WillMessage", "WillQos", "WillRetain", "TlsEnable", |
|
131 "TlsCaCert". |
122 @rtype tuple of (int, dict) |
132 @rtype tuple of (int, dict) |
123 """ |
133 """ |
124 return { |
134 return { |
125 "ClientId": self.clientIdEdit.text(), |
135 "ClientId": self.clientIdEdit.text(), |
126 "Keepalive": self.keepaliveSpinBox.value(), |
136 "Keepalive": self.keepaliveSpinBox.value(), |
129 "Password": pwConvert(self.passwordEdit.text(), encode=True), |
139 "Password": pwConvert(self.passwordEdit.text(), encode=True), |
130 "WillTopic": self.willTopicEdit.text(), |
140 "WillTopic": self.willTopicEdit.text(), |
131 "WillMessage": self.willMessageEdit.toPlainText(), |
141 "WillMessage": self.willMessageEdit.toPlainText(), |
132 "WillQos": self.willQosSpinBox.value(), |
142 "WillQos": self.willQosSpinBox.value(), |
133 "WillRetain": self.willRetainCheckBox.isChecked(), |
143 "WillRetain": self.willRetainCheckBox.isChecked(), |
|
144 "TlsEnable": self.tlsEnableCheckBox.isChecked(), |
|
145 "TlsCaCert": self.tlsCertsFilePicker.text() |
134 } |
146 } |
135 |
147 |
136 @pyqtSlot(str) |
148 @pyqtSlot(str) |
137 def on_clientIdEdit_textChanged(self, clientId): |
149 def on_clientIdEdit_textChanged(self, clientId): |
138 """ |
150 """ |