summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/scanlist.cpp
blob: a689cca576bfe1002d2ed47c461ee255aad2bd0e (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer.  All rights reserved.
**
** This file is part of Opie Environment.
**
** 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.
**
**********************************************************************/

#include "scanlist.h"
#include "scanlistitem.h"

#include <assert.h>

#include "manufacturers.h"

MScanListView::MScanListView( QWidget* parent, const char* name )
              :QListView( parent, name ), _manufacturerdb( 0 )
{

    setFrameShape( QListView::StyledPanel );
    setFrameShadow( QListView::Sunken );
    
    addColumn( tr( "Net/Station" ) );
    setColumnAlignment( 0, AlignLeft || AlignVCenter );
    addColumn( tr( "B" ) );
    setColumnAlignment( 1, AlignCenter );
    addColumn( tr( "AP" ) );
    setColumnAlignment( 2, AlignCenter );
    addColumn( tr( "Chn" ) );
    setColumnAlignment( 3, AlignCenter );
    addColumn( tr( "W" ) );
    setColumnAlignment( 4, AlignCenter );
    addColumn( tr( "T" ) );
    setColumnAlignment( 5, AlignCenter );
    addColumn( tr( "Manufacturer" ) );
    setColumnAlignment( 6, AlignCenter );
    addColumn( tr( "First Seen" ) );
    setColumnAlignment( 7, AlignCenter );
    addColumn( tr( "Last Seen" ) );
    setColumnAlignment( 8, AlignCenter );
    setRootIsDecorated( true );
    setAllColumnsShowFocus( true );
};
    
MScanListView::~MScanListView()
{
};

void MScanListView::setManufacturerDB( ManufacturerDB* manufacturerdb )
{
    _manufacturerdb = manufacturerdb;
}

void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
{
    // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...)

        qDebug( "MScanList::addNewItem( %s / %s / %s [%d]",
        (const char*) type,
        (const char*) essid,
        (const char*) macaddr,
        channel );
        
    // search, if we already have seen this net
      
    QString s;
    MScanListItem* network;
    MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );

    while ( item && ( item->text( 0 ) != essid ) )
    {
        qDebug( "itemtext: %s", (const char*) item->text( 0 ) );
        item = static_cast<MScanListItem*> ( item->itemBelow() );
    }
    if ( item )
    {
        // animate the item
        
        /*
        
        const QPixmap* pixmap = item->pixmap( 0 );
        const QPixmap* nextpixmap = ani2;
        if ( pixmap == ani1 )
            nextpixmap = ani2;
        else if ( pixmap == ani2 )
            nextpixmap = ani3;
        else if ( pixmap == ani3 )
            nextpixmap = ani4;
        else if ( pixmap == ani4 )
            nextpixmap = ani1;
        item->setPixmap( 0, *nextpixmap ); */
        
        //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap );
        
        // we have already seen this net, check all childs if MAC exists
        
        network = item;
        
        item = static_cast<MScanListItem*> ( item->firstChild() );
        assert( item ); // this shouldn't fail
        
        while ( item && ( item->text( 2 ) != macaddr ) )
        {
            qDebug( "subitemtext: %s", (const char*) item->text( 2 ) );
            item = static_cast<MScanListItem*> ( item->itemBelow() );
        }
        
        if ( item )
        {
            // we have already seen this item, it's a dupe
            #ifdef DEBUG
            qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
            #endif
            item->receivedBeacon();
            return;
        }
    }
    else
    {
        s.sprintf( "(i) new network: '%s'", (const char*) essid );
        
        network = new MScanListItem( this, "networks", essid, QString::null, 0, 0, 0 );
    }    
        
        
    // insert new station as child from network
        
    // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
    
    qDebug( "inserting new station %s", (const char*) macaddr );
    
    MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal );
    if ( _manufacturerdb )
        station->setManufacturer( _manufacturerdb->lookup( macaddr ) );

    if ( type == "managed" )
    {
        s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel );
    }
    else
    {
        s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel );
    }
    
}