From d0e64d0c7961de1c3ecb886ae76c6701f268d767 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Sun, 02 Mar 2003 16:38:17 +0000 Subject: first attempt to add session persistence --- (limited to 'noncore/net/wellenreiter/gui') diff --git a/noncore/net/wellenreiter/gui/gui.pro b/noncore/net/wellenreiter/gui/gui.pro index 6037661..8861a50 100644 --- a/noncore/net/wellenreiter/gui/gui.pro +++ b/noncore/net/wellenreiter/gui/gui.pro @@ -7,7 +7,6 @@ CONFIG = qt warn_on debug HEADERS = wellenreiterbase.h \ mainwindow.h \ wellenreiter.h \ - scanlistitem.h \ scanlist.h \ logwindow.h \ hexwindow.h \ @@ -20,7 +19,6 @@ SOURCES = main.cpp \ mainwindow.cpp \ wellenreiterbase.cpp \ wellenreiter.cpp \ - scanlistitem.cpp \ scanlist.cpp \ logwindow.cpp \ hexwindow.cpp \ diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index e388fc5..0ef89d4 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp @@ -21,6 +21,7 @@ #include "scanlist.h" #include +#include #include #include #include @@ -44,6 +45,13 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n mw->setConfigWindow( cw ); setCentralWidget( mw ); + // setup application icon + + #ifndef QWS + setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); + setIconText( "Wellenreiter/X11" ); + #endif + // setup icon sets infoIconSet = new QIconSet( Resource::loadPixmap( "wellenreiter/InfoIcon" ) ); @@ -99,11 +107,10 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n QPopupMenu* fileLoad = new QPopupMenu( mb ); fileLoad->insertItem( "&Session", this, SLOT( fileLoadSession() ) ); - fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); + //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); QPopupMenu* file = new QPopupMenu( mb ); id = file->insertItem( "&Load", fileLoad ); - file->setItemEnabled( id, false ); file->insertItem( "&Save", fileSave ); QPopupMenu* view = new QPopupMenu( mb ); @@ -185,7 +192,7 @@ WellenreiterMainWindow::~WellenreiterMainWindow() void WellenreiterMainWindow::demoAddStations() { mw->netView()->addNewItem( "managed", "Vanille", "00:00:20:EF:A6:43", true, 6, 80 ); - mw->netView()->addNewItem( "managed", "Vanille", "00:00:1c:EF:A6:23", true, 11, 10 ); + mw->netView()->addNewItem( "managed", "Vanille", "00:30:6D:EF:A6:23", true, 11, 10 ); mw->netView()->addNewItem( "adhoc", "ELAN", "00:A0:F8:E7:16:22", false, 3, 10 ); mw->netView()->addNewItem( "adhoc", "ELAN", "00:AA:01:E7:56:62", false, 3, 15 ); mw->netView()->addNewItem( "adhoc", "ELAN", "00:B0:8E:E7:56:E2", false, 3, 20 ); @@ -215,8 +222,8 @@ void WellenreiterMainWindow::fileSaveSession() QFile f( fname ); if ( f.open(IO_WriteOnly) ) { - QTextStream t( &f ); - mw->netView()->dump( t ); + QDataStream t( &f ); + t << *mw->netView(); f.close(); qDebug( "Saved session to file '%s'", (const char*) fname ); } @@ -226,6 +233,25 @@ void WellenreiterMainWindow::fileSaveSession() } } +void WellenreiterMainWindow::fileLoadSession() +{ + const QString fname( "/tmp/session.xml" ); + QFile f( fname ); + + if ( f.open(IO_ReadOnly) ) + { + QDataStream t( &f ); + t >> *mw->netView(); + f.close(); + qDebug( "Loaded session from file '%s'", (const char*) fname ); + } + else + { + qDebug( "Problem loading session from file '%s'", (const char*) fname ); + } + +} + void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) { if ( mw->isDaemonRunning() ) diff --git a/noncore/net/wellenreiter/gui/mainwindow.h b/noncore/net/wellenreiter/gui/mainwindow.h index 8bfccf3..59f259d 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.h +++ b/noncore/net/wellenreiter/gui/mainwindow.h @@ -51,6 +51,7 @@ class WellenreiterMainWindow: public QMainWindow void demoAddStations(); void fileSaveLog(); void fileSaveSession(); + void fileLoadSession(); }; #endif diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index cdc2c48..58a04fb 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -14,12 +14,10 @@ **********************************************************************/ #include "scanlist.h" -#include "scanlistitem.h" #include - #include "manufacturers.h" - +#include #include MScanListView::MScanListView( QWidget* parent, const char* name ) @@ -50,11 +48,23 @@ MScanListView::MScanListView( QWidget* parent, const char* name ) setRootIsDecorated( true ); setAllColumnsShowFocus( true ); }; - + MScanListView::~MScanListView() { }; +void MScanListView::serializeTo( QDataStream& s) const +{ + qDebug( "serializing MScanListView" ); + OListView::serializeTo( s ); +} + +void MScanListView::serializeFrom( QDataStream& s) +{ + qDebug( "serializing MScanListView" ); + OListView::serializeFrom( s ); +} + void MScanListView::setManufacturerDB( ManufacturerDB* manufacturerdb ) { _manufacturerdb = manufacturerdb; @@ -69,9 +79,9 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo (const char*) essid, (const char*) macaddr, channel ); - + // search, if we already have seen this net - + QString s; MScanListItem* network; MScanListItem* item = static_cast ( firstChild() ); @@ -98,9 +108,9 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo 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; @@ -113,7 +123,7 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); item = static_cast ( item->itemBelow() ); } - + if ( item ) { // we have already seen this item, it's a dupe @@ -153,15 +163,101 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo } -void MScanListView::dump( QTextStream& t ) const +#ifdef QWS +#include +#else +#include "resource.h" +#endif + +const int col_type = 0; +const int col_essid = 0; +const int col_sig = 1; +const int col_ap = 2; +const int col_channel = 3; +const int col_wep = 4; +const int col_traffic = 5; +const int col_manuf = 6; +const int col_firstseen = 7; +const int col_lastseen = 8; + +MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, + bool wep, int channel, int signal ) + :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), + _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), + _channel( channel ), _signal( signal ), _beacons( 0 ) { - qDebug( "dumping scanlist..." ); + qDebug( "creating scanlist item" ); + decorateItem( type, essid, macaddr, wep, channel, signal ); +} - QListViewItemIterator it( const_cast( this ) ); - for ( ; it.current(); ++it ) - { - static_cast( it.current() )->dump( t ); - } +MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, + bool wep, int channel, int signal ) + :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) +{ + qDebug( "creating scanlist item" ); + decorateItem( type, essid, macaddr, wep, channel, signal ); +} - qDebug( "dump finished." ); +void MScanListItem::serializeTo( QDataStream& s ) const +{ + OListViewItem::serializeTo( s ); +} + +void MScanListItem::serializeFrom( QDataStream& s ) +{ + OListViewItem::serializeFrom( s ); } + +void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) +{ + qDebug( "decorating scanlist item %s / %s / %s [%d]", + (const char*) type, + (const char*) essid, + (const char*) macaddr, + channel ); + + // set icon for managed or adhoc mode + QString name; + name.sprintf( "wellenreiter/%s", (const char*) type ); + setPixmap( col_type, Resource::loadPixmap( name ) ); + + // set icon for wep (wireless encryption protocol) + if ( wep ) + setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! + + // set channel and signal text + + if ( signal != -1 ) + setText( col_sig, QString::number( signal ) ); + if ( channel != -1 ) + setText( col_channel, QString::number( channel ) ); + + setText( col_firstseen, QTime::currentTime().toString() ); + //setText( col_lastseen, QTime::currentTime().toString() ); + + listView()->triggerUpdate(); + + this->type = type; + _type = type; + _essid = essid; + _macaddr = macaddr; + _channel = channel; + _beacons = 0; + _signal = 0; +} + +void MScanListItem::setManufacturer( const QString& manufacturer ) +{ + setText( col_manuf, manufacturer ); +} + +void MScanListItem::receivedBeacon() +{ + _beacons++; + #ifdef DEBUG + qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons ); + #endif + setText( col_sig, QString::number( _beacons ) ); + setText( col_lastseen, QTime::currentTime().toString() ); +} + diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index f06f251..66c701b 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -32,15 +32,88 @@ class MScanListView: public OListView virtual ~MScanListView(); void setManufacturerDB( ManufacturerDB* manufacturerdb ); - void dump( QTextStream& t ) const; + + virtual void serializeTo( QDataStream& s ) const; + virtual void serializeFrom( QDataStream& s ); public slots: void addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); - + private: ManufacturerDB* _manufacturerdb; }; +//****************************** MScanListItem **************************************************************** + +class MScanListItem: public OListViewItem +{ + public: + MScanListItem::MScanListItem( QListView* parent, + QString type, + QString essid, + QString macaddr, + bool wep, + int channel, + int signal ); + + MScanListItem::MScanListItem( QListViewItem* parent, + QString type, + QString essid, + QString macaddr, + bool wep, + int channel, + int signal ); + + + protected: + virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); + + public: + QString type; + + public: + //const QString& type() { return _type; }; + const QString& essid() { return _essid; }; + const QString& macaddr() { return _macaddr; }; + bool wep() { return _wep; }; + int channel() { return _channel; }; + int signal() { return _signal; }; + int beacons() { return _beacons; }; + + void setSignal( int signal ) { /* TODO */ }; + void receivedBeacon(); + + void setManufacturer( const QString& manufacturer ); + + virtual void serializeTo( QDataStream& s ) const; + virtual void serializeFrom( QDataStream& s ); + + private: + QString _type; + QString _essid; + QString _macaddr; + bool _wep; + int _channel; + int _signal; + int _beacons; + +}; + +//****************************** MScanListViewFactory **************************************************************** + +/* + +class MScanListViewFactory : public OListViewFactory +{ +public: + virtual QListView* listViewFactory(); + virtual QListViewItem* listViewItemFactory( QListView* lv ); + virtual QListViewItem* listViewItemFactory( QListViewItem* lvi ); + virtual void setColumnText( int depth, QListViewItem* lvi, int column, const QString& text ); + virtual void setCustomData( int depth, QListViewItem* lvi, const QString& text ); +} +*/ + #endif diff --git a/noncore/net/wellenreiter/gui/scanlistitem.cpp b/noncore/net/wellenreiter/gui/scanlistitem.cpp deleted file mode 100644 index 4aecd2b..0000000 --- a/noncore/net/wellenreiter/gui/scanlistitem.cpp +++ b/dev/null @@ -1,121 +0,0 @@ -/********************************************************************** -** 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 "scanlistitem.h" -#include -#include -#include - -#ifdef QWS -#include -#else -#include "resource.h" -#endif - -const int col_type = 0; -const int col_essid = 0; -const int col_sig = 1; -const int col_ap = 2; -const int col_channel = 3; -const int col_wep = 4; -const int col_traffic = 5; -const int col_manuf = 6; -const int col_firstseen = 7; -const int col_lastseen = 8; - -MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, - bool wep, int channel, int signal ) - :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), - _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), - _channel( channel ), _signal( signal ), _beacons( 0 ) -{ - qDebug( "creating scanlist item" ); - decorateItem( type, essid, macaddr, wep, channel, signal ); -} - -MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, - bool wep, int channel, int signal ) - :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) -{ - qDebug( "creating scanlist item" ); - decorateItem( type, essid, macaddr, wep, channel, signal ); -} - -void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) -{ - qDebug( "decorating scanlist item %s / %s / %s [%d]", - (const char*) type, - (const char*) essid, - (const char*) macaddr, - channel ); - - // set icon for managed or adhoc mode - QString name; - name.sprintf( "wellenreiter/%s", (const char*) type ); - setPixmap( col_type, Resource::loadPixmap( name ) ); - - // set icon for wep (wireless encryption protocol) - if ( wep ) - setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! - - // set channel and signal text - - if ( signal != -1 ) - setText( col_sig, QString::number( signal ) ); - if ( channel != -1 ) - setText( col_channel, QString::number( channel ) ); - - setText( col_firstseen, QTime::currentTime().toString() ); - //setText( col_lastseen, QTime::currentTime().toString() ); - - listView()->triggerUpdate(); - - this->type = type; - _type = type; - _essid = essid; - _macaddr = macaddr; - _channel = channel; - _beacons = 0; - _signal = 0; -} - -void MScanListItem::setManufacturer( const QString& manufacturer ) -{ - setText( col_manuf, manufacturer ); -} - -void MScanListItem::receivedBeacon() -{ - _beacons++; - #ifdef DEBUG - qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons ); - #endif - setText( col_sig, QString::number( _beacons ) ); - setText( col_lastseen, QTime::currentTime().toString() ); -} - -void MScanListItem::dump( QTextStream& t ) const -{ - qDebug( "dumping scanlistitem at <%d>", this ); - t << "\n"; -} - diff --git a/noncore/net/wellenreiter/gui/scanlistitem.h b/noncore/net/wellenreiter/gui/scanlistitem.h deleted file mode 100644 index 5f6ae40..0000000 --- a/noncore/net/wellenreiter/gui/scanlistitem.h +++ b/dev/null @@ -1,83 +0,0 @@ -/********************************************************************** -** 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. -** -**********************************************************************/ - -#ifndef SCANLISTITEM_H -#define SCANLISTITEM_H - -#include - -#include - -class QString; - -class MScanListItem: public OListViewItem -{ - public: - - MScanListItem::MScanListItem( QListView* parent, - QString type, - QString essid, - QString macaddr, - bool wep, - int channel, - int signal ); - - MScanListItem::MScanListItem( QListViewItem* parent, - QString type, - QString essid, - QString macaddr, - bool wep, - int channel, - int signal ); - - - protected: - - virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); - - public: - - QString type; - - public: - - //const QString& type() { return _type; }; - const QString& essid() { return _essid; }; - const QString& macaddr() { return _macaddr; }; - bool wep() { return _wep; }; - int channel() { return _channel; }; - int signal() { return _signal; }; - int beacons() { return _beacons; }; - - void setSignal( int signal ) { /* TODO */ }; - void receivedBeacon(); - - void setManufacturer( const QString& manufacturer ); - - void dump( QTextStream& t ) const; - - private: - QString _type; - QString _essid; - QString _macaddr; - bool _wep; - int _channel; - int _signal; - int _beacons; - -}; - -#endif - diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 1ccf971..dd8a365 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -123,11 +123,19 @@ Wellenreiter::~Wellenreiter() // no need to delete child widgets, Qt does it all for us delete manufacturerdb; + + // X11-only - Hmm... Closing the socket here segfaults on exit, + // Maybe because the notifier still has a handle to it!? Seems not to + // occur on Qt/Embedded + + #ifdef QWS if ( daemon_fd != -1 ) { qDebug( "closing comm socket" ); close( daemon_fd ); } + #endif + } void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) -- cgit v0.9.0.2