Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Interfaces Class Reference

#include </home/clem/local/src/opie/noncore/settings/networksettings/interfaces/interfaces.h>

Collaboration diagram for Interfaces:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Interfaces (QString useInterfacesFile="/etc/network/interfaces")
QStringList getInterfaceList ()
bool isAuto (const QString &interface) const
bool setAuto (const QString &interface, bool setAuto)
bool removeInterface ()
bool addInterface (const QString &interface, const QString &family, const QString &method)
bool copyInterface (const QString &oldInterface, const QString &newInterface)
bool setInterface (QString interface)
bool isInterfaceSet () const
QString getInterfaceName (bool &error)
bool setInterfaceName (const QString &newName)
QString getInterfaceFamily (bool &error)
bool setInterfaceFamily (const QString &newName)
QString getInterfaceMethod (bool &error)
bool setInterfaceMethod (const QString &newName)
QString getInterfaceOption (const QString &option, bool &error)
bool setInterfaceOption (const QString &option, const QString &value)
bool removeInterfaceOption (const QString &option)
bool removeInterfaceOption (const QString &option, const QString &value)
bool removeAllInterfaceOptions ()
bool setMapping (const QString &interface)
bool removeMapping ()
void addMapping (const QString &options)
bool setMap (const QString &map, const QString &value)
bool removeMap (const QString &map, const QString &value)
QString getMap (const QString &map, bool &error)
bool setScript (const QString &argument)
QString getScript (bool &error)
bool write ()

Private Member Functions

bool setStanza (const QString &stanza, const QString &option, QStringList::Iterator &iterator)
bool removeStanza (QStringList::Iterator &stanza)
bool setOption (const QStringList::Iterator &start, const QString &option, const QString &value)
bool removeAllOptions (const QStringList::Iterator &start)
bool removeOption (const QStringList::Iterator &start, const QString &option)
bool removeOption (const QStringList::Iterator &start, const QString &option, const QString &value)
QString getOption (const QStringList::Iterator &start, const QString &option, bool &error)

Private Attributes

QString interfacesFile
QStringList interfaces
QStringList::Iterator currentIface
QStringList::Iterator currentMapping
QStringList acceptedFamily

Detailed Description

This class provides a clean frontend for parsing the network interfaces file. It provides helper functions to minipulate the options within the file. See the interfaces man page for the syntax rules.

Definition at line 22 of file interfaces.h.


Constructor & Destructor Documentation

Interfaces::Interfaces QString  useInterfacesFile = "/etc/network/interfaces"  ) 
 

Constructor. Reads in the interfaces file and then split the file up by the
for interfaces variable.

Parameters:
useInterfacesFile if an interface file other then the default is desired to be used it should be passed in.

Definition at line 21 of file interfaces.cpp.

References acceptedFamily, QValueList< T >::append(), currentIface, currentMapping, QValueList< T >::end(), QTextStream::eof(), interfaces, INTERFACES_FAMILY_INET, INTERFACES_FAMILY_INET6, INTERFACES_FAMILY_IPX, interfacesFile, IO_ReadOnly, odebug, oendl, QFile::open(), QTextStream::readLine(), QStringList::split(), and stream.


Member Function Documentation

bool Interfaces::addInterface const QString interface,
const QString family,
const QString method
 

Add a new interface of with the settings - family and method

Parameters:
interface the name of the interface to set. All whitespace is removed from the interface name.
family the family of this interface inet or inet, ipx or inet6 Must of one of the families defined in interfaces.h
method for the family. see interfaces man page for family methods.
Returns:
true if successful.

Definition at line 156 of file interfaces.cpp.

References acceptedFamily, QValueList< T >::append(), QValueList< T >::contains(), IFACE, interfaces, QString::latin1(), odebug, oendl, QString::replace(), and QString::simplifyWhiteSpace().

Referenced by copyInterface(), and InterfaceSetupImp::setProfile().

void Interfaces::addMapping const QString option  ) 
 

Adds a new Mapping to the interfaces file with interfaces.

Parameters:
interface the name(s) of the interfaces to set to this mapping

Definition at line 400 of file interfaces.cpp.

