File indexing completed on 2024-12-01 08:10:01
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 "btwidget.h" 0008 #include "ui_bt.h" 0009 0010 #include <KLocalizedString> 0011 0012 #include <NetworkManagerQt/Utils> 0013 0014 BtWidget::BtWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f) 0015 : SettingWidget(setting, parent, f) 0016 , m_ui(new Ui::BtWidget) 0017 { 0018 m_ui->setupUi(this); 0019 0020 m_ui->type->addItem(i18n("DUN (dial up networking)"), NetworkManager::BluetoothSetting::Dun); 0021 m_ui->type->addItem(i18n("PAN (personal area network)"), NetworkManager::BluetoothSetting::Panu); 0022 0023 m_ui->type->setEnabled(false); 0024 0025 // Connect for setting check 0026 watchChangedSetting(); 0027 0028 // Connect for validity check 0029 connect(m_ui->bdaddr, &HwAddrComboBox::hwAddressChanged, this, &BtWidget::slotWidgetChanged); 0030 0031 KAcceleratorManager::manage(this); 0032 0033 if (setting) { 0034 loadConfig(setting); 0035 } 0036 } 0037 0038 BtWidget::~BtWidget() 0039 { 0040 delete m_ui; 0041 } 0042 0043 void BtWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) 0044 { 0045 NetworkManager::BluetoothSetting::Ptr btSetting = setting.staticCast<NetworkManager::BluetoothSetting>(); 0046 0047 m_ui->bdaddr->init(NetworkManager::Device::Bluetooth, NetworkManager::macAddressAsString(btSetting->bluetoothAddress())); 0048 m_ui->type->setCurrentIndex(m_ui->type->findData(btSetting->profileType())); 0049 } 0050 0051 QVariantMap BtWidget::setting() const 0052 { 0053 NetworkManager::BluetoothSetting btSetting; 0054 0055 btSetting.setBluetoothAddress(NetworkManager::macAddressFromString(m_ui->bdaddr->hwAddress())); 0056 btSetting.setProfileType(static_cast<NetworkManager::BluetoothSetting::ProfileType>(m_ui->type->itemData(m_ui->type->currentIndex()).toInt())); 0057 0058 return btSetting.toMap(); 0059 } 0060 0061 bool BtWidget::isValid() const 0062 { 0063 return m_ui->bdaddr->isValid(); 0064 } 0065 0066 #include "moc_btwidget.cpp"