author | mickeyl <mickeyl> | 2004-05-03 13:21:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-05-03 13:21:26 (UTC) |
commit | 9efa98c49988a41de7613f56818f2e31bb24e22b (patch) (unidiff) | |
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 | |||
@@ -1,151 +1,153 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Wellenreiter II. | 4 | ** This file is part of Wellenreiter II. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "packetview.h" | 16 | #include "packetview.h" |
17 | 17 | ||
18 | /* OPIE */ | 18 | /* OPIE */ |
19 | #include <opie2/opcap.h> | 19 | #include <opie2/opcap.h> |
20 | #include <opie2/odebug.h> | 20 | #include <opie2/odebug.h> |
21 | #include <opie2/olistview.h> | 21 | #include <opie2/olistview.h> |
22 | #include <opie2/oapplication.h> | 22 | #include <opie2/oapplication.h> |
23 | 23 | ||
24 | /* QT */ | 24 | /* QT */ |
25 | #include <qfont.h> | 25 | #include <qfont.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qlist.h> | 28 | #include <qlist.h> |
29 | #include <qlistview.h> | 29 | #include <qlistview.h> |
30 | #include <qobjectlist.h> | 30 | #include <qobjectlist.h> |
31 | #include <qspinbox.h> | 31 | #include <qspinbox.h> |
32 | #include <qtextview.h> | 32 | #include <qtextview.h> |
33 | 33 | ||
34 | using namespace Opie::Net; | 34 | using namespace Opie::Net; |
35 | using namespace Opie::Core; | 35 | using namespace Opie::Core; |
36 | using namespace Opie::Ui; | 36 | using namespace Opie::Ui; |
37 | 37 | ||
38 | PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) | 38 | PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) |
39 | :QFrame( parent, name, f ) | 39 | :QFrame( parent, name, f ) |
40 | { | 40 | { |
41 | _number = new QSpinBox( this ); | 41 | _number = new QSpinBox( this ); |
42 | _number->setPrefix( "Pkt# " ); | 42 | _number->setPrefix( "Pkt# " ); |
43 | _label = new QLabel( this ); | 43 | _label = new QLabel( this ); |
44 | _list = new OListView( this ); | 44 | _list = new OListView( this ); |
45 | _list->addColumn( "#" ); | 45 | _list->addColumn( "#" ); |
46 | _list->addColumn( "Packet Type" ); | 46 | _list->addColumn( "Packet Type" ); |
47 | _list->setColumnAlignment( 0, Qt::AlignCenter ); | 47 | _list->setColumnAlignment( 0, Qt::AlignCenter ); |
48 | _list->setColumnAlignment( 1, Qt::AlignLeft ); | 48 | _list->setColumnAlignment( 1, Qt::AlignLeft ); |
49 | _list->setAllColumnsShowFocus( true ); | 49 | _list->setAllColumnsShowFocus( true ); |
50 | _list->setFont( QFont( "Fixed", 8 ) ); | 50 | _list->setFont( QFont( "Fixed", 8 ) ); |
51 | 51 | ||
52 | _hex = new QTextView( this ); | 52 | _hex = new QTextView( this ); |
53 | _hex->setMargin( 0 ); | 53 | _hex->setMargin( 0 ); |
54 | _hex->setFont( QFont( "Fixed", 8 ) ); | 54 | _hex->setFont( QFont( "Fixed", 8 ) ); |
55 | 55 | ||
56 | QVBoxLayout* vb = new QVBoxLayout( this, 2, 2 ); | 56 | QVBoxLayout* vb = new QVBoxLayout( this, 2, 2 ); |
57 | QHBoxLayout* hb = new QHBoxLayout( vb, 2 ); | 57 | QHBoxLayout* hb = new QHBoxLayout( vb, 2 ); |
58 | hb->addWidget( _label, 5 ); | 58 | hb->addWidget( _label, 5 ); |
59 | hb->addWidget( _number, 2 ); | 59 | hb->addWidget( _number, 2 ); |
60 | vb->addWidget( _list, 3 ); | 60 | vb->addWidget( _list, 3 ); |
61 | vb->addWidget( _hex, 4 ); // allow a bit (4/3) more space | 61 | vb->addWidget( _hex, 4 ); // allow a bit (4/3) more space |
62 | 62 | ||
63 | _packets.setAutoDelete( true ); | 63 | _packets.setAutoDelete( true ); |
64 | 64 | ||
65 | connect( _number, SIGNAL( valueChanged( int ) ), this, SLOT( showPacket( int ) ) ); | 65 | connect( _number, SIGNAL( valueChanged( int ) ), this, SLOT( showPacket( int ) ) ); |
66 | connect( parent, SIGNAL( currentChanged( QWidget *) ), this, SLOT( activated( QWidget* ) ) ); | 66 | connect( parent, SIGNAL( currentChanged( QWidget *) ), this, SLOT( activated( QWidget* ) ) ); |
67 | 67 | ||
68 | clear(); | 68 | clear(); |
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | void PacketView::add( const OPacket* p, int size ) | 72 | void PacketView::add( const OPacket* p, int size ) |
73 | { | 73 | { |
74 | odebug << "PacketView::add() size = " << size << oendl; | 74 | odebug << "PacketView::add() size = " << size << oendl; |
75 | if ( size == -1 ) // unlimited buffer | 75 | if ( size == -1 ) // unlimited buffer |
76 | { | 76 | { |
77 | _packets.append( p ); | 77 | _packets.append( p ); |
78 | } | 78 | } |
79 | else | 79 | else |
80 | // limited buffer, limit = size | 80 | { // limited buffer, limit = size |
81 | if ( _packets.count() < size ) | 81 | while ( _packets.count() >= size ) |
82 | { | 82 | { |
83 | _packets.removeFirst(); | ||
84 | } | ||
83 | _packets.append( p ); | 85 | _packets.append( p ); |
84 | } | 86 | } |
85 | 87 | ||
86 | _number->setMinValue( 1 ); | 88 | _number->setMinValue( 1 ); |
87 | _number->setMaxValue( _packets.count() ); | 89 | _number->setMaxValue( _packets.count() ); |
88 | _number->setValue( _packets.count() ); | 90 | _number->setValue( _packets.count() ); |
89 | } | 91 | } |
90 | 92 | ||
91 | void PacketView::showPacket( int number ) | 93 | void PacketView::showPacket( int number ) |
92 | { | 94 | { |
93 | _list->clear(); | 95 | _list->clear(); |
94 | _hex->setText(""); | 96 | _hex->setText(""); |
95 | const OPacket* p = _packets.at( number-1 ); | 97 | const OPacket* p = _packets.at( number-1 ); |
96 | 98 | ||
97 | if ( p ) | 99 | if ( p ) |
98 | { | 100 | { |
99 | _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 ); | 101 | _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 ); |
100 | _doHexPacket( p ); | 102 | _doHexPacket( p ); |
101 | QDateTime dt; dt.setTime_t( p->timeval().tv_sec ); | 103 | QDateTime dt; dt.setTime_t( p->timeval().tv_sec ); |
102 | _label->setText( dt.toString() + QString().sprintf( " Len=%d", p->len() ) ); | 104 | _label->setText( dt.toString() + QString().sprintf( " Len=%d", p->len() ) ); |
103 | } | 105 | } |
104 | else | 106 | else |
105 | { | 107 | { |
106 | odebug << "D'oh! No packet!" << oendl; | 108 | odebug << "D'oh! No packet!" << oendl; |
107 | } | 109 | } |
108 | } | 110 | } |
109 | 111 | ||
110 | void PacketView::activated( QWidget* w ) | 112 | void PacketView::activated( QWidget* w ) |
111 | { | 113 | { |
112 | if ( ( this == w ) && _packets.count() ) | 114 | if ( ( this == w ) && _packets.count() ) |
113 | { | 115 | { |
114 | _number->setValue( 1 ); | 116 | _number->setValue( 1 ); |
115 | } | 117 | } |
116 | } | 118 | } |
117 | 119 | ||
118 | void PacketView::_doSubPackets( QObjectList* l, int counter ) | 120 | void PacketView::_doSubPackets( QObjectList* l, int counter ) |
119 | { | 121 | { |
120 | if (!l) return; | 122 | if (!l) return; |
121 | QObject* o = l->first(); | 123 | QObject* o = l->first(); |
122 | while ( o ) | 124 | while ( o ) |
123 | { | 125 | { |
124 | new OListViewItem( _list, QString::number( counter++ ), o->name() ); | 126 | new OListViewItem( _list, QString::number( counter++ ), o->name() ); |
125 | _doSubPackets( const_cast<QObjectList*>( o->children() ), counter ); | 127 | _doSubPackets( const_cast<QObjectList*>( o->children() ), counter ); |
126 | o = l->next(); | 128 | o = l->next(); |
127 | } | 129 | } |
128 | } | 130 | } |
129 | 131 | ||
130 | void PacketView::_doHexPacket( const OPacket* p ) | 132 | void PacketView::_doHexPacket( const OPacket* p ) |
131 | { | 133 | { |
132 | if ( oApp->desktop()->width() > 320 ) | 134 | if ( oApp->desktop()->width() > 320 ) |
133 | _hex->setText( p->dump( 16 ) ); | 135 | _hex->setText( p->dump( 16 ) ); |
134 | else | 136 | else |
135 | _hex->setText( p->dump( 8 ) ); | 137 | _hex->setText( p->dump( 8 ) ); |
136 | } | 138 | } |
137 | 139 | ||
138 | const QString PacketView::getLog() const | 140 | const QString PacketView::getLog() const |
139 | { | 141 | { |
140 | } | 142 | } |
141 | 143 | ||
142 | void PacketView::clear() | 144 | void PacketView::clear() |
143 | { | 145 | { |
144 | _packets.clear(); | 146 | _packets.clear(); |
145 | _number->setMinValue( 0 ); | 147 | _number->setMinValue( 0 ); |
146 | _number->setMaxValue( 0 ); | 148 | _number->setMaxValue( 0 ); |
147 | _label->setText( "---" ); | 149 | _label->setText( "---" ); |
148 | _list->clear(); | 150 | _list->clear(); |
149 | _hex->setText( " <center><i>-- no Packet available --</i></center> " ); | 151 | _hex->setText( " <center><i>-- no Packet available --</i></center> " ); |
150 | } | 152 | } |
151 | 153 | ||