301 Private slot to handling entering or selecting a broker host name. |
302 Private slot to handling entering or selecting a broker host name. |
302 |
303 |
303 @param host host name of the broker |
304 @param host host name of the broker |
304 @type str |
305 @type str |
305 """ |
306 """ |
306 if not self.__connectedToBroker and not host: |
307 self.__setConnectButtonState() |
307 self.connectButton.setEnabled(False) |
|
308 else: |
|
309 self.connectButton.setEnabled(True) |
|
310 |
308 |
311 @pyqtSlot() |
309 @pyqtSlot() |
312 def on_brokerConnectionOptionsButton_clicked(self): |
310 def on_brokerConnectionOptionsButton_clicked(self): |
313 """ |
311 """ |
314 Private slot to show a dialog to modify connection options or a |
312 Private slot to show a dialog to modify connection options or a |
315 dialog to edit connection profiles. |
313 dialog to edit connection profiles. |
316 """ |
314 """ |
317 if self.__connectionModeProfile: |
315 if self.__connectionModeProfile: |
318 # TODO: implement this path |
|
319 from .MqttConnectionProfilesDialog import \ |
316 from .MqttConnectionProfilesDialog import \ |
320 MqttConnectionProfilesDialog |
317 MqttConnectionProfilesDialog |
321 dlg = MqttConnectionProfilesDialog( |
318 dlg = MqttConnectionProfilesDialog( |
322 self.__client, self.__plugin.getPreferences("BrokerProfiles"), |
319 self.__client, self.__plugin.getPreferences("BrokerProfiles"), |
323 parent=self) |
320 parent=self) |
324 if dlg.exec_() == QDialog.Accepted: |
321 if dlg.exec_() == QDialog.Accepted: |
325 profiles = dlg.getProfiles() |
322 profilesDict = dlg.getProfiles() |
326 self.__plugin.setPreferences("BrokerProfiles", profiles) |
323 self.__plugin.setPreferences("BrokerProfiles", profilesDict) |
327 self.__populateProfileComboBox() |
324 self.__populateProfileComboBox() |
328 else: |
325 else: |
329 from .MqttConnectionOptionsDialog import \ |
326 from .MqttConnectionOptionsDialog import \ |
330 MqttConnectionOptionsDialog |
327 MqttConnectionOptionsDialog |
331 dlg = MqttConnectionOptionsDialog( |
328 dlg = MqttConnectionOptionsDialog( |
340 """ |
337 """ |
341 if self.__connectedToBroker: |
338 if self.__connectedToBroker: |
342 self.__client.disconnectFromServer() |
339 self.__client.disconnectFromServer() |
343 else: |
340 else: |
344 if self.__connectionModeProfile: |
341 if self.__connectionModeProfile: |
345 # TODO: implement this path |
342 self.__profileConnectToBroker |
346 pass |
|
347 else: |
343 else: |
348 self.__directConnectToBroker() |
344 self.__directConnectToBroker() |
349 |
345 |
350 @pyqtSlot(str) |
346 @pyqtSlot(str) |
351 def on_subscribeTopicEdit_textChanged(self, topic): |
347 def on_subscribeTopicEdit_textChanged(self, topic): |
507 self.brokerPortComboBox.clear() |
503 self.brokerPortComboBox.clear() |
508 |
504 |
509 # step 2a: populate the broker name list |
505 # step 2a: populate the broker name list |
510 self.brokerComboBox.addItems([b[0].strip() for b in brokerList]) |
506 self.brokerComboBox.addItems([b[0].strip() for b in brokerList]) |
511 |
507 |
|
508 self.__setConnectButtonState() |
|
509 |
512 # step 2b: populate the broker ports list |
510 # step 2b: populate the broker ports list |
513 if brokerList: |
511 if brokerList: |
514 currentPort = brokerList[0][1] |
512 currentPort = brokerList[0][1] |
515 else: |
513 else: |
516 currentPort = 1883 |
514 currentPort = 1883 |
528 """ |
526 """ |
529 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
527 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
530 |
528 |
531 self.profileComboBox.clear() |
529 self.profileComboBox.clear() |
532 self.profileComboBox.addItems(sorted(profilesDict.keys())) |
530 self.profileComboBox.addItems(sorted(profilesDict.keys())) |
|
531 |
|
532 self.__setConnectButtonState() |
533 |
533 |
534 def __updateUnsubscribeTopicComboBox(self): |
534 def __updateUnsubscribeTopicComboBox(self): |
535 """ |
535 """ |
536 Private method to update the unsubcribe topic combo box. |
536 Private method to update the unsubcribe topic combo box. |
537 """ |
537 """ |
652 else: |
652 else: |
653 self.modeButton.setIcon(UI.PixmapCache.getIcon( |
653 self.modeButton.setIcon(UI.PixmapCache.getIcon( |
654 os.path.join("MqttMonitor", "icons", "quickopen.png"))) |
654 os.path.join("MqttMonitor", "icons", "quickopen.png"))) |
655 |
655 |
656 self.profileComboBox.setVisible(profileMode) |
656 self.profileComboBox.setVisible(profileMode) |
657 self.brokerComboBox.setVisible(not profileMode) |
657 self.brokerConnectionWidget.setVisible(not profileMode) |
658 self.brokerPortComboBox.setVisible(not profileMode) |
658 self.__setConnectButtonState() |
|
659 |
|
660 def __setConnectButtonState(self): |
|
661 """ |
|
662 Private method to set the enabled state of the connect button. |
|
663 """ |
|
664 if self.__connectionModeProfile: |
|
665 self.connectButton.setEnabled( |
|
666 bool(self.profileComboBox.currentText())) |
|
667 else: |
|
668 self.connectButton.setEnabled( |
|
669 bool(self.brokerComboBox.currentText())) |
659 |
670 |
660 def __directConnectToBroker(self): |
671 def __directConnectToBroker(self): |
661 """ |
672 """ |
662 Private method to connect to the broker with entered data. |
673 Private method to connect to the broker with entered data. |
663 """ |
674 """ |
680 """ |
691 """ |
681 Private method to connect to the broker with selected profile. |
692 Private method to connect to the broker with selected profile. |
682 """ |
693 """ |
683 profileName = self.profileComboBox.currentText() |
694 profileName = self.profileComboBox.currentText() |
684 if profileName: |
695 if profileName: |
685 # TODO: implement connect by profile name |
696 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
686 pass |
697 profile = copy.copy(profilesDict[profileName]) # play it save |
|
698 host = profile["BrokerAddress"] |
|
699 port = profile["BrokerPort"] |
|
700 |
|
701 self.__client.connectToServerWithOptions(host, port=port, |
|
702 options=profile) |