Qtopia library API Documentation

networkinterface.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "networkinterface.h"
00022 #include "network.h"
00023 #include "config.h"
00024 #include <stdio.h>
00025 
00026 QString NetworkInterface::device( Config& cfg ) const
00027 {
00028     return cfg.readEntry("Device");
00029 }
00030 
00031 bool NetworkInterface::isActive( Config& cfg ) const
00032 {    
00033     QString dev = device(cfg);
00034     if ( dev.isEmpty() )
00035     return FALSE;
00036     QString dev0 = dev+'0';
00037 
00038     FILE* f;
00039     f = fopen("/proc/net/dev", "r");
00040     if ( f ) {
00041     char line[1024];
00042     char devname[80];
00043     while ( fgets( line, 1024, f ) ) {
00044         if ( sscanf(line," %[^:]:", devname)==1 )
00045         {
00046         if ( devname == dev || devname == dev0 ) {
00047             fclose(f);
00048             Network::writeProxySettings( cfg );
00049             return TRUE;
00050         }
00051         }
00052     }
00053     fclose(f);
00054     }
00055     return FALSE;
00056 }
00057 
00058 QString NetworkInterface::cardType( Config& cfg ) const
00059 {
00060     return cfg.readEntry("CardType");
00061 }
00062 
00063 bool NetworkInterface::isAvailable( Config& cfg ) const
00064 {
00065     QString ct = cardType(cfg);
00066     if ( ct.isEmpty() )
00067     return FALSE;
00068 
00069     FILE* f = fopen("/var/run/stab", "r");
00070     if (!f) f = fopen("/var/state/pcmcia/stab", "r");
00071     if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
00072 
00073     if ( f ) {
00074     char line[1024];
00075     char devtype[80];
00076     while ( fgets( line, 1024, f ) ) {
00077         if ( sscanf(line,"%*d %s %*s", devtype )==1 )
00078         {
00079         if ( ct == devtype ) {
00080             fclose(f);
00081             return TRUE;
00082         }
00083         }
00084     }
00085     fclose(f);
00086     }
00087 
00088     return FALSE;
00089 }
00090 
00091 bool NetworkInterface::start( Config& cfg, const QString& /*password*/ )
00092 {
00093     return start(cfg);
00094 }
00095 
00096 bool NetworkInterface::needPassword( Config& ) const
00097 {
00098     return FALSE;
00099 }
00100 
00101 QWidget* NetworkInterface::addStateWidget( QWidget*, Config& ) const
00102 {
00103     return 0;
00104 }
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001