29 |
29 |
30 class MqttConnectionProfilesDialog(QDialog, Ui_MqttConnectionProfilesDialog): |
30 class MqttConnectionProfilesDialog(QDialog, Ui_MqttConnectionProfilesDialog): |
31 """ |
31 """ |
32 Class implementing a dialog to edit the MQTT connection profiles. |
32 Class implementing a dialog to edit the MQTT connection profiles. |
33 """ |
33 """ |
34 def __init__(self, profiles, parent=None): |
34 def __init__(self, profiles, currentProfile="", parent=None): |
35 """ |
35 """ |
36 Constructor |
36 Constructor |
37 |
37 |
38 @param profiles dictionary containing dictionaries containing the |
38 @param profiles dictionary containing dictionaries containing the |
39 connection parameters. Each entry must have the keys |
39 connection parameters. Each entry must have the keys |
40 "BrokerAddress", "BrokerPort", "ClientId", "Protocol", |
40 "BrokerAddress", "BrokerPort", "ClientId", "Protocol", |
41 "ConnectionTimeout", "Keepalive", "CleanSession", "Username", |
41 "ConnectionTimeout", "Keepalive", "CleanSession", "Username", |
42 "Password", "WillTopic", "WillMessage", "WillQos", "WillRetain", |
42 "Password", "WillTopic", "WillMessage", "WillQos", "WillRetain", |
43 "TlsEnable", "TlsCaCert", "TlsClientCert", "TlsClientKey", |
43 "WillProperties", "TlsEnable", "TlsCaCert", "TlsClientCert", |
44 "UserProperties". |
44 "TlsClientKey", "UserProperties". |
45 @type dict |
45 @type dict |
|
46 @param currentProfile name of the currently selected profile |
|
47 @type str |
46 @param parent reference to the parent widget |
48 @param parent reference to the parent widget |
47 @type QWidget |
49 @type QWidget |
48 """ |
50 """ |
49 super().__init__(parent) |
51 super().__init__(parent) |
50 self.setupUi(self) |
52 self.setupUi(self) |
51 |
53 |
52 self.__profiles = collections.defaultdict(self.__defaultProfile) |
54 self.__profiles = collections.defaultdict(self.__defaultProfile) |
53 self.__profiles.update(profiles) |
55 self.__profiles.update(copy.deepcopy(profiles)) |
54 self.__profilesChanged = False |
56 self.__profilesChanged = False |
55 |
57 |
56 self.plusButton.setIcon(UI.PixmapCache.getIcon("plus")) |
58 self.plusButton.setIcon(UI.PixmapCache.getIcon("plus")) |
57 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy")) |
59 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy")) |
58 self.minusButton.setIcon(UI.PixmapCache.getIcon("minus")) |
60 self.minusButton.setIcon(UI.PixmapCache.getIcon("minus")) |
59 self.showPasswordButton.setIcon(UI.PixmapCache.getIcon("showPassword")) |
61 self.showPasswordButton.setIcon(UI.PixmapCache.getIcon("showPassword")) |
|
62 self.willPropertiesButton.setIcon( |
|
63 UI.PixmapCache.getIcon("listSelection")) |
60 |
64 |
61 self.tlsCertsFilePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
65 self.tlsCertsFilePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
62 self.tlsCertsFilePicker.setFilters( |
66 self.tlsCertsFilePicker.setFilters( |
63 self.tr("Certificate Files (*.crt *.pem);;All Files (*)")) |
67 self.tr("Certificate Files (*.crt *.pem);;All Files (*)")) |
64 self.tlsSelfSignedCertsFilePicker.setMode( |
68 self.tlsSelfSignedCertsFilePicker.setMode( |
204 self.tr("Copy Connection Profile"), |
208 self.tr("Copy Connection Profile"), |
205 self.tr("""<p>A connection named <b>{0}</b> exists""" |
209 self.tr("""<p>A connection named <b>{0}</b> exists""" |
206 """ already. Aborting...</p>""").format( |
210 """ already. Aborting...</p>""").format( |
207 newProfileName)) |
211 newProfileName)) |
208 else: |
212 else: |
209 profile = self.__defaultProfile() |
213 connectionProfile = self.__defaultProfile() |
210 profile.update(self.__profiles[profileName]) |
214 connectionProfile.update( |
211 self.__profiles[newProfileName] = profile |
215 copy.deepcopy(self.__profiles[profileName])) |
|
216 self.__profiles[newProfileName] = connectionProfile |
|
217 self.__profilesChanged = True |
212 |
218 |
213 itm = QListWidgetItem(newProfileName, self.profilesList) |
219 itm = QListWidgetItem(newProfileName, self.profilesList) |
214 self.profilesList.setCurrentItem(itm) |
220 self.profilesList.setCurrentItem(itm) |
215 self.brokerAddressEdit.setFocus( |
221 self.brokerAddressEdit.setFocus( |
216 Qt.FocusReason.OtherFocusReason) |
222 Qt.FocusReason.OtherFocusReason) |
244 |
250 |
245 @return dictionary containing dictionaries containing the defined |
251 @return dictionary containing dictionaries containing the defined |
246 connection profiles. Each entry has the keys "BrokerAddress", |
252 connection profiles. Each entry has the keys "BrokerAddress", |
247 "BrokerPort", "ClientId", "Protocol", "ConnectionTimeout", |
253 "BrokerPort", "ClientId", "Protocol", "ConnectionTimeout", |
248 "Keepalive", "CleanSession", "Username", "Password", "WillTopic", |
254 "Keepalive", "CleanSession", "Username", "Password", "WillTopic", |
249 "WillMessage", "WillQos", "WillRetain", "TlsEnable", "TlsCaCert", |
255 "WillMessage", "WillQos", "WillRetain", "WillProperties", |
250 "TlsClientCert", "TlsClientKey", "UserProperties". |
256 "TlsEnable", "TlsCaCert", "TlsClientCert", "TlsClientKey", |
|
257 "UserProperties". |
251 @rtype dict |
258 @rtype dict |
252 """ |
259 """ |
253 profilesDict = {} |
260 profilesDict = {} |
254 profilesDict.update(self.__profiles) |
261 profilesDict.update(copy.deepcopy(dict(self.__profiles))) |
255 return profilesDict |
262 return profilesDict |
256 |
263 |
257 def __applyProfile(self): |
264 def __applyProfile(self): |
258 """ |
265 """ |
259 Private method to apply the entered data to the list of profiles. |
266 Private method to apply the entered data to the list of profiles. |
279 self.propertiesWidget.getProperties()) |
286 self.propertiesWidget.getProperties()) |
280 self.__userProperties["use_connect"] = ( |
287 self.__userProperties["use_connect"] = ( |
281 self.samePropertiesCheckBox.isChecked()) |
288 self.samePropertiesCheckBox.isChecked()) |
282 else: |
289 else: |
283 self.__userProperties = {} |
290 self.__userProperties = {} |
|
291 self.__willProperties = [] |
284 |
292 |
285 profileName = self.profileEdit.text() |
293 profileName = self.profileEdit.text() |
286 connectionProfile = { |
294 connectionProfile = { |
287 "BrokerAddress": self.brokerAddressEdit.text(), |
295 "BrokerAddress": self.brokerAddressEdit.text(), |
288 "BrokerPort": self.brokerPortSpinBox.value(), |
296 "BrokerPort": self.brokerPortSpinBox.value(), |
295 "Password": pwConvert(self.passwordEdit.text(), encode=True), |
303 "Password": pwConvert(self.passwordEdit.text(), encode=True), |
296 "WillTopic": self.willTopicEdit.text(), |
304 "WillTopic": self.willTopicEdit.text(), |
297 "WillMessage": self.willMessageEdit.toPlainText(), |
305 "WillMessage": self.willMessageEdit.toPlainText(), |
298 "WillQos": self.willQosSpinBox.value(), |
306 "WillQos": self.willQosSpinBox.value(), |
299 "WillRetain": self.willRetainCheckBox.isChecked(), |
307 "WillRetain": self.willRetainCheckBox.isChecked(), |
|
308 "WillProperties": copy.deepcopy(self.__willProperties), |
300 "TlsEnable": self.tlsGroupBox.isChecked(), |
309 "TlsEnable": self.tlsGroupBox.isChecked(), |
301 "TlsCaCert": "", |
310 "TlsCaCert": "", |
302 "TlsClientCert": "", |
311 "TlsClientCert": "", |
303 "TlsClientKey": "", |
312 "TlsClientKey": "", |
304 "UserProperties": copy.deepcopy(self.__userProperties), |
313 "UserProperties": copy.deepcopy(self.__userProperties), |
398 # will tab |
407 # will tab |
399 self.willTopicEdit.setText(connectionProfile["WillTopic"]) |
408 self.willTopicEdit.setText(connectionProfile["WillTopic"]) |
400 self.willMessageEdit.setPlainText(connectionProfile["WillMessage"]) |
409 self.willMessageEdit.setPlainText(connectionProfile["WillMessage"]) |
401 self.willQosSpinBox.setValue(connectionProfile["WillQos"]) |
410 self.willQosSpinBox.setValue(connectionProfile["WillQos"]) |
402 self.willRetainCheckBox.setChecked(connectionProfile["WillRetain"]) |
411 self.willRetainCheckBox.setChecked(connectionProfile["WillRetain"]) |
|
412 self.__willProperties = copy.deepcopy( |
|
413 connectionProfile.get("WillProperties", [])) |
403 |
414 |
404 # SSL/TLS tab |
415 # SSL/TLS tab |
405 self.tlsGroupBox.setChecked(connectionProfile["TlsEnable"]) |
416 self.tlsGroupBox.setChecked(connectionProfile["TlsEnable"]) |
406 if ( |
417 if ( |
407 connectionProfile["TlsCaCert"] and |
418 connectionProfile["TlsCaCert"] and |
465 self.passwordEdit.setText("") |
476 self.passwordEdit.setText("") |
466 self.willTopicEdit.setText("") |
477 self.willTopicEdit.setText("") |
467 self.willMessageEdit.setPlainText("") |
478 self.willMessageEdit.setPlainText("") |
468 self.willQosSpinBox.setValue(0) |
479 self.willQosSpinBox.setValue(0) |
469 self.willRetainCheckBox.setChecked(False) |
480 self.willRetainCheckBox.setChecked(False) |
|
481 self.__willProperties = [] |
470 self.tlsGroupBox.setChecked(False) |
482 self.tlsGroupBox.setChecked(False) |
471 self.tlsDefaultCertsButton.setChecked(True) |
483 self.tlsDefaultCertsButton.setChecked(True) |
472 self.tlsCertsFileButton.setChecked(True) |
484 self.tlsCertsFileButton.setChecked(True) |
473 self.tlsCertsFilePicker.setText("") |
485 self.tlsCertsFilePicker.setText("") |
474 self.tlsSelfSignedCertsButton.setChecked(False) |
486 self.tlsSelfSignedCertsButton.setChecked(False) |
554 self.willQosSpinBox.value() != connectionProfile["WillQos"] or |
566 self.willQosSpinBox.value() != connectionProfile["WillQos"] or |
555 self.willRetainCheckBox.isChecked() != |
567 self.willRetainCheckBox.isChecked() != |
556 connectionProfile["WillRetain"] or |
568 connectionProfile["WillRetain"] or |
557 self.tlsGroupBox.isChecked() != connectionProfile["TlsEnable"] |
569 self.tlsGroupBox.isChecked() != connectionProfile["TlsEnable"] |
558 ) |
570 ) |
|
571 # check will properties only, ig not yet changed |
|
572 if not changed and protocol == MqttProtocols.MQTTv5: |
|
573 changed |= ( |
|
574 sorted(self.__willProperties) != |
|
575 sorted(connectionProfile["WillProperties"]) |
|
576 ) |
559 # check TLS stuff only, if not yet changed |
577 # check TLS stuff only, if not yet changed |
560 if not changed: |
578 if not changed: |
561 if self.tlsCertsFileButton.isChecked(): |
579 if self.tlsCertsFileButton.isChecked(): |
562 changed |= ( |
580 changed |= ( |
563 self.tlsCertsFilePicker.text() != |
581 self.tlsCertsFilePicker.text() != |
696 ( |
715 ( |
697 self.passwordEdit.setEchoMode(QLineEdit.EchoMode.Normal) |
716 self.passwordEdit.setEchoMode(QLineEdit.EchoMode.Normal) |
698 if checked else |
717 if checked else |
699 self.passwordEdit.setEchoMode(QLineEdit.EchoMode.Password) |
718 self.passwordEdit.setEchoMode(QLineEdit.EchoMode.Password) |
700 ) |
719 ) |
|
720 |
|
721 @pyqtSlot() |
|
722 def on_willPropertiesButton_clicked(self): |
|
723 """ |
|
724 Private slot to edit the last will user properties. |
|
725 """ |
|
726 from .MqttUserPropertiesEditor import MqttUserPropertiesEditorDialog |
|
727 |
|
728 dlg = MqttUserPropertiesEditorDialog( |
|
729 self.tr("Last Will User Properties"), self.__willProperties, self) |
|
730 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
731 self.__willProperties = dlg.getProperties() |
701 |
732 |
702 @pyqtSlot(str) |
733 @pyqtSlot(str) |
703 def on_tlsCertsFilePicker_textChanged(self, path): |
734 def on_tlsCertsFilePicker_textChanged(self, path): |
704 """ |
735 """ |
705 Private slot handling a change of the TLS CA certificates file. |
736 Private slot handling a change of the TLS CA certificates file. |