References QValueList< T >::append(), interfaces, and MAPPING.

Referenced by InterfaceSetupImp::setProfile().

bool Interfaces::copyInterface const QString interface,
const QString newInterface
 

Copies interface with name interface to name newInterface

Parameters:
newInterface name of the new interface.
Returns:
bool true if successful

Definition at line 172 of file interfaces.cpp.

References addInterface(), AUTO, currentIface, QValueList< T >::end(), error(), getInterfaceFamily(), getInterfaceMethod(), IFACE, QValueList< T >::insert(), interfaces, QString::latin1(), MAPPING, odebug, oendl, and setInterface().

Referenced by InterfaceSetupImp::setProfile().

QString Interfaces::getInterfaceFamily bool &  error  ) 
 

Gets the family name of the interface that is currently selected.

Returns:
QString name of the family (inet, inet6, ipx).
Parameters:
error set to true if any error occurs, false otherwise.

Definition at line 235 of file interfaces.cpp.

References QString::find(), getInterfaceName(), IFACE, QString::length(), QString::mid(), name, and QString::simplifyWhiteSpace().

Referenced by copyInterface(), getInterfaceMethod(), setInterfaceMethod(), and setInterfaceName().

QStringList Interfaces::getInterfaceList  ) 
 

Get a list of all interfaces in the interface file. Useful for hardware that is not currently connected such as an 802.11b card not plugged in, but configured for when it is plugged in.

Returns:
Return string list of interfaces.

Definition at line 54 of file interfaces.cpp.

References QValueList< T >::append(), QString::at(), QValueList< T >::begin(), QString::contains(), QValueList< T >::end(), QString::find(), IFACE, interfaces, QString::length(), list, QString::mid(), and QString::simplifyWhiteSpace().

Referenced by MainWindowImp::MainWindowImp().

QString Interfaces::getInterfaceMethod bool &  error  ) 
 

Gets the method of the interface that is currently selected.

Returns:
QString name of the method such as staic or dhcp. See the man page of interfaces for possible methods depending on the family.
Parameters:
error set to true if any error occurs, false otherwise.

Definition at line 258 of file interfaces.cpp.

References getInterfaceFamily(), getInterfaceName(), IFACE, QString::length(), QString::mid(), name, and QString::simplifyWhiteSpace().

Referenced by copyInterface(), InterfaceSetupImp::saveSettings(), setInterfaceFamily(), setInterfaceName(), and InterfaceSetupImp::setProfile().

QString Interfaces::getInterfaceName bool &  error  ) 
 

Gets the hardware name of the interface that is currently selected.

Returns:
QString name of the hardware interface (eth0, usb2, wlan1...).
Parameters:
error set to true if any error occurs, false otherwise.

Definition at line 213 of file interfaces.cpp.

References currentIface, QValueList< T >::end(), QString::find(), IFACE, interfaces, QString::length(), QString::mid(), and QString::simplifyWhiteSpace().

Referenced by getInterfaceFamily(), getInterfaceMethod(), InterfaceSetupImp::saveChanges(), setInterfaceFamily(), setInterfaceMethod(), InterfaceSetupImp::setProfile(), and WLANImp::writeOpts().

QString Interfaces::getInterfaceOption const QString option,
bool &  error
 

Get a value for an option in the currently selected interface. For example calling getInterfaceOption("address") on the following stanza would return 192.168.1.1. iface eth0 static address 192.168.1.1

Parameters:
option the options to get the value.
error set to true if any error occurs, false otherwise.
Returns:
QString the options value. QString::null if error == true

Definition at line 332 of file interfaces.cpp.

References currentIface, and getOption().

Referenced by WLANImp::parseOpts(), InterfaceSetupImp::setProfile(), and WLANImp::writeOpts().

QString Interfaces::getMap const QString map,
bool &  error
 

Get a map value within a mapping.

Parameters:
map map to get value of
bool true if it is successful.
Returns:
value that goes to the map

Definition at line 439 of file interfaces.cpp.

References currentMapping, and getOption().

QString Interfaces::getOption const QStringList::Iterator start,
const QString option,
bool &  error
[private]
 

Gets a value of an option in a stanza

