summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
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
@@ -38,17 +38,43 @@
#include <qlistview.h>
OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f )
:QVBox( parent, name, f )
{
lv = new ONamedListView( this );
+ lv->setRootIsDecorated( true );
lv->addColumns( QStringList::split( ' ', "Column1 Column2 Column3 Column4" ) );
ONamedListViewItem* item = new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
item->setText( "Column2", "ModifiedText" );
item->setText( "Column5", "ThisColumnDoesNotExits" );
+
+ new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
+ new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
+ new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Minni" ) );
+ item = new ONamedListViewItem( lv, QStringList::split( ' ', "XXX YYY ZZZ ***" ) );
+ new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
+ new ONamedListViewItem( lv, QStringList::split( ' ', "Text1 Text2 Text3 Text4" ) );
+
+ new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
+ new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
+ new ONamedListViewItem( item, QStringList::split( ' ', "SubText1 Text2 Text3 Text4" ) );
+ item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 HereItComes" ) );
+ item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 HereItComesSoon" ) );
+ item = new ONamedListViewItem( item, QStringList::split( ' ', "Text1 Text2 Text3 Mickey" ) );
+
+ if ( lv->find( 3, "Mickey", 3 ) )
+ qDebug( "found Mickey :-)" );
+ else
+ qDebug( "did not found Mickey :-(" );
+
+ if ( lv->find( 3, "Minni", 0 ) )
+ qDebug( "found Minni :-)" );
+ else
+ qDebug( "did not found Minni :-(" );
+
}
OListViewDemo::~OListViewDemo()
{
}
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
@@ -73,12 +73,13 @@ class OMonitoringInterface;
*======================================================================================*/
/**
* @brief A container class for all network interfaces
*
* This class provides access to all available network interfaces of your computer.
+ *
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class ONetwork : public QObject
{
Q_OBJECT
@@ -134,12 +135,13 @@ class ONetwork : public QObject
* @brief A network interface wrapper.
*
* This class provides a wrapper for a network interface. All the cumbersume details of
* Linux ioctls are hidden under a convenient high-level interface.
* @warning Most of the setting methods contained in this class require the appropriate
* process permissions to work.
+ *
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class ONetworkInterface : public QObject
{
friend class OMonitoringInterface;
friend class OCiscoMonitoringInterface;
@@ -243,12 +245,13 @@ class ONetworkInterface : public QObject
* @brief A radio frequency channel hopper.
*
* This class provides a channel hopper for radio frequencies. A channel hopper frequently
* changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
* This is necessary when in monitoring mode and scanning for other devices, because
* the radio frequency hardware can only detect packets sent on the same frequency.
+ *
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class OChannelHopper : public QObject
{
Q_OBJECT
@@ -302,12 +305,14 @@ class OChannelHopper : public QObject
*======================================================================================*/
/**
* @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
*
* This class provides a high-level encapsulation of the Linux wireless extension API.
+ *
+ * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class OWirelessNetworkInterface : public ONetworkInterface
{
friend class OMonitoringInterface;
friend class OCiscoMonitoringInterface;
friend class OWlanNGMonitoringInterface;
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
@@ -463,12 +463,74 @@ void ONamedListView::addColumns( const QStringList& columns )
qDebug( "adding column %s", (const char*) *it );
addColumn( *it );
}
}
+int ONamedListView::findColumn( const QString& text ) const
+{
+ //FIXME: If used excessively, this will slow down performance of updates
+ //FIXME: because of the linear search over all column texts.
+ //FIXME: I will optimize later by using a hash map.
+ for ( int i = 0; i < columns(); ++i )
+ if ( columnText( i ) == text )
+ return i;
+ return -1;
+}
+
+
+ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
+{
+ return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
+}
+
+
+ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
+{
+ ONamedListViewItem* result;
+ while ( item && item->text( column ) != text )
+ {
+ qDebug( "checked %s", (const char*) item->text( column ) );
+
+ if ( recurse < 0 || recurse > 0 )
+ {
+ qDebug( "recursion is %d - recursing into...", recurse );
+ result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
+ if ( result ) return result;
+ }
+
+
+ item = (ONamedListViewItem*) item->itemBelow();
+ }
+ if ( item && item->text( column ) == text )
+ return item;
+ else
+ return 0;
+}
+
+
+ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
+{
+ int col = findColumn( column );
+ if ( col != -1 )
+ return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
+ else
+ return 0;
+}
+
+
+ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
+{
+ int col = findColumn( column );
+ if ( col != -1 )
+ return find( item, col, text, recurse );
+ else
+ return 0;
+}
+
+
/*======================================================================================
* ONamedListViewItem
*======================================================================================*/
ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
:OListViewItem( parent )
@@ -517,16 +579,29 @@ void ONamedListViewItem::setText( const QStringList& texts )
void ONamedListViewItem::setText( const QString& column, const QString& text )
{
//FIXME: If used excessively, this will slow down performance of updates
//FIXME: because of the linear search over all column texts.
//FIXME: I will optimize later by using a hash map.
- for ( int i = 0; i < listView()->columns(); ++i )
- {
- if ( listView()->columnText( i ) == column )
- {
- OListViewItem::setText( i, text );
- return;
- }
- }
- qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
+ int col = ( (ONamedListView*) listView() )->findColumn( column );
+ if ( col != -1 )
+ OListViewItem::setText( col, text );
+ else
+ qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
+}
+
+
+ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
+{
+ return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
}
+
+
+ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
+{
+ int col = ( (ONamedListView*) listView() )->findColumn( column );
+ if ( col != -1 )
+ return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
+ else
+ return 0;
+}
+
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
@@ -238,16 +238,18 @@ QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
#endif // QT_NO_DATASTREAM
/*======================================================================================
* ONamedListView
*======================================================================================*/
+class ONamedListViewItem;
+
/**
* @brief An OListView variant with named columns.
*
- * This class provides a higher-level interface to the columns in an OListView.
+ * This class provides a higher-level interface to an OListView.
*
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class ONamedListView: public OListView
{
public:
@@ -263,22 +265,40 @@ class ONamedListView: public OListView
*/
virtual ~ONamedListView();
/**
* Add a number of @a columns to the listview.
*/
virtual void addColumns( const QStringList& columns );
+ /**
+ * @returns the column index matching to @a text or -1 if not found.
+ */
+ virtual int findColumn( const QString& text ) const;
+ /**
+ * @returns the first item which has a @a text in column @a column.
+ * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
+ * <li>set it to 0 to search only among direct childs,
+ * <li>set it to 1 to search direct childs and all 1st order subchilds
+ * <li>set it to -1 for maximum recursion.
+ * </ul>
+ * @sa ONamedListViewItem::find()
+ */
+ virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
+ virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
+
+ virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
+ virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
};
/*======================================================================================
* ONamedListViewItem
*======================================================================================*/
/**
* @brief An OListView variant with named columns.
*
- * This class provides a higher-level interface to the columns in an OListViewItem.
+ * This class provides a higher-level interface to an OListViewItem.
*
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class ONamedListViewItem: public OListViewItem
{
public:
@@ -301,10 +321,21 @@ class ONamedListViewItem: public OListViewItem
*/
virtual void setText( const QString& column, const QString& text );
/**
* Sets a number of @a texts for this item.
*/
virtual void setText( const QStringList& texts );
+ /**
+ * @returns the first child which has a @a text in column @a column.
+ * Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
+ * <li>set it to 0 to search only among direct childs,
+ * <li>set it to 1 to search direct childs and all 1st order subchilds
+ * <li>set it to -1 for maximum recursion.
+ * </ul>
+ * @sa ONamedListView::find()
+ */
+ virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
+ virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
};
#endif // OLISTVIEW_H