add more spacing
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / conditions / conditions.h
blobab1716d22910e69d991ef68941239dbb75bb0f6c
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #ifndef _CONDITIONS_H_
12 #define _CONDITIONS_H_
14 #include "action_data/action_data_group.h"
16 #include "windows.h"
18 // Needed for None below
19 #include <X11/Xlib.h>
20 #include <fixx11h.h>
22 #include <QtCore/QObject>
24 class KConfig;
26 namespace KHotKeys
29 class ActionDataBase;
30 class ActionData;
31 class Condition_list_base;
33 class KDE_EXPORT Condition
35 Q_DISABLE_COPY( Condition )
37 public:
38 Condition( Condition_list_base* parent_P );
39 Condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
40 virtual ~Condition();
41 virtual bool match() const = 0;
42 virtual void updated() const; // called when the condition changes
43 virtual void cfg_write( KConfigGroup& cfg_P ) const = 0;
44 virtual const QString description() const = 0;
45 virtual Condition* copy( Condition_list_base* parent_P ) const = 0;
46 const Condition_list_base* parent() const;
47 Condition_list_base* parent();
48 static Condition* create_cfg_read( KConfigGroup& cfg_P, Condition_list_base* parent_P );
49 protected:
50 Condition_list_base* const _parent;
53 class KDE_EXPORT Condition_list_base
54 : public Condition, public Q3PtrList< Condition > // inheritance ?
56 typedef Condition base;
57 public:
58 Condition_list_base( Condition_list_base* parent_P );
59 Condition_list_base( const Q3PtrList< Condition >& children_P,
60 Condition_list_base* parent_P );
61 Condition_list_base( KConfigGroup& cfg_P, Condition_list_base* parent_P );
62 virtual ~Condition_list_base();
63 virtual void cfg_write( KConfigGroup& cfg_P ) const;
64 virtual bool accepts_children() const;
65 typedef Q3PtrListIterator< Condition > Iterator;
68 class KDE_EXPORT Condition_list
69 : public Condition_list_base
71 typedef Condition_list_base base;
72 public:
73 Condition_list( const QString& comment_P, ActionDataBase* data_P );
74 Condition_list( KConfigGroup& cfg_P, ActionDataBase* data_P );
75 void cfg_write( KConfigGroup& cfg_P ) const;
76 Condition_list* copy( ActionDataBase* data_P ) const;
77 virtual bool match() const;
78 const QString& comment() const;
79 void set_data( ActionDataBase* data_P );
80 virtual void updated() const;
81 virtual Condition_list* copy( Condition_list_base* parent_P ) const;
82 virtual const QString description() const;
83 private:
84 QString _comment;
85 ActionDataBase* data;
88 class KDE_EXPORT Active_window_condition
89 : public QObject, public Condition
91 Q_OBJECT
92 typedef Condition base;
93 public:
94 Active_window_condition( Windowdef_list* window_P, Condition_list_base* parent_P );
95 Active_window_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
96 virtual ~Active_window_condition();
97 virtual bool match() const;
98 virtual void cfg_write( KConfigGroup& cfg_P ) const;
99 const Windowdef_list* window() const;
100 virtual Active_window_condition* copy( Condition_list_base* parent_P ) const;
101 virtual const QString description() const;
102 public Q_SLOTS:
103 void active_window_changed( WId );
104 private:
105 void init();
106 void set_match();
107 Windowdef_list* _window;
108 bool is_match;
111 class KDE_EXPORT Existing_window_condition
112 : public QObject, public Condition
114 Q_OBJECT
115 typedef Condition base;
116 public:
117 Existing_window_condition( Windowdef_list* window_P, Condition_list_base* parent_P );
118 Existing_window_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
119 virtual ~Existing_window_condition();
120 virtual bool match() const;
121 virtual void cfg_write( KConfigGroup& cfg_P ) const;
122 const Windowdef_list* window() const;
123 virtual Existing_window_condition* copy( Condition_list_base* parent_P ) const;
124 virtual const QString description() const;
125 public Q_SLOTS:
126 void window_added( WId w_P );
127 void window_removed( WId w_P );
128 private:
129 void init();
130 void set_match( WId w_P = None );
131 Windowdef_list* _window;
132 bool is_match;
135 class KDE_EXPORT Not_condition
136 : public Condition_list_base
138 typedef Condition_list_base base;
139 public:
140 Not_condition( Condition_list_base* parent_P );
141 Not_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
142 virtual bool match() const;
143 virtual void cfg_write( KConfigGroup& cfg_P ) const;
144 virtual Not_condition* copy( Condition_list_base* parent_P ) const;
145 virtual const QString description() const;
146 const Condition* condition() const;
147 virtual bool accepts_children() const;
150 class KDE_EXPORT And_condition
151 : public Condition_list_base
153 typedef Condition_list_base base;
154 public:
155 And_condition( Condition_list_base* parent_P );
156 And_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
157 virtual bool match() const;
158 virtual void cfg_write( KConfigGroup& cfg_P ) const;
159 virtual And_condition* copy( Condition_list_base* parent_P ) const;
160 virtual const QString description() const;
163 class KDE_EXPORT Or_condition
164 : public Condition_list_base
166 typedef Condition_list_base base;
167 public:
168 Or_condition( Condition_list_base* parent_P );
169 Or_condition( KConfigGroup& cfg_P, Condition_list_base* parent_P );
170 virtual bool match() const;
171 virtual void cfg_write( KConfigGroup& cfg_P ) const;
172 virtual Or_condition* copy( Condition_list_base* parent_P ) const;
173 virtual const QString description() const;
176 //***************************************************************************
177 // Inline
178 //***************************************************************************
180 // Condition
182 inline
183 const Condition_list_base* Condition::parent() const
185 return _parent;
188 inline
189 Condition_list_base* Condition::parent()
191 return _parent;
194 // Condition_list_base
196 inline
197 Condition_list_base::Condition_list_base( Condition_list_base* parent_P )
198 : Condition( parent_P ), Q3PtrList< Condition >()
202 inline
203 Condition_list_base::Condition_list_base( const Q3PtrList< Condition >& children_P,
204 Condition_list_base* parent_P )
205 : Condition( parent_P ), Q3PtrList< Condition >( children_P )
209 // Condition_list
211 inline
212 Condition_list::Condition_list( const QString& comment_P, ActionDataBase* data_P )
213 : Condition_list_base( NULL ), _comment( comment_P ), data( data_P )
217 inline
218 const QString& Condition_list::comment() const
220 return _comment;
223 // Active_window_condition
225 inline
226 Active_window_condition::Active_window_condition( Windowdef_list* window_P,
227 Condition_list_base* parent_P )
228 : Condition( parent_P ), _window( window_P )
230 init();
231 set_match();
234 inline
235 const Windowdef_list* Active_window_condition::window() const
237 return _window;
240 // Existing_window_condition
242 inline
243 Existing_window_condition::Existing_window_condition( Windowdef_list* window_P,
244 Condition_list_base* parent_P )
245 : Condition( parent_P ), _window( window_P ), is_match( false )
247 init();
248 set_match();
251 inline
252 const Windowdef_list* Existing_window_condition::window() const
254 return _window;
257 // Not_condition
259 inline
260 Not_condition::Not_condition( Condition_list_base* parent_P )
261 : Condition_list_base( parent_P )
265 inline
266 const Condition* Not_condition::condition() const
268 return getFirst();
271 // And_condition
273 inline
274 And_condition::And_condition( Condition_list_base* parent_P )
275 : Condition_list_base( parent_P )
279 // Or_condition
281 inline
282 Or_condition::Or_condition( Condition_list_base* parent_P )
283 : Condition_list_base( parent_P )
287 } // namespace KHotKeys
289 #endif