Networksettings API API Documentation

Interfaces Class Reference

This class provides a clean frontend for parsing the network interfaces file. More...

#include <interfaces.h>

Collaboration diagram for Interfaces:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Interfaces (QString useInterfacesFile="/etc/network/interfaces")
 Constructor.

QStringList getInterfaceList ()
 Get a list of all interfaces in the interface file.

bool isAuto (const QString &interface) const
 Find out if interface is in an "auto" group or not.

bool setAuto (const QString &interface, bool setAuto)
 Attempt to set the auto option for interface to setAuto.

bool removeInterface ()
 Remove the currently selected interface and all of its options.

bool addInterface (const QString &interface, const QString &family, const QString &method)
 Add a new interface of with the settings - family and method.

bool copyInterface (const QString &oldInterface, const QString &newInterface)
 Copies interface with name interface to name newInterface.

bool setInterface (QString interface)
 Set the current interface to interface.

bool isInterfaceSet () const
 A quick helper funtion to see if the current interface is set.

QString getInterfaceName (bool &error)
 Gets the hardware name of the interface that is currently selected.

bool setInterfaceName (const QString &newName)
 Sets the interface name to newName.

QString getInterfaceFamily (bool &error)
 Gets the family name of the interface that is currently selected.

bool setInterfaceFamily (const QString &newName)
 Sets the interface family to newName.

QString getInterfaceMethod (bool &error)
 Gets the method of the interface that is currently selected.

bool setInterfaceMethod (const QString &newName)
 Sets the interface method to newName.

QString getInterfaceOption (const QString &option, bool &error)
 Get a value for an option in the currently selected interface.

bool setInterfaceOption (const QString &option, const QString &value)
 Set a value for an option in the currently selected interface.

bool removeInterfaceOption (const QString &option)
 Removes a value for an option in the currently selected interface.

bool removeInterfaceOption (const QString &option, const QString &value)
 Removes a value for an option in the currently selected interface.

bool removeAllInterfaceOptions ()
 Removes all of the options from the currently selected interface.

bool setMapping (const QString &interface)
 Set the current map to interface's map.

bool removeMapping ()
 Remove the currently selected map and all of its options.

void addMapping (const QString &options)
 Adds a new Mapping to the interfaces file with interfaces.

bool setMap (const QString &map, const QString &value)
 Set a map option within a mapping.

bool removeMap (const QString &map, const QString &value)
 Removes a map option within a mapping.

QString getMap (const QString &map, bool &error)
 Get a map value within a mapping.

bool setScript (const QString &argument)
 Sets a script value of the current mapping to argument.

QString getScript (bool &error)
bool write ()
 Write out the interfaces file to the file passed into the constructor.


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 19 of file interfaces.cpp.

References QValueList::append(), QFile::close(), QValueList::end(), QString::latin1(), QFile::open(), QTextStream::readLine(), and QStringList::split().


Member Function Documentation

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 52 of file interfaces.cpp.

References QValueList::append(), QString::at(), QValueList::begin(), QString::contains(), QValueList::end(), QString::find(), QString::length(), QString::mid(), and QString::simplifyWhiteSpace().

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 75 of file interfaces.cpp.

References QValueList::count(), and QStringList::grep().

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

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 89 of file interfaces.cpp.

References QValueList::append(), QValueList::begin(), QValueList::end(), isAuto(), and QString::simplifyWhiteSpace().

Referenced by InterfaceSetupImp::saveSettings().

bool Interfaces::removeInterface  ) 
 

Remove the currently selected interface and all of its options.

Returns:
bool if successful or not.

Definition at line 202 of file interfaces.cpp.

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 154 of file interfaces.cpp.

References QValueList::append(), QValueList::contains(), QString::latin1(), QString::replace(), and QString::simplifyWhiteSpace().

Referenced by copyInterface(), and 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 170 of file interfaces.cpp.

References addInterface(), QValueList::end(), getInterfaceFamily(), getInterfaceMethod(), QValueList::insert(), QString::latin1(), and setInterface().

Referenced by InterfaceSetupImp::setProfile().

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 131 of file interfaces.cpp.

References QString::replace(), and QString::simplifyWhiteSpace().

Referenced by copyInterface(), 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 141 of file interfaces.cpp.

References QValueList::end().

Referenced by InterfaceSetupImp::saveSettings().

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 211 of file interfaces.cpp.

References QValueList::end(), QString::find(), QString::length(), QString::mid(), and QString::simplifyWhiteSpace().

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

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 277 of file interfaces.cpp.

References QValueList::end(), getInterfaceFamily(), getInterfaceMethod(), QString::latin1(), QString::replace(), and QString::simplifyWhiteSpace().

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 233 of file interfaces.cpp.

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

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

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 297 of file interfaces.cpp.

References QValueList::contains(), QValueList::end(), getInterfaceMethod(), and getInterfaceName().

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 256 of file interfaces.cpp.

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

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

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 312 of file interfaces.cpp.

References QValueList::end(), getInterfaceFamily(), and getInterfaceName().

Referenced by InterfaceSetupImp::saveSettings().

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 330 of file interfaces.cpp.

Referenced by InterfaceSetupImp::setProfile().

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 344 of file interfaces.cpp.

References QString::latin1(), removeInterfaceOption(), and QString::stripWhiteSpace().

Referenced by InterfaceSetupImp::saveSettings().

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 358 of file interfaces.cpp.

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

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 369 of file interfaces.cpp.

bool Interfaces::removeAllInterfaceOptions  ) 
 

Removes all of the options from the currently selected interface.

Returns:
bool error if if successful

Definition at line 377 of file interfaces.cpp.

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 388 of file interfaces.cpp.

References QString::replace(), and QString::simplifyWhiteSpace().

Referenced by InterfaceSetupImp::setProfile().

bool Interfaces::removeMapping  ) 
 

Remove the currently selected map and all of its options.

Returns:
bool if successful or not.

Definition at line 407 of file interfaces.cpp.

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 398 of file interfaces.cpp.

References QValueList::append().

Referenced by InterfaceSetupImp::setProfile().

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 417 of file interfaces.cpp.

Referenced by InterfaceSetupImp::setProfile().

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 427 of file interfaces.cpp.

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 437 of file interfaces.cpp.

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 446 of file interfaces.cpp.

Referenced by InterfaceSetupImp::setProfile().

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 454 of file interfaces.cpp.

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 685 of file interfaces.cpp.

References QValueList::begin(), QFile::close(), QValueList::end(), QString::length(), QFile::open(), QFile::remove(), QString::replace(), and QString::simplifyWhiteSpace().

Referenced by InterfaceSetupImp::saveChanges().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for OPIE Version 1.0.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:26:46 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001