MqttMonitor/MqttConnectionOptionsDialog.py

branch
eric7
changeset 104
9a4c9b7f078c
parent 103
5fe4f179975f
child 105
36ec7431ad04
diff -r 5fe4f179975f -r 9a4c9b7f078c MqttMonitor/MqttConnectionOptionsDialog.py
--- a/MqttMonitor/MqttConnectionOptionsDialog.py	Thu Jul 22 19:02:32 2021 +0200
+++ b/MqttMonitor/MqttConnectionOptionsDialog.py	Fri Jul 23 17:48:22 2021 +0200
@@ -20,13 +20,13 @@
 from .MqttClient import MqttClient, MqttProtocols
 
 from Utilities.crypto import pwConvert
+import UI.PixmapCache
 
 
 class MqttConnectionOptionsDialog(QDialog, Ui_MqttConnectionOptionsDialog):
     """
     Class implementing a dialog to enter MQTT connection options.
     """
-    # TODO: add WILL user properties
     def __init__(self, options=None, parent=None):
         """
         Constructor
@@ -35,7 +35,8 @@
             populate the dialog with. It must have the keys "ClientId",
             "Protocol", "ConnectionTimeout", "Keepalive", "CleanSession",
             "Username", "Password", "WillTopic", "WillMessage", "WillQos",
-            "WillRetain", "TlsEnable", "TlsCaCert", "UserProperties".
+            "WillRetain", "WillProperties", "TlsEnable", "TlsCaCert",
+            "UserProperties".
         @type dict
         @param parent reference to the parent widget
         @type QWidget
@@ -47,6 +48,11 @@
         self.tlsCertsFilePicker.setFilters(
             self.tr("Certificate Files (*.crt *.pem);;All Files (*)"))
         
+        self.willPropertiesButton.setIcon(
+            UI.PixmapCache.getIcon("listSelection"))
+        
+        self.optionsWidget.setCurrentIndex(0)
+        
         # initialize MQTTv5 related stuff
         self.on_mqttv5Button_toggled(False)
         
@@ -119,7 +125,8 @@
             self.optionsWidget.indexOf(self.propertiesTab),
             checked
         )
-        # TODO: add code to enable the WILL properties button
+        self.willPropertiesButton.setEnabled(checked)
+        self.willPropertiesButton.setVisible(checked)
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
@@ -168,6 +175,18 @@
                 self.propertiesWidget.setProperties(
                     self.__userProperties["disconnect"])
     
+    @pyqtSlot()
+    def on_willPropertiesButton_clicked(self):
+        """
+        Private slot to edit the last will user properties.
+        """
+        from .MqttUserPropertiesEditor import MqttUserPropertiesEditorDialog
+        
+        dlg = MqttUserPropertiesEditorDialog(
+            self.tr("Last Will User Properties"), self.__willProperties, self)
+        if dlg.exec() == QDialog.DialogCode.Accepted:
+            self.__willProperties = dlg.getProperties()
+    
     def __populateDefaults(self, options=None):
         """
         Private method to populate the dialog.
@@ -179,7 +198,7 @@
             the dialog with. It must have the keys "ClientId", "Protocol",
             "ConnectionTimeout", "Keepalive", "CleanSession", "Username",
             "Password", "WillTopic", "WillMessage", "WillQos", "WillRetain",
-            "TlsEnable", "TlsCaCert", "UserProperties".
+            "WillProperties", "TlsEnable", "TlsCaCert", "UserProperties".
         @type dict
         """
         if options is None:
@@ -206,6 +225,8 @@
         self.willRetainCheckBox.setChecked(options["WillRetain"])
         self.willTopicEdit.setText(options["WillTopic"])
         self.willMessageEdit.setPlainText(options["WillMessage"])
+        self.__willProperties = copy.deepcopy(
+            options.get("WillProperties", []))
         
         # TLS parameters
         self.tlsEnableCheckBox.setChecked(options["TlsEnable"])
@@ -239,8 +260,8 @@
         @return dictionary containing the connection options. It has the keys
             "ClientId", "Protocol", "ConnectionTimeout", "Keepalive",
             "CleanSession", "Username", "Password", "WillTopic", "WillMessage",
-            "WillQos", "WillRetain", "TlsEnable", "TlsCaCert",
-            "UserProperties".
+            "WillQos", "WillRetain", "WillProperties", "TlsEnable",
+            "TlsCaCert", "UserProperties".
         @rtype dict
         """
         if self.mqttv31Button.isChecked():
@@ -263,6 +284,7 @@
                 self.samePropertiesCheckBox.isChecked())
         else:
             self.__userProperties = {}
+            self.__willProperties = []
         
         return {
             "ClientId": self.clientIdEdit.text(),
@@ -276,6 +298,7 @@
             "WillMessage": self.willMessageEdit.toPlainText(),
             "WillQos": self.willQosSpinBox.value(),
             "WillRetain": self.willRetainCheckBox.isChecked(),
+            "WillProperties": copy.deepcopy(self.__willProperties),
             "TlsEnable": self.tlsEnableCheckBox.isChecked(),
             "TlsCaCert": self.tlsCertsFilePicker.text(),
             "UserProperties": copy.deepcopy(self.__userProperties),

eric ide

mercurial