File indexing completed on 2024-04-28 07:49:04
0001 /* 0002 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@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 "bluetoothsetting.h" 0008 #include "bluetoothsetting_p.h" 0009 0010 #include <QDebug> 0011 0012 NetworkManager::BluetoothSettingPrivate::BluetoothSettingPrivate() 0013 : name(NM_SETTING_BLUETOOTH_SETTING_NAME) 0014 , profileType(BluetoothSetting::Unknown) 0015 { 0016 } 0017 0018 NetworkManager::BluetoothSetting::BluetoothSetting() 0019 : Setting(Setting::Bluetooth) 0020 , d_ptr(new BluetoothSettingPrivate()) 0021 { 0022 } 0023 0024 NetworkManager::BluetoothSetting::BluetoothSetting(const Ptr &other) 0025 : Setting(other) 0026 , d_ptr(new BluetoothSettingPrivate()) 0027 { 0028 setBluetoothAddress(other->bluetoothAddress()); 0029 setProfileType(other->profileType()); 0030 } 0031 0032 NetworkManager::BluetoothSetting::~BluetoothSetting() 0033 { 0034 delete d_ptr; 0035 } 0036 0037 QString NetworkManager::BluetoothSetting::name() const 0038 { 0039 Q_D(const BluetoothSetting); 0040 0041 return d->name; 0042 } 0043 0044 void NetworkManager::BluetoothSetting::setBluetoothAddress(const QByteArray &address) 0045 { 0046 Q_D(BluetoothSetting); 0047 0048 d->bdaddr = address; 0049 } 0050 0051 QByteArray NetworkManager::BluetoothSetting::bluetoothAddress() const 0052 { 0053 Q_D(const BluetoothSetting); 0054 0055 return d->bdaddr; 0056 } 0057 0058 void NetworkManager::BluetoothSetting::setProfileType(NetworkManager::BluetoothSetting::ProfileType type) 0059 { 0060 Q_D(BluetoothSetting); 0061 0062 d->profileType = type; 0063 } 0064 0065 NetworkManager::BluetoothSetting::ProfileType NetworkManager::BluetoothSetting::profileType() const 0066 { 0067 Q_D(const BluetoothSetting); 0068 0069 return d->profileType; 0070 } 0071 0072 void NetworkManager::BluetoothSetting::fromMap(const QVariantMap &setting) 0073 { 0074 if (setting.contains(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR))) { 0075 setBluetoothAddress(setting.value(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR)).toByteArray()); 0076 } 0077 0078 if (setting.contains(QLatin1String(NM_SETTING_BLUETOOTH_TYPE))) { 0079 const QString type = setting.value(QLatin1String(NM_SETTING_BLUETOOTH_TYPE)).toString(); 0080 0081 if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN)) { 0082 setProfileType(Dun); 0083 } else if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU)) { 0084 setProfileType(Panu); 0085 } 0086 } 0087 } 0088 0089 QVariantMap NetworkManager::BluetoothSetting::toMap() const 0090 { 0091 QVariantMap setting; 0092 0093 if (!bluetoothAddress().isEmpty()) { 0094 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR), bluetoothAddress()); 0095 } 0096 0097 switch (profileType()) { 0098 case Dun: 0099 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN)); 0100 break; 0101 case Panu: 0102 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU)); 0103 break; 0104 case Unknown: 0105 break; 0106 } 0107 0108 return setting; 0109 } 0110 0111 QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BluetoothSetting &setting) 0112 { 0113 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; 0114 dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; 0115 0116 dbg.nospace() << NM_SETTING_BLUETOOTH_BDADDR << ": " << setting.bluetoothAddress() << '\n'; 0117 dbg.nospace() << NM_SETTING_BLUETOOTH_TYPE << ": " << setting.profileType() << '\n'; 0118 0119 return dbg.maybeSpace(); 0120 }