152 @param flags flags set for the connection |
152 @param flags flags set for the connection |
153 @type dict |
153 @type dict |
154 @param rc CONNACK result code |
154 @param rc CONNACK result code |
155 @type int |
155 @type int |
156 """ |
156 """ |
|
157 self.brokerStatusLabel.hide() |
|
158 |
|
159 # TODO: add support for flags[‘session present’] |
157 if rc == 0: |
160 if rc == 0: |
158 self.__connectedToBroker = True |
161 self.__connectedToBroker = True |
159 self.__connectionOptions = None |
162 self.__connectionOptions = None |
160 |
163 |
161 msg = mqttConnackMessage(rc) |
164 msg = mqttConnackMessage(rc) |
162 self.__flashBrokerStatusLabel(msg) |
165 self.__flashBrokerStatusLabel(msg) |
163 |
166 |
164 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) |
167 self.connectButton.setEnabled(True) |
165 |
168 if rc == 0: |
166 self.subscribeGroup.setEnabled(True) |
169 self.__connectedToBroker = True |
167 self.unsubscribeGroup.setEnabled(True) |
170 self.__connectionOptions = None |
168 self.publishGroup.setEnabled(True) |
171 |
169 self.brokerStatusButton.setEnabled(True) |
172 self.connectButton.setIcon( |
170 |
173 UI.PixmapCache.getIcon("ircDisconnect.png")) |
171 self.__statusLoadValues.clear() |
174 |
172 self.__clearBrokerStatusLabels() |
175 self.subscribeGroup.setEnabled(True) |
173 self.__setBrokerStatusSubscribed(False) |
176 self.unsubscribeGroup.setEnabled(True) |
|
177 self.publishGroup.setEnabled(True) |
|
178 self.brokerStatusButton.setEnabled(True) |
|
179 |
|
180 self.__statusLoadValues.clear() |
|
181 self.__clearBrokerStatusLabels() |
|
182 self.__setBrokerStatusSubscribed(False) |
|
183 else: |
|
184 self.__client.stopLoop() |
174 |
185 |
175 @pyqtSlot(int) |
186 @pyqtSlot(int) |
176 def __brokerDisconnected(self, rc): |
187 def __brokerDisconnected(self, rc): |
177 """ |
188 """ |
178 Private slot to handle a disconnection from the broker. |
189 Private slot to handle a disconnection from the broker. |
183 self.__connectedToBroker = False |
194 self.__connectedToBroker = False |
184 |
195 |
185 # ensure, the client loop is stopped |
196 # ensure, the client loop is stopped |
186 self.__client.stopLoop() |
197 self.__client.stopLoop() |
187 |
198 |
188 if rc != 0: |
199 if rc > 0: |
189 msg = mqttErrorMessage(rc) |
200 msg = mqttErrorMessage(rc) |
190 else: |
201 else: |
191 msg = self.tr("Connection to Broker shut down cleanly.") |
202 msg = self.tr("Connection to Broker shut down cleanly.") |
192 self.__flashBrokerStatusLabel(msg) |
203 self.__flashBrokerStatusLabel(msg) |
193 |
204 |
194 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
205 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
|
206 self.connectButton.setEnabled(True) |
195 |
207 |
196 self.__subscribedTopics = [] |
208 self.__subscribedTopics = [] |
197 self.__topicQueue = {} |
209 self.__topicQueue = {} |
198 self.__updateUnsubscribeTopicComboBox() |
210 self.__updateUnsubscribeTopicComboBox() |
199 self.__updatePublishTopicComboBox() |
211 self.__updatePublishTopicComboBox() |
422 @pyqtSlot() |
434 @pyqtSlot() |
423 def on_publishButton_clicked(self): |
435 def on_publishButton_clicked(self): |
424 """ |
436 """ |
425 Private slot to publish the entered message. |
437 Private slot to publish the entered message. |
426 """ |
438 """ |
|
439 # TODO: read message data from file as binary |
|
440 # size of data <= 268435455 |
427 topic = self.publishTopicComboBox.currentText() |
441 topic = self.publishTopicComboBox.currentText() |
428 qos = self.publishQosSpinBox.value() |
442 qos = self.publishQosSpinBox.value() |
429 retain = self.publishRetainCheckBox.isChecked() |
443 retain = self.publishRetainCheckBox.isChecked() |
430 payloadStr = self.publishPayloadEdit.toPlainText() |
444 payloadStr = self.publishPayloadEdit.toPlainText() |
431 if not payloadStr: |
445 if not payloadStr: |
543 def __populateProfileComboBox(self): |
557 def __populateProfileComboBox(self): |
544 """ |
558 """ |
545 Private method to populate the profiles selection box. |
559 Private method to populate the profiles selection box. |
546 """ |
560 """ |
547 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
561 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
|
562 mostRecentProfile = self.__plugin.getPreferences("MostRecentProfile") |
548 |
563 |
549 self.profileComboBox.clear() |
564 self.profileComboBox.clear() |
550 self.profileComboBox.addItems(sorted(profilesDict.keys())) |
565 self.profileComboBox.addItems(sorted(profilesDict.keys())) |
|
566 if mostRecentProfile: |
|
567 index = self.profileComboBox.findText(mostRecentProfile) |
|
568 if index >= 0: |
|
569 self.profileComboBox.setCurrentIndex(index) |
551 |
570 |
552 self.__setConnectButtonState() |
571 self.__setConnectButtonState() |
553 |
572 |
554 def __updateUnsubscribeTopicComboBox(self): |
573 def __updateUnsubscribeTopicComboBox(self): |
555 """ |
574 """ |
707 port = int(port) |
726 port = int(port) |
708 except ValueError: |
727 except ValueError: |
709 # use standard port at 1883 |
728 # use standard port at 1883 |
710 port = 1883 |
729 port = 1883 |
711 if host: |
730 if host: |
|
731 self.brokerStatusLabel.setText( |
|
732 self.tr("Connecting to {0}:{1} ...").format( |
|
733 host, port)) |
|
734 self.brokerStatusLabel.show() |
|
735 |
712 self.__addBrokerToRecent(host, port) |
736 self.__addBrokerToRecent(host, port) |
|
737 self.connectButton.setEnabled(False) |
713 if self.__connectionOptions is None: |
738 if self.__connectionOptions is None: |
714 self.__client.connectToServer(host, port=port) |
739 self.__client.connectToServer(host, port=port) |
715 else: |
740 else: |
716 self.__client.connectToServerWithOptions( |
741 self.__client.connectToServerWithOptions( |
717 host, port=port, options=self.__connectionOptions) |
742 host, port=port, options=self.__connectionOptions) |
720 """ |
745 """ |
721 Private method to connect to the broker with selected profile. |
746 Private method to connect to the broker with selected profile. |
722 """ |
747 """ |
723 profileName = self.profileComboBox.currentText() |
748 profileName = self.profileComboBox.currentText() |
724 if profileName: |
749 if profileName: |
|
750 self.__plugin.setPreferences("MostRecentProfile", profileName) |
|
751 |
725 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
752 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
726 profile = copy.copy(profilesDict[profileName]) # play it save |
753 profile = copy.copy(profilesDict[profileName]) # play it save |
727 host = profile["BrokerAddress"] |
754 host = profile["BrokerAddress"] |
728 port = profile["BrokerPort"] |
755 port = profile["BrokerPort"] |
729 |
756 |
|
757 self.brokerStatusLabel.setText( |
|
758 self.tr("Connecting to {0}:{1} ...").format( |
|
759 host, port)) |
|
760 self.brokerStatusLabel.show() |
|
761 |
|
762 self.connectButton.setEnabled(False) |
730 self.__client.connectToServerWithOptions(host, port=port, |
763 self.__client.connectToServerWithOptions(host, port=port, |
731 options=profile) |
764 options=profile) |