-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.cpp | 14 | ||||
-rw-r--r-- | noncore/net/wellenreiter/cornucopia/olistview.h | 26 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 25 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 26 |
4 files changed, 64 insertions, 27 deletions
diff --git a/noncore/net/wellenreiter/cornucopia/olistview.cpp b/noncore/net/wellenreiter/cornucopia/olistview.cpp index f2d3730..c292eb9 100644 --- a/noncore/net/wellenreiter/cornucopia/olistview.cpp +++ b/noncore/net/wellenreiter/cornucopia/olistview.cpp @@ -78,154 +78,159 @@ int OListView::addColumn( const QString& label, int width ) return result; } int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) { int result = QListView::addColumn( iconset, label, width ); #if QT_VERSION > 290 if (m_fullWidth) { header()->setStretchEnabled( false, columns()-2 ); header()->setStretchEnabled( true, columns()-1 ); } #endif return result; } void OListView::removeColumn( int index ) { QListView::removeColumn(index); #if QT_VERSION > 290 if ( m_fullWidth && index == columns() ) { header()->setStretchEnabled( true, columns()-1 ); } #endif } const QColor& OListView::alternateBackground() const { return m_alternateBackground; } void OListView::setAlternateBackground( const QColor &c ) { m_alternateBackground = c; repaint(); } const QPen& OListView::columnSeparator() const { return m_columnSeparator; } void OListView::setColumnSeparator( const QPen& p ) { m_columnSeparator = p; repaint(); } +OListViewItem* OListView::childFactory() +{ + return new OListViewItem( this ); +} + #ifndef QT_NO_DATASTREAM void OListView::serializeTo( QDataStream& s ) const { #warning Caution... the binary format is still under construction... qDebug( "storing OListView..." ); // store number of columns and the labels s << columns(); for ( int i = 0; i < columns(); ++i ) s << columnText( i ); // calculate the number of top-level items to serialize int items = 0; QListViewItem* item = firstChild(); while ( item ) { item = item->nextSibling(); items++; } // store number of items and the items itself s << items; item = firstChild(); for ( int i = 0; i < items; ++i ) { s << *static_cast<OListViewItem*>( item ); item = item->nextSibling(); } qDebug( "OListview stored." ); } void OListView::serializeFrom( QDataStream& s ) { #warning Caution... the binary format is still under construction... qDebug( "loading OListView..." ); int cols; s >> cols; qDebug( "read number of columns = %d", cols ); while ( columns() < cols ) addColumn( QString::null ); for ( int i = 0; i < cols; ++i ) { QString coltext; s >> coltext; qDebug( "read text '%s' for column %d", (const char*) coltext, i ); setColumnText( i, coltext ); } int items; s >> items; qDebug( "read number of items = %d", items ); for ( int i = 0; i < items; ++i ) { - OListViewItem* item = new OListViewItem( this ); + OListViewItem* item = childFactory(); s >> *item; } qDebug( "OListView loaded." ); } QDataStream& operator<<( QDataStream& s, const OListView& lv ) { lv.serializeTo( s ); } QDataStream& operator>>( QDataStream& s, OListView& lv ) { lv.serializeFrom( s ); } #endif // QT_NO_DATASTREAM //****************************** OListViewItem *********************************************************************** OListViewItem::OListViewItem(QListView *parent) : QListViewItem(parent) { init(); } OListViewItem::OListViewItem(QListViewItem *parent) : QListViewItem(parent) { init(); } OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) : QListViewItem(parent, after) { init(); } OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) : QListViewItem(parent, after) { init(); } OListViewItem::OListViewItem(QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5, QString label6, QString label7, QString label8) : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) @@ -292,116 +297,121 @@ bool OListViewItem::isAlternate() { OListViewItem *item; bool previous = true; if (parent()) { item = static_cast<OListViewItem *>(parent()); if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; item = static_cast<OListViewItem *>(parent()->firstChild()); /* if ( !item.inherits( "OListViewItem" ) item = 0; */ } else { item = static_cast<OListViewItem *>(lv->firstChild()); } while(item) { item->m_odd = previous = !previous; item->m_known = true; item = static_cast<OListViewItem *>(item->nextSibling()); /* if (!item.inherits( "OListViewItem" ) ) break; */ } } return m_odd; } void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) { QColorGroup _cg = cg; const QPixmap *pm = listView()->viewport()->backgroundPixmap(); if (pm && !pm->isNull()) { _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); } else if ( isAlternate() ) { _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); } QListViewItem::paintCell( p, _cg, column, width, alignment ); //FIXME: Use styling here! const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); p->setPen( pen ); p->drawLine( width-1, 0, width-1, height() ); } +OListViewItem* OListViewItem::childFactory() +{ + return new OListViewItem( this ); +} + #ifndef QT_NO_DATASTREAM void OListViewItem::serializeTo( QDataStream& s ) const { #warning Caution... the binary format is still under construction... qDebug( "storing OListViewItem..." ); // store item text for ( int i = 0; i < listView()->columns(); ++i ) { s << text( i ); } // calculate the number of children to serialize int items = 0; QListViewItem* item = firstChild(); while ( item ) { item = item->nextSibling(); items++; } // store number of items and the items itself s << items; item = firstChild(); for ( int i = 0; i < items; ++i ) { s << *static_cast<OListViewItem*>( item ); item = item->nextSibling(); } qDebug( "OListviewItem stored." ); } void OListViewItem::serializeFrom( QDataStream& s ) { #warning Caution... the binary format is still under construction... qDebug( "loading OListViewItem..." ); for ( int i = 0; i < listView()->columns(); ++i ) { QString coltext; s >> coltext; qDebug( "read text '%s' for column %d", (const char*) coltext, i ); setText( i, coltext ); } int items; s >> items; qDebug( "read number of items = %d", items ); for ( int i = 0; i < items; ++i ) { - OListViewItem* item = new OListViewItem( this ); + OListViewItem* item = childFactory(); s >> (*item); } qDebug( "OListViewItem loaded." ); } QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) { lvi.serializeTo( s ); } QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) { lvi.serializeFrom( s ); } #endif // QT_NO_DATASTREAM diff --git a/noncore/net/wellenreiter/cornucopia/olistview.h b/noncore/net/wellenreiter/cornucopia/olistview.h index 9df5500..8911e22 100644 --- a/noncore/net/wellenreiter/cornucopia/olistview.h +++ b/noncore/net/wellenreiter/cornucopia/olistview.h @@ -1,237 +1,237 @@ /* This file is part of the Opie Project Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OLISTVIEW_H #define OLISTVIEW_H #include <qcolor.h> #include <qlistview.h> #include <qpen.h> #include <qdatastream.h> -class OListViewFactory; +class OListViewItem; /** * A @ref QListView variant featuring visual and functional enhancements * like an alternate background for odd rows, an autostretch mode * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. * * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> * @short OListView list/tree widget. */ class OListView: public QListView { public: /** * Constructor. * * The parameters @p parent and @p name are handled by * @ref QListView, as usual. */ OListView ( QWidget *parent = 0, const char *name = 0 ); /** * Destructor. */ virtual ~OListView(); /** * Let the last column fit exactly all the available width. */ void setFullWidth( bool fullWidth ); /** * Returns whether the last column is set to fit the available width. */ bool fullWidth() const; /** * Reimplemented for full width support */ virtual int addColumn( const QString& label, int width = -1 ); /** * Reimplemented for full width support */ virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); /** * Reimplemented for full width support */ virtual void removeColumn(int index); /** * sets the alternate background background color. * This only has an effect if the items are OListViewItems * * @param c the color to use for every other item. Set to an invalid * color to disable alternate colors. */ void setAlternateBackground( const QColor &c ); /** * sets the column separator pen. * * @param p the pen used to draw the column separator. */ void setColumnSeparator( const QPen &p ); /** * @return the alternate background color */ const QColor& alternateBackground() const; /** * @return the column separator pen */ const QPen& columnSeparator() const; + /** + * create a list view item as child of this object + * @return the new object + */ + virtual OListViewItem* childFactory(); + #ifndef QT_NO_DATASTREAM /** * serialize this object to a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeTo( QDataStream& s ) const; /** * serialize this object from a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeFrom( QDataStream& s ); #endif - /** - * returns a factory for OListView classes - * creates one on the fly if it doesn't exist - * @return the XML Factory - */ - #ifndef QT_NO_XML - //OListViewFactory* Factory(); - #endif - private: QColor m_alternateBackground; bool m_fullWidth; QPen m_columnSeparator; - #ifndef QT_NO_XML - //OListViewFactory* m_Factory; - #endif }; #ifndef QT_NO_DATASTREAM /** * \relates QListView * Writes a listview to the stream and returns a reference to the stream. */ QDataStream& operator<<( QDataStream& s, const OListView& lv ); /** * \relates QListView * Reads a listview from the stream and returns a reference to the stream. */ QDataStream& operator>>( QDataStream& s, OListView& lv ); #endif // QT_NO_DATASTREAM //****************************** OListViewItem ****************************************************************** class OListViewItem: public QListViewItem { public: OListViewItem( QListView * parent ); OListViewItem( QListViewItem * parent ); OListViewItem( QListView * parent, QListViewItem * after ); OListViewItem( QListViewItem * parent, QListViewItem * after ); OListViewItem( QListView * parent, QString, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null ); OListViewItem( QListViewItem * parent, QString, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null ); OListViewItem( QListView * parent, QListViewItem * after, QString, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null ); OListViewItem( QListViewItem * parent, QListViewItem * after, QString, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null, QString = QString::null ); virtual ~OListViewItem(); const QColor& backgroundColor(); bool isAlternate(); void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); void init(); + /** + * create a list view item as child of this object + * @return the new object + */ + virtual OListViewItem* childFactory(); + #ifndef QT_NO_DATASTREAM /** * serialize this object to or from a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeTo( QDataStream& s ) const; /** * serialize this object to or from a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeFrom( QDataStream& s ); #endif private: bool m_known; bool m_odd; }; #ifndef QT_NO_DATASTREAM /** * \relates QListViewItem * Writes a listview item and all subitems recursively to the stream * and returns a reference to the stream. */ QDataStream& operator<<( QDataStream &s, const OListViewItem& lvi ); /** * \relates QListViewItem * Reads a listview item from the stream and returns a reference to the stream. */ QDataStream& operator>>( QDataStream &s, OListViewItem& lvi ); #endif // QT_NO_DATASTREAM #endif // OLISTVIEW_H diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index 58a04fb..be1245e 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -8,96 +8,101 @@ ** 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 <assert.h> #include "manufacturers.h" #include <qdatetime.h> #include <qtextstream.h> MScanListView::MScanListView( QWidget* parent, const char* name ) :OListView( 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() { }; +OListViewItem* MScanListView::childFactory() +{ + return new MScanListItem( this ); +} + 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; } 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; @@ -153,104 +158,124 @@ void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bo 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 ); } } #ifdef QWS #include <qpe/resource.h> #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 ); } +OListViewItem* MScanListItem::childFactory() +{ + return new MScanListItem( this ); +} + void MScanListItem::serializeTo( QDataStream& s ) const { + qDebug( "serializing MScanListItem" ); OListViewItem::serializeTo( s ); + + s << _type; + s << (Q_UINT8) _wep; } void MScanListItem::serializeFrom( QDataStream& s ) { + qDebug( "serializing MScanListItem" ); OListViewItem::serializeFrom( s ); + + s >> _type; + s >> (Q_UINT8) _wep; + + QString name; + name.sprintf( "wellenreiter/%s", (const char*) _type ); + setPixmap( col_type, Resource::loadPixmap( name ) ); + if ( _wep ) + setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! + listView()->triggerUpdate(); } 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++; diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index 66c701b..222217c 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -1,119 +1,121 @@ /********************************************************************** ** 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 SCANLIST_H #define SCANLIST_H #include <cornucopia/olistview.h> #include <qtextstream.h> class QString; class ManufacturerDB; class MScanListView: public OListView { Q_OBJECT public: MScanListView( QWidget* parent = 0, const char* name = 0 ); virtual ~MScanListView(); void setManufacturerDB( ManufacturerDB* manufacturerdb ); + virtual OListViewItem* childFactory(); 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 ); + QString type = "unknown", + QString essid = "unknown", + QString macaddr = "unknown", + bool wep = false, + int channel = 0, + int signal = 0 ); MScanListItem::MScanListItem( QListViewItem* parent, - QString type, - QString essid, - QString macaddr, - bool wep, - int channel, - int signal ); + QString type = "unknown", + QString essid = "unknown", + QString macaddr = "unknown", + bool wep = false, + int channel = 0, + int signal = 0 ); 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 OListViewItem* childFactory(); 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 |