author | mickeyl <mickeyl> | 2004-05-03 13:21:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-05-03 13:21:26 (UTC) |
commit | 9efa98c49988a41de7613f56818f2e31bb24e22b (patch) (side-by-side diff) | |
tree | 62e5f95df7302eeef9a03681b708ae80c3d78d55 | |
parent | 0490226f4ed54fdeef5578255594830659a8d3bd (diff) | |
download | opie-9efa98c49988a41de7613f56818f2e31bb24e22b.zip opie-9efa98c49988a41de7613f56818f2e31bb24e22b.tar.gz opie-9efa98c49988a41de7613f56818f2e31bb24e22b.tar.bz2 |
honor limited buffer size, if set
-rw-r--r-- | noncore/net/wellenreiter/gui/packetview.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/gui/packetview.cpp b/noncore/net/wellenreiter/gui/packetview.cpp index f0f16ff..69438fa 100644 --- a/noncore/net/wellenreiter/gui/packetview.cpp +++ b/noncore/net/wellenreiter/gui/packetview.cpp @@ -32,99 +32,101 @@ #include <qtextview.h> using namespace Opie::Net; using namespace Opie::Core; using namespace Opie::Ui; PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) :QFrame( parent, name, f ) { _number = new QSpinBox( this ); _number->setPrefix( "Pkt# " ); _label = new QLabel( this ); _list = new OListView( this ); _list->addColumn( "#" ); _list->addColumn( "Packet Type" ); _list->setColumnAlignment( 0, Qt::AlignCenter ); _list->setColumnAlignment( 1, Qt::AlignLeft ); _list->setAllColumnsShowFocus( true ); _list->setFont( QFont( "Fixed", 8 ) ); _hex = new QTextView( this ); _hex->setMargin( 0 ); _hex->setFont( QFont( "Fixed", 8 ) ); QVBoxLayout* vb = new QVBoxLayout( this, 2, 2 ); QHBoxLayout* hb = new QHBoxLayout( vb, 2 ); hb->addWidget( _label, 5 ); hb->addWidget( _number, 2 ); vb->addWidget( _list, 3 ); vb->addWidget( _hex, 4 ); // allow a bit (4/3) more space _packets.setAutoDelete( true ); connect( _number, SIGNAL( valueChanged( int ) ), this, SLOT( showPacket( int ) ) ); connect( parent, SIGNAL( currentChanged( QWidget *) ), this, SLOT( activated( QWidget* ) ) ); clear(); } void PacketView::add( const OPacket* p, int size ) { odebug << "PacketView::add() size = " << size << oendl; if ( size == -1 ) // unlimited buffer { _packets.append( p ); } else - // limited buffer, limit = size - if ( _packets.count() < size ) - { + { // limited buffer, limit = size + while ( _packets.count() >= size ) + { + _packets.removeFirst(); + } _packets.append( p ); } _number->setMinValue( 1 ); _number->setMaxValue( _packets.count() ); _number->setValue( _packets.count() ); } void PacketView::showPacket( int number ) { _list->clear(); _hex->setText(""); const OPacket* p = _packets.at( number-1 ); if ( p ) { _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 ); _doHexPacket( p ); QDateTime dt; dt.setTime_t( p->timeval().tv_sec ); _label->setText( dt.toString() + QString().sprintf( " Len=%d", p->len() ) ); } else { odebug << "D'oh! No packet!" << oendl; } } void PacketView::activated( QWidget* w ) { if ( ( this == w ) && _packets.count() ) { _number->setValue( 1 ); } } void PacketView::_doSubPackets( QObjectList* l, int counter ) { if (!l) return; QObject* o = l->first(); while ( o ) { new OListViewItem( _list, QString::number( counter++ ), o->name() ); _doSubPackets( const_cast<QObjectList*>( o->children() ), counter ); o = l->next(); } } void PacketView::_doHexPacket( const OPacket* p ) |