1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "bluetoothsetting.h"
8#include "bluetoothsetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::BluetoothSettingPrivate::BluetoothSettingPrivate()
13 : name(NM_SETTING_BLUETOOTH_SETTING_NAME)
14 , profileType(BluetoothSetting::Unknown)
15{
16}
17
18NetworkManager::BluetoothSetting::BluetoothSetting()
19 : Setting(Setting::Bluetooth)
20 , d_ptr(new BluetoothSettingPrivate())
21{
22}
23
24NetworkManager::BluetoothSetting::BluetoothSetting(const Ptr &other)
25 : Setting(other)
26 , d_ptr(new BluetoothSettingPrivate())
27{
28 setBluetoothAddress(other->bluetoothAddress());
29 setProfileType(other->profileType());
30}
31
32NetworkManager::BluetoothSetting::~BluetoothSetting()
33{
34 delete d_ptr;
35}
36
37QString NetworkManager::BluetoothSetting::name() const
38{
39 Q_D(const BluetoothSetting);
40
41 return d->name;
42}
43
44void NetworkManager::BluetoothSetting::setBluetoothAddress(const QByteArray &address)
45{
46 Q_D(BluetoothSetting);
47
48 d->bdaddr = address;
49}
50
51QByteArray NetworkManager::BluetoothSetting::bluetoothAddress() const
52{
53 Q_D(const BluetoothSetting);
54
55 return d->bdaddr;
56}
57
58void NetworkManager::BluetoothSetting::setProfileType(NetworkManager::BluetoothSetting::ProfileType type)
59{
60 Q_D(BluetoothSetting);
61
62 d->profileType = type;
63}
64
65NetworkManager::BluetoothSetting::ProfileType NetworkManager::BluetoothSetting::profileType() const
66{
67 Q_D(const BluetoothSetting);
68
69 return d->profileType;
70}
71
72void NetworkManager::BluetoothSetting::fromMap(const QVariantMap &setting)
73{
74 if (setting.contains(key: QLatin1String(NM_SETTING_BLUETOOTH_BDADDR))) {
75 setBluetoothAddress(setting.value(key: QLatin1String(NM_SETTING_BLUETOOTH_BDADDR)).toByteArray());
76 }
77
78 if (setting.contains(key: QLatin1String(NM_SETTING_BLUETOOTH_TYPE))) {
79 const QString type = setting.value(key: QLatin1String(NM_SETTING_BLUETOOTH_TYPE)).toString();
80
81 if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN)) {
82 setProfileType(Dun);
83 } else if (type == QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU)) {
84 setProfileType(Panu);
85 }
86 }
87}
88
89QVariantMap NetworkManager::BluetoothSetting::toMap() const
90{
91 QVariantMap setting;
92
93 if (!bluetoothAddress().isEmpty()) {
94 setting.insert(key: QLatin1String(NM_SETTING_BLUETOOTH_BDADDR), value: bluetoothAddress());
95 }
96
97 switch (profileType()) {
98 case Dun:
99 setting.insert(key: QLatin1String(NM_SETTING_BLUETOOTH_TYPE), value: QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN));
100 break;
101 case Panu:
102 setting.insert(key: QLatin1String(NM_SETTING_BLUETOOTH_TYPE), value: QLatin1String(NM_SETTING_BLUETOOTH_TYPE_PANU));
103 break;
104 case Unknown:
105 break;
106 }
107
108 return setting;
109}
110
111QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::BluetoothSetting &setting)
112{
113 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
114 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
115
116 dbg.nospace() << NM_SETTING_BLUETOOTH_BDADDR << ": " << setting.bluetoothAddress() << '\n';
117 dbg.nospace() << NM_SETTING_BLUETOOTH_TYPE << ": " << setting.profileType() << '\n';
118
119 return dbg.maybeSpace();
120}
121

source code of networkmanager-qt/src/settings/bluetoothsetting.cpp