NetworkManagerQt

serialsetting.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 "serialsetting.h"
8#include "serialsetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::SerialSettingPrivate::SerialSettingPrivate()
13 : name(NM_SETTING_SERIAL_SETTING_NAME)
14 , baud(57600)
15 , bits(8)
16 , parity(SerialSetting::NoParity)
17 , stopbits(1)
18 , sendDelay(0)
19{
20}
21
22NetworkManager::SerialSetting::SerialSetting()
23 : Setting(Setting::Serial)
24 , d_ptr(new SerialSettingPrivate())
25{
26}
27
28NetworkManager::SerialSetting::SerialSetting(const Ptr &other)
29 : Setting(other)
30 , d_ptr(new SerialSettingPrivate())
31{
32 setBaud(other->baud());
33 setBits(other->bits());
34 setParity(other->parity());
35 setStopbits(other->stopbits());
36 setSendDelay(other->sendDelay());
37}
38
39NetworkManager::SerialSetting::~SerialSetting()
40{
41 delete d_ptr;
42}
43
45{
46 Q_D(const SerialSetting);
47
48 return d->name;
49}
50
51void NetworkManager::SerialSetting::setBaud(quint32 speed)
52{
54
55 d->baud = speed;
56}
57
58quint32 NetworkManager::SerialSetting::baud() const
59{
60 Q_D(const SerialSetting);
61
62 return d->baud;
63}
64
65void NetworkManager::SerialSetting::setBits(quint32 byteWidgh)
66{
67 Q_D(SerialSetting);
68
69 d->bits = byteWidgh;
70}
71
72quint32 NetworkManager::SerialSetting::bits() const
73{
74 Q_D(const SerialSetting);
75
76 return d->bits;
77}
78
79void NetworkManager::SerialSetting::setParity(NetworkManager::SerialSetting::Parity paritysetting)
80{
81 Q_D(SerialSetting);
82
83 d->parity = paritysetting;
84}
85
86NetworkManager::SerialSetting::Parity NetworkManager::SerialSetting::parity() const
87{
88 Q_D(const SerialSetting);
89
90 return d->parity;
91}
92
93void NetworkManager::SerialSetting::setStopbits(quint32 number)
94{
95 Q_D(SerialSetting);
96
97 d->stopbits = number;
98}
99
100quint32 NetworkManager::SerialSetting::stopbits() const
101{
102 Q_D(const SerialSetting);
103
104 return d->stopbits;
105}
106
107void NetworkManager::SerialSetting::setSendDelay(quint64 delay)
108{
109 Q_D(SerialSetting);
110
111 d->sendDelay = delay;
112}
113
114quint64 NetworkManager::SerialSetting::sendDelay() const
115{
116 Q_D(const SerialSetting);
117
118 return d->sendDelay;
119}
120
121void NetworkManager::SerialSetting::fromMap(const QVariantMap &setting)
122{
123 if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BAUD))) {
124 setBaud(setting.value(QLatin1String(NM_SETTING_SERIAL_BAUD)).toUInt());
125 }
126
127 if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BITS))) {
128 setBits(setting.value(QLatin1String(NM_SETTING_SERIAL_BITS)).toUInt());
129 }
130
131 if (setting.contains(QLatin1String(NM_SETTING_SERIAL_PARITY))) {
132 QChar character = setting.value(QLatin1String(NM_SETTING_SERIAL_PARITY)).toChar();
133
134 if (character == 'n') {
135 setParity(NoParity);
136 } else if (character == 'E') {
137 setParity(EvenParity);
138 } else if (character == 'o') {
139 setParity(OddParity);
140 }
141 }
142
143 if (setting.contains(QLatin1String(NM_SETTING_SERIAL_STOPBITS))) {
144 setStopbits(setting.value(QLatin1String(NM_SETTING_SERIAL_STOPBITS)).toUInt());
145 }
146
147 if (setting.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) {
148 setSendDelay((Setting::SecretFlagType)setting.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).toULongLong());
149 }
150}
151
153{
154 QVariantMap setting;
155
156 if (baud() != 57600) {
157 setting.insert(QLatin1String(NM_SETTING_SERIAL_BAUD), baud());
158 }
159
160 if (bits() != 8) {
161 setting.insert(QLatin1String(NM_SETTING_SERIAL_BITS), bits());
162 }
163
164 if (parity() != NoParity) {
165 if (parity() == EvenParity) {
166 setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), QChar('E'));
167 } else if (parity() == OddParity) {
168 setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), QChar('o'));
169 }
170 }
171
172 if (stopbits() != 1) {
173 setting.insert(QLatin1String(NM_SETTING_SERIAL_STOPBITS), stopbits());
174 }
175
176 if (sendDelay()) {
177 setting.insert(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY), sendDelay());
178 }
179
180 return setting;
181}
182
183QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::SerialSetting &setting)
184{
185 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
186 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
187
188 dbg.nospace() << NM_SETTING_SERIAL_BAUD << ": " << setting.baud() << '\n';
189 dbg.nospace() << NM_SETTING_SERIAL_BITS << ": " << setting.bits() << '\n';
190 dbg.nospace() << NM_SETTING_SERIAL_PARITY << ": " << setting.parity() << '\n';
191 dbg.nospace() << NM_SETTING_SERIAL_STOPBITS << ": " << setting.stopbits() << '\n';
192 dbg.nospace() << NM_SETTING_SERIAL_SEND_DELAY << ": " << setting.sendDelay() << '\n';
193
194 return dbg.maybeSpace();
195}
Represents serial setting.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:59:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.