5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to enter MQTT connection options. |
7 Module implementing a dialog to enter MQTT connection options. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, QUuid |
10 from PyQt6.QtCore import pyqtSlot, QUuid |
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
12 |
12 |
13 from E5Gui import E5MessageBox |
13 from EricWidgets import EricMessageBox |
14 from E5Gui.E5PathPicker import E5PathPickerModes |
14 from EricWidgets.EricPathPicker import EricPathPickerModes |
15 |
15 |
16 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
16 from .Ui_MqttConnectionOptionsDialog import Ui_MqttConnectionOptionsDialog |
17 |
17 |
18 from Utilities.crypto import pwConvert |
18 from Utilities.crypto import pwConvert |
19 |
19 |
40 super().__init__(parent) |
40 super().__init__(parent) |
41 self.setupUi(self) |
41 self.setupUi(self) |
42 |
42 |
43 self.__client = client |
43 self.__client = client |
44 |
44 |
45 self.tlsCertsFilePicker.setMode(E5PathPickerModes.OpenFileMode) |
45 self.tlsCertsFilePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
46 self.tlsCertsFilePicker.setFilters( |
46 self.tlsCertsFilePicker.setFilters( |
47 self.tr("Certificate Files (*.crt *.pem);;All Files (*)")) |
47 self.tr("Certificate Files (*.crt *.pem);;All Files (*)")) |
48 |
48 |
49 self.__populateDefaults(options=options) |
49 self.__populateDefaults(options=options) |
50 |
50 |
57 if ( |
57 if ( |
58 self.clientIdEdit.text() == "" and |
58 self.clientIdEdit.text() == "" and |
59 not self.cleanSessionCheckBox.isChecked() |
59 not self.cleanSessionCheckBox.isChecked() |
60 ): |
60 ): |
61 enable = False |
61 enable = False |
62 E5MessageBox.critical( |
62 EricMessageBox.critical( |
63 self, |
63 self, |
64 self.tr("Invalid Connection Parameters"), |
64 self.tr("Invalid Connection Parameters"), |
65 self.tr("""An empty Client ID requires a clean session.""")) |
65 self.tr("""An empty Client ID requires a clean session.""")) |
66 else: |
66 else: |
67 enable = True |
67 enable = True |
68 |
68 |
69 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
69 self.buttonBox.button( |
|
70 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
70 |
71 |
71 @pyqtSlot() |
72 @pyqtSlot() |
72 def on_generateIdButton_clicked(self): |
73 def on_generateIdButton_clicked(self): |
73 """ |
74 """ |
74 Private slot to generate a client ID. |
75 Private slot to generate a client ID. |
75 """ |
76 """ |
76 uuid = QUuid.createUuid() |
77 uuid = QUuid.createUuid() |
77 self.clientIdEdit.setText(uuid.toString(QUuid.WithoutBraces)) |
78 self.clientIdEdit.setText( |
|
79 uuid.toString(QUuid.StringFormat.WithoutBraces)) |
78 |
80 |
79 @pyqtSlot(QAbstractButton) |
81 @pyqtSlot(QAbstractButton) |
80 def on_buttonBox_clicked(self, button): |
82 def on_buttonBox_clicked(self, button): |
81 """ |
83 """ |
82 Private slot to handle the press of a button box button. |
84 Private slot to handle the press of a button box button. |
83 |
85 |
84 @param button button that has been pressed |
86 @param button button that has been pressed |
85 @type QAbstractButton |
87 @type QAbstractButton |
86 """ |
88 """ |
87 if button == self.buttonBox.button(QDialogButtonBox.RestoreDefaults): |
89 if button == self.buttonBox.button( |
|
90 QDialogButtonBox.StandardButton.RestoreDefaults |
|
91 ): |
88 self.__populateDefaults(options=None) |
92 self.__populateDefaults(options=None) |
89 |
93 |
90 def __populateDefaults(self, options=None): |
94 def __populateDefaults(self, options=None): |
91 """ |
95 """ |
92 Private method to populate the dialog. |
96 Private method to populate the dialog. |
130 |
134 |
131 @return dictionary containing the connection options. It has the keys |
135 @return dictionary containing the connection options. It has the keys |
132 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
136 "ClientId", "Keepalive", "CleanSession", "Username", "Password", |
133 "WillTopic", "WillMessage", "WillQos", "WillRetain", "TlsEnable", |
137 "WillTopic", "WillMessage", "WillQos", "WillRetain", "TlsEnable", |
134 "TlsCaCert", "ConnectionTimeout". |
138 "TlsCaCert", "ConnectionTimeout". |
135 @rtype tuple of (int, dict) |
139 @rtype dict |
136 """ |
140 """ |
137 return { |
141 return { |
138 "ClientId": self.clientIdEdit.text(), |
142 "ClientId": self.clientIdEdit.text(), |
139 "ConnectionTimeout": self.connectionTimeoutSpinBox.value(), |
143 "ConnectionTimeout": self.connectionTimeoutSpinBox.value(), |
140 "Keepalive": self.keepaliveSpinBox.value(), |
144 "Keepalive": self.keepaliveSpinBox.value(), |