58 |
58 |
59 self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap( |
59 self.pixmapLabel.setPixmap(UI.PixmapCache.getPixmap( |
60 os.path.join("MqttMonitor", "icons", "mqtt48.png"))) |
60 os.path.join("MqttMonitor", "icons", "mqtt48.png"))) |
61 |
61 |
62 self.brokerWidget.setCurrentIndex(0) |
62 self.brokerWidget.setCurrentIndex(0) |
|
63 |
|
64 self.__connectionModeProfile = True |
|
65 self.__setConnectionMode(True) # initial mode is 'profile connection' |
|
66 self.__populateProfileComboBox() |
63 |
67 |
64 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
68 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
65 self.brokerConnectionOptionsButton.setIcon(UI.PixmapCache.getIcon( |
69 self.brokerConnectionOptionsButton.setIcon(UI.PixmapCache.getIcon( |
66 os.path.join("MqttMonitor", "icons", "connectionOptions.png"))) |
70 os.path.join("MqttMonitor", "icons", "connectionOptions.png"))) |
67 self.__populateBrokerComboBoxes() |
71 self.__populateBrokerComboBoxes() |
281 """ |
285 """ |
282 self.brokerStatusLabel.setText(message) |
286 self.brokerStatusLabel.setText(message) |
283 self.brokerStatusLabel.show() |
287 self.brokerStatusLabel.show() |
284 QTimer.singleShot(5000, self.brokerStatusLabel.hide) |
288 QTimer.singleShot(5000, self.brokerStatusLabel.hide) |
285 |
289 |
|
290 @pyqtSlot() |
|
291 def on_modeButton_clicked(self): |
|
292 """ |
|
293 Private slot to switch between connection profiles and direct |
|
294 connection mode. |
|
295 """ |
|
296 self.__setConnectionMode(not self.__connectionModeProfile) |
|
297 |
286 @pyqtSlot(str) |
298 @pyqtSlot(str) |
287 def on_brokerComboBox_editTextChanged(self, host): |
299 def on_brokerComboBox_editTextChanged(self, host): |
288 """ |
300 """ |
289 Private slot to handling entering or selecting a broker host name. |
301 Private slot to handling entering or selecting a broker host name. |
290 |
302 |
297 self.connectButton.setEnabled(True) |
309 self.connectButton.setEnabled(True) |
298 |
310 |
299 @pyqtSlot() |
311 @pyqtSlot() |
300 def on_brokerConnectionOptionsButton_clicked(self): |
312 def on_brokerConnectionOptionsButton_clicked(self): |
301 """ |
313 """ |
302 Private slot to show a dialog to modify connection options. |
314 Private slot to show a dialog to modify connection options or a |
303 """ |
315 dialog to edit connection profiles. |
304 from .MqttConnectionOptionsDialog import MqttConnectionOptionsDialog |
316 """ |
305 dlg = MqttConnectionOptionsDialog( |
317 if self.__connectionModeProfile: |
306 self.__client, self.__connectionOptions, parent=self) |
318 # TODO: implement this path |
307 if dlg.exec_() == QDialog.Accepted: |
319 from .MqttConnectionProfilesDialog import \ |
308 self.__connectionOptions = dlg.getConnectionOptions() |
320 MqttConnectionProfilesDialog |
|
321 dlg = MqttConnectionProfilesDialog( |
|
322 self.__client, self.__plugin.getPreferences("BrokerProfiles"), |
|
323 parent=self) |
|
324 if dlg.exec_() == QDialog.Accepted: |
|
325 profiles = dlg.getProfiles() |
|
326 self.__plugin.setPreferences("BrokerProfiles", profiles) |
|
327 self.__populateProfileComboBox() |
|
328 else: |
|
329 from .MqttConnectionOptionsDialog import \ |
|
330 MqttConnectionOptionsDialog |
|
331 dlg = MqttConnectionOptionsDialog( |
|
332 self.__client, self.__connectionOptions, parent=self) |
|
333 if dlg.exec_() == QDialog.Accepted: |
|
334 self.__connectionOptions = dlg.getConnectionOptions() |
309 |
335 |
310 @pyqtSlot() |
336 @pyqtSlot() |
311 def on_connectButton_clicked(self): |
337 def on_connectButton_clicked(self): |
312 """ |
338 """ |
313 Private slot to handle a connect or disconnect request. |
339 Private slot to handle a connect or disconnect request. |
314 """ |
340 """ |
315 if self.__connectedToBroker: |
341 if self.__connectedToBroker: |
316 self.__client.disconnectFromServer() |
342 self.__client.disconnectFromServer() |
317 else: |
343 else: |
318 host = self.brokerComboBox.currentText() |
344 if self.__connectionModeProfile: |
319 port = self.brokerPortComboBox.currentText().strip() |
345 # TODO: implement this path |
320 try: |
346 pass |
321 port = int(port) |
347 else: |
322 except ValueError: |
348 self.__directConnectToBroker() |
323 # use standard port at 1883 |
|
324 port = 1883 |
|
325 if host: |
|
326 self.__addBrokerToRecent(host, port) |
|
327 if self.__connectionOptions is None: |
|
328 self.__client.connectToServer(host, port=port) |
|
329 else: |
|
330 self.__client.connectToServerWithOptions( |
|
331 host, port=port, options=self.__connectionOptions) |
|
332 |
349 |
333 @pyqtSlot(str) |
350 @pyqtSlot(str) |
334 def on_subscribeTopicEdit_textChanged(self, topic): |
351 def on_subscribeTopicEdit_textChanged(self, topic): |
335 """ |
352 """ |
336 Private slot to handle a change of the entered topic. |
353 Private slot to handle a change of the entered topic. |
503 self.brokerPortComboBox.addItems( |
520 self.brokerPortComboBox.addItems( |
504 sorted("{0:5}".format(p) for p in portsSet)) |
521 sorted("{0:5}".format(p) for p in portsSet)) |
505 index = self.brokerPortComboBox.findText(currentPortStr) |
522 index = self.brokerPortComboBox.findText(currentPortStr) |
506 self.brokerPortComboBox.setCurrentIndex(index) |
523 self.brokerPortComboBox.setCurrentIndex(index) |
507 |
524 |
|
525 def __populateProfileComboBox(self): |
|
526 """ |
|
527 Private method to populate the profiles selection box. |
|
528 """ |
|
529 profilesDict = self.__plugin.getPreferences("BrokerProfiles") |
|
530 |
|
531 self.profileComboBox.clear() |
|
532 self.profileComboBox.addItems(sorted(profilesDict.keys())) |
|
533 |
508 def __updateUnsubscribeTopicComboBox(self): |
534 def __updateUnsubscribeTopicComboBox(self): |
509 """ |
535 """ |
510 Private method to update the unsubcribe topic combo box. |
536 Private method to update the unsubcribe topic combo box. |
511 """ |
537 """ |
512 self.unsubscribeTopicComboBox.clear() |
538 self.unsubscribeTopicComboBox.clear() |
609 return { |
635 return { |
610 "1min": "-", |
636 "1min": "-", |
611 "5min": "-", |
637 "5min": "-", |
612 "15min": "-", |
638 "15min": "-", |
613 } |
639 } |
|
640 |
|
641 def __setConnectionMode(self, profileMode): |
|
642 """ |
|
643 Private method to set the connection mode. |
|
644 |
|
645 @param profileMode flag indicating the profile connection mode |
|
646 @type bool |
|
647 """ |
|
648 self.__connectionModeProfile = profileMode |
|
649 if profileMode: |
|
650 self.modeButton.setIcon(UI.PixmapCache.getIcon( |
|
651 os.path.join("MqttMonitor", "icons", "profiles.png"))) |
|
652 else: |
|
653 self.modeButton.setIcon(UI.PixmapCache.getIcon( |
|
654 os.path.join("MqttMonitor", "icons", "quickopen.png"))) |
|
655 |
|
656 self.profileComboBox.setVisible(profileMode) |
|
657 self.brokerComboBox.setVisible(not profileMode) |
|
658 self.brokerPortComboBox.setVisible(not profileMode) |
|
659 |
|
660 def __directConnectToBroker(self): |
|
661 """ |
|
662 Private method to connect to the broker with entered data. |
|
663 """ |
|
664 host = self.brokerComboBox.currentText() |
|
665 port = self.brokerPortComboBox.currentText().strip() |
|
666 try: |
|
667 port = int(port) |
|
668 except ValueError: |
|
669 # use standard port at 1883 |
|
670 port = 1883 |
|
671 if host: |
|
672 self.__addBrokerToRecent(host, port) |
|
673 if self.__connectionOptions is None: |
|
674 self.__client.connectToServer(host, port=port) |
|
675 else: |
|
676 self.__client.connectToServerWithOptions( |
|
677 host, port=port, options=self.__connectionOptions) |
|
678 |
|
679 def __profileConnectToBroker(self): |
|
680 """ |
|
681 Private method to connect to the broker with selected profile. |
|
682 """ |
|
683 profileName = self.profileComboBox.currentText() |
|
684 if profileName: |
|
685 # TODO: implement connect by profile name |
|
686 pass |