1
/***************************************************************************
3
* knetworkmanager-network.cpp - A NetworkManager frontend for KDE
5
* Copyright (C) 2005, 2006 Novell, Inc.
7
* Author: Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
8
* Will Stephenson <wstephenson@suse.de>, <wstephenson@kde.org>
9
* Valentine Sinitsyn <e_val@inbox.ru>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
**************************************************************************/
27
#include "knetworkmanager-network.h"
28
#include "knetworkmanager-encryption.h"
30
#include <kconfigbase.h>
34
Network::setObjectPath (const QString & obj_path)
40
Network::getObjectPath () const
46
Network::setEssid (const QString & essid)
48
_dirty |= (_essid != essid);
53
Network::getEssid () const
59
Network::insertHardwareAddress (const QString & hw_address)
61
if ( ( hw_address != "00:00:00:00:00:00" ) && ( _hw_addresses.find( hw_address ) == _hw_addresses.end() ) ) {
62
_hw_addresses.append( hw_address );
68
Network::removeHardwareAddress (const QString & hw_address)
70
QStringList::Iterator it = _hw_addresses.find( hw_address );
71
if ( it != _hw_addresses.end() ) {
72
_hw_addresses.remove( it );
78
Network::getHardwareAddresses () const
84
Network::setHardwareAddresses( const QStringList & addresses )
86
_dirty |= (_hw_addresses != addresses);
87
_hw_addresses = addresses;
91
Network::setStrength (int strength)
97
Network::getStrength () const
103
Network::setFrequency (double frequency)
105
_frequency = frequency;
109
Network::getFrequency () const
115
Network::setRate (int rate)
121
Network::getRate () const
127
Network::setMode (int mode)
133
Network::getMode () const
139
Network::setCapabilities (int capabilties)
141
_capabilities = capabilties;
145
Network::getCapabilities () const
147
return _capabilities;
151
Network::setActive (bool active)
157
Network::isActive () const
163
Network::getEncryption (void) const
169
Network::setEncryption (Encryption* encryption)
171
_encryption = encryption;
174
_encryption->setNetwork(this);
178
Network::getEncryptionProtocol () const
180
QStringList encryptionProtocol;
183
if (_capabilities & NM_802_11_CAP_PROTO_NONE)
184
encryptionProtocol.append (i18n ("None"));
186
if (_capabilities & NM_802_11_CAP_PROTO_WEP)
187
encryptionProtocol.append ("WEP");
188
if (_capabilities & NM_802_11_CAP_PROTO_WPA)
189
encryptionProtocol.append ("WPA");
190
if (_capabilities & NM_802_11_CAP_PROTO_WPA2)
191
encryptionProtocol.append ("WPA2");
193
return encryptionProtocol;
197
Network::isEncrypted () const
199
if (_capabilities & NM_802_11_CAP_PROTO_NONE) {
206
bool Network::isTrusted() const
211
void Network::setTrusted( bool trusted )
213
_dirty |= (_trusted != trusted);
217
bool Network::isHidden () const
222
void Network::setHidden (bool hidden)
224
_dirty |= (_hidden != hidden);
229
Network::operator == (Network net)
231
return (this->getObjectPath () == net.getObjectPath ());
235
Network::isModified (void) const
238
* Since Encryption objects are persisted on par with Network, we need
239
* to mark Network dirty if it was modified itself or it contains modified Encryption
241
return ( _dirty || _encryption->isModified() );
244
Network::Network (const QString & obj_path): _encryption (0), _obj_path (obj_path), _essid (""), _hw_addresses (),
245
_strength (0), _frequency (0), _rate (0), _passphrase (""), _active( false ), _mode (0),
246
_capabilities( NM_DEVICE_CAP_NONE ), _trusted( true )
248
_encryption = new EncryptionNone ();
249
_encryption->setNetwork(this);
253
Network::Network () : _encryption (0), _obj_path (""), _essid (""), _hw_addresses (), _strength (0), _frequency (0),
254
_rate (0), _passphrase (""), _active( false ), _mode (0), _capabilities( NM_DEVICE_CAP_NONE ),
257
_encryption = new EncryptionNone ();
258
_encryption->setNetwork(this);
267
QDateTime Network::getTimestamp( void ) const
272
void Network::setTimestamp( const QDateTime & dt )
277
void Network::persist( KConfigBase * cfg, bool updateTimestamp, bool withKey ) const
279
// write network settings
281
cfg->writeEntry( "ESSID", getEssid() );
283
cfg->writeEntry( "Trusted", _trusted );
284
// hardware addresses
285
//if ( !_hw_addresses.isEmpty() )
286
cfg->writeEntry( "HardwareAddresses", _hw_addresses );
288
if ( updateTimestamp )
289
persistTimestamp( cfg );
291
if ( _encryption && _encryption->isModified( ) )
292
_encryption->persist( cfg, withKey );
297
void Network::restore( KConfigBase * cfg, double version, bool withKey )
299
setEssid( cfg->readEntry( "ESSID", QString::null ) );
300
//setEncryption( 0 ); /* Memory leak here */
301
QDateTime defaultTime;
302
defaultTime.setTime_t( 1 ); // invalid time
303
setTimestamp( cfg->readDateTimeEntry( "Timestamp", &defaultTime) );
304
kdDebug() << "restore read timestamp " << _timeStamp << endl;
305
_hw_addresses = cfg->readListEntry( "HardwareAddresses" );
306
QString encryption = cfg->readEntry( "Encryption", "none" );
307
_trusted = cfg->readBoolEntry( "Trusted", false );
312
if ( "WPA" == encryption )
313
_encryption = new EncryptionWPAPersonal ( );
314
else if ( "WPA-EAP" == encryption )
315
_encryption = new EncryptionWPAEnterprise ( );
316
else if ( "WEP" == encryption )
317
_encryption = new EncryptionWEP( WEP_ASCII ); // actual type is not important, restore overwrites it
318
else if ( "none" == encryption )
319
_encryption = new EncryptionNone();
320
_encryption->setNetwork(this);
321
_encryption->restore( cfg, version, withKey);
325
void Network::persistTimestamp( KConfigBase *cfg ) const
327
QDateTime current = QDateTime::currentDateTime( );
328
cfg->writeEntry( "Timestamp", current );