author | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-01 23:06:29 (UTC) |
commit | 49dfb55bd22f5027fcbcbc55648efd4bce6c8fd6 (patch) (unidiff) | |
tree | 503a7fe9fba8e297b15c07398fbf2ee215294f1c | |
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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) 2003 Michael 'Mickey' Lauer | 4 | Copyright (C) 2003 Michael 'Mickey' Lauer |
5 | <mickey@tm.informatik.uni-frankfurt.de> | 5 | <mickey@tm.informatik.uni-frankfurt.de> |
6 | =. | 6 | =. |
7 | .=l. | 7 | .=l. |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
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 | ||
40 | OListViewDemo::OListViewDemo( QWidget* parent, const char* name, WFlags f ) | 40 | OListViewDemo::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 | ||
51 | OListViewDemo::~OListViewDemo() | 77 | OListViewDemo::~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 | |||
@@ -1,533 +1,538 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | 38 | ||
39 | #include <opie2/onetutils.h> | 39 | #include <opie2/onetutils.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | 42 | ||
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | #include <qdict.h> | 44 | #include <qdict.h> |
45 | #include <qmap.h> | 45 | #include <qmap.h> |
46 | #include <qobject.h> | 46 | #include <qobject.h> |
47 | #include <qhostaddress.h> | 47 | #include <qhostaddress.h> |
48 | 48 | ||
49 | #ifndef IFNAMSIZ | 49 | #ifndef IFNAMSIZ |
50 | #define IFNAMSIZ 16 | 50 | #define IFNAMSIZ 16 |
51 | #endif | 51 | #endif |
52 | #ifndef IW_MAX_PRIV_DEF | 52 | #ifndef IW_MAX_PRIV_DEF |
53 | #define IW_MAX_PRIV_DEF 128 | 53 | #define IW_MAX_PRIV_DEF 128 |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
58 | // ML: which conflicts with the user header <net/if.h> | 58 | // ML: which conflicts with the user header <net/if.h> |
59 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> | 59 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> |
60 | // ML: I will drop Jean a mail on that subject | 60 | // ML: I will drop Jean a mail on that subject |
61 | 61 | ||
62 | #include <net/if.h> | 62 | #include <net/if.h> |
63 | #define _LINUX_IF_H | 63 | #define _LINUX_IF_H |
64 | #include <linux/wireless.h> | 64 | #include <linux/wireless.h> |
65 | 65 | ||
66 | class ONetworkInterface; | 66 | class ONetworkInterface; |
67 | class OWirelessNetworkInterface; | 67 | class OWirelessNetworkInterface; |
68 | class OChannelHopper; | 68 | class OChannelHopper; |
69 | class OMonitoringInterface; | 69 | class 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 | */ |
81 | class ONetwork : public QObject | 82 | class 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 | /** |
91 | * @returns the number of available interfaces | 92 | * @returns the number of available interfaces |
92 | */ | 93 | */ |
93 | int count() const; | 94 | int count() const; |
94 | /** | 95 | /** |
95 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 96 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
96 | */ | 97 | */ |
97 | static ONetwork* instance(); | 98 | static ONetwork* instance(); |
98 | /** | 99 | /** |
99 | * @returns an iterator usable for iterating through all network interfaces. | 100 | * @returns an iterator usable for iterating through all network interfaces. |
100 | */ | 101 | */ |
101 | InterfaceIterator iterator() const; | 102 | InterfaceIterator iterator() const; |
102 | /** | 103 | /** |
103 | * @returns true, if the @a interface supports the wireless extension protocol. | 104 | * @returns true, if the @a interface supports the wireless extension protocol. |
104 | */ | 105 | */ |
105 | // FIXME QString? -zecke | 106 | // FIXME QString? -zecke |
106 | bool isWirelessInterface( const char* interface ) const; | 107 | bool isWirelessInterface( const char* interface ) const; |
107 | /** | 108 | /** |
108 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found | 109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found |
109 | * @see ONetworkInterface | 110 | * @see ONetworkInterface |
110 | */ | 111 | */ |
111 | // FIXME: const QString& is prefered over QString!!! -zecke | 112 | // FIXME: const QString& is prefered over QString!!! -zecke |
112 | ONetworkInterface* interface( const QString& interface ) const; | 113 | ONetworkInterface* interface( const QString& interface ) const; |
113 | /** | 114 | /** |
114 | * @internal Rebuild the internal interface database | 115 | * @internal Rebuild the internal interface database |
115 | * @note Sometimes it might be useful to call this from client code, | 116 | * @note Sometimes it might be useful to call this from client code, |
116 | * e.g. after issuing a cardctl insert | 117 | * e.g. after issuing a cardctl insert |
117 | */ | 118 | */ |
118 | void synchronize(); | 119 | void synchronize(); |
119 | 120 | ||
120 | protected: | 121 | protected: |
121 | ONetwork(); | 122 | ONetwork(); |
122 | 123 | ||
123 | private: | 124 | private: |
124 | static ONetwork* _instance; | 125 | static ONetwork* _instance; |
125 | InterfaceMap _interfaces; | 126 | InterfaceMap _interfaces; |
126 | }; | 127 | }; |
127 | 128 | ||
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 | */ |
142 | class ONetworkInterface : public QObject | 144 | class 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 | /** |
152 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 154 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
153 | * but access them via @ref ONetwork::interface(). | 155 | * but access them via @ref ONetwork::interface(). |
154 | */ | 156 | */ |
155 | ONetworkInterface( QObject* parent, const char* name ); | 157 | ONetworkInterface( QObject* parent, const char* name ); |
156 | /** | 158 | /** |
157 | * Destructor. | 159 | * Destructor. |
158 | */ | 160 | */ |
159 | virtual ~ONetworkInterface(); | 161 | virtual ~ONetworkInterface(); |
160 | /** | 162 | /** |
161 | * Associates a @a monitoring interface with this network interface. | 163 | * Associates a @a monitoring interface with this network interface. |
162 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 164 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
163 | */ | 165 | */ |
164 | void setMonitoring( OMonitoringInterface* monitoring ); | 166 | void setMonitoring( OMonitoringInterface* monitoring ); |
165 | /** | 167 | /** |
166 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 168 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
167 | */ | 169 | */ |
168 | OMonitoringInterface* monitoring() const; | 170 | OMonitoringInterface* monitoring() const; |
169 | /** | 171 | /** |
170 | * Setting an interface to promiscuous mode enables the device to receive | 172 | * Setting an interface to promiscuous mode enables the device to receive |
171 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 173 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
172 | */ | 174 | */ |
173 | bool setPromiscuousMode( bool ); | 175 | bool setPromiscuousMode( bool ); |
174 | /** | 176 | /** |
175 | * @returns true if the interface is set to promiscuous mode. | 177 | * @returns true if the interface is set to promiscuous mode. |
176 | */ | 178 | */ |
177 | bool promiscuousMode() const; | 179 | bool promiscuousMode() const; |
178 | /** | 180 | /** |
179 | * Setting an interface to up enables it to receive packets. | 181 | * Setting an interface to up enables it to receive packets. |
180 | */ | 182 | */ |
181 | bool setUp( bool ); | 183 | bool setUp( bool ); |
182 | /** | 184 | /** |
183 | * @returns true if the interface is up. | 185 | * @returns true if the interface is up. |
184 | */ | 186 | */ |
185 | bool isUp() const; | 187 | bool isUp() const; |
186 | /** | 188 | /** |
187 | * @returns true if the interface is a loopback interface. | 189 | * @returns true if the interface is a loopback interface. |
188 | */ | 190 | */ |
189 | bool isLoopback() const; | 191 | bool isLoopback() const; |
190 | /** | 192 | /** |
191 | * @returns true if the interface is featuring supports the wireless extension protocol. | 193 | * @returns true if the interface is featuring supports the wireless extension protocol. |
192 | */ | 194 | */ |
193 | bool isWireless() const; | 195 | bool isWireless() const; |
194 | /** | 196 | /** |
195 | * Associate the IP address @ addr with the interface. | 197 | * Associate the IP address @ addr with the interface. |
196 | */ | 198 | */ |
197 | void setIPV4Address( const QHostAddress& addr ); | 199 | void setIPV4Address( const QHostAddress& addr ); |
198 | /** | 200 | /** |
199 | * @returns the IPv4 address associated with the interface. | 201 | * @returns the IPv4 address associated with the interface. |
200 | */ | 202 | */ |
201 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 203 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
202 | /** | 204 | /** |
203 | * Associate the MAC address @a addr with the interface. | 205 | * Associate the MAC address @a addr with the interface. |
204 | * @note It can be necessary to shut down the interface prior to calling this method. | 206 | * @note It can be necessary to shut down the interface prior to calling this method. |
205 | * @warning This is not supported by all drivers. | 207 | * @warning This is not supported by all drivers. |
206 | */ | 208 | */ |
207 | void setMacAddress( const OMacAddress& addr ); | 209 | void setMacAddress( const OMacAddress& addr ); |
208 | /** | 210 | /** |
209 | * @returns the MAC address associated with the interface. | 211 | * @returns the MAC address associated with the interface. |
210 | */ | 212 | */ |
211 | OMacAddress macAddress() const; | 213 | OMacAddress macAddress() const; |
212 | /** | 214 | /** |
213 | * Associate the IPv4 @a netmask with the interface. | 215 | * Associate the IPv4 @a netmask with the interface. |
214 | */ | 216 | */ |
215 | void setIPV4Netmask( const QHostAddress& netmask ); | 217 | void setIPV4Netmask( const QHostAddress& netmask ); |
216 | /** | 218 | /** |
217 | * @returns the IPv4 netmask associated with the interface. | 219 | * @returns the IPv4 netmask associated with the interface. |
218 | */ | 220 | */ |
219 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 221 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
220 | /** | 222 | /** |
221 | * @returns the data link type currently associated with the interface. | 223 | * @returns the data link type currently associated with the interface. |
222 | * @see #include <net/if_arp.h> for possible values. | 224 | * @see #include <net/if_arp.h> for possible values. |
223 | */ | 225 | */ |
224 | int dataLinkType() const; | 226 | int dataLinkType() const; |
225 | 227 | ||
226 | protected: | 228 | protected: |
227 | const int _sfd; | 229 | const int _sfd; |
228 | mutable ifreq _ifr; | 230 | mutable ifreq _ifr; |
229 | OMonitoringInterface* _mon; | 231 | OMonitoringInterface* _mon; |
230 | 232 | ||
231 | protected: | 233 | protected: |
232 | struct ifreq& ifr() const; | 234 | struct ifreq& ifr() const; |
233 | virtual void init(); | 235 | virtual void init(); |
234 | bool ioctl( int call ) const; | 236 | bool ioctl( int call ) const; |
235 | bool ioctl( int call, struct ifreq& ) const; | 237 | bool ioctl( int call, struct ifreq& ) const; |
236 | }; | 238 | }; |
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 | */ |
251 | class OChannelHopper : public QObject | 254 | class 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 | /** |
261 | * Destructor. | 264 | * Destructor. |
262 | */ | 265 | */ |
263 | virtual ~OChannelHopper(); | 266 | virtual ~OChannelHopper(); |
264 | /** | 267 | /** |
265 | * @returns true, if the channel hopper is hopping channels | 268 | * @returns true, if the channel hopper is hopping channels |
266 | */ | 269 | */ |
267 | bool isActive() const; | 270 | bool isActive() const; |
268 | /** | 271 | /** |
269 | * @returns the last hopped channel | 272 | * @returns the last hopped channel |
270 | */ | 273 | */ |
271 | int channel() const; | 274 | int channel() const; |
272 | /** | 275 | /** |
273 | * Set the channel hopping @a interval. | 276 | * Set the channel hopping @a interval. |
274 | * An interval of 0 deactivates the channel hopper. | 277 | * An interval of 0 deactivates the channel hopper. |
275 | */ | 278 | */ |
276 | void setInterval( int interval ); | 279 | void setInterval( int interval ); |
277 | /** | 280 | /** |
278 | * @returns the channel hopping interval | 281 | * @returns the channel hopping interval |
279 | */ | 282 | */ |
280 | int interval() const; | 283 | int interval() const; |
281 | 284 | ||
282 | signals: | 285 | signals: |
283 | /** | 286 | /** |
284 | * This signal is emitted right after the channel hopper performed a hop | 287 | * This signal is emitted right after the channel hopper performed a hop |
285 | */ | 288 | */ |
286 | void hopped( int ); | 289 | void hopped( int ); |
287 | 290 | ||
288 | protected: | 291 | protected: |
289 | virtual void timerEvent( QTimerEvent* ); | 292 | virtual void timerEvent( QTimerEvent* ); |
290 | 293 | ||
291 | private: | 294 | private: |
292 | OWirelessNetworkInterface* _iface; | 295 | OWirelessNetworkInterface* _iface; |
293 | int _interval; | 296 | int _interval; |
294 | int _tid; | 297 | int _tid; |
295 | QValueList<int> _channels; | 298 | QValueList<int> _channels; |
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 | */ |
309 | class OWirelessNetworkInterface : public ONetworkInterface | 314 | class 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: |
320 | /** | 325 | /** |
321 | * Constructor. | 326 | * Constructor. |
322 | */ | 327 | */ |
323 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 328 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
324 | /** | 329 | /** |
325 | * Destructor. | 330 | * Destructor. |
326 | */ | 331 | */ |
327 | virtual ~OWirelessNetworkInterface(); | 332 | virtual ~OWirelessNetworkInterface(); |
328 | /** | 333 | /** |
329 | * Setting the @a channel of the interface changes the radio frequency (RF) | 334 | * Setting the @a channel of the interface changes the radio frequency (RF) |
330 | * of the corresponding wireless network device. | 335 | * of the corresponding wireless network device. |
331 | */ | 336 | */ |
332 | virtual void setChannel( int channel ) const; | 337 | virtual void setChannel( int channel ) const; |
333 | /** | 338 | /** |
334 | * @returns the channel index of the current radio frequency. | 339 | * @returns the channel index of the current radio frequency. |
335 | */ | 340 | */ |
336 | virtual int channel() const; | 341 | virtual int channel() const; |
337 | /** | 342 | /** |
338 | * @returns the current radio frequency (in MHz). | 343 | * @returns the current radio frequency (in MHz). |
339 | */ | 344 | */ |
340 | virtual double frequency() const; | 345 | virtual double frequency() const; |
341 | /** | 346 | /** |
342 | * @returns the number of radio frequency channels for the | 347 | * @returns the number of radio frequency channels for the |
343 | * corresponding wireless network device. | 348 | * corresponding wireless network device. |
344 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 349 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
345 | */ | 350 | */ |
346 | virtual int channels() const; | 351 | virtual int channels() const; |
347 | /** | 352 | /** |
348 | * Set the IEEE 802.11 operation @a mode. | 353 | * Set the IEEE 802.11 operation @a mode. |
349 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 354 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
350 | * @warning Not all drivers support the all modes. | 355 | * @warning Not all drivers support the all modes. |
351 | * @note You might have to change the SSID to get the operation mode change into effect. | 356 | * @note You might have to change the SSID to get the operation mode change into effect. |
352 | */ | 357 | */ |
353 | virtual void setMode( const QString& mode ); | 358 | virtual void setMode( const QString& mode ); |
354 | /** | 359 | /** |
355 | * @returns the current IEEE 802.11 operation mode. | 360 | * @returns the current IEEE 802.11 operation mode. |
356 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 361 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
357 | */ | 362 | */ |
358 | virtual QString mode() const; | 363 | virtual QString mode() const; |
359 | /** | 364 | /** |
360 | * Setting the monitor mode on a wireless network interface enables | 365 | * Setting the monitor mode on a wireless network interface enables |
361 | * listening to IEEE 802.11 data and management frames which normally | 366 | * listening to IEEE 802.11 data and management frames which normally |
362 | * are handled by the device firmware. This can be used to detect | 367 | * are handled by the device firmware. This can be used to detect |
363 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 368 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
364 | * @warning Standard wireless network drives don't support the monitor mode. | 369 | * @warning Standard wireless network drives don't support the monitor mode. |
365 | * @warning You need a patched driver for this to work. | 370 | * @warning You need a patched driver for this to work. |
366 | * @note Enabling the monitor mode is highly driver dependent and requires | 371 | * @note Enabling the monitor mode is highly driver dependent and requires |
367 | * the proper @ref OMonitoringInterface to be associated with the interface. | 372 | * the proper @ref OMonitoringInterface to be associated with the interface. |
368 | * @see OMonitoringInterface | 373 | * @see OMonitoringInterface |
369 | */ | 374 | */ |
370 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); | 375 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); |
371 | /** | 376 | /** |
372 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 377 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
373 | */ | 378 | */ |
374 | virtual bool monitorMode() const; //FIXME: ==> mode() | 379 | virtual bool monitorMode() const; //FIXME: ==> mode() |
375 | /** | 380 | /** |
376 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 381 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
377 | * @see OChannelHopper | 382 | * @see OChannelHopper |
378 | */ | 383 | */ |
379 | virtual void setChannelHopping( int interval = 0 ); | 384 | virtual void setChannelHopping( int interval = 0 ); |
380 | /** | 385 | /** |
381 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 386 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
382 | */ | 387 | */ |
383 | virtual int channelHopping() const; | 388 | virtual int channelHopping() const; |
384 | /** | 389 | /** |
385 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 390 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
386 | */ | 391 | */ |
387 | virtual OChannelHopper* channelHopper() const; | 392 | virtual OChannelHopper* channelHopper() const; |
388 | /** | 393 | /** |
389 | * Set the station @a nickname. | 394 | * Set the station @a nickname. |
390 | */ | 395 | */ |
391 | virtual void setNickName( const QString& nickname ); | 396 | virtual void setNickName( const QString& nickname ); |
392 | /** | 397 | /** |
393 | * @returns the current station nickname. | 398 | * @returns the current station nickname. |
394 | */ | 399 | */ |
395 | virtual QString nickName() const; | 400 | virtual QString nickName() const; |
396 | /** | 401 | /** |
397 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 402 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
398 | * @see OPrivateIOCTL | 403 | * @see OPrivateIOCTL |
399 | */ | 404 | */ |
400 | virtual void setPrivate( const QString& command, int number, ... ); | 405 | virtual void setPrivate( const QString& command, int number, ... ); |
401 | /** | 406 | /** |
402 | * @returns true if the interface is featuring the private IOCTL @command. | 407 | * @returns true if the interface is featuring the private IOCTL @command. |
403 | */ | 408 | */ |
404 | virtual bool hasPrivate( const QString& command ); | 409 | virtual bool hasPrivate( const QString& command ); |
405 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 410 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
406 | 411 | ||
407 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | 412 | virtual bool isAssociated() const {}; //FIXME: Implement and document this |
408 | /** | 413 | /** |
409 | * @returns the MAC address of the Access Point if the | 414 | * @returns the MAC address of the Access Point if the |
410 | * device is in infrastructure mode. @returns a (more or less random) CELL | 415 | * device is in infrastructure mode. @returns a (more or less random) CELL |
411 | * address if the device is in adhoc mode. | 416 | * address if the device is in adhoc mode. |
412 | */ | 417 | */ |
413 | virtual QString associatedAP() const; | 418 | virtual QString associatedAP() const; |
414 | /** | 419 | /** |
415 | * Set the @a ssid (Service Set ID) string. This is used to decide | 420 | * Set the @a ssid (Service Set ID) string. This is used to decide |
416 | * which network to associate with (use "any" to let the driver decide). | 421 | * which network to associate with (use "any" to let the driver decide). |
417 | */ | 422 | */ |
418 | virtual void setSSID( const QString& ssid ); | 423 | virtual void setSSID( const QString& ssid ); |
419 | /** | 424 | /** |
420 | * @returns the current SSID (Service Set ID). | 425 | * @returns the current SSID (Service Set ID). |
421 | */ | 426 | */ |
422 | virtual QString SSID() const; | 427 | virtual QString SSID() const; |
423 | 428 | ||
424 | protected: | 429 | protected: |
425 | void buildChannelList(); | 430 | void buildChannelList(); |
426 | void buildPrivateList(); | 431 | void buildPrivateList(); |
427 | virtual void init(); | 432 | virtual void init(); |
428 | struct iwreq& iwr() const; | 433 | struct iwreq& iwr() const; |
429 | bool wioctl( int call ) const; | 434 | bool wioctl( int call ) const; |
430 | bool wioctl( int call, struct iwreq& ) const; | 435 | bool wioctl( int call, struct iwreq& ) const; |
431 | 436 | ||
432 | protected: | 437 | protected: |
433 | mutable struct iwreq _iwr; | 438 | mutable struct iwreq _iwr; |
434 | QMap<int,int> _channels; | 439 | QMap<int,int> _channels; |
435 | 440 | ||
436 | private: | 441 | private: |
437 | OChannelHopper* _hopper; | 442 | OChannelHopper* _hopper; |
438 | }; | 443 | }; |
439 | 444 | ||
440 | 445 | ||
441 | /*====================================================================================== | 446 | /*====================================================================================== |
442 | * OMonitoringInterface | 447 | * OMonitoringInterface |
443 | *======================================================================================*/ | 448 | *======================================================================================*/ |
444 | 449 | ||
445 | 450 | ||
446 | class OMonitoringInterface | 451 | class OMonitoringInterface |
447 | { | 452 | { |
448 | public: | 453 | public: |
449 | OMonitoringInterface(); | 454 | OMonitoringInterface(); |
450 | OMonitoringInterface( ONetworkInterface* ); | 455 | OMonitoringInterface( ONetworkInterface* ); |
451 | virtual ~OMonitoringInterface(); | 456 | virtual ~OMonitoringInterface(); |
452 | 457 | ||
453 | public: | 458 | public: |
454 | virtual void setEnabled( bool ); | 459 | virtual void setEnabled( bool ); |
455 | virtual bool enabled() const; | 460 | virtual bool enabled() const; |
456 | virtual void setChannel( int ); | 461 | virtual void setChannel( int ); |
457 | 462 | ||
458 | virtual QString name() const = 0; | 463 | virtual QString name() const = 0; |
459 | 464 | ||
460 | protected: | 465 | protected: |
461 | OWirelessNetworkInterface* _if; | 466 | OWirelessNetworkInterface* _if; |
462 | 467 | ||
463 | }; | 468 | }; |
464 | 469 | ||
465 | 470 | ||
466 | /*====================================================================================== | 471 | /*====================================================================================== |
467 | * OCiscoMonitoring | 472 | * OCiscoMonitoring |
468 | *======================================================================================*/ | 473 | *======================================================================================*/ |
469 | 474 | ||
470 | 475 | ||
471 | class OCiscoMonitoringInterface : public OMonitoringInterface | 476 | class OCiscoMonitoringInterface : public OMonitoringInterface |
472 | { | 477 | { |
473 | public: | 478 | public: |
474 | OCiscoMonitoringInterface( ONetworkInterface* ); | 479 | OCiscoMonitoringInterface( ONetworkInterface* ); |
475 | virtual ~OCiscoMonitoringInterface(); | 480 | virtual ~OCiscoMonitoringInterface(); |
476 | 481 | ||
477 | virtual void setEnabled( bool ); | 482 | virtual void setEnabled( bool ); |
478 | virtual QString name() const; | 483 | virtual QString name() const; |
479 | virtual void setChannel( int ); | 484 | virtual void setChannel( int ); |
480 | 485 | ||
481 | }; | 486 | }; |
482 | 487 | ||
483 | /*====================================================================================== | 488 | /*====================================================================================== |
484 | * OWlanNGMonitoringInterface | 489 | * OWlanNGMonitoringInterface |
485 | *======================================================================================*/ | 490 | *======================================================================================*/ |
486 | 491 | ||
487 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 492 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
488 | { | 493 | { |
489 | public: | 494 | public: |
490 | OWlanNGMonitoringInterface( ONetworkInterface* ); | 495 | OWlanNGMonitoringInterface( ONetworkInterface* ); |
491 | virtual ~OWlanNGMonitoringInterface(); | 496 | virtual ~OWlanNGMonitoringInterface(); |
492 | 497 | ||
493 | public: | 498 | public: |
494 | virtual void setEnabled( bool ); | 499 | virtual void setEnabled( bool ); |
495 | virtual QString name() const; | 500 | virtual QString name() const; |
496 | virtual void setChannel( int ); | 501 | virtual void setChannel( int ); |
497 | 502 | ||
498 | }; | 503 | }; |
499 | 504 | ||
500 | /*====================================================================================== | 505 | /*====================================================================================== |
501 | * OHostAPMonitoringInterface | 506 | * OHostAPMonitoringInterface |
502 | *======================================================================================*/ | 507 | *======================================================================================*/ |
503 | 508 | ||
504 | class OHostAPMonitoringInterface : public OMonitoringInterface | 509 | class OHostAPMonitoringInterface : public OMonitoringInterface |
505 | { | 510 | { |
506 | public: | 511 | public: |
507 | OHostAPMonitoringInterface( ONetworkInterface* ); | 512 | OHostAPMonitoringInterface( ONetworkInterface* ); |
508 | virtual ~OHostAPMonitoringInterface(); | 513 | virtual ~OHostAPMonitoringInterface(); |
509 | 514 | ||
510 | public: | 515 | public: |
511 | virtual void setEnabled( bool ); | 516 | virtual void setEnabled( bool ); |
512 | virtual QString name() const; | 517 | virtual QString name() const; |
513 | }; | 518 | }; |
514 | 519 | ||
515 | /*====================================================================================== | 520 | /*====================================================================================== |
516 | * OOrinocoMonitoringInterface | 521 | * OOrinocoMonitoringInterface |
517 | *======================================================================================*/ | 522 | *======================================================================================*/ |
518 | 523 | ||
519 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 524 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
520 | { | 525 | { |
521 | public: | 526 | public: |
522 | OOrinocoMonitoringInterface( ONetworkInterface* ); | 527 | OOrinocoMonitoringInterface( ONetworkInterface* ); |
523 | virtual ~OOrinocoMonitoringInterface(); | 528 | virtual ~OOrinocoMonitoringInterface(); |
524 | 529 | ||
525 | public: | 530 | public: |
526 | virtual void setChannel( int ); | 531 | virtual void setChannel( int ); |
527 | virtual void setEnabled( bool ); | 532 | virtual void setEnabled( bool ); |
528 | virtual QString name() const; | 533 | virtual QString name() const; |
529 | 534 | ||
530 | }; | 535 | }; |
531 | 536 | ||
532 | #endif // ONETWORK_H | 537 | #endif // ONETWORK_H |
533 | 538 | ||
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 | |||
@@ -1,532 +1,607 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* QT */ | 31 | /* QT */ |
32 | 32 | ||
33 | #include <qcolor.h> | 33 | #include <qcolor.h> |
34 | #include <qheader.h> | 34 | #include <qheader.h> |
35 | #include <qpainter.h> | 35 | #include <qpainter.h> |
36 | #include <qpixmap.h> | 36 | #include <qpixmap.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | 39 | ||
40 | #include <opie2/olistview.h> | 40 | #include <opie2/olistview.h> |
41 | 41 | ||
42 | /*====================================================================================== | 42 | /*====================================================================================== |
43 | * OListView | 43 | * OListView |
44 | *======================================================================================*/ | 44 | *======================================================================================*/ |
45 | 45 | ||
46 | OListView::OListView( QWidget *parent, const char *name ) | 46 | OListView::OListView( QWidget *parent, const char *name ) |
47 | :QListView( parent, name ) | 47 | :QListView( parent, name ) |
48 | { | 48 | { |
49 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* | 49 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* |
50 | 50 | ||
51 | m_alternateBackground = QColor( 238, 246, 255 ); | 51 | m_alternateBackground = QColor( 238, 246, 255 ); |
52 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); | 52 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); |
53 | m_fullWidth = true; | 53 | m_fullWidth = true; |
54 | } | 54 | } |
55 | 55 | ||
56 | OListView::~OListView() | 56 | OListView::~OListView() |
57 | { | 57 | { |
58 | } | 58 | } |
59 | 59 | ||
60 | void OListView::setFullWidth( bool fullWidth ) | 60 | void OListView::setFullWidth( bool fullWidth ) |
61 | { | 61 | { |
62 | m_fullWidth = m_fullWidth; | 62 | m_fullWidth = m_fullWidth; |
63 | #if QT_VERSION > 290 | 63 | #if QT_VERSION > 290 |
64 | header()->setStretchEnabled( fullWidth, columns()-1 ); | 64 | header()->setStretchEnabled( fullWidth, columns()-1 ); |
65 | #endif | 65 | #endif |
66 | } | 66 | } |
67 | 67 | ||
68 | bool OListView::fullWidth() const | 68 | bool OListView::fullWidth() const |
69 | { | 69 | { |
70 | return m_fullWidth; | 70 | return m_fullWidth; |
71 | } | 71 | } |
72 | 72 | ||
73 | int OListView::addColumn( const QString& label, int width ) | 73 | int OListView::addColumn( const QString& label, int width ) |
74 | { | 74 | { |
75 | int result = QListView::addColumn( label, width ); | 75 | int result = QListView::addColumn( label, width ); |
76 | #if QT_VERSION > 290 | 76 | #if QT_VERSION > 290 |
77 | if (m_fullWidth) { | 77 | if (m_fullWidth) { |
78 | header()->setStretchEnabled( false, columns()-2 ); | 78 | header()->setStretchEnabled( false, columns()-2 ); |
79 | header()->setStretchEnabled( true, columns()-1 ); | 79 | header()->setStretchEnabled( true, columns()-1 ); |
80 | } | 80 | } |
81 | #endif | 81 | #endif |
82 | return result; | 82 | return result; |
83 | } | 83 | } |
84 | 84 | ||
85 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) | 85 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) |
86 | { | 86 | { |
87 | int result = QListView::addColumn( iconset, label, width ); | 87 | int result = QListView::addColumn( iconset, label, width ); |
88 | #if QT_VERSION > 290 | 88 | #if QT_VERSION > 290 |
89 | if (m_fullWidth) { | 89 | if (m_fullWidth) { |
90 | header()->setStretchEnabled( false, columns()-2 ); | 90 | header()->setStretchEnabled( false, columns()-2 ); |
91 | header()->setStretchEnabled( true, columns()-1 ); | 91 | header()->setStretchEnabled( true, columns()-1 ); |
92 | } | 92 | } |
93 | #endif | 93 | #endif |
94 | return result; | 94 | return result; |
95 | } | 95 | } |
96 | 96 | ||
97 | void OListView::removeColumn( int index ) | 97 | void OListView::removeColumn( int index ) |
98 | { | 98 | { |
99 | QListView::removeColumn(index); | 99 | QListView::removeColumn(index); |
100 | #if QT_VERSION > 290 | 100 | #if QT_VERSION > 290 |
101 | if ( m_fullWidth && index == columns() ) | 101 | if ( m_fullWidth && index == columns() ) |
102 | { | 102 | { |
103 | header()->setStretchEnabled( true, columns()-1 ); | 103 | header()->setStretchEnabled( true, columns()-1 ); |
104 | } | 104 | } |
105 | #endif | 105 | #endif |
106 | } | 106 | } |
107 | 107 | ||
108 | const QColor& OListView::alternateBackground() const | 108 | const QColor& OListView::alternateBackground() const |
109 | { | 109 | { |
110 | return m_alternateBackground; | 110 | return m_alternateBackground; |
111 | } | 111 | } |
112 | 112 | ||
113 | void OListView::setAlternateBackground( const QColor &c ) | 113 | void OListView::setAlternateBackground( const QColor &c ) |
114 | { | 114 | { |
115 | m_alternateBackground = c; | 115 | m_alternateBackground = c; |
116 | repaint(); | 116 | repaint(); |
117 | } | 117 | } |
118 | 118 | ||
119 | const QPen& OListView::columnSeparator() const | 119 | const QPen& OListView::columnSeparator() const |
120 | { | 120 | { |
121 | return m_columnSeparator; | 121 | return m_columnSeparator; |
122 | } | 122 | } |
123 | 123 | ||
124 | void OListView::setColumnSeparator( const QPen& p ) | 124 | void OListView::setColumnSeparator( const QPen& p ) |
125 | { | 125 | { |
126 | m_columnSeparator = p; | 126 | m_columnSeparator = p; |
127 | repaint(); | 127 | repaint(); |
128 | } | 128 | } |
129 | 129 | ||
130 | OListViewItem* OListView::childFactory() | 130 | OListViewItem* OListView::childFactory() |
131 | { | 131 | { |
132 | return new OListViewItem( this ); | 132 | return new OListViewItem( this ); |
133 | } | 133 | } |
134 | 134 | ||
135 | #ifndef QT_NO_DATASTREAM | 135 | #ifndef QT_NO_DATASTREAM |
136 | void OListView::serializeTo( QDataStream& s ) const | 136 | void OListView::serializeTo( QDataStream& s ) const |
137 | { | 137 | { |
138 | #warning Caution... the binary format is still under construction... | 138 | #warning Caution... the binary format is still under construction... |
139 | qDebug( "storing OListView..." ); | 139 | qDebug( "storing OListView..." ); |
140 | 140 | ||
141 | // store number of columns and the labels | 141 | // store number of columns and the labels |
142 | s << columns(); | 142 | s << columns(); |
143 | for ( int i = 0; i < columns(); ++i ) | 143 | for ( int i = 0; i < columns(); ++i ) |
144 | s << columnText( i ); | 144 | s << columnText( i ); |
145 | 145 | ||
146 | // calculate the number of top-level items to serialize | 146 | // calculate the number of top-level items to serialize |
147 | int items = 0; | 147 | int items = 0; |
148 | QListViewItem* item = firstChild(); | 148 | QListViewItem* item = firstChild(); |
149 | while ( item ) | 149 | while ( item ) |
150 | { | 150 | { |
151 | item = item->nextSibling(); | 151 | item = item->nextSibling(); |
152 | items++; | 152 | items++; |
153 | } | 153 | } |
154 | 154 | ||
155 | // store number of items and the items itself | 155 | // store number of items and the items itself |
156 | s << items; | 156 | s << items; |
157 | item = firstChild(); | 157 | item = firstChild(); |
158 | for ( int i = 0; i < items; ++i ) | 158 | for ( int i = 0; i < items; ++i ) |
159 | { | 159 | { |
160 | s << *static_cast<OListViewItem*>( item ); | 160 | s << *static_cast<OListViewItem*>( item ); |
161 | item = item->nextSibling(); | 161 | item = item->nextSibling(); |
162 | } | 162 | } |
163 | 163 | ||
164 | qDebug( "OListview stored." ); | 164 | qDebug( "OListview stored." ); |
165 | } | 165 | } |
166 | 166 | ||
167 | void OListView::serializeFrom( QDataStream& s ) | 167 | void OListView::serializeFrom( QDataStream& s ) |
168 | { | 168 | { |
169 | #warning Caution... the binary format is still under construction... | 169 | #warning Caution... the binary format is still under construction... |
170 | qDebug( "loading OListView..." ); | 170 | qDebug( "loading OListView..." ); |
171 | 171 | ||
172 | int cols; | 172 | int cols; |
173 | s >> cols; | 173 | s >> cols; |
174 | qDebug( "read number of columns = %d", cols ); | 174 | qDebug( "read number of columns = %d", cols ); |
175 | 175 | ||
176 | while ( columns() < cols ) addColumn( QString::null ); | 176 | while ( columns() < cols ) addColumn( QString::null ); |
177 | 177 | ||
178 | for ( int i = 0; i < cols; ++i ) | 178 | for ( int i = 0; i < cols; ++i ) |
179 | { | 179 | { |
180 | QString coltext; | 180 | QString coltext; |
181 | s >> coltext; | 181 | s >> coltext; |
182 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 182 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
183 | setColumnText( i, coltext ); | 183 | setColumnText( i, coltext ); |
184 | } | 184 | } |
185 | 185 | ||
186 | int items; | 186 | int items; |
187 | s >> items; | 187 | s >> items; |
188 | qDebug( "read number of items = %d", items ); | 188 | qDebug( "read number of items = %d", items ); |
189 | 189 | ||
190 | for ( int i = 0; i < items; ++i ) | 190 | for ( int i = 0; i < items; ++i ) |
191 | { | 191 | { |
192 | OListViewItem* item = childFactory(); | 192 | OListViewItem* item = childFactory(); |
193 | s >> *item; | 193 | s >> *item; |
194 | } | 194 | } |
195 | 195 | ||
196 | qDebug( "OListView loaded." ); | 196 | qDebug( "OListView loaded." ); |
197 | 197 | ||
198 | } | 198 | } |
199 | 199 | ||
200 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) | 200 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) |
201 | { | 201 | { |
202 | lv.serializeTo( s ); | 202 | lv.serializeTo( s ); |
203 | } | 203 | } |
204 | 204 | ||
205 | QDataStream& operator>>( QDataStream& s, OListView& lv ) | 205 | QDataStream& operator>>( QDataStream& s, OListView& lv ) |
206 | { | 206 | { |
207 | lv.serializeFrom( s ); | 207 | lv.serializeFrom( s ); |
208 | } | 208 | } |
209 | #endif // QT_NO_DATASTREAM | 209 | #endif // QT_NO_DATASTREAM |
210 | 210 | ||
211 | /*====================================================================================== | 211 | /*====================================================================================== |
212 | * OListViewItem | 212 | * OListViewItem |
213 | *======================================================================================*/ | 213 | *======================================================================================*/ |
214 | 214 | ||
215 | OListViewItem::OListViewItem(QListView *parent) | 215 | OListViewItem::OListViewItem(QListView *parent) |
216 | : QListViewItem(parent) | 216 | : QListViewItem(parent) |
217 | { | 217 | { |
218 | init(); | 218 | init(); |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | OListViewItem::OListViewItem(QListViewItem *parent) | 222 | OListViewItem::OListViewItem(QListViewItem *parent) |
223 | : QListViewItem(parent) | 223 | : QListViewItem(parent) |
224 | { | 224 | { |
225 | init(); | 225 | init(); |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 229 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
230 | : QListViewItem(parent, after) | 230 | : QListViewItem(parent, after) |
231 | { | 231 | { |
232 | init(); | 232 | init(); |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 236 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
237 | : QListViewItem(parent, after) | 237 | : QListViewItem(parent, after) |
238 | { | 238 | { |
239 | init(); | 239 | init(); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | OListViewItem::OListViewItem(QListView *parent, | 243 | OListViewItem::OListViewItem(QListView *parent, |
244 | QString label1, QString label2, QString label3, QString label4, | 244 | QString label1, QString label2, QString label3, QString label4, |
245 | QString label5, QString label6, QString label7, QString label8) | 245 | QString label5, QString label6, QString label7, QString label8) |
246 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 246 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
247 | { | 247 | { |
248 | init(); | 248 | init(); |
249 | } | 249 | } |
250 | 250 | ||
251 | 251 | ||
252 | OListViewItem::OListViewItem(QListViewItem *parent, | 252 | OListViewItem::OListViewItem(QListViewItem *parent, |
253 | QString label1, QString label2, QString label3, QString label4, | 253 | QString label1, QString label2, QString label3, QString label4, |
254 | QString label5, QString label6, QString label7, QString label8) | 254 | QString label5, QString label6, QString label7, QString label8) |
255 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 255 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
256 | { | 256 | { |
257 | init(); | 257 | init(); |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
261 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 261 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
262 | QString label1, QString label2, QString label3, QString label4, | 262 | QString label1, QString label2, QString label3, QString label4, |
263 | QString label5, QString label6, QString label7, QString label8) | 263 | QString label5, QString label6, QString label7, QString label8) |
264 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 264 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
265 | { | 265 | { |
266 | init(); | 266 | init(); |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 270 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
271 | QString label1, QString label2, QString label3, QString label4, | 271 | QString label1, QString label2, QString label3, QString label4, |
272 | QString label5, QString label6, QString label7, QString label8) | 272 | QString label5, QString label6, QString label7, QString label8) |
273 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 273 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
274 | { | 274 | { |
275 | init(); | 275 | init(); |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | OListViewItem::~OListViewItem() | 279 | OListViewItem::~OListViewItem() |
280 | { | 280 | { |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | void OListViewItem::init() | 284 | void OListViewItem::init() |
285 | { | 285 | { |
286 | m_known = false; | 286 | m_known = false; |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | const QColor &OListViewItem::backgroundColor() | 290 | const QColor &OListViewItem::backgroundColor() |
291 | { | 291 | { |
292 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 292 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
293 | listView()->viewport()->colorGroup().base(); | 293 | listView()->viewport()->colorGroup().base(); |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | bool OListViewItem::isAlternate() | 297 | bool OListViewItem::isAlternate() |
298 | { | 298 | { |
299 | OListView *lv = static_cast<OListView*>( listView() ); | 299 | OListView *lv = static_cast<OListView*>( listView() ); |
300 | 300 | ||
301 | // check if the item above is an OListViewItem | 301 | // check if the item above is an OListViewItem |
302 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 302 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
303 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ | 303 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ |
304 | 304 | ||
305 | // check if we have a valid alternate background color | 305 | // check if we have a valid alternate background color |
306 | if (!(lv && lv->alternateBackground().isValid())) return false; | 306 | if (!(lv && lv->alternateBackground().isValid())) return false; |
307 | 307 | ||
308 | m_known = above ? above->m_known : true; | 308 | m_known = above ? above->m_known : true; |
309 | if (m_known) | 309 | if (m_known) |
310 | { | 310 | { |
311 | m_odd = above ? !above->m_odd : false; | 311 | m_odd = above ? !above->m_odd : false; |
312 | } | 312 | } |
313 | else | 313 | else |
314 | { | 314 | { |
315 | OListViewItem *item; | 315 | OListViewItem *item; |
316 | bool previous = true; | 316 | bool previous = true; |
317 | if (parent()) | 317 | if (parent()) |
318 | { | 318 | { |
319 | item = static_cast<OListViewItem *>(parent()); | 319 | item = static_cast<OListViewItem *>(parent()); |
320 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; | 320 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; |
321 | item = static_cast<OListViewItem *>(parent()->firstChild()); | 321 | item = static_cast<OListViewItem *>(parent()->firstChild()); |
322 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ | 322 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ |
323 | } | 323 | } |
324 | else | 324 | else |
325 | { | 325 | { |
326 | item = static_cast<OListViewItem *>(lv->firstChild()); | 326 | item = static_cast<OListViewItem *>(lv->firstChild()); |
327 | } | 327 | } |
328 | 328 | ||
329 | while(item) | 329 | while(item) |
330 | { | 330 | { |
331 | item->m_odd = previous = !previous; | 331 | item->m_odd = previous = !previous; |
332 | item->m_known = true; | 332 | item->m_known = true; |
333 | item = static_cast<OListViewItem *>(item->nextSibling()); | 333 | item = static_cast<OListViewItem *>(item->nextSibling()); |
334 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 334 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
335 | } | 335 | } |
336 | } | 336 | } |
337 | return m_odd; | 337 | return m_odd; |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 341 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
342 | { | 342 | { |
343 | QColorGroup _cg = cg; | 343 | QColorGroup _cg = cg; |
344 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 344 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
345 | if (pm && !pm->isNull()) | 345 | if (pm && !pm->isNull()) |
346 | { | 346 | { |
347 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 347 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
348 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 348 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
349 | } | 349 | } |
350 | else if ( isAlternate() ) | 350 | else if ( isAlternate() ) |
351 | { | 351 | { |
352 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); | 352 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); |
353 | } | 353 | } |
354 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 354 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
355 | 355 | ||
356 | //FIXME: Use styling here! | 356 | //FIXME: Use styling here! |
357 | 357 | ||
358 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 358 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
359 | p->setPen( pen ); | 359 | p->setPen( pen ); |
360 | p->drawLine( width-1, 0, width-1, height() ); | 360 | p->drawLine( width-1, 0, width-1, height() ); |
361 | } | 361 | } |
362 | 362 | ||
363 | 363 | ||
364 | OListViewItem* OListViewItem::childFactory() | 364 | OListViewItem* OListViewItem::childFactory() |
365 | { | 365 | { |
366 | return new OListViewItem( this ); | 366 | return new OListViewItem( this ); |
367 | } | 367 | } |
368 | 368 | ||
369 | 369 | ||
370 | #ifndef QT_NO_DATASTREAM | 370 | #ifndef QT_NO_DATASTREAM |
371 | void OListViewItem::serializeTo( QDataStream& s ) const | 371 | void OListViewItem::serializeTo( QDataStream& s ) const |
372 | { | 372 | { |
373 | #warning Caution... the binary format is still under construction... | 373 | #warning Caution... the binary format is still under construction... |
374 | qDebug( "storing OListViewItem..." ); | 374 | qDebug( "storing OListViewItem..." ); |
375 | 375 | ||
376 | // store item text | 376 | // store item text |
377 | for ( int i = 0; i < listView()->columns(); ++i ) | 377 | for ( int i = 0; i < listView()->columns(); ++i ) |
378 | { | 378 | { |
379 | s << text( i ); | 379 | s << text( i ); |
380 | } | 380 | } |
381 | 381 | ||
382 | // calculate the number of children to serialize | 382 | // calculate the number of children to serialize |
383 | int items = 0; | 383 | int items = 0; |
384 | QListViewItem* item = firstChild(); | 384 | QListViewItem* item = firstChild(); |
385 | while ( item ) | 385 | while ( item ) |
386 | { | 386 | { |
387 | item = item->nextSibling(); | 387 | item = item->nextSibling(); |
388 | items++; | 388 | items++; |
389 | } | 389 | } |
390 | 390 | ||
391 | // store number of items and the items itself | 391 | // store number of items and the items itself |
392 | s << items; | 392 | s << items; |
393 | item = firstChild(); | 393 | item = firstChild(); |
394 | for ( int i = 0; i < items; ++i ) | 394 | for ( int i = 0; i < items; ++i ) |
395 | { | 395 | { |
396 | s << *static_cast<OListViewItem*>( item ); | 396 | s << *static_cast<OListViewItem*>( item ); |
397 | item = item->nextSibling(); | 397 | item = item->nextSibling(); |
398 | } | 398 | } |
399 | 399 | ||
400 | qDebug( "OListviewItem stored." ); | 400 | qDebug( "OListviewItem stored." ); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | void OListViewItem::serializeFrom( QDataStream& s ) | 404 | void OListViewItem::serializeFrom( QDataStream& s ) |
405 | { | 405 | { |
406 | #warning Caution... the binary format is still under construction... | 406 | #warning Caution... the binary format is still under construction... |
407 | qDebug( "loading OListViewItem..." ); | 407 | qDebug( "loading OListViewItem..." ); |
408 | 408 | ||
409 | for ( int i = 0; i < listView()->columns(); ++i ) | 409 | for ( int i = 0; i < listView()->columns(); ++i ) |
410 | { | 410 | { |
411 | QString coltext; | 411 | QString coltext; |
412 | s >> coltext; | 412 | s >> coltext; |
413 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 413 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
414 | setText( i, coltext ); | 414 | setText( i, coltext ); |
415 | } | 415 | } |
416 | 416 | ||
417 | int items; | 417 | int items; |
418 | s >> items; | 418 | s >> items; |
419 | qDebug( "read number of items = %d", items ); | 419 | qDebug( "read number of items = %d", items ); |
420 | 420 | ||
421 | for ( int i = 0; i < items; ++i ) | 421 | for ( int i = 0; i < items; ++i ) |
422 | { | 422 | { |
423 | OListViewItem* item = childFactory(); | 423 | OListViewItem* item = childFactory(); |
424 | s >> (*item); | 424 | s >> (*item); |
425 | } | 425 | } |
426 | 426 | ||
427 | qDebug( "OListViewItem loaded." ); | 427 | qDebug( "OListViewItem loaded." ); |
428 | } | 428 | } |
429 | 429 | ||
430 | 430 | ||
431 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 431 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
432 | { | 432 | { |
433 | lvi.serializeTo( s ); | 433 | lvi.serializeTo( s ); |
434 | } | 434 | } |
435 | 435 | ||
436 | 436 | ||
437 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 437 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
438 | { | 438 | { |
439 | lvi.serializeFrom( s ); | 439 | lvi.serializeFrom( s ); |
440 | } | 440 | } |
441 | #endif // QT_NO_DATASTREAM | 441 | #endif // QT_NO_DATASTREAM |
442 | 442 | ||
443 | 443 | ||
444 | /*====================================================================================== | 444 | /*====================================================================================== |
445 | * ONamedListView | 445 | * ONamedListView |
446 | *======================================================================================*/ | 446 | *======================================================================================*/ |
447 | 447 | ||
448 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | 448 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) |
449 | :OListView( parent, name ) | 449 | :OListView( parent, name ) |
450 | { | 450 | { |
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
454 | ONamedListView::~ONamedListView() | 454 | ONamedListView::~ONamedListView() |
455 | { | 455 | { |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | void ONamedListView::addColumns( const QStringList& columns ) | 459 | void 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 | ||
469 | int 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 | |||
481 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const | ||
482 | { | ||
483 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | ||
484 | } | ||
485 | |||
486 | |||
487 | ONamedListViewItem* 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 | |||
511 | ONamedListViewItem* 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 | |||
521 | ONamedListViewItem* 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 | ||
473 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | 535 | ONamedListViewItem::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 | ||
480 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | 542 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) |
481 | :OListViewItem( parent ) | 543 | :OListViewItem( parent ) |
482 | { | 544 | { |
483 | setText( texts ); | 545 | setText( texts ); |
484 | } | 546 | } |
485 | 547 | ||
486 | 548 | ||
487 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | 549 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) |
488 | :OListViewItem( parent, after ) | 550 | :OListViewItem( parent, after ) |
489 | { | 551 | { |
490 | setText( texts ); | 552 | setText( texts ); |
491 | } | 553 | } |
492 | 554 | ||
493 | 555 | ||
494 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | 556 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) |
495 | :OListViewItem( parent, after ) | 557 | :OListViewItem( parent, after ) |
496 | { | 558 | { |
497 | setText( texts ); | 559 | setText( texts ); |
498 | } | 560 | } |
499 | 561 | ||
500 | 562 | ||
501 | ONamedListViewItem::~ONamedListViewItem() | 563 | ONamedListViewItem::~ONamedListViewItem() |
502 | { | 564 | { |
503 | } | 565 | } |
504 | 566 | ||
505 | 567 | ||
506 | void ONamedListViewItem::setText( const QStringList& texts ) | 568 | void ONamedListViewItem::setText( const QStringList& texts ) |
507 | { | 569 | { |
508 | int col = 0; | 570 | int col = 0; |
509 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | 571 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) |
510 | { | 572 | { |
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 | ||
518 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | 580 | void 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 ); | 593 | ONamedListViewItem* 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 | |||
599 | ONamedListViewItem* 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 | |||
@@ -1,310 +1,341 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OLISTVIEW_H | 31 | #ifndef OLISTVIEW_H |
32 | #define OLISTVIEW_H | 32 | #define OLISTVIEW_H |
33 | 33 | ||
34 | #include <qcolor.h> | 34 | #include <qcolor.h> |
35 | #include <qlistview.h> | 35 | #include <qlistview.h> |
36 | #include <qpen.h> | 36 | #include <qpen.h> |
37 | #include <qdatastream.h> | 37 | #include <qdatastream.h> |
38 | 38 | ||
39 | class OListViewItem; | 39 | class OListViewItem; |
40 | 40 | ||
41 | /*====================================================================================== | 41 | /*====================================================================================== |
42 | * OListView | 42 | * OListView |
43 | *======================================================================================*/ | 43 | *======================================================================================*/ |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * @brief A list/tree widget. | 46 | * @brief A list/tree widget. |
47 | * | 47 | * |
48 | * A @ref QListView variant featuring visual and functional enhancements | 48 | * A @ref QListView variant featuring visual and functional enhancements |
49 | * like an alternate background for odd rows, an autostretch mode | 49 | * like an alternate background for odd rows, an autostretch mode |
50 | * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. | 50 | * for the width of the widget ( >= Qt 3 only ) and persistence capabilities. |
51 | * | 51 | * |
52 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 52 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
53 | */ | 53 | */ |
54 | class OListView: public QListView | 54 | class OListView: public QListView |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | /** | 57 | /** |
58 | * Constructor. | 58 | * Constructor. |
59 | * | 59 | * |
60 | * The parameters @a parent and @a name are handled by | 60 | * The parameters @a parent and @a name are handled by |
61 | * @ref QListView, as usual. | 61 | * @ref QListView, as usual. |
62 | */ | 62 | */ |
63 | OListView( QWidget* parent = 0, const char* name = 0 ); | 63 | OListView( QWidget* parent = 0, const char* name = 0 ); |
64 | /** | 64 | /** |
65 | * Destructor. | 65 | * Destructor. |
66 | */ | 66 | */ |
67 | virtual ~OListView(); | 67 | virtual ~OListView(); |
68 | /** | 68 | /** |
69 | * Let the last column fit exactly all the available width. | 69 | * Let the last column fit exactly all the available width. |
70 | */ | 70 | */ |
71 | void setFullWidth( bool fullWidth ); | 71 | void setFullWidth( bool fullWidth ); |
72 | /** | 72 | /** |
73 | * Returns whether the last column is set to fit the available width. | 73 | * Returns whether the last column is set to fit the available width. |
74 | */ | 74 | */ |
75 | bool fullWidth() const; | 75 | bool fullWidth() const; |
76 | /** | 76 | /** |
77 | * Reimplemented for full width support | 77 | * Reimplemented for full width support |
78 | */ | 78 | */ |
79 | virtual int addColumn( const QString& label, int width = -1 ); | 79 | virtual int addColumn( const QString& label, int width = -1 ); |
80 | /** | 80 | /** |
81 | * Reimplemented for full width support | 81 | * Reimplemented for full width support |
82 | */ | 82 | */ |
83 | virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); | 83 | virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 ); |
84 | /** | 84 | /** |
85 | * Reimplemented for full width support | 85 | * Reimplemented for full width support |
86 | */ | 86 | */ |
87 | virtual void removeColumn(int index); | 87 | virtual void removeColumn(int index); |
88 | /** | 88 | /** |
89 | * Set the alternate background background @a color. | 89 | * Set the alternate background background @a color. |
90 | * Set to an invalid color to disable alternate colors. | 90 | * Set to an invalid color to disable alternate colors. |
91 | * This only has an effect if the items are OListViewItems | 91 | * This only has an effect if the items are OListViewItems |
92 | */ | 92 | */ |
93 | void setAlternateBackground( const QColor& color ); | 93 | void setAlternateBackground( const QColor& color ); |
94 | /** | 94 | /** |
95 | * Sets the column separator @a pen. | 95 | * Sets the column separator @a pen. |
96 | */ | 96 | */ |
97 | void setColumnSeparator( const QPen& pen ); | 97 | void setColumnSeparator( const QPen& pen ); |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * @returns the alternate background color | 100 | * @returns the alternate background color |
101 | */ | 101 | */ |
102 | const QColor& alternateBackground() const; | 102 | const QColor& alternateBackground() const; |
103 | /** | 103 | /** |
104 | * @return the column separator pen | 104 | * @return the column separator pen |
105 | */ | 105 | */ |
106 | const QPen& columnSeparator() const; | 106 | const QPen& columnSeparator() const; |
107 | /** | 107 | /** |
108 | * Create a list view item as child of this object | 108 | * Create a list view item as child of this object |
109 | * @returns the new object | 109 | * @returns the new object |
110 | */ | 110 | */ |
111 | virtual OListViewItem* childFactory(); | 111 | virtual OListViewItem* childFactory(); |
112 | #ifndef QT_NO_DATASTREAM | 112 | #ifndef QT_NO_DATASTREAM |
113 | /** | 113 | /** |
114 | * Serialize this object to @ref QDataStream @a stream | 114 | * Serialize this object to @ref QDataStream @a stream |
115 | */ | 115 | */ |
116 | virtual void serializeTo( QDataStream& stream ) const; | 116 | virtual void serializeTo( QDataStream& stream ) const; |
117 | /** | 117 | /** |
118 | * Serialize this object from a @ref QDataStream @a stream | 118 | * Serialize this object from a @ref QDataStream @a stream |
119 | */ | 119 | */ |
120 | virtual void serializeFrom( QDataStream& s ); | 120 | virtual void serializeFrom( QDataStream& s ); |
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | private: | 123 | private: |
124 | QColor m_alternateBackground; | 124 | QColor m_alternateBackground; |
125 | bool m_fullWidth; | 125 | bool m_fullWidth; |
126 | QPen m_columnSeparator; | 126 | QPen m_columnSeparator; |
127 | }; | 127 | }; |
128 | 128 | ||
129 | #ifndef QT_NO_DATASTREAM | 129 | #ifndef QT_NO_DATASTREAM |
130 | /** | 130 | /** |
131 | * @relates OListView | 131 | * @relates OListView |
132 | * Writes @a listview to the @a stream and returns a reference to the stream. | 132 | * Writes @a listview to the @a stream and returns a reference to the stream. |
133 | */ | 133 | */ |
134 | QDataStream& operator<<( QDataStream& stream, const OListView& listview ); | 134 | QDataStream& operator<<( QDataStream& stream, const OListView& listview ); |
135 | /** | 135 | /** |
136 | * @relates OListView | 136 | * @relates OListView |
137 | * Reads @a listview from the @a stream and returns a reference to the stream. | 137 | * Reads @a listview from the @a stream and returns a reference to the stream. |
138 | */ | 138 | */ |
139 | QDataStream& operator>>( QDataStream& stream, OListView& listview ); | 139 | QDataStream& operator>>( QDataStream& stream, OListView& listview ); |
140 | #endif // QT_NO_DATASTREAM | 140 | #endif // QT_NO_DATASTREAM |
141 | 141 | ||
142 | /*====================================================================================== | 142 | /*====================================================================================== |
143 | * OListViewItem | 143 | * OListViewItem |
144 | *======================================================================================*/ | 144 | *======================================================================================*/ |
145 | 145 | ||
146 | class OListViewItem: public QListViewItem | 146 | class OListViewItem: public QListViewItem |
147 | { | 147 | { |
148 | public: | 148 | public: |
149 | /** | 149 | /** |
150 | * Constructors. | 150 | * Constructors. |
151 | */ | 151 | */ |
152 | OListViewItem( QListView * parent ); | 152 | OListViewItem( QListView * parent ); |
153 | OListViewItem( QListViewItem * parent ); | 153 | OListViewItem( QListViewItem * parent ); |
154 | OListViewItem( QListView * parent, QListViewItem * after ); | 154 | OListViewItem( QListView * parent, QListViewItem * after ); |
155 | OListViewItem( QListViewItem * parent, QListViewItem * after ); | 155 | OListViewItem( QListViewItem * parent, QListViewItem * after ); |
156 | 156 | ||
157 | OListViewItem( QListView * parent, | 157 | OListViewItem( QListView * parent, |
158 | QString, QString = QString::null, | 158 | QString, QString = QString::null, |
159 | QString = QString::null, QString = QString::null, | 159 | QString = QString::null, QString = QString::null, |
160 | QString = QString::null, QString = QString::null, | 160 | QString = QString::null, QString = QString::null, |
161 | QString = QString::null, QString = QString::null ); | 161 | QString = QString::null, QString = QString::null ); |
162 | 162 | ||
163 | OListViewItem( QListViewItem * parent, | 163 | OListViewItem( QListViewItem * parent, |
164 | QString, QString = QString::null, | 164 | QString, QString = QString::null, |
165 | QString = QString::null, QString = QString::null, | 165 | QString = QString::null, QString = QString::null, |
166 | QString = QString::null, QString = QString::null, | 166 | QString = QString::null, QString = QString::null, |
167 | QString = QString::null, QString = QString::null ); | 167 | QString = QString::null, QString = QString::null ); |
168 | 168 | ||
169 | OListViewItem( QListView * parent, QListViewItem * after, | 169 | OListViewItem( QListView * parent, QListViewItem * after, |
170 | QString, QString = QString::null, | 170 | QString, QString = QString::null, |
171 | QString = QString::null, QString = QString::null, | 171 | QString = QString::null, QString = QString::null, |
172 | QString = QString::null, QString = QString::null, | 172 | QString = QString::null, QString = QString::null, |
173 | QString = QString::null, QString = QString::null ); | 173 | QString = QString::null, QString = QString::null ); |
174 | 174 | ||
175 | OListViewItem( QListViewItem * parent, QListViewItem * after, | 175 | OListViewItem( QListViewItem * parent, QListViewItem * after, |
176 | QString, QString = QString::null, | 176 | QString, QString = QString::null, |
177 | QString = QString::null, QString = QString::null, | 177 | QString = QString::null, QString = QString::null, |
178 | QString = QString::null, QString = QString::null, | 178 | QString = QString::null, QString = QString::null, |
179 | QString = QString::null, QString = QString::null ); | 179 | QString = QString::null, QString = QString::null ); |
180 | /** | 180 | /** |
181 | * Destructor. | 181 | * Destructor. |
182 | */ | 182 | */ |
183 | virtual ~OListViewItem(); | 183 | virtual ~OListViewItem(); |
184 | /** | 184 | /** |
185 | * @returns the background color of the list item. | 185 | * @returns the background color of the list item. |
186 | */ | 186 | */ |
187 | const QColor& backgroundColor(); | 187 | const QColor& backgroundColor(); |
188 | /** | 188 | /** |
189 | * @returns true, if the item is at an odd position and | 189 | * @returns true, if the item is at an odd position and |
190 | * thus have to be painted with the alternate background color. | 190 | * thus have to be painted with the alternate background color. |
191 | */ | 191 | */ |
192 | bool isAlternate(); | 192 | bool isAlternate(); |
193 | /** | 193 | /** |
194 | * @note: Reimplemented for internal purposes - the API is not affected | 194 | * @note: Reimplemented for internal purposes - the API is not affected |
195 | * | 195 | * |
196 | */ | 196 | */ |
197 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); | 197 | void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ); |
198 | /** | 198 | /** |
199 | * Perform object initialization. | 199 | * Perform object initialization. |
200 | */ | 200 | */ |
201 | void init(); | 201 | void init(); |
202 | /** | 202 | /** |
203 | * create a list view item as child of this object | 203 | * create a list view item as child of this object |
204 | * @returns the new object | 204 | * @returns the new object |
205 | */ | 205 | */ |
206 | virtual OListViewItem* childFactory(); | 206 | virtual OListViewItem* childFactory(); |
207 | #ifndef QT_NO_DATASTREAM | 207 | #ifndef QT_NO_DATASTREAM |
208 | /** | 208 | /** |
209 | * serialize this object to or from a @ref QDataStream | 209 | * serialize this object to or from a @ref QDataStream |
210 | * @param s the stream used to serialize this object. | 210 | * @param s the stream used to serialize this object. |
211 | */ | 211 | */ |
212 | virtual void serializeTo( QDataStream& s ) const; | 212 | virtual void serializeTo( QDataStream& s ) const; |
213 | 213 | ||
214 | /** | 214 | /** |
215 | * serialize this object to or from a @ref QDataStream | 215 | * serialize this object to or from a @ref QDataStream |
216 | * @param s the stream used to serialize this object. | 216 | * @param s the stream used to serialize this object. |
217 | */ | 217 | */ |
218 | virtual void serializeFrom( QDataStream& s ); | 218 | virtual void serializeFrom( QDataStream& s ); |
219 | #endif | 219 | #endif |
220 | 220 | ||
221 | private: | 221 | private: |
222 | bool m_known; | 222 | bool m_known; |
223 | bool m_odd; | 223 | bool m_odd; |
224 | }; | 224 | }; |
225 | 225 | ||
226 | #ifndef QT_NO_DATASTREAM | 226 | #ifndef QT_NO_DATASTREAM |
227 | /** | 227 | /** |
228 | * @relates QListViewItem | 228 | * @relates QListViewItem |
229 | * Writes listview @a item and all subitems recursively to @a stream | 229 | * Writes listview @a item and all subitems recursively to @a stream |
230 | * and returns a reference to the stream. | 230 | * and returns a reference to the stream. |
231 | */ | 231 | */ |
232 | QDataStream& operator<<( QDataStream& stream, const OListViewItem& item ); | 232 | QDataStream& 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 | */ |
237 | QDataStream& operator>>( QDataStream& stream, OListViewItem& item ); | 237 | QDataStream& 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 | ||
244 | class 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 | */ |
251 | class ONamedListView: public OListView | 253 | class 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 | */ |
282 | class ONamedListViewItem: public OListViewItem | 302 | class 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 ); |
291 | ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); | 311 | ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ); |
292 | ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); | 312 | ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ); |
293 | /** | 313 | /** |
294 | * Destructor. | 314 | * Destructor. |
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 |