Parameters:
start the start of the stanza
option the option to use when getting the value.
bool true if errors false otherwise.
Returns:
QString the value of option QString::null() if error == true.

Definition at line 654 of file interfaces.cpp.

References AUTO, QValueList< T >::end(), QString::find(), IFACE, interfaces, QString::length(), MAPPING, QString::mid(), odebug, and oendl.

Referenced by getInterfaceOption(), getMap(), and getScript().

QString Interfaces::getScript bool &  error  ) 
 

Parameters:
error true if could not retrieve the current script argument.
Returns:
QString the argument of the script for the current mapping.

Definition at line 456 of file interfaces.cpp.

References currentMapping, and getOption().

bool Interfaces::isAuto const QString interface  )  const
 

Find out if interface is in an "auto" group or not. Report any duplicates such as eth0 being in two differnt auto's

Parameters:
interface interface to check to see if it is on or not.
Returns:
true is interface is in auto

Definition at line 77 of file interfaces.cpp.

References AUTO, QValueList< T >::count(), QStringList::grep(), interfaces, odebug, and oendl.

Referenced by setAuto(), and InterfaceSetupImp::setProfile().

bool Interfaces::isInterfaceSet  )  const
 

A quick helper funtion to see if the current interface is set.

Returns:
bool true if set, false otherwise.

Definition at line 143 of file interfaces.cpp.

References currentIface, QValueList< T >::end(), and interfaces.

Referenced by WLANImp::parseOpts(), InterfaceSetupImp::saveSettings(), and WLANImp::writeOpts().

bool Interfaces::removeAllInterfaceOptions  ) 
 

Removes all of the options from the currently selected interface.

Returns:
bool error if if successful

Definition at line 379 of file interfaces.cpp.

References currentIface, and removeAllOptions().

bool Interfaces::removeAllOptions const QStringList::Iterator start  )  [private]
 

Removes all options in a stanza

Parameters:
start the start of the stanza
Returns:
bool true if successful, false otherwise.

Definition at line 629 of file interfaces.cpp.

References AUTO, QValueList< T >::end(), IFACE, QValueList< T >::insert(), interfaces, MAPPING, and QValueList< T >::remove().

Referenced by removeAllInterfaceOptions(), and removeStanza().

bool Interfaces::removeInterface  ) 
 

Remove the currently selected interface and all of its options.

Returns:
bool if successful or not.

Definition at line 204 of file interfaces.cpp.

References currentIface, and removeStanza().

Referenced by MainWindowImp::removeProfile().

bool Interfaces::removeInterfaceOption const QString option,
const QString value
 

Removes a value for an option in the currently selected interface.

Parameters:
option the options to set the value.
value the value that option should be set to.
error set to true if any error occurs, false otherwise.
Returns:
QString the options value. QString::null if error == true

Definition at line 371 of file interfaces.cpp.

References currentIface, and removeOption().

bool Interfaces::removeInterfaceOption const QString option  ) 
 

Removes a value for an option in the currently selected interface.

Parameters:
option the options to set the value.
error set to true if any error occurs, false otherwise.
Returns:
QString the options value. QString::null if error == true

Definition at line 360 of file interfaces.cpp.

References currentIface, and removeOption().

Referenced by InterfaceSetupImp::saveSettings(), setInterfaceOption(), and WLANImp::writeOpts().

bool Interfaces::removeMap const QString map,
const QString value
 

Removes a map option within a mapping.

Parameters:
map map to use
value value to go with map
Returns:
bool true if it is successful.

Definition at line 429 of file interfaces.cpp.

References currentMapping, and removeOption().

Referenced by MainWindowImp::removeProfile().

bool Interfaces::removeMapping  ) 
 

Remove the currently selected map and all of its options.

Returns:
bool if successful or not.

Definition at line 409 of file interfaces.cpp.

References currentMapping, and removeStanza().

Referenced by MainWindowImp::removeProfile().

bool Interfaces::removeOption const QStringList::Iterator start,
const QString option,
const QString value
[private]
 

Removes a option in a stanza

Parameters:
start the start of the stanza
option the option to use when setting value.
Returns:
bool true if successful, false otherwise.

