summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-connection_setting_serial.cpp
blob: 788e7ebebe8fd2958cadc7b90e6fe9986ec03358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/***************************************************************************
 *
 * knetworkmanager-connection_setting_serial.cpp - A NetworkManager frontend for KDE
 *
 * Copyright (C) 2005, 2006 Novell, Inc.
 *
 * Author: Helmut Schaa <[email protected]>, <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

/* qt headers */
#include <tqhostaddress.h>
#include <tqvariant.h>

/* kde headers */
#include <kdebug.h>
#include <tdelocale.h>

/* TQT_DBus headers*/
#include <tqdbusdata.h>
#include <tqdbusdatamap.h>

/* knetworkmanager headers */
#include "knetworkmanager.h"
#include "knetworkmanager-connection.h"
#include "knetworkmanager-connection_setting_serial.h"

using namespace ConnectionSettings;

/*
	class Serial
*/
Serial::Serial(Connection* conn)
	: ConnectionSetting(conn, NM_SETTING_SERIAL_SETTING_NAME),
	_baud( 115200 ),
	_bits( 8 ),
	_parity( PARITY_NONE ),
	_stopBits( 1 ),
    _sendDelay( 0 )
{
}

void Serial::setBaud(TQ_UINT32 baud)
{
	_baud = baud;
}

TQ_UINT32 Serial::getBaud() const
{
	return _baud;
}

void Serial::setBits(TQ_UINT32 bits)
{
	if (bits >= 5 && bits <= 8)
		_bits = bits;
	else
		kdWarning() << k_funcinfo << "bits property not accepted" << endl;
}

TQ_UINT32 Serial::getBits() const
{
	return _bits;
}

void Serial::setParity(PARITY_MODE parity)
{
	_parity = parity;
}

Serial::PARITY_MODE Serial::getParity() const
{
	return _parity;
}

void Serial::setStopBits(TQ_UINT32 stopBits)
{
	if (stopBits >= 1 && stopBits <= 2)
		_stopBits = stopBits;
	else
		kdWarning() << k_funcinfo << "stopbits property: wrong value" << endl;
}

TQ_UINT32 Serial::getStopBits() const
{
	return _stopBits;
}

void Serial::setSendDelay(TQ_UINT64 delay)
{
	_sendDelay = delay;
}

TQ_UINT64 Serial::getSendDelay() const
{
	return _sendDelay;
}

bool
Serial::isValid() const
{
	// serial setting without ppp setting is not valid
	if (!(getConnection()->getSetting(NM_SETTING_PPP_SETTING_NAME)))
		return false;
	return true;
}

SettingsMap
Serial::toMap() const
{
	SettingsMap map;

	map.insert(NM_SETTING_SERIAL_BAUD, TQT_DBusData::fromUInt32(_baud));
	map.insert(NM_SETTING_SERIAL_BITS, TQT_DBusData::fromUInt32(_bits));

	if (_parity == PARITY_NONE)
		map.insert(NM_SETTING_SERIAL_PARITY, TQT_DBusData::fromByte('n'));
	else if (_parity == PARITY_EVEN)
		map.insert(NM_SETTING_SERIAL_PARITY, TQT_DBusData::fromByte('e'));
	else if (_parity == PARITY_ODD)
		map.insert(NM_SETTING_SERIAL_PARITY, TQT_DBusData::fromByte('o'));

	map.insert(NM_SETTING_SERIAL_STOPBITS, TQT_DBusData::fromUInt32(_stopBits));
	map.insert(NM_SETTING_SERIAL_SEND_DELAY, TQT_DBusData::fromUInt64(_sendDelay));
	
	return map;
}

void
Serial::fromMap(const SettingsMap& map)
{
	for (SettingsMap::ConstIterator it = map.begin(); it != map.end(); ++it)
	{
		if (it.key() == NM_SETTING_SERIAL_BAUD)
			setBaud(it.data().toUInt32());
		else if (it.key() == NM_SETTING_SERIAL_BITS)
			setBits(it.data().toUInt32());
		else if (it.key() == NM_SETTING_SERIAL_PARITY)
                {
			if (it.data().toByte() == 'n')
				_parity = PARITY_NONE;
			else if (it.data().toByte() == 'e')
				_parity = PARITY_EVEN;
			else if (it.data().toByte() == 'o')
				_parity = PARITY_ODD;
                }
		else if (it.key() == NM_SETTING_SERIAL_STOPBITS)
			setStopBits(it.data().toUInt32());
		else if (it.key() == NM_SETTING_SERIAL_SEND_DELAY)
			setSendDelay(it.data().toUInt64());
		else
			kdWarning() << k_funcinfo << " Unknown setting: " << it.key() << endl;
	}
}