9 ui->listWidget->clear();
11 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
19 ui->lineEditPort->setValidator(
new QIntValidator);
21 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
23 static QString uuid = QString(
"Plotjuggler-") + QString::number(rand());
26 restoreGeometry(settings.value(
"MosquittoMQTT::geometry").toByteArray());
28 QString host = settings.value(
"MosquittoMQTT::host").toString();
29 ui->lineEditHost->setText(host);
31 int port = settings.value(
"MosquittoMQTT::port", 1883).toInt();
32 ui->lineEditPort->setText(QString::number(port));
34 int qos = settings.value(
"MosquittoMQTT::qos", 0).toInt();
35 ui->comboBoxQoS->setCurrentIndex(qos);
37 int protocol_mqtt = settings.value(
"MosquittoMQTT::protocol_version").toInt();
38 ui->comboBoxVersion->setCurrentIndex(protocol_mqtt);
40 QString topic_filter = settings.value(
"MosquittoMQTT::filter").toString();
41 ui->lineEditTopicFilter->setText(topic_filter);
43 QString username = settings.value(
"MosquittoMQTT::username",
"").toString();
44 ui->lineEditUsername->setText(username);
46 QString password = settings.value(
"MosquittoMQTT::password",
"").toString();
47 ui->lineEditPassword->setText(password);
50 settings.value(
"MosquittoMQTT::server_certificate",
"").toString();
54 ui->buttonEraseServerCertificate->setEnabled(
true);
58 settings.value(
"MosquittoMQTT::client_certificate",
"").toString();
62 ui->buttonEraseClientCertificate->setEnabled(
true);
69 ui->buttonErasePrivateKey->setEnabled(
true);
72 bool enable_tls = settings.value(
"MosquittoMQTT::enable_tls",
false).toBool();
73 ui->checkBoxSecurity->setChecked(enable_tls);
77 QString theme = settings.value(
"StyleSheet::theme",
"light").toString();
79 const QPixmap& icon_pixmap =
LoadSvg(
":/resources/svg/import.svg", theme);
80 ui->buttonLoadServerCertificate->setIcon(icon_pixmap);
81 ui->buttonLoadClientCertificate->setIcon(icon_pixmap);
82 ui->buttonLoadPrivateKey->setIcon(icon_pixmap);
88 connect(
ui->listWidget, &QListWidget::itemSelectionChanged,
this,
91 connect(
ui->buttonLoadServerCertificate, &QPushButton::clicked,
this,
94 connect(
ui->buttonLoadClientCertificate, &QPushButton::clicked,
this,
97 connect(
ui->buttonLoadPrivateKey, &QPushButton::clicked,
this,
100 connect(
ui->buttonEraseServerCertificate, &QPushButton::clicked,
this, [
this]() {
101 ui->buttonEraseServerCertificate->setEnabled(false);
102 ui->labelServerCertificate->setText(
"");
103 _server_certificate_file.clear();
106 connect(
ui->buttonEraseClientCertificate, &QPushButton::clicked,
this, [
this]() {
107 ui->buttonEraseClientCertificate->setEnabled(false);
108 ui->labelClientCertificate->setText(
"");
109 _client_certificate_file.clear();
112 connect(
ui->buttonErasePrivateKey, &QPushButton::clicked,
this, [
this]() {
113 ui->buttonErasePrivateKey->setEnabled(false);
114 ui->labelPrivateKey->setText(
"");
115 _private_key_file.clear();
119 onConnectionClosed();
120 QMessageBox::warning(this,
"Connection Lost",
121 "Client disconnected. Maybe a problem with autentication?");
128 settings.setValue(
"MosquittoMQTT::geometry", this->saveGeometry());
131 settings.setValue(
"MosquittoMQTT::host",
ui->lineEditHost->text());
132 settings.setValue(
"MosquittoMQTT::port",
ui->lineEditPort->text().toInt());
133 settings.setValue(
"MosquittoMQTT::filter",
ui->lineEditTopicFilter->text());
134 settings.setValue(
"MosquittoMQTT::username",
ui->lineEditPassword->text());
135 settings.setValue(
"MosquittoMQTT::password",
ui->lineEditUsername->text());
136 settings.setValue(
"MosquittoMQTT::protocol_version",
137 ui->comboBoxVersion->currentIndex());
138 settings.setValue(
"MosquittoMQTT::qos",
ui->comboBoxQoS->currentIndex());
139 settings.setValue(
"MosquittoMQTT::serialization_protocol",
140 ui->comboBoxProtocol->currentText());
144 settings.setValue(
"MosquittoMQTT::enable_tls",
ui->checkBoxSecurity->isChecked());
149 while (
ui->layoutOptions->count() > 0)
151 auto item =
ui->layoutOptions->takeAt(0);
152 item->widget()->setParent(
nullptr);
170 config.
host =
ui->lineEditHost->text().toStdString();
171 config.
port =
ui->lineEditPort->text().toInt();
173 config.
topics.push_back(
ui->lineEditTopicFilter->text().toStdString());
174 config.
username =
ui->lineEditUsername->text().toStdString();
175 config.
password =
ui->lineEditPassword->text().toStdString();
176 config.
qos =
ui->comboBoxQoS->currentIndex();
185 if (
ui->checkBoxSecurity->isChecked())
201 auto topic_list =
_client->getTopicList();
203 bool changed =
ui->listWidget->count() != topic_list.size();
206 for (
const auto&
topic : topic_list)
218 ui->listWidget->clear();
219 for (
const auto&
topic : topic_list)
221 ui->listWidget->addItem(QString::fromStdString(
topic));
224 ui->listWidget->sortItems();
227 if (
_client->isConnected() ==
false)
235 bool selected =
ui->listWidget->selectedItems().count() > 0;
236 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(selected);
241 ui->connectionFrame->setEnabled(!connected);
242 ui->buttonConnect->setText(connected ?
"Disconnect" :
"Connect");
243 ui->lineEditTopicFilter->setEnabled(!connected);
244 ui->listWidget->setEnabled(connected);
251 settings.value(
"MQTT_Dialog.loadDirectory", QDir::currentPath()).toString();
253 QString filename = QFileDialog::getOpenFileName(
this,
"Select Server Certificate",
254 directory, tr(
"CRT (*.crt)"));
256 if (!filename.isEmpty())
259 directory = QFileInfo(filename).absolutePath();
260 settings.setValue(
"MQTT_Dialog.loadDirectory", directory);
262 ui->labelServerCertificate->setText(QFileInfo(filename).fileName());
263 ui->buttonEraseServerCertificate->setEnabled(
true);
271 settings.value(
"MQTT_Dialog.loadDirectory", QDir::currentPath()).toString();
273 QString filename = QFileDialog::getOpenFileName(
this,
"Select Client Certificate",
274 directory, tr(
"CRT (*.crt)"));
276 if (!filename.isEmpty())
279 directory = QFileInfo(filename).absolutePath();
280 settings.setValue(
"MQTT_Dialog.loadDirectory", directory);
282 ui->labelClientCertificate->setText(QFileInfo(filename).fileName());
283 ui->buttonEraseClientCertificate->setEnabled(
true);
291 settings.value(
"MQTT_Dialog.loadDirectory", QDir::currentPath()).toString();
293 QString filename = QFileDialog::getOpenFileName(
this,
"Select PrivateKey", directory,
296 if (!filename.isEmpty())
299 directory = QFileInfo(filename).absolutePath();
300 settings.setValue(
"MQTT_Dialog.loadDirectory", directory);
302 ui->labelPrivateKey->setText(QFileInfo(filename).fileName());
303 ui->buttonErasePrivateKey->setEnabled(
true);