summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-05-01 23:06:29 (UTC)
committer mickeyl <mickeyl>2003-05-01 23:06:29 (UTC)
commit49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6 (patch) (unidiff)
tree503a7fe9fba8e297b15c07398fbf2ee215294f1c /libopie2
parent8266da96576ad43a768da37000cef4e8eba000ac (diff)
downloadopie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.zip
opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.gz
opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.bz2
more work on a higher level listview interface
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp26
-rw-r--r--libopie2/opienet/onetwork.h5
-rw-r--r--libopie2/opieui/olistview.cpp93
-rw-r--r--libopie2/opieui/olistview.h35
4 files changed, 148 insertions, 11 deletions
diff --git a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp
index 31bda9d..5ba7b69 100644
--- a/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp
+++ b/libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp
@@ -32,23 +32,49 @@
32 32
33#include "olistviewdemo.h" 33#include "olistviewdemo.h"
34#include <opie2/olistview.h> 34#include <opie2/olistview.h>
35 35
36#include <qstring.h> 36#include <qstring.h>
37#include <qpixmap.h> 37#include <qpixmap.h>
38#include <qlistview.h> 38#include <qlistview.h>
39 39
40OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f ) 40OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f )
41 :QVBox( parent, name, f ) 41 :QVBox( parent, name, f )
42{ 42{
43 lv = new ONamedListView( this ); 43 lv = new ONamedListView( this );
44 lv->setRootIsDecorated( true );
44 lv->addColumns( QStringList::split( ' ', "Column1 Column2 Column3 Column4" ) ); 45 lv->addColumns( QStringList::split( ' ', "Column1 Column2 Column3 Column4" ) );
45 46
46 ONamedListViewItem* item = new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) ); 47 ONamedListViewItem* item = new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
47 item->setText( "Column2", "ModifiedText" ); 48 item->setText( "Column2", "ModifiedText" );
48 item->setText( "Column5", "ThisColumnDoesNotExits" ); 49 item->setText( "Column5", "ThisColumnDoesNotExits" );
50
51 new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
52 new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
53 new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Minni" ) );
54 item = new ONamedListViewItem( lv, QStringList::split( ' ', "XXX YYY ZZZ ***" ) );
55 new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
56 new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
57
58 new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
59 new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
60 new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
61 item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 HereItComes" ) );
62 item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 HereItComesSoon" ) );
63 item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 Mickey" ) );
64
65 if ( lv->find( 3, "Mickey", 3 ) )
66 qDebug( "found Mickey :-)" );
67 else
68 qDebug( "did not found Mickey :-(" );
69
70 if ( lv->find( 3, "Minni", 0 ) )
71 qDebug( "found Minni :-)" );
72 else
73 qDebug( "did not found Minni :-(" );
74
49} 75}
50 76
51OListViewDemo::~OListViewDemo() 77OListViewDemo::~OListViewDemo()
52{ 78{
53} 79}
54 80
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index a29b29d..1b38d02 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -67,24 +67,25 @@ class ONetworkInterface;
67class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
68class OChannelHopper; 68class OChannelHopper;
69class OMonitoringInterface; 69class OMonitoringInterface;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * ONetwork 72 * ONetwork
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/** 75/**
76 * @brief A container class for all network interfaces 76 * @brief A container class for all network interfaces
77 * 77 *
78 * This class provides access to all available network interfaces of your computer. 78 * This class provides access to all available network interfaces of your computer.
79 *
79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 80 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
80 */ 81 */
81class ONetwork : public QObject 82class ONetwork : public QObject
82{ 83{
83 Q_OBJECT 84 Q_OBJECT
84 85
85 public: 86 public:
86 typedef QDict<ONetworkInterface> InterfaceMap; 87 typedef QDict<ONetworkInterface> InterfaceMap;
87 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 88 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
88 89
89 public: 90 public:
90 /** 91 /**
@@ -128,24 +129,25 @@ class ONetwork : public QObject
128 129
129/*====================================================================================== 130/*======================================================================================
130 * ONetworkInterface 131 * ONetworkInterface
131 *======================================================================================*/ 132 *======================================================================================*/
132 133
133/** 134/**
134 * @brief A network interface wrapper. 135 * @brief A network interface wrapper.
135 * 136 *
136 * This class provides a wrapper for a network interface. All the cumbersume details of 137 * This class provides a wrapper for a network interface. All the cumbersume details of
137 * Linux ioctls are hidden under a convenient high-level interface. 138 * Linux ioctls are hidden under a convenient high-level interface.
138 * @warning Most of the setting methods contained in this class require the appropriate 139 * @warning Most of the setting methods contained in this class require the appropriate
139 * process permissions to work. 140 * process permissions to work.
141 *
140 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 142 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
141 */ 143 */
142class ONetworkInterface : public QObject 144class ONetworkInterface : public QObject
143{ 145{
144 friend class OMonitoringInterface; 146 friend class OMonitoringInterface;
145 friend class OCiscoMonitoringInterface; 147 friend class OCiscoMonitoringInterface;
146 friend class OWlanNGMonitoringInterface; 148 friend class OWlanNGMonitoringInterface;
147 friend class OHostAPMonitoringInterface; 149 friend class OHostAPMonitoringInterface;
148 friend class OOrinocoMonitoringInterface; 150 friend class OOrinocoMonitoringInterface;
149 151
150 public: 152 public:
151 /** 153 /**
@@ -237,24 +239,25 @@ class ONetworkInterface : public QObject
237 239
238/*====================================================================================== 240/*======================================================================================
239 * OChannelHopper 241 * OChannelHopper
240 *======================================================================================*/ 242 *======================================================================================*/
241 243
242/** 244/**
243 * @brief A radio frequency channel hopper. 245 * @brief A radio frequency channel hopper.
244 * 246 *
245 * This class provides a channel hopper for radio frequencies. A channel hopper frequently 247 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
246 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. 248 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
247 * This is necessary when in monitoring mode and scanning for other devices, because 249 * This is necessary when in monitoring mode and scanning for other devices, because
248 * the radio frequency hardware can only detect packets sent on the same frequency. 250 * the radio frequency hardware can only detect packets sent on the same frequency.
251 *
249 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 252 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
250 */ 253 */
251class OChannelHopper : public QObject 254class OChannelHopper : public QObject
252{ 255{
253 Q_OBJECT 256 Q_OBJECT
254 257
255 public: 258 public:
256 /** 259 /**
257 * Constructor. 260 * Constructor.
258 */ 261 */
259 OChannelHopper( OWirelessNetworkInterface* ); 262 OChannelHopper( OWirelessNetworkInterface* );
260 /** 263 /**
@@ -296,24 +299,26 @@ class OChannelHopper : public QObject
296 QValueList<int>::Iterator _channel; 299 QValueList<int>::Iterator _channel;
297}; 300};
298 301
299 302
300/*====================================================================================== 303/*======================================================================================
301 * OWirelessNetworkInterface 304 * OWirelessNetworkInterface
302 *======================================================================================*/ 305 *======================================================================================*/
303 306
304/** 307/**
305 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 308 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
306 * 309 *
307 * This class provides a high-level encapsulation of the Linux wireless extension API. 310 * This class provides a high-level encapsulation of the Linux wireless extension API.
311 *
312 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
308 */ 313 */
309class OWirelessNetworkInterface : public ONetworkInterface 314class OWirelessNetworkInterface : public ONetworkInterface
310{ 315{
311 friend class OMonitoringInterface; 316 friend class OMonitoringInterface;
312 friend class OCiscoMonitoringInterface; 317 friend class OCiscoMonitoringInterface;
313 friend class OWlanNGMonitoringInterface; 318 friend class OWlanNGMonitoringInterface;
314 friend class OHostAPMonitoringInterface; 319 friend class OHostAPMonitoringInterface;
315 friend class OOrinocoMonitoringInterface; 320 friend class OOrinocoMonitoringInterface;
316 321
317 friend class OPrivateIOCTL; 322 friend class OPrivateIOCTL;
318 323
319 public: 324 public:
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 8f97cc6..8f290d3 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -457,24 +457,86 @@ ONamedListView::~ONamedListView()
457 457
458 458
459void ONamedListView::addColumns( const QStringList& columns ) 459void ONamedListView::addColumns( const QStringList& columns )
460{ 460{
461 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) 461 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
462 { 462 {
463 qDebug( "adding column %s", (const char*) *it ); 463 qDebug( "adding column %s", (const char*) *it );
464 addColumn( *it ); 464 addColumn( *it );
465 } 465 }
466} 466}
467 467
468 468
469int ONamedListView::findColumn( const QString& text ) const
470{
471 //FIXME: If used excessively, this will slow down performance of updates
472 //FIXME: because of the linear search over all column texts.
473 //FIXME: I will optimize later by using a hash map.
474 for ( int i = 0; i < columns(); ++i )
475 if ( columnText( i ) == text )
476 return i;
477 return -1;
478}
479
480
481ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
482{
483 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
484}
485
486
487ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
488{
489 ONamedListViewItem* result;
490 while ( item && item->text( column ) != text )
491 {
492 qDebug( "checked %s", (const char*) item->text( column ) );
493
494 if ( recurse < 0 || recurse > 0 )
495 {
496 qDebug( "recursion is %d - recursing into...", recurse );
497 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
498 if ( result ) return result;
499 }
500
501
502 item = (ONamedListViewItem*) item->itemBelow();
503 }
504 if ( item && item->text( column ) == text )
505 return item;
506 else
507 return 0;
508}
509
510
511ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
512{
513 int col = findColumn( column );
514 if ( col != -1 )
515 return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
516 else
517 return 0;
518}
519
520
521ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
522{
523 int col = findColumn( column );
524 if ( col != -1 )
525 return find( item, col, text, recurse );
526 else
527 return 0;
528}
529
530
469/*====================================================================================== 531/*======================================================================================
470 * ONamedListViewItem 532 * ONamedListViewItem
471 *======================================================================================*/ 533 *======================================================================================*/
472 534
473ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) 535ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
474 :OListViewItem( parent ) 536 :OListViewItem( parent )
475{ 537{
476 setText( texts ); 538 setText( texts );
477} 539}
478 540
479 541
480ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) 542ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
@@ -511,22 +573,35 @@ void ONamedListViewItem::setText( const QStringList& texts )
511 qDebug( "setting column %d = text %s", col, (const char*) *it ); 573 qDebug( "setting column %d = text %s", col, (const char*) *it );
512 OListViewItem::setText( col++, *it ); 574 OListViewItem::setText( col++, *it );
513 } 575 }
514 576
515} 577}
516 578
517 579
518void ONamedListViewItem::setText( const QString& column, const QString& text ) 580void ONamedListViewItem::setText( const QString& column, const QString& text )
519{ 581{
520 //FIXME: If used excessively, this will slow down performance of updates 582 //FIXME: If used excessively, this will slow down performance of updates
521 //FIXME: because of the linear search over all column texts. 583 //FIXME: because of the linear search over all column texts.
522 //FIXME: I will optimize later by using a hash map. 584 //FIXME: I will optimize later by using a hash map.
523 for ( int i = 0; i < listView()->columns(); ++i ) 585 int col = ( (ONamedListView*) listView() )->findColumn( column );
524 { 586 if ( col != -1 )
525 if ( listView()->columnText( i ) == column ) 587 OListViewItem::setText( col, text );
526 { 588 else
527 OListViewItem::setText( i, text ); 589 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
528 return; 590}
529 } 591
530 } 592
531 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); 593ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
594{
595 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
532} 596}
597
598
599ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
600{
601 int col = ( (ONamedListView*) listView() )->findColumn( column );
602 if ( col != -1 )
603 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
604 else
605 return 0;
606}
607
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index 99770bf..1bbdd5b 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -232,59 +232,79 @@ class OListViewItem: public QListViewItem
232QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); 232QDataStream& operator<<( QDataStream& stream, const OListViewItem& item );
233/** 233/**
234 * @relates QListViewItem 234 * @relates QListViewItem
235 * Reads listview @a item from @a stream and returns a reference to the stream. 235 * Reads listview @a item from @a stream and returns a reference to the stream.
236 */ 236 */
237QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); 237QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
238#endif // QT_NO_DATASTREAM 238#endif // QT_NO_DATASTREAM
239 239
240/*====================================================================================== 240/*======================================================================================
241 * ONamedListView 241 * ONamedListView
242 *======================================================================================*/ 242 *======================================================================================*/
243 243
244class ONamedListViewItem;
245
244/** 246/**
245 * @brief An OListView variant with named columns. 247 * @brief An OListView variant with named columns.
246 * 248 *
247 * This class provides a higher-level interface to the columns in an OListView. 249 * This class provides a higher-level interface to an OListView.
248 * 250 *
249 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 251 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
250 */ 252 */
251class ONamedListView: public OListView 253class ONamedListView: public OListView
252{ 254{
253 public: 255 public:
254 /** 256 /**
255 * Constructor. 257 * Constructor.
256 * 258 *
257 * The parameters @a parent and @a name are handled by 259 * The parameters @a parent and @a name are handled by
258 * @ref OListView, as usual. 260 * @ref OListView, as usual.
259 */ 261 */
260 ONamedListView( QWidget* parent = 0, const char* name = 0 ); 262 ONamedListView( QWidget* parent = 0, const char* name = 0 );
261 /** 263 /**
262 * Destructor. 264 * Destructor.
263 */ 265 */
264 virtual ~ONamedListView(); 266 virtual ~ONamedListView();
265 /** 267 /**
266 * Add a number of @a columns to the listview. 268 * Add a number of @a columns to the listview.
267 */ 269 */
268 virtual void addColumns( const QStringList& columns ); 270 virtual void addColumns( const QStringList& columns );
271 /**
272 * @returns the column index matching to @a text or -1 if not found.
273 */
274 virtual int findColumn( const QString& text ) const;
275 /**
276 * @returns the first item which has a @a text in column @a column.
277 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
278 * <li>set it to 0 to search only among direct childs,
279 * <li>set it to 1 to search direct childs and all 1st order subchilds
280 * <li>set it to -1 for maximum recursion.
281 * </ul>
282 * @sa ONamedListViewItem::find()
283 */
284 virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
285 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
286
287 virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
288 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
269}; 289};
270 290
271/*====================================================================================== 291/*======================================================================================
272 * ONamedListViewItem 292 * ONamedListViewItem
273 *======================================================================================*/ 293 *======================================================================================*/
274 294
275/** 295/**
276 * @brief An OListView variant with named columns. 296 * @brief An OListView variant with named columns.
277 * 297 *
278 * This class provides a higher-level interface to the columns in an OListViewItem. 298 * This class provides a higher-level interface to an OListViewItem.
279 * 299 *
280 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 300 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
281 */ 301 */
282class ONamedListViewItem: public OListViewItem 302class ONamedListViewItem: public OListViewItem
283{ 303{
284 public: 304 public:
285 /** 305 /**
286 * Constructor. Accepts the same parameters as a @ref OListViewItem, 306 * Constructor. Accepts the same parameters as a @ref OListViewItem,
287 * plus a @ref QStringList which holds an arbitrary number of @a texts. 307 * plus a @ref QStringList which holds an arbitrary number of @a texts.
288 */ 308 */
289 ONamedListViewItem( QListView* parent, const QStringList& texts ); 309 ONamedListViewItem( QListView* parent, const QStringList& texts );
290 ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); 310 ONamedListViewItem( QListViewItem* parent, const QStringList& texts );
@@ -295,16 +315,27 @@ class ONamedListViewItem: public OListViewItem
295 */ 315 */
296 virtual ~ONamedListViewItem(); 316 virtual ~ONamedListViewItem();
297 /** 317 /**
298 * Sets the text in column @a column to @a text. 318 * Sets the text in column @a column to @a text.
299 * This method differs from @ref QListViewItem::setText() in that it 319 * This method differs from @ref QListViewItem::setText() in that it
300 * accepts a string as column indicator instead of an int. 320 * accepts a string as column indicator instead of an int.
301 */ 321 */
302 virtual void setText( const QString& column, const QString& text ); 322 virtual void setText( const QString& column, const QString& text );
303 /** 323 /**
304 * Sets a number of @a texts for this item. 324 * Sets a number of @a texts for this item.
305 */ 325 */
306 virtual void setText( const QStringList& texts ); 326 virtual void setText( const QStringList& texts );
327 /**
328 * @returns the first child which has a @a text in column @a column.
329 * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
330 * <li>set it to 0 to search only among direct childs,
331 * <li>set it to 1 to search direct childs and all 1st order subchilds
332 * <li>set it to -1 for maximum recursion.
333 * </ul>
334 * @sa ONamedListView::find()
335 */
336 virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
337 virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
307}; 338};
308 339
309 340
310#endif // OLISTVIEW_H 341#endif // OLISTVIEW_H