summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.h181
-rw-r--r--libopie2/opieui/odialog.h3
-rw-r--r--libopie2/qt3/opiecore/ocompletion.h1
3 files changed, 161 insertions, 24 deletions
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index e249aee..10f52b8 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,322 +1,461 @@
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/* QT */ 37/* QT */
38 38
39#include <qvaluelist.h> 39#include <qvaluelist.h>
40#include <qdict.h> 40#include <qdict.h>
41#include <qmap.h> 41#include <qmap.h>
42#include <qobject.h> 42#include <qobject.h>
43#include <qhostaddress.h> 43#include <qhostaddress.h>
44 44
45/* OPIE */ 45/* OPIE */
46 46
47#include <opie2/onetutils.h> 47#include <opie2/onetutils.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 a user header for the Wireless Extensions, something like <net/wireless.h> 59// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
60// ML: I will drop Jean an mail on that subject 60// ML: I will drop Jean an 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
66class ONetworkInterface; 66class ONetworkInterface;
67class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
68class OChannelHopper; 68class OChannelHopper;
69class OMonitoringInterface; 69class OMonitoringInterface;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * ONetwork 72 * ONetwork
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/**
76 * @brief A container class for all network devices.
77 *
78 * This class provides access to all available network devices of your computer.
79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
80 */
75class ONetwork : public QObject 81class ONetwork : public QObject
76{ 82{
77 Q_OBJECT 83 Q_OBJECT
78 84
79 public: 85 public:
80 typedef QDict<ONetworkInterface> InterfaceMap; 86 typedef QDict<ONetworkInterface> InterfaceMap;
81 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 87 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
82 88
83 public: 89 public:
90 /**
91 * @returns a pointer to the (one and only) @ref ONetwork instance.
92 */
84 static ONetwork* instance(); 93 static ONetwork* instance();
94 /**
95 * @returns an iterator usable for iterating through all network interfaces.
96 */
85 InterfaceIterator iterator() const; 97 InterfaceIterator iterator() const;
86 bool isWirelessInterface( const char* ) const; 98 /**
87 ONetworkInterface* interface( QString ) const; 99 * @returns true, if the @p interface supports the wireless extension protocol.
100 */
101 bool isWirelessInterface( const char* interface ) const;
102 /**
103 * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found
104 * @see ONetworkInterface
105 */
106 ONetworkInterface* interface( QString interface ) const;
88 107
89 protected: 108 protected:
90 ONetwork(); 109 ONetwork();
91 void synchronize(); 110 void synchronize();
92 111
93 private: 112 private:
94 static ONetwork* _instance; 113 static ONetwork* _instance;
95 InterfaceMap _interfaces; 114 InterfaceMap _interfaces;
96}; 115};
97 116
98 117
99/*====================================================================================== 118/*======================================================================================
100 * ONetworkInterface 119 * ONetworkInterface
101 *======================================================================================*/ 120 *======================================================================================*/
102 121
122/**
123 * @brief A network interface wrapper.
124 *
125 * This class provides a wrapper for a network interface. All the cumbersume details of
126 * Linux ioctls are hidden under a convenient high-level interface.
127 * @warning Most of the setting methods contained in this class require the appropriate
128 * process permissions to work.
129 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
130 */
103class ONetworkInterface : public QObject 131class ONetworkInterface : public QObject
104{ 132{
105 friend class OMonitoringInterface; 133 friend class OMonitoringInterface;
106 friend class OCiscoMonitoringInterface; 134 friend class OCiscoMonitoringInterface;
107 friend class OWlanNGMonitoringInterface; 135 friend class OWlanNGMonitoringInterface;
108 friend class OHostAPMonitoringInterface; 136 friend class OHostAPMonitoringInterface;
109 friend class OOrinocoMonitoringInterface; 137 friend class OOrinocoMonitoringInterface;
110 138
111 public: 139 public:
140 /**
141 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
142 * but access them via @ref ONetwork::interface().
143 */
112 ONetworkInterface( QObject* parent, const char* name ); 144 ONetworkInterface( QObject* parent, const char* name );
145 /**
146 * Destructor.
147 */
113 virtual ~ONetworkInterface(); 148 virtual ~ONetworkInterface();
114 149 /**
115 void setMonitoring( OMonitoringInterface* ); 150 * Associates a @a monitoring interface with this network interface.
151 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
152 */
153 void setMonitoring( OMonitoringInterface* monitoring );
154 /**
155 * @returns the currently associated monitoring interface or 0, if no monitoring is associated.
156 */
116 OMonitoringInterface* monitoring() const; 157 OMonitoringInterface* monitoring() const;
158 /**
159 * Setting an interface to promiscuous mode enables the device to receive
160 * all packets on the shared medium - as opposed to packets which are addressed to this interface.
161 */
117 bool setPromiscuousMode( bool ); 162 bool setPromiscuousMode( bool );
163 /**
164 * @returns true if the interface is set to promiscuous mode.
165 */
118 bool promiscuousMode() const; 166 bool promiscuousMode() const;
167 /**
168 * Setting an interface to up enables it to receive packets.
169 */
119 bool setUp( bool ); 170 bool setUp( bool );
171 /**
172 * @returns true if the interface is up.
173 */
120 bool isUp() const; 174 bool isUp() const;
175 /*
176 * @returns true if the interface is a loopback interface.
177 */
121 bool isLoopback() const; 178 bool isLoopback() const;
179 /*
180 * @returns true if the interface is featuring supports the wireless extension protocol.
181 */
122 bool isWireless() const; 182 bool isWireless() const;
183 /*
184 * @returns the IPv4 address associated with this interface.
185 */
123 QString ipV4Address() const; 186 QString ipV4Address() const;
124 void setMacAddress( const OMacAddress& ); 187 /*
188 * Associate the MAC address @a addr with the interface.
189 * @note It can be necessary to shut down the interface prior to calling this method.
190 * @warning This is not supported by all drivers.
191 */
192 void setMacAddress( const OMacAddress& addr );
193 /*
194 * @returns the MAC address associated with this interface.
195 */
125 OMacAddress macAddress() const; 196 OMacAddress macAddress() const;
197 /*
198 * @returns the data link type currently associated with this interface.
199 * @see #include <net/if_arp.h> for possible values.
200 */
126 int dataLinkType() const; 201 int dataLinkType() const;
127 202
128 protected: 203 protected:
129 const int _sfd; 204 const int _sfd;
130 mutable ifreq _ifr; 205 mutable ifreq _ifr;
131 OMonitoringInterface* _mon; 206 OMonitoringInterface* _mon;
132 207
133 protected: 208 protected:
134 struct ifreq& ifr() const; 209 struct ifreq& ifr() const;
135 virtual void init(); 210 virtual void init();
136 bool ioctl( int call ) const; 211 bool ioctl( int call ) const;
137 bool ioctl( int call, struct ifreq& ) const; 212 bool ioctl( int call, struct ifreq& ) const;
138}; 213};
139 214
140/*====================================================================================== 215/*======================================================================================
141 * OChannelHopper 216 * OChannelHopper
142 *======================================================================================*/ 217 *======================================================================================*/
143 218
219/**
220 * @brief A radio frequency channel hopper.
221 *
222 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
223 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
224 * This is necessary when in monitoring mode and scanning for other devices, because
225 * the radio frequency hardware can only detect packets sent on the same frequency.
226 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
227 */
144class OChannelHopper : public QObject 228class OChannelHopper : public QObject
145{ 229{
146 public: 230 public:
147 OChannelHopper( OWirelessNetworkInterface* ); 231 OChannelHopper( OWirelessNetworkInterface* );
148 virtual ~OChannelHopper(); 232 virtual ~OChannelHopper();
149 bool isActive() const; 233 bool isActive() const;
150 int channel() const; 234 int channel() const;
151 virtual void timerEvent( QTimerEvent* ); 235 virtual void timerEvent( QTimerEvent* );
152 void setInterval( int ); 236 void setInterval( int );
153 int interval() const; 237 int interval() const;
154 238
155 private: 239 private:
156 OWirelessNetworkInterface* _iface; 240 OWirelessNetworkInterface* _iface;
157 int _interval; 241 int _interval;
158 int _tid; 242 int _tid;
159 QValueList<int> _channels; 243 QValueList<int> _channels;
160 QValueList<int>::Iterator _channel; 244 QValueList<int>::Iterator _channel;
161
162}; 245};
163 246
164 247
165/*====================================================================================== 248/*======================================================================================
166 * OWirelessNetworkInterface 249 * OWirelessNetworkInterface
167 *======================================================================================*/ 250 *======================================================================================*/
168 251
252/**
253 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
254 *
255 * This class provides a high-level encapsulation of the Linux wireless extension API.
256 */
169class OWirelessNetworkInterface : public ONetworkInterface 257class OWirelessNetworkInterface : public ONetworkInterface
170{ 258{
171 friend class OMonitoringInterface; 259 friend class OMonitoringInterface;
172 friend class OCiscoMonitoringInterface; 260 friend class OCiscoMonitoringInterface;
173 friend class OWlanNGMonitoringInterface; 261 friend class OWlanNGMonitoringInterface;
174 friend class OHostAPMonitoringInterface; 262 friend class OHostAPMonitoringInterface;
175 friend class OOrinocoMonitoringInterface; 263 friend class OOrinocoMonitoringInterface;
176 264
177 friend class OPrivateIOCTL; 265 friend class OPrivateIOCTL;
178 266
179 public: 267 public:
180 enum Mode { AdHoc, Managed, Monitor }; 268 enum Mode { AdHoc, Managed, Monitor };
181 269
270 /**
271 * Constructor.
272 */
182 OWirelessNetworkInterface( QObject* parent, const char* name ); 273 OWirelessNetworkInterface( QObject* parent, const char* name );
274 /**
275 * Destructor.
276 */
183 virtual ~OWirelessNetworkInterface(); 277 virtual ~OWirelessNetworkInterface();
184 278 /**
185 virtual void setChannel( int ) const; 279 * Setting the @a channel of the interface changes the radio frequency (RF)
280 * of the corresponding wireless network device.
281 */
282 virtual void setChannel( int channel ) const;
283 /**
284 * @returns the channel index of the current radio frequency.
285 */
186 virtual int channel() const; 286 virtual int channel() const;
287 /**
288 * @returns the current radio frequency (in MHz).
289 */
187 virtual double frequency() const; 290 virtual double frequency() const;
291 /**
292 * @returns the number of radio frequency channels for the
293 * corresponding wireless network device.
294 * @note European devices usually have 14 channels, while American typically feature 11 channels.
295 */
188 virtual int channels() const; 296 virtual int channels() const;
189 //virtual double frequency(int) const; 297 //virtual double frequency(int) const;
190 298
191 virtual void setMode( Mode ) {}; 299 virtual void setMode( Mode ) {}; //FIXME: Implement and document this
192 virtual bool mode() const {}; 300 virtual bool mode() const {}; //FIXME: Implement and document this
193 301
302 /**
303 * Setting the monitor mode on a wireless network interface enables
304 * listening to IEEE 802.11 data and management frames which normally
305 * are handled by the device firmware. This can be used to detect
306 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
307 * @warning Standard wireless network drives don't support the monitor mode.
308 * @warning You need a patched driver for this to work.
309 * @note Enabling the monitor mode is highly driver dependent and requires
310 * the proper @ref OMonitoringInterface to be associated with the interface.
311 * @see OMonitoringInterface
312 */
194 virtual void setMonitorMode( bool ); 313 virtual void setMonitorMode( bool );
314 /**
315 * @returns true if the device is listening in IEEE 802.11 monitor mode
316 */
195 virtual bool monitorMode() const; 317 virtual bool monitorMode() const;
196 318 /**
319 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
320 * @see OChannelHopper
321 */
197 virtual void setChannelHopping( int interval = 0 ); 322 virtual void setChannelHopping( int interval = 0 );
323 /**
324 * @returns the channel hopping interval or 0, if channel hopping is disabled.
325 */
198 virtual int channelHopping() const; 326 virtual int channelHopping() const;
199 327 /**
200 virtual void setNickName( const QString& ) {}; 328 * Set the station @a nickname.
329 */
330 virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this
331 /**
332 * @returns the current station nickname.
333 */
201 virtual QString nickName() const; 334 virtual QString nickName() const;
202 335 /**
203 virtual void setPrivate( const QString&, int, ... ); 336 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
204 virtual bool hasPrivate( const QString& ); 337 * @see OPrivateIOCTL
205 virtual void getPrivate( const QString& ); 338 */
206 339 virtual void setPrivate( const QString& command, int number, ... );
207 virtual bool isAssociated() const {}; 340 /**
208 virtual QString associatedAP() const; 341 * @returns true if the interface is featuring the private IOCTL @command.
342 */
343 virtual bool hasPrivate( const QString& command );
344 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
345
346 virtual bool isAssociated() const {}; //FIXME: Implement and document this
347 virtual QString associatedAP() const; //FIXME: Implement and document this
209 348
210 virtual void setSSID( const QString& ); 349 virtual void setSSID( const QString& );
211 virtual QString SSID() const; 350 virtual QString SSID() const;
212 351
213 protected: 352 protected:
214 void buildChannelList(); 353 void buildChannelList();
215 void buildPrivateList(); 354 void buildPrivateList();
216 virtual void init(); 355 virtual void init();
217 struct iwreq& iwr() const; 356 struct iwreq& iwr() const;
218 bool wioctl( int call ) const; 357 bool wioctl( int call ) const;
219 bool wioctl( int call, struct iwreq& ) const; 358 bool wioctl( int call, struct iwreq& ) const;
220 359
221 protected: 360 protected:
222 mutable struct iwreq _iwr; 361 mutable struct iwreq _iwr;
223 QMap<int,int> _channels; 362 QMap<int,int> _channels;
224 363
225 private: 364 private:
226 OChannelHopper* _hopper; 365 OChannelHopper* _hopper;
227}; 366};
228 367
229 368
230/*====================================================================================== 369/*======================================================================================
231 * OMonitoringInterface 370 * OMonitoringInterface
232 *======================================================================================*/ 371 *======================================================================================*/
233 372
234 373
235class OMonitoringInterface 374class OMonitoringInterface
236{ 375{
237 public: 376 public:
238 OMonitoringInterface(); 377 OMonitoringInterface();
239 OMonitoringInterface( ONetworkInterface* ); 378 OMonitoringInterface( ONetworkInterface* );
240 virtual ~OMonitoringInterface(); 379 virtual ~OMonitoringInterface();
241 380
242 public: 381 public:
243 virtual void setEnabled( bool ); 382 virtual void setEnabled( bool );
244 virtual bool enabled() const; 383 virtual bool enabled() const;
245 virtual void setChannel( int ); 384 virtual void setChannel( int );
246 385
247 virtual QString name() const = 0; 386 virtual QString name() const = 0;
248 387
249 protected: 388 protected:
250 OWirelessNetworkInterface* _if; 389 OWirelessNetworkInterface* _if;
251 390
252}; 391};
253 392
254 393
255/*====================================================================================== 394/*======================================================================================
256 * OCiscoMonitoring 395 * OCiscoMonitoring
257 *======================================================================================*/ 396 *======================================================================================*/
258 397
259 398
260class OCiscoMonitoringInterface : public OMonitoringInterface 399class OCiscoMonitoringInterface : public OMonitoringInterface
261{ 400{
262 public: 401 public:
263 OCiscoMonitoringInterface( ONetworkInterface* ); 402 OCiscoMonitoringInterface( ONetworkInterface* );
264 virtual ~OCiscoMonitoringInterface(); 403 virtual ~OCiscoMonitoringInterface();
265 404
266 virtual void setEnabled( bool ); 405 virtual void setEnabled( bool );
267 virtual QString name() const; 406 virtual QString name() const;
268 virtual void setChannel( int ); 407 virtual void setChannel( int );
269 408
270}; 409};
271 410
272/*====================================================================================== 411/*======================================================================================
273 * OWlanNGMonitoringInterface 412 * OWlanNGMonitoringInterface
274 *======================================================================================*/ 413 *======================================================================================*/
275 414
276class OWlanNGMonitoringInterface : public OMonitoringInterface 415class OWlanNGMonitoringInterface : public OMonitoringInterface
277{ 416{
278 public: 417 public:
279 OWlanNGMonitoringInterface( ONetworkInterface* ); 418 OWlanNGMonitoringInterface( ONetworkInterface* );
280 virtual ~OWlanNGMonitoringInterface(); 419 virtual ~OWlanNGMonitoringInterface();
281 420
282 public: 421 public:
283 virtual void setEnabled( bool ); 422 virtual void setEnabled( bool );
284 virtual QString name() const; 423 virtual QString name() const;
285 virtual void setChannel( int ); 424 virtual void setChannel( int );
286 425
287}; 426};
288 427
289/*====================================================================================== 428/*======================================================================================
290 * OHostAPMonitoringInterface 429 * OHostAPMonitoringInterface
291 *======================================================================================*/ 430 *======================================================================================*/
292 431
293class OHostAPMonitoringInterface : public OMonitoringInterface 432class OHostAPMonitoringInterface : public OMonitoringInterface
294{ 433{
295 public: 434 public:
296 OHostAPMonitoringInterface( ONetworkInterface* ); 435 OHostAPMonitoringInterface( ONetworkInterface* );
297 virtual ~OHostAPMonitoringInterface(); 436 virtual ~OHostAPMonitoringInterface();
298 437
299 public: 438 public:
300 virtual void setEnabled( bool ); 439 virtual void setEnabled( bool );
301 virtual QString name() const; 440 virtual QString name() const;
302 }; 441 };
303 442
304/*====================================================================================== 443/*======================================================================================
305 * OOrinocoMonitoringInterface 444 * OOrinocoMonitoringInterface
306 *======================================================================================*/ 445 *======================================================================================*/
307 446
308class OOrinocoMonitoringInterface : public OMonitoringInterface 447class OOrinocoMonitoringInterface : public OMonitoringInterface
309{ 448{
310 public: 449 public:
311 OOrinocoMonitoringInterface( ONetworkInterface* ); 450 OOrinocoMonitoringInterface( ONetworkInterface* );
312 virtual ~OOrinocoMonitoringInterface(); 451 virtual ~OOrinocoMonitoringInterface();
313 452
314 public: 453 public:
315 virtual void setChannel( int ); 454 virtual void setChannel( int );
316 virtual void setEnabled( bool ); 455 virtual void setEnabled( bool );
317 virtual QString name() const; 456 virtual QString name() const;
318 457
319}; 458};
320 459
321#endif // ONETWORK_H 460#endif // ONETWORK_H
322 461
diff --git a/libopie2/opieui/odialog.h b/libopie2/opieui/odialog.h
index 38f25e8..7947dfb 100644
--- a/libopie2/opieui/odialog.h
+++ b/libopie2/opieui/odialog.h
@@ -1,89 +1,88 @@
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 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef ODIALOG_H 32#ifndef ODIALOG_H
33#define ODIALOG_H 33#define ODIALOG_H
34 34
35class QLayoutItem; 35class QLayoutItem;
36 36
37#include <qdialog.h> 37#include <qdialog.h>
38 38
39/** 39/**
40 * Dialog with extended nonmodal support and methods for OPIE standard 40 * Dialog with extended nonmodal support and methods for OPIE standard
41 * compliance. 41 * compliance.
42 * 42 *
43 * The @ref marginHint() and @ref spacingHint() sizes shall be used 43 * The @ref marginHint() and @ref spacingHint() sizes shall be used
44 * whenever you layout the interior of a dialog. One special note. If 44 * whenever you layout the interior of a dialog. One special note. If
45 * you make your own action buttons (OK, Cancel etc), the space 45 * you make your own action buttons (OK, Cancel etc), the space
46 * beteween the buttons shall be @ref spacingHint(), whereas the space 46 * beteween the buttons shall be @ref spacingHint(), whereas the space
47 * above, below, to the right and to the left shall be @ref marginHint(). 47 * above, below, to the right and to the left shall be @ref marginHint().
48 * If you add a separator line above the buttons, there shall be a 48 * If you add a separator line above the buttons, there shall be a
49 * @ref marginHint() between the buttons and the separator and a 49 * @ref marginHint() between the buttons and the separator and a
50 * @ref marginHint() above the separator as well. 50 * @ref marginHint() above the separator as well.
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 54
55class ODialog : public QDialog 55class ODialog : public QDialog
56{ 56{
57 Q_OBJECT 57 Q_OBJECT
58 58
59 public: 59 public:
60 60
61 /** 61 /**
62 * Constructor. 62 * Constructor.
63 * 63 *
64 * Takes the same arguments as @ref QDialog. 64 * Takes the same arguments as @ref QDialog.
65 */ 65 */
66 ODialog(QWidget *parent = 0, const char *name = 0, 66 ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
67 bool modal = false, WFlags f = 0);
68 67
69 /** 68 /**
70 * Return the number of pixels you shall use between a 69 * Return the number of pixels you shall use between a
71 * dialog edge and the outermost widget(s) according to the KDE standard. 70 * dialog edge and the outermost widget(s) according to the KDE standard.
72 **/ 71 **/
73 static int marginHint(); 72 static int marginHint();
74 73
75 /** 74 /**
76 * Return the number of pixels you shall use between 75 * Return the number of pixels you shall use between
77 * widgets inside a dialog according to the KDE standard. 76 * widgets inside a dialog according to the KDE standard.
78 */ 77 */
79 static int spacingHint(); 78 static int spacingHint();
80 79
81 private: 80 private:
82 static int mMarginSize; 81 static int mMarginSize;
83 static int mSpacingSize; 82 static int mSpacingSize;
84 83
85 //class ODialogPrivate; 84 //class ODialogPrivate;
86 //ODialogPrivate *d; 85 //ODialogPrivate *d;
87 86
88}; 87};
89#endif // ODIALOG_H 88#endif // ODIALOG_H
diff --git a/libopie2/qt3/opiecore/ocompletion.h b/libopie2/qt3/opiecore/ocompletion.h
index 0317c1b..7f28182 100644
--- a/libopie2/qt3/opiecore/ocompletion.h
+++ b/libopie2/qt3/opiecore/ocompletion.h
@@ -1,603 +1,602 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 Originally part of the KDE Project 3 Originally part of the KDE Project
4 Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org> 4 Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#ifndef OCOMPLETION_H 31#ifndef OCOMPLETION_H
32#define OCOMPLETION_H 32#define OCOMPLETION_H
33 33
34/* QT */ 34/* QT */
35 35
36#include <qmap.h> 36#include <qmap.h>
37#include <qlist.h> 37#include <qlist.h>
38#include <qobject.h> 38#include <qobject.h>
39#include <qstring.h> 39#include <qstring.h>
40#include <qstringlist.h> 40#include <qstringlist.h>
41#include <qguardedptr.h> 41#include <qguardedptr.h>
42 42
43/* OPIE */ 43/* OPIE */
44 44
45#include <opie2/oglobalsettings.h> 45#include <opie2/oglobalsettings.h>
46#include <opie2/osortablevaluelist.h> 46#include <opie2/osortablevaluelist.h>
47 47
48/* FORWARDS */ 48/* FORWARDS */
49 49
50class OCompTreeNode; 50class OCompTreeNode;
51class OCompletionPrivate; 51class OCompletionPrivate;
52class OCompletionBasePrivate; 52class OCompletionBasePrivate;
53class OCompletionMatchesWrapper; 53class OCompletionMatchesWrapper;
54class OCompletionMatches; 54class OCompletionMatches;
55class QPopupMenu; 55class QPopupMenu;
56 56
57// FIXME: Do we need special ShortCut handling in Opie? If so, revise this. 57// FIXME: Do we need special ShortCut handling in Opie? If so, revise this.
58class OShortcut 58class OShortcut
59{ 59{
60public: 60public:
61 bool isNull() const { return true; }; 61 bool isNull() const { return true; };
62 bool operator == ( const OShortcut& bla ) const { return false; }; 62 bool operator == ( const OShortcut& bla ) const { return false; };
63}; 63};
64 64
65 65
66/** 66/**
67 * This class offers easy use of "auto-completion", "manual-completion" or 67 * This class offers easy use of "auto-completion", "manual-completion" or
68 * "shell completion" on QString objects. A common use is completing filenames 68 * "shell completion" on QString objects. A common use is completing filenames
69 * or URLs (see @ref OURLCompletion()). 69 * or URLs (see @ref OURLCompletion()).
70 * But it is not limited to URL-completion -- everything should be completable! 70 * But it is not limited to URL-completion -- everything should be completable!
71 * The user should be able to complete email-addresses, telephone-numbers, 71 * The user should be able to complete email-addresses, telephone-numbers,
72 * commands, SQL queries, ... 72 * commands, SQL queries, ...
73 * Every time your program knows what the user can type into an edit-field, you 73 * Every time your program knows what the user can type into an edit-field, you
74 * should offer completion. With OCompletion, this is very easy, and if you are 74 * should offer completion. With OCompletion, this is very easy, and if you are
75 * using a line edit widget (@ref OLineEdit), it is even more easy. 75 * using a line edit widget (@ref OLineEdit), it is even more easy.
76 * Basically, you tell a OCompletion object what strings should be completable 76 * Basically, you tell a OCompletion object what strings should be completable
77 * and whenever completion should be invoked, you call @ref makeCompletion(). 77 * and whenever completion should be invoked, you call @ref makeCompletion().
78 * OLineEdit and (an editable) OComboBox even do this automatically for you. 78 * OLineEdit and (an editable) OComboBox even do this automatically for you.
79 * 79 *
80 * OCompletion offers the completed string via the signal @ref match() and 80 * OCompletion offers the completed string via the signal @ref match() and
81 * all matching strings (when the result is ambiguous) via the method 81 * all matching strings (when the result is ambiguous) via the method
82 * @ref allMatches(). 82 * @ref allMatches().
83 * 83 *
84 * Notice: auto-completion, shell completion and manual completion work 84 * Notice: auto-completion, shell completion and manual completion work
85 * slightly differently: 85 * slightly differently:
86 * 86 *
87 * @li auto-completion always returns a complete item as match. 87 * @li auto-completion always returns a complete item as match.
88 * When more than one matching items are available, it will deliver just 88 * When more than one matching items are available, it will deliver just
89 * the first (depending on sorting order) item. Iterating over all matches 89 * the first (depending on sorting order) item. Iterating over all matches
90 * is possible via @ref nextMatch() and @ref previousMatch(). 90 * is possible via @ref nextMatch() and @ref previousMatch().
91 * 91 *
92 * @li popup-completion works in the same way, the only difference being that 92 * @li popup-completion works in the same way, the only difference being that
93 * the completed items are not put into the edit-widget, but into a 93 * the completed items are not put into the edit-widget, but into a
94 * separate popup-box. 94 * separate popup-box.
95 * 95 *
96 * @li manual completion works the same way as auto-completion, the 96 * @li manual completion works the same way as auto-completion, the
97 * subtle difference is, that it isn't invoked automatically while the user 97 * subtle difference is, that it isn't invoked automatically while the user
98 * is typing, but only when the user presses a special key. The difference 98 * is typing, but only when the user presses a special key. The difference
99 * of manual and auto-completion is therefore only visible in UI classes, 99 * of manual and auto-completion is therefore only visible in UI classes,
100 * OCompletion needs to know whether to deliver partial matches 100 * OCompletion needs to know whether to deliver partial matches
101 * (shell completion) or whole matches (auto/manual completion), therefore 101 * (shell completion) or whole matches (auto/manual completion), therefore
102 * @ref OGlobalSettings::CompletionMan and 102 * @ref OGlobalSettings::CompletionMan and
103 * @ref OGlobalSettings::CompletionAuto have the exact same effect in 103 * @ref OGlobalSettings::CompletionAuto have the exact same effect in
104 * OCompletion. 104 * OCompletion.
105 * 105 *
106 * @li shell completion works like how shells complete filenames: 106 * @li shell completion works like how shells complete filenames:
107 * when multiple matches are available, the longest possible string of all 107 * when multiple matches are available, the longest possible string of all
108 * matches is returned (i.e. only a partial item). 108 * matches is returned (i.e. only a partial item).
109 * Iterating over all matching items (complete, not partial) is possible 109 * Iterating over all matching items (complete, not partial) is possible
110 * via @ref nextMatch() and @ref previousMatch(). 110 * via @ref nextMatch() and @ref previousMatch().
111 * 111 *
112 * You don't have to worry much about that though, OCompletion handles 112 * You don't have to worry much about that though, OCompletion handles
113 * that for you, according to the setting @ref setCompletionMode(). 113 * that for you, according to the setting @ref setCompletionMode().
114 * The default setting is globally configured by the user and read 114 * The default setting is globally configured by the user and read
115 * from @ref OGlobalSettings::completionMode(). 115 * from @ref OGlobalSettings::completionMode().
116 * 116 *
117 * A short example: 117 * A short example:
118 * <pre> 118 * <pre>
119 * OCompletion completion; 119 * OCompletion completion;
120 * completion.setOrder( OCompletion::Sorted ); 120 * completion.setOrder( OCompletion::Sorted );
121 * completion.addItem( "pfeiffer@kde.org" ); 121 * completion.addItem( "pfeiffer@kde.org" );
122 * completion.addItem( "coolo@kde.org" ); 122 * completion.addItem( "coolo@kde.org" );
123 * completion.addItem( "carpdjih@sp.zrz.tu-berlin.de" ); 123 * completion.addItem( "carpdjih@sp.zrz.tu-berlin.de" );
124 * completion.addItem( "carp@cs.tu-berlin.de" ); 124 * completion.addItem( "carp@cs.tu-berlin.de" );
125 * 125 *
126 * cout << completion.makeCompletion( "ca" ).latin1() << endl; 126 * cout << completion.makeCompletion( "ca" ).latin1() << endl;
127 * </pre> 127 * </pre>
128 * In shell-completion-mode, this will be "carp"; in auto-completion- 128 * In shell-completion-mode, this will be "carp"; in auto-completion-
129 * mode it will be "carp@cs.tu-berlin.de", as that is alphabetically 129 * mode it will be "carp@cs.tu-berlin.de", as that is alphabetically
130 * smaller. 130 * smaller.
131 * If setOrder was set to Insertion, "carpdjih@sp.zrz.tu-berlin.de" 131 * If setOrder was set to Insertion, "carpdjih@sp.zrz.tu-berlin.de"
132 * would be completed in auto-completion-mode, as that was inserted before 132 * would be completed in auto-completion-mode, as that was inserted before
133 * "carp@cs.tu-berlin.de". 133 * "carp@cs.tu-berlin.de".
134 * 134 *
135 * You can dynamically update the completable items by removing and adding them 135 * You can dynamically update the completable items by removing and adding them
136 * whenever you want. 136 * whenever you want.
137 * For advanced usage, you could even use multiple OCompletion objects. E.g. 137 * For advanced usage, you could even use multiple OCompletion objects. E.g.
138 * imagine an editor like kwrite with multiple open files. You could store 138 * imagine an editor like kwrite with multiple open files. You could store
139 * items of each file in a different OCompletion object, so that you know (and 139 * items of each file in a different OCompletion object, so that you know (and
140 * tell the user) where a completion comes from. 140 * tell the user) where a completion comes from.
141 * 141 *
142 * Note: OCompletion does not work with strings that contain 0x0 characters 142 * Note: OCompletion does not work with strings that contain 0x0 characters
143 * (unicode nul), as this is used internally as a delimiter. 143 * (unicode nul), as this is used internally as a delimiter.
144 * 144 *
145 * You may inherit from OCompletion and override @ref makeCompletion() in 145 * You may inherit from OCompletion and override @ref makeCompletion() in
146 * special cases (like reading directories/urls and then supplying the 146 * special cases (like reading directories/urls and then supplying the
147 * contents to OCompletion, as OURLCompletion does), but generally, this is 147 * contents to OCompletion, as OURLCompletion does), but generally, this is
148 * not necessary. 148 * not necessary.
149 * 149 *
150 * 150 *
151 * @short A generic class for completing QStrings 151 * @short A generic class for completing QStrings
152 * @author Carsten Pfeiffer <pfeiffer@kde.org> 152 * @author Carsten Pfeiffer <pfeiffer@kde.org>
153 * @version $Id$
154 */ 153 */
155 154
156class OCompletion : public QObject 155class OCompletion : public QObject
157{ 156{
158 Q_ENUMS( CompOrder ) 157 Q_ENUMS( CompOrder )
159 Q_PROPERTY( CompOrder order READ order WRITE setOrder ) 158 Q_PROPERTY( CompOrder order READ order WRITE setOrder )
160 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase ) 159 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
161 Q_PROPERTY( QStringList items READ items WRITE setItems ) 160 Q_PROPERTY( QStringList items READ items WRITE setItems )
162 Q_OBJECT 161 Q_OBJECT
163 162
164 public: 163 public:
165 /** 164 /**
166 * Constants that represent the order in which OCompletion performs 165 * Constants that represent the order in which OCompletion performs
167 * completion-lookups. 166 * completion-lookups.
168 */ 167 */
169 enum CompOrder { Sorted, Insertion, Weighted }; 168 enum CompOrder { Sorted, Insertion, Weighted };
170 169
171 /** 170 /**
172 * Constructor, nothing special here :) 171 * Constructor, nothing special here :)
173 */ 172 */
174 OCompletion(); 173 OCompletion();
175 174
176 // FIXME: copy constructor, assignment constructor... 175 // FIXME: copy constructor, assignment constructor...
177 176
178 /** 177 /**
179 * Destructor, nothing special here, either. 178 * Destructor, nothing special here, either.
180 */ 179 */
181 virtual ~OCompletion(); 180 virtual ~OCompletion();
182 181
183 /** 182 /**
184 * Attempts to find an item in the list of available completions, 183 * Attempts to find an item in the list of available completions,
185 * that begins with @p string. Will either return the first matching item 184 * that begins with @p string. Will either return the first matching item
186 * (if there is more than one match) or QString::null, if no match was 185 * (if there is more than one match) or QString::null, if no match was
187 * found. 186 * found.
188 * 187 *
189 * In the latter case, a sound will be issued, depending on 188 * In the latter case, a sound will be issued, depending on
190 * @ref isSoundsEnabled(). 189 * @ref isSoundsEnabled().
191 * If a match was found, it will also be emitted via the signal 190 * If a match was found, it will also be emitted via the signal
192 * @ref match(). 191 * @ref match().
193 * 192 *
194 * If this is called twice or more often with the same string while no 193 * If this is called twice or more often with the same string while no
195 * items were added or removed in the meantime, all available completions 194 * items were added or removed in the meantime, all available completions
196 * will be emitted via the signal @ref matches(). 195 * will be emitted via the signal @ref matches().
197 * This happens only in shell-completion-mode. 196 * This happens only in shell-completion-mode.
198 * 197 *
199 * @returns the matching item, or QString::null if there is no matching 198 * @returns the matching item, or QString::null if there is no matching
200 * item. 199 * item.
201 * @see #slotMakeCompletion 200 * @see #slotMakeCompletion
202 * @see #substringCompletion 201 * @see #substringCompletion
203 */ 202 */
204 virtual QString makeCompletion( const QString& string ); 203 virtual QString makeCompletion( const QString& string );
205 204
206 /** 205 /**
207 * @returns a list of items which all contain @p text as a substring, 206 * @returns a list of items which all contain @p text as a substring,
208 * i.e. not necessarily at the beginning. 207 * i.e. not necessarily at the beginning.
209 * 208 *
210 * @see #makeCompletion 209 * @see #makeCompletion
211 */ 210 */
212 QStringList substringCompletion( const QString& string ) const; 211 QStringList substringCompletion( const QString& string ) const;
213 212
214 /** 213 /**
215 * @returns the next item from the matching-items-list. 214 * @returns the next item from the matching-items-list.
216 * When reaching the beginning, the list is rotated so it will return the 215 * When reaching the beginning, the list is rotated so it will return the
217 * last match and a sound is issued (depending on @ref isSoundsEnabled()). 216 * last match and a sound is issued (depending on @ref isSoundsEnabled()).
218 * When there is no match, QString::null is returned and 217 * When there is no match, QString::null is returned and
219 * a sound is be issued. 218 * a sound is be issued.
220 * @see #slotPreviousMatch 219 * @see #slotPreviousMatch
221 */ 220 */
222 QString previousMatch(); 221 QString previousMatch();
223 222
224 /** 223 /**
225 * @returns the previous item from the matching-items-list 224 * @returns the previous item from the matching-items-list
226 * When reaching the last item, the list is rotated, so it will return 225 * When reaching the last item, the list is rotated, so it will return
227 * the first match and a sound is issued (depending on 226 * the first match and a sound is issued (depending on
228 * @ref isSoundsEnabled()). When there is no match, QString::null is 227 * @ref isSoundsEnabled()). When there is no match, QString::null is
229 * returned and a sound is issued. 228 * returned and a sound is issued.
230 * @see #slotNextMatch 229 * @see #slotNextMatch
231 */ 230 */
232 QString nextMatch(); 231 QString nextMatch();
233 232
234 /** 233 /**
235 * @returns the last match. Might be useful if you need to check whether 234 * @returns the last match. Might be useful if you need to check whether
236 * a completion is different from the last one. 235 * a completion is different from the last one.
237 * QString::null is returned when there is no last match. 236 * QString::null is returned when there is no last match.
238 */ 237 */
239 virtual const QString& lastMatch() const { return myLastMatch; } 238 virtual const QString& lastMatch() const { return myLastMatch; }
240 239
241 /** 240 /**
242 * Returns a list of all items inserted into OCompletion. This is useful 241 * Returns a list of all items inserted into OCompletion. This is useful
243 * if you need to save the state of a OCompletion object and restore it 242 * if you need to save the state of a OCompletion object and restore it
244 * later. 243 * later.
245 * 244 *
246 * Important note: when @ref order() == Weighted, then every item in the 245 * Important note: when @ref order() == Weighted, then every item in the
247 * stringlist has its weight appended, delimited by a colon. E.g. an item 246 * stringlist has its weight appended, delimited by a colon. E.g. an item
248 * "www.kde.org" might look like "www.kde.org:4", where 4 is the weight. 247 * "www.kde.org" might look like "www.kde.org:4", where 4 is the weight.
249 * 248 *
250 * This is necessary so that you can save the items along with its 249 * This is necessary so that you can save the items along with its
251 * weighting on disk and load them back with @ref setItems(), restoring its 250 * weighting on disk and load them back with @ref setItems(), restoring its
252 * weight as well. If you really don't want the appended weightings, call 251 * weight as well. If you really don't want the appended weightings, call
253 * @ref setOrder( OCompletion::Insertion ) 252 * @ref setOrder( OCompletion::Insertion )
254 * before calling items(). 253 * before calling items().
255 * 254 *
256 * @returns a list of all items 255 * @returns a list of all items
257 * @see #setItems 256 * @see #setItems
258 */ 257 */
259 QStringList items() const; 258 QStringList items() const;
260 259
261 /** 260 /**
262 * Sets the completion mode to Auto/Manual, Shell or None. 261 * Sets the completion mode to Auto/Manual, Shell or None.
263 * If you don't set the mode explicitly, the global default value 262 * If you don't set the mode explicitly, the global default value
264 * OGlobalSettings::completionMode() is used. 263 * OGlobalSettings::completionMode() is used.
265 * @ref OGlobalSettings::CompletionNone disables completion. 264 * @ref OGlobalSettings::CompletionNone disables completion.
266 * @see #completionMode 265 * @see #completionMode
267 * @see #OGlobalSettings::completionMode 266 * @see #OGlobalSettings::completionMode
268 */ 267 */
269 virtual void setCompletionMode( OGlobalSettings::Completion mode ); 268 virtual void setCompletionMode( OGlobalSettings::Completion mode );
270 269
271 /** 270 /**
272 * @returns the current completion mode. 271 * @returns the current completion mode.
273 * May be different from @ref OGlobalSettings::completionMode(), if you 272 * May be different from @ref OGlobalSettings::completionMode(), if you
274 * explicitly called @ref setCompletionMode(). 273 * explicitly called @ref setCompletionMode().
275 * @see #setCompletionMode 274 * @see #setCompletionMode
276 */ 275 */
277 OGlobalSettings::Completion completionMode() const { return myCompletionMode; }; 276 OGlobalSettings::Completion completionMode() const { return myCompletionMode; };
278 277
279 /** 278 /**
280 * OCompletion offers three different ways in which it offers its items: 279 * OCompletion offers three different ways in which it offers its items:
281 * @li in the order of insertion 280 * @li in the order of insertion
282 * @li sorted alphabetically 281 * @li sorted alphabetically
283 * @li weighted 282 * @li weighted
284 * 283 *
285 * Choosing weighted makes OCompletion perform an implicit weighting based 284 * Choosing weighted makes OCompletion perform an implicit weighting based
286 * on how often an item is inserted. Imagine a web browser with a location 285 * on how often an item is inserted. Imagine a web browser with a location
287 * bar, where the user enters URLs. The more often a URL is entered, the 286 * bar, where the user enters URLs. The more often a URL is entered, the
288 * higher priority it gets. 287 * higher priority it gets.
289 * 288 *
290 * Note: Setting the order to sorted only affects new inserted items, 289 * Note: Setting the order to sorted only affects new inserted items,
291 * already existing items will stay in the current order. So you probably 290 * already existing items will stay in the current order. So you probably
292 * want to call setOrder( Sorted ) before inserting items, when you want 291 * want to call setOrder( Sorted ) before inserting items, when you want
293 * everything sorted. 292 * everything sorted.
294 * 293 *
295 * Default is insertion order 294 * Default is insertion order
296 * @see #order 295 * @see #order
297 */ 296 */
298 virtual void setOrder( CompOrder order ); 297 virtual void setOrder( CompOrder order );
299 298
300 /** 299 /**
301 * @returns the current completion order. 300 * @returns the current completion order.
302 * @see #setOrder 301 * @see #setOrder
303 */ 302 */
304 CompOrder order() const { return myOrder; } 303 CompOrder order() const { return myOrder; }
305 304
306 /** 305 /**
307 * Setting this to true makes OCompletion behave case insensitively. 306 * Setting this to true makes OCompletion behave case insensitively.
308 * E.g. makeCompletion( "CA" ); might return "carp@cs.tu-berlin.de". 307 * E.g. makeCompletion( "CA" ); might return "carp@cs.tu-berlin.de".
309 * Default is false (case sensitive). 308 * Default is false (case sensitive).
310 * @see #ignoreCase 309 * @see #ignoreCase
311 */ 310 */
312 virtual void setIgnoreCase( bool ignoreCase ); 311 virtual void setIgnoreCase( bool ignoreCase );
313 312
314 /** 313 /**
315 * @returns whether OCompletion acts case insensitively or not. 314 * @returns whether OCompletion acts case insensitively or not.
316 * Default is false (case sensitive). 315 * Default is false (case sensitive).
317 * @see #setIgnoreCase 316 * @see #setIgnoreCase
318 */ 317 */
319 bool ignoreCase() const { return myIgnoreCase; }; 318 bool ignoreCase() const { return myIgnoreCase; };
320 319
321 /** 320 /**
322 * @returns a list of all items matching the last completed string. 321 * @returns a list of all items matching the last completed string.
323 * Might take some time, when you have LOTS of items. 322 * Might take some time, when you have LOTS of items.
324 * 323 *
325 * @see #substringCompletion 324 * @see #substringCompletion
326 */ 325 */
327 QStringList allMatches(); 326 QStringList allMatches();
328 327
329 /** 328 /**
330 * @returns a list of all items matching @p string. 329 * @returns a list of all items matching @p string.
331 */ 330 */
332 QStringList allMatches( const QString& string ); 331 QStringList allMatches( const QString& string );
333 332
334 /** 333 /**
335 * @returns a list of all items matching the last completed string. 334 * @returns a list of all items matching the last completed string.
336 * Might take some time, when you have LOTS of items. 335 * Might take some time, when you have LOTS of items.
337 * The matches are returned as OCompletionMatches, which also 336 * The matches are returned as OCompletionMatches, which also
338 * keeps the weight of the matches, allowing 337 * keeps the weight of the matches, allowing
339 * you to modify some matches or merge them with matches 338 * you to modify some matches or merge them with matches
340 * from another call to allWeightedMatches(), and sort the matches 339 * from another call to allWeightedMatches(), and sort the matches
341 * after that in order to have the matches ordered correctly 340 * after that in order to have the matches ordered correctly
342 * 341 *
343 * @see #substringCompletion 342 * @see #substringCompletion
344 */ 343 */
345 OCompletionMatches allWeightedMatches(); 344 OCompletionMatches allWeightedMatches();
346 345
347 /** 346 /**
348 * @returns a list of all items matching @p string. 347 * @returns a list of all items matching @p string.
349 */ 348 */
350 OCompletionMatches allWeightedMatches( const QString& string ); 349 OCompletionMatches allWeightedMatches( const QString& string );
351 350
352 /** 351 /**
353 * Enables/disables playing a sound when 352 * Enables/disables playing a sound when
354 * @li @ref makeCompletion() can't find a match 353 * @li @ref makeCompletion() can't find a match
355 * @li there is a partial completion (= multiple matches in 354 * @li there is a partial completion (= multiple matches in
356 * Shell-completion mode) 355 * Shell-completion mode)
357 * @li @ref nextMatch() or @ref previousMatch() hit the last possible 356 * @li @ref nextMatch() or @ref previousMatch() hit the last possible
358 * match -> rotation 357 * match -> rotation
359 * 358 *
360 * For playing the sounds, @ref ONotifyClient() is used. // FIXME: Revise this for Opie 359 * For playing the sounds, @ref ONotifyClient() is used. // FIXME: Revise this for Opie
361 * 360 *
362 * @see #isSoundsEnabled 361 * @see #isSoundsEnabled
363 */ 362 */
364 virtual void setEnableSounds( bool enable ) { myBeep = enable; } 363 virtual void setEnableSounds( bool enable ) { myBeep = enable; }
365 364
366 /** 365 /**
367 * Tells you whether OCompletion will play sounds on certain occasions. 366 * Tells you whether OCompletion will play sounds on certain occasions.
368 * Default is enabled 367 * Default is enabled
369 * @see #enableSounds 368 * @see #enableSounds
370 * @see #disableSounds 369 * @see #disableSounds
371 */ 370 */
372 bool isSoundsEnabled() const { return myBeep; }; 371 bool isSoundsEnabled() const { return myBeep; };
373 372
374 /** 373 /**
375 * @returns true when more than one match is found 374 * @returns true when more than one match is found
376 * @see #multipleMatches 375 * @see #multipleMatches
377 */ 376 */
378 bool hasMultipleMatches() const { return myHasMultipleMatches; }; 377 bool hasMultipleMatches() const { return myHasMultipleMatches; };
379 378
380 public slots: 379 public slots:
381 /** 380 /**
382 * Attempts to complete "string" and emits the completion via @ref match(). 381 * Attempts to complete "string" and emits the completion via @ref match().
383 * Same as @ref makeCompletion() (just as a slot). 382 * Same as @ref makeCompletion() (just as a slot).
384 * @see #makeCompletion 383 * @see #makeCompletion
385 */ 384 */
386 void slotMakeCompletion( const QString& string ) { (void) makeCompletion( string ); }; 385 void slotMakeCompletion( const QString& string ) { (void) makeCompletion( string ); };
387 386
388 /** 387 /**
389 * Searches the previous matching item and emits it via @ref match() 388 * Searches the previous matching item and emits it via @ref match()
390 * Same as @ref previousMatch() (just as a slot). 389 * Same as @ref previousMatch() (just as a slot).
391 * @see #previousMatch 390 * @see #previousMatch
392 */ 391 */
393 void slotPreviousMatch() { (void) previousMatch(); }; 392 void slotPreviousMatch() { (void) previousMatch(); };
394 393
395 /** 394 /**
396 * Searches the next matching item and emits it via @ref match() 395 * Searches the next matching item and emits it via @ref match()
397 * Same as @ref nextMatch() (just as a slot). 396 * Same as @ref nextMatch() (just as a slot).
398 * @see #nextMatch 397 * @see #nextMatch
399 */ 398 */
400 void slotNextMatch() { (void) nextMatch(); }; 399 void slotNextMatch() { (void) nextMatch(); };
401 400
402 /** 401 /**
403 * Inserts @p items into the list of possible completions. 402 * Inserts @p items into the list of possible completions.
404 * Does the same as @ref setItems(), but does not call @ref clear() before. 403 * Does the same as @ref setItems(), but does not call @ref clear() before.
405 */ 404 */
406 void insertItems( const QStringList& items ); 405 void insertItems( const QStringList& items );
407 406
408 /** 407 /**
409 * Sets the list of items available for completion. Removes all previous 408 * Sets the list of items available for completion. Removes all previous
410 * items. 409 * items.
411 * 410 *
412 * Notice: when order() == Weighted, then the weighting is looked up for 411 * Notice: when order() == Weighted, then the weighting is looked up for
413 * every item in the stringlist. Every item should have ":number" appended, 412 * every item in the stringlist. Every item should have ":number" appended,
414 * where number is an unsigned integer, specifying the weighting. 413 * where number is an unsigned integer, specifying the weighting.
415 * 414 *
416 * If you don't like this, call 415 * If you don't like this, call
417 * setOrder( OCompletion::Insertion ) 416 * setOrder( OCompletion::Insertion )
418 * before calling setItems(). 417 * before calling setItems().
419 * 418 *
420 * @see #items 419 * @see #items
421 */ 420 */
422 virtual void setItems( const QStringList& ); 421 virtual void setItems( const QStringList& );
423 422
424 /** 423 /**
425 * Adds an item to the list of available completions. 424 * Adds an item to the list of available completions.
426 * Resets the current item-state (@ref previousMatch() and @ref nextMatch() 425 * Resets the current item-state (@ref previousMatch() and @ref nextMatch()
427 * won't work anymore). 426 * won't work anymore).
428 */ 427 */
429 void addItem( const QString& ); 428 void addItem( const QString& );
430 429
431 /** 430 /**
432 * Adds an item to the list of available completions. 431 * Adds an item to the list of available completions.
433 * Resets the current item-state (@ref previousMatch() and @ref nextMatch() 432 * Resets the current item-state (@ref previousMatch() and @ref nextMatch()
434 * won't work anymore). 433 * won't work anymore).
435 * 434 *
436 * Sets the weighting of the item to @p weight or adds it to the current 435 * Sets the weighting of the item to @p weight or adds it to the current
437 * weighting if the item is already available. The weight has to be greater 436 * weighting if the item is already available. The weight has to be greater
438 * than 1 to take effect (default weight is 1). 437 * than 1 to take effect (default weight is 1).
439 */ 438 */
440 void addItem( const QString&, uint weight ); 439 void addItem( const QString&, uint weight );
441 440
442 /** 441 /**
443 * Removes an item from the list of available completions. 442 * Removes an item from the list of available completions.
444 * Resets the current item-state (@ref previousMatch() and @ref nextMatch() 443 * Resets the current item-state (@ref previousMatch() and @ref nextMatch()
445 * won't work anymore). 444 * won't work anymore).
446 */ 445 */
447 void removeItem( const QString& ); 446 void removeItem( const QString& );
448 447
449 /** 448 /**
450 * Removes all inserted items. 449 * Removes all inserted items.
451 */ 450 */
452 virtual void clear(); 451 virtual void clear();
453 452
454 signals: 453 signals:
455 /** 454 /**
456 * The matching item. Will be emitted by @ref makeCompletion(), 455 * The matching item. Will be emitted by @ref makeCompletion(),
457 * @ref previousMatch() or @ref nextMatch(). May be QString::null if there 456 * @ref previousMatch() or @ref nextMatch(). May be QString::null if there
458 * is no matching item. 457 * is no matching item.
459 */ 458 */
460 void match( const QString& ); 459 void match( const QString& );
461 460
462 /** 461 /**
463 * All matching items. Will be emitted by @ref makeCompletion() in shell- 462 * All matching items. Will be emitted by @ref makeCompletion() in shell-
464 * completion-mode, when the same string is passed to makeCompletion twice 463 * completion-mode, when the same string is passed to makeCompletion twice
465 * or more often. 464 * or more often.
466 */ 465 */
467 void matches( const QStringList& ); 466 void matches( const QStringList& );
468 467
469 /** 468 /**
470 * This signal is emitted, when calling @ref makeCompletion() and more than 469 * This signal is emitted, when calling @ref makeCompletion() and more than
471 * one matching item is found. 470 * one matching item is found.
472 * @see #hasMultipleMatches 471 * @see #hasMultipleMatches
473 */ 472 */
474 void multipleMatches(); 473 void multipleMatches();
475 474
476 protected: 475 protected:
477 /** 476 /**
478 * This method is called after a completion is found and before the 477 * This method is called after a completion is found and before the
479 * matching string is emitted. You can override this method to modify the 478 * matching string is emitted. You can override this method to modify the
480 * string that will be emitted. 479 * string that will be emitted.
481 * This is necessary e.g. in @ref OURLCompletion(), where files with spaces 480 * This is necessary e.g. in @ref OURLCompletion(), where files with spaces
482 * in their names are shown escaped ("filename\ with\ spaces"), but stored 481 * in their names are shown escaped ("filename\ with\ spaces"), but stored
483 * unescaped inside OCompletion. 482 * unescaped inside OCompletion.
484 * Never delete that pointer! 483 * Never delete that pointer!
485 * 484 *
486 * Default implementation does nothing. 485 * Default implementation does nothing.
487 * @see #postProcessMatches 486 * @see #postProcessMatches
488 */ 487 */
489 virtual void postProcessMatch( QString * /*match*/ ) const {} 488 virtual void postProcessMatch( QString * /*match*/ ) const {}
490 489
491 /** 490 /**
492 * This method is called before a list of all available completions is 491 * This method is called before a list of all available completions is
493 * emitted via @ref matches. You can override this method to modify the 492 * emitted via @ref matches. You can override this method to modify the
494 * found items before @ref match() or @ref matches() are emitted. 493 * found items before @ref match() or @ref matches() are emitted.
495 * Never delete that pointer! 494 * Never delete that pointer!
496 * 495 *
497 * Default implementation does nothing. 496 * Default implementation does nothing.
498 * @see #postProcessMatch 497 * @see #postProcessMatch
499 */ 498 */
500 virtual void postProcessMatches( QStringList * /*matches*/ ) const {} 499 virtual void postProcessMatches( QStringList * /*matches*/ ) const {}
501 500
502 /** 501 /**
503 * This method is called before a list of all available completions is 502 * This method is called before a list of all available completions is
504 * emitted via @ref matches. You can override this method to modify the 503 * emitted via @ref matches. You can override this method to modify the
505 * found items before @ref match() or @ref matches() are emitted. 504 * found items before @ref match() or @ref matches() are emitted.
506 * Never delete that pointer! 505 * Never delete that pointer!
507 * 506 *
508 * Default implementation does nothing. 507 * Default implementation does nothing.
509 * @see #postProcessMatch 508 * @see #postProcessMatch
510 */ 509 */
511 virtual void postProcessMatches( OCompletionMatches * /*matches*/ ) const {} 510 virtual void postProcessMatches( OCompletionMatches * /*matches*/ ) const {}
512 511
513private: 512private:
514 void addWeightedItem( const QString& ); 513 void addWeightedItem( const QString& );
515 QString findCompletion( const QString& string ); 514 QString findCompletion( const QString& string );
516 void findAllCompletions( const QString&, OCompletionMatchesWrapper *matches, bool& hasMultipleMatches ) const; 515 void findAllCompletions( const QString&, OCompletionMatchesWrapper *matches, bool& hasMultipleMatches ) const;
517 516
518 void extractStringsFromNode( const OCompTreeNode *, 517 void extractStringsFromNode( const OCompTreeNode *,
519 const QString& beginning, 518 const QString& beginning,
520 OCompletionMatchesWrapper *matches, 519 OCompletionMatchesWrapper *matches,
521 bool addWeight = false ) const; 520 bool addWeight = false ) const;
522 void extractStringsFromNodeCI( const OCompTreeNode *, 521 void extractStringsFromNodeCI( const OCompTreeNode *,
523 const QString& beginning, 522 const QString& beginning,
524 const QString& restString, 523 const QString& restString,
525 OCompletionMatchesWrapper *matches) const; 524 OCompletionMatchesWrapper *matches) const;
526 525
527 enum BeepMode { NoMatch, PartialMatch, Rotation }; 526 enum BeepMode { NoMatch, PartialMatch, Rotation };
528 void doBeep( BeepMode ) const; 527 void doBeep( BeepMode ) const;
529 528
530 OGlobalSettings::Completion myCompletionMode; 529 OGlobalSettings::Completion myCompletionMode;
531 530
532 CompOrder myOrder; 531 CompOrder myOrder;
533 QString myLastString; 532 QString myLastString;
534 QString myLastMatch; 533 QString myLastMatch;
535 QString myCurrentMatch; 534 QString myCurrentMatch;
536 OCompTreeNode * myTreeRoot; 535 OCompTreeNode * myTreeRoot;
537 QStringList myRotations; 536 QStringList myRotations;
538 bool myBeep; 537 bool myBeep;
539 bool myIgnoreCase; 538 bool myIgnoreCase;
540 bool myHasMultipleMatches; 539 bool myHasMultipleMatches;
541 uint myRotationIndex; 540 uint myRotationIndex;
542 541
543 private: 542 private:
544 OCompletionPrivate *d; 543 OCompletionPrivate *d;
545}; 544};
546 545
547// some more helper stuff 546// some more helper stuff
548typedef OSortableValueList<QString> OCompletionMatchesList; 547typedef OSortableValueList<QString> OCompletionMatchesList;
549class OCompletionMatchesPrivate; 548class OCompletionMatchesPrivate;
550 549
551/** 550/**
552 * This structure is returned by @ref OCompletion::allWeightedMatches . 551 * This structure is returned by @ref OCompletion::allWeightedMatches .
553 * It also keeps the weight of the matches, allowing 552 * It also keeps the weight of the matches, allowing
554 * you to modify some matches or merge them with matches 553 * you to modify some matches or merge them with matches
555 * from another call to allWeightedMatches(), and sort the matches 554 * from another call to allWeightedMatches(), and sort the matches
556 * after that in order to have the matches ordered correctly 555 * after that in order to have the matches ordered correctly
557 * 556 *
558 * Example (a simplified example of what Oonqueror's completion does): 557 * Example (a simplified example of what Oonqueror's completion does):
559 * <pre> 558 * <pre>
560 * OCompletionMatches matches = completion->allWeightedMatches( location ); 559 * OCompletionMatches matches = completion->allWeightedMatches( location );
561 * if( !location.startsWith( "www." )) 560 * if( !location.startsWith( "www." ))
562 matches += completion->allWeightedmatches( "www." + location" ); 561 matches += completion->allWeightedmatches( "www." + location" );
563 * matches.removeDuplicates(); 562 * matches.removeDuplicates();
564 * QStringList list = matches.list(); 563 * QStringList list = matches.list();
565 * </pre> 564 * </pre>
566 * 565 *
567 * @short List for keeping matches returned from OCompletion 566 * @short List for keeping matches returned from OCompletion
568 */ 567 */
569 568
570class OCompletionMatches 569class OCompletionMatches
571 : public OCompletionMatchesList 570 : public OCompletionMatchesList
572{ 571{
573 public: 572 public:
574 OCompletionMatches( bool sort ); 573 OCompletionMatches( bool sort );
575 /** 574 /**
576 * @internal 575 * @internal
577 */ 576 */
578 OCompletionMatches( const OCompletionMatchesWrapper& matches ); 577 OCompletionMatches( const OCompletionMatchesWrapper& matches );
579 ~OCompletionMatches(); 578 ~OCompletionMatches();
580 /** 579 /**
581 * Removes duplicate matches. Needed only when you merged several matches 580 * Removes duplicate matches. Needed only when you merged several matches
582 * results and there's a possibility of duplicates. 581 * results and there's a possibility of duplicates.
583 */ 582 */
584 void removeDuplicates(); 583 void removeDuplicates();
585 /** 584 /**
586 * Returns the matches as a QStringList. 585 * Returns the matches as a QStringList.
587 * @param sort if false, the matches won't be sorted before the conversion, 586 * @param sort if false, the matches won't be sorted before the conversion,
588 * use only if you're sure the sorting is not needed 587 * use only if you're sure the sorting is not needed
589 */ 588 */
590 QStringList list( bool sort = true ) const; 589 QStringList list( bool sort = true ) const;
591 /** 590 /**
592 * If sorting() returns false, the matches aren't sorted by their weight, 591 * If sorting() returns false, the matches aren't sorted by their weight,
593 * even if true is passed to list(). 592 * even if true is passed to list().
594 */ 593 */
595 bool sorting() const { 594 bool sorting() const {
596 return _sorting; 595 return _sorting;
597 } 596 }
598private: 597private:
599 bool _sorting; 598 bool _sorting;
600 OCompletionMatchesPrivate* d; 599 OCompletionMatchesPrivate* d;
601}; 600};
602 601
603#endif // OCOMPLETION_H 602#endif // OCOMPLETION_H