File indexing completed on 2024-07-21 07:58:04

0001 /*
0002     SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "infinibandwidget.h"
0008 #include "ui_infiniband.h"
0009 #include "uiutils.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 #include <NetworkManagerQt/InfinibandSetting>
0014 #include <NetworkManagerQt/Utils>
0015 
0016 InfinibandWidget::InfinibandWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f)
0017     : SettingWidget(setting, parent, f)
0018     , m_ui(new Ui::InfinibandWidget)
0019 {
0020     m_ui->setupUi(this);
0021 
0022     m_ui->transport->addItem(i18nc("infiniband transport mode", "Datagram"), NetworkManager::InfinibandSetting::Datagram);
0023     m_ui->transport->addItem(i18nc("infiniband transport mode", "Connected"), NetworkManager::InfinibandSetting::Connected);
0024     m_ui->transport->setCurrentIndex(0);
0025 
0026     // Connect for setting check
0027     watchChangedSetting();
0028 
0029     // Connect for validity check
0030     connect(m_ui->macAddress, &HwAddrComboBox::hwAddressChanged, this, &InfinibandWidget::slotWidgetChanged);
0031 
0032     KAcceleratorManager::manage(this);
0033 
0034     if (setting) {
0035         loadConfig(setting);
0036     }
0037 }
0038 
0039 InfinibandWidget::~InfinibandWidget()
0040 {
0041     delete m_ui;
0042 }
0043 
0044 void InfinibandWidget::loadConfig(const NetworkManager::Setting::Ptr &setting)
0045 {
0046     NetworkManager::InfinibandSetting::Ptr infinibandSetting = setting.staticCast<NetworkManager::InfinibandSetting>();
0047 
0048     if (infinibandSetting->transportMode() != NetworkManager::InfinibandSetting::Unknown) {
0049         if (infinibandSetting->transportMode() == NetworkManager::InfinibandSetting::Datagram) {
0050             m_ui->transport->setCurrentIndex(0);
0051         } else if (infinibandSetting->transportMode() == NetworkManager::InfinibandSetting::Connected) {
0052             m_ui->transport->setCurrentIndex(1);
0053         }
0054     }
0055     m_ui->macAddress->init(NetworkManager::Device::InfiniBand, NetworkManager::macAddressAsString(infinibandSetting->macAddress()));
0056     if (infinibandSetting->mtu()) {
0057         m_ui->mtu->setValue(infinibandSetting->mtu());
0058     }
0059 }
0060 
0061 QVariantMap InfinibandWidget::setting() const
0062 {
0063     NetworkManager::InfinibandSetting setting;
0064     if (m_ui->transport->currentIndex() == 0) {
0065         setting.setTransportMode(NetworkManager::InfinibandSetting::Datagram);
0066     } else {
0067         setting.setTransportMode(NetworkManager::InfinibandSetting::Connected);
0068     }
0069     setting.setMacAddress(NetworkManager::macAddressFromString(m_ui->macAddress->hwAddress()));
0070     if (m_ui->mtu->value()) {
0071         setting.setMtu(m_ui->mtu->value());
0072     }
0073 
0074     return setting.toMap();
0075 }
0076 
0077 bool InfinibandWidget::isValid() const
0078 {
0079     return m_ui->macAddress->isValid();
0080 }
0081 
0082 #include "moc_infinibandwidget.cpp"