! * \brief Checks whether every connection's settings are alright or not */
| 524 | * \brief Checks whether every connection's settings are alright or not |
| 525 | */ |
| 526 | bool MQTTConnectionManagerWidget::checkConnections() { |
| 527 | if (m_connections.isEmpty()) |
| 528 | return true; |
| 529 | |
| 530 | bool connectionsOk = true; |
| 531 | |
| 532 | for (int i = 0; i < m_connections.size(); ++i) { |
| 533 | auto& c1 = m_connections[i]; |
| 534 | auto equalNames = ui.lwConnections->findItems(c1.name, Qt::MatchExactly); |
| 535 | bool nameOK = (!c1.name.isEmpty()) && (equalNames.size() == 1); |
| 536 | |
| 537 | bool authenticationUsed = c1.useAuthentication; |
| 538 | bool idUsed = c1.useID; |
| 539 | bool authenticationFilled = !c1.userName.isEmpty() && !c1.password.isEmpty(); |
| 540 | bool idFilled = !c1.clientID.isEmpty(); |
| 541 | bool authenticationOK = (!authenticationUsed || authenticationFilled); |
| 542 | bool idOK = (!idUsed || idFilled); |
| 543 | |
| 544 | bool uniqueHost = true; |
| 545 | for (int j = 0; j < m_connections.size(); ++j) { |
| 546 | if (i == j) |
| 547 | continue; |
| 548 | auto& c2 = m_connections[j]; |
| 549 | |
| 550 | if (c2.hostName == c1.hostName && c2.port == c1.port) { |
| 551 | uniqueHost = false; |
| 552 | break; |
| 553 | } |
| 554 | } |
| 555 | bool hostOK = (!c1.hostName.isEmpty()) && uniqueHost; |
| 556 | bool allOk = authenticationOK && idOK && hostOK && nameOK; |
| 557 | |
| 558 | if (!allOk) { |
| 559 | connectionsOk = false; |
| 560 | SET_WARNING_BACKGROUND(ui.lwConnections->item(i)) |
| 561 | } else |
| 562 | ui.lwConnections->item(i)->setBackground(QBrush()); |
| 563 | } |
| 564 | return connectionsOk; |
| 565 | } |
| 566 | |
| 567 | /*! |
| 568 | * \brief Provides a sample host name, which has to be changed before use. |