NetworkManagerQt

bluetoothsetting.cpp
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
38{
39 Q_D(const BluetoothSetting);
40
41 return d->name;
42}
43
44void NetworkManager::BluetoothSetting::setBluetoothAddress(const QByteArray &address)
45{
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(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR))) {
75 setBluetoothAddress(setting.value(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR)).toByteArray());
76 }
77
78 if (setting.contains(QLatin1String(NM_SETTING_BLUETOOTH_TYPE))) {
79 const QString type = setting.value(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
90{
91 QVariantMap setting;
92
93 if (!bluetoothAddress().isEmpty()) {
94 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_BDADDR), bluetoothAddress());
95 }
96
97 switch (profileType()) {
98 case Dun:
99 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), QLatin1String(NM_SETTING_BLUETOOTH_TYPE_DUN));
100 break;
101 case Panu:
102 setting.insert(QLatin1String(NM_SETTING_BLUETOOTH_TYPE), 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(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}
Represents bluetooth setting.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
Type type(const QSqlDatabase &db)
@ Unknown
the networking system is not active or unable to report its status - proceed with caution
Definition manager.h:33
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.