summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/networkinfo.h
blob: 7e50bc46ca77255f149e6e564a1c9d5ebf5ac030 (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
/**********************************************************************
** MNetwork* classes
**
** Encapsulates network information
**
** Copyright (C) 2002, Michael Lauer
**                    mickey@tm.informatik.uni-frankfurt.de
**                    http://www.Vanille.de
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/

#ifndef NETWORKINFO_H
#define NETWORKINFO_H

#include <qstring.h>
#include <qdict.h>

//---------------------------------------------------------------------------
// class MNetworkInterface
//

class MNetworkInterface
{
public:
        
    MNetworkInterface( const char* name = "eth0" );
    virtual ~MNetworkInterface();

    bool isLoopback() { return isLoopbackInterface; };
    const QString& getName() { return name; };

    virtual bool updateStatistics();   

protected:
        
    int fd;
    const QString name;
    bool isLoopbackInterface;
    bool isIrda;
    bool isTunnel;
};

//---------------------------------------------------------------------------
// class MWirelessNetworkInterface
//

class MWirelessNetworkInterface : public MNetworkInterface
{
public:
    MWirelessNetworkInterface( const char* name = "wlan0" );
    virtual ~MWirelessNetworkInterface();
    
    int noisePercent();
    int qualityPercent();
    int signalPercent();

    QString APAddr;
    QString essid;
    QString mode;
    QString nick;
    QString rate;
    double freq;
    int channel;

    virtual bool updateStatistics();
   
private: 
    int quality;
    int signal;
    int noise;

    bool hasWirelessExtensions;   
};

//---------------------------------------------------------------------------
// class MNetwork
//

class MNetwork
{
public:
    MNetwork();
    virtual ~MNetwork();

    typedef QDict<MNetworkInterface> InterfaceMap;
    typedef QDictIterator<MNetworkInterface> InterfaceMapIterator;

    bool hasInterfaces() const { return interfaces.isEmpty(); };
    int numInterfaces() const { return interfaces.count(); };

    MNetworkInterface* getFirstInterface();
    
protected:
    QString procfile;
    InterfaceMap interfaces;

    virtual MNetworkInterface* createInterface( const char* name ) const;

private:
    void enumerateInterfaces();
};

//---------------------------------------------------------------------------
// class MWirelessNetwork
//

class MWirelessNetwork : public MNetwork
{
public:
    MWirelessNetwork();
    virtual ~MWirelessNetwork();

protected:
    virtual MNetworkInterface* createInterface( const char* name )
        const;
};

#endif