author | mickeyl <mickeyl> | 2004-05-02 20:08:30 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-05-02 20:08:30 (UTC) |
commit | 109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95 (patch) (unidiff) | |
tree | f7484ada7bff7e4f7a91184f6a8e078af6053dca /noncore/net/wellenreiter/gui/packetview.cpp | |
parent | 8602449caa5a055bd5f033e3792d0a59a0b41bfa (diff) | |
download | opie-109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95.zip opie-109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95.tar.gz opie-109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95.tar.bz2 |
PacketViewer improvements:
- expose buffer size through API
- improve packet viewer logic
- display time/date of capture + capture length
Diffstat (limited to 'noncore/net/wellenreiter/gui/packetview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/packetview.cpp | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/noncore/net/wellenreiter/gui/packetview.cpp b/noncore/net/wellenreiter/gui/packetview.cpp index 4df01da..f0f16ff 100644 --- a/noncore/net/wellenreiter/gui/packetview.cpp +++ b/noncore/net/wellenreiter/gui/packetview.cpp | |||
@@ -16,12 +16,13 @@ | |||
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 | 23 | ||
23 | /* QT */ | 24 | /* QT */ |
24 | #include <qfont.h> | 25 | #include <qfont.h> |
25 | #include <qlabel.h> | 26 | #include <qlabel.h> |
26 | #include <qlayout.h> | 27 | #include <qlayout.h> |
27 | #include <qlist.h> | 28 | #include <qlist.h> |
@@ -35,59 +36,85 @@ using namespace Opie::Core; | |||
35 | using namespace Opie::Ui; | 36 | using namespace Opie::Ui; |
36 | 37 | ||
37 | PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) | 38 | PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) |
38 | :QFrame( parent, name, f ) | 39 | :QFrame( parent, name, f ) |
39 | { | 40 | { |
40 | _number = new QSpinBox( this ); | 41 | _number = new QSpinBox( this ); |
41 | _number->setPrefix( "Packet # " ); | 42 | _number->setPrefix( "Pkt# " ); |
42 | _label = new QLabel( this ); | 43 | _label = new QLabel( this ); |
43 | _label->setText( "eth0 2004/03/08 - 00:00:21" ); | ||
44 | |||
45 | _list = new OListView( this ); | 44 | _list = new OListView( this ); |
46 | _list->addColumn( "#" ); | 45 | _list->addColumn( "#" ); |
47 | _list->addColumn( "Packet Type" ); | 46 | _list->addColumn( "Packet Type" ); |
48 | _list->setColumnAlignment( 0, Qt::AlignCenter ); | 47 | _list->setColumnAlignment( 0, Qt::AlignCenter ); |
49 | _list->setColumnAlignment( 1, Qt::AlignLeft ); | 48 | _list->setColumnAlignment( 1, Qt::AlignLeft ); |
50 | _list->setAllColumnsShowFocus( true ); | 49 | _list->setAllColumnsShowFocus( true ); |
51 | _list->setFont( QFont( "Fixed", 8 ) ); | 50 | _list->setFont( QFont( "Fixed", 8 ) ); |
52 | 51 | ||
53 | _hex = new QTextView( this ); | 52 | _hex = new QTextView( this ); |
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 ); | 58 | hb->addWidget( _label, 5 ); |
59 | hb->addWidget( _number ); | 59 | hb->addWidget( _number, 2 ); |
60 | vb->addWidget( _list ); | 60 | vb->addWidget( _list, 3 ); |
61 | vb->addWidget( _hex ); | 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* ) ) ); | ||
67 | |||
68 | clear(); | ||
69 | |||
66 | } | 70 | } |
67 | 71 | ||
68 | void PacketView::add( const OPacket* p ) | 72 | void PacketView::add( const OPacket* p, int size ) |
69 | { | 73 | { |
70 | _packets.append( p ); | 74 | odebug << "PacketView::add() size = " << size << oendl; |
71 | // Add Circular Buffer and check for number of elements here | 75 | if ( size == -1 ) // unlimited buffer |
76 | { | ||
77 | _packets.append( p ); | ||
78 | } | ||
79 | else | ||
80 | // limited buffer, limit = size | ||
81 | if ( _packets.count() < size ) | ||
82 | { | ||
83 | _packets.append( p ); | ||
84 | } | ||
85 | |||
86 | _number->setMinValue( 1 ); | ||
87 | _number->setMaxValue( _packets.count() ); | ||
88 | _number->setValue( _packets.count() ); | ||
72 | } | 89 | } |
73 | 90 | ||
74 | void PacketView::showPacket( int number ) | 91 | void PacketView::showPacket( int number ) |
75 | { | 92 | { |
76 | _list->clear(); | 93 | _list->clear(); |
77 | _hex->setText(""); | 94 | _hex->setText(""); |
78 | const OPacket* p = _packets.at( number ); | 95 | const OPacket* p = _packets.at( number-1 ); |
79 | 96 | ||
80 | if ( p ) | 97 | if ( p ) |
81 | { | 98 | { |
82 | _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 ); | 99 | _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 ); |
83 | _doHexPacket( p ); | 100 | _doHexPacket( p ); |
101 | QDateTime dt; dt.setTime_t( p->timeval().tv_sec ); | ||
102 | _label->setText( dt.toString() + QString().sprintf( " Len=%d", p->len() ) ); | ||
84 | } | 103 | } |
85 | else | 104 | else |
86 | { | 105 | { |
87 | odebug << "D'oh! No packet!" << oendl; | 106 | odebug << "D'oh! No packet!" << oendl; |
107 | } | ||
108 | } | ||
109 | |||
110 | void PacketView::activated( QWidget* w ) | ||
111 | { | ||
112 | if ( ( this == w ) && _packets.count() ) | ||
113 | { | ||
114 | _number->setValue( 1 ); | ||
88 | } | 115 | } |
89 | } | 116 | } |
90 | 117 | ||
91 | void PacketView::_doSubPackets( QObjectList* l, int counter ) | 118 | void PacketView::_doSubPackets( QObjectList* l, int counter ) |
92 | { | 119 | { |
93 | if (!l) return; | 120 | if (!l) return; |
@@ -95,17 +122,20 @@ void PacketView::_doSubPackets( QObjectList* l, int counter ) | |||
95 | while ( o ) | 122 | while ( o ) |
96 | { | 123 | { |
97 | new OListViewItem( _list, QString::number( counter++ ), o->name() ); | 124 | new OListViewItem( _list, QString::number( counter++ ), o->name() ); |
98 | _doSubPackets( const_cast<QObjectList*>( o->children() ), counter ); | 125 | _doSubPackets( const_cast<QObjectList*>( o->children() ), counter ); |
99 | o = l->next(); | 126 | o = l->next(); |
100 | } | 127 | } |
101 | } | 128 | } |
102 | 129 | ||
103 | void PacketView::_doHexPacket( const OPacket* p ) | 130 | void PacketView::_doHexPacket( const OPacket* p ) |
104 | { | 131 | { |
105 | _hex->setText( p->dump( 16 ) ); | 132 | if ( oApp->desktop()->width() > 320 ) |
133 | _hex->setText( p->dump( 16 ) ); | ||
134 | else | ||
135 | _hex->setText( p->dump( 8 ) ); | ||
106 | } | 136 | } |
107 | 137 | ||
108 | const QString PacketView::getLog() const | 138 | const QString PacketView::getLog() const |
109 | { | 139 | { |
110 | } | 140 | } |
111 | 141 | ||
@@ -113,9 +143,9 @@ void PacketView::clear() | |||
113 | { | 143 | { |
114 | _packets.clear(); | 144 | _packets.clear(); |
115 | _number->setMinValue( 0 ); | 145 | _number->setMinValue( 0 ); |
116 | _number->setMaxValue( 0 ); | 146 | _number->setMaxValue( 0 ); |
117 | _label->setText( "---" ); | 147 | _label->setText( "---" ); |
118 | _list->clear(); | 148 | _list->clear(); |
119 | _hex->setText( " <i>-- no Packet available --</i> " ); | 149 | _hex->setText( " <center><i>-- no Packet available --</i></center> " ); |
120 | } | 150 | } |
121 | 151 | ||