summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-accesspoint.cpp
blob: 0bd5528d03bac0705fcf0052c79364f6bb505d4b (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/***************************************************************************
 *
 * knetworkmanager-accesspoint.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
 *
 **************************************************************************/

// TQt
#include <tqguardedptr.h>

// TQT_DBus includes
#include <tqdbuserror.h>
#include <tqdbusconnection.h>
#include <tqdbuserror.h>

// NM includes
#include <NetworkManager.h>

// KNM includes
#include "knetworkmanager.h"
#include "knetworkmanager-accesspoint.h"
#include "dbus/accesspointproxy.h"

class AccessPointPrivate
{
public:
	AccessPointPrivate(TQString objpath = TQString(), const DBus::AccessPointProxy* proxy = NULL)
		: nmAccessPoint(proxy)
		, objPath(objpath)
	{
	}

	~AccessPointPrivate() { }

	// pointer to the shared DBus proxy
	TQGuardedPtr<const DBus::AccessPointProxy> nmAccessPoint;
	// DBus object path
	TQString objPath;

	// Properties
	TQ_UINT32 flags;
	TQ_UINT32 wpaFlags;
	TQ_UINT32 rsnFlags;
	TQValueList<TQ_UINT8> ssid;
	TQ_UINT32 freq;
	TQString  hwAddress;
	TQ_INT32  mode;
	TQ_UINT32 rate;
	TQ_UINT8  strength;
};

TQ_UINT32 AccessPoint::getFlags() const
{
	return d->flags;
}

TQ_UINT32 AccessPoint::getWpaFlags() const
{
	return d->wpaFlags;
}

TQ_UINT32 AccessPoint::getRsnFlags() const
{
	return d->rsnFlags;
}

TQValueList<TQ_UINT8> AccessPoint::getSsid() const
{
	return d->ssid;
}

TQ_UINT32 AccessPoint::getFrequency() const
{
	return d->freq;
}

TQString AccessPoint::getHwAddress() const
{
	return d->hwAddress;
}

TQ_INT32 AccessPoint::getMode() const
{
	return d->mode;
}

TQ_UINT32 AccessPoint::getRate() const
{
	return d->rate;
}

TQ_UINT8 AccessPoint::getStrength() const
{
	return d->strength;
}

const TQByteArray AccessPoint::getSsidByteArray() const
{
	// FIXME: Wow, thats ugly
	TQValueList<TQ_UINT8> ssid = d->ssid;
	TQByteArray ret_ssid(ssid.count());
	TQByteArray::Iterator byteit = ret_ssid.begin();
	for (TQValueList<TQ_UINT8>::iterator it = ssid.begin(); it != ssid.end(); ++it)
	{
		(*byteit) = (*it);
		++byteit;
	}
	return ret_ssid;
}

TQString AccessPoint::getDisplaySsid() const
{
	return TQString(getSsidByteArray());
}

bool AccessPoint::isEncrypted() const
{
	return (getFlags() && NM_802_11_AP_FLAGS_PRIVACY);
}

void AccessPoint::slotPropertiesChanged(const TQMap<TQString, TQT_DBusVariant>& properties)
{
	updateProperties();
}

void AccessPoint::updateProperties()
{
	//TODO do this proper-like
	TQT_DBusError err;
	if (d->nmAccessPoint.isNull())
		return;

	d->flags = d->nmAccessPoint->getFlags(err);
	d->wpaFlags = d->nmAccessPoint->getWpaFlags(err);
	d->rsnFlags = d->nmAccessPoint->getRsnFlags(err);
	d->ssid = d->nmAccessPoint->getSsid(err);
	d->freq = d->nmAccessPoint->getFrequency(err);
	d->hwAddress = d->nmAccessPoint->getHwAddress(err);
	d->mode = d->nmAccessPoint->getMode(err);
	d->rate = d->nmAccessPoint->getMaxBitrate(err);
	d->strength = d->nmAccessPoint->getStrength(err);
	emit strengthChanged(d->strength);
}

TQString AccessPoint::getObjectPath() const
{
	return d->objPath;
}

bool AccessPoint::isValid() const
{
	return !(d->objPath.isEmpty());
}

bool AccessPoint::operator== (const AccessPoint& other) const
{
	return (other.getObjectPath() == getObjectPath());
}
#if 0
AccessPoint& AccessPoint::operator= (const AccessPoint& other)
{
	kdDebug() << "AccessPoint::operator=\n" << endl;
	d->objPath = other.d->objPath;
	d->nmAccessPoint = other.d->nmAccessPoint;
	connect(d->nmAccessPoint, TQT_SIGNAL(PropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)), this, TQT_SLOT(slotPropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)));

	updateProperties();

	return *this;
}
#endif
AccessPoint::AccessPoint(TQString obj_path, TQObject * parent, const char * name)
: TQObject(parent, name)
{
	DBus::AccessPointProxy * proxy = new DBus::AccessPointProxy(NM_DBUS_SERVICE, obj_path);
	proxy->setConnection(TQT_DBusConnection::systemBus());
	d = new AccessPointPrivate(obj_path, proxy);

	if (!d->nmAccessPoint.isNull())
		connect(d->nmAccessPoint, TQT_SIGNAL(PropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)), this, TQT_SLOT(slotPropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)));

	updateProperties();
}
#if 0
// copy constructor
AccessPoint::AccessPoint(const AccessPoint& other)
	: TQObject()
{
	// just copy the private data from other
	d = new AccessPointPrivate(*other.d);

	if (!d->nmAccessPoint.isNull())
		connect(d->nmAccessPoint, TQT_SIGNAL(PropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)), this, TQT_SLOT(slotPropertiesChanged(const TQMap<TQString, TQT_DBusVariant>&)));

	updateProperties();
}
#endif
AccessPoint::~AccessPoint()
{
	delete d->nmAccessPoint;
	delete d;
}


#include "knetworkmanager-accesspoint.moc"