MqttMonitor/MqttMonitorWidget.py

branch
eric7
changeset 104
9a4c9b7f078c
parent 103
5fe4f179975f
child 105
36ec7431ad04
diff -r 5fe4f179975f -r 9a4c9b7f078c MqttMonitor/MqttMonitorWidget.py
--- a/MqttMonitor/MqttMonitorWidget.py	Thu Jul 22 19:02:32 2021 +0200
+++ b/MqttMonitor/MqttMonitorWidget.py	Fri Jul 23 17:48:22 2021 +0200
@@ -137,6 +137,8 @@
         ))
         self.__populateBrokerComboBoxes()
         self.brokerStatusLabel.hide()
+        self.clearWillButton.setIcon(
+            UI.PixmapCache.getIcon("certificateDelete"))
         
         self.subscribeButton.setIcon(UI.PixmapCache.getIcon("plus"))
         self.subscribeButton.setEnabled(False)
@@ -294,16 +296,22 @@
         """
         self.brokerStatusLabel.hide()
         
-        # TODO: add support for flags[‘session present’]
         if rc == 0:
             self.__connectedToBroker = True
             self.__connectionOptions = None
         
+        try:
+            sessionPresent = flags["session present"] == 1
+        except KeyError:
+            sessionPresent = False
+        
         msg = (
             mqttReasonCode(rc, packetType)
             if packetType is not None else
             mqttConnackMessage(rc)
         )
+        if sessionPresent:
+            msg = self.tr("{0} - Session still present").format(msg)
         self.__flashBrokerStatusLabel(msg)
         
         if properties:
@@ -600,8 +608,10 @@
             from .MqttConnectionProfilesDialog import (
                 MqttConnectionProfilesDialog
             )
+            profileName = self.profileComboBox.currentText()
             dlg = MqttConnectionProfilesDialog(
-                self.__plugin.getPreferences("BrokerProfiles"), parent=self)
+                self.__plugin.getPreferences("BrokerProfiles"),
+                currentProfile=profileName, parent=self)
             if dlg.exec() == QDialog.DialogCode.Accepted:
                 profilesDict = dlg.getProfiles()
                 self.__plugin.setPreferences("BrokerProfiles", profilesDict)
@@ -1296,9 +1306,17 @@
             
             self.__addBrokerToRecent(host, port)
             self.connectButton.setEnabled(False)
+            
+            if self.clearWillButton.isChecked():
+                clearWill = True
+                self.clearWillButton.setChecked(False)
+            else:
+                clearWill = False
+            
             if self.__connectionOptions is None:
                 self.__client = self.__createClient()
-                self.__client.connectToServer(host, port=port)
+                self.__client.connectToServer(
+                    host, port=port, clearWill=clearWill)
             else:
                 self.__client = self.__createClient(
                     clientId=self.__connectionOptions["ClientId"],
@@ -1306,7 +1324,8 @@
                     protocol=self.__connectionOptions["Protocol"]
                 )
                 self.__client.connectToServerWithOptions(
-                    host, port=port, options=self.__connectionOptions)
+                    host, port=port, options=self.__connectionOptions,
+                    clearWill=clearWill)
     
     def __profileConnectToBroker(self):
         """
@@ -1332,13 +1351,20 @@
             
             self.connectButton.setEnabled(False)
             
+            if self.clearWillButton.isChecked():
+                clearWill = True
+                self.clearWillButton.setChecked(False)
+            else:
+                clearWill = False
+            
             self.__client = self.__createClient(
                 clientId=connectionProfile["ClientId"],
                 cleanSession=connectionProfile["CleanSession"],
                 protocol=protocol
             )
             self.__client.connectToServerWithOptions(
-                host, port=port, options=connectionProfile)
+                host, port=port, options=connectionProfile,
+                clearWill=clearWill)
     
     def __showProperties(self, typeStr, properties):
         """

eric ide

mercurial