MCPcopy Create free account
hub / github.com/KDE/labplot / checkConnections

Method checkConnections

src/frontend/datasources/MQTTConnectionManagerWidget.cpp:526–565  ·  view source on GitHub ↗

! * \brief Checks whether every connection's settings are alright or not */

Source from the content-addressed store, hash-verified

524 * \brief Checks whether every connection's settings are alright or not
525 */
526bool 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.

Callers 1

changedMethod · 0.80

Calls 3

QBrushClass · 0.50
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected