add more spacing
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / triggers / triggers.h
blob71116c657ffd1350b10647f25cbcaac7e2579dd7
1 /*
2 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3 Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef _TRIGGERS_H_
21 #define _TRIGGERS_H_
23 #include <QtCore/QList>
24 #include <QtCore/QMap>
25 #include <QtCore/QUuid>
27 #include <KDE/KShortcut>
29 #include <kdemacros.h>
30 #include "khotkeysglobal.h"
31 #include "voicesignature.h"
33 #include "input.h"
34 #include "windows.h"
37 class KConfig;
38 class QKeySequence;
40 namespace KHotKeys
43 class Windowdef_list;
44 class ActionData;
46 class KDE_EXPORT Trigger
48 Q_DISABLE_COPY( Trigger )
50 public:
52 enum TriggerType
54 GestureTriggerType = 0x01, //!< @see GestureTrigger
55 ShortcutTriggerType = 0x02, //!< @see ShortcutTrigger
56 WindowTriggerType = 0x04, //!< @see WindowTrigger
57 TriggerListType = 0x08, //!< @see Trigger_list
58 AllTypes = 0xFF //!< All types. For convenience.
61 Q_DECLARE_FLAGS(TriggerTypes, TriggerType)
63 Trigger( ActionData* data_P );
64 Trigger( KConfigGroup& cfg_P, ActionData* data_P );
65 virtual ~Trigger();
66 virtual void cfg_write( KConfigGroup& cfg_P ) const = 0;
67 virtual Trigger* copy( ActionData* data_P ) const = 0;
68 virtual const QString description() const = 0;
69 static Trigger* create_cfg_read( KConfigGroup& cfg_P, ActionData* data_P );
70 virtual void activate( bool activate_P ) = 0;
72 /**
73 * The trigger will be erased permanently
75 virtual void aboutToBeErased();
77 /**
78 * The actual type for this trigger
80 virtual TriggerType type() const = 0;
82 protected:
83 ActionData* const data;
86 Q_DECLARE_OPERATORS_FOR_FLAGS(Trigger::TriggerTypes)
89 class KDE_EXPORT Trigger_list
90 : public QList< Trigger* >
92 Q_DISABLE_COPY( Trigger_list )
94 public:
95 Trigger_list( const QString& comment_P ); // CHECKME nebo i data ?
96 Trigger_list( KConfigGroup& cfg_P, ActionData* data_P );
97 ~Trigger_list();
98 void activate( bool activate_P );
99 void cfg_write( KConfigGroup& cfg_P ) const;
100 //! Some convenience typedef
101 typedef QList< Trigger* >::Iterator Iterator;
102 typedef QList< Trigger* >::ConstIterator ConstIterator;
103 const QString comment() const;
104 Trigger_list* copy( ActionData* data_P ) const;
107 * @reimp
109 void aboutToBeErased();
111 private:
112 QString _comment;
115 class KDE_EXPORT ShortcutTrigger
116 : public QObject, public Trigger
118 Q_OBJECT
120 typedef Trigger base;
121 public:
122 ShortcutTrigger(
123 ActionData* data_P,
124 const KShortcut& shortcut_P,
125 const QUuid &uuid = QUuid::createUuid() );
127 ShortcutTrigger(
128 KConfigGroup& cfg_P,
129 ActionData* data_P );
131 virtual ~ShortcutTrigger();
132 virtual void cfg_write( KConfigGroup& cfg_P ) const;
133 virtual ShortcutTrigger* copy( ActionData* data_P ) const;
134 virtual const QString description() const;
135 KShortcut shortcut() const;
136 virtual void activate( bool activate_P );
138 void set_key_sequence( const QKeySequence &seq );
140 virtual TriggerType type() const { return ShortcutTriggerType; }
143 * @reimp
145 void aboutToBeErased();
147 Q_SIGNALS:
149 //! Emitted when the global shortcut is changed from somewhere else
150 // (Global Shortcuts KCM)
151 void globalShortcutChanged(const QKeySequence&);
153 public Q_SLOTS:
155 void trigger();
157 private:
159 //! A persistent identifier for this shortcut
160 QUuid _uuid;
163 class KDE_EXPORT WindowTrigger
164 : public QObject, public Trigger
166 Q_OBJECT
167 typedef Trigger base;
168 public:
169 enum window_action_t
171 WINDOW_APPEARS = ( 1 << 0 ),
172 WINDOW_DISAPPEARS = ( 1 << 1 ),
173 WINDOW_ACTIVATES = ( 1 << 2 ),
174 WINDOW_DEACTIVATES = ( 1 << 3 )
176 WindowTrigger( ActionData* data_P, Windowdef_list* windows_P, int window_actions_P );
177 WindowTrigger( KConfigGroup& cfg_P, ActionData* data_P );
178 virtual ~WindowTrigger();
179 virtual void cfg_write( KConfigGroup& cfg_P ) const;
180 virtual WindowTrigger* copy( ActionData* data_P ) const;
181 virtual const QString description() const;
182 const Windowdef_list* windows() const;
183 bool triggers_on( window_action_t w_action_P ) const;
184 virtual void activate( bool activate_P );
186 virtual TriggerType type() const { return WindowTriggerType; }
187 protected: // CHECKME neco private ?
188 Windowdef_list* _windows;
189 int window_actions;
190 void init();
191 typedef QMap< WId, bool > Windows_map;
192 Windows_map existing_windows;
193 WId last_active_window;
194 protected Q_SLOTS:
195 void window_added( WId window_P );
196 void window_removed( WId window_P );
197 void active_window_changed( WId window_P );
198 void window_changed( WId window_P, unsigned int dirty_P );
199 protected:
200 bool active;
203 class KDE_EXPORT GestureTrigger
204 : public QObject, public Trigger
206 Q_OBJECT
207 typedef Trigger base;
208 public:
209 GestureTrigger( ActionData* data_P, const QString& gesture_P );
210 GestureTrigger( KConfigGroup& cfg_P, ActionData* data_P );
211 virtual ~GestureTrigger();
212 virtual void cfg_write( KConfigGroup& cfg_P ) const;
213 virtual Trigger* copy( ActionData* data_P ) const;
214 virtual const QString description() const;
215 const QString& gesturecode() const;
216 virtual void activate( bool activate_P );
218 virtual TriggerType type() const { return GestureTriggerType; }
219 protected Q_SLOTS:
220 void handle_gesture( const QString& gesture_P, WId window_P );
221 private:
222 QString _gesturecode;
226 // FIXME: SOUND
227 #if 0
228 class KDE_EXPORT Voice_trigger
229 : public QObject, public Trigger
231 Q_OBJECT
232 typedef Trigger base;
233 public:
234 Voice_trigger( ActionData* data_P, const QString& Voice_P, const VoiceSignature & signature1_P, const VoiceSignature & signature2_P );
235 Voice_trigger( KConfigGroup& cfg_P, ActionData* data_P );
236 virtual ~Voice_trigger();
237 virtual void cfg_write( KConfigGroup& cfg_P ) const;
238 virtual Trigger* copy( ActionData* data_P ) const;
239 virtual const QString description() const;
240 const QString& voicecode() const;
241 virtual void activate( bool activate_P );
242 VoiceSignature voicesignature( int ech ) const;
244 virtual TriggerType type() const { return SoundTrigger; }
245 public slots:
246 void handle_Voice( );
247 private:
248 QString _voicecode;
249 VoiceSignature _voicesignature[2];
251 #endif
253 // FIXME: SOUND
254 #if 0
255 // Voice_trigger
256 inline
257 const QString& Voice_trigger::voicecode() const
259 return _voicecode;
262 inline
263 VoiceSignature Voice_trigger::voicesignature(int ech) const
265 return _voicesignature[ech-1];
267 #endif
268 } // namespace KHotKeys
270 #endif