--- a/MqttMonitor/MqttMonitorWidget.py Sat Sep 08 16:55:42 2018 +0200 +++ b/MqttMonitor/MqttMonitorWidget.py Sun Sep 09 12:21:19 2018 +0200 @@ -154,6 +154,9 @@ @param rc CONNACK result code @type int """ + self.brokerStatusLabel.hide() + + # TODO: add support for flags[‘session present’] if rc == 0: self.__connectedToBroker = True self.__connectionOptions = None @@ -161,16 +164,24 @@ msg = mqttConnackMessage(rc) self.__flashBrokerStatusLabel(msg) - self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) - - self.subscribeGroup.setEnabled(True) - self.unsubscribeGroup.setEnabled(True) - self.publishGroup.setEnabled(True) - self.brokerStatusButton.setEnabled(True) - - self.__statusLoadValues.clear() - self.__clearBrokerStatusLabels() - self.__setBrokerStatusSubscribed(False) + self.connectButton.setEnabled(True) + if rc == 0: + self.__connectedToBroker = True + self.__connectionOptions = None + + self.connectButton.setIcon( + UI.PixmapCache.getIcon("ircDisconnect.png")) + + self.subscribeGroup.setEnabled(True) + self.unsubscribeGroup.setEnabled(True) + self.publishGroup.setEnabled(True) + self.brokerStatusButton.setEnabled(True) + + self.__statusLoadValues.clear() + self.__clearBrokerStatusLabels() + self.__setBrokerStatusSubscribed(False) + else: + self.__client.stopLoop() @pyqtSlot(int) def __brokerDisconnected(self, rc): @@ -185,13 +196,14 @@ # ensure, the client loop is stopped self.__client.stopLoop() - if rc != 0: + if rc > 0: msg = mqttErrorMessage(rc) else: msg = self.tr("Connection to Broker shut down cleanly.") self.__flashBrokerStatusLabel(msg) self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) + self.connectButton.setEnabled(True) self.__subscribedTopics = [] self.__topicQueue = {} @@ -424,6 +436,8 @@ """ Private slot to publish the entered message. """ + # TODO: read message data from file as binary + # size of data <= 268435455 topic = self.publishTopicComboBox.currentText() qos = self.publishQosSpinBox.value() retain = self.publishRetainCheckBox.isChecked() @@ -545,9 +559,14 @@ Private method to populate the profiles selection box. """ profilesDict = self.__plugin.getPreferences("BrokerProfiles") + mostRecentProfile = self.__plugin.getPreferences("MostRecentProfile") self.profileComboBox.clear() self.profileComboBox.addItems(sorted(profilesDict.keys())) + if mostRecentProfile: + index = self.profileComboBox.findText(mostRecentProfile) + if index >= 0: + self.profileComboBox.setCurrentIndex(index) self.__setConnectButtonState() @@ -709,7 +728,13 @@ # use standard port at 1883 port = 1883 if host: + self.brokerStatusLabel.setText( + self.tr("Connecting to {0}:{1} ...").format( + host, port)) + self.brokerStatusLabel.show() + self.__addBrokerToRecent(host, port) + self.connectButton.setEnabled(False) if self.__connectionOptions is None: self.__client.connectToServer(host, port=port) else: @@ -722,10 +747,18 @@ """ profileName = self.profileComboBox.currentText() if profileName: + self.__plugin.setPreferences("MostRecentProfile", profileName) + profilesDict = self.__plugin.getPreferences("BrokerProfiles") profile = copy.copy(profilesDict[profileName]) # play it save host = profile["BrokerAddress"] port = profile["BrokerPort"] + self.brokerStatusLabel.setText( + self.tr("Connecting to {0}:{1} ...").format( + host, port)) + self.brokerStatusLabel.show() + + self.connectButton.setEnabled(False) self.__client.connectToServerWithOptions(host, port=port, options=profile)