Definition at line 602 of file interfaces.cpp.

References AUTO, QValueList< T >::end(), IFACE, interfaces, MAPPING, odebug, oendl, and QValueList< T >::remove().

bool Interfaces::removeOption const QStringList::Iterator start,
const QString option
[private]
 

Removes a option in a stanza

Parameters:
start the start of the stanza
option the option to remove
Returns:
bool true if successful, false otherwise.

Definition at line 574 of file interfaces.cpp.

References AUTO, QValueList< T >::end(), IFACE, interfaces, MAPPING, odebug, oendl, and QValueList< T >::remove().

Referenced by removeInterfaceOption(), and removeMap().

bool Interfaces::removeStanza QStringList::Iterator stanza  )  [private]
 

Removes a stanza and all of its options

Parameters:
stanza the stanza to remove
Returns:
bool true if successful.

Definition at line 561 of file interfaces.cpp.

References QValueList< T >::end(), interfaces, and removeAllOptions().

Referenced by removeInterface(), and removeMapping().

bool Interfaces::setAuto const QString interface,
bool  setAuto
 

Attempt to set the auto option for interface to setAuto.

Parameters:
interface the interface to set
setAuto the value to set interface to.
Returns:
false if already set to setAuto.

Definition at line 91 of file interfaces.cpp.

References QValueList< T >::append(), AUTO, QValueList< T >::begin(), QValueList< T >::end(), interfaces, and isAuto().

Referenced by InterfaceSetupImp::saveSettings().

bool Interfaces::setInterface QString  interface  ) 
 

Set the current interface to interface. This needs to be done before you can call getFamily(), getMethod, and get/setOption().

Parameters:
interface the name of the interface to set. All whitespace is removed from the interface name.
Returns:
bool true if it is successful.

Definition at line 133 of file interfaces.cpp.

References currentIface, IFACE, and setStanza().

Referenced by copyInterface(), MainWindowImp::removeProfile(), and InterfaceSetupImp::setProfile().

bool Interfaces::setInterfaceFamily const QString newName  ) 
 

Sets the interface family to newName.

Parameters:
newName the new name of the interface. Must be one of the families defined in the interfaces.h file.
Returns:
bool true if successful.

Definition at line 299 of file interfaces.cpp.

References acceptedFamily, QValueList< T >::contains(), currentIface, QValueList< T >::end(), getInterfaceMethod(), getInterfaceName(), and interfaces.

bool Interfaces::setInterfaceMethod const QString newName  ) 
 

Sets the interface method to newName

Parameters:
newName the new name of the interface
Returns:
bool true if successful.

Definition at line 314 of file interfaces.cpp.

References currentIface, QValueList< T >::end(), getInterfaceFamily(), getInterfaceName(), and interfaces.

Referenced by InterfaceSetupImp::saveSettings().

bool Interfaces::setInterfaceName const QString newName  ) 
 

Sets the interface name to newName.

Parameters:
newName the new name of the interface. All whitespace is removed.
Returns:
bool true if successful.

Definition at line 279 of file interfaces.cpp.

References currentIface, QValueList< T >::end(), getInterfaceFamily(), getInterfaceMethod(), interfaces, QString::latin1(), name, odebug, oendl, QString::replace(), and QString::simplifyWhiteSpace().

bool Interfaces::setInterfaceOption const QString option,
const QString value
 

Set a value for an option in the currently selected interface. If option doesn't exist then it is added along with the value. If value isEmpty() then we will remove the option

Parameters:
option the options to set the value.
value the value that option should be set to.
error set to true if any error occurs, false otherwise.
Returns:
QString the options value. QString::null if error == true

Definition at line 346 of file interfaces.cpp.

References currentIface, QString::latin1(), odebug, oendl, removeInterfaceOption(), setOption(), and QString::stripWhiteSpace().

Referenced by InterfaceSetupImp::saveSettings(), and WLANImp::writeOpts().

bool Interfaces::setMap const QString map,
const QString value
 

Set a map option within a mapping.

Parameters:
map map to use
value value to go with map
Returns:
bool true if it is successful.

Definition at line 419 of file interfaces.cpp.

References currentMapping, and setOption().

Referenced by InterfaceSetupImp::setProfile().

bool Interfaces::setMapping const QString interface  ) 
 

Set the current map to interface's map. This needs to be done before you can call addMapping(), set/getMap(), and get/setScript().

Parameters:
interface the name of the interface to set. All whitespace is removed from the interface name.
Returns:
bool true if it is successful.

Definition at line 390 of file interfaces.cpp.

References currentMapping, MAPPING, QString::replace(), setStanza(), and QString::simplifyWhiteSpace().

Referenced by MainWindowImp::removeProfile(), and InterfaceSetupImp::setProfile().

bool Interfaces::setOption const QStringList::Iterator start,
const QString option,
const QString value
[private]
 

Sets a value of an option in a stanza

Parameters:
start the start of the stanza
option the option to use when setting value.
Returns:
bool true if successful, false otherwise.

Definition at line 507 of file interfaces.cpp.

References AUTO, QValueList< T >::end(), IFACE, QValueList< T >::insert(), interfaces, MAPPING, NULL, odebug, oendl, and p.

Referenced by setInterfaceOption(), setMap(), and setScript().

bool Interfaces::setScript const QString argument  ) 
 

Sets a script value of the current mapping to argument.

Parameters:
argument the script name.
Returns:
true if successful.

Definition at line 448 of file interfaces.cpp.

References currentMapping, and setOption().

Referenced by InterfaceSetupImp::setProfile().

bool Interfaces::setStanza const QString stanza,
const QString option,
QStringList::Iterator iterator
[private]
 

Helper function used to parse through the QStringList and put pointers in the correct place.

Parameters:
stanza The stanza (auto, iface, mapping) to look for.
option string that must be in the stanza's main line.
interator interator to place at location of stanza if successful.
Returns:
bool true if the stanza is found.

Definition at line 470 of file interfaces.cpp.

References QString::at(), QValueList< T >::begin(), QString::contains(), QValueList< T >::end(), QString::find(), interfaces, QString::length(), odebug, and oendl.

Referenced by setInterface(), and setMapping().

bool Interfaces::write  ) 
 

Write out the interfaces file to the file passed into the constructor. Removes any excess blank lines over 1 line long.

Returns:
bool true if successful, false if not.

Definition at line 687 of file interfaces.cpp.

References QValueList< T >::begin(), QValueList< T >::end(), interfaces, interfacesFile, IO_ReadWrite, QString::length(), odebug, oendl, QFile::open(), QFile::remove(), QString::replace(), and stream.

Referenced by MainWindowImp::removeProfile(), and InterfaceSetupImp::saveChanges().


Member Data Documentation

QStringList Interfaces::acceptedFamily [private]
 

Definition at line 73 of file interfaces.h.

Referenced by addInterface(), Interfaces(), and setInterfaceFamily().

QStringList::Iterator Interfaces::currentIface [private]
 

Definition at line 70 of file interfaces.h.

Referenced by copyInterface(), getInterfaceName(), getInterfaceOption(), Interfaces(), isInterfaceSet(), removeAllInterfaceOptions(), removeInterface(), removeInterfaceOption(), setInterface(), setInterfaceFamily(), setInterfaceMethod(), setInterfaceName(), and setInterfaceOption().

QStringList::Iterator Interfaces::currentMapping [private]
 

Definition at line 71 of file interfaces.h.

Referenced by getMap(), getScript(), Interfaces(), removeMap(), removeMapping(), setMap(), setMapping(), and setScript().

QStringList Interfaces::interfaces [private]
 

Definition at line 69 of file interfaces.h.

Referenced by addInterface(), addMapping(), copyInterface(), getInterfaceList(), getInterfaceName(), getOption(), Interfaces(), isAuto(), isInterfaceSet(), removeAllOptions(), removeOption(), removeStanza(), setAuto(), setInterfaceFamily(), setInterfaceMethod(), setInterfaceName(), setOption(), setStanza(), and write().

QString Interfaces::interfacesFile [private]
 

Definition at line 68 of file interfaces.h.

Referenced by Interfaces(), and write().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:36:19 2005 for OPIE by  doxygen 1.4.2