author | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
commit | 49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6 (patch) (side-by-side diff) | |
tree | 503a7fe9fba8e297b15c07398fbf2ee215294f1c /libopie2 | |
parent | 8266da96576ad43a768da37000cef4e8eba000ac (diff) | |
download | opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.zip opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.gz opie-49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6.tar.bz2 |
more work on a higher level listview interface
-rw-r--r-- | libopie2/examples/opieui/olistviewdemo/olistviewdemo.cpp | 26 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 5 | ||||
-rw-r--r-- | libopie2/opieui/olistview.cpp | 93 | ||||
-rw-r--r-- | libopie2/opieui/olistview.h | 35 |
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 @@ -1,54 +1,80 @@ /* This file is part of the Opie Project Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "olistviewdemo.h" #include <opie2/olistview.h> #include <qstring.h> #include <qpixmap.h> #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 @@ -31,157 +31,159 @@ */ #ifndef ONETWORK_H #define ONETWORK_H /* OPIE */ #include <opie2/onetutils.h> /* QT */ #include <qvaluelist.h> #include <qdict.h> #include <qmap.h> #include <qobject.h> #include <qhostaddress.h> #ifndef IFNAMSIZ #define IFNAMSIZ 16 #endif #ifndef IW_MAX_PRIV_DEF #define IW_MAX_PRIV_DEF 128 #endif // ML: Yeah, I hate to include kernel headers, but it's necessary here // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> // ML: which conflicts with the user header <net/if.h> // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> // ML: I will drop Jean a mail on that subject #include <net/if.h> #define _LINUX_IF_H #include <linux/wireless.h> class ONetworkInterface; class OWirelessNetworkInterface; class OChannelHopper; class OMonitoringInterface; /*====================================================================================== * ONetwork *======================================================================================*/ /** * @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 public: typedef QDict<ONetworkInterface> InterfaceMap; typedef QDictIterator<ONetworkInterface> InterfaceIterator; public: /** * @returns the number of available interfaces */ int count() const; /** * @returns a pointer to the (one and only) @ref ONetwork instance. */ static ONetwork* instance(); /** * @returns an iterator usable for iterating through all network interfaces. */ InterfaceIterator iterator() const; /** * @returns true, if the @a interface supports the wireless extension protocol. */ // FIXME QString? -zecke bool isWirelessInterface( const char* interface ) const; /** * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found * @see ONetworkInterface */ // FIXME: const QString& is prefered over QString!!! -zecke ONetworkInterface* interface( const QString& interface ) const; /** * @internal Rebuild the internal interface database * @note Sometimes it might be useful to call this from client code, * e.g. after issuing a cardctl insert */ void synchronize(); protected: ONetwork(); private: static ONetwork* _instance; InterfaceMap _interfaces; }; /*====================================================================================== * ONetworkInterface *======================================================================================*/ /** * @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; friend class OWlanNGMonitoringInterface; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; public: /** * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, * but access them via @ref ONetwork::interface(). */ ONetworkInterface( QObject* parent, const char* name ); /** * Destructor. */ virtual ~ONetworkInterface(); /** * Associates a @a monitoring interface with this network interface. * @note This is currently only useful with @ref OWirelessNetworkInterface objects. */ void setMonitoring( OMonitoringInterface* monitoring ); /** * @returns the currently associated monitoring interface or 0, if no monitoring is associated. */ OMonitoringInterface* monitoring() const; /** * Setting an interface to promiscuous mode enables the device to receive * all packets on the shared medium - as opposed to packets which are addressed to this interface. */ bool setPromiscuousMode( bool ); /** * @returns true if the interface is set to promiscuous mode. */ bool promiscuousMode() const; /** * Setting an interface to up enables it to receive packets. */ bool setUp( bool ); /** * @returns true if the interface is up. */ bool isUp() const; /** * @returns true if the interface is a loopback interface. @@ -201,155 +203,158 @@ class ONetworkInterface : public QObject QString ipV4Address() const; //TODO: make this return an OHostAddress /** * Associate the MAC address @a addr with the interface. * @note It can be necessary to shut down the interface prior to calling this method. * @warning This is not supported by all drivers. */ void setMacAddress( const OMacAddress& addr ); /** * @returns the MAC address associated with the interface. */ OMacAddress macAddress() const; /** * Associate the IPv4 @a netmask with the interface. */ void setIPV4Netmask( const QHostAddress& netmask ); /** * @returns the IPv4 netmask associated with the interface. */ QString ipV4Netmask() const; //TODO: make this return an OHostAddress /** * @returns the data link type currently associated with the interface. * @see #include <net/if_arp.h> for possible values. */ int dataLinkType() const; protected: const int _sfd; mutable ifreq _ifr; OMonitoringInterface* _mon; protected: struct ifreq& ifr() const; virtual void init(); bool ioctl( int call ) const; bool ioctl( int call, struct ifreq& ) const; }; /*====================================================================================== * OChannelHopper *======================================================================================*/ /** * @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 public: /** * Constructor. */ OChannelHopper( OWirelessNetworkInterface* ); /** * Destructor. */ virtual ~OChannelHopper(); /** * @returns true, if the channel hopper is hopping channels */ bool isActive() const; /** * @returns the last hopped channel */ int channel() const; /** * Set the channel hopping @a interval. * An interval of 0 deactivates the channel hopper. */ void setInterval( int interval ); /** * @returns the channel hopping interval */ int interval() const; signals: /** * This signal is emitted right after the channel hopper performed a hop */ void hopped( int ); protected: virtual void timerEvent( QTimerEvent* ); private: OWirelessNetworkInterface* _iface; int _interval; int _tid; QValueList<int> _channels; QValueList<int>::Iterator _channel; }; /*====================================================================================== * OWirelessNetworkInterface *======================================================================================*/ /** * @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; friend class OHostAPMonitoringInterface; friend class OOrinocoMonitoringInterface; friend class OPrivateIOCTL; public: /** * Constructor. */ OWirelessNetworkInterface( QObject* parent, const char* name ); /** * Destructor. */ virtual ~OWirelessNetworkInterface(); /** * Setting the @a channel of the interface changes the radio frequency (RF) * of the corresponding wireless network device. */ virtual void setChannel( int channel ) const; /** * @returns the channel index of the current radio frequency. */ virtual int channel() const; /** * @returns the current radio frequency (in MHz). */ virtual double frequency() const; /** * @returns the number of radio frequency channels for the * corresponding wireless network device. * @note European devices usually have 14 channels, while American typically feature 11 channels. */ virtual int channels() const; /** * Set the IEEE 802.11 operation @a mode. * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master * @warning Not all drivers support the all modes. * @note You might have to change the SSID to get the operation mode change into effect. */ virtual void setMode( const QString& mode ); /** * @returns the current IEEE 802.11 operation mode. 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 @@ -421,112 +421,187 @@ void OListViewItem::serializeFrom( QDataStream& s ) for ( int i = 0; i < items; ++i ) { OListViewItem* item = childFactory(); s >> (*item); } qDebug( "OListViewItem loaded." ); } QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) { lvi.serializeTo( s ); } QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) { lvi.serializeFrom( s ); } #endif // QT_NO_DATASTREAM /*====================================================================================== * ONamedListView *======================================================================================*/ ONamedListView::ONamedListView( QWidget *parent, const char *name ) :OListView( parent, name ) { } ONamedListView::~ONamedListView() { } void ONamedListView::addColumns( const QStringList& columns ) { for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) { 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 ) { setText( texts ); } ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) :OListViewItem( parent ) { setText( texts ); } ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) :OListViewItem( parent, after ) { setText( texts ); } ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) :OListViewItem( parent, after ) { setText( texts ); } ONamedListViewItem::~ONamedListViewItem() { } void ONamedListViewItem::setText( const QStringList& texts ) { int col = 0; for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) { qDebug( "setting column %d = text %s", col, (const char*) *it ); OListViewItem::setText( col++, *it ); } } 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 @@ -196,115 +196,146 @@ class OListViewItem: public QListViewItem */ void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); /** * Perform object initialization. */ void init(); /** * create a list view item as child of this object * @returns the new object */ virtual OListViewItem* childFactory(); #ifndef QT_NO_DATASTREAM /** * serialize this object to or from a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeTo( QDataStream& s ) const; /** * serialize this object to or from a @ref QDataStream * @param s the stream used to serialize this object. */ virtual void serializeFrom( QDataStream& s ); #endif private: bool m_known; bool m_odd; }; #ifndef QT_NO_DATASTREAM /** * @relates QListViewItem * Writes listview @a item and all subitems recursively to @a stream * and returns a reference to the stream. */ QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); /** * @relates QListViewItem * Reads listview @a item from @a stream and returns a reference to the stream. */ 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: /** * Constructor. * * The parameters @a parent and @a name are handled by * @ref OListView, as usual. */ ONamedListView( QWidget* parent = 0, const char* name = 0 ); /** * Destructor. */ 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: /** * Constructor. Accepts the same parameters as a @ref OListViewItem, * plus a @ref QStringList which holds an arbitrary number of @a texts. */ ONamedListViewItem( QListView* parent, const QStringList& texts ); ONamedListViewItem( QListViewItem* parent, const QStringList& texts ); ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); /** * Destructor. */ virtual ~ONamedListViewItem(); /** * Sets the text in column @a column to @a text. * This method differs from @ref QListViewItem::setText() in that it * accepts a string as column indicator instead of an int. */ 